tsc-ts 0.0.10 → 0.1.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/README.md +1 -1
- package/bin/tsc-ts.js +70 -1
- package/dist/api/compiler/ast-utilities.d.ts +19 -1
- package/dist/api/compiler/ast-utilities.js +180 -95
- package/dist/api/compiler/ast.d.ts +20 -15
- package/dist/api/compiler/ast.js +1023 -995
- package/dist/api/compiler/astnav.js +15 -15
- package/dist/api/compiler/binder-utilities.js +186 -186
- package/dist/api/compiler/binder.js +290 -263
- package/dist/api/compiler/character-codes.js +2 -2
- package/dist/api/compiler/checker-calls.js +173 -123
- package/dist/api/compiler/checker-classes.d.ts +14 -3
- package/dist/api/compiler/checker-classes.js +134 -90
- package/dist/api/compiler/checker-contextual.js +64 -61
- package/dist/api/compiler/checker-declaration-order.js +79 -79
- package/dist/api/compiler/checker-declarations.d.ts +1 -0
- package/dist/api/compiler/checker-declarations.js +160 -136
- package/dist/api/compiler/checker-declared-types.js +67 -65
- package/dist/api/compiler/checker-decorators.js +77 -77
- package/dist/api/compiler/checker-deprecation.d.ts +8 -3
- package/dist/api/compiler/checker-deprecation.js +76 -55
- package/dist/api/compiler/checker-destructuring.js +47 -45
- package/dist/api/compiler/checker-elaboration.js +24 -24
- package/dist/api/compiler/checker-emit-helpers.js +4 -4
- package/dist/api/compiler/checker-emit-resolver.d.ts +4 -2
- package/dist/api/compiler/checker-emit-resolver.js +25 -13
- package/dist/api/compiler/checker-evaluator.js +9 -9
- package/dist/api/compiler/checker-expressions.js +244 -211
- package/dist/api/compiler/checker-functions.js +113 -107
- package/dist/api/compiler/checker-generated-code.d.ts +0 -11
- package/dist/api/compiler/checker-generated-code.js +28 -52
- package/dist/api/compiler/checker-grammar.d.ts +1 -0
- package/dist/api/compiler/checker-grammar.js +469 -438
- package/dist/api/compiler/checker-heritage.js +91 -93
- package/dist/api/compiler/checker-inference.d.ts +77 -5
- package/dist/api/compiler/checker-inference.js +487 -113
- package/dist/api/compiler/checker-iteration.d.ts +0 -10
- package/dist/api/compiler/checker-iteration.js +35 -52
- package/dist/api/compiler/checker-javascript.js +14 -14
- package/dist/api/compiler/checker-jsdoc.d.ts +8 -10
- package/dist/api/compiler/checker-jsdoc.js +67 -58
- package/dist/api/compiler/checker-jsx.js +105 -88
- package/dist/api/compiler/checker-members.d.ts +9 -2
- package/dist/api/compiler/checker-members.js +210 -74
- package/dist/api/compiler/checker-modules.d.ts +15 -6
- package/dist/api/compiler/checker-modules.js +469 -309
- package/dist/api/compiler/checker-narrowing.js +273 -189
- package/dist/api/compiler/checker-object-literals.js +25 -22
- package/dist/api/compiler/checker-operators.js +126 -118
- package/dist/api/compiler/checker-overloads.js +27 -27
- package/dist/api/compiler/checker-property-access.js +59 -55
- package/dist/api/compiler/checker-services.d.ts +1 -0
- package/dist/api/compiler/checker-services.js +222 -210
- package/dist/api/compiler/checker-signatures.js +65 -49
- package/dist/api/compiler/checker-source-file.d.ts +5 -0
- package/dist/api/compiler/checker-source-file.js +154 -130
- package/dist/api/compiler/checker-statements.js +33 -32
- package/dist/api/compiler/checker-super.js +50 -50
- package/dist/api/compiler/checker-symbol-types.js +109 -93
- package/dist/api/compiler/checker-symbols.d.ts +13 -1
- package/dist/api/compiler/checker-symbols.js +264 -149
- package/dist/api/compiler/checker-type-factory.d.ts +5 -0
- package/dist/api/compiler/checker-type-factory.js +137 -34
- package/dist/api/compiler/checker-type-nodes.d.ts +1 -0
- package/dist/api/compiler/checker-type-nodes.js +179 -141
- package/dist/api/compiler/checker-type-operators.d.ts +2 -0
- package/dist/api/compiler/checker-type-operators.js +110 -63
- package/dist/api/compiler/checker-types.d.ts +80 -3
- package/dist/api/compiler/checker-types.js +121 -2
- package/dist/api/compiler/checker-unused.js +114 -118
- package/dist/api/compiler/checker-utilities.js +11 -11
- package/dist/api/compiler/checker.d.ts +93 -31
- package/dist/api/compiler/checker.js +143 -35
- package/dist/api/compiler/command-line.d.ts +1 -3
- package/dist/api/compiler/command-line.js +47 -44
- package/dist/api/compiler/compile-program.d.ts +19 -4
- package/dist/api/compiler/compile-program.js +45 -26
- package/dist/api/compiler/diagnostic-messages.d.ts +1849 -1774
- package/dist/api/compiler/diagnostic-messages.js +128 -122
- package/dist/api/compiler/diagnostics.js +7 -7
- package/dist/api/compiler/emitter.d.ts +7 -1
- package/dist/api/compiler/emitter.js +53 -11
- package/dist/api/compiler/file-include.d.ts +2 -1
- package/dist/api/compiler/file-include.js +11 -7
- package/dist/api/compiler/file-loader.d.ts +10 -0
- package/dist/api/compiler/file-loader.js +138 -41
- package/dist/api/compiler/instantiation.d.ts +7 -0
- package/dist/api/compiler/instantiation.js +101 -49
- package/dist/api/compiler/jsdoc.js +23 -23
- package/dist/api/compiler/link-tables.d.ts +48 -18
- package/dist/api/compiler/link-tables.js +80 -37
- package/dist/api/compiler/locales/cs-CZ.d.ts +1 -1
- package/dist/api/compiler/locales/cs-CZ.js +1 -1
- package/dist/api/compiler/locales/de-DE.d.ts +1 -1
- package/dist/api/compiler/locales/de-DE.js +1 -1
- package/dist/api/compiler/locales/es-ES.d.ts +1 -1
- package/dist/api/compiler/locales/es-ES.js +1 -1
- package/dist/api/compiler/locales/fr-FR.d.ts +1 -1
- package/dist/api/compiler/locales/fr-FR.js +1 -1
- package/dist/api/compiler/locales/it-IT.d.ts +1 -1
- package/dist/api/compiler/locales/it-IT.js +1 -1
- package/dist/api/compiler/locales/ja-JP.d.ts +1 -1
- package/dist/api/compiler/locales/ja-JP.js +1 -1
- package/dist/api/compiler/locales/ko-KR.d.ts +1 -1
- package/dist/api/compiler/locales/ko-KR.js +1 -1
- package/dist/api/compiler/locales/pl-PL.d.ts +1 -1
- package/dist/api/compiler/locales/pl-PL.js +1 -1
- package/dist/api/compiler/locales/pt-BR.d.ts +1 -1
- package/dist/api/compiler/locales/pt-BR.js +1 -1
- package/dist/api/compiler/locales/ru-RU.d.ts +1 -1
- package/dist/api/compiler/locales/ru-RU.js +1 -1
- package/dist/api/compiler/locales/tr-TR.d.ts +1 -1
- package/dist/api/compiler/locales/tr-TR.js +1 -1
- package/dist/api/compiler/locales/zh-CN.d.ts +1 -1
- package/dist/api/compiler/locales/zh-CN.js +1 -1
- package/dist/api/compiler/locales/zh-TW.d.ts +1 -1
- package/dist/api/compiler/locales/zh-TW.js +1 -1
- package/dist/api/compiler/module-resolution-types.js +6 -6
- package/dist/api/compiler/module-resolution.d.ts +10 -1
- package/dist/api/compiler/module-resolution.js +115 -84
- package/dist/api/compiler/module-specifiers.d.ts +15 -0
- package/dist/api/compiler/module-specifiers.js +24 -18
- package/dist/api/compiler/name-resolver.js +74 -65
- package/dist/api/compiler/node-builder-names.d.ts +11 -3
- package/dist/api/compiler/node-builder-names.js +210 -90
- package/dist/api/compiler/node-builder-pseudo.js +29 -31
- package/dist/api/compiler/node-builder-reuse.js +23 -22
- package/dist/api/compiler/node-builder.d.ts +18 -1
- package/dist/api/compiler/node-builder.js +191 -102
- package/dist/api/compiler/option-declarations.d.ts +2 -6
- package/dist/api/compiler/option-declarations.js +315 -375
- package/dist/api/compiler/options.d.ts +15 -33
- package/dist/api/compiler/options.js +21 -54
- package/dist/api/compiler/output-paths.d.ts +4 -1
- package/dist/api/compiler/output-paths.js +6 -11
- package/dist/api/compiler/package-json.d.ts +3 -3
- package/dist/api/compiler/package-json.js +11 -10
- package/dist/api/compiler/parser.d.ts +40 -19
- package/dist/api/compiler/parser.js +308 -216
- package/dist/api/compiler/path.d.ts +9 -0
- package/dist/api/compiler/path.js +20 -3
- package/dist/api/compiler/printer/emit-context.d.ts +3 -1
- package/dist/api/compiler/printer/emit-context.js +16 -1
- package/dist/api/compiler/printer/factory-base.d.ts +2 -2
- package/dist/api/compiler/printer/factory-base.js +7 -3
- package/dist/api/compiler/printer/factory.js +3 -1
- package/dist/api/compiler/printer/helpers.js +10 -1
- package/dist/api/compiler/printer/name-generator.d.ts +1 -1
- package/dist/api/compiler/printer/name-generator.js +35 -16
- package/dist/api/compiler/printer/printer.d.ts +1 -0
- package/dist/api/compiler/printer/printer.js +303 -281
- package/dist/api/compiler/printer/utilities.js +149 -147
- package/dist/api/compiler/program-checker.d.ts +8 -2
- package/dist/api/compiler/program-checker.js +84 -34
- package/dist/api/compiler/program-utilities.d.ts +3 -1
- package/dist/api/compiler/program-utilities.js +28 -15
- package/dist/api/compiler/program.d.ts +2 -0
- package/dist/api/compiler/program.js +69 -57
- package/dist/api/compiler/pseudo-bigint.d.ts +2 -0
- package/dist/api/compiler/pseudo-bigint.js +18 -0
- package/dist/api/compiler/regexp-checker.d.ts +1 -1
- package/dist/api/compiler/regexp-checker.js +93 -76
- package/dist/api/compiler/relations.d.ts +27 -4
- package/dist/api/compiler/relations.js +337 -180
- package/dist/api/compiler/reparser.js +60 -56
- package/dist/api/compiler/scanner.d.ts +19 -2
- package/dist/api/compiler/scanner.js +123 -108
- package/dist/api/compiler/shared-results.d.ts +463 -0
- package/dist/api/compiler/shared-results.js +2128 -0
- package/dist/api/compiler/sourcemap.js +2 -2
- package/dist/api/compiler/symbol-accessibility.js +87 -74
- package/dist/api/compiler/symbol.d.ts +22 -13
- package/dist/api/compiler/symbol.js +15 -1
- package/dist/api/compiler/syntax-kind.d.ts +198 -197
- package/dist/api/compiler/transformers/alias-references.js +247 -139
- package/dist/api/compiler/transformers/async-utilities.js +25 -25
- package/dist/api/compiler/transformers/async.d.ts +0 -1
- package/dist/api/compiler/transformers/async.js +64 -77
- package/dist/api/compiler/transformers/class-fields.d.ts +1 -0
- package/dist/api/compiler/transformers/class-fields.js +81 -78
- package/dist/api/compiler/transformers/commonjs-module.js +18 -15
- package/dist/api/compiler/transformers/const-enum-inliner.js +1 -1
- package/dist/api/compiler/transformers/declarations-diagnostics.js +247 -244
- package/dist/api/compiler/transformers/declarations-pseudo.js +100 -100
- package/dist/api/compiler/transformers/declarations-resolver.d.ts +0 -3
- package/dist/api/compiler/transformers/declarations-syntactic.d.ts +1 -2
- package/dist/api/compiler/transformers/declarations-syntactic.js +134 -156
- package/dist/api/compiler/transformers/declarations-tracker.js +18 -18
- package/dist/api/compiler/transformers/declarations.d.ts +4 -1
- package/dist/api/compiler/transformers/declarations.js +305 -238
- package/dist/api/compiler/transformers/decorator-metadata.d.ts +1 -1
- package/dist/api/compiler/transformers/decorator-metadata.js +53 -45
- package/dist/api/compiler/transformers/decorator-utilities.js +24 -24
- package/dist/api/compiler/transformers/destructuring.js +19 -18
- package/dist/api/compiler/transformers/emit-resolver.js +1 -1
- package/dist/api/compiler/transformers/es-decorators.js +55 -55
- package/dist/api/compiler/transformers/external-module-info.js +3 -3
- package/dist/api/compiler/transformers/for-await.js +25 -25
- package/dist/api/compiler/transformers/import-elision.js +14 -14
- package/dist/api/compiler/transformers/jsx.js +12 -12
- package/dist/api/compiler/transformers/legacy-decorators.js +17 -17
- package/dist/api/compiler/transformers/module.js +8 -8
- package/dist/api/compiler/transformers/named-evaluation.js +4 -4
- package/dist/api/compiler/transformers/object-rest-spread.js +20 -20
- package/dist/api/compiler/transformers/optional-chain.js +10 -10
- package/dist/api/compiler/transformers/reference-resolver.d.ts +12 -1
- package/dist/api/compiler/transformers/reference-resolver.js +131 -69
- package/dist/api/compiler/transformers/runtime-syntax.js +35 -31
- package/dist/api/compiler/transformers/subtree-facts.js +47 -47
- package/dist/api/compiler/transformers/syntax-facts.js +56 -58
- package/dist/api/compiler/transformers/type-eraser.js +73 -66
- package/dist/api/compiler/transformers/type-serialization.js +24 -24
- package/dist/api/compiler/transformers/using.js +12 -12
- package/dist/api/compiler/transformers/utilities.js +77 -77
- package/dist/api/compiler/transformers/visitor-base.js +172 -172
- package/dist/api/compiler/transformers/visitor-hooks.js +6 -2
- package/dist/api/compiler/tsconfig.d.ts +10 -2
- package/dist/api/compiler/tsconfig.js +136 -48
- package/dist/api/compiler/type-printer.js +40 -3
- package/dist/api/compiler/types.d.ts +2 -1
- package/dist/api/library/ast.generated.d.ts +42 -39
- package/dist/api/library/ast.generated.js +1 -1
- package/dist/api/library/compiler-options.generated.d.ts +111 -100
- package/dist/api/library/compiler-options.generated.js +1 -1
- package/dist/api/library/disk.js +12 -1
- package/dist/api/library/enums.generated.d.ts +206 -206
- package/dist/api/library/enums.generated.js +206 -206
- package/dist/api/library/nodes.js +26 -26
- package/package.json +9 -9
- package/src/compiler/ast-utilities.ts +99 -7
- package/src/compiler/ast.ts +55 -26
- package/src/compiler/binder.ts +39 -4
- package/src/compiler/character-codes.ts +2 -2
- package/src/compiler/checker-calls.ts +76 -8
- package/src/compiler/checker-classes.ts +78 -24
- package/src/compiler/checker-contextual.ts +6 -1
- package/src/compiler/checker-declarations.ts +31 -4
- package/src/compiler/checker-declared-types.ts +8 -5
- package/src/compiler/checker-decorators.ts +1 -1
- package/src/compiler/checker-deprecation.ts +29 -8
- package/src/compiler/checker-destructuring.ts +10 -3
- package/src/compiler/checker-emit-helpers.ts +1 -0
- package/src/compiler/checker-emit-resolver.ts +16 -6
- package/src/compiler/checker-expressions.ts +79 -46
- package/src/compiler/checker-functions.ts +21 -6
- package/src/compiler/checker-generated-code.ts +2 -22
- package/src/compiler/checker-grammar.ts +133 -60
- package/src/compiler/checker-heritage.ts +22 -21
- package/src/compiler/checker-inference.ts +514 -87
- package/src/compiler/checker-iteration.ts +18 -31
- package/src/compiler/checker-javascript.ts +1 -1
- package/src/compiler/checker-jsdoc.ts +50 -27
- package/src/compiler/checker-jsx.ts +26 -4
- package/src/compiler/checker-members.ts +197 -55
- package/src/compiler/checker-modules.ts +332 -65
- package/src/compiler/checker-narrowing.ts +98 -19
- package/src/compiler/checker-object-literals.ts +3 -0
- package/src/compiler/checker-operators.ts +11 -4
- package/src/compiler/checker-property-access.ts +7 -2
- package/src/compiler/checker-services.ts +39 -12
- package/src/compiler/checker-signatures.ts +15 -1
- package/src/compiler/checker-source-file.ts +39 -13
- package/src/compiler/checker-statements.ts +3 -2
- package/src/compiler/checker-symbol-types.ts +29 -6
- package/src/compiler/checker-symbols.ts +158 -15
- package/src/compiler/checker-type-factory.ts +120 -21
- package/src/compiler/checker-type-nodes.ts +46 -3
- package/src/compiler/checker-type-operators.ts +83 -26
- package/src/compiler/checker-types.ts +147 -4
- package/src/compiler/checker-unused.ts +9 -14
- package/src/compiler/checker.ts +168 -41
- package/src/compiler/command-line.ts +28 -28
- package/src/compiler/compile-program.ts +51 -25
- package/src/compiler/decoder.ts +13 -4
- package/src/compiler/diagnostic-messages.ts +1973 -1892
- package/src/compiler/emitter.ts +57 -8
- package/src/compiler/encoder.ts +23 -8
- package/src/compiler/file-include.ts +9 -3
- package/src/compiler/file-loader.ts +139 -32
- package/src/compiler/help.ts +10 -14
- package/src/compiler/incremental.ts +86 -18
- package/src/compiler/init.ts +2 -7
- package/src/compiler/instantiation.ts +77 -22
- package/src/compiler/jsdoc.ts +3 -1
- package/src/compiler/link-tables.ts +82 -37
- package/src/compiler/locales/cs-CZ.ts +1 -1
- package/src/compiler/locales/de-DE.ts +1 -1
- package/src/compiler/locales/es-ES.ts +1 -1
- package/src/compiler/locales/fr-FR.ts +1 -1
- package/src/compiler/locales/it-IT.ts +1 -1
- package/src/compiler/locales/ja-JP.ts +1 -1
- package/src/compiler/locales/ko-KR.ts +1 -1
- package/src/compiler/locales/pl-PL.ts +1 -1
- package/src/compiler/locales/pt-BR.ts +1 -1
- package/src/compiler/locales/ru-RU.ts +1 -1
- package/src/compiler/locales/tr-TR.ts +1 -1
- package/src/compiler/locales/zh-CN.ts +1 -1
- package/src/compiler/locales/zh-TW.ts +1 -1
- package/src/compiler/module-resolution.ts +44 -8
- package/src/compiler/module-specifiers.ts +62 -20
- package/src/compiler/name-resolver.ts +9 -1
- package/src/compiler/node-builder-names.ts +236 -54
- package/src/compiler/node-builder-pseudo.ts +4 -7
- package/src/compiler/node-builder-reuse.ts +5 -4
- package/src/compiler/node-builder.ts +130 -31
- package/src/compiler/option-declarations.ts +33 -103
- package/src/compiler/options.ts +23 -62
- package/src/compiler/output-paths.ts +5 -18
- package/src/compiler/package-entrypoints.ts +345 -0
- package/src/compiler/package-json.ts +4 -4
- package/src/compiler/parallel-check.ts +197 -8
- package/src/compiler/parallel-emit.ts +1 -1
- package/src/compiler/parser.ts +156 -39
- package/src/compiler/path.ts +22 -2
- package/src/compiler/printer/emit-context.ts +16 -0
- package/src/compiler/printer/factory-base.ts +10 -3
- package/src/compiler/printer/factory.ts +4 -1
- package/src/compiler/printer/helpers.ts +10 -1
- package/src/compiler/printer/name-generator.ts +24 -2
- package/src/compiler/printer/printer.ts +35 -14
- package/src/compiler/printer/utilities.ts +8 -2
- package/src/compiler/program-checker.ts +53 -5
- package/src/compiler/program-utilities.ts +23 -10
- package/src/compiler/program.ts +13 -1
- package/src/compiler/pseudo-bigint.ts +17 -0
- package/src/compiler/regexp-checker.ts +63 -30
- package/src/compiler/relations.ts +233 -77
- package/src/compiler/reparser.ts +7 -2
- package/src/compiler/scanner.ts +109 -79
- package/src/compiler/shared-results.ts +2414 -0
- package/src/compiler/show-config.ts +18 -1
- package/src/compiler/sourcemap.ts +2 -2
- package/src/compiler/symbol-accessibility.ts +26 -3
- package/src/compiler/symbol.ts +31 -14
- package/src/compiler/syntax-kind.ts +188 -187
- package/src/compiler/thread-entry.ts +19 -2
- package/src/compiler/transformers/alias-references.ts +123 -4
- package/src/compiler/transformers/async.ts +2 -17
- package/src/compiler/transformers/class-fields.ts +13 -12
- package/src/compiler/transformers/commonjs-module.ts +11 -7
- package/src/compiler/transformers/declarations-diagnostics.ts +5 -3
- package/src/compiler/transformers/declarations-pseudo.ts +2 -4
- package/src/compiler/transformers/declarations-resolver.ts +0 -3
- package/src/compiler/transformers/declarations-syntactic.ts +1 -21
- package/src/compiler/transformers/declarations.ts +134 -48
- package/src/compiler/transformers/decorator-metadata.ts +9 -1
- package/src/compiler/transformers/destructuring.ts +4 -3
- package/src/compiler/transformers/external-module-info.ts +1 -1
- package/src/compiler/transformers/jsx.ts +2 -1
- package/src/compiler/transformers/reference-resolver.ts +83 -19
- package/src/compiler/transformers/runtime-syntax.ts +6 -1
- package/src/compiler/transformers/syntax-facts.ts +2 -7
- package/src/compiler/transformers/type-eraser.ts +10 -1
- package/src/compiler/transformers/type-serialization.ts +3 -2
- package/src/compiler/transformers/visitor-base.ts +2 -1
- package/src/compiler/transformers/visitor-hooks.ts +9 -4
- package/src/compiler/tsc-build.ts +3 -0
- package/src/compiler/tsc-cli.ts +2 -0
- package/src/compiler/tsc-compile.ts +7 -2
- package/src/compiler/tsc-watch.ts +74 -45
- package/src/compiler/tsconfig.ts +176 -19
- package/src/compiler/type-printer.ts +36 -2
- package/src/compiler/types.ts +2 -1
- package/src/library/ast.generated.ts +57 -41
- package/src/library/compiler-options.generated.ts +117 -103
- package/src/library/disk.ts +10 -1
- package/src/library/enums.generated.ts +196 -196
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// The TypeScript/JavaScript/JSX/JSON parser, a port of TypeScript 7.
|
|
1
|
+
// The TypeScript/JavaScript/JSX/JSON parser, a port of TypeScript 7.1's (tsgo) parser with its
|
|
2
2
|
// error recovery, parse diagnostics and JavaScript-specific reparsing.
|
|
3
3
|
//
|
|
4
4
|
// ```ts
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
// for (const statement of file.statements.nodes) console.log(statement.kind);
|
|
7
7
|
// ```
|
|
8
8
|
import { appendToList, ArrayLiteralExpression, ArrayTypeNode, ArrowFunction, AsExpression, AwaitExpression, BigIntLiteral, BinaryExpression, BindingElement, BindingPattern, Block, BreakStatement, CallExpression, CallSignatureDeclaration, CaseBlock, CaseOrDefaultClause, CatchClause, CheckJsDirective, ClassDeclaration, ClassExpression, ClassStaticBlockDeclaration, ComputedPropertyName, ConditionalExpression, ConditionalTypeNode, ConstructSignatureDeclaration, ConstructorDeclaration, ConstructorTypeNode, ContinueStatement, DebuggerStatement, Decorator, DeleteExpression, DoStatement, ElementAccessExpression, emptyCommentDirectives, emptyDiagnostics, emptyFileReferences, emptyNodes, emptyPragmas, EmptyStatement, EnumDeclaration, EnumMember, ExportAssignment, ExportDeclaration, ExportSpecifier, ExpressionStatement, ExpressionWithTypeArguments, ExternalModuleIndicatorOptions, ExternalModuleReference, FileReference, ForInOrOfStatement, ForStatement, FunctionDeclaration, FunctionExpression, FunctionTypeNode, GetAccessorDeclaration, HeritageClause, Identifier, IfStatement, ImportAttribute, ImportAttributes, ImportClause, ImportDeclaration, ImportEqualsDeclaration, ImportSpecifier, ImportTypeNode, IndexSignatureDeclaration, IndexedAccessTypeNode, InferTypeNode, InterfaceDeclaration, IntersectionTypeNode, JSDocAllType, JSDocNonNullableType, JSDocNullableType, JSDocOptionalType, JSDocVariadicType, JsxAttribute, JsxAttributes, JsxClosingElement, JsxClosingFragment, JsxElement, JsxExpression, JsxFragment, JsxNamespacedName, JsxOpeningElement, JsxOpeningFragment, JsxSelfClosingElement, JsxSpreadAttribute, JsxText, KeywordExpression, KeywordTypeNode, LabeledStatement, LiteralTypeNode, MappedTypeNode, MetaProperty, MethodDeclaration, MethodSignatureDeclaration, MissingDeclaration, MissingNodeList, ModifierList, ModuleBlock, ModuleDeclaration, NamedExports, NamedImports, NamedTupleMember, NamespaceExport, NamespaceExportDeclaration, NamespaceImport, NewExpression, NoSubstitutionTemplateLiteral, NodeList, NodeVisitor, NonNullExpression, NumericLiteral, ObjectLiteralExpression, OmittedExpression, OptionalTypeNode, ParameterDeclaration, ParenthesizedExpression, ParenthesizedTypeNode, PostfixUnaryExpression, Pragma, PragmaArgument, PrefixUnaryExpression, PrivateIdentifier, PropertyAccessExpression, PropertyAssignment, PropertyDeclaration, PropertySignatureDeclaration, QualifiedName, ReferenceIdentifier, RegularExpressionLiteral, RestTypeNode, ReturnStatement, SatisfiesExpression, SemicolonClassElement, SetAccessorDeclaration, ShorthandPropertyAssignment, SourceFile, SpreadAssignment, SpreadElement, StringLiteral, SwitchStatement, TaggedTemplateExpression, TemplateExpression, TemplateHead, TemplateLiteralTypeNode, TemplateLiteralTypeSpan, TemplateMiddle, TemplateSpan, TemplateTail, ThisTypeNode, ThrowStatement, Token, TryStatement, TupleTypeNode, TypeAliasDeclaration, TypeAssertion, TypeLiteralNode, TypeOfExpression, TypeOperatorNode, TypeParameterDeclaration, TypePredicateNode, TypeQueryNode, TypeReferenceNode, UnionTypeNode, VariableDeclaration, VariableDeclarationList, VariableStatement, VoidExpression, WhileStatement, WithStatement, YieldExpression, getBody, getIsTypeOnly, getModifiers, getName, getPostfixToken, getQuestionToken, getStatements, getText, getType, getTypeArguments, getTypeParameters, newCallExpression, newPropertyAssignment, } from './ast.js';
|
|
9
|
-
import { canHaveDecorators, canHaveIllegalDecorators, compareNodePositions, getBinaryOperatorPrecedence, getExternalModuleName, getImportTypeNodeLiteral, getTextOfNodeFromSourceText, isAmbientModule, isAnyImportOrReExport, isAssignmentOperator, isClassMemberModifier, isFunctionLike, isImportCall, isImportMeta, isInJSFile, isKeyword, isKeywordOrPunctuation, isLeftHandSideExpression, isModifierKind, isRequireCall, isReservedWord, isStringLiteralLike, modifierToFlag, modifiersToFlags, nodeIsMissing, nodeIsPresent, tagNamesAreEquivalent, tokenIsIdentifierOrKeyword, tokenIsIdentifierOrKeywordOrGreaterThan, } from './ast-utilities.js';
|
|
9
|
+
import { canHaveDecorators, canHaveIllegalDecorators, compareNodePositions, getBinaryOperatorPrecedence, getExternalModuleName, getImportTypeNodeLiteral, getTextOfNodeFromSourceText, isAmbientModule, isAnyImportOrReExport, isAssignmentOperator, isClassMemberModifier, isFunctionLike, isImportCall, isImportMeta, isImportPhaseMetaProperty, isInJSFile, isKeyword, isKeywordOrPunctuation, isLeftHandSideExpression, isModifierKind, isRequireCall, isReservedWord, isStringLiteralLike, modifierToFlag, modifiersToFlags, nodeIsMissing, nodeIsPresent, tagNamesAreEquivalent, tokenIsIdentifierOrKeyword, tokenIsIdentifierOrKeywordOrGreaterThan, } from './ast-utilities.js';
|
|
10
10
|
import { isLineBreak } from './character-codes.js';
|
|
11
11
|
import { Diagnostic, messageCode } from './diagnostics.js';
|
|
12
12
|
import { JSDocParser } from './jsdoc.js';
|
|
@@ -15,6 +15,11 @@ import { isDeclarationFileName, isExternalModuleNameRelative } from './path.js';
|
|
|
15
15
|
import { Scanner, ScannerErrorReporter, ScannerState, getLeadingCommentRanges, getViableKeywordSuggestions, skipTrivia, tokenToString, } from './scanner.js';
|
|
16
16
|
import { getSpellingSuggestion } from './spelling.js';
|
|
17
17
|
const noArgs = [];
|
|
18
|
+
/** Whether `operator` binds before an operator of `currentPrecedence`: at equal precedence, only the right-associative `**`. */
|
|
19
|
+
function shouldConsumeBinaryOperator(operator, operatorPrecedence, currentPrecedence) {
|
|
20
|
+
return (operatorPrecedence > currentPrecedence ||
|
|
21
|
+
(operatorPrecedence === currentPrecedence && operator === 42 /* SyntaxKind.AsteriskAsteriskToken */));
|
|
22
|
+
}
|
|
18
23
|
/** Parser state saved by `mark` for speculative parsing. */
|
|
19
24
|
export class ParserState extends ScannerState {
|
|
20
25
|
contextFlags;
|
|
@@ -80,7 +85,7 @@ export function parseSourceFile(fileName, text, options) {
|
|
|
80
85
|
export function parseIsolatedEntityName(text) {
|
|
81
86
|
const p = new Parser('/', '/', text, 1 /* ScriptKind.JS */, new ExternalModuleIndicatorOptions(false, false));
|
|
82
87
|
p.nextToken();
|
|
83
|
-
const entityName = p.parseEntityName(true, undefined);
|
|
88
|
+
const entityName = p.parseEntityName(true, false, undefined);
|
|
84
89
|
return p.token() === 1 /* SyntaxKind.EndOfFile */ && p.diagnostics.length === 0 ? entityName : undefined;
|
|
85
90
|
}
|
|
86
91
|
export function getScriptKindFromFileName(fileName) {
|
|
@@ -570,40 +575,44 @@ export class Parser extends ScannerErrorReporter {
|
|
|
570
575
|
case 7 /* ListElement.ClassElement */:
|
|
571
576
|
return this.parseClassElement();
|
|
572
577
|
case 8 /* ListElement.HeritageClause */:
|
|
573
|
-
return this.parseHeritageClause();
|
|
574
|
-
case 9 /* ListElement.
|
|
578
|
+
return this.parseHeritageClause(false);
|
|
579
|
+
case 9 /* ListElement.InterfaceHeritageClause */:
|
|
580
|
+
return this.parseHeritageClause(true);
|
|
581
|
+
case 10 /* ListElement.ExpressionWithTypeArguments */:
|
|
575
582
|
return this.parseExpressionWithTypeArguments();
|
|
576
|
-
case
|
|
583
|
+
case 11 /* ListElement.TypeHeritageClauseElement */:
|
|
584
|
+
return this.parseTypeHeritageClauseElement();
|
|
585
|
+
case 12 /* ListElement.EnumMember */:
|
|
577
586
|
return this.parseEnumMember();
|
|
578
|
-
case
|
|
587
|
+
case 13 /* ListElement.ImportSpecifier */:
|
|
579
588
|
return this.parseImportSpecifier();
|
|
580
|
-
case
|
|
589
|
+
case 14 /* ListElement.ExportSpecifier */:
|
|
581
590
|
return this.parseExportSpecifier();
|
|
582
|
-
case
|
|
591
|
+
case 15 /* ListElement.Type */:
|
|
583
592
|
return this.parseType();
|
|
584
|
-
case
|
|
593
|
+
case 16 /* ListElement.ImportAttribute */:
|
|
585
594
|
return this.parseImportAttribute();
|
|
586
|
-
case
|
|
595
|
+
case 17 /* ListElement.TypeMember */:
|
|
587
596
|
return this.parseTypeMember();
|
|
588
|
-
case
|
|
597
|
+
case 18 /* ListElement.TypeParameter */:
|
|
589
598
|
return this.parseTypeParameter();
|
|
590
|
-
case
|
|
599
|
+
case 19 /* ListElement.Parameter */:
|
|
591
600
|
return this.parseParameter();
|
|
592
|
-
case
|
|
601
|
+
case 20 /* ListElement.SignatureParameter */: {
|
|
593
602
|
const parameter = this.parseParameterEx(this.signatureParameterInAwaitContext, this.signatureParameterAllowAmbiguity);
|
|
594
603
|
if (parameter !== this.noElement && (this.signatureParameterFlags & 4 /* ParseFlags.Type */) === 0)
|
|
595
604
|
this.checkJSSyntax(parameter);
|
|
596
605
|
return parameter;
|
|
597
606
|
}
|
|
598
|
-
case
|
|
607
|
+
case 21 /* ListElement.TupleElement */:
|
|
599
608
|
return this.parseTupleElementNameOrTupleElementType();
|
|
600
|
-
case
|
|
609
|
+
case 22 /* ListElement.JsxAttribute */:
|
|
601
610
|
return this.parseJsxAttribute();
|
|
602
|
-
case
|
|
611
|
+
case 23 /* ListElement.ArgumentExpression */:
|
|
603
612
|
return this.parseArgumentExpression();
|
|
604
|
-
case
|
|
613
|
+
case 24 /* ListElement.ArrayLiteralElement */:
|
|
605
614
|
return this.parseArgumentOrArrayLiteralElement();
|
|
606
|
-
case
|
|
615
|
+
case 25 /* ListElement.ObjectLiteralElement */:
|
|
607
616
|
return this.parseObjectLiteralElement();
|
|
608
617
|
}
|
|
609
618
|
}
|
|
@@ -623,7 +632,7 @@ export class Parser extends ScannerErrorReporter {
|
|
|
623
632
|
if (reparseList.length !== 0) {
|
|
624
633
|
for (const e of reparseList) {
|
|
625
634
|
// Propagate @typedef aliases and @import declarations to a context that permits them.
|
|
626
|
-
if ((e.kind ===
|
|
635
|
+
if ((e.kind === 346 /* SyntaxKind.JSTypeAliasDeclaration */ || e.kind === 347 /* SyntaxKind.JSImportDeclaration */) &&
|
|
627
636
|
kind !== 0 /* ParsingContext.SourceElements */ &&
|
|
628
637
|
kind !== 1 /* ParsingContext.BlockStatements */)
|
|
629
638
|
outerReparseList.push(e);
|
|
@@ -831,7 +840,7 @@ export class Parser extends ScannerErrorReporter {
|
|
|
831
840
|
this.parseErrorAtCurrentToken(1 /* Diagnostics.Identifier_expected */);
|
|
832
841
|
break;
|
|
833
842
|
case 24 /* ParsingContext.ImportAttributes */:
|
|
834
|
-
this.parseErrorAtCurrentToken(
|
|
843
|
+
this.parseErrorAtCurrentToken(391 /* Diagnostics.Identifier_or_string_literal_expected */);
|
|
835
844
|
break;
|
|
836
845
|
default:
|
|
837
846
|
throw new Error('Unhandled case in parsingContextErrors');
|
|
@@ -1217,7 +1226,7 @@ export class Parser extends ScannerErrorReporter {
|
|
|
1217
1226
|
this.finishNode(result, pos);
|
|
1218
1227
|
this.withJSDoc(result, jsdoc);
|
|
1219
1228
|
if (this.token() === 63 /* SyntaxKind.EqualsToken */) {
|
|
1220
|
-
this.parseErrorAtCurrentToken(
|
|
1229
|
+
this.parseErrorAtCurrentToken(947 /* Diagnostics.Declaration_or_statement_expected_This_follows_a_block_of_statements_so_if_you_intended_to_write_a_destructuring_assignment_you_might_need_to_wrap_the_whole_assignment_in_parentheses */);
|
|
1221
1230
|
this.nextToken();
|
|
1222
1231
|
}
|
|
1223
1232
|
return result;
|
|
@@ -1309,12 +1318,12 @@ export class Parser extends ScannerErrorReporter {
|
|
|
1309
1318
|
const expression = this.parseAssignmentExpressionOrHigher();
|
|
1310
1319
|
this.contextFlags = saveContextFlags;
|
|
1311
1320
|
this.parseExpected(21 /* SyntaxKind.CloseParenToken */);
|
|
1312
|
-
result = new ForInOrOfStatement(
|
|
1321
|
+
result = new ForInOrOfStatement(252 /* SyntaxKind.ForOfStatement */, awaitToken, initializer, expression, this.parseStatement());
|
|
1313
1322
|
}
|
|
1314
1323
|
else if (this.parseOptional(102 /* SyntaxKind.InKeyword */)) {
|
|
1315
1324
|
const expression = this.parseExpressionAllowIn();
|
|
1316
1325
|
this.parseExpected(21 /* SyntaxKind.CloseParenToken */);
|
|
1317
|
-
result = new ForInOrOfStatement(
|
|
1326
|
+
result = new ForInOrOfStatement(251 /* SyntaxKind.ForInStatement */, undefined, initializer, expression, this.parseStatement());
|
|
1318
1327
|
}
|
|
1319
1328
|
else {
|
|
1320
1329
|
this.parseExpected(26 /* SyntaxKind.SemicolonToken */);
|
|
@@ -1376,7 +1385,7 @@ export class Parser extends ScannerErrorReporter {
|
|
|
1376
1385
|
const expression = this.parseExpressionAllowIn();
|
|
1377
1386
|
this.parseExpected(58 /* SyntaxKind.ColonToken */);
|
|
1378
1387
|
const statements = this.parseList(3 /* ParsingContext.SwitchClauseStatements */, 0 /* ListElement.Statement */);
|
|
1379
|
-
return this.finishWithJSDoc(new CaseOrDefaultClause(
|
|
1388
|
+
return this.finishWithJSDoc(new CaseOrDefaultClause(298 /* SyntaxKind.CaseClause */, expression, statements), pos, jsdoc);
|
|
1380
1389
|
}
|
|
1381
1390
|
parseDefaultClause() {
|
|
1382
1391
|
const pos = this.nodePos();
|
|
@@ -1384,7 +1393,7 @@ export class Parser extends ScannerErrorReporter {
|
|
|
1384
1393
|
this.parseExpected(89 /* SyntaxKind.DefaultKeyword */);
|
|
1385
1394
|
this.parseExpected(58 /* SyntaxKind.ColonToken */);
|
|
1386
1395
|
const statements = this.parseList(3 /* ParsingContext.SwitchClauseStatements */, 0 /* ListElement.Statement */);
|
|
1387
|
-
return this.finishWithJSDoc(new CaseOrDefaultClause(
|
|
1396
|
+
return this.finishWithJSDoc(new CaseOrDefaultClause(299 /* SyntaxKind.DefaultClause */, undefined, statements), pos, jsdoc);
|
|
1388
1397
|
}
|
|
1389
1398
|
parseCaseOrDefaultClause() {
|
|
1390
1399
|
return this.token() === 83 /* SyntaxKind.CaseKeyword */ ? this.parseCaseClause() : this.parseDefaultClause();
|
|
@@ -1430,7 +1439,7 @@ export class Parser extends ScannerErrorReporter {
|
|
|
1430
1439
|
// Without a catch clause there must be a finally clause; parse one regardless.
|
|
1431
1440
|
let finallyBlock;
|
|
1432
1441
|
if (catchClause === undefined || this.token() === 97 /* SyntaxKind.FinallyKeyword */) {
|
|
1433
|
-
this.parseExpectedWithDiagnostic(97 /* SyntaxKind.FinallyKeyword */,
|
|
1442
|
+
this.parseExpectedWithDiagnostic(97 /* SyntaxKind.FinallyKeyword */, 385 /* Diagnostics.X_catch_or_finally_expected */, true);
|
|
1434
1443
|
finallyBlock = this.parseBlock(false, undefined);
|
|
1435
1444
|
}
|
|
1436
1445
|
return this.finishWithJSDoc(new TryStatement(tryBlock, catchClause, finallyBlock), pos, jsdoc);
|
|
@@ -1529,7 +1538,7 @@ export class Parser extends ScannerErrorReporter {
|
|
|
1529
1538
|
parseVariableDeclarationWorker(allowExclamation) {
|
|
1530
1539
|
const pos = this.nodePos();
|
|
1531
1540
|
const jsdoc = this.jsdocScannerInfo();
|
|
1532
|
-
const name = this.parseIdentifierOrPatternWithDiagnostic(
|
|
1541
|
+
const name = this.parseIdentifierOrPatternWithDiagnostic(1866 /* Diagnostics.Private_identifiers_are_not_allowed_in_variable_declarations */);
|
|
1533
1542
|
let exclamationToken;
|
|
1534
1543
|
if (allowExclamation &&
|
|
1535
1544
|
name.kind === 79 /* SyntaxKind.Identifier */ &&
|
|
@@ -1563,7 +1572,7 @@ export class Parser extends ScannerErrorReporter {
|
|
|
1563
1572
|
const elements = this.parseDelimitedList(10 /* ParsingContext.ArrayBindingElements */, 5 /* ListElement.ArrayBindingElement */);
|
|
1564
1573
|
this.contextFlags = saveContextFlags;
|
|
1565
1574
|
this.parseExpected(23 /* SyntaxKind.CloseBracketToken */);
|
|
1566
|
-
return this.finishNode(new BindingPattern(
|
|
1575
|
+
return this.finishNode(new BindingPattern(209 /* SyntaxKind.ArrayBindingPattern */, elements), pos);
|
|
1567
1576
|
}
|
|
1568
1577
|
parseArrayBindingElement() {
|
|
1569
1578
|
const pos = this.nodePos();
|
|
@@ -1586,7 +1595,7 @@ export class Parser extends ScannerErrorReporter {
|
|
|
1586
1595
|
const elements = this.parseDelimitedList(9 /* ParsingContext.ObjectBindingElements */, 6 /* ListElement.ObjectBindingElement */);
|
|
1587
1596
|
this.contextFlags = saveContextFlags;
|
|
1588
1597
|
this.parseExpected(19 /* SyntaxKind.CloseBraceToken */);
|
|
1589
|
-
return this.finishNode(new BindingPattern(
|
|
1598
|
+
return this.finishNode(new BindingPattern(208 /* SyntaxKind.ObjectBindingPattern */, elements), pos);
|
|
1590
1599
|
}
|
|
1591
1600
|
parseObjectBindingElement() {
|
|
1592
1601
|
const pos = this.nodePos();
|
|
@@ -1645,10 +1654,10 @@ export class Parser extends ScannerErrorReporter {
|
|
|
1645
1654
|
return result;
|
|
1646
1655
|
}
|
|
1647
1656
|
parseClassDeclaration(pos, jsdoc, modifiers) {
|
|
1648
|
-
return this.parseClassDeclarationOrExpression(pos, jsdoc, modifiers,
|
|
1657
|
+
return this.parseClassDeclarationOrExpression(pos, jsdoc, modifiers, 265 /* SyntaxKind.ClassDeclaration */);
|
|
1649
1658
|
}
|
|
1650
1659
|
parseClassExpression() {
|
|
1651
|
-
return this.parseClassDeclarationOrExpression(this.nodePos(), this.jsdocScannerInfo(), undefined,
|
|
1660
|
+
return this.parseClassDeclarationOrExpression(this.nodePos(), this.jsdocScannerInfo(), undefined, 233 /* SyntaxKind.ClassExpression */);
|
|
1652
1661
|
}
|
|
1653
1662
|
parseClassDeclarationOrExpression(pos, jsdoc, modifiers, kind) {
|
|
1654
1663
|
const saveContextFlags = this.contextFlags;
|
|
@@ -1657,9 +1666,16 @@ export class Parser extends ScannerErrorReporter {
|
|
|
1657
1666
|
// The name isn't parsed in an await context; the checker reports `await` names.
|
|
1658
1667
|
const name = this.parseNameOfClassDeclarationOrExpression();
|
|
1659
1668
|
const typeParameters = this.parseTypeParameters();
|
|
1660
|
-
|
|
1669
|
+
// An exported class at the top level of a module, not one nested in a block or a namespace, has its
|
|
1670
|
+
// heritage clauses and members parsed in an await context.
|
|
1671
|
+
if (modifiers !== undefined &&
|
|
1672
|
+
(this.parsingContexts & (1 << 0 /* ParsingContext.SourceElements */)) !== 0 &&
|
|
1673
|
+
(this.parsingContexts &
|
|
1674
|
+
((1 << 1 /* ParsingContext.BlockStatements */) | (1 << 3 /* ParsingContext.SwitchClauseStatements */))) ===
|
|
1675
|
+
0 &&
|
|
1676
|
+
hasModifierOfKind(modifiers, 94 /* SyntaxKind.ExportKeyword */))
|
|
1661
1677
|
this.setContextFlags(8192 /* NodeFlags.AwaitContext */, true);
|
|
1662
|
-
const heritageClauses = this.parseHeritageClauses();
|
|
1678
|
+
const heritageClauses = this.parseHeritageClauses(false);
|
|
1663
1679
|
let members;
|
|
1664
1680
|
if (this.parseExpected(18 /* SyntaxKind.OpenBraceToken */)) {
|
|
1665
1681
|
members = this.parseList(5 /* ParsingContext.ClassMembers */, 7 /* ListElement.ClassElement */);
|
|
@@ -1671,7 +1687,7 @@ export class Parser extends ScannerErrorReporter {
|
|
|
1671
1687
|
this.contextFlags = saveContextFlags;
|
|
1672
1688
|
if (modifiers !== undefined && (modifiersToFlags(modifiers.nodes) & 128 /* ModifierFlags.Ambient */) !== 0)
|
|
1673
1689
|
this.statementHasAwaitIdentifier = saveHasAwaitIdentifier;
|
|
1674
|
-
const result = kind ===
|
|
1690
|
+
const result = kind === 265 /* SyntaxKind.ClassDeclaration */
|
|
1675
1691
|
? new ClassDeclaration(modifiers, name, typeParameters, heritageClauses, members)
|
|
1676
1692
|
: new ClassExpression(modifiers, name, typeParameters, heritageClauses, members);
|
|
1677
1693
|
this.finishWithJSDoc(result, pos, jsdoc);
|
|
@@ -1699,18 +1715,39 @@ export class Parser extends ScannerErrorReporter {
|
|
|
1699
1715
|
isImplementsClause() {
|
|
1700
1716
|
return this.token() === 118 /* SyntaxKind.ImplementsKeyword */ && this.lookAhead(nextTokenIsIdentifierOrKeyword);
|
|
1701
1717
|
}
|
|
1702
|
-
parseHeritageClauses() {
|
|
1718
|
+
parseHeritageClauses(isInterface) {
|
|
1703
1719
|
return this.isHeritageClause()
|
|
1704
|
-
? this.parseList(22 /* ParsingContext.HeritageClauses */, 8 /* ListElement.HeritageClause */)
|
|
1720
|
+
? this.parseList(22 /* ParsingContext.HeritageClauses */, isInterface ? 9 /* ListElement.InterfaceHeritageClause */ : 8 /* ListElement.HeritageClause */)
|
|
1705
1721
|
: undefined;
|
|
1706
1722
|
}
|
|
1707
|
-
parseHeritageClause() {
|
|
1723
|
+
parseHeritageClause(isInterface) {
|
|
1708
1724
|
const pos = this.nodePos();
|
|
1709
1725
|
const kind = this.token();
|
|
1710
1726
|
this.nextToken();
|
|
1711
|
-
|
|
1727
|
+
// A class's `implements` and an interface's `extends` name types: their elements are type references.
|
|
1728
|
+
const isTypeClause = isInterface ? kind === 95 /* SyntaxKind.ExtendsKeyword */ : kind === 118 /* SyntaxKind.ImplementsKeyword */;
|
|
1729
|
+
const types = this.parseDelimitedList(7 /* ParsingContext.HeritageClauseElement */, isTypeClause ? 11 /* ListElement.TypeHeritageClauseElement */ : 10 /* ListElement.ExpressionWithTypeArguments */);
|
|
1712
1730
|
return this.checkJSSyntax(this.finishNode(new HeritageClause(kind, types), pos));
|
|
1713
1731
|
}
|
|
1732
|
+
/** A type reference when the element is an entity name with optional type arguments, otherwise the
|
|
1733
|
+
* `ExpressionWithTypeArguments`, which the checker reports. */
|
|
1734
|
+
parseTypeHeritageClauseElement() {
|
|
1735
|
+
const pos = this.nodePos();
|
|
1736
|
+
const element = this.parseExpressionWithTypeArguments();
|
|
1737
|
+
if (!isValidHeritageTypeReferenceExpression(element.expression))
|
|
1738
|
+
return element;
|
|
1739
|
+
const typeName = this.convertEntityNameExpressionToEntityName(element.expression);
|
|
1740
|
+
return this.finishNode(new TypeReferenceNode(typeName, element.typeArguments), pos);
|
|
1741
|
+
}
|
|
1742
|
+
/** The `QualifiedName` chain for an identifier or a chain of property accesses, spanning the same text. */
|
|
1743
|
+
convertEntityNameExpressionToEntityName(node) {
|
|
1744
|
+
if (node instanceof Identifier)
|
|
1745
|
+
return node;
|
|
1746
|
+
const access = node;
|
|
1747
|
+
// The name can be a private name, as upstream's.
|
|
1748
|
+
const result = new QualifiedName(this.convertEntityNameExpressionToEntityName(access.expression), access.name);
|
|
1749
|
+
return this.finishNodeWithEnd(result, node.pos, node.end);
|
|
1750
|
+
}
|
|
1714
1751
|
parseExpressionWithTypeArguments() {
|
|
1715
1752
|
const pos = this.nodePos();
|
|
1716
1753
|
const expression = this.parseLeftHandSideExpressionOrHigher();
|
|
@@ -1730,9 +1767,9 @@ export class Parser extends ScannerErrorReporter {
|
|
|
1730
1767
|
if (this.token() === 125 /* SyntaxKind.StaticKeyword */ && this.lookAhead(nextTokenIsOpenBrace))
|
|
1731
1768
|
return this.parseClassStaticBlockDeclaration(pos, jsdoc, modifiers);
|
|
1732
1769
|
if (this.parseContextualModifier(138 /* SyntaxKind.GetKeyword */))
|
|
1733
|
-
return this.parseAccessorDeclaration(pos, jsdoc, modifiers,
|
|
1770
|
+
return this.parseAccessorDeclaration(pos, jsdoc, modifiers, 179 /* SyntaxKind.GetAccessor */, 0 /* ParseFlags.None */);
|
|
1734
1771
|
if (this.parseContextualModifier(153 /* SyntaxKind.SetKeyword */))
|
|
1735
|
-
return this.parseAccessorDeclaration(pos, jsdoc, modifiers,
|
|
1772
|
+
return this.parseAccessorDeclaration(pos, jsdoc, modifiers, 180 /* SyntaxKind.SetAccessor */, 0 /* ParseFlags.None */);
|
|
1736
1773
|
if (this.token() === 136 /* SyntaxKind.ConstructorKeyword */ || this.token() === 10 /* SyntaxKind.StringLiteral */) {
|
|
1737
1774
|
const constructorDeclaration = this.tryParseConstructorDeclaration(pos, jsdoc, modifiers);
|
|
1738
1775
|
if (constructorDeclaration !== undefined)
|
|
@@ -1883,17 +1920,17 @@ export class Parser extends ScannerErrorReporter {
|
|
|
1883
1920
|
// A declaration that failed to parse already reported a diagnostic.
|
|
1884
1921
|
return;
|
|
1885
1922
|
case 'interface':
|
|
1886
|
-
this.parseErrorForInvalidName(
|
|
1923
|
+
this.parseErrorForInvalidName(603 /* Diagnostics.Interface_name_cannot_be_0 */, 364 /* Diagnostics.Interface_must_be_given_a_name */, 18 /* SyntaxKind.OpenBraceToken */);
|
|
1887
1924
|
return;
|
|
1888
1925
|
case 'is':
|
|
1889
1926
|
this.parseErrorAt(pos, this.scanner.getTokenStart(), 178 /* Diagnostics.A_type_predicate_is_only_allowed_in_return_type_position_for_functions_and_methods */);
|
|
1890
1927
|
return;
|
|
1891
1928
|
case 'module':
|
|
1892
1929
|
case 'namespace':
|
|
1893
|
-
this.parseErrorForInvalidName(
|
|
1930
|
+
this.parseErrorForInvalidName(957 /* Diagnostics.Namespace_name_cannot_be_0 */, 363 /* Diagnostics.Namespace_must_be_given_a_name */, 18 /* SyntaxKind.OpenBraceToken */);
|
|
1894
1931
|
return;
|
|
1895
1932
|
case 'type':
|
|
1896
|
-
this.parseErrorForInvalidName(
|
|
1933
|
+
this.parseErrorForInvalidName(630 /* Diagnostics.Type_alias_name_cannot_be_0 */, 365 /* Diagnostics.Type_alias_must_be_given_a_name */, 63 /* SyntaxKind.EqualsToken */);
|
|
1897
1934
|
return;
|
|
1898
1935
|
}
|
|
1899
1936
|
// A misspelled keyword, or a missing space after one.
|
|
@@ -1920,7 +1957,7 @@ export class Parser extends ScannerErrorReporter {
|
|
|
1920
1957
|
this.parseExpected(119 /* SyntaxKind.InterfaceKeyword */);
|
|
1921
1958
|
const name = this.parseIdentifier(1 /* IdentifierUse.Name */);
|
|
1922
1959
|
const typeParameters = this.parseTypeParameters();
|
|
1923
|
-
const heritageClauses = this.parseHeritageClauses();
|
|
1960
|
+
const heritageClauses = this.parseHeritageClauses(true);
|
|
1924
1961
|
const members = this.parseObjectTypeMembers();
|
|
1925
1962
|
const result = this.finishWithJSDoc(new InterfaceDeclaration(modifiers, name, typeParameters, heritageClauses, members), pos, jsdoc);
|
|
1926
1963
|
this.checkJSSyntax(result);
|
|
@@ -1937,7 +1974,7 @@ export class Parser extends ScannerErrorReporter {
|
|
|
1937
1974
|
? this.parseKeywordTypeNode()
|
|
1938
1975
|
: this.parseType();
|
|
1939
1976
|
this.parseSemicolon();
|
|
1940
|
-
const result = this.finishWithJSDoc(new TypeAliasDeclaration(
|
|
1977
|
+
const result = this.finishWithJSDoc(new TypeAliasDeclaration(267 /* SyntaxKind.TypeAliasDeclaration */, modifiers, name, typeParameters, type), pos, jsdoc);
|
|
1941
1978
|
this.checkJSSyntax(result);
|
|
1942
1979
|
return result;
|
|
1943
1980
|
}
|
|
@@ -1961,7 +1998,7 @@ export class Parser extends ScannerErrorReporter {
|
|
|
1961
1998
|
if (this.parseExpected(18 /* SyntaxKind.OpenBraceToken */)) {
|
|
1962
1999
|
const saveContextFlags = this.contextFlags;
|
|
1963
2000
|
this.setContextFlags(2048 /* NodeFlags.YieldContext */ | 8192 /* NodeFlags.AwaitContext */, false);
|
|
1964
|
-
members = this.parseDelimitedList(6 /* ParsingContext.EnumMembers */,
|
|
2001
|
+
members = this.parseDelimitedList(6 /* ParsingContext.EnumMembers */, 12 /* ListElement.EnumMember */);
|
|
1965
2002
|
this.contextFlags = saveContextFlags;
|
|
1966
2003
|
this.parseExpected(19 /* SyntaxKind.CloseBraceToken */);
|
|
1967
2004
|
}
|
|
@@ -2001,12 +2038,16 @@ export class Parser extends ScannerErrorReporter {
|
|
|
2001
2038
|
else {
|
|
2002
2039
|
name = this.parseLiteralExpression(true);
|
|
2003
2040
|
}
|
|
2041
|
+
// `declare module "*.ext" with { type: "..." }`: the import attributes the module matches.
|
|
2042
|
+
const attributes = keyword === 144 /* SyntaxKind.ModuleKeyword */ && this.parseOptional(117 /* SyntaxKind.WithKeyword */)
|
|
2043
|
+
? this.parseTypeLiteral()
|
|
2044
|
+
: undefined;
|
|
2004
2045
|
let body;
|
|
2005
2046
|
if (this.token() === 18 /* SyntaxKind.OpenBraceToken */)
|
|
2006
2047
|
body = this.parseModuleBlock();
|
|
2007
2048
|
else
|
|
2008
2049
|
this.parseSemicolon();
|
|
2009
|
-
const result = this.finishWithJSDoc(new ModuleDeclaration(modifiers, keyword, name, body), pos, jsdoc);
|
|
2050
|
+
const result = this.finishWithJSDoc(new ModuleDeclaration(modifiers, keyword, name, attributes, body), pos, jsdoc);
|
|
2010
2051
|
this.statementHasAwaitIdentifier = saveHasAwaitIdentifier;
|
|
2011
2052
|
return result;
|
|
2012
2053
|
}
|
|
@@ -2037,7 +2078,7 @@ export class Parser extends ScannerErrorReporter {
|
|
|
2037
2078
|
else {
|
|
2038
2079
|
body = this.parseModuleBlock();
|
|
2039
2080
|
}
|
|
2040
|
-
const result = this.finishWithJSDoc(new ModuleDeclaration(modifiers, keyword, name, body), pos, jsdoc);
|
|
2081
|
+
const result = this.finishWithJSDoc(new ModuleDeclaration(modifiers, keyword, name, undefined, body), pos, jsdoc);
|
|
2041
2082
|
this.checkJSSyntax(result);
|
|
2042
2083
|
this.statementHasAwaitIdentifier = saveHasAwaitIdentifier;
|
|
2043
2084
|
return result;
|
|
@@ -2047,6 +2088,7 @@ export class Parser extends ScannerErrorReporter {
|
|
|
2047
2088
|
const afterImportPos = this.nodePos();
|
|
2048
2089
|
// The identifier isn't parsed in an await context; the checker reports `await`.
|
|
2049
2090
|
const saveHasAwaitIdentifier = this.statementHasAwaitIdentifier;
|
|
2091
|
+
const phaseModifierCandidate = this.currentImportPhaseModifier();
|
|
2050
2092
|
let identifier = this.isIdentifier() ? this.parseIdentifier(1 /* IdentifierUse.Name */) : undefined;
|
|
2051
2093
|
let phaseModifier = 0 /* SyntaxKind.Unknown */;
|
|
2052
2094
|
if (identifier !== undefined &&
|
|
@@ -2057,18 +2099,16 @@ export class Parser extends ScannerErrorReporter {
|
|
|
2057
2099
|
phaseModifier = 156 /* SyntaxKind.TypeKeyword */;
|
|
2058
2100
|
identifier = this.isIdentifier() ? this.parseIdentifier(1 /* IdentifierUse.Name */) : undefined;
|
|
2059
2101
|
}
|
|
2060
|
-
else if (identifier !== undefined &&
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
phaseModifier = 166 /* SyntaxKind.DeferKeyword */;
|
|
2066
|
-
identifier = this.isIdentifier() ? this.parseIdentifier(1 /* IdentifierUse.Name */) : undefined;
|
|
2067
|
-
}
|
|
2102
|
+
else if (identifier !== undefined &&
|
|
2103
|
+
phaseModifierCandidate !== 0 /* SyntaxKind.Unknown */ &&
|
|
2104
|
+
this.shouldParseImportPhaseModifier()) {
|
|
2105
|
+
phaseModifier = phaseModifierCandidate;
|
|
2106
|
+
identifier = this.isIdentifier() ? this.parseIdentifier(1 /* IdentifierUse.Name */) : undefined;
|
|
2068
2107
|
}
|
|
2069
2108
|
if (identifier !== undefined &&
|
|
2070
2109
|
!this.tokenAfterImportedIdentifierDefinitelyProducesImportDeclaration() &&
|
|
2071
|
-
phaseModifier !== 166 /* SyntaxKind.DeferKeyword */
|
|
2110
|
+
phaseModifier !== 166 /* SyntaxKind.DeferKeyword */ &&
|
|
2111
|
+
phaseModifier !== 167 /* SyntaxKind.SourceKeyword */) {
|
|
2072
2112
|
const importEquals = this.checkJSSyntax(this.parseImportEqualsDeclaration(pos, jsdoc, modifiers, identifier, phaseModifier === 156 /* SyntaxKind.TypeKeyword */));
|
|
2073
2113
|
// Import= declarations are always parsed in an await context; no reparse needed.
|
|
2074
2114
|
this.statementHasAwaitIdentifier = saveHasAwaitIdentifier;
|
|
@@ -2080,13 +2120,35 @@ export class Parser extends ScannerErrorReporter {
|
|
|
2080
2120
|
const moduleSpecifier = this.parseModuleSpecifier();
|
|
2081
2121
|
const attributes = this.tryParseImportAttributes();
|
|
2082
2122
|
this.parseSemicolon();
|
|
2083
|
-
const result = this.finishWithJSDoc(new ImportDeclaration(
|
|
2123
|
+
const result = this.finishWithJSDoc(new ImportDeclaration(274 /* SyntaxKind.ImportDeclaration */, modifiers, importClause, moduleSpecifier, attributes), pos, jsdoc);
|
|
2084
2124
|
this.checkJSSyntax(result);
|
|
2085
2125
|
return result;
|
|
2086
2126
|
}
|
|
2087
2127
|
tokenAfterImportDefinitelyProducesImportDeclaration() {
|
|
2088
2128
|
return this.token() === 41 /* SyntaxKind.AsteriskToken */ || this.token() === 18 /* SyntaxKind.OpenBraceToken */;
|
|
2089
2129
|
}
|
|
2130
|
+
/** In `import defer ___` or `import source ___`, whether `defer` or `source` is a phase modifier rather than the
|
|
2131
|
+
* default import's name. */
|
|
2132
|
+
shouldParseImportPhaseModifier() {
|
|
2133
|
+
switch (this.token()) {
|
|
2134
|
+
case 27 /* SyntaxKind.CommaToken */:
|
|
2135
|
+
case 63 /* SyntaxKind.EqualsToken */:
|
|
2136
|
+
return false;
|
|
2137
|
+
case 161 /* SyntaxKind.FromKeyword */:
|
|
2138
|
+
return !this.lookAhead(nextTokenIsTokenStringLiteral);
|
|
2139
|
+
}
|
|
2140
|
+
return true;
|
|
2141
|
+
}
|
|
2142
|
+
/** The phase modifier the current token's text spells, written without escapes, or `Unknown`. */
|
|
2143
|
+
currentImportPhaseModifier() {
|
|
2144
|
+
switch (this.scanner.getTokenText()) {
|
|
2145
|
+
case 'defer':
|
|
2146
|
+
return 166 /* SyntaxKind.DeferKeyword */;
|
|
2147
|
+
case 'source':
|
|
2148
|
+
return 167 /* SyntaxKind.SourceKeyword */;
|
|
2149
|
+
}
|
|
2150
|
+
return 0 /* SyntaxKind.Unknown */;
|
|
2151
|
+
}
|
|
2090
2152
|
/** In `import id ___`, whether the token makes this an ImportDeclaration rather than ImportEqualsDeclaration. */
|
|
2091
2153
|
tokenAfterImportedIdentifierDefinitelyProducesImportDeclaration() {
|
|
2092
2154
|
return this.token() === 27 /* SyntaxKind.CommaToken */ || this.token() === 161 /* SyntaxKind.FromKeyword */;
|
|
@@ -2100,7 +2162,7 @@ export class Parser extends ScannerErrorReporter {
|
|
|
2100
2162
|
parseModuleReference() {
|
|
2101
2163
|
if (this.token() === 149 /* SyntaxKind.RequireKeyword */ && this.lookAhead(nextTokenIsOpenParen))
|
|
2102
2164
|
return this.parseExternalModuleReference();
|
|
2103
|
-
return this.parseEntityName(false, undefined);
|
|
2165
|
+
return this.parseEntityName(false, false, undefined);
|
|
2104
2166
|
}
|
|
2105
2167
|
parseExternalModuleReference() {
|
|
2106
2168
|
const saveHasAwaitIdentifier = this.statementHasAwaitIdentifier;
|
|
@@ -2129,6 +2191,9 @@ export class Parser extends ScannerErrorReporter {
|
|
|
2129
2191
|
this.parseExpected(161 /* SyntaxKind.FromKeyword */);
|
|
2130
2192
|
return importClause;
|
|
2131
2193
|
}
|
|
2194
|
+
// A phase modifier without bindings still makes an import clause; the checker reports it.
|
|
2195
|
+
if (phaseModifier === 166 /* SyntaxKind.DeferKeyword */ || phaseModifier === 167 /* SyntaxKind.SourceKeyword */)
|
|
2196
|
+
return this.finishNode(new ImportClause(phaseModifier, undefined, undefined), pos);
|
|
2132
2197
|
return undefined;
|
|
2133
2198
|
}
|
|
2134
2199
|
parseImportClause(identifier, pos, phaseModifier, skipJSDocLeadingAsterisks) {
|
|
@@ -2159,22 +2224,22 @@ export class Parser extends ScannerErrorReporter {
|
|
|
2159
2224
|
}
|
|
2160
2225
|
parseNamedImports() {
|
|
2161
2226
|
const pos = this.nodePos();
|
|
2162
|
-
const imports = this.parseBracketedList(23 /* ParsingContext.ImportOrExportSpecifiers */,
|
|
2227
|
+
const imports = this.parseBracketedList(23 /* ParsingContext.ImportOrExportSpecifiers */, 13 /* ListElement.ImportSpecifier */, 18 /* SyntaxKind.OpenBraceToken */, 19 /* SyntaxKind.CloseBraceToken */);
|
|
2163
2228
|
return this.finishNode(new NamedImports(imports), pos);
|
|
2164
2229
|
}
|
|
2165
2230
|
parseImportSpecifier() {
|
|
2166
|
-
return this.parseImportOrExportSpecifier(
|
|
2231
|
+
return this.parseImportOrExportSpecifier(278 /* SyntaxKind.ImportSpecifier */);
|
|
2167
2232
|
}
|
|
2168
2233
|
parseExportSpecifier() {
|
|
2169
|
-
return this.parseImportOrExportSpecifier(
|
|
2234
|
+
return this.parseImportOrExportSpecifier(283 /* SyntaxKind.ExportSpecifier */);
|
|
2170
2235
|
}
|
|
2171
2236
|
parseImportOrExportSpecifier(kind) {
|
|
2172
2237
|
// ImportSpecifier: BindingIdentifier | ModuleExportName as BindingIdentifier
|
|
2173
2238
|
// ExportSpecifier: ModuleExportName | ModuleExportName as ModuleExportName
|
|
2174
2239
|
const pos = this.nodePos();
|
|
2175
|
-
const jsdoc = kind ===
|
|
2240
|
+
const jsdoc = kind === 283 /* SyntaxKind.ExportSpecifier */ ? this.jsdocScannerInfo() : 0 /* JSDocScannerInfo.None */;
|
|
2176
2241
|
let canParseAsKeyword = true;
|
|
2177
|
-
const disallowKeywords = kind ===
|
|
2242
|
+
const disallowKeywords = kind === 278 /* SyntaxKind.ImportSpecifier */;
|
|
2178
2243
|
let isTypeOnly = false;
|
|
2179
2244
|
let propertyName;
|
|
2180
2245
|
let nameOk = this.isModuleExportNameOk(disallowKeywords);
|
|
@@ -2232,7 +2297,7 @@ export class Parser extends ScannerErrorReporter {
|
|
|
2232
2297
|
}
|
|
2233
2298
|
if (!nameOk)
|
|
2234
2299
|
this.parseErrorAt(skipTrivia(this.sourceText, name.pos), name.end, 1 /* Diagnostics.Identifier_expected */);
|
|
2235
|
-
if (kind ===
|
|
2300
|
+
if (kind === 283 /* SyntaxKind.ExportSpecifier */) {
|
|
2236
2301
|
const result = this.finishWithJSDoc(new ExportSpecifier(isTypeOnly, propertyName, name), pos, jsdoc);
|
|
2237
2302
|
this.checkJSSyntax(result);
|
|
2238
2303
|
return result;
|
|
@@ -2265,7 +2330,7 @@ export class Parser extends ScannerErrorReporter {
|
|
|
2265
2330
|
if (this.token() === 117 /* SyntaxKind.WithKeyword */ ||
|
|
2266
2331
|
(this.token() === 131 /* SyntaxKind.AssertKeyword */ && !this.hasPrecedingLineBreak())) {
|
|
2267
2332
|
if (this.token() === 131 /* SyntaxKind.AssertKeyword */)
|
|
2268
|
-
this.parseErrorAtCurrentToken(
|
|
2333
|
+
this.parseErrorAtCurrentToken(1007 /* Diagnostics.Import_assertions_have_been_replaced_by_import_attributes_Use_with_instead_of_assert */);
|
|
2269
2334
|
return this.parseImportAttributes(this.token(), false);
|
|
2270
2335
|
}
|
|
2271
2336
|
return undefined;
|
|
@@ -2326,7 +2391,7 @@ export class Parser extends ScannerErrorReporter {
|
|
|
2326
2391
|
(this.token() === 117 /* SyntaxKind.WithKeyword */ || this.token() === 131 /* SyntaxKind.AssertKeyword */) &&
|
|
2327
2392
|
!this.hasPrecedingLineBreak()) {
|
|
2328
2393
|
if (this.token() === 131 /* SyntaxKind.AssertKeyword */)
|
|
2329
|
-
this.parseErrorAtCurrentToken(
|
|
2394
|
+
this.parseErrorAtCurrentToken(1007 /* Diagnostics.Import_assertions_have_been_replaced_by_import_attributes_Use_with_instead_of_assert */);
|
|
2330
2395
|
attributes = this.parseImportAttributes(this.token(), false);
|
|
2331
2396
|
}
|
|
2332
2397
|
this.parseSemicolon();
|
|
@@ -2342,7 +2407,7 @@ export class Parser extends ScannerErrorReporter {
|
|
|
2342
2407
|
}
|
|
2343
2408
|
parseNamedExports() {
|
|
2344
2409
|
const pos = this.nodePos();
|
|
2345
|
-
const exports = this.parseBracketedList(23 /* ParsingContext.ImportOrExportSpecifiers */,
|
|
2410
|
+
const exports = this.parseBracketedList(23 /* ParsingContext.ImportOrExportSpecifiers */, 14 /* ListElement.ExportSpecifier */, 18 /* SyntaxKind.OpenBraceToken */, 19 /* SyntaxKind.CloseBraceToken */);
|
|
2346
2411
|
return this.finishNode(new NamedExports(exports), pos);
|
|
2347
2412
|
}
|
|
2348
2413
|
// Types
|
|
@@ -2631,10 +2696,13 @@ export class Parser extends ScannerErrorReporter {
|
|
|
2631
2696
|
return this.finishNode(new TypeReferenceNode(this.parseEntityNameOfTypeReference(), this.parseTypeArgumentsOfTypeReference()), pos);
|
|
2632
2697
|
}
|
|
2633
2698
|
parseEntityNameOfTypeReference() {
|
|
2634
|
-
return this.parseEntityName(true, 79 /* Diagnostics.Type_expected */);
|
|
2699
|
+
return this.parseEntityName(true, false, 79 /* Diagnostics.Type_expected */);
|
|
2635
2700
|
}
|
|
2636
|
-
/**
|
|
2637
|
-
|
|
2701
|
+
/**
|
|
2702
|
+
* An entity name; `use` is for its first identifier, the qualified names' right sides are names.
|
|
2703
|
+
* Only a type query allows private names on the right (`typeof this.#x`).
|
|
2704
|
+
*/
|
|
2705
|
+
parseEntityName(allowReservedWords, allowPrivateName, diagnosticMessage, use = 1 /* IdentifierUse.Name */) {
|
|
2638
2706
|
const pos = this.nodePos();
|
|
2639
2707
|
let entity = allowReservedWords
|
|
2640
2708
|
? this.parseIdentifierNameWithDiagnostic(diagnosticMessage, use)
|
|
@@ -2643,7 +2711,7 @@ export class Parser extends ScannerErrorReporter {
|
|
|
2643
2711
|
// A JSDoc-style generic; the checker reports the gap between the name and the type arguments.
|
|
2644
2712
|
if (this.token() === 29 /* SyntaxKind.LessThanToken */)
|
|
2645
2713
|
break;
|
|
2646
|
-
entity = this.finishNode(new QualifiedName(entity, this.
|
|
2714
|
+
entity = this.finishNode(new QualifiedName(entity, this.parseRightSideOfDot(allowReservedWords, allowPrivateName, true)), pos);
|
|
2647
2715
|
}
|
|
2648
2716
|
return entity;
|
|
2649
2717
|
}
|
|
@@ -2737,7 +2805,7 @@ export class Parser extends ScannerErrorReporter {
|
|
|
2737
2805
|
}
|
|
2738
2806
|
parseTypeArguments() {
|
|
2739
2807
|
if (this.token() === 29 /* SyntaxKind.LessThanToken */)
|
|
2740
|
-
return this.parseBracketedList(20 /* ParsingContext.TypeArguments */,
|
|
2808
|
+
return this.parseBracketedList(20 /* ParsingContext.TypeArguments */, 15 /* ListElement.Type */, 29 /* SyntaxKind.LessThanToken */, 31 /* SyntaxKind.GreaterThanToken */);
|
|
2741
2809
|
return undefined;
|
|
2742
2810
|
}
|
|
2743
2811
|
parseImportType() {
|
|
@@ -2754,7 +2822,7 @@ export class Parser extends ScannerErrorReporter {
|
|
|
2754
2822
|
const currentToken = this.token();
|
|
2755
2823
|
if (currentToken === 117 /* SyntaxKind.WithKeyword */ || currentToken === 131 /* SyntaxKind.AssertKeyword */) {
|
|
2756
2824
|
if (currentToken === 131 /* SyntaxKind.AssertKeyword */)
|
|
2757
|
-
this.parseErrorAtCurrentToken(
|
|
2825
|
+
this.parseErrorAtCurrentToken(1007 /* Diagnostics.Import_assertions_have_been_replaced_by_import_attributes_Use_with_instead_of_assert */);
|
|
2758
2826
|
this.nextToken();
|
|
2759
2827
|
}
|
|
2760
2828
|
else {
|
|
@@ -2790,7 +2858,7 @@ export class Parser extends ScannerErrorReporter {
|
|
|
2790
2858
|
if (name !== undefined)
|
|
2791
2859
|
this.parseExpected(58 /* SyntaxKind.ColonToken */);
|
|
2792
2860
|
else
|
|
2793
|
-
this.parseErrorAtCurrentToken(
|
|
2861
|
+
this.parseErrorAtCurrentToken(391 /* Diagnostics.Identifier_or_string_literal_expected */);
|
|
2794
2862
|
const value = this.parseAssignmentExpressionOrHigher();
|
|
2795
2863
|
return this.finishNode(new ImportAttribute(name, value), pos);
|
|
2796
2864
|
}
|
|
@@ -2803,7 +2871,7 @@ export class Parser extends ScannerErrorReporter {
|
|
|
2803
2871
|
const openBracePosition = this.scanner.getTokenStart();
|
|
2804
2872
|
if (this.parseExpected(18 /* SyntaxKind.OpenBraceToken */)) {
|
|
2805
2873
|
multiLine = this.hasPrecedingLineBreak();
|
|
2806
|
-
elements = this.parseDelimitedList(24 /* ParsingContext.ImportAttributes */,
|
|
2874
|
+
elements = this.parseDelimitedList(24 /* ParsingContext.ImportAttributes */, 16 /* ListElement.ImportAttribute */);
|
|
2807
2875
|
if (!this.parseExpected(19 /* SyntaxKind.CloseBraceToken */))
|
|
2808
2876
|
this.addMatchingBraceRelatedInfo(openBracePosition);
|
|
2809
2877
|
}
|
|
@@ -2817,7 +2885,7 @@ export class Parser extends ScannerErrorReporter {
|
|
|
2817
2885
|
parseTypeQuery() {
|
|
2818
2886
|
const pos = this.nodePos();
|
|
2819
2887
|
this.parseExpected(113 /* SyntaxKind.TypeOfKeyword */);
|
|
2820
|
-
const entityName = this.parseEntityName(true, undefined, 0 /* IdentifierUse.Reference */);
|
|
2888
|
+
const entityName = this.parseEntityName(true, true, undefined, 0 /* IdentifierUse.Reference */);
|
|
2821
2889
|
// ASI: don't parse the next line's type arguments as part of an instantiation expression.
|
|
2822
2890
|
const typeArguments = this.hasPrecedingLineBreak() ? undefined : this.parseTypeArguments();
|
|
2823
2891
|
return this.finishNode(new TypeQueryNode(entityName, typeArguments), pos);
|
|
@@ -2847,7 +2915,7 @@ export class Parser extends ScannerErrorReporter {
|
|
|
2847
2915
|
}
|
|
2848
2916
|
const type = this.parseTypeAnnotation();
|
|
2849
2917
|
this.parseSemicolon();
|
|
2850
|
-
const members = this.parseList(4 /* ParsingContext.TypeMembers */,
|
|
2918
|
+
const members = this.parseList(4 /* ParsingContext.TypeMembers */, 17 /* ListElement.TypeMember */);
|
|
2851
2919
|
this.parseExpected(19 /* SyntaxKind.CloseBraceToken */);
|
|
2852
2920
|
return this.finishNode(new MappedTypeNode(readonlyToken, typeParameter, nameType, questionToken, type, members), pos);
|
|
2853
2921
|
}
|
|
@@ -2862,16 +2930,16 @@ export class Parser extends ScannerErrorReporter {
|
|
|
2862
2930
|
}
|
|
2863
2931
|
parseTypeMember() {
|
|
2864
2932
|
if (this.token() === 20 /* SyntaxKind.OpenParenToken */ || this.token() === 29 /* SyntaxKind.LessThanToken */)
|
|
2865
|
-
return this.parseSignatureMember(
|
|
2933
|
+
return this.parseSignatureMember(181 /* SyntaxKind.CallSignature */);
|
|
2866
2934
|
if (this.token() === 104 /* SyntaxKind.NewKeyword */ && this.lookAhead(nextTokenIsOpenParenOrLessThan))
|
|
2867
|
-
return this.parseSignatureMember(
|
|
2935
|
+
return this.parseSignatureMember(182 /* SyntaxKind.ConstructSignature */);
|
|
2868
2936
|
const pos = this.nodePos();
|
|
2869
2937
|
const jsdoc = this.jsdocScannerInfo();
|
|
2870
2938
|
const modifiers = this.parseModifiers();
|
|
2871
2939
|
if (this.parseContextualModifier(138 /* SyntaxKind.GetKeyword */))
|
|
2872
|
-
return this.parseAccessorDeclaration(pos, jsdoc, modifiers,
|
|
2940
|
+
return this.parseAccessorDeclaration(pos, jsdoc, modifiers, 179 /* SyntaxKind.GetAccessor */, 4 /* ParseFlags.Type */);
|
|
2873
2941
|
if (this.parseContextualModifier(153 /* SyntaxKind.SetKeyword */))
|
|
2874
|
-
return this.parseAccessorDeclaration(pos, jsdoc, modifiers,
|
|
2942
|
+
return this.parseAccessorDeclaration(pos, jsdoc, modifiers, 180 /* SyntaxKind.SetAccessor */, 4 /* ParseFlags.Type */);
|
|
2875
2943
|
if (this.isIndexSignature())
|
|
2876
2944
|
return this.parseIndexSignatureDeclaration(pos, jsdoc, modifiers);
|
|
2877
2945
|
return this.parsePropertyOrMethodSignature(pos, jsdoc, modifiers);
|
|
@@ -2879,20 +2947,20 @@ export class Parser extends ScannerErrorReporter {
|
|
|
2879
2947
|
parseSignatureMember(kind) {
|
|
2880
2948
|
const pos = this.nodePos();
|
|
2881
2949
|
const jsdoc = this.jsdocScannerInfo();
|
|
2882
|
-
if (kind ===
|
|
2950
|
+
if (kind === 182 /* SyntaxKind.ConstructSignature */)
|
|
2883
2951
|
this.parseExpected(104 /* SyntaxKind.NewKeyword */);
|
|
2884
2952
|
const typeParameters = this.parseTypeParameters();
|
|
2885
2953
|
const parameters = this.parseParameters(4 /* ParseFlags.Type */);
|
|
2886
2954
|
const type = this.parseReturnType(58 /* SyntaxKind.ColonToken */, true);
|
|
2887
2955
|
this.parseTypeMemberSemicolon();
|
|
2888
|
-
const result = kind ===
|
|
2956
|
+
const result = kind === 181 /* SyntaxKind.CallSignature */
|
|
2889
2957
|
? new CallSignatureDeclaration(typeParameters, parameters, type)
|
|
2890
2958
|
: new ConstructSignatureDeclaration(typeParameters, parameters, type);
|
|
2891
2959
|
return this.finishWithJSDoc(result, pos, jsdoc);
|
|
2892
2960
|
}
|
|
2893
2961
|
parseTypeParameters() {
|
|
2894
2962
|
if (this.token() === 29 /* SyntaxKind.LessThanToken */)
|
|
2895
|
-
return this.parseBracketedList(19 /* ParsingContext.TypeParameters */,
|
|
2963
|
+
return this.parseBracketedList(19 /* ParsingContext.TypeParameters */, 18 /* ListElement.TypeParameter */, 29 /* SyntaxKind.LessThanToken */, 31 /* SyntaxKind.GreaterThanToken */);
|
|
2896
2964
|
return undefined;
|
|
2897
2965
|
}
|
|
2898
2966
|
parseTypeParameter() {
|
|
@@ -2932,7 +3000,7 @@ export class Parser extends ScannerErrorReporter {
|
|
|
2932
3000
|
const saveContextFlags = this.contextFlags;
|
|
2933
3001
|
this.setContextFlags(2048 /* NodeFlags.YieldContext */, (flags & 1 /* ParseFlags.Yield */) !== 0);
|
|
2934
3002
|
this.setContextFlags(8192 /* NodeFlags.AwaitContext */, (flags & 2 /* ParseFlags.Await */) !== 0);
|
|
2935
|
-
const parameters = this.parseDelimitedList(16 /* ParsingContext.Parameters */,
|
|
3003
|
+
const parameters = this.parseDelimitedList(16 /* ParsingContext.Parameters */, 20 /* ListElement.SignatureParameter */);
|
|
2936
3004
|
this.contextFlags = saveContextFlags;
|
|
2937
3005
|
this.signatureParameterInAwaitContext = saveInAwaitContext;
|
|
2938
3006
|
this.signatureParameterAllowAmbiguity = saveAllowAmbiguity;
|
|
@@ -2976,7 +3044,7 @@ export class Parser extends ScannerErrorReporter {
|
|
|
2976
3044
|
this.token() === 18 /* SyntaxKind.OpenBraceToken */);
|
|
2977
3045
|
}
|
|
2978
3046
|
parseNameOfParameter(modifiers) {
|
|
2979
|
-
const name = this.parseIdentifierOrPatternWithDiagnostic(
|
|
3047
|
+
const name = this.parseIdentifierOrPatternWithDiagnostic(1851 /* Diagnostics.Private_identifiers_cannot_be_used_as_parameters */);
|
|
2980
3048
|
if (name.end - name.pos === 0 && modifiers === undefined && isModifierKind(this.token())) {
|
|
2981
3049
|
// In `function foo(static)`, `static` is a modifier but not a strict-mode identifier: the name
|
|
2982
3050
|
// is missing and the token didn't change, so advance to avoid looping forever.
|
|
@@ -3030,7 +3098,7 @@ export class Parser extends ScannerErrorReporter {
|
|
|
3030
3098
|
const returnType = this.parseReturnType(58 /* SyntaxKind.ColonToken */, false);
|
|
3031
3099
|
const body = this.parseFunctionBlockOrSemicolon(flags, undefined);
|
|
3032
3100
|
// Type parameters (and setter return types) are kept for the grammar checker.
|
|
3033
|
-
const result = kind ===
|
|
3101
|
+
const result = kind === 179 /* SyntaxKind.GetAccessor */
|
|
3034
3102
|
? new GetAccessorDeclaration(modifiers, name, typeParameters, parameters, returnType, undefined, body)
|
|
3035
3103
|
: new SetAccessorDeclaration(modifiers, name, typeParameters, parameters, returnType, undefined, body);
|
|
3036
3104
|
this.finishWithJSDoc(result, pos, jsdoc);
|
|
@@ -3091,7 +3159,7 @@ export class Parser extends ScannerErrorReporter {
|
|
|
3091
3159
|
return this.token() === 22 /* SyntaxKind.OpenBracketToken */ && this.lookAhead(nextIsUnambiguouslyIndexSignature);
|
|
3092
3160
|
}
|
|
3093
3161
|
parseIndexSignatureDeclaration(pos, jsdoc, modifiers) {
|
|
3094
|
-
const parameters = this.parseBracketedList(16 /* ParsingContext.Parameters */,
|
|
3162
|
+
const parameters = this.parseBracketedList(16 /* ParsingContext.Parameters */, 19 /* ListElement.Parameter */, 22 /* SyntaxKind.OpenBracketToken */, 23 /* SyntaxKind.CloseBracketToken */);
|
|
3095
3163
|
const type = this.parseTypeAnnotation();
|
|
3096
3164
|
this.parseTypeMemberSemicolon();
|
|
3097
3165
|
return this.finishWithJSDoc(new IndexSignatureDeclaration(modifiers, parameters, type), pos, jsdoc);
|
|
@@ -3122,7 +3190,7 @@ export class Parser extends ScannerErrorReporter {
|
|
|
3122
3190
|
}
|
|
3123
3191
|
parseObjectTypeMembers() {
|
|
3124
3192
|
if (this.parseExpected(18 /* SyntaxKind.OpenBraceToken */)) {
|
|
3125
|
-
const members = this.parseList(4 /* ParsingContext.TypeMembers */,
|
|
3193
|
+
const members = this.parseList(4 /* ParsingContext.TypeMembers */, 17 /* ListElement.TypeMember */);
|
|
3126
3194
|
this.parseExpected(19 /* SyntaxKind.CloseBraceToken */);
|
|
3127
3195
|
return members;
|
|
3128
3196
|
}
|
|
@@ -3130,7 +3198,7 @@ export class Parser extends ScannerErrorReporter {
|
|
|
3130
3198
|
}
|
|
3131
3199
|
parseTupleType() {
|
|
3132
3200
|
const pos = this.nodePos();
|
|
3133
|
-
return this.finishNode(new TupleTypeNode(this.parseBracketedList(21 /* ParsingContext.TupleElementTypes */,
|
|
3201
|
+
return this.finishNode(new TupleTypeNode(this.parseBracketedList(21 /* ParsingContext.TupleElementTypes */, 21 /* ListElement.TupleElement */, 22 /* SyntaxKind.OpenBracketToken */, 23 /* SyntaxKind.CloseBracketToken */)), pos);
|
|
3134
3202
|
}
|
|
3135
3203
|
parseTupleElementNameOrTupleElementType() {
|
|
3136
3204
|
if (this.lookAhead(scanStartOfNamedTupleElement)) {
|
|
@@ -3231,7 +3299,7 @@ export class Parser extends ScannerErrorReporter {
|
|
|
3231
3299
|
if (this.isStartOfFunctionTypeOrConstructorType()) {
|
|
3232
3300
|
const type = this.parseFunctionOrConstructorType();
|
|
3233
3301
|
let diagnostic;
|
|
3234
|
-
if (type.kind ===
|
|
3302
|
+
if (type.kind === 186 /* SyntaxKind.FunctionType */)
|
|
3235
3303
|
diagnostic = isInUnionType
|
|
3236
3304
|
? 312 /* Diagnostics.Function_type_notation_must_be_parenthesized_when_used_in_a_union_type */
|
|
3237
3305
|
: 314 /* Diagnostics.Function_type_notation_must_be_parenthesized_when_used_in_an_intersection_type */;
|
|
@@ -3778,8 +3846,7 @@ export class Parser extends ScannerErrorReporter {
|
|
|
3778
3846
|
// Take a left-associative operator when its precedence is higher than the current one (so
|
|
3779
3847
|
// `a - b - c` returns `b` as the right operand of the first `-`), and `**` (right
|
|
3780
3848
|
// associative) when it is at least as high.
|
|
3781
|
-
|
|
3782
|
-
if (!consumeCurrentOperator)
|
|
3849
|
+
if (!shouldConsumeBinaryOperator(operator, newPrecedence, precedence))
|
|
3783
3850
|
break;
|
|
3784
3851
|
if (operator === 102 /* SyntaxKind.InKeyword */ && this.inDisallowInContext())
|
|
3785
3852
|
break;
|
|
@@ -3788,7 +3855,7 @@ export class Parser extends ScannerErrorReporter {
|
|
|
3788
3855
|
if (this.hasPrecedingLineBreak())
|
|
3789
3856
|
break;
|
|
3790
3857
|
this.nextToken();
|
|
3791
|
-
// In `a ## b as T`, stop
|
|
3858
|
+
// In `a ## b as T $$ c`, stop when `$$` would bind before `##` once the `as` is erased: the
|
|
3792
3859
|
// `as` couldn't be erased without changing the meaning (TypeScript#63527).
|
|
3793
3860
|
const lastPrecedence = lastOperand instanceof BinaryExpression
|
|
3794
3861
|
? getBinaryOperatorPrecedence(lastOperand.operatorToken.kind)
|
|
@@ -3797,7 +3864,8 @@ export class Parser extends ScannerErrorReporter {
|
|
|
3797
3864
|
operator === 152 /* SyntaxKind.SatisfiesKeyword */
|
|
3798
3865
|
? this.makeSatisfiesExpression(leftOperand, this.parseType())
|
|
3799
3866
|
: this.makeAsExpression(leftOperand, this.parseType());
|
|
3800
|
-
|
|
3867
|
+
const nextOperator = this.reScanGreaterThanToken();
|
|
3868
|
+
if (shouldConsumeBinaryOperator(nextOperator, getBinaryOperatorPrecedence(nextOperator), lastPrecedence))
|
|
3801
3869
|
break;
|
|
3802
3870
|
}
|
|
3803
3871
|
else {
|
|
@@ -3831,10 +3899,10 @@ export class Parser extends ScannerErrorReporter {
|
|
|
3831
3899
|
if (this.token() === 42 /* SyntaxKind.AsteriskAsteriskToken */) {
|
|
3832
3900
|
const pos = skipTrivia(this.sourceText, simpleUnaryExpression.pos);
|
|
3833
3901
|
const end = simpleUnaryExpression.end;
|
|
3834
|
-
if (simpleUnaryExpression.kind ===
|
|
3835
|
-
this.parseErrorAt(pos, end,
|
|
3902
|
+
if (simpleUnaryExpression.kind === 218 /* SyntaxKind.TypeAssertionExpression */)
|
|
3903
|
+
this.parseErrorAt(pos, end, 1830 /* Diagnostics.A_type_assertion_expression_is_not_allowed_in_the_left_hand_side_of_an_exponentiation_expression_Consider_enclosing_the_expression_in_parentheses */);
|
|
3836
3904
|
else
|
|
3837
|
-
this.parseErrorAt(pos, end,
|
|
3905
|
+
this.parseErrorAt(pos, end, 1829 /* Diagnostics.An_unary_expression_with_the_0_operator_is_not_allowed_in_the_left_hand_side_of_an_exponentiation_expression_Consider_enclosing_the_expression_in_parentheses */, [tokenToString(unaryOperator)]);
|
|
3838
3906
|
}
|
|
3839
3907
|
return simpleUnaryExpression;
|
|
3840
3908
|
}
|
|
@@ -3913,14 +3981,14 @@ export class Parser extends ScannerErrorReporter {
|
|
|
3913
3981
|
tagNamesAreEquivalent(closingElement.tagName, openingTag.tagName)) {
|
|
3914
3982
|
// The opening matched its parent's closing: report it on the opening.
|
|
3915
3983
|
const tagName = opening.tagName;
|
|
3916
|
-
this.parseErrorAt(tagName.pos, tagName.end,
|
|
3984
|
+
this.parseErrorAt(tagName.pos, tagName.end, 1831 /* Diagnostics.JSX_element_0_has_no_corresponding_closing_tag */, [
|
|
3917
3985
|
getTextOfNodeFromSourceText(this.sourceText, tagName),
|
|
3918
3986
|
]);
|
|
3919
3987
|
}
|
|
3920
3988
|
else {
|
|
3921
3989
|
// Other mismatches are reported on the closing.
|
|
3922
3990
|
const tagName = closingElement.tagName;
|
|
3923
|
-
this.parseErrorAt(tagName.pos, tagName.end,
|
|
3991
|
+
this.parseErrorAt(tagName.pos, tagName.end, 1826 /* Diagnostics.Expected_corresponding_JSX_closing_tag_for_0 */, [
|
|
3924
3992
|
getTextOfNodeFromSourceText(this.sourceText, opening.tagName),
|
|
3925
3993
|
]);
|
|
3926
3994
|
}
|
|
@@ -3934,7 +4002,7 @@ export class Parser extends ScannerErrorReporter {
|
|
|
3934
4002
|
const children = this.parseJsxChildren(opening);
|
|
3935
4003
|
result = this.finishNode(new JsxFragment(opening, children, this.parseJsxClosingFragment(inExpressionContext)), pos);
|
|
3936
4004
|
}
|
|
3937
|
-
else if (opening.kind ===
|
|
4005
|
+
else if (opening.kind === 287 /* SyntaxKind.JsxSelfClosingElement */) {
|
|
3938
4006
|
result = opening;
|
|
3939
4007
|
}
|
|
3940
4008
|
else {
|
|
@@ -3949,7 +4017,7 @@ export class Parser extends ScannerErrorReporter {
|
|
|
3949
4017
|
const operatorToken = new Token(27 /* SyntaxKind.CommaToken */);
|
|
3950
4018
|
operatorToken.pos = invalidElement.pos;
|
|
3951
4019
|
operatorToken.end = invalidElement.pos;
|
|
3952
|
-
this.parseErrorAt(skipTrivia(this.sourceText, topBadPos), invalidElement.end,
|
|
4020
|
+
this.parseErrorAt(skipTrivia(this.sourceText, topBadPos), invalidElement.end, 798 /* Diagnostics.JSX_expressions_must_have_one_parent_element */);
|
|
3953
4021
|
result = this.finishNode(new BinaryExpression(undefined, result, undefined, operatorToken, invalidElement), pos);
|
|
3954
4022
|
}
|
|
3955
4023
|
return result;
|
|
@@ -3981,13 +4049,13 @@ export class Parser extends ScannerErrorReporter {
|
|
|
3981
4049
|
case 1 /* SyntaxKind.EndOfFile */:
|
|
3982
4050
|
// Report at the tag without a closing element rather than at the end of the file.
|
|
3983
4051
|
if (openingTag instanceof JsxOpeningFragment) {
|
|
3984
|
-
this.parseErrorAt(openingTag.pos, openingTag.end,
|
|
4052
|
+
this.parseErrorAt(openingTag.pos, openingTag.end, 1837 /* Diagnostics.JSX_fragment_has_no_corresponding_closing_tag */);
|
|
3985
4053
|
}
|
|
3986
4054
|
else if (openingTag instanceof JsxOpeningElement) {
|
|
3987
4055
|
// Only cover `Foo.Bar` in `< Foo.Bar >`.
|
|
3988
4056
|
const tag = openingTag.tagName;
|
|
3989
4057
|
const start = Math.min(skipTrivia(this.sourceText, tag.pos), tag.end);
|
|
3990
|
-
this.parseErrorAt(start, tag.end,
|
|
4058
|
+
this.parseErrorAt(start, tag.end, 1831 /* Diagnostics.JSX_element_0_has_no_corresponding_closing_tag */, [
|
|
3991
4059
|
getTextOfNodeFromSourceText(this.sourceText, tag),
|
|
3992
4060
|
]);
|
|
3993
4061
|
}
|
|
@@ -4114,7 +4182,7 @@ export class Parser extends ScannerErrorReporter {
|
|
|
4114
4182
|
}
|
|
4115
4183
|
parseJsxAttributes() {
|
|
4116
4184
|
const pos = this.nodePos();
|
|
4117
|
-
const result = new JsxAttributes(this.parseList(13 /* ParsingContext.JsxAttributes */,
|
|
4185
|
+
const result = new JsxAttributes(this.parseList(13 /* ParsingContext.JsxAttributes */, 22 /* ListElement.JsxAttribute */));
|
|
4118
4186
|
this.finishNode(result, pos);
|
|
4119
4187
|
return result;
|
|
4120
4188
|
}
|
|
@@ -4149,8 +4217,9 @@ export class Parser extends ScannerErrorReporter {
|
|
|
4149
4217
|
return this.parseLiteralExpression(false);
|
|
4150
4218
|
if (this.token() === 18 /* SyntaxKind.OpenBraceToken */)
|
|
4151
4219
|
return this.parseJsxExpression(true);
|
|
4220
|
+
// An attribute value is a single element: sibling-element recovery must not wrap it in a binary expression.
|
|
4152
4221
|
if (this.token() === 29 /* SyntaxKind.LessThanToken */)
|
|
4153
|
-
return this.parseJsxElementOrSelfClosingElementOrFragment(true, -1, undefined,
|
|
4222
|
+
return this.parseJsxElementOrSelfClosingElementOrFragment(true, -1, undefined, true);
|
|
4154
4223
|
this.parseErrorAtCurrentToken(110 /* Diagnostics.X_or_JSX_element_expected */);
|
|
4155
4224
|
}
|
|
4156
4225
|
return undefined;
|
|
@@ -4158,7 +4227,7 @@ export class Parser extends ScannerErrorReporter {
|
|
|
4158
4227
|
parseJsxClosingFragment(inExpressionContext) {
|
|
4159
4228
|
const pos = this.nodePos();
|
|
4160
4229
|
this.parseExpected(30 /* SyntaxKind.LessThanSlashToken */);
|
|
4161
|
-
if (this.parseExpectedWithDiagnostic(31 /* SyntaxKind.GreaterThanToken */,
|
|
4230
|
+
if (this.parseExpectedWithDiagnostic(31 /* SyntaxKind.GreaterThanToken */, 1838 /* Diagnostics.Expected_corresponding_closing_tag_for_JSX_fragment */, false)) {
|
|
4162
4231
|
// Advance manually to scan JSX text inside JSX.
|
|
4163
4232
|
if (inExpressionContext)
|
|
4164
4233
|
this.nextToken();
|
|
@@ -4257,9 +4326,9 @@ export class Parser extends ScannerErrorReporter {
|
|
|
4257
4326
|
// An `import.*` meta property, such as `import.meta`.
|
|
4258
4327
|
this.nextToken();
|
|
4259
4328
|
this.nextToken();
|
|
4260
|
-
const name = this.
|
|
4329
|
+
const name = this.parseImportMetaPropertyName();
|
|
4261
4330
|
expression = this.finishNode(new MetaProperty(101 /* SyntaxKind.ImportKeyword */, name), pos);
|
|
4262
|
-
if (
|
|
4331
|
+
if (isImportPhaseMetaProperty(expression)) {
|
|
4263
4332
|
if (this.token() === 20 /* SyntaxKind.OpenParenToken */ || this.token() === 29 /* SyntaxKind.LessThanToken */)
|
|
4264
4333
|
this.sourceFlags |= 524288 /* NodeFlags.PossiblyContainsDynamicImport */;
|
|
4265
4334
|
}
|
|
@@ -4280,6 +4349,13 @@ export class Parser extends ScannerErrorReporter {
|
|
|
4280
4349
|
// We may have consumed the start of a call or optional expression; consume the rest.
|
|
4281
4350
|
return this.parseCallExpressionRest(pos, expression);
|
|
4282
4351
|
}
|
|
4352
|
+
/** The name after `import.`; `defer` and `source` written with escapes are reported. */
|
|
4353
|
+
parseImportMetaPropertyName() {
|
|
4354
|
+
if ((this.token() === 166 /* SyntaxKind.DeferKeyword */ || this.token() === 167 /* SyntaxKind.SourceKeyword */) &&
|
|
4355
|
+
this.currentImportPhaseModifier() === 0 /* SyntaxKind.Unknown */)
|
|
4356
|
+
this.parseErrorAtCurrentToken(209 /* Diagnostics.Keywords_cannot_contain_escape_characters */);
|
|
4357
|
+
return this.parseIdentifierName(1 /* IdentifierUse.Name */);
|
|
4358
|
+
}
|
|
4283
4359
|
parseSuperExpression() {
|
|
4284
4360
|
const pos = this.nodePos();
|
|
4285
4361
|
let expression = this.parseKeywordExpression();
|
|
@@ -4287,7 +4363,7 @@ export class Parser extends ScannerErrorReporter {
|
|
|
4287
4363
|
const startPos = this.nodePos();
|
|
4288
4364
|
const typeArguments = this.tryParseTypeArgumentsInExpression();
|
|
4289
4365
|
if (typeArguments !== undefined) {
|
|
4290
|
-
this.parseErrorAt(startPos, this.nodePos(),
|
|
4366
|
+
this.parseErrorAt(startPos, this.nodePos(), 893 /* Diagnostics.X_super_may_not_use_type_arguments */);
|
|
4291
4367
|
if (!this.isTemplateStartOfTaggedTemplate())
|
|
4292
4368
|
expression = this.finishNode(new ExpressionWithTypeArguments(expression, typeArguments), pos);
|
|
4293
4369
|
}
|
|
@@ -4312,7 +4388,7 @@ export class Parser extends ScannerErrorReporter {
|
|
|
4312
4388
|
const state = this.mark();
|
|
4313
4389
|
if (this.reScanLessThanToken() === 29 /* SyntaxKind.LessThanToken */) {
|
|
4314
4390
|
this.nextToken();
|
|
4315
|
-
const typeArguments = this.parseDelimitedList(20 /* ParsingContext.TypeArguments */,
|
|
4391
|
+
const typeArguments = this.parseDelimitedList(20 /* ParsingContext.TypeArguments */, 15 /* ListElement.Type */);
|
|
4316
4392
|
// Without the closing `>` it's not a type argument list.
|
|
4317
4393
|
if (this.reScanGreaterThanToken() === 31 /* SyntaxKind.GreaterThanToken */) {
|
|
4318
4394
|
this.nextToken();
|
|
@@ -4408,11 +4484,11 @@ export class Parser extends ScannerErrorReporter {
|
|
|
4408
4484
|
const isOptionalChain = questionDotToken !== undefined || this.tryReparseOptionalChain(expression);
|
|
4409
4485
|
const propertyAccess = new PropertyAccessExpression(expression, questionDotToken, name, isOptionalChain ? 32 /* NodeFlags.OptionalChain */ : 0 /* NodeFlags.None */);
|
|
4410
4486
|
if (isOptionalChain && name.kind === 80 /* SyntaxKind.PrivateIdentifier */)
|
|
4411
|
-
this.parseErrorAt(skipTrivia(this.sourceText, name.pos), name.end,
|
|
4487
|
+
this.parseErrorAt(skipTrivia(this.sourceText, name.pos), name.end, 1867 /* Diagnostics.An_optional_chain_cannot_contain_private_identifiers */);
|
|
4412
4488
|
if (expression instanceof ExpressionWithTypeArguments) {
|
|
4413
4489
|
const typeArguments = expression.typeArguments;
|
|
4414
4490
|
if (typeArguments !== undefined)
|
|
4415
|
-
this.parseErrorAt(typeArguments.pos - 1, skipTrivia(this.sourceText, typeArguments.end) + 1,
|
|
4491
|
+
this.parseErrorAt(typeArguments.pos - 1, skipTrivia(this.sourceText, typeArguments.end) + 1, 390 /* Diagnostics.An_instantiation_expression_cannot_be_followed_by_a_property_access */);
|
|
4416
4492
|
}
|
|
4417
4493
|
return this.finishNode(propertyAccess, pos);
|
|
4418
4494
|
}
|
|
@@ -4439,10 +4515,15 @@ export class Parser extends ScannerErrorReporter {
|
|
|
4439
4515
|
parseElementAccessExpressionRest(pos, expression, questionDotToken) {
|
|
4440
4516
|
let argumentExpression;
|
|
4441
4517
|
if (this.token() === 23 /* SyntaxKind.CloseBracketToken */) {
|
|
4442
|
-
|
|
4518
|
+
// The missing argument is created before the error, so the error marks the element access.
|
|
4443
4519
|
argumentExpression = this.createMissingIdentifier();
|
|
4520
|
+
this.parseErrorAt(this.nodePos(), this.nodePos(), 7 /* Diagnostics.An_element_access_expression_should_take_an_argument */);
|
|
4444
4521
|
}
|
|
4445
4522
|
else {
|
|
4523
|
+
// tsgo creates the missing argument first and drops it when there is one. Finishing that node takes the
|
|
4524
|
+
// error flag of an error before the argument (`i[01]`), so the argument doesn't get it.
|
|
4525
|
+
this.identifierCount++;
|
|
4526
|
+
this.hasParseError = false;
|
|
4446
4527
|
const argument = this.parseExpressionAllowIn();
|
|
4447
4528
|
if (argument.kind === 10 /* SyntaxKind.StringLiteral */ ||
|
|
4448
4529
|
argument.kind === 14 /* SyntaxKind.NoSubstitutionTemplateLiteral */ ||
|
|
@@ -4491,7 +4572,7 @@ export class Parser extends ScannerErrorReporter {
|
|
|
4491
4572
|
}
|
|
4492
4573
|
parseArgumentList() {
|
|
4493
4574
|
this.parseExpected(20 /* SyntaxKind.OpenParenToken */);
|
|
4494
|
-
const result = this.parseDelimitedList(11 /* ParsingContext.ArgumentExpressions */,
|
|
4575
|
+
const result = this.parseDelimitedList(11 /* ParsingContext.ArgumentExpressions */, 23 /* ListElement.ArgumentExpression */);
|
|
4495
4576
|
this.parseExpected(21 /* SyntaxKind.CloseParenToken */);
|
|
4496
4577
|
return result;
|
|
4497
4578
|
}
|
|
@@ -4614,7 +4695,7 @@ export class Parser extends ScannerErrorReporter {
|
|
|
4614
4695
|
const openBracketPosition = this.scanner.getTokenStart();
|
|
4615
4696
|
const openBracketParsed = this.parseExpected(22 /* SyntaxKind.OpenBracketToken */);
|
|
4616
4697
|
const multiLine = this.hasPrecedingLineBreak();
|
|
4617
|
-
const elements = this.parseDelimitedList(15 /* ParsingContext.ArrayLiteralMembers */,
|
|
4698
|
+
const elements = this.parseDelimitedList(15 /* ParsingContext.ArrayLiteralMembers */, 24 /* ListElement.ArrayLiteralElement */);
|
|
4618
4699
|
this.parseExpectedMatchingBrackets(22 /* SyntaxKind.OpenBracketToken */, 23 /* SyntaxKind.CloseBracketToken */, openBracketParsed, openBracketPosition);
|
|
4619
4700
|
return this.finishNode(new ArrayLiteralExpression(elements, multiLine), pos);
|
|
4620
4701
|
}
|
|
@@ -4623,7 +4704,7 @@ export class Parser extends ScannerErrorReporter {
|
|
|
4623
4704
|
const openBracePosition = this.scanner.getTokenStart();
|
|
4624
4705
|
const openBraceParsed = this.parseExpected(18 /* SyntaxKind.OpenBraceToken */);
|
|
4625
4706
|
const multiLine = this.hasPrecedingLineBreak();
|
|
4626
|
-
const properties = this.parseDelimitedList(12 /* ParsingContext.ObjectLiteralMembers */,
|
|
4707
|
+
const properties = this.parseDelimitedList(12 /* ParsingContext.ObjectLiteralMembers */, 25 /* ListElement.ObjectLiteralElement */);
|
|
4627
4708
|
this.parseExpectedMatchingBrackets(18 /* SyntaxKind.OpenBraceToken */, 19 /* SyntaxKind.CloseBraceToken */, openBraceParsed, openBracePosition);
|
|
4628
4709
|
return this.finishNode(new ObjectLiteralExpression(properties, multiLine), pos);
|
|
4629
4710
|
}
|
|
@@ -4636,9 +4717,9 @@ export class Parser extends ScannerErrorReporter {
|
|
|
4636
4717
|
}
|
|
4637
4718
|
const modifiers = this.parseModifiersEx(true, false, false);
|
|
4638
4719
|
if (this.parseContextualModifier(138 /* SyntaxKind.GetKeyword */))
|
|
4639
|
-
return this.parseAccessorDeclaration(pos, jsdoc, modifiers,
|
|
4720
|
+
return this.parseAccessorDeclaration(pos, jsdoc, modifiers, 179 /* SyntaxKind.GetAccessor */, 0 /* ParseFlags.None */);
|
|
4640
4721
|
if (this.parseContextualModifier(153 /* SyntaxKind.SetKeyword */))
|
|
4641
|
-
return this.parseAccessorDeclaration(pos, jsdoc, modifiers,
|
|
4722
|
+
return this.parseAccessorDeclaration(pos, jsdoc, modifiers, 180 /* SyntaxKind.SetAccessor */, 0 /* ParseFlags.None */);
|
|
4642
4723
|
const asteriskToken = this.parseOptionalToken(41 /* SyntaxKind.AsteriskToken */);
|
|
4643
4724
|
const tokenIsIdentifier = this.isIdentifier();
|
|
4644
4725
|
const name = this.parsePropertyName(2 /* IdentifierUse.ElementName */);
|
|
@@ -4703,7 +4784,7 @@ export class Parser extends ScannerErrorReporter {
|
|
|
4703
4784
|
const jsdoc = this.jsdocScannerInfo();
|
|
4704
4785
|
const modifiers = this.parseModifiersEx(true, false, false);
|
|
4705
4786
|
if (this.token() === 85 /* SyntaxKind.ClassKeyword */)
|
|
4706
|
-
return this.parseClassDeclarationOrExpression(pos, jsdoc, modifiers,
|
|
4787
|
+
return this.parseClassDeclarationOrExpression(pos, jsdoc, modifiers, 233 /* SyntaxKind.ClassExpression */);
|
|
4707
4788
|
this.parseErrorAt(this.nodePos(), this.nodePos(), 78 /* Diagnostics.Expression_expected */);
|
|
4708
4789
|
return this.finishNode(new MissingDeclaration(modifiers), pos);
|
|
4709
4790
|
}
|
|
@@ -4776,7 +4857,7 @@ export class Parser extends ScannerErrorReporter {
|
|
|
4776
4857
|
// Identifiers
|
|
4777
4858
|
parseIdentifierNameErrorOnUnicodeEscapeSequence(use = 0 /* IdentifierUse.Reference */) {
|
|
4778
4859
|
if (this.scanner.hasUnicodeEscape() || this.scanner.hasExtendedUnicodeEscape())
|
|
4779
|
-
this.parseErrorAtCurrentToken(
|
|
4860
|
+
this.parseErrorAtCurrentToken(1844 /* Diagnostics.Unicode_escape_sequence_cannot_appear_here */);
|
|
4780
4861
|
return this.createIdentifier(tokenIsIdentifierOrKeyword(this.token()), use);
|
|
4781
4862
|
}
|
|
4782
4863
|
parseBindingIdentifier() {
|
|
@@ -4818,7 +4899,7 @@ export class Parser extends ScannerErrorReporter {
|
|
|
4818
4899
|
if (this.token() === 80 /* SyntaxKind.PrivateIdentifier */) {
|
|
4819
4900
|
this.parseErrorAtCurrentToken(privateIdentifierDiagnosticMessage !== undefined
|
|
4820
4901
|
? privateIdentifierDiagnosticMessage
|
|
4821
|
-
:
|
|
4902
|
+
: 1858 /* Diagnostics.Private_identifiers_are_not_allowed_outside_class_bodies */);
|
|
4822
4903
|
return this.createIdentifier(true, use);
|
|
4823
4904
|
}
|
|
4824
4905
|
// Report at the current position only at the end of the file: elsewhere the error would land
|
|
@@ -5268,14 +5349,14 @@ export class Parser extends ScannerErrorReporter {
|
|
|
5268
5349
|
const modifiers = modifierList.nodes;
|
|
5269
5350
|
if (canHaveIllegalDecorators(node)) {
|
|
5270
5351
|
for (const modifier of modifiers)
|
|
5271
|
-
if (modifier.kind ===
|
|
5352
|
+
if (modifier.kind === 172 /* SyntaxKind.Decorator */) {
|
|
5272
5353
|
this.jsErrorAt(modifier.pos, modifier.end, 160 /* Diagnostics.Decorators_are_not_valid_here */);
|
|
5273
5354
|
break;
|
|
5274
5355
|
}
|
|
5275
5356
|
}
|
|
5276
5357
|
else if (canHaveDecorators(node)) {
|
|
5277
|
-
const decoratorIndex = findKindIndex(modifiers,
|
|
5278
|
-
if (decoratorIndex >= 0 && node.kind ===
|
|
5358
|
+
const decoratorIndex = findKindIndex(modifiers, 172 /* SyntaxKind.Decorator */, 0);
|
|
5359
|
+
if (decoratorIndex >= 0 && node.kind === 265 /* SyntaxKind.ClassDeclaration */) {
|
|
5279
5360
|
const exportIndex = findKindIndex(modifiers, 94 /* SyntaxKind.ExportKeyword */, 0);
|
|
5280
5361
|
if (exportIndex >= 0) {
|
|
5281
5362
|
const defaultIndex = findKindIndex(modifiers, 89 /* SyntaxKind.DefaultKeyword */, 0);
|
|
@@ -5286,12 +5367,12 @@ export class Parser extends ScannerErrorReporter {
|
|
|
5286
5367
|
}
|
|
5287
5368
|
else if (decoratorIndex < exportIndex) {
|
|
5288
5369
|
// A trailing decorator after `export`.
|
|
5289
|
-
const trailingDecoratorIndex = findKindIndex(modifiers,
|
|
5370
|
+
const trailingDecoratorIndex = findKindIndex(modifiers, 172 /* SyntaxKind.Decorator */, exportIndex);
|
|
5290
5371
|
if (trailingDecoratorIndex >= 0) {
|
|
5291
5372
|
const trailing = modifiers[trailingDecoratorIndex];
|
|
5292
5373
|
const leading = modifiers[decoratorIndex];
|
|
5293
|
-
const diagnostic = new Diagnostic(undefined, skipTrivia(this.sourceText, trailing.pos), trailing.end,
|
|
5294
|
-
diagnostic.addRelatedInfo(new Diagnostic(undefined, skipTrivia(this.sourceText, leading.pos), leading.end,
|
|
5374
|
+
const diagnostic = new Diagnostic(undefined, skipTrivia(this.sourceText, trailing.pos), trailing.end, 1787 /* Diagnostics.Decorators_may_not_appear_after_export_or_export_default_if_they_also_appear_before_export */, noArgs);
|
|
5375
|
+
diagnostic.addRelatedInfo(new Diagnostic(undefined, skipTrivia(this.sourceText, leading.pos), leading.end, 399 /* Diagnostics.Decorator_used_before_export_here */, noArgs));
|
|
5295
5376
|
this.jsDiagnostics.push(diagnostic);
|
|
5296
5377
|
}
|
|
5297
5378
|
}
|
|
@@ -5304,150 +5385,150 @@ export class Parser extends ScannerErrorReporter {
|
|
|
5304
5385
|
if ((node.flags & 65536 /* NodeFlags.JavaScriptFile */) === 0 || (node.flags & (4194304 /* NodeFlags.JSDoc */ | 8 /* NodeFlags.Reparsed */)) !== 0)
|
|
5305
5386
|
return node;
|
|
5306
5387
|
switch (node.kind) {
|
|
5307
|
-
case
|
|
5308
|
-
case
|
|
5309
|
-
case
|
|
5310
|
-
case
|
|
5311
|
-
case
|
|
5312
|
-
case
|
|
5313
|
-
case
|
|
5314
|
-
case
|
|
5315
|
-
case
|
|
5316
|
-
case
|
|
5317
|
-
case
|
|
5318
|
-
case
|
|
5319
|
-
if (node.kind ===
|
|
5320
|
-
node.kind ===
|
|
5321
|
-
node.kind ===
|
|
5388
|
+
case 171 /* SyntaxKind.Parameter */:
|
|
5389
|
+
case 174 /* SyntaxKind.PropertyDeclaration */:
|
|
5390
|
+
case 176 /* SyntaxKind.MethodDeclaration */:
|
|
5391
|
+
case 175 /* SyntaxKind.MethodSignature */:
|
|
5392
|
+
case 178 /* SyntaxKind.Constructor */:
|
|
5393
|
+
case 179 /* SyntaxKind.GetAccessor */:
|
|
5394
|
+
case 180 /* SyntaxKind.SetAccessor */:
|
|
5395
|
+
case 220 /* SyntaxKind.FunctionExpression */:
|
|
5396
|
+
case 264 /* SyntaxKind.FunctionDeclaration */:
|
|
5397
|
+
case 221 /* SyntaxKind.ArrowFunction */:
|
|
5398
|
+
case 262 /* SyntaxKind.VariableDeclaration */:
|
|
5399
|
+
case 183 /* SyntaxKind.IndexSignature */: {
|
|
5400
|
+
if (node.kind === 171 /* SyntaxKind.Parameter */ ||
|
|
5401
|
+
node.kind === 174 /* SyntaxKind.PropertyDeclaration */ ||
|
|
5402
|
+
node.kind === 176 /* SyntaxKind.MethodDeclaration */) {
|
|
5322
5403
|
const token = getQuestionTokenOfNode(node);
|
|
5323
5404
|
if (token !== undefined &&
|
|
5324
5405
|
(token.flags & 8 /* NodeFlags.Reparsed */) === 0 &&
|
|
5325
5406
|
token.kind === 57 /* SyntaxKind.QuestionToken */)
|
|
5326
|
-
this.jsErrorAt(token.pos, token.end,
|
|
5407
|
+
this.jsErrorAt(token.pos, token.end, 1761 /* Diagnostics.The_0_modifier_can_only_be_used_in_TypeScript_files */, [
|
|
5327
5408
|
'?',
|
|
5328
5409
|
]);
|
|
5329
5410
|
}
|
|
5330
5411
|
const type = getType(node);
|
|
5331
5412
|
if (isFunctionLike(node) && getBody(node) === undefined)
|
|
5332
|
-
this.jsErrorAt(node.pos, node.end,
|
|
5413
|
+
this.jsErrorAt(node.pos, node.end, 1767 /* Diagnostics.Signature_declarations_can_only_be_used_in_TypeScript_files */);
|
|
5333
5414
|
else if (type !== undefined && (type.flags & 8 /* NodeFlags.Reparsed */) === 0)
|
|
5334
|
-
this.jsErrorAt(type.pos, type.end,
|
|
5415
|
+
this.jsErrorAt(type.pos, type.end, 1762 /* Diagnostics.Type_annotations_can_only_be_used_in_TypeScript_files */);
|
|
5335
5416
|
break;
|
|
5336
5417
|
}
|
|
5337
|
-
case
|
|
5418
|
+
case 274 /* SyntaxKind.ImportDeclaration */:
|
|
5338
5419
|
if (node instanceof ImportDeclaration) {
|
|
5339
5420
|
const clause = node.importClause;
|
|
5340
5421
|
if (clause !== undefined && clause.phaseModifier === 156 /* SyntaxKind.TypeKeyword */)
|
|
5341
|
-
this.jsErrorAt(node.pos, node.end,
|
|
5422
|
+
this.jsErrorAt(node.pos, node.end, 1759 /* Diagnostics.X_0_declarations_can_only_be_used_in_TypeScript_files */, ['import type']);
|
|
5342
5423
|
}
|
|
5343
5424
|
break;
|
|
5344
|
-
case
|
|
5425
|
+
case 280 /* SyntaxKind.ExportDeclaration */:
|
|
5345
5426
|
if (getIsTypeOnly(node))
|
|
5346
|
-
this.jsErrorAt(node.pos, node.end,
|
|
5427
|
+
this.jsErrorAt(node.pos, node.end, 1759 /* Diagnostics.X_0_declarations_can_only_be_used_in_TypeScript_files */, [
|
|
5347
5428
|
'export type',
|
|
5348
5429
|
]);
|
|
5349
5430
|
break;
|
|
5350
|
-
case
|
|
5431
|
+
case 278 /* SyntaxKind.ImportSpecifier */:
|
|
5351
5432
|
if (getIsTypeOnly(node))
|
|
5352
|
-
this.jsErrorAt(node.pos, node.end,
|
|
5433
|
+
this.jsErrorAt(node.pos, node.end, 1759 /* Diagnostics.X_0_declarations_can_only_be_used_in_TypeScript_files */, [
|
|
5353
5434
|
'import...type',
|
|
5354
5435
|
]);
|
|
5355
5436
|
break;
|
|
5356
|
-
case
|
|
5437
|
+
case 283 /* SyntaxKind.ExportSpecifier */:
|
|
5357
5438
|
if (getIsTypeOnly(node))
|
|
5358
|
-
this.jsErrorAt(node.pos, node.end,
|
|
5439
|
+
this.jsErrorAt(node.pos, node.end, 1759 /* Diagnostics.X_0_declarations_can_only_be_used_in_TypeScript_files */, [
|
|
5359
5440
|
'export...type',
|
|
5360
5441
|
]);
|
|
5361
5442
|
break;
|
|
5362
|
-
case
|
|
5363
|
-
this.jsErrorAt(node.pos, node.end,
|
|
5443
|
+
case 273 /* SyntaxKind.ImportEqualsDeclaration */:
|
|
5444
|
+
this.jsErrorAt(node.pos, node.end, 1755 /* Diagnostics.X_import_can_only_be_used_in_TypeScript_files */);
|
|
5364
5445
|
break;
|
|
5365
|
-
case
|
|
5446
|
+
case 279 /* SyntaxKind.ExportAssignment */:
|
|
5366
5447
|
if (node instanceof ExportAssignment && node.isExportEquals)
|
|
5367
|
-
this.jsErrorAt(node.pos, node.end,
|
|
5448
|
+
this.jsErrorAt(node.pos, node.end, 1756 /* Diagnostics.X_export_can_only_be_used_in_TypeScript_files */);
|
|
5368
5449
|
break;
|
|
5369
|
-
case
|
|
5450
|
+
case 300 /* SyntaxKind.HeritageClause */:
|
|
5370
5451
|
if (node instanceof HeritageClause && node.token === 118 /* SyntaxKind.ImplementsKeyword */)
|
|
5371
|
-
this.jsErrorAt(node.pos, node.end,
|
|
5452
|
+
this.jsErrorAt(node.pos, node.end, 1758 /* Diagnostics.X_implements_clauses_can_only_be_used_in_TypeScript_files */);
|
|
5372
5453
|
break;
|
|
5373
|
-
case
|
|
5454
|
+
case 266 /* SyntaxKind.InterfaceDeclaration */: {
|
|
5374
5455
|
const name = getName(node);
|
|
5375
|
-
this.jsErrorAt(name.pos, name.end,
|
|
5456
|
+
this.jsErrorAt(name.pos, name.end, 1759 /* Diagnostics.X_0_declarations_can_only_be_used_in_TypeScript_files */, [
|
|
5376
5457
|
'interface',
|
|
5377
5458
|
]);
|
|
5378
5459
|
break;
|
|
5379
5460
|
}
|
|
5380
|
-
case
|
|
5461
|
+
case 269 /* SyntaxKind.ModuleDeclaration */:
|
|
5381
5462
|
if (node instanceof ModuleDeclaration)
|
|
5382
|
-
this.jsErrorAt(node.name.pos, node.name.end,
|
|
5463
|
+
this.jsErrorAt(node.name.pos, node.name.end, 1759 /* Diagnostics.X_0_declarations_can_only_be_used_in_TypeScript_files */, [tokenToString(node.keyword)]);
|
|
5383
5464
|
break;
|
|
5384
|
-
case
|
|
5465
|
+
case 267 /* SyntaxKind.TypeAliasDeclaration */: {
|
|
5385
5466
|
const name = getName(node);
|
|
5386
|
-
this.jsErrorAt(name.pos, name.end,
|
|
5467
|
+
this.jsErrorAt(name.pos, name.end, 1760 /* Diagnostics.Type_aliases_can_only_be_used_in_TypeScript_files */);
|
|
5387
5468
|
break;
|
|
5388
5469
|
}
|
|
5389
|
-
case
|
|
5470
|
+
case 268 /* SyntaxKind.EnumDeclaration */: {
|
|
5390
5471
|
const name = getName(node);
|
|
5391
|
-
this.jsErrorAt(name.pos, name.end,
|
|
5472
|
+
this.jsErrorAt(name.pos, name.end, 1759 /* Diagnostics.X_0_declarations_can_only_be_used_in_TypeScript_files */, ['enum']);
|
|
5392
5473
|
break;
|
|
5393
5474
|
}
|
|
5394
|
-
case
|
|
5395
|
-
this.jsErrorAt(node.pos, node.end,
|
|
5475
|
+
case 237 /* SyntaxKind.NonNullExpression */:
|
|
5476
|
+
this.jsErrorAt(node.pos, node.end, 1765 /* Diagnostics.Non_null_assertions_can_only_be_used_in_TypeScript_files */);
|
|
5396
5477
|
break;
|
|
5397
|
-
case
|
|
5478
|
+
case 236 /* SyntaxKind.AsExpression */: {
|
|
5398
5479
|
const type = getType(node);
|
|
5399
|
-
this.jsErrorAt(type.pos, type.end,
|
|
5480
|
+
this.jsErrorAt(type.pos, type.end, 1766 /* Diagnostics.Type_assertion_expressions_can_only_be_used_in_TypeScript_files */);
|
|
5400
5481
|
break;
|
|
5401
5482
|
}
|
|
5402
|
-
case
|
|
5483
|
+
case 240 /* SyntaxKind.SatisfiesExpression */: {
|
|
5403
5484
|
const type = getType(node);
|
|
5404
|
-
this.jsErrorAt(type.pos, type.end,
|
|
5485
|
+
this.jsErrorAt(type.pos, type.end, 1786 /* Diagnostics.Type_satisfaction_expressions_can_only_be_used_in_TypeScript_files */);
|
|
5405
5486
|
break;
|
|
5406
5487
|
}
|
|
5407
5488
|
}
|
|
5408
5489
|
this.checkJSDecoratorSyntax(node);
|
|
5409
5490
|
// Type parameters, type arguments and TypeScript-only modifiers.
|
|
5410
5491
|
switch (node.kind) {
|
|
5411
|
-
case
|
|
5412
|
-
case
|
|
5413
|
-
case
|
|
5414
|
-
case
|
|
5415
|
-
case
|
|
5416
|
-
case
|
|
5417
|
-
case
|
|
5418
|
-
case
|
|
5419
|
-
case
|
|
5420
|
-
case
|
|
5421
|
-
case
|
|
5422
|
-
if (node.kind !==
|
|
5492
|
+
case 265 /* SyntaxKind.ClassDeclaration */:
|
|
5493
|
+
case 233 /* SyntaxKind.ClassExpression */:
|
|
5494
|
+
case 176 /* SyntaxKind.MethodDeclaration */:
|
|
5495
|
+
case 178 /* SyntaxKind.Constructor */:
|
|
5496
|
+
case 179 /* SyntaxKind.GetAccessor */:
|
|
5497
|
+
case 180 /* SyntaxKind.SetAccessor */:
|
|
5498
|
+
case 220 /* SyntaxKind.FunctionExpression */:
|
|
5499
|
+
case 264 /* SyntaxKind.FunctionDeclaration */:
|
|
5500
|
+
case 221 /* SyntaxKind.ArrowFunction */:
|
|
5501
|
+
case 245 /* SyntaxKind.VariableStatement */:
|
|
5502
|
+
case 174 /* SyntaxKind.PropertyDeclaration */: {
|
|
5503
|
+
if (node.kind !== 245 /* SyntaxKind.VariableStatement */ && node.kind !== 174 /* SyntaxKind.PropertyDeclaration */) {
|
|
5423
5504
|
const list = getTypeParameters(node);
|
|
5424
5505
|
if (list !== undefined && hasNonReparsedNode(list.nodes))
|
|
5425
|
-
this.jsErrorAt(list.pos, list.end,
|
|
5506
|
+
this.jsErrorAt(list.pos, list.end, 1757 /* Diagnostics.Type_parameter_declarations_can_only_be_used_in_TypeScript_files */);
|
|
5426
5507
|
}
|
|
5427
5508
|
const modifiers = getModifiers(node);
|
|
5428
5509
|
if (modifiers !== undefined)
|
|
5429
5510
|
for (const modifier of modifiers.nodes)
|
|
5430
5511
|
if ((modifier.flags & 8 /* NodeFlags.Reparsed */) === 0 &&
|
|
5431
|
-
modifier.kind !==
|
|
5512
|
+
modifier.kind !== 172 /* SyntaxKind.Decorator */ &&
|
|
5432
5513
|
(modifierToFlag(modifier.kind) & 3872 /* ModifierFlags.JavaScript */) === 0)
|
|
5433
|
-
this.jsErrorAt(modifier.pos, modifier.end,
|
|
5514
|
+
this.jsErrorAt(modifier.pos, modifier.end, 1761 /* Diagnostics.The_0_modifier_can_only_be_used_in_TypeScript_files */, [tokenToString(modifier.kind)]);
|
|
5434
5515
|
break;
|
|
5435
5516
|
}
|
|
5436
|
-
case
|
|
5517
|
+
case 171 /* SyntaxKind.Parameter */: {
|
|
5437
5518
|
const modifiers = getModifiers(node);
|
|
5438
5519
|
if (modifiers !== undefined && hasModifierNode(modifiers.nodes))
|
|
5439
|
-
this.jsErrorAt(modifiers.pos, modifiers.end,
|
|
5520
|
+
this.jsErrorAt(modifiers.pos, modifiers.end, 1764 /* Diagnostics.Parameter_modifiers_can_only_be_used_in_TypeScript_files */);
|
|
5440
5521
|
break;
|
|
5441
5522
|
}
|
|
5442
|
-
case
|
|
5443
|
-
case
|
|
5444
|
-
case
|
|
5445
|
-
case
|
|
5446
|
-
case
|
|
5447
|
-
case
|
|
5523
|
+
case 215 /* SyntaxKind.CallExpression */:
|
|
5524
|
+
case 216 /* SyntaxKind.NewExpression */:
|
|
5525
|
+
case 235 /* SyntaxKind.ExpressionWithTypeArguments */:
|
|
5526
|
+
case 287 /* SyntaxKind.JsxSelfClosingElement */:
|
|
5527
|
+
case 288 /* SyntaxKind.JsxOpeningElement */:
|
|
5528
|
+
case 217 /* SyntaxKind.TaggedTemplateExpression */: {
|
|
5448
5529
|
const list = getTypeArguments(node);
|
|
5449
5530
|
if (list !== undefined && hasNonReparsedNode(list.nodes))
|
|
5450
|
-
this.jsErrorAt(list.pos, list.end,
|
|
5531
|
+
this.jsErrorAt(list.pos, list.end, 1763 /* Diagnostics.Type_arguments_can_only_be_used_in_TypeScript_files */);
|
|
5451
5532
|
break;
|
|
5452
5533
|
}
|
|
5453
5534
|
}
|
|
@@ -5521,7 +5602,9 @@ export class Parser extends ScannerErrorReporter {
|
|
|
5521
5602
|
return result;
|
|
5522
5603
|
}
|
|
5523
5604
|
jsonError(node, message) {
|
|
5524
|
-
|
|
5605
|
+
// A missing node (a property without a value) keeps its position: trivia after it isn't its own.
|
|
5606
|
+
const pos = nodeIsMissing(node) ? node.pos : skipTrivia(this.sourceText, node.pos);
|
|
5607
|
+
this.diagnostics.push(new Diagnostic(undefined, pos, node.end, message, noArgs));
|
|
5525
5608
|
}
|
|
5526
5609
|
validateJsonValue(sourceFile, value) {
|
|
5527
5610
|
switch (value.kind) {
|
|
@@ -5534,17 +5617,17 @@ export class Parser extends ScannerErrorReporter {
|
|
|
5534
5617
|
if (!isDoubleQuotedString(value))
|
|
5535
5618
|
this.jsonError(value, 263 /* Diagnostics.String_literal_with_double_quotes_expected */);
|
|
5536
5619
|
return;
|
|
5537
|
-
case
|
|
5620
|
+
case 226 /* SyntaxKind.PrefixUnaryExpression */:
|
|
5538
5621
|
if (value instanceof PrefixUnaryExpression &&
|
|
5539
5622
|
value.operator === 40 /* SyntaxKind.MinusToken */ &&
|
|
5540
5623
|
value.operand.kind === 8 /* SyntaxKind.NumericLiteral */)
|
|
5541
5624
|
return;
|
|
5542
5625
|
break;
|
|
5543
|
-
case
|
|
5626
|
+
case 212 /* SyntaxKind.ObjectLiteralExpression */:
|
|
5544
5627
|
if (value instanceof ObjectLiteralExpression)
|
|
5545
5628
|
this.validateJsonObjectLiteral(sourceFile, value);
|
|
5546
5629
|
return;
|
|
5547
|
-
case
|
|
5630
|
+
case 211 /* SyntaxKind.ArrayLiteralExpression */:
|
|
5548
5631
|
if (value instanceof ArrayLiteralExpression)
|
|
5549
5632
|
for (const element of value.elements.nodes)
|
|
5550
5633
|
this.validateJsonValue(sourceFile, element);
|
|
@@ -5705,7 +5788,7 @@ export function getAttachedJSDoc(node) {
|
|
|
5705
5788
|
break;
|
|
5706
5789
|
root = parent;
|
|
5707
5790
|
}
|
|
5708
|
-
if (root.kind !==
|
|
5791
|
+
if (root.kind !== 308 /* SyntaxKind.SourceFile */)
|
|
5709
5792
|
return undefined;
|
|
5710
5793
|
const jsDocs = root.jsDocs;
|
|
5711
5794
|
const attached = jsDocs === undefined ? undefined : jsDocs.get(node.id);
|
|
@@ -5861,6 +5944,15 @@ function nextTokenIsIdentifier(p) {
|
|
|
5861
5944
|
function nextTokenIsOpenParen(p) {
|
|
5862
5945
|
return p.nextToken() === 20 /* SyntaxKind.OpenParenToken */;
|
|
5863
5946
|
}
|
|
5947
|
+
/** An identifier or a chain of property accesses without optional chaining, each name present. */
|
|
5948
|
+
function isValidHeritageTypeReferenceExpression(node) {
|
|
5949
|
+
if (node instanceof Identifier)
|
|
5950
|
+
return nodeIsPresent(node);
|
|
5951
|
+
if (!(node instanceof PropertyAccessExpression) || (node.flags & 32 /* NodeFlags.OptionalChain */) !== 0)
|
|
5952
|
+
return false;
|
|
5953
|
+
return (nodeIsPresent(node.name) &&
|
|
5954
|
+
isValidHeritageTypeReferenceExpression(node.expression));
|
|
5955
|
+
}
|
|
5864
5956
|
function nextTokenIsOpenBrace(p) {
|
|
5865
5957
|
return p.nextToken() === 18 /* SyntaxKind.OpenBraceToken */;
|
|
5866
5958
|
}
|
|
@@ -6297,7 +6389,7 @@ class PositionFinder extends NodeVisitor {
|
|
|
6297
6389
|
}
|
|
6298
6390
|
}
|
|
6299
6391
|
function nodeContainsPosition(node, position) {
|
|
6300
|
-
return (node.kind >=
|
|
6392
|
+
return (node.kind >= 168 /* SyntaxKind.FirstNode */ &&
|
|
6301
6393
|
node.pos <= position &&
|
|
6302
6394
|
(position < node.end || (position === node.end && node.kind === 1 /* SyntaxKind.EndOfFile */)));
|
|
6303
6395
|
}
|
|
@@ -6324,7 +6416,7 @@ export function getNodeAtPosition(file, position, includeJSDoc) {
|
|
|
6324
6416
|
current.forEachChild(finder);
|
|
6325
6417
|
child = finder.found;
|
|
6326
6418
|
}
|
|
6327
|
-
if (child === undefined || child.kind ===
|
|
6419
|
+
if (child === undefined || child.kind === 238 /* SyntaxKind.MetaProperty */)
|
|
6328
6420
|
return current;
|
|
6329
6421
|
current = child;
|
|
6330
6422
|
}
|
|
@@ -6332,9 +6424,9 @@ export function getNodeAtPosition(file, position, includeJSDoc) {
|
|
|
6332
6424
|
class JsxTagFinder extends NodeVisitor {
|
|
6333
6425
|
found = undefined;
|
|
6334
6426
|
visitNode(node) {
|
|
6335
|
-
if (node.kind ===
|
|
6336
|
-
node.kind ===
|
|
6337
|
-
node.kind ===
|
|
6427
|
+
if (node.kind === 288 /* SyntaxKind.JsxOpeningElement */ ||
|
|
6428
|
+
node.kind === 287 /* SyntaxKind.JsxSelfClosingElement */ ||
|
|
6429
|
+
node.kind === 290 /* SyntaxKind.JsxFragment */) {
|
|
6338
6430
|
this.found = node;
|
|
6339
6431
|
return true;
|
|
6340
6432
|
}
|
|
@@ -6354,10 +6446,10 @@ class ImportMetaFinder extends NodeVisitor {
|
|
|
6354
6446
|
function isAnExternalModuleIndicatorNode(node) {
|
|
6355
6447
|
return (hasModifierFlag(node, 32 /* ModifierFlags.Export */) ||
|
|
6356
6448
|
(node instanceof ImportEqualsDeclaration &&
|
|
6357
|
-
node.moduleReference.kind ===
|
|
6358
|
-
node.kind ===
|
|
6359
|
-
node.kind ===
|
|
6360
|
-
node.kind ===
|
|
6449
|
+
node.moduleReference.kind === 285 /* SyntaxKind.ExternalModuleReference */) ||
|
|
6450
|
+
node.kind === 274 /* SyntaxKind.ImportDeclaration */ ||
|
|
6451
|
+
node.kind === 279 /* SyntaxKind.ExportAssignment */ ||
|
|
6452
|
+
node.kind === 280 /* SyntaxKind.ExportDeclaration */);
|
|
6361
6453
|
}
|
|
6362
6454
|
function getExternalModuleIndicator(file) {
|
|
6363
6455
|
if (file.scriptKind === 6 /* ScriptKind.JSON */)
|
|
@@ -6394,7 +6486,7 @@ export function isNodeCoreModule(moduleName) {
|
|
|
6394
6486
|
(moduleName.startsWith('node:') && unprefixedNodeCoreModules.has(moduleName.substring(5))));
|
|
6395
6487
|
}
|
|
6396
6488
|
// `require('module').builtinModules`, without and with only the `node:` prefix.
|
|
6397
|
-
const unprefixedNodeCoreModules = new Set([
|
|
6489
|
+
export const unprefixedNodeCoreModules = new Set([
|
|
6398
6490
|
'assert',
|
|
6399
6491
|
'assert/strict',
|
|
6400
6492
|
'async_hooks',
|
|
@@ -6450,7 +6542,7 @@ const unprefixedNodeCoreModules = new Set([
|
|
|
6450
6542
|
'worker_threads',
|
|
6451
6543
|
'zlib',
|
|
6452
6544
|
]);
|
|
6453
|
-
const exclusivelyPrefixedNodeCoreModules = new Set([
|
|
6545
|
+
export const exclusivelyPrefixedNodeCoreModules = new Set([
|
|
6454
6546
|
'node:quic',
|
|
6455
6547
|
'node:sea',
|
|
6456
6548
|
'node:sqlite',
|