tsc-ts 0.0.10 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/bin/tsc-ts.js +70 -1
- package/dist/api/compiler/ast-utilities.d.ts +19 -1
- package/dist/api/compiler/ast-utilities.js +180 -95
- package/dist/api/compiler/ast.d.ts +20 -15
- package/dist/api/compiler/ast.js +1023 -995
- package/dist/api/compiler/astnav.js +15 -15
- package/dist/api/compiler/binder-utilities.js +186 -186
- package/dist/api/compiler/binder.js +290 -263
- package/dist/api/compiler/character-codes.js +2 -2
- package/dist/api/compiler/checker-calls.js +173 -123
- package/dist/api/compiler/checker-classes.d.ts +14 -3
- package/dist/api/compiler/checker-classes.js +134 -90
- package/dist/api/compiler/checker-contextual.js +64 -61
- package/dist/api/compiler/checker-declaration-order.js +79 -79
- package/dist/api/compiler/checker-declarations.d.ts +1 -0
- package/dist/api/compiler/checker-declarations.js +160 -136
- package/dist/api/compiler/checker-declared-types.js +67 -65
- package/dist/api/compiler/checker-decorators.js +77 -77
- package/dist/api/compiler/checker-deprecation.d.ts +8 -3
- package/dist/api/compiler/checker-deprecation.js +76 -55
- package/dist/api/compiler/checker-destructuring.js +47 -45
- package/dist/api/compiler/checker-elaboration.js +24 -24
- package/dist/api/compiler/checker-emit-helpers.js +4 -4
- package/dist/api/compiler/checker-emit-resolver.d.ts +4 -2
- package/dist/api/compiler/checker-emit-resolver.js +25 -13
- package/dist/api/compiler/checker-evaluator.js +9 -9
- package/dist/api/compiler/checker-expressions.js +244 -211
- package/dist/api/compiler/checker-functions.js +113 -107
- package/dist/api/compiler/checker-generated-code.d.ts +0 -11
- package/dist/api/compiler/checker-generated-code.js +28 -52
- package/dist/api/compiler/checker-grammar.d.ts +1 -0
- package/dist/api/compiler/checker-grammar.js +469 -438
- package/dist/api/compiler/checker-heritage.js +91 -93
- package/dist/api/compiler/checker-inference.d.ts +77 -5
- package/dist/api/compiler/checker-inference.js +487 -113
- package/dist/api/compiler/checker-iteration.d.ts +0 -10
- package/dist/api/compiler/checker-iteration.js +35 -52
- package/dist/api/compiler/checker-javascript.js +14 -14
- package/dist/api/compiler/checker-jsdoc.d.ts +8 -10
- package/dist/api/compiler/checker-jsdoc.js +67 -58
- package/dist/api/compiler/checker-jsx.js +105 -88
- package/dist/api/compiler/checker-members.d.ts +9 -2
- package/dist/api/compiler/checker-members.js +210 -74
- package/dist/api/compiler/checker-modules.d.ts +15 -6
- package/dist/api/compiler/checker-modules.js +469 -309
- package/dist/api/compiler/checker-narrowing.js +273 -189
- package/dist/api/compiler/checker-object-literals.js +25 -22
- package/dist/api/compiler/checker-operators.js +126 -118
- package/dist/api/compiler/checker-overloads.js +27 -27
- package/dist/api/compiler/checker-property-access.js +59 -55
- package/dist/api/compiler/checker-services.d.ts +1 -0
- package/dist/api/compiler/checker-services.js +222 -210
- package/dist/api/compiler/checker-signatures.js +65 -49
- package/dist/api/compiler/checker-source-file.d.ts +5 -0
- package/dist/api/compiler/checker-source-file.js +154 -130
- package/dist/api/compiler/checker-statements.js +33 -32
- package/dist/api/compiler/checker-super.js +50 -50
- package/dist/api/compiler/checker-symbol-types.js +109 -93
- package/dist/api/compiler/checker-symbols.d.ts +13 -1
- package/dist/api/compiler/checker-symbols.js +264 -149
- package/dist/api/compiler/checker-type-factory.d.ts +5 -0
- package/dist/api/compiler/checker-type-factory.js +137 -34
- package/dist/api/compiler/checker-type-nodes.d.ts +1 -0
- package/dist/api/compiler/checker-type-nodes.js +179 -141
- package/dist/api/compiler/checker-type-operators.d.ts +2 -0
- package/dist/api/compiler/checker-type-operators.js +110 -63
- package/dist/api/compiler/checker-types.d.ts +80 -3
- package/dist/api/compiler/checker-types.js +121 -2
- package/dist/api/compiler/checker-unused.js +114 -118
- package/dist/api/compiler/checker-utilities.js +11 -11
- package/dist/api/compiler/checker.d.ts +93 -31
- package/dist/api/compiler/checker.js +143 -35
- package/dist/api/compiler/command-line.d.ts +1 -3
- package/dist/api/compiler/command-line.js +47 -44
- package/dist/api/compiler/compile-program.d.ts +19 -4
- package/dist/api/compiler/compile-program.js +45 -26
- package/dist/api/compiler/diagnostic-messages.d.ts +1849 -1774
- package/dist/api/compiler/diagnostic-messages.js +128 -122
- package/dist/api/compiler/diagnostics.js +7 -7
- package/dist/api/compiler/emitter.d.ts +7 -1
- package/dist/api/compiler/emitter.js +53 -11
- package/dist/api/compiler/file-include.d.ts +2 -1
- package/dist/api/compiler/file-include.js +11 -7
- package/dist/api/compiler/file-loader.d.ts +10 -0
- package/dist/api/compiler/file-loader.js +138 -41
- package/dist/api/compiler/instantiation.d.ts +7 -0
- package/dist/api/compiler/instantiation.js +101 -49
- package/dist/api/compiler/jsdoc.js +23 -23
- package/dist/api/compiler/link-tables.d.ts +48 -18
- package/dist/api/compiler/link-tables.js +80 -37
- package/dist/api/compiler/locales/cs-CZ.d.ts +1 -1
- package/dist/api/compiler/locales/cs-CZ.js +1 -1
- package/dist/api/compiler/locales/de-DE.d.ts +1 -1
- package/dist/api/compiler/locales/de-DE.js +1 -1
- package/dist/api/compiler/locales/es-ES.d.ts +1 -1
- package/dist/api/compiler/locales/es-ES.js +1 -1
- package/dist/api/compiler/locales/fr-FR.d.ts +1 -1
- package/dist/api/compiler/locales/fr-FR.js +1 -1
- package/dist/api/compiler/locales/it-IT.d.ts +1 -1
- package/dist/api/compiler/locales/it-IT.js +1 -1
- package/dist/api/compiler/locales/ja-JP.d.ts +1 -1
- package/dist/api/compiler/locales/ja-JP.js +1 -1
- package/dist/api/compiler/locales/ko-KR.d.ts +1 -1
- package/dist/api/compiler/locales/ko-KR.js +1 -1
- package/dist/api/compiler/locales/pl-PL.d.ts +1 -1
- package/dist/api/compiler/locales/pl-PL.js +1 -1
- package/dist/api/compiler/locales/pt-BR.d.ts +1 -1
- package/dist/api/compiler/locales/pt-BR.js +1 -1
- package/dist/api/compiler/locales/ru-RU.d.ts +1 -1
- package/dist/api/compiler/locales/ru-RU.js +1 -1
- package/dist/api/compiler/locales/tr-TR.d.ts +1 -1
- package/dist/api/compiler/locales/tr-TR.js +1 -1
- package/dist/api/compiler/locales/zh-CN.d.ts +1 -1
- package/dist/api/compiler/locales/zh-CN.js +1 -1
- package/dist/api/compiler/locales/zh-TW.d.ts +1 -1
- package/dist/api/compiler/locales/zh-TW.js +1 -1
- package/dist/api/compiler/module-resolution-types.js +6 -6
- package/dist/api/compiler/module-resolution.d.ts +10 -1
- package/dist/api/compiler/module-resolution.js +115 -84
- package/dist/api/compiler/module-specifiers.d.ts +15 -0
- package/dist/api/compiler/module-specifiers.js +24 -18
- package/dist/api/compiler/name-resolver.js +74 -65
- package/dist/api/compiler/node-builder-names.d.ts +11 -3
- package/dist/api/compiler/node-builder-names.js +210 -90
- package/dist/api/compiler/node-builder-pseudo.js +29 -31
- package/dist/api/compiler/node-builder-reuse.js +23 -22
- package/dist/api/compiler/node-builder.d.ts +18 -1
- package/dist/api/compiler/node-builder.js +191 -102
- package/dist/api/compiler/option-declarations.d.ts +2 -6
- package/dist/api/compiler/option-declarations.js +315 -375
- package/dist/api/compiler/options.d.ts +15 -33
- package/dist/api/compiler/options.js +21 -54
- package/dist/api/compiler/output-paths.d.ts +4 -1
- package/dist/api/compiler/output-paths.js +6 -11
- package/dist/api/compiler/package-json.d.ts +3 -3
- package/dist/api/compiler/package-json.js +11 -10
- package/dist/api/compiler/parser.d.ts +40 -19
- package/dist/api/compiler/parser.js +308 -216
- package/dist/api/compiler/path.d.ts +9 -0
- package/dist/api/compiler/path.js +20 -3
- package/dist/api/compiler/printer/emit-context.d.ts +3 -1
- package/dist/api/compiler/printer/emit-context.js +16 -1
- package/dist/api/compiler/printer/factory-base.d.ts +2 -2
- package/dist/api/compiler/printer/factory-base.js +7 -3
- package/dist/api/compiler/printer/factory.js +3 -1
- package/dist/api/compiler/printer/helpers.js +10 -1
- package/dist/api/compiler/printer/name-generator.d.ts +1 -1
- package/dist/api/compiler/printer/name-generator.js +35 -16
- package/dist/api/compiler/printer/printer.d.ts +1 -0
- package/dist/api/compiler/printer/printer.js +303 -281
- package/dist/api/compiler/printer/utilities.js +149 -147
- package/dist/api/compiler/program-checker.d.ts +8 -2
- package/dist/api/compiler/program-checker.js +84 -34
- package/dist/api/compiler/program-utilities.d.ts +3 -1
- package/dist/api/compiler/program-utilities.js +28 -15
- package/dist/api/compiler/program.d.ts +2 -0
- package/dist/api/compiler/program.js +69 -57
- package/dist/api/compiler/pseudo-bigint.d.ts +2 -0
- package/dist/api/compiler/pseudo-bigint.js +18 -0
- package/dist/api/compiler/regexp-checker.d.ts +1 -1
- package/dist/api/compiler/regexp-checker.js +93 -76
- package/dist/api/compiler/relations.d.ts +27 -4
- package/dist/api/compiler/relations.js +337 -180
- package/dist/api/compiler/reparser.js +60 -56
- package/dist/api/compiler/scanner.d.ts +19 -2
- package/dist/api/compiler/scanner.js +123 -108
- package/dist/api/compiler/shared-results.d.ts +463 -0
- package/dist/api/compiler/shared-results.js +2128 -0
- package/dist/api/compiler/sourcemap.js +2 -2
- package/dist/api/compiler/symbol-accessibility.js +87 -74
- package/dist/api/compiler/symbol.d.ts +22 -13
- package/dist/api/compiler/symbol.js +15 -1
- package/dist/api/compiler/syntax-kind.d.ts +198 -197
- package/dist/api/compiler/transformers/alias-references.js +247 -139
- package/dist/api/compiler/transformers/async-utilities.js +25 -25
- package/dist/api/compiler/transformers/async.d.ts +0 -1
- package/dist/api/compiler/transformers/async.js +64 -77
- package/dist/api/compiler/transformers/class-fields.d.ts +1 -0
- package/dist/api/compiler/transformers/class-fields.js +81 -78
- package/dist/api/compiler/transformers/commonjs-module.js +18 -15
- package/dist/api/compiler/transformers/const-enum-inliner.js +1 -1
- package/dist/api/compiler/transformers/declarations-diagnostics.js +247 -244
- package/dist/api/compiler/transformers/declarations-pseudo.js +100 -100
- package/dist/api/compiler/transformers/declarations-resolver.d.ts +0 -3
- package/dist/api/compiler/transformers/declarations-syntactic.d.ts +1 -2
- package/dist/api/compiler/transformers/declarations-syntactic.js +134 -156
- package/dist/api/compiler/transformers/declarations-tracker.js +18 -18
- package/dist/api/compiler/transformers/declarations.d.ts +4 -1
- package/dist/api/compiler/transformers/declarations.js +305 -238
- package/dist/api/compiler/transformers/decorator-metadata.d.ts +1 -1
- package/dist/api/compiler/transformers/decorator-metadata.js +53 -45
- package/dist/api/compiler/transformers/decorator-utilities.js +24 -24
- package/dist/api/compiler/transformers/destructuring.js +19 -18
- package/dist/api/compiler/transformers/emit-resolver.js +1 -1
- package/dist/api/compiler/transformers/es-decorators.js +55 -55
- package/dist/api/compiler/transformers/external-module-info.js +3 -3
- package/dist/api/compiler/transformers/for-await.js +25 -25
- package/dist/api/compiler/transformers/import-elision.js +14 -14
- package/dist/api/compiler/transformers/jsx.js +12 -12
- package/dist/api/compiler/transformers/legacy-decorators.js +17 -17
- package/dist/api/compiler/transformers/module.js +8 -8
- package/dist/api/compiler/transformers/named-evaluation.js +4 -4
- package/dist/api/compiler/transformers/object-rest-spread.js +20 -20
- package/dist/api/compiler/transformers/optional-chain.js +10 -10
- package/dist/api/compiler/transformers/reference-resolver.d.ts +12 -1
- package/dist/api/compiler/transformers/reference-resolver.js +131 -69
- package/dist/api/compiler/transformers/runtime-syntax.js +35 -31
- package/dist/api/compiler/transformers/subtree-facts.js +47 -47
- package/dist/api/compiler/transformers/syntax-facts.js +56 -58
- package/dist/api/compiler/transformers/type-eraser.js +73 -66
- package/dist/api/compiler/transformers/type-serialization.js +24 -24
- package/dist/api/compiler/transformers/using.js +12 -12
- package/dist/api/compiler/transformers/utilities.js +77 -77
- package/dist/api/compiler/transformers/visitor-base.js +172 -172
- package/dist/api/compiler/transformers/visitor-hooks.js +6 -2
- package/dist/api/compiler/tsconfig.d.ts +10 -2
- package/dist/api/compiler/tsconfig.js +136 -48
- package/dist/api/compiler/type-printer.js +40 -3
- package/dist/api/compiler/types.d.ts +2 -1
- package/dist/api/library/ast.generated.d.ts +42 -39
- package/dist/api/library/ast.generated.js +1 -1
- package/dist/api/library/compiler-options.generated.d.ts +111 -100
- package/dist/api/library/compiler-options.generated.js +1 -1
- package/dist/api/library/disk.js +12 -1
- package/dist/api/library/enums.generated.d.ts +206 -206
- package/dist/api/library/enums.generated.js +206 -206
- package/dist/api/library/nodes.js +26 -26
- package/package.json +9 -9
- package/src/compiler/ast-utilities.ts +99 -7
- package/src/compiler/ast.ts +55 -26
- package/src/compiler/binder.ts +39 -4
- package/src/compiler/character-codes.ts +2 -2
- package/src/compiler/checker-calls.ts +76 -8
- package/src/compiler/checker-classes.ts +78 -24
- package/src/compiler/checker-contextual.ts +6 -1
- package/src/compiler/checker-declarations.ts +31 -4
- package/src/compiler/checker-declared-types.ts +8 -5
- package/src/compiler/checker-decorators.ts +1 -1
- package/src/compiler/checker-deprecation.ts +29 -8
- package/src/compiler/checker-destructuring.ts +10 -3
- package/src/compiler/checker-emit-helpers.ts +1 -0
- package/src/compiler/checker-emit-resolver.ts +16 -6
- package/src/compiler/checker-expressions.ts +79 -46
- package/src/compiler/checker-functions.ts +21 -6
- package/src/compiler/checker-generated-code.ts +2 -22
- package/src/compiler/checker-grammar.ts +133 -60
- package/src/compiler/checker-heritage.ts +22 -21
- package/src/compiler/checker-inference.ts +514 -87
- package/src/compiler/checker-iteration.ts +18 -31
- package/src/compiler/checker-javascript.ts +1 -1
- package/src/compiler/checker-jsdoc.ts +50 -27
- package/src/compiler/checker-jsx.ts +26 -4
- package/src/compiler/checker-members.ts +197 -55
- package/src/compiler/checker-modules.ts +332 -65
- package/src/compiler/checker-narrowing.ts +98 -19
- package/src/compiler/checker-object-literals.ts +3 -0
- package/src/compiler/checker-operators.ts +11 -4
- package/src/compiler/checker-property-access.ts +7 -2
- package/src/compiler/checker-services.ts +39 -12
- package/src/compiler/checker-signatures.ts +15 -1
- package/src/compiler/checker-source-file.ts +39 -13
- package/src/compiler/checker-statements.ts +3 -2
- package/src/compiler/checker-symbol-types.ts +29 -6
- package/src/compiler/checker-symbols.ts +158 -15
- package/src/compiler/checker-type-factory.ts +120 -21
- package/src/compiler/checker-type-nodes.ts +46 -3
- package/src/compiler/checker-type-operators.ts +83 -26
- package/src/compiler/checker-types.ts +147 -4
- package/src/compiler/checker-unused.ts +9 -14
- package/src/compiler/checker.ts +168 -41
- package/src/compiler/command-line.ts +28 -28
- package/src/compiler/compile-program.ts +51 -25
- package/src/compiler/decoder.ts +13 -4
- package/src/compiler/diagnostic-messages.ts +1973 -1892
- package/src/compiler/emitter.ts +57 -8
- package/src/compiler/encoder.ts +23 -8
- package/src/compiler/file-include.ts +9 -3
- package/src/compiler/file-loader.ts +139 -32
- package/src/compiler/help.ts +10 -14
- package/src/compiler/incremental.ts +86 -18
- package/src/compiler/init.ts +2 -7
- package/src/compiler/instantiation.ts +77 -22
- package/src/compiler/jsdoc.ts +3 -1
- package/src/compiler/link-tables.ts +82 -37
- package/src/compiler/locales/cs-CZ.ts +1 -1
- package/src/compiler/locales/de-DE.ts +1 -1
- package/src/compiler/locales/es-ES.ts +1 -1
- package/src/compiler/locales/fr-FR.ts +1 -1
- package/src/compiler/locales/it-IT.ts +1 -1
- package/src/compiler/locales/ja-JP.ts +1 -1
- package/src/compiler/locales/ko-KR.ts +1 -1
- package/src/compiler/locales/pl-PL.ts +1 -1
- package/src/compiler/locales/pt-BR.ts +1 -1
- package/src/compiler/locales/ru-RU.ts +1 -1
- package/src/compiler/locales/tr-TR.ts +1 -1
- package/src/compiler/locales/zh-CN.ts +1 -1
- package/src/compiler/locales/zh-TW.ts +1 -1
- package/src/compiler/module-resolution.ts +44 -8
- package/src/compiler/module-specifiers.ts +62 -20
- package/src/compiler/name-resolver.ts +9 -1
- package/src/compiler/node-builder-names.ts +236 -54
- package/src/compiler/node-builder-pseudo.ts +4 -7
- package/src/compiler/node-builder-reuse.ts +5 -4
- package/src/compiler/node-builder.ts +130 -31
- package/src/compiler/option-declarations.ts +33 -103
- package/src/compiler/options.ts +23 -62
- package/src/compiler/output-paths.ts +5 -18
- package/src/compiler/package-entrypoints.ts +345 -0
- package/src/compiler/package-json.ts +4 -4
- package/src/compiler/parallel-check.ts +197 -8
- package/src/compiler/parallel-emit.ts +1 -1
- package/src/compiler/parser.ts +156 -39
- package/src/compiler/path.ts +22 -2
- package/src/compiler/printer/emit-context.ts +16 -0
- package/src/compiler/printer/factory-base.ts +10 -3
- package/src/compiler/printer/factory.ts +4 -1
- package/src/compiler/printer/helpers.ts +10 -1
- package/src/compiler/printer/name-generator.ts +24 -2
- package/src/compiler/printer/printer.ts +35 -14
- package/src/compiler/printer/utilities.ts +8 -2
- package/src/compiler/program-checker.ts +53 -5
- package/src/compiler/program-utilities.ts +23 -10
- package/src/compiler/program.ts +13 -1
- package/src/compiler/pseudo-bigint.ts +17 -0
- package/src/compiler/regexp-checker.ts +63 -30
- package/src/compiler/relations.ts +233 -77
- package/src/compiler/reparser.ts +7 -2
- package/src/compiler/scanner.ts +109 -79
- package/src/compiler/shared-results.ts +2414 -0
- package/src/compiler/show-config.ts +18 -1
- package/src/compiler/sourcemap.ts +2 -2
- package/src/compiler/symbol-accessibility.ts +26 -3
- package/src/compiler/symbol.ts +31 -14
- package/src/compiler/syntax-kind.ts +188 -187
- package/src/compiler/thread-entry.ts +19 -2
- package/src/compiler/transformers/alias-references.ts +123 -4
- package/src/compiler/transformers/async.ts +2 -17
- package/src/compiler/transformers/class-fields.ts +13 -12
- package/src/compiler/transformers/commonjs-module.ts +11 -7
- package/src/compiler/transformers/declarations-diagnostics.ts +5 -3
- package/src/compiler/transformers/declarations-pseudo.ts +2 -4
- package/src/compiler/transformers/declarations-resolver.ts +0 -3
- package/src/compiler/transformers/declarations-syntactic.ts +1 -21
- package/src/compiler/transformers/declarations.ts +134 -48
- package/src/compiler/transformers/decorator-metadata.ts +9 -1
- package/src/compiler/transformers/destructuring.ts +4 -3
- package/src/compiler/transformers/external-module-info.ts +1 -1
- package/src/compiler/transformers/jsx.ts +2 -1
- package/src/compiler/transformers/reference-resolver.ts +83 -19
- package/src/compiler/transformers/runtime-syntax.ts +6 -1
- package/src/compiler/transformers/syntax-facts.ts +2 -7
- package/src/compiler/transformers/type-eraser.ts +10 -1
- package/src/compiler/transformers/type-serialization.ts +3 -2
- package/src/compiler/transformers/visitor-base.ts +2 -1
- package/src/compiler/transformers/visitor-hooks.ts +9 -4
- package/src/compiler/tsc-build.ts +3 -0
- package/src/compiler/tsc-cli.ts +2 -0
- package/src/compiler/tsc-compile.ts +7 -2
- package/src/compiler/tsc-watch.ts +74 -45
- package/src/compiler/tsconfig.ts +176 -19
- package/src/compiler/type-printer.ts +36 -2
- package/src/compiler/types.ts +2 -1
- package/src/library/ast.generated.ts +57 -41
- package/src/library/compiler-options.generated.ts +117 -103
- package/src/library/disk.ts +10 -1
- package/src/library/enums.generated.ts +196 -196
|
@@ -1,32 +1,31 @@
|
|
|
1
1
|
// Type inference: inference contexts, inferring from source to target types, and the inferred
|
|
2
2
|
// types of type parameters.
|
|
3
3
|
import { sideOf, signatureSideOf } from './side-state.js';
|
|
4
|
+
import { isInJSFile } from './ast-utilities.js';
|
|
4
5
|
import { hasSyntacticModifier } from './binder-utilities.js';
|
|
5
|
-
import { ArrayToSingleTypeMapper, MergedTypeMapper, TupleElementInfo, TypeMapper, newTypeMapper, SimpleTypeMapper, emptyTypes, } from './checker-types.js';
|
|
6
|
-
import { createAnonymousType, createArrayType, createArrayTypeEx, createTupleType, createTupleTypeEx, filterType, getBaseTypeOfLiteralType, getBigIntLiteralType, getElementTypes, getEndElementCount, getIntersectionType, getNumberLiteralType, getRegularTypeOfLiteralType, getStringLiteralType, getTemplateLiteralType, getTypeArguments, getTypeReferenceArity, getUnionType, getUnionTypeEx, getWidenedLiteralType, isArrayOrTupleType, isErrorType, isArrayType, isGenericTupleType, isLiteralType, isMutableArrayOrTuple, isReadonlyArrayType, isTupleType, mapType, newIndexInfo, newObjectType, setStructuredTypeMembers, someType, tupleTargetOf, typesOf, } from './checker-type-factory.js';
|
|
6
|
+
import { ArrayToSingleTypeMapper, MergedTypeMapper, TupleElementInfo, TypeMapper, newTypeMapper, SimpleTypeMapper, emptyTypes, getNonDistributedTypeParameter, } from './checker-types.js';
|
|
7
|
+
import { createAnonymousType, createArrayType, createArrayTypeEx, createTupleType, createTupleTypeEx, filterType, getBaseTypeOfLiteralType, getBigIntLiteralType, getElementTypes, getEndElementCount, getIntersectionType, getNumberLiteralType, getRegularTypeOfLiteralType, getStringLiteralType, getTemplateLiteralType, getTypeArguments, getTypeReferenceArity, getUnionType, getUnionTypeEx, getWidenedLiteralType, isArrayOrTupleType, isErrorType, isArrayType, isGenericTupleType, isLiteralType, isMutableArrayOrTuple, isReadonlyArrayType, isTupleType, mapType, newIndexInfo, newObjectType, setStructuredTypeMembers, someType, tupleTargetOf, typesOf, compareTypes, } from './checker-type-factory.js';
|
|
7
8
|
import { getDeclaredTypeOfClassOrInterface, getDeclaredTypeOfSymbol, fillMissingTypeArguments, getConstraintOfTypeParameter, getDefaultFromTypeParameter, getMinTypeArgumentCount, getDeclaredTypeOfTypeParameter, } from './checker-declared-types.js';
|
|
8
9
|
import { applyStringMapping, getActualTypeVariable, getBranchTypesFromConditionalType, getConstraintFromConditionalType, getConstraintOfConditionalType, getConstraintTypeFromMappedType, getElementTypeOfSliceOfTupleType, getFalseTypeFromConditionalType, getHomomorphicTypeVariable, getIndexType, getIndexTypeEx, getIndexedAccessType, getLiteralTypeFromProperty, getMappedTypeModifiers, getNameTypeFromMappedType, getSimplifiedType, getSubstitutionIntersection, getTemplateTypeFromMappedType, getTrueTypeFromConditionalType, getTypeParameterFromMappedType, isGenericMappedType, isNoInferType, isTypeMatchedByTemplateLiteralType, shouldDeferIndexType, } from './checker-type-operators.js';
|
|
9
10
|
import { getApparentType, getApplicableIndexInfo, getBaseConstraintOfType, getBaseConstraintOrType, getConstraintOfType, getIndexInfoOfType, getIndexInfosOfType, getPropertiesOfObjectType, getPropertiesOfType, getPropertyOfType, getPropertyOfUnionOrIntersectionType, getReducedApparentType, getReducedType, getSignaturesOfType, getTypeWithThisArgument, isApplicableIndexType, isObjectLiteralType, } from './checker-members.js';
|
|
10
11
|
import { getEffectiveRestType, getErasedSignature, getParameterCount, getRestTypeAtPosition, getReturnTypeOfSignature, getSignatureInstantiation, getThisTypeOfSignature, getTypeAtPosition, getTypePredicateOfSignature, sliceTupleType, } from './checker-signatures.js';
|
|
11
12
|
import { getNullableType, getTypeOfSymbol, getWidenedType, isReadonlySymbol, removeMissingOrUndefinedType, removeMissingType, } from './checker-symbol-types.js';
|
|
12
13
|
import { combineTypeMappers, couldContainTypeVariables, instantiateSignature, instantiateSignatureEx, instantiateType, instantiateTypes, } from './instantiation.js';
|
|
13
|
-
import { getAliasVariances, getComparer, getUnmatchedProperty, getVariances, isUnmatchedProperty, isDeeplyNestedType, setStackEntry, isObjectTypeWithInferableIndex, isTypeAssignableTo, isTypeIdenticalTo, isTypeStrictSubtypeOf, isTypeSubtypeOf, } from './relations.js';
|
|
14
|
+
import { getAliasVariances, getComparer, getUnmatchedProperty, getVariances, isUnmatchedProperty, isDeeplyNestedStackEntry, isDeeplyNestedType, setStackEntry, isObjectTypeWithInferableIndex, isTypeAssignableTo, isTypeIdenticalTo, isTypeStrictSubtypeOf, isTypeSubtypeOf, } from './relations.js';
|
|
14
15
|
import { maybeTypeOfKind } from './checker-utilities.js';
|
|
15
16
|
import { getTypeFromTypeNode } from './checker-type-nodes.js';
|
|
16
|
-
import { getMergedSymbol, getSymbolOfDeclaration } from './checker-symbols.js';
|
|
17
|
+
import { findResolutionCycleStartIndex, getMergedSymbol, getSymbolOfDeclaration, } from './checker-symbols.js';
|
|
17
18
|
import { parsePseudoBigInt } from './pseudo-bigint.js';
|
|
18
19
|
import { getContextualTypeForInference } from './checker-contextual.js';
|
|
19
20
|
import { copyDeclarations, declarationCount, getDeclarations, getSymbolId, } from './symbol.js';
|
|
20
21
|
// Shared empty candidate lists: an InferenceInfo gets its own on its first candidate, as tsgo's nil
|
|
21
22
|
// slices do. Never changed.
|
|
22
23
|
const noCandidates = [];
|
|
23
|
-
const noCandidateDepths = [];
|
|
24
24
|
/** Inferences for one type parameter. */
|
|
25
25
|
export class InferenceInfo {
|
|
26
26
|
typeParameter;
|
|
27
|
-
/** Covariant candidates
|
|
27
|
+
/** Covariant candidates. */
|
|
28
28
|
candidates = noCandidates;
|
|
29
|
-
candidateDepths = noCandidateDepths;
|
|
30
29
|
contraCandidates = noCandidates;
|
|
31
30
|
inferredType = undefined;
|
|
32
31
|
priority = 2048 /* InferencePriority.MaxValue */;
|
|
@@ -39,10 +38,8 @@ export class InferenceInfo {
|
|
|
39
38
|
}
|
|
40
39
|
clone() {
|
|
41
40
|
const info = new InferenceInfo(this.typeParameter);
|
|
42
|
-
if (this.candidates.length !== 0)
|
|
41
|
+
if (this.candidates.length !== 0)
|
|
43
42
|
info.candidates = this.candidates.slice();
|
|
44
|
-
info.candidateDepths = this.candidateDepths.slice();
|
|
45
|
-
}
|
|
46
43
|
if (this.contraCandidates.length !== 0)
|
|
47
44
|
info.contraCandidates = this.contraCandidates.slice();
|
|
48
45
|
info.inferredType = this.inferredType;
|
|
@@ -201,7 +198,7 @@ function hasTypeParameterDefault(tp) {
|
|
|
201
198
|
if (symbol === undefined)
|
|
202
199
|
return false;
|
|
203
200
|
for (const d of getDeclarations(symbol))
|
|
204
|
-
if (d.kind ===
|
|
201
|
+
if (d.kind === 170 /* SyntaxKind.TypeParameter */ && d.defaultType !== undefined)
|
|
205
202
|
return true;
|
|
206
203
|
return false;
|
|
207
204
|
}
|
|
@@ -222,6 +219,224 @@ export function inferTypes(c, inferences, source, target, priority, contravarian
|
|
|
222
219
|
const state = new InferenceState(c, inferences, target, priority, contravariant);
|
|
223
220
|
state.inferFromTypes(source, target);
|
|
224
221
|
}
|
|
222
|
+
/** Whether no inference has a candidate or an inferred type, or is fixed, as in a new context. */
|
|
223
|
+
function isUnstarted(inferences) {
|
|
224
|
+
for (const i of inferences)
|
|
225
|
+
if (i.candidates.length !== 0 || i.contraCandidates.length !== 0 || i.inferredType !== undefined || i.isFixed)
|
|
226
|
+
return false;
|
|
227
|
+
return true;
|
|
228
|
+
}
|
|
229
|
+
/** A memoized `inferTypesFromUnstarted` walk. */
|
|
230
|
+
export class UnstartedInference {
|
|
231
|
+
state;
|
|
232
|
+
inferences;
|
|
233
|
+
/** The instantiations the walk does, which a skipped walk adds to the counts. */
|
|
234
|
+
instantiations;
|
|
235
|
+
/** The instantiation depth the confirming walk started at: a walk starting deeper might reach the limit. */
|
|
236
|
+
depth;
|
|
237
|
+
/** The variance reliability flags the walk reports. */
|
|
238
|
+
reliabilityFlags;
|
|
239
|
+
/** The unions and intersections the walk searched before their properties were resolved. */
|
|
240
|
+
searched;
|
|
241
|
+
constructor(state, inferences, instantiations, depth, reliabilityFlags, searched) {
|
|
242
|
+
this.state = state;
|
|
243
|
+
this.inferences = inferences;
|
|
244
|
+
this.instantiations = instantiations;
|
|
245
|
+
this.depth = depth;
|
|
246
|
+
this.reliabilityFlags = reliabilityFlags;
|
|
247
|
+
this.searched = searched;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
const verifyUnstartedInferences = process.env['TSC_TS_VERIFY_INFERENCE_MEMO'] === '1';
|
|
251
|
+
/**
|
|
252
|
+
* `inferTypes` into the inferences for `signature`'s type parameters, to `target`, which is
|
|
253
|
+
* determined by `signature` (its return type). When no inference has started, the walk depends only
|
|
254
|
+
* on `signature`, `source` and `priority`, so it is memoized per checker. Contextual return type
|
|
255
|
+
* inference repeats the same walk for calls of a generic function with the same contextual type at
|
|
256
|
+
* different call sites.
|
|
257
|
+
*
|
|
258
|
+
* A walk is skipped only when it would add nothing but the inferences:
|
|
259
|
+
* - Once a second and a third walk have both created no types or signatures and done the same. The
|
|
260
|
+
* first walk resolves the types it reaches; only walks that repeat keep their inferences.
|
|
261
|
+
* - With the instantiation count and depth replayed. The walk is skipped only where it could not
|
|
262
|
+
* reach the instantiation limits.
|
|
263
|
+
* - With the variance reliability flags replayed.
|
|
264
|
+
* - Never when a walk reported a diagnostic or met a circularity. Never during a variance
|
|
265
|
+
* computation, where relations are not cached and circularities are found differently.
|
|
266
|
+
* - Only while the unions and intersections whose unresolved properties the walk searched
|
|
267
|
+
* (hasUnmatchedProperty) are still unresolved. Once they are resolved, the same walk creates the
|
|
268
|
+
* property types, so it is learned again.
|
|
269
|
+
*/
|
|
270
|
+
export function inferTypesFromUnstarted(c, signature, inferences, source, target, priority) {
|
|
271
|
+
if (c.varianceStack.length !== 0 || !isUnstarted(inferences)) {
|
|
272
|
+
inferTypes(c, inferences, source, target, priority, false);
|
|
273
|
+
return;
|
|
274
|
+
}
|
|
275
|
+
const caches = c.inferenceCaches;
|
|
276
|
+
const memo = caches.unstartedInferences;
|
|
277
|
+
let bySource = memo.get(signature.id);
|
|
278
|
+
if (bySource === undefined) {
|
|
279
|
+
bySource = new Map();
|
|
280
|
+
memo.set(signature.id, bySource);
|
|
281
|
+
}
|
|
282
|
+
const key = source.id * 4096 + priority;
|
|
283
|
+
let known = bySource.get(key);
|
|
284
|
+
if (known !== undefined && known.state === 2 /* UnstartedInferenceState.Confirmed */) {
|
|
285
|
+
if (havePropertiesResolved(c, known.searched)) {
|
|
286
|
+
// Learn the walk again for the resolved properties; each union's properties are resolved once.
|
|
287
|
+
bySource.delete(key);
|
|
288
|
+
known = undefined;
|
|
289
|
+
}
|
|
290
|
+
else if (c.instantiationDepth <= known.depth && c.instantiationCount + known.instantiations < 5000000) {
|
|
291
|
+
if (verifyUnstartedInferences)
|
|
292
|
+
verifyUnstartedInference(c, signature, known, source, target, priority);
|
|
293
|
+
copyInferences(inferences, known.inferences);
|
|
294
|
+
const outer = c.unresolvedPropertySearches;
|
|
295
|
+
if (outer !== undefined)
|
|
296
|
+
for (const t of known.searched)
|
|
297
|
+
outer.push(t);
|
|
298
|
+
c.instantiationCount += known.instantiations;
|
|
299
|
+
c.totalInstantiations += known.instantiations;
|
|
300
|
+
c.reliabilityFlags |= known.reliabilityFlags;
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
const reports = c.reports;
|
|
305
|
+
const cycles = c.resolutionCycleCount;
|
|
306
|
+
const outerSearches = c.unresolvedPropertySearches;
|
|
307
|
+
const searches = [];
|
|
308
|
+
c.unresolvedPropertySearches = searches;
|
|
309
|
+
const types = c.typeCount;
|
|
310
|
+
const signatures = c.signatureCount;
|
|
311
|
+
const count = c.instantiationCount;
|
|
312
|
+
const total = c.totalInstantiations;
|
|
313
|
+
const depth = c.instantiationDepth;
|
|
314
|
+
const reliabilityFlags = c.reliabilityFlags;
|
|
315
|
+
// Nothing reads the flags before setting them, so the walk's own are those it leaves from zero.
|
|
316
|
+
c.reliabilityFlags = 0;
|
|
317
|
+
inferTypes(c, inferences, source, target, priority, false);
|
|
318
|
+
const walkFlags = c.reliabilityFlags;
|
|
319
|
+
c.reliabilityFlags = reliabilityFlags | walkFlags;
|
|
320
|
+
c.unresolvedPropertySearches = outerSearches;
|
|
321
|
+
// An enclosing walk depends on the searches of the walks within it.
|
|
322
|
+
if (outerSearches !== undefined)
|
|
323
|
+
for (const t of searches)
|
|
324
|
+
outerSearches.push(t);
|
|
325
|
+
const state = known === undefined ? undefined : known.state;
|
|
326
|
+
if (state === 2 /* UnstartedInferenceState.Confirmed */ || state === 3 /* UnstartedInferenceState.Unusable */)
|
|
327
|
+
return;
|
|
328
|
+
const instantiations = c.totalInstantiations - total;
|
|
329
|
+
if (c.reports !== reports || c.resolutionCycleCount !== cycles || c.instantiationCount - count !== instantiations) {
|
|
330
|
+
bySource.set(key, caches.alwaysWalked);
|
|
331
|
+
return;
|
|
332
|
+
}
|
|
333
|
+
if (state === undefined) {
|
|
334
|
+
bySource.set(key, caches.seenOnce);
|
|
335
|
+
return;
|
|
336
|
+
}
|
|
337
|
+
if (c.typeCount !== types || c.signatureCount !== signatures) {
|
|
338
|
+
bySource.set(key, caches.alwaysWalked);
|
|
339
|
+
return;
|
|
340
|
+
}
|
|
341
|
+
const searched = searches.length === 0 ? searches : [...new Set(searches)];
|
|
342
|
+
if (state === 0 /* UnstartedInferenceState.Seen */) {
|
|
343
|
+
const snapshot = [];
|
|
344
|
+
for (const i of inferences)
|
|
345
|
+
snapshot.push(i.clone());
|
|
346
|
+
bySource.set(key, new UnstartedInference(1 /* UnstartedInferenceState.Walked */, snapshot, instantiations, depth, walkFlags, searched));
|
|
347
|
+
return;
|
|
348
|
+
}
|
|
349
|
+
bySource.set(key, sameInferences(inferences, known.inferences) &&
|
|
350
|
+
instantiations === known.instantiations &&
|
|
351
|
+
walkFlags === known.reliabilityFlags
|
|
352
|
+
? new UnstartedInference(2 /* UnstartedInferenceState.Confirmed */, known.inferences, instantiations, depth, walkFlags, searched)
|
|
353
|
+
: caches.alwaysWalked);
|
|
354
|
+
}
|
|
355
|
+
/** Whether the properties of any of `types` have been resolved. */
|
|
356
|
+
function havePropertiesResolved(c, types) {
|
|
357
|
+
for (const t of types)
|
|
358
|
+
if (sideOf(c, t).membersOf?.resolvedProperties !== undefined)
|
|
359
|
+
return true;
|
|
360
|
+
return false;
|
|
361
|
+
}
|
|
362
|
+
function copyInferences(inferences, from) {
|
|
363
|
+
for (let k = 0; k < inferences.length; k++) {
|
|
364
|
+
const info = inferences[k];
|
|
365
|
+
const known = from[k];
|
|
366
|
+
if (known.candidates.length !== 0)
|
|
367
|
+
info.candidates = known.candidates.slice();
|
|
368
|
+
if (known.contraCandidates.length !== 0)
|
|
369
|
+
info.contraCandidates = known.contraCandidates.slice();
|
|
370
|
+
info.inferredType = known.inferredType;
|
|
371
|
+
info.priority = known.priority;
|
|
372
|
+
info.topLevel = known.topLevel;
|
|
373
|
+
info.isFixed = known.isFixed;
|
|
374
|
+
info.impliedArity = known.impliedArity;
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
function sameTypes(a, b) {
|
|
378
|
+
if (a.length !== b.length)
|
|
379
|
+
return false;
|
|
380
|
+
for (let k = 0; k < a.length; k++)
|
|
381
|
+
if (a[k] !== b[k])
|
|
382
|
+
return false;
|
|
383
|
+
return true;
|
|
384
|
+
}
|
|
385
|
+
function sameInferences(a, b) {
|
|
386
|
+
for (let k = 0; k < a.length; k++) {
|
|
387
|
+
const x = a[k];
|
|
388
|
+
const y = b[k];
|
|
389
|
+
if (!sameTypes(x.candidates, y.candidates) ||
|
|
390
|
+
!sameTypes(x.contraCandidates, y.contraCandidates) ||
|
|
391
|
+
x.inferredType !== y.inferredType ||
|
|
392
|
+
x.priority !== y.priority ||
|
|
393
|
+
x.topLevel !== y.topLevel ||
|
|
394
|
+
x.isFixed !== y.isFixed ||
|
|
395
|
+
x.impliedArity !== y.impliedArity)
|
|
396
|
+
return false;
|
|
397
|
+
}
|
|
398
|
+
return true;
|
|
399
|
+
}
|
|
400
|
+
/** With TSC_TS_VERIFY_INFERENCE_MEMO=1: walks anyway and reports how the skipped walk would have differed. */
|
|
401
|
+
function verifyUnstartedInference(c, signature, known, source, target, priority) {
|
|
402
|
+
const inferences = [];
|
|
403
|
+
for (const i of known.inferences)
|
|
404
|
+
inferences.push(new InferenceInfo(i.typeParameter));
|
|
405
|
+
const types = c.typeCount;
|
|
406
|
+
const signatures = c.signatureCount;
|
|
407
|
+
const total = c.totalInstantiations;
|
|
408
|
+
const reports = c.reports;
|
|
409
|
+
const cycles = c.resolutionCycleCount;
|
|
410
|
+
const reliabilityFlags = c.reliabilityFlags;
|
|
411
|
+
const outerSearches = c.unresolvedPropertySearches;
|
|
412
|
+
c.reliabilityFlags = 0;
|
|
413
|
+
c.unresolvedPropertySearches = undefined;
|
|
414
|
+
inferTypes(c, inferences, source, target, priority, false);
|
|
415
|
+
const walkFlags = c.reliabilityFlags;
|
|
416
|
+
c.reliabilityFlags = reliabilityFlags;
|
|
417
|
+
c.unresolvedPropertySearches = outerSearches;
|
|
418
|
+
const instantiations = c.totalInstantiations - total;
|
|
419
|
+
// Undo the check walk's count so the run continues as without verification.
|
|
420
|
+
c.instantiationCount -= instantiations;
|
|
421
|
+
c.totalInstantiations -= instantiations;
|
|
422
|
+
const differences = [];
|
|
423
|
+
if (!sameInferences(inferences, known.inferences))
|
|
424
|
+
differences.push('inferences');
|
|
425
|
+
if (c.typeCount !== types)
|
|
426
|
+
differences.push(`${c.typeCount - types} types`);
|
|
427
|
+
if (c.signatureCount !== signatures)
|
|
428
|
+
differences.push(`${c.signatureCount - signatures} signatures`);
|
|
429
|
+
if (instantiations !== known.instantiations)
|
|
430
|
+
differences.push(`${instantiations} instantiations, not ${known.instantiations}`);
|
|
431
|
+
if (c.reports !== reports)
|
|
432
|
+
differences.push(`${c.reports - reports} diagnostics`);
|
|
433
|
+
if (c.resolutionCycleCount !== cycles)
|
|
434
|
+
differences.push('a circularity');
|
|
435
|
+
if (walkFlags !== known.reliabilityFlags)
|
|
436
|
+
differences.push('reliability flags');
|
|
437
|
+
if (differences.length !== 0)
|
|
438
|
+
process.stderr.write(`inference memo: signature ${signature.id} source ${source.id} priority ${priority}: ${differences.join(', ')}\n`);
|
|
439
|
+
}
|
|
225
440
|
class MatchedTypes {
|
|
226
441
|
sources;
|
|
227
442
|
targets;
|
|
@@ -251,20 +466,34 @@ class InferenceState {
|
|
|
251
466
|
bivariant = false;
|
|
252
467
|
expandingFlags = 0 /* ExpandingFlags.None */;
|
|
253
468
|
propagationType = undefined;
|
|
254
|
-
/**
|
|
469
|
+
/**
|
|
470
|
+
* The statuses of the pairs invokeOnce finished, for each priority and variance of the walk (`visitMode`), by
|
|
471
|
+
* packed type ids (`visitKey`), or spelled when an id is too large to pack. The first pair with packed ids is in
|
|
472
|
+
* `firstVisitKey` instead: most walks finish at most one.
|
|
473
|
+
*/
|
|
255
474
|
visited = undefined;
|
|
256
475
|
visitedSpelled = undefined;
|
|
257
|
-
/**
|
|
258
|
-
|
|
259
|
-
|
|
476
|
+
/** The mode `visitedPairs` belongs to, or -1 before the first `visitedPairsOf`. */
|
|
477
|
+
visitedMode = -1;
|
|
478
|
+
/** `visited`'s map for `visitedMode`; a walk mostly stays in one mode. */
|
|
479
|
+
visitedPairs = undefined;
|
|
480
|
+
/** The first finished pair with packed ids (-1 before it), its mode and its status. */
|
|
481
|
+
firstVisitKey = -1;
|
|
482
|
+
firstVisitMode = 0;
|
|
483
|
+
firstVisitStatus = 2048 /* InferencePriority.MaxValue */;
|
|
484
|
+
/**
|
|
485
|
+
* Where this walk's entries start on the checker's invokeOnce stacks (`InferenceCaches.invokeSourceStack`). The
|
|
486
|
+
* `stackDepth` entries from there are live: the pairs being visited.
|
|
487
|
+
*/
|
|
488
|
+
stackBase;
|
|
260
489
|
stackDepth = 0;
|
|
261
|
-
depth = 0;
|
|
262
490
|
constructor(c, inferences, originalTarget, priority, contravariant) {
|
|
263
491
|
this.c = c;
|
|
264
492
|
this.inferences = inferences;
|
|
265
493
|
this.originalTarget = originalTarget;
|
|
266
494
|
this.priority = priority;
|
|
267
495
|
this.contravariant = contravariant;
|
|
496
|
+
this.stackBase = c.inferenceCaches.invokeStackDepth;
|
|
268
497
|
}
|
|
269
498
|
infoFor(t) {
|
|
270
499
|
return getInferenceInfoForType(this.inferences, t);
|
|
@@ -284,14 +513,9 @@ class InferenceState {
|
|
|
284
513
|
const sourceAlias = source.alias;
|
|
285
514
|
const targetAlias = target.alias;
|
|
286
515
|
if (sourceAlias !== undefined && targetAlias !== undefined && sourceAlias.symbol === targetAlias.symbol) {
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
const minParams = getMinTypeArgumentCount(c, params);
|
|
291
|
-
const sourceTypes = fillMissingTypeArguments(c, sourceAlias.typeArguments, params, minParams, false);
|
|
292
|
-
const targetTypes = fillMissingTypeArguments(c, targetAlias.typeArguments, params, minParams, false);
|
|
293
|
-
this.inferFromTypeArguments(sourceTypes, targetTypes, someTypeCouldHoldInference(c, targetTypes) ? getAliasVariances(c, sourceAlias.symbol) : noVariances);
|
|
294
|
-
}
|
|
516
|
+
// Instantiations of the same alias infer between their type arguments, once for each pair of types, as tsc does.
|
|
517
|
+
if (sourceAlias.typeArguments.length !== 0 || targetAlias.typeArguments.length !== 0)
|
|
518
|
+
this.invokeOnce(source, target, 0 /* InferenceAction.AliasTypeArguments */);
|
|
295
519
|
return;
|
|
296
520
|
}
|
|
297
521
|
if (source === target && (source.flags & 402653184 /* TypeFlags.UnionOrIntersection */) !== 0) {
|
|
@@ -302,7 +526,7 @@ class InferenceState {
|
|
|
302
526
|
if ((target.flags & 134217728 /* TypeFlags.Union */) !== 0) {
|
|
303
527
|
const sourceTypes = (source.flags & 134217728 /* TypeFlags.Union */) !== 0 ? typesOf(source) : [source];
|
|
304
528
|
// Infer between identically matching constituents, then closely matching ones, removing them.
|
|
305
|
-
const temp = this.inferFromMatchingTypes(sourceTypes,
|
|
529
|
+
const temp = this.inferFromMatchingTypes(sourceTypes, typesOf(target), 0 /* MatchKind.TypeOrBaseIdentical */);
|
|
306
530
|
const matched = this.inferFromMatchingTypes(temp.sources, temp.targets, 1 /* MatchKind.CloselyMatched */);
|
|
307
531
|
if (matched.targets.length === 0)
|
|
308
532
|
return;
|
|
@@ -355,7 +579,7 @@ class InferenceState {
|
|
|
355
579
|
(target.objectFlags & 4 /* ObjectFlags.Reference */) !== 0 &&
|
|
356
580
|
(referenceTarget(source) === referenceTarget(target) || (isArrayType(c, source) && isArrayType(c, target))) &&
|
|
357
581
|
!(referenceNode(source) !== undefined && referenceNode(target) !== undefined)) {
|
|
358
|
-
this.
|
|
582
|
+
this.invokeOnce(source, target, 4 /* InferenceAction.ReferenceTypeArguments */);
|
|
359
583
|
}
|
|
360
584
|
else if ((source.flags & 2097152 /* TypeFlags.Index */) !== 0 && (target.flags & 2097152 /* TypeFlags.Index */) !== 0) {
|
|
361
585
|
this.inferFromContravariantTypes(source.target, target.target);
|
|
@@ -379,7 +603,7 @@ class InferenceState {
|
|
|
379
603
|
this.inferWithPriority(getSubstitutionIntersection(c, source), target, 4 /* InferencePriority.SubstituteSource */);
|
|
380
604
|
}
|
|
381
605
|
else if ((target.flags & 67108864 /* TypeFlags.Conditional */) !== 0) {
|
|
382
|
-
this.invokeOnce(source, target,
|
|
606
|
+
this.invokeOnce(source, target, 1 /* InferenceAction.ConditionalType */);
|
|
383
607
|
}
|
|
384
608
|
else if ((target.flags & 402653184 /* TypeFlags.UnionOrIntersection */) !== 0) {
|
|
385
609
|
this.inferToMultipleTypes(source, typesOf(target), target.flags);
|
|
@@ -394,7 +618,7 @@ class InferenceState {
|
|
|
394
618
|
else {
|
|
395
619
|
source = getReducedType(c, source);
|
|
396
620
|
if (isGenericMappedType(c, source) && isGenericMappedType(c, target))
|
|
397
|
-
this.invokeOnce(source, target,
|
|
621
|
+
this.invokeOnce(source, target, 2 /* InferenceAction.GenericMappedTypes */);
|
|
398
622
|
if (!((this.priority & 512 /* InferencePriority.NoConstraints */) !== 0 &&
|
|
399
623
|
(source.flags & (268435456 /* TypeFlags.Intersection */ | 132644864 /* TypeFlags.Instantiable */)) !== 0)) {
|
|
400
624
|
const apparentSource = getApparentType(c, source);
|
|
@@ -406,7 +630,7 @@ class InferenceState {
|
|
|
406
630
|
source = apparentSource;
|
|
407
631
|
}
|
|
408
632
|
if ((source.flags & (1048576 /* TypeFlags.Object */ | 268435456 /* TypeFlags.Intersection */)) !== 0)
|
|
409
|
-
this.invokeOnce(source, target,
|
|
633
|
+
this.invokeOnce(source, target, 3 /* InferenceAction.ObjectTypes */);
|
|
410
634
|
}
|
|
411
635
|
}
|
|
412
636
|
inferToTypeVariable(inference, source, target) {
|
|
@@ -420,7 +644,6 @@ class InferenceState {
|
|
|
420
644
|
return;
|
|
421
645
|
if (this.priority < inference.priority) {
|
|
422
646
|
inference.candidates = noCandidates;
|
|
423
|
-
inference.candidateDepths = noCandidateDepths;
|
|
424
647
|
inference.contraCandidates = noCandidates;
|
|
425
648
|
inference.topLevel = true;
|
|
426
649
|
inference.priority = this.priority;
|
|
@@ -435,31 +658,11 @@ class InferenceState {
|
|
|
435
658
|
clearCachedInferences(this.inferences);
|
|
436
659
|
}
|
|
437
660
|
}
|
|
438
|
-
else {
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
inference.candidateDepths.splice(index, 1);
|
|
444
|
-
}
|
|
445
|
-
if (inference.candidates === noCandidates) {
|
|
446
|
-
inference.candidates = [];
|
|
447
|
-
inference.candidateDepths = [];
|
|
448
|
-
}
|
|
449
|
-
// Keep candidates with the highest depth first.
|
|
450
|
-
index = 0;
|
|
451
|
-
while (index < inference.candidateDepths.length && inference.candidateDepths[index] >= this.depth)
|
|
452
|
-
index++;
|
|
453
|
-
if (index === inference.candidates.length) {
|
|
454
|
-
inference.candidates.push(candidate);
|
|
455
|
-
inference.candidateDepths.push(this.depth);
|
|
456
|
-
}
|
|
457
|
-
else {
|
|
458
|
-
inference.candidates.splice(index, 0, candidate);
|
|
459
|
-
inference.candidateDepths.splice(index, 0, this.depth);
|
|
460
|
-
}
|
|
461
|
-
clearCachedInferences(this.inferences);
|
|
462
|
-
}
|
|
661
|
+
else if (!inference.candidates.includes(candidate)) {
|
|
662
|
+
if (inference.candidates === noCandidates)
|
|
663
|
+
inference.candidates = [];
|
|
664
|
+
inference.candidates.push(candidate);
|
|
665
|
+
clearCachedInferences(this.inferences);
|
|
463
666
|
}
|
|
464
667
|
}
|
|
465
668
|
if ((this.priority & 128 /* InferencePriority.ReturnType */) === 0 &&
|
|
@@ -484,7 +687,6 @@ class InferenceState {
|
|
|
484
687
|
this.inferFromTypeArguments(sourceTypes, targetTypes, someTypeCouldHoldInference(c, targetTypes) ? getVariances(c, referenceTarget(source)) : noVariances);
|
|
485
688
|
}
|
|
486
689
|
inferFromTypeArguments(sourceTypes, targetTypes, variances) {
|
|
487
|
-
this.depth++;
|
|
488
690
|
const count = Math.min(sourceTypes.length, targetTypes.length);
|
|
489
691
|
for (let i = 0; i < count; i++) {
|
|
490
692
|
if (i < variances.length && (variances[i] & 7 /* VarianceFlags.VarianceMask */) === 2 /* VarianceFlags.Contravariant */)
|
|
@@ -492,7 +694,6 @@ class InferenceState {
|
|
|
492
694
|
else
|
|
493
695
|
this.inferFromTypes(sourceTypes[i], targetTypes[i]);
|
|
494
696
|
}
|
|
495
|
-
this.depth--;
|
|
496
697
|
}
|
|
497
698
|
inferWithPriority(source, target, newPriority) {
|
|
498
699
|
const savePriority = this.priority;
|
|
@@ -519,62 +720,138 @@ class InferenceState {
|
|
|
519
720
|
}
|
|
520
721
|
/** Runs `action` once per source and target pair, stopping at circularities. */
|
|
521
722
|
invokeOnce(source, target, action) {
|
|
723
|
+
// As in tsc, a pair is visited once for each priority and variance it is inferred with.
|
|
724
|
+
const mode = visitMode(this.priority, this.contravariant, this.bivariant);
|
|
522
725
|
const key = visitKey(source, target);
|
|
523
|
-
const status =
|
|
726
|
+
const status = this.getVisited(source, target, key, mode);
|
|
524
727
|
if (status !== undefined) {
|
|
525
728
|
this.inferencePriority = Math.min(this.inferencePriority, status);
|
|
526
729
|
return;
|
|
527
730
|
}
|
|
528
|
-
this.setVisited(source, target, key, -1 /* InferencePriority.Circularity */);
|
|
529
731
|
const saveInferencePriority = this.inferencePriority;
|
|
530
732
|
this.inferencePriority = 2048 /* InferencePriority.MaxValue */;
|
|
531
733
|
// Duplicate recursion identities on both sides mean a circularity.
|
|
532
734
|
const saveExpandingFlags = this.expandingFlags;
|
|
735
|
+
const caches = this.c.inferenceCaches;
|
|
533
736
|
const stackDepth = this.stackDepth;
|
|
534
|
-
|
|
535
|
-
|
|
737
|
+
const start = this.stackBase;
|
|
738
|
+
const end = start + stackDepth + 1;
|
|
739
|
+
setStackEntry(caches.invokeSourceStack, end - 1, source);
|
|
740
|
+
setStackEntry(caches.invokeTargetStack, end - 1, target);
|
|
741
|
+
setNumberEntry(caches.invokeModeStack, end - 1, mode);
|
|
742
|
+
setNumberEntry(caches.invokeSourceIdentities, end - 1, 0);
|
|
743
|
+
setNumberEntry(caches.invokeTargetIdentities, end - 1, 0);
|
|
536
744
|
this.stackDepth = stackDepth + 1;
|
|
537
|
-
|
|
745
|
+
caches.invokeStackDepth = end;
|
|
746
|
+
if (isDeeplyNestedStackEntry(this.c, caches.invokeSourceStack, caches.invokeSourceIdentities, start, end, 2))
|
|
538
747
|
this.expandingFlags |= 1 /* ExpandingFlags.Source */;
|
|
539
|
-
if (
|
|
748
|
+
if (isDeeplyNestedStackEntry(this.c, caches.invokeTargetStack, caches.invokeTargetIdentities, start, end, 2))
|
|
540
749
|
this.expandingFlags |= 2 /* ExpandingFlags.Target */;
|
|
541
750
|
if (this.expandingFlags !== 3 /* ExpandingFlags.Both */) {
|
|
542
751
|
switch (action) {
|
|
543
|
-
case 0 /* InferenceAction.
|
|
752
|
+
case 0 /* InferenceAction.AliasTypeArguments */:
|
|
753
|
+
this.inferFromAliasTypeArguments(source, target);
|
|
754
|
+
break;
|
|
755
|
+
case 1 /* InferenceAction.ConditionalType */:
|
|
544
756
|
this.inferToConditionalType(source, target);
|
|
545
757
|
break;
|
|
546
|
-
case
|
|
758
|
+
case 2 /* InferenceAction.GenericMappedTypes */:
|
|
547
759
|
this.inferFromGenericMappedTypes(source, target);
|
|
548
760
|
break;
|
|
549
|
-
case
|
|
761
|
+
case 3 /* InferenceAction.ObjectTypes */:
|
|
550
762
|
this.inferFromObjectTypes(source, target);
|
|
551
763
|
break;
|
|
764
|
+
case 4 /* InferenceAction.ReferenceTypeArguments */:
|
|
765
|
+
this.inferFromReferenceTypeArguments(source, target);
|
|
766
|
+
break;
|
|
552
767
|
}
|
|
553
768
|
}
|
|
554
769
|
else
|
|
555
770
|
this.inferencePriority = -1 /* InferencePriority.Circularity */;
|
|
556
771
|
this.stackDepth = stackDepth;
|
|
772
|
+
caches.invokeStackDepth = end - 1;
|
|
557
773
|
this.expandingFlags = saveExpandingFlags;
|
|
558
|
-
this.setVisited(source, target, key, this.inferencePriority);
|
|
774
|
+
this.setVisited(source, target, key, mode, this.inferencePriority);
|
|
559
775
|
this.inferencePriority = Math.min(this.inferencePriority, saveInferencePriority);
|
|
560
776
|
}
|
|
561
|
-
|
|
777
|
+
/**
|
|
778
|
+
* The status of the pair in `mode`: its status once it is finished, Circularity while it is being visited, and
|
|
779
|
+
* undefined before its first visit.
|
|
780
|
+
*/
|
|
781
|
+
getVisited(source, target, key, mode) {
|
|
562
782
|
if (key >= 0) {
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
visited.set(key, status);
|
|
783
|
+
if (key === this.firstVisitKey && mode === this.firstVisitMode)
|
|
784
|
+
return this.firstVisitStatus;
|
|
785
|
+
const status = this.visited !== undefined ? this.visitedPairsOf(mode)?.get(key) : undefined;
|
|
786
|
+
if (status !== undefined)
|
|
787
|
+
return status;
|
|
569
788
|
}
|
|
570
789
|
else {
|
|
790
|
+
const status = this.visitedSpelled?.get(source.id + ',' + target.id + ',' + mode);
|
|
791
|
+
if (status !== undefined)
|
|
792
|
+
return status;
|
|
793
|
+
}
|
|
794
|
+
const caches = this.c.inferenceCaches;
|
|
795
|
+
const targetStack = caches.invokeTargetStack;
|
|
796
|
+
const end = this.stackBase + this.stackDepth;
|
|
797
|
+
for (let i = this.stackBase; i < end; i++)
|
|
798
|
+
if (targetStack[i] === target && caches.invokeSourceStack[i] === source && caches.invokeModeStack[i] === mode)
|
|
799
|
+
return -1 /* InferencePriority.Circularity */;
|
|
800
|
+
return undefined;
|
|
801
|
+
}
|
|
802
|
+
/** Records the status of a finished pair. */
|
|
803
|
+
setVisited(source, target, key, mode, status) {
|
|
804
|
+
if (key < 0) {
|
|
571
805
|
let visited = this.visitedSpelled;
|
|
572
806
|
if (visited === undefined) {
|
|
573
807
|
visited = new Map();
|
|
574
808
|
this.visitedSpelled = visited;
|
|
575
809
|
}
|
|
576
|
-
visited.set(source.id + ',' + target.id, status);
|
|
810
|
+
visited.set(source.id + ',' + target.id + ',' + mode, status);
|
|
811
|
+
}
|
|
812
|
+
else if (this.firstVisitKey < 0) {
|
|
813
|
+
this.firstVisitKey = key;
|
|
814
|
+
this.firstVisitMode = mode;
|
|
815
|
+
this.firstVisitStatus = status;
|
|
577
816
|
}
|
|
817
|
+
else {
|
|
818
|
+
let modes = this.visited;
|
|
819
|
+
if (modes === undefined) {
|
|
820
|
+
modes = new Map();
|
|
821
|
+
this.visited = modes;
|
|
822
|
+
}
|
|
823
|
+
let pairs = this.visitedPairsOf(mode);
|
|
824
|
+
if (pairs === undefined) {
|
|
825
|
+
pairs = new Map();
|
|
826
|
+
modes.set(mode, pairs);
|
|
827
|
+
this.visitedMode = mode;
|
|
828
|
+
this.visitedPairs = pairs;
|
|
829
|
+
}
|
|
830
|
+
pairs.set(key, status);
|
|
831
|
+
}
|
|
832
|
+
}
|
|
833
|
+
// Source and target are instantiations of the same type alias: infers between the type arguments, with defaults
|
|
834
|
+
// applied.
|
|
835
|
+
inferFromAliasTypeArguments(source, target) {
|
|
836
|
+
const c = this.c;
|
|
837
|
+
const sourceAlias = source.alias;
|
|
838
|
+
const params = c.symbolLinks(sourceAlias.symbol).typeParameters ?? [];
|
|
839
|
+
const minParams = getMinTypeArgumentCount(c, params);
|
|
840
|
+
const isJavaScript = isInJSFile(sourceAlias.symbol.valueDeclaration);
|
|
841
|
+
const sourceTypes = fillMissingTypeArguments(c, sourceAlias.typeArguments, params, minParams, isJavaScript);
|
|
842
|
+
const targetTypes = fillMissingTypeArguments(c, target.alias.typeArguments, params, minParams, isJavaScript);
|
|
843
|
+
this.inferFromTypeArguments(sourceTypes, targetTypes, someTypeCouldHoldInference(c, targetTypes) ? getAliasVariances(c, sourceAlias.symbol) : noVariances);
|
|
844
|
+
}
|
|
845
|
+
/** `visited`'s map of the pairs finished in `mode`, if there is one. */
|
|
846
|
+
visitedPairsOf(mode) {
|
|
847
|
+
if (mode === this.visitedMode)
|
|
848
|
+
return this.visitedPairs;
|
|
849
|
+
const pairs = this.visited?.get(mode);
|
|
850
|
+
if (pairs !== undefined) {
|
|
851
|
+
this.visitedMode = mode;
|
|
852
|
+
this.visitedPairs = pairs;
|
|
853
|
+
}
|
|
854
|
+
return pairs;
|
|
578
855
|
}
|
|
579
856
|
inferFromMatchingTypes(sources, targets, kind) {
|
|
580
857
|
const c = this.c;
|
|
@@ -583,12 +860,24 @@ class InferenceState {
|
|
|
583
860
|
for (const t of targets)
|
|
584
861
|
for (const s of sources)
|
|
585
862
|
if (typesMatch(c, s, t, kind)) {
|
|
586
|
-
|
|
863
|
+
if (kind !== 1 /* MatchKind.CloselyMatched */)
|
|
864
|
+
this.inferFromTypes(s, t);
|
|
587
865
|
if (!matchedSources.includes(s))
|
|
588
866
|
matchedSources.push(s);
|
|
589
867
|
if (!matchedTargets.includes(t))
|
|
590
868
|
matchedTargets.push(t);
|
|
591
869
|
}
|
|
870
|
+
if (kind === 1 /* MatchKind.CloselyMatched */) {
|
|
871
|
+
// Infer to closely matched targets in decreasing depth of generic instantiations: an inference
|
|
872
|
+
// from a more deeply nested type argument has had more layers of instantiation stripped away. For
|
|
873
|
+
// example, from `string[] | string[][]` to `T[] | T[][]`, relating `string[][]` to `T[][]` infers
|
|
874
|
+
// `string`, a better inference than the `string[]` that relating `string[][]` to `T[]` infers.
|
|
875
|
+
matchedTargets.sort((t1, t2) => compareTypesAndDepth(c, t1, t2));
|
|
876
|
+
for (const t of matchedTargets)
|
|
877
|
+
for (const s of matchedSources)
|
|
878
|
+
if (typesMatch(c, s, t, kind))
|
|
879
|
+
this.inferFromTypes(s, t);
|
|
880
|
+
}
|
|
592
881
|
return new MatchedTypes(matchedSources.length !== 0 ? sources.filter((t) => !matchedSources.includes(t)) : sources, matchedTargets.length !== 0 ? targets.filter((t) => !matchedTargets.includes(t)) : targets);
|
|
593
882
|
}
|
|
594
883
|
inferToMultipleTypes(source, targets, targetFlags) {
|
|
@@ -675,10 +964,11 @@ class InferenceState {
|
|
|
675
964
|
const c = this.c;
|
|
676
965
|
if ((source.flags & 67108864 /* TypeFlags.Conditional */) !== 0) {
|
|
677
966
|
const s = source;
|
|
678
|
-
|
|
679
|
-
this.inferFromTypes(s.
|
|
680
|
-
this.inferFromTypes(
|
|
681
|
-
this.inferFromTypes(
|
|
967
|
+
// A source's distributed type parameters infer as the type parameters they were made from.
|
|
968
|
+
this.inferFromTypes(getNonDistributedTypeParameter(s.checkType), target.checkType);
|
|
969
|
+
this.inferFromTypes(getNonDistributedTypeParameter(s.extendsType), target.extendsType);
|
|
970
|
+
this.inferFromTypes(getNonDistributedTypeParameter(getTrueTypeFromConditionalType(c, s)), getTrueTypeFromConditionalType(c, target));
|
|
971
|
+
this.inferFromTypes(getNonDistributedTypeParameter(getFalseTypeFromConditionalType(c, s)), getFalseTypeFromConditionalType(c, target));
|
|
682
972
|
}
|
|
683
973
|
else {
|
|
684
974
|
const savePriority = this.priority;
|
|
@@ -888,9 +1178,9 @@ class InferenceState {
|
|
|
888
1178
|
// Once in a bivariant signature, nested inferences stay bivariant.
|
|
889
1179
|
this.bivariant =
|
|
890
1180
|
this.bivariant ||
|
|
891
|
-
kind ===
|
|
892
|
-
kind ===
|
|
893
|
-
kind ===
|
|
1181
|
+
kind === 176 /* SyntaxKind.MethodDeclaration */ ||
|
|
1182
|
+
kind === 175 /* SyntaxKind.MethodSignature */ ||
|
|
1183
|
+
kind === 178 /* SyntaxKind.Constructor */;
|
|
894
1184
|
applyToParameterTypes(c, source, target, (s, t) => this.inferFromContravariantTypesIfStrictFunctionTypes(s, t));
|
|
895
1185
|
this.bivariant = saveBivariant;
|
|
896
1186
|
}
|
|
@@ -965,12 +1255,47 @@ class InferenceState {
|
|
|
965
1255
|
}
|
|
966
1256
|
// ---- Helpers
|
|
967
1257
|
function getInferenceInfoForType(inferences, t) {
|
|
968
|
-
if ((t.flags & 34078720 /* TypeFlags.TypeVariable */) !== 0)
|
|
1258
|
+
if ((t.flags & 34078720 /* TypeFlags.TypeVariable */) !== 0) {
|
|
1259
|
+
const typeVariable = getNonDistributedTypeParameter(t);
|
|
969
1260
|
for (const inference of inferences)
|
|
970
|
-
if (
|
|
1261
|
+
if (typeVariable === inference.typeParameter)
|
|
971
1262
|
return inference;
|
|
1263
|
+
}
|
|
972
1264
|
return undefined;
|
|
973
1265
|
}
|
|
1266
|
+
/** Orders types by decreasing depth, then by the regular type ordering. */
|
|
1267
|
+
function compareTypesAndDepth(c, t1, t2) {
|
|
1268
|
+
const d1 = getTypeDepth(c, t1, 3);
|
|
1269
|
+
const d2 = getTypeDepth(c, t2, 3);
|
|
1270
|
+
if (d1 !== d2)
|
|
1271
|
+
return d2 - d1;
|
|
1272
|
+
return compareTypes(c, t1, t2);
|
|
1273
|
+
}
|
|
1274
|
+
/**
|
|
1275
|
+
* The depth of a type, up to `maxDepth`: one plus the largest type argument depth for generic aliased
|
|
1276
|
+
* types and type references, the largest constituent depth for unions and intersections, and zero
|
|
1277
|
+
* otherwise. The maximum keeps circular types from recursing forever.
|
|
1278
|
+
*/
|
|
1279
|
+
function getTypeDepth(c, t, maxDepth) {
|
|
1280
|
+
if (maxDepth !== 0) {
|
|
1281
|
+
if (t.alias !== undefined && t.alias.typeArguments.length !== 0)
|
|
1282
|
+
return getTypeListDepth(c, t.alias.typeArguments, maxDepth - 1) + 1;
|
|
1283
|
+
if ((t.objectFlags & 4 /* ObjectFlags.Reference */) !== 0) {
|
|
1284
|
+
const typeArguments = getTypeArguments(c, t);
|
|
1285
|
+
if (typeArguments.length !== 0)
|
|
1286
|
+
return getTypeListDepth(c, typeArguments, maxDepth - 1) + 1;
|
|
1287
|
+
}
|
|
1288
|
+
if ((t.flags & 402653184 /* TypeFlags.UnionOrIntersection */) !== 0)
|
|
1289
|
+
return getTypeListDepth(c, typesOf(t), maxDepth);
|
|
1290
|
+
}
|
|
1291
|
+
return 0;
|
|
1292
|
+
}
|
|
1293
|
+
function getTypeListDepth(c, types, maxDepth) {
|
|
1294
|
+
let depth = 0;
|
|
1295
|
+
for (const t of types)
|
|
1296
|
+
depth = Math.max(depth, getTypeDepth(c, t, maxDepth));
|
|
1297
|
+
return depth;
|
|
1298
|
+
}
|
|
974
1299
|
function distributedTypes(t) {
|
|
975
1300
|
return (t.flags & 134217728 /* TypeFlags.Union */) !== 0 ? typesOf(t) : [t];
|
|
976
1301
|
}
|
|
@@ -990,9 +1315,10 @@ function someTypeCouldHoldInference(c, targets) {
|
|
|
990
1315
|
}
|
|
991
1316
|
/**
|
|
992
1317
|
* `couldContainTypeVariables` without two of its conservative answers: a deferred reference without an
|
|
993
|
-
* alias
|
|
994
|
-
*
|
|
995
|
-
*
|
|
1318
|
+
* alias holds type variables only through its type arguments, like any other reference; and the static
|
|
1319
|
+
* side of a class declared at the top level of a file or module holds none outside its generic
|
|
1320
|
+
* signatures, which inference erases. A deferred reference's type arguments are resolved here unless
|
|
1321
|
+
* they are being resolved already, where resolving them would report a circularity.
|
|
996
1322
|
*/
|
|
997
1323
|
function couldHoldInference(c, t, depth) {
|
|
998
1324
|
if (!couldContainTypeVariables(c, t))
|
|
@@ -1000,7 +1326,11 @@ function couldHoldInference(c, t, depth) {
|
|
|
1000
1326
|
if (t.alias !== undefined || depth === 4)
|
|
1001
1327
|
return true;
|
|
1002
1328
|
if ((t.objectFlags & 4 /* ObjectFlags.Reference */) !== 0) {
|
|
1003
|
-
const resolved = t.resolvedTypeArguments ??
|
|
1329
|
+
const resolved = t.resolvedTypeArguments ??
|
|
1330
|
+
sideOf(c, t).resolvedTypeArguments ??
|
|
1331
|
+
(findResolutionCycleStartIndex(c, t, 5 /* TypeSystemPropertyName.ResolvedTypeArguments */) < 0
|
|
1332
|
+
? getTypeArguments(c, t)
|
|
1333
|
+
: undefined);
|
|
1004
1334
|
if (resolved === undefined)
|
|
1005
1335
|
return true;
|
|
1006
1336
|
for (const a of resolved)
|
|
@@ -1021,12 +1351,12 @@ function isTopLevelClassStaticSide(t) {
|
|
|
1021
1351
|
declarationCount(symbol) === 0)
|
|
1022
1352
|
return false;
|
|
1023
1353
|
for (const d of getDeclarations(symbol)) {
|
|
1024
|
-
if (d.kind !==
|
|
1025
|
-
d.kind !==
|
|
1026
|
-
d.kind !==
|
|
1354
|
+
if (d.kind !== 265 /* SyntaxKind.ClassDeclaration */ &&
|
|
1355
|
+
d.kind !== 266 /* SyntaxKind.InterfaceDeclaration */ &&
|
|
1356
|
+
d.kind !== 269 /* SyntaxKind.ModuleDeclaration */)
|
|
1027
1357
|
return false;
|
|
1028
|
-
for (let n = d.parent; n.kind !==
|
|
1029
|
-
if (n.kind !==
|
|
1358
|
+
for (let n = d.parent; n.kind !== 308 /* SyntaxKind.SourceFile */; n = n.parent)
|
|
1359
|
+
if (n.kind !== 270 /* SyntaxKind.ModuleBlock */ && n.kind !== 269 /* SyntaxKind.ModuleDeclaration */)
|
|
1030
1360
|
return false;
|
|
1031
1361
|
}
|
|
1032
1362
|
return true;
|
|
@@ -1130,6 +1460,8 @@ function hasUnmatchedProperty(c, source, target, matchDiscriminantProperties) {
|
|
|
1130
1460
|
if ((t.flags & 402653184 /* TypeFlags.UnionOrIntersection */) === 0 ||
|
|
1131
1461
|
sideOf(c, t).membersOf?.resolvedProperties !== undefined)
|
|
1132
1462
|
return getUnmatchedProperty(c, source, target, false, matchDiscriminantProperties) !== undefined;
|
|
1463
|
+
if (c.unresolvedPropertySearches !== undefined)
|
|
1464
|
+
c.unresolvedPropertySearches.push(t);
|
|
1133
1465
|
const containingType = t;
|
|
1134
1466
|
const isUnion = (t.flags & 134217728 /* TypeFlags.Union */) !== 0;
|
|
1135
1467
|
const checked = new Set();
|
|
@@ -1205,7 +1537,8 @@ export function isConstTypeVariable(c, t, depth) {
|
|
|
1205
1537
|
}
|
|
1206
1538
|
export function isMutableArrayLikeType(c, t) {
|
|
1207
1539
|
return (isMutableArrayOrTuple(c, t) ||
|
|
1208
|
-
((t.flags & (1 /* TypeFlags.Any */ | 12 /* TypeFlags.Nullable */)) === 0 &&
|
|
1540
|
+
((t.flags & (1 /* TypeFlags.Any */ | 12 /* TypeFlags.Nullable */ | 262144 /* TypeFlags.Never */)) === 0 &&
|
|
1541
|
+
isTypeAssignableTo(c, t, c.anyArrayType)));
|
|
1209
1542
|
}
|
|
1210
1543
|
function typePredicateKindsMatch(a, b) {
|
|
1211
1544
|
return a.kind === b.kind && a.parameterIndex === b.parameterIndex;
|
|
@@ -1328,7 +1661,11 @@ export function isUnmatchedTemplateLiteralKey(source, target) {
|
|
|
1328
1661
|
return failsTemplateLiteralTextTest(source, target);
|
|
1329
1662
|
}
|
|
1330
1663
|
/** The types matched by `target`'s placeholders in `source`, or undefined if it doesn't match. */
|
|
1331
|
-
|
|
1664
|
+
/**
|
|
1665
|
+
* The types that `source` gives the placeholders of `target`. A placeholder of a source template with the same
|
|
1666
|
+
* texts keeps its type where `compareTypes` (assignability by default) relates their base constraints.
|
|
1667
|
+
*/
|
|
1668
|
+
export function inferTypesFromTemplateLiteralType(c, source, target, compareTypes) {
|
|
1332
1669
|
if ((source.flags & 1024 /* TypeFlags.StringLiteral */) !== 0) {
|
|
1333
1670
|
// Most string literals fail the start and end text test; apply it before building the
|
|
1334
1671
|
// one-element source texts.
|
|
@@ -1342,9 +1679,12 @@ export function inferTypesFromTemplateLiteralType(c, source, target) {
|
|
|
1342
1679
|
const result = [];
|
|
1343
1680
|
for (let i = 0; i < s.types.length; i++) {
|
|
1344
1681
|
const t = s.types[i];
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1682
|
+
const sourceConstraint = getBaseConstraintOrType(c, t);
|
|
1683
|
+
const targetConstraint = getBaseConstraintOrType(c, target.types[i]);
|
|
1684
|
+
const related = compareTypes !== undefined
|
|
1685
|
+
? compareTypes(sourceConstraint, targetConstraint)
|
|
1686
|
+
: isTypeAssignableTo(c, sourceConstraint, targetConstraint);
|
|
1687
|
+
result.push(related ? t : getStringLikeTypeForType(c, t));
|
|
1348
1688
|
}
|
|
1349
1689
|
return result;
|
|
1350
1690
|
}
|
|
@@ -1641,7 +1981,7 @@ export function resolveReverseMappedTypeMembers(c, t) {
|
|
|
1641
1981
|
if (!isTypeAssignableTo(c, propertyNameType, limitedConstraint))
|
|
1642
1982
|
continue;
|
|
1643
1983
|
}
|
|
1644
|
-
const checkFlags =
|
|
1984
|
+
const checkFlags = 65536 /* CheckFlags.ReverseMapped */ | (readonlyMask && isReadonlySymbol(c, prop) ? 8 /* CheckFlags.Readonly */ : 0);
|
|
1645
1985
|
const inferredProp = c.newSymbolWithCheckFlags(4 /* SymbolFlags.Property */ | (prop.flags & optionalMask), prop.name, checkFlags);
|
|
1646
1986
|
copyDeclarations(inferredProp, prop);
|
|
1647
1987
|
const links = c.symbolLinks(inferredProp);
|
|
@@ -1761,7 +2101,10 @@ export function getInferredType(c, context, index) {
|
|
|
1761
2101
|
const constraint = getConstraintOfTypeParameter(c, inference.typeParameter);
|
|
1762
2102
|
if (constraint !== undefined) {
|
|
1763
2103
|
const instantiatedConstraint = instantiateType(c, constraint, context.nonFixingMapper);
|
|
1764
|
-
|
|
2104
|
+
// A pure return type inference is still filtered in a recursive call resolution: its result can become
|
|
2105
|
+
// the type of the enclosing declaration.
|
|
2106
|
+
if (inferredType !== undefined &&
|
|
2107
|
+
((context.flags & 8 /* InferenceFlags.NoConstraintChecks */) === 0 || inference.priority === 128 /* InferencePriority.ReturnType */)) {
|
|
1765
2108
|
const constraintWithThis = getTypeWithThisArgument(c, instantiatedConstraint, inferredType, false);
|
|
1766
2109
|
if (context.compareTypes.compare(inferredType, constraintWithThis, false) === 0 /* Ternary.False */) {
|
|
1767
2110
|
// A pure return type inference may still succeed without the constituents the constraint rejects.
|
|
@@ -1790,8 +2133,18 @@ function clearActiveMapperCaches(c) {
|
|
|
1790
2133
|
if (cache !== undefined)
|
|
1791
2134
|
cache.clear();
|
|
1792
2135
|
}
|
|
2136
|
+
function setNumberEntry(stack, depth, value) {
|
|
2137
|
+
if (depth < stack.length)
|
|
2138
|
+
stack[depth] = value;
|
|
2139
|
+
else
|
|
2140
|
+
stack.push(value);
|
|
2141
|
+
}
|
|
1793
2142
|
/** Type ids below this bound pack in pairs into one exact number. */
|
|
1794
2143
|
const VisitKeyIdLimit = 1 << 26;
|
|
2144
|
+
/** The priority and variance of an inference walk, packed. */
|
|
2145
|
+
function visitMode(priority, contravariant, bivariant) {
|
|
2146
|
+
return priority * 4 + (contravariant ? 2 : 0) + (bivariant ? 1 : 0);
|
|
2147
|
+
}
|
|
1795
2148
|
/** invokeOnce's key for a pair of types: both ids in one number, or -1 when an id is too large. */
|
|
1796
2149
|
function visitKey(source, target) {
|
|
1797
2150
|
const s = source.id;
|
|
@@ -1998,11 +2351,32 @@ export class InferenceCaches {
|
|
|
1998
2351
|
contextFreeTypes = new Map();
|
|
1999
2352
|
reverseMapped = new Map();
|
|
2000
2353
|
reverseHomomorphicMapped = new Map();
|
|
2354
|
+
/**
|
|
2355
|
+
* invokeOnce's recursion stacks, shared by the checker's inference walks, with the mode of each visit and the
|
|
2356
|
+
* recursion identities isDeeplyNestedStackEntry keeps for each entry. The first `invokeStackDepth` entries are live.
|
|
2357
|
+
* A walk's entries start where the live entries end when it starts (`InferenceState.stackBase`), so a walk started
|
|
2358
|
+
* during another one keeps the other's entries.
|
|
2359
|
+
*/
|
|
2360
|
+
invokeSourceStack = [];
|
|
2361
|
+
invokeTargetStack = [];
|
|
2362
|
+
invokeModeStack = [];
|
|
2363
|
+
invokeSourceIdentities = [];
|
|
2364
|
+
invokeTargetIdentities = [];
|
|
2365
|
+
invokeStackDepth = 0;
|
|
2001
2366
|
/** inferReverseMappedType's recursion stacks; the first `reverseStackDepth` entries of each are live. */
|
|
2002
2367
|
reverseSourceStack = [];
|
|
2003
2368
|
reverseTargetStack = [];
|
|
2004
2369
|
reverseStackDepth = 0;
|
|
2005
2370
|
reverseExpandingFlags = 0 /* ExpandingFlags.None */;
|
|
2371
|
+
/**
|
|
2372
|
+
* What `inferTypesFromUnstarted` left in each inference, by signature id, then by source type id
|
|
2373
|
+
* times 4096 plus the priority.
|
|
2374
|
+
*/
|
|
2375
|
+
unstartedInferences = new Map();
|
|
2376
|
+
/** The `unstartedInferences` entry of a walk seen once. */
|
|
2377
|
+
seenOnce = new UnstartedInference(0 /* UnstartedInferenceState.Seen */, [], 0, 0, 0, []);
|
|
2378
|
+
/** The `unstartedInferences` entry of a walk that is never skipped. */
|
|
2379
|
+
alwaysWalked = new UnstartedInference(3 /* UnstartedInferenceState.Unusable */, [], 0, 0, 0, []);
|
|
2006
2380
|
}
|
|
2007
2381
|
// ---- Constraints of `infer` type parameters
|
|
2008
2382
|
/**
|
|
@@ -2044,18 +2418,18 @@ export function getInferredTypeParameterConstraint(c, t, omitTypeReferences = fa
|
|
|
2044
2418
|
const symbol = t.symbol;
|
|
2045
2419
|
if (symbol !== undefined)
|
|
2046
2420
|
for (const declaration of getDeclarations(symbol)) {
|
|
2047
|
-
if (declaration.parent === undefined || declaration.parent.kind !==
|
|
2421
|
+
if (declaration.parent === undefined || declaration.parent.kind !== 197 /* SyntaxKind.InferType */)
|
|
2048
2422
|
continue;
|
|
2049
2423
|
let child = declaration.parent;
|
|
2050
2424
|
let parent = child.parent;
|
|
2051
|
-
while (parent !== undefined && parent.kind ===
|
|
2425
|
+
while (parent !== undefined && parent.kind === 198 /* SyntaxKind.ParenthesizedType */) {
|
|
2052
2426
|
child = parent;
|
|
2053
2427
|
parent = child.parent;
|
|
2054
2428
|
}
|
|
2055
2429
|
if (parent === undefined)
|
|
2056
2430
|
continue;
|
|
2057
2431
|
switch (parent.kind) {
|
|
2058
|
-
case
|
|
2432
|
+
case 185 /* SyntaxKind.TypeReference */: {
|
|
2059
2433
|
if (omitTypeReferences)
|
|
2060
2434
|
break;
|
|
2061
2435
|
// `Foo<infer T>` takes the constraint of Foo's corresponding type parameter.
|
|
@@ -2075,34 +2449,34 @@ export function getInferredTypeParameterConstraint(c, t, omitTypeReferences = fa
|
|
|
2075
2449
|
inferences.push(constraint);
|
|
2076
2450
|
break;
|
|
2077
2451
|
}
|
|
2078
|
-
case
|
|
2452
|
+
case 171 /* SyntaxKind.Parameter */:
|
|
2079
2453
|
if (parent.dotDotDotToken !== undefined)
|
|
2080
2454
|
inferences.push(createArrayType(c, c.unknownType));
|
|
2081
2455
|
break;
|
|
2082
|
-
case
|
|
2456
|
+
case 193 /* SyntaxKind.RestType */:
|
|
2083
2457
|
inferences.push(createArrayType(c, c.unknownType));
|
|
2084
2458
|
break;
|
|
2085
|
-
case
|
|
2459
|
+
case 204 /* SyntaxKind.NamedTupleMember */:
|
|
2086
2460
|
if (parent.dotDotDotToken !== undefined)
|
|
2087
2461
|
inferences.push(createArrayType(c, c.unknownType));
|
|
2088
2462
|
break;
|
|
2089
|
-
case
|
|
2463
|
+
case 206 /* SyntaxKind.TemplateLiteralTypeSpan */:
|
|
2090
2464
|
inferences.push(c.stringType);
|
|
2091
2465
|
break;
|
|
2092
|
-
case
|
|
2093
|
-
if (parent.parent !== undefined && parent.parent.kind ===
|
|
2466
|
+
case 170 /* SyntaxKind.TypeParameter */:
|
|
2467
|
+
if (parent.parent !== undefined && parent.parent.kind === 202 /* SyntaxKind.MappedType */)
|
|
2094
2468
|
inferences.push(c.stringNumberSymbolType);
|
|
2095
2469
|
break;
|
|
2096
|
-
case
|
|
2470
|
+
case 202 /* SyntaxKind.MappedType */: {
|
|
2097
2471
|
// `{ [P in K]: X } extends { [Q in L]: infer U }` constrains U to X with P replaced by K.
|
|
2098
2472
|
const mapped = parent;
|
|
2099
2473
|
const conditional = parent.parent;
|
|
2100
2474
|
if (mapped.type !== undefined &&
|
|
2101
2475
|
mapped.type === declaration.parent &&
|
|
2102
2476
|
conditional !== undefined &&
|
|
2103
|
-
conditional.kind ===
|
|
2477
|
+
conditional.kind === 196 /* SyntaxKind.ConditionalType */ &&
|
|
2104
2478
|
conditional.extendsType === parent &&
|
|
2105
|
-
conditional.checkType.kind ===
|
|
2479
|
+
conditional.checkType.kind === 202 /* SyntaxKind.MappedType */ &&
|
|
2106
2480
|
conditional.checkType.type !== undefined) {
|
|
2107
2481
|
const checkMappedType = conditional.checkType;
|
|
2108
2482
|
const nodeType = getTypeFromTypeNode(c, checkMappedType.type);
|