@typescript-eslint/typescript-estree 8.70.1-alpha.11 → 8.70.1-alpha.13

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 (2) hide show
  1. package/dist/node-utils.js +47 -2
  2. package/package.json +5 -5
@@ -521,8 +521,16 @@ function convertTokens(ast) {
521
521
  if (isComment(node) || isJSDocComment(node)) {
522
522
  return;
523
523
  }
524
- if (isToken(node) && node.kind !== SyntaxKind.EndOfFileToken) {
525
- result.push(convertToken(node, ast));
524
+ const { kind } = node;
525
+ if (isToken(node) && kind !== SyntaxKind.EndOfFileToken) {
526
+ const token = convertToken(node, ast);
527
+ // TypeScript drops first half of a `<<` in some cases.
528
+ // Gating on `kind` (a cheap check) keeps the rest of the check,
529
+ // which has to look at the text, off the hot path.
530
+ if (kind === SyntaxKind.LessThanToken) {
531
+ addMissingLessThanToken(result, token, ast);
532
+ }
533
+ result.push(token);
526
534
  }
527
535
  else {
528
536
  node.getChildren(ast).forEach(walk);
@@ -531,6 +539,43 @@ function convertTokens(ast) {
531
539
  walk(ast);
532
540
  return result;
533
541
  }
542
+ /**
543
+ * TypeScript recovers the tokens its parser did not keep as children of a node
544
+ * (`<` and `>` of a type argument list, for instance) by re-scanning the source
545
+ * text in the gaps between the children it did keep, and discards any token
546
+ * that runs past the end of the gap being filled.
547
+ *
548
+ * Its scanner produces `<<` as a single token, which the parser splits back
549
+ * apart when the second `<` opens a type parameter list, as in
550
+ * `ReturnType<<T>(x: T) => number>`. The re-scan is not aware of that split,
551
+ * so the `<<` it scans overruns the gap left by the first `<`, and that token
552
+ * is dropped from `getChildren()` entirely.
553
+ *
554
+ * Text skipped in front of a token can otherwise only be trivia, and no trivia
555
+ * can end in a `<`: line comments, shebangs and conflict markers all run to the
556
+ * end of a line, and block comments all end in `*` + `/`. So a `<` sitting
557
+ * directly in front of a token, with anything at all skipped before it,
558
+ * is unambiguously a token TypeScript lost.
559
+ *
560
+ * Only ever called for a `<` token — see the caller.
561
+ */
562
+ function addMissingLessThanToken(result, token, ast) {
563
+ if (result.length === 0) {
564
+ return;
565
+ }
566
+ const currentTokenStart = token.range[0];
567
+ const previousTokenEnd = result[result.length - 1].range[1];
568
+ if (currentTokenStart > previousTokenEnd &&
569
+ ast.text[currentTokenStart - 1] === '<') {
570
+ const range = [currentTokenStart - 1, currentTokenStart];
571
+ result.push({
572
+ type: ts_estree_1.AST_TOKEN_TYPES.Punctuator,
573
+ loc: getLocFor(range, ast),
574
+ range,
575
+ value: '<',
576
+ });
577
+ }
578
+ }
534
579
  class TSError extends Error {
535
580
  fileName;
536
581
  location;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typescript-eslint/typescript-estree",
3
- "version": "8.70.1-alpha.11",
3
+ "version": "8.70.1-alpha.13",
4
4
  "description": "A parser that converts TypeScript source code into an ESTree compatible form",
5
5
  "files": [
6
6
  "dist",
@@ -43,10 +43,10 @@
43
43
  "syntax"
44
44
  ],
45
45
  "dependencies": {
46
- "@typescript-eslint/project-service": "8.70.1-alpha.11",
47
- "@typescript-eslint/tsconfig-utils": "8.70.1-alpha.11",
48
- "@typescript-eslint/types": "8.70.1-alpha.11",
49
- "@typescript-eslint/visitor-keys": "8.70.1-alpha.11",
46
+ "@typescript-eslint/project-service": "8.70.1-alpha.13",
47
+ "@typescript-eslint/tsconfig-utils": "8.70.1-alpha.13",
48
+ "@typescript-eslint/types": "8.70.1-alpha.13",
49
+ "@typescript-eslint/visitor-keys": "8.70.1-alpha.13",
50
50
  "debug": "^4.4.3",
51
51
  "minimatch": "^10.2.2",
52
52
  "semver": "^7.7.3",