@tsrx/react 0.2.50 → 0.2.52
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 +12 -5
- package/src/index.js +5 -5
- package/types/error-boundary.d.ts +1 -1
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"description": "React compiler built on @tsrx/core",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Dominic Gannaway",
|
|
6
|
-
"version": "0.2.
|
|
6
|
+
"version": "0.2.52",
|
|
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.52"
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|
|
43
43
|
"react": ">=18"
|
package/src/error-boundary.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
/** @import { ReactNode } from 'react' */
|
|
2
|
+
/** @import { TsrxErrorBoundaryProps, TsrxErrorBoundaryState } from '../types/error-boundary' */
|
|
3
|
+
|
|
4
|
+
import { Component } from 'react';
|
|
2
5
|
|
|
3
6
|
/**
|
|
4
7
|
* A reusable React error boundary class component.
|
|
@@ -6,24 +9,28 @@ import { Component, createElement } from 'react';
|
|
|
6
9
|
* Used by the `@tsrx/react` 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 {ReactNode} */
|
|
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,5 +1,5 @@
|
|
|
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
4
|
|
|
5
5
|
import { analyzeTsrx, createVolarMappingsResult, dedupeMappings, parseModule } from '@tsrx/core';
|
|
@@ -26,8 +26,8 @@ export function parse(source, filename, options) {
|
|
|
26
26
|
* @template {string} T
|
|
27
27
|
* @param {string} source
|
|
28
28
|
* @param {NonEmptyString<T>} filename
|
|
29
|
-
* @param {
|
|
30
|
-
* @returns {
|
|
29
|
+
* @param {BaseCompileOptions} [options]
|
|
30
|
+
* @returns {CompileResult}
|
|
31
31
|
*/
|
|
32
32
|
export function compile(source, filename, options) {
|
|
33
33
|
const errors = /** @type {CompileError[]} */ ([]);
|
|
@@ -59,10 +59,10 @@ export function compile(source, filename, options) {
|
|
|
59
59
|
* @param {string} source
|
|
60
60
|
* @param {NonEmptyString<T>} filename
|
|
61
61
|
* @param {ParseOptions} [options]
|
|
62
|
-
* @returns {
|
|
62
|
+
* @returns {VolarMappingsResult}
|
|
63
63
|
*/
|
|
64
64
|
export function compile_to_volar_mappings(source, filename, options) {
|
|
65
|
-
const errors = /** @type {
|
|
65
|
+
const errors = /** @type {CompileError[]} */ ([]);
|
|
66
66
|
const comments = /** @type {AST.CommentWithLocation[]} */ ([]);
|
|
67
67
|
const ast = parseModule(source, filename, {
|
|
68
68
|
...options,
|
|
@@ -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(): ReactNode;
|
|
15
15
|
}
|