@tsrx/preact 0.1.50 → 0.1.51
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/src/error-boundary.js +11 -4
- package/src/index.js +6 -6
- package/src/transform.js +0 -7
- package/types/error-boundary.d.ts +1 -1
- package/types/index.d.ts +9 -0
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"description": "Preact compiler built on @tsrx/core",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Dominic Gannaway",
|
|
6
|
-
"version": "0.1.
|
|
6
|
+
"version": "0.1.51",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"publishConfig": {
|
|
9
9
|
"access": "public"
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"esrap": "^2.3.0",
|
|
39
39
|
"zimmerframe": "^1.1.2",
|
|
40
|
-
"@tsrx/core": "0.1.
|
|
40
|
+
"@tsrx/core": "0.1.51"
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|
|
43
43
|
"preact": ">=10"
|
package/src/error-boundary.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
/** @import { ComponentChildren } from 'preact' */
|
|
2
|
+
/** @import { TsrxErrorBoundaryProps, TsrxErrorBoundaryState } from '../types/error-boundary' */
|
|
3
|
+
|
|
1
4
|
import { Component } from 'preact';
|
|
2
5
|
|
|
3
6
|
/**
|
|
@@ -6,24 +9,28 @@ import { Component } from 'preact';
|
|
|
6
9
|
* Used by the `@tsrx/preact` compiler to implement `try/catch` blocks.
|
|
7
10
|
* The `fallback` prop receives the caught error and a `reset` function
|
|
8
11
|
* that clears the error state to re-render the children.
|
|
12
|
+
*
|
|
13
|
+
* @extends {Component<TsrxErrorBoundaryProps, TsrxErrorBoundaryState>}
|
|
9
14
|
*/
|
|
10
15
|
export class TsrxErrorBoundary extends Component {
|
|
11
|
-
|
|
16
|
+
/** @param {TsrxErrorBoundaryProps} props */
|
|
17
|
+
constructor(props) {
|
|
12
18
|
super(props);
|
|
13
|
-
/** @type {
|
|
19
|
+
/** @type {TsrxErrorBoundaryState} */
|
|
14
20
|
this.state = { error: null };
|
|
15
21
|
}
|
|
16
22
|
|
|
17
23
|
/**
|
|
18
24
|
* @param {Error} error
|
|
19
|
-
* @returns {
|
|
25
|
+
* @returns {TsrxErrorBoundaryState}
|
|
20
26
|
*/
|
|
21
27
|
static getDerivedStateFromError(error) {
|
|
22
28
|
return { error };
|
|
23
29
|
}
|
|
24
30
|
|
|
31
|
+
/** @returns {ComponentChildren} */
|
|
25
32
|
render() {
|
|
26
|
-
const { error } =
|
|
33
|
+
const { error } = this.state;
|
|
27
34
|
if (error !== null) {
|
|
28
35
|
const reset = () => this.setState({ error: null });
|
|
29
36
|
return this.props.fallback(error, reset);
|
package/src/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/** @import * as AST from 'estree' */
|
|
2
|
-
/** @import { CompileError, ParseOptions } from '@tsrx/core/types' */
|
|
2
|
+
/** @import { BaseCompileOptions, CompileError, CompileResult, ParseOptions, VolarMappingsResult } from '@tsrx/core/types' */
|
|
3
3
|
/** @import { NonEmptyString } from '@tsrx/core/types/helpers' */
|
|
4
|
-
/** @import { CompileOptions } from '
|
|
4
|
+
/** @import { CompileOptions } from '../types/index' */
|
|
5
5
|
|
|
6
6
|
import { analyzeTsrx, createVolarMappingsResult, dedupeMappings, parseModule } from '@tsrx/core';
|
|
7
7
|
import { DEFAULT_SUSPENSE_SOURCE, transform } from './transform.js';
|
|
@@ -28,8 +28,8 @@ export function parse(source, filename, options) {
|
|
|
28
28
|
* @template {string} T
|
|
29
29
|
* @param {string} source
|
|
30
30
|
* @param {NonEmptyString<T>} filename
|
|
31
|
-
* @param {CompileOptions &
|
|
32
|
-
* @returns {
|
|
31
|
+
* @param {CompileOptions & BaseCompileOptions} [compile_options]
|
|
32
|
+
* @returns {CompileResult}
|
|
33
33
|
*/
|
|
34
34
|
export function compile(source, filename, compile_options) {
|
|
35
35
|
const errors = /** @type {CompileError[]} */ ([]);
|
|
@@ -70,10 +70,10 @@ export function compile(source, filename, compile_options) {
|
|
|
70
70
|
* @param {string} source
|
|
71
71
|
* @param {NonEmptyString<T>} filename
|
|
72
72
|
* @param {ParseOptions & CompileOptions} [options]
|
|
73
|
-
* @returns {
|
|
73
|
+
* @returns {VolarMappingsResult}
|
|
74
74
|
*/
|
|
75
75
|
export function compile_to_volar_mappings(source, filename, options) {
|
|
76
|
-
const errors = /** @type {
|
|
76
|
+
const errors = /** @type {CompileError[]} */ ([]);
|
|
77
77
|
const comments = /** @type {AST.CommentWithLocation[]} */ ([]);
|
|
78
78
|
const ast = parseModule(source, filename, {
|
|
79
79
|
...options,
|
package/src/transform.js
CHANGED
|
@@ -10,13 +10,6 @@ import { createJsxTransform } from '@tsrx/core';
|
|
|
10
10
|
*/
|
|
11
11
|
export const DEFAULT_SUSPENSE_SOURCE = 'preact/compat';
|
|
12
12
|
|
|
13
|
-
/**
|
|
14
|
-
* Per-call compile options for tsrx-preact. Exposed publicly so the Vite
|
|
15
|
-
* plugin's typings can extend them.
|
|
16
|
-
*
|
|
17
|
-
* @typedef {{ suspenseSource?: string }} CompileOptions
|
|
18
|
-
*/
|
|
19
|
-
|
|
20
13
|
/**
|
|
21
14
|
* Preact platform descriptor consumed by `createJsxTransform`.
|
|
22
15
|
*
|
|
@@ -10,6 +10,6 @@ export interface TsrxErrorBoundaryState {
|
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
export class TsrxErrorBoundary extends Component<TsrxErrorBoundaryProps, TsrxErrorBoundaryState> {
|
|
13
|
-
static getDerivedStateFromError(error: Error):
|
|
13
|
+
static getDerivedStateFromError(error: Error): TsrxErrorBoundaryState;
|
|
14
14
|
render(): ComponentChildren | VNode;
|
|
15
15
|
}
|
package/types/index.d.ts
CHANGED
|
@@ -1,7 +1,16 @@
|
|
|
1
1
|
import type { Program } from 'estree';
|
|
2
2
|
import type { BaseCompileOptions, CompileFn, ParseOptions, VolarCompileFn } from '@tsrx/core/types';
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Per-call compile options for tsrx-preact. Exposed publicly so the Vite
|
|
6
|
+
* plugin's typings can extend them.
|
|
7
|
+
*/
|
|
4
8
|
export interface CompileOptions {
|
|
9
|
+
/**
|
|
10
|
+
* Module `Suspense` is imported from. Defaults to
|
|
11
|
+
* {@link DEFAULT_SUSPENSE_SOURCE} (`preact/compat`); projects on
|
|
12
|
+
* `@preact/compat` or a workspace alias override it here.
|
|
13
|
+
*/
|
|
5
14
|
suspenseSource?: string;
|
|
6
15
|
}
|
|
7
16
|
|