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.
Files changed (34) hide show
  1. package/README.md +1 -1
  2. package/package.json +1 -1
  3. package/src/compiler/errors.js +20 -22
  4. package/src/compiler/phases/1-parse/index.js +21 -19
  5. package/src/compiler/phases/1-parse/style.js +27 -27
  6. package/src/compiler/phases/2-analyze/index.js +25 -25
  7. package/src/compiler/phases/2-analyze/prune.js +64 -27
  8. package/src/compiler/phases/3-transform/index.js +150 -113
  9. package/src/compiler/phases/3-transform/segments.js +25 -20
  10. package/src/compiler/phases/3-transform/stylesheet.js +28 -28
  11. package/src/compiler/scope.js +3 -3
  12. package/src/compiler/utils.js +7 -9
  13. package/src/constants.js +1 -2
  14. package/src/jsx-runtime.d.ts +59 -59
  15. package/src/jsx-runtime.js +13 -13
  16. package/src/runtime/array.js +15 -15
  17. package/src/runtime/index.js +2 -0
  18. package/src/runtime/internal/client/blocks.js +16 -5
  19. package/src/runtime/internal/client/constants.js +1 -1
  20. package/src/runtime/internal/client/events.js +2 -2
  21. package/src/runtime/internal/client/for.js +6 -7
  22. package/src/runtime/internal/client/operations.js +1 -1
  23. package/src/runtime/internal/client/runtime.js +41 -20
  24. package/src/runtime/internal/client/template.js +1 -1
  25. package/src/runtime/internal/client/try.js +2 -2
  26. package/src/utils/ast.js +9 -9
  27. package/src/utils/builders.js +66 -28
  28. package/tests/__snapshots__/for.test.ripple.snap +81 -0
  29. package/tests/basic.test.ripple +292 -263
  30. package/tests/composite.test.ripple +151 -0
  31. package/tests/for.test.ripple +58 -0
  32. package/tests/ref.test.ripple +52 -0
  33. package/tests/use.test.ripple +24 -22
  34. package/types/index.d.ts +7 -1
package/README.md CHANGED
@@ -7,4 +7,4 @@
7
7
 
8
8
  > Currently, this project is still in early development, and should not be used in production.
9
9
 
10
- Ripple is a TypeScript UI framework for the web. To find out more, view [Ripple's Github README](https://github.com/trueadm/ripple).
10
+ Ripple is a TypeScript UI framework for the web. To find out more, view [Ripple's Github README](https://github.com/trueadm/ripple).
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "Ripple is a TypeScript UI framework for the web",
4
4
  "license": "MIT",
5
5
  "author": "Dominic Gannaway",
6
- "version": "0.2.6",
6
+ "version": "0.2.8",
7
7
  "type": "module",
8
8
  "module": "src/runtime/index.js",
9
9
  "main": "src/runtime/index.js",
@@ -1,26 +1,24 @@
1
-
2
-
3
1
  /**
4
- *
5
- * @param {string} message
2
+ *
3
+ * @param {string} message
6
4
  * @param {string} filename
7
- * @param {any} node
5
+ * @param {any} node
8
6
  */
9
7
  export function error(message, filename, node) {
10
- let errorMessage = message;
11
-
12
- if (node && node.loc) {
13
- // Use GitHub-style range format: filename#L39C24-L39C32
14
- const startLine = node.loc.start.line;
15
- const startColumn = node.loc.start.column;
16
- const endLine = node.loc.end.line;
17
- const endColumn = node.loc.end.column;
18
-
19
- const rangeInfo = `${filename}#L${startLine}C${startColumn}-L${endLine}C${endColumn}`;
20
- errorMessage += ` (${rangeInfo})`;
21
- } else {
22
- errorMessage += ` (${filename})`;
23
- }
24
-
25
- throw new Error(errorMessage);
26
- }
8
+ let errorMessage = message;
9
+
10
+ if (node && node.loc) {
11
+ // Use GitHub-style range format: filename#L39C24-L39C32
12
+ const startLine = node.loc.start.line;
13
+ const startColumn = node.loc.start.column;
14
+ const endLine = node.loc.end.line;
15
+ const endColumn = node.loc.end.column;
16
+
17
+ const rangeInfo = `${filename}#L${startLine}C${startColumn}-L${endLine}C${endColumn}`;
18
+ errorMessage += ` (${rangeInfo})`;
19
+ } else {
20
+ errorMessage += ` (${filename})`;
21
+ }
22
+
23
+ throw new Error(errorMessage);
24
+ }
@@ -67,7 +67,6 @@ function RipplePlugin(config) {
67
67
  }
68
68
 
69
69
  jsx_parseExpressionContainer() {
70
- const tok = this.acornTypeScript.tokTypes;
71
70
  let node = this.startNode();
72
71
  this.next();
73
72
 
@@ -136,13 +135,6 @@ function RipplePlugin(config) {
136
135
  this.raise(t.start, 'attributes must only be assigned a non-empty expression'),
137
136
  t
138
137
  );
139
- // case tt.bracketL:
140
- // var t = this.jsx_parseTupleContainer();
141
- // return (
142
- // 'JSXEmptyExpression' === t.expression.type &&
143
- // this.raise(t.start, 'attributes must only be assigned a non-empty expression'),
144
- // t
145
- // );
146
138
  case tok.jsxTagStart:
147
139
  case tt.string:
148
140
  return this.parseExprAtom();
@@ -236,7 +228,7 @@ function RipplePlugin(config) {
236
228
  commentStart,
237
229
  commentEnd,
238
230
  startLoc,
239
- endLoc
231
+ endLoc,
240
232
  );
241
233
  }
242
234
 
@@ -273,7 +265,7 @@ function RipplePlugin(config) {
273
265
  commentStart,
274
266
  commentEnd,
275
267
  startLoc,
276
- endLoc
268
+ endLoc,
277
269
  );
278
270
  }
