@typescript-eslint/typescript-estree 8.51.1-alpha.8 → 8.52.0

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.
@@ -234,6 +234,31 @@ function checkSyntaxError(tsNode) {
234
234
  throw (0, node_utils_1.createError)(node.expression, 'String literal expected.');
235
235
  }
236
236
  break;
237
+ case SyntaxKind.PrefixUnaryExpression:
238
+ case SyntaxKind.PostfixUnaryExpression: {
239
+ const operator = (0, node_utils_1.getTextForTokenKind)(node.operator);
240
+ /**
241
+ * ESTree uses UpdateExpression for ++/--
242
+ */
243
+ if ((operator === '++' || operator === '--') &&
244
+ !(0, node_utils_1.isValidAssignmentTarget)(node.operand)) {
245
+ throw (0, node_utils_1.createError)(node.operand, 'Invalid left-hand side expression in unary operation');
246
+ }
247
+ break;
248
+ }
249
+ case SyntaxKind.ImportDeclaration:
250
+ assertModuleSpecifier(node, false);
251
+ break;
252
+ case SyntaxKind.ExportDeclaration:
253
+ assertModuleSpecifier(node, node.exportClause?.kind === SyntaxKind.NamedExports);
254
+ break;
255
+ case SyntaxKind.CallExpression:
256
+ if (node.expression.kind === SyntaxKind.ImportKeyword &&
257
+ node.arguments.length !== 1 &&
258
+ node.arguments.length !== 2) {
259
+ throw (0, node_utils_1.createError)(node.arguments.length > 1 ? node.arguments[2] : node, 'Dynamic import requires exactly one or two arguments.');
260
+ }
261
+ break;
237
262
  case SyntaxKind.ForInStatement:
238
263
  case SyntaxKind.ForOfStatement: {
239
264
  checkForStatementDeclaration(node);
@@ -267,3 +292,12 @@ function checkForStatementDeclaration(node) {
267
292
  throw (0, node_utils_1.createError)(initializer, `The left-hand side of a '${loop}' statement must be a variable or a property access.`);
268
293
  }
269
294
  }
295
+ function assertModuleSpecifier(node, allowNull) {
296
+ if (!allowNull && node.moduleSpecifier == null) {
297
+ throw (0, node_utils_1.createError)(node, 'Module specifier must be a string literal.');
298
+ }
299
+ if (node.moduleSpecifier &&
300
+ node.moduleSpecifier.kind !== SyntaxKind.StringLiteral) {
301
+ throw (0, node_utils_1.createError)(node.moduleSpecifier, 'Module specifier must be a string literal.');
302
+ }
303
+ }
package/dist/convert.d.ts CHANGED
@@ -33,7 +33,6 @@ export declare class Converter {
33
33
  * @returns the converted ESTreeNode
34
34
  */
35
35
  constructor(ast: ts.SourceFile, options?: ConverterOptions);
36
- private assertModuleSpecifier;
37
36
  private convertBindingNameWithTypeAnnotation;
38
37
  /**
39
38
  * Coverts body Nodes and add a directive field to StringLiterals
@@ -78,7 +77,7 @@ export declare class Converter {
78
77
  * @param node parent used to create this node
79
78
  * @returns TypeParameterInstantiation node
80
79
  */
81
- private convertTypeArgumentsToTypeParameterInstantiation;
80
+ private convertTypeArguments;
82
81
  /**
83
82
  * Converts a ts.Node's typeParameters to TSTypeParameterDeclaration node
84
83
  * @param typeParameters ts.Node typeParameters
package/dist/convert.js CHANGED
@@ -146,15 +146,6 @@ class Converter {
146
146
  });
147
147
  return node;
148
148
  }
149
- assertModuleSpecifier(node, allowNull) {
150
- if (!allowNull && node.moduleSpecifier == null) {
151
- this.#throwError(node, 'Module specifier must be a string literal.');
152
- }
153
- if (node.moduleSpecifier &&
154
- node.moduleSpecifier?.kind !== SyntaxKind.StringLiteral) {
155
- this.#throwError(node.moduleSpecifier, 'Module specifier must be a string literal.');
156
- }
157
- }
158
149
  convertBindingNameWithTypeAnnotation(name, tsType, parent) {
159
150
  const id = this.convertPattern(name);
160
151
  if (tsType) {
@@ -277,7 +268,11 @@ class Converter {
277
268
  * @param node parent used to create this node
278
269
  * @returns TypeParameterInstantiation node
279
270
  */
280
- convertTypeArgumentsToTypeParameterInstantiation(typeArguments, node) {
271
+ convertTypeArguments(node) {
272
+ const { typeArguments } = node;
273
+ if (!typeArguments) {
274
+ return undefined;
275
+ }
281
276
  const greaterThanToken = (0, node_utils_1.findNextToken)(typeArguments, this.ast, this.ast);
282
277
  const range = [typeArguments.pos - 1, greaterThanToken.end];
283
278
  if (typeArguments.length === 0) {
@@ -1130,8 +1125,7 @@ class Converter {
1130
1125
  type: ts_estree_1.AST_NODE_TYPES.TaggedTemplateExpression,
1131
1126
  quasi: this.convertChild(node.template),
1132
1127
  tag: this.convertChild(node.tag),
1133
- typeArguments: node.typeArguments &&
1134
- this.convertTypeArgumentsToTypeParameterInstantiation(node.typeArguments, node),
1128
+ typeArguments: this.convertTypeArguments(node),
1135
1129
  });
1136
1130
  }
1137
1131
  case SyntaxKind.TemplateHead:
@@ -1277,8 +1271,7 @@ class Converter {
1277
1271
  this.convertTSTypeParametersToTypeParametersDeclaration(node.typeParameters),
1278
1272
  });
1279
1273
  if (extendsClause?.types[0]?.typeArguments) {
1280
- result.superTypeArguments =
1281
- this.convertTypeArgumentsToTypeParameterInstantiation(extendsClause.types[0].typeArguments, extendsClause.types[0]);
1274
+ result.superTypeArguments = this.convertTypeArguments(extendsClause.types[0]);
1282
1275
  }
1283
1276
  return this.fixExports(node, result);
1284
1277
  }
