tsc-ts 0.0.9 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- 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 +22 -15
- package/dist/api/compiler/ast.js +1026 -995
- package/dist/api/compiler/astnav.js +15 -15
- package/dist/api/compiler/binder-utilities.js +186 -186
- package/dist/api/compiler/binder.js +290 -263
- package/dist/api/compiler/character-codes.js +2 -2
- package/dist/api/compiler/checker-calls.js +178 -124
- package/dist/api/compiler/checker-classes.d.ts +14 -3
- package/dist/api/compiler/checker-classes.js +134 -90
- package/dist/api/compiler/checker-contextual.js +64 -61
- package/dist/api/compiler/checker-declaration-order.js +79 -79
- package/dist/api/compiler/checker-declarations.d.ts +1 -0
- package/dist/api/compiler/checker-declarations.js +160 -136
- package/dist/api/compiler/checker-declared-types.js +67 -65
- package/dist/api/compiler/checker-decorators.js +77 -77
- package/dist/api/compiler/checker-deprecation.d.ts +8 -3
- package/dist/api/compiler/checker-deprecation.js +76 -55
- package/dist/api/compiler/checker-destructuring.js +47 -45
- package/dist/api/compiler/checker-elaboration.js +24 -24
- package/dist/api/compiler/checker-emit-helpers.js +4 -4
- package/dist/api/compiler/checker-emit-resolver.d.ts +4 -2
- package/dist/api/compiler/checker-emit-resolver.js +25 -13
- package/dist/api/compiler/checker-evaluator.js +9 -9
- package/dist/api/compiler/checker-expressions.js +244 -211
- package/dist/api/compiler/checker-functions.js +113 -107
- package/dist/api/compiler/checker-generated-code.d.ts +0 -11
- package/dist/api/compiler/checker-generated-code.js +28 -52
- package/dist/api/compiler/checker-grammar.d.ts +1 -0
- package/dist/api/compiler/checker-grammar.js +472 -440
- 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 -107
- package/dist/api/compiler/checker-iteration.d.ts +0 -10
- package/dist/api/compiler/checker-iteration.js +35 -52
- package/dist/api/compiler/checker-javascript.js +14 -14
- package/dist/api/compiler/checker-jsdoc.d.ts +8 -10
- package/dist/api/compiler/checker-jsdoc.js +67 -58
- package/dist/api/compiler/checker-jsx.js +105 -88
- package/dist/api/compiler/checker-members.d.ts +9 -2
- package/dist/api/compiler/checker-members.js +212 -75
- 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 +145 -36
- 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 +104 -31
- package/dist/api/compiler/checker.js +181 -33
- 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 +42 -3
- package/dist/api/compiler/compile-program.js +139 -27
- package/dist/api/compiler/diagnostic-messages.d.ts +1849 -1774
- package/dist/api/compiler/diagnostic-messages.js +128 -122
- package/dist/api/compiler/diagnostics.d.ts +22 -0
- package/dist/api/compiler/diagnostics.js +93 -11
- package/dist/api/compiler/emitter.d.ts +7 -1
- package/dist/api/compiler/emitter.js +53 -11
- package/dist/api/compiler/file-include.d.ts +2 -1
- package/dist/api/compiler/file-include.js +11 -7
- package/dist/api/compiler/file-loader.d.ts +21 -1
- package/dist/api/compiler/file-loader.js +201 -48
- package/dist/api/compiler/instantiation.d.ts +7 -0
- package/dist/api/compiler/instantiation.js +101 -49
- package/dist/api/compiler/jsdoc.js +23 -23
- package/dist/api/compiler/link-tables.d.ts +48 -18
- package/dist/api/compiler/link-tables.js +80 -37
- package/dist/api/compiler/locales/cs-CZ.d.ts +1 -1
- package/dist/api/compiler/locales/cs-CZ.js +1 -1
- package/dist/api/compiler/locales/de-DE.d.ts +1 -1
- package/dist/api/compiler/locales/de-DE.js +1 -1
- package/dist/api/compiler/locales/es-ES.d.ts +1 -1
- package/dist/api/compiler/locales/es-ES.js +1 -1
- package/dist/api/compiler/locales/fr-FR.d.ts +1 -1
- package/dist/api/compiler/locales/fr-FR.js +1 -1
- package/dist/api/compiler/locales/it-IT.d.ts +1 -1
- package/dist/api/compiler/locales/it-IT.js +1 -1
- package/dist/api/compiler/locales/ja-JP.d.ts +1 -1
- package/dist/api/compiler/locales/ja-JP.js +1 -1
- package/dist/api/compiler/locales/ko-KR.d.ts +1 -1
- package/dist/api/compiler/locales/ko-KR.js +1 -1
- package/dist/api/compiler/locales/pl-PL.d.ts +1 -1
- package/dist/api/compiler/locales/pl-PL.js +1 -1
- package/dist/api/compiler/locales/pt-BR.d.ts +1 -1
- package/dist/api/compiler/locales/pt-BR.js +1 -1
- package/dist/api/compiler/locales/ru-RU.d.ts +1 -1
- package/dist/api/compiler/locales/ru-RU.js +1 -1
- package/dist/api/compiler/locales/tr-TR.d.ts +1 -1
- package/dist/api/compiler/locales/tr-TR.js +1 -1
- package/dist/api/compiler/locales/zh-CN.d.ts +1 -1
- package/dist/api/compiler/locales/zh-CN.js +1 -1
- package/dist/api/compiler/locales/zh-TW.d.ts +1 -1
- package/dist/api/compiler/locales/zh-TW.js +1 -1
- package/dist/api/compiler/module-resolution-types.js +6 -6
- package/dist/api/compiler/module-resolution.d.ts +10 -1
- package/dist/api/compiler/module-resolution.js +115 -84
- package/dist/api/compiler/module-specifiers.d.ts +15 -0
- package/dist/api/compiler/module-specifiers.js +24 -18
- package/dist/api/compiler/name-resolver.js +74 -65
- package/dist/api/compiler/node-builder-names.d.ts +11 -3
- package/dist/api/compiler/node-builder-names.js +210 -90
- package/dist/api/compiler/node-builder-pseudo.js +29 -31
- package/dist/api/compiler/node-builder-reuse.js +23 -22
- package/dist/api/compiler/node-builder.d.ts +18 -1
- package/dist/api/compiler/node-builder.js +191 -102
- package/dist/api/compiler/option-declarations.d.ts +2 -6
- package/dist/api/compiler/option-declarations.js +315 -375
- package/dist/api/compiler/options.d.ts +15 -33
- package/dist/api/compiler/options.js +21 -54
- package/dist/api/compiler/output-paths.d.ts +4 -1
- package/dist/api/compiler/output-paths.js +6 -11
- package/dist/api/compiler/package-json.d.ts +3 -3
- package/dist/api/compiler/package-json.js +11 -10
- package/dist/api/compiler/parallel-parse.d.ts +3 -2
- package/dist/api/compiler/parallel-parse.js +17 -5
- package/dist/api/compiler/parser.d.ts +40 -19
- package/dist/api/compiler/parser.js +308 -216
- package/dist/api/compiler/path.d.ts +9 -0
- package/dist/api/compiler/path.js +20 -3
- package/dist/api/compiler/printer/emit-context.d.ts +5 -1
- package/dist/api/compiler/printer/emit-context.js +20 -1
- package/dist/api/compiler/printer/factory-base.d.ts +2 -2
- package/dist/api/compiler/printer/factory-base.js +7 -3
- package/dist/api/compiler/printer/factory.js +3 -1
- package/dist/api/compiler/printer/helpers.js +10 -1
- package/dist/api/compiler/printer/name-generator.d.ts +1 -1
- package/dist/api/compiler/printer/name-generator.js +35 -16
- package/dist/api/compiler/printer/printer.d.ts +49 -2
- package/dist/api/compiler/printer/printer.js +539 -293
- package/dist/api/compiler/printer/utilities.js +149 -147
- package/dist/api/compiler/program-checker.d.ts +12 -2
- package/dist/api/compiler/program-checker.js +88 -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 +4 -6
- package/dist/api/compiler/program.js +74 -87
- 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 +347 -180
- package/dist/api/compiler/reparser.js +60 -56
- package/dist/api/compiler/scanner.d.ts +19 -2
- package/dist/api/compiler/scanner.js +123 -108
- package/dist/api/compiler/shared-results.d.ts +463 -0
- package/dist/api/compiler/shared-results.js +2128 -0
- package/dist/api/compiler/sourcemap.js +2 -2
- package/dist/api/compiler/symbol-accessibility.js +87 -74
- package/dist/api/compiler/symbol.d.ts +23 -14
- package/dist/api/compiler/symbol.js +23 -11
- package/dist/api/compiler/syntax-kind.d.ts +198 -197
- package/dist/api/compiler/transformers/alias-references.js +247 -139
- package/dist/api/compiler/transformers/async-utilities.js +25 -25
- package/dist/api/compiler/transformers/async.d.ts +0 -1
- package/dist/api/compiler/transformers/async.js +64 -77
- package/dist/api/compiler/transformers/class-fields.d.ts +1 -0
- package/dist/api/compiler/transformers/class-fields.js +81 -78
- package/dist/api/compiler/transformers/commonjs-module.js +18 -15
- package/dist/api/compiler/transformers/const-enum-inliner.js +1 -1
- package/dist/api/compiler/transformers/declarations-diagnostics.js +247 -244
- package/dist/api/compiler/transformers/declarations-pseudo.js +100 -100
- package/dist/api/compiler/transformers/declarations-resolver.d.ts +0 -3
- package/dist/api/compiler/transformers/declarations-syntactic.d.ts +1 -2
- package/dist/api/compiler/transformers/declarations-syntactic.js +134 -156
- package/dist/api/compiler/transformers/declarations-tracker.js +18 -18
- package/dist/api/compiler/transformers/declarations.d.ts +4 -1
- package/dist/api/compiler/transformers/declarations.js +305 -238
- package/dist/api/compiler/transformers/decorator-metadata.d.ts +1 -1
- package/dist/api/compiler/transformers/decorator-metadata.js +53 -45
- package/dist/api/compiler/transformers/decorator-utilities.js +24 -24
- package/dist/api/compiler/transformers/destructuring.js +19 -18
- package/dist/api/compiler/transformers/emit-resolver.js +1 -1
- package/dist/api/compiler/transformers/es-decorators.js +55 -55
- package/dist/api/compiler/transformers/external-module-info.js +3 -3
- package/dist/api/compiler/transformers/for-await.js +25 -25
- package/dist/api/compiler/transformers/import-elision.js +14 -14
- package/dist/api/compiler/transformers/jsx.js +12 -12
- package/dist/api/compiler/transformers/legacy-decorators.js +17 -17
- package/dist/api/compiler/transformers/module.js +8 -8
- package/dist/api/compiler/transformers/named-evaluation.js +4 -4
- package/dist/api/compiler/transformers/object-rest-spread.js +20 -20
- package/dist/api/compiler/transformers/optional-chain.js +10 -10
- package/dist/api/compiler/transformers/reference-resolver.d.ts +12 -1
- package/dist/api/compiler/transformers/reference-resolver.js +131 -69
- package/dist/api/compiler/transformers/runtime-syntax.js +35 -31
- package/dist/api/compiler/transformers/subtree-facts.js +47 -47
- package/dist/api/compiler/transformers/syntax-facts.js +56 -58
- package/dist/api/compiler/transformers/type-eraser.js +73 -66
- package/dist/api/compiler/transformers/type-serialization.js +24 -24
- package/dist/api/compiler/transformers/using.js +12 -12
- package/dist/api/compiler/transformers/utilities.js +77 -77
- package/dist/api/compiler/transformers/visitor-base.js +172 -172
- package/dist/api/compiler/transformers/visitor-hooks.js +6 -2
- package/dist/api/compiler/tsconfig.d.ts +10 -2
- package/dist/api/compiler/tsconfig.js +136 -48
- package/dist/api/compiler/type-printer.js +40 -3
- package/dist/api/compiler/types.d.ts +2 -1
- package/dist/api/library/ast.generated.d.ts +42 -39
- package/dist/api/library/ast.generated.js +1 -1
- package/dist/api/library/compiler-options.generated.d.ts +111 -100
- package/dist/api/library/compiler-options.generated.js +1 -1
- package/dist/api/library/disk.js +12 -1
- package/dist/api/library/enums.generated.d.ts +206 -206
- package/dist/api/library/enums.generated.js +206 -206
- package/dist/api/library/nodes.js +26 -26
- package/package.json +9 -9
- package/src/compiler/ast-utilities.ts +99 -7
- package/src/compiler/ast.ts +58 -26
- package/src/compiler/binder.ts +39 -4
- package/src/compiler/character-codes.ts +2 -2
- package/src/compiler/checker-calls.ts +79 -9
- package/src/compiler/checker-classes.ts +78 -24
- package/src/compiler/checker-contextual.ts +6 -1
- package/src/compiler/checker-declarations.ts +31 -4
- package/src/compiler/checker-declared-types.ts +8 -5
- package/src/compiler/checker-decorators.ts +1 -1
- package/src/compiler/checker-deprecation.ts +29 -8
- package/src/compiler/checker-destructuring.ts +10 -3
- package/src/compiler/checker-emit-helpers.ts +1 -0
- package/src/compiler/checker-emit-resolver.ts +16 -6
- package/src/compiler/checker-expressions.ts +79 -46
- package/src/compiler/checker-functions.ts +21 -6
- package/src/compiler/checker-generated-code.ts +2 -22
- package/src/compiler/checker-grammar.ts +136 -62
- package/src/compiler/checker-heritage.ts +22 -21
- package/src/compiler/checker-inference.ts +514 -82
- package/src/compiler/checker-iteration.ts +18 -31
- package/src/compiler/checker-javascript.ts +1 -1
- package/src/compiler/checker-jsdoc.ts +50 -27
- package/src/compiler/checker-jsx.ts +26 -4
- package/src/compiler/checker-members.ts +200 -56
- 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 +124 -23
- 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 +203 -39
- package/src/compiler/command-line.ts +28 -28
- package/src/compiler/compile-program.ts +167 -27
- package/src/compiler/decoder.ts +13 -4
- package/src/compiler/diagnostic-messages.ts +1973 -1892
- package/src/compiler/diagnostics.ts +84 -3
- package/src/compiler/emitter.ts +57 -8
- package/src/compiler/encoder.ts +23 -8
- package/src/compiler/file-include.ts +9 -3
- package/src/compiler/file-loader.ts +197 -38
- package/src/compiler/help.ts +10 -14
- package/src/compiler/incremental.ts +165 -30
- package/src/compiler/init.ts +2 -7
- package/src/compiler/instantiation.ts +77 -22
- package/src/compiler/jsdoc.ts +3 -1
- package/src/compiler/link-tables.ts +82 -37
- package/src/compiler/locales/cs-CZ.ts +1 -1
- package/src/compiler/locales/de-DE.ts +1 -1
- package/src/compiler/locales/es-ES.ts +1 -1
- package/src/compiler/locales/fr-FR.ts +1 -1
- package/src/compiler/locales/it-IT.ts +1 -1
- package/src/compiler/locales/ja-JP.ts +1 -1
- package/src/compiler/locales/ko-KR.ts +1 -1
- package/src/compiler/locales/pl-PL.ts +1 -1
- package/src/compiler/locales/pt-BR.ts +1 -1
- package/src/compiler/locales/ru-RU.ts +1 -1
- package/src/compiler/locales/tr-TR.ts +1 -1
- package/src/compiler/locales/zh-CN.ts +1 -1
- package/src/compiler/locales/zh-TW.ts +1 -1
- package/src/compiler/module-resolution.ts +44 -8
- package/src/compiler/module-specifiers.ts +62 -20
- package/src/compiler/name-resolver.ts +9 -1
- package/src/compiler/node-builder-names.ts +236 -54
- package/src/compiler/node-builder-pseudo.ts +4 -7
- package/src/compiler/node-builder-reuse.ts +5 -4
- package/src/compiler/node-builder.ts +130 -31
- package/src/compiler/option-declarations.ts +33 -103
- package/src/compiler/options.ts +23 -62
- package/src/compiler/output-paths.ts +5 -18
- package/src/compiler/package-entrypoints.ts +345 -0
- package/src/compiler/package-json.ts +4 -4
- package/src/compiler/parallel-check.ts +326 -52
- package/src/compiler/parallel-emit.ts +320 -0
- package/src/compiler/parallel-parse.ts +16 -5
- package/src/compiler/parse-thread.ts +3 -0
- package/src/compiler/parser.ts +156 -39
- package/src/compiler/path.ts +22 -2
- package/src/compiler/printer/emit-context.ts +21 -0
- package/src/compiler/printer/factory-base.ts +10 -3
- package/src/compiler/printer/factory.ts +4 -1
- package/src/compiler/printer/helpers.ts +10 -1
- package/src/compiler/printer/name-generator.ts +24 -2
- package/src/compiler/printer/printer.ts +266 -30
- package/src/compiler/printer/utilities.ts +8 -2
- package/src/compiler/program-checker.ts +57 -5
- package/src/compiler/program-utilities.ts +23 -10
- package/src/compiler/program.ts +18 -26
- package/src/compiler/pseudo-bigint.ts +17 -0
- package/src/compiler/regexp-checker.ts +63 -30
- package/src/compiler/relations.ts +240 -77
- package/src/compiler/reparser.ts +7 -2
- package/src/compiler/scanner.ts +109 -79
- package/src/compiler/shared-results.ts +2414 -0
- package/src/compiler/show-config.ts +18 -1
- package/src/compiler/sourcemap.ts +2 -2
- package/src/compiler/symbol-accessibility.ts +26 -3
- package/src/compiler/symbol.ts +46 -24
- package/src/compiler/syntax-kind.ts +188 -187
- package/src/compiler/thread-entry.ts +64 -4
- package/src/compiler/transformers/alias-references.ts +123 -4
- package/src/compiler/transformers/async.ts +2 -17
- package/src/compiler/transformers/class-fields.ts +13 -12
- package/src/compiler/transformers/commonjs-module.ts +11 -7
- package/src/compiler/transformers/declarations-diagnostics.ts +5 -3
- package/src/compiler/transformers/declarations-pseudo.ts +2 -4
- package/src/compiler/transformers/declarations-resolver.ts +0 -3
- package/src/compiler/transformers/declarations-syntactic.ts +1 -21
- package/src/compiler/transformers/declarations.ts +134 -48
- package/src/compiler/transformers/decorator-metadata.ts +9 -1
- package/src/compiler/transformers/destructuring.ts +4 -3
- package/src/compiler/transformers/external-module-info.ts +1 -1
- package/src/compiler/transformers/jsx.ts +2 -1
- package/src/compiler/transformers/reference-resolver.ts +83 -19
- package/src/compiler/transformers/runtime-syntax.ts +6 -1
- package/src/compiler/transformers/syntax-facts.ts +2 -7
- package/src/compiler/transformers/type-eraser.ts +10 -1
- package/src/compiler/transformers/type-serialization.ts +3 -2
- package/src/compiler/transformers/visitor-base.ts +2 -1
- package/src/compiler/transformers/visitor-hooks.ts +9 -4
- package/src/compiler/tsc-build.ts +66 -9
- package/src/compiler/tsc-cli.ts +7 -0
- package/src/compiler/tsc-compile.ts +284 -4
- package/src/compiler/tsc-watch.ts +74 -45
- package/src/compiler/tsconfig.ts +176 -19
- package/src/compiler/type-printer.ts +36 -2
- package/src/compiler/types.ts +2 -1
- package/src/library/ast.generated.ts +57 -41
- package/src/library/compiler-options.generated.ts +117 -103
- package/src/library/disk.ts +10 -1
- package/src/library/enums.generated.ts +196 -196
|
@@ -42,9 +42,11 @@ import {
|
|
|
42
42
|
NodeVisitor,
|
|
43
43
|
type ObjectLiteralExpression,
|
|
44
44
|
type ParameterDeclaration,
|
|
45
|
+
type LiteralTypeNode,
|
|
45
46
|
type PrefixUnaryExpression,
|
|
46
47
|
type PropertyAccessExpression,
|
|
47
48
|
type PropertyDeclaration,
|
|
49
|
+
type PropertySignatureDeclaration,
|
|
48
50
|
type ShorthandPropertyAssignment,
|
|
49
51
|
type SourceFile,
|
|
50
52
|
StringLiteral,
|
|
@@ -52,6 +54,7 @@ import {
|
|
|
52
54
|
type TaggedTemplateExpression,
|
|
53
55
|
type ThrowStatement,
|
|
54
56
|
type TupleTypeNode,
|
|
57
|
+
type TypeLiteralNode,
|
|
55
58
|
type TypeOperatorNode,
|
|
56
59
|
type TypeParameterDeclaration,
|
|
57
60
|
type TypeReferenceNode,
|
|
@@ -91,7 +94,11 @@ import {
|
|
|
91
94
|
isAmbientModule,
|
|
92
95
|
isFunctionLike,
|
|
93
96
|
isFunctionLikeDeclarationKind,
|
|
97
|
+
isImportDeferMetaProperty,
|
|
98
|
+
isImportPhaseMetaProperty,
|
|
99
|
+
isImportSourceMetaProperty,
|
|
94
100
|
isModifierKind,
|
|
101
|
+
isSourcePhaseImportCall,
|
|
95
102
|
isStringLiteralLike,
|
|
96
103
|
modifierToFlag,
|
|
97
104
|
nodeIsPresent,
|
|
@@ -128,15 +135,26 @@ import { getPropertyNameFromType, isTypeUsableAsPropertyName, isValidIndexKeyTyp
|
|
|
128
135
|
import { getSymbolOfDeclaration, resolveAlias } from './checker-symbols.js';
|
|
129
136
|
import { Diagnostics } from './diagnostic-messages.js';
|
|
130
137
|
import { Diagnostic, DiagnosticCategory, type DiagnosticMessage, messageCategory } from './diagnostics.js';
|
|
131
|
-
import {
|
|
138
|
+
import {
|
|
139
|
+
ModuleKind,
|
|
140
|
+
ScriptTarget,
|
|
141
|
+
getEmitModuleKind,
|
|
142
|
+
supportsDeferredImports,
|
|
143
|
+
supportsSourcePhaseImports,
|
|
144
|
+
} from './options.js';
|
|
145
|
+
import { getEmitSyntaxForModuleSpecifierExpression } from './checker-modules.js';
|
|
132
146
|
import { fileExtensionIsOneOf, isExternalModuleNameRelative } from './path.js';
|
|
133
|
-
import {
|
|
147
|
+
import {
|
|
148
|
+
SourceFileMetadata,
|
|
149
|
+
getEmitModuleFormatOfFile,
|
|
150
|
+
getImpliedNodeFormatForEmit,
|
|
151
|
+
resolutionModeAttribute,
|
|
152
|
+
} from './program-utilities.js';
|
|
134
153
|
import { CharacterCodes } from './character-codes.js';
|
|
135
154
|
import { Scanner, ScannerErrorReporter, skipTrivia, tokenToString } from './scanner.js';
|
|
136
155
|
import { typeToString } from './type-printer.js';
|
|
137
156
|
import type { ScriptTarget as LanguageTarget } from './types.js';
|
|
138
157
|
import { SyntaxKind } from './syntax-kind.js';
|
|
139
|
-
import { findMismatchedAugmentsTag } from './checker-jsdoc.js';
|
|
140
158
|
import { getDeclarations, SymbolFlags } from './symbol.js';
|
|
141
159
|
|
|
142
160
|
/** Runs the grammar checks of every node of `file`. */
|
|
@@ -443,7 +461,8 @@ function checkGrammarNode(g: GrammarChecker, node: Node): boolean {
|
|
|
443
461
|
return true;
|
|
444
462
|
case SyntaxKind.ImportType: {
|
|
445
463
|
const attributes = (node as ImportTypeNode).attributes;
|
|
446
|
-
if (attributes !== undefined)
|
|
464
|
+
if (attributes !== undefined) checkGrammarImportAttributeValues(g, attributes);
|
|
465
|
+
checkGrammarImportAttributes(g, node);
|
|
447
466
|
return true;
|
|
448
467
|
}
|
|
449
468
|
case SyntaxKind.TupleType:
|
|
@@ -1631,18 +1650,6 @@ function checkGrammarClassDeclarationHeritageClauses(g: GrammarChecker, node: No
|
|
|
1631
1650
|
return grammarErrorOnFirstToken(g, clause, Diagnostics.X_extends_clause_must_precede_implements_clause);
|
|
1632
1651
|
if (clause.types.nodes.length > 1)
|
|
1633
1652
|
return grammarErrorOnFirstToken(g, clause.types.nodes[1]!, Diagnostics.Classes_can_only_extend_a_single_class);
|
|
1634
|
-
if (clause.types.nodes.length > 0) {
|
|
1635
|
-
const mismatch = findMismatchedAugmentsTag(node, clause.types.nodes[0]! as ExpressionWithTypeArguments);
|
|
1636
|
-
if (mismatch !== undefined)
|
|
1637
|
-
return grammarErrorOnNode(
|
|
1638
|
-
g,
|
|
1639
|
-
mismatch.name,
|
|
1640
|
-
Diagnostics.JSDoc_0_1_does_not_match_the_extends_2_clause,
|
|
1641
|
-
mismatch.tagName,
|
|
1642
|
-
mismatch.className,
|
|
1643
|
-
mismatch.extendsName,
|
|
1644
|
-
);
|
|
1645
|
-
}
|
|
1646
1653
|
seenExtendsClause = true;
|
|
1647
1654
|
} else {
|
|
1648
1655
|
if (seenImplementsClause)
|
|
@@ -2588,7 +2595,51 @@ function checkGrammarModuleElementContext(g: GrammarChecker, node: Node, message
|
|
|
2588
2595
|
return !isInAppropriateContext;
|
|
2589
2596
|
}
|
|
2590
2597
|
|
|
2598
|
+
/** An ambient module's import attributes type: property signatures with string literal types, each required,
|
|
2599
|
+
* not readonly, named by an identifier or a string other than `resolution-mode`. */
|
|
2600
|
+
function checkGrammarImportAttributesType(g: GrammarChecker, attributes: TypeLiteralNode): boolean {
|
|
2601
|
+
for (const member of attributes.members.nodes) {
|
|
2602
|
+
if (member.kind !== SyntaxKind.PropertySignature)
|
|
2603
|
+
return grammarErrorOnNode(g, member, Diagnostics.An_import_attributes_type_may_only_contain_property_signatures);
|
|
2604
|
+
const property = member as PropertySignatureDeclaration;
|
|
2605
|
+
for (const modifier of property.modifiers?.nodes ?? [])
|
|
2606
|
+
if (modifier.kind === SyntaxKind.ReadonlyKeyword)
|
|
2607
|
+
return grammarErrorOnNode(
|
|
2608
|
+
g,
|
|
2609
|
+
modifier,
|
|
2610
|
+
Diagnostics.An_import_attributes_property_cannot_have_a_readonly_modifier,
|
|
2611
|
+
);
|
|
2612
|
+
if (property.type === undefined)
|
|
2613
|
+
return grammarErrorOnNode(g, member, Diagnostics.An_import_attributes_property_must_have_a_type_annotation);
|
|
2614
|
+
if (property.postfixToken?.kind === SyntaxKind.QuestionToken)
|
|
2615
|
+
return grammarErrorOnNode(g, member, Diagnostics.An_import_attributes_property_cannot_be_optional);
|
|
2616
|
+
const name = property.name;
|
|
2617
|
+
if (!isStringLiteralLike(name) && name.kind !== SyntaxKind.Identifier)
|
|
2618
|
+
return grammarErrorOnNode(
|
|
2619
|
+
g,
|
|
2620
|
+
name,
|
|
2621
|
+
Diagnostics.An_import_attributes_property_must_have_a_string_literal_or_identifier_name,
|
|
2622
|
+
);
|
|
2623
|
+
if (getText(name) === 'resolution-mode')
|
|
2624
|
+
return grammarErrorOnNode(
|
|
2625
|
+
g,
|
|
2626
|
+
name,
|
|
2627
|
+
Diagnostics.X_0_is_not_a_valid_key_for_an_import_attributes_type,
|
|
2628
|
+
getText(name),
|
|
2629
|
+
);
|
|
2630
|
+
const type = property.type;
|
|
2631
|
+
if (type.kind !== SyntaxKind.LiteralType || (type as LiteralTypeNode).literal.kind !== SyntaxKind.StringLiteral)
|
|
2632
|
+
return grammarErrorOnNode(
|
|
2633
|
+
g,
|
|
2634
|
+
type,
|
|
2635
|
+
Diagnostics.An_import_attributes_property_must_have_a_string_literal_type_annotation,
|
|
2636
|
+
);
|
|
2637
|
+
}
|
|
2638
|
+
return false;
|
|
2639
|
+
}
|
|
2640
|
+
|
|
2591
2641
|
function checkGrammarModuleDeclaration(g: GrammarChecker, node: ModuleDeclaration): boolean {
|
|
2642
|
+
if (node.attributes !== undefined) checkGrammarImportAttributesType(g, node.attributes);
|
|
2592
2643
|
// The declaration check reports an illegal context and skips the rest.
|
|
2593
2644
|
const parent = node.parent!.kind;
|
|
2594
2645
|
if (parent !== SyntaxKind.SourceFile && parent !== SyntaxKind.ModuleBlock && parent !== SyntaxKind.ModuleDeclaration)
|
|
@@ -2636,22 +2687,27 @@ function checkExternalImportOrExportDeclaration(g: GrammarChecker, node: Node):
|
|
|
2636
2687
|
}
|
|
2637
2688
|
if (node.kind === SyntaxKind.ImportEqualsDeclaration) return true;
|
|
2638
2689
|
const attributes = getImportAttributes(node);
|
|
2639
|
-
|
|
2690
|
+
return attributes === undefined || !checkGrammarImportAttributeValues(g, attributes);
|
|
2691
|
+
}
|
|
2692
|
+
|
|
2693
|
+
/** Reports attribute values that are not string literals, and returns whether there are any. */
|
|
2694
|
+
function checkGrammarImportAttributeValues(g: GrammarChecker, node: ImportAttributes): boolean {
|
|
2640
2695
|
let hasError = false;
|
|
2641
|
-
for (const attribute of
|
|
2696
|
+
for (const attribute of node.attributes.nodes) {
|
|
2642
2697
|
const value = (attribute as ImportAttribute).value;
|
|
2643
2698
|
if (value.kind !== SyntaxKind.StringLiteral) {
|
|
2644
2699
|
hasError = true;
|
|
2645
2700
|
g.c.error(value, Diagnostics.Import_attribute_values_must_be_string_literal_expressions);
|
|
2646
2701
|
}
|
|
2647
2702
|
}
|
|
2648
|
-
return
|
|
2703
|
+
return hasError;
|
|
2649
2704
|
}
|
|
2650
2705
|
|
|
2651
2706
|
function getImportAttributes(node: Node): ImportAttributes | undefined {
|
|
2652
2707
|
if (node.kind === SyntaxKind.ImportDeclaration || node.kind === SyntaxKind.JSImportDeclaration)
|
|
2653
2708
|
return (node as ImportDeclaration).attributes;
|
|
2654
2709
|
if (node.kind === SyntaxKind.ExportDeclaration) return (node as ExportDeclaration).attributes;
|
|
2710
|
+
if (node.kind === SyntaxKind.ImportType) return (node as ImportTypeNode).attributes;
|
|
2655
2711
|
return undefined;
|
|
2656
2712
|
}
|
|
2657
2713
|
|
|
@@ -2687,14 +2743,38 @@ function checkGrammarImportClause(g: GrammarChecker, node: ImportClause): boolea
|
|
|
2687
2743
|
} else if (node.phaseModifier === SyntaxKind.DeferKeyword) {
|
|
2688
2744
|
if (node.name !== undefined)
|
|
2689
2745
|
return grammarErrorOnNode(g, node, Diagnostics.Default_imports_are_not_allowed_in_a_deferred_import);
|
|
2690
|
-
if (namedBindings
|
|
2746
|
+
if (namedBindings === undefined)
|
|
2747
|
+
return grammarErrorOnNode(g, node, Diagnostics.A_deferred_import_must_specify_a_namespace_binding);
|
|
2748
|
+
if (namedBindings.kind === SyntaxKind.NamedImports)
|
|
2691
2749
|
return grammarErrorOnNode(g, node, Diagnostics.Named_imports_are_not_allowed_in_a_deferred_import);
|
|
2692
|
-
if (g.moduleKind
|
|
2750
|
+
if (!supportsDeferredImports(g.moduleKind))
|
|
2693
2751
|
return grammarErrorOnNode(
|
|
2694
2752
|
g,
|
|
2695
2753
|
node,
|
|
2696
2754
|
Diagnostics.Deferred_imports_are_only_supported_when_the_module_flag_is_set_to_esnext_or_preserve,
|
|
2697
2755
|
);
|
|
2756
|
+
} else if (node.phaseModifier === SyntaxKind.SourceKeyword) {
|
|
2757
|
+
if (namedBindings !== undefined)
|
|
2758
|
+
return grammarErrorOnNode(
|
|
2759
|
+
g,
|
|
2760
|
+
node,
|
|
2761
|
+
Diagnostics.Named_and_namespace_imports_are_not_allowed_in_a_source_phase_import,
|
|
2762
|
+
);
|
|
2763
|
+
if (node.name === undefined)
|
|
2764
|
+
return grammarErrorOnNode(g, node, Diagnostics.A_source_phase_import_must_specify_a_local_binding);
|
|
2765
|
+
if (!supportsSourcePhaseImports(g.moduleKind))
|
|
2766
|
+
return grammarErrorOnNode(
|
|
2767
|
+
g,
|
|
2768
|
+
node,
|
|
2769
|
+
Diagnostics.Source_phase_imports_are_only_supported_when_the_module_option_is_set_to_esnext_nodenext_or_preserve,
|
|
2770
|
+
);
|
|
2771
|
+
const moduleSpecifier = (node.parent as ImportDeclaration).moduleSpecifier;
|
|
2772
|
+
if (getEmitSyntaxForModuleSpecifierExpression(g.c, moduleSpecifier) === ModuleKind.CommonJS)
|
|
2773
|
+
return grammarErrorOnNode(
|
|
2774
|
+
g,
|
|
2775
|
+
node,
|
|
2776
|
+
Diagnostics.Source_phase_imports_are_not_allowed_on_statements_that_compile_to_CommonJS_require_calls,
|
|
2777
|
+
);
|
|
2698
2778
|
}
|
|
2699
2779
|
return false;
|
|
2700
2780
|
}
|
|
@@ -3039,26 +3119,10 @@ function checkGrammarJSDocTypeInTypeScript(g: GrammarChecker, node: Node): void
|
|
|
3039
3119
|
);
|
|
3040
3120
|
}
|
|
3041
3121
|
|
|
3042
|
-
/** The `resolution-mode` of import type attributes, as tsgo's `
|
|
3122
|
+
/** The `resolution-mode` of import type attributes, as tsgo's `GetResolutionModeOverride`. */
|
|
3043
3123
|
function getResolutionModeOverride(g: GrammarChecker, node: ImportAttributes, reportErrors: boolean): ModuleKind {
|
|
3044
|
-
const
|
|
3045
|
-
if (
|
|
3046
|
-
if (reportErrors)
|
|
3047
|
-
grammarErrorOnNode(
|
|
3048
|
-
g,
|
|
3049
|
-
node,
|
|
3050
|
-
Diagnostics.Type_import_attributes_should_have_exactly_one_key_resolution_mode_with_value_import_or_require,
|
|
3051
|
-
);
|
|
3052
|
-
return ModuleKind.None;
|
|
3053
|
-
}
|
|
3054
|
-
const attribute = attributes[0]! as ImportAttribute;
|
|
3055
|
-
const name = attribute.name;
|
|
3056
|
-
if (name === undefined || !isStringLiteralLike(name)) return ModuleKind.None;
|
|
3057
|
-
if (getText(name) !== 'resolution-mode') {
|
|
3058
|
-
if (reportErrors)
|
|
3059
|
-
grammarErrorOnNode(g, name, Diagnostics.X_resolution_mode_is_the_only_valid_key_for_type_import_attributes);
|
|
3060
|
-
return ModuleKind.None;
|
|
3061
|
-
}
|
|
3124
|
+
const attribute = resolutionModeAttribute(node);
|
|
3125
|
+
if (attribute === undefined) return ModuleKind.None;
|
|
3062
3126
|
const value = attribute.value;
|
|
3063
3127
|
if (!isStringLiteralLike(value)) return ModuleKind.None;
|
|
3064
3128
|
const text = getText(value);
|
|
@@ -3072,10 +3136,10 @@ function getResolutionModeOverride(g: GrammarChecker, node: ImportAttributes, re
|
|
|
3072
3136
|
function checkGrammarImportAttributes(g: GrammarChecker, declaration: Node): void {
|
|
3073
3137
|
const node = getImportAttributes(declaration);
|
|
3074
3138
|
if (node === undefined) return;
|
|
3075
|
-
const isTypeOnly = isExclusivelyTypeOnlyImportOrExport(declaration);
|
|
3139
|
+
const isTypeOnly = isExclusivelyTypeOnlyImportOrExport(declaration) || declaration.kind === SyntaxKind.ImportType;
|
|
3076
3140
|
const override = getResolutionModeOverride(g, node, isTypeOnly);
|
|
3077
|
-
// Other checks don't apply to type-only imports
|
|
3078
|
-
if (isTypeOnly
|
|
3141
|
+
// Other checks don't apply to type-only imports and import types.
|
|
3142
|
+
if (isTypeOnly) return;
|
|
3079
3143
|
const moduleKind = g.moduleKind;
|
|
3080
3144
|
if (
|
|
3081
3145
|
!(
|
|
@@ -3104,10 +3168,6 @@ function checkGrammarImportAttributes(g: GrammarChecker, declaration: Node): voi
|
|
|
3104
3168
|
);
|
|
3105
3169
|
return;
|
|
3106
3170
|
}
|
|
3107
|
-
if (isTypeOnly) {
|
|
3108
|
-
grammarErrorOnNode(g, node, Diagnostics.Import_attributes_cannot_be_used_with_type_only_imports_or_exports);
|
|
3109
|
-
return;
|
|
3110
|
-
}
|
|
3111
3171
|
if (override !== ModuleKind.None)
|
|
3112
3172
|
grammarErrorOnNode(g, node, Diagnostics.X_resolution_mode_can_only_be_set_for_type_only_imports);
|
|
3113
3173
|
}
|
|
@@ -3143,7 +3203,8 @@ function checkGrammarObjectLiteralExpression(
|
|
|
3143
3203
|
node: ObjectLiteralExpression,
|
|
3144
3204
|
inDestructuring: boolean,
|
|
3145
3205
|
): boolean {
|
|
3146
|
-
|
|
3206
|
+
// An object literal with one property can't repeat a name, so it needs no table of names.
|
|
3207
|
+
const seen = node.properties.nodes.length > 1 ? new Map<string, DeclarationMeaning>() : undefined;
|
|
3147
3208
|
for (const property of node.properties.nodes) {
|
|
3148
3209
|
if (property.kind === SyntaxKind.SpreadAssignment) {
|
|
3149
3210
|
if (inDestructuring) {
|
|
@@ -3222,7 +3283,7 @@ function checkGrammarObjectLiteralExpression(
|
|
|
3222
3283
|
}
|
|
3223
3284
|
if (inDestructuring) continue;
|
|
3224
3285
|
const effectiveName = getEffectivePropertyNameForPropertyNameNode(g.c, name);
|
|
3225
|
-
if (effectiveName === undefined) continue;
|
|
3286
|
+
if (effectiveName === undefined || seen === undefined) continue;
|
|
3226
3287
|
const existingKind = seen.get(effectiveName);
|
|
3227
3288
|
if (existingKind === undefined) {
|
|
3228
3289
|
seen.set(effectiveName, currentKind);
|
|
@@ -3301,12 +3362,8 @@ function getEffectivePropertyNameForPropertyNameNode(c: Checker, name: Node): st
|
|
|
3301
3362
|
|
|
3302
3363
|
function checkGrammarCallExpression(g: GrammarChecker, node: CallExpression): void {
|
|
3303
3364
|
const callee = node.expression;
|
|
3304
|
-
|
|
3305
|
-
|
|
3306
|
-
(callee.kind === SyntaxKind.MetaProperty &&
|
|
3307
|
-
(callee as MetaProperty).keywordToken === SyntaxKind.ImportKeyword &&
|
|
3308
|
-
(callee as MetaProperty).name.text === 'defer');
|
|
3309
|
-
if (isImportCall) checkGrammarImportCallExpression(g, node);
|
|
3365
|
+
if (callee.kind === SyntaxKind.ImportKeyword || isImportPhaseMetaProperty(callee))
|
|
3366
|
+
checkGrammarImportCallExpression(g, node);
|
|
3310
3367
|
else checkGrammarTypeArguments(g, callTypeArguments(node));
|
|
3311
3368
|
}
|
|
3312
3369
|
|
|
@@ -3320,8 +3377,15 @@ function checkGrammarImportCallExpression(g: GrammarChecker, node: CallExpressio
|
|
|
3320
3377
|
? Diagnostics.ECMAScript_imports_and_exports_cannot_be_written_in_a_CommonJS_file_under_verbatimModuleSyntax
|
|
3321
3378
|
: Diagnostics.ECMAScript_imports_and_exports_cannot_be_written_in_a_CommonJS_file_under_verbatimModuleSyntax_Adjust_the_type_field_in_the_nearest_package_json_to_make_this_file_an_ECMAScript_module_or_adjust_your_verbatimModuleSyntax_module_and_moduleResolution_settings_in_TypeScript,
|
|
3322
3379
|
);
|
|
3323
|
-
if (node.expression
|
|
3324
|
-
if (moduleKind
|
|
3380
|
+
if (isImportSourceMetaProperty(node.expression)) {
|
|
3381
|
+
if (!supportsSourcePhaseImports(moduleKind))
|
|
3382
|
+
return grammarErrorOnNode(
|
|
3383
|
+
g,
|
|
3384
|
+
node,
|
|
3385
|
+
Diagnostics.Source_phase_imports_are_only_supported_when_the_module_option_is_set_to_esnext_nodenext_or_preserve,
|
|
3386
|
+
);
|
|
3387
|
+
} else if (isImportDeferMetaProperty(node.expression)) {
|
|
3388
|
+
if (!supportsDeferredImports(moduleKind))
|
|
3325
3389
|
return grammarErrorOnNode(
|
|
3326
3390
|
g,
|
|
3327
3391
|
node,
|
|
@@ -3333,6 +3397,9 @@ function checkGrammarImportCallExpression(g: GrammarChecker, node: CallExpressio
|
|
|
3333
3397
|
node,
|
|
3334
3398
|
Diagnostics.Dynamic_imports_are_only_supported_when_the_module_flag_is_set_to_es2020_es2022_esnext_commonjs_amd_system_umd_node16_node18_node20_or_nodenext,
|
|
3335
3399
|
);
|
|
3400
|
+
const questionDotToken = callQuestionDotToken(node);
|
|
3401
|
+
if (questionDotToken !== undefined && isSourcePhaseImportCall(node))
|
|
3402
|
+
return grammarErrorOnNode(g, questionDotToken, Diagnostics.Optional_chaining_cannot_be_used_with_import_source);
|
|
3336
3403
|
if (callTypeArguments(node) !== undefined)
|
|
3337
3404
|
return grammarErrorOnNode(
|
|
3338
3405
|
g,
|
|
@@ -3393,14 +3460,14 @@ function checkGrammarMetaProperty(g: GrammarChecker, node: MetaProperty): boolea
|
|
|
3393
3460
|
} else if (node.keywordToken === SyntaxKind.ImportKeyword && nameText !== 'meta') {
|
|
3394
3461
|
const parent = node.parent!;
|
|
3395
3462
|
const isCallee = parent.kind === SyntaxKind.CallExpression && (parent as CallExpression).expression === node;
|
|
3396
|
-
if (
|
|
3463
|
+
if (isImportPhaseMetaProperty(node)) {
|
|
3397
3464
|
if (!isCallee) return grammarErrorAtPos(g, node.end, 0, Diagnostics.X_0_expected, '(');
|
|
3398
3465
|
} else {
|
|
3399
3466
|
if (isCallee)
|
|
3400
3467
|
return grammarErrorOnNode(
|
|
3401
3468
|
g,
|
|
3402
3469
|
name,
|
|
3403
|
-
Diagnostics.
|
|
3470
|
+
Diagnostics.X_0_is_not_a_valid_meta_property_for_keyword_import_Did_you_mean_meta_defer_or_source,
|
|
3404
3471
|
nameText,
|
|
3405
3472
|
);
|
|
3406
3473
|
return grammarErrorOnNode(
|
|
@@ -3507,7 +3574,7 @@ function checkGrammarYieldExpression(g: GrammarChecker, node: Node): boolean {
|
|
|
3507
3574
|
return hasError;
|
|
3508
3575
|
}
|
|
3509
3576
|
|
|
3510
|
-
function isInParameterInitializerBeforeContainingFunction(node: Node): boolean {
|
|
3577
|
+
export function isInParameterInitializerBeforeContainingFunction(node: Node): boolean {
|
|
3511
3578
|
let inBindingInitializer = false;
|
|
3512
3579
|
let current = node;
|
|
3513
3580
|
while (current.parent !== undefined && !isFunctionLike(current.parent)) {
|
|
@@ -3523,8 +3590,15 @@ function isInParameterInitializerBeforeContainingFunction(node: Node): boolean {
|
|
|
3523
3590
|
/** A private name in an expression, which is only valid as `#x in obj`. */
|
|
3524
3591
|
function checkGrammarPrivateIdentifierExpression(g: GrammarChecker, node: Node): boolean {
|
|
3525
3592
|
const parent = node.parent!;
|
|
3526
|
-
// Names of members
|
|
3527
|
-
|
|
3593
|
+
// Names of members, property accesses, qualified names (`typeof this.#x`) and destructured properties aren't
|
|
3594
|
+
// expressions.
|
|
3595
|
+
if (
|
|
3596
|
+
parent.kind === SyntaxKind.PropertyAccessExpression ||
|
|
3597
|
+
parent.kind === SyntaxKind.QualifiedName ||
|
|
3598
|
+
getName(parent) === node ||
|
|
3599
|
+
(parent.kind === SyntaxKind.BindingElement && (parent as BindingElement).propertyName === node)
|
|
3600
|
+
)
|
|
3601
|
+
return false;
|
|
3528
3602
|
const isForIn = parent.kind === SyntaxKind.ForInStatement;
|
|
3529
3603
|
if (getContainingClass(node) === undefined)
|
|
3530
3604
|
return grammarErrorOnNode(g, node, Diagnostics.Private_identifiers_are_not_allowed_outside_class_bodies);
|
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
getType,
|
|
18
18
|
getTypeParameters,
|
|
19
19
|
getTypeArguments,
|
|
20
|
+
type ExpressionWithTypeArguments,
|
|
20
21
|
} from './ast.js';
|
|
21
22
|
import {
|
|
22
23
|
findConstructorDeclaration,
|
|
@@ -33,6 +34,7 @@ import { type Diagnostic, type DiagnosticMessage, Diagnostics, chainDiagnostic }
|
|
|
33
34
|
import { getUseDefineForClassFields } from './options.js';
|
|
34
35
|
import { SyntaxKind } from './syntax-kind.js';
|
|
35
36
|
import { type Checker, createDiagnosticForNode } from './checker.js';
|
|
37
|
+
import { checkJSDocAugmentsTagMatchesExtends } from './checker-jsdoc.js';
|
|
36
38
|
import {
|
|
37
39
|
type IndexInfo,
|
|
38
40
|
type InterfaceType,
|
|
@@ -113,7 +115,7 @@ import {
|
|
|
113
115
|
import { Ternary } from './checker-types.js';
|
|
114
116
|
import { symbolToString, typeToString } from './type-printer.js';
|
|
115
117
|
import { checkFunctionOrConstructorSymbol } from './checker-overloads.js';
|
|
116
|
-
import { isPropertyInitializedInConstructor } from './checker-classes.js';
|
|
118
|
+
import { getConstructorAccessibilityError, isPropertyInitializedInConstructor } from './checker-classes.js';
|
|
117
119
|
import {
|
|
118
120
|
CheckFlags,
|
|
119
121
|
declarationCount,
|
|
@@ -144,12 +146,15 @@ export function checkClassHeritage(c: Checker, node: Node): void {
|
|
|
144
146
|
}
|
|
145
147
|
checkMembersForOverrideModifier(c, node, classType, typeWithThis, staticType);
|
|
146
148
|
for (const typeRefNode of getImplementsHeritageClauseElements(node)) {
|
|
147
|
-
|
|
148
|
-
if (
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
149
|
+
// The parser makes an entity name element a type reference; anything else stays an expression.
|
|
150
|
+
if (typeRefNode.kind === SyntaxKind.ExpressionWithTypeArguments) {
|
|
151
|
+
const expr = getExpression(typeRefNode)!;
|
|
152
|
+
if (!isEntityNameExpression(expr) || isOptionalChain(expr))
|
|
153
|
+
c.error(
|
|
154
|
+
expr,
|
|
155
|
+
Diagnostics.A_class_can_only_implement_an_identifier_Slashqualified_name_with_optional_type_arguments,
|
|
156
|
+
);
|
|
157
|
+
}
|
|
153
158
|
const t = getReducedType(c, getTypeFromTypeNode(c, typeRefNode));
|
|
154
159
|
if (isErrorType(c, t)) continue;
|
|
155
160
|
if (!isValidBaseType(c, t)) {
|
|
@@ -181,8 +186,9 @@ function checkBaseClass(
|
|
|
181
186
|
baseType: Type,
|
|
182
187
|
): void {
|
|
183
188
|
const baseConstructorType = getBaseConstructorTypeOfClass(c, classType);
|
|
184
|
-
const staticBaseType = getApparentType(c, baseConstructorType);
|
|
185
189
|
const baseTypeNode = getExtendsHeritageClauseElement(node)!;
|
|
190
|
+
checkJSDocAugmentsTagMatchesExtends(c, node, baseTypeNode as ExpressionWithTypeArguments, baseType);
|
|
191
|
+
const staticBaseType = getApparentType(c, baseConstructorType);
|
|
186
192
|
checkBaseTypeAccessibility(c, staticBaseType, baseTypeNode);
|
|
187
193
|
const typeArgumentNodes = getTypeArguments(baseTypeNode);
|
|
188
194
|
if (typeArgumentNodes !== undefined && typeArgumentNodes.nodes.length !== 0) {
|
|
@@ -304,23 +310,15 @@ function getImplementsHeritageClauseElements(node: Node): Node[] {
|
|
|
304
310
|
|
|
305
311
|
function checkBaseTypeAccessibility(c: Checker, t: Type, node: Node): void {
|
|
306
312
|
const signatures = getSignaturesOfType(c, t, SignatureKind.Construct);
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
if (declaration === undefined || !hasSyntacticModifier(declaration, ModifierFlags.Private)) return;
|
|
310
|
-
const typeClassDeclaration = t.symbol !== undefined ? getClassLikeDeclarationOfSymbol(t.symbol) : undefined;
|
|
311
|
-
if (!isNodeWithinClass(node, typeClassDeclaration))
|
|
313
|
+
const error = getConstructorAccessibilityError(c, node, signatures, ModifierFlags.Private);
|
|
314
|
+
if (error !== undefined)
|
|
312
315
|
c.error(
|
|
313
316
|
node,
|
|
314
317
|
Diagnostics.Cannot_extend_a_class_0_Class_constructor_is_marked_as_private,
|
|
315
|
-
getFullyQualifiedName(c,
|
|
318
|
+
getFullyQualifiedName(c, error.declaringClass.symbol!),
|
|
316
319
|
);
|
|
317
320
|
}
|
|
318
321
|
|
|
319
|
-
function isNodeWithinClass(node: Node, classDeclaration: Node | undefined): boolean {
|
|
320
|
-
for (let n: Node | undefined = node; n !== undefined; n = n.parent) if (n === classDeclaration) return true;
|
|
321
|
-
return false;
|
|
322
|
-
}
|
|
323
|
-
|
|
324
322
|
/** Reports each incompatible member, or the class as a whole when no member is to blame. */
|
|
325
323
|
function issueMemberSpecificError(
|
|
326
324
|
c: Checker,
|
|
@@ -784,17 +782,19 @@ export function checkInterfaceHeritage(c: Checker, node: Node): void {
|
|
|
784
782
|
const links = c.symbolLinks(symbol);
|
|
785
783
|
if (!links.interfaceChecked) {
|
|
786
784
|
links.interfaceChecked = true;
|
|
785
|
+
// Reported on the first interface declaration, whichever declaration is checked first.
|
|
786
|
+
const firstName = getName(getDeclarationOfKind(symbol, SyntaxKind.InterfaceDeclaration)!)!;
|
|
787
787
|
const t = getDeclaredTypeOfSymbol(c, symbol) as InterfaceType;
|
|
788
788
|
if ((t.flags & TypeFlags.Object) !== 0) {
|
|
789
789
|
const typeWithThis = getTypeWithThisArgument(c, t, undefined, false);
|
|
790
790
|
// Later checks run only when inherited properties agree.
|
|
791
|
-
if (checkInheritedPropertiesAreIdentical(c, t,
|
|
791
|
+
if (checkInheritedPropertiesAreIdentical(c, t, firstName)) {
|
|
792
792
|
for (const baseType of getBaseTypes(c, t))
|
|
793
793
|
checkTypeAssignableTo(
|
|
794
794
|
c,
|
|
795
795
|
typeWithThis,
|
|
796
796
|
getTypeWithThisArgument(c, baseType, t.thisType, false),
|
|
797
|
-
|
|
797
|
+
firstName,
|
|
798
798
|
Diagnostics.Interface_0_incorrectly_extends_interface_1,
|
|
799
799
|
);
|
|
800
800
|
checkIndexConstraints(c, t, symbol, false);
|
|
@@ -803,6 +803,7 @@ export function checkInterfaceHeritage(c: Checker, node: Node): void {
|
|
|
803
803
|
}
|
|
804
804
|
checkObjectTypeForDuplicateDeclarations(c, node, false);
|
|
805
805
|
for (const element of getExtendsHeritageClauseElements(node)) {
|
|
806
|
+
if (element.kind !== SyntaxKind.ExpressionWithTypeArguments) continue;
|
|
806
807
|
const expr = getExpression(element)!;
|
|
807
808
|
if (!isEntityNameExpression(expr) || isOptionalChain(expr))
|
|
808
809
|
c.error(
|