279
271
 
@@ -294,7 +286,10 @@ function RipplePlugin(config) {
294
286
  case 62: // '>'
295
287
  case 125: {
296
288
  // '}'
297
- if (ch === 125 && this.#path.at(-1).type === 'Component') {
289
+ if (
290
+ ch === 125 &&
291
+ (this.#path.length === 0 || this.#path.at(-1)?.type === 'Component')
292
+ ) {
298
293
  return original.readToken.call(this, ch);
299
294
  }
300
295
  this.raise(
@@ -307,7 +302,7 @@ function RipplePlugin(config) {
307
302
  '`{"' +
308
303
  this.input[this.pos] +
309
304
  '"}' +
310
- '`?'
305
+ '`?',
311
306
  );
312
307
  }
313
308
 
@@ -316,7 +311,7 @@ function RipplePlugin(config) {
316
311
  out += this.input.slice(chunkStart, this.pos);
317
312
  out += this.jsx_readNewLine(true);
318
313
  chunkStart = this.pos;
319
- } else if (ch === 32) {
314
+ } else if (ch === 32 || ch === 9) {
320
315
  ++this.pos;
321
316
  } else {
322
317
  this.context.push(tc.b_stat);
@@ -364,8 +359,8 @@ function RipplePlugin(config) {
364
359
 
365
360
  if (element.selfClosing) {
366
361
  this.#path.pop();
367
- if (this.type !== tok.jsxTagStart) {
368
- // Eat the closing `/>`
362
+
363
+ if (this.type.label === '</>/<=/>=') {
369
364
  this.pos--;
370
365
  this.next();
371
366
  }
@@ -396,6 +391,13 @@ function RipplePlugin(config) {
396
391
  } else {
397
392
  this.parseTemplateBody(element.children);
398
393
  }
394
+ const tok = this.acornTypeScript.tokContexts;
395
+
396
+ const curContext = this.curContext();
397
+
398
+ if (curContext === tok.tc_expr) {
399
+ this.context.pop();
400
+ }
399
401
  }
400
402
 
401
403
  this.finishNode(element, 'Element');
@@ -429,7 +431,7 @@ function RipplePlugin(config) {
429
431
  noCalls,
430
432
  maybeAsyncArrow,
431
433
  optionalChained,
432
- forInit
434
+ forInit,
433
435
  );
434
436
  }
435
437
 
@@ -573,10 +575,10 @@ export function parse(source) {
573
575
  end,
574
576
  loc: {
575
577
  start: startLoc,
576
- end: endLoc
577
- }
578
+ end: endLoc,
579
+ },
578
580
  });
579
- }
581
+ },
580
582
  });
