@typescript-eslint/typescript-estree 8.52.1-alpha.1 → 8.52.1-alpha.10
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/dist/check-syntax-errors.js +54 -22
- package/dist/convert.js +2 -19
- package/package.json +5 -5
|
@@ -90,19 +90,12 @@ function checkSyntaxError(tsNode, parent, allowPattern) {
|
|
|
90
90
|
if (node.parent.kind === SyntaxKind.VariableDeclarationList) {
|
|
91
91
|
const variableDeclarationList = node.parent;
|
|
92
92
|
const kind = (0, node_utils_1.getDeclarationKind)(variableDeclarationList);
|
|
93
|
-
if (
|
|
94
|
-
variableDeclarationList.parent.kind === SyntaxKind.
|
|
95
|
-
|
|
96
|
-
if (!node.initializer) {
|
|
97
|
-
throw (0, node_utils_1.createError)(node, `'${kind}' declarations may not be initialized in for statement.`);
|
|
93
|
+
if (kind === 'using' || kind === 'await using') {
|
|
94
|
+
if (variableDeclarationList.parent.kind === SyntaxKind.ForInStatement) {
|
|
95
|
+
throw (0, node_utils_1.createError)(variableDeclarationList, `The left-hand side of a 'for...in' statement cannot be a '${kind}' declaration.`);
|
|
98
96
|
}
|
|
99
|
-
if (
|
|
100
|
-
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
if (variableDeclarationList.parent.kind === SyntaxKind.VariableStatement) {
|
|
104
|
-
const variableStatement = variableDeclarationList.parent;
|
|
105
|
-
if (kind === 'using' || kind === 'await using') {
|
|
97
|
+
if (variableDeclarationList.parent.kind === SyntaxKind.ForStatement ||
|
|
98
|
+
variableDeclarationList.parent.kind === SyntaxKind.VariableStatement) {
|
|
106
99
|
if (!node.initializer) {
|
|
107
100
|
throw (0, node_utils_1.createError)(node, `'${kind}' declarations must be initialized.`);
|
|
108
101
|
}
|
|
@@ -110,6 +103,9 @@ function checkSyntaxError(tsNode, parent, allowPattern) {
|
|
|
110
103
|
throw (0, node_utils_1.createError)(node.name, `'${kind}' declarations may not have binding patterns.`);
|
|
111
104
|
}
|
|
112
105
|
}
|
|
106
|
+
}
|
|
107
|
+
if (variableDeclarationList.parent.kind === SyntaxKind.VariableStatement) {
|
|
108
|
+
const variableStatement = variableDeclarationList.parent;
|
|
113
109
|
const hasDeclareKeyword = (0, node_utils_1.hasModifier)(SyntaxKind.DeclareKeyword, variableStatement);
|
|
114
110
|
// Definite assignment only allowed for non-declare let and var
|
|
115
111
|
if ((hasDeclareKeyword ||
|
|
@@ -305,6 +301,12 @@ function checkSyntaxError(tsNode, parent, allowPattern) {
|
|
|
305
301
|
if (seenImplementsClause) {
|
|
306
302
|
throw (0, node_utils_1.createError)(heritageClause, "'implements' clause already seen.");
|
|
307
303
|
}
|
|
304
|
+
for (const heritageType of heritageClause.types) {
|
|
305
|
+
if (!(0, node_utils_1.isEntityNameExpression)(heritageType.expression) ||
|
|
306
|
+
ts.isOptionalChain(heritageType.expression)) {
|
|
307
|
+
throw (0, node_utils_1.createError)(heritageType, 'A class can only implement an identifier/qualified-name with optional type arguments.');
|
|
308
|
+
}
|
|
309
|
+
}
|
|
308
310
|
seenImplementsClause = true;
|
|
309
311
|
}
|
|
310
312
|
}
|
|
@@ -314,12 +316,16 @@ function checkSyntaxError(tsNode, parent, allowPattern) {
|
|
|
314
316
|
const interfaceHeritageClauses = node.heritageClauses ?? [];
|
|
315
317
|
let seenExtendsClause = false;
|
|
316
318
|
for (const heritageClause of interfaceHeritageClauses) {
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
319
|
+
const { token, types } = heritageClause;
|
|
320
|
+
if (token === SyntaxKind.ImplementsKeyword) {
|
|
321
|
+
throw (0, node_utils_1.createError)(heritageClause, "Interface declaration cannot have 'implements' clause.");
|
|
322
|
+
}
|
|
323
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
324
|
+
if (token !== SyntaxKind.ExtendsKeyword) {
|
|
325
|
+
throw (0, node_utils_1.createError)(heritageClause, 'Unexpected token.');
|
|
326
|
+
}
|
|
327
|
+
if (types.length === 0) {
|
|
328
|
+
throw (0, node_utils_1.createError)(heritageClause, `'${ts.tokenToString(token)}' list cannot be empty.`);
|
|
323
329
|
}
|
|
324
330
|
if (seenExtendsClause) {
|
|
325
331
|
throw (0, node_utils_1.createError)(heritageClause, "'extends' clause already seen.");
|
|
@@ -364,6 +370,36 @@ function checkSyntaxError(tsNode, parent, allowPattern) {
|
|
|
364
370
|
}
|
|
365
371
|
break;
|
|
366
372
|
}
|
|
373
|
+
case SyntaxKind.ImportEqualsDeclaration:
|
|
374
|
+
if (node.isTypeOnly &&
|
|
375
|
+
node.moduleReference.kind !== SyntaxKind.ExternalModuleReference) {
|
|
376
|
+
throw (0, node_utils_1.createError)(node, "An import alias cannot use 'import type'");
|
|
377
|
+
}
|
|
378
|
+
break;
|
|
379
|
+
case SyntaxKind.ModuleDeclaration: {
|
|
380
|
+
if (node.flags & ts.NodeFlags.GlobalAugmentation) {
|
|
381
|
+
const { body } = node;
|
|
382
|
+
if (body == null || body.kind === SyntaxKind.ModuleDeclaration) {
|
|
383
|
+
throw (0, node_utils_1.createError)(node.body ?? node, 'Expected a valid module body');
|
|
384
|
+
}
|
|
385
|
+
const { name } = node;
|
|
386
|
+
if (name.kind !== ts.SyntaxKind.Identifier) {
|
|
387
|
+
throw (0, node_utils_1.createError)(name, 'global module augmentation must have an Identifier id');
|
|
388
|
+
}
|
|
389
|
+
return;
|
|
390
|
+
}
|
|
391
|
+
if (ts.isStringLiteral(node.name)) {
|
|
392
|
+
return;
|
|
393
|
+
}
|
|
394
|
+
if (node.body == null) {
|
|
395
|
+
throw (0, node_utils_1.createError)(node, 'Expected a module body');
|
|
396
|
+
}
|
|
397
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- Fixme: confirm if it's possible
|
|
398
|
+
if (node.name.kind !== ts.SyntaxKind.Identifier) {
|
|
399
|
+
throw (0, node_utils_1.createError)(node.name, '`namespace`s must have an Identifier id');
|
|
400
|
+
}
|
|
401
|
+
break;
|
|
402
|
+
}
|
|
367
403
|
case SyntaxKind.ForInStatement:
|
|
368
404
|
case SyntaxKind.ForOfStatement: {
|
|
369
405
|
checkForStatementDeclaration(node);
|
|
@@ -386,10 +422,6 @@ function checkForStatementDeclaration(node) {
|
|
|
386
422
|
else if (declaration.type) {
|
|
387
423
|
throw (0, node_utils_1.createError)(declaration, `The variable declaration of a '${loop}' statement cannot have a type annotation.`);
|
|
388
424
|
}
|
|
389
|
-
if (kind === SyntaxKind.ForInStatement &&
|
|
390
|
-
initializer.flags & ts.NodeFlags.Using) {
|
|
391
|
-
throw (0, node_utils_1.createError)(initializer, "The left-hand side of a 'for...in' statement cannot be a 'using' declaration.");
|
|
392
|
-
}
|
|
393
425
|
}
|
|
394
426
|
else if (!(0, node_utils_1.isValidAssignmentTarget)(initializer) &&
|
|
395
427
|
initializer.kind !== SyntaxKind.ObjectLiteralExpression &&
|
package/dist/convert.js
CHANGED
|
@@ -1996,23 +1996,12 @@ class Converter {
|
|
|
1996
1996
|
const result = this.createNode(node, {
|
|
1997
1997
|
type: ts_estree_1.AST_NODE_TYPES.TSModuleDeclaration,
|
|
1998
1998
|
...(() => {
|
|
1999
|
-
// the constraints checked by this function are syntactically enforced by TS
|
|
2000
|
-
// the checks mostly exist for type's sake
|
|
2001
1999
|
if (node.flags & ts.NodeFlags.GlobalAugmentation) {
|
|
2002
|
-
const id = this.convertChild(node.name);
|
|
2003
|
-
const body = this.convertChild(node.body);
|
|
2004
|
-
if (body == null ||
|
|
2005
|
-
body.type === ts_estree_1.AST_NODE_TYPES.TSModuleDeclaration) {
|
|
2006
|
-
this.#throwError(node.body ?? node, 'Expected a valid module body');
|
|
2007
|
-
}
|
|
2008
|
-
if (id.type !== ts_estree_1.AST_NODE_TYPES.Identifier) {
|
|
2009
|
-
this.#throwError(node.name, 'global module augmentation must have an Identifier id');
|
|
2010
|
-
}
|
|
2011
2000
|
return {
|
|
2012
|
-
body: body,
|
|
2001
|
+
body: this.convertChild(node.body),
|
|
2013
2002
|
declare: false,
|
|
2014
2003
|
global: false,
|
|
2015
|
-
id,
|
|
2004
|
+
id: this.convertChild(node.name),
|
|
2016
2005
|
kind: 'global',
|
|
2017
2006
|
};
|
|
2018
2007
|
}
|
|
@@ -2029,12 +2018,6 @@ class Converter {
|
|
|
2029
2018
|
// Nested module declarations are stored in TypeScript as nested tree nodes.
|
|
2030
2019
|
// We "unravel" them here by making our own nested TSQualifiedName,
|
|
2031
2020
|
// with the innermost node's body as the actual node body.
|
|
2032
|
-
if (node.body == null) {
|
|
2033
|
-
this.#throwError(node, 'Expected a module body');
|
|
2034
|
-
}
|
|
2035
|
-
if (node.name.kind !== ts.SyntaxKind.Identifier) {
|
|
2036
|
-
this.#throwError(node.name, '`namespace`s must have an Identifier id');
|
|
2037
|
-
}
|
|
2038
2021
|
let name = this.createNode(node.name, {
|
|
2039
2022
|
type: ts_estree_1.AST_NODE_TYPES.Identifier,
|
|
2040
2023
|
range: [node.name.getStart(this.ast), node.name.getEnd()],
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@typescript-eslint/typescript-estree",
|
|
3
|
-
"version": "8.52.1-alpha.
|
|
3
|
+
"version": "8.52.1-alpha.10",
|
|
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.52.1-alpha.
|
|
56
|
-
"@typescript-eslint/tsconfig-utils": "8.52.1-alpha.
|
|
57
|
-
"@typescript-eslint/types": "8.52.1-alpha.
|
|
58
|
-
"@typescript-eslint/visitor-keys": "8.52.1-alpha.
|
|
55
|
+
"@typescript-eslint/project-service": "8.52.1-alpha.10",
|
|
56
|
+
"@typescript-eslint/tsconfig-utils": "8.52.1-alpha.10",
|
|
57
|
+
"@typescript-eslint/types": "8.52.1-alpha.10",
|
|
58
|
+
"@typescript-eslint/visitor-keys": "8.52.1-alpha.10",
|
|
59
59
|
"debug": "^4.4.3",
|
|
60
60
|
"minimatch": "^9.0.5",
|
|
61
61
|
"semver": "^7.7.3",
|