ripple 0.2.67 → 0.2.69

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.
@@ -3,7 +3,13 @@ import path from 'node:path';
3
3
  import { print } from 'esrap';
4
4
  import tsx from 'esrap/languages/tsx';
5
5
  import * as b from '../../../utils/builders.js';
6
- import { IS_CONTROLLED, TEMPLATE_FRAGMENT } from '../../../constants.js';
6
+ import {
7
+ IS_CONTROLLED,
8
+ IS_INDEXED,
9
+ TEMPLATE_FRAGMENT,
10
+ TEMPLATE_SVG_NAMESPACE,
11
+ TEMPLATE_MATHML_NAMESPACE,
12
+ } from '../../../constants.js';
7
13
  import { sanitize_template_string } from '../../../utils/sanitize_template_string.js';
8
14
  import {
9
15
  build_hoisted_params,
@@ -13,7 +19,6 @@ import {
13
19
  escape_html,
14
20
  is_boolean_attribute,
15
21
  is_dom_property,
16
- is_ripple_import,
17
22
  is_declared_function_within_component,
18
23
  is_inside_call_expression,
19
24
  is_value_static,
@@ -21,6 +26,7 @@ import {
21
26
  is_component_level_function,
22
27
  is_element_dom_element,
23
28
  is_top_level_await,
29
+ is_ripple_track_call,
24
30
  } from '../../utils.js';
25
31
  import is_reference from 'is-reference';
26
32
  import { object } from '../../../utils/ast.js';
@@ -29,8 +35,8 @@ import { is_event_attribute, is_passive_event } from '../../../utils/events.js';
29
35
 
30
36
  function add_ripple_internal_import(context) {
31
37
  if (!context.state.to_ts) {
32
- if (!context.state.imports.has(`import * as $ from 'ripple/internal/client'`)) {
33
- context.state.imports.add(`import * as $ from 'ripple/internal/client'`);
38
+ if (!context.state.imports.has(`import * as _$_ from 'ripple/internal/client'`)) {
39
+ context.state.imports.add(`import * as _$_ from 'ripple/internal/client'`);
34
40
  }
35
41
  }
36
42
  }
@@ -66,7 +72,7 @@ function visit_function(node, context) {
66
72
 
67
73
  if (!is_inside_component(context, true) && is_component_level_function(context)) {
68
74
  add_ripple_internal_import(context);
69
- new_body.push(b.var('__block', b.call('$.scope')));
75
+ new_body.push(b.var('__block', b.call('_$_.scope')));
70
76
  }
71
77
  if (body.type === 'BlockStatement') {
72
78
  new_body.push(...body.body);
@@ -104,6 +110,22 @@ function build_getter(node, context) {
104
110
  return node;
105
111
  }
106
112
 
113
+ function determine_namespace_for_children(element_name, current_namespace) {
114
+ if (element_name === 'foreignObject') {
115
+ return 'html';
116
+ }
117
+
118
+ if (element_name === 'svg') {
119
+ return 'svg';
120
+ }
121
+
122
+ if (element_name === 'math') {
123
+ return 'mathml';
124
+ }
125
+
126
+ return current_namespace;
127
+ }
128
+
107
129
  const visitors = {
108
130
  _: function set_scope(node, { next, state }) {
109
131
  const scope = state.scopes.get(node);
@@ -128,14 +150,17 @@ const visitors = {
128
150
  if (
129
151
  (context.state.metadata?.tracking === false ||
130
152
  (parent.type !== 'AssignmentExpression' && parent.type !== 'UpdateExpression')) &&
131
- (node.tracked || binding?.kind === 'prop' || binding?.kind === 'prop_fallback') &&
153
+ (node.tracked ||
154
+ binding?.kind === 'prop' ||
155
+ binding?.kind === 'index' ||
156
+ binding?.kind === 'prop_fallback') &&
132
157
  binding?.node !== node
133
158
  ) {
134
159
  if (context.state.metadata?.tracking === false) {
135
160
  context.state.metadata.tracking = true;
136
161
  }
137
162
  if (node.tracked) {
138
- return b.call('$.get', build_getter(node, context));
163
+ return b.call('_$_.get', build_getter(node, context));
139
164
  }
140
165
  }
141
166
 
@@ -165,12 +190,7 @@ const visitors = {
165
190
  context.state.metadata.tracking = true;
166
191
  }
167
192
 
168
- if (
169
- !context.state.to_ts &&
170
- callee.type === 'Identifier' &&
171
- callee.name === 'track' &&
172
- is_ripple_import(callee, context)
173
- ) {
193
+ if (!context.state.to_ts && is_ripple_track_call(callee, context)) {
174
194
  if (node.arguments.length === 0) {
175
195
  node.arguments.push(b.void0);
176
196
  }
@@ -186,9 +206,6 @@ const visitors = {
186
206
  (parent?.type === 'MemberExpression' && parent.property === node) ||
187
207
  is_inside_call_expression(context) ||
188
208
  !context.path.some((node) => node.type === 'Component') ||
189
- (is_ripple_import(callee, context) &&
190
- (callee.type !== 'Identifier' ||
191
- (callee.name !== 'array' && callee.name !== 'deferred'))) ||
192
209
  is_declared_function_within_component(callee, context)
193
210
  ) {
194
211
  return context.next();
@@ -200,11 +217,11 @@ const visitors = {
200
217
 
201
218
  if (callee.computed) {
202
219
  return b.call(
203
- '$.with_scope',
220
+ '_$_.with_scope',
204
221
  b.id('__block'),
205
222
  b.thunk(
206
223
  b.call(
207
- '$.call_property',
224
+ '_$_.call_property',
208
225
  context.visit(callee.object),
209
226
  context.visit(property),
210
227
  callee.optional ? b.true : undefined,
@@ -217,7 +234,7 @@ const visitors = {
217
234
  }
218
235
 
219
236
  return b.call(
220
- '$.with_scope',
237
+ '_$_.with_scope',
221
238
  b.id('__block'),
222
239
  b.thunk(
223
240
  {
@@ -269,7 +286,7 @@ const visitors = {
269
286
  }
270
287
 
271
288
  return b.call(
272
- '$.with_scope',
289
+ '_$_.with_scope',
273
290
  b.id('__block'),
274
291
  b.thunk({
275
292
  ...node,
@@ -290,7 +307,7 @@ const visitors = {
290
307
  add_ripple_internal_import(context);
291
308
 
292
309
  return b.call(
293
- '$.get_property',
310
+ '_$_.get_property',
294
311
  context.visit(node.object),
295
312
  node.computed ? context.visit(node.property) : b.literal(node.property.name),
296
313
  node.optional ? b.true : undefined,
@@ -351,13 +368,13 @@ const visitors = {
351
368
  // TypeScript mode: lighter transformation
352
369
  if (metadata.tracking && !metadata.await) {
353
370
  expression = b.call(
354
- '$.derived',
371
+ '_$_.derived',
355
372
  b.thunk(context.visit(declarator.init)),
356
373
  b.id('__block'),
357
374
  );
358
375
  } else {
359
376
  expression = b.call(
360
- '$.tracked',
377
+ '_$_.tracked',
361
378
  declarator.init === null ? undefined : context.visit(declarator.init),
362
379
  b.id('__block'),
363
380
  );
@@ -369,9 +386,9 @@ const visitors = {
369
386
  expression = b.call(
370
387
  b.await(
371
388
  b.call(
372
- '$.resume_context',
389
+ '_$_.resume_context',
373
390
  b.call(
374
- '$.async_computed',
391
+ '_$_.async_computed',
375
392
  b.thunk(context.visit(declarator.init), true),
376
393
  b.id('__block'),
377
394
  ),
@@ -380,13 +397,13 @@ const visitors = {
380
397
  );
381
398
  } else if (metadata.tracking && !metadata.await) {
382
399
  expression = b.call(
383
- '$.derived',
400
+ '_$_.derived',
384
401
  b.thunk(context.visit(declarator.init)),
385
402
  b.id('__block'),
386
403
  );
387
404
  } else {
388
405
  expression = b.call(
389
- '$.tracked',
406
+ '_$_.tracked',
390
407
  declarator.init === null ? undefined : context.visit(declarator.init),
391
408
  b.id('__block'),
392
409
  );
@@ -426,6 +443,10 @@ const visitors = {
426
443
  const is_spreading = node.attributes.some((attr) => attr.type === 'SpreadAttribute');
427
444
  const spread_attributes = is_spreading ? [] : null;
428
445
 
446
+ const child_namespace = is_dom_element
447
+ ? determine_namespace_for_children(node.id.name, state.namespace)
448
+ : state.namespace;
449
+
429
450
  const handle_static_attr = (name, value) => {
430
451
  const attr_value = b.literal(
431
452
  ` ${name}${
@@ -481,9 +502,9 @@ const visitors = {
481
502
  const expression = visit(attr.value, { ...state, metadata });
482
503
 
483
504
  if (name === '$value' || metadata.tracking) {
484
- local_updates.push(b.stmt(b.call('$.set_value', id, expression)));
505
+ local_updates.push(b.stmt(b.call('_$_.set_value', id, expression)));
485
506
  } else {
486
- state.init.push(b.stmt(b.call('$.set_value', id, expression)));
507
+ state.init.push(b.stmt(b.call('_$_.set_value', id, expression)));
487
508
  }
488
509
 
489
510
  continue;
@@ -495,9 +516,9 @@ const visitors = {
495
516
  const expression = visit(attr.value, { ...state, metadata });
496
517
 
497
518
  if (name === '$checked' || metadata.tracking) {
498
- local_updates.push(b.stmt(b.call('$.set_checked', id, expression)));
519
+ local_updates.push(b.stmt(b.call('_$_.set_checked', id, expression)));
499
520
  } else {
500
- state.init.push(b.stmt(b.call('$.set_checked', id, expression)));
521
+ state.init.push(b.stmt(b.call('_$_.set_checked', id, expression)));
501
522
  }
502
523
  continue;
503
524
  }
@@ -508,9 +529,9 @@ const visitors = {
508
529
  const expression = visit(attr.value, { ...state, metadata });
509
530
 
510
531
  if (name === '$selected' || metadata.tracking) {
511
- local_updates.push(b.stmt(b.call('$.set_selected', id, expression)));
532
+ local_updates.push(b.stmt(b.call('_$_.set_selected', id, expression)));
512
533
  } else {
513
- state.init.push(b.stmt(b.call('$.set_selected', id, expression)));
534
+ state.init.push(b.stmt(b.call('_$_.set_selected', id, expression)));
514
535
  }
515
536
  continue;
516
537
  }
@@ -563,7 +584,7 @@ const visitors = {
563
584
  state.init.push(
564
585
  b.stmt(
565
586
  b.call(
566
- '$.event',
587
+ '_$_.event',
567
588
  b.literal(event_name),
568
589
  id,
569
590
  handler,
@@ -588,7 +609,7 @@ const visitors = {
588
609
  local_updates.push(b.stmt(b.assignment('=', b.member(id, attribute), expression)));
589
610
  } else {
590
611
  local_updates.push(
591
- b.stmt(b.call('$.set_attribute', id, b.literal(attribute), expression)),
612
+ b.stmt(b.call('_$_.set_attribute', id, b.literal(attribute), expression)),
592
613
  );
593
614
  }
594
615
  } else {
@@ -597,7 +618,9 @@ const visitors = {
597
618
  if (is_dom_property(name)) {
598
619
  state.init.push(b.stmt(b.assignment('=', b.member(id, name), expression)));
599
620
  } else {
600
- state.init.push(b.stmt(b.call('$.set_attribute', id, b.literal(name), expression)));
621
+ state.init.push(
622
+ b.stmt(b.call('_$_.set_attribute', id, b.literal(name), expression)),
623
+ );
601
624
  }
602
625
  }
603
626
  }
@@ -605,7 +628,7 @@ const visitors = {
605
628
  spread_attributes.push(b.spread(visit(attr.argument, state)));
606
629
  } else if (attr.type === 'RefAttribute') {
607
630
  const id = state.flush_node();
608
- state.init.push(b.stmt(b.call('$.ref', id, b.thunk(visit(attr.argument, state)))));
631
+ state.init.push(b.stmt(b.call('_$_.ref', id, b.thunk(visit(attr.argument, state)))));
609
632
  }
610
633
  }
611
634
 
@@ -626,11 +649,16 @@ const visitors = {
626
649
  if (node.metadata.scoped && state.component.css) {
627
650
  expression = b.binary('+', b.literal(state.component.css.hash + ' '), expression);
628
651
  }
652
+ const is_html = context.state.metadata.namespace === 'html' && node.id.name !== 'svg';
629
653
 
630
654
  if (class_attribute.name.name === '$class' || metadata.tracking) {
631
- local_updates.push(b.stmt(b.call('$.set_class', id, expression)));
655
+ local_updates.push(
656
+ b.stmt(b.call('_$_.set_class', id, expression, undefined, b.literal(is_html))),
657
+ );
632
658
  } else {
633
- state.init.push(b.stmt(b.call('$.set_class', id, expression)));
659
+ state.init.push(
660
+ b.stmt(b.call('_$_.set_class', id, expression, undefined, b.literal(is_html))),
661
+ );
634
662
  }
635
663
  }
636
664
  } else if (node.metadata.scoped && state.component.css) {
@@ -644,7 +672,7 @@ const visitors = {
644
672
  if (spread_attributes !== null && spread_attributes.length > 0) {
645
673
  const id = state.flush_node();
646
674
  state.init.push(
647
- b.stmt(b.call('$.render_spread', id, b.thunk(b.object(spread_attributes)))),
675
+ b.stmt(b.call('_$_.render_spread', id, b.thunk(b.object(spread_attributes)))),
648
676
  );
649
677
  }
650
678
 
@@ -654,7 +682,7 @@ const visitors = {
654
682
  if (!is_void) {
655
683
  transform_children(node.children, {
656
684
  visit,
657
- state: { ...state, init, update },
685
+ state: { ...state, init, update, namespace: child_namespace },
658
686
  root: false,
659
687
  });
660
688
  state.template.push(`</${node.id.name}>`);
@@ -668,7 +696,7 @@ const visitors = {
668
696
 
669
697
  if (update.length > 0) {
670
698
  if (state.scope.parent.declarations.size > 0) {
671
- state.init.push(b.stmt(b.call('$.render', b.thunk(b.block(update), !!update.async))));
699
+ state.init.push(b.stmt(b.call('_$_.render', b.thunk(b.block(update), !!update.async))));
672
700
  } else {
673
701
  state.update.push(...update);
674
702
  }
@@ -710,7 +738,7 @@ const visitors = {
710
738
  ),
711
739
  );
712
740
  } else if (attr.type === 'RefAttribute') {
713
- props.push(b.prop('init', b.call('$.ref_prop'), visit(attr.argument, state), true));
741
+ props.push(b.prop('init', b.call('_$_.ref_prop'), visit(attr.argument, state), true));
714
742
  } else if (attr.type === 'AccessorAttribute') {
715
743
  let get_expr;
716
744
 
@@ -765,7 +793,7 @@ const visitors = {
765
793
  for (const child of node.children) {
766
794
  if (child.type === 'Component') {
767
795
  const id = child.id;
768
- props.push(b.prop('init', id, visit(child, state)));
796
+ props.push(b.prop('init', id, visit(child, { ...state, namespace: child_namespace })));
769
797
  } else {
770
798
  children_filtered.push(child);
771
799
  }
@@ -776,6 +804,7 @@ const visitors = {
776
804
  const children = visit(b.component(b.id('children'), [], children_filtered), {
777
805
  ...context.state,
778
806
  scope: component_scope,
807
+ namespace: child_namespace,
779
808
  });
780
809
 
781
810
  if (children_prop) {
@@ -791,14 +820,14 @@ const visitors = {
791
820
  b.call(
792
821
  node.id,
793
822
  id,
794
- b.call('$.spread_props', b.thunk(b.object(props)), b.id('__block')),
795
- b.id('$.active_block'),
823
+ b.call('_$_.spread_props', b.thunk(b.object(props)), b.id('__block')),
824
+ b.id('_$_.active_block'),
796
825
  ),
797
826
  ),
798
827
  );
799
828
  } else {
800
829
  state.init.push(
801
- b.stmt(b.call(visit(node.id, state), id, b.object(props), b.id('$.active_block'))),
830
+ b.stmt(b.call(visit(node.id, state), id, b.object(props), b.id('_$_.active_block'))),
802
831
  );
803
832
  }
804
833
  }
@@ -821,7 +850,7 @@ const visitors = {
821
850
  [b.id('__anchor'), ...node.params.map((param) => context.visit(param, context.state))],
822
851
  b.block(
823
852
  metadata.await
824
- ? [b.stmt(b.call('$.async', b.thunk(b.block(body_statements), true)))]
853
+ ? [b.stmt(b.call('_$_.async', b.thunk(b.block(body_statements), true)))]
825
854
  : body_statements,
826
855
  ),
827
856
  );
@@ -859,12 +888,12 @@ const visitors = {
859
888
  }
860
889
 
861
890
  const body_statements = [
862
- b.stmt(b.call('$.push_component')),
891
+ b.stmt(b.call('_$_.push_component')),
863
892
  ...transform_body(node.body, {
864
893
  ...context,
865
894
  state: { ...context.state, component: node, metadata },
866
895
  }),
867
- b.stmt(b.call('$.pop_component')),
896
+ b.stmt(b.call('_$_.pop_component')),
868
897
  ];
869
898
 
870
899
  if (node.css !== null && node.css) {
@@ -879,7 +908,7 @@ const visitors = {
879
908
  b.block([
880
909
  ...(prop_statements ?? []),
881
910
  ...(metadata.await
882
- ? [b.stmt(b.call('$.async', b.thunk(b.block(body_statements), true)))]
911
+ ? [b.stmt(b.call('_$_.async', b.thunk(b.block(body_statements), true)))]
883
912
  : body_statements),
884
913
  ]),
885
914
  );
@@ -906,7 +935,7 @@ const visitors = {
906
935
  }
907
936
 
908
937
  return b.call(
909
- '$.set_property',
938
+ '_$_.set_property',
910
939
  context.visit(left.object, { ...context.state, metadata: { tracking: false } }),
911
940
  left.computed ? context.visit(left.property) : b.literal(left.property.name),
912
941
  operator === '='
@@ -926,7 +955,7 @@ const visitors = {
926
955
  const right = node.right;
927
956
 
928
957
  return b.call(
929
- '$.set',
958
+ '_$_.set',
930
959
  context.visit(left, { ...context.state, metadata: { tracking: null } }),
931
960
  operator === '='
932
961
  ? context.visit(right)
@@ -960,7 +989,7 @@ const visitors = {
960
989
  context.state.metadata.tracking = true;
961
990
 
962
991
  return b.call(
963
- node.prefix ? '$.update_pre_property' : '$.update_property',
992
+ node.prefix ? '_$_.update_pre_property' : '_$_.update_property',
964
993
  context.visit(argument.object, { ...context.state, metadata: { tracking: false } }),
965
994
  argument.computed ? context.visit(argument.property) : b.literal(argument.property.name),
966
995
  b.id('__block'),
@@ -970,7 +999,7 @@ const visitors = {
970
999
 
971
1000
  if (argument.type === 'Identifier' && argument.tracked) {
972
1001
  return b.call(
973
- node.prefix ? '$.update_pre' : '$.update',
1002
+ node.prefix ? '_$_.update_pre' : '_$_.update',
974
1003
  context.visit(argument, { ...context.state, metadata: { tracking: null } }),
975
1004
  b.id('__block'),
976
1005
  node.operator === '--' ? b.literal(-1) : undefined,
@@ -997,6 +1026,12 @@ const visitors = {
997
1026
  return;
998
1027
  }
999
1028
  const is_controlled = node.is_controlled;
1029
+ const index = node.index;
1030
+ let flags = is_controlled ? IS_CONTROLLED : 0;
1031
+
1032
+ if (index !== null) {
1033
+ flags |= IS_INDEXED;
1034
+ }
1000
1035
 
1001
1036
  // do only if not controller
1002
1037
  if (!is_controlled) {
@@ -1010,19 +1045,19 @@ const visitors = {
1010
1045
  context.state.init.push(
1011
1046
  b.stmt(
1012
1047
  b.call(
1013
- '$.for',
1048
+ '_$_.for',
1014
1049
  id,
1015
1050
  b.thunk(context.visit(node.right)),
1016
1051
  b.arrow(
1017
- [b.id('__anchor'), pattern],
1052
+ index ? [b.id('__anchor'), pattern, index] : [b.id('__anchor'), pattern],
1018
1053
  b.block(
1019
1054
  transform_body(node.body.body, {
1020
1055
  ...context,
1021
- state: { ...context.state, scope: body_scope },
1056
+ state: { ...context.state, scope: body_scope, namespace: context.state.namespace },
1022
1057
  }),
1023
1058
  ),
1024
1059
  ),
1025
- b.literal(is_controlled ? IS_CONTROLLED : 0),
1060
+ b.literal(flags),
1026
1061
  ),
1027
1062
  ),
1028
1063
  );
@@ -1070,7 +1105,7 @@ const visitors = {
1070
1105
  statements.push(
1071
1106
  b.stmt(
1072
1107
  b.call(
1073
- '$.if',
1108
+ '_$_.if',
1074
1109
  id,
1075
1110
  b.arrow(
1076
1111
  [b.id('__render')],
@@ -1119,13 +1154,13 @@ const visitors = {
1119
1154
  });
1120
1155
 
1121
1156
  if (metadata.pending) {
1122
- body = [b.stmt(b.call('$.async', b.thunk(b.block(body), true)))];
1157
+ body = [b.stmt(b.call('_$_.async', b.thunk(b.block(body), true)))];
1123
1158
  }
1124
1159
 
1125
1160
  context.state.init.push(
1126
1161
  b.stmt(
1127
1162
  b.call(
1128
- '$.try',
1163
+ '_$_.try',
1129
1164
  id,
1130
1165
  b.arrow([b.id('__anchor')], b.block(body)),
1131
1166
  node.handler === null
@@ -1151,7 +1186,7 @@ const visitors = {
1151
1186
  context.state.metadata.await = true;
1152
1187
  }
1153
1188
 
1154
- return b.call(b.await(b.call('$.maybe_tracked', context.visit(node.argument))));
1189
+ return b.call(b.await(b.call('_$_.maybe_tracked', context.visit(node.argument))));
1155
1190
  },
1156
1191
 
1157
1192
  BinaryExpression(node, context) {
@@ -1466,9 +1501,15 @@ function transform_children(children, context) {
1466
1501
 
1467
1502
  if (child.type === 'Text' && prev_child?.type === 'Text') {
1468
1503
  if (child.expression.type === 'Literal' && prev_child.expression.type === 'Literal') {
1469
- prev_child.expression = b.literal(prev_child.expression.value + child.expression.value);
1504
+ prev_child.expression = b.literal(
1505
+ prev_child.expression.value + String(child.expression.value),
1506
+ );
1470
1507
  } else {
1471
- prev_child.expression = b.binary('+', prev_child.expression, child.expression);
1508
+ prev_child.expression = b.binary(
1509
+ '+',
1510
+ prev_child.expression,
1511
+ b.call('String', child.expression),
1512
+ );
1472
1513
  }
1473
1514
  normalized.splice(i, 1);
1474
1515
  }
@@ -1489,7 +1530,7 @@ function transform_children(children, context) {
1489
1530
  const metadata = { await: false };
1490
1531
  state.init.push(visit(node, { ...state, metadata }));
1491
1532
  if (metadata.await) {
1492
- state.init.push(b.if(b.call('$.aborted'), b.return(null)));
1533
+ state.init.push(b.if(b.call('_$_.aborted'), b.return(null)));
1493
1534
  if (state.metadata?.await === false) {
1494
1535
  state.metadata.await = true;
1495
1536
  }
@@ -1508,13 +1549,13 @@ function transform_children(children, context) {
1508
1549
  return cached;
1509
1550
  } else if (current_prev !== null) {
1510
1551
  const id = get_id(node);
1511
- state.setup.push(b.var(id, b.call('$.sibling', current_prev())));
1552
+ state.setup.push(b.var(id, b.call('_$_.sibling', current_prev())));
1512
1553
  cached = id;
1513
1554
  return id;
1514
1555
  } else if (initial !== null) {
1515
1556
  if (is_fragment) {
1516
1557
  const id = get_id(node);
1517
- state.setup.push(b.var(id, b.call('$.child_frag', initial)));
1558
+ state.setup.push(b.var(id, b.call('_$_.child_frag', initial)));
1518
1559
  cached = id;
1519
1560
  return id;
1520
1561
  }
@@ -1525,7 +1566,7 @@ function transform_children(children, context) {
1525
1566
  }
1526
1567
 
1527
1568
  const id = get_id(node);
1528
- state.setup.push(b.var(id, b.call('$.child', state.flush_node())));
1569
+ state.setup.push(b.var(id, b.call('_$_.child', state.flush_node())));
1529
1570
  cached = id;
1530
1571
  return id;
1531
1572
  } else {
@@ -1536,7 +1577,7 @@ function transform_children(children, context) {
1536
1577
  prev = flush_node;
1537
1578
 
1538
1579
  if (node.type === 'Element') {
1539
- visit(node, { ...state, flush_node });
1580
+ visit(node, { ...state, flush_node, namespace: state.namespace });
1540
1581
  } else if (node.type === 'Text') {
1541
1582
  const metadata = { tracking: false, await: false };
1542
1583
  const expression = visit(node.expression, { ...state, metadata });
@@ -1544,7 +1585,7 @@ function transform_children(children, context) {
1544
1585
  if (metadata.tracking) {
1545
1586
  state.template.push(' ');
1546
1587
  const id = flush_node();
1547
- state.update.push(b.stmt(b.call('$.set_text', id, expression)));
1588
+ state.update.push(b.stmt(b.call('_$_.set_text', id, expression)));
1548
1589
  if (metadata.await) {
1549
1590
  state.update.async = true;
1550
1591
  }
@@ -1556,7 +1597,7 @@ function transform_children(children, context) {
1556
1597
  state.template.push(' ');
1557
1598
  state.init.push(
1558
1599
  b.stmt(
1559
- b.assignment('=', b.member(b.call('$.child', id), b.id('nodeValue')), expression),
1600
+ b.assignment('=', b.member(b.call('_$_.child', id), b.id('nodeValue')), expression),
1560
1601
  ),
1561
1602
  );
1562
1603
  }
@@ -1564,7 +1605,7 @@ function transform_children(children, context) {
1564
1605
  // Handle Text nodes in fragments
1565
1606
  state.template.push(' ');
1566
1607
  const id = flush_node();
1567
- state.update.push(b.stmt(b.call('$.set_text', id, expression)));
1608
+ state.update.push(b.stmt(b.call('_$_.set_text', id, expression)));
1568
1609
  if (metadata.await) {
1569
1610
  state.update.async = true;
1570
1611
  }
@@ -1572,26 +1613,33 @@ function transform_children(children, context) {
1572
1613
  } else if (node.type === 'ForOfStatement') {
1573
1614
  const is_controlled = normalized.length === 1;
1574
1615
  node.is_controlled = is_controlled;
1575
- visit(node, { ...state, flush_node });
1616
+ visit(node, { ...state, flush_node, namespace: state.namespace });
1576
1617
  } else if (node.type === 'IfStatement') {
1577
1618
  const is_controlled = normalized.length === 1;
1578
1619
  node.is_controlled = is_controlled;
1579
- visit(node, { ...state, flush_node });
1620
+ visit(node, { ...state, flush_node, namespace: state.namespace });
1580
1621
  } else if (node.type === 'TryStatement') {
1581
1622
  const is_controlled = normalized.length === 1;
1582
1623
  node.is_controlled = is_controlled;
1583
- visit(node, { ...state, flush_node });
1624
+ visit(node, { ...state, flush_node, namespace: state.namespace });
1584
1625
  } else {
1585
1626
  debugger;
1586
1627
  }
1587
1628
  }
1588
1629
  }
1589
1630
 
1631
+ const template_namespace = state.namespace || 'html';
1632
+
1590
1633
  if (root && initial !== null && template_id !== null) {
1591
- const flags = is_fragment ? b.literal(TEMPLATE_FRAGMENT) : b.literal(0);
1592
- state.final.push(b.stmt(b.call('$.append', b.id('__anchor'), initial)));
1634
+ let flags = is_fragment ? TEMPLATE_FRAGMENT : 0;
1635
+ if (template_namespace === 'svg') {
1636
+ flags |= TEMPLATE_SVG_NAMESPACE;
1637
+ } else if (template_namespace === 'mathml') {
1638
+ flags |= TEMPLATE_MATHML_NAMESPACE;
1639
+ }
1640
+ state.final.push(b.stmt(b.call('_$_.append', b.id('__anchor'), initial)));
1593
1641
  state.hoisted.push(
1594
- b.var(template_id, b.call('$.template', join_template(state.template), flags)),
1642
+ b.var(template_id, b.call('_$_.template', join_template(state.template), b.literal(flags))),
1595
1643
  );
1596
1644
  }
1597
1645
  }
@@ -1605,12 +1653,13 @@ function transform_body(body, { visit, state }) {
1605
1653
  update: [],
1606
1654
  final: [],
1607
1655
  metadata: state.metadata,
1656
+ namespace: state.namespace || 'html', // Preserve namespace context
1608
1657
  };
1609
1658
 
1610
1659
  transform_children(body, { visit, state: body_state, root: true });
1611
1660
 
1612
1661
  if (body_state.update.length > 0) {
1613
- body_state.init.push(b.stmt(b.call('$.render', b.thunk(b.block(body_state.update)))));
1662
+ body_state.init.push(b.stmt(b.call('_$_.render', b.thunk(b.block(body_state.update)))));
1614
1663
  }
1615
1664
 
1616
1665
  return [...body_state.setup, ...body_state.init, ...body_state.final];
@@ -1633,7 +1682,9 @@ export function transform(filename, source, analysis, to_ts) {
1633
1682
  to_ts,
1634
1683
  };
1635
1684
 
1636
- const program = /** @type {ESTree.Program} */ (walk(analysis.ast, state, visitors));
1685
+ const program = /** @type {ESTree.Program} */ (
1686
+ walk(analysis.ast, { ...state, namespace: 'html' }, visitors)
1687
+ );
1637
1688
 
1638
1689
  for (const hoisted of state.hoisted) {
1639
1690
  program.body.unshift(hoisted);
@@ -1646,7 +1697,7 @@ export function transform(filename, source, analysis, to_ts) {
1646
1697
  if (state.events.size > 0) {
1647
1698
  program.body.push(
1648
1699
  b.stmt(
1649
- b.call('$.delegate', b.array(Array.from(state.events).map((name) => b.literal(name)))),
1700
+ b.call('_$_.delegate', b.array(Array.from(state.events).map((name) => b.literal(name)))),
1650
1701
  ),
1651
1702
  );
1652
1703
  }