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
|
@@ -15,6 +15,7 @@ import { checkExpressionWithTypeArguments } from './checker-calls.js';
|
|
|
15
15
|
import { getIntendedTypeFromJSDocTypeReference } from './checker-jsdoc.js';
|
|
16
16
|
import { getCombinedNodeFlags, hasSyntacticModifier } from './binder-utilities.js';
|
|
17
17
|
import { getDeclarations, getSymbolId } from './symbol.js';
|
|
18
|
+
import { isStatement } from './printer/utilities.js';
|
|
18
19
|
export function getTypeFromTypeNode(c, node) {
|
|
19
20
|
return getConditionalFlowTypeOfType(c, getTypeFromTypeNodeWorker(c, node), node);
|
|
20
21
|
}
|
|
@@ -30,11 +31,11 @@ function getConditionalFlowTypeOfType(c, t, start) {
|
|
|
30
31
|
if (parent === undefined)
|
|
31
32
|
break;
|
|
32
33
|
// Only parameter positions flip variance; `keyof` is mostly used invariantly in indexed accesses.
|
|
33
|
-
if (parent.kind ===
|
|
34
|
+
if (parent.kind === 171 /* SyntaxKind.Parameter */)
|
|
34
35
|
covariant = !covariant;
|
|
35
36
|
// Type variables always substitute, as even contravariant positions may rely on their constraints.
|
|
36
37
|
if ((covariant || (t.flags & 34078720 /* TypeFlags.TypeVariable */) !== 0) &&
|
|
37
|
-
parent.kind ===
|
|
38
|
+
parent.kind === 196 /* SyntaxKind.ConditionalType */ &&
|
|
38
39
|
node === parent.trueType) {
|
|
39
40
|
const conditional = parent;
|
|
40
41
|
const constraint = getImpliedConstraint(c, t, conditional.checkType, conditional.extendsType);
|
|
@@ -42,7 +43,7 @@ function getConditionalFlowTypeOfType(c, t, start) {
|
|
|
42
43
|
(constraints ??= []).push(constraint);
|
|
43
44
|
}
|
|
44
45
|
else if ((t.flags & 524288 /* TypeFlags.TypeParameter */) !== 0 &&
|
|
45
|
-
parent.kind ===
|
|
46
|
+
parent.kind === 202 /* SyntaxKind.MappedType */ &&
|
|
46
47
|
parent.nameType === undefined &&
|
|
47
48
|
node === parent.type) {
|
|
48
49
|
// Homomorphic mapped types over arrays and tuples map numeric keys only.
|
|
@@ -67,32 +68,32 @@ function getImpliedConstraint(c, t, checkNode, extendsNode) {
|
|
|
67
68
|
return undefined;
|
|
68
69
|
}
|
|
69
70
|
function isUnaryTupleTypeNode(node) {
|
|
70
|
-
return node.kind ===
|
|
71
|
+
return node.kind === 191 /* SyntaxKind.TupleType */ && node.elements.nodes.length === 1;
|
|
71
72
|
}
|
|
72
73
|
/** A statement, declaration statement or block, which ends the search for enclosing conditional types. */
|
|
73
74
|
function isStatementLike(node) {
|
|
74
75
|
switch (node.kind) {
|
|
75
|
-
case
|
|
76
|
-
case
|
|
77
|
-
case
|
|
78
|
-
case
|
|
79
|
-
case
|
|
80
|
-
case
|
|
81
|
-
case
|
|
82
|
-
case
|
|
83
|
-
case
|
|
84
|
-
case
|
|
85
|
-
case
|
|
86
|
-
case
|
|
87
|
-
case
|
|
88
|
-
case
|
|
89
|
-
case
|
|
90
|
-
case
|
|
91
|
-
case
|
|
92
|
-
case
|
|
93
|
-
case
|
|
94
|
-
case
|
|
95
|
-
case
|
|
76
|
+
case 243 /* SyntaxKind.Block */:
|
|
77
|
+
case 254 /* SyntaxKind.BreakStatement */:
|
|
78
|
+
case 253 /* SyntaxKind.ContinueStatement */:
|
|
79
|
+
case 261 /* SyntaxKind.DebuggerStatement */:
|
|
80
|
+
case 248 /* SyntaxKind.DoStatement */:
|
|
81
|
+
case 246 /* SyntaxKind.ExpressionStatement */:
|
|
82
|
+
case 244 /* SyntaxKind.EmptyStatement */:
|
|
83
|
+
case 251 /* SyntaxKind.ForInStatement */:
|
|
84
|
+
case 252 /* SyntaxKind.ForOfStatement */:
|
|
85
|
+
case 250 /* SyntaxKind.ForStatement */:
|
|
86
|
+
case 247 /* SyntaxKind.IfStatement */:
|
|
87
|
+
case 258 /* SyntaxKind.LabeledStatement */:
|
|
88
|
+
case 255 /* SyntaxKind.ReturnStatement */:
|
|
89
|
+
case 257 /* SyntaxKind.SwitchStatement */:
|
|
90
|
+
case 259 /* SyntaxKind.ThrowStatement */:
|
|
91
|
+
case 260 /* SyntaxKind.TryStatement */:
|
|
92
|
+
case 245 /* SyntaxKind.VariableStatement */:
|
|
93
|
+
case 249 /* SyntaxKind.WhileStatement */:
|
|
94
|
+
case 256 /* SyntaxKind.WithStatement */:
|
|
95
|
+
case 348 /* SyntaxKind.NotEmittedStatement */:
|
|
96
|
+
case 316 /* SyntaxKind.JSDoc */:
|
|
96
97
|
return true;
|
|
97
98
|
}
|
|
98
99
|
return isDeclarationStatementKind(node.kind);
|
|
@@ -100,17 +101,17 @@ function isStatementLike(node) {
|
|
|
100
101
|
function getTypeFromTypeNodeWorker(c, node) {
|
|
101
102
|
switch (node.kind) {
|
|
102
103
|
case 132 /* SyntaxKind.AnyKeyword */:
|
|
103
|
-
case
|
|
104
|
+
case 311 /* SyntaxKind.JSDocAllType */:
|
|
104
105
|
return c.anyType;
|
|
105
|
-
case
|
|
106
|
+
case 313 /* SyntaxKind.JSDocNonNullableType */:
|
|
106
107
|
return getTypeFromTypeNode(c, getType(node));
|
|
107
|
-
case
|
|
108
|
+
case 312 /* SyntaxKind.JSDocNullableType */: {
|
|
108
109
|
const t = getTypeFromTypeNode(c, getType(node));
|
|
109
110
|
return c.strictNullChecks ? getNullableType(c, t, 8 /* TypeFlags.Null */) : t;
|
|
110
111
|
}
|
|
111
|
-
case
|
|
112
|
+
case 315 /* SyntaxKind.JSDocVariadicType */:
|
|
112
113
|
return createArrayType(c, getTypeFromTypeNode(c, getType(node)));
|
|
113
|
-
case
|
|
114
|
+
case 314 /* SyntaxKind.JSDocOptionalType */:
|
|
114
115
|
return addOptionality(c, getTypeFromTypeNode(c, getType(node)), false, true);
|
|
115
116
|
case 159 /* SyntaxKind.UnknownKeyword */:
|
|
116
117
|
return c.unknownType;
|
|
@@ -136,48 +137,48 @@ function getTypeFromTypeNodeWorker(c, node) {
|
|
|
136
137
|
return c.nonPrimitiveType;
|
|
137
138
|
case 141 /* SyntaxKind.IntrinsicKeyword */:
|
|
138
139
|
return c.intrinsicMarkerType;
|
|
139
|
-
case
|
|
140
|
+
case 199 /* SyntaxKind.ThisType */:
|
|
140
141
|
case 109 /* SyntaxKind.ThisKeyword */:
|
|
141
142
|
return getTypeFromThisTypeNode(c, node);
|
|
142
|
-
case
|
|
143
|
+
case 203 /* SyntaxKind.LiteralType */:
|
|
143
144
|
return getTypeFromLiteralTypeNode(c, node);
|
|
144
|
-
case
|
|
145
|
-
case
|
|
145
|
+
case 185 /* SyntaxKind.TypeReference */:
|
|
146
|
+
case 235 /* SyntaxKind.ExpressionWithTypeArguments */:
|
|
146
147
|
return getTypeFromTypeReference(c, node);
|
|
147
|
-
case
|
|
148
|
+
case 184 /* SyntaxKind.TypePredicate */:
|
|
148
149
|
return node.assertsModifier !== undefined ? c.voidType : c.booleanType;
|
|
149
|
-
case
|
|
150
|
+
case 188 /* SyntaxKind.TypeQuery */:
|
|
150
151
|
return getTypeFromTypeQueryNode(c, node);
|
|
151
|
-
case
|
|
152
|
-
case
|
|
152
|
+
case 190 /* SyntaxKind.ArrayType */:
|
|
153
|
+
case 191 /* SyntaxKind.TupleType */:
|
|
153
154
|
return getTypeFromArrayOrTupleTypeNode(c, node);
|
|
154
|
-
case
|
|
155
|
+
case 192 /* SyntaxKind.OptionalType */:
|
|
155
156
|
return addOptionality(c, getTypeFromTypeNode(c, node.type), true, true);
|
|
156
|
-
case
|
|
157
|
+
case 194 /* SyntaxKind.UnionType */:
|
|
157
158
|
return getTypeFromUnionTypeNode(c, node);
|
|
158
|
-
case
|
|
159
|
+
case 195 /* SyntaxKind.IntersectionType */:
|
|
159
160
|
return getTypeFromIntersectionTypeNode(c, node);
|
|
160
|
-
case
|
|
161
|
+
case 204 /* SyntaxKind.NamedTupleMember */:
|
|
161
162
|
return getTypeFromNamedTupleTypeNode(c, node);
|
|
162
|
-
case
|
|
163
|
+
case 198 /* SyntaxKind.ParenthesizedType */:
|
|
163
164
|
return getTypeFromTypeNode(c, getType(node));
|
|
164
|
-
case
|
|
165
|
+
case 193 /* SyntaxKind.RestType */:
|
|
165
166
|
return getTypeFromRestTypeNode(c, node);
|
|
166
|
-
case
|
|
167
|
-
case
|
|
168
|
-
case
|
|
167
|
+
case 186 /* SyntaxKind.FunctionType */:
|
|
168
|
+
case 187 /* SyntaxKind.ConstructorType */:
|
|
169
|
+
case 189 /* SyntaxKind.TypeLiteral */:
|
|
169
170
|
return getTypeFromTypeLiteralOrFunctionOrConstructorTypeNode(c, node);
|
|
170
|
-
case
|
|
171
|
+
case 200 /* SyntaxKind.TypeOperator */:
|
|
171
172
|
return getTypeFromTypeOperatorNode(c, node);
|
|
172
|
-
case
|
|
173
|
+
case 201 /* SyntaxKind.IndexedAccessType */:
|
|
173
174
|
return getTypeFromIndexedAccessTypeNode(c, node);
|
|
174
|
-
case
|
|
175
|
+
case 205 /* SyntaxKind.TemplateLiteralType */:
|
|
175
176
|
return getTypeFromTemplateTypeNode(c, node);
|
|
176
|
-
case
|
|
177
|
+
case 202 /* SyntaxKind.MappedType */:
|
|
177
178
|
return getTypeFromMappedTypeNode(c, node);
|
|
178
|
-
case
|
|
179
|
+
case 196 /* SyntaxKind.ConditionalType */:
|
|
179
180
|
return getTypeFromConditionalTypeNode(c, node);
|
|
180
|
-
case
|
|
181
|
+
case 197 /* SyntaxKind.InferType */: {
|
|
181
182
|
let type = c.resolvedTypes.get(node.id);
|
|
182
183
|
if (type === undefined) {
|
|
183
184
|
type = getDeclaredTypeOfTypeParameter(c, getSymbolOfDeclaration(c, node.typeParameter));
|
|
@@ -185,7 +186,7 @@ function getTypeFromTypeNodeWorker(c, node) {
|
|
|
185
186
|
}
|
|
186
187
|
return type;
|
|
187
188
|
}
|
|
188
|
-
case
|
|
189
|
+
case 207 /* SyntaxKind.ImportType */:
|
|
189
190
|
return getTypeFromImportTypeNode(c, node);
|
|
190
191
|
}
|
|
191
192
|
return c.errorType;
|
|
@@ -201,11 +202,11 @@ export function getTypeFromThisTypeNode(c, node) {
|
|
|
201
202
|
function getThisType(c, node) {
|
|
202
203
|
const container = getThisContainer(node, false, false);
|
|
203
204
|
const parent = container.parent;
|
|
204
|
-
if (parent !== undefined && (isClassLike(parent) || parent.kind ===
|
|
205
|
-
if (!isStatic(container) && (container.kind !==
|
|
205
|
+
if (parent !== undefined && (isClassLike(parent) || parent.kind === 266 /* SyntaxKind.InterfaceDeclaration */)) {
|
|
206
|
+
if (!isStatic(container) && (container.kind !== 178 /* SyntaxKind.Constructor */ || isDescendant(node, getBody(container))))
|
|
206
207
|
return getDeclaredTypeOfClassOrInterface(c, getSymbolOfDeclaration(c, parent)).thisType ?? c.errorType;
|
|
207
208
|
}
|
|
208
|
-
c.error(node,
|
|
209
|
+
c.error(node, 691 /* Diagnostics.A_this_type_is_available_only_in_a_non_static_member_of_a_class_or_interface */);
|
|
209
210
|
return c.errorType;
|
|
210
211
|
}
|
|
211
212
|
function isDescendant(node, ancestor) {
|
|
@@ -276,34 +277,39 @@ function getTypeFromTypeOperatorNode(c, node) {
|
|
|
276
277
|
}
|
|
277
278
|
function walkUpParenthesizedTypes(node) {
|
|
278
279
|
let n = node;
|
|
279
|
-
while (n.kind ===
|
|
280
|
+
while (n.kind === 198 /* SyntaxKind.ParenthesizedType */ && n.parent !== undefined)
|
|
280
281
|
n = n.parent;
|
|
281
282
|
return n;
|
|
282
283
|
}
|
|
283
284
|
/** A const variable of a variable statement, a static readonly property, or a readonly property signature. */
|
|
284
285
|
function isValidESSymbolDeclaration(node) {
|
|
285
286
|
switch (node.kind) {
|
|
286
|
-
case
|
|
287
|
+
case 262 /* SyntaxKind.VariableDeclaration */: {
|
|
287
288
|
const list = node.parent;
|
|
288
289
|
return ((getCombinedNodeFlags(node) & 6 /* NodeFlags.Constant */) === 2 /* NodeFlags.Const */ &&
|
|
289
290
|
getName(node).kind === 79 /* SyntaxKind.Identifier */ &&
|
|
290
|
-
list.kind ===
|
|
291
|
-
list.parent.kind ===
|
|
291
|
+
list.kind === 263 /* SyntaxKind.VariableDeclarationList */ &&
|
|
292
|
+
list.parent.kind === 245 /* SyntaxKind.VariableStatement */);
|
|
292
293
|
}
|
|
293
|
-
case
|
|
294
|
+
case 174 /* SyntaxKind.PropertyDeclaration */:
|
|
294
295
|
return hasSyntacticModifier(node, 8 /* ModifierFlags.Readonly */) && isStatic(node);
|
|
295
|
-
case
|
|
296
|
+
case 173 /* SyntaxKind.PropertySignature */:
|
|
296
297
|
return hasSyntacticModifier(node, 8 /* ModifierFlags.Readonly */);
|
|
297
298
|
}
|
|
298
299
|
return false;
|
|
299
300
|
}
|
|
301
|
+
/** tsgo's ast.BlockIdOffset, the first id of the symbols a checker numbers. */
|
|
302
|
+
const symbolBlockIdOffset = 2 ** 48;
|
|
300
303
|
export function getESSymbolLikeTypeForNode(c, node) {
|
|
301
304
|
if (isValidESSymbolDeclaration(node)) {
|
|
302
305
|
const symbol = getSymbolOfDeclaration(c, node);
|
|
303
306
|
if (symbol !== undefined) {
|
|
304
307
|
let uniqueType = c.uniqueESSymbolTypes.get(symbol);
|
|
305
308
|
if (uniqueType === undefined) {
|
|
306
|
-
|
|
309
|
+
// tsgo numbers the symbols its checker keeps links for from 2^48 (ast.BlockIdOffset), and the name's length
|
|
310
|
+
// counts toward the node builder's truncation.
|
|
311
|
+
const name = '@' + symbol.name + '@' + (symbolBlockIdOffset + getSymbolId(symbol));
|
|
312
|
+
uniqueType = new UniqueESSymbolType(c.nextTypeId(), symbol, name);
|
|
307
313
|
c.uniqueESSymbolTypes.set(symbol, uniqueType);
|
|
308
314
|
}
|
|
309
315
|
return uniqueType;
|
|
@@ -313,13 +319,13 @@ export function getESSymbolLikeTypeForNode(c, node) {
|
|
|
313
319
|
}
|
|
314
320
|
// ---- Type references
|
|
315
321
|
function isConstTypeReference(node) {
|
|
316
|
-
if (node.kind !==
|
|
322
|
+
if (node.kind !== 185 /* SyntaxKind.TypeReference */)
|
|
317
323
|
return false;
|
|
318
324
|
const ref = node;
|
|
319
325
|
return (ref.typeName.kind === 79 /* SyntaxKind.Identifier */ && getText(ref.typeName) === 'const' && ref.typeArguments === undefined);
|
|
320
326
|
}
|
|
321
|
-
function isAssertionExpression(node) {
|
|
322
|
-
return (node !== undefined && (node.kind ===
|
|
327
|
+
export function isAssertionExpression(node) {
|
|
328
|
+
return (node !== undefined && (node.kind === 236 /* SyntaxKind.AsExpression */ || node.kind === 218 /* SyntaxKind.TypeAssertionExpression */));
|
|
323
329
|
}
|
|
324
330
|
export function getTypeFromTypeReference(c, node) {
|
|
325
331
|
let type = c.resolvedTypes.get(node.id);
|
|
@@ -329,11 +335,43 @@ export function getTypeFromTypeReference(c, node) {
|
|
|
329
335
|
else
|
|
330
336
|
type =
|
|
331
337
|
getIntendedTypeFromJSDocTypeReference(c, node) ??
|
|
332
|
-
getTypeReferenceType(c, node, getSymbolFromTypeReference(c, node));
|
|
338
|
+
getDistributedTypeParameter(c, node, getTypeReferenceType(c, node, getSymbolFromTypeReference(c, node)));
|
|
333
339
|
c.resolvedTypes.set(node.id, type);
|
|
334
340
|
}
|
|
335
341
|
return type;
|
|
336
342
|
}
|
|
343
|
+
/**
|
|
344
|
+
* The distributed form of a type parameter `t` that `node` references inside a distributive conditional type on
|
|
345
|
+
* it (one whose check type is a bare reference to the type parameter), up to the enclosing statement; otherwise `t`.
|
|
346
|
+
*/
|
|
347
|
+
function getDistributedTypeParameter(c, node, t) {
|
|
348
|
+
if ((t.flags & 524288 /* TypeFlags.TypeParameter */) === 0 || t.isDistributed)
|
|
349
|
+
return t;
|
|
350
|
+
for (let n = node.parent; n !== undefined && !isStatement(n); n = n.parent) {
|
|
351
|
+
if (n.kind !== 196 /* SyntaxKind.ConditionalType */)
|
|
352
|
+
continue;
|
|
353
|
+
const checkTypeNode = n.checkType;
|
|
354
|
+
if (isSimpleIdentifierTypeReference(checkTypeNode) && getSymbolFromTypeReference(c, checkTypeNode) === t.symbol)
|
|
355
|
+
return getDistributedTypeFromTypeParameter(c, t);
|
|
356
|
+
}
|
|
357
|
+
return t;
|
|
358
|
+
}
|
|
359
|
+
function getDistributedTypeFromTypeParameter(c, t) {
|
|
360
|
+
let distributed = t.distributedType;
|
|
361
|
+
if (distributed === undefined) {
|
|
362
|
+
distributed = c.newTypeParameter(t.symbol);
|
|
363
|
+
distributed.isDistributed = true;
|
|
364
|
+
distributed.constraint = t;
|
|
365
|
+
t.distributedType = distributed;
|
|
366
|
+
}
|
|
367
|
+
return distributed;
|
|
368
|
+
}
|
|
369
|
+
/** A type reference that is a bare identifier without type arguments. */
|
|
370
|
+
function isSimpleIdentifierTypeReference(node) {
|
|
371
|
+
return (node.kind === 185 /* SyntaxKind.TypeReference */ &&
|
|
372
|
+
node.typeName.kind === 79 /* SyntaxKind.Identifier */ &&
|
|
373
|
+
node.typeArguments === undefined);
|
|
374
|
+
}
|
|
337
375
|
export function getSymbolFromTypeReference(c, node) {
|
|
338
376
|
let symbol = c.resolvedSymbols.get(node.id);
|
|
339
377
|
if (symbol === undefined) {
|
|
@@ -346,9 +384,9 @@ export function getSymbolFromTypeReference(c, node) {
|
|
|
346
384
|
return symbol;
|
|
347
385
|
}
|
|
348
386
|
function getTypeReferenceName(node) {
|
|
349
|
-
if (node.kind ===
|
|
387
|
+
if (node.kind === 185 /* SyntaxKind.TypeReference */)
|
|
350
388
|
return node.typeName;
|
|
351
|
-
if (node.kind ===
|
|
389
|
+
if (node.kind === 235 /* SyntaxKind.ExpressionWithTypeArguments */) {
|
|
352
390
|
const e = node.expression;
|
|
353
391
|
if (isEntityNameExpression(e))
|
|
354
392
|
return e;
|
|
@@ -358,7 +396,7 @@ function getTypeReferenceName(node) {
|
|
|
358
396
|
function isEntityNameExpression(node) {
|
|
359
397
|
if (node.kind === 79 /* SyntaxKind.Identifier */)
|
|
360
398
|
return true;
|
|
361
|
-
if (node.kind ===
|
|
399
|
+
if (node.kind === 213 /* SyntaxKind.PropertyAccessExpression */) {
|
|
362
400
|
const name = getName(node);
|
|
363
401
|
return name !== undefined && name.kind === 79 /* SyntaxKind.Identifier */ && isEntityNameExpression(getExpression(node));
|
|
364
402
|
}
|
|
@@ -377,9 +415,9 @@ export function resolveTypeReferenceName(c, typeReference, meaning, ignoreErrors
|
|
|
377
415
|
}
|
|
378
416
|
export function getUnresolvedSymbolForEntityName(c, name) {
|
|
379
417
|
let identifier;
|
|
380
|
-
if (name.kind ===
|
|
418
|
+
if (name.kind === 168 /* SyntaxKind.QualifiedName */)
|
|
381
419
|
identifier = name.right;
|
|
382
|
-
else if (name.kind ===
|
|
420
|
+
else if (name.kind === 213 /* SyntaxKind.PropertyAccessExpression */)
|
|
383
421
|
identifier = getName(name);
|
|
384
422
|
else
|
|
385
423
|
identifier = name;
|
|
@@ -387,14 +425,14 @@ export function getUnresolvedSymbolForEntityName(c, name) {
|
|
|
387
425
|
if (text === '')
|
|
388
426
|
return c.unknownSymbol;
|
|
389
427
|
let parentSymbol;
|
|
390
|
-
if (name.kind ===
|
|
428
|
+
if (name.kind === 168 /* SyntaxKind.QualifiedName */)
|
|
391
429
|
parentSymbol = getUnresolvedSymbolForEntityName(c, name.left);
|
|
392
|
-
else if (name.kind ===
|
|
430
|
+
else if (name.kind === 213 /* SyntaxKind.PropertyAccessExpression */)
|
|
393
431
|
parentSymbol = getUnresolvedSymbolForEntityName(c, getExpression(name));
|
|
394
432
|
const path = parentSymbol !== undefined ? getSymbolPath(parentSymbol) + '.' + text : text;
|
|
395
433
|
let result = c.unresolvedSymbols.get(path);
|
|
396
434
|
if (result === undefined) {
|
|
397
|
-
result = c.newSymbolWithCheckFlags(524288 /* SymbolFlags.TypeAlias */, text,
|
|
435
|
+
result = c.newSymbolWithCheckFlags(524288 /* SymbolFlags.TypeAlias */, text, 8388608 /* CheckFlags.Unresolved */);
|
|
398
436
|
c.unresolvedSymbols.set(path, result);
|
|
399
437
|
result.parent = parentSymbol;
|
|
400
438
|
c.symbolLinks(result).declaredType = c.unresolvedType;
|
|
@@ -442,13 +480,13 @@ export function getTypeFromClassOrInterfaceReference(c, node, symbol) {
|
|
|
442
480
|
const isJsImplicitAny = !c.noImplicitAny && isJs;
|
|
443
481
|
if (!isJsImplicitAny && (numTypeArguments < minTypeArgumentCount || numTypeArguments > typeParameters.length)) {
|
|
444
482
|
const message = minTypeArgumentCount < typeParameters.length
|
|
445
|
-
?
|
|
446
|
-
:
|
|
483
|
+
? 846 /* Diagnostics.Generic_type_0_requires_between_1_and_2_type_arguments */
|
|
484
|
+
: 499 /* Diagnostics.Generic_type_0_requires_1_type_argument_s */;
|
|
447
485
|
c.error(node, message, typeToString(c, t, undefined, 1 << 1), String(minTypeArgumentCount), String(typeParameters.length));
|
|
448
486
|
if (!isJs)
|
|
449
487
|
return c.errorType;
|
|
450
488
|
}
|
|
451
|
-
if (node.kind ===
|
|
489
|
+
if (node.kind === 185 /* SyntaxKind.TypeReference */ &&
|
|
452
490
|
isDeferredTypeReferenceNode(c, node, numTypeArguments !== typeParameters.length))
|
|
453
491
|
return createDeferredTypeReference(c, t, node, undefined, getAliasForTypeNode(c, node));
|
|
454
492
|
// Outer type parameters are supplied automatically; the reference gives the local ones.
|
|
@@ -456,13 +494,13 @@ export function getTypeFromClassOrInterfaceReference(c, node, symbol) {
|
|
|
456
494
|
// localTypeArguments is a new list, so without outer type parameters it is the reference's own.
|
|
457
495
|
const outerCount = t.outerTypeParameterCount;
|
|
458
496
|
if (outerCount === 0)
|
|
459
|
-
return createTypeReferenceEx(c, t, localTypeArguments,
|
|
497
|
+
return createTypeReferenceEx(c, t, localTypeArguments, 536870912 /* ObjectFlags.FromTypeNode */);
|
|
460
498
|
const typeArguments = [];
|
|
461
499
|
for (let i = 0; i < outerCount; i++)
|
|
462
500
|
typeArguments.push(t.allTypeParameters[i]);
|
|
463
501
|
for (const typeArgument of localTypeArguments)
|
|
464
502
|
typeArguments.push(typeArgument);
|
|
465
|
-
return createTypeReferenceEx(c, t, typeArguments,
|
|
503
|
+
return createTypeReferenceEx(c, t, typeArguments, 536870912 /* ObjectFlags.FromTypeNode */);
|
|
466
504
|
}
|
|
467
505
|
export function checkNoTypeArguments(c, node, symbol) {
|
|
468
506
|
if (typeArgumentNodesOf(node).length === 0)
|
|
@@ -470,7 +508,7 @@ export function checkNoTypeArguments(c, node, symbol) {
|
|
|
470
508
|
const typeName = symbol !== undefined
|
|
471
509
|
? symbolToString(c, symbol)
|
|
472
510
|
: declarationNameToString(getSourceFileOfNode(node), node.typeName);
|
|
473
|
-
c.error(node,
|
|
511
|
+
c.error(node, 500 /* Diagnostics.Type_0_is_not_generic */, typeName);
|
|
474
512
|
return false;
|
|
475
513
|
}
|
|
476
514
|
/** Directly aliased references, and those possibly in circular chains of eagerly resolved types, are deferred. */
|
|
@@ -480,11 +518,11 @@ function isDeferredTypeReferenceNode(c, node, hasDefaultTypeArguments) {
|
|
|
480
518
|
if (!isResolvedByTypeAlias(node))
|
|
481
519
|
return false;
|
|
482
520
|
switch (node.kind) {
|
|
483
|
-
case
|
|
521
|
+
case 190 /* SyntaxKind.ArrayType */:
|
|
484
522
|
return mayResolveTypeAlias(c, node.elementType);
|
|
485
|
-
case
|
|
523
|
+
case 191 /* SyntaxKind.TupleType */:
|
|
486
524
|
return someMayResolveTypeAlias(c, node.elements.nodes);
|
|
487
|
-
case
|
|
525
|
+
case 185 /* SyntaxKind.TypeReference */:
|
|
488
526
|
return hasDefaultTypeArguments || someMayResolveTypeAlias(c, typeArgumentNodesOf(node));
|
|
489
527
|
}
|
|
490
528
|
return false;
|
|
@@ -492,48 +530,48 @@ function isDeferredTypeReferenceNode(c, node, hasDefaultTypeArguments) {
|
|
|
492
530
|
function isResolvedByTypeAlias(node) {
|
|
493
531
|
const parent = node.parent;
|
|
494
532
|
switch (parent.kind) {
|
|
495
|
-
case
|
|
496
|
-
case
|
|
497
|
-
case
|
|
498
|
-
case
|
|
499
|
-
case
|
|
500
|
-
case
|
|
501
|
-
case
|
|
502
|
-
case
|
|
503
|
-
case
|
|
504
|
-
case
|
|
533
|
+
case 198 /* SyntaxKind.ParenthesizedType */:
|
|
534
|
+
case 204 /* SyntaxKind.NamedTupleMember */:
|
|
535
|
+
case 185 /* SyntaxKind.TypeReference */:
|
|
536
|
+
case 194 /* SyntaxKind.UnionType */:
|
|
537
|
+
case 195 /* SyntaxKind.IntersectionType */:
|
|
538
|
+
case 201 /* SyntaxKind.IndexedAccessType */:
|
|
539
|
+
case 196 /* SyntaxKind.ConditionalType */:
|
|
540
|
+
case 200 /* SyntaxKind.TypeOperator */:
|
|
541
|
+
case 190 /* SyntaxKind.ArrayType */:
|
|
542
|
+
case 191 /* SyntaxKind.TupleType */:
|
|
505
543
|
return isResolvedByTypeAlias(parent);
|
|
506
|
-
case
|
|
507
|
-
case
|
|
544
|
+
case 267 /* SyntaxKind.TypeAliasDeclaration */:
|
|
545
|
+
case 346 /* SyntaxKind.JSTypeAliasDeclaration */:
|
|
508
546
|
return true;
|
|
509
547
|
}
|
|
510
548
|
return false;
|
|
511
549
|
}
|
|
512
550
|
function mayResolveTypeAlias(c, node) {
|
|
513
551
|
switch (node.kind) {
|
|
514
|
-
case
|
|
552
|
+
case 185 /* SyntaxKind.TypeReference */:
|
|
515
553
|
return (resolveTypeReferenceName(c, node, 788968 /* SymbolFlags.Type */, false).flags & 524288 /* SymbolFlags.TypeAlias */) !== 0;
|
|
516
|
-
case
|
|
554
|
+
case 188 /* SyntaxKind.TypeQuery */:
|
|
517
555
|
return true;
|
|
518
|
-
case
|
|
556
|
+
case 200 /* SyntaxKind.TypeOperator */:
|
|
519
557
|
return (node.operator !== 158 /* SyntaxKind.UniqueKeyword */ &&
|
|
520
558
|
mayResolveTypeAlias(c, node.type));
|
|
521
|
-
case
|
|
522
|
-
case
|
|
523
|
-
case
|
|
559
|
+
case 198 /* SyntaxKind.ParenthesizedType */:
|
|
560
|
+
case 192 /* SyntaxKind.OptionalType */:
|
|
561
|
+
case 204 /* SyntaxKind.NamedTupleMember */:
|
|
524
562
|
return mayResolveTypeAlias(c, getType(node));
|
|
525
|
-
case
|
|
563
|
+
case 193 /* SyntaxKind.RestType */: {
|
|
526
564
|
const t = node.type;
|
|
527
|
-
return t.kind !==
|
|
565
|
+
return t.kind !== 190 /* SyntaxKind.ArrayType */ || mayResolveTypeAlias(c, t.elementType);
|
|
528
566
|
}
|
|
529
|
-
case
|
|
567
|
+
case 194 /* SyntaxKind.UnionType */:
|
|
530
568
|
return someMayResolveTypeAlias(c, node.types.nodes);
|
|
531
|
-
case
|
|
569
|
+
case 195 /* SyntaxKind.IntersectionType */:
|
|
532
570
|
return someMayResolveTypeAlias(c, node.types.nodes);
|
|
533
|
-
case
|
|
571
|
+
case 201 /* SyntaxKind.IndexedAccessType */:
|
|
534
572
|
return (mayResolveTypeAlias(c, node.objectType) ||
|
|
535
573
|
mayResolveTypeAlias(c, node.indexType));
|
|
536
|
-
case
|
|
574
|
+
case 196 /* SyntaxKind.ConditionalType */: {
|
|
537
575
|
const n = node;
|
|
538
576
|
return (mayResolveTypeAlias(c, n.checkType) ||
|
|
539
577
|
mayResolveTypeAlias(c, n.extendsType) ||
|
|
@@ -551,7 +589,7 @@ function someMayResolveTypeAlias(c, nodes) {
|
|
|
551
589
|
}
|
|
552
590
|
// ---- Type aliases
|
|
553
591
|
export function isTypeAlias(node) {
|
|
554
|
-
return node.kind ===
|
|
592
|
+
return node.kind === 267 /* SyntaxKind.TypeAliasDeclaration */ || node.kind === 346 /* SyntaxKind.JSTypeAliasDeclaration */;
|
|
555
593
|
}
|
|
556
594
|
export function getAliasForTypeNode(c, node) {
|
|
557
595
|
const symbol = getAliasSymbolForTypeNode(c, node);
|
|
@@ -561,8 +599,8 @@ export function getAliasForTypeNode(c, node) {
|
|
|
561
599
|
}
|
|
562
600
|
export function getAliasSymbolForTypeNode(c, node) {
|
|
563
601
|
let host = node.parent;
|
|
564
|
-
while (host.kind ===
|
|
565
|
-
(host.kind ===
|
|
602
|
+
while (host.kind === 198 /* SyntaxKind.ParenthesizedType */ ||
|
|
603
|
+
(host.kind === 200 /* SyntaxKind.TypeOperator */ && host.operator === 148 /* SyntaxKind.ReadonlyKeyword */))
|
|
566
604
|
host = host.parent;
|
|
567
605
|
return isTypeAlias(host) ? getSymbolOfDeclaration(c, host) : undefined;
|
|
568
606
|
}
|
|
@@ -578,13 +616,13 @@ function isLocalTypeAlias(symbol) {
|
|
|
578
616
|
return false;
|
|
579
617
|
for (let n = declaration.parent; n !== undefined; n = n.parent) {
|
|
580
618
|
switch (n.kind) {
|
|
581
|
-
case
|
|
582
|
-
case
|
|
583
|
-
case
|
|
584
|
-
case
|
|
585
|
-
case
|
|
586
|
-
case
|
|
587
|
-
case
|
|
619
|
+
case 264 /* SyntaxKind.FunctionDeclaration */:
|
|
620
|
+
case 220 /* SyntaxKind.FunctionExpression */:
|
|
621
|
+
case 221 /* SyntaxKind.ArrowFunction */:
|
|
622
|
+
case 176 /* SyntaxKind.MethodDeclaration */:
|
|
623
|
+
case 178 /* SyntaxKind.Constructor */:
|
|
624
|
+
case 179 /* SyntaxKind.GetAccessor */:
|
|
625
|
+
case 180 /* SyntaxKind.SetAccessor */:
|
|
588
626
|
return true;
|
|
589
627
|
}
|
|
590
628
|
}
|
|
@@ -592,7 +630,7 @@ function isLocalTypeAlias(symbol) {
|
|
|
592
630
|
}
|
|
593
631
|
function getTypeFromTypeAliasReference(c, node, symbol) {
|
|
594
632
|
const typeArgumentNodes = typeArgumentNodesOf(node);
|
|
595
|
-
if ((symbol.checkFlags &
|
|
633
|
+
if ((symbol.checkFlags & 8388608 /* CheckFlags.Unresolved */) !== 0) {
|
|
596
634
|
const alias = new TypeAlias(symbol, getTypesFromTypeNodes(c, typeArgumentNodes));
|
|
597
635
|
const key = aliasKey(alias);
|
|
598
636
|
let errorType = c.errorTypes.get(key);
|
|
@@ -610,8 +648,8 @@ function getTypeFromTypeAliasReference(c, node, symbol) {
|
|
|
610
648
|
const minTypeArgumentCount = getMinTypeArgumentCount(c, typeParameters);
|
|
611
649
|
if (numTypeArguments < minTypeArgumentCount || numTypeArguments > typeParameters.length) {
|
|
612
650
|
const message = minTypeArgumentCount === typeParameters.length
|
|
613
|
-
?
|
|
614
|
-
:
|
|
651
|
+
? 499 /* Diagnostics.Generic_type_0_requires_1_type_argument_s */
|
|
652
|
+
: 846 /* Diagnostics.Generic_type_0_requires_between_1_and_2_type_arguments */;
|
|
615
653
|
c.error(node, message, symbolToString(c, symbol), String(minTypeArgumentCount), String(typeParameters.length));
|
|
616
654
|
return c.errorType;
|
|
617
655
|
}
|
|
@@ -623,7 +661,7 @@ function getTypeFromTypeAliasReference(c, node, symbol) {
|
|
|
623
661
|
let aliasTypeArguments;
|
|
624
662
|
if (newAliasSymbol !== undefined)
|
|
625
663
|
aliasTypeArguments = getLocalTypeParametersOfClassOrInterfaceOrTypeAlias(c, newAliasSymbol);
|
|
626
|
-
else if (node.kind ===
|
|
664
|
+
else if (node.kind === 185 /* SyntaxKind.TypeReference */) {
|
|
627
665
|
const aliased = resolveTypeReferenceName(c, node, 2097152 /* SymbolFlags.Alias */, true);
|
|
628
666
|
if (aliased !== c.unknownSymbol) {
|
|
629
667
|
const resolved = resolveAlias(c, aliased);
|
|
@@ -675,13 +713,13 @@ function getTypeFromTypeQueryNode(c, node) {
|
|
|
675
713
|
}
|
|
676
714
|
export function getTupleElementFlags(c, node) {
|
|
677
715
|
switch (node.kind) {
|
|
678
|
-
case
|
|
716
|
+
case 192 /* SyntaxKind.OptionalType */:
|
|
679
717
|
return 2 /* ElementFlags.Optional */;
|
|
680
|
-
case
|
|
718
|
+
case 193 /* SyntaxKind.RestType */:
|
|
681
719
|
return getArrayElementTypeNode(node.type) !== undefined
|
|
682
720
|
? 4 /* ElementFlags.Rest */
|
|
683
721
|
: 8 /* ElementFlags.Variadic */;
|
|
684
|
-
case
|
|
722
|
+
case 204 /* SyntaxKind.NamedTupleMember */: {
|
|
685
723
|
const named = node;
|
|
686
724
|
if (named.questionToken !== undefined)
|
|
687
725
|
return 2 /* ElementFlags.Optional */;
|
|
@@ -693,31 +731,31 @@ export function getTupleElementFlags(c, node) {
|
|
|
693
731
|
return 1 /* ElementFlags.Required */;
|
|
694
732
|
}
|
|
695
733
|
function getTupleElementInfo(c, node) {
|
|
696
|
-
return new TupleElementInfo(getTupleElementFlags(c, node), node.kind ===
|
|
734
|
+
return new TupleElementInfo(getTupleElementFlags(c, node), node.kind === 204 /* SyntaxKind.NamedTupleMember */ || node.kind === 171 /* SyntaxKind.Parameter */ ? node : undefined);
|
|
697
735
|
}
|
|
698
736
|
function getArrayElementTypeNode(node) {
|
|
699
737
|
switch (node.kind) {
|
|
700
|
-
case
|
|
738
|
+
case 198 /* SyntaxKind.ParenthesizedType */:
|
|
701
739
|
return getArrayElementTypeNode(getType(node));
|
|
702
|
-
case
|
|
740
|
+
case 191 /* SyntaxKind.TupleType */: {
|
|
703
741
|
const elements = node.elements.nodes;
|
|
704
742
|
if (elements.length === 1) {
|
|
705
743
|
const e = elements[0];
|
|
706
|
-
if (e.kind ===
|
|
744
|
+
if (e.kind === 193 /* SyntaxKind.RestType */)
|
|
707
745
|
return getArrayElementTypeNode(e.type);
|
|
708
|
-
if (e.kind ===
|
|
746
|
+
if (e.kind === 204 /* SyntaxKind.NamedTupleMember */ && e.dotDotDotToken !== undefined)
|
|
709
747
|
return getArrayElementTypeNode(e.type);
|
|
710
748
|
}
|
|
711
749
|
return undefined;
|
|
712
750
|
}
|
|
713
|
-
case
|
|
751
|
+
case 190 /* SyntaxKind.ArrayType */:
|
|
714
752
|
return node.elementType;
|
|
715
753
|
}
|
|
716
754
|
return undefined;
|
|
717
755
|
}
|
|
718
756
|
function getArrayOrTupleTargetType(c, node) {
|
|
719
757
|
const parent = node.parent;
|
|
720
|
-
const readonly = parent.kind ===
|
|
758
|
+
const readonly = parent.kind === 200 /* SyntaxKind.TypeOperator */ && parent.operator === 148 /* SyntaxKind.ReadonlyKeyword */;
|
|
721
759
|
if (getArrayElementTypeNode(node) !== undefined)
|
|
722
760
|
return readonly ? c.globalReadonlyArrayType : c.globalArrayType;
|
|
723
761
|
const elementInfos = [];
|
|
@@ -732,18 +770,18 @@ function getTypeFromArrayOrTupleTypeNode(c, node) {
|
|
|
732
770
|
const target = getArrayOrTupleTargetType(c, node);
|
|
733
771
|
if (target === c.emptyGenericType)
|
|
734
772
|
c.resolvedTypes.set(node.id, c.emptyObjectType);
|
|
735
|
-
else if (!(node.kind ===
|
|
773
|
+
else if (!(node.kind === 191 /* SyntaxKind.TupleType */ && hasVariadicTupleElement(c, node)) &&
|
|
736
774
|
isDeferredTypeReferenceNode(c, node, false))
|
|
737
|
-
c.resolvedTypes.set(node.id, node.kind ===
|
|
775
|
+
c.resolvedTypes.set(node.id, node.kind === 191 /* SyntaxKind.TupleType */ && node.elements.nodes.length === 0
|
|
738
776
|
? target
|
|
739
777
|
: createDeferredTypeReference(c, target, node, undefined, getAliasForTypeNode(c, node)));
|
|
740
778
|
else {
|
|
741
|
-
const elementTypes = node.kind ===
|
|
779
|
+
const elementTypes = node.kind === 190 /* SyntaxKind.ArrayType */
|
|
742
780
|
? [getTypeFromTypeNode(c, node.elementType)]
|
|
743
781
|
: getTypesFromTypeNodes(c, node.elements.nodes);
|
|
744
782
|
c.resolvedTypes.set(node.id, (target.objectFlags & 8 /* ObjectFlags.Tuple */) !== 0
|
|
745
|
-
? createNormalizedTupleType(c, target, elementTypes,
|
|
746
|
-
: createTypeReferenceEx(c, target, elementTypes,
|
|
783
|
+
? createNormalizedTupleType(c, target, elementTypes, 536870912 /* ObjectFlags.FromTypeNode */)
|
|
784
|
+
: createTypeReferenceEx(c, target, elementTypes, 536870912 /* ObjectFlags.FromTypeNode */));
|
|
747
785
|
}
|
|
748
786
|
return c.resolvedTypes.get(node.id);
|
|
749
787
|
}
|
|
@@ -756,13 +794,13 @@ function hasVariadicTupleElement(c, node) {
|
|
|
756
794
|
/** Type arguments of a deferred reference from its node. */
|
|
757
795
|
export function getTypeArgumentsOfDeferredReference(c, node, target) {
|
|
758
796
|
switch (node.kind) {
|
|
759
|
-
case
|
|
797
|
+
case 185 /* SyntaxKind.TypeReference */:
|
|
760
798
|
return target
|
|
761
799
|
.outerTypeParameters()
|
|
762
800
|
.concat(fillMissingTypeArguments(c, getTypeArgumentsFromNode(c, node), target.localTypeParameters(), getMinTypeArgumentCount(c, target.localTypeParameters()), (node.flags & 65536 /* NodeFlags.JavaScriptFile */) !== 0));
|
|
763
|
-
case
|
|
801
|
+
case 190 /* SyntaxKind.ArrayType */:
|
|
764
802
|
return [getTypeFromTypeNode(c, node.elementType)];
|
|
765
|
-
case
|
|
803
|
+
case 191 /* SyntaxKind.TupleType */:
|
|
766
804
|
return getTypesFromTypeNodes(c, node.elements.nodes);
|
|
767
805
|
}
|
|
768
806
|
return [];
|