581
583
  } catch (e) {
582
584
  throw e;
@@ -1,4 +1,4 @@
1
- import { hash } from "../../utils.js";
1
+ import { hash } from '../../utils.js';
2
2
 
3
3
  const REGEX_COMMENT_CLOSE = /\*\//;
4
4
  const REGEX_HTML_COMMENT_CLOSE = /-->/;
@@ -90,10 +90,10 @@ export function parse_style(content) {
90
90
  const parser = new Parser(content, false);
91
91
 
92
92
  return {
93
- source: content,
94
- hash: `ripple-${hash(content)}`,
93
+ source: content,
94
+ hash: `ripple-${hash(content)}`,
95
95
  type: 'StyleSheet',
96
- body: read_body(parser)
96
+ body: read_body(parser),
97
97
  };
98
98
  }
99
99
 
@@ -146,8 +146,8 @@ function read_rule(parser) {
146
146
  metadata: {
147
147
  parent_rule: null,
148
148
  has_local_selectors: false,
149
- is_global_block: false
150
- }
149
+ is_global_block: false,
150
+ },
151
151
  };
152
152
  }
153
153
 
@@ -175,7 +175,7 @@ function read_block(parser) {
175
175
  type: 'Block',
176
176
  start,
177
177
  end: parser.index,
178
- children
178
+ children,
179
179
  };
180
180
  }
181
181
 
@@ -220,7 +220,7 @@ function read_declaration(parser) {
220
220
  start,
221
221
  end,
222
222
  property,
223
- value
223
+ value,
224
224
  };
225
225
  }
226
226
 
@@ -280,7 +280,7 @@ function read_selector_list(parser, inside_pseudo_class = false) {
280
280
  type: 'SelectorList',
281
281
  start,
282
282
  end,
283
- children
283
+ children,
284
284
  };
285
285
  } else {
286
286
  parser.eat(',', true);
@@ -306,7 +306,7 @@ function read_combinator(parser) {
306
306
  type: 'Combinator',
307
307
  name,
308
308
  start: index,
309
- end
309
+ end,
310
310
  };
311
311
  }
312
312
 
@@ -315,7 +315,7 @@ function read_combinator(parser) {
315
315
  type: 'Combinator',
316
316
  name: ' ',
317
317
  start,
318
- end: parser.index
318
+ end: parser.index,
319
319
  };
320
320
  }
321
321
 
@@ -343,8 +343,8 @@ function read_selector(parser, inside_pseudo_class = false) {
343
343
  metadata: {
344
344
  is_global: false,
345
345
  is_global_like: false,
346
- scoped: false
347
- }
346
+ scoped: false,
347
+ },
348
348
  };
349
349
  }
350
350
 
@@ -359,7 +359,7 @@ function read_selector(parser, inside_pseudo_class = false) {
359
359
  type: 'NestingSelector',
360
360
  name: '&',
361
361
  start,
362
- end: parser.index
362
+ end: parser.index,
363
363
  });
364
364
  } else if (parser.eat('*')) {
365
365
  let name = '*';
@@ -373,28 +373,28 @@ function read_selector(parser, inside_pseudo_class = false) {
373
373
  type: 'TypeSelector',
374
374
  name,
375
375
  start,
376
- end: parser.index
376
+ end: parser.index,
377
377
  });
378
378
  } else if (parser.eat('#')) {
379
379
  relative_selector.selectors.push({
380
380
  type: 'IdSelector',
381
381
  name: read_identifier(parser),
382
382
  start,
383
- end: parser.index
383
+ end: parser.index,
384
384
  });
385
385
  } else if (parser.eat('.')) {
386
386
  relative_selector.selectors.push({
387
387
  type: 'ClassSelector',
388
388
  name: read_identifier(parser),
389
389
  start,
390
- end: parser.index
390
+ end: parser.index,
391
391
  });
392
392
  } else if (parser.eat('::')) {
393
393
  relative_selector.selectors.push({
394
394
  type: 'PseudoElementSelector',
395
395
  name: read_identifier(parser),
396
396
  start,
397
- end: parser.index
397
+ end: parser.index,
398
398
  });
399
399
  // We read the inner selectors of a pseudo element to ensure it parses correctly,
400
400
  // but we don't do anything with the result.
@@ -418,7 +418,7 @@ function read_selector(parser, inside_pseudo_class = false) {
418
418
  name,
419
419
  args,
420
420
  start,
421
- end: parser.index
421
+ end: parser.index,
422
422
  });
423
423
  } else if (parser.eat('[')) {
424
424
  parser.allow_whitespace();
@@ -449,7 +449,7 @@ function read_selector(parser, inside_pseudo_class = false) {
449
449
  name,
450
450
  matcher,
451
451
  value,
452
- flags
452
+ flags,
453
453
  });
