ripple 0.2.82 → 0.2.84
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 +1151 -1062
- package/src/compiler/phases/2-analyze/index.js +561 -523
- package/src/compiler/phases/3-transform/client/index.js +105 -28
- package/src/compiler/phases/3-transform/server/index.js +1 -1
- package/src/compiler/utils.js +613 -595
- package/src/runtime/array.js +4 -0
- package/src/runtime/index-client.js +8 -2
- package/src/runtime/internal/client/constants.js +9 -8
- package/src/runtime/internal/client/head.js +14 -0
- package/src/runtime/internal/client/index.js +43 -34
- package/src/runtime/internal/client/operations.js +34 -30
- package/src/runtime/internal/client/runtime.js +30 -29
- package/src/utils/builders.js +1 -0
- package/tests/client/basic.test.ripple +130 -22
- package/types/index.d.ts +6 -11
|
@@ -95,6 +95,54 @@ function visit_function(node, context) {
|
|
|
95
95
|
context.next(state);
|
|
96
96
|
}
|
|
97
97
|
|
|
98
|
+
function visit_head_element(node, context) {
|
|
99
|
+
const { state, visit } = context;
|
|
100
|
+
|
|
101
|
+
const init = [];
|
|
102
|
+
const update = [];
|
|
103
|
+
const final = [];
|
|
104
|
+
const template = [];
|
|
105
|
+
|
|
106
|
+
transform_children(node.children, {
|
|
107
|
+
visit,
|
|
108
|
+
state: { ...state, init, update, final, template, inside_head: true },
|
|
109
|
+
root: true,
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
if (init.length > 0 || update.length > 0 || final.length > 0) {
|
|
113
|
+
context.state.init.push(
|
|
114
|
+
b.call('_$_.head', b.arrow([b.id('__anchor')], b.block([...init, ...update, ...final]))),
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function visit_title_element(node, context) {
|
|
120
|
+
const normalized = normalize_children(node.children, context);
|
|
121
|
+
const content = normalized[0];
|
|
122
|
+
|
|
123
|
+
const metadata = { tracking: false, await: false };
|
|
124
|
+
const result = context.visit(content, { ...context.state, metadata }).expression;
|
|
125
|
+
|
|
126
|
+
if (metadata.tracking) {
|
|
127
|
+
context.state.init.push(
|
|
128
|
+
b.stmt(
|
|
129
|
+
b.call(
|
|
130
|
+
'_$_.render',
|
|
131
|
+
b.thunk(b.block([b.assignment('=', b.id('_$_.document.title'), result)])),
|
|
132
|
+
),
|
|
133
|
+
),
|
|
134
|
+
);
|
|
135
|
+
} else {
|
|
136
|
+
debugger;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function visit_style_element(node, context) {
|
|
141
|
+
context.state.template.push(
|
|
142
|
+
b.literal(`<style>${sanitize_template_string(node.css)}</style>`),
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
|
|
98
146
|
const visitors = {
|
|
99
147
|
_: function set_scope(node, { next, state }) {
|
|
100
148
|
const scope = state.scopes.get(node);
|
|
@@ -162,10 +210,14 @@ const visitors = {
|
|
|
162
210
|
}
|
|
163
211
|
|
|
164
212
|
if (!context.state.to_ts && is_ripple_track_call(callee, context)) {
|
|
165
|
-
if (
|
|
166
|
-
node.arguments.
|
|
167
|
-
|
|
168
|
-
node.arguments.
|
|
213
|
+
if (callee.name === 'track') {
|
|
214
|
+
if (node.arguments.length === 0) {
|
|
215
|
+
node.arguments.push(b.void0, b.void0, b.void0);
|
|
216
|
+
} else if (node.arguments.length === 1) {
|
|
217
|
+
node.arguments.push(b.void0, b.void0);
|
|
218
|
+
} else if (node.arguments.length === 2) {
|
|
219
|
+
node.arguments.push(b.void0);
|
|
220
|
+
}
|
|
169
221
|
}
|
|
170
222
|
return {
|
|
171
223
|
...node,
|
|
@@ -269,6 +321,27 @@ const visitors = {
|
|
|
269
321
|
);
|
|
270
322
|
},
|
|
271
323
|
|
|
324
|
+
TrackedArrayExpression(node, context) {
|
|
325
|
+
if (context.state.to_ts) {
|
|
326
|
+
if (!context.state.imports.has(`import { TrackedArray } from 'ripple'`)) {
|
|
327
|
+
context.state.imports.add(`import { TrackedArray } from 'ripple'`);
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
return b.new(
|
|
331
|
+
b.call(
|
|
332
|
+
b.member(b.id('TrackedArray'), b.id('from')),
|
|
333
|
+
node.elements.map((el) => context.visit(el)),
|
|
334
|
+
),
|
|
335
|
+
);
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
return b.call(
|
|
339
|
+
'_$_.tracked_array',
|
|
340
|
+
b.array(node.elements.map((el) => context.visit(el))),
|
|
341
|
+
b.id('__block'),
|
|
342
|
+
);
|
|
343
|
+
},
|
|
344
|
+
|
|
272
345
|
MemberExpression(node, context) {
|
|
273
346
|
const parent = context.path.at(-1);
|
|
274
347
|
|
|
@@ -402,9 +475,11 @@ const visitors = {
|
|
|
402
475
|
FunctionDeclaration(node, context) {
|
|
403
476
|
return visit_function(node, context);
|
|
404
477
|
},
|
|
478
|
+
|
|
405
479
|
ArrowFunctionExpression(node, context) {
|
|
406
480
|
return visit_function(node, context);
|
|
407
481
|
},
|
|
482
|
+
|
|
408
483
|
FunctionExpression(node, context) {
|
|
409
484
|
return visit_function(node, context);
|
|
410
485
|
},
|
|
@@ -412,6 +487,11 @@ const visitors = {
|
|
|
412
487
|
Element(node, context) {
|
|
413
488
|
const { state, visit } = context;
|
|
414
489
|
|
|
490
|
+
if (context.state.inside_head && node.id.type === 'Identifier' && node.id.name === 'style') {
|
|
491
|
+
state.template.push(`<style>${sanitize_template_string(node.css)}</style>`);
|
|
492
|
+
return;
|
|
493
|
+
}
|
|
494
|
+
|
|
415
495
|
const is_dom_element = is_element_dom_element(node);
|
|
416
496
|
const is_spreading = node.attributes.some((attr) => attr.type === 'SpreadAttribute');
|
|
417
497
|
const spread_attributes = is_spreading ? [] : null;
|
|
@@ -776,29 +856,6 @@ const visitors = {
|
|
|
776
856
|
}
|
|
777
857
|
},
|
|
778
858
|
|
|
779
|
-
Fragment(node, context) {
|
|
780
|
-
if (!context.state.to_ts) {
|
|
781
|
-
add_ripple_internal_import(context);
|
|
782
|
-
}
|
|
783
|
-
|
|
784
|
-
const metadata = { await: false };
|
|
785
|
-
|
|
786
|
-
const body_statements = transform_body(node.body, {
|
|
787
|
-
...context,
|
|
788
|
-
state: { ...context.state, component: node, metadata },
|
|
789
|
-
});
|
|
790
|
-
|
|
791
|
-
return b.function(
|
|
792
|
-
node.id,
|
|
793
|
-
[b.id('__anchor'), ...node.params.map((param) => context.visit(param, context.state))],
|
|
794
|
-
b.block(
|
|
795
|
-
metadata.await
|
|
796
|
-
? [b.stmt(b.call('_$_.async', b.thunk(b.block(body_statements), true)))]
|
|
797
|
-
: body_statements,
|
|
798
|
-
),
|
|
799
|
-
);
|
|
800
|
-
},
|
|
801
|
-
|
|
802
859
|
Component(node, context) {
|
|
803
860
|
let prop_statements;
|
|
804
861
|
|
|
@@ -1389,7 +1446,10 @@ function transform_ts_child(node, context) {
|
|
|
1389
1446
|
|
|
1390
1447
|
function transform_children(children, context) {
|
|
1391
1448
|
const { visit, state, root } = context;
|
|
1392
|
-
const normalized = normalize_children(children);
|
|
1449
|
+
const normalized = normalize_children(children, context);
|
|
1450
|
+
const head_elements = children.filter(
|
|
1451
|
+
(node) => node.type === 'Element' && node.id.type === 'Identifier' && node.id.name === 'head',
|
|
1452
|
+
);
|
|
1393
1453
|
|
|
1394
1454
|
const is_fragment =
|
|
1395
1455
|
normalized.some(
|
|
@@ -1489,6 +1549,8 @@ function transform_children(children, context) {
|
|
|
1489
1549
|
|
|
1490
1550
|
if (node.type === 'Element') {
|
|
1491
1551
|
visit(node, { ...state, flush_node, namespace: state.namespace });
|
|
1552
|
+
} else if (node.type === 'HeadElement') {
|
|
1553
|
+
visit(node, { ...state, flush_node, namespace: state.namespace });
|
|
1492
1554
|
} else if (node.type === 'Text') {
|
|
1493
1555
|
const metadata = { tracking: false, await: false };
|
|
1494
1556
|
const expression = visit(node.expression, { ...state, metadata });
|
|
@@ -1533,6 +1595,20 @@ function transform_children(children, context) {
|
|
|
1533
1595
|
}
|
|
1534
1596
|
}
|
|
1535
1597
|
|
|
1598
|
+
for (const head_element of head_elements) {
|
|
1599
|
+
visit_head_element(head_element, context);
|
|
1600
|
+
}
|
|
1601
|
+
if (context.state.inside_head) {
|
|
1602
|
+
const title_element = children.find(
|
|
1603
|
+
(node) =>
|
|
1604
|
+
node.type === 'Element' && node.id.type === 'Identifier' && node.id.name === 'title',
|
|
1605
|
+
);
|
|
1606
|
+
|
|
1607
|
+
if (title_element) {
|
|
1608
|
+
visit_title_element(title_element, context);
|
|
1609
|
+
}
|
|
1610
|
+
}
|
|
1611
|
+
|
|
1536
1612
|
const template_namespace = state.namespace || 'html';
|
|
1537
1613
|
|
|
1538
1614
|
if (root && initial !== null && template_id !== null) {
|
|
@@ -1559,6 +1635,7 @@ function transform_body(body, { visit, state }) {
|
|
|
1559
1635
|
final: [],
|
|
1560
1636
|
metadata: state.metadata,
|
|
1561
1637
|
namespace: state.namespace || 'html', // Preserve namespace context
|
|
1638
|
+
inside_head: state.inside_head || false,
|
|
1562
1639
|
};
|
|
1563
1640
|
|
|
1564
1641
|
transform_children(body, { visit, state: body_state, root: true });
|
|
@@ -27,7 +27,7 @@ function add_ripple_internal_import(context) {
|
|
|
27
27
|
|
|
28
28
|
function transform_children(children, context) {
|
|
29
29
|
const { visit, state, root } = context;
|
|
30
|
-
const normalized = normalize_children(children);
|
|
30
|
+
const normalized = normalize_children(children, context);
|
|
31
31
|
|
|
32
32
|
for (const node of normalized) {
|
|
33
33
|
if (
|