ripple 0.3.7 → 0.3.9
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/CHANGELOG.md +14 -0
- package/package.json +2 -2
- package/src/compiler/phases/1-parse/index.js +48 -349
- package/src/compiler/phases/2-analyze/index.js +343 -52
- package/src/compiler/phases/3-transform/client/index.js +28 -160
- package/src/compiler/phases/3-transform/segments.js +0 -7
- package/src/compiler/phases/3-transform/server/index.js +31 -154
- package/src/compiler/types/acorn.d.ts +1 -1
- package/src/compiler/types/estree.d.ts +1 -1
- package/src/compiler/types/import.d.ts +0 -2
- package/src/compiler/types/index.d.ts +5 -17
- package/src/compiler/types/parse.d.ts +1 -17
- package/src/compiler/utils.js +53 -20
- package/src/runtime/index-client.js +2 -13
- package/src/runtime/index-server.js +2 -2
- package/src/runtime/internal/client/bindings.js +3 -1
- package/src/runtime/internal/client/composite.js +3 -2
- package/src/runtime/internal/client/events.js +1 -1
- package/src/runtime/internal/client/head.js +3 -4
- package/src/runtime/internal/client/index.js +0 -1
- package/src/runtime/internal/client/runtime.js +0 -52
- package/src/runtime/internal/server/index.js +31 -55
- package/tests/client/array/array.copy-within.test.ripple +12 -12
- package/tests/client/array/array.derived.test.ripple +46 -46
- package/tests/client/array/array.iteration.test.ripple +10 -10
- package/tests/client/array/array.mutations.test.ripple +20 -20
- package/tests/client/array/array.to-methods.test.ripple +6 -6
- package/tests/client/async-suspend.test.ripple +5 -5
- package/tests/client/basic/basic.attributes.test.ripple +81 -81
- package/tests/client/basic/basic.collections.test.ripple +9 -9
- package/tests/client/basic/basic.components.test.ripple +28 -28
- package/tests/client/basic/basic.errors.test.ripple +46 -18
- package/tests/client/basic/basic.events.test.ripple +37 -37
- package/tests/client/basic/basic.get-set.test.ripple +6 -6
- package/tests/client/basic/basic.reactivity.test.ripple +58 -203
- package/tests/client/basic/basic.rendering.test.ripple +19 -19
- package/tests/client/basic/basic.utilities.test.ripple +3 -3
- package/tests/client/boundaries.test.ripple +12 -12
- package/tests/client/compiler/__snapshots__/compiler.assignments.test.ripple.snap +5 -5
- package/tests/client/compiler/compiler.assignments.test.ripple +19 -19
- package/tests/client/compiler/compiler.basic.test.ripple +46 -27
- package/tests/client/compiler/compiler.tracked-access.test.ripple +2 -2
- package/tests/client/composite/composite.dynamic-components.test.ripple +9 -9
- package/tests/client/composite/composite.props.test.ripple +14 -16
- package/tests/client/composite/composite.reactivity.test.ripple +69 -70
- package/tests/client/composite/composite.render.test.ripple +3 -3
- package/tests/client/computed-properties.test.ripple +4 -4
- package/tests/client/date.test.ripple +42 -42
- package/tests/client/dynamic-elements.test.ripple +44 -45
- package/tests/client/events.test.ripple +70 -70
- package/tests/client/for.test.ripple +25 -25
- package/tests/client/head.test.ripple +19 -19
- package/tests/client/html.test.ripple +3 -3
- package/tests/client/input-value.test.ripple +84 -84
- package/tests/client/lazy-destructuring.test.ripple +138 -26
- package/tests/client/map.test.ripple +16 -16
- package/tests/client/media-query.test.ripple +7 -7
- package/tests/client/portal.test.ripple +11 -11
- package/tests/client/ref.test.ripple +4 -4
- package/tests/client/return.test.ripple +52 -52
- package/tests/client/set.test.ripple +6 -6
- package/tests/client/svg.test.ripple +5 -5
- package/tests/client/switch.test.ripple +44 -44
- package/tests/client/try.test.ripple +5 -5
- package/tests/client/url/url.derived.test.ripple +6 -6
- package/tests/client/url-search-params/url-search-params.derived.test.ripple +8 -8
- package/tests/client/url-search-params/url-search-params.iteration.test.ripple +10 -10
- package/tests/client/url-search-params/url-search-params.mutation.test.ripple +10 -10
- package/tests/client/url-search-params/url-search-params.retrieval.test.ripple +18 -18
- package/tests/client/url-search-params/url-search-params.serialization.test.ripple +2 -2
- package/tests/hydration/compiled/client/events.js +25 -25
- package/tests/hydration/compiled/client/for.js +70 -66
- package/tests/hydration/compiled/client/head.js +25 -25
- package/tests/hydration/compiled/client/hmr.js +2 -2
- package/tests/hydration/compiled/client/html.js +3 -3
- package/tests/hydration/compiled/client/if-children.js +24 -24
- package/tests/hydration/compiled/client/if.js +18 -18
- package/tests/hydration/compiled/client/mixed-control-flow.js +9 -9
- package/tests/hydration/compiled/client/portal.js +3 -3
- package/tests/hydration/compiled/client/reactivity.js +16 -16
- package/tests/hydration/compiled/client/return.js +40 -40
- package/tests/hydration/compiled/client/switch.js +12 -12
- package/tests/hydration/compiled/server/events.js +19 -19
- package/tests/hydration/compiled/server/for.js +41 -41
- package/tests/hydration/compiled/server/head.js +26 -26
- package/tests/hydration/compiled/server/hmr.js +2 -2
- package/tests/hydration/compiled/server/html.js +2 -2
- package/tests/hydration/compiled/server/if-children.js +16 -16
- package/tests/hydration/compiled/server/if.js +11 -11
- package/tests/hydration/compiled/server/mixed-control-flow.js +6 -6
- package/tests/hydration/compiled/server/portal.js +2 -2
- package/tests/hydration/compiled/server/reactivity.js +16 -16
- package/tests/hydration/compiled/server/return.js +25 -25
- package/tests/hydration/compiled/server/switch.js +8 -8
- package/tests/hydration/components/events.ripple +25 -25
- package/tests/hydration/components/for.ripple +66 -66
- package/tests/hydration/components/head.ripple +16 -16
- package/tests/hydration/components/hmr.ripple +2 -2
- package/tests/hydration/components/html.ripple +3 -3
- package/tests/hydration/components/if-children.ripple +24 -24
- package/tests/hydration/components/if.ripple +18 -18
- package/tests/hydration/components/mixed-control-flow.ripple +9 -9
- package/tests/hydration/components/portal.ripple +3 -3
- package/tests/hydration/components/reactivity.ripple +16 -16
- package/tests/hydration/components/return.ripple +40 -40
- package/tests/hydration/components/switch.ripple +20 -20
- package/tests/server/await.test.ripple +3 -3
- package/tests/server/basic.attributes.test.ripple +34 -34
- package/tests/server/basic.components.test.ripple +10 -10
- package/tests/server/basic.test.ripple +38 -40
- package/tests/server/compiler.test.ripple +22 -0
- package/tests/server/composite.props.test.ripple +12 -14
- package/tests/server/dynamic-elements.test.ripple +15 -15
- package/tests/server/head.test.ripple +11 -11
- package/tests/server/lazy-destructuring.test.ripple +92 -13
- package/tsconfig.typecheck.json +4 -0
- package/types/index.d.ts +0 -19
- package/tests/client/__snapshots__/tracked-expression.test.ripple.snap +0 -34
- package/tests/client/tracked-expression.test.ripple +0 -26
|
@@ -58,6 +58,7 @@ import {
|
|
|
58
58
|
flatten_switch_consequent,
|
|
59
59
|
get_ripple_namespace_call_name,
|
|
60
60
|
is_ripple_import,
|
|
61
|
+
replace_lazy_param_pattern,
|
|
61
62
|
ripple_import_requires_block,
|
|
62
63
|
} from '../../../utils.js';
|
|
63
64
|
import {
|
|
@@ -111,16 +112,12 @@ function visit_function(node, context) {
|
|
|
111
112
|
// Replace lazy destructuring params with generated identifiers
|
|
112
113
|
const transformed_params = node.params.map((param) => {
|
|
113
114
|
const pattern = param.type === 'AssignmentPattern' ? param.left : param;
|
|
114
|
-
if (
|
|
115
|
-
|
|
116
|
-
pattern.lazy &&
|
|
117
|
-
pattern.metadata?.lazy_id
|
|
118
|
-
) {
|
|
119
|
-
const id = b.id(pattern.metadata.lazy_id);
|
|
115
|
+
if (pattern.type === 'ObjectPattern' || pattern.type === 'ArrayPattern') {
|
|
116
|
+
const transformed_pattern = replace_lazy_param_pattern(pattern);
|
|
120
117
|
if (param.type === 'AssignmentPattern') {
|
|
121
|
-
return /** @type {AST.AssignmentPattern} */ ({ ...param, left:
|
|
118
|
+
return /** @type {AST.AssignmentPattern} */ ({ ...param, left: transformed_pattern });
|
|
122
119
|
}
|
|
123
|
-
return
|
|
120
|
+
return transformed_pattern;
|
|
124
121
|
}
|
|
125
122
|
return param;
|
|
126
123
|
});
|
|
@@ -533,9 +530,6 @@ const visitors = {
|
|
|
533
530
|
if (context.state.metadata?.tracking === false) {
|
|
534
531
|
context.state.metadata.tracking = true;
|
|
535
532
|
}
|
|
536
|
-
if (node.tracked && !binding?.read_unwraps) {
|
|
537
|
-
return b.call('_$_.get', build_getter(node, context));
|
|
538
|
-
}
|
|
539
533
|
}
|
|
540
534
|
return build_getter(node, context);
|
|
541
535
|
}
|
|
@@ -636,7 +630,7 @@ const visitors = {
|
|
|
636
630
|
|
|
637
631
|
const matched_track_call = !context.state.to_ts ? is_ripple_track_call(callee, context) : null;
|
|
638
632
|
if (matched_track_call) {
|
|
639
|
-
const track_method_name =
|
|
633
|
+
const track_method_name = 'track';
|
|
640
634
|
|
|
641
635
|
if (callee.type === 'Identifier' && callee.name === 'track') {
|
|
642
636
|
if (node.arguments.length === 0) {
|
|
@@ -806,71 +800,11 @@ const visitors = {
|
|
|
806
800
|
return b.call('_$_.with_scope', b.id('__block'), b.thunk(new_node));
|
|
807
801
|
},
|
|
808
802
|
|
|
809
|
-
TrackedExpression(node, context) {
|
|
810
|
-
if (context.state.to_ts) {
|
|
811
|
-
const visited = /** @type {AST.Expression} */ (context.visit(node.argument));
|
|
812
|
-
const member = b.member(
|
|
813
|
-
visited,
|
|
814
|
-
b.literal('#v'),
|
|
815
|
-
true,
|
|
816
|
-
!is_inside_left_side_assignment(node),
|
|
817
|
-
/** @type {AST.NodeWithLocation} */ (node),
|
|
818
|
-
);
|
|
819
|
-
member.tracked = true;
|
|
820
|
-
return member;
|
|
821
|
-
}
|
|
822
|
-
return b.call('_$_.get', /** @type {AST.Expression} */ (context.visit(node.argument)));
|
|
823
|
-
},
|
|
824
|
-
|
|
825
803
|
MemberExpression(node, context) {
|
|
826
804
|
if (context.state.metadata?.tracking === false) {
|
|
827
805
|
context.state.metadata.tracking = true;
|
|
828
806
|
}
|
|
829
807
|
|
|
830
|
-
if (
|
|
831
|
-
node.tracked ||
|
|
832
|
-
((node.property.type === 'Identifier' || node.property.type === 'Literal') &&
|
|
833
|
-
node.property.tracked)
|
|
834
|
-
) {
|
|
835
|
-
if (context.state.to_ts) {
|
|
836
|
-
// In TypeScript mode, transform @user.@name or @user.@['name'] or @user?.@name
|
|
837
|
-
// to user['#v'].name['#v'] or user['#v']['name']['#v'] or user['#v']?.name['#v']
|
|
838
|
-
const visited_object = /** @type {AST.Expression} */ (context.visit(node.object));
|
|
839
|
-
const visited_property = /** @type {AST.Expression} */ (context.visit(node.property));
|
|
840
|
-
|
|
841
|
-
// Build the member access: object.property or object[property]
|
|
842
|
-
const member = b.member(
|
|
843
|
-
visited_object,
|
|
844
|
-
visited_property,
|
|
845
|
-
node.computed,
|
|
846
|
-
node.optional,
|
|
847
|
-
/** @type {AST.NodeWithLocation} */ (node),
|
|
848
|
-
);
|
|
849
|
-
|
|
850
|
-
// Wrap with ['#v'] access
|
|
851
|
-
const member_expanded = b.member(
|
|
852
|
-
member,
|
|
853
|
-
b.literal('#v'),
|
|
854
|
-
true,
|
|
855
|
-
!is_inside_left_side_assignment(node),
|
|
856
|
-
/** @type {AST.NodeWithLocation} */ (node),
|
|
857
|
-
);
|
|
858
|
-
member_expanded.tracked = true;
|
|
859
|
-
return member_expanded;
|
|
860
|
-
} else {
|
|
861
|
-
if (!context.state.to_ts) {
|
|
862
|
-
return b.call(
|
|
863
|
-
'_$_.get_property',
|
|
864
|
-
/** @type {AST.Expression} */ (context.visit(node.object)),
|
|
865
|
-
node.computed
|
|
866
|
-
? /** @type {AST.Expression} */ (context.visit(node.property))
|
|
867
|
-
: b.literal(/** @type {AST.Identifier} */ (node.property).name),
|
|
868
|
-
node.optional ? b.true : undefined,
|
|
869
|
-
);
|
|
870
|
-
}
|
|
871
|
-
}
|
|
872
|
-
}
|
|
873
|
-
|
|
874
808
|
if (node.object.type === 'MemberExpression' && node.object.optional) {
|
|
875
809
|
const metadata = { tracking: false, await: false };
|
|
876
810
|
|
|
@@ -919,6 +853,25 @@ const visitors = {
|
|
|
919
853
|
return context.next();
|
|
920
854
|
},
|
|
921
855
|
|
|
856
|
+
ExpressionStatement(node, context) {
|
|
857
|
+
// Handle standalone lazy destructuring: &[data] = track(0); → const lazy0 = track(0);
|
|
858
|
+
if (
|
|
859
|
+
node.expression.type === 'AssignmentExpression' &&
|
|
860
|
+
node.expression.left.lazy &&
|
|
861
|
+
node.expression.left.metadata?.lazy_id
|
|
862
|
+
) {
|
|
863
|
+
if (context.state.to_ts) {
|
|
864
|
+
// In TypeScript mode, convert to a regular assignment (drop the pattern)
|
|
865
|
+
node.expression.left.lazy = false;
|
|
866
|
+
delete node.expression.left.metadata.lazy_id;
|
|
867
|
+
return context.next();
|
|
868
|
+
}
|
|
869
|
+
const right = /** @type {AST.Expression} */ (context.visit(node.expression.right));
|
|
870
|
+
return b.const(b.id(node.expression.left.metadata.lazy_id), right);
|
|
871
|
+
}
|
|
872
|
+
return context.next();
|
|
873
|
+
},
|
|
874
|
+
|
|
922
875
|
VariableDeclaration(node, context) {
|
|
923
876
|
for (const declarator of node.declarations) {
|
|
924
877
|
if (!context.state.to_ts) {
|
|
@@ -1970,7 +1923,9 @@ const visitors = {
|
|
|
1970
1923
|
delete props_param.typeAnnotation;
|
|
1971
1924
|
if (!props_param.lazy) {
|
|
1972
1925
|
// Non-lazy destructuring: use the pattern directly as the function param
|
|
1973
|
-
props =
|
|
1926
|
+
props = /** @type {AST.ObjectPattern | AST.ArrayPattern} */ (
|
|
1927
|
+
replace_lazy_param_pattern(props_param)
|
|
1928
|
+
);
|
|
1974
1929
|
}
|
|
1975
1930
|
// Lazy destructuring: props stays as __props, bindings resolved via transforms
|
|
1976
1931
|
}
|
|
@@ -2043,56 +1998,6 @@ const visitors = {
|
|
|
2043
1998
|
}
|
|
2044
1999
|
}
|
|
2045
2000
|
|
|
2046
|
-
if (
|
|
2047
|
-
left.type === 'MemberExpression' &&
|
|
2048
|
-
(left.tracked || (left.property.type === 'Identifier' && left.property.tracked))
|
|
2049
|
-
) {
|
|
2050
|
-
const operator = node.operator;
|
|
2051
|
-
const right = node.right;
|
|
2052
|
-
|
|
2053
|
-
if (operator !== '=' && context.state.metadata?.tracking === false) {
|
|
2054
|
-
context.state.metadata.tracking = true;
|
|
2055
|
-
}
|
|
2056
|
-
|
|
2057
|
-
return b.call(
|
|
2058
|
-
'_$_.set_property',
|
|
2059
|
-
/** @type {AST.Expression} */ (
|
|
2060
|
-
context.visit(left.object, { ...context.state, metadata: { tracking: false } })
|
|
2061
|
-
),
|
|
2062
|
-
left.computed
|
|
2063
|
-
? /** @type {AST.Expression} */ (context.visit(left.property))
|
|
2064
|
-
: b.literal(/** @type {AST.Identifier} */ (left.property).name),
|
|
2065
|
-
operator === '='
|
|
2066
|
-
? /** @type {AST.Expression} */ (context.visit(right))
|
|
2067
|
-
: b.binary(
|
|
2068
|
-
operator === '+=' ? '+' : operator === '-=' ? '-' : operator === '*=' ? '*' : '/',
|
|
2069
|
-
/** @type {AST.Expression} */ (context.visit(left)),
|
|
2070
|
-
/** @type {AST.Expression} */ (context.visit(right)),
|
|
2071
|
-
),
|
|
2072
|
-
);
|
|
2073
|
-
}
|
|
2074
|
-
|
|
2075
|
-
if (left.type === 'Identifier' && left.tracked) {
|
|
2076
|
-
const operator = node.operator;
|
|
2077
|
-
const right = node.right;
|
|
2078
|
-
|
|
2079
|
-
return b.call(
|
|
2080
|
-
'_$_.set',
|
|
2081
|
-
/** @type {AST.Expression} */ (
|
|
2082
|
-
context.visit(left, { ...context.state, metadata: { tracking: null } })
|
|
2083
|
-
),
|
|
2084
|
-
operator === '='
|
|
2085
|
-
? /** @type {AST.Expression} */ (context.visit(right))
|
|
2086
|
-
: b.binary(
|
|
2087
|
-
operator === '+=' ? '+' : operator === '-=' ? '-' : operator === '*=' ? '*' : '/',
|
|
2088
|
-
/** @type {AST.Expression} */ (
|
|
2089
|
-
context.visit(left, { ...context.state, metadata: { tracking: false } })
|
|
2090
|
-
),
|
|
2091
|
-
/** @type {AST.Expression} */ (context.visit(right)),
|
|
2092
|
-
),
|
|
2093
|
-
);
|
|
2094
|
-
}
|
|
2095
|
-
|
|
2096
2001
|
return visit_assignment_expression(node, context, build_assignment) ?? context.next();
|
|
2097
2002
|
},
|
|
2098
2003
|
|
|
@@ -2110,43 +2015,6 @@ const visitors = {
|
|
|
2110
2015
|
}
|
|
2111
2016
|
}
|
|
2112
2017
|
|
|
2113
|
-
if (
|
|
2114
|
-
argument.type === 'MemberExpression' &&
|
|
2115
|
-
(argument.tracked || (argument.property.type === 'Identifier' && argument.property.tracked))
|
|
2116
|
-
) {
|
|
2117
|
-
if (context.state.metadata?.tracking === false) {
|
|
2118
|
-
context.state.metadata.tracking = true;
|
|
2119
|
-
}
|
|
2120
|
-
|
|
2121
|
-
return b.call(
|
|
2122
|
-
node.prefix ? '_$_.update_pre_property' : '_$_.update_property',
|
|
2123
|
-
/** @type {AST.Expression} */
|
|
2124
|
-
(context.visit(argument.object, { ...context.state, metadata: { tracking: false } })),
|
|
2125
|
-
argument.computed
|
|
2126
|
-
? /** @type {AST.Expression} */ (context.visit(argument.property))
|
|
2127
|
-
: b.literal(/** @type {AST.Identifier} */ (argument.property).name),
|
|
2128
|
-
node.operator === '--' ? b.literal(-1) : undefined,
|
|
2129
|
-
);
|
|
2130
|
-
}
|
|
2131
|
-
|
|
2132
|
-
if (argument.type === 'Identifier' && argument.tracked) {
|
|
2133
|
-
return b.call(
|
|
2134
|
-
node.prefix ? '_$_.update_pre' : '_$_.update',
|
|
2135
|
-
/** @type {AST.Expression} */
|
|
2136
|
-
(context.visit(argument, { ...context.state, metadata: { tracking: null } })),
|
|
2137
|
-
node.operator === '--' ? b.literal(-1) : undefined,
|
|
2138
|
-
);
|
|
2139
|
-
}
|
|
2140
|
-
|
|
2141
|
-
if (argument.type === 'TrackedExpression') {
|
|
2142
|
-
return b.call(
|
|
2143
|
-
node.prefix ? '_$_.update_pre' : '_$_.update',
|
|
2144
|
-
/** @type {AST.Expression} */
|
|
2145
|
-
(context.visit(argument.argument, { ...context.state, metadata: { tracking: null } })),
|
|
2146
|
-
node.operator === '--' ? b.literal(-1) : undefined,
|
|
2147
|
-
);
|
|
2148
|
-
}
|
|
2149
|
-
|
|
2150
2018
|
const left = object(/** @type {AST.MemberExpression | AST.Identifier} */ (argument));
|
|
2151
2019
|
const binding = left && context.state.scope.get(left.name);
|
|
2152
2020
|
const transformers = left && binding?.transform;
|
|
@@ -1123,13 +1123,6 @@ export function convert_source_map_to_mappings(
|
|
|
1123
1123
|
mapping_data_verify_only,
|
|
1124
1124
|
);
|
|
1125
1125
|
|
|
1126
|
-
if (node.tracked) {
|
|
1127
|
-
mapping.generatedLengths[0] = mapping.generatedLengths[0] + "['#v']".length;
|
|
1128
|
-
if (node.optional) {
|
|
1129
|
-
mapping.generatedLengths[0] = mapping.generatedLengths[0] + '.?'.length;
|
|
1130
|
-
}
|
|
1131
|
-
}
|
|
1132
|
-
|
|
1133
1126
|
mappings.push(mapping);
|
|
1134
1127
|
}
|
|
1135
1128
|
|
|
@@ -27,7 +27,7 @@ import {
|
|
|
27
27
|
is_element_dynamic,
|
|
28
28
|
is_ripple_track_call,
|
|
29
29
|
is_ripple_import,
|
|
30
|
-
|
|
30
|
+
replace_lazy_param_pattern,
|
|
31
31
|
hash,
|
|
32
32
|
flatten_switch_consequent,
|
|
33
33
|
get_ripple_namespace_call_name,
|
|
@@ -333,29 +333,7 @@ const visitors = {
|
|
|
333
333
|
binding.node !== node &&
|
|
334
334
|
(binding.kind === 'lazy' || binding.kind === 'lazy_fallback')
|
|
335
335
|
) {
|
|
336
|
-
|
|
337
|
-
if (node.tracked && !binding.read_unwraps) {
|
|
338
|
-
const is_right_side_of_assignment =
|
|
339
|
-
parent.type === 'AssignmentExpression' && parent.right === node;
|
|
340
|
-
if (
|
|
341
|
-
(parent.type !== 'AssignmentExpression' && parent.type !== 'UpdateExpression') ||
|
|
342
|
-
is_right_side_of_assignment
|
|
343
|
-
) {
|
|
344
|
-
return b.call('_$_.get', transformed);
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
return transformed;
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
if (node.tracked) {
|
|
351
|
-
const is_right_side_of_assignment =
|
|
352
|
-
parent.type === 'AssignmentExpression' && parent.right === node;
|
|
353
|
-
if (
|
|
354
|
-
(parent.type !== 'AssignmentExpression' && parent.type !== 'UpdateExpression') ||
|
|
355
|
-
is_right_side_of_assignment
|
|
356
|
-
) {
|
|
357
|
-
return b.call('_$_.get', node);
|
|
358
|
-
}
|
|
336
|
+
return binding.transform.read(node);
|
|
359
337
|
}
|
|
360
338
|
|
|
361
339
|
return node;
|
|
@@ -377,7 +355,7 @@ const visitors = {
|
|
|
377
355
|
// Lazy destructuring: use __props identifier, bindings resolved via transforms
|
|
378
356
|
props_param_output = b.id('__props');
|
|
379
357
|
} else {
|
|
380
|
-
props_param_output = props_param;
|
|
358
|
+
props_param_output = replace_lazy_param_pattern(props_param);
|
|
381
359
|
}
|
|
382
360
|
} else {
|
|
383
361
|
props_param_output = props_param;
|
|
@@ -522,7 +500,7 @@ const visitors = {
|
|
|
522
500
|
|
|
523
501
|
const track_call_name = is_ripple_track_call(callee, context);
|
|
524
502
|
if (track_call_name) {
|
|
525
|
-
const track_method_name =
|
|
503
|
+
const track_method_name = 'track';
|
|
526
504
|
|
|
527
505
|
return {
|
|
528
506
|
...node,
|
|
@@ -619,16 +597,12 @@ const visitors = {
|
|
|
619
597
|
}
|
|
620
598
|
// Replace lazy destructuring params with generated identifiers
|
|
621
599
|
const pattern = param.type === 'AssignmentPattern' ? param.left : param;
|
|
622
|
-
if (
|
|
623
|
-
|
|
624
|
-
pattern.lazy &&
|
|
625
|
-
pattern.metadata?.lazy_id
|
|
626
|
-
) {
|
|
627
|
-
const id = b.id(pattern.metadata.lazy_id);
|
|
600
|
+
if (pattern.type === 'ObjectPattern' || pattern.type === 'ArrayPattern') {
|
|
601
|
+
const transformed_pattern = replace_lazy_param_pattern(pattern);
|
|
628
602
|
node.params[i] =
|
|
629
603
|
param.type === 'AssignmentPattern'
|
|
630
|
-
? /** @type {AST.AssignmentPattern} */ ({ ...param, left:
|
|
631
|
-
:
|
|
604
|
+
? /** @type {AST.AssignmentPattern} */ ({ ...param, left: transformed_pattern })
|
|
605
|
+
: transformed_pattern;
|
|
632
606
|
}
|
|
633
607
|
}
|
|
634
608
|
}
|
|
@@ -648,16 +622,12 @@ const visitors = {
|
|
|
648
622
|
}
|
|
649
623
|
// Replace lazy destructuring params with generated identifiers
|
|
650
624
|
const pattern = param.type === 'AssignmentPattern' ? param.left : param;
|
|
651
|
-
if (
|
|
652
|
-
|
|
653
|
-
pattern.lazy &&
|
|
654
|
-
pattern.metadata?.lazy_id
|
|
655
|
-
) {
|
|
656
|
-
const id = b.id(pattern.metadata.lazy_id);
|
|
625
|
+
if (pattern.type === 'ObjectPattern' || pattern.type === 'ArrayPattern') {
|
|
626
|
+
const transformed_pattern = replace_lazy_param_pattern(pattern);
|
|
657
627
|
node.params[i] =
|
|
658
628
|
param.type === 'AssignmentPattern'
|
|
659
|
-
? /** @type {AST.AssignmentPattern} */ ({ ...param, left:
|
|
660
|
-
:
|
|
629
|
+
? /** @type {AST.AssignmentPattern} */ ({ ...param, left: transformed_pattern })
|
|
630
|
+
: transformed_pattern;
|
|
661
631
|
}
|
|
662
632
|
}
|
|
663
633
|
}
|
|
@@ -687,16 +657,12 @@ const visitors = {
|
|
|
687
657
|
}
|
|
688
658
|
// Replace lazy destructuring params with generated identifiers
|
|
689
659
|
const pattern = param.type === 'AssignmentPattern' ? param.left : param;
|
|
690
|
-
if (
|
|
691
|
-
|
|
692
|
-
pattern.lazy &&
|
|
693
|
-
pattern.metadata?.lazy_id
|
|
694
|
-
) {
|
|
695
|
-
const id = b.id(pattern.metadata.lazy_id);
|
|
660
|
+
if (pattern.type === 'ObjectPattern' || pattern.type === 'ArrayPattern') {
|
|
661
|
+
const transformed_pattern = replace_lazy_param_pattern(pattern);
|
|
696
662
|
node.params[i] =
|
|
697
663
|
param.type === 'AssignmentPattern'
|
|
698
|
-
? /** @type {AST.AssignmentPattern} */ ({ ...param, left:
|
|
699
|
-
:
|
|
664
|
+
? /** @type {AST.AssignmentPattern} */ ({ ...param, left: transformed_pattern })
|
|
665
|
+
: transformed_pattern;
|
|
700
666
|
}
|
|
701
667
|
}
|
|
702
668
|
|
|
@@ -835,6 +801,19 @@ const visitors = {
|
|
|
835
801
|
return statements.length ? b.block(statements) : b.empty;
|
|
836
802
|
},
|
|
837
803
|
|
|
804
|
+
ExpressionStatement(node, context) {
|
|
805
|
+
// Handle standalone lazy destructuring: &[data] = track(0); → const lazy0 = track(0);
|
|
806
|
+
if (
|
|
807
|
+
node.expression.type === 'AssignmentExpression' &&
|
|
808
|
+
node.expression.left.lazy &&
|
|
809
|
+
node.expression.left.metadata?.lazy_id
|
|
810
|
+
) {
|
|
811
|
+
const right = /** @type {AST.Expression} */ (context.visit(node.expression.right));
|
|
812
|
+
return b.const(b.id(node.expression.left.metadata.lazy_id), right);
|
|
813
|
+
}
|
|
814
|
+
return context.next();
|
|
815
|
+
},
|
|
816
|
+
|
|
838
817
|
VariableDeclaration(node, context) {
|
|
839
818
|
for (const declarator of node.declarations) {
|
|
840
819
|
if (!context.state.to_ts) {
|
|
@@ -1202,9 +1181,10 @@ const visitors = {
|
|
|
1202
1181
|
|
|
1203
1182
|
/** @type {AST.Statement[]} */
|
|
1204
1183
|
const init = [];
|
|
1184
|
+
const visited_id = /** @type {AST.Expression} */ (visit(node.id, state));
|
|
1205
1185
|
/** @type {AST.Statement[]} */
|
|
1206
1186
|
const statements = [
|
|
1207
|
-
b.const(comp_id,
|
|
1187
|
+
b.const(comp_id, is_element_dynamic(node) ? b.call('_$_.get', visited_id) : visited_id),
|
|
1208
1188
|
b.const(args_id, b.array(args)),
|
|
1209
1189
|
];
|
|
1210
1190
|
|
|
@@ -1437,53 +1417,6 @@ const visitors = {
|
|
|
1437
1417
|
}
|
|
1438
1418
|
}
|
|
1439
1419
|
|
|
1440
|
-
if (
|
|
1441
|
-
left.type === 'MemberExpression' &&
|
|
1442
|
-
(left.tracked || (left.property.type === 'Identifier' && left.property.tracked))
|
|
1443
|
-
) {
|
|
1444
|
-
const operator = node.operator;
|
|
1445
|
-
const right = node.right;
|
|
1446
|
-
|
|
1447
|
-
return b.call(
|
|
1448
|
-
'_$_.set_property',
|
|
1449
|
-
/** @type {AST.Expression} */ (context.visit(left.object)),
|
|
1450
|
-
left.computed
|
|
1451
|
-
? /** @type {AST.Expression} */ (context.visit(left.property))
|
|
1452
|
-
: b.literal(/** @type {AST.Identifier} */ (left.property).name),
|
|
1453
|
-
operator === '='
|
|
1454
|
-
? /** @type {AST.Expression} */ (context.visit(right))
|
|
1455
|
-
: b.binary(
|
|
1456
|
-
operator === '+=' ? '+' : operator === '-=' ? '-' : operator === '*=' ? '*' : '/',
|
|
1457
|
-
b.call(
|
|
1458
|
-
'_$_.get_property',
|
|
1459
|
-
/** @type {AST.Expression} */ (context.visit(left.object)),
|
|
1460
|
-
left.computed
|
|
1461
|
-
? /** @type {AST.Expression} */ (context.visit(left.property))
|
|
1462
|
-
: b.literal(/** @type {AST.Identifier} */ (left.property).name),
|
|
1463
|
-
undefined,
|
|
1464
|
-
),
|
|
1465
|
-
/** @type {AST.Expression} */ (context.visit(right)),
|
|
1466
|
-
),
|
|
1467
|
-
);
|
|
1468
|
-
}
|
|
1469
|
-
|
|
1470
|
-
if (left.type === 'Identifier' && left.tracked) {
|
|
1471
|
-
const operator = node.operator;
|
|
1472
|
-
const right = node.right;
|
|
1473
|
-
|
|
1474
|
-
return b.call(
|
|
1475
|
-
'_$_.set',
|
|
1476
|
-
/** @type {AST.Expression} */ (context.visit(left)),
|
|
1477
|
-
operator === '='
|
|
1478
|
-
? /** @type {AST.Expression} */ (context.visit(right))
|
|
1479
|
-
: b.binary(
|
|
1480
|
-
operator === '+=' ? '+' : operator === '-=' ? '-' : operator === '*=' ? '*' : '/',
|
|
1481
|
-
b.call('_$_.get', left),
|
|
1482
|
-
/** @type {AST.Expression} */ (context.visit(right)),
|
|
1483
|
-
),
|
|
1484
|
-
);
|
|
1485
|
-
}
|
|
1486
|
-
|
|
1487
1420
|
return context.next();
|
|
1488
1421
|
},
|
|
1489
1422
|
|
|
@@ -1497,39 +1430,6 @@ const visitors = {
|
|
|
1497
1430
|
return binding.transform.update(node);
|
|
1498
1431
|
}
|
|
1499
1432
|
}
|
|
1500
|
-
|
|
1501
|
-
if (
|
|
1502
|
-
argument.type === 'MemberExpression' &&
|
|
1503
|
-
(argument.tracked || (argument.property.type === 'Identifier' && argument.property.tracked))
|
|
1504
|
-
) {
|
|
1505
|
-
return b.call(
|
|
1506
|
-
node.prefix ? '_$_.update_pre_property' : '_$_.update_property',
|
|
1507
|
-
/** @type {AST.Expression} */
|
|
1508
|
-
(context.visit(argument.object, { ...context.state, metadata: { tracking: false } })),
|
|
1509
|
-
argument.computed
|
|
1510
|
-
? /** @type {AST.Expression} */ (context.visit(argument.property))
|
|
1511
|
-
: b.literal(/** @type {AST.Identifier} */ (argument.property).name),
|
|
1512
|
-
node.operator === '--' ? b.literal(-1) : undefined,
|
|
1513
|
-
);
|
|
1514
|
-
}
|
|
1515
|
-
|
|
1516
|
-
if (argument.type === 'Identifier' && argument.tracked) {
|
|
1517
|
-
return b.call(
|
|
1518
|
-
node.prefix ? '_$_.update_pre' : '_$_.update',
|
|
1519
|
-
/** @type {AST.Expression} */
|
|
1520
|
-
(context.visit(argument)),
|
|
1521
|
-
node.operator === '--' ? b.literal(-1) : undefined,
|
|
1522
|
-
);
|
|
1523
|
-
}
|
|
1524
|
-
|
|
1525
|
-
if (argument.type === 'TrackedExpression') {
|
|
1526
|
-
return b.call(
|
|
1527
|
-
node.prefix ? '_$_.update_pre' : '_$_.update',
|
|
1528
|
-
/** @type {AST.Expression} */
|
|
1529
|
-
(context.visit(argument.argument)),
|
|
1530
|
-
node.operator === '--' ? b.literal(-1) : undefined,
|
|
1531
|
-
);
|
|
1532
|
-
}
|
|
1533
1433
|
},
|
|
1534
1434
|
|
|
1535
1435
|
ServerIdentifier(node, context) {
|
|
@@ -1711,26 +1611,7 @@ const visitors = {
|
|
|
1711
1611
|
return b.await(/** @type {AST.AwaitExpression} */ (context.visit(node.argument)));
|
|
1712
1612
|
},
|
|
1713
1613
|
|
|
1714
|
-
TrackedExpression(node, context) {
|
|
1715
|
-
return b.call('_$_.get', /** @type {AST.Expression} */ (context.visit(node.argument)));
|
|
1716
|
-
},
|
|
1717
|
-
|
|
1718
1614
|
MemberExpression(node, context) {
|
|
1719
|
-
if (
|
|
1720
|
-
node.tracked ||
|
|
1721
|
-
((node.property.type === 'Identifier' || node.property.type === 'Literal') &&
|
|
1722
|
-
node.property.tracked)
|
|
1723
|
-
) {
|
|
1724
|
-
return b.call(
|
|
1725
|
-
'_$_.get_property',
|
|
1726
|
-
/** @type {AST.Expression} */ (context.visit(node.object)),
|
|
1727
|
-
node.computed
|
|
1728
|
-
? /** @type {AST.Expression} */ (context.visit(node.property))
|
|
1729
|
-
: b.literal(/** @type {AST.Identifier} */ (node.property).name),
|
|
1730
|
-
node.optional ? b.true : undefined,
|
|
1731
|
-
);
|
|
1732
|
-
}
|
|
1733
|
-
|
|
1734
1615
|
return context.next();
|
|
1735
1616
|
},
|
|
1736
1617
|
|
|
@@ -1738,10 +1619,6 @@ const visitors = {
|
|
|
1738
1619
|
const metadata = { await: false };
|
|
1739
1620
|
let expression = /** @type {AST.Expression} */ (visit(node.expression, { ...state, metadata }));
|
|
1740
1621
|
|
|
1741
|
-
if (expression.type === 'Identifier' && expression.tracked) {
|
|
1742
|
-
expression = b.call('_$_.get', expression);
|
|
1743
|
-
}
|
|
1744
|
-
|
|
1745
1622
|
if (expression.type === 'Literal') {
|
|
1746
1623
|
state.init?.push(
|
|
1747
1624
|
b.stmt(
|
|
@@ -6,6 +6,6 @@
|
|
|
6
6
|
//
|
|
7
7
|
// The relative import of './parser' loads the augmentation declarations
|
|
8
8
|
// (declare module 'acorn' { ... }) so the re-exported types include
|
|
9
|
-
// Ripple-specific nodes like Component, Element,
|
|
9
|
+
// Ripple-specific nodes like Component, Element, etc.
|
|
10
10
|
import './parser.d.ts';
|
|
11
11
|
export * from 'acorn';
|
|
@@ -6,6 +6,6 @@
|
|
|
6
6
|
//
|
|
7
7
|
// The relative import of './index' loads the augmentation declarations
|
|
8
8
|
// (declare module 'estree' { ... }) so the re-exported types include
|
|
9
|
-
// Ripple-specific nodes like Component, Element,
|
|
9
|
+
// Ripple-specific nodes like Component, Element, etc.
|
|
10
10
|
import './index';
|
|
11
11
|
export * from 'estree';
|
|
@@ -41,7 +41,6 @@ import {
|
|
|
41
41
|
MediaQuery as _$_MediaQuery__,
|
|
42
42
|
createRefKey as _$_RefKey__create,
|
|
43
43
|
track as _$_track__,
|
|
44
|
-
trackSplit as _$_trackSplit__,
|
|
45
44
|
effect as _$_effect__,
|
|
46
45
|
untrack as _$_untrack__,
|
|
47
46
|
ripple_namespace as _$__u0023_ripple,
|
|
@@ -59,7 +58,6 @@ export {
|
|
|
59
58
|
_$_MediaQuery__,
|
|
60
59
|
_$_RefKey__create,
|
|
61
60
|
_$_track__,
|
|
62
|
-
_$_trackSplit__,
|
|
63
61
|
_$_effect__,
|
|
64
62
|
_$_untrack__,
|
|
65
63
|
_$__u0023_ripple,
|
|
@@ -116,19 +116,17 @@ declare module 'estree' {
|
|
|
116
116
|
|
|
117
117
|
// We mark the whole node as marked when member is @[expression]
|
|
118
118
|
// Otherwise, we only mark Identifier nodes
|
|
119
|
-
interface MemberExpression
|
|
119
|
+
interface MemberExpression {}
|
|
120
120
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
interface
|
|
124
|
-
interface RegExpLiteral extends AST.LiteralTrackedNode {}
|
|
125
|
-
interface BigIntLiteral extends AST.LiteralTrackedNode {}
|
|
121
|
+
interface SimpleLiteral extends AST.LiteralNode {}
|
|
122
|
+
interface RegExpLiteral extends AST.LiteralNode {}
|
|
123
|
+
interface BigIntLiteral extends AST.LiteralNode {}
|
|
126
124
|
|
|
127
125
|
interface TrackedNode {
|
|
128
126
|
tracked?: boolean;
|
|
129
127
|
}
|
|
130
128
|
|
|
131
|
-
interface
|
|
129
|
+
interface LiteralNode {
|
|
132
130
|
was_expression?: boolean;
|
|
133
131
|
}
|
|
134
132
|
|
|
@@ -143,7 +141,6 @@ declare module 'estree' {
|
|
|
143
141
|
ServerBlockStatement: ServerBlockStatement;
|
|
144
142
|
ServerIdentifier: ServerIdentifier;
|
|
145
143
|
StyleIdentifier: StyleIdentifier;
|
|
146
|
-
TrackedExpression: TrackedExpression;
|
|
147
144
|
Attribute: Attribute;
|
|
148
145
|
RefAttribute: RefAttribute;
|
|
149
146
|
SpreadAttribute: SpreadAttribute;
|
|
@@ -152,7 +149,6 @@ declare module 'estree' {
|
|
|
152
149
|
}
|
|
153
150
|
|
|
154
151
|
interface ExpressionMap {
|
|
155
|
-
TrackedExpression: TrackedExpression;
|
|
156
152
|
StyleIdentifier: StyleIdentifier;
|
|
157
153
|
ServerIdentifier: ServerIdentifier;
|
|
158
154
|
Text: TextNode;
|
|
@@ -345,14 +341,6 @@ declare module 'estree' {
|
|
|
345
341
|
content: string;
|
|
346
342
|
}
|
|
347
343
|
|
|
348
|
-
/**
|
|
349
|
-
* Tracked Expressions
|
|
350
|
-
*/
|
|
351
|
-
interface TrackedExpression extends AST.BaseExpression {
|
|
352
|
-
argument: AST.Expression;
|
|
353
|
-
type: 'TrackedExpression';
|
|
354
|
-
}
|
|
355
|
-
|
|
356
344
|
/**
|
|
357
345
|
* Ripple attribute nodes
|
|
358
346
|
*/
|
|
@@ -543,8 +543,6 @@ export namespace Parse {
|
|
|
543
543
|
*/
|
|
544
544
|
finishToken(type: TokenType, val?: string | number | RegExp | bigint): void;
|
|
545
545
|
|
|
546
|
-
readAtIdentifier(): void;
|
|
547
|
-
|
|
548
546
|
/**
|
|
549
547
|
* Read a token based on character code
|
|
550
548
|
* Called by nextToken() for each character
|
|
@@ -926,15 +924,7 @@ export namespace Parse {
|
|
|
926
924
|
refDestructuringErrors?: DestructuringErrors,
|
|
927
925
|
forInit?: ForInit,
|
|
928
926
|
forNew?: boolean,
|
|
929
|
-
):
|
|
930
|
-
| AST.ServerIdentifier
|
|
931
|
-
| AST.StyleIdentifier
|
|
932
|
-
| AST.TrackedExpression
|
|
933
|
-
| AST.RippleArrayExpression
|
|
934
|
-
| AST.RippleObjectExpression
|
|
935
|
-
| AST.Component
|
|
936
|
-
| AST.Identifier
|
|
937
|
-
| AST.Literal;
|
|
927
|
+
): AST.ServerIdentifier | AST.StyleIdentifier | AST.Component | AST.Identifier | AST.Literal;
|
|
938
928
|
|
|
939
929
|
/** Default handler for parseExprAtom when no other case matches */
|
|
940
930
|
parseExprAtomDefault(): AST.Expression;
|
|
@@ -954,12 +944,6 @@ export namespace Parse {
|
|
|
954
944
|
/** Parse parenthesized expression (just the expression) */
|
|
955
945
|
parseParenExpression(): AST.Expression;
|
|
956
946
|
|
|
957
|
-
parseRippleArrayExpression(): AST.RippleArrayExpression;
|
|
958
|
-
|
|
959
|
-
parseTrackedExpression(): AST.TrackedExpression;
|
|
960
|
-
|
|
961
|
-
parseRippleObjectExpression(): AST.RippleObjectExpression;
|
|
962
|
-
|
|
963
947
|
/**
|
|
964
948
|
* Parse item in parentheses (can be overridden for flow/ts)
|
|
965
949
|
*/
|