@typescript-eslint/typescript-estree 8.51.1-alpha.1 → 8.51.1-alpha.2
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.d.ts +2 -0
- package/dist/check-syntax-errors.js +79 -0
- package/dist/convert.js +4 -30
- package/package.json +5 -5
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.checkSyntaxError = checkSyntaxError;
|
|
37
|
+
const ts = __importStar(require("typescript"));
|
|
38
|
+
const check_modifiers_1 = require("./check-modifiers");
|
|
39
|
+
const node_utils_1 = require("./node-utils");
|
|
40
|
+
const SyntaxKind = ts.SyntaxKind;
|
|
41
|
+
function checkSyntaxError(tsNode) {
|
|
42
|
+
(0, check_modifiers_1.checkModifiers)(tsNode);
|
|
43
|
+
const node = tsNode;
|
|
44
|
+
switch (node.kind) {
|
|
45
|
+
case SyntaxKind.ForInStatement:
|
|
46
|
+
case SyntaxKind.ForOfStatement: {
|
|
47
|
+
checkForStatementDeclaration(node);
|
|
48
|
+
break;
|
|
49
|
+
}
|
|
50
|
+
default: {
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
function checkForStatementDeclaration(node) {
|
|
56
|
+
const { initializer, kind } = node;
|
|
57
|
+
const loop = kind === SyntaxKind.ForInStatement ? 'for...in' : 'for...of';
|
|
58
|
+
if (ts.isVariableDeclarationList(initializer)) {
|
|
59
|
+
if (initializer.declarations.length !== 1) {
|
|
60
|
+
throw (0, node_utils_1.createError)(initializer, `Only a single variable declaration is allowed in a '${loop}' statement.`);
|
|
61
|
+
}
|
|
62
|
+
const declaration = initializer.declarations[0];
|
|
63
|
+
if (declaration.initializer) {
|
|
64
|
+
throw (0, node_utils_1.createError)(declaration, `The variable declaration of a '${loop}' statement cannot have an initializer.`);
|
|
65
|
+
}
|
|
66
|
+
else if (declaration.type) {
|
|
67
|
+
throw (0, node_utils_1.createError)(declaration, `The variable declaration of a '${loop}' statement cannot have a type annotation.`);
|
|
68
|
+
}
|
|
69
|
+
if (kind === SyntaxKind.ForInStatement &&
|
|
70
|
+
initializer.flags & ts.NodeFlags.Using) {
|
|
71
|
+
throw (0, node_utils_1.createError)(initializer, "The left-hand side of a 'for...in' statement cannot be a 'using' declaration.");
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
else if (!(0, node_utils_1.isValidAssignmentTarget)(initializer) &&
|
|
75
|
+
initializer.kind !== SyntaxKind.ObjectLiteralExpression &&
|
|
76
|
+
initializer.kind !== SyntaxKind.ArrayLiteralExpression) {
|
|
77
|
+
throw (0, node_utils_1.createError)(initializer, `The left-hand side of a '${loop}' statement must be a variable or a property access.`);
|
|
78
|
+
}
|
|
79
|
+
}
|
package/dist/convert.js
CHANGED
|
@@ -38,7 +38,7 @@ exports.convertError = convertError;
|
|
|
38
38
|
// There's lots of funny stuff due to the typing of ts.Node
|
|
39
39
|
/* eslint-disable @typescript-eslint/no-non-null-assertion, @typescript-eslint/no-unnecessary-condition, @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-member-access */
|
|
40
40
|
const ts = __importStar(require("typescript"));
|
|
41
|
-
const
|
|
41
|
+
const check_syntax_errors_1 = require("./check-syntax-errors");
|
|
42
42
|
const getModifiers_1 = require("./getModifiers");
|
|
43
43
|
const node_utils_1 = require("./node-utils");
|
|
44
44
|
const ts_estree_1 = require("./ts-estree");
|
|
@@ -76,35 +76,11 @@ class Converter {
|
|
|
76
76
|
this.ast = ast;
|
|
77
77
|
this.options = { ...options };
|
|
78
78
|
}
|
|
79
|
-
#
|
|
80
|
-
const loop = kind === ts.SyntaxKind.ForInStatement ? 'for...in' : 'for...of';
|
|
81
|
-
if (ts.isVariableDeclarationList(initializer)) {
|
|
82
|
-
if (initializer.declarations.length !== 1) {
|
|
83
|
-
this.#throwError(initializer, `Only a single variable declaration is allowed in a '${loop}' statement.`);
|
|
84
|
-
}
|
|
85
|
-
const declaration = initializer.declarations[0];
|
|
86
|
-
if (declaration.initializer) {
|
|
87
|
-
this.#throwError(declaration, `The variable declaration of a '${loop}' statement cannot have an initializer.`);
|
|
88
|
-
}
|
|
89
|
-
else if (declaration.type) {
|
|
90
|
-
this.#throwError(declaration, `The variable declaration of a '${loop}' statement cannot have a type annotation.`);
|
|
91
|
-
}
|
|
92
|
-
if (kind === ts.SyntaxKind.ForInStatement &&
|
|
93
|
-
initializer.flags & ts.NodeFlags.Using) {
|
|
94
|
-
this.#throwError(initializer, "The left-hand side of a 'for...in' statement cannot be a 'using' declaration.");
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
else if (!(0, node_utils_1.isValidAssignmentTarget)(initializer) &&
|
|
98
|
-
initializer.kind !== ts.SyntaxKind.ObjectLiteralExpression &&
|
|
99
|
-
initializer.kind !== ts.SyntaxKind.ArrayLiteralExpression) {
|
|
100
|
-
this.#throwError(initializer, `The left-hand side of a '${loop}' statement must be a variable or a property access.`);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
#checkModifiers(node) {
|
|
79
|
+
#checkSyntaxError(node) {
|
|
104
80
|
if (this.options.allowInvalidAST) {
|
|
105
81
|
return;
|
|
106
82
|
}
|
|
107
|
-
(0,
|
|
83
|
+
(0, check_syntax_errors_1.checkSyntaxError)(node);
|
|
108
84
|
}
|
|
109
85
|
#throwError(node, message) {
|
|
110
86
|
if (this.options.allowInvalidAST) {
|
|
@@ -364,7 +340,7 @@ class Converter {
|
|
|
364
340
|
if (!node) {
|
|
365
341
|
return null;
|
|
366
342
|
}
|
|
367
|
-
this.#
|
|
343
|
+
this.#checkSyntaxError(node);
|
|
368
344
|
const pattern = this.allowPattern;
|
|
369
345
|
if (allowPattern != null) {
|
|
370
346
|
this.allowPattern = allowPattern;
|
|
@@ -653,7 +629,6 @@ class Converter {
|
|
|
653
629
|
update: this.convertChild(node.incrementor),
|
|
654
630
|
});
|
|
655
631
|
case SyntaxKind.ForInStatement:
|
|
656
|
-
this.#checkForStatementDeclaration(node.initializer, node.kind);
|
|
657
632
|
return this.createNode(node, {
|
|
658
633
|
type: ts_estree_1.AST_NODE_TYPES.ForInStatement,
|
|
659
634
|
body: this.convertChild(node.statement),
|
|
@@ -661,7 +636,6 @@ class Converter {
|
|
|
661
636
|
right: this.convertChild(node.expression),
|
|
662
637
|
});
|
|
663
638
|
case SyntaxKind.ForOfStatement: {
|
|
664
|
-
this.#checkForStatementDeclaration(node.initializer, node.kind);
|
|
665
639
|
return this.createNode(node, {
|
|
666
640
|
type: ts_estree_1.AST_NODE_TYPES.ForOfStatement,
|
|
667
641
|
await: node.awaitModifier?.kind === SyntaxKind.AwaitKeyword,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@typescript-eslint/typescript-estree",
|
|
3
|
-
"version": "8.51.1-alpha.
|
|
3
|
+
"version": "8.51.1-alpha.2",
|
|
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.
|
|
56
|
-
"@typescript-eslint/tsconfig-utils": "8.51.1-alpha.
|
|
57
|
-
"@typescript-eslint/types": "8.51.1-alpha.
|
|
58
|
-
"@typescript-eslint/visitor-keys": "8.51.1-alpha.
|
|
55
|
+
"@typescript-eslint/project-service": "8.51.1-alpha.2",
|
|
56
|
+
"@typescript-eslint/tsconfig-utils": "8.51.1-alpha.2",
|
|
57
|
+
"@typescript-eslint/types": "8.51.1-alpha.2",
|
|
58
|
+
"@typescript-eslint/visitor-keys": "8.51.1-alpha.2",
|
|
59
59
|
"debug": "^4.3.4",
|
|
60
60
|
"minimatch": "^9.0.4",
|
|
61
61
|
"semver": "^7.6.0",
|