ripple 0.2.83 → 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 -1121
- package/src/compiler/phases/2-analyze/index.js +561 -523
- package/src/compiler/phases/3-transform/client/index.js +84 -28
- package/src/compiler/phases/3-transform/server/index.js +1 -1
- package/src/compiler/utils.js +613 -595
- 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 +42 -35
- package/src/runtime/internal/client/operations.js +34 -30
- package/src/runtime/internal/client/runtime.js +22 -27
- package/tests/client/basic.test.ripple +105 -11
- 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,
|
|
@@ -423,9 +475,11 @@ const visitors = {
|
|
|
423
475
|
FunctionDeclaration(node, context) {
|
|
424
476
|
return visit_function(node, context);
|
|
425
477
|
},
|
|
478
|
+
|
|
426
479
|
ArrowFunctionExpression(node, context) {
|
|
427
480
|
return visit_function(node, context);
|
|
428
481
|
},
|
|
482
|
+
|
|
429
483
|
FunctionExpression(node, context) {
|
|
430
484
|
return visit_function(node, context);
|
|
431
485
|
},
|
|
@@ -433,6 +487,11 @@ const visitors = {
|
|
|
433
487
|
Element(node, context) {
|
|
434
488
|
const { state, visit } = context;
|
|
435
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
|
+
|
|
436
495
|
const is_dom_element = is_element_dom_element(node);
|
|
437
496
|
const is_spreading = node.attributes.some((attr) => attr.type === 'SpreadAttribute');
|
|
438
497
|
const spread_attributes = is_spreading ? [] : null;
|
|
@@ -797,29 +856,6 @@ const visitors = {
|
|
|
797
856
|
}
|
|
798
857
|
},
|
|
799
858
|
|
|
800
|
-
Fragment(node, context) {
|
|
801
|
-
if (!context.state.to_ts) {
|
|
802
|
-
add_ripple_internal_import(context);
|
|
803
|
-
}
|
|
804
|
-
|
|
805
|
-
const metadata = { await: false };
|
|
806
|
-
|
|
807
|
-
const body_statements = transform_body(node.body, {
|
|
808
|
-
...context,
|
|
809
|
-
state: { ...context.state, component: node, metadata },
|
|
810
|
-
});
|
|
811
|
-
|
|
812
|
-
return b.function(
|
|
813
|
-
node.id,
|
|
814
|
-
[b.id('__anchor'), ...node.params.map((param) => context.visit(param, context.state))],
|
|
815
|
-
b.block(
|
|
816
|
-
metadata.await
|
|
817
|
-
? [b.stmt(b.call('_$_.async', b.thunk(b.block(body_statements), true)))]
|
|
818
|
-
: body_statements,
|
|
819
|
-
),
|
|
820
|
-
);
|
|
821
|
-
},
|
|
822
|
-
|
|
823
859
|
Component(node, context) {
|
|
824
860
|
let prop_statements;
|
|
825
861
|
|
|
@@ -1410,7 +1446,10 @@ function transform_ts_child(node, context) {
|
|
|
1410
1446
|
|
|
1411
1447
|
function transform_children(children, context) {
|
|
1412
1448
|
const { visit, state, root } = context;
|
|
1413
|
-
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
|
+
);
|
|
1414
1453
|
|
|
1415
1454
|
const is_fragment =
|
|
1416
1455
|
normalized.some(
|
|
@@ -1510,6 +1549,8 @@ function transform_children(children, context) {
|
|
|
1510
1549
|
|
|
1511
1550
|
if (node.type === 'Element') {
|
|
1512
1551
|
visit(node, { ...state, flush_node, namespace: state.namespace });
|
|
1552
|
+
} else if (node.type === 'HeadElement') {
|
|
1553
|
+
visit(node, { ...state, flush_node, namespace: state.namespace });
|
|
1513
1554
|
} else if (node.type === 'Text') {
|
|
1514
1555
|
const metadata = { tracking: false, await: false };
|
|
1515
1556
|
const expression = visit(node.expression, { ...state, metadata });
|
|
@@ -1554,6 +1595,20 @@ function transform_children(children, context) {
|
|
|
1554
1595
|
}
|
|
1555
1596
|
}
|
|
1556
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
|
+
|
|
1557
1612
|
const template_namespace = state.namespace || 'html';
|
|
1558
1613
|
|
|
1559
1614
|
if (root && initial !== null && template_id !== null) {
|
|
@@ -1580,6 +1635,7 @@ function transform_body(body, { visit, state }) {
|
|
|
1580
1635
|
final: [],
|
|
1581
1636
|
metadata: state.metadata,
|
|
1582
1637
|
namespace: state.namespace || 'html', // Preserve namespace context
|
|
1638
|
+
inside_head: state.inside_head || false,
|
|
1583
1639
|
};
|
|
1584
1640
|
|
|
1585
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 (
|