ripple 0.2.41 → 0.2.43
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 +4 -4
- package/src/compiler/phases/3-transform/index.js +77 -29
- package/src/runtime/array.js +393 -57
- package/src/runtime/internal/client/constants.js +1 -0
- package/src/runtime/internal/client/index.js +1 -0
- package/src/runtime/internal/client/runtime.js +49 -15
- package/src/runtime/internal/client/utils.js +18 -0
- package/tests/__snapshots__/basic.test.ripple.snap +14 -0
- package/tests/array.test.ripple +1424 -10
- package/tests/basic.test.ripple +159 -4
- package/tests/compiler.test.ripple +56 -1
package/package.json
CHANGED
|
@@ -413,9 +413,9 @@ function RipplePlugin(config) {
|
|
|
413
413
|
}
|
|
414
414
|
} else {
|
|
415
415
|
if (open.name.name === 'style') {
|
|
416
|
-
// jsx_parseOpeningElementAt
|
|
417
|
-
//
|
|
418
|
-
const start =
|
|
416
|
+
// jsx_parseOpeningElementAt treats ID selectors (ie. #myid) or type selectors (ie. div) as identifier and read it
|
|
417
|
+
// So backtrack to the end of the <style> tag to make sure everything is included
|
|
418
|
+
const start = open.end;
|
|
419
419
|
const input = this.input.slice(start);
|
|
420
420
|
const end = input.indexOf('</style>');
|
|
421
421
|
const content = input.slice(0, end);
|
|
@@ -428,7 +428,7 @@ function RipplePlugin(config) {
|
|
|
428
428
|
|
|
429
429
|
const newLines = content.match(regex_newline_characters)?.length;
|
|
430
430
|
if (newLines) {
|
|
431
|
-
this.curLine
|
|
431
|
+
this.curLine = open.loc.end.line + newLines;
|
|
432
432
|
this.lineStart = start + content.lastIndexOf('\n') + 1;
|
|
433
433
|
}
|
|
434
434
|
this.pos = start + content.length + 1;
|
|
@@ -150,40 +150,57 @@ const visitors = {
|
|
|
150
150
|
}
|
|
151
151
|
|
|
152
152
|
// Handle array methods that access the array
|
|
153
|
-
if (
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
153
|
+
if (callee.type === 'MemberExpression') {
|
|
154
|
+
const property = callee.property;
|
|
155
|
+
|
|
156
|
+
if (property.type === 'Identifier' && !callee.optional) {
|
|
157
|
+
const name = property.name;
|
|
158
|
+
if (
|
|
159
|
+
// TODO support the missing array methods
|
|
160
|
+
name === 'reduce' ||
|
|
161
|
+
name === 'map' ||
|
|
162
|
+
name === 'forEach' ||
|
|
163
|
+
name === 'join' ||
|
|
164
|
+
name === 'includes' ||
|
|
165
|
+
name === 'indexOf' ||
|
|
166
|
+
name === 'lastIndexOf' ||
|
|
167
|
+
name === 'filter' ||
|
|
168
|
+
name === 'every' ||
|
|
169
|
+
name === 'some' ||
|
|
170
|
+
name === 'toSpliced' ||
|
|
171
|
+
name === 'toSorted' ||
|
|
172
|
+
name === 'toString' ||
|
|
173
|
+
name === 'values' ||
|
|
174
|
+
name === 'entries'
|
|
175
|
+
) {
|
|
176
|
+
return b.call(
|
|
177
|
+
'$.with_scope',
|
|
178
|
+
b.id('__block'),
|
|
179
|
+
b.thunk(
|
|
180
|
+
b.call(
|
|
181
|
+
'$.array_' + name,
|
|
182
|
+
context.visit(callee.object),
|
|
183
|
+
...node.arguments.map((arg) => context.visit(arg)),
|
|
184
|
+
),
|
|
185
|
+
),
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
if (callee.computed) {
|
|
177
191
|
return b.call(
|
|
178
192
|
'$.with_scope',
|
|
179
193
|
b.id('__block'),
|
|
180
194
|
b.thunk(
|
|
181
195
|
b.call(
|
|
182
|
-
'$.
|
|
196
|
+
'$.call_property',
|
|
183
197
|
context.visit(callee.object),
|
|
198
|
+
context.visit(property),
|
|
199
|
+
callee.optional ? b.true : undefined,
|
|
200
|
+
node.optional ? b.true : undefined,
|
|
184
201
|
...node.arguments.map((arg) => context.visit(arg)),
|
|
185
|
-
)
|
|
186
|
-
)
|
|
202
|
+
)
|
|
203
|
+
)
|
|
187
204
|
);
|
|
188
205
|
}
|
|
189
206
|
}
|
|
@@ -199,6 +216,27 @@ const visitors = {
|
|
|
199
216
|
);
|
|
200
217
|
},
|
|
201
218
|
|
|
219
|
+
TSTypeAliasDeclaration(_, context) {
|
|
220
|
+
if (!context.state.to_ts) {
|
|
221
|
+
return b.empty;
|
|
222
|
+
}
|
|
223
|
+
context.next();
|
|
224
|
+
},
|
|
225
|
+
|
|
226
|
+
TSInterfaceDeclaration(_, context) {
|
|
227
|
+
if (!context.state.to_ts) {
|
|
228
|
+
return b.empty;
|
|
229
|
+
}
|
|
230
|
+
context.next();
|
|
231
|
+
},
|
|
232
|
+
|
|
233
|
+
TSMappedType(_, context) {
|
|
234
|
+
if (!context.state.to_ts) {
|
|
235
|
+
return b.empty;
|
|
236
|
+
}
|
|
237
|
+
context.next();
|
|
238
|
+
},
|
|
239
|
+
|
|
202
240
|
NewExpression(node, context) {
|
|
203
241
|
const callee = node.callee;
|
|
204
242
|
const parent = context.path.at(-1);
|
|
@@ -469,7 +507,11 @@ const visitors = {
|
|
|
469
507
|
);
|
|
470
508
|
|
|
471
509
|
if (is_spreading) {
|
|
472
|
-
|
|
510
|
+
// For spread attributes, store just the actual value, not the full attribute string
|
|
511
|
+
const actual_value = is_boolean_attribute(name) && value === true
|
|
512
|
+
? b.literal(true)
|
|
513
|
+
: b.literal(value === true ? '' : value);
|
|
514
|
+
spread_attributes.push(b.prop('init', b.literal(name), actual_value));
|
|
473
515
|
} else {
|
|
474
516
|
state.template.push(attr_value);
|
|
475
517
|
}
|
|
@@ -959,7 +1001,8 @@ const visitors = {
|
|
|
959
1001
|
const left = node.left;
|
|
960
1002
|
|
|
961
1003
|
if (left.type === 'MemberExpression') {
|
|
962
|
-
|
|
1004
|
+
// need to capture setting length of array to throw a runtime error
|
|
1005
|
+
if (left.property.type === 'Identifier' && (is_tracked_name(left.property.name) || left.property.name === 'length')) {
|
|
963
1006
|
if (left.property.name !== '$length') {
|
|
964
1007
|
return b.call(
|
|
965
1008
|
'$.set_property',
|
|
@@ -1255,6 +1298,11 @@ const visitors = {
|
|
|
1255
1298
|
return b.binary(node.operator, context.visit(node.left), context.visit(node.right));
|
|
1256
1299
|
},
|
|
1257
1300
|
|
|
1301
|
+
TemplateLiteral(node, context) {
|
|
1302
|
+
const expressions = node.expressions.map(expr => context.visit(expr));
|
|
1303
|
+
return b.template(node.quasis, expressions);
|
|
1304
|
+
},
|
|
1305
|
+
|
|
1258
1306
|
RenderFragment(node, context) {
|
|
1259
1307
|
const identifer = node.expression.callee;
|
|
1260
1308
|
|