@tsrx/preact 0.0.13 → 0.0.15

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": "Preact compiler built on @tsrx/core",
4
4
  "license": "MIT",
5
5
  "author": "Dominic Gannaway",
6
- "version": "0.0.13",
6
+ "version": "0.0.15",
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
  "preact": ">=10"
package/src/index.js CHANGED
@@ -24,14 +24,26 @@ export function parse(source, filename, options) {
24
24
  *
25
25
  * @param {string} source
26
26
  * @param {string} [filename]
27
- * @param {CompileOptions & { loose?: boolean }} [compile_options]
27
+ * @param {CompileOptions & { collect?: boolean, loose?: boolean }} [compile_options]
28
28
  * @returns {{ code: string, map: any, css: { code: string, hash: string } | null, errors: CompileError[] }}
29
29
  */
30
30
  export function compile(source, filename, compile_options) {
31
31
  const errors = /** @type {CompileError[]} */ ([]);
32
- const collect = !!compile_options?.loose;
33
- const ast = parseModule(source, filename, collect ? { loose: true, errors } : undefined);
34
- const { ast: _ast, ...result } = transform(ast, source, filename, compile_options);
32
+ const comments = /** @type {AST.CommentWithLocation[]} */ ([]);
33
+ const collect = !!(compile_options?.collect || compile_options?.loose);
34
+ const ast = parseModule(
35
+ source,
36
+ filename,
37
+ collect ? { collect: true, loose: !!compile_options?.loose, errors, comments } : undefined,
38
+ );
39
+ const { ast: _ast, ...result } = transform(
40
+ ast,
41
+ source,
42
+ filename,
43
+ collect
44
+ ? { ...compile_options, collect: true, loose: !!compile_options?.loose, errors, comments }
45
+ : compile_options,
46
+ );
35
47
  return { ...result, errors };
36
48
  }
37
49
 
@@ -45,8 +57,21 @@ export function compile(source, filename, compile_options) {
45
57
  */
46
58
  export function compile_to_volar_mappings(source, filename, options) {
47
59
  const errors = /** @type {import('@tsrx/core/types').CompileError[]} */ ([]);
48
- const ast = parseModule(source, filename, { ...options, errors });
49
- const transformed = transform(ast, source, filename, options);
60
+ const comments = /** @type {AST.CommentWithLocation[]} */ ([]);
61
+ const ast = parseModule(source, filename, {
62
+ ...options,
63
+ collect: true,
64
+ loose: !!options?.loose,
65
+ errors,
66
+ comments,
67
+ });
68
+ const transformed = transform(ast, source, filename, {
69
+ ...options,
70
+ collect: true,
71
+ loose: !!options?.loose,
72
+ errors,
73
+ comments,
74
+ });
50
75
  const result = createVolarMappingsResult({
51
76
  ast: transformed.ast,
52
77
  ast_from_source: ast,
@@ -0,0 +1,15 @@
1
+ import { Component, type ComponentChildren, type VNode } from 'preact';
2
+
3
+ export interface TsrxErrorBoundaryProps {
4
+ fallback: (error: Error, reset: () => void) => ComponentChildren;
5
+ children?: ComponentChildren;
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(): ComponentChildren | VNode;
15
+ }
package/types/index.d.ts CHANGED
@@ -12,7 +12,7 @@ export function parse(source: string, filename?: string, options?: ParseOptions)
12
12
  export function compile(
13
13
  source: string,
14
14
  filename?: string,
15
- compile_options?: CompileOptions & { loose?: boolean },
15
+ compile_options?: CompileOptions & { collect?: boolean; loose?: boolean },
16
16
  ): {
17
17
  code: string;
18
18
  map: unknown;
@@ -0,0 +1 @@
1
+ export { mergeRefs } from '@tsrx/core/runtime/merge-refs';