@tsrx/core 0.1.26 → 0.1.27

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": "Core compiler infrastructure for TSRX syntax",
4
4
  "license": "MIT",
5
5
  "author": "Dominic Gannaway",
6
- "version": "0.1.26",
6
+ "version": "0.1.27",
7
7
  "type": "module",
8
8
  "repository": {
9
9
  "type": "git",
package/src/plugin.js CHANGED
@@ -55,27 +55,6 @@ const CharCode = Object.freeze({
55
55
  closeBrace: 125,
56
56
  });
57
57
 
58
- /**
59
- * Keywords after which a `/` begins a regex literal rather than division, used
60
- * by the look-ahead scanners to track expression position in script content.
61
- */
62
- const REGEX_PRECEDING_KEYWORDS = new Set([
63
- 'return',
64
- 'typeof',
65
- 'instanceof',
66
- 'in',
67
- 'of',
68
- 'new',
69
- 'delete',
70
- 'void',
71
- 'do',
72
- 'else',
73
- 'yield',
74
- 'await',
75
- 'case',
76
- 'throw',
77
- ]);
78
-
79
58
  // Transparent wrappers to look through when validating a dynamic tag
80
59
  // expression (`<{expr}>`), and syntax that disqualifies one outright.
81
60
  const DYNAMIC_TAG_WRAPPER_TYPES = new Set([
@@ -596,6 +575,26 @@ export function TSRXPlugin(config) {
596
575
  }
597
576
  continue;
598
577
  }
578
+ if (this.#isTemplateBlockCommentStart(index)) {
579
+ const comment_start = index;
580
+ const comment_start_loc = acorn.getLineInfo(this.input, comment_start);
581
+ const close = this.input.indexOf('*/', index + 2);
582
+ const value_end = close === -1 ? this.input.length : close;
583
+ index = close === -1 ? this.input.length : close + 2;
584
+ if (this.options.onComment && comment_start >= token_end) {
585
+ const comment_end_loc = acorn.getLineInfo(this.input, index);
586
+ this.options.onComment(
587
+ true,
588
+ this.input.slice(comment_start + 2, value_end),
589
+ comment_start,
590
+ index,
591
+ new acorn.Position(comment_start_loc.line, comment_start_loc.column),
592
+ new acorn.Position(comment_end_loc.line, comment_end_loc.column),
593
+ /** @type {any} */ (null),
594
+ );
595
+ }
596
+ continue;
597
+ }
599
598
  const ch = this.input.charCodeAt(index);
600
599
  if (
601
600
  ch === CharCode.lessThan ||
@@ -972,6 +971,19 @@ export function TSRXPlugin(config) {
972
971
  );
973
972
  }
974
973
 
974
+ /**
975
+ * Unlike `//` (which is only a comment at line-start so inline text like
976
+ * `https://…` stays text), `/*` starts a comment anywhere in template
977
+ * text, matching `jsx_readToken`.
978
+ * @param {number} index
979
+ */
980
+ #isTemplateBlockCommentStart(index) {
981
+ return (
982
+ this.input.charCodeAt(index) === CharCode.slash &&
983
+ this.input.charCodeAt(index + 1) === CharCode.asterisk
984
+ );
985
+ }
986
+
975
987
  /**
976
988
  * @param {number} start
977
989
  */
@@ -984,7 +996,8 @@ export function TSRXPlugin(config) {
984
996
  ch === CharCode.openBrace ||
985
997
  ch === CharCode.closeBrace ||
986
998
  this.#isJSXControlFlowDirectiveAt(index) ||
987
- this.#isTemplateLineCommentStart(index)
999
+ this.#isTemplateLineCommentStart(index) ||
1000
+ this.#isTemplateBlockCommentStart(index)
988
1001
  ) {
989
1002
  break;
990
1003
  }
@@ -2005,9 +2018,10 @@ export function TSRXPlugin(config) {
2005
2018
  );
2006
2019
  const closingEnd = closingStart + '</style>'.length;
2007
2020
  const closingEndInfo = acorn.getLineInfo(this.input, closingEnd);
2008
- const closingElement = /** @type {ESTreeJSX.JSXClosingElement & AST.NodeWithLocation} */ (
2009
- this.startNodeAt(closingStart, closingStartLoc)
2010
- );
2021
+ const closingElement =
2022
+ /** @type {ESTreeJSX.TSRXJSXClosingElement & AST.NodeWithLocation} */ (
2023
+ this.startNodeAt(closingStart, closingStartLoc)
2024
+ );
2011
2025
  closingElement.name = name;
2012
2026
  this.finishNodeAt(
2013
2027
  closingElement,
@@ -4208,8 +4222,10 @@ export function TSRXPlugin(config) {
4208
4222
  } else {
4209
4223
  if (is_style) {
4210
4224
  /** @type {AST.JSXStyleElement} */ (node).type = 'JSXStyleElement';
4211
- /** @type {AST.JSXStyleElement} */ (node).openingElement = open;
4212
- /** @type {AST.JSXStyleElement} */ (node).closingElement = null;
4225
+ /** @type {AST.JSXStyleElement} */ (node).openingElement =
4226
+ /** @type {AST.JSXStyleElement['openingElement']} */ (open);
4227
+ /** @type {AST.JSXStyleElement} */ (node).closingElement =
4228
+ /** @type {AST.JSXStyleElement['closingElement']} */ (null);
4213
4229
  } else {
4214
4230
  /** @type {ESTreeJSX.JSXElement} */ (node).type = 'JSXElement';
4215
4231
  /** @type {ESTreeJSX.JSXElement} */ (node).openingElement = open;
package/types/index.d.ts CHANGED
@@ -253,6 +253,9 @@ declare module 'estree' {
253
253
  TsrxFragment: TsrxFragment;
254
254
  Text: Text;
255
255
  TSRXJSXElement: TSRXJSXElement;
256
+ TSRXJSXFragment: TSRXJSXFragment;
257
+ TSRXJSXOpeningElement: ESTreeJSX.TSRXJSXOpeningElement;
258
+ TSRXJSXClosingElement: ESTreeJSX.TSRXJSXClosingElement;
256
259
  TSRXExpression: TSRXExpression;
257
260
  Attribute: Attribute;
258
261
  SpreadAttribute: SpreadAttribute;
@@ -346,7 +349,11 @@ declare module 'estree' {
346
349
  | AST.JSXCodeBlock;
347
350
 
348
351
  interface TSRXJSXElement
349
- extends Omit<ESTreeJSX.JSXElement, 'children'>, AST.NodeWithMaybeComments {
352
+ extends
353
+ Omit<ESTreeJSX.JSXElement, 'children' | 'openingElement' | 'closingElement'>,
354
+ AST.NodeWithMaybeComments {
355
+ openingElement: ESTreeJSX.TSRXJSXOpeningElement;
356
+ closingElement: ESTreeJSX.TSRXJSXClosingElement | null;
350
357
  children: TSRXJSXChild[];
351
358
  metadata: BaseNodeMetaData & {
352
359
  ts_name?: string;
@@ -366,13 +373,10 @@ declare module 'estree' {
366
373
  innerComments?: AST.Comment[] | undefined;
367
374
  }
368
375
 
369
- interface JSXStyleElement extends AST.BaseExpression {
376
+ interface JSXStyleElement extends Omit<AST.TSRXJSXElement, 'type' | 'children'> {
370
377
  type: 'JSXStyleElement';
371
- openingElement: ESTreeJSX.JSXOpeningElement;
372
- closingElement: ESTreeJSX.JSXClosingElement | null;
373
378
  children: AST.CSS.StyleSheet[];
374
379
  css?: string;
375
- metadata: BaseNodeMetaData;
376
380
  unclosed?: boolean;
377
381
  }
378
382
 
@@ -520,7 +524,7 @@ declare module 'estree' {
520
524
 
521
525
  type TSRXStatement = AST.Statement | TSESTree.Statement;
522
526
 
523
- type NodeWithChildren = TSRXJSXElement | TSRXJSXFragment | JSXStyleElement;
527
+ type NodeWithChildren = TSRXJSXElement | TSRXJSXFragment | JSXStyleElement | ESTreeJSX.JSXElement;
524
528
 
525
529
  export namespace CSS {
526
530
  export interface BaseNode extends AST.NodeWithMaybeComments {
@@ -736,11 +740,11 @@ declare module 'estree-jsx' {
736
740
  }
737
741
 
738
742
  interface TSRXJSXOpeningElement extends Omit<JSXOpeningElement, 'name'> {
739
- name: AST.MemberExpression | JSXIdentifier | JSXNamespacedName;
743
+ name: AST.MemberExpression | JSXIdentifier | JSXNamespacedName | JSXExpressionContainer;
740
744
  }
741
745
 
742
746
  interface TSRXJSXClosingElement extends Omit<JSXClosingElement, 'name'> {
743
- name: AST.MemberExpression | JSXIdentifier | JSXNamespacedName;
747
+ name: AST.MemberExpression | JSXIdentifier | JSXNamespacedName | JSXExpressionContainer;
744
748
  }
745
749
 
746
750
  interface ExpressionMap {