@tsrx/react 0.1.12 → 0.1.14

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 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.1.12",
6
+ "version": "0.1.14",
7
7
  "type": "module",
8
8
  "publishConfig": {
9
9
  "access": "public"
@@ -19,16 +19,18 @@
19
19
  "default": "./src/index.js"
20
20
  },
21
21
  "./error-boundary": {
22
+ "types": "./types/error-boundary.d.ts",
22
23
  "default": "./src/error-boundary.js"
23
24
  },
24
25
  "./merge-refs": {
26
+ "types": "./types/merge-refs.d.ts",
25
27
  "default": "./src/merge-refs.js"
26
28
  }
27
29
  },
28
30
  "dependencies": {
29
31
  "esrap": "^2.1.0",
30
32
  "zimmerframe": "^1.1.2",
31
- "@tsrx/core": "0.0.18"
33
+ "@tsrx/core": "0.0.20"
32
34
  },
33
35
  "peerDependencies": {
34
36
  "react": ">=18"
package/src/index.js CHANGED
@@ -21,14 +21,24 @@ export function parse(source, filename, options) {
21
21
  *
22
22
  * @param {string} source
23
23
  * @param {string} [filename]
24
- * @param {{ loose?: boolean }} [options]
24
+ * @param {{ collect?: boolean, loose?: boolean }} [options]
25
25
  * @returns {{ code: string, map: any, css: { code: string, hash: string } | null, errors: CompileError[] }}
26
26
  */
27
27
  export function compile(source, filename, options) {
28
28
  const errors = /** @type {CompileError[]} */ ([]);
29
- const collect = !!options?.loose;
30
- const ast = parseModule(source, filename, collect ? { loose: true, errors } : undefined);
31
- const { ast: _ast, ...result } = transform(ast, source, filename);
29
+ const comments = /** @type {AST.CommentWithLocation[]} */ ([]);
30
+ const collect = !!(options?.collect || options?.loose);
31
+ const ast = parseModule(
32
+ source,
33
+ filename,
34
+ collect ? { collect: true, loose: !!options?.loose, errors, comments } : undefined,
35
+ );
36
+ const { ast: _ast, ...result } = transform(
37
+ ast,
38
+ source,
39
+ filename,
40
+ collect ? { collect: true, loose: !!options?.loose, errors, comments } : undefined,
41
+ );
32
42
  return { ...result, errors };
33
43
  }
34
44
 
@@ -42,8 +52,20 @@ export function compile(source, filename, options) {
42
52
  */
43
53
  export function compile_to_volar_mappings(source, filename, options) {
44
54
  const errors = /** @type {import('@tsrx/core/types').CompileError[]} */ ([]);
45
- const ast = parseModule(source, filename, { ...options, errors });
46
- const transformed = transform(ast, source, filename);
55
+ const comments = /** @type {AST.CommentWithLocation[]} */ ([]);
56
+ const ast = parseModule(source, filename, {
57
+ ...options,
58
+ collect: true,
59
+ loose: !!options?.loose,
60
+ errors,
61
+ comments,
62
+ });
63
+ const transformed = transform(ast, source, filename, {
64
+ collect: true,
65
+ loose: !!options?.loose,
66
+ errors,
67
+ comments,
68
+ });
47
69
  const result = createVolarMappingsResult({
48
70
  ast: transformed.ast,
49
71
  ast_from_source: ast,
@@ -0,0 +1,15 @@
1
+ import { Component, type ReactNode } from 'react';
2
+
3
+ export interface TsrxErrorBoundaryProps {
4
+ fallback: (error: Error, reset: () => void) => ReactNode;
5
+ children?: ReactNode;
6
+ }
7
+
8
+ export interface TsrxErrorBoundaryState {
9
+ error: Error | null;
10
+ }
11
+
12
+ export class TsrxErrorBoundary extends Component<TsrxErrorBoundaryProps, TsrxErrorBoundaryState> {
13
+ static getDerivedStateFromError(error: Error): { error: Error };
14
+ render(): ReactNode;
15
+ }
package/types/index.d.ts CHANGED
@@ -6,7 +6,7 @@ export function parse(source: string, filename?: string, options?: ParseOptions)
6
6
  export function compile(
7
7
  source: string,
8
8
  filename?: string,
9
- options?: { loose?: boolean },
9
+ options?: { collect?: boolean; loose?: boolean },
10
10
  ): {
11
11
  code: string;
12
12
  map: unknown;
@@ -0,0 +1 @@
1
+ export { mergeRefs } from '@tsrx/core/runtime/merge-refs';