@tsrx/vue 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 +4 -2
- package/src/index.js +28 -6
- package/src/transform.js +33 -12
- package/types/error-boundary.d.ts +11 -0
- package/types/index.d.ts +1 -1
- package/types/merge-refs.d.ts +1 -0
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"description": "Vue compiler built on @tsrx/core",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Dominic Gannaway",
|
|
6
|
-
"version": "0.0.
|
|
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.
|
|
33
|
+
"@tsrx/core": "0.0.20"
|
|
32
34
|
},
|
|
33
35
|
"peerDependencies": {
|
|
34
36
|
"vue": ">=3.5",
|
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
|
|
30
|
-
const
|
|
31
|
-
const
|
|
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
|
|
46
|
-
const
|
|
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,
|
package/src/transform.js
CHANGED
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
clone_identifier,
|
|
7
7
|
componentToFunctionDeclaration,
|
|
8
8
|
createJsxTransform,
|
|
9
|
-
|
|
9
|
+
error,
|
|
10
10
|
identifier_to_jsx_name,
|
|
11
11
|
setLocation,
|
|
12
12
|
} from '@tsrx/core';
|
|
@@ -68,13 +68,22 @@ const vue_platform = {
|
|
|
68
68
|
metadata: { path: [] },
|
|
69
69
|
};
|
|
70
70
|
},
|
|
71
|
-
transformElementChildren(node, walked_children, raw_children, attributes) {
|
|
72
|
-
return rewrite_host_text_or_html_children(
|
|
71
|
+
transformElementChildren(node, walked_children, raw_children, attributes, ctx) {
|
|
72
|
+
return rewrite_host_text_or_html_children(
|
|
73
|
+
node,
|
|
74
|
+
walked_children,
|
|
75
|
+
raw_children,
|
|
76
|
+
attributes,
|
|
77
|
+
ctx,
|
|
78
|
+
);
|
|
73
79
|
},
|
|
74
|
-
validateComponentAwait(await_expression) {
|
|
75
|
-
|
|
76
|
-
await_expression,
|
|
80
|
+
validateComponentAwait(await_expression, _component, ctx) {
|
|
81
|
+
error(
|
|
77
82
|
'`await` is not yet supported in Vue TSRX components.',
|
|
83
|
+
ctx?.filename ?? null,
|
|
84
|
+
await_expression,
|
|
85
|
+
ctx?.errors,
|
|
86
|
+
ctx?.comments,
|
|
78
87
|
);
|
|
79
88
|
},
|
|
80
89
|
componentToFunction(component, ctx, helper_state) {
|
|
@@ -418,15 +427,17 @@ function is_vue_setup_call(call_expression) {
|
|
|
418
427
|
* @returns {any[]}
|
|
419
428
|
*/
|
|
420
429
|
function preprocess_ref_attributes(attrs, element, transform_context) {
|
|
421
|
-
void transform_context;
|
|
422
430
|
if (!is_component_like_element(element)) {
|
|
423
431
|
return attrs;
|
|
424
432
|
}
|
|
425
433
|
for (const attr of attrs) {
|
|
426
434
|
if (attr?.type === 'RefAttribute') {
|
|
427
|
-
|
|
428
|
-
attr,
|
|
435
|
+
error(
|
|
429
436
|
'`{ref ...}` on the Vue target is only supported on host elements. Vue component refs resolve to component instances rather than the rendered DOM node, so Ripple-style component refs are not supported here.',
|
|
437
|
+
transform_context?.filename ?? null,
|
|
438
|
+
attr,
|
|
439
|
+
transform_context?.errors,
|
|
440
|
+
transform_context?.comments,
|
|
430
441
|
);
|
|
431
442
|
}
|
|
432
443
|
}
|
|
@@ -438,9 +449,16 @@ function preprocess_ref_attributes(attrs, element, transform_context) {
|
|
|
438
449
|
* @param {any[]} walked_children
|
|
439
450
|
* @param {any[]} raw_children
|
|
440
451
|
* @param {any[]} attributes
|
|
452
|
+
* @param {any} [transform_context]
|
|
441
453
|
* @returns {{ children: any[]; selfClosing?: boolean } | null}
|
|
442
454
|
*/
|
|
443
|
-
function rewrite_host_text_or_html_children(
|
|
455
|
+
function rewrite_host_text_or_html_children(
|
|
456
|
+
node,
|
|
457
|
+
walked_children,
|
|
458
|
+
raw_children,
|
|
459
|
+
attributes,
|
|
460
|
+
transform_context,
|
|
461
|
+
) {
|
|
444
462
|
const source_children = raw_children || walked_children;
|
|
445
463
|
const is_composite = is_component_like_element(node);
|
|
446
464
|
const html_children = source_children.filter((child) => child?.type === 'Html');
|
|
@@ -452,9 +470,12 @@ function rewrite_host_text_or_html_children(node, walked_children, raw_children,
|
|
|
452
470
|
has_dom_content_attribute(attributes, 'innerHTML') ||
|
|
453
471
|
has_dom_content_attribute(attributes, 'textContent')
|
|
454
472
|
) {
|
|
455
|
-
|
|
456
|
-
html_children[0],
|
|
473
|
+
error(
|
|
457
474
|
'`{html ...}` on the Vue target is only supported as the sole child of a host element. Use `innerHTML={...}` as an element attribute when you need the explicit prop form.',
|
|
475
|
+
transform_context?.filename ?? null,
|
|
476
|
+
html_children[0],
|
|
477
|
+
transform_context?.errors,
|
|
478
|
+
transform_context?.comments,
|
|
458
479
|
);
|
|
459
480
|
}
|
|
460
481
|
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export interface TsrxErrorBoundaryProps {
|
|
2
|
+
content: () => any;
|
|
3
|
+
fallback: (error: unknown, reset: () => void) => any;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export interface TsrxErrorBoundaryComponent {
|
|
7
|
+
(props: TsrxErrorBoundaryProps): any;
|
|
8
|
+
__setup(): void;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export const TsrxErrorBoundary: TsrxErrorBoundaryComponent;
|
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';
|