@typescript-eslint/typescript-estree 8.0.0-alpha.9 → 8.0.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.
- package/dist/ast-converter.js +1 -2
- package/dist/ast-converter.js.map +1 -1
- package/dist/clear-caches.js +2 -2
- package/dist/clear-caches.js.map +1 -1
- package/dist/convert-comments.js +1 -2
- package/dist/convert-comments.js.map +1 -1
- package/dist/convert.d.ts.map +1 -1
- package/dist/convert.js +289 -263
- package/dist/convert.js.map +1 -1
- package/dist/create-program/createIsolatedProgram.js +1 -2
- package/dist/create-program/createIsolatedProgram.js.map +1 -1
- package/dist/create-program/createProjectProgram.js +4 -5
- package/dist/create-program/createProjectProgram.js.map +1 -1
- package/dist/create-program/createProjectService.d.ts +1 -1
- package/dist/create-program/createProjectService.d.ts.map +1 -1
- package/dist/create-program/createProjectService.js +67 -26
- package/dist/create-program/createProjectService.js.map +1 -1
- package/dist/create-program/createSourceFile.js +2 -3
- package/dist/create-program/createSourceFile.js.map +1 -1
- package/dist/create-program/describeFilePath.js +1 -2
- package/dist/create-program/describeFilePath.js.map +1 -1
- package/dist/create-program/getParsedConfigFile.d.ts +10 -0
- package/dist/create-program/getParsedConfigFile.d.ts.map +1 -0
- package/dist/create-program/getParsedConfigFile.js +67 -0
- package/dist/create-program/getParsedConfigFile.js.map +1 -0
- package/dist/create-program/getScriptKind.js +2 -3
- package/dist/create-program/getScriptKind.js.map +1 -1
- package/dist/create-program/getWatchProgramsForProjects.d.ts.map +1 -1
- package/dist/create-program/getWatchProgramsForProjects.js +7 -15
- package/dist/create-program/getWatchProgramsForProjects.js.map +1 -1
- package/dist/create-program/shared.js +7 -7
- package/dist/create-program/shared.js.map +1 -1
- package/dist/create-program/useProvidedPrograms.d.ts +2 -5
- package/dist/create-program/useProvidedPrograms.d.ts.map +1 -1
- package/dist/create-program/useProvidedPrograms.js +21 -45
- package/dist/create-program/useProvidedPrograms.js.map +1 -1
- package/dist/create-program/validateDefaultProjectForFilesGlob.d.ts +1 -1
- package/dist/create-program/validateDefaultProjectForFilesGlob.d.ts.map +1 -1
- package/dist/create-program/validateDefaultProjectForFilesGlob.js +7 -7
- package/dist/create-program/validateDefaultProjectForFilesGlob.js.map +1 -1
- package/dist/createParserServices.js +1 -2
- package/dist/createParserServices.js.map +1 -1
- package/dist/getModifiers.js +2 -3
- package/dist/getModifiers.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/node-utils.d.ts.map +1 -1
- package/dist/node-utils.js +47 -45
- package/dist/node-utils.js.map +1 -1
- package/dist/parseSettings/ExpiringCache.js +10 -23
- package/dist/parseSettings/ExpiringCache.js.map +1 -1
- package/dist/parseSettings/createParseSettings.d.ts.map +1 -1
- package/dist/parseSettings/createParseSettings.js +11 -13
- package/dist/parseSettings/createParseSettings.js.map +1 -1
- package/dist/parseSettings/getProjectConfigFiles.js +1 -2
- package/dist/parseSettings/getProjectConfigFiles.js.map +1 -1
- package/dist/parseSettings/index.d.ts +4 -12
- package/dist/parseSettings/index.d.ts.map +1 -1
- package/dist/parseSettings/inferSingleRun.d.ts.map +1 -1
- package/dist/parseSettings/inferSingleRun.js +8 -3
- package/dist/parseSettings/inferSingleRun.js.map +1 -1
- package/dist/parseSettings/resolveProjectList.js +3 -4
- package/dist/parseSettings/resolveProjectList.js.map +1 -1
- package/dist/parseSettings/warnAboutTSVersion.js +2 -3
- package/dist/parseSettings/warnAboutTSVersion.js.map +1 -1
- package/dist/parser-options.d.ts +10 -42
- package/dist/parser-options.d.ts.map +1 -1
- package/dist/parser.d.ts.map +1 -1
- package/dist/parser.js +10 -12
- package/dist/parser.js.map +1 -1
- package/dist/semantic-or-syntactic-errors.js +1 -2
- package/dist/semantic-or-syntactic-errors.js.map +1 -1
- package/dist/simple-traverse.js +4 -3
- package/dist/simple-traverse.js.map +1 -1
- package/dist/source-files.js +2 -3
- package/dist/source-files.js.map +1 -1
- package/dist/ts-estree/ts-nodes.d.ts +1 -1
- package/dist/ts-estree/ts-nodes.d.ts.map +1 -1
- package/dist/useProgramFromProjectService.d.ts +4 -2
- package/dist/useProgramFromProjectService.d.ts.map +1 -1
- package/dist/useProgramFromProjectService.js +118 -39
- package/dist/useProgramFromProjectService.js.map +1 -1
- package/dist/version-check.d.ts +3 -1
- package/dist/version-check.d.ts.map +1 -1
- package/dist/withoutProjectParserOptions.d.ts +11 -0
- package/dist/withoutProjectParserOptions.d.ts.map +1 -0
- package/dist/withoutProjectParserOptions.js +17 -0
- package/dist/withoutProjectParserOptions.js.map +1 -0
- package/package.json +5 -8
package/dist/convert.js
CHANGED
|
@@ -22,14 +22,9 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
22
22
|
__setModuleDefault(result, mod);
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
26
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
27
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
28
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
29
|
-
};
|
|
30
|
-
var _Converter_instances, _Converter_checkModifiers, _Converter_throwUnlessAllowInvalidAST, _Converter_withDeprecatedAliasGetter, _Converter_withDeprecatedGetter, _Converter_throwError, _Converter_checkForStatementDeclaration;
|
|
31
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
32
|
-
exports.Converter =
|
|
26
|
+
exports.Converter = void 0;
|
|
27
|
+
exports.convertError = convertError;
|
|
33
28
|
// There's lots of funny stuff due to the typing of ts.Node
|
|
34
29
|
/* 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 */
|
|
35
30
|
const ts = __importStar(require("typescript"));
|
|
@@ -45,8 +40,12 @@ const SyntaxKind = ts.SyntaxKind;
|
|
|
45
40
|
function convertError(error) {
|
|
46
41
|
return (0, node_utils_1.createError)(('message' in error && error.message) || error.messageText, error.file, error.start);
|
|
47
42
|
}
|
|
48
|
-
exports.convertError = convertError;
|
|
49
43
|
class Converter {
|
|
44
|
+
ast;
|
|
45
|
+
options;
|
|
46
|
+
esTreeNodeToTSNodeMap = new WeakMap();
|
|
47
|
+
tsNodeToESTreeNodeMap = new WeakMap();
|
|
48
|
+
allowPattern = false;
|
|
50
49
|
/**
|
|
51
50
|
* Converts a TypeScript node into an ESTree node
|
|
52
51
|
* @param ast the full TypeScript AST
|
|
@@ -54,10 +53,6 @@ class Converter {
|
|
|
54
53
|
* @returns the converted ESTreeNode
|
|
55
54
|
*/
|
|
56
55
|
constructor(ast, options) {
|
|
57
|
-
_Converter_instances.add(this);
|
|
58
|
-
this.esTreeNodeToTSNodeMap = new WeakMap();
|
|
59
|
-
this.tsNodeToESTreeNodeMap = new WeakMap();
|
|
60
|
-
this.allowPattern = false;
|
|
61
56
|
this.ast = ast;
|
|
62
57
|
this.options = { ...options };
|
|
63
58
|
}
|
|
@@ -84,7 +79,7 @@ class Converter {
|
|
|
84
79
|
if (!node) {
|
|
85
80
|
return null;
|
|
86
81
|
}
|
|
87
|
-
|
|
82
|
+
this.#checkModifiers(node);
|
|
88
83
|
const pattern = this.allowPattern;
|
|
89
84
|
if (allowPattern !== undefined) {
|
|
90
85
|
this.allowPattern = allowPattern;
|
|
@@ -130,7 +125,7 @@ class Converter {
|
|
|
130
125
|
const isDeclare = 'declare' in result && result.declare;
|
|
131
126
|
return this.createNode(node,
|
|
132
127
|
// @ts-expect-error - TODO, narrow the types here
|
|
133
|
-
|
|
128
|
+
this.#withDeprecatedAliasGetter({
|
|
134
129
|
type: ts_estree_1.AST_NODE_TYPES.ExportNamedDeclaration,
|
|
135
130
|
declaration: result,
|
|
136
131
|
specifiers: [],
|
|
@@ -325,7 +320,7 @@ class Converter {
|
|
|
325
320
|
*/
|
|
326
321
|
deeplyCopy(node) {
|
|
327
322
|
if (node.kind === ts.SyntaxKind.JSDocFunctionType) {
|
|
328
|
-
|
|
323
|
+
this.#throwError(node, 'JSDoc types can only be used inside documentation comments.');
|
|
329
324
|
}
|
|
330
325
|
const customType = `TS${SyntaxKind[node.kind]}`;
|
|
331
326
|
/**
|
|
@@ -349,7 +344,6 @@ class Converter {
|
|
|
349
344
|
node.typeArguments && 'pos' in node.typeArguments
|
|
350
345
|
? this.convertTypeArgumentsToTypeParameterInstantiation(node.typeArguments, node)
|
|
351
346
|
: null;
|
|
352
|
-
__classPrivateFieldGet(this, _Converter_instances, "m", _Converter_withDeprecatedAliasGetter).call(this, result, 'typeParameters', 'typeArguments');
|
|
353
347
|
}
|
|
354
348
|
if ('typeParameters' in node) {
|
|
355
349
|
result.typeParameters =
|
|
@@ -465,7 +459,7 @@ class Converter {
|
|
|
465
459
|
if (node.name.kind === SyntaxKind.PrivateIdentifier) {
|
|
466
460
|
// This is one of the few times where TS explicitly errors, and doesn't even gracefully handle the syntax.
|
|
467
461
|
// So we shouldn't ever get into this state to begin with.
|
|
468
|
-
|
|
462
|
+
this.#throwError(node.name, 'Non-private identifier expected.');
|
|
469
463
|
}
|
|
470
464
|
result = this.createNode(node, {
|
|
471
465
|
type: ts_estree_1.AST_NODE_TYPES.JSXMemberExpression,
|
|
@@ -528,11 +522,11 @@ class Converter {
|
|
|
528
522
|
}
|
|
529
523
|
assertModuleSpecifier(node, allowNull) {
|
|
530
524
|
if (!allowNull && node.moduleSpecifier == null) {
|
|
531
|
-
|
|
525
|
+
this.#throwUnlessAllowInvalidAST(node, 'Module specifier must be a string literal.');
|
|
532
526
|
}
|
|
533
527
|
if (node.moduleSpecifier &&
|
|
534
528
|
node.moduleSpecifier?.kind !== SyntaxKind.StringLiteral) {
|
|
535
|
-
|
|
529
|
+
this.#throwUnlessAllowInvalidAST(node.moduleSpecifier, 'Module specifier must be a string literal.');
|
|
536
530
|
}
|
|
537
531
|
}
|
|
538
532
|
/**
|
|
@@ -620,7 +614,7 @@ class Converter {
|
|
|
620
614
|
});
|
|
621
615
|
case SyntaxKind.SwitchStatement:
|
|
622
616
|
if (node.caseBlock.clauses.filter(switchCase => switchCase.kind === SyntaxKind.DefaultClause).length > 1) {
|
|
623
|
-
|
|
617
|
+
this.#throwError(node, "A 'default' clause cannot appear more than once in a 'switch' statement.");
|
|
624
618
|
}
|
|
625
619
|
return this.createNode(node, {
|
|
626
620
|
type: ts_estree_1.AST_NODE_TYPES.SwitchStatement,
|
|
@@ -640,7 +634,7 @@ class Converter {
|
|
|
640
634
|
// Exceptions
|
|
641
635
|
case SyntaxKind.ThrowStatement:
|
|
642
636
|
if (node.expression.end === node.expression.pos) {
|
|
643
|
-
|
|
637
|
+
this.#throwUnlessAllowInvalidAST(node, 'A throw statement must throw an expression.');
|
|
644
638
|
}
|
|
645
639
|
return this.createNode(node, {
|
|
646
640
|
type: ts_estree_1.AST_NODE_TYPES.ThrowStatement,
|
|
@@ -655,7 +649,7 @@ class Converter {
|
|
|
655
649
|
});
|
|
656
650
|
case SyntaxKind.CatchClause:
|
|
657
651
|
if (node.variableDeclaration?.initializer) {
|
|
658
|
-
|
|
652
|
+
this.#throwError(node.variableDeclaration.initializer, 'Catch clause variable cannot have an initializer.');
|
|
659
653
|
}
|
|
660
654
|
return this.createNode(node, {
|
|
661
655
|
type: ts_estree_1.AST_NODE_TYPES.CatchClause,
|
|
@@ -690,7 +684,7 @@ class Converter {
|
|
|
690
684
|
body: this.convertChild(node.statement),
|
|
691
685
|
});
|
|
692
686
|
case SyntaxKind.ForInStatement:
|
|
693
|
-
|
|
687
|
+
this.#checkForStatementDeclaration(node.initializer);
|
|
694
688
|
return this.createNode(node, {
|
|
695
689
|
type: ts_estree_1.AST_NODE_TYPES.ForInStatement,
|
|
696
690
|
left: this.convertPattern(node.initializer),
|
|
@@ -709,15 +703,32 @@ class Converter {
|
|
|
709
703
|
// Declarations
|
|
710
704
|
case SyntaxKind.FunctionDeclaration: {
|
|
711
705
|
const isDeclare = (0, node_utils_1.hasModifier)(SyntaxKind.DeclareKeyword, node);
|
|
706
|
+
const isAsync = (0, node_utils_1.hasModifier)(SyntaxKind.AsyncKeyword, node);
|
|
707
|
+
const isGenerator = !!node.asteriskToken;
|
|
708
|
+
if (isDeclare) {
|
|
709
|
+
if (node.body) {
|
|
710
|
+
this.#throwError(node, 'An implementation cannot be declared in ambient contexts.');
|
|
711
|
+
}
|
|
712
|
+
else if (isAsync) {
|
|
713
|
+
this.#throwError(node, "'async' modifier cannot be used in an ambient context.");
|
|
714
|
+
}
|
|
715
|
+
else if (isGenerator) {
|
|
716
|
+
this.#throwError(node, 'Generators are not allowed in an ambient context.');
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
else if (!node.body && isGenerator) {
|
|
720
|
+
this.#throwError(node, 'A function signature cannot be declared as a generator.');
|
|
721
|
+
}
|
|
712
722
|
const result = this.createNode(node, {
|
|
713
|
-
|
|
723
|
+
// declare implies no body due to the invariant above
|
|
724
|
+
type: !node.body
|
|
714
725
|
? ts_estree_1.AST_NODE_TYPES.TSDeclareFunction
|
|
715
726
|
: ts_estree_1.AST_NODE_TYPES.FunctionDeclaration,
|
|
716
|
-
async:
|
|
727
|
+
async: isAsync,
|
|
717
728
|
body: this.convertChild(node.body) || undefined,
|
|
718
729
|
declare: isDeclare,
|
|
719
730
|
expression: false,
|
|
720
|
-
generator:
|
|
731
|
+
generator: isGenerator,
|
|
721
732
|
id: this.convertChild(node.name),
|
|
722
733
|
params: this.convertParameters(node.parameters),
|
|
723
734
|
returnType: node.type && this.convertTypeAnnotation(node.type, node),
|
|
@@ -742,15 +753,15 @@ class Converter {
|
|
|
742
753
|
kind: (0, node_utils_1.getDeclarationKind)(node.declarationList),
|
|
743
754
|
});
|
|
744
755
|
if (!result.declarations.length) {
|
|
745
|
-
|
|
756
|
+
this.#throwUnlessAllowInvalidAST(node, 'A variable declaration list must have at least one variable declarator.');
|
|
746
757
|
}
|
|
747
758
|
if (result.kind === 'using' || result.kind === 'await using') {
|
|
748
759
|
node.declarationList.declarations.forEach((declaration, i) => {
|
|
749
760
|
if (result.declarations[i].init == null) {
|
|
750
|
-
|
|
761
|
+
this.#throwError(declaration, `'${result.kind}' declarations must be initialized.`);
|
|
751
762
|
}
|
|
752
763
|
if (result.declarations[i].id.type !== ts_estree_1.AST_NODE_TYPES.Identifier) {
|
|
753
|
-
|
|
764
|
+
this.#throwError(declaration.name, `'${result.kind}' declarations may not have binding patterns.`);
|
|
754
765
|
}
|
|
755
766
|
});
|
|
756
767
|
}
|
|
@@ -774,10 +785,10 @@ class Converter {
|
|
|
774
785
|
if (result.kind === 'using' || result.kind === 'await using') {
|
|
775
786
|
node.declarations.forEach((declaration, i) => {
|
|
776
787
|
if (result.declarations[i].init != null) {
|
|
777
|
-
|
|
788
|
+
this.#throwError(declaration, `'${result.kind}' declarations may not be initialized in for statement.`);
|
|
778
789
|
}
|
|
779
790
|
if (result.declarations[i].id.type !== ts_estree_1.AST_NODE_TYPES.Identifier) {
|
|
780
|
-
|
|
791
|
+
this.#throwError(declaration.name, `'${result.kind}' declarations may not have binding patterns.`);
|
|
781
792
|
}
|
|
782
793
|
});
|
|
783
794
|
}
|
|
@@ -827,7 +838,7 @@ class Converter {
|
|
|
827
838
|
property.kind === SyntaxKind.SetAccessor ||
|
|
828
839
|
property.kind === SyntaxKind.MethodDeclaration) &&
|
|
829
840
|
!property.body) {
|
|
830
|
-
|
|
841
|
+
this.#throwUnlessAllowInvalidAST(property.end - 1, "'{' expected.");
|
|
831
842
|
}
|
|
832
843
|
properties.push(this.convertChild(property));
|
|
833
844
|
}
|
|
@@ -840,10 +851,10 @@ class Converter {
|
|
|
840
851
|
// eslint-disable-next-line deprecation/deprecation
|
|
841
852
|
const { questionToken, exclamationToken } = node;
|
|
842
853
|
if (questionToken) {
|
|
843
|
-
|
|
854
|
+
this.#throwError(questionToken, 'A property assignment cannot have a question token.');
|
|
844
855
|
}
|
|
845
856
|
if (exclamationToken) {
|
|
846
|
-
|
|
857
|
+
this.#throwError(exclamationToken, 'A property assignment cannot have an exclamation token.');
|
|
847
858
|
}
|
|
848
859
|
return this.createNode(node, {
|
|
849
860
|
type: ts_estree_1.AST_NODE_TYPES.Property,
|
|
@@ -860,13 +871,13 @@ class Converter {
|
|
|
860
871
|
// eslint-disable-next-line deprecation/deprecation
|
|
861
872
|
const { modifiers, questionToken, exclamationToken } = node;
|
|
862
873
|
if (modifiers) {
|
|
863
|
-
|
|
874
|
+
this.#throwError(modifiers[0], 'A shorthand property assignment cannot have modifiers.');
|
|
864
875
|
}
|
|
865
876
|
if (questionToken) {
|
|
866
|
-
|
|
877
|
+
this.#throwError(questionToken, 'A shorthand property assignment cannot have a question token.');
|
|
867
878
|
}
|
|
868
879
|
if (exclamationToken) {
|
|
869
|
-
|
|
880
|
+
this.#throwError(exclamationToken, 'A shorthand property assignment cannot have an exclamation token.');
|
|
870
881
|
}
|
|
871
882
|
if (node.objectAssignmentInitializer) {
|
|
872
883
|
return this.createNode(node, {
|
|
@@ -903,7 +914,7 @@ class Converter {
|
|
|
903
914
|
case SyntaxKind.PropertyDeclaration: {
|
|
904
915
|
const isAbstract = (0, node_utils_1.hasModifier)(SyntaxKind.AbstractKeyword, node);
|
|
905
916
|
if (isAbstract && node.initializer) {
|
|
906
|
-
|
|
917
|
+
this.#throwError(node.initializer, `Abstract property cannot have an initializer.`);
|
|
907
918
|
}
|
|
908
919
|
const isAccessor = (0, node_utils_1.hasModifier)(SyntaxKind.AccessorKeyword, node);
|
|
909
920
|
const type = (() => {
|
|
@@ -1222,13 +1233,13 @@ class Converter {
|
|
|
1222
1233
|
return result;
|
|
1223
1234
|
}
|
|
1224
1235
|
case SyntaxKind.TaggedTemplateExpression:
|
|
1225
|
-
return this.createNode(node,
|
|
1236
|
+
return this.createNode(node, {
|
|
1226
1237
|
type: ts_estree_1.AST_NODE_TYPES.TaggedTemplateExpression,
|
|
1227
1238
|
typeArguments: node.typeArguments &&
|
|
1228
1239
|
this.convertTypeArgumentsToTypeParameterInstantiation(node.typeArguments, node),
|
|
1229
1240
|
tag: this.convertChild(node.tag),
|
|
1230
1241
|
quasi: this.convertChild(node.template),
|
|
1231
|
-
}
|
|
1242
|
+
});
|
|
1232
1243
|
case SyntaxKind.TemplateHead:
|
|
1233
1244
|
case SyntaxKind.TemplateMiddle:
|
|
1234
1245
|
case SyntaxKind.TemplateTail: {
|
|
@@ -1323,7 +1334,7 @@ class Converter {
|
|
|
1323
1334
|
if (!node.name &&
|
|
1324
1335
|
(!(0, node_utils_1.hasModifier)(ts.SyntaxKind.ExportKeyword, node) ||
|
|
1325
1336
|
!(0, node_utils_1.hasModifier)(ts.SyntaxKind.DefaultKeyword, node))) {
|
|
1326
|
-
|
|
1337
|
+
this.#throwUnlessAllowInvalidAST(node, "A class declaration without the 'default' modifier must have a name.");
|
|
1327
1338
|
}
|
|
1328
1339
|
/* intentional fallthrough */
|
|
1329
1340
|
case SyntaxKind.ClassExpression: {
|
|
@@ -1336,28 +1347,28 @@ class Converter {
|
|
|
1336
1347
|
for (const heritageClause of heritageClauses) {
|
|
1337
1348
|
const { token, types } = heritageClause;
|
|
1338
1349
|
if (types.length === 0) {
|
|
1339
|
-
|
|
1350
|
+
this.#throwUnlessAllowInvalidAST(heritageClause, `'${ts.tokenToString(token)}' list cannot be empty.`);
|
|
1340
1351
|
}
|
|
1341
1352
|
if (token === SyntaxKind.ExtendsKeyword) {
|
|
1342
1353
|
if (extendsClause) {
|
|
1343
|
-
|
|
1354
|
+
this.#throwUnlessAllowInvalidAST(heritageClause, "'extends' clause already seen.");
|
|
1344
1355
|
}
|
|
1345
1356
|
if (implementsClause) {
|
|
1346
|
-
|
|
1357
|
+
this.#throwUnlessAllowInvalidAST(heritageClause, "'extends' clause must precede 'implements' clause.");
|
|
1347
1358
|
}
|
|
1348
1359
|
if (types.length > 1) {
|
|
1349
|
-
|
|
1360
|
+
this.#throwUnlessAllowInvalidAST(types[1], 'Classes can only extend a single class.');
|
|
1350
1361
|
}
|
|
1351
1362
|
extendsClause ??= heritageClause;
|
|
1352
1363
|
}
|
|
1353
1364
|
else if (token === SyntaxKind.ImplementsKeyword) {
|
|
1354
1365
|
if (implementsClause) {
|
|
1355
|
-
|
|
1366
|
+
this.#throwUnlessAllowInvalidAST(heritageClause, "'implements' clause already seen.");
|
|
1356
1367
|
}
|
|
1357
1368
|
implementsClause ??= heritageClause;
|
|
1358
1369
|
}
|
|
1359
1370
|
}
|
|
1360
|
-
const result = this.createNode(node,
|
|
1371
|
+
const result = this.createNode(node, {
|
|
1361
1372
|
type: classNodeType,
|
|
1362
1373
|
abstract: (0, node_utils_1.hasModifier)(SyntaxKind.AbstractKeyword, node),
|
|
1363
1374
|
body: this.createNode(node, {
|
|
@@ -1377,7 +1388,7 @@ class Converter {
|
|
|
1377
1388
|
superTypeArguments: undefined,
|
|
1378
1389
|
typeParameters: node.typeParameters &&
|
|
1379
1390
|
this.convertTSTypeParametersToTypeParametersDeclaration(node.typeParameters),
|
|
1380
|
-
}
|
|
1391
|
+
});
|
|
1381
1392
|
if (extendsClause?.types[0]?.typeArguments) {
|
|
1382
1393
|
result.superTypeArguments =
|
|
1383
1394
|
this.convertTypeArgumentsToTypeParameterInstantiation(extendsClause.types[0].typeArguments, extendsClause.types[0]);
|
|
@@ -1392,7 +1403,7 @@ class Converter {
|
|
|
1392
1403
|
});
|
|
1393
1404
|
case SyntaxKind.ImportDeclaration: {
|
|
1394
1405
|
this.assertModuleSpecifier(node, false);
|
|
1395
|
-
const result = this.createNode(node,
|
|
1406
|
+
const result = this.createNode(node, this.#withDeprecatedAliasGetter({
|
|
1396
1407
|
type: ts_estree_1.AST_NODE_TYPES.ImportDeclaration,
|
|
1397
1408
|
source: this.convertChild(node.moduleSpecifier),
|
|
1398
1409
|
specifiers: [],
|
|
@@ -1444,7 +1455,7 @@ class Converter {
|
|
|
1444
1455
|
case SyntaxKind.ExportDeclaration: {
|
|
1445
1456
|
if (node.exportClause?.kind === SyntaxKind.NamedExports) {
|
|
1446
1457
|
this.assertModuleSpecifier(node, true);
|
|
1447
|
-
return this.createNode(node,
|
|
1458
|
+
return this.createNode(node, this.#withDeprecatedAliasGetter({
|
|
1448
1459
|
type: ts_estree_1.AST_NODE_TYPES.ExportNamedDeclaration,
|
|
1449
1460
|
source: this.convertChild(node.moduleSpecifier),
|
|
1450
1461
|
specifiers: node.exportClause.elements.map(el => this.convertChild(el)),
|
|
@@ -1456,7 +1467,7 @@ class Converter {
|
|
|
1456
1467
|
}, 'assertions', 'attributes', true));
|
|
1457
1468
|
}
|
|
1458
1469
|
this.assertModuleSpecifier(node, false);
|
|
1459
|
-
return this.createNode(node,
|
|
1470
|
+
return this.createNode(node, this.#withDeprecatedAliasGetter({
|
|
1460
1471
|
type: ts_estree_1.AST_NODE_TYPES.ExportAllDeclaration,
|
|
1461
1472
|
source: this.convertChild(node.moduleSpecifier),
|
|
1462
1473
|
exportKind: node.isTypeOnly ? 'type' : 'value',
|
|
@@ -1496,7 +1507,7 @@ class Converter {
|
|
|
1496
1507
|
*/
|
|
1497
1508
|
if (operator === '++' || operator === '--') {
|
|
1498
1509
|
if (!(0, node_utils_1.isValidAssignmentTarget)(node.operand)) {
|
|
1499
|
-
|
|
1510
|
+
this.#throwUnlessAllowInvalidAST(node.operand, 'Invalid left-hand side expression in unary operation');
|
|
1500
1511
|
}
|
|
1501
1512
|
return this.createNode(node, {
|
|
1502
1513
|
type: ts_estree_1.AST_NODE_TYPES.UpdateExpression,
|
|
@@ -1605,7 +1616,7 @@ class Converter {
|
|
|
1605
1616
|
case SyntaxKind.CallExpression: {
|
|
1606
1617
|
if (node.expression.kind === SyntaxKind.ImportKeyword) {
|
|
1607
1618
|
if (node.arguments.length !== 1 && node.arguments.length !== 2) {
|
|
1608
|
-
|
|
1619
|
+
this.#throwUnlessAllowInvalidAST(node.arguments[2] ?? node, 'Dynamic import requires exactly one or two arguments.');
|
|
1609
1620
|
}
|
|
1610
1621
|
return this.createNode(node, {
|
|
1611
1622
|
type: ts_estree_1.AST_NODE_TYPES.ImportExpression,
|
|
@@ -1619,27 +1630,27 @@ class Converter {
|
|
|
1619
1630
|
const args = node.arguments.map(el => this.convertChild(el));
|
|
1620
1631
|
const typeArguments = node.typeArguments &&
|
|
1621
1632
|
this.convertTypeArgumentsToTypeParameterInstantiation(node.typeArguments, node);
|
|
1622
|
-
const result = this.createNode(node,
|
|
1633
|
+
const result = this.createNode(node, {
|
|
1623
1634
|
type: ts_estree_1.AST_NODE_TYPES.CallExpression,
|
|
1624
1635
|
callee,
|
|
1625
1636
|
arguments: args,
|
|
1626
1637
|
optional: node.questionDotToken !== undefined,
|
|
1627
1638
|
typeArguments,
|
|
1628
|
-
}
|
|
1639
|
+
});
|
|
1629
1640
|
return this.convertChainExpression(result, node);
|
|
1630
1641
|
}
|
|
1631
1642
|
case SyntaxKind.NewExpression: {
|
|
1632
1643
|
const typeArguments = node.typeArguments &&
|
|
1633
1644
|
this.convertTypeArgumentsToTypeParameterInstantiation(node.typeArguments, node);
|
|
1634
1645
|
// NOTE - NewExpression cannot have an optional chain in it
|
|
1635
|
-
return this.createNode(node,
|
|
1646
|
+
return this.createNode(node, {
|
|
1636
1647
|
type: ts_estree_1.AST_NODE_TYPES.NewExpression,
|
|
1637
1648
|
arguments: node.arguments
|
|
1638
1649
|
? node.arguments.map(el => this.convertChild(el))
|
|
1639
1650
|
: [],
|
|
1640
1651
|
callee: this.convertChild(node.expression),
|
|
1641
1652
|
typeArguments,
|
|
1642
|
-
}
|
|
1653
|
+
});
|
|
1643
1654
|
}
|
|
1644
1655
|
case SyntaxKind.ConditionalExpression:
|
|
1645
1656
|
return this.createNode(node, {
|
|
@@ -1773,7 +1784,7 @@ class Converter {
|
|
|
1773
1784
|
* Convert SyntaxKind.JsxSelfClosingElement to SyntaxKind.JsxOpeningElement,
|
|
1774
1785
|
* TypeScript does not seem to have the idea of openingElement when tag is self-closing
|
|
1775
1786
|
*/
|
|
1776
|
-
openingElement: this.createNode(node,
|
|
1787
|
+
openingElement: this.createNode(node, {
|
|
1777
1788
|
type: ts_estree_1.AST_NODE_TYPES.JSXOpeningElement,
|
|
1778
1789
|
typeArguments: node.typeArguments
|
|
1779
1790
|
? this.convertTypeArgumentsToTypeParameterInstantiation(node.typeArguments, node)
|
|
@@ -1782,20 +1793,20 @@ class Converter {
|
|
|
1782
1793
|
name: this.convertJSXTagName(node.tagName, node),
|
|
1783
1794
|
attributes: node.attributes.properties.map(el => this.convertChild(el)),
|
|
1784
1795
|
range: (0, node_utils_1.getRange)(node, this.ast),
|
|
1785
|
-
}
|
|
1796
|
+
}),
|
|
1786
1797
|
closingElement: null,
|
|
1787
1798
|
children: [],
|
|
1788
1799
|
});
|
|
1789
1800
|
}
|
|
1790
1801
|
case SyntaxKind.JsxOpeningElement: {
|
|
1791
|
-
return this.createNode(node,
|
|
1802
|
+
return this.createNode(node, {
|
|
1792
1803
|
type: ts_estree_1.AST_NODE_TYPES.JSXOpeningElement,
|
|
1793
1804
|
typeArguments: node.typeArguments &&
|
|
1794
1805
|
this.convertTypeArgumentsToTypeParameterInstantiation(node.typeArguments, node),
|
|
1795
1806
|
selfClosing: false,
|
|
1796
1807
|
name: this.convertJSXTagName(node.tagName, node),
|
|
1797
1808
|
attributes: node.attributes.properties.map(el => this.convertChild(el)),
|
|
1798
|
-
}
|
|
1809
|
+
});
|
|
1799
1810
|
}
|
|
1800
1811
|
case SyntaxKind.JsxClosingElement:
|
|
1801
1812
|
return this.createNode(node, {
|
|
@@ -1860,12 +1871,12 @@ class Converter {
|
|
|
1860
1871
|
}
|
|
1861
1872
|
// TypeScript specific
|
|
1862
1873
|
case SyntaxKind.TypeReference:
|
|
1863
|
-
return this.createNode(node,
|
|
1874
|
+
return this.createNode(node, {
|
|
1864
1875
|
type: ts_estree_1.AST_NODE_TYPES.TSTypeReference,
|
|
1865
1876
|
typeName: this.convertChild(node.typeName),
|
|
1866
1877
|
typeArguments: node.typeArguments &&
|
|
1867
1878
|
this.convertTypeArgumentsToTypeParameterInstantiation(node.typeArguments, node),
|
|
1868
|
-
}
|
|
1879
|
+
});
|
|
1869
1880
|
case SyntaxKind.TypeParameter: {
|
|
1870
1881
|
return this.createNode(node, {
|
|
1871
1882
|
type: ts_estree_1.AST_NODE_TYPES.TSTypeParameter,
|
|
@@ -1933,17 +1944,17 @@ class Converter {
|
|
|
1933
1944
|
});
|
|
1934
1945
|
}
|
|
1935
1946
|
case SyntaxKind.TypeQuery:
|
|
1936
|
-
return this.createNode(node,
|
|
1947
|
+
return this.createNode(node, {
|
|
1937
1948
|
type: ts_estree_1.AST_NODE_TYPES.TSTypeQuery,
|
|
1938
1949
|
exprName: this.convertChild(node.exprName),
|
|
1939
1950
|
typeArguments: node.typeArguments &&
|
|
1940
1951
|
this.convertTypeArgumentsToTypeParameterInstantiation(node.typeArguments, node),
|
|
1941
|
-
}
|
|
1952
|
+
});
|
|
1942
1953
|
case SyntaxKind.MappedType: {
|
|
1943
1954
|
if (node.members && node.members.length > 0) {
|
|
1944
|
-
|
|
1955
|
+
this.#throwUnlessAllowInvalidAST(node.members[0], 'A mapped type may not declare properties or methods.');
|
|
1945
1956
|
}
|
|
1946
|
-
return this.createNode(node,
|
|
1957
|
+
return this.createNode(node, this.#withDeprecatedGetter({
|
|
1947
1958
|
type: ts_estree_1.AST_NODE_TYPES.TSMappedType,
|
|
1948
1959
|
constraint: this.convertChild(node.typeParameter.constraint),
|
|
1949
1960
|
key: this.convertChild(node.typeParameter.name),
|
|
@@ -1977,7 +1988,7 @@ class Converter {
|
|
|
1977
1988
|
// eslint-disable-next-line deprecation/deprecation
|
|
1978
1989
|
const { initializer } = node;
|
|
1979
1990
|
if (initializer) {
|
|
1980
|
-
|
|
1991
|
+
this.#throwError(initializer, 'A property signature cannot have an initializer.');
|
|
1981
1992
|
}
|
|
1982
1993
|
return this.createNode(node, {
|
|
1983
1994
|
type: ts_estree_1.AST_NODE_TYPES.TSPropertySignature,
|
|
@@ -2014,7 +2025,7 @@ class Converter {
|
|
|
2014
2025
|
// eslint-disable-next-line deprecation/deprecation
|
|
2015
2026
|
const { modifiers } = node;
|
|
2016
2027
|
if (modifiers) {
|
|
2017
|
-
|
|
2028
|
+
this.#throwError(modifiers[0], 'A function type cannot have modifiers.');
|
|
2018
2029
|
}
|
|
2019
2030
|
}
|
|
2020
2031
|
// intentional fallthrough
|
|
@@ -2040,19 +2051,19 @@ class Converter {
|
|
|
2040
2051
|
: parentKind === SyntaxKind.HeritageClause
|
|
2041
2052
|
? ts_estree_1.AST_NODE_TYPES.TSClassImplements
|
|
2042
2053
|
: ts_estree_1.AST_NODE_TYPES.TSInstantiationExpression;
|
|
2043
|
-
return this.createNode(node,
|
|
2054
|
+
return this.createNode(node, {
|
|
2044
2055
|
type,
|
|
2045
2056
|
expression: this.convertChild(node.expression),
|
|
2046
2057
|
typeArguments: node.typeArguments &&
|
|
2047
2058
|
this.convertTypeArgumentsToTypeParameterInstantiation(node.typeArguments, node),
|
|
2048
|
-
}
|
|
2059
|
+
});
|
|
2049
2060
|
}
|
|
2050
2061
|
case SyntaxKind.InterfaceDeclaration: {
|
|
2051
2062
|
const interfaceHeritageClauses = node.heritageClauses ?? [];
|
|
2052
2063
|
const interfaceExtends = [];
|
|
2053
2064
|
for (const heritageClause of interfaceHeritageClauses) {
|
|
2054
2065
|
if (heritageClause.token !== SyntaxKind.ExtendsKeyword) {
|
|
2055
|
-
|
|
2066
|
+
this.#throwError(heritageClause, heritageClause.token === SyntaxKind.ImplementsKeyword
|
|
2056
2067
|
? "Interface declaration cannot have 'implements' clause."
|
|
2057
2068
|
: 'Unexpected token.');
|
|
2058
2069
|
}
|
|
@@ -2099,7 +2110,7 @@ class Converter {
|
|
|
2099
2110
|
const token = (0, node_utils_1.findNextToken)(node.getFirstToken(), node, this.ast);
|
|
2100
2111
|
range[0] = token.getStart(this.ast);
|
|
2101
2112
|
}
|
|
2102
|
-
const result = this.createNode(node,
|
|
2113
|
+
const result = this.createNode(node, {
|
|
2103
2114
|
type: ts_estree_1.AST_NODE_TYPES.TSImportType,
|
|
2104
2115
|
argument: this.convertChild(node.argument),
|
|
2105
2116
|
qualifier: this.convertChild(node.qualifier),
|
|
@@ -2107,20 +2118,19 @@ class Converter {
|
|
|
2107
2118
|
? this.convertTypeArgumentsToTypeParameterInstantiation(node.typeArguments, node)
|
|
2108
2119
|
: null,
|
|
2109
2120
|
range: range,
|
|
2110
|
-
}
|
|
2121
|
+
});
|
|
2111
2122
|
if (node.isTypeOf) {
|
|
2112
2123
|
return this.createNode(node, {
|
|
2113
2124
|
type: ts_estree_1.AST_NODE_TYPES.TSTypeQuery,
|
|
2114
2125
|
exprName: result,
|
|
2115
2126
|
typeArguments: undefined,
|
|
2116
|
-
typeParameters: undefined,
|
|
2117
2127
|
});
|
|
2118
2128
|
}
|
|
2119
2129
|
return result;
|
|
2120
2130
|
}
|
|
2121
2131
|
case SyntaxKind.EnumDeclaration: {
|
|
2122
2132
|
const members = node.members.map(el => this.convertChild(el));
|
|
2123
|
-
const result = this.createNode(node,
|
|
2133
|
+
const result = this.createNode(node, this.#withDeprecatedGetter({
|
|
2124
2134
|
type: ts_estree_1.AST_NODE_TYPES.TSEnumDeclaration,
|
|
2125
2135
|
body: this.createNode(node, {
|
|
2126
2136
|
type: ts_estree_1.AST_NODE_TYPES.TSEnumBody,
|
|
@@ -2153,10 +2163,10 @@ class Converter {
|
|
|
2153
2163
|
const body = this.convertChild(node.body);
|
|
2154
2164
|
if (body == null ||
|
|
2155
2165
|
body.type === ts_estree_1.AST_NODE_TYPES.TSModuleDeclaration) {
|
|
2156
|
-
|
|
2166
|
+
this.#throwUnlessAllowInvalidAST(node.body ?? node, 'Expected a valid module body');
|
|
2157
2167
|
}
|
|
2158
2168
|
if (id.type !== ts_estree_1.AST_NODE_TYPES.Identifier) {
|
|
2159
|
-
|
|
2169
|
+
this.#throwUnlessAllowInvalidAST(node.name, 'global module augmentation must have an Identifier id');
|
|
2160
2170
|
}
|
|
2161
2171
|
return {
|
|
2162
2172
|
kind: 'global',
|
|
@@ -2180,10 +2190,10 @@ class Converter {
|
|
|
2180
2190
|
// We "unravel" them here by making our own nested TSQualifiedName,
|
|
2181
2191
|
// with the innermost node's body as the actual node body.
|
|
2182
2192
|
if (node.body == null) {
|
|
2183
|
-
|
|
2193
|
+
this.#throwUnlessAllowInvalidAST(node, 'Expected a module body');
|
|
2184
2194
|
}
|
|
2185
2195
|
if (node.name.kind !== ts.SyntaxKind.Identifier) {
|
|
2186
|
-
|
|
2196
|
+
this.#throwUnlessAllowInvalidAST(node.name, '`namespace`s must have an Identifier id');
|
|
2187
2197
|
}
|
|
2188
2198
|
let name = this.createNode(node.name, {
|
|
2189
2199
|
decorators: [],
|
|
@@ -2225,6 +2235,7 @@ class Converter {
|
|
|
2225
2235
|
});
|
|
2226
2236
|
result.declare = isDeclare;
|
|
2227
2237
|
if (node.flags & ts.NodeFlags.GlobalAugmentation) {
|
|
2238
|
+
// eslint-disable-next-line deprecation/deprecation
|
|
2228
2239
|
result.global = true;
|
|
2229
2240
|
}
|
|
2230
2241
|
return this.fixExports(node, result);
|
|
@@ -2287,6 +2298,9 @@ class Converter {
|
|
|
2287
2298
|
}));
|
|
2288
2299
|
}
|
|
2289
2300
|
case SyntaxKind.ExternalModuleReference: {
|
|
2301
|
+
if (node.expression.kind !== SyntaxKind.StringLiteral) {
|
|
2302
|
+
this.#throwError(node.expression, 'String literal expected.');
|
|
2303
|
+
}
|
|
2290
2304
|
return this.createNode(node, {
|
|
2291
2305
|
type: ts_estree_1.AST_NODE_TYPES.TSExternalModuleReference,
|
|
2292
2306
|
expression: this.convertChild(node.expression),
|
|
@@ -2380,203 +2394,215 @@ class Converter {
|
|
|
2380
2394
|
return this.deeplyCopy(node);
|
|
2381
2395
|
}
|
|
2382
2396
|
}
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
if (this.options.allowInvalidAST) {
|
|
2387
|
-
return;
|
|
2388
|
-
}
|
|
2389
|
-
// typescript<5.0.0
|
|
2390
|
-
if ((0, node_utils_1.nodeHasIllegalDecorators)(node)) {
|
|
2391
|
-
__classPrivateFieldGet(this, _Converter_instances, "m", _Converter_throwError).call(this, node.illegalDecorators[0], 'Decorators are not valid here.');
|
|
2392
|
-
}
|
|
2393
|
-
for (const decorator of (0, getModifiers_1.getDecorators)(node,
|
|
2394
|
-
/* includeIllegalDecorators */ true) ?? []) {
|
|
2395
|
-
// `checkGrammarModifiers` function in typescript
|
|
2396
|
-
if (!(0, node_utils_1.nodeCanBeDecorated)(node)) {
|
|
2397
|
-
if (ts.isMethodDeclaration(node) && !(0, node_utils_1.nodeIsPresent)(node.body)) {
|
|
2398
|
-
__classPrivateFieldGet(this, _Converter_instances, "m", _Converter_throwError).call(this, decorator, 'A decorator can only decorate a method implementation, not an overload.');
|
|
2399
|
-
}
|
|
2400
|
-
else {
|
|
2401
|
-
__classPrivateFieldGet(this, _Converter_instances, "m", _Converter_throwError).call(this, decorator, 'Decorators are not valid here.');
|
|
2402
|
-
}
|
|
2403
|
-
}
|
|
2404
|
-
}
|
|
2405
|
-
for (const modifier of (0, getModifiers_1.getModifiers)(node,
|
|
2406
|
-
/* includeIllegalModifiers */ true) ?? []) {
|
|
2407
|
-
if (modifier.kind !== SyntaxKind.ReadonlyKeyword) {
|
|
2408
|
-
if (node.kind === SyntaxKind.PropertySignature ||
|
|
2409
|
-
node.kind === SyntaxKind.MethodSignature) {
|
|
2410
|
-
__classPrivateFieldGet(this, _Converter_instances, "m", _Converter_throwError).call(this, modifier, `'${ts.tokenToString(modifier.kind)}' modifier cannot appear on a type member`);
|
|
2411
|
-
}
|
|
2412
|
-
if (node.kind === SyntaxKind.IndexSignature &&
|
|
2413
|
-
(modifier.kind !== SyntaxKind.StaticKeyword ||
|
|
2414
|
-
!ts.isClassLike(node.parent))) {
|
|
2415
|
-
__classPrivateFieldGet(this, _Converter_instances, "m", _Converter_throwError).call(this, modifier, `'${ts.tokenToString(modifier.kind)}' modifier cannot appear on an index signature`);
|
|
2416
|
-
}
|
|
2417
|
-
}
|
|
2418
|
-
if (modifier.kind !== SyntaxKind.InKeyword &&
|
|
2419
|
-
modifier.kind !== SyntaxKind.OutKeyword &&
|
|
2420
|
-
modifier.kind !== SyntaxKind.ConstKeyword &&
|
|
2421
|
-
node.kind === SyntaxKind.TypeParameter) {
|
|
2422
|
-
__classPrivateFieldGet(this, _Converter_instances, "m", _Converter_throwError).call(this, modifier, `'${ts.tokenToString(modifier.kind)}' modifier cannot appear on a type parameter`);
|
|
2423
|
-
}
|
|
2424
|
-
if ((modifier.kind === SyntaxKind.InKeyword ||
|
|
2425
|
-
modifier.kind === SyntaxKind.OutKeyword) &&
|
|
2426
|
-
(node.kind !== SyntaxKind.TypeParameter ||
|
|
2427
|
-
!(ts.isInterfaceDeclaration(node.parent) ||
|
|
2428
|
-
ts.isClassLike(node.parent) ||
|
|
2429
|
-
ts.isTypeAliasDeclaration(node.parent)))) {
|
|
2430
|
-
__classPrivateFieldGet(this, _Converter_instances, "m", _Converter_throwError).call(this, modifier, `'${ts.tokenToString(modifier.kind)}' modifier can only appear on a type parameter of a class, interface or type alias`);
|
|
2431
|
-
}
|
|
2432
|
-
if (modifier.kind === SyntaxKind.ReadonlyKeyword &&
|
|
2433
|
-
node.kind !== SyntaxKind.PropertyDeclaration &&
|
|
2434
|
-
node.kind !== SyntaxKind.PropertySignature &&
|
|
2435
|
-
node.kind !== SyntaxKind.IndexSignature &&
|
|
2436
|
-
node.kind !== SyntaxKind.Parameter) {
|
|
2437
|
-
__classPrivateFieldGet(this, _Converter_instances, "m", _Converter_throwError).call(this, modifier, "'readonly' modifier can only appear on a property declaration or index signature.");
|
|
2438
|
-
}
|
|
2439
|
-
if (modifier.kind === SyntaxKind.DeclareKeyword &&
|
|
2440
|
-
ts.isClassLike(node.parent) &&
|
|
2441
|
-
!ts.isPropertyDeclaration(node)) {
|
|
2442
|
-
__classPrivateFieldGet(this, _Converter_instances, "m", _Converter_throwError).call(this, modifier, `'${ts.tokenToString(modifier.kind)}' modifier cannot appear on class elements of this kind.`);
|
|
2443
|
-
}
|
|
2444
|
-
if (modifier.kind === SyntaxKind.DeclareKeyword &&
|
|
2445
|
-
ts.isVariableStatement(node)) {
|
|
2446
|
-
const declarationKind = (0, node_utils_1.getDeclarationKind)(node.declarationList);
|
|
2447
|
-
if (declarationKind === 'using' || declarationKind === 'await using') {
|
|
2448
|
-
__classPrivateFieldGet(this, _Converter_instances, "m", _Converter_throwError).call(this, modifier, `'declare' modifier cannot appear on a '${declarationKind}' declaration.`);
|
|
2449
|
-
}
|
|
2450
|
-
}
|
|
2451
|
-
if (modifier.kind === SyntaxKind.AbstractKeyword &&
|
|
2452
|
-
node.kind !== SyntaxKind.ClassDeclaration &&
|
|
2453
|
-
node.kind !== SyntaxKind.ConstructorType &&
|
|
2454
|
-
node.kind !== SyntaxKind.MethodDeclaration &&
|
|
2455
|
-
node.kind !== SyntaxKind.PropertyDeclaration &&
|
|
2456
|
-
node.kind !== SyntaxKind.GetAccessor &&
|
|
2457
|
-
node.kind !== SyntaxKind.SetAccessor) {
|
|
2458
|
-
__classPrivateFieldGet(this, _Converter_instances, "m", _Converter_throwError).call(this, modifier, `'${ts.tokenToString(modifier.kind)}' modifier can only appear on a class, method, or property declaration.`);
|
|
2397
|
+
#checkModifiers(node) {
|
|
2398
|
+
if (this.options.allowInvalidAST) {
|
|
2399
|
+
return;
|
|
2459
2400
|
}
|
|
2460
|
-
|
|
2461
|
-
|
|
2462
|
-
|
|
2463
|
-
modifier.kind === SyntaxKind.PrivateKeyword) &&
|
|
2464
|
-
(node.parent.kind === SyntaxKind.ModuleBlock ||
|
|
2465
|
-
node.parent.kind === SyntaxKind.SourceFile)) {
|
|
2466
|
-
__classPrivateFieldGet(this, _Converter_instances, "m", _Converter_throwError).call(this, modifier, `'${ts.tokenToString(modifier.kind)}' modifier cannot appear on a module or namespace element.`);
|
|
2401
|
+
// typescript<5.0.0
|
|
2402
|
+
if ((0, node_utils_1.nodeHasIllegalDecorators)(node)) {
|
|
2403
|
+
this.#throwError(node.illegalDecorators[0], 'Decorators are not valid here.');
|
|
2467
2404
|
}
|
|
2468
|
-
|
|
2469
|
-
|
|
2470
|
-
|
|
2471
|
-
|
|
2472
|
-
|
|
2473
|
-
|
|
2474
|
-
|
|
2475
|
-
|
|
2476
|
-
|
|
2477
|
-
node.kind !== SyntaxKind.ArrowFunction) {
|
|
2478
|
-
__classPrivateFieldGet(this, _Converter_instances, "m", _Converter_throwError).call(this, modifier, "'async' modifier cannot be used here.");
|
|
2479
|
-
}
|
|
2480
|
-
// `checkGrammarModifiers` function in `typescript`
|
|
2481
|
-
if (node.kind === SyntaxKind.Parameter &&
|
|
2482
|
-
(modifier.kind === SyntaxKind.StaticKeyword ||
|
|
2483
|
-
modifier.kind === SyntaxKind.ExportKeyword ||
|
|
2484
|
-
modifier.kind === SyntaxKind.DeclareKeyword ||
|
|
2485
|
-
modifier.kind === SyntaxKind.AsyncKeyword)) {
|
|
2486
|
-
__classPrivateFieldGet(this, _Converter_instances, "m", _Converter_throwError).call(this, modifier, `'${ts.tokenToString(modifier.kind)}' modifier cannot appear on a parameter.`);
|
|
2487
|
-
}
|
|
2488
|
-
// `checkGrammarModifiers` function in `typescript`
|
|
2489
|
-
if (modifier.kind === SyntaxKind.PublicKeyword ||
|
|
2490
|
-
modifier.kind === SyntaxKind.ProtectedKeyword ||
|
|
2491
|
-
modifier.kind === SyntaxKind.PrivateKeyword) {
|
|
2492
|
-
for (const anotherModifier of (0, getModifiers_1.getModifiers)(node) ?? []) {
|
|
2493
|
-
if (anotherModifier !== modifier &&
|
|
2494
|
-
(anotherModifier.kind === SyntaxKind.PublicKeyword ||
|
|
2495
|
-
anotherModifier.kind === SyntaxKind.ProtectedKeyword ||
|
|
2496
|
-
anotherModifier.kind === SyntaxKind.PrivateKeyword)) {
|
|
2497
|
-
__classPrivateFieldGet(this, _Converter_instances, "m", _Converter_throwError).call(this, anotherModifier, `Accessibility modifier already seen.`);
|
|
2405
|
+
for (const decorator of (0, getModifiers_1.getDecorators)(node,
|
|
2406
|
+
/* includeIllegalDecorators */ true) ?? []) {
|
|
2407
|
+
// `checkGrammarModifiers` function in typescript
|
|
2408
|
+
if (!(0, node_utils_1.nodeCanBeDecorated)(node)) {
|
|
2409
|
+
if (ts.isMethodDeclaration(node) && !(0, node_utils_1.nodeIsPresent)(node.body)) {
|
|
2410
|
+
this.#throwError(decorator, 'A decorator can only decorate a method implementation, not an overload.');
|
|
2411
|
+
}
|
|
2412
|
+
else {
|
|
2413
|
+
this.#throwError(decorator, 'Decorators are not valid here.');
|
|
2498
2414
|
}
|
|
2499
2415
|
}
|
|
2500
2416
|
}
|
|
2501
|
-
|
|
2502
|
-
|
|
2503
|
-
|
|
2504
|
-
|
|
2505
|
-
|
|
2506
|
-
|
|
2417
|
+
for (const modifier of (0, getModifiers_1.getModifiers)(node,
|
|
2418
|
+
/* includeIllegalModifiers */ true) ?? []) {
|
|
2419
|
+
if (modifier.kind !== SyntaxKind.ReadonlyKeyword) {
|
|
2420
|
+
if (node.kind === SyntaxKind.PropertySignature ||
|
|
2421
|
+
node.kind === SyntaxKind.MethodSignature) {
|
|
2422
|
+
this.#throwError(modifier, `'${ts.tokenToString(modifier.kind)}' modifier cannot appear on a type member`);
|
|
2423
|
+
}
|
|
2424
|
+
if (node.kind === SyntaxKind.IndexSignature &&
|
|
2425
|
+
(modifier.kind !== SyntaxKind.StaticKeyword ||
|
|
2426
|
+
!ts.isClassLike(node.parent))) {
|
|
2427
|
+
this.#throwError(modifier, `'${ts.tokenToString(modifier.kind)}' modifier cannot appear on an index signature`);
|
|
2428
|
+
}
|
|
2429
|
+
}
|
|
2430
|
+
if (modifier.kind !== SyntaxKind.InKeyword &&
|
|
2431
|
+
modifier.kind !== SyntaxKind.OutKeyword &&
|
|
2432
|
+
modifier.kind !== SyntaxKind.ConstKeyword &&
|
|
2433
|
+
node.kind === SyntaxKind.TypeParameter) {
|
|
2434
|
+
this.#throwError(modifier, `'${ts.tokenToString(modifier.kind)}' modifier cannot appear on a type parameter`);
|
|
2435
|
+
}
|
|
2436
|
+
if ((modifier.kind === SyntaxKind.InKeyword ||
|
|
2437
|
+
modifier.kind === SyntaxKind.OutKeyword) &&
|
|
2438
|
+
(node.kind !== SyntaxKind.TypeParameter ||
|
|
2439
|
+
!(ts.isInterfaceDeclaration(node.parent) ||
|
|
2440
|
+
ts.isClassLike(node.parent) ||
|
|
2441
|
+
ts.isTypeAliasDeclaration(node.parent)))) {
|
|
2442
|
+
this.#throwError(modifier, `'${ts.tokenToString(modifier.kind)}' modifier can only appear on a type parameter of a class, interface or type alias`);
|
|
2443
|
+
}
|
|
2444
|
+
if (modifier.kind === SyntaxKind.ReadonlyKeyword &&
|
|
2445
|
+
node.kind !== SyntaxKind.PropertyDeclaration &&
|
|
2446
|
+
node.kind !== SyntaxKind.PropertySignature &&
|
|
2447
|
+
node.kind !== SyntaxKind.IndexSignature &&
|
|
2448
|
+
node.kind !== SyntaxKind.Parameter) {
|
|
2449
|
+
this.#throwError(modifier, "'readonly' modifier can only appear on a property declaration or index signature.");
|
|
2450
|
+
}
|
|
2451
|
+
if (modifier.kind === SyntaxKind.DeclareKeyword &&
|
|
2452
|
+
ts.isClassLike(node.parent) &&
|
|
2453
|
+
!ts.isPropertyDeclaration(node)) {
|
|
2454
|
+
this.#throwError(modifier, `'${ts.tokenToString(modifier.kind)}' modifier cannot appear on class elements of this kind.`);
|
|
2455
|
+
}
|
|
2456
|
+
if (modifier.kind === SyntaxKind.DeclareKeyword &&
|
|
2457
|
+
ts.isVariableStatement(node)) {
|
|
2458
|
+
const declarationKind = (0, node_utils_1.getDeclarationKind)(node.declarationList);
|
|
2459
|
+
if (declarationKind === 'using' || declarationKind === 'await using') {
|
|
2460
|
+
this.#throwError(modifier, `'declare' modifier cannot appear on a '${declarationKind}' declaration.`);
|
|
2461
|
+
}
|
|
2462
|
+
}
|
|
2463
|
+
if (modifier.kind === SyntaxKind.AbstractKeyword &&
|
|
2464
|
+
node.kind !== SyntaxKind.ClassDeclaration &&
|
|
2465
|
+
node.kind !== SyntaxKind.ConstructorType &&
|
|
2466
|
+
node.kind !== SyntaxKind.MethodDeclaration &&
|
|
2467
|
+
node.kind !== SyntaxKind.PropertyDeclaration &&
|
|
2468
|
+
node.kind !== SyntaxKind.GetAccessor &&
|
|
2469
|
+
node.kind !== SyntaxKind.SetAccessor) {
|
|
2470
|
+
this.#throwError(modifier, `'${ts.tokenToString(modifier.kind)}' modifier can only appear on a class, method, or property declaration.`);
|
|
2471
|
+
}
|
|
2472
|
+
if ((modifier.kind === SyntaxKind.StaticKeyword ||
|
|
2473
|
+
modifier.kind === SyntaxKind.PublicKeyword ||
|
|
2507
2474
|
modifier.kind === SyntaxKind.ProtectedKeyword ||
|
|
2508
|
-
modifier.kind === SyntaxKind.
|
|
2509
|
-
|
|
2510
|
-
|
|
2511
|
-
|
|
2512
|
-
|
|
2475
|
+
modifier.kind === SyntaxKind.PrivateKeyword) &&
|
|
2476
|
+
(node.parent.kind === SyntaxKind.ModuleBlock ||
|
|
2477
|
+
node.parent.kind === SyntaxKind.SourceFile)) {
|
|
2478
|
+
this.#throwError(modifier, `'${ts.tokenToString(modifier.kind)}' modifier cannot appear on a module or namespace element.`);
|
|
2479
|
+
}
|
|
2480
|
+
if (modifier.kind === SyntaxKind.AccessorKeyword &&
|
|
2481
|
+
node.kind !== SyntaxKind.PropertyDeclaration) {
|
|
2482
|
+
this.#throwError(modifier, "'accessor' modifier can only appear on a property declaration.");
|
|
2483
|
+
}
|
|
2484
|
+
// `checkGrammarAsyncModifier` function in `typescript`
|
|
2485
|
+
if (modifier.kind === SyntaxKind.AsyncKeyword &&
|
|
2486
|
+
node.kind !== SyntaxKind.MethodDeclaration &&
|
|
2487
|
+
node.kind !== SyntaxKind.FunctionDeclaration &&
|
|
2488
|
+
node.kind !== SyntaxKind.FunctionExpression &&
|
|
2489
|
+
node.kind !== SyntaxKind.ArrowFunction) {
|
|
2490
|
+
this.#throwError(modifier, "'async' modifier cannot be used here.");
|
|
2491
|
+
}
|
|
2492
|
+
// `checkGrammarModifiers` function in `typescript`
|
|
2493
|
+
if (node.kind === SyntaxKind.Parameter &&
|
|
2494
|
+
(modifier.kind === SyntaxKind.StaticKeyword ||
|
|
2495
|
+
modifier.kind === SyntaxKind.ExportKeyword ||
|
|
2496
|
+
modifier.kind === SyntaxKind.DeclareKeyword ||
|
|
2497
|
+
modifier.kind === SyntaxKind.AsyncKeyword)) {
|
|
2498
|
+
this.#throwError(modifier, `'${ts.tokenToString(modifier.kind)}' modifier cannot appear on a parameter.`);
|
|
2499
|
+
}
|
|
2500
|
+
// `checkGrammarModifiers` function in `typescript`
|
|
2501
|
+
if (modifier.kind === SyntaxKind.PublicKeyword ||
|
|
2502
|
+
modifier.kind === SyntaxKind.ProtectedKeyword ||
|
|
2503
|
+
modifier.kind === SyntaxKind.PrivateKeyword) {
|
|
2504
|
+
for (const anotherModifier of (0, getModifiers_1.getModifiers)(node) ?? []) {
|
|
2505
|
+
if (anotherModifier !== modifier &&
|
|
2506
|
+
(anotherModifier.kind === SyntaxKind.PublicKeyword ||
|
|
2507
|
+
anotherModifier.kind === SyntaxKind.ProtectedKeyword ||
|
|
2508
|
+
anotherModifier.kind === SyntaxKind.PrivateKeyword)) {
|
|
2509
|
+
this.#throwError(anotherModifier, `Accessibility modifier already seen.`);
|
|
2510
|
+
}
|
|
2511
|
+
}
|
|
2512
|
+
}
|
|
2513
|
+
// `checkParameter` function in `typescript`
|
|
2514
|
+
if (node.kind === SyntaxKind.Parameter &&
|
|
2515
|
+
// In `typescript` package, it's `ts.hasSyntacticModifier(node, ts.ModifierFlags.ParameterPropertyModifier)`
|
|
2516
|
+
// https://github.com/typescript-eslint/typescript-eslint/pull/6615#discussion_r1136489935
|
|
2517
|
+
(modifier.kind === SyntaxKind.PublicKeyword ||
|
|
2518
|
+
modifier.kind === SyntaxKind.PrivateKeyword ||
|
|
2519
|
+
modifier.kind === SyntaxKind.ProtectedKeyword ||
|
|
2520
|
+
modifier.kind === SyntaxKind.ReadonlyKeyword ||
|
|
2521
|
+
modifier.kind === SyntaxKind.OverrideKeyword)) {
|
|
2522
|
+
const func = (0, node_utils_1.getContainingFunction)(node);
|
|
2523
|
+
if (!(func.kind === SyntaxKind.Constructor && (0, node_utils_1.nodeIsPresent)(func.body))) {
|
|
2524
|
+
this.#throwError(modifier, 'A parameter property is only allowed in a constructor implementation.');
|
|
2525
|
+
}
|
|
2513
2526
|
}
|
|
2514
2527
|
}
|
|
2515
2528
|
}
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
|
|
2529
|
+
#throwUnlessAllowInvalidAST(node, message) {
|
|
2530
|
+
if (!this.options.allowInvalidAST) {
|
|
2531
|
+
this.#throwError(node, message);
|
|
2532
|
+
}
|
|
2519
2533
|
}
|
|
2520
|
-
|
|
2521
|
-
|
|
2522
|
-
|
|
2523
|
-
|
|
2524
|
-
|
|
2525
|
-
|
|
2526
|
-
|
|
2527
|
-
|
|
2528
|
-
|
|
2529
|
-
|
|
2530
|
-
|
|
2531
|
-
|
|
2534
|
+
/**
|
|
2535
|
+
* Creates a getter for a property under aliasKey that returns the value under
|
|
2536
|
+
* valueKey. If suppressDeprecatedPropertyWarnings is not enabled, the
|
|
2537
|
+
* getter also console warns about the deprecation.
|
|
2538
|
+
*
|
|
2539
|
+
* @see https://github.com/typescript-eslint/typescript-eslint/issues/6469
|
|
2540
|
+
*/
|
|
2541
|
+
#withDeprecatedAliasGetter(node, aliasKey, valueKey, suppressWarnings = false) {
|
|
2542
|
+
let warned = suppressWarnings;
|
|
2543
|
+
Object.defineProperty(node, aliasKey, {
|
|
2544
|
+
configurable: true,
|
|
2545
|
+
get: this.options.suppressDeprecatedPropertyWarnings
|
|
2546
|
+
? () => node[valueKey]
|
|
2547
|
+
: () => {
|
|
2548
|
+
if (!warned) {
|
|
2549
|
+
process.emitWarning(`The '${aliasKey}' property is deprecated on ${node.type} nodes. Use '${valueKey}' instead. See https://typescript-eslint.io/troubleshooting/faqs/general#the-key-property-is-deprecated-on-type-nodes-use-key-instead-warnings.`, 'DeprecationWarning');
|
|
2550
|
+
warned = true;
|
|
2551
|
+
}
|
|
2552
|
+
return node[valueKey];
|
|
2553
|
+
},
|
|
2554
|
+
set(value) {
|
|
2555
|
+
Object.defineProperty(node, aliasKey, {
|
|
2556
|
+
enumerable: true,
|
|
2557
|
+
writable: true,
|
|
2558
|
+
value,
|
|
2559
|
+
});
|
|
2532
2560
|
},
|
|
2533
|
-
|
|
2534
|
-
|
|
2535
|
-
|
|
2536
|
-
|
|
2537
|
-
|
|
2538
|
-
|
|
2539
|
-
|
|
2540
|
-
|
|
2541
|
-
|
|
2542
|
-
|
|
2543
|
-
|
|
2544
|
-
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
|
|
2551
|
-
|
|
2552
|
-
|
|
2553
|
-
|
|
2561
|
+
});
|
|
2562
|
+
return node;
|
|
2563
|
+
}
|
|
2564
|
+
#withDeprecatedGetter(node, deprecatedKey, preferredKey, value) {
|
|
2565
|
+
let warned = false;
|
|
2566
|
+
Object.defineProperty(node, deprecatedKey, {
|
|
2567
|
+
configurable: true,
|
|
2568
|
+
get: this.options.suppressDeprecatedPropertyWarnings
|
|
2569
|
+
? () => value
|
|
2570
|
+
: () => {
|
|
2571
|
+
if (!warned) {
|
|
2572
|
+
process.emitWarning(`The '${deprecatedKey}' property is deprecated on ${node.type} nodes. Use ${preferredKey} instead. See https://typescript-eslint.io/troubleshooting/faqs/general#the-key-property-is-deprecated-on-type-nodes-use-key-instead-warnings.`, 'DeprecationWarning');
|
|
2573
|
+
warned = true;
|
|
2574
|
+
}
|
|
2575
|
+
return value;
|
|
2576
|
+
},
|
|
2577
|
+
set(value) {
|
|
2578
|
+
Object.defineProperty(node, deprecatedKey, {
|
|
2579
|
+
enumerable: true,
|
|
2580
|
+
writable: true,
|
|
2581
|
+
value,
|
|
2582
|
+
});
|
|
2554
2583
|
},
|
|
2555
|
-
|
|
2556
|
-
|
|
2557
|
-
enumerable: true,
|
|
2558
|
-
writable: true,
|
|
2559
|
-
value,
|
|
2560
|
-
});
|
|
2561
|
-
},
|
|
2562
|
-
});
|
|
2563
|
-
return node;
|
|
2564
|
-
}, _Converter_throwError = function _Converter_throwError(node, message) {
|
|
2565
|
-
let start;
|
|
2566
|
-
let end;
|
|
2567
|
-
if (typeof node === 'number') {
|
|
2568
|
-
start = end = node;
|
|
2584
|
+
});
|
|
2585
|
+
return node;
|
|
2569
2586
|
}
|
|
2570
|
-
|
|
2571
|
-
start
|
|
2572
|
-
end
|
|
2587
|
+
#throwError(node, message) {
|
|
2588
|
+
let start;
|
|
2589
|
+
let end;
|
|
2590
|
+
if (typeof node === 'number') {
|
|
2591
|
+
start = end = node;
|
|
2592
|
+
}
|
|
2593
|
+
else {
|
|
2594
|
+
start = node.getStart(this.ast);
|
|
2595
|
+
end = node.getEnd();
|
|
2596
|
+
}
|
|
2597
|
+
throw (0, node_utils_1.createError)(message, this.ast, start, end);
|
|
2573
2598
|
}
|
|
2574
|
-
|
|
2575
|
-
|
|
2576
|
-
|
|
2577
|
-
|
|
2578
|
-
|
|
2599
|
+
#checkForStatementDeclaration(initializer) {
|
|
2600
|
+
if (ts.isVariableDeclarationList(initializer)) {
|
|
2601
|
+
if ((initializer.flags & ts.NodeFlags.Using) !== 0) {
|
|
2602
|
+
this.#throwError(initializer, "The left-hand side of a 'for...in' statement cannot be a 'using' declaration.");
|
|
2603
|
+
}
|
|
2579
2604
|
}
|
|
2580
2605
|
}
|
|
2581
|
-
}
|
|
2606
|
+
}
|
|
2607
|
+
exports.Converter = Converter;
|
|
2582
2608
|
//# sourceMappingURL=convert.js.map
|