@@ -1289,7 +1282,6 @@ class Converter {
1289
1282
  body: this.convertBodyExpressions(node.statements, node),
1290
1283
  });
1291
1284
  case SyntaxKind.ImportDeclaration: {
1292
- this.assertModuleSpecifier(node, false);
1293
1285
  const result = this.createNode(node, this.#withDeprecatedAliasGetter({
1294
1286
  type: ts_estree_1.AST_NODE_TYPES.ImportDeclaration,
1295
1287
  attributes: this.convertImportAttributes(node),
@@ -1342,7 +1334,6 @@ class Converter {
1342
1334
  }
1343
1335
  case SyntaxKind.ExportDeclaration: {
1344
1336
  if (node.exportClause?.kind === SyntaxKind.NamedExports) {
1345
- this.assertModuleSpecifier(node, true);
1346
1337
  return this.createNode(node, this.#withDeprecatedAliasGetter({
1347
1338
  type: ts_estree_1.AST_NODE_TYPES.ExportNamedDeclaration,
1348
1339
  attributes: this.convertImportAttributes(node),
@@ -1352,7 +1343,6 @@ class Converter {
1352
1343
  specifiers: this.convertChildren(node.exportClause.elements, node),
1353
1344
  }, 'assertions', 'attributes', true));
1354
1345
  }
1355
- this.assertModuleSpecifier(node, false);
1356
1346
  return this.createNode(node, this.#withDeprecatedAliasGetter({
1357
1347
  type: ts_estree_1.AST_NODE_TYPES.ExportAllDeclaration,
1358
1348
  attributes: this.convertImportAttributes(node),
@@ -1397,9 +1387,6 @@ class Converter {
1397
1387
  * ESTree uses UpdateExpression for ++/--
1398
1388
  */
1399
1389
  if (operator === '++' || operator === '--') {
1400
- if (!(0, node_utils_1.isValidAssignmentTarget)(node.operand)) {
1401
- this.#throwError(node.operand, 'Invalid left-hand side expression in unary operation');
1402
- }
1403
1390
  return this.createNode(node, {
1404
1391
  type: ts_estree_1.AST_NODE_TYPES.UpdateExpression,
1405
1392
  argument: this.convertChild(node.operand),
@@ -1506,9 +1493,6 @@ class Converter {
1506
1493
  }
1507
1494
  case SyntaxKind.CallExpression: {
1508
1495
  if (node.expression.kind === SyntaxKind.ImportKeyword) {
1509
- if (node.arguments.length !== 1 && node.arguments.length !== 2) {
1510
- this.#throwError(node.arguments[2] ?? node, 'Dynamic import requires exactly one or two arguments.');
1511
- }
1512
1496
  return this.createNode(node, this.#withDeprecatedAliasGetter({
1513
1497
  type: ts_estree_1.AST_NODE_TYPES.ImportExpression,
1514
1498
  options: node.arguments[1]
@@ -1519,8 +1503,7 @@ class Converter {
1519
1503
  }
1520
1504
  const callee = this.convertChild(node.expression);
1521
1505
  const args = this.convertChildren(node.arguments);
1522
- const typeArguments = node.typeArguments &&
1523
- this.convertTypeArgumentsToTypeParameterInstantiation(node.typeArguments, node);
1506
+ const typeArguments = this.convertTypeArguments(node);
1524
1507
  const result = this.createNode(node, {
1525
1508
  type: ts_estree_1.AST_NODE_TYPES.CallExpression,
1526
1509
  arguments: args,
@@ -1531,8 +1514,7 @@ class Converter {
1531
1514
  return this.convertChainExpression(result, node);
1532
1515
  }
1533
1516
  case SyntaxKind.NewExpression: {
1534
- const typeArguments = node.typeArguments &&
1535
- this.convertTypeArgumentsToTypeParameterInstantiation(node.typeArguments, node);
1517
+ const typeArguments = this.convertTypeArguments(node);
1536
1518
  // NOTE - NewExpression cannot have an optional chain in it
1537
1519
  return this.createNode(node, {
1538
1520
  type: ts_estree_1.AST_NODE_TYPES.NewExpression,
@@ -1681,9 +1663,7 @@ class Converter {
1681
1663
  attributes: this.convertChildren(node.attributes.properties),
1682
1664
  name: this.convertJSXTagName(node.tagName, node),
1683
1665
  selfClosing: true,
1684
- typeArguments: node.typeArguments
1685
- ? this.convertTypeArgumentsToTypeParameterInstantiation(node.typeArguments, node)
1686
- : undefined,
1666
+ typeArguments: this.convertTypeArguments(node),
1687
1667
  }),
1688
1668
  });
1689
1669
  }
@@ -1693,8 +1673,7 @@ class Converter {
1693
1673
  attributes: this.convertChildren(node.attributes.properties),
1694
1674
  name: this.convertJSXTagName(node.tagName, node),
1695
1675
  selfClosing: false,
1696
- typeArguments: node.typeArguments &&
1697
- this.convertTypeArgumentsToTypeParameterInstantiation(node.typeArguments, node),
1676
+ typeArguments: this.convertTypeArguments(node),
1698
1677
  });
1699
1678
  }
1700
1679
  case SyntaxKind.JsxClosingElement:
@@ -1762,8 +1741,7 @@ class Converter {
1762
1741
  case SyntaxKind.TypeReference:
1763
1742
  return this.createNode(node, {
1764
1743
  type: ts_estree_1.AST_NODE_TYPES.TSTypeReference,
1765
- typeArguments: node.typeArguments &&
1766
- this.convertTypeArgumentsToTypeParameterInstantiation(node.typeArguments, node),
1744
+ typeArguments: this.convertTypeArguments(node),
1767
1745
  typeName: this.convertChild(node.typeName),
1768
1746
  });
1769
1747
  case SyntaxKind.TypeParameter: {
@@ -1836,8 +1814,7 @@ class Converter {
1836
1814
  return this.createNode(node, {
1837
1815
  type: ts_estree_1.AST_NODE_TYPES.TSTypeQuery,
1838
1816
  exprName: this.convertChild(node.exprName),
1839
- typeArguments: node.typeArguments &&
1840
- this.convertTypeArgumentsToTypeParameterInstantiation(node.typeArguments, node),
1817
+ typeArguments: this.convertTypeArguments(node),
1841
1818
  });
1842
1819
  case SyntaxKind.MappedType: {
1843
1820
  return this.createNode(node, this.#withDeprecatedGetter({
@@ -1930,8 +1907,7 @@ class Converter {
1930
1907
  return this.createNode(node, {
1931
1908
  type,
1932
1909
  expression: this.convertChild(node.expression),
1933
- typeArguments: node.typeArguments &&
1934
- this.convertTypeArgumentsToTypeParameterInstantiation(node.typeArguments, node),
1910
+ typeArguments: this.convertTypeArguments(node),
1935
1911
  });
1936
1912
  }
1937
1913
  case SyntaxKind.InterfaceDeclaration: {
@@ -2055,9 +2031,7 @@ class Converter {
2055
2031
  options,
2056
2032
  qualifier: this.convertChild(node.qualifier),
2057
2033
  source,
2058
- typeArguments: node.typeArguments
2059
- ? this.convertTypeArgumentsToTypeParameterInstantiation(node.typeArguments, node)
2060
- : null,
2034
+ typeArguments: this.convertTypeArguments(node) ?? null,
2061
2035
  }, 'argument', 'source', argument));
2062
2036
  if (node.isTypeOf) {
2063
2037
  return this.createNode(node, {
@@ -2372,7 +2346,7 @@ class Converter {
2372
2346
  if ('typeArguments' in node) {
2373
2347
  result.typeArguments =
2374
2348
  node.typeArguments && 'pos' in node.typeArguments
2375
- ? this.convertTypeArgumentsToTypeParameterInstantiation(node.typeArguments, node)
2349
+ ? this.convertTypeArguments(node)
2376
2350
  : null;
2377
2351
  }
2378
2352
  if ('typeParameters' in node) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typescript-eslint/typescript-estree",
3
- "version": "8.51.1-alpha.8",
3
+ "version": "8.52.0",
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.51.1-alpha.8",
56
- "@typescript-eslint/tsconfig-utils": "8.51.1-alpha.8",
57
- "@typescript-eslint/types": "8.51.1-alpha.8",
58
- "@typescript-eslint/visitor-keys": "8.51.1-alpha.8",
55
+ "@typescript-eslint/project-service": "8.52.0",
56
+ "@typescript-eslint/tsconfig-utils": "8.52.0",
57
+ "@typescript-eslint/types": "8.52.0",
58
+ "@typescript-eslint/visitor-keys": "8.52.0",
59
59
  "debug": "^4.4.3",
60
60
  "minimatch": "^9.0.5",
61
61
  "semver": "^7.7.3",