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 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.7",
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
+ }
@@ -236,7 +236,7 @@ function RipplePlugin(config) {
236
236
  commentStart,
237
237
  commentEnd,
238
238
  startLoc,
239
- endLoc
239
+ endLoc,
240
240
  );
241
241
  }
242
242
 
@@ -273,7 +273,7 @@ function RipplePlugin(config) {
273
273
  commentStart,
274
274
  commentEnd,
275
275
  startLoc,
276
- endLoc
276
+ endLoc,
277
277
  );
278
278
  }
279
279
 
@@ -294,7 +294,7 @@ function RipplePlugin(config) {
294
294
  case 62: // '>'
295
295
  case 125: {
296
296
  // '}'
297
- if (ch === 125 && this.#path.at(-1).type === 'Component') {
297
+ if (ch === 125 && (this.#path.length === 0 || this.#path.at(-1)?.type === 'Component')) {
298
298
  return original.readToken.call(this, ch);
299
299
  }
300
300
  this.raise(
@@ -307,7 +307,7 @@ function RipplePlugin(config) {
307
307
  '`{"' +
308
308
  this.input[this.pos] +
309
309
  '"}' +
310
- '`?'
310
+ '`?',
311
311
  );
312
312
  }
313
313
 
@@ -316,7 +316,7 @@ function RipplePlugin(config) {
316
316
  out += this.input.slice(chunkStart, this.pos);
317
317
  out += this.jsx_readNewLine(true);
318
318
  chunkStart = this.pos;
319
- } else if (ch === 32) {
319
+ } else if (ch === 32 || ch === 9) {
320
320
  ++this.pos;
321
321
  } else {
322
322
  this.context.push(tc.b_stat);
@@ -364,7 +364,11 @@ function RipplePlugin(config) {
364
364
 
365
365
  if (element.selfClosing) {
366
366
  this.#path.pop();
367
- if (this.type !== tok.jsxTagStart) {
367
+ if (
368
+ this.type !== tok.jsxTagStart &&
369
+ this.type?.keyword !== 'for' &&
370
+ this.type?.keyword !== 'try'
371
+ ) {
368
372
  // Eat the closing `/>`
369
373
  this.pos--;
370
374
  this.next();
@@ -429,7 +433,7 @@ function RipplePlugin(config) {
429
433
  noCalls,
430
434
  maybeAsyncArrow,
431
435
  optionalChained,
432
- forInit
436
+ forInit,
433
437
  );
434
438
  }
435
439
 
@@ -573,10 +577,10 @@ export function parse(source) {
573
577
  end,
574
578
  loc: {
575
579
  start: startLoc,
576
- end: endLoc
577
- }
580
+ end: endLoc,
581
+ },
578
582
  });
579
- }
583
+ },
580
584
  });
581
585
  } catch (e) {
582
586
  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;