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