ripple 0.2.46 → 0.2.48
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 +1 -1
- package/src/compiler/phases/1-parse/index.js +52 -2
- package/src/compiler/phases/2-analyze/index.js +640 -667
- package/src/compiler/phases/3-transform/index.js +1878 -1879
- package/src/compiler/phases/3-transform/segments.js +2 -2
- package/src/compiler/utils.js +598 -550
- package/src/jsx-runtime.js +12 -12
- package/src/runtime/array.js +611 -609
- package/src/runtime/index.js +29 -17
- package/src/runtime/internal/client/array.js +121 -121
- package/src/runtime/internal/client/blocks.js +206 -206
- package/src/runtime/internal/client/constants.js +2 -2
- package/src/runtime/internal/client/context.js +40 -40
- package/src/runtime/internal/client/events.js +191 -191
- package/src/runtime/internal/client/for.js +355 -355
- package/src/runtime/internal/client/if.js +25 -25
- package/src/runtime/internal/client/index.js +57 -56
- package/src/runtime/internal/client/operations.js +32 -32
- package/src/runtime/internal/client/portal.js +19 -19
- package/src/runtime/internal/client/render.js +132 -132
- package/src/runtime/internal/client/runtime.js +839 -835
- package/src/runtime/internal/client/template.js +36 -36
- package/src/runtime/internal/client/try.js +113 -113
- package/src/runtime/internal/client/types.d.ts +12 -11
- package/src/runtime/internal/client/utils.js +5 -5
- package/src/runtime/map.js +139 -139
- package/src/runtime/set.js +130 -130
- package/src/utils/ast.js +189 -189
- package/src/utils/builders.js +244 -244
- package/src/utils/sanitize_template_string.js +1 -1
- package/tests/__snapshots__/composite.test.ripple.snap +1 -1
- package/tests/accessors-props.test.ripple +9 -9
- package/tests/basic.test.ripple +4 -4
- package/tests/boundaries.test.ripple +17 -17
- package/tests/compiler.test.ripple +14 -14
- package/tests/composite.test.ripple +43 -72
- package/tests/context.test.ripple +35 -12
- package/types/index.d.ts +38 -34
package/src/utils/ast.js
CHANGED
|
@@ -1,208 +1,208 @@
|
|
|
1
1
|
import * as b from './builders.js';
|
|
2
2
|
|
|
3
3
|
export function object(expression) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
while (expression.type === 'MemberExpression') {
|
|
5
|
+
expression = /** @type {ESTree.MemberExpression | ESTree.Identifier} */ (expression.object);
|
|
6
|
+
}
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
if (expression.type !== 'Identifier') {
|
|
9
|
+
return null;
|
|
10
|
+
}
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
return expression;
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
export function unwrap_pattern(pattern, nodes = []) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
16
|
+
switch (pattern.type) {
|
|
17
|
+
case 'Identifier':
|
|
18
|
+
nodes.push(pattern);
|
|
19
|
+
break;
|
|
20
|
+
|
|
21
|
+
case 'MemberExpression':
|
|
22
|
+
// member expressions can be part of an assignment pattern, but not a binding pattern
|
|
23
|
+
// see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment#binding_and_assignment
|
|
24
|
+
nodes.push(pattern);
|
|
25
|
+
break;
|
|
26
|
+
|
|
27
|
+
case 'ObjectPattern':
|
|
28
|
+
for (const prop of pattern.properties) {
|
|
29
|
+
if (prop.type === 'RestElement') {
|
|
30
|
+
unwrap_pattern(prop.argument, nodes);
|
|
31
|
+
} else {
|
|
32
|
+
unwrap_pattern(prop.value, nodes);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
break;
|
|
37
|
+
|
|
38
|
+
case 'ArrayPattern':
|
|
39
|
+
for (const element of pattern.elements) {
|
|
40
|
+
if (element) unwrap_pattern(element, nodes);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
break;
|
|
44
|
+
|
|
45
|
+
case 'RestElement':
|
|
46
|
+
unwrap_pattern(pattern.argument, nodes);
|
|
47
|
+
break;
|
|
48
|
+
|
|
49
|
+
case 'AssignmentPattern':
|
|
50
|
+
unwrap_pattern(pattern.left, nodes);
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return nodes;
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
export function extract_identifiers(pattern) {
|
|
58
|
-
|
|
58
|
+
return unwrap_pattern(pattern, []).filter((node) => node.type === 'Identifier');
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
export function extract_paths(param) {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
62
|
+
return _extract_paths(
|
|
63
|
+
[],
|
|
64
|
+
param,
|
|
65
|
+
(node) => /** @type {ESTree.Identifier | ESTree.MemberExpression} */ (node),
|
|
66
|
+
(node) => /** @type {ESTree.Identifier | ESTree.MemberExpression} */ (node),
|
|
67
|
+
false,
|
|
68
|
+
);
|
|
69
69
|
}
|
|
70
70
|
|
|
71
71
|
function _extract_paths(assignments = [], param, expression, update_expression, has_default_value) {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
72
|
+
switch (param.type) {
|
|
73
|
+
case 'Identifier':
|
|
74
|
+
case 'MemberExpression':
|
|
75
|
+
assignments.push({
|
|
76
|
+
node: param,
|
|
77
|
+
is_rest: false,
|
|
78
|
+
has_default_value,
|
|
79
|
+
expression,
|
|
80
|
+
update_expression,
|
|
81
|
+
});
|
|
82
|
+
break;
|
|
83
|
+
|
|
84
|
+
case 'ObjectPattern':
|
|
85
|
+
for (const prop of param.properties) {
|
|
86
|
+
if (prop.type === 'RestElement') {
|
|
87
|
+
/** @type {DestructuredAssignment['expression']} */
|
|
88
|
+
const rest_expression = (object) => {
|
|
89
|
+
/** @type {ESTree.Expression[]} */
|
|
90
|
+
const props = [];
|
|
91
|
+
|
|
92
|
+
for (const p of param.properties) {
|
|
93
|
+
if (p.type === 'Property' && p.key.type !== 'PrivateIdentifier') {
|
|
94
|
+
if (p.key.type === 'Identifier' && !p.computed) {
|
|
95
|
+
props.push(b.literal(p.key.name));
|
|
96
|
+
} else if (p.key.type === 'Literal') {
|
|
97
|
+
props.push(b.literal(String(p.key.value)));
|
|
98
|
+
} else {
|
|
99
|
+
props.push(b.call('String', p.key));
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return b.call('$.exclude_from_object', expression(object), b.array(props));
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
if (prop.argument.type === 'Identifier') {
|
|
108
|
+
assignments.push({
|
|
109
|
+
node: prop.argument,
|
|
110
|
+
is_rest: true,
|
|
111
|
+
has_default_value,
|
|
112
|
+
expression: rest_expression,
|
|
113
|
+
update_expression: rest_expression,
|
|
114
|
+
});
|
|
115
|
+
} else {
|
|
116
|
+
_extract_paths(
|
|
117
|
+
assignments,
|
|
118
|
+
prop.argument,
|
|
119
|
+
rest_expression,
|
|
120
|
+
rest_expression,
|
|
121
|
+
has_default_value,
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
} else {
|
|
125
|
+
/** @type {DestructuredAssignment['expression']} */
|
|
126
|
+
const object_expression = (object) =>
|
|
127
|
+
b.member(expression(object), prop.key, prop.computed || prop.key.type !== 'Identifier');
|
|
128
|
+
_extract_paths(
|
|
129
|
+
assignments,
|
|
130
|
+
prop.value,
|
|
131
|
+
object_expression,
|
|
132
|
+
object_expression,
|
|
133
|
+
has_default_value,
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
break;
|
|
139
|
+
|
|
140
|
+
case 'ArrayPattern':
|
|
141
|
+
for (let i = 0; i < param.elements.length; i += 1) {
|
|
142
|
+
const element = param.elements[i];
|
|
143
|
+
if (element) {
|
|
144
|
+
if (element.type === 'RestElement') {
|
|
145
|
+
/** @type {DestructuredAssignment['expression']} */
|
|
146
|
+
const rest_expression = (object) =>
|
|
147
|
+
b.call(b.member(expression(object), 'slice'), b.literal(i));
|
|
148
|
+
if (element.argument.type === 'Identifier') {
|
|
149
|
+
assignments.push({
|
|
150
|
+
node: element.argument,
|
|
151
|
+
is_rest: true,
|
|
152
|
+
has_default_value,
|
|
153
|
+
expression: rest_expression,
|
|
154
|
+
update_expression: rest_expression,
|
|
155
|
+
});
|
|
156
|
+
} else {
|
|
157
|
+
_extract_paths(
|
|
158
|
+
assignments,
|
|
159
|
+
element.argument,
|
|
160
|
+
rest_expression,
|
|
161
|
+
rest_expression,
|
|
162
|
+
has_default_value,
|
|
163
|
+
);
|
|
164
|
+
}
|
|
165
|
+
} else {
|
|
166
|
+
/** @type {DestructuredAssignment['expression']} */
|
|
167
|
+
const array_expression = (object) => b.member(expression(object), b.literal(i), true);
|
|
168
|
+
_extract_paths(
|
|
169
|
+
assignments,
|
|
170
|
+
element,
|
|
171
|
+
array_expression,
|
|
172
|
+
array_expression,
|
|
173
|
+
has_default_value,
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
break;
|
|
180
|
+
|
|
181
|
+
case 'AssignmentPattern': {
|
|
182
|
+
/** @type {DestructuredAssignment['expression']} */
|
|
183
|
+
const fallback_expression = (object) => build_fallback(expression(object), param.right);
|
|
184
|
+
|
|
185
|
+
if (param.left.type === 'Identifier') {
|
|
186
|
+
assignments.push({
|
|
187
|
+
node: param.left,
|
|
188
|
+
is_rest: false,
|
|
189
|
+
has_default_value: true,
|
|
190
|
+
expression: fallback_expression,
|
|
191
|
+
update_expression,
|
|
192
|
+
});
|
|
193
|
+
} else {
|
|
194
|
+
_extract_paths(assignments, param.left, fallback_expression, update_expression, true);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
break;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
return assignments;
|
|
202
202
|
}
|
|
203
203
|
|
|
204
204
|
export function build_fallback(expression, fallback) {
|
|
205
|
-
|
|
205
|
+
return b.call('$.fallback', expression, fallback);
|
|
206
206
|
}
|
|
207
207
|
|
|
208
208
|
/**
|
|
@@ -211,8 +211,8 @@ export function build_fallback(expression, fallback) {
|
|
|
211
211
|
* @param {ESTree.Expression} right
|
|
212
212
|
*/
|
|
213
213
|
export function build_assignment_value(operator, left, right) {
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
214
|
+
return operator === '='
|
|
215
|
+
? right
|
|
216
|
+
: // turn something like x += 1 into x = x + 1
|
|
217
|
+
b.binary(/** @type {ESTree.BinaryOperator} */ (operator.slice(0, -1)), left, right);
|
|
218
218
|
}
|