ripple 0.2.53 → 0.2.55

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 CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "Ripple is an elegant TypeScript UI framework",
4
4
  "license": "MIT",
5
5
  "author": "Dominic Gannaway",
6
- "version": "0.2.53",
6
+ "version": "0.2.55",
7
7
  "type": "module",
8
8
  "module": "src/runtime/index.js",
9
9
  "main": "src/runtime/index.js",
@@ -7,7 +7,6 @@ import {
7
7
  is_event_attribute,
8
8
  is_inside_component,
9
9
  is_ripple_import,
10
- is_tracked_computed_property,
11
10
  is_void_element,
12
11
  } from '../../utils.js';
13
12
  import { extract_paths } from '../../../utils/ast.js';
@@ -166,37 +165,7 @@ const visitors = {
166
165
  (declarator.init.callee.name === 'untrack' || declarator.init.callee.name === 'deferred');
167
166
 
168
167
  if (declarator.id.type === 'Identifier') {
169
- const binding = state.scope.get(declarator.id.name);
170
-
171
- if (binding !== null && parent?.type !== 'ForOfStatement') {
172
- if (binding.initial?.type !== 'Literal') {
173
- for (const ref of binding.references) {
174
- const path = ref.path;
175
- const parent_node = path?.at(-1);
176
-
177
- // We're reading a computed property, which might mean it's a reactive property
178
- if (
179
- !ref.node.tracked &&
180
- parent_node?.type === 'MemberExpression' &&
181
- parent_node.computed
182
- ) {
183
- binding.transform = {
184
- assign: (node, value, computed) => {
185
- if (!computed) {
186
- return node;
187
- }
188
- return b.call('$.old_set_property', node, computed, value, b.id('__block'));
189
- },
190
- };
191
- break;
192
- }
193
- }
194
- }
195
-
196
- visit(declarator, state);
197
- } else {
198
- visit(declarator, state);
199
- }
168
+ visit(declarator, state);
200
169
  } else {
201
170
  const paths = extract_paths(declarator.id);
202
171
 
@@ -18,7 +18,6 @@ import {
18
18
  is_ripple_import,
19
19
  is_declared_function_within_component,
20
20
  is_inside_call_expression,
21
- is_tracked_computed_property,
22
21
  is_value_static,
23
22
  is_void_element,
24
23
  is_component_level_function,
@@ -141,10 +140,6 @@ const visitors = {
141
140
  }
142
141
  }
143
142
 
144
- if (node.name === 'structuredClone' && binding === null) {
145
- return b.id('$.structured_clone');
146
- }
147
-
148
143
  return build_getter(node, context);
149
144
  }
150
145
  }
@@ -225,11 +220,14 @@ const visitors = {
225
220
  return b.call(
226
221
  '$.with_scope',
227
222
  b.id('__block'),
228
- b.thunk({
229
- ...node,
230
- callee: context.visit(callee),
231
- arguments: node.arguments.map((arg) => context.visit(arg)),
232
- }, context.state.metadata?.await ?? false),
223
+ b.thunk(
224
+ {
225
+ ...node,
226
+ callee: context.visit(callee),
227
+ arguments: node.arguments.map((arg) => context.visit(arg)),
228
+ },
229
+ context.state.metadata?.await ?? false,
230
+ ),
233
231
  );
234
232
  },
235
233
 
