ripple 0.2.6 → 0.2.8
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 +21 -19
- 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 +150 -113
- 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/index.js +2 -0
- package/src/runtime/internal/client/blocks.js +16 -5
- 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 +6 -7
- package/src/runtime/internal/client/operations.js +1 -1
- package/src/runtime/internal/client/runtime.js +41 -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/__snapshots__/for.test.ripple.snap +81 -0
- package/tests/basic.test.ripple +292 -263
- package/tests/composite.test.ripple +151 -0
- package/tests/for.test.ripple +58 -0
- package/tests/ref.test.ripple +52 -0
- package/tests/use.test.ripple +24 -22
- package/types/index.d.ts +7 -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
|
|
|
@@ -806,10 +806,12 @@ const visitors = {
|
|
|
806
806
|
const binding = context.state.scope.get(left.name);
|
|
807
807
|
const transformers = left && binding?.transform;
|
|
808
808
|
|
|
809
|
-
if (left === argument
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
809
|
+
if (left === argument ) {
|
|
810
|
+
if (transformers?.update) {
|
|
811
|
+
return transformers.update(node);
|
|
812
|
+
} else if (binding.kind === 'prop') {
|
|
813
|
+
throw new Error('Cannot update component prop property, component props are not writable');
|
|
814
|
+
}
|
|
813
815
|
}
|
|
814
816
|
|
|
815
817
|
context.next();
|
|
@@ -834,7 +836,7 @@ const visitors = {
|
|
|
834
836
|
if (metadata.tracking) {
|
|
835
837
|
properties.push({
|
|
836
838
|
...tracked_property,
|
|
837
|
-
value: b.call('$.computed_property', b.thunk(tracked_property.value), b.id('__block'))
|
|
839
|
+
value: b.call('$.computed_property', b.thunk(tracked_property.value), b.id('__block')),
|
|
838
840
|
});
|
|
839
841
|
} else {
|
|
840
842
|
properties.push(tracked_property);
|
|
@@ -920,13 +922,13 @@ const visitors = {
|
|
|
920
922
|
b.block(
|
|
921
923
|
transform_body(node.body.body, {
|
|
922
924
|
...context,
|
|
923
|
-
state: { ...context.state, scope: body_scope }
|
|
924
|
-
})
|
|
925
|
-
)
|
|
925
|
+
state: { ...context.state, scope: body_scope },
|
|
926
|
+
}),
|
|
927
|
+
),
|
|
926
928
|
),
|
|
927
|
-
b.literal(is_controlled ? IS_CONTROLLED : 0)
|
|
928
|
-
)
|
|
929
|
-
)
|
|
929
|
+
b.literal(is_controlled ? IS_CONTROLLED : 0),
|
|
930
|
+
),
|
|
931
|
+
),
|
|
930
932
|
);
|
|
931
933
|
},
|
|
932
934
|
|
|
@@ -944,8 +946,8 @@ const visitors = {
|
|
|
944
946
|
const consequent = b.block(
|
|
945
947
|
transform_body(node.consequent.body, {
|
|
946
948
|
...context,
|
|
947
|
-
state: { ...context.state, scope: consequent_scope }
|
|
948
|
-
})
|
|
949
|
+
state: { ...context.state, scope: consequent_scope },
|
|
950
|
+
}),
|
|
949
951
|
);
|
|
950
952
|
const consequent_id = context.state.scope.generate('consequent');
|
|
951
953
|
|
|
@@ -962,8 +964,8 @@ const visitors = {
|
|
|
962
964
|
const alternate = b.block(
|
|
963
965
|
transform_body(alternate_body, {
|
|
964
966
|
...context,
|
|
965
|
-
state: { ...context.state, scope: alternate_scope }
|
|
966
|
-
})
|
|
967
|
+
state: { ...context.state, scope: alternate_scope },
|
|
968
|
+
}),
|
|
967
969
|
);
|
|
968
970
|
alternate_id = context.state.scope.generate('alternate');
|
|
969
971
|
statements.push(b.var(b.id(alternate_id), b.arrow([b.id('__anchor')], alternate)));
|
|
@@ -985,15 +987,15 @@ const visitors = {
|
|
|
985
987
|
b.call(
|
|
986
988
|
b.id('__render'),
|
|
987
989
|
b.id(alternate_id),
|
|
988
|
-
node.alternate ? b.literal(false) : undefined
|
|
989
|
-
)
|
|
990
|
-
|
|
991
|
-
: undefined
|
|
992
|
-
)
|
|
993
|
-
])
|
|
994
|
-
)
|
|
995
|
-
)
|
|
996
|
-
)
|
|
990
|
+
node.alternate ? b.literal(false) : undefined,
|
|
991
|
+
),
|
|
992
|
+
)
|
|
993
|
+
: undefined,
|
|
994
|
+
),
|
|
995
|
+
]),
|
|
996
|
+
),
|
|
997
|
+
),
|
|
998
|
+
),
|
|
997
999
|
);
|
|
998
1000
|
|
|
999
1001
|
context.state.init.push(b.block(statements));
|
|
@@ -1010,7 +1012,7 @@ const visitors = {
|
|
|
1010
1012
|
const metadata = { await: false };
|
|
1011
1013
|
let body = transform_body(node.block.body, {
|
|
1012
1014
|
...context,
|
|
1013
|
-
state: { ...context.state, metadata }
|
|
1015
|
+
state: { ...context.state, metadata },
|
|
1014
1016
|
});
|
|
1015
1017
|
|
|
1016
1018
|
if (metadata.await) {
|
|
@@ -1027,13 +1029,13 @@ const visitors = {
|
|
|
1027
1029
|
? b.literal(null)
|
|
1028
1030
|
: b.arrow(
|
|
1029
1031
|
[b.id('__anchor'), ...(node.handler.param ? [node.handler.param] : [])],
|
|
1030
|
-
b.block(transform_body(node.handler.body.body, context))
|
|
1031
|
-
|
|
1032
|
+
b.block(transform_body(node.handler.body.body, context)),
|
|
1033
|
+
),
|
|
1032
1034
|
node.async === null
|
|
1033
1035
|
? undefined
|
|
1034
|
-
: b.arrow([b.id('__anchor')], b.block(transform_body(node.async.body, context)))
|
|
1035
|
-
)
|
|
1036
|
-
)
|
|
1036
|
+
: b.arrow([b.id('__anchor')], b.block(transform_body(node.async.body, context))),
|
|
1037
|
+
),
|
|
1038
|
+
),
|
|
1037
1039
|
);
|
|
1038
1040
|
},
|
|
1039
1041
|
|
|
@@ -1065,9 +1067,9 @@ const visitors = {
|
|
|
1065
1067
|
b.call(
|
|
1066
1068
|
context.visit(identifer),
|
|
1067
1069
|
id,
|
|
1068
|
-
...node.expression.arguments.map((arg) => context.visit(arg, context.state))
|
|
1069
|
-
)
|
|
1070
|
-
)
|
|
1070
|
+
...node.expression.arguments.map((arg) => context.visit(arg, context.state)),
|
|
1071
|
+
),
|
|
1072
|
+
),
|
|
1071
1073
|
);
|
|
1072
1074
|
},
|
|
1073
1075
|
|
|
@@ -1119,7 +1121,7 @@ const visitors = {
|
|
|
1119
1121
|
}
|
|
1120
1122
|
|
|
1121
1123
|
return { ...node, body: statements };
|
|
1122
|
-
}
|
|
1124
|
+
},
|
|
1123
1125
|
};
|
|
1124
1126
|
|
|
1125
1127
|
/**
|
|
@@ -1195,7 +1197,7 @@ function transform_ts_child(node, context) {
|
|
|
1195
1197
|
const type = node.id.name;
|
|
1196
1198
|
const children = [];
|
|
1197
1199
|
let has_children_props = false;
|
|
1198
|
-
|
|
1200
|
+
|
|
1199
1201
|
// Filter out UseAttributes and handle them separately
|
|
1200
1202
|
const use_attributes = [];
|
|
1201
1203
|
const attributes = node.attributes
|
|
@@ -1240,9 +1242,9 @@ function transform_ts_child(node, context) {
|
|
|
1240
1242
|
b.block(
|
|
1241
1243
|
transform_body(node.children, {
|
|
1242
1244
|
...context,
|
|
1243
|
-
state: { ...state, scope: component_scope }
|
|
1244
|
-
})
|
|
1245
|
-
)
|
|
1245
|
+
state: { ...state, scope: component_scope },
|
|
1246
|
+
}),
|
|
1247
|
+
),
|
|
1246
1248
|
);
|
|
1247
1249
|
|
|
1248
1250
|
if (is_dom_element) {
|
|
@@ -1267,25 +1269,25 @@ function transform_ts_child(node, context) {
|
|
|
1267
1269
|
closing_type.loc = {
|
|
1268
1270
|
start: {
|
|
1269
1271
|
line: node.loc.end.line,
|
|
1270
|
-
column: node.loc.end.column - type.length - 1
|
|
1272
|
+
column: node.loc.end.column - type.length - 1,
|
|
1271
1273
|
},
|
|
1272
1274
|
end: {
|
|
1273
1275
|
line: node.loc.end.line,
|
|
1274
|
-
column: node.loc.end.column - 1
|
|
1275
|
-
}
|
|
1276
|
+
column: node.loc.end.column - 1,
|
|
1277
|
+
},
|
|
1276
1278
|
};
|
|
1277
1279
|
}
|
|
1278
1280
|
|
|
1279
1281
|
state.init.push(
|
|
1280
|
-
b.stmt(b.jsx_element(opening_type, attributes, children, node.selfClosing, closing_type))
|
|
1282
|
+
b.stmt(b.jsx_element(opening_type, attributes, children, node.selfClosing, closing_type)),
|
|
1281
1283
|
);
|
|
1282
1284
|
} else if (node.type === 'IfStatement') {
|
|
1283
1285
|
const consequent_scope = context.state.scopes.get(node.consequent);
|
|
1284
1286
|
const consequent = b.block(
|
|
1285
1287
|
transform_body(node.consequent.body, {
|
|
1286
1288
|
...context,
|
|
1287
|
-
state: { ...context.state, scope: consequent_scope }
|
|
1288
|
-
})
|
|
1289
|
+
state: { ...context.state, scope: consequent_scope },
|
|
1290
|
+
}),
|
|
1289
1291
|
);
|
|
1290
1292
|
|
|
1291
1293
|
let alternate;
|
|
@@ -1299,8 +1301,8 @@ function transform_ts_child(node, context) {
|
|
|
1299
1301
|
alternate = b.block(
|
|
1300
1302
|
transform_body(alternate_body, {
|
|
1301
1303
|
...context,
|
|
1302
|
-
state: { ...context.state, scope: alternate_scope }
|
|
1303
|
-
})
|
|
1304
|
+
state: { ...context.state, scope: alternate_scope },
|
|
1305
|
+
}),
|
|
1304
1306
|
);
|
|
1305
1307
|
}
|
|
1306
1308
|
|
|
@@ -1310,11 +1312,44 @@ function transform_ts_child(node, context) {
|
|
|
1310
1312
|
const body = b.block(
|
|
1311
1313
|
transform_body(node.body.body, {
|
|
1312
1314
|
...context,
|
|
1313
|
-
state: { ...context.state, scope: body_scope }
|
|
1314
|
-
})
|
|
1315
|
+
state: { ...context.state, scope: body_scope },
|
|
1316
|
+
}),
|
|
1315
1317
|
);
|
|
1316
1318
|
|
|
1317
1319
|
state.init.push(b.for_of(visit(node.left), visit(node.right), body, node.await));
|
|
1320
|
+
} else if (node.type === 'TryStatement') {
|
|
1321
|
+
const try_scope = context.state.scopes.get(node.block);
|
|
1322
|
+
const try_body = b.block(
|
|
1323
|
+
transform_body(node.block.body, {
|
|
1324
|
+
...context,
|
|
1325
|
+
state: { ...context.state, scope: try_scope },
|
|
1326
|
+
}),
|
|
1327
|
+
);
|
|
1328
|
+
|
|
1329
|
+
let catch_handler = null;
|
|
1330
|
+
if (node.handler) {
|
|
1331
|
+
const catch_scope = context.state.scopes.get(node.handler.body);
|
|
1332
|
+
const catch_body = b.block(
|
|
1333
|
+
transform_body(node.handler.body.body, {
|
|
1334
|
+
...context,
|
|
1335
|
+
state: { ...context.state, scope: catch_scope },
|
|
1336
|
+
}),
|
|
1337
|
+
);
|
|
1338
|
+
catch_handler = b.catch_clause(node.handler.param || null, catch_body);
|
|
1339
|
+
}
|
|
1340
|
+
|
|
1341
|
+
let finally_block = null;
|
|
1342
|
+
if (node.finalizer) {
|
|
1343
|
+
const finally_scope = context.state.scopes.get(node.finalizer);
|
|
1344
|
+
finally_block = b.block(
|
|
1345
|
+
transform_body(node.finalizer.body, {
|
|
1346
|
+
...context,
|
|
1347
|
+
state: { ...context.state, scope: finally_scope },
|
|
1348
|
+
}),
|
|
1349
|
+
);
|
|
1350
|
+
}
|
|
1351
|
+
|
|
1352
|
+
state.init.push(b.try(try_body, catch_handler, finally_block));
|
|
1318
1353
|
} else if (node.type === 'RenderFragment') {
|
|
1319
1354
|
const identifer = node.expression.callee;
|
|
1320
1355
|
|
|
@@ -1322,9 +1357,9 @@ function transform_ts_child(node, context) {
|
|
|
1322
1357
|
b.stmt(
|
|
1323
1358
|
b.call(
|
|
1324
1359
|
context.visit(identifer),
|
|
1325
|
-
...node.expression.arguments.map((arg) => context.visit(arg, context.state))
|
|
1326
|
-
)
|
|
1327
|
-
)
|
|
1360
|
+
...node.expression.arguments.map((arg) => context.visit(arg, context.state)),
|
|
1361
|
+
),
|
|
1362
|
+
),
|
|
1328
1363
|
);
|
|
1329
1364
|
} else {
|
|
1330
1365
|
throw new Error('TODO');
|
|
@@ -1348,10 +1383,10 @@ function transform_children(children, { visit, state, root }) {
|
|
|
1348
1383
|
(node.type === 'Element' &&
|
|
1349
1384
|
(node.id.type !== 'Identifier' ||
|
|
1350
1385
|
node.id.name[0].toLowerCase() !== node.id.name[0] ||
|
|
1351
|
-
node.id.name[0] === '$'))
|
|
1386
|
+
node.id.name[0] === '$')),
|
|
1352
1387
|
) ||
|
|
1353
1388
|
normalized.filter(
|
|
1354
|
-
(node) => node.type !== 'VariableDeclaration' && node.type !== 'EmptyStatement'
|
|
1389
|
+
(node) => node.type !== 'VariableDeclaration' && node.type !== 'EmptyStatement',
|
|
1355
1390
|
).length > 1;
|
|
1356
1391
|
let initial = null;
|
|
1357
1392
|
let prev = null;
|
|
@@ -1365,8 +1400,8 @@ function transform_children(children, { visit, state, root }) {
|
|
|
1365
1400
|
node.id.name[0] !== '$'
|
|
1366
1401
|
? state.scope.generate(node.id.name)
|
|
1367
1402
|
: node.type == 'Text'
|
|
1368
|
-
|
|
1369
|
-
|
|
1403
|
+
? state.scope.generate('text')
|
|
1404
|
+
: state.scope.generate('node'),
|
|
1370
1405
|
);
|
|
1371
1406
|
};
|
|
1372
1407
|
|
|
@@ -1464,7 +1499,7 @@ function transform_children(children, { visit, state, root }) {
|
|
|
1464
1499
|
} else {
|
|
1465
1500
|
const id = state.flush_node();
|
|
1466
1501
|
state.init.push(
|
|
1467
|
-
b.stmt(b.assignment('=', b.member(id, b.id('textContent')), expression))
|
|
1502
|
+
b.stmt(b.assignment('=', b.member(id, b.id('textContent')), expression)),
|
|
1468
1503
|
);
|
|
1469
1504
|
}
|
|
1470
1505
|
} else {
|
|
@@ -1499,7 +1534,7 @@ function transform_children(children, { visit, state, root }) {
|
|
|
1499
1534
|
const flags = is_fragment ? b.literal(TEMPLATE_FRAGMENT) : b.literal(0);
|
|
1500
1535
|
state.final.push(b.stmt(b.call('$.append', b.id('__anchor'), initial)));
|
|
1501
1536
|
state.hoisted.push(
|
|
1502
|
-
b.var(template_id, b.call('$.template', join_template(state.template), flags))
|
|
1537
|
+
b.var(template_id, b.call('$.template', join_template(state.template), flags)),
|
|
1503
1538
|
);
|
|
1504
1539
|
}
|
|
1505
1540
|
}
|
|
@@ -1512,7 +1547,7 @@ function transform_body(body, { visit, state }) {
|
|
|
1512
1547
|
init: [],
|
|
1513
1548
|
update: [],
|
|
1514
1549
|
final: [],
|
|
1515
|
-
metadata: state.metadata
|
|
1550
|
+
metadata: state.metadata,
|
|
1516
1551
|
};
|
|
1517
1552
|
|
|
1518
1553
|
transform_children(body, { visit, state: body_state, root: true });
|
|
@@ -1538,7 +1573,7 @@ export function transform(filename, source, analysis, to_ts) {
|
|
|
1538
1573
|
scope: analysis.scope,
|
|
1539
1574
|
scopes: analysis.scopes,
|
|
1540
1575
|
stylesheets: [],
|
|
1541
|
-
to_ts
|
|
1576
|
+
to_ts,
|
|
1542
1577
|
};
|
|
1543
1578
|
|
|
1544
1579
|
const program = /** @type {ESTree.Program} */ (
|
|
@@ -1555,19 +1590,21 @@ export function transform(filename, source, analysis, to_ts) {
|
|
|
1555
1590
|
|
|
1556
1591
|
if (state.events.size > 0) {
|
|
1557
1592
|
program.body.push(
|
|
1558
|
-
b.stmt(
|
|
1593
|
+
b.stmt(
|
|
1594
|
+
b.call('$.delegate', b.array(Array.from(state.events).map((name) => b.literal(name)))),
|
|
1595
|
+
),
|
|
1559
1596
|
);
|
|
1560
1597
|
}
|
|
1561
1598
|
|
|
1562
1599
|
const js = print(
|
|
1563
1600
|
program,
|
|
1564
1601
|
tsx({
|
|
1565
|
-
comments: analysis.ast.comments || []
|
|
1602
|
+
comments: analysis.ast.comments || [],
|
|
1566
1603
|
}),
|
|
1567
1604
|
{
|
|
1568
1605
|
sourceMapContent: source,
|
|
1569
|
-
sourceMapSource: path.basename(filename)
|
|
1570
|
-
}
|
|
1606
|
+
sourceMapSource: path.basename(filename),
|
|
1607
|
+
},
|
|
1571
1608
|
);
|
|
1572
1609
|
|
|
1573
1610
|
const css = render_stylesheets(state.stylesheets);
|
|
@@ -1575,6 +1612,6 @@ export function transform(filename, source, analysis, to_ts) {
|
|
|
1575
1612
|
return {
|
|
1576
1613
|
ast: program,
|
|
1577
1614
|
js,
|
|
1578
|
-
css
|
|
1615
|
+
css,
|
|
1579
1616
|
};
|
|
1580
1617
|
}
|