ripple 0.2.6 → 0.2.7
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/README.md +1 -1
- package/package.json +1 -1
- package/src/compiler/errors.js +20 -22
- package/src/compiler/phases/1-parse/index.js +14 -10
- package/src/compiler/phases/1-parse/style.js +27 -27
- package/src/compiler/phases/2-analyze/index.js +25 -25
- package/src/compiler/phases/2-analyze/prune.js +64 -27
- package/src/compiler/phases/3-transform/index.js +144 -109
- package/src/compiler/phases/3-transform/segments.js +25 -20
- package/src/compiler/phases/3-transform/stylesheet.js +28 -28
- package/src/compiler/scope.js +3 -3
- package/src/compiler/utils.js +7 -9
- package/src/constants.js +1 -2
- package/src/jsx-runtime.d.ts +59 -59
- package/src/jsx-runtime.js +13 -13
- package/src/runtime/array.js +15 -15
- package/src/runtime/internal/client/blocks.js +1 -1
- package/src/runtime/internal/client/constants.js +1 -1
- package/src/runtime/internal/client/events.js +2 -2
- package/src/runtime/internal/client/for.js +5 -5
- package/src/runtime/internal/client/operations.js +1 -1
- package/src/runtime/internal/client/runtime.js +28 -20
- package/src/runtime/internal/client/template.js +1 -1
- package/src/runtime/internal/client/try.js +2 -2
- package/src/utils/ast.js +9 -9
- package/src/utils/builders.js +66 -28
- package/tests/basic.test.ripple +292 -263
- package/tests/composite.test.ripple +125 -0
- package/tests/use.test.ripple +24 -22
- package/types/index.d.ts +1 -1
|
@@ -18,7 +18,7 @@ import {
|
|
|
18
18
|
is_dom_property,
|
|
19
19
|
is_svelte_import,
|
|
20
20
|
is_declared_within_component,
|
|
21
|
-
is_inside_call_expression
|
|
21
|
+
is_inside_call_expression,
|
|
22
22
|
} from '../../utils.js';
|
|
23
23
|
import is_reference from 'is-reference';
|
|
24
24
|
import { extract_paths, object } from '../../../utils/ast.js';
|
|
@@ -44,7 +44,7 @@ function visit_function(node, context) {
|
|
|
44
44
|
return /** @type {FunctionExpression} */ ({
|
|
45
45
|
...node,
|
|
46
46
|
params,
|
|
47
|
-
body: context.visit(node.body, state)
|
|
47
|
+
body: context.visit(node.body, state),
|
|
48
48
|
});
|
|
49
49
|
}
|
|
50
50
|
|
|
@@ -57,7 +57,7 @@ function visit_function(node, context) {
|
|
|
57
57
|
body:
|
|
58
58
|
body.type === 'BlockStatement'
|
|
59
59
|
? { ...body, body: [b.var('__block', b.call('$.scope')), ...body.body] }
|
|
60
|
-
: body
|
|
60
|
+
: body,
|
|
61
61
|
});
|
|
62
62
|
}
|
|
63
63
|
|
|
@@ -145,8 +145,8 @@ const visitors = {
|
|
|
145
145
|
b.thunk({
|
|
146
146
|
...node,
|
|
147
147
|
callee: context.visit(callee),
|
|
148
|
-
arguments: node.arguments.map((arg) => context.visit(arg))
|
|
149
|
-
})
|
|
148
|
+
arguments: node.arguments.map((arg) => context.visit(arg)),
|
|
149
|
+
}),
|
|
150
150
|
);
|
|
151
151
|
},
|
|
152
152
|
|
|
@@ -172,14 +172,14 @@ const visitors = {
|
|
|
172
172
|
'$.get_property',
|
|
173
173
|
context.visit(object),
|
|
174
174
|
property.type === 'Identifier' ? b.literal(property.name) : property,
|
|
175
|
-
node.optional ? b.true : undefined
|
|
175
|
+
node.optional ? b.true : undefined,
|
|
176
176
|
);
|
|
177
177
|
} else {
|
|
178
178
|
return b.call(
|
|
179
179
|
'$.get_property',
|
|
180
180
|
context.visit(object),
|
|
181
181
|
context.visit(property),
|
|
182
|
-
node.optional ? b.true : undefined
|
|
182
|
+
node.optional ? b.true : undefined,
|
|
183
183
|
);
|
|
184
184
|
}
|
|
185
185
|
}
|
|
@@ -213,7 +213,7 @@ const visitors = {
|
|
|
213
213
|
...node,
|
|
214
214
|
optional: true,
|
|
215
215
|
object,
|
|
216
|
-
property: context.visit(node.property)
|
|
216
|
+
property: context.visit(node.property),
|
|
217
217
|
};
|
|
218
218
|
}
|
|
219
219
|
if (metadata.await) {
|
|
@@ -260,22 +260,22 @@ const visitors = {
|
|
|
260
260
|
b.call(
|
|
261
261
|
'$.async_computed',
|
|
262
262
|
b.thunk(context.visit(declarator.init), true),
|
|
263
|
-
b.id('__block')
|
|
264
|
-
)
|
|
265
|
-
)
|
|
266
|
-
)
|
|
263
|
+
b.id('__block'),
|
|
264
|
+
),
|
|
265
|
+
),
|
|
266
|
+
),
|
|
267
267
|
);
|
|
268
268
|
} else if (metadata.tracking && !metadata.await) {
|
|
269
269
|
expression = b.call(
|
|
270
270
|
'$.computed',
|
|
271
271
|
b.thunk(context.visit(declarator.init)),
|
|
272
|
-
b.id('__block')
|
|
272
|
+
b.id('__block'),
|
|
273
273
|
);
|
|
274
274
|
} else {
|
|
275
275
|
expression = b.call(
|
|
276
276
|
'$.tracked',
|
|
277
277
|
declarator.init === null ? undefined : context.visit(declarator.init),
|
|
278
|
-
b.id('__block')
|
|
278
|
+
b.id('__block'),
|
|
279
279
|
);
|
|
280
280
|
}
|
|
281
281
|
|
|
@@ -286,7 +286,7 @@ const visitors = {
|
|
|
286
286
|
} else {
|
|
287
287
|
const paths = extract_paths(declarator.id);
|
|
288
288
|
const has_tracked = paths.some(
|
|
289
|
-
(path) => path.node.type === 'Identifier' && is_tracked_name(path.node.name)
|
|
289
|
+
(path) => path.node.type === 'Identifier' && is_tracked_name(path.node.name),
|
|
290
290
|
);
|
|
291
291
|
|
|
292
292
|
if (!context.state.to_ts) {
|
|
@@ -308,7 +308,7 @@ const visitors = {
|
|
|
308
308
|
expression = b.call(
|
|
309
309
|
'$.computed',
|
|
310
310
|
b.thunk(context.visit(declarator.init)),
|
|
311
|
-
b.id('__block')
|
|
311
|
+
b.id('__block'),
|
|
312
312
|
);
|
|
313
313
|
} else {
|
|
314
314
|
expression = context.visit(declarator.init);
|
|
@@ -347,7 +347,7 @@ const visitors = {
|
|
|
347
347
|
is_boolean_attribute(name) && value === true
|
|
348
348
|
? ''
|
|
349
349
|
: `="${value === true ? '' : escape_html(value, true)}"`
|
|
350
|
-
}
|
|
350
|
+
}`,
|
|
351
351
|
);
|
|
352
352
|
|
|
353
353
|
if (is_spreading) {
|
|
@@ -454,7 +454,7 @@ const visitors = {
|
|
|
454
454
|
const id = state.flush_node();
|
|
455
455
|
|
|
456
456
|
state.init.push(
|
|
457
|
-
b.stmt(b.assignment('=', b.member(id, '__' + event_name), delegated_assignment))
|
|
457
|
+
b.stmt(b.assignment('=', b.member(id, '__' + event_name), delegated_assignment)),
|
|
458
458
|
);
|
|
459
459
|
} else {
|
|
460
460
|
const passive = is_passive_event(event_name);
|
|
@@ -468,9 +468,9 @@ const visitors = {
|
|
|
468
468
|
id,
|
|
469
469
|
handler,
|
|
470
470
|
capture && b.true,
|
|
471
|
-
passive === undefined ? undefined : b.literal(passive)
|
|
472
|
-
)
|
|
473
|
-
)
|
|
471
|
+
passive === undefined ? undefined : b.literal(passive),
|
|
472
|
+
),
|
|
473
|
+
),
|
|
474
474
|
);
|
|
475
475
|
}
|
|
476
476
|
|
|
@@ -487,7 +487,7 @@ const visitors = {
|
|
|
487
487
|
state.update.push(b.stmt(b.assignment('=', b.member(id, attribute), expression)));
|
|
488
488
|
} else {
|
|
489
489
|
state.update.push(
|
|
490
|
-
b.stmt(b.call('$.set_attribute', id, b.literal(attribute), expression))
|
|
490
|
+
b.stmt(b.call('$.set_attribute', id, b.literal(attribute), expression)),
|
|
491
491
|
);
|
|
492
492
|
}
|
|
493
493
|
} else {
|
|
@@ -543,7 +543,7 @@ const visitors = {
|
|
|
543
543
|
if (spread_attributes !== null && spread_attributes.length > 0) {
|
|
544
544
|
const id = state.flush_node();
|
|
545
545
|
state.init.push(
|
|
546
|
-
b.stmt(b.call('$.render_spread', id, b.thunk(b.object(spread_attributes))))
|
|
546
|
+
b.stmt(b.call('$.render_spread', id, b.thunk(b.object(spread_attributes)))),
|
|
547
547
|
);
|
|
548
548
|
}
|
|
549
549
|
|
|
@@ -586,9 +586,9 @@ const visitors = {
|
|
|
586
586
|
b.spread(
|
|
587
587
|
b.call(
|
|
588
588
|
'$.spread_object',
|
|
589
|
-
visit(attr.argument, { ...state, metadata: { ...state.metadata, spread: true } })
|
|
590
|
-
)
|
|
591
|
-
)
|
|
589
|
+
visit(attr.argument, { ...state, metadata: { ...state.metadata, spread: true } }),
|
|
590
|
+
),
|
|
591
|
+
),
|
|
592
592
|
);
|
|
593
593
|
} else if (attr.type === 'UseAttribute') {
|
|
594
594
|
props.push(b.prop('init', b.call('$.use_prop'), visit(attr.argument, state), true));
|
|
@@ -604,9 +604,9 @@ const visitors = {
|
|
|
604
604
|
b.block(
|
|
605
605
|
transform_body(node.children, {
|
|
606
606
|
...context,
|
|
607
|
-
state: { ...context.state, scope: component_scope }
|
|
608
|
-
})
|
|
609
|
-
)
|
|
607
|
+
state: { ...context.state, scope: component_scope },
|
|
608
|
+
}),
|
|
609
|
+
),
|
|
610
610
|
);
|
|
611
611
|
if (children_prop) {
|
|
612
612
|
children_prop.body = b.logical('??', children_prop.body, children);
|
|
@@ -622,9 +622,9 @@ const visitors = {
|
|
|
622
622
|
node.id,
|
|
623
623
|
id,
|
|
624
624
|
b.call('$.tracked_spread_object', b.thunk(b.object(props))),
|
|
625
|
-
b.id('$.active_block')
|
|
626
|
-
)
|
|
627
|
-
)
|
|
625
|
+
b.id('$.active_block'),
|
|
626
|
+
),
|
|
627
|
+
),
|
|
628
628
|
);
|
|
629
629
|
} else if (tracked.length > 0) {
|
|
630
630
|
state.init.push(
|
|
@@ -633,13 +633,13 @@ const visitors = {
|
|
|
633
633
|
node.id,
|
|
634
634
|
id,
|
|
635
635
|
b.call('$.tracked_object', b.object(props), b.array(tracked), b.id('__block')),
|
|
636
|
-
b.id('$.active_block')
|
|
637
|
-
)
|
|
638
|
-
)
|
|
636
|
+
b.id('$.active_block'),
|
|
637
|
+
),
|
|
638
|
+
),
|
|
639
639
|
);
|
|
640
640
|
} else {
|
|
641
641
|
state.init.push(
|
|
642
|
-
b.stmt(b.call(visit(node.id, state), id, b.object(props), b.id('$.active_block')))
|
|
642
|
+
b.stmt(b.call(visit(node.id, state), id, b.object(props), b.id('$.active_block'))),
|
|
643
643
|
);
|
|
644
644
|
}
|
|
645
645
|
}
|
|
@@ -656,7 +656,7 @@ const visitors = {
|
|
|
656
656
|
|
|
657
657
|
const body_statements = transform_body(node.body, {
|
|
658
658
|
...context,
|
|
659
|
-
state: { ...context.state, component: node, metadata }
|
|
659
|
+
state: { ...context.state, component: node, metadata },
|
|
660
660
|
});
|
|
661
661
|
|
|
662
662
|
return b.function(
|
|
@@ -665,8 +665,8 @@ const visitors = {
|
|
|
665
665
|
b.block(
|
|
666
666
|
metadata.await
|
|
667
667
|
? [b.stmt(b.call('$.async', b.thunk(b.block(body_statements), true)))]
|
|
668
|
-
: body_statements
|
|
669
|
-
)
|
|
668
|
+
: body_statements,
|
|
669
|
+
),
|
|
670
670
|
);
|
|
671
671
|
},
|
|
672
672
|
|
|
@@ -685,8 +685,8 @@ const visitors = {
|
|
|
685
685
|
const body_statements = [
|
|
686
686
|
...transform_body(node.body, {
|
|
687
687
|
...context,
|
|
688
|
-
state: { ...context.state, component: node, metadata }
|
|
689
|
-
})
|
|
688
|
+
state: { ...context.state, component: node, metadata },
|
|
689
|
+
}),
|
|
690
690
|
];
|
|
691
691
|
|
|
692
692
|
return b.function(node.id, node.params, b.block(body_statements));
|
|
@@ -719,9 +719,9 @@ const visitors = {
|
|
|
719
719
|
b.stmt(b.call('$.push_component')),
|
|
720
720
|
...transform_body(node.body, {
|
|
721
721
|
...context,
|
|
722
|
-
state: { ...context.state, component: node, metadata }
|
|
722
|
+
state: { ...context.state, component: node, metadata },
|
|
723
723
|
}),
|
|
724
|
-
b.stmt(b.call('$.pop_component'))
|
|
724
|
+
b.stmt(b.call('$.pop_component')),
|
|
725
725
|
];
|
|
726
726
|
|
|
727
727
|
if (node.css !== null) {
|
|
@@ -734,15 +734,15 @@ const visitors = {
|
|
|
734
734
|
? [
|
|
735
735
|
b.id('__anchor'),
|
|
736
736
|
node.params[0].type === 'Identifier' ? node.params[0] : b.id('__props'),
|
|
737
|
-
b.id('__block')
|
|
738
|
-
|
|
737
|
+
b.id('__block'),
|
|
738
|
+
]
|
|
739
739
|
: [b.id('__anchor'), b.id('_'), b.id('__block')],
|
|
740
740
|
b.block([
|
|
741
741
|
...(prop_statements ?? []),
|
|
742
742
|
...(metadata.await
|
|
743
743
|
? [b.stmt(b.call('$.async', b.thunk(b.block(body_statements), true)))]
|
|
744
|
-
: body_statements)
|
|
745
|
-
])
|
|
744
|
+
: body_statements),
|
|
745
|
+
]),
|
|
746
746
|
);
|
|
747
747
|
},
|
|
748
748
|
|
|
@@ -763,7 +763,7 @@ const visitors = {
|
|
|
763
763
|
context.visit(left.object),
|
|
764
764
|
left.computed ? context.visit(left.property) : b.literal(left.property.name),
|
|
765
765
|
visit_assignment_expression(node, context, build_assignment) ?? context.next(),
|
|
766
|
-
b.id('__block')
|
|
766
|
+
b.id('__block'),
|
|
767
767
|
);
|
|
768
768
|
}
|
|
769
769
|
|
|
@@ -798,7 +798,7 @@ const visitors = {
|
|
|
798
798
|
context.visit(argument.object),
|
|
799
799
|
argument.computed ? context.visit(argument.property) : b.literal(argument.property.name),
|
|
800
800
|
b.id('__block'),
|
|
801
|
-
node.operator === '--' ? b.literal(-1) : undefined
|
|
801
|
+
node.operator === '--' ? b.literal(-1) : undefined,
|
|
802
802
|
);
|
|
803
803
|
}
|
|
804
804
|
|
|
@@ -834,7 +834,7 @@ const visitors = {
|
|
|
834
834
|
if (metadata.tracking) {
|
|
835
835
|
properties.push({
|
|
836
836
|
...tracked_property,
|
|
837
|
-
value: b.call('$.computed_property', b.thunk(tracked_property.value), b.id('__block'))
|
|
837
|
+
value: b.call('$.computed_property', b.thunk(tracked_property.value), b.id('__block')),
|
|
838
838
|
});
|
|
839
839
|
} else {
|
|
840
840
|
properties.push(tracked_property);
|
|
@@ -920,13 +920,13 @@ const visitors = {
|
|
|
920
920
|
b.block(
|
|
921
921
|
transform_body(node.body.body, {
|
|
922
922
|
...context,
|
|
923
|
-
state: { ...context.state, scope: body_scope }
|
|
924
|
-
})
|
|
925
|
-
)
|
|
923
|
+
state: { ...context.state, scope: body_scope },
|
|
924
|
+
}),
|
|
925
|
+
),
|
|
926
926
|
),
|
|
927
|
-
b.literal(is_controlled ? IS_CONTROLLED : 0)
|
|
928
|
-
)
|
|
929
|
-
)
|
|
927
|
+
b.literal(is_controlled ? IS_CONTROLLED : 0),
|
|
928
|
+
),
|
|
929
|
+
),
|
|
930
930
|
);
|
|
931
931
|
},
|
|
932
932
|
|
|
@@ -944,8 +944,8 @@ const visitors = {
|
|
|
944
944
|
const consequent = b.block(
|
|
945
945
|
transform_body(node.consequent.body, {
|
|
946
946
|
...context,
|
|
947
|
-
state: { ...context.state, scope: consequent_scope }
|
|
948
|
-
})
|
|
947
|
+
state: { ...context.state, scope: consequent_scope },
|
|
948
|
+
}),
|
|
949
949
|
);
|
|
950
950
|
const consequent_id = context.state.scope.generate('consequent');
|
|
951
951
|
|
|
@@ -962,8 +962,8 @@ const visitors = {
|
|
|
962
962
|
const alternate = b.block(
|
|
963
963
|
transform_body(alternate_body, {
|
|
964
964
|
...context,
|
|
965
|
-
state: { ...context.state, scope: alternate_scope }
|
|
966
|
-
})
|
|
965
|
+
state: { ...context.state, scope: alternate_scope },
|
|
966
|
+
}),
|
|
967
967
|
);
|
|
968
968
|
alternate_id = context.state.scope.generate('alternate');
|
|
969
969
|
statements.push(b.var(b.id(alternate_id), b.arrow([b.id('__anchor')], alternate)));
|
|
@@ -985,15 +985,15 @@ const visitors = {
|
|
|
985
985
|
b.call(
|
|
986
986
|
b.id('__render'),
|
|
987
987
|
b.id(alternate_id),
|
|
988
|
-
node.alternate ? b.literal(false) : undefined
|
|
989
|
-
)
|
|
990
|
-
|
|
991
|
-
: undefined
|
|
992
|
-
)
|
|
993
|
-
])
|
|
994
|
-
)
|
|
995
|
-
)
|
|
996
|
-
)
|
|
988
|
+
node.alternate ? b.literal(false) : undefined,
|
|
989
|
+
),
|
|
990
|
+
)
|
|
991
|
+
: undefined,
|
|
992
|
+
),
|
|
993
|
+
]),
|
|
994
|
+
),
|
|
995
|
+
),
|
|
996
|
+
),
|
|
997
997
|
);
|
|
998
998
|
|
|
999
999
|
context.state.init.push(b.block(statements));
|
|
@@ -1010,7 +1010,7 @@ const visitors = {
|
|
|
1010
1010
|
const metadata = { await: false };
|
|
1011
1011
|
let body = transform_body(node.block.body, {
|
|
1012
1012
|
...context,
|
|
1013
|
-
state: { ...context.state, metadata }
|
|
1013
|
+
state: { ...context.state, metadata },
|
|
1014
1014
|
});
|
|
1015
1015
|
|
|
1016
1016
|
if (metadata.await) {
|
|
@@ -1027,13 +1027,13 @@ const visitors = {
|
|
|
1027
1027
|
? b.literal(null)
|
|
1028
1028
|
: b.arrow(
|
|
1029
1029
|
[b.id('__anchor'), ...(node.handler.param ? [node.handler.param] : [])],
|
|
1030
|
-
b.block(transform_body(node.handler.body.body, context))
|
|
1031
|
-
|
|
1030
|
+
b.block(transform_body(node.handler.body.body, context)),
|
|
1031
|
+
),
|
|
1032
1032
|
node.async === null
|
|
1033
1033
|
? undefined
|
|
1034
|
-
: b.arrow([b.id('__anchor')], b.block(transform_body(node.async.body, context)))
|
|
1035
|
-
)
|
|
1036
|
-
)
|
|
1034
|
+
: b.arrow([b.id('__anchor')], b.block(transform_body(node.async.body, context))),
|
|
1035
|
+
),
|
|
1036
|
+
),
|
|
1037
1037
|
);
|
|
1038
1038
|
},
|
|
1039
1039
|
|
|
@@ -1065,9 +1065,9 @@ const visitors = {
|
|
|
1065
1065
|
b.call(
|
|
1066
1066
|
context.visit(identifer),
|
|
1067
1067
|
id,
|
|
1068
|
-
...node.expression.arguments.map((arg) => context.visit(arg, context.state))
|
|
1069
|
-
)
|
|
1070
|
-
)
|
|
1068
|
+
...node.expression.arguments.map((arg) => context.visit(arg, context.state)),
|
|
1069
|
+
),
|
|
1070
|
+
),
|
|
1071
1071
|
);
|
|
1072
1072
|
},
|
|
1073
1073
|
|
|
@@ -1119,7 +1119,7 @@ const visitors = {
|
|
|
1119
1119
|
}
|
|
1120
1120
|
|
|
1121
1121
|
return { ...node, body: statements };
|
|
1122
|
-
}
|
|
1122
|
+
},
|
|
1123
1123
|
};
|
|
1124
1124
|
|
|
1125
1125
|
/**
|
|
@@ -1195,7 +1195,7 @@ function transform_ts_child(node, context) {
|
|
|
1195
1195
|
const type = node.id.name;
|
|
1196
1196
|
const children = [];
|
|
1197
1197
|
let has_children_props = false;
|
|
1198
|
-
|
|
1198
|
+
|
|
1199
1199
|
// Filter out UseAttributes and handle them separately
|
|
1200
1200
|
const use_attributes = [];
|
|
1201
1201
|
const attributes = node.attributes
|
|
@@ -1240,9 +1240,9 @@ function transform_ts_child(node, context) {
|
|
|
1240
1240
|
b.block(
|
|
1241
1241
|
transform_body(node.children, {
|
|
1242
1242
|
...context,
|
|
1243
|
-
state: { ...state, scope: component_scope }
|
|
1244
|
-
})
|
|
1245
|
-
)
|
|
1243
|
+
state: { ...state, scope: component_scope },
|
|
1244
|
+
}),
|
|
1245
|
+
),
|
|
1246
1246
|
);
|
|
1247
1247
|
|
|
1248
1248
|
if (is_dom_element) {
|
|
@@ -1267,25 +1267,25 @@ function transform_ts_child(node, context) {
|
|
|
1267
1267
|
closing_type.loc = {
|
|
1268
1268
|
start: {
|
|
1269
1269
|
line: node.loc.end.line,
|
|
1270
|
-
column: node.loc.end.column - type.length - 1
|
|
1270
|
+
column: node.loc.end.column - type.length - 1,
|
|
1271
1271
|
},
|
|
1272
1272
|
end: {
|
|
1273
1273
|
line: node.loc.end.line,
|
|
1274
|
-
column: node.loc.end.column - 1
|
|
1275
|
-
}
|
|
1274
|
+
column: node.loc.end.column - 1,
|
|
1275
|
+
},
|
|
1276
1276
|
};
|
|
1277
1277
|
}
|
|
1278
1278
|
|
|
1279
1279
|
state.init.push(
|
|
1280
|
-
b.stmt(b.jsx_element(opening_type, attributes, children, node.selfClosing, closing_type))
|
|
1280
|
+
b.stmt(b.jsx_element(opening_type, attributes, children, node.selfClosing, closing_type)),
|
|
1281
1281
|
);
|
|
1282
1282
|
} else if (node.type === 'IfStatement') {
|
|
1283
1283
|
const consequent_scope = context.state.scopes.get(node.consequent);
|
|
1284
1284
|
const consequent = b.block(
|
|
1285
1285
|
transform_body(node.consequent.body, {
|
|
1286
1286
|
...context,
|
|
1287
|
-
state: { ...context.state, scope: consequent_scope }
|
|
1288
|
-
})
|
|
1287
|
+
state: { ...context.state, scope: consequent_scope },
|
|
1288
|
+
}),
|
|
1289
1289
|
);
|
|
1290
1290
|
|
|
1291
1291
|
let alternate;
|
|
@@ -1299,8 +1299,8 @@ function transform_ts_child(node, context) {
|
|
|
1299
1299
|
alternate = b.block(
|
|
1300
1300
|
transform_body(alternate_body, {
|
|
1301
1301
|
...context,
|
|
1302
|
-
state: { ...context.state, scope: alternate_scope }
|
|
1303
|
-
})
|
|
1302
|
+
state: { ...context.state, scope: alternate_scope },
|
|
1303
|
+
}),
|
|
1304
1304
|
);
|
|
1305
1305
|
}
|
|
1306
1306
|
|
|
@@ -1310,11 +1310,44 @@ function transform_ts_child(node, context) {
|
|
|
1310
1310
|
const body = b.block(
|
|
1311
1311
|
transform_body(node.body.body, {
|
|
1312
1312
|
...context,
|
|
1313
|
-
state: { ...context.state, scope: body_scope }
|
|
1314
|
-
})
|
|
1313
|
+
state: { ...context.state, scope: body_scope },
|
|
1314
|
+
}),
|
|
1315
1315
|
);
|
|
1316
1316
|
|
|
1317
1317
|
state.init.push(b.for_of(visit(node.left), visit(node.right), body, node.await));
|
|
1318
|
+
} else if (node.type === 'TryStatement') {
|
|
1319
|
+
const try_scope = context.state.scopes.get(node.block);
|
|
1320
|
+
const try_body = b.block(
|
|
1321
|
+
transform_body(node.block.body, {
|
|
1322
|
+
...context,
|
|
1323
|
+
state: { ...context.state, scope: try_scope },
|
|
1324
|
+
}),
|
|
1325
|
+
);
|
|
1326
|
+
|
|
1327
|
+
let catch_handler = null;
|
|
1328
|
+
if (node.handler) {
|
|
1329
|
+
const catch_scope = context.state.scopes.get(node.handler.body);
|
|
1330
|
+
const catch_body = b.block(
|
|
1331
|
+
transform_body(node.handler.body.body, {
|
|
1332
|
+
...context,
|
|
1333
|
+
state: { ...context.state, scope: catch_scope },
|
|
1334
|
+
}),
|
|
1335
|
+
);
|
|
1336
|
+
catch_handler = b.catch_clause(node.handler.param || null, catch_body);
|
|
1337
|
+
}
|
|
1338
|
+
|
|
1339
|
+
let finally_block = null;
|
|
1340
|
+
if (node.finalizer) {
|
|
1341
|
+
const finally_scope = context.state.scopes.get(node.finalizer);
|
|
1342
|
+
finally_block = b.block(
|
|
1343
|
+
transform_body(node.finalizer.body, {
|
|
1344
|
+
...context,
|
|
1345
|
+
state: { ...context.state, scope: finally_scope },
|
|
1346
|
+
}),
|
|
1347
|
+
);
|
|
1348
|
+
}
|
|
1349
|
+
|
|
1350
|
+
state.init.push(b.try(try_body, catch_handler, finally_block));
|
|
1318
1351
|
} else if (node.type === 'RenderFragment') {
|
|
1319
1352
|
const identifer = node.expression.callee;
|
|
1320
1353
|
|
|
@@ -1322,9 +1355,9 @@ function transform_ts_child(node, context) {
|
|
|
1322
1355
|
b.stmt(
|
|
1323
1356
|
b.call(
|
|
1324
1357
|
context.visit(identifer),
|
|
1325
|
-
...node.expression.arguments.map((arg) => context.visit(arg, context.state))
|
|
1326
|
-
)
|
|
1327
|
-
)
|
|
1358
|
+
...node.expression.arguments.map((arg) => context.visit(arg, context.state)),
|
|
1359
|
+
),
|
|
1360
|
+
),
|
|
1328
1361
|
);
|
|
1329
1362
|
} else {
|
|
1330
1363
|
throw new Error('TODO');
|
|
@@ -1348,10 +1381,10 @@ function transform_children(children, { visit, state, root }) {
|
|
|
1348
1381
|
(node.type === 'Element' &&
|
|
1349
1382
|
(node.id.type !== 'Identifier' ||
|
|
1350
1383
|
node.id.name[0].toLowerCase() !== node.id.name[0] ||
|
|
1351
|
-
node.id.name[0] === '$'))
|
|
1384
|
+
node.id.name[0] === '$')),
|
|
1352
1385
|
) ||
|
|
1353
1386
|
normalized.filter(
|
|
1354
|
-
(node) => node.type !== 'VariableDeclaration' && node.type !== 'EmptyStatement'
|
|
1387
|
+
(node) => node.type !== 'VariableDeclaration' && node.type !== 'EmptyStatement',
|
|
1355
1388
|
).length > 1;
|
|
1356
1389
|
let initial = null;
|
|
1357
1390
|
let prev = null;
|
|
@@ -1365,8 +1398,8 @@ function transform_children(children, { visit, state, root }) {
|
|
|
1365
1398
|
node.id.name[0] !== '$'
|
|
1366
1399
|
? state.scope.generate(node.id.name)
|
|
1367
1400
|
: node.type == 'Text'
|
|
1368
|
-
|
|
1369
|
-
|
|
1401
|
+
? state.scope.generate('text')
|
|
1402
|
+
: state.scope.generate('node'),
|
|
1370
1403
|
);
|
|
1371
1404
|
};
|
|
1372
1405
|
|
|
@@ -1464,7 +1497,7 @@ function transform_children(children, { visit, state, root }) {
|
|
|
1464
1497
|
} else {
|
|
1465
1498
|
const id = state.flush_node();
|
|
1466
1499
|
state.init.push(
|
|
1467
|
-
b.stmt(b.assignment('=', b.member(id, b.id('textContent')), expression))
|
|
1500
|
+
b.stmt(b.assignment('=', b.member(id, b.id('textContent')), expression)),
|
|
1468
1501
|
);
|
|
1469
1502
|
}
|
|
1470
1503
|
} else {
|
|
@@ -1499,7 +1532,7 @@ function transform_children(children, { visit, state, root }) {
|
|
|
1499
1532
|
const flags = is_fragment ? b.literal(TEMPLATE_FRAGMENT) : b.literal(0);
|
|
1500
1533
|
state.final.push(b.stmt(b.call('$.append', b.id('__anchor'), initial)));
|
|
1501
1534
|
state.hoisted.push(
|
|
1502
|
-
b.var(template_id, b.call('$.template', join_template(state.template), flags))
|
|
1535
|
+
b.var(template_id, b.call('$.template', join_template(state.template), flags)),
|
|
1503
1536
|
);
|
|
1504
1537
|
}
|
|
1505
1538
|
}
|
|
@@ -1512,7 +1545,7 @@ function transform_body(body, { visit, state }) {
|
|
|
1512
1545
|
init: [],
|
|
1513
1546
|
update: [],
|
|
1514
1547
|
final: [],
|
|
1515
|
-
metadata: state.metadata
|
|
1548
|
+
metadata: state.metadata,
|
|
1516
1549
|
};
|
|
1517
1550
|
|
|
1518
1551
|
transform_children(body, { visit, state: body_state, root: true });
|
|
@@ -1538,7 +1571,7 @@ export function transform(filename, source, analysis, to_ts) {
|
|
|
1538
1571
|
scope: analysis.scope,
|
|
1539
1572
|
scopes: analysis.scopes,
|
|
1540
1573
|
stylesheets: [],
|
|
1541
|
-
to_ts
|
|
1574
|
+
to_ts,
|
|
1542
1575
|
};
|
|
1543
1576
|
|
|
1544
1577
|
const program = /** @type {ESTree.Program} */ (
|
|
@@ -1555,19 +1588,21 @@ export function transform(filename, source, analysis, to_ts) {
|
|
|
1555
1588
|
|
|
1556
1589
|
if (state.events.size > 0) {
|
|
1557
1590
|
program.body.push(
|
|
1558
|
-
b.stmt(
|
|
1591
|
+
b.stmt(
|
|
1592
|
+
b.call('$.delegate', b.array(Array.from(state.events).map((name) => b.literal(name)))),
|
|
1593
|
+
),
|
|
1559
1594
|
);
|
|
1560
1595
|
}
|
|
1561
1596
|
|
|
1562
1597
|
const js = print(
|
|
1563
1598
|
program,
|
|
1564
1599
|
tsx({
|
|
1565
|
-
comments: analysis.ast.comments || []
|
|
1600
|
+
comments: analysis.ast.comments || [],
|
|
1566
1601
|
}),
|
|
1567
1602
|
{
|
|
1568
1603
|
sourceMapContent: source,
|
|
1569
|
-
sourceMapSource: path.basename(filename)
|
|
1570
|
-
}
|
|
1604
|
+
sourceMapSource: path.basename(filename),
|
|
1605
|
+
},
|
|
1571
1606
|
);
|
|
1572
1607
|
|
|
1573
1608
|
const css = render_stylesheets(state.stylesheets);
|
|
@@ -1575,6 +1610,6 @@ export function transform(filename, source, analysis, to_ts) {
|
|
|
1575
1610
|
return {
|
|
1576
1611
|
ast: program,
|
|
1577
1612
|
js,
|
|
1578
|
-
css
|
|
1613
|
+
css,
|
|
1579
1614
|
};
|
|
1580
1615
|
}
|