@@ -303,20 +301,6 @@ const visitors = {
303
301
  const object = node.object;
304
302
  const property = node.property;
305
303
 
306
- // TODO should we enforce that the identifier is tracked too?
307
- if (node.computed && is_tracked_computed_property(node.object, node.property, context)) {
308
- if (context.state.metadata?.tracking === false) {
309
- context.state.metadata.tracking = true;
310
- }
311
-
312
- return b.call(
313
- '$.old_get_property',
314
- context.visit(object),
315
- context.visit(property),
316
- node.optional ? b.true : undefined,
317
- );
318
- }
319
-
320
304
  if (object.type === 'Identifier' && object.name === 'Object') {
321
305
  const binding = context.state.scope.get(object.name);
322
306
 
@@ -359,16 +343,6 @@ const visitors = {
359
343
  }
360
344
  },
361
345
 
362
- SpreadElement(node, context) {
363
- const parent = context.path.at(-1);
364
-
365
- if (parent.type === 'ObjectExpression') {
366
- return b.spread(b.call('$.spread_object', context.visit(node.argument)));
367
- }
368
-
369
- context.next();
370
- },
371
-
372
346
  VariableDeclaration(node, context) {
373
347
  const declarations = [];
374
348
 
@@ -635,7 +609,7 @@ const visitors = {
635
609
  }
636
610
  }
637
611
  } else if (attr.type === 'SpreadAttribute') {
638
- spread_attributes.push(b.spread(b.call('$.spread_object', visit(attr.argument, state))));
612
+ spread_attributes.push(b.spread(visit(attr.argument, state)));
639
613
  } else if (attr.type === 'RefAttribute') {
640
614
  const id = state.flush_node();
641
615
  state.init.push(b.stmt(b.call('$.ref', id, b.thunk(visit(attr.argument, state)))));
@@ -735,10 +709,7 @@ const visitors = {
735
709
  } else if (attr.type === 'SpreadAttribute') {
736
710
  props.push(
737
711
  b.spread(
738
- b.call(
739
- '$.spread_object',
740
- visit(attr.argument, { ...state, metadata: { ...state.metadata, spread: true } }),
741
- ),
712
+ visit(attr.argument, { ...state, metadata: { ...state.metadata, spread: true } }),
742
713
  ),
743
714
  );
744
715
  } else if (attr.type === 'RefAttribute') {
@@ -823,7 +794,7 @@ const visitors = {
823
794
  b.call(
824
795
  node.id,
825
796
  id,
826
- b.call('$.tracked_spread_object', b.thunk(b.object(props)), b.id('__block')),
797
+ b.call('$.spread_props', b.thunk(b.object(props)), b.id('__block')),
827
798
  b.id('$.active_block'),
828
799
  ),
829
800
  ),
@@ -952,23 +923,6 @@ const visitors = {
952
923
  );
953
924
  }
954
925
 
955
- if (left.type === 'MemberExpression') {
956
- // need to capture setting length of array to throw a runtime error
957
- if (left.property.type === 'Identifier' && left.property.name === 'length') {
958
- if (left.property.name !== '$length') {
959
- return b.call(
960
- '$.old_set_property',
961
- context.visit(left.object),
962
- left.computed ? context.visit(left.property) : b.literal(left.property.name),
963
- visit_assignment_expression(node, context, build_assignment) ?? context.next(),
964
- b.id('__block'),
965
- );
966
- }
967
- } else if (!is_tracked_computed_property(left.object, left.property, context)) {
968
- return context.next();
969
- }
970
- }
971
-
972
926
  if (left.type === 'Identifier' && left.tracked) {
973
927
  add_ripple_internal_import(context);
974
928
  const operator = node.operator;
@@ -990,18 +944,7 @@ const visitors = {
990
944
  );
991
945
  }
992
946
 
993
- const visited = visit_assignment_expression(node, context, build_assignment) ?? context.next();
994
-
995
- if (
996
- left.type === 'MemberExpression' &&
997
- left.property.type === 'Identifier' &&
998
- left.property.name === '$length' &&
999
- !left.computed
1000
- ) {
1001
- return b.call('$.with_scope', b.id('__block'), b.thunk(visited));
1002
- }
1003
-
1004
- return visited;
947
+ return visit_assignment_expression(node, context, build_assignment) ?? context.next();
1005
948
  },
1006
949
 
1007
950
  UpdateExpression(node, context) {
@@ -1028,20 +971,6 @@ const visitors = {
1028
971
  );
1029
972
  }
1030
973
 