454
454
  } else if (inside_pseudo_class && parser.match_regex(REGEX_NTH_OF)) {
455
455
  // nth of matcher must come before combinator matcher to prevent collision else the '+' in '+2n-1' would be parsed as a combinator
@@ -458,14 +458,14 @@ function read_selector(parser, inside_pseudo_class = false) {
458
458
  type: 'Nth',
459
459
  value: /**@type {string} */ (parser.read(REGEX_NTH_OF)),
460
460
  start,
461
- end: parser.index
461
+ end: parser.index,
462
462
  });
463
463
  } else if (parser.match_regex(REGEX_PERCENTAGE)) {
464
464
  relative_selector.selectors.push({
465
465
  type: 'Percentage',
466
466
  value: /** @type {string} */ (parser.read(REGEX_PERCENTAGE)),
467
467
  start,
468
- end: parser.index
468
+ end: parser.index,
469
469
  });
470
470
  } else if (!parser.match_regex(REGEX_COMBINATOR)) {
471
471
  let name = read_identifier(parser);
@@ -479,7 +479,7 @@ function read_selector(parser, inside_pseudo_class = false) {
479
479
  type: 'TypeSelector',
480
480
  name,
481
481
  start,
482
- end: parser.index
482
+ end: parser.index,
483
483
  });
484
484
  }
485
485
 
@@ -500,8 +500,8 @@ function read_selector(parser, inside_pseudo_class = false) {
500
500
  children,
501
501
  metadata: {
502
502
  rule: null,
503
- used: false
504
- }
503
+ used: false,
504
+ },
505
505
  };
506
506
  }
507
507
 
@@ -539,7 +539,7 @@ function read_identifier(parser) {
539
539
 
540
540
  let escaped = false;
541
541
 
542
- while (parser.index < parser.template.length) {
542
+ while (parser.index < parser.template.length) {
543
543
  const char = parser.template[parser.index];
544
544
  if (escaped) {
545
545
  identifier += '\\' + char;
@@ -559,7 +559,7 @@ function read_identifier(parser) {
559
559
  }
560
560
 
561
561
  if (identifier === '') {
562
- throw new Error('Expected identifier');
562
+ throw new Error('Expected identifier');
563
563
  }
564
564
 
565
565
  return identifier;
@@ -6,7 +6,7 @@ import {
6
6
  is_event_attribute,
7
7
  is_inside_component,
8
8
  is_svelte_import,
9
- is_tracked_name
9
+ is_tracked_name,
10
10
  } from '../../utils.js';
11
11
  import { extract_paths } from '../../../utils/ast.js';
12
12
  import is_reference from 'is-reference';
@@ -18,7 +18,7 @@ function visit_function(node, context) {
18
18
  hoisted: false,
19
19
  hoisted_params: [],
20
20
  scope: context.state.scope,
21
- tracked: false
21
+ tracked: false,
22
22
  };
23
23
 
24
24
  if (node.params.length > 0) {
@@ -37,7 +37,7 @@ function visit_function(node, context) {
37
37
  binding.kind = 'prop';
38
38
 
39
39
  binding.transform = {
40
- read: (_) => b.call('$.get_property', b.id(id), b.literal(name))
40
+ read: (_) => b.call('$.get_property', b.id(id), b.literal(name)),
41
41
  };
42
42
  }
43
43
  }
@@ -48,7 +48,7 @@ function visit_function(node, context) {
48
48
  context.next({
49
49
  ...context.state,
50
50
  function_depth: context.state.function_depth + 1,
51
- expression: null
51
+ expression: null,
52
52
  });
53
53
  }
54
54
 
@@ -192,9 +192,9 @@ const visitors = {
192
192
  node.prefix ? '$.update_pre' : '$.update',
193
193
  node.argument,
194
194
  b.id('__block'),
195
- node.operator === '--' && b.literal(-1)
195
+ node.operator === '--' && b.literal(-1),
196
196
  );
197
- }
197
+ },
198
198
  };
199
199
  } else {
200
200
  visit(declarator, state);
@@ -202,7 +202,7 @@ const visitors = {
202
202
  } else {
203
203
  const paths = extract_paths(declarator.id);
204
204
  const has_tracked = paths.some(
205
- (path) => path.node.type === 'Identifier' && is_tracked_name(path.node.name)
205
+ (path) => path.node.type === 'Identifier' && is_tracked_name(path.node.name),
206
206
  );
207
207
 
208
208
  if (has_tracked) {
@@ -234,7 +234,7 @@ const visitors = {
234
234
  b.call('$.get_computed', value.object),
235
235
  value.property.type === 'Identifier'
236
236
  ? b.literal(value.property.name)
237
- : value.property
237
+ : value.property,
238
238
  );
239
239
  }
240
240
 
@@ -246,7 +246,7 @@ const visitors = {
246
246
  return b.member(
247
247
  b.call('$.get_computed', value.object),
248
248
  key,
249
- key.type === 'Literal'
249
+ key.type === 'Literal',
250
250
  );
251
251
  }
252
252
 
@@ -256,12 +256,12 @@ const visitors = {
256
256
  value.object,
257
257
  value.property.type === 'Identifier'
258
258
  ? b.literal(value.property.name)
259
- : value.property
259
+ : value.property,
260
260
  );
261
261
  }
262
262
 
263
263
  return value;
264
- }
264
+ },
265
265
  };
