@typescript-eslint/typescript-estree 8.50.2-alpha.7 → 8.50.2-alpha.9

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/convert.js +55 -54
  2. package/package.json +5 -5
package/dist/convert.js CHANGED
@@ -709,8 +709,8 @@ class Converter {
709
709
  return this.fixExports(node, result);
710
710
  }
711
711
  case SyntaxKind.VariableDeclaration: {
712
- const definite = !!node.exclamationToken;
713
- if (definite) {
712
+ const hasExclamationToken = !!node.exclamationToken;
713
+ if (hasExclamationToken) {
714
714
  if (node.initializer) {
715
715
  this.#throwError(node, 'Declarations with initializers cannot also have definite assignment assertions.');
716
716
  }
@@ -718,60 +718,72 @@ class Converter {
718
718
  this.#throwError(node, 'Declarations with definite assignment assertions must also have type annotations.');
719
719
  }
720
720
  }
721
+ if (node.parent.kind === SyntaxKind.VariableDeclarationList) {
722
+ const variableDeclarationList = node.parent;
723
+ const kind = (0, node_utils_1.getDeclarationKind)(variableDeclarationList);
724
+ if ((variableDeclarationList.parent.kind ===
725
+ SyntaxKind.ForInStatement ||
726
+ variableDeclarationList.parent.kind ===
727
+ SyntaxKind.ForStatement) &&
728
+ (kind === 'using' || kind === 'await using')) {
729
+ if (!node.initializer) {
730
+ this.#throwError(node, `'${kind}' declarations may not be initialized in for statement.`);
731
+ }
732
+ if (node.name.kind !== SyntaxKind.Identifier) {
733
+ this.#throwError(node.name, `'${kind}' declarations may not have binding patterns.`);
734
+ }
735
+ }
736
+ if (variableDeclarationList.parent.kind === SyntaxKind.VariableStatement) {
737
+ const variableStatement = variableDeclarationList.parent;
738
+ if (kind === 'using' || kind === 'await using') {
739
+ if (!node.initializer) {
740
+ this.#throwError(node, `'${kind}' declarations must be initialized.`);
741
+ }
742
+ if (node.name.kind !== SyntaxKind.Identifier) {
743
+ this.#throwError(node.name, `'${kind}' declarations may not have binding patterns.`);
744
+ }
745
+ }
746
+ const hasDeclareKeyword = (0, node_utils_1.hasModifier)(SyntaxKind.DeclareKeyword, variableStatement);
747
+ // Definite assignment only allowed for non-declare let and var
748
+ if ((hasDeclareKeyword ||
749
+ ['await using', 'const', 'using'].includes(kind)) &&
750
+ hasExclamationToken) {
751
+ this.#throwError(node, `A definite assignment assertion '!' is not permitted in this context.`);
752
+ }
753
+ if (hasDeclareKeyword &&
754
+ node.initializer &&
755
+ (['let', 'var'].includes(kind) || node.type)) {
756
+ this.#throwError(node, `Initializers are not permitted in ambient contexts.`);
757
+ }
758
+ // Theoretically, only certain initializers are allowed for declare const,
759
+ // (TS1254: A 'const' initializer in an ambient context must be a string
760
+ // or numeric literal or literal enum reference.) but we just allow
761
+ // all expressions
762
+ // Note! No-declare does not mean the variable is not ambient, because
763
+ // it can be further nested in other declare contexts. Therefore we cannot
764
+ // check for const initializers.
765
+ }
766
+ }
721
767
  const init = this.convertChild(node.initializer);
722
768
  const id = this.convertBindingNameWithTypeAnnotation(node.name, node.type, node);
723
769
  return this.createNode(node, {
724
770
  type: ts_estree_1.AST_NODE_TYPES.VariableDeclarator,
725
- definite,
771
+ definite: hasExclamationToken,
726
772
  id,
727
773
  init,
728
774
  });
729
775
  }
730
776
  case SyntaxKind.VariableStatement: {
777
+ const declarations = node.declarationList.declarations;
778
+ if (!declarations.length) {
779
+ this.#throwError(node, 'A variable declaration list must have at least one variable declarator.');
780
+ }
731
781
  const result = this.createNode(node, {
732
782
  type: ts_estree_1.AST_NODE_TYPES.VariableDeclaration,
733
- declarations: this.convertChildren(node.declarationList.declarations),
783
+ declarations: this.convertChildren(declarations),
734
784
  declare: (0, node_utils_1.hasModifier)(SyntaxKind.DeclareKeyword, node),
735
785
  kind: (0, node_utils_1.getDeclarationKind)(node.declarationList),
736
786
  });
737
- if (!result.declarations.length) {
738
- this.#throwError(node, 'A variable declaration list must have at least one variable declarator.');
739
- }
740
- if (result.kind === 'using' || result.kind === 'await using') {
741
- node.declarationList.declarations.forEach((declaration, i) => {
742
- if (result.declarations[i].init == null) {
743
- this.#throwError(declaration, `'${result.kind}' declarations must be initialized.`);
744
- }
745
- if (result.declarations[i].id.type !== ts_estree_1.AST_NODE_TYPES.Identifier) {
746
- this.#throwError(declaration.name, `'${result.kind}' declarations may not have binding patterns.`);
747
- }
748
- });
749
- }
750
- // Definite assignment only allowed for non-declare let and var
751
- if (result.declare ||
752
- ['await using', 'const', 'using'].includes(result.kind)) {
753
- node.declarationList.declarations.forEach((declaration, i) => {
754
- if (result.declarations[i].definite) {
755
- this.#throwError(declaration, `A definite assignment assertion '!' is not permitted in this context.`);
756
- }
757
- });
758
- }
759
- if (result.declare) {
760
- node.declarationList.declarations.forEach((declaration, i) => {
761
- if (result.declarations[i].init &&
762
- (['let', 'var'].includes(result.kind) ||
763
- result.declarations[i].id.typeAnnotation)) {
764
- this.#throwError(declaration, `Initializers are not permitted in ambient contexts.`);
765
- }
766
- });
767
- // Theoretically, only certain initializers are allowed for declare const,
768
- // (TS1254: A 'const' initializer in an ambient context must be a string
769
- // or numeric literal or literal enum reference.) but we just allow
770
- // all expressions
771
- }
772
- // Note! No-declare does not mean the variable is not ambient, because
773
- // it can be further nested in other declare contexts. Therefore we cannot
774
- // check for const initializers.
775
787
  /**
776
788
  * Semantically, decorators are not allowed on variable declarations,
777
789
  * Pre 4.8 TS would include them in the AST, so we did as well.
@@ -783,23 +795,12 @@ class Converter {
783
795
  }
784
796
  // mostly for for-of, for-in
785
797
  case SyntaxKind.VariableDeclarationList: {
786
- const result = this.createNode(node, {
798
+ return this.createNode(node, {
787
799
  type: ts_estree_1.AST_NODE_TYPES.VariableDeclaration,
788
800
  declarations: this.convertChildren(node.declarations),
789
801
  declare: false,
790
802
  kind: (0, node_utils_1.getDeclarationKind)(node),
791
803
  });
792
- if (result.kind === 'using' || result.kind === 'await using') {
793
- node.declarations.forEach((declaration, i) => {
794
- if (result.declarations[i].init != null) {
795
- this.#throwError(declaration, `'${result.kind}' declarations may not be initialized in for statement.`);
796
- }
797
- if (result.declarations[i].id.type !== ts_estree_1.AST_NODE_TYPES.Identifier) {
798
- this.#throwError(declaration.name, `'${result.kind}' declarations may not have binding patterns.`);
799
- }
800
- });
801
- }
802
- return result;
803
804
  }
804
805
  // Expressions
805
806
  case SyntaxKind.ExpressionStatement:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typescript-eslint/typescript-estree",
3
- "version": "8.50.2-alpha.7",
3
+ "version": "8.50.2-alpha.9",
4
4
  "description": "A parser that converts TypeScript source code into an ESTree compatible form",
5
5
  "files": [
6
6
  "dist",
@@ -52,10 +52,10 @@
52
52
  "typecheck": "yarn run -BT nx typecheck"
53
53
  },
54
54
  "dependencies": {
55
- "@typescript-eslint/project-service": "8.50.2-alpha.7",
56
- "@typescript-eslint/tsconfig-utils": "8.50.2-alpha.7",
57
- "@typescript-eslint/types": "8.50.2-alpha.7",
58
- "@typescript-eslint/visitor-keys": "8.50.2-alpha.7",
55
+ "@typescript-eslint/project-service": "8.50.2-alpha.9",
56
+ "@typescript-eslint/tsconfig-utils": "8.50.2-alpha.9",
57
+ "@typescript-eslint/types": "8.50.2-alpha.9",
58
+ "@typescript-eslint/visitor-keys": "8.50.2-alpha.9",
59
59
  "debug": "^4.3.4",
60
60
  "minimatch": "^9.0.4",
61
61
  "semver": "^7.6.0",