1031
- if (
1032
- argument.type === 'MemberExpression' &&
1033
- argument.computed &&
1034
- is_tracked_computed_property(argument.object, argument.property, context)
1035
- ) {
1036
- return b.call(
1037
- node.prefix ? '$.old_update_pre_property' : '$.old_update_property',
1038
- context.visit(argument.object),
1039
- argument.computed ? context.visit(argument.property) : b.literal(argument.property.name),
1040
- b.id('__block'),
1041
- node.operator === '--' ? b.literal(-1) : undefined,
1042
- );
1043
- }
1044
-
1045
974
  if (argument.type === 'Identifier' && argument.tracked) {
1046
975
  return b.call(
1047
976
  node.prefix ? '$.update_pre' : '$.update',
@@ -1543,7 +1472,7 @@ function transform_children(children, context) {
1543
1472
  if (
1544
1473
  node.type === 'VariableDeclaration' ||
1545
1474
  node.type === 'ExpressionStatement' ||
1546
- node.type === 'ThrowStatement' ||
1475
+ node.type === 'ThrowStatement' ||
1547
1476
  node.type === 'FunctionDeclaration' ||
1548
1477
  node.type === 'DebuggerStatement' ||
1549
1478
  node.type === 'ClassDeclaration'
@@ -62,6 +62,10 @@ function escape_comment_close(node, code) {
62
62
  }
63
63
  }
64
64
 
65
+ function append_hash(state, index) {
66
+ state.code.prependRight(index, `${state.hash}-`);
67
+ }
68
+
65
69
  /**
66
70
  * @param {AST.CSS.Rule} rule
67
71
  * @param {boolean} is_in_global_block
@@ -106,7 +110,9 @@ const visitors = {
106
110
  if (node.prelude.startsWith('-global-')) {
107
111
  state.code.remove(start, start + 8);
108
112
  } else if (!is_in_global_block(path)) {
109
- state.code.prependRight(start, `${state.hash}-`);
113
+ append_hash(state, start);
114
+ state.keyframes[node.prelude]?.indexes.forEach((index) => append_hash(state, index));
115
+ state.keyframes[node.prelude] = { indexes: [], local: true };
110
116
  }
111
117
 
112
118
  return; // don't transform anything within
@@ -124,8 +130,14 @@ const visitors = {
124
130
  const character = state.code.original[index];
125
131
 
126
132
  if (regex_css_name_boundary.test(character)) {
127
- if (state.keyframes.includes(name)) {
128
- state.code.prependRight(index - name.length, `${state.hash}-`);
133
+ if (character !== ' ') {
134
+ const append_index = index - name.length;
135
+ state.keyframes[name] ??= { indexes: [], local: undefined };
136
+ if (state.keyframes[name].local) {
137
+ append_hash(state, append_index);
138
+ } else {
139
+ state.keyframes[name].indexes.push(append_index);
140
+ }
129
141
  }
130
142
 
131
143
  if (character === ';' || character === '}') {
@@ -360,6 +372,7 @@ export function render_stylesheets(stylesheets) {
360
372
  code,
361
373
  hash: stylesheet.hash,
362
374
  selector: `.${stylesheet.hash}`,
375
+ keyframes: {},
363
376
  specificity: {
364
377
  bumped: false,
365
378
  },
@@ -454,26 +454,6 @@ export function is_value_static(node) {
454
454
  return false;
455
455
  }
456
456
 
457
- export function is_tracked_computed_property(object, property, context) {
458
- if (object.tracked) {
459
- return false;
460
- }
461
- const binding = context.state.scope.get(object.name);
462
-
463
- if (binding) {
464
- const initial = binding.initial;
465
- if (initial && is_value_static(initial)) {
466
- return false;
467
- }
468
- }
469
- if (property.type === 'Identifier') {
470
- return true;
471
- }
472
-
473
- // TODO: do we need to handle more logic here? default to false for now
474
- return true;
475
- }
476
-
477
457
  export function is_ripple_import(callee, context) {
478
458
  if (callee.type === 'Identifier') {
479
459
  const binding = context.state.scope.get(callee.name);