@tsrx/vue 0.4.2 → 0.4.3
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 +7 -3
- package/src/runtime/iterable.js +1 -0
- package/src/transform.js +30 -3
- package/types/runtime/iterable.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.4.
|
|
6
|
+
"version": "0.4.3",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"publishConfig": {
|
|
9
9
|
"access": "public"
|
|
@@ -32,14 +32,18 @@
|
|
|
32
32
|
"./ref": {
|
|
33
33
|
"types": "./types/ref.d.ts",
|
|
34
34
|
"default": "./src/ref.js"
|
|
35
|
+
},
|
|
36
|
+
"./runtime/iterable": {
|
|
37
|
+
"types": "./types/runtime/iterable.d.ts",
|
|
38
|
+
"default": "./src/runtime/iterable.js"
|
|
35
39
|
}
|
|
36
40
|
},
|
|
37
41
|
"dependencies": {
|
|
38
42
|
"esrap": "^2.4.0",
|
|
39
43
|
"is-reference": "^3.0.3",
|
|
40
44
|
"zimmerframe": "^1.1.2",
|
|
41
|
-
"@tsrx/core": "0.6.
|
|
42
|
-
"@tsrx/vue-runtime": "0.2.
|
|
45
|
+
"@tsrx/core": "0.6.3",
|
|
46
|
+
"@tsrx/vue-runtime": "0.2.2"
|
|
43
47
|
},
|
|
44
48
|
"peerDependencies": {
|
|
45
49
|
"vue": ">=3.6.0-0",
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@tsrx/vue-runtime/iterable';
|
package/src/transform.js
CHANGED
|
@@ -23,6 +23,8 @@ import {
|
|
|
23
23
|
insertAfterDirectives,
|
|
24
24
|
is_component_like_element,
|
|
25
25
|
JOIN_SCOPE_CLASS_INTERNAL_NAME,
|
|
26
|
+
MAP_ITERABLE_ASYNC_INTERNAL_NAME,
|
|
27
|
+
MAP_ITERABLE_INTERNAL_NAME,
|
|
26
28
|
MERGE_REFS_INTERNAL_NAME,
|
|
27
29
|
NORMALIZE_SPREAD_PROPS_FOR_REF_ATTR_INTERNAL_NAME,
|
|
28
30
|
NORMALIZE_SPREAD_PROPS_INTERNAL_NAME,
|
|
@@ -75,11 +77,13 @@ const vue_platform = {
|
|
|
75
77
|
errorBoundary: '@tsrx/vue/error-boundary',
|
|
76
78
|
mergeRefs: '@tsrx/vue/ref',
|
|
77
79
|
refProp: '@tsrx/vue/ref',
|
|
80
|
+
forOfIterableHelper: '@tsrx/vue/runtime/iterable',
|
|
78
81
|
},
|
|
79
82
|
directRuntimeImports: {
|
|
80
83
|
errorBoundary: '@tsrx/vue-runtime/error-boundary',
|
|
81
84
|
mergeRefs: '@tsrx/vue-runtime/ref',
|
|
82
85
|
refProp: '@tsrx/vue-runtime/ref',
|
|
86
|
+
forOfIterableHelper: '@tsrx/vue-runtime/iterable',
|
|
83
87
|
},
|
|
84
88
|
jsx: {
|
|
85
89
|
rewriteClassAttr: false,
|
|
@@ -1804,7 +1808,7 @@ function render_for_of_as_vapor_for(node, loop_params, body_statements, transfor
|
|
|
1804
1808
|
|
|
1805
1809
|
const rendered = statement.argument;
|
|
1806
1810
|
if (expression_can_skip_rendering(rendered)) {
|
|
1807
|
-
return
|
|
1811
|
+
return render_for_of_as_map_iterable(node, loop_params, rendered, transform_context);
|
|
1808
1812
|
}
|
|
1809
1813
|
|
|
1810
1814
|
const key_expression = node.key
|
|
@@ -1857,12 +1861,17 @@ function render_for_of_as_vapor_for(node, loop_params, body_statements, transfor
|
|
|
1857
1861
|
* @param {AST.ForOfStatement} node
|
|
1858
1862
|
* @param {AST.Pattern[]} loop_params
|
|
1859
1863
|
* @param {AST.Expression} rendered
|
|
1864
|
+
* @param {TransformContext} transform_context
|
|
1860
1865
|
* @returns {ESTreeJSX.JSXExpressionContainer}
|
|
1861
1866
|
*/
|
|
1862
|
-
function
|
|
1867
|
+
function render_for_of_as_map_iterable(node, loop_params, rendered, transform_context) {
|
|
1868
|
+
// `map_iterable` flattens a returned array the way `flatMap` does, and it
|
|
1869
|
+
// takes any iterable, so a `Set`, `Map` or generator source works too.
|
|
1870
|
+
transform_context.needs_for_of_iterable = true;
|
|
1863
1871
|
return to_jsx_expression_container(
|
|
1864
1872
|
b.call(
|
|
1865
|
-
b.
|
|
1873
|
+
b.id(MAP_ITERABLE_INTERNAL_NAME),
|
|
1874
|
+
clone_ast_node(node.right),
|
|
1866
1875
|
b.arrow(loop_params, b.block([b.return(to_array_render_expression(rendered))])),
|
|
1867
1876
|
),
|
|
1868
1877
|
);
|
|
@@ -2932,6 +2941,24 @@ function inject_vue_imports(program, transform_context) {
|
|
|
2932
2941
|
ensure_named_import(program, 'vue-jsx-vapor', DEFINE_VAPOR_COMPONENT);
|
|
2933
2942
|
}
|
|
2934
2943
|
|
|
2944
|
+
const iterable_source = transform_context.platform.imports.forOfIterableHelper;
|
|
2945
|
+
if (iterable_source) {
|
|
2946
|
+
if (transform_context.needs_for_of_iterable) {
|
|
2947
|
+
ensure_named_import(program, iterable_source, 'map_iterable', MAP_ITERABLE_INTERNAL_NAME);
|
|
2948
|
+
}
|
|
2949
|
+
// A `@for` body that awaits is `await map_iterable_async(...)`. The
|
|
2950
|
+
// shared pass sets this on its own, including for a plain async
|
|
2951
|
+
// function, which Vue still compiles.
|
|
2952
|
+
if (transform_context.needs_for_of_iterable_async) {
|
|
2953
|
+
ensure_named_import(
|
|
2954
|
+
program,
|
|
2955
|
+
iterable_source,
|
|
2956
|
+
'map_iterable_async',
|
|
2957
|
+
MAP_ITERABLE_ASYNC_INTERNAL_NAME,
|
|
2958
|
+
);
|
|
2959
|
+
}
|
|
2960
|
+
}
|
|
2961
|
+
|
|
2935
2962
|
if (transform_context.needs_vapor_for) {
|
|
2936
2963
|
ensure_named_import(program, 'vue-jsx-vapor', 'VaporFor', VAPOR_FOR_INTERNAL_NAME);
|
|
2937
2964
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@tsrx/vue-runtime/iterable';
|