tsc-ts 0.0.3 → 0.0.5
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 +46 -0
- package/dist/api/compiler/ast-utilities.d.ts +82 -0
- package/dist/api/compiler/ast-utilities.js +462 -0
- package/dist/api/compiler/ast.d.ts +2350 -0
- package/dist/api/compiler/ast.js +11206 -0
- package/dist/api/compiler/astnav.d.ts +37 -0
- package/dist/api/compiler/astnav.js +767 -0
- package/dist/api/compiler/binder-utilities.d.ts +182 -0
- package/dist/api/compiler/binder-utilities.js +1240 -0
- package/dist/api/compiler/binder.d.ts +33 -0
- package/dist/api/compiler/binder.js +2358 -0
- package/dist/api/compiler/character-codes.d.ts +161 -0
- package/dist/api/compiler/character-codes.js +160 -0
- package/dist/api/compiler/checker-calls.d.ts +46 -0
- package/dist/api/compiler/checker-calls.js +1640 -0
- package/dist/api/compiler/checker-classes.d.ts +30 -0
- package/dist/api/compiler/checker-classes.js +582 -0
- package/dist/api/compiler/checker-contextual.d.ts +77 -0
- package/dist/api/compiler/checker-contextual.js +1136 -0
- package/dist/api/compiler/checker-declaration-order.d.ts +12 -0
- package/dist/api/compiler/checker-declaration-order.js +356 -0
- package/dist/api/compiler/checker-declarations.d.ts +33 -0
- package/dist/api/compiler/checker-declarations.js +888 -0
- package/dist/api/compiler/checker-declared-types.d.ts +48 -0
- package/dist/api/compiler/checker-declared-types.js +787 -0
- package/dist/api/compiler/checker-decorators.d.ts +26 -0
- package/dist/api/compiler/checker-decorators.js +562 -0
- package/dist/api/compiler/checker-deprecation.d.ts +33 -0
- package/dist/api/compiler/checker-deprecation.js +315 -0
- package/dist/api/compiler/checker-destructuring.d.ts +34 -0
- package/dist/api/compiler/checker-destructuring.js +584 -0
- package/dist/api/compiler/checker-elaboration.d.ts +15 -0
- package/dist/api/compiler/checker-elaboration.js +290 -0
- package/dist/api/compiler/checker-emit-helpers.d.ts +58 -0
- package/dist/api/compiler/checker-emit-helpers.js +154 -0
- package/dist/api/compiler/checker-emit-resolver.d.ts +75 -0
- package/dist/api/compiler/checker-emit-resolver.js +579 -0
- package/dist/api/compiler/checker-evaluator.d.ts +27 -0
- package/dist/api/compiler/checker-evaluator.js +188 -0
- package/dist/api/compiler/checker-expressions.d.ts +67 -0
- package/dist/api/compiler/checker-expressions.js +1351 -0
- package/dist/api/compiler/checker-features.d.ts +6 -0
- package/dist/api/compiler/checker-features.js +354 -0
- package/dist/api/compiler/checker-flow.d.ts +86 -0
- package/dist/api/compiler/checker-flow.js +169 -0
- package/dist/api/compiler/checker-functions.d.ts +43 -0
- package/dist/api/compiler/checker-functions.js +1002 -0
- package/dist/api/compiler/checker-generated-code.d.ts +25 -0
- package/dist/api/compiler/checker-generated-code.js +168 -0
- package/dist/api/compiler/checker-globals.d.ts +14 -0
- package/dist/api/compiler/checker-globals.js +37 -0
- package/dist/api/compiler/checker-grammar.d.ts +35 -0
- package/dist/api/compiler/checker-grammar.js +2573 -0
- package/dist/api/compiler/checker-heritage.d.ts +28 -0
- package/dist/api/compiler/checker-heritage.js +900 -0
- package/dist/api/compiler/checker-inference.d.ts +179 -0
- package/dist/api/compiler/checker-inference.js +2105 -0
- package/dist/api/compiler/checker-iteration.d.ts +115 -0
- package/dist/api/compiler/checker-iteration.js +857 -0
- package/dist/api/compiler/checker-javascript.d.ts +42 -0
- package/dist/api/compiler/checker-javascript.js +441 -0
- package/dist/api/compiler/checker-jsdoc.d.ts +30 -0
- package/dist/api/compiler/checker-jsdoc.js +320 -0
- package/dist/api/compiler/checker-jsx.d.ts +94 -0
- package/dist/api/compiler/checker-jsx.js +1433 -0
- package/dist/api/compiler/checker-literals.d.ts +6 -0
- package/dist/api/compiler/checker-literals.js +43 -0
- package/dist/api/compiler/checker-members.d.ts +198 -0
- package/dist/api/compiler/checker-members.js +2126 -0
- package/dist/api/compiler/checker-modules.d.ts +85 -0
- package/dist/api/compiler/checker-modules.js +2141 -0
- package/dist/api/compiler/checker-narrowing.d.ts +120 -0
- package/dist/api/compiler/checker-narrowing.js +2797 -0
- package/dist/api/compiler/checker-object-literals.d.ts +14 -0
- package/dist/api/compiler/checker-object-literals.js +479 -0
- package/dist/api/compiler/checker-operators.d.ts +33 -0
- package/dist/api/compiler/checker-operators.js +1040 -0
- package/dist/api/compiler/checker-overloads.d.ts +7 -0
- package/dist/api/compiler/checker-overloads.js +270 -0
- package/dist/api/compiler/checker-property-access.d.ts +34 -0
- package/dist/api/compiler/checker-property-access.js +672 -0
- package/dist/api/compiler/checker-services.d.ts +49 -0
- package/dist/api/compiler/checker-services.js +995 -0
- package/dist/api/compiler/checker-signatures.d.ts +55 -0
- package/dist/api/compiler/checker-signatures.js +788 -0
- package/dist/api/compiler/checker-source-file.d.ts +27 -0
- package/dist/api/compiler/checker-source-file.js +619 -0
- package/dist/api/compiler/checker-statements.d.ts +18 -0
- package/dist/api/compiler/checker-statements.js +226 -0
- package/dist/api/compiler/checker-super.d.ts +13 -0
- package/dist/api/compiler/checker-super.js +241 -0
- package/dist/api/compiler/checker-symbol-types.d.ts +67 -0
- package/dist/api/compiler/checker-symbol-types.js +1885 -0
- package/dist/api/compiler/checker-symbols.d.ts +181 -0
- package/dist/api/compiler/checker-symbols.js +1782 -0
- package/dist/api/compiler/checker-type-factory.d.ts +142 -0
- package/dist/api/compiler/checker-type-factory.js +2501 -0
- package/dist/api/compiler/checker-type-nodes.d.ts +26 -0
- package/dist/api/compiler/checker-type-nodes.js +828 -0
- package/dist/api/compiler/checker-type-operators.d.ts +109 -0
- package/dist/api/compiler/checker-type-operators.js +1842 -0
- package/dist/api/compiler/checker-types.d.ts +1027 -0
- package/dist/api/compiler/checker-types.js +1697 -0
- package/dist/api/compiler/checker-unused.d.ts +19 -0
- package/dist/api/compiler/checker-unused.js +524 -0
- package/dist/api/compiler/checker-utilities.d.ts +33 -0
- package/dist/api/compiler/checker-utilities.js +141 -0
- package/dist/api/compiler/checker.d.ts +491 -0
- package/dist/api/compiler/checker.js +912 -0
- package/dist/api/compiler/command-line.d.ts +32 -0
- package/dist/api/compiler/command-line.js +383 -0
- package/dist/api/compiler/compile-program.d.ts +118 -0
- package/dist/api/compiler/compile-program.js +384 -0
- package/dist/api/compiler/diagnostic-locales.d.ts +22 -0
- package/dist/api/compiler/diagnostic-locales.js +64 -0
- package/dist/api/compiler/diagnostic-messages.d.ts +2166 -0
- package/dist/api/compiler/diagnostic-messages.js +184 -0
- package/dist/api/compiler/diagnostics.d.ts +167 -0
- package/dist/api/compiler/diagnostics.js +820 -0
- package/dist/api/compiler/emitter.d.ts +71 -0
- package/dist/api/compiler/emitter.js +327 -0
- package/dist/api/compiler/file-include.d.ts +117 -0
- package/dist/api/compiler/file-include.js +536 -0
- package/dist/api/compiler/file-loader.d.ts +261 -0
- package/dist/api/compiler/file-loader.js +1257 -0
- package/dist/api/compiler/file-system.d.ts +51 -0
- package/dist/api/compiler/file-system.js +132 -0
- package/dist/api/compiler/flow.d.ts +60 -0
- package/dist/api/compiler/flow.js +45 -0
- package/dist/api/compiler/instantiation.d.ts +74 -0
- package/dist/api/compiler/instantiation.js +799 -0
- package/dist/api/compiler/jsdoc.d.ts +75 -0
- package/dist/api/compiler/jsdoc.js +1229 -0
- package/dist/api/compiler/link-tables.d.ts +36 -0
- package/dist/api/compiler/link-tables.js +83 -0
- package/dist/api/compiler/locale-data.d.ts +24 -0
- package/dist/api/compiler/locale-data.js +183 -0
- package/dist/api/compiler/locale.d.ts +4 -0
- package/dist/api/compiler/locale.js +317 -0
- package/dist/api/compiler/locales/cs-CZ.d.ts +2 -0
- package/dist/api/compiler/locales/cs-CZ.js +3 -0
- package/dist/api/compiler/locales/de-DE.d.ts +2 -0
- package/dist/api/compiler/locales/de-DE.js +3 -0
- package/dist/api/compiler/locales/es-ES.d.ts +2 -0
- package/dist/api/compiler/locales/es-ES.js +3 -0
- package/dist/api/compiler/locales/fr-FR.d.ts +2 -0
- package/dist/api/compiler/locales/fr-FR.js +3 -0
- package/dist/api/compiler/locales/it-IT.d.ts +2 -0
- package/dist/api/compiler/locales/it-IT.js +3 -0
- package/dist/api/compiler/locales/ja-JP.d.ts +2 -0
- package/dist/api/compiler/locales/ja-JP.js +3 -0
- package/dist/api/compiler/locales/ko-KR.d.ts +2 -0
- package/dist/api/compiler/locales/ko-KR.js +3 -0
- package/dist/api/compiler/locales/pl-PL.d.ts +2 -0
- package/dist/api/compiler/locales/pl-PL.js +3 -0
- package/dist/api/compiler/locales/pt-BR.d.ts +2 -0
- package/dist/api/compiler/locales/pt-BR.js +3 -0
- package/dist/api/compiler/locales/ru-RU.d.ts +2 -0
- package/dist/api/compiler/locales/ru-RU.js +3 -0
- package/dist/api/compiler/locales/tr-TR.d.ts +2 -0
- package/dist/api/compiler/locales/tr-TR.js +3 -0
- package/dist/api/compiler/locales/zh-CN.d.ts +2 -0
- package/dist/api/compiler/locales/zh-CN.js +3 -0
- package/dist/api/compiler/locales/zh-TW.d.ts +2 -0
- package/dist/api/compiler/locales/zh-TW.js +3 -0
- package/dist/api/compiler/module-resolution-types.d.ts +83 -0
- package/dist/api/compiler/module-resolution-types.js +176 -0
- package/dist/api/compiler/module-resolution.d.ts +71 -0
- package/dist/api/compiler/module-resolution.js +1598 -0
- package/dist/api/compiler/module-specifiers.d.ts +64 -0
- package/dist/api/compiler/module-specifiers.js +1101 -0
- package/dist/api/compiler/name-resolver.d.ts +43 -0
- package/dist/api/compiler/name-resolver.js +509 -0
- package/dist/api/compiler/node-builder-names.d.ts +32 -0
- package/dist/api/compiler/node-builder-names.js +854 -0
- package/dist/api/compiler/node-builder-pseudo.d.ts +36 -0
- package/dist/api/compiler/node-builder-pseudo.js +744 -0
- package/dist/api/compiler/node-builder-reuse.d.ts +4 -0
- package/dist/api/compiler/node-builder-reuse.js +647 -0
- package/dist/api/compiler/node-builder.d.ts +270 -0
- package/dist/api/compiler/node-builder.js +2645 -0
- package/dist/api/compiler/option-declarations.d.ts +90 -0
- package/dist/api/compiler/option-declarations.js +1460 -0
- package/dist/api/compiler/options.d.ts +289 -0
- package/dist/api/compiler/options.js +1197 -0
- package/dist/api/compiler/output-paths.d.ts +42 -0
- package/dist/api/compiler/output-paths.js +195 -0
- package/dist/api/compiler/package-json.d.ts +175 -0
- package/dist/api/compiler/package-json.js +1015 -0
- package/dist/api/compiler/parallel-parse.d.ts +219 -0
- package/dist/api/compiler/parallel-parse.js +537 -0
- package/dist/api/compiler/parser.d.ts +587 -0
- package/dist/api/compiler/parser.js +6407 -0
- package/dist/api/compiler/path.d.ts +91 -0
- package/dist/api/compiler/path.js +705 -0
- package/dist/api/compiler/printer/async-helpers.d.ts +22 -0
- package/dist/api/compiler/printer/async-helpers.js +91 -0
- package/dist/api/compiler/printer/auto-generate.d.ts +13 -0
- package/dist/api/compiler/printer/auto-generate.js +20 -0
- package/dist/api/compiler/printer/decorator-helpers.d.ts +24 -0
- package/dist/api/compiler/printer/decorator-helpers.js +118 -0
- package/dist/api/compiler/printer/emit-context.d.ts +154 -0
- package/dist/api/compiler/printer/emit-context.js +576 -0
- package/dist/api/compiler/printer/emit-flags.d.ts +60 -0
- package/dist/api/compiler/printer/emit-flags.js +2 -0
- package/dist/api/compiler/printer/factory-base.d.ts +171 -0
- package/dist/api/compiler/printer/factory-base.js +1505 -0
- package/dist/api/compiler/printer/factory.d.ts +147 -0
- package/dist/api/compiler/printer/factory.js +542 -0
- package/dist/api/compiler/printer/helpers.d.ts +27 -0
- package/dist/api/compiler/printer/helpers.js +164 -0
- package/dist/api/compiler/printer/name-generator.d.ts +41 -0
- package/dist/api/compiler/printer/name-generator.js +283 -0
- package/dist/api/compiler/printer/printer.d.ts +411 -0
- package/dist/api/compiler/printer/printer.js +4517 -0
- package/dist/api/compiler/printer/text-writer.d.ts +46 -0
- package/dist/api/compiler/printer/text-writer.js +172 -0
- package/dist/api/compiler/printer/utilities.d.ts +82 -0
- package/dist/api/compiler/printer/utilities.js +817 -0
- package/dist/api/compiler/program-checker.d.ts +156 -0
- package/dist/api/compiler/program-checker.js +526 -0
- package/dist/api/compiler/program-utilities.d.ts +52 -0
- package/dist/api/compiler/program-utilities.js +365 -0
- package/dist/api/compiler/program.d.ts +180 -0
- package/dist/api/compiler/program.js +1011 -0
- package/dist/api/compiler/pseudo-bigint.d.ts +5 -0
- package/dist/api/compiler/pseudo-bigint.js +61 -0
- package/dist/api/compiler/regexp-checker.d.ts +38 -0
- package/dist/api/compiler/regexp-checker.js +942 -0
- package/dist/api/compiler/relations.d.ts +263 -0
- package/dist/api/compiler/relations.js +4002 -0
- package/dist/api/compiler/reparser.d.ts +48 -0
- package/dist/api/compiler/reparser.js +1323 -0
- package/dist/api/compiler/scanner.d.ts +256 -0
- package/dist/api/compiler/scanner.js +2853 -0
- package/dist/api/compiler/side-state.d.ts +16 -0
- package/dist/api/compiler/side-state.js +89 -0
- package/dist/api/compiler/sourcemap.d.ts +55 -0
- package/dist/api/compiler/sourcemap.js +340 -0
- package/dist/api/compiler/spelling.d.ts +14 -0
- package/dist/api/compiler/spelling.js +128 -0
- package/dist/api/compiler/symbol-accessibility.d.ts +57 -0
- package/dist/api/compiler/symbol-accessibility.js +894 -0
- package/dist/api/compiler/symbol.d.ts +240 -0
- package/dist/api/compiler/symbol.js +228 -0
- package/dist/api/compiler/symlinks.d.ts +32 -0
- package/dist/api/compiler/symlinks.js +114 -0
- package/dist/api/compiler/syntax-kind.d.ts +389 -0
- package/dist/api/compiler/syntax-kind.js +2 -0
- package/dist/api/compiler/timeline.d.ts +9 -0
- package/dist/api/compiler/timeline.js +54 -0
- package/dist/api/compiler/transformers/alias-references.d.ts +39 -0
- package/dist/api/compiler/transformers/alias-references.js +676 -0
- package/dist/api/compiler/transformers/async-utilities.d.ts +51 -0
- package/dist/api/compiler/transformers/async-utilities.js +260 -0
- package/dist/api/compiler/transformers/async.d.ts +53 -0
- package/dist/api/compiler/transformers/async.js +645 -0
- package/dist/api/compiler/transformers/class-fields.d.ts +206 -0
- package/dist/api/compiler/transformers/class-fields.js +2418 -0
- package/dist/api/compiler/transformers/class-utilities.d.ts +46 -0
- package/dist/api/compiler/transformers/class-utilities.js +261 -0
- package/dist/api/compiler/transformers/commonjs-module.d.ts +103 -0
- package/dist/api/compiler/transformers/commonjs-module.js +1180 -0
- package/dist/api/compiler/transformers/const-enum-inliner.d.ts +11 -0
- package/dist/api/compiler/transformers/const-enum-inliner.js +36 -0
- package/dist/api/compiler/transformers/declarations-diagnostics.d.ts +52 -0
- package/dist/api/compiler/transformers/declarations-diagnostics.js +538 -0
- package/dist/api/compiler/transformers/declarations-pseudo.d.ts +160 -0
- package/dist/api/compiler/transformers/declarations-pseudo.js +797 -0
- package/dist/api/compiler/transformers/declarations-resolver.d.ts +152 -0
- package/dist/api/compiler/transformers/declarations-resolver.js +35 -0
- package/dist/api/compiler/transformers/declarations-syntactic.d.ts +119 -0
- package/dist/api/compiler/transformers/declarations-syntactic.js +1582 -0
- package/dist/api/compiler/transformers/declarations-tracker.d.ts +46 -0
- package/dist/api/compiler/transformers/declarations-tracker.js +197 -0
- package/dist/api/compiler/transformers/declarations.d.ts +175 -0
- package/dist/api/compiler/transformers/declarations.js +2380 -0
- package/dist/api/compiler/transformers/decorator-metadata.d.ts +54 -0
- package/dist/api/compiler/transformers/decorator-metadata.js +554 -0
- package/dist/api/compiler/transformers/decorator-utilities.d.ts +38 -0
- package/dist/api/compiler/transformers/decorator-utilities.js +238 -0
- package/dist/api/compiler/transformers/destructuring.d.ts +25 -0
- package/dist/api/compiler/transformers/destructuring.js +626 -0
- package/dist/api/compiler/transformers/downlevel.d.ts +6 -0
- package/dist/api/compiler/transformers/downlevel.js +45 -0
- package/dist/api/compiler/transformers/emit-resolver.d.ts +61 -0
- package/dist/api/compiler/transformers/emit-resolver.js +197 -0
- package/dist/api/compiler/transformers/es-decorators.d.ts +118 -0
- package/dist/api/compiler/transformers/es-decorators.js +1901 -0
- package/dist/api/compiler/transformers/exponentiation.d.ts +11 -0
- package/dist/api/compiler/transformers/exponentiation.js +76 -0
- package/dist/api/compiler/transformers/external-module-info.d.ts +35 -0
- package/dist/api/compiler/transformers/external-module-info.js +351 -0
- package/dist/api/compiler/transformers/for-await.d.ts +43 -0
- package/dist/api/compiler/transformers/for-await.js +469 -0
- package/dist/api/compiler/transformers/import-elision.d.ts +16 -0
- package/dist/api/compiler/transformers/import-elision.js +124 -0
- package/dist/api/compiler/transformers/jsx-entities.d.ts +1 -0
- package/dist/api/compiler/transformers/jsx-entities.js +256 -0
- package/dist/api/compiler/transformers/jsx.d.ts +71 -0
- package/dist/api/compiler/transformers/jsx.js +700 -0
- package/dist/api/compiler/transformers/legacy-decorators.d.ts +56 -0
- package/dist/api/compiler/transformers/legacy-decorators.js +564 -0
- package/dist/api/compiler/transformers/logical-assignment.d.ts +14 -0
- package/dist/api/compiler/transformers/logical-assignment.js +62 -0
- package/dist/api/compiler/transformers/module-utilities.d.ts +9 -0
- package/dist/api/compiler/transformers/module-utilities.js +36 -0
- package/dist/api/compiler/transformers/module.d.ts +49 -0
- package/dist/api/compiler/transformers/module.js +296 -0
- package/dist/api/compiler/transformers/named-evaluation.d.ts +26 -0
- package/dist/api/compiler/transformers/named-evaluation.js +266 -0
- package/dist/api/compiler/transformers/nullish-coalescing.d.ts +9 -0
- package/dist/api/compiler/transformers/nullish-coalescing.js +26 -0
- package/dist/api/compiler/transformers/object-rest-spread.d.ts +34 -0
- package/dist/api/compiler/transformers/object-rest-spread.js +411 -0
- package/dist/api/compiler/transformers/optional-catch.d.ts +9 -0
- package/dist/api/compiler/transformers/optional-catch.js +20 -0
- package/dist/api/compiler/transformers/optional-chain.d.ts +14 -0
- package/dist/api/compiler/transformers/optional-chain.js +188 -0
- package/dist/api/compiler/transformers/reference-resolver.d.ts +128 -0
- package/dist/api/compiler/transformers/reference-resolver.js +1155 -0
- package/dist/api/compiler/transformers/runtime-syntax.d.ts +71 -0
- package/dist/api/compiler/transformers/runtime-syntax.js +753 -0
- package/dist/api/compiler/transformers/subtree-facts.d.ts +9 -0
- package/dist/api/compiler/transformers/subtree-facts.js +203 -0
- package/dist/api/compiler/transformers/syntax-facts.d.ts +51 -0
- package/dist/api/compiler/transformers/syntax-facts.js +254 -0
- package/dist/api/compiler/transformers/tagged-template.d.ts +17 -0
- package/dist/api/compiler/transformers/tagged-template.js +148 -0
- package/dist/api/compiler/transformers/transformer.d.ts +17 -0
- package/dist/api/compiler/transformers/transformer.js +54 -0
- package/dist/api/compiler/transformers/type-eraser.d.ts +21 -0
- package/dist/api/compiler/transformers/type-eraser.js +346 -0
- package/dist/api/compiler/transformers/type-serialization.d.ts +20 -0
- package/dist/api/compiler/transformers/type-serialization.js +347 -0
- package/dist/api/compiler/transformers/using.d.ts +56 -0
- package/dist/api/compiler/transformers/using.js +453 -0
- package/dist/api/compiler/transformers/utilities.d.ts +50 -0
- package/dist/api/compiler/transformers/utilities.js +347 -0
- package/dist/api/compiler/transformers/visitor-base.d.ts +6 -0
- package/dist/api/compiler/transformers/visitor-base.js +817 -0
- package/dist/api/compiler/transformers/visitor-hooks.d.ts +29 -0
- package/dist/api/compiler/transformers/visitor-hooks.js +189 -0
- package/dist/api/compiler/tsconfig.d.ts +177 -0
- package/dist/api/compiler/tsconfig.js +1311 -0
- package/dist/api/compiler/type-printer.d.ts +15 -0
- package/dist/api/compiler/type-printer.js +74 -0
- package/dist/api/compiler/types.d.ts +87 -0
- package/dist/api/compiler/types.js +23 -0
- package/dist/api/compiler/unicode-identifiers.d.ts +2 -0
- package/dist/api/compiler/unicode-identifiers.js +209 -0
- package/dist/api/compiler/unicode-properties.d.ts +8 -0
- package/dist/api/compiler/unicode-properties.js +531 -0
- package/dist/api/compiler/vfs-match.d.ts +24 -0
- package/dist/api/compiler/vfs-match.js +587 -0
- package/dist/api/library/ast.d.ts +74 -0
- package/dist/api/library/ast.generated.d.ts +1145 -0
- package/dist/api/library/ast.generated.js +3 -0
- package/dist/api/library/ast.js +5 -0
- package/dist/api/library/checker.d.ts +51 -0
- package/dist/api/library/checker.js +318 -0
- package/dist/api/library/compiler-options.generated.d.ts +108 -0
- package/dist/api/library/compiler-options.generated.js +3 -0
- package/dist/api/library/diagnostics.d.ts +13 -0
- package/dist/api/library/diagnostics.js +50 -0
- package/dist/api/library/disk.d.ts +13 -0
- package/dist/api/library/disk.js +66 -0
- package/dist/api/library/enums.generated.d.ts +891 -0
- package/dist/api/library/enums.generated.js +916 -0
- package/dist/api/library/errors.d.ts +13 -0
- package/dist/api/library/errors.js +24 -0
- package/dist/api/library/host.d.ts +24 -0
- package/dist/api/library/host.js +52 -0
- package/dist/api/library/index.d.ts +14 -0
- package/dist/api/library/index.js +15 -0
- package/dist/api/library/nodes.d.ts +51 -0
- package/dist/api/library/nodes.js +196 -0
- package/dist/api/library/options.d.ts +144 -0
- package/dist/api/library/options.js +308 -0
- package/dist/api/library/parse.d.ts +19 -0
- package/dist/api/library/parse.js +41 -0
- package/dist/api/library/program.d.ts +21 -0
- package/dist/api/library/program.js +234 -0
- package/dist/api/library/symbols.d.ts +8 -0
- package/dist/api/library/symbols.js +11 -0
- package/dist/api/library/types.d.ts +313 -0
- package/dist/api/library/types.js +6 -0
- package/package.json +22 -8
- package/src/compiler/ast-utilities.ts +548 -0
- package/src/compiler/ast.ts +12862 -0
- package/src/compiler/astnav.ts +799 -0
- package/src/compiler/binder-utilities.ts +1392 -0
- package/src/compiler/binder.ts +2703 -0
- package/src/compiler/build-info.ts +1197 -0
- package/src/compiler/character-codes.ts +323 -0
- package/src/compiler/checker-calls.ts +2155 -0
- package/src/compiler/checker-classes.ts +706 -0
- package/src/compiler/checker-contextual.ts +1457 -0
- package/src/compiler/checker-declaration-order.ts +438 -0
- package/src/compiler/checker-declarations.ts +1194 -0
- package/src/compiler/checker-declared-types.ts +919 -0
- package/src/compiler/checker-decorators.ts +694 -0
- package/src/compiler/checker-deprecation.ts +359 -0
- package/src/compiler/checker-destructuring.ts +805 -0
- package/src/compiler/checker-elaboration.ts +477 -0
- package/src/compiler/checker-emit-helpers.ts +224 -0
- package/src/compiler/checker-emit-resolver.ts +769 -0
- package/src/compiler/checker-evaluator.ts +243 -0
- package/src/compiler/checker-expressions.ts +1831 -0
- package/src/compiler/checker-features.ts +361 -0
- package/src/compiler/checker-flow.ts +394 -0
- package/src/compiler/checker-functions.ts +1296 -0
- package/src/compiler/checker-generated-code.ts +227 -0
- package/src/compiler/checker-globals.ts +52 -0
- package/src/compiler/checker-grammar.ts +3584 -0
- package/src/compiler/checker-heritage.ts +1233 -0
- package/src/compiler/checker-inference.ts +2576 -0
- package/src/compiler/checker-iteration.ts +1206 -0
- package/src/compiler/checker-javascript.ts +502 -0
- package/src/compiler/checker-jsdoc.ts +360 -0
- package/src/compiler/checker-jsx.ts +1924 -0
- package/src/compiler/checker-literals.ts +61 -0
- package/src/compiler/checker-members.ts +2436 -0
- package/src/compiler/checker-modules.ts +2886 -0
- package/src/compiler/checker-narrowing.ts +3230 -0
- package/src/compiler/checker-object-literals.ts +575 -0
- package/src/compiler/checker-operators.ts +1422 -0
- package/src/compiler/checker-overloads.ts +328 -0
- package/src/compiler/checker-property-access.ts +906 -0
- package/src/compiler/checker-services.ts +1149 -0
- package/src/compiler/checker-signatures.ts +1032 -0
- package/src/compiler/checker-source-file.ts +732 -0
- package/src/compiler/checker-statements.ts +292 -0
- package/src/compiler/checker-super.ts +261 -0
- package/src/compiler/checker-symbol-types.ts +2107 -0
- package/src/compiler/checker-symbols.ts +2150 -0
- package/src/compiler/checker-type-factory.ts +2579 -0
- package/src/compiler/checker-type-nodes.ts +1033 -0
- package/src/compiler/checker-type-operators.ts +2502 -0
- package/src/compiler/checker-types.ts +2340 -0
- package/src/compiler/checker-unused.ts +642 -0
- package/src/compiler/checker-utilities.ts +161 -0
- package/src/compiler/checker.ts +1116 -0
- package/src/compiler/command-line.ts +436 -0
- package/src/compiler/compile-program.ts +439 -0
- package/src/compiler/decoder.ts +1209 -0
- package/src/compiler/diagnostic-locales.ts +86 -0
- package/src/compiler/diagnostic-messages.ts +2349 -0
- package/src/compiler/diagnostics.ts +897 -0
- package/src/compiler/emitter.ts +434 -0
- package/src/compiler/encoder.ts +1945 -0
- package/src/compiler/file-include.ts +673 -0
- package/src/compiler/file-loader.ts +1528 -0
- package/src/compiler/file-system.ts +143 -0
- package/src/compiler/flow.ts +89 -0
- package/src/compiler/help.ts +473 -0
- package/src/compiler/incremental.ts +2784 -0
- package/src/compiler/init.ts +141 -0
- package/src/compiler/instantiation.ts +894 -0
- package/src/compiler/jsdoc.ts +1386 -0
- package/src/compiler/link-tables.ts +98 -0
- package/src/compiler/locale-data.ts +203 -0
- package/src/compiler/locale.ts +307 -0
- package/src/compiler/locales/cs-CZ.ts +5 -0
- package/src/compiler/locales/de-DE.ts +5 -0
- package/src/compiler/locales/es-ES.ts +5 -0
- package/src/compiler/locales/fr-FR.ts +5 -0
- package/src/compiler/locales/it-IT.ts +5 -0
- package/src/compiler/locales/ja-JP.ts +5 -0
- package/src/compiler/locales/ko-KR.ts +5 -0
- package/src/compiler/locales/pl-PL.ts +5 -0
- package/src/compiler/locales/pt-BR.ts +5 -0
- package/src/compiler/locales/ru-RU.ts +5 -0
- package/src/compiler/locales/tr-TR.ts +5 -0
- package/src/compiler/locales/zh-CN.ts +5 -0
- package/src/compiler/locales/zh-TW.ts +5 -0
- package/src/compiler/module-resolution-types.ts +243 -0
- package/src/compiler/module-resolution.ts +2072 -0
- package/src/compiler/module-specifiers.ts +1491 -0
- package/src/compiler/name-resolver.ts +646 -0
- package/src/compiler/node-builder-names.ts +1069 -0
- package/src/compiler/node-builder-pseudo.ts +892 -0
- package/src/compiler/node-builder-reuse.ts +764 -0
- package/src/compiler/node-builder.ts +3425 -0
- package/src/compiler/option-declarations.ts +1560 -0
- package/src/compiler/options.ts +1576 -0
- package/src/compiler/output-paths.ts +334 -0
- package/src/compiler/package-json.ts +1083 -0
- package/src/compiler/parallel-check.ts +1951 -0
- package/src/compiler/parallel-parse.ts +590 -0
- package/src/compiler/parse-thread.ts +140 -0
- package/src/compiler/parser.ts +7716 -0
- package/src/compiler/path.ts +717 -0
- package/src/compiler/printer/async-helpers.ts +183 -0
- package/src/compiler/printer/auto-generate.ts +27 -0
- package/src/compiler/printer/decorator-helpers.ts +218 -0
- package/src/compiler/printer/emit-context.ts +679 -0
- package/src/compiler/printer/emit-flags.ts +64 -0
- package/src/compiler/printer/factory-base.ts +2577 -0
- package/src/compiler/printer/factory.ts +764 -0
- package/src/compiler/printer/helpers.ts +291 -0
- package/src/compiler/printer/name-generator.ts +372 -0
- package/src/compiler/printer/printer.ts +5072 -0
- package/src/compiler/printer/text-writer.ts +183 -0
- package/src/compiler/printer/utilities.ts +884 -0
- package/src/compiler/program-checker.ts +592 -0
- package/src/compiler/program-utilities.ts +435 -0
- package/src/compiler/program.ts +1419 -0
- package/src/compiler/pseudo-bigint.ts +62 -0
- package/src/compiler/regexp-checker.ts +1142 -0
- package/src/compiler/relations.ts +5149 -0
- package/src/compiler/reparser.ts +1566 -0
- package/src/compiler/scanner.ts +2951 -0
- package/src/compiler/show-config.ts +239 -0
- package/src/compiler/side-state.ts +125 -0
- package/src/compiler/sourcemap.ts +366 -0
- package/src/compiler/spelling.ts +122 -0
- package/src/compiler/symbol-accessibility.ts +1071 -0
- package/src/compiler/symbol.ts +439 -0
- package/src/compiler/symlinks.ts +137 -0
- package/src/compiler/syntax-kind.ts +391 -0
- package/src/compiler/thread-entry.ts +191 -0
- package/src/compiler/timeline.ts +53 -0
- package/src/compiler/transformers/alias-references.ts +757 -0
- package/src/compiler/transformers/async-utilities.ts +335 -0
- package/src/compiler/transformers/async.ts +838 -0
- package/src/compiler/transformers/class-fields.ts +2967 -0
- package/src/compiler/transformers/class-utilities.ts +324 -0
- package/src/compiler/transformers/commonjs-module.ts +1621 -0
- package/src/compiler/transformers/const-enum-inliner.ts +50 -0
- package/src/compiler/transformers/declarations-diagnostics.ts +832 -0
- package/src/compiler/transformers/declarations-pseudo.ts +966 -0
- package/src/compiler/transformers/declarations-resolver.ts +249 -0
- package/src/compiler/transformers/declarations-syntactic.ts +1859 -0
- package/src/compiler/transformers/declarations-tracker.ts +269 -0
- package/src/compiler/transformers/declarations.ts +3120 -0
- package/src/compiler/transformers/decorator-metadata.ts +697 -0
- package/src/compiler/transformers/decorator-utilities.ts +283 -0
- package/src/compiler/transformers/destructuring.ts +708 -0
- package/src/compiler/transformers/downlevel.ts +50 -0
- package/src/compiler/transformers/emit-resolver.ts +258 -0
- package/src/compiler/transformers/es-decorators.ts +2682 -0
- package/src/compiler/transformers/exponentiation.ts +80 -0
- package/src/compiler/transformers/external-module-info.ts +412 -0
- package/src/compiler/transformers/for-await.ts +687 -0
- package/src/compiler/transformers/import-elision.ts +152 -0
- package/src/compiler/transformers/jsx-entities.ts +256 -0
- package/src/compiler/transformers/jsx.ts +824 -0
- package/src/compiler/transformers/legacy-decorators.ts +726 -0
- package/src/compiler/transformers/logical-assignment.ts +75 -0
- package/src/compiler/transformers/module-utilities.ts +42 -0
- package/src/compiler/transformers/module.ts +474 -0
- package/src/compiler/transformers/named-evaluation.ts +389 -0
- package/src/compiler/transformers/nullish-coalescing.ts +35 -0
- package/src/compiler/transformers/object-rest-spread.ts +577 -0
- package/src/compiler/transformers/optional-catch.ts +29 -0
- package/src/compiler/transformers/optional-chain.ts +246 -0
- package/src/compiler/transformers/reference-resolver.ts +1201 -0
- package/src/compiler/transformers/runtime-syntax.ts +942 -0
- package/src/compiler/transformers/subtree-facts.ts +245 -0
- package/src/compiler/transformers/syntax-facts.ts +353 -0
- package/src/compiler/transformers/tagged-template.ts +167 -0
- package/src/compiler/transformers/transformer.ts +56 -0
- package/src/compiler/transformers/type-eraser.ts +520 -0
- package/src/compiler/transformers/type-serialization.ts +374 -0
- package/src/compiler/transformers/using.ts +613 -0
- package/src/compiler/transformers/utilities.ts +419 -0
- package/src/compiler/transformers/visitor-base.ts +1601 -0
- package/src/compiler/transformers/visitor-hooks.ts +252 -0
- package/src/compiler/tsc-build.ts +1418 -0
- package/src/compiler/tsc-cli.ts +666 -0
- package/src/compiler/tsc-compile.ts +437 -0
- package/src/compiler/tsc-watch.ts +854 -0
- package/src/compiler/tsconfig.ts +1574 -0
- package/src/compiler/type-printer.ts +110 -0
- package/src/compiler/types.ts +115 -0
- package/src/compiler/unicode-identifiers.ts +212 -0
- package/src/compiler/unicode-properties.ts +537 -0
- package/src/compiler/vfs-match.ts +597 -0
- package/src/compiler/xxh3.ts +650 -0
- package/src/library/ast.generated.ts +1685 -0
- package/src/library/ast.ts +104 -0
- package/src/library/checker.ts +384 -0
- package/src/library/compiler-options.generated.ts +114 -0
- package/src/library/diagnostics.ts +72 -0
- package/src/library/disk.ts +73 -0
- package/src/library/enums.generated.ts +1024 -0
- package/src/library/errors.ts +26 -0
- package/src/library/host.ts +63 -0
- package/src/library/index.ts +71 -0
- package/src/library/nodes.ts +232 -0
- package/src/library/options.ts +449 -0
- package/src/library/parse.ts +63 -0
- package/src/library/program.ts +293 -0
- package/src/library/symbols.ts +15 -0
- package/src/library/types.ts +359 -0
|
@@ -0,0 +1,1136 @@
|
|
|
1
|
+
// Contextual typing: the type an expression's position implies, and contextual signatures.
|
|
2
|
+
import { resolvedReturnTypeOf } from './side-state.js';
|
|
3
|
+
import { getInitializer, getName, getParameters, getType, getText, getSymbol, getTypeParameters, JsxAttribute, JsxElement, } from './ast.js';
|
|
4
|
+
import { getImmediatelyInvokedFunctionExpression, isFunctionExpressionOrArrowFunction, isObjectLiteralMethod, isStatic, } from './binder-utilities.js';
|
|
5
|
+
import { filterType, getIntersectionType, getNumberLiteralType, getRegularTypeOfLiteralType, getUnionType, getUnionTypeEx, getWidenedLiteralType, getEndElementCount, getStringLiteralType, getTypeArguments, getTypeReferenceArity, mapType, mapTypeEx, isTupleType, tupleTargetOf, typesOf, } from './checker-type-factory.js';
|
|
6
|
+
import { combineUnionOrIntersectionMemberSignatures, compareTypeParametersIdentical, findApplicableIndexInfo, getApparentType, getBaseConstraintOrType, getIndexInfosOfStructuredType, getPropertiesOfType, getPropertyOfType, getReducedType, getSignaturesOfType, } from './checker-members.js';
|
|
7
|
+
import { getTypeFromTypeNode } from './checker-type-nodes.js';
|
|
8
|
+
import { getSymbolId } from './symbol.js';
|
|
9
|
+
import { findResolutionCycleStartIndex, getCachedGlobalType, getGlobalType, getSymbolOfDeclaration, } from './checker-symbols.js';
|
|
10
|
+
import { isImportCall } from './ast-utilities.js';
|
|
11
|
+
import { CompositeSignature } from './checker-types.js';
|
|
12
|
+
import { compareSignaturesIdentical } from './relations.js';
|
|
13
|
+
import { cloneSignature, getOrCreateTypeFromSignature, getParameterCount, getReturnTypeFromAnnotation, hasEffectiveRestParameter, } from './checker-signatures.js';
|
|
14
|
+
import { getActualTypeVariable, getConstraintTypeFromMappedType, getElementTypeOfSliceOfTupleType, getFalseTypeFromConditionalType, getLiteralTypeFromPropertyName, getMappedTypeNameTypeKind, getNameTypeFromMappedType, getTrueTypeFromConditionalType, isGenericMappedType, substituteIndexedMappedType, } from './checker-type-operators.js';
|
|
15
|
+
import { getOptionalType, getWidenedType, removeMissingType } from './checker-symbol-types.js';
|
|
16
|
+
import { getConstituentTypeForKeyType, getKeyPropertyName } from './checker-narrowing.js';
|
|
17
|
+
import { getElements, getExpression, getNodeId, getProperties, } from './ast.js';
|
|
18
|
+
import { isDiscriminantProperty, isTypeAssignableTo } from './relations.js';
|
|
19
|
+
import { getPropertyNameFromType, hasDynamicName, hasLateBindableName, isNumericLiteralName, isTypeUsableAsPropertyName, } from './checker-utilities.js';
|
|
20
|
+
import { getReturnTypeOfSignature, getRestTypeAtPosition, getTypeAtPosition, tryGetTypeAtPosition, } from './checker-signatures.js';
|
|
21
|
+
import { checkExpressionCached, checkComputedPropertyName, getPropertyNameOfObjectLiteralElement, getTypeOfExpression, isConstTypeReference, } from './checker-expressions.js';
|
|
22
|
+
import { getEffectiveCallArguments, getRestArgumentsType, resolveCallSignatureForContext } from './checker-calls.js';
|
|
23
|
+
import { checkDeclarationInitializer, checkExpression, checkExpressionEx, isLiteralOfContextualType, } from './checker-expressions.js';
|
|
24
|
+
import { getMapperFromContext, someInferenceHasCandidatesOrDefault, } from './checker-inference.js';
|
|
25
|
+
import { instantiateType, isNodeDescendantOf } from './instantiation.js';
|
|
26
|
+
import { getIndexedAccessTypeEx } from './checker-type-operators.js';
|
|
27
|
+
import { getTypeOfSymbol } from './checker-symbol-types.js';
|
|
28
|
+
import { getNonNullableType } from './checker-flow.js';
|
|
29
|
+
import { maybeTypeOfKind } from './checker-utilities.js';
|
|
30
|
+
import { getFunctionFlags, indexOfNode } from './checker-utilities.js';
|
|
31
|
+
import { getContextualTypeForAssignmentExpression } from './checker-javascript.js';
|
|
32
|
+
import { isContextSensitive } from './checker-functions.js';
|
|
33
|
+
import { checkGeneratorInstantiationAssignabilityToReturnType, createGeneratorType, createPromiseLikeType, getAwaitedTypeNoAlias, getAwaitedTypeOfPromise, getIteratedTypeOrElementType, getIterationTypeOfGeneratorFunctionReturnType, getIterationTypesOfGeneratorFunctionReturnType, } from './checker-iteration.js';
|
|
34
|
+
import { isFunctionLike } from './ast-utilities.js';
|
|
35
|
+
import { getTypeFromBindingPattern } from './checker-destructuring.js';
|
|
36
|
+
import { getContextualJsxElementAttributesType, getContextualTypeForJsxAttribute, getContextualTypeForJsxExpression, getJsxElementChildrenPropertyName, getJsxNamespaceAt, getSemanticJsxChildren, } from './checker-jsx.js';
|
|
37
|
+
import { getDecoratorCallSignature } from './checker-decorators.js';
|
|
38
|
+
// ---- Contextual type and inference context stacks
|
|
39
|
+
export function pushContextualType(c, node, t, isCache) {
|
|
40
|
+
const caches = c.inferenceCaches;
|
|
41
|
+
const depth = caches.contextualDepth;
|
|
42
|
+
if (depth < caches.contextualNodes.length) {
|
|
43
|
+
caches.contextualNodes[depth] = node;
|
|
44
|
+
caches.contextualTypes[depth] = t;
|
|
45
|
+
caches.contextualIsCache[depth] = isCache;
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
caches.contextualNodes.push(node);
|
|
49
|
+
caches.contextualTypes.push(t);
|
|
50
|
+
caches.contextualIsCache.push(isCache);
|
|
51
|
+
}
|
|
52
|
+
caches.contextualDepth = depth + 1;
|
|
53
|
+
}
|
|
54
|
+
/** Caches the contextual type of `node` for the contextual types of its elements. */
|
|
55
|
+
export function pushCachedContextualType(c, node) {
|
|
56
|
+
pushContextualType(c, node, getContextualTypeEx(c, node, 0 /* ContextFlags.None */), true);
|
|
57
|
+
}
|
|
58
|
+
export function popContextualType(c) {
|
|
59
|
+
c.inferenceCaches.contextualDepth--;
|
|
60
|
+
}
|
|
61
|
+
/** The index of the contextual type pushed onto `node`, or -1. */
|
|
62
|
+
export function findContextualNode(c, node, includeCaches) {
|
|
63
|
+
const caches = c.inferenceCaches;
|
|
64
|
+
const nodes = caches.contextualNodes;
|
|
65
|
+
const depth = caches.contextualDepth;
|
|
66
|
+
for (let i = 0; i < depth; i++)
|
|
67
|
+
if (nodes[i] === node && (includeCaches || !caches.contextualIsCache[i]))
|
|
68
|
+
return i;
|
|
69
|
+
return -1;
|
|
70
|
+
}
|
|
71
|
+
export function pushInferenceContext(c, node, context) {
|
|
72
|
+
const caches = c.inferenceCaches;
|
|
73
|
+
const depth = caches.inferenceDepth;
|
|
74
|
+
if (depth < caches.inferenceNodes.length) {
|
|
75
|
+
caches.inferenceNodes[depth] = node;
|
|
76
|
+
caches.inferenceContexts[depth] = context;
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
caches.inferenceNodes.push(node);
|
|
80
|
+
caches.inferenceContexts.push(context);
|
|
81
|
+
}
|
|
82
|
+
caches.inferenceDepth = depth + 1;
|
|
83
|
+
}
|
|
84
|
+
export function popInferenceContext(c) {
|
|
85
|
+
const caches = c.inferenceCaches;
|
|
86
|
+
const depth = caches.inferenceDepth - 1;
|
|
87
|
+
// The context is released when popped; the node slot stays until it is reused.
|
|
88
|
+
caches.inferenceContexts[depth] = undefined;
|
|
89
|
+
caches.inferenceDepth = depth;
|
|
90
|
+
}
|
|
91
|
+
/** The inference context of the innermost call argument containing `node`. */
|
|
92
|
+
export function getInferenceContext(c, node) {
|
|
93
|
+
const caches = c.inferenceCaches;
|
|
94
|
+
for (let i = caches.inferenceDepth - 1; i >= 0; i--)
|
|
95
|
+
if (isNodeDescendantOf(node, caches.inferenceNodes[i]))
|
|
96
|
+
return caches.inferenceContexts[i];
|
|
97
|
+
return undefined;
|
|
98
|
+
}
|
|
99
|
+
/** The node a contextual type for `node` is pushed onto: an element for its attributes, which spans its children. */
|
|
100
|
+
function getContextNode(node) {
|
|
101
|
+
if (node.kind === 293 /* SyntaxKind.JsxAttributes */ && node.parent.kind !== 286 /* SyntaxKind.JsxSelfClosingElement */)
|
|
102
|
+
return node.parent.parent;
|
|
103
|
+
return node;
|
|
104
|
+
}
|
|
105
|
+
/** Checks `node` with `contextualType` as its contextual type, inferring into `inferenceContext`. */
|
|
106
|
+
export function checkExpressionWithContextualType(c, node, contextualType, inferenceContext, checkMode) {
|
|
107
|
+
const contextNode = getContextNode(node);
|
|
108
|
+
pushContextualType(c, contextNode, contextualType, false);
|
|
109
|
+
pushInferenceContext(c, contextNode, inferenceContext);
|
|
110
|
+
let t = checkExpressionEx(c, node, checkMode | 1 /* CheckMode.Contextual */ | (inferenceContext !== undefined ? 2 /* CheckMode.Inferential */ : 0));
|
|
111
|
+
// Intra-expression inference sites only matter during this check.
|
|
112
|
+
if (inferenceContext !== undefined)
|
|
113
|
+
inferenceContext.intraExpressionInferenceSites = [];
|
|
114
|
+
// Contextually typed literals keep their literal types rather than widening during inference.
|
|
115
|
+
if (maybeTypeOfKind(t, 15360 /* TypeFlags.Literal */) &&
|
|
116
|
+
isLiteralOfContextualType(c, t, instantiateContextualType(c, contextualType, node, 0 /* ContextFlags.None */)))
|
|
117
|
+
t = getRegularTypeOfLiteralType(c, t);
|
|
118
|
+
popInferenceContext(c);
|
|
119
|
+
popContextualType(c);
|
|
120
|
+
return t;
|
|
121
|
+
}
|
|
122
|
+
/** `contextualType` instantiated with the inferences made so far for an enclosing call. */
|
|
123
|
+
export function instantiateContextualType(c, contextualType, node, contextFlags) {
|
|
124
|
+
if (contextualType === undefined || !maybeTypeOfKind(contextualType, 132644864 /* TypeFlags.Instantiable */))
|
|
125
|
+
return contextualType;
|
|
126
|
+
const inferenceContext = getInferenceContext(c, node);
|
|
127
|
+
// Without inferences or defaults, instantiation would only substitute constraints.
|
|
128
|
+
if (inferenceContext === undefined)
|
|
129
|
+
return contextualType;
|
|
130
|
+
if ((contextFlags & 1 /* ContextFlags.Signature */) !== 0 &&
|
|
131
|
+
someInferenceHasCandidatesOrDefault(inferenceContext.inferences)) {
|
|
132
|
+
// Contextual signatures use all inferences so far, from return types and earlier arguments.
|
|
133
|
+
const t = instantiateInstantiableTypes(c, contextualType, inferenceContext.nonFixingMapper);
|
|
134
|
+
if ((t.flags & 3 /* TypeFlags.AnyOrUnknown */) === 0)
|
|
135
|
+
return t;
|
|
136
|
+
}
|
|
137
|
+
const returnMapper = inferenceContext.returnMapper;
|
|
138
|
+
if (returnMapper !== undefined) {
|
|
139
|
+
// Otherwise only return type inferences apply, without `boolean` so that contextually typed
|
|
140
|
+
// boolean literals widen.
|
|
141
|
+
const t = instantiateInstantiableTypes(c, contextualType, returnMapper);
|
|
142
|
+
if ((t.flags & 3 /* TypeFlags.AnyOrUnknown */) === 0) {
|
|
143
|
+
if ((t.flags & 134217728 /* TypeFlags.Union */) !== 0 &&
|
|
144
|
+
typesOf(t).includes(c.regularFalseType) &&
|
|
145
|
+
typesOf(t).includes(c.regularTrueType))
|
|
146
|
+
return filterType(c, t, (u) => u !== c.regularFalseType && u !== c.regularTrueType);
|
|
147
|
+
return t;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return contextualType;
|
|
151
|
+
}
|
|
152
|
+
/** Like instantiateType, but only for instantiable types and without reducing unions. */
|
|
153
|
+
function instantiateInstantiableTypes(c, t, mapper) {
|
|
154
|
+
if ((t.flags & 132644864 /* TypeFlags.Instantiable */) !== 0)
|
|
155
|
+
return instantiateType(c, t, mapper);
|
|
156
|
+
if ((t.flags & 402653184 /* TypeFlags.UnionOrIntersection */) === 0)
|
|
157
|
+
return t;
|
|
158
|
+
const types = [];
|
|
159
|
+
for (const u of typesOf(t))
|
|
160
|
+
types.push(instantiateInstantiableTypes(c, u, mapper));
|
|
161
|
+
return (t.flags & 134217728 /* TypeFlags.Union */) !== 0
|
|
162
|
+
? getUnionTypeEx(c, types, 0 /* UnionReduction.None */, undefined, undefined)
|
|
163
|
+
: getIntersectionType(c, types);
|
|
164
|
+
}
|
|
165
|
+
/** The type implied by `node`'s position, if any. */
|
|
166
|
+
export function getContextualType(c, node) {
|
|
167
|
+
return getContextualTypeEx(c, node, 0 /* ContextFlags.None */);
|
|
168
|
+
}
|
|
169
|
+
export function getContextualTypeEx(c, node, contextFlags) {
|
|
170
|
+
// Cached contextual types were obtained without flags.
|
|
171
|
+
const index = findContextualNode(c, node, contextFlags === 0 /* ContextFlags.None */);
|
|
172
|
+
if (index >= 0)
|
|
173
|
+
return c.inferenceCaches.contextualTypes[index];
|
|
174
|
+
const parent = node.parent;
|
|
175
|
+
if (parent === undefined)
|
|
176
|
+
return undefined;
|
|
177
|
+
switch (parent.kind) {
|
|
178
|
+
case 261 /* SyntaxKind.VariableDeclaration */:
|
|
179
|
+
case 170 /* SyntaxKind.Parameter */:
|
|
180
|
+
case 173 /* SyntaxKind.PropertyDeclaration */:
|
|
181
|
+
case 172 /* SyntaxKind.PropertySignature */:
|
|
182
|
+
case 209 /* SyntaxKind.BindingElement */:
|
|
183
|
+
if (getInitializer(parent) !== node)
|
|
184
|
+
return undefined;
|
|
185
|
+
return getContextualTypeForInitializerExpression(c, parent, contextFlags);
|
|
186
|
+
case 220 /* SyntaxKind.ArrowFunction */:
|
|
187
|
+
case 254 /* SyntaxKind.ReturnStatement */:
|
|
188
|
+
return getContextualTypeForReturnExpression(c, node);
|
|
189
|
+
case 230 /* SyntaxKind.YieldExpression */:
|
|
190
|
+
return getContextualTypeForYieldOperand(c, parent, contextFlags);
|
|
191
|
+
case 224 /* SyntaxKind.AwaitExpression */:
|
|
192
|
+
return getContextualTypeForAwaitOperand(c, parent, contextFlags);
|
|
193
|
+
case 214 /* SyntaxKind.CallExpression */:
|
|
194
|
+
case 215 /* SyntaxKind.NewExpression */:
|
|
195
|
+
return getContextualTypeForArgument(c, parent, node);
|
|
196
|
+
case 171 /* SyntaxKind.Decorator */: {
|
|
197
|
+
// A decorator expression is contextually typed by the call the runtime makes.
|
|
198
|
+
const signature = getDecoratorCallSignature(c, parent);
|
|
199
|
+
return signature !== undefined ? getOrCreateTypeFromSignature(c, signature) : undefined;
|
|
200
|
+
}
|
|
201
|
+
case 235 /* SyntaxKind.AsExpression */:
|
|
202
|
+
case 217 /* SyntaxKind.TypeAssertionExpression */: {
|
|
203
|
+
const typeNode = getType(parent);
|
|
204
|
+
return isConstTypeReference(typeNode)
|
|
205
|
+
? getContextualTypeEx(c, parent, contextFlags)
|
|
206
|
+
: getTypeFromTypeNode(c, typeNode);
|
|
207
|
+
}
|
|
208
|
+
case 239 /* SyntaxKind.SatisfiesExpression */:
|
|
209
|
+
return getTypeFromTypeNode(c, getType(parent));
|
|
210
|
+
case 278 /* SyntaxKind.ExportAssignment */: {
|
|
211
|
+
// A JSDoc `@type` on `export default`.
|
|
212
|
+
const typeNode = getType(parent);
|
|
213
|
+
return typeNode !== undefined ? getTypeFromTypeNode(c, typeNode) : undefined;
|
|
214
|
+
}
|
|
215
|
+
case 227 /* SyntaxKind.BinaryExpression */:
|
|
216
|
+
return getContextualTypeForBinaryOperand(c, parent, node, contextFlags);
|
|
217
|
+
case 303 /* SyntaxKind.PropertyAssignment */:
|
|
218
|
+
case 304 /* SyntaxKind.ShorthandPropertyAssignment */:
|
|
219
|
+
// The property's name gets the property's contextual type too.
|
|
220
|
+
return getContextualTypeForObjectLiteralElement(c, parent, contextFlags);
|
|
221
|
+
case 211 /* SyntaxKind.ObjectLiteralExpression */:
|
|
222
|
+
return node.kind === 175 /* SyntaxKind.MethodDeclaration */
|
|
223
|
+
? getContextualTypeForObjectLiteralElement(c, node, contextFlags)
|
|
224
|
+
: undefined;
|
|
225
|
+
case 305 /* SyntaxKind.SpreadAssignment */:
|
|
226
|
+
return getContextualTypeEx(c, parent.parent, contextFlags);
|
|
227
|
+
case 210 /* SyntaxKind.ArrayLiteralExpression */: {
|
|
228
|
+
const elements = parent.elements.nodes;
|
|
229
|
+
const index = indexOfNode(elements, node);
|
|
230
|
+
if (index < 0)
|
|
231
|
+
return undefined;
|
|
232
|
+
const spreads = getSpreadIndices(c, parent, elements);
|
|
233
|
+
return getContextualTypeForElementExpression(c, getApparentTypeOfContextualTypeEx(c, parent, contextFlags), index, elements.length, spreads.first, spreads.last);
|
|
234
|
+
}
|
|
235
|
+
case 228 /* SyntaxKind.ConditionalExpression */: {
|
|
236
|
+
const cond = parent;
|
|
237
|
+
return node === cond.whenTrue || node === cond.whenFalse
|
|
238
|
+
? getContextualTypeEx(c, parent, contextFlags)
|
|
239
|
+
: undefined;
|
|
240
|
+
}
|
|
241
|
+
case 240 /* SyntaxKind.TemplateSpan */: {
|
|
242
|
+
const template = parent.parent;
|
|
243
|
+
return template.parent !== undefined && template.parent.kind === 216 /* SyntaxKind.TaggedTemplateExpression */
|
|
244
|
+
? getContextualTypeForArgument(c, template.parent, node)
|
|
245
|
+
: undefined;
|
|
246
|
+
}
|
|
247
|
+
case 218 /* SyntaxKind.ParenthesizedExpression */:
|
|
248
|
+
case 236 /* SyntaxKind.NonNullExpression */:
|
|
249
|
+
return getContextualTypeEx(c, parent, contextFlags);
|
|
250
|
+
case 295 /* SyntaxKind.JsxExpression */:
|
|
251
|
+
return getContextualTypeForJsxExpression(c, parent, contextFlags);
|
|
252
|
+
case 292 /* SyntaxKind.JsxAttribute */:
|
|
253
|
+
case 294 /* SyntaxKind.JsxSpreadAttribute */:
|
|
254
|
+
return getContextualTypeForJsxAttribute(c, parent, contextFlags);
|
|
255
|
+
case 287 /* SyntaxKind.JsxOpeningElement */:
|
|
256
|
+
case 286 /* SyntaxKind.JsxSelfClosingElement */:
|
|
257
|
+
return getContextualJsxElementAttributesType(c, parent, contextFlags);
|
|
258
|
+
}
|
|
259
|
+
return undefined;
|
|
260
|
+
}
|
|
261
|
+
function getContextualTypeForInitializerExpression(c, declaration, contextFlags) {
|
|
262
|
+
const result = getContextualTypeForInitializer(c, declaration, contextFlags);
|
|
263
|
+
if (result !== undefined)
|
|
264
|
+
return result;
|
|
265
|
+
// A binding pattern implies a type, such as a tuple for an array pattern.
|
|
266
|
+
const name = getName(declaration);
|
|
267
|
+
if ((contextFlags & 8 /* ContextFlags.SkipBindingPatterns */) === 0 &&
|
|
268
|
+
name !== undefined &&
|
|
269
|
+
(name.kind === 207 /* SyntaxKind.ObjectBindingPattern */ || name.kind === 208 /* SyntaxKind.ArrayBindingPattern */) &&
|
|
270
|
+
getElements(name).nodes.length > 0)
|
|
271
|
+
return getTypeFromBindingPattern(c, name, true, false);
|
|
272
|
+
return undefined;
|
|
273
|
+
}
|
|
274
|
+
function getContextualTypeForInitializer(c, declaration, contextFlags) {
|
|
275
|
+
const typeNode = getType(declaration);
|
|
276
|
+
if (typeNode !== undefined)
|
|
277
|
+
return getTypeFromTypeNode(c, typeNode);
|
|
278
|
+
if (declaration.kind === 170 /* SyntaxKind.Parameter */)
|
|
279
|
+
return getContextuallyTypedParameterTypeOrUndefined(c, declaration);
|
|
280
|
+
if (declaration.kind === 209 /* SyntaxKind.BindingElement */)
|
|
281
|
+
return getContextualTypeForBindingElement(c, declaration);
|
|
282
|
+
// A static property of a class expression takes the type of the same property of the class's contextual type.
|
|
283
|
+
if (declaration.kind === 173 /* SyntaxKind.PropertyDeclaration */ &&
|
|
284
|
+
isStatic(declaration) &&
|
|
285
|
+
declaration.parent.kind === 232 /* SyntaxKind.ClassExpression */) {
|
|
286
|
+
const parentType = getContextualTypeEx(c, declaration.parent, contextFlags);
|
|
287
|
+
const symbol = getSymbolOfDeclaration(c, declaration);
|
|
288
|
+
if (parentType !== undefined && symbol !== undefined)
|
|
289
|
+
return getTypeOfPropertyOfContextualType(c, parentType, symbol.name);
|
|
290
|
+
}
|
|
291
|
+
return undefined;
|
|
292
|
+
}
|
|
293
|
+
/** The type of the property or element a binding element destructures from its parent's contextual type. */
|
|
294
|
+
function getContextualTypeForBindingElement(c, declaration) {
|
|
295
|
+
const element = declaration;
|
|
296
|
+
const name = element.propertyName ?? element.name;
|
|
297
|
+
if (name === undefined ||
|
|
298
|
+
name.kind === 207 /* SyntaxKind.ObjectBindingPattern */ ||
|
|
299
|
+
name.kind === 208 /* SyntaxKind.ArrayBindingPattern */ ||
|
|
300
|
+
(name.kind === 168 /* SyntaxKind.ComputedPropertyName */ && !isLiteralComputedName(name)))
|
|
301
|
+
return undefined;
|
|
302
|
+
const parent = declaration.parent.parent;
|
|
303
|
+
let parentType = getContextualTypeForInitializer(c, parent, 0 /* ContextFlags.None */);
|
|
304
|
+
if (parentType === undefined && parent.kind !== 209 /* SyntaxKind.BindingElement */ && getInitializer(parent) !== undefined)
|
|
305
|
+
parentType = checkDeclarationInitializer(c, parent, element.dotDotDotToken !== undefined ? 32 /* CheckMode.RestBindingElement */ : 0 /* CheckMode.Normal */);
|
|
306
|
+
if (parentType === undefined)
|
|
307
|
+
return undefined;
|
|
308
|
+
const parentName = getName(parent);
|
|
309
|
+
if (parentName.kind === 208 /* SyntaxKind.ArrayBindingPattern */) {
|
|
310
|
+
const index = getElements(parentName).nodes.indexOf(declaration);
|
|
311
|
+
if (index < 0)
|
|
312
|
+
return undefined;
|
|
313
|
+
return getContextualTypeForElementExpression(c, parentType, index, -1, -1, -1);
|
|
314
|
+
}
|
|
315
|
+
const nameType = getLiteralTypeFromPropertyName(c, name);
|
|
316
|
+
if (nameType === undefined || !isTypeUsableAsPropertyName(nameType))
|
|
317
|
+
return undefined;
|
|
318
|
+
const prop = getPropertyOfType(c, parentType, getPropertyNameFromType(nameType));
|
|
319
|
+
return prop !== undefined ? getTypeOfSymbol(c, prop) : undefined;
|
|
320
|
+
}
|
|
321
|
+
function isLiteralComputedName(name) {
|
|
322
|
+
const expression = getExpression(name);
|
|
323
|
+
return expression.kind === 10 /* SyntaxKind.StringLiteral */ || expression.kind === 8 /* SyntaxKind.NumericLiteral */;
|
|
324
|
+
}
|
|
325
|
+
function getContainingFunction(node) {
|
|
326
|
+
let current = node.parent;
|
|
327
|
+
while (current !== undefined && !isFunctionLike(current))
|
|
328
|
+
current = current.parent;
|
|
329
|
+
return current;
|
|
330
|
+
}
|
|
331
|
+
function getContextualTypeForReturnExpression(c, node) {
|
|
332
|
+
const func = getContainingFunction(node);
|
|
333
|
+
if (func === undefined)
|
|
334
|
+
return undefined;
|
|
335
|
+
let contextualReturnType = getContextualReturnType(c, func);
|
|
336
|
+
if (contextualReturnType === undefined)
|
|
337
|
+
return undefined;
|
|
338
|
+
const functionFlags = getFunctionFlags(func);
|
|
339
|
+
const isAsync = (functionFlags & 2 /* FunctionFlags.Async */) !== 0;
|
|
340
|
+
if ((functionFlags & 1 /* FunctionFlags.Generator */) !== 0) {
|
|
341
|
+
if ((contextualReturnType.flags & 134217728 /* TypeFlags.Union */) !== 0)
|
|
342
|
+
contextualReturnType = filterType(c, contextualReturnType, (t) => getIterationTypeOfGeneratorFunctionReturnType(c, 1 /* IterationTypeKind.Return */, t, isAsync) !== undefined);
|
|
343
|
+
const iterationReturnType = getIterationTypeOfGeneratorFunctionReturnType(c, 1 /* IterationTypeKind.Return */, contextualReturnType, isAsync);
|
|
344
|
+
if (iterationReturnType === undefined)
|
|
345
|
+
return undefined;
|
|
346
|
+
// Async generators also unwrap the promise below.
|
|
347
|
+
contextualReturnType = iterationReturnType;
|
|
348
|
+
}
|
|
349
|
+
if (isAsync) {
|
|
350
|
+
// The awaited type without the `Awaited<T>` alias.
|
|
351
|
+
const contextualAwaitedType = mapType(c, contextualReturnType, (t) => getAwaitedTypeNoAlias(c, t));
|
|
352
|
+
return getUnionType(c, [contextualAwaitedType, createPromiseLikeType(c, contextualAwaitedType)]);
|
|
353
|
+
}
|
|
354
|
+
return contextualReturnType;
|
|
355
|
+
}
|
|
356
|
+
function getContextualTypeForYieldOperand(c, node, contextFlags) {
|
|
357
|
+
const func = getContainingFunction(node);
|
|
358
|
+
if (func === undefined)
|
|
359
|
+
return undefined;
|
|
360
|
+
const functionFlags = getFunctionFlags(func);
|
|
361
|
+
let contextualReturnType = getContextualReturnType(c, func);
|
|
362
|
+
if (contextualReturnType === undefined)
|
|
363
|
+
return undefined;
|
|
364
|
+
const isAsyncGenerator = (functionFlags & 2 /* FunctionFlags.Async */) !== 0;
|
|
365
|
+
const isYieldStar = node.asteriskToken !== undefined;
|
|
366
|
+
if (!isYieldStar && (contextualReturnType.flags & 134217728 /* TypeFlags.Union */) !== 0)
|
|
367
|
+
contextualReturnType = filterType(c, contextualReturnType, (t) => getIterationTypeOfGeneratorFunctionReturnType(c, 1 /* IterationTypeKind.Return */, t, isAsyncGenerator) !== undefined);
|
|
368
|
+
if (isYieldStar) {
|
|
369
|
+
const iterationTypes = getIterationTypesOfGeneratorFunctionReturnType(c, contextualReturnType, isAsyncGenerator);
|
|
370
|
+
const yieldType = iterationTypes.yieldType ?? c.silentNeverType;
|
|
371
|
+
const returnType = getContextualTypeEx(c, node, contextFlags) ?? c.silentNeverType;
|
|
372
|
+
const nextType = iterationTypes.nextType ?? c.unknownType;
|
|
373
|
+
const generatorType = createGeneratorType(c, yieldType, returnType, nextType, false);
|
|
374
|
+
if (!isAsyncGenerator)
|
|
375
|
+
return generatorType;
|
|
376
|
+
return getUnionType(c, [generatorType, createGeneratorType(c, yieldType, returnType, nextType, true)]);
|
|
377
|
+
}
|
|
378
|
+
return getIterationTypeOfGeneratorFunctionReturnType(c, 0 /* IterationTypeKind.Yield */, contextualReturnType, isAsyncGenerator);
|
|
379
|
+
}
|
|
380
|
+
function getContextualTypeForAwaitOperand(c, node, contextFlags) {
|
|
381
|
+
const contextualType = getContextualTypeEx(c, node, contextFlags);
|
|
382
|
+
if (contextualType === undefined)
|
|
383
|
+
return undefined;
|
|
384
|
+
const contextualAwaitedType = getAwaitedTypeNoAlias(c, contextualType);
|
|
385
|
+
if (contextualAwaitedType === undefined)
|
|
386
|
+
return undefined;
|
|
387
|
+
return getUnionType(c, [contextualAwaitedType, createPromiseLikeType(c, contextualAwaitedType)]);
|
|
388
|
+
}
|
|
389
|
+
/** The iteration type of `kind` a generator's contextual return type implies. */
|
|
390
|
+
export function getContextualIterationType(c, kind, func) {
|
|
391
|
+
const contextualReturnType = getContextualReturnType(c, func);
|
|
392
|
+
if (contextualReturnType === undefined)
|
|
393
|
+
return undefined;
|
|
394
|
+
return getIterationTypeOfGeneratorFunctionReturnType(c, kind, contextualReturnType, (getFunctionFlags(func) & 2 /* FunctionFlags.Async */) !== 0);
|
|
395
|
+
}
|
|
396
|
+
/** The return type a function's annotation or contextual signature implies. */
|
|
397
|
+
export function getContextualReturnType(c, func) {
|
|
398
|
+
// A return type annotation, a constructor's class, a getter's annotated setter or a JSDoc `@type`.
|
|
399
|
+
const annotated = getReturnTypeFromAnnotation(c, func);
|
|
400
|
+
if (annotated !== undefined)
|
|
401
|
+
return annotated;
|
|
402
|
+
const signature = getContextualSignatureForFunctionLikeDeclaration(c, func);
|
|
403
|
+
if (signature !== undefined && !isResolvingReturnTypeOfSignature(c, signature)) {
|
|
404
|
+
const returnType = getReturnTypeOfSignature(c, signature);
|
|
405
|
+
const functionFlags = getFunctionFlags(func);
|
|
406
|
+
if ((functionFlags & 1 /* FunctionFlags.Generator */) !== 0)
|
|
407
|
+
return filterType(c, returnType, (t) => (t.flags & (3 /* TypeFlags.AnyOrUnknown */ | 16 /* TypeFlags.Void */ | 117964800 /* TypeFlags.InstantiableNonPrimitive */)) !== 0 ||
|
|
408
|
+
checkGeneratorInstantiationAssignabilityToReturnType(c, t, functionFlags, undefined));
|
|
409
|
+
if ((functionFlags & 2 /* FunctionFlags.Async */) !== 0)
|
|
410
|
+
return filterType(c, returnType, (t) => (t.flags & (3 /* TypeFlags.AnyOrUnknown */ | 16 /* TypeFlags.Void */ | 117964800 /* TypeFlags.InstantiableNonPrimitive */)) !== 0 ||
|
|
411
|
+
getAwaitedTypeOfPromise(c, t) !== undefined);
|
|
412
|
+
return returnType;
|
|
413
|
+
}
|
|
414
|
+
const iife = getImmediatelyInvokedFunctionExpression(func);
|
|
415
|
+
return iife !== undefined ? getContextualType(c, iife) : undefined;
|
|
416
|
+
}
|
|
417
|
+
function isResolvingReturnTypeOfSignature(c, signature) {
|
|
418
|
+
const composite = signature.composite;
|
|
419
|
+
if (composite !== undefined)
|
|
420
|
+
for (const s of composite.signatures)
|
|
421
|
+
if (isResolvingReturnTypeOfSignature(c, s))
|
|
422
|
+
return true;
|
|
423
|
+
return (resolvedReturnTypeOf(c, signature) === undefined &&
|
|
424
|
+
findResolutionCycleStartIndex(c, signature, 3 /* TypeSystemPropertyName.ResolvedReturnType */) >= 0);
|
|
425
|
+
}
|
|
426
|
+
function getContextualTypeForArgument(c, call, arg) {
|
|
427
|
+
const index = getEffectiveCallArguments(c, call).indexOf(arg);
|
|
428
|
+
// -1 for the callee.
|
|
429
|
+
if (index < 0)
|
|
430
|
+
return undefined;
|
|
431
|
+
return getContextualTypeForArgumentAtIndex(c, call, index);
|
|
432
|
+
}
|
|
433
|
+
export function getContextualTypeForArgumentAtIndex(c, call, argIndex) {
|
|
434
|
+
// `import(specifier, options)`.
|
|
435
|
+
if (isImportCall(call))
|
|
436
|
+
return argIndex === 0
|
|
437
|
+
? c.stringType
|
|
438
|
+
: argIndex === 1
|
|
439
|
+
? getCachedGlobalType(c, 'ImportCallOptions', 0, false)
|
|
440
|
+
: c.anyType;
|
|
441
|
+
// While resolving the call's signature, arguments get the resolving signature's `any`.
|
|
442
|
+
const signature = resolveCallSignatureForContext(c, call);
|
|
443
|
+
const restIndex = signature.parameters.length - 1;
|
|
444
|
+
if (signature.hasRestParameter() && argIndex >= restIndex)
|
|
445
|
+
return getIndexedAccessTypeEx(c, getTypeOfSymbol(c, signature.parameters[restIndex]), getNumberLiteralType(c, argIndex - restIndex), 256 /* AccessFlags.Contextual */, undefined, undefined);
|
|
446
|
+
return getTypeAtPosition(c, signature, argIndex);
|
|
447
|
+
}
|
|
448
|
+
/**
|
|
449
|
+
* The contextual type of element `index` of an array literal of `length` elements (or -1 when
|
|
450
|
+
* unknown) in `t`, given the indices of the literal's first and last spreads (or -1).
|
|
451
|
+
*/
|
|
452
|
+
export function getContextualTypeForElementExpression(c, t, index, length, firstSpreadIndex, lastSpreadIndex) {
|
|
453
|
+
if (t === undefined)
|
|
454
|
+
return undefined;
|
|
455
|
+
return mapTypeEx(c, t, (u) => {
|
|
456
|
+
if (isTupleType(u)) {
|
|
457
|
+
const target = tupleTargetOf(u);
|
|
458
|
+
// Before any spread and within the fixed part: the tuple element.
|
|
459
|
+
if ((firstSpreadIndex < 0 || index < firstSpreadIndex) && index < target.fixedLength)
|
|
460
|
+
return removeMissingType(c, getTypeArguments(c, u)[index], (target.elementInfos[index].flags & 2 /* ElementFlags.Optional */) !== 0);
|
|
461
|
+
// With a known length and the index after all spreads, count from the end.
|
|
462
|
+
const offset = length >= 0 && (lastSpreadIndex < 0 || index > lastSpreadIndex) ? length - index : 0;
|
|
463
|
+
const fixedEndLength = offset > 0 && (target.combinedFlags & 12 /* ElementFlags.Variable */) !== 0
|
|
464
|
+
? getEndElementCount(target, 3 /* ElementFlags.Fixed */)
|
|
465
|
+
: 0;
|
|
466
|
+
if (offset > 0 && offset <= fixedEndLength)
|
|
467
|
+
return getTypeArguments(c, u)[getTypeReferenceArity(u) - offset];
|
|
468
|
+
// Otherwise the union of the possible element types, without subtype reduction.
|
|
469
|
+
const tupleIndex = firstSpreadIndex >= 0 ? Math.min(target.fixedLength, firstSpreadIndex) : target.fixedLength;
|
|
470
|
+
const endSkipCount = length >= 0 && lastSpreadIndex >= 0 ? Math.min(fixedEndLength, length - lastSpreadIndex) : fixedEndLength;
|
|
471
|
+
return getElementTypeOfSliceOfTupleType(c, u, tupleIndex, endSkipCount, false, true);
|
|
472
|
+
}
|
|
473
|
+
// A contextual property named by the index, else the iterated or element type.
|
|
474
|
+
if (firstSpreadIndex < 0 || index < firstSpreadIndex) {
|
|
475
|
+
const propType = getTypeOfPropertyOfContextualType(c, u, String(index));
|
|
476
|
+
if (propType !== undefined)
|
|
477
|
+
return propType;
|
|
478
|
+
}
|
|
479
|
+
return getIteratedTypeOrElementTypeForContext(c, u);
|
|
480
|
+
}, true);
|
|
481
|
+
}
|
|
482
|
+
function getIteratedTypeOrElementTypeForContext(c, t) {
|
|
483
|
+
return getIteratedTypeOrElementType(c, 1 /* IterationUse.Element */, t, c.undefinedType, undefined, false);
|
|
484
|
+
}
|
|
485
|
+
/** The indices of the first and last spread elements of an array literal, or -1. */
|
|
486
|
+
export class SpreadIndices {
|
|
487
|
+
first;
|
|
488
|
+
last;
|
|
489
|
+
constructor(first, last) {
|
|
490
|
+
this.first = first;
|
|
491
|
+
this.last = last;
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
function getSpreadIndices(c, node, elements) {
|
|
495
|
+
const cached = c.spreadIndices.get(node);
|
|
496
|
+
if (cached !== undefined)
|
|
497
|
+
return cached;
|
|
498
|
+
let first = -1;
|
|
499
|
+
let last = -1;
|
|
500
|
+
for (let i = 0; i < elements.length; i++)
|
|
501
|
+
if (elements[i].kind === 231 /* SyntaxKind.SpreadElement */) {
|
|
502
|
+
if (first < 0)
|
|
503
|
+
first = i;
|
|
504
|
+
last = i;
|
|
505
|
+
}
|
|
506
|
+
const result = new SpreadIndices(first, last);
|
|
507
|
+
c.spreadIndices.set(node, result);
|
|
508
|
+
return result;
|
|
509
|
+
}
|
|
510
|
+
function getContextualTypeForObjectLiteralElement(c, element, contextFlags) {
|
|
511
|
+
// A JSDoc `@type` on the property.
|
|
512
|
+
const typeNode = getType(element);
|
|
513
|
+
if (typeNode !== undefined && !isObjectLiteralMethod(element))
|
|
514
|
+
return getTypeFromTypeNode(c, typeNode);
|
|
515
|
+
const objectLiteral = element.parent;
|
|
516
|
+
const t = getApparentTypeOfContextualTypeEx(c, objectLiteral, contextFlags);
|
|
517
|
+
if (t === undefined)
|
|
518
|
+
return undefined;
|
|
519
|
+
const isDynamic = hasDynamicName(element);
|
|
520
|
+
if (!isDynamic || hasLateBindableName(c, element)) {
|
|
521
|
+
const name = getPropertyNameOfObjectLiteralElement(c, element);
|
|
522
|
+
if (name !== undefined) {
|
|
523
|
+
const symbol = getSymbol(element);
|
|
524
|
+
let nameType = symbol !== undefined ? c.symbolNameTypes.get(getSymbolId(symbol)) : undefined;
|
|
525
|
+
// Late-bound members are named by the type of their computed name, like a unique symbol.
|
|
526
|
+
const nameNode = getName(element);
|
|
527
|
+
if (nameType === undefined && nameNode.kind === 168 /* SyntaxKind.ComputedPropertyName */)
|
|
528
|
+
nameType = checkComputedPropertyName(c, nameNode);
|
|
529
|
+
return getTypeOfPropertyOfContextualTypeEx(c, t, name, nameType);
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
else {
|
|
533
|
+
// Other computed names are checked again, uncached.
|
|
534
|
+
const exprType = checkExpression(c, getExpression(getName(element)));
|
|
535
|
+
if (isTypeUsableAsPropertyName(exprType)) {
|
|
536
|
+
const propType = getTypeOfPropertyOfContextualType(c, t, getPropertyNameFromType(exprType));
|
|
537
|
+
if (propType !== undefined)
|
|
538
|
+
return propType;
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
const nameNode = getName(element);
|
|
542
|
+
if (nameNode === undefined)
|
|
543
|
+
return undefined;
|
|
544
|
+
const nameType = getLiteralTypeFromPropertyName(c, nameNode);
|
|
545
|
+
if (nameType === undefined)
|
|
546
|
+
return undefined;
|
|
547
|
+
// Avoids getApplicableIndexInfo's potentially expensive intersection reduction.
|
|
548
|
+
return mapTypeEx(c, t, (u) => {
|
|
549
|
+
const info = findApplicableIndexInfo(c, getIndexInfosOfStructuredType(c, u), nameType);
|
|
550
|
+
return info !== undefined ? info.valueType : undefined;
|
|
551
|
+
}, true);
|
|
552
|
+
}
|
|
553
|
+
/** The type of property `name` in a contextual type, through unions, intersections, mapped types and index signatures. */
|
|
554
|
+
export function getTypeOfPropertyOfContextualType(c, t, name) {
|
|
555
|
+
return getTypeOfPropertyOfContextualTypeEx(c, t, name, undefined);
|
|
556
|
+
}
|
|
557
|
+
function getTypeOfPropertyOfContextualTypeEx(c, t, name, nameType) {
|
|
558
|
+
// Most contextual types are not unions: map them without a closure (as mapTypeEx would).
|
|
559
|
+
if ((t.flags & 134217728 /* TypeFlags.Union */) === 0)
|
|
560
|
+
return (t.flags & 262144 /* TypeFlags.Never */) !== 0 ? t : getTypeOfPropertyOfContextualConstituent(c, t, name, nameType);
|
|
561
|
+
return mapTypeEx(c, t, (u) => getTypeOfPropertyOfContextualConstituent(c, u, name, nameType), true);
|
|
562
|
+
}
|
|
563
|
+
function getTypeOfPropertyOfContextualConstituent(c, u, name, nameType) {
|
|
564
|
+
if ((u.flags & 268435456 /* TypeFlags.Intersection */) !== 0) {
|
|
565
|
+
let types = [];
|
|
566
|
+
let indexInfoCandidates = [];
|
|
567
|
+
let ignoreIndexInfos = false;
|
|
568
|
+
for (const constituent of typesOf(u)) {
|
|
569
|
+
if ((constituent.flags & 1048576 /* TypeFlags.Object */) === 0)
|
|
570
|
+
continue;
|
|
571
|
+
if (isGenericMappedType(c, constituent) &&
|
|
572
|
+
getMappedTypeNameTypeKind(c, constituent) !== 2 /* MappedTypeNameTypeKind.Remapping */) {
|
|
573
|
+
types = appendContextualPropertyTypeConstituent(c, types, getIndexedMappedTypeSubstitutedTypeOfContextualType(c, constituent, name, nameType));
|
|
574
|
+
continue;
|
|
575
|
+
}
|
|
576
|
+
const propertyType = getTypeOfConcretePropertyOfContextualType(c, constituent, name);
|
|
577
|
+
if (propertyType === undefined) {
|
|
578
|
+
if (!ignoreIndexInfos)
|
|
579
|
+
indexInfoCandidates.push(constituent);
|
|
580
|
+
continue;
|
|
581
|
+
}
|
|
582
|
+
ignoreIndexInfos = true;
|
|
583
|
+
indexInfoCandidates = [];
|
|
584
|
+
types = appendContextualPropertyTypeConstituent(c, types, propertyType);
|
|
585
|
+
}
|
|
586
|
+
for (const candidate of indexInfoCandidates)
|
|
587
|
+
types = appendContextualPropertyTypeConstituent(c, types, getTypeFromIndexInfosOfContextualType(c, candidate, name, nameType));
|
|
588
|
+
if (types.length === 0)
|
|
589
|
+
return undefined;
|
|
590
|
+
return types.length === 1 ? types[0] : getIntersectionType(c, types);
|
|
591
|
+
}
|
|
592
|
+
if ((u.flags & 1048576 /* TypeFlags.Object */) === 0)
|
|
593
|
+
return undefined;
|
|
594
|
+
if (isGenericMappedType(c, u) && getMappedTypeNameTypeKind(c, u) !== 2 /* MappedTypeNameTypeKind.Remapping */)
|
|
595
|
+
return getIndexedMappedTypeSubstitutedTypeOfContextualType(c, u, name, nameType);
|
|
596
|
+
return (getTypeOfConcretePropertyOfContextualType(c, u, name) ?? getTypeFromIndexInfosOfContextualType(c, u, name, nameType));
|
|
597
|
+
}
|
|
598
|
+
function getIndexedMappedTypeSubstitutedTypeOfContextualType(c, t, name, nameType) {
|
|
599
|
+
const propertyNameType = nameType ?? getStringLiteralType(c, name);
|
|
600
|
+
const constraint = getConstraintTypeFromMappedType(c, t);
|
|
601
|
+
// Conditional types pretending to be negated types.
|
|
602
|
+
const mappedNameType = getNameTypeFromMappedType(c, t);
|
|
603
|
+
if ((mappedNameType !== undefined && isExcludedMappedPropertyName(c, mappedNameType, propertyNameType)) ||
|
|
604
|
+
isExcludedMappedPropertyName(c, constraint, propertyNameType))
|
|
605
|
+
return undefined;
|
|
606
|
+
if (!isTypeAssignableTo(c, propertyNameType, getBaseConstraintOrType(c, constraint)))
|
|
607
|
+
return undefined;
|
|
608
|
+
return substituteIndexedMappedType(c, t, propertyNameType);
|
|
609
|
+
}
|
|
610
|
+
function isExcludedMappedPropertyName(c, t, propertyNameType) {
|
|
611
|
+
if ((t.flags & 67108864 /* TypeFlags.Conditional */) !== 0) {
|
|
612
|
+
const conditional = t;
|
|
613
|
+
return ((getReducedType(c, getTrueTypeFromConditionalType(c, conditional)).flags & 262144 /* TypeFlags.Never */) !== 0 &&
|
|
614
|
+
getActualTypeVariable(c, getFalseTypeFromConditionalType(c, conditional)) ===
|
|
615
|
+
getActualTypeVariable(c, conditional.checkType) &&
|
|
616
|
+
isTypeAssignableTo(c, propertyNameType, conditional.extendsType));
|
|
617
|
+
}
|
|
618
|
+
if ((t.flags & 268435456 /* TypeFlags.Intersection */) !== 0)
|
|
619
|
+
for (const u of typesOf(t))
|
|
620
|
+
if (isExcludedMappedPropertyName(c, u, propertyNameType))
|
|
621
|
+
return true;
|
|
622
|
+
return false;
|
|
623
|
+
}
|
|
624
|
+
function getTypeOfConcretePropertyOfContextualType(c, t, name) {
|
|
625
|
+
const prop = getPropertyOfType(c, t, name);
|
|
626
|
+
if (prop === undefined || isCircularMappedProperty(c, prop))
|
|
627
|
+
return undefined;
|
|
628
|
+
return removeMissingType(c, getTypeOfSymbol(c, prop), (prop.flags & 16777216 /* SymbolFlags.Optional */) !== 0);
|
|
629
|
+
}
|
|
630
|
+
/** Whether the type of a mapped type property is being resolved. */
|
|
631
|
+
function isCircularMappedProperty(c, symbol) {
|
|
632
|
+
return ((symbol.checkFlags & 262144 /* CheckFlags.Mapped */) !== 0 &&
|
|
633
|
+
c.symbolTypes.get(getSymbolId(symbol)) === undefined &&
|
|
634
|
+
findResolutionCycleStartIndex(c, symbol, 0 /* TypeSystemPropertyName.Type */) >= 0);
|
|
635
|
+
}
|
|
636
|
+
function getTypeFromIndexInfosOfContextualType(c, t, name, nameType) {
|
|
637
|
+
if (isTupleType(t) && isNumericLiteralName(name) && Number(name) >= 0) {
|
|
638
|
+
const restType = getElementTypeOfSliceOfTupleType(c, t, tupleTargetOf(t).fixedLength, 0, false, true);
|
|
639
|
+
if (restType !== undefined)
|
|
640
|
+
return restType;
|
|
641
|
+
}
|
|
642
|
+
const info = findApplicableIndexInfo(c, getIndexInfosOfStructuredType(c, t), nameType ?? getStringLiteralType(c, name));
|
|
643
|
+
return info !== undefined ? info.valueType : undefined;
|
|
644
|
+
}
|
|
645
|
+
/** `any` gives no contextual information and would spoil other constituents, so it becomes `unknown`. */
|
|
646
|
+
function appendContextualPropertyTypeConstituent(c, types, t) {
|
|
647
|
+
if (t === undefined)
|
|
648
|
+
return types;
|
|
649
|
+
types.push((t.flags & 1 /* TypeFlags.Any */) !== 0 ? c.unknownType : t);
|
|
650
|
+
return types;
|
|
651
|
+
}
|
|
652
|
+
function getContextualTypeForBinaryOperand(c, binary, node, contextFlags) {
|
|
653
|
+
// A JSDoc type on a JavaScript assignment.
|
|
654
|
+
if (binary.type !== undefined)
|
|
655
|
+
return getTypeFromTypeNode(c, binary.type);
|
|
656
|
+
const op = binary.operatorToken.kind;
|
|
657
|
+
switch (op) {
|
|
658
|
+
case 63 /* SyntaxKind.EqualsToken */:
|
|
659
|
+
case 76 /* SyntaxKind.AmpersandAmpersandEqualsToken */:
|
|
660
|
+
case 75 /* SyntaxKind.BarBarEqualsToken */:
|
|
661
|
+
case 77 /* SyntaxKind.QuestionQuestionEqualsToken */:
|
|
662
|
+
if (node !== binary.right)
|
|
663
|
+
return undefined;
|
|
664
|
+
return getContextualTypeForAssignmentExpression(c, binary);
|
|
665
|
+
case 56 /* SyntaxKind.BarBarToken */:
|
|
666
|
+
case 60 /* SyntaxKind.QuestionQuestionToken */: {
|
|
667
|
+
const t = getContextualTypeEx(c, binary, contextFlags);
|
|
668
|
+
// A contextual type implied by a binding pattern gives way to the left operand's type.
|
|
669
|
+
return node === binary.right && (t === undefined || c.patternForType.has(t))
|
|
670
|
+
? getTypeOfExpression(c, binary.left)
|
|
671
|
+
: t;
|
|
672
|
+
}
|
|
673
|
+
case 55 /* SyntaxKind.AmpersandAmpersandToken */:
|
|
674
|
+
case 27 /* SyntaxKind.CommaToken */:
|
|
675
|
+
return node === binary.right ? getContextualTypeEx(c, binary, contextFlags) : undefined;
|
|
676
|
+
}
|
|
677
|
+
return undefined;
|
|
678
|
+
}
|
|
679
|
+
/** The apparent form of `node`'s contextual type. */
|
|
680
|
+
export function getApparentTypeOfContextualType(c, node) {
|
|
681
|
+
return getApparentTypeOfContextualTypeEx(c, node, 0 /* ContextFlags.None */);
|
|
682
|
+
}
|
|
683
|
+
export function getApparentTypeOfContextualTypeEx(c, node, contextFlags) {
|
|
684
|
+
const contextualType = isObjectLiteralMethod(node)
|
|
685
|
+
? getContextualTypeForObjectLiteralElement(c, node, contextFlags)
|
|
686
|
+
: getContextualTypeEx(c, node, contextFlags);
|
|
687
|
+
const t = instantiateContextualType(c, contextualType, node, contextFlags);
|
|
688
|
+
if (t === undefined)
|
|
689
|
+
return undefined;
|
|
690
|
+
if ((contextFlags & 2 /* ContextFlags.NoConstraints */) !== 0 && (t.flags & 34078720 /* TypeFlags.TypeVariable */) !== 0)
|
|
691
|
+
return undefined;
|
|
692
|
+
// Most contextual types are not unions: map them without a closure (as mapTypeEx would).
|
|
693
|
+
const apparentType = (t.flags & 134217728 /* TypeFlags.Union */) === 0
|
|
694
|
+
? (t.flags & 262144 /* TypeFlags.Never */) !== 0 || (t.objectFlags & 32 /* ObjectFlags.Mapped */) !== 0
|
|
695
|
+
? t
|
|
696
|
+
: getApparentType(c, t)
|
|
697
|
+
: mapTypeEx(c, t, (u) => ((u.objectFlags & 32 /* ObjectFlags.Mapped */) !== 0 ? u : getApparentType(c, u)), true);
|
|
698
|
+
if (apparentType === undefined)
|
|
699
|
+
return undefined;
|
|
700
|
+
if ((apparentType.flags & 134217728 /* TypeFlags.Union */) !== 0 && node.kind === 211 /* SyntaxKind.ObjectLiteralExpression */)
|
|
701
|
+
return discriminateContextualTypeByObjectMembers(c, node, apparentType);
|
|
702
|
+
if ((apparentType.flags & 134217728 /* TypeFlags.Union */) !== 0 && node.kind === 293 /* SyntaxKind.JsxAttributes */)
|
|
703
|
+
return discriminateContextualTypeByJSXAttributes(c, node, apparentType);
|
|
704
|
+
return apparentType;
|
|
705
|
+
}
|
|
706
|
+
/** Node ids below this and type ids below `PairTypeIdLimit` pack into one exact number. */
|
|
707
|
+
const PairNodeIdLimit = 1 << 29;
|
|
708
|
+
const PairTypeIdLimit = 1 << 24;
|
|
709
|
+
function getDiscriminatedContextualType(c, nodeId, t) {
|
|
710
|
+
const caches = c.inferenceCaches;
|
|
711
|
+
return nodeId < PairNodeIdLimit && t.id < PairTypeIdLimit
|
|
712
|
+
? caches.discriminatedContextualTypesById.get(nodeId * PairTypeIdLimit + t.id)
|
|
713
|
+
: caches.discriminatedContextualTypes.get(nodeId + ',' + t.id);
|
|
714
|
+
}
|
|
715
|
+
function setDiscriminatedContextualType(c, nodeId, t, value) {
|
|
716
|
+
const caches = c.inferenceCaches;
|
|
717
|
+
if (nodeId < PairNodeIdLimit && t.id < PairTypeIdLimit)
|
|
718
|
+
caches.discriminatedContextualTypesById.set(nodeId * PairTypeIdLimit + t.id, value);
|
|
719
|
+
else
|
|
720
|
+
caches.discriminatedContextualTypes.set(nodeId + ',' + t.id, value);
|
|
721
|
+
}
|
|
722
|
+
/** The constituents of a union contextual type an object literal's discriminant members select. */
|
|
723
|
+
function discriminateContextualTypeByObjectMembers(c, node, contextualType) {
|
|
724
|
+
const nodeId = getNodeId(node);
|
|
725
|
+
const cached = getDiscriminatedContextualType(c, nodeId, contextualType);
|
|
726
|
+
if (cached !== undefined)
|
|
727
|
+
return cached;
|
|
728
|
+
let discriminated = getMatchingUnionConstituentForObjectLiteral(c, contextualType, node);
|
|
729
|
+
if (discriminated === undefined) {
|
|
730
|
+
const props = [];
|
|
731
|
+
for (const p of getProperties(node).nodes) {
|
|
732
|
+
const symbol = getSymbol(p);
|
|
733
|
+
if (symbol === undefined)
|
|
734
|
+
continue;
|
|
735
|
+
if ((p.kind === 303 /* SyntaxKind.PropertyAssignment */ &&
|
|
736
|
+
isPossiblyDiscriminantValue(p.initializer) &&
|
|
737
|
+
isDiscriminantProperty(c, contextualType, symbol.name)) ||
|
|
738
|
+
(p.kind === 304 /* SyntaxKind.ShorthandPropertyAssignment */ && isDiscriminantProperty(c, contextualType, symbol.name)))
|
|
739
|
+
props.push(p);
|
|
740
|
+
}
|
|
741
|
+
const nodeSymbol = getSymbol(node);
|
|
742
|
+
const members = getPropertiesOfType(c, contextualType).filter((s) => (s.flags & 16777216 /* SymbolFlags.Optional */) !== 0 &&
|
|
743
|
+
nodeSymbol !== undefined &&
|
|
744
|
+
(nodeSymbol.members === undefined || !nodeSymbol.members.has(s.name)) &&
|
|
745
|
+
isDiscriminantProperty(c, contextualType, s.name));
|
|
746
|
+
discriminated = discriminateTypeByObjectLiteral(c, contextualType, props, members);
|
|
747
|
+
}
|
|
748
|
+
setDiscriminatedContextualType(c, nodeId, contextualType, discriminated);
|
|
749
|
+
return discriminated;
|
|
750
|
+
}
|
|
751
|
+
function discriminateContextualTypeByJSXAttributes(c, node, contextualType) {
|
|
752
|
+
const nodeId = getNodeId(node);
|
|
753
|
+
const cached = getDiscriminatedContextualType(c, nodeId, contextualType);
|
|
754
|
+
if (cached !== undefined)
|
|
755
|
+
return cached;
|
|
756
|
+
const childrenPropertyName = getJsxElementChildrenPropertyName(c, getJsxNamespaceAt(c, node));
|
|
757
|
+
const props = [];
|
|
758
|
+
for (const p of getProperties(node).nodes) {
|
|
759
|
+
const symbol = getSymbol(p);
|
|
760
|
+
if (symbol === undefined || !(p instanceof JsxAttribute))
|
|
761
|
+
continue;
|
|
762
|
+
const initializer = p.initializer;
|
|
763
|
+
if ((initializer === undefined || isPossiblyDiscriminantValue(initializer)) &&
|
|
764
|
+
isDiscriminantProperty(c, contextualType, symbol.name))
|
|
765
|
+
props.push(p);
|
|
766
|
+
}
|
|
767
|
+
const nodeSymbol = getSymbol(node);
|
|
768
|
+
const element = node.parent.parent;
|
|
769
|
+
const members = getPropertiesOfType(c, contextualType).filter((s) => {
|
|
770
|
+
if ((s.flags & 16777216 /* SymbolFlags.Optional */) === 0 || nodeSymbol === undefined)
|
|
771
|
+
return false;
|
|
772
|
+
// Children given in the body aren't missing.
|
|
773
|
+
if (s.name === childrenPropertyName &&
|
|
774
|
+
element instanceof JsxElement &&
|
|
775
|
+
getSemanticJsxChildren(element.children.nodes).length !== 0)
|
|
776
|
+
return false;
|
|
777
|
+
return ((nodeSymbol.members === undefined || !nodeSymbol.members.has(s.name)) &&
|
|
778
|
+
isDiscriminantProperty(c, contextualType, s.name));
|
|
779
|
+
});
|
|
780
|
+
const discriminated = discriminateTypeByObjectLiteral(c, contextualType, props, members);
|
|
781
|
+
setDiscriminatedContextualType(c, nodeId, contextualType, discriminated);
|
|
782
|
+
return discriminated;
|
|
783
|
+
}
|
|
784
|
+
function getMatchingUnionConstituentForObjectLiteral(c, unionType, node) {
|
|
785
|
+
const keyPropertyName = getKeyPropertyName(c, unionType);
|
|
786
|
+
if (keyPropertyName === '')
|
|
787
|
+
return undefined;
|
|
788
|
+
let propNode;
|
|
789
|
+
for (const p of getProperties(node).nodes) {
|
|
790
|
+
const symbol = getSymbol(p);
|
|
791
|
+
if (symbol !== undefined &&
|
|
792
|
+
p.kind === 303 /* SyntaxKind.PropertyAssignment */ &&
|
|
793
|
+
symbol.name === keyPropertyName &&
|
|
794
|
+
isPossiblyDiscriminantValue(p.initializer)) {
|
|
795
|
+
propNode = p;
|
|
796
|
+
break;
|
|
797
|
+
}
|
|
798
|
+
}
|
|
799
|
+
if (propNode === undefined)
|
|
800
|
+
return undefined;
|
|
801
|
+
return getConstituentTypeForKeyType(c, unionType, getContextFreeTypeOfExpression(c, propNode.initializer));
|
|
802
|
+
}
|
|
803
|
+
/** Whether `node` may be a discriminant value without depending on its contextual type. */
|
|
804
|
+
function isPossiblyDiscriminantValue(node) {
|
|
805
|
+
switch (node.kind) {
|
|
806
|
+
case 10 /* SyntaxKind.StringLiteral */:
|
|
807
|
+
case 8 /* SyntaxKind.NumericLiteral */:
|
|
808
|
+
case 9 /* SyntaxKind.BigIntLiteral */:
|
|
809
|
+
case 14 /* SyntaxKind.NoSubstitutionTemplateLiteral */:
|
|
810
|
+
case 229 /* SyntaxKind.TemplateExpression */:
|
|
811
|
+
case 111 /* SyntaxKind.TrueKeyword */:
|
|
812
|
+
case 96 /* SyntaxKind.FalseKeyword */:
|
|
813
|
+
case 105 /* SyntaxKind.NullKeyword */:
|
|
814
|
+
case 79 /* SyntaxKind.Identifier */:
|
|
815
|
+
case 157 /* SyntaxKind.UndefinedKeyword */:
|
|
816
|
+
return true;
|
|
817
|
+
case 212 /* SyntaxKind.PropertyAccessExpression */:
|
|
818
|
+
case 218 /* SyntaxKind.ParenthesizedExpression */:
|
|
819
|
+
return isPossiblyDiscriminantValue(getExpression(node));
|
|
820
|
+
case 295 /* SyntaxKind.JsxExpression */: {
|
|
821
|
+
const expression = getExpression(node);
|
|
822
|
+
return expression === undefined || isPossiblyDiscriminantValue(expression);
|
|
823
|
+
}
|
|
824
|
+
}
|
|
825
|
+
return false;
|
|
826
|
+
}
|
|
827
|
+
/** The type of `node` checked without a contextual type, cached. */
|
|
828
|
+
export function getContextFreeTypeOfExpression(c, node) {
|
|
829
|
+
const cache = c.inferenceCaches.contextFreeTypes;
|
|
830
|
+
const cached = cache.get(node);
|
|
831
|
+
if (cached !== undefined)
|
|
832
|
+
return cached;
|
|
833
|
+
pushContextualType(c, node, c.anyType, false);
|
|
834
|
+
const t = checkExpressionEx(c, node, 4 /* CheckMode.SkipContextSensitive */);
|
|
835
|
+
cache.set(node, t);
|
|
836
|
+
popContextualType(c);
|
|
837
|
+
return t;
|
|
838
|
+
}
|
|
839
|
+
function discriminateTypeByObjectLiteral(c, target, props, members) {
|
|
840
|
+
const types = target.types;
|
|
841
|
+
const include = [];
|
|
842
|
+
for (const t of types)
|
|
843
|
+
include.push((t.flags & 12713980 /* TypeFlags.Primitive */) === 0 && (getReducedType(c, t).flags & 262144 /* TypeFlags.Never */) === 0
|
|
844
|
+
? -1 /* Ternary.True */
|
|
845
|
+
: 0 /* Ternary.False */);
|
|
846
|
+
const count = props.length + members.length;
|
|
847
|
+
// Whether `undefined` (a missing property) matches a constituent's property depends only on the
|
|
848
|
+
// union and the name: it is remembered for each constituent, two bits each.
|
|
849
|
+
let missingStates = undefined;
|
|
850
|
+
if (members.length !== 0 && types.length <= 16) {
|
|
851
|
+
missingStates = c.inferenceCaches.missingPropertyStates.get(target);
|
|
852
|
+
if (missingStates === undefined) {
|
|
853
|
+
missingStates = new Map();
|
|
854
|
+
c.inferenceCaches.missingPropertyStates.set(target, missingStates);
|
|
855
|
+
}
|
|
856
|
+
}
|
|
857
|
+
for (let n = 0; n < count; n++) {
|
|
858
|
+
// Eliminate non-matching constituents only if some constituent matches.
|
|
859
|
+
let matched = false;
|
|
860
|
+
if (n >= props.length && missingStates !== undefined) {
|
|
861
|
+
const name = members[n - props.length].name;
|
|
862
|
+
let states = missingStates.get(name) ?? 0;
|
|
863
|
+
for (let i = 0; i < types.length; i++) {
|
|
864
|
+
if (include[i] === 0 /* Ternary.False */)
|
|
865
|
+
continue;
|
|
866
|
+
let state = (states >>> (i * 2)) & 3;
|
|
867
|
+
if (state === 0 /* MissingPropertyState.Unknown */) {
|
|
868
|
+
const targetType = getTypeOfPropertyOrIndexSignatureOfType(c, types[i], name);
|
|
869
|
+
state =
|
|
870
|
+
targetType === undefined
|
|
871
|
+
? 1 /* MissingPropertyState.Absent */
|
|
872
|
+
: discriminantMatches(c, props, n, targetType)
|
|
873
|
+
? 2 /* MissingPropertyState.Matches */
|
|
874
|
+
: 3 /* MissingPropertyState.Mismatches */;
|
|
875
|
+
states |= state << (i * 2);
|
|
876
|
+
}
|
|
877
|
+
if (state === 2 /* MissingPropertyState.Matches */)
|
|
878
|
+
matched = true;
|
|
879
|
+
else if (state === 3 /* MissingPropertyState.Mismatches */)
|
|
880
|
+
include[i] = 3 /* Ternary.Maybe */;
|
|
881
|
+
}
|
|
882
|
+
missingStates.set(name, states);
|
|
883
|
+
}
|
|
884
|
+
else {
|
|
885
|
+
const name = n < props.length ? getSymbol(props[n]).name : members[n - props.length].name;
|
|
886
|
+
for (let i = 0; i < types.length; i++) {
|
|
887
|
+
if (include[i] === 0 /* Ternary.False */)
|
|
888
|
+
continue;
|
|
889
|
+
const targetType = getTypeOfPropertyOrIndexSignatureOfType(c, types[i], name);
|
|
890
|
+
if (targetType === undefined)
|
|
891
|
+
continue;
|
|
892
|
+
if (discriminantMatches(c, props, n, targetType))
|
|
893
|
+
matched = true;
|
|
894
|
+
else
|
|
895
|
+
include[i] = 3 /* Ternary.Maybe */;
|
|
896
|
+
}
|
|
897
|
+
}
|
|
898
|
+
for (let i = 0; i < types.length; i++)
|
|
899
|
+
if (include[i] === 3 /* Ternary.Maybe */)
|
|
900
|
+
include[i] = matched ? 0 /* Ternary.False */ : -1 /* Ternary.True */;
|
|
901
|
+
}
|
|
902
|
+
if (!include.includes(0 /* Ternary.False */))
|
|
903
|
+
return target;
|
|
904
|
+
const filteredTypes = [];
|
|
905
|
+
for (let i = 0; i < types.length; i++)
|
|
906
|
+
if (include[i] === -1 /* Ternary.True */)
|
|
907
|
+
filteredTypes.push(types[i]);
|
|
908
|
+
const filtered = getUnionTypeEx(c, filteredTypes, 0 /* UnionReduction.None */, undefined, undefined);
|
|
909
|
+
return (filtered.flags & 262144 /* TypeFlags.Never */) === 0 ? filtered : target;
|
|
910
|
+
}
|
|
911
|
+
function discriminantMatches(c, props, index, t) {
|
|
912
|
+
let propType;
|
|
913
|
+
if (index < props.length) {
|
|
914
|
+
const prop = props[index];
|
|
915
|
+
if (prop.kind === 303 /* SyntaxKind.PropertyAssignment */)
|
|
916
|
+
propType = getContextFreeTypeOfExpression(c, prop.initializer);
|
|
917
|
+
else if (prop instanceof JsxAttribute)
|
|
918
|
+
// An attribute without an initializer is `true`.
|
|
919
|
+
propType = prop.initializer !== undefined ? getContextFreeTypeOfExpression(c, prop.initializer) : c.trueType;
|
|
920
|
+
else
|
|
921
|
+
propType = getContextFreeTypeOfExpression(c, getName(prop));
|
|
922
|
+
}
|
|
923
|
+
else
|
|
924
|
+
propType = c.undefinedType;
|
|
925
|
+
const sources = (propType.flags & 134217728 /* TypeFlags.Union */) !== 0 ? typesOf(propType) : [propType];
|
|
926
|
+
for (const s of sources) {
|
|
927
|
+
// A type is assignable to a union it is a constituent of, such as `undefined` to the type of
|
|
928
|
+
// an optional property; most discriminants checked are missing optional properties.
|
|
929
|
+
if ((t.flags & 134217728 /* TypeFlags.Union */) !== 0 && typesOf(t).includes(s))
|
|
930
|
+
return true;
|
|
931
|
+
if (isTypeAssignableTo(c, s, t))
|
|
932
|
+
return true;
|
|
933
|
+
}
|
|
934
|
+
return false;
|
|
935
|
+
}
|
|
936
|
+
function getTypeOfPropertyOrIndexSignatureOfType(c, t, name) {
|
|
937
|
+
const prop = getPropertyOfType(c, t, name);
|
|
938
|
+
if (prop !== undefined)
|
|
939
|
+
return getTypeOfSymbol(c, prop);
|
|
940
|
+
const info = findApplicableIndexInfo(c, getIndexInfosOfStructuredType(c, t), getStringLiteralType(c, name));
|
|
941
|
+
return info !== undefined ? getOptionalType(c, info.valueType, true) : undefined;
|
|
942
|
+
}
|
|
943
|
+
/** Whether `node` is a function, arrow or object literal method whose parameters may get types from context. */
|
|
944
|
+
export function isContextSensitiveFunctionOrObjectLiteralMethod(c, func) {
|
|
945
|
+
return ((isFunctionExpressionOrArrowFunction(func) || isObjectLiteralMethod(func)) &&
|
|
946
|
+
isContextSensitiveFunctionLikeDeclaration(c, func));
|
|
947
|
+
}
|
|
948
|
+
export function isContextSensitiveFunctionLikeDeclaration(c, func) {
|
|
949
|
+
return isContextSensitive(c, func);
|
|
950
|
+
}
|
|
951
|
+
/** Whether a function has parameters, or an implicit `this`, that take types from context. */
|
|
952
|
+
export function hasContextSensitiveParameters(func) {
|
|
953
|
+
// Functions with type parameters are not context sensitive.
|
|
954
|
+
if (getTypeParameters(func) !== undefined)
|
|
955
|
+
return false;
|
|
956
|
+
const params = getParameters(func).nodes;
|
|
957
|
+
for (const p of params)
|
|
958
|
+
if (getType(p) === undefined)
|
|
959
|
+
return true;
|
|
960
|
+
if (func.kind !== 220 /* SyntaxKind.ArrowFunction */) {
|
|
961
|
+
// Without an explicit `this` parameter, the implicit one is contextually typed.
|
|
962
|
+
if (params.length === 0 || !isThisParameter(params[0]))
|
|
963
|
+
return (func.flags & 128 /* NodeFlags.ContainsThis */) !== 0;
|
|
964
|
+
}
|
|
965
|
+
return false;
|
|
966
|
+
}
|
|
967
|
+
/** The contextual signature of a function expression, arrow or object literal method. */
|
|
968
|
+
export function getContextualSignatureForFunctionLikeDeclaration(c, func) {
|
|
969
|
+
if (!isFunctionExpressionOrArrowFunction(func) && !isObjectLiteralMethod(func))
|
|
970
|
+
return undefined;
|
|
971
|
+
return getContextualSignature(c, func);
|
|
972
|
+
}
|
|
973
|
+
/**
|
|
974
|
+
* The contextual signature of a function: the single call signature of its contextual type, or of
|
|
975
|
+
* each union constituent when they're identical ignoring return types.
|
|
976
|
+
*/
|
|
977
|
+
export function getContextualSignature(c, node) {
|
|
978
|
+
const t = getApparentTypeOfContextualTypeEx(c, node, 1 /* ContextFlags.Signature */);
|
|
979
|
+
if (t === undefined)
|
|
980
|
+
return undefined;
|
|
981
|
+
if ((t.flags & 134217728 /* TypeFlags.Union */) === 0)
|
|
982
|
+
return getContextualCallSignature(c, t, node);
|
|
983
|
+
const signatureList = [];
|
|
984
|
+
for (const current of typesOf(t)) {
|
|
985
|
+
const signature = getContextualCallSignature(c, current, node);
|
|
986
|
+
if (signature === undefined)
|
|
987
|
+
continue;
|
|
988
|
+
if (signatureList.length !== 0 &&
|
|
989
|
+
compareSignaturesIdentical(c, signatureList[0], signature, false, true, true, 0 /* ComparerKind.Identical */) ===
|
|
990
|
+
0 /* Ternary.False */)
|
|
991
|
+
return undefined;
|
|
992
|
+
signatureList.push(signature);
|
|
993
|
+
}
|
|
994
|
+
if (signatureList.length === 0)
|
|
995
|
+
return undefined;
|
|
996
|
+
if (signatureList.length === 1)
|
|
997
|
+
return signatureList[0];
|
|
998
|
+
// The union of the signatures, with the union of their return types.
|
|
999
|
+
const result = cloneSignature(c, signatureList[0]);
|
|
1000
|
+
result.composite = new CompositeSignature(true, signatureList);
|
|
1001
|
+
result.target = undefined;
|
|
1002
|
+
result.mapper = undefined;
|
|
1003
|
+
return result;
|
|
1004
|
+
}
|
|
1005
|
+
/** The single call signature of `t` with at least as many parameters as `node`. */
|
|
1006
|
+
export function getContextualCallSignature(c, t, node) {
|
|
1007
|
+
const signatures = getSignaturesOfType(c, t, 0 /* SignatureKind.Call */);
|
|
1008
|
+
const applicableByArity = [];
|
|
1009
|
+
for (const s of signatures)
|
|
1010
|
+
if (!isAritySmaller(c, s, node))
|
|
1011
|
+
applicableByArity.push(s);
|
|
1012
|
+
return applicableByArity.length === 1 ? applicableByArity[0] : getIntersectedSignatures(c, applicableByArity);
|
|
1013
|
+
}
|
|
1014
|
+
/** Signatures with identical type parameters combined into one, under noImplicitAny. */
|
|
1015
|
+
function getIntersectedSignatures(c, signatures) {
|
|
1016
|
+
if (!c.noImplicitAny)
|
|
1017
|
+
return undefined;
|
|
1018
|
+
let combined = undefined;
|
|
1019
|
+
for (const sig of signatures) {
|
|
1020
|
+
if (combined === undefined || combined === sig)
|
|
1021
|
+
combined = sig;
|
|
1022
|
+
else if (compareTypeParametersIdentical(c, combined.typeParameters, sig.typeParameters))
|
|
1023
|
+
combined = combineUnionOrIntersectionMemberSignatures(c, combined, sig, false);
|
|
1024
|
+
else
|
|
1025
|
+
return undefined;
|
|
1026
|
+
}
|
|
1027
|
+
return combined;
|
|
1028
|
+
}
|
|
1029
|
+
function isAritySmaller(c, signature, target) {
|
|
1030
|
+
const parameters = getParameters(target).nodes;
|
|
1031
|
+
let targetParameterCount = 0;
|
|
1032
|
+
while (targetParameterCount < parameters.length) {
|
|
1033
|
+
const param = parameters[targetParameterCount];
|
|
1034
|
+
if (param.initializer !== undefined || param.questionToken !== undefined || param.dotDotDotToken !== undefined)
|
|
1035
|
+
break;
|
|
1036
|
+
targetParameterCount++;
|
|
1037
|
+
}
|
|
1038
|
+
if (parameters.length !== 0 && isThisParameter(parameters[0]))
|
|
1039
|
+
targetParameterCount--;
|
|
1040
|
+
return !hasEffectiveRestParameter(c, signature) && getParameterCount(c, signature) < targetParameterCount;
|
|
1041
|
+
}
|
|
1042
|
+
function isThisParameter(node) {
|
|
1043
|
+
const name = getName(node);
|
|
1044
|
+
return name !== undefined && name.kind === 79 /* SyntaxKind.Identifier */ && getText(name) === 'this';
|
|
1045
|
+
}
|
|
1046
|
+
function getContextuallyTypedParameterTypeOrUndefined(c, parameter) {
|
|
1047
|
+
const func = parameter.parent;
|
|
1048
|
+
if (!isContextSensitiveFunctionOrObjectLiteralMethod(c, func))
|
|
1049
|
+
return undefined;
|
|
1050
|
+
const iife = getImmediatelyInvokedFunctionExpression(func);
|
|
1051
|
+
if (iife !== undefined) {
|
|
1052
|
+
// Parameters of an immediately invoked function take the types of the arguments.
|
|
1053
|
+
const args = getEffectiveCallArguments(c, iife);
|
|
1054
|
+
const indexOfParameter = getParameters(func).nodes.indexOf(parameter);
|
|
1055
|
+
if (parameter.dotDotDotToken !== undefined)
|
|
1056
|
+
return getRestArgumentsType(c, iife, args, indexOfParameter);
|
|
1057
|
+
const cached = c.resolvedSignatures.get(iife.id);
|
|
1058
|
+
c.resolvedSignatures.set(iife.id, c.anySignature);
|
|
1059
|
+
const t = indexOfParameter < args.length
|
|
1060
|
+
? getWidenedLiteralType(c, checkExpression(c, args[indexOfParameter]))
|
|
1061
|
+
: getInitializer(parameter) !== undefined
|
|
1062
|
+
? undefined
|
|
1063
|
+
: c.undefinedWideningType;
|
|
1064
|
+
c.resolvedSignatures.set(iife.id, cached);
|
|
1065
|
+
return t;
|
|
1066
|
+
}
|
|
1067
|
+
const signature = getContextualSignatureForFunctionLikeDeclaration(c, func);
|
|
1068
|
+
if (signature === undefined)
|
|
1069
|
+
return undefined;
|
|
1070
|
+
const params = getParameters(func).nodes;
|
|
1071
|
+
let index = params.indexOf(parameter);
|
|
1072
|
+
if (params.length > 0) {
|
|
1073
|
+
const first = getName(params[0]);
|
|
1074
|
+
if (first !== undefined && first.kind === 79 /* SyntaxKind.Identifier */ && getText(first) === 'this')
|
|
1075
|
+
index--;
|
|
1076
|
+
}
|
|
1077
|
+
if (parameter.dotDotDotToken !== undefined && index === params.length - 1)
|
|
1078
|
+
return getRestTypeAtPosition(c, signature, index, false);
|
|
1079
|
+
return tryGetTypeAtPosition(c, signature, index);
|
|
1080
|
+
}
|
|
1081
|
+
/** The type a parameter of a context-sensitive function gets from its contextual signature. */
|
|
1082
|
+
export function getContextuallyTypedParameterType(c, parameter) {
|
|
1083
|
+
return getContextuallyTypedParameterTypeOrUndefined(c, parameter);
|
|
1084
|
+
}
|
|
1085
|
+
/** The contextual type of an intra-expression inference site. */
|
|
1086
|
+
export function getContextualTypeForInference(c, node) {
|
|
1087
|
+
return node.kind === 175 /* SyntaxKind.MethodDeclaration */
|
|
1088
|
+
? getContextualTypeForObjectLiteralElement(c, node, 2 /* ContextFlags.NoConstraints */)
|
|
1089
|
+
: getContextualTypeEx(c, node, 2 /* ContextFlags.NoConstraints */);
|
|
1090
|
+
}
|
|
1091
|
+
// ---- `this` in object literals
|
|
1092
|
+
/**
|
|
1093
|
+
* `this` in a method of an object literal: the `T` of a contextual `ThisType<T>` of the literal or
|
|
1094
|
+
* an enclosing one, else the literal's contextual type or its own type.
|
|
1095
|
+
*/
|
|
1096
|
+
export function getThisTypeOfObjectLiteralMember(c, literal) {
|
|
1097
|
+
const contextualType = getApparentTypeOfContextualTypeEx(c, literal, 0 /* ContextFlags.None */);
|
|
1098
|
+
const thisType = getThisTypeOfObjectLiteralFromContextualType(c, literal, contextualType);
|
|
1099
|
+
if (thisType !== undefined) {
|
|
1100
|
+
const mapper = getMapperFromContext(getInferenceContext(c, literal));
|
|
1101
|
+
return mapper !== undefined ? instantiateType(c, thisType, mapper) : thisType;
|
|
1102
|
+
}
|
|
1103
|
+
return getWidenedType(c, contextualType !== undefined ? getNonNullableType(c, contextualType) : checkExpressionCached(c, literal));
|
|
1104
|
+
}
|
|
1105
|
+
function getThisTypeOfObjectLiteralFromContextualType(c, containingLiteral, contextualType) {
|
|
1106
|
+
let literal = containingLiteral;
|
|
1107
|
+
let t = contextualType;
|
|
1108
|
+
while (t !== undefined) {
|
|
1109
|
+
const thisType = getThisTypeFromContextualType(c, t);
|
|
1110
|
+
if (thisType !== undefined)
|
|
1111
|
+
return thisType;
|
|
1112
|
+
if (literal.parent.kind !== 303 /* SyntaxKind.PropertyAssignment */)
|
|
1113
|
+
break;
|
|
1114
|
+
literal = literal.parent.parent;
|
|
1115
|
+
t = getApparentTypeOfContextualTypeEx(c, literal, 0 /* ContextFlags.None */);
|
|
1116
|
+
}
|
|
1117
|
+
return undefined;
|
|
1118
|
+
}
|
|
1119
|
+
function getThisTypeFromContextualType(c, t) {
|
|
1120
|
+
return mapTypeEx(c, t, (u) => {
|
|
1121
|
+
if ((u.flags & 268435456 /* TypeFlags.Intersection */) === 0)
|
|
1122
|
+
return getThisTypeArgument(c, u);
|
|
1123
|
+
for (const v of typesOf(u)) {
|
|
1124
|
+
const typeArgument = getThisTypeArgument(c, v);
|
|
1125
|
+
if (typeArgument !== undefined)
|
|
1126
|
+
return typeArgument;
|
|
1127
|
+
}
|
|
1128
|
+
return undefined;
|
|
1129
|
+
}, false);
|
|
1130
|
+
}
|
|
1131
|
+
function getThisTypeArgument(c, t) {
|
|
1132
|
+
if ((t.objectFlags & 4 /* ObjectFlags.Reference */) === 0)
|
|
1133
|
+
return undefined;
|
|
1134
|
+
const globalThisType = getGlobalType(c, 'ThisType', 1, false);
|
|
1135
|
+
return t.target === globalThisType ? getTypeArguments(c, t)[0] : undefined;
|
|
1136
|
+
}
|