266
266
  }
267
267
  } else {
@@ -300,7 +300,7 @@ const visitors = {
300
300
  binding.kind = 'prop';
301
301
 
302
302
  binding.transform = {
303
- read: (_) => b.call('$.get_property', b.id('__props'), b.literal(name))
303
+ read: (_) => b.call('$.get_property', b.id('__props'), b.literal(name)),
304
304
  };
305
305
  }
306
306
  }
@@ -324,7 +324,7 @@ const visitors = {
324
324
  error(
325
325
  'For loops are not supported in components. Use for...of instead.',
326
326
  context.state.analysis.module.filename,
327
- node
327
+ node,
328
328
  );
329
329
  }
330
330
 
@@ -336,7 +336,7 @@ const visitors = {
336
336
  error(
337
337
  'For...in loops are not supported in components. Use for...of instead.',
338
338
  context.state.analysis.module.filename,
339
- node
339
+ node,
340
340
  );
341
341
  }
342
342
 
@@ -348,7 +348,7 @@ const visitors = {
348
348
  error(
349
349
  'Elements cannot be used as generic expressions, only as statements within a component',
350
350
  context.state.analysis.module.filename,
351
- node
351
+ node,
352
352
  );
353
353
  }
354
354
  },
@@ -411,7 +411,7 @@ const visitors = {
411
411
  error(
412
412
  'Cannot have both implicit and explicit children',
413
413
  context.state.analysis.module.filename,
414
- node
414
+ node,
415
415
  );
416
416
  }
417
417
  }
@@ -421,7 +421,7 @@ const visitors = {
421
421
  error(
422
422
  'Cannot have both implicit and explicit children',
423
423
  context.state.analysis.module.filename,
424
- node
424
+ node,
425
425
  );
426
426
  }
427
427
  }
@@ -436,13 +436,13 @@ const visitors = {
436
436
  error(
437
437
  'Cannot have a `children` prop on an element',
438
438
  state.analysis.module.filename,
439
- attribute
439
+ attribute,
440
440
  );
441
441
  } else {
442
442
  error(
443
443
  'Cannot have a `children` prop on a component, did you mean `$children`?',
444
444
  state.analysis.module.filename,
445
- attribute
445
+ attribute,
446
446
  );
447
447
  }
448
448
  }
@@ -453,7 +453,7 @@ const visitors = {
453
453
  error(
454
454
  `Cannot have both ${name} and ${name.slice(1)} on the same element`,
455
455
  state.analysis.module.filename,
456
- n
456
+ n,
457
457
  );
458
458
  }
459
459
  });
@@ -462,7 +462,7 @@ const visitors = {
462
462
 
463
463
  return {
464
464
  ...node,
465
- children: node.children.map((child) => visit(child))
465
+ children: node.children.map((child) => visit(child)),
466
466
  };
467
467
  },
468
468
 
@@ -474,7 +474,7 @@ const visitors = {
474
474
  }
475
475
 
476
476
  context.next();
477
- }
477
+ },
478
478
  };
479
479
 
480
480
  export function analyze(ast, filename) {
@@ -486,7 +486,7 @@ export function analyze(ast, filename) {
486
486
  module: { ast, scope, scopes, filename },
487
487
  ast,
488
488
  scope,
489
- scopes
489
+ scopes,
490
490
  };
491
491
 
492
492
  walk(
@@ -494,9 +494,9 @@ export function analyze(ast, filename) {
494
494
  {
495
495
  scope,
496
496
  scopes,
497
- analysis
497
+ analysis,
498
498
  },
499
- visitors
499
+ visitors,
500
500
  );
501
501
 
502
502
  return analysis;