tsc-ts 0.0.4 → 0.0.6
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 +34 -2
- 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 +2351 -0
- package/dist/api/compiler/ast.js +11212 -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 +1241 -0
- package/dist/api/compiler/binder.d.ts +33 -0
- package/dist/api/compiler/binder.js +2359 -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 +1641 -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 +357 -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 +788 -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 +314 -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 +291 -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 +580 -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 +2587 -0
- package/dist/api/compiler/checker-heritage.d.ts +28 -0
- package/dist/api/compiler/checker-heritage.js +901 -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 +442 -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 +200 -0
- package/dist/api/compiler/checker-members.js +2148 -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 +483 -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 +271 -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 +789 -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 +51 -0
- package/dist/api/compiler/checker-symbol-types.js +955 -0
- package/dist/api/compiler/checker-symbols.d.ts +181 -0
- package/dist/api/compiler/checker-symbols.js +1784 -0
- package/dist/api/compiler/checker-type-factory.d.ts +142 -0
- package/dist/api/compiler/checker-type-factory.js +2542 -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 +1093 -0
- package/dist/api/compiler/checker-types.js +1874 -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 +512 -0
- package/dist/api/compiler/checker.js +932 -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 +161 -0
- package/dist/api/compiler/diagnostics.js +784 -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 +144 -0
- package/dist/api/compiler/file-include.js +599 -0
- package/dist/api/compiler/file-loader.d.ts +290 -0
- package/dist/api/compiler/file-loader.js +1323 -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 +835 -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 +105 -0
- package/dist/api/compiler/link-tables.js +319 -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 +745 -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 +221 -0
- package/dist/api/compiler/parallel-parse.js +541 -0
- package/dist/api/compiler/parser.d.ts +604 -0
- package/dist/api/compiler/parser.js +6426 -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 +157 -0
- package/dist/api/compiler/printer/emit-context.js +582 -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 +529 -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 +1019 -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 +991 -0
- package/dist/api/compiler/symbol.d.ts +282 -0
- package/dist/api/compiler/symbol.js +339 -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 +677 -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 +539 -0
- package/dist/api/compiler/transformers/declarations-pseudo.d.ts +160 -0
- package/dist/api/compiler/transformers/declarations-pseudo.js +799 -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 +198 -0
- package/dist/api/compiler/transformers/declarations.d.ts +175 -0
- package/dist/api/compiler/transformers/declarations.js +2381 -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 +129 -0
- package/dist/api/compiler/transformers/reference-resolver.js +1157 -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 +10 -0
- package/dist/api/compiler/transformers/subtree-facts.js +205 -0
- package/dist/api/compiler/transformers/syntax-facts.d.ts +52 -0
- package/dist/api/compiler/transformers/syntax-facts.js +258 -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 +3 -2
- package/dist/api/library/ast.generated.d.ts +127 -139
- package/dist/api/library/checker.d.ts +51 -0
- package/dist/api/library/checker.js +318 -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/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 +5 -1
- package/dist/api/library/index.js +4 -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/types.d.ts +14 -1
- package/package.json +12 -8
- package/src/compiler/ast-utilities.ts +548 -0
- package/src/compiler/ast.ts +12870 -0
- package/src/compiler/astnav.ts +799 -0
- package/src/compiler/binder-utilities.ts +1392 -0
- package/src/compiler/binder.ts +2707 -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 +1201 -0
- package/src/compiler/checker-declared-types.ts +919 -0
- package/src/compiler/checker-decorators.ts +694 -0
- package/src/compiler/checker-deprecation.ts +355 -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 +3596 -0
- package/src/compiler/checker-heritage.ts +1240 -0
- package/src/compiler/checker-inference.ts +2584 -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 +1928 -0
- package/src/compiler/checker-literals.ts +61 -0
- package/src/compiler/checker-members.ts +2480 -0
- package/src/compiler/checker-modules.ts +2896 -0
- package/src/compiler/checker-narrowing.ts +3230 -0
- package/src/compiler/checker-object-literals.ts +591 -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 +1187 -0
- package/src/compiler/checker-symbols.ts +2157 -0
- package/src/compiler/checker-type-factory.ts +2616 -0
- package/src/compiler/checker-type-nodes.ts +1033 -0
- package/src/compiler/checker-type-operators.ts +2510 -0
- package/src/compiler/checker-types.ts +2520 -0
- package/src/compiler/checker-unused.ts +642 -0
- package/src/compiler/checker-utilities.ts +161 -0
- package/src/compiler/checker.ts +1138 -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 +858 -0
- package/src/compiler/emitter.ts +434 -0
- package/src/compiler/encoder.ts +1945 -0
- package/src/compiler/file-include.ts +741 -0
- package/src/compiler/file-loader.ts +1597 -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 +2818 -0
- package/src/compiler/init.ts +141 -0
- package/src/compiler/instantiation.ts +938 -0
- package/src/compiler/jsdoc.ts +1386 -0
- package/src/compiler/link-tables.ts +343 -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 +1071 -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 +3433 -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 +1954 -0
- package/src/compiler/parallel-parse.ts +595 -0
- package/src/compiler/parse-thread.ts +136 -0
- package/src/compiler/parser.ts +7766 -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 +684 -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 +594 -0
- package/src/compiler/program-utilities.ts +435 -0
- package/src/compiler/program.ts +1426 -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 +1166 -0
- package/src/compiler/symbol.ts +557 -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 +833 -0
- package/src/compiler/transformers/declarations-pseudo.ts +969 -0
- package/src/compiler/transformers/declarations-resolver.ts +249 -0
- package/src/compiler/transformers/declarations-syntactic.ts +1867 -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 +1213 -0
- package/src/compiler/transformers/runtime-syntax.ts +942 -0
- package/src/compiler/transformers/subtree-facts.ts +253 -0
- package/src/compiler/transformers/syntax-facts.ts +358 -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 +1422 -0
- package/src/compiler/tsc-cli.ts +669 -0
- package/src/compiler/tsc-compile.ts +446 -0
- package/src/compiler/tsc-watch.ts +922 -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 +141 -167
- package/src/library/ast.ts +4 -1
- package/src/library/checker.ts +384 -0
- package/src/library/diagnostics.ts +72 -0
- package/src/library/disk.ts +73 -0
- package/src/library/errors.ts +26 -0
- package/src/library/host.ts +63 -0
- package/src/library/index.ts +21 -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/types.ts +14 -1
|
@@ -0,0 +1,2148 @@
|
|
|
1
|
+
import { getCombinedModifierFlags, getDeclarationOfKind } from './binder-utilities.js';
|
|
2
|
+
import { getSymbol, getName } from './ast.js';
|
|
3
|
+
import { cachedTypeKey, CompositeSignature, IndexInfo, MemberNames, unionOrIntersectionMembers, emptyIndexInfos, emptySignatures, emptySymbols, emptyTypes, newThisArgumentTypeMapper, newTypeMapper, prependTypeMapping, PendingMembers, } from './checker-types.js';
|
|
4
|
+
import { createArrayTypeEx, createTupleTypeEx, createTypeReference, everyType, getElementTypes, getIntersectionType, getStringLiteralType, getTemplateLiteralType, getTypeArguments, getUnionOrIntersectionType, getUnionType, getUnionTypeEx, isArrayOrTupleType, isErrorType, isGenericTupleType, isLiteralType, isPatternLiteralType, isReadonlyArrayType, isTupleType, mapType, setStructuredTypeMembers, someType, tupleTargetOf, typesOf, } from './checker-type-factory.js';
|
|
5
|
+
import { getRestTypeOfTupleType, mappedTypeTarget } from './checker-type-operators.js';
|
|
6
|
+
import { isAmbientModule } from './ast-utilities.js';
|
|
7
|
+
import { getExportsOfSymbol, getLateBoundSymbol, getMembersOfSymbol, getMergedSymbol, getNamedMembers, getSymbolOfDeclaration, isReservedMemberName, popTypeResolution, pushTypeResolution, symbolIsValue, } from './checker-symbols.js';
|
|
8
|
+
import { getBaseConstructorTypeOfClass, getBaseTypes, getConstraintDeclaration, getConstraintFromTypeParameter, getDeclaredTypeOfClassOrInterface, getDeclaredTypeOfSymbol, getLocalTypeParametersOfClassOrInterfaceOrTypeAlias, isMixinConstructorType, } from './checker-declared-types.js';
|
|
9
|
+
import { getTypeOfSymbol, getWriteTypeOfSymbol, isReadonlySymbol } from './checker-symbol-types.js';
|
|
10
|
+
import { getTypeFromTypeNode } from './checker-type-nodes.js';
|
|
11
|
+
import { instantiateIndexInfos, instantiateSignatures, instantiateSymbol, instantiateType, keepsSymbolUnderInstantiation, newInstantiatedSymbol, instantiateTypes, } from './instantiation.js';
|
|
12
|
+
import { compareProperties, compareSignaturesIdentical, compareTypesIdentical, getRecursionIdentity, isTypeAssignableTo, } from './relations.js';
|
|
13
|
+
import { isUnmatchedTemplateLiteralKey } from './checker-inference.js';
|
|
14
|
+
import { typeToString } from './type-printer.js';
|
|
15
|
+
import { cloneSignature, createSignatureInstantiation, getDefaultConstructSignatures, getIndexInfosOfIndexSymbol, getMinArgumentCount, getParameterCount, getParameterNameAtPosition, getReturnTypeOfSignature, getSignaturesOfSymbol, getTypeAtPosition, hasEffectiveRestParameter, tryGetTypeAtPosition, } from './checker-signatures.js';
|
|
16
|
+
import { getConstraintFromConditionalType, getHomomorphicTypeVariable, getIndexForMappedType, getIndexedAccessTypeOrUndefined, getModifiersTypeFromMappedType, getNameTypeFromMappedType, getSimplifiedType, getStringMappingType, getSubstitutionIntersection, isGenericMappedType, isMappedTypeGenericIndexedAccess, isMappedTypeWithKeyofConstraintDeclaration, resolveMappedTypeMembers, resolveReverseMappedTypeMembers, substituteIndexedMappedType, } from './checker-type-operators.js';
|
|
17
|
+
import { getGlobalBigIntType, getGlobalESSymbolType } from './checker-globals.js';
|
|
18
|
+
import { isLateBoundName, isNumericLiteralName } from './checker-utilities.js';
|
|
19
|
+
import { lazyObjectFlags, sideOf, sideOfIfAny } from './side-state.js';
|
|
20
|
+
import { copyDeclarations, declarationCount, getDeclarations, getSymbolId, setDeclarations, } from './symbol.js';
|
|
21
|
+
// ---- Resolution
|
|
22
|
+
/**
|
|
23
|
+
* `t` with its members resolved. The test is small enough to inline into callers, so a resolved
|
|
24
|
+
* type (almost every call) costs no call; the resolution itself is out of line.
|
|
25
|
+
*/
|
|
26
|
+
export function resolveStructuredTypeMembers(c, t) {
|
|
27
|
+
if ((t.objectFlags & 2097152 /* ObjectFlags.MembersResolved */) !== 0)
|
|
28
|
+
return t;
|
|
29
|
+
const resolved = membersHolder(c, t);
|
|
30
|
+
if ((resolved.objectFlags & 2097152 /* ObjectFlags.MembersResolved */) === 0)
|
|
31
|
+
resolveMembersOfType(c, t);
|
|
32
|
+
return resolved;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* The object that holds the resolved members of `t`: `t` itself, or for a type with side state
|
|
36
|
+
* (`ObjectFlags.SideState`) the checker's holder of its state (`sideOf`). Resolving the members of
|
|
37
|
+
* `t` writes them there; `t` keeps its identity and is never written.
|
|
38
|
+
*/
|
|
39
|
+
export function membersHolder(c, t) {
|
|
40
|
+
const side = sideOf(c, t);
|
|
41
|
+
if ((side.flags & 402653184 /* TypeFlags.UnionOrIntersection */) !== 0)
|
|
42
|
+
return unionOrIntersectionMembers(side);
|
|
43
|
+
return side;
|
|
44
|
+
}
|
|
45
|
+
/** The `objectFlags` of `t` that resolving its members sets (MembersResolved, UnresolvedMembers). */
|
|
46
|
+
export function memberResolutionFlags(c, t) {
|
|
47
|
+
if ((t.flags & 402653184 /* TypeFlags.UnionOrIntersection */) === 0)
|
|
48
|
+
return lazyObjectFlags(c, t);
|
|
49
|
+
const side = sideOfIfAny(c, t);
|
|
50
|
+
const members = side !== undefined ? side.membersOf : undefined;
|
|
51
|
+
return members !== undefined ? members.objectFlags : 0 /* ObjectFlags.None */;
|
|
52
|
+
}
|
|
53
|
+
function resolveMembersOfType(c, t) {
|
|
54
|
+
if ((t.flags & 1048576 /* TypeFlags.Object */) !== 0) {
|
|
55
|
+
const objectFlags = t.objectFlags;
|
|
56
|
+
if ((objectFlags & 4 /* ObjectFlags.Reference */) !== 0)
|
|
57
|
+
resolveTypeReferenceMembers(c, t);
|
|
58
|
+
else if ((objectFlags & 3 /* ObjectFlags.ClassOrInterface */) !== 0)
|
|
59
|
+
resolveObjectTypeMembers(c, membersHolder(c, t), t, emptyTypes, emptyTypes, undefined);
|
|
60
|
+
else if ((objectFlags & 1024 /* ObjectFlags.ReverseMapped */) !== 0)
|
|
61
|
+
resolveReverseMappedTypeMembers(c, t);
|
|
62
|
+
else if ((objectFlags & 16 /* ObjectFlags.Anonymous */) !== 0)
|
|
63
|
+
resolveAnonymousTypeMembers(c, t);
|
|
64
|
+
else if ((objectFlags & 32 /* ObjectFlags.Mapped */) !== 0)
|
|
65
|
+
resolveMappedTypeMembers(c, t);
|
|
66
|
+
}
|
|
67
|
+
else if ((t.flags & 134217728 /* TypeFlags.Union */) !== 0)
|
|
68
|
+
resolveUnionTypeMembers(c, t);
|
|
69
|
+
else if ((t.flags & 268435456 /* TypeFlags.Intersection */) !== 0)
|
|
70
|
+
resolveIntersectionTypeMembers(c, t);
|
|
71
|
+
}
|
|
72
|
+
function resolveTypeReferenceMembers(c, t) {
|
|
73
|
+
const source = t.target;
|
|
74
|
+
const typeParameters = source.allTypeParameters;
|
|
75
|
+
const typeArguments = getTypeArguments(c, t);
|
|
76
|
+
// With one type argument fewer than parameters, the reference itself is the `this` type argument.
|
|
77
|
+
const thisArgument = typeArguments.length === typeParameters.length - 1 ? t : undefined;
|
|
78
|
+
resolveObjectTypeMembers(c, membersHolder(c, t), source, typeParameters, typeArguments, thisArgument);
|
|
79
|
+
}
|
|
80
|
+
/** Whether `b`, followed by `last` where given, is the list `a`. */
|
|
81
|
+
function sameTypes(a, b, last) {
|
|
82
|
+
const count = b.length;
|
|
83
|
+
if (a.length !== (last !== undefined ? count + 1 : count))
|
|
84
|
+
return false;
|
|
85
|
+
for (let i = 0; i < count; i++)
|
|
86
|
+
if (a[i] !== b[i])
|
|
87
|
+
return false;
|
|
88
|
+
return last === undefined || a[count] === last;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Resolves the members of an instantiation of `source` into `t`, the holder of its members: with
|
|
92
|
+
* `typeArguments` for its type parameters, followed by `thisArgument` where given.
|
|
93
|
+
*/
|
|
94
|
+
function resolveObjectTypeMembers(c, t, source, typeParameters, typeArguments, thisArgument) {
|
|
95
|
+
const declared = resolveDeclaredMembers(c, source);
|
|
96
|
+
let mapper;
|
|
97
|
+
let members;
|
|
98
|
+
let callSignatures;
|
|
99
|
+
let constructSignatures;
|
|
100
|
+
let indexInfos;
|
|
101
|
+
let instantiated = false;
|
|
102
|
+
// The member symbols of an instantiation are instantiated on demand (PendingInstantiatedMembers).
|
|
103
|
+
let pending;
|
|
104
|
+
if (sameTypes(typeParameters, typeArguments, thisArgument)) {
|
|
105
|
+
members = declared.declaredMembers;
|
|
106
|
+
callSignatures = declared.declaredCallSignatures;
|
|
107
|
+
constructSignatures = declared.declaredConstructSignatures;
|
|
108
|
+
indexInfos = declared.declaredIndexInfos;
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
instantiated = true;
|
|
112
|
+
mapper =
|
|
113
|
+
thisArgument !== undefined
|
|
114
|
+
? newThisArgumentTypeMapper(typeParameters, typeArguments, thisArgument)
|
|
115
|
+
: newTypeMapper(typeParameters, typeArguments);
|
|
116
|
+
pending = pendingInstantiatedTable(c, source, mapper);
|
|
117
|
+
members = pending === undefined ? instantiateSymbolTable(c, declared.declaredMembers, mapper) : undefined;
|
|
118
|
+
callSignatures = instantiateSignatures(c, declared.declaredCallSignatures, mapper);
|
|
119
|
+
constructSignatures = instantiateSignatures(c, declared.declaredConstructSignatures, mapper);
|
|
120
|
+
indexInfos = instantiateIndexInfos(c, declared.declaredIndexInfos, mapper);
|
|
121
|
+
}
|
|
122
|
+
const baseTypes = getBaseTypes(c, source);
|
|
123
|
+
// The last type argument, the `this` type argument where the reference has one.
|
|
124
|
+
const lastArgument = thisArgument ?? (typeArguments.length !== 0 ? typeArguments[typeArguments.length - 1] : undefined);
|
|
125
|
+
if (pending !== undefined) {
|
|
126
|
+
resolvePendingObjectTypeMembers(c, t, pending, baseTypes, mapper, lastArgument, callSignatures, constructSignatures, indexInfos);
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
if (baseTypes.length !== 0) {
|
|
130
|
+
members = !instantiated || members === undefined ? new Map(members ?? []) : members;
|
|
131
|
+
setStructuredTypeMembers(c, t, members, callSignatures, constructSignatures, indexInfos);
|
|
132
|
+
t.objectFlags |= 536870912 /* ObjectFlags.UnresolvedMembers */;
|
|
133
|
+
for (const baseType of baseTypes) {
|
|
134
|
+
const instantiatedBaseType = lastArgument !== undefined
|
|
135
|
+
? getTypeWithThisArgument(c, instantiateType(c, baseType, mapper), lastArgument, false)
|
|
136
|
+
: baseType;
|
|
137
|
+
addInheritedMembers(members, getPropertiesOfType(c, instantiatedBaseType));
|
|
138
|
+
// A base without signatures adds none: no copy of the list then.
|
|
139
|
+
const baseCallSignatures = getSignaturesOfType(c, instantiatedBaseType, 0 /* SignatureKind.Call */);
|
|
140
|
+
if (baseCallSignatures.length !== 0)
|
|
141
|
+
callSignatures = callSignatures.concat(baseCallSignatures);
|
|
142
|
+
const baseConstructSignatures = getSignaturesOfType(c, instantiatedBaseType, 1 /* SignatureKind.Construct */);
|
|
143
|
+
if (baseConstructSignatures.length !== 0)
|
|
144
|
+
constructSignatures = constructSignatures.concat(baseConstructSignatures);
|
|
145
|
+
const inherited = instantiatedBaseType !== c.anyType ? getIndexInfosOfType(c, instantiatedBaseType) : [c.anyBaseTypeIndexInfo];
|
|
146
|
+
const added = [];
|
|
147
|
+
for (const info of inherited)
|
|
148
|
+
if (findIndexInfo(indexInfos, info.keyType) === undefined)
|
|
149
|
+
added.push(info);
|
|
150
|
+
if (added.length !== 0)
|
|
151
|
+
indexInfos = indexInfos.concat(added);
|
|
152
|
+
}
|
|
153
|
+
t.objectFlags &= ~536870912 /* ObjectFlags.UnresolvedMembers */;
|
|
154
|
+
}
|
|
155
|
+
setStructuredTypeMembers(c, t, members, callSignatures, constructSignatures, indexInfos);
|
|
156
|
+
}
|
|
157
|
+
const noBaseTypes = [];
|
|
158
|
+
const noBaseProperties = [];
|
|
159
|
+
export class PendingInstantiatedMembers extends PendingMembers {
|
|
160
|
+
c;
|
|
161
|
+
/** References: the declared members of the class or interface, by name. */
|
|
162
|
+
sourceTable;
|
|
163
|
+
/** Anonymous type instantiations: the properties of the target, in order. */
|
|
164
|
+
sourceList;
|
|
165
|
+
mapper;
|
|
166
|
+
/** MemberState of each member of the source, in order, 16 to a word. */
|
|
167
|
+
states;
|
|
168
|
+
/** Position of each member of the source by name (shared by all instantiations of the source). */
|
|
169
|
+
positions;
|
|
170
|
+
/**
|
|
171
|
+
* What a reference inherits, per base type as far as resolution has come (`baseCount` bases): a
|
|
172
|
+
* base whose own pending table is complete (its properties are read on demand), or else the base's
|
|
173
|
+
* properties as read when tsgo reads them. Most types have one base: the first is kept in
|
|
174
|
+
* `firstBase` or `firstBaseProperties`, the others in `otherBases` or `otherBaseProperties`.
|
|
175
|
+
*/
|
|
176
|
+
baseCount;
|
|
177
|
+
firstBase;
|
|
178
|
+
firstBaseProperties;
|
|
179
|
+
otherBases;
|
|
180
|
+
otherBaseProperties;
|
|
181
|
+
/** Whether the type has base types (tsgo copies the instantiated table into a new one then). */
|
|
182
|
+
hasBases;
|
|
183
|
+
/** While the base types are resolved: `properties` holds the own members only, as in tsgo. */
|
|
184
|
+
resolving;
|
|
185
|
+
/** Members instantiated by name lookups so far. */
|
|
186
|
+
instantiated;
|
|
187
|
+
/** References: the holder of the declared members of the class or interface. */
|
|
188
|
+
owner;
|
|
189
|
+
/** Whether the instantiated table has an own member, and one that isn't optional. */
|
|
190
|
+
hasOwnMembers;
|
|
191
|
+
hasRequiredOwnMembers;
|
|
192
|
+
constructor(c, sourceTable, sourceList, mapper, states, positions, hasOwnMembers, hasRequiredOwnMembers) {
|
|
193
|
+
super();
|
|
194
|
+
this.hasOwnMembers = hasOwnMembers;
|
|
195
|
+
this.hasRequiredOwnMembers = hasRequiredOwnMembers;
|
|
196
|
+
this.c = c;
|
|
197
|
+
this.sourceTable = sourceTable;
|
|
198
|
+
this.sourceList = sourceList;
|
|
199
|
+
this.mapper = mapper;
|
|
200
|
+
this.states = states;
|
|
201
|
+
this.positions = positions;
|
|
202
|
+
// Most instantiations have no base types, or one: the lists are created by the second one.
|
|
203
|
+
this.baseCount = 0;
|
|
204
|
+
this.firstBase = undefined;
|
|
205
|
+
this.firstBaseProperties = undefined;
|
|
206
|
+
this.otherBases = noBaseTypes;
|
|
207
|
+
this.otherBaseProperties = noBaseProperties;
|
|
208
|
+
this.hasBases = false;
|
|
209
|
+
this.resolving = false;
|
|
210
|
+
this.instantiated = undefined;
|
|
211
|
+
this.owner = undefined;
|
|
212
|
+
}
|
|
213
|
+
/** Records the next base: `base` where its pending table is complete, else its `properties`. */
|
|
214
|
+
addBase(base, properties) {
|
|
215
|
+
if (this.baseCount === 0) {
|
|
216
|
+
this.firstBase = base;
|
|
217
|
+
this.firstBaseProperties = properties;
|
|
218
|
+
}
|
|
219
|
+
else {
|
|
220
|
+
if (this.otherBases === noBaseTypes) {
|
|
221
|
+
this.otherBases = [];
|
|
222
|
+
this.otherBaseProperties = [];
|
|
223
|
+
}
|
|
224
|
+
this.otherBases.push(base);
|
|
225
|
+
this.otherBaseProperties.push(properties);
|
|
226
|
+
}
|
|
227
|
+
this.baseCount++;
|
|
228
|
+
}
|
|
229
|
+
/** The base at `index` where its pending table is complete (`addBase`), else undefined. */
|
|
230
|
+
baseAt(index) {
|
|
231
|
+
return index === 0 ? this.firstBase : this.otherBases[index - 1];
|
|
232
|
+
}
|
|
233
|
+
/** The properties the base at `index` adds. */
|
|
234
|
+
inheritedProperties(index) {
|
|
235
|
+
const base = this.baseAt(index);
|
|
236
|
+
if (base !== undefined)
|
|
237
|
+
return base.properties;
|
|
238
|
+
return index === 0 ? this.firstBaseProperties : this.otherBaseProperties[index - 1];
|
|
239
|
+
}
|
|
240
|
+
state(position) {
|
|
241
|
+
return ((this.states[position >> 4] >>> ((position & 15) * 2)) & 3);
|
|
242
|
+
}
|
|
243
|
+
/** The member symbol at `position` of the source, instantiated as tsgo would have. */
|
|
244
|
+
memberAt(position, source) {
|
|
245
|
+
const name = source.name;
|
|
246
|
+
const instantiated = this.instantiated;
|
|
247
|
+
if (instantiated !== undefined) {
|
|
248
|
+
const known = instantiated.get(name);
|
|
249
|
+
if (known !== undefined)
|
|
250
|
+
return known;
|
|
251
|
+
}
|
|
252
|
+
return this.state(position) === 3 /* MemberState.Kept */ ? source : newInstantiatedSymbol(this.c, source, this.mapper);
|
|
253
|
+
}
|
|
254
|
+
/** The own member `name` as in tsgo's instantiated table, or undefined. */
|
|
255
|
+
ownMember(name) {
|
|
256
|
+
const position = this.positions.get(name);
|
|
257
|
+
if (position === undefined || this.state(position) === 0 /* MemberState.Skipped */)
|
|
258
|
+
return undefined;
|
|
259
|
+
let instantiated = this.instantiated;
|
|
260
|
+
if (instantiated !== undefined) {
|
|
261
|
+
const known = instantiated.get(name);
|
|
262
|
+
if (known !== undefined)
|
|
263
|
+
return known;
|
|
264
|
+
}
|
|
265
|
+
const source = this.sourceTable !== undefined ? this.sourceTable.get(name) : this.sourceList[position];
|
|
266
|
+
const symbol = this.state(position) === 3 /* MemberState.Kept */ ? source : newInstantiatedSymbol(this.c, source, this.mapper);
|
|
267
|
+
if (instantiated === undefined)
|
|
268
|
+
this.instantiated = instantiated = new Map();
|
|
269
|
+
instantiated.set(name, symbol);
|
|
270
|
+
return symbol;
|
|
271
|
+
}
|
|
272
|
+
get(name) {
|
|
273
|
+
let existing = this.ownMember(name);
|
|
274
|
+
// Own members have value flags (pendingInstantiatedTable), so no base replaces them.
|
|
275
|
+
const count = this.baseCount;
|
|
276
|
+
if (existing !== undefined || count === 0)
|
|
277
|
+
return existing;
|
|
278
|
+
// addInheritedMembers: a base property replaces a missing or non-value member.
|
|
279
|
+
for (let i = 0; i < count; i++) {
|
|
280
|
+
if (existing !== undefined && (existing.flags & 111551 /* SymbolFlags.Value */) !== 0)
|
|
281
|
+
break;
|
|
282
|
+
const base = this.baseAt(i);
|
|
283
|
+
const inherited = base !== undefined
|
|
284
|
+
? getInheritedProperty(this.c, base, name)
|
|
285
|
+
: findProperty(this.c, this.inheritedProperties(i), name);
|
|
286
|
+
if (inherited !== undefined && !isStaticPrivateIdentifierProperty(inherited))
|
|
287
|
+
existing = inherited;
|
|
288
|
+
}
|
|
289
|
+
return existing;
|
|
290
|
+
}
|
|
291
|
+
/** The table of own members, as instantiateSymbolTable or createInstantiatedSymbolTable builds it. */
|
|
292
|
+
ownTable() {
|
|
293
|
+
const table = new Map();
|
|
294
|
+
const list = this.sourceList;
|
|
295
|
+
if (list !== undefined) {
|
|
296
|
+
for (let i = 0; i < list.length; i++) {
|
|
297
|
+
const source = list[i];
|
|
298
|
+
// Of two properties with one name, the table keeps the last (and the lookups use it).
|
|
299
|
+
table.set(source.name, this.positions.get(source.name) === i
|
|
300
|
+
? this.memberAt(i, source)
|
|
301
|
+
: this.state(i) === 3 /* MemberState.Kept */
|
|
302
|
+
? source
|
|
303
|
+
: newInstantiatedSymbol(this.c, source, this.mapper));
|
|
304
|
+
}
|
|
305
|
+
return table;
|
|
306
|
+
}
|
|
307
|
+
let i = 0;
|
|
308
|
+
for (const [id, source] of this.sourceTable) {
|
|
309
|
+
if (this.state(i) !== 0 /* MemberState.Skipped */)
|
|
310
|
+
table.set(id, this.memberAt(i, source));
|
|
311
|
+
i++;
|
|
312
|
+
}
|
|
313
|
+
return table;
|
|
314
|
+
}
|
|
315
|
+
materialize(t) {
|
|
316
|
+
const c = this.c;
|
|
317
|
+
t.pendingMembers = undefined;
|
|
318
|
+
const members = this.ownTable();
|
|
319
|
+
this.instantiated = undefined;
|
|
320
|
+
if (!this.hasBases) {
|
|
321
|
+
t.membersValue = members;
|
|
322
|
+
t.propertiesValue = getNamedMembers(c, members, t.symbol);
|
|
323
|
+
this.keepTableOnDemand(t, members);
|
|
324
|
+
return;
|
|
325
|
+
}
|
|
326
|
+
// While the bases are resolved, tsgo's `properties` holds the own members and its table
|
|
327
|
+
// grows by each base as it is resolved; the rest of resolution continues eagerly.
|
|
328
|
+
const resolving = this.resolving;
|
|
329
|
+
const ownProperties = resolving ? getNamedMembers(c, members, t.symbol) : undefined;
|
|
330
|
+
for (let i = 0; i < this.baseCount; i++)
|
|
331
|
+
addInheritedMembers(members, this.inheritedProperties(i));
|
|
332
|
+
t.membersValue = members;
|
|
333
|
+
t.propertiesValue = ownProperties ?? getNamedMembers(c, members, t.symbol);
|
|
334
|
+
// Resolving the bases goes on with the table (resolvePendingObjectTypeMembers).
|
|
335
|
+
if (!resolving)
|
|
336
|
+
this.keepTableOnDemand(t, members);
|
|
337
|
+
}
|
|
338
|
+
/**
|
|
339
|
+
* After `materialize`: drops `members`, the table, where every member of it is a property. The
|
|
340
|
+
* table's names are then the names of the properties, so lookups by name read the properties by
|
|
341
|
+
* the positions of their names, and `materializeTable` builds the table again from them. The
|
|
342
|
+
* names come from the last instantiation of the same source, where they are the same.
|
|
343
|
+
*/
|
|
344
|
+
keepTableOnDemand(t, members) {
|
|
345
|
+
const properties = t.propertiesValue;
|
|
346
|
+
if (properties.length !== members.size)
|
|
347
|
+
return;
|
|
348
|
+
const owner = this.owner;
|
|
349
|
+
const last = owner !== undefined ? owner.lastMemberNames : this.c.memberNamesOfLists.get(this.sourceList);
|
|
350
|
+
let names = last !== undefined && hasMemberNames(last, properties, members) ? last : undefined;
|
|
351
|
+
if (names === undefined) {
|
|
352
|
+
names = memberNamesOf(properties, members);
|
|
353
|
+
if (owner !== undefined)
|
|
354
|
+
owner.lastMemberNames = names;
|
|
355
|
+
else
|
|
356
|
+
this.c.memberNamesOfLists.set(this.sourceList, names);
|
|
357
|
+
}
|
|
358
|
+
t.membersValue = undefined;
|
|
359
|
+
t.pendingMembers = new PropertyMembers(properties, names);
|
|
360
|
+
}
|
|
361
|
+
materializeTable(t) {
|
|
362
|
+
this.materialize(t);
|
|
363
|
+
const pending = t.pendingMembers;
|
|
364
|
+
if (pending !== undefined)
|
|
365
|
+
pending.materializeTable(t);
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
/**
|
|
369
|
+
* The members of a type whose members table holds only its properties, in the order of the
|
|
370
|
+
* properties or of `names.tableOrder`: lookups by name read the properties, by the positions of
|
|
371
|
+
* their names in `names` (`MemberNames`), or by comparing the names of a few properties
|
|
372
|
+
* (`scannedPropertiesLimit`) without `names`. Reading `members` builds the table.
|
|
373
|
+
*/
|
|
374
|
+
export class PropertyMembers extends PendingMembers {
|
|
375
|
+
names;
|
|
376
|
+
constructor(properties, names) {
|
|
377
|
+
super();
|
|
378
|
+
this.materializedProperties = properties;
|
|
379
|
+
this.names = names;
|
|
380
|
+
}
|
|
381
|
+
materialize(_t) { }
|
|
382
|
+
materializeTable(t) {
|
|
383
|
+
const properties = this.materializedProperties;
|
|
384
|
+
const names = this.names;
|
|
385
|
+
const members = new Map();
|
|
386
|
+
if (names !== undefined)
|
|
387
|
+
for (const i of names.tableOrder)
|
|
388
|
+
members.set(properties[i].name, properties[i]);
|
|
389
|
+
else
|
|
390
|
+
for (const p of properties)
|
|
391
|
+
members.set(p.name, p);
|
|
392
|
+
t.pendingMembers = undefined;
|
|
393
|
+
t.membersValue = members;
|
|
394
|
+
}
|
|
395
|
+
get(name) {
|
|
396
|
+
const properties = this.materializedProperties;
|
|
397
|
+
const names = this.names;
|
|
398
|
+
if (names === undefined) {
|
|
399
|
+
for (const p of properties)
|
|
400
|
+
if (p.name === name)
|
|
401
|
+
return p;
|
|
402
|
+
return undefined;
|
|
403
|
+
}
|
|
404
|
+
const position = names.positions.get(name);
|
|
405
|
+
return position !== undefined ? properties[position] : undefined;
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
/** The most properties of a table that `keepPropertiesOnly` drops: a lookup compares that many names at most. */
|
|
409
|
+
const scannedPropertiesLimit = 8;
|
|
410
|
+
/** The most properties of an object literal's table that `keepPropertiesOnly` drops: literals are looked up often. */
|
|
411
|
+
export const scannedLiteralPropertiesLimit = 4;
|
|
412
|
+
/**
|
|
413
|
+
* After `setStructuredTypeMembers(c, t, members, ...)`: drops `members` where it holds only the
|
|
414
|
+
* type's properties, at most `limit` of them (`PropertyMembers`).
|
|
415
|
+
*/
|
|
416
|
+
export function keepPropertiesOnly(c, t, members, limit = scannedPropertiesLimit) {
|
|
417
|
+
const resolved = membersHolder(c, t);
|
|
418
|
+
const properties = resolved.propertiesValue;
|
|
419
|
+
if (members.size === 0 || members.size > limit || properties.length !== members.size)
|
|
420
|
+
return;
|
|
421
|
+
resolved.membersValue = undefined;
|
|
422
|
+
resolved.pendingMembers = new PropertyMembers(properties, undefined);
|
|
423
|
+
}
|
|
424
|
+
/** The names of `properties`, and the order of the names of `members`, a table with the same names. */
|
|
425
|
+
function memberNamesOf(properties, members) {
|
|
426
|
+
const names = [];
|
|
427
|
+
const positions = new Map();
|
|
428
|
+
for (let i = 0; i < properties.length; i++) {
|
|
429
|
+
const name = properties[i].name;
|
|
430
|
+
names.push(name);
|
|
431
|
+
positions.set(name, i);
|
|
432
|
+
}
|
|
433
|
+
const tableOrder = [];
|
|
434
|
+
for (const name of members.keys())
|
|
435
|
+
tableOrder.push(positions.get(name));
|
|
436
|
+
return new MemberNames(names, positions, tableOrder);
|
|
437
|
+
}
|
|
438
|
+
/** Whether `properties` have the names of `names`, and `members` has them in its table order. */
|
|
439
|
+
function hasMemberNames(names, properties, members) {
|
|
440
|
+
const list = names.names;
|
|
441
|
+
if (list.length !== properties.length)
|
|
442
|
+
return false;
|
|
443
|
+
for (let i = 0; i < list.length; i++)
|
|
444
|
+
if (properties[i].name !== list[i])
|
|
445
|
+
return false;
|
|
446
|
+
const order = names.tableOrder;
|
|
447
|
+
let k = 0;
|
|
448
|
+
for (const name of members.keys())
|
|
449
|
+
if (list[order[k++]] !== name)
|
|
450
|
+
return false;
|
|
451
|
+
return true;
|
|
452
|
+
}
|
|
453
|
+
/**
|
|
454
|
+
* The pending table of `table` instantiated with `mapper`, or undefined where it isn't worth it or
|
|
455
|
+
* tsgo's table wouldn't be keyed by symbol names. Records the decisions instantiateSymbolTable makes.
|
|
456
|
+
*/
|
|
457
|
+
function pendingInstantiatedTable(c, source, mapper) {
|
|
458
|
+
const declared = sideOf(c, source);
|
|
459
|
+
const table = declared.declaredMembers;
|
|
460
|
+
if (table === undefined || table.size === 0)
|
|
461
|
+
return undefined;
|
|
462
|
+
const states = [];
|
|
463
|
+
let word = 0;
|
|
464
|
+
let i = 0;
|
|
465
|
+
let hasOwnMembers = false;
|
|
466
|
+
let hasRequiredOwnMembers = false;
|
|
467
|
+
for (const [id, symbol] of table) {
|
|
468
|
+
if (id !== symbol.name)
|
|
469
|
+
return undefined;
|
|
470
|
+
let state = 0 /* MemberState.Skipped */;
|
|
471
|
+
if (isNamedMember(c, symbol, id)) {
|
|
472
|
+
// A named member without a value flag (an alias) could be replaced by an inherited one; keep
|
|
473
|
+
// such tables eager, so that an own member always stands.
|
|
474
|
+
if ((symbol.flags & 111551 /* SymbolFlags.Value */) === 0)
|
|
475
|
+
return undefined;
|
|
476
|
+
state = keepsSymbolUnderInstantiation(c, symbol, mapper) ? 3 /* MemberState.Kept */ : 1 /* MemberState.Instantiated */;
|
|
477
|
+
// Instantiated symbols have the flags of their source.
|
|
478
|
+
hasOwnMembers = true;
|
|
479
|
+
if ((symbol.flags & 16777216 /* SymbolFlags.Optional */) === 0)
|
|
480
|
+
hasRequiredOwnMembers = true;
|
|
481
|
+
}
|
|
482
|
+
word |= state << ((i & 15) * 2);
|
|
483
|
+
if ((i & 15) === 15) {
|
|
484
|
+
states.push(word);
|
|
485
|
+
word = 0;
|
|
486
|
+
}
|
|
487
|
+
i++;
|
|
488
|
+
}
|
|
489
|
+
if ((i & 15) !== 0)
|
|
490
|
+
states.push(word);
|
|
491
|
+
const pending = new PendingInstantiatedMembers(c, table, undefined, mapper, sharedStates(declared, states), declaredMemberPositions(declared, table), hasOwnMembers, hasRequiredOwnMembers);
|
|
492
|
+
pending.owner = declared;
|
|
493
|
+
return pending;
|
|
494
|
+
}
|
|
495
|
+
/**
|
|
496
|
+
* `states`, or the equal list the last instantiation of `source` used: most instantiations of a
|
|
497
|
+
* source keep and instantiate the same members, and the lists are never changed.
|
|
498
|
+
*/
|
|
499
|
+
function sharedStates(source, states) {
|
|
500
|
+
const last = source.lastMemberStates;
|
|
501
|
+
if (last !== undefined && last.length === states.length) {
|
|
502
|
+
let i = 0;
|
|
503
|
+
while (i < states.length && last[i] === states[i])
|
|
504
|
+
i++;
|
|
505
|
+
if (i === states.length)
|
|
506
|
+
return last;
|
|
507
|
+
}
|
|
508
|
+
source.lastMemberStates = states;
|
|
509
|
+
return states;
|
|
510
|
+
}
|
|
511
|
+
/** The pending table of the properties `list` instantiated with `mapper` (createInstantiatedSymbolTable). */
|
|
512
|
+
function pendingInstantiatedList(c, list, mapper) {
|
|
513
|
+
const states = [];
|
|
514
|
+
let word = 0;
|
|
515
|
+
let hasRequiredOwnMembers = false;
|
|
516
|
+
for (let i = 0; i < list.length; i++) {
|
|
517
|
+
const state = keepsSymbolUnderInstantiation(c, list[i], mapper) ? 3 /* MemberState.Kept */ : 1 /* MemberState.Instantiated */;
|
|
518
|
+
if ((list[i].flags & 16777216 /* SymbolFlags.Optional */) === 0)
|
|
519
|
+
hasRequiredOwnMembers = true;
|
|
520
|
+
word |= state << ((i & 15) * 2);
|
|
521
|
+
if ((i & 15) === 15) {
|
|
522
|
+
states.push(word);
|
|
523
|
+
word = 0;
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
if ((list.length & 15) !== 0)
|
|
527
|
+
states.push(word);
|
|
528
|
+
return new PendingInstantiatedMembers(c, undefined, list, mapper, states, listPositions(c, list), true, hasRequiredOwnMembers);
|
|
529
|
+
}
|
|
530
|
+
/**
|
|
531
|
+
* Positions of the declared members of a class or interface by name, shared by all its
|
|
532
|
+
* instantiations; `source` is the holder of its declared members (`resolveDeclaredMembers`).
|
|
533
|
+
*/
|
|
534
|
+
function declaredMemberPositions(source, table) {
|
|
535
|
+
let positions = source.declaredMemberPositions;
|
|
536
|
+
if (positions === undefined) {
|
|
537
|
+
positions = new Map();
|
|
538
|
+
let i = 0;
|
|
539
|
+
for (const id of table.keys())
|
|
540
|
+
positions.set(id, i++);
|
|
541
|
+
source.declaredMemberPositions = positions;
|
|
542
|
+
}
|
|
543
|
+
return positions;
|
|
544
|
+
}
|
|
545
|
+
/** Positions by name in a target's properties, shared by its instantiations. The last of equal names wins. */
|
|
546
|
+
function listPositions(c, list) {
|
|
547
|
+
let positions = c.memberPositionsInLists.get(list);
|
|
548
|
+
if (positions === undefined) {
|
|
549
|
+
positions = new Map();
|
|
550
|
+
let i = 0;
|
|
551
|
+
for (const symbol of list)
|
|
552
|
+
positions.set(symbol.name, i++);
|
|
553
|
+
c.memberPositionsInLists.set(list, positions);
|
|
554
|
+
}
|
|
555
|
+
return positions;
|
|
556
|
+
}
|
|
557
|
+
/** The property `name` of a base whose pending table is complete, without building that table. */
|
|
558
|
+
function getInheritedProperty(c, base, name) {
|
|
559
|
+
// getNamedMembers: properties are the value members whose names aren't reserved.
|
|
560
|
+
if (isReservedMemberName(name))
|
|
561
|
+
return undefined;
|
|
562
|
+
const symbol = getResolvedMember(base, name);
|
|
563
|
+
return symbol !== undefined && symbolIsValue(c, symbol) ? symbol : undefined;
|
|
564
|
+
}
|
|
565
|
+
/** The symbol named `name` in a list of properties. Long lists are indexed once. */
|
|
566
|
+
function findProperty(c, properties, name) {
|
|
567
|
+
if (properties.length < 16) {
|
|
568
|
+
for (const p of properties)
|
|
569
|
+
if (p.name === name)
|
|
570
|
+
return p;
|
|
571
|
+
return undefined;
|
|
572
|
+
}
|
|
573
|
+
let byName = c.propertiesByName.get(properties);
|
|
574
|
+
if (byName === undefined) {
|
|
575
|
+
byName = new Map();
|
|
576
|
+
for (const p of properties)
|
|
577
|
+
if (!byName.has(p.name))
|
|
578
|
+
byName.set(p.name, p);
|
|
579
|
+
c.propertiesByName.set(properties, byName);
|
|
580
|
+
}
|
|
581
|
+
return byName.get(name);
|
|
582
|
+
}
|
|
583
|
+
/** `t.members?.get(name)` of a type whose members are resolved, without building a pending table. */
|
|
584
|
+
export function getResolvedMember(t, name) {
|
|
585
|
+
const pending = t.pendingMembers;
|
|
586
|
+
if (pending !== undefined)
|
|
587
|
+
return pending.get(name);
|
|
588
|
+
return t.membersValue?.get(name);
|
|
589
|
+
}
|
|
590
|
+
/** `t.properties.length !== 0` of a type whose members are resolved, without building a pending table. */
|
|
591
|
+
export function hasResolvedProperties(t) {
|
|
592
|
+
const pending = t.pendingMembers;
|
|
593
|
+
// Own members are all properties; with none, what the bases add decides.
|
|
594
|
+
if (pending !== undefined && pending.materializedProperties === undefined) {
|
|
595
|
+
const instantiated = pending;
|
|
596
|
+
if (!instantiated.resolving && instantiated.hasOwnMembers)
|
|
597
|
+
return true;
|
|
598
|
+
}
|
|
599
|
+
return t.properties.length !== 0;
|
|
600
|
+
}
|
|
601
|
+
/** `getPropertiesOfType(c, t).length !== 0`, without building a pending table. */
|
|
602
|
+
export function hasPropertiesOfType(c, t) {
|
|
603
|
+
if (!isOwnReducedApparentType(t))
|
|
604
|
+
t = getReducedApparentTypeWorker(c, t);
|
|
605
|
+
if ((t.flags & 402653184 /* TypeFlags.UnionOrIntersection */) !== 0)
|
|
606
|
+
return getPropertiesOfUnionOrIntersectionType(c, t).length !== 0;
|
|
607
|
+
return (t.flags & 1048576 /* TypeFlags.Object */) !== 0 && hasResolvedProperties(resolveStructuredTypeMembers(c, t));
|
|
608
|
+
}
|
|
609
|
+
/**
|
|
610
|
+
* `t.properties.every(p => p is optional)` of a type whose members are resolved and that has
|
|
611
|
+
* properties, without building a pending table where its own members decide.
|
|
612
|
+
*/
|
|
613
|
+
export function resolvedPropertiesAreOptional(t) {
|
|
614
|
+
const pending = t.pendingMembers;
|
|
615
|
+
if (pending !== undefined && pending.materializedProperties === undefined) {
|
|
616
|
+
const instantiated = pending;
|
|
617
|
+
if (!instantiated.resolving) {
|
|
618
|
+
// A required own member is in the table whatever the bases add.
|
|
619
|
+
if (instantiated.hasRequiredOwnMembers)
|
|
620
|
+
return false;
|
|
621
|
+
if (!instantiated.hasBases)
|
|
622
|
+
return true;
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
for (const p of t.properties)
|
|
626
|
+
if ((p.flags & 16777216 /* SymbolFlags.Optional */) === 0)
|
|
627
|
+
return false;
|
|
628
|
+
return true;
|
|
629
|
+
}
|
|
630
|
+
/** resolveObjectTypeMembers for an instantiation whose member symbols are instantiated on demand. */
|
|
631
|
+
function resolvePendingObjectTypeMembers(c, t, pending, baseTypes, mapper, thisArgument, callSignatures, constructSignatures, indexInfos) {
|
|
632
|
+
setPendingStructuredTypeMembers(c, t, pending, callSignatures, constructSignatures, indexInfos);
|
|
633
|
+
if (baseTypes.length === 0)
|
|
634
|
+
return;
|
|
635
|
+
pending.hasBases = true;
|
|
636
|
+
pending.resolving = true;
|
|
637
|
+
t.objectFlags |= 536870912 /* ObjectFlags.UnresolvedMembers */;
|
|
638
|
+
for (const baseType of baseTypes) {
|
|
639
|
+
const instantiatedBaseType = thisArgument !== undefined
|
|
640
|
+
? getTypeWithThisArgument(c, instantiateType(c, baseType, mapper), thisArgument, false)
|
|
641
|
+
: baseType;
|
|
642
|
+
// getPropertiesOfType, except that a base whose pending table is complete keeps it pending:
|
|
643
|
+
// resolving its members has created every type already, and its table won't change. The
|
|
644
|
+
// reduced apparent type of an object type is itself except for mapped types, whose apparent
|
|
645
|
+
// type getPropertiesOfType computes first.
|
|
646
|
+
let lazyBase;
|
|
647
|
+
if ((instantiatedBaseType.flags & 1048576 /* TypeFlags.Object */) !== 0 &&
|
|
648
|
+
(instantiatedBaseType.objectFlags & 32 /* ObjectFlags.Mapped */) === 0) {
|
|
649
|
+
const resolved = resolveStructuredTypeMembers(c, instantiatedBaseType);
|
|
650
|
+
const basePending = resolved.pendingMembers;
|
|
651
|
+
if (basePending !== undefined &&
|
|
652
|
+
basePending.materializedProperties === undefined &&
|
|
653
|
+
!basePending.resolving)
|
|
654
|
+
lazyBase = resolved;
|
|
655
|
+
}
|
|
656
|
+
const baseProperties = lazyBase === undefined ? getPropertiesOfType(c, instantiatedBaseType) : undefined;
|
|
657
|
+
if (t.pendingMembers === pending)
|
|
658
|
+
pending.addBase(lazyBase, baseProperties);
|
|
659
|
+
else
|
|
660
|
+
addInheritedMembers(t.membersValue, baseProperties ?? lazyBase.properties);
|
|
661
|
+
const baseCallSignatures = getSignaturesOfType(c, instantiatedBaseType, 0 /* SignatureKind.Call */);
|
|
662
|
+
if (baseCallSignatures.length !== 0)
|
|
663
|
+
callSignatures = callSignatures.concat(baseCallSignatures);
|
|
664
|
+
const baseConstructSignatures = getSignaturesOfType(c, instantiatedBaseType, 1 /* SignatureKind.Construct */);
|
|
665
|
+
if (baseConstructSignatures.length !== 0)
|
|
666
|
+
constructSignatures = constructSignatures.concat(baseConstructSignatures);
|
|
667
|
+
const inherited = instantiatedBaseType !== c.anyType ? getIndexInfosOfType(c, instantiatedBaseType) : [c.anyBaseTypeIndexInfo];
|
|
668
|
+
const added = [];
|
|
669
|
+
for (const info of inherited)
|
|
670
|
+
if (findIndexInfo(indexInfos, info.keyType) === undefined)
|
|
671
|
+
added.push(info);
|
|
672
|
+
if (added.length !== 0)
|
|
673
|
+
indexInfos = indexInfos.concat(added);
|
|
674
|
+
}
|
|
675
|
+
t.objectFlags &= ~536870912 /* ObjectFlags.UnresolvedMembers */;
|
|
676
|
+
pending.resolving = false;
|
|
677
|
+
if (t.pendingMembers === pending)
|
|
678
|
+
setPendingStructuredTypeMembers(c, t, pending, callSignatures, constructSignatures, indexInfos);
|
|
679
|
+
else
|
|
680
|
+
setStructuredTypeMembers(c, t, t.membersValue, callSignatures, constructSignatures, indexInfos);
|
|
681
|
+
}
|
|
682
|
+
function setPendingStructuredTypeMembers(c, type, pending, callSignatures, constructSignatures, indexInfos) {
|
|
683
|
+
const t = membersHolder(c, type);
|
|
684
|
+
t.objectFlags |= 2097152 /* ObjectFlags.MembersResolved */;
|
|
685
|
+
t.membersValue = undefined;
|
|
686
|
+
t.propertiesValue = emptySymbols;
|
|
687
|
+
t.pendingMembers = pending;
|
|
688
|
+
t.callSignatures = callSignatures;
|
|
689
|
+
t.constructSignatures = constructSignatures;
|
|
690
|
+
t.indexInfos = indexInfos;
|
|
691
|
+
}
|
|
692
|
+
export function findIndexInfo(indexInfos, keyType) {
|
|
693
|
+
for (const info of indexInfos)
|
|
694
|
+
if (info.keyType === keyType)
|
|
695
|
+
return info;
|
|
696
|
+
return undefined;
|
|
697
|
+
}
|
|
698
|
+
/** Resolves the declared members of `t`; returns the object that holds them (`sideOf`). */
|
|
699
|
+
export function resolveDeclaredMembers(c, t) {
|
|
700
|
+
const declared = sideOf(c, t);
|
|
701
|
+
if (!declared.declaredMembersResolved) {
|
|
702
|
+
const members = getMembersOfSymbol(c, t.symbol);
|
|
703
|
+
declared.declaredMembersResolved = true;
|
|
704
|
+
declared.declaredMembers = members;
|
|
705
|
+
declared.declaredCallSignatures = getSignaturesOfSymbol(c, members.get("\uFFFEcall" /* InternalSymbolName.Call */));
|
|
706
|
+
declared.declaredConstructSignatures = getSignaturesOfSymbol(c, members.get("\uFFFEnew" /* InternalSymbolName.New */));
|
|
707
|
+
declared.declaredIndexInfos = getIndexInfosOfSymbol(c, t.symbol);
|
|
708
|
+
}
|
|
709
|
+
return declared;
|
|
710
|
+
}
|
|
711
|
+
export function getIndexSymbol(c, symbol) {
|
|
712
|
+
return getMembersOfSymbol(c, symbol).get("\uFFFEindex" /* InternalSymbolName.Index */);
|
|
713
|
+
}
|
|
714
|
+
export function getIndexInfosOfSymbol(c, symbol) {
|
|
715
|
+
const indexSymbol = getIndexSymbol(c, symbol);
|
|
716
|
+
if (indexSymbol === undefined)
|
|
717
|
+
return emptyIndexInfos;
|
|
718
|
+
return getIndexInfosOfIndexSymbol(c, indexSymbol, [...getMembersOfSymbol(c, symbol).values()]);
|
|
719
|
+
}
|
|
720
|
+
function isStaticPrivateIdentifierProperty(symbol) {
|
|
721
|
+
const d = symbol.valueDeclaration;
|
|
722
|
+
if (d === undefined)
|
|
723
|
+
return false;
|
|
724
|
+
const name = getName(d);
|
|
725
|
+
return (name !== undefined &&
|
|
726
|
+
name.kind === 80 /* SyntaxKind.PrivateIdentifier */ &&
|
|
727
|
+
(getCombinedModifierFlags(d) & 256 /* ModifierFlags.Static */) !== 0);
|
|
728
|
+
}
|
|
729
|
+
export function addInheritedMembers(symbols, baseSymbols) {
|
|
730
|
+
for (const base of baseSymbols) {
|
|
731
|
+
if (isStaticPrivateIdentifierProperty(base))
|
|
732
|
+
continue;
|
|
733
|
+
const existing = symbols.get(base.name);
|
|
734
|
+
if (existing === undefined || (existing.flags & 111551 /* SymbolFlags.Value */) === 0)
|
|
735
|
+
symbols.set(base.name, base);
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
export function instantiateSymbolTable(c, symbols, mapper) {
|
|
739
|
+
if (symbols === undefined || symbols.size === 0)
|
|
740
|
+
return undefined;
|
|
741
|
+
const result = new Map();
|
|
742
|
+
for (const [id, symbol] of symbols)
|
|
743
|
+
if (isNamedMember(c, symbol, id))
|
|
744
|
+
result.set(id, instantiateSymbol(c, symbol, mapper));
|
|
745
|
+
return result;
|
|
746
|
+
}
|
|
747
|
+
export function isNamedMember(c, symbol, id) {
|
|
748
|
+
if (id.length >= 2 && id.charCodeAt(0) === 0xfffe) {
|
|
749
|
+
const second = id.charCodeAt(1);
|
|
750
|
+
if (second !== 0x40 && second !== 0x23)
|
|
751
|
+
return false;
|
|
752
|
+
}
|
|
753
|
+
return symbolIsValue(c, symbol);
|
|
754
|
+
}
|
|
755
|
+
function createInstantiatedSymbolTable(c, symbols, mapper) {
|
|
756
|
+
if (symbols.length === 0)
|
|
757
|
+
return undefined;
|
|
758
|
+
const result = new Map();
|
|
759
|
+
for (const symbol of symbols)
|
|
760
|
+
result.set(symbol.name, mapper !== undefined ? instantiateSymbol(c, symbol, mapper) : symbol);
|
|
761
|
+
return result;
|
|
762
|
+
}
|
|
763
|
+
function resolveAnonymousTypeMembers(c, t) {
|
|
764
|
+
const resolved = membersHolder(c, t);
|
|
765
|
+
if (t.target !== undefined) {
|
|
766
|
+
setStructuredTypeMembers(c, t, undefined, emptySignatures, emptySignatures, emptyIndexInfos);
|
|
767
|
+
const target = t.target;
|
|
768
|
+
// createInstantiatedSymbolTable, on demand (PendingInstantiatedMembers).
|
|
769
|
+
const targetProperties = getPropertiesOfObjectType(c, target);
|
|
770
|
+
const pending = targetProperties.length !== 0 && t.mapper !== undefined
|
|
771
|
+
? pendingInstantiatedList(c, targetProperties, t.mapper)
|
|
772
|
+
: undefined;
|
|
773
|
+
const members = pending === undefined ? createInstantiatedSymbolTable(c, targetProperties, t.mapper) : undefined;
|
|
774
|
+
const callSignatures = instantiateSignatures(c, getSignaturesOfType(c, target, 0 /* SignatureKind.Call */), t.mapper);
|
|
775
|
+
const constructSignatures = instantiateSignatures(c, getSignaturesOfType(c, target, 1 /* SignatureKind.Construct */), t.mapper);
|
|
776
|
+
const indexInfos = instantiateIndexInfos(c, getIndexInfosOfType(c, target), t.mapper);
|
|
777
|
+
if (pending !== undefined)
|
|
778
|
+
setPendingStructuredTypeMembers(c, t, pending, callSignatures, constructSignatures, indexInfos);
|
|
779
|
+
else
|
|
780
|
+
setStructuredTypeMembers(c, t, members, callSignatures, constructSignatures, indexInfos);
|
|
781
|
+
return;
|
|
782
|
+
}
|
|
783
|
+
const symbol = getMergedSymbol(c, t.symbol);
|
|
784
|
+
if ((symbol.flags & 2048 /* SymbolFlags.TypeLiteral */) !== 0) {
|
|
785
|
+
setStructuredTypeMembers(c, t, undefined, emptySignatures, emptySignatures, emptyIndexInfos);
|
|
786
|
+
const members = getMembersOfSymbol(c, symbol);
|
|
787
|
+
const callSignatures = getSignaturesOfSymbol(c, members.get("\uFFFEcall" /* InternalSymbolName.Call */));
|
|
788
|
+
const constructSignatures = getSignaturesOfSymbol(c, members.get("\uFFFEnew" /* InternalSymbolName.New */));
|
|
789
|
+
const indexInfos = getIndexInfosOfSymbol(c, symbol);
|
|
790
|
+
setStructuredTypeMembers(c, t, members, callSignatures, constructSignatures, indexInfos);
|
|
791
|
+
return;
|
|
792
|
+
}
|
|
793
|
+
// Combinations of function, class, enum and module.
|
|
794
|
+
let members = getExportsOfSymbol(c, symbol);
|
|
795
|
+
if (symbol === c.globalThisSymbol) {
|
|
796
|
+
const varsOnly = new Map();
|
|
797
|
+
for (const p of members.values()) {
|
|
798
|
+
if ((p.flags & 418 /* SymbolFlags.BlockScoped */) !== 0)
|
|
799
|
+
continue;
|
|
800
|
+
if ((p.flags & 512 /* SymbolFlags.ValueModule */) !== 0 && isOnlyAmbientModuleDeclarations(getDeclarations(p)))
|
|
801
|
+
continue;
|
|
802
|
+
varsOnly.set(p.name, p);
|
|
803
|
+
}
|
|
804
|
+
members = varsOnly;
|
|
805
|
+
}
|
|
806
|
+
let baseConstructorIndexInfo;
|
|
807
|
+
setStructuredTypeMembers(c, t, members, emptySignatures, emptySignatures, emptyIndexInfos);
|
|
808
|
+
if ((symbol.flags & 32 /* SymbolFlags.Class */) !== 0) {
|
|
809
|
+
const classType = getDeclaredTypeOfClassOrInterface(c, symbol);
|
|
810
|
+
const baseConstructorType = getBaseConstructorTypeOfClass(c, classType);
|
|
811
|
+
if ((baseConstructorType.flags & (1048576 /* TypeFlags.Object */ | 268435456 /* TypeFlags.Intersection */ | 34078720 /* TypeFlags.TypeVariable */)) !== 0) {
|
|
812
|
+
members = new Map(members);
|
|
813
|
+
addInheritedMembers(members, getPropertiesOfType(c, baseConstructorType));
|
|
814
|
+
setStructuredTypeMembers(c, t, members, emptySignatures, emptySignatures, emptyIndexInfos);
|
|
815
|
+
}
|
|
816
|
+
else if (baseConstructorType === c.anyType)
|
|
817
|
+
baseConstructorIndexInfo = c.anyBaseTypeIndexInfo;
|
|
818
|
+
}
|
|
819
|
+
let indexInfos = [];
|
|
820
|
+
const indexSymbol = members.get("\uFFFEindex" /* InternalSymbolName.Index */);
|
|
821
|
+
if (indexSymbol !== undefined)
|
|
822
|
+
indexInfos = getIndexInfosOfIndexSymbol(c, indexSymbol, [...members.values()]);
|
|
823
|
+
else {
|
|
824
|
+
if (baseConstructorIndexInfo !== undefined)
|
|
825
|
+
indexInfos.push(baseConstructorIndexInfo);
|
|
826
|
+
if ((symbol.flags & 384 /* SymbolFlags.Enum */) !== 0) {
|
|
827
|
+
let numberLike = (getDeclaredTypeOfSymbol(c, symbol).flags & 65536 /* TypeFlags.Enum */) !== 0;
|
|
828
|
+
if (!numberLike)
|
|
829
|
+
for (const prop of resolved.properties)
|
|
830
|
+
if ((getTypeOfSymbol(c, prop).flags & 67648 /* TypeFlags.NumberLike */) !== 0) {
|
|
831
|
+
numberLike = true;
|
|
832
|
+
break;
|
|
833
|
+
}
|
|
834
|
+
if (numberLike)
|
|
835
|
+
indexInfos.push(c.enumNumberIndexInfo);
|
|
836
|
+
}
|
|
837
|
+
}
|
|
838
|
+
resolved.indexInfos = indexInfos.length === 0 ? emptyIndexInfos : indexInfos;
|
|
839
|
+
// Members are resolved before signatures, which may use `typeof` on this type (#6072).
|
|
840
|
+
if ((symbol.flags & (16 /* SymbolFlags.Function */ | 8192 /* SymbolFlags.Method */)) !== 0)
|
|
841
|
+
resolved.callSignatures = getSignaturesOfSymbol(c, symbol);
|
|
842
|
+
if ((symbol.flags & 32 /* SymbolFlags.Class */) !== 0) {
|
|
843
|
+
const classType = getDeclaredTypeOfClassOrInterface(c, symbol);
|
|
844
|
+
let constructSignatures = getSignaturesOfSymbol(c, symbol.members?.get("\uFFFEconstructor" /* InternalSymbolName.Constructor */));
|
|
845
|
+
if (constructSignatures.length === 0)
|
|
846
|
+
constructSignatures = getDefaultConstructSignatures(c, classType);
|
|
847
|
+
resolved.constructSignatures = constructSignatures;
|
|
848
|
+
}
|
|
849
|
+
}
|
|
850
|
+
function isOnlyAmbientModuleDeclarations(declarations) {
|
|
851
|
+
if (declarations.length === 0)
|
|
852
|
+
return false;
|
|
853
|
+
for (const d of declarations)
|
|
854
|
+
if (d.kind !== 268 /* SyntaxKind.ModuleDeclaration */ || !isAmbientModule(d))
|
|
855
|
+
return false;
|
|
856
|
+
return true;
|
|
857
|
+
}
|
|
858
|
+
function resolveUnionTypeMembers(c, t) {
|
|
859
|
+
// Members and properties are empty for unions; getPropertiesOfType computes them.
|
|
860
|
+
const callLists = [];
|
|
861
|
+
const constructLists = [];
|
|
862
|
+
for (const u of t.types) {
|
|
863
|
+
callLists.push(u === c.globalFunctionType ? [c.unknownSignature] : getSignaturesOfType(c, u, 0 /* SignatureKind.Call */));
|
|
864
|
+
constructLists.push(getSignaturesOfType(c, u, 1 /* SignatureKind.Construct */));
|
|
865
|
+
}
|
|
866
|
+
let callSignatures = getUnionSignatures(c, callLists);
|
|
867
|
+
if (callSignatures.length === 0)
|
|
868
|
+
callSignatures = getArrayMemberCallSignatures(c, t);
|
|
869
|
+
const constructSignatures = getUnionSignatures(c, constructLists);
|
|
870
|
+
const indexInfos = getUnionIndexInfos(c, t.types);
|
|
871
|
+
setStructuredTypeMembers(c, t, undefined, callSignatures, constructSignatures, indexInfos);
|
|
872
|
+
}
|
|
873
|
+
function getArrayMemberCallSignatures(c, t) {
|
|
874
|
+
// A union of instantiations of one Array or ReadonlyArray member: `(A[] | B[])["m"]` is `(A | B)[]["m"]`.
|
|
875
|
+
let memberName = '';
|
|
876
|
+
for (let i = 0; i < t.types.length; i++) {
|
|
877
|
+
const u = t.types[i];
|
|
878
|
+
if ((u.objectFlags & 64 /* ObjectFlags.Instantiated */) === 0 ||
|
|
879
|
+
u.symbol === undefined ||
|
|
880
|
+
u.symbol.parent === undefined ||
|
|
881
|
+
!isArrayOrTupleSymbol(c, u.symbol.parent))
|
|
882
|
+
return emptySignatures;
|
|
883
|
+
if (i === 0)
|
|
884
|
+
memberName = u.symbol.name;
|
|
885
|
+
else if (memberName !== u.symbol.name)
|
|
886
|
+
return emptySignatures;
|
|
887
|
+
}
|
|
888
|
+
const arrayArg = mapType(c, t, (u) => {
|
|
889
|
+
const generic = isReadonlyArraySymbol(c, u.symbol.parent) ? c.globalReadonlyArrayType : c.globalArrayType;
|
|
890
|
+
return u.mapper.map(generic.typeParameters()[0]);
|
|
891
|
+
});
|
|
892
|
+
const arrayType = createArrayTypeEx(c, arrayArg, someType(t, (u) => isReadonlyArraySymbol(c, u.symbol.parent)));
|
|
893
|
+
const memberType = getTypeOfPropertyOfType(c, arrayType, memberName);
|
|
894
|
+
return memberType !== undefined ? getSignaturesOfType(c, memberType, 0 /* SignatureKind.Call */) : emptySignatures;
|
|
895
|
+
}
|
|
896
|
+
function isArrayOrTupleSymbol(c, symbol) {
|
|
897
|
+
if (c.globalArrayType.symbol === undefined || c.globalReadonlyArrayType.symbol === undefined)
|
|
898
|
+
return false;
|
|
899
|
+
return (sameReference(c, symbol, c.globalArrayType.symbol) || sameReference(c, symbol, c.globalReadonlyArrayType.symbol));
|
|
900
|
+
}
|
|
901
|
+
function isReadonlyArraySymbol(c, symbol) {
|
|
902
|
+
return c.globalReadonlyArrayType.symbol !== undefined && sameReference(c, symbol, c.globalReadonlyArrayType.symbol);
|
|
903
|
+
}
|
|
904
|
+
function sameReference(c, s1, s2) {
|
|
905
|
+
return getMergedSymbol(c, s1) === getMergedSymbol(c, s2);
|
|
906
|
+
}
|
|
907
|
+
/**
|
|
908
|
+
* The signatures present in every constituent: generic ones must match exactly; others may have
|
|
909
|
+
* extra optional parameters and differing return types, which are unioned.
|
|
910
|
+
*/
|
|
911
|
+
export function getUnionSignatures(c, signatureLists) {
|
|
912
|
+
let result;
|
|
913
|
+
let indexWithLengthOverOne = 0;
|
|
914
|
+
let countLengthOverOne = 0;
|
|
915
|
+
for (let i = 0; i < signatureLists.length; i++) {
|
|
916
|
+
const list = signatureLists[i];
|
|
917
|
+
if (list.length === 0)
|
|
918
|
+
return emptySignatures;
|
|
919
|
+
if (list.length > 1) {
|
|
920
|
+
indexWithLengthOverOne = i;
|
|
921
|
+
countLengthOverOne++;
|
|
922
|
+
}
|
|
923
|
+
for (const signature of list) {
|
|
924
|
+
if (result !== undefined && findMatchingSignature(c, result, signature, false, false, true) !== undefined)
|
|
925
|
+
continue;
|
|
926
|
+
const unionSignatures = findMatchingSignatures(c, signatureLists, signature, i);
|
|
927
|
+
if (unionSignatures === undefined)
|
|
928
|
+
continue;
|
|
929
|
+
let s = signature;
|
|
930
|
+
if (unionSignatures.length > 1) {
|
|
931
|
+
let thisParameter = signature.thisParameter;
|
|
932
|
+
let firstThisParameter;
|
|
933
|
+
for (const sig of unionSignatures)
|
|
934
|
+
if (sig.thisParameter !== undefined) {
|
|
935
|
+
firstThisParameter = sig.thisParameter;
|
|
936
|
+
break;
|
|
937
|
+
}
|
|
938
|
+
if (firstThisParameter !== undefined) {
|
|
939
|
+
const thisTypes = [];
|
|
940
|
+
for (const sig of unionSignatures)
|
|
941
|
+
if (sig.thisParameter !== undefined)
|
|
942
|
+
thisTypes.push(getTypeOfSymbol(c, sig.thisParameter));
|
|
943
|
+
thisParameter = createSymbolWithType(c, firstThisParameter, getIntersectionType(c, thisTypes));
|
|
944
|
+
}
|
|
945
|
+
s = createUnionSignature(c, signature, unionSignatures);
|
|
946
|
+
s.thisParameter = thisParameter;
|
|
947
|
+
}
|
|
948
|
+
if (result === undefined)
|
|
949
|
+
result = [];
|
|
950
|
+
result.push(s);
|
|
951
|
+
}
|
|
952
|
+
}
|
|
953
|
+
if ((result === undefined || result.length === 0) && countLengthOverOne <= 1) {
|
|
954
|
+
// One constituent has overloads: try a single signature that handles all of them.
|
|
955
|
+
const masterList = signatureLists[indexWithLengthOverOne];
|
|
956
|
+
let results = masterList.slice();
|
|
957
|
+
for (const signatures of signatureLists) {
|
|
958
|
+
if (signatures === masterList)
|
|
959
|
+
continue;
|
|
960
|
+
const signature = signatures[0];
|
|
961
|
+
if (signature.typeParameters.length !== 0 && hasNonIdenticalTypeParameters(c, results, signature)) {
|
|
962
|
+
results = undefined;
|
|
963
|
+
break;
|
|
964
|
+
}
|
|
965
|
+
const combined = [];
|
|
966
|
+
for (const sig of results)
|
|
967
|
+
combined.push(combineUnionOrIntersectionMemberSignatures(c, sig, signature, true));
|
|
968
|
+
results = combined;
|
|
969
|
+
}
|
|
970
|
+
result = results;
|
|
971
|
+
}
|
|
972
|
+
return result ?? emptySignatures;
|
|
973
|
+
}
|
|
974
|
+
function findMatchingSignatures(c, signatureLists, signature, listIndex) {
|
|
975
|
+
if (signature.typeParameters.length !== 0) {
|
|
976
|
+
// Generic signatures need exact matches in the other lists.
|
|
977
|
+
if (listIndex > 0)
|
|
978
|
+
return undefined;
|
|
979
|
+
for (let i = 1; i < signatureLists.length; i++)
|
|
980
|
+
if (findMatchingSignature(c, signatureLists[i], signature, false, false, false) === undefined)
|
|
981
|
+
return undefined;
|
|
982
|
+
return [signature];
|
|
983
|
+
}
|
|
984
|
+
const result = [];
|
|
985
|
+
for (let i = 0; i < signatureLists.length; i++) {
|
|
986
|
+
const match = i === listIndex
|
|
987
|
+
? signature
|
|
988
|
+
: (findMatchingSignature(c, signatureLists[i], signature, false, false, true) ??
|
|
989
|
+
findMatchingSignature(c, signatureLists[i], signature, true, false, true));
|
|
990
|
+
if (match === undefined)
|
|
991
|
+
return undefined;
|
|
992
|
+
if (!result.includes(match))
|
|
993
|
+
result.push(match);
|
|
994
|
+
}
|
|
995
|
+
return result;
|
|
996
|
+
}
|
|
997
|
+
export function findMatchingSignature(c, signatureList, signature, partialMatch, ignoreThisTypes, ignoreReturnTypes) {
|
|
998
|
+
for (const s of signatureList)
|
|
999
|
+
if (compareSignaturesIdentical(c, s, signature, partialMatch, ignoreThisTypes, ignoreReturnTypes, partialMatch ? 1 /* ComparerKind.SubtypeOf */ : 0 /* ComparerKind.Identical */) !== 0 /* Ternary.False */)
|
|
1000
|
+
return s;
|
|
1001
|
+
return undefined;
|
|
1002
|
+
}
|
|
1003
|
+
function hasNonIdenticalTypeParameters(c, signatures, signature) {
|
|
1004
|
+
for (const s of signatures)
|
|
1005
|
+
if (s.typeParameters.length !== 0 && !compareTypeParametersIdentical(c, signature.typeParameters, s.typeParameters))
|
|
1006
|
+
return true;
|
|
1007
|
+
return false;
|
|
1008
|
+
}
|
|
1009
|
+
export function compareTypeParametersIdentical(c, sourceParams, targetParams) {
|
|
1010
|
+
if (sourceParams.length !== targetParams.length)
|
|
1011
|
+
return false;
|
|
1012
|
+
const mapper = newTypeMapper(targetParams, sourceParams);
|
|
1013
|
+
for (let i = 0; i < sourceParams.length; i++) {
|
|
1014
|
+
const source = sourceParams[i];
|
|
1015
|
+
const target = targetParams[i];
|
|
1016
|
+
if (source === target)
|
|
1017
|
+
continue;
|
|
1018
|
+
// A type parameter matches another one with an identical (instantiated) constraint.
|
|
1019
|
+
const sourceConstraint = getConstraintFromTypeParameter(c, source) ?? c.unknownType;
|
|
1020
|
+
const targetConstraint = getConstraintFromTypeParameter(c, target);
|
|
1021
|
+
if (!compareTypesIdenticalBool(c, sourceConstraint, targetConstraint !== undefined ? instantiateType(c, targetConstraint, mapper) : c.unknownType))
|
|
1022
|
+
return false;
|
|
1023
|
+
}
|
|
1024
|
+
return true;
|
|
1025
|
+
}
|
|
1026
|
+
function compareTypesIdenticalBool(c, s, t) {
|
|
1027
|
+
return compareTypesIdentical(c, s, t) !== 0 /* Ternary.False */;
|
|
1028
|
+
}
|
|
1029
|
+
function createUnionSignature(c, sig, unionSignatures) {
|
|
1030
|
+
const result = cloneSignature(c, sig);
|
|
1031
|
+
result.composite = new CompositeSignature(true, unionSignatures);
|
|
1032
|
+
result.target = undefined;
|
|
1033
|
+
result.mapper = undefined;
|
|
1034
|
+
return result;
|
|
1035
|
+
}
|
|
1036
|
+
export function combineUnionOrIntersectionMemberSignatures(c, left, right, isUnion) {
|
|
1037
|
+
const typeParams = left.typeParameters.length !== 0 ? left.typeParameters : right.typeParameters;
|
|
1038
|
+
// Use the type parameter defaults from the first signature.
|
|
1039
|
+
const paramMapper = left.typeParameters.length !== 0 && right.typeParameters.length !== 0
|
|
1040
|
+
? newTypeMapper(right.typeParameters, left.typeParameters)
|
|
1041
|
+
: undefined;
|
|
1042
|
+
let flags = (left.flags | right.flags) & (335 /* SignatureFlags.PropagatingFlags */ & ~1 /* SignatureFlags.HasRestParameter */);
|
|
1043
|
+
const params = combineUnionOrIntersectionParameters(c, left, right, paramMapper, isUnion);
|
|
1044
|
+
const lastParam = params.length !== 0 ? params[params.length - 1] : undefined;
|
|
1045
|
+
if (lastParam !== undefined && (lastParam.checkFlags & 32768 /* CheckFlags.RestParameter */) !== 0)
|
|
1046
|
+
flags |= 1 /* SignatureFlags.HasRestParameter */;
|
|
1047
|
+
const thisParam = combineUnionOrIntersectionThisParam(c, left.thisParameter, right.thisParameter, paramMapper, isUnion);
|
|
1048
|
+
const minArgCount = Math.max(left.minArgumentCount, right.minArgumentCount);
|
|
1049
|
+
const result = c.newSignature(flags, left.declaration, typeParams, thisParam, params, undefined, minArgCount);
|
|
1050
|
+
const leftSignatures = left.composite !== undefined && left.composite.isUnion ? left.composite.signatures : [left];
|
|
1051
|
+
result.composite = new CompositeSignature(isUnion, leftSignatures.concat([right]));
|
|
1052
|
+
if (paramMapper !== undefined) {
|
|
1053
|
+
result.mapper =
|
|
1054
|
+
left.composite !== undefined && left.composite.isUnion === isUnion && left.mapper !== undefined
|
|
1055
|
+
? combineMappers(c, left.mapper, paramMapper)
|
|
1056
|
+
: paramMapper;
|
|
1057
|
+
}
|
|
1058
|
+
else if (left.composite !== undefined && left.composite.isUnion === isUnion)
|
|
1059
|
+
result.mapper = left.mapper;
|
|
1060
|
+
return result;
|
|
1061
|
+
}
|
|
1062
|
+
import { combineTypeMappers as combineMappers } from './instantiation.js';
|
|
1063
|
+
function combineUnionOrIntersectionParameters(c, left, right, mapper, isUnion) {
|
|
1064
|
+
const leftCount = getParameterCount(c, left);
|
|
1065
|
+
const rightCount = getParameterCount(c, right);
|
|
1066
|
+
const longest = leftCount >= rightCount ? left : right;
|
|
1067
|
+
const shorter = longest === left ? right : left;
|
|
1068
|
+
const longestCount = longest === left ? leftCount : rightCount;
|
|
1069
|
+
const eitherHasEffectiveRest = hasEffectiveRestParameter(c, left) || hasEffectiveRestParameter(c, right);
|
|
1070
|
+
const needsExtraRestElement = eitherHasEffectiveRest && !hasEffectiveRestParameter(c, longest);
|
|
1071
|
+
const params = [];
|
|
1072
|
+
for (let i = 0; i < longestCount; i++) {
|
|
1073
|
+
let longestParamType = tryGetTypeAtPosition(c, longest, i);
|
|
1074
|
+
if (longest === right)
|
|
1075
|
+
longestParamType = instantiateType(c, longestParamType, mapper);
|
|
1076
|
+
let shorterParamType = tryGetTypeAtPosition(c, shorter, i) ?? c.unknownType;
|
|
1077
|
+
if (shorter === right)
|
|
1078
|
+
shorterParamType = instantiateType(c, shorterParamType, mapper);
|
|
1079
|
+
const combinedParamType = getUnionOrIntersectionType(c, [longestParamType, shorterParamType], !isUnion, 1 /* UnionReduction.Literal */);
|
|
1080
|
+
const isRestParam = eitherHasEffectiveRest && !needsExtraRestElement && i === longestCount - 1;
|
|
1081
|
+
const isOptional = i >= getMinArgumentCount(c, longest) && i >= getMinArgumentCount(c, shorter);
|
|
1082
|
+
const leftName = i < leftCount ? getParameterNameAtPosition(c, left, i) : '';
|
|
1083
|
+
const rightName = i < rightCount ? getParameterNameAtPosition(c, right, i) : '';
|
|
1084
|
+
let paramName = leftName === rightName ? leftName : leftName === '' ? rightName : rightName === '' ? leftName : '';
|
|
1085
|
+
if (paramName === '')
|
|
1086
|
+
paramName = 'arg' + i;
|
|
1087
|
+
const paramSymbol = c.newSymbolWithCheckFlags(1 /* SymbolFlags.FunctionScopedVariable */ | (isOptional && !isRestParam ? 16777216 /* SymbolFlags.Optional */ : 0), paramName, isRestParam ? 32768 /* CheckFlags.RestParameter */ : isOptional ? 16384 /* CheckFlags.OptionalParameter */ : 0 /* CheckFlags.None */);
|
|
1088
|
+
c.symbolTypes.set(getSymbolId(paramSymbol), isRestParam ? createArrayTypeEx(c, combinedParamType, false) : combinedParamType);
|
|
1089
|
+
params.push(paramSymbol);
|
|
1090
|
+
}
|
|
1091
|
+
if (needsExtraRestElement) {
|
|
1092
|
+
const restParamSymbol = c.newSymbolWithCheckFlags(1 /* SymbolFlags.FunctionScopedVariable */, 'args', 32768 /* CheckFlags.RestParameter */);
|
|
1093
|
+
let restType = createArrayTypeEx(c, getTypeAtPosition(c, shorter, longestCount), false);
|
|
1094
|
+
if (shorter === right)
|
|
1095
|
+
restType = instantiateType(c, restType, mapper);
|
|
1096
|
+
c.symbolTypes.set(getSymbolId(restParamSymbol), restType);
|
|
1097
|
+
params.push(restParamSymbol);
|
|
1098
|
+
}
|
|
1099
|
+
return params;
|
|
1100
|
+
}
|
|
1101
|
+
function combineUnionOrIntersectionThisParam(c, left, right, mapper, isUnion) {
|
|
1102
|
+
if (left === undefined)
|
|
1103
|
+
return right;
|
|
1104
|
+
if (right === undefined)
|
|
1105
|
+
return left;
|
|
1106
|
+
// Intersected like parameter types, to be permissive when calling.
|
|
1107
|
+
const thisType = getUnionOrIntersectionType(c, [getTypeOfSymbol(c, left), instantiateType(c, getTypeOfSymbol(c, right), mapper)], !isUnion, 1 /* UnionReduction.Literal */);
|
|
1108
|
+
return createSymbolWithType(c, left, thisType);
|
|
1109
|
+
}
|
|
1110
|
+
export function getUnionIndexInfos(c, types) {
|
|
1111
|
+
const sourceInfos = getIndexInfosOfType(c, types[0]);
|
|
1112
|
+
const result = [];
|
|
1113
|
+
for (const info of sourceInfos) {
|
|
1114
|
+
const indexType = info.keyType;
|
|
1115
|
+
let everyHas = true;
|
|
1116
|
+
for (const t of types)
|
|
1117
|
+
if (getIndexInfoOfType(c, t, indexType) === undefined) {
|
|
1118
|
+
everyHas = false;
|
|
1119
|
+
break;
|
|
1120
|
+
}
|
|
1121
|
+
if (!everyHas)
|
|
1122
|
+
continue;
|
|
1123
|
+
const valueTypes = [];
|
|
1124
|
+
let isReadonly = false;
|
|
1125
|
+
for (const t of types) {
|
|
1126
|
+
const i = getIndexInfoOfType(c, t, indexType);
|
|
1127
|
+
valueTypes.push(i.valueType);
|
|
1128
|
+
if (i.isReadonly)
|
|
1129
|
+
isReadonly = true;
|
|
1130
|
+
}
|
|
1131
|
+
result.push(new IndexInfo(indexType, getUnionType(c, valueTypes), isReadonly, undefined, []));
|
|
1132
|
+
}
|
|
1133
|
+
return result;
|
|
1134
|
+
}
|
|
1135
|
+
function resolveIntersectionTypeMembers(c, t) {
|
|
1136
|
+
let callSignatures = [];
|
|
1137
|
+
let constructSignatures = [];
|
|
1138
|
+
let indexInfos = [];
|
|
1139
|
+
const types = t.types;
|
|
1140
|
+
const mixinFlags = [];
|
|
1141
|
+
for (const u of types)
|
|
1142
|
+
mixinFlags.push(isMixinConstructorType(c, u));
|
|
1143
|
+
let constructorTypeCount = 0;
|
|
1144
|
+
let mixinCount = 0;
|
|
1145
|
+
let firstMixinIndex = -1;
|
|
1146
|
+
for (let i = 0; i < types.length; i++) {
|
|
1147
|
+
if (getSignaturesOfType(c, types[i], 1 /* SignatureKind.Construct */).length > 0)
|
|
1148
|
+
constructorTypeCount++;
|
|
1149
|
+
if (mixinFlags[i]) {
|
|
1150
|
+
if (firstMixinIndex < 0)
|
|
1151
|
+
firstMixinIndex = i;
|
|
1152
|
+
mixinCount++;
|
|
1153
|
+
}
|
|
1154
|
+
}
|
|
1155
|
+
if (constructorTypeCount > 0 && constructorTypeCount === mixinCount) {
|
|
1156
|
+
mixinFlags[firstMixinIndex] = false;
|
|
1157
|
+
mixinCount--;
|
|
1158
|
+
}
|
|
1159
|
+
for (let i = 0; i < types.length; i++) {
|
|
1160
|
+
const u = types[i];
|
|
1161
|
+
// Mixin construct signatures are dropped; their return types mix into the others.
|
|
1162
|
+
if (!mixinFlags[i]) {
|
|
1163
|
+
let signatures = getSignaturesOfType(c, u, 1 /* SignatureKind.Construct */);
|
|
1164
|
+
if (signatures.length !== 0 && mixinCount > 0) {
|
|
1165
|
+
const clones = [];
|
|
1166
|
+
for (const s of signatures) {
|
|
1167
|
+
const clone = cloneSignature(c, s);
|
|
1168
|
+
clone.resolvedReturnType = includeMixinType(c, getReturnTypeOfSignature(c, s), types, mixinFlags, i);
|
|
1169
|
+
clones.push(clone);
|
|
1170
|
+
}
|
|
1171
|
+
signatures = clones;
|
|
1172
|
+
}
|
|
1173
|
+
constructSignatures = appendSignatures(c, constructSignatures, signatures);
|
|
1174
|
+
}
|
|
1175
|
+
callSignatures = appendSignatures(c, callSignatures, getSignaturesOfType(c, u, 0 /* SignatureKind.Call */));
|
|
1176
|
+
for (const info of getIndexInfosOfType(c, u))
|
|
1177
|
+
indexInfos = appendIndexInfo(c, indexInfos, info, false);
|
|
1178
|
+
}
|
|
1179
|
+
setStructuredTypeMembers(c, t, undefined, callSignatures, constructSignatures, indexInfos);
|
|
1180
|
+
}
|
|
1181
|
+
function includeMixinType(c, t, types, mixinFlags, index) {
|
|
1182
|
+
const mixed = [];
|
|
1183
|
+
for (let i = 0; i < types.length; i++) {
|
|
1184
|
+
if (i === index)
|
|
1185
|
+
mixed.push(t);
|
|
1186
|
+
else if (mixinFlags[i])
|
|
1187
|
+
mixed.push(getReturnTypeOfSignature(c, getSignaturesOfType(c, types[i], 1 /* SignatureKind.Construct */)[0]));
|
|
1188
|
+
}
|
|
1189
|
+
return getIntersectionType(c, mixed);
|
|
1190
|
+
}
|
|
1191
|
+
function appendSignatures(c, signatures, newSignatures) {
|
|
1192
|
+
for (const sig of newSignatures) {
|
|
1193
|
+
let unique = true;
|
|
1194
|
+
for (const s of signatures)
|
|
1195
|
+
if (compareSignaturesIdentical(c, s, sig, false, false, false, 0 /* ComparerKind.Identical */) !== 0 /* Ternary.False */) {
|
|
1196
|
+
unique = false;
|
|
1197
|
+
break;
|
|
1198
|
+
}
|
|
1199
|
+
if (signatures.length === 0 || unique)
|
|
1200
|
+
signatures.push(sig);
|
|
1201
|
+
}
|
|
1202
|
+
return signatures;
|
|
1203
|
+
}
|
|
1204
|
+
export function appendIndexInfo(c, indexInfos, newInfo, union) {
|
|
1205
|
+
for (let i = 0; i < indexInfos.length; i++) {
|
|
1206
|
+
const info = indexInfos[i];
|
|
1207
|
+
if (info.keyType !== newInfo.keyType)
|
|
1208
|
+
continue;
|
|
1209
|
+
const valueType = union
|
|
1210
|
+
? getUnionType(c, [info.valueType, newInfo.valueType])
|
|
1211
|
+
: getIntersectionType(c, [info.valueType, newInfo.valueType]);
|
|
1212
|
+
const isReadonly = union ? info.isReadonly || newInfo.isReadonly : info.isReadonly && newInfo.isReadonly;
|
|
1213
|
+
indexInfos[i] = new IndexInfo(info.keyType, valueType, isReadonly, undefined, []);
|
|
1214
|
+
return indexInfos;
|
|
1215
|
+
}
|
|
1216
|
+
indexInfos.push(newInfo);
|
|
1217
|
+
return indexInfos;
|
|
1218
|
+
}
|
|
1219
|
+
// ---- Properties
|
|
1220
|
+
export function getPropertiesOfType(c, t) {
|
|
1221
|
+
if (!isOwnReducedApparentType(t))
|
|
1222
|
+
t = getReducedApparentTypeWorker(c, t);
|
|
1223
|
+
if ((t.flags & 402653184 /* TypeFlags.UnionOrIntersection */) !== 0)
|
|
1224
|
+
return getPropertiesOfUnionOrIntersectionType(c, t);
|
|
1225
|
+
return getPropertiesOfObjectType(c, t);
|
|
1226
|
+
}
|
|
1227
|
+
export function getPropertiesOfObjectType(c, t) {
|
|
1228
|
+
return (t.flags & 1048576 /* TypeFlags.Object */) !== 0 ? resolveStructuredTypeMembers(c, t).properties : emptySymbols;
|
|
1229
|
+
}
|
|
1230
|
+
export function getPropertiesOfUnionOrIntersectionType(c, t) {
|
|
1231
|
+
const known = sideOf(c, t).membersOf;
|
|
1232
|
+
if (known !== undefined && known.resolvedProperties !== undefined)
|
|
1233
|
+
return known.resolvedProperties;
|
|
1234
|
+
{
|
|
1235
|
+
const checked = new Set();
|
|
1236
|
+
const props = [];
|
|
1237
|
+
for (const current of t.types) {
|
|
1238
|
+
for (const prop of getPropertiesOfType(c, current)) {
|
|
1239
|
+
if (checked.has(prop.name))
|
|
1240
|
+
continue;
|
|
1241
|
+
checked.add(prop.name);
|
|
1242
|
+
const combined = getPropertyOfUnionOrIntersectionType(c, t, prop.name, (t.flags & 268435456 /* TypeFlags.Intersection */) !== 0);
|
|
1243
|
+
if (combined !== undefined)
|
|
1244
|
+
props.push(combined);
|
|
1245
|
+
}
|
|
1246
|
+
// Union properties are in every constituent: the first without index signatures suffices.
|
|
1247
|
+
if ((t.flags & 134217728 /* TypeFlags.Union */) !== 0 && getIndexInfosOfType(c, current).length === 0)
|
|
1248
|
+
break;
|
|
1249
|
+
}
|
|
1250
|
+
// Resolving the properties may have created the holder.
|
|
1251
|
+
const side = unionOrIntersectionMembers(sideOf(c, t));
|
|
1252
|
+
side.resolvedProperties = props;
|
|
1253
|
+
return props;
|
|
1254
|
+
}
|
|
1255
|
+
}
|
|
1256
|
+
export function getPropertyOfType(c, t, name) {
|
|
1257
|
+
return getPropertyOfTypeEx(c, t, name, false, false);
|
|
1258
|
+
}
|
|
1259
|
+
/**
|
|
1260
|
+
* The property `name` of `t`: synthesizes union and intersection properties, uses apparent types of
|
|
1261
|
+
* primitives and type parameters, and falls back to Object and Function members.
|
|
1262
|
+
*/
|
|
1263
|
+
export function getPropertyOfTypeEx(c, t, name, skipObjectFunctionPropertyAugment, includeTypeOnlyMembers) {
|
|
1264
|
+
if (!isOwnReducedApparentType(t))
|
|
1265
|
+
t = getReducedApparentTypeWorker(c, t);
|
|
1266
|
+
if ((t.flags & 1048576 /* TypeFlags.Object */) !== 0) {
|
|
1267
|
+
const resolved = resolveStructuredTypeMembers(c, t);
|
|
1268
|
+
const symbol = getResolvedMember(resolved, name);
|
|
1269
|
+
if (symbol !== undefined && includeTypeOnlyMembers)
|
|
1270
|
+
return symbol;
|
|
1271
|
+
if (symbol !== undefined) {
|
|
1272
|
+
// A module's member that only an `export type *` declaration exports is not a value.
|
|
1273
|
+
if (t.symbol !== undefined &&
|
|
1274
|
+
(t.symbol.flags & 512 /* SymbolFlags.ValueModule */) !== 0 &&
|
|
1275
|
+
c.symbolLinks(t.symbol).typeOnlyExportStarMap?.has(name) === true)
|
|
1276
|
+
return undefined;
|
|
1277
|
+
if (symbolIsValue(c, symbol))
|
|
1278
|
+
return symbol;
|
|
1279
|
+
}
|
|
1280
|
+
if (skipObjectFunctionPropertyAugment)
|
|
1281
|
+
return undefined;
|
|
1282
|
+
let functionType;
|
|
1283
|
+
if (t === c.anyFunctionType)
|
|
1284
|
+
functionType = c.globalFunctionType;
|
|
1285
|
+
else if (resolved.callSignatures.length !== 0)
|
|
1286
|
+
functionType = c.globalCallableFunctionType;
|
|
1287
|
+
else if (resolved.constructSignatures.length !== 0)
|
|
1288
|
+
functionType = c.globalNewableFunctionType;
|
|
1289
|
+
if (functionType !== undefined) {
|
|
1290
|
+
const found = getPropertyOfObjectType(c, functionType, name);
|
|
1291
|
+
if (found !== undefined)
|
|
1292
|
+
return found;
|
|
1293
|
+
}
|
|
1294
|
+
return getPropertyOfObjectType(c, c.globalObjectType, name);
|
|
1295
|
+
}
|
|
1296
|
+
if ((t.flags & 268435456 /* TypeFlags.Intersection */) !== 0) {
|
|
1297
|
+
const prop = getPropertyOfUnionOrIntersectionType(c, t, name, true);
|
|
1298
|
+
if (prop !== undefined)
|
|
1299
|
+
return prop;
|
|
1300
|
+
if (!skipObjectFunctionPropertyAugment)
|
|
1301
|
+
return getPropertyOfUnionOrIntersectionType(c, t, name, false);
|
|
1302
|
+
return undefined;
|
|
1303
|
+
}
|
|
1304
|
+
if ((t.flags & 134217728 /* TypeFlags.Union */) !== 0)
|
|
1305
|
+
return getPropertyOfUnionOrIntersectionType(c, t, name, skipObjectFunctionPropertyAugment);
|
|
1306
|
+
return undefined;
|
|
1307
|
+
}
|
|
1308
|
+
export function getPropertyOfObjectType(c, t, name) {
|
|
1309
|
+
if ((t.flags & 1048576 /* TypeFlags.Object */) === 0)
|
|
1310
|
+
return undefined;
|
|
1311
|
+
const symbol = getResolvedMember(resolveStructuredTypeMembers(c, t), name);
|
|
1312
|
+
return symbol !== undefined && symbolIsValue(c, symbol) ? symbol : undefined;
|
|
1313
|
+
}
|
|
1314
|
+
export function getTypeOfPropertyOfType(c, t, name) {
|
|
1315
|
+
const prop = getPropertyOfType(c, t, name);
|
|
1316
|
+
return prop !== undefined ? getTypeOfSymbol(c, prop) : undefined;
|
|
1317
|
+
}
|
|
1318
|
+
export function getPropertyOfUnionOrIntersectionType(c, t, name, skipObjectFunctionPropertyAugment) {
|
|
1319
|
+
const prop = getUnionOrIntersectionProperty(c, t, name, skipObjectFunctionPropertyAugment);
|
|
1320
|
+
// Partial union properties are filtered out.
|
|
1321
|
+
return prop !== undefined && (prop.checkFlags & 16 /* CheckFlags.ReadPartial */) !== 0 ? undefined : prop;
|
|
1322
|
+
}
|
|
1323
|
+
/**
|
|
1324
|
+
* The (possibly partial) property `name` of a union or intersection, cached on the type.
|
|
1325
|
+
*
|
|
1326
|
+
* Non-partial results without the Object/Function augment also serve lookups with it (tsgo copies
|
|
1327
|
+
* them into the augmented cache unless it already has the name). The augmented cache keeps only
|
|
1328
|
+
* its own results and a miss there falls back to the other cache, which answers exactly what the
|
|
1329
|
+
* copy would have: a name is in the augmented cache whenever a non-partial copy was skipped. This
|
|
1330
|
+
* keeps intersections, which resolve every property without the augment, from holding each
|
|
1331
|
+
* property twice.
|
|
1332
|
+
*/
|
|
1333
|
+
export function getUnionOrIntersectionProperty(c, t, name, skipObjectFunctionPropertyAugment) {
|
|
1334
|
+
const known = sideOf(c, t).membersOf;
|
|
1335
|
+
if (known !== undefined) {
|
|
1336
|
+
const cached = (skipObjectFunctionPropertyAugment ? known.propertyCacheWithoutFunctionPropertyAugment : known.propertyCache)?.get(name);
|
|
1337
|
+
if (cached !== undefined)
|
|
1338
|
+
return cached;
|
|
1339
|
+
if (!skipObjectFunctionPropertyAugment) {
|
|
1340
|
+
const withoutAugment = known.propertyCacheWithoutFunctionPropertyAugment?.get(name);
|
|
1341
|
+
if (withoutAugment !== undefined && (withoutAugment.checkFlags & 48 /* CheckFlags.Partial */) === 0)
|
|
1342
|
+
return withoutAugment;
|
|
1343
|
+
}
|
|
1344
|
+
}
|
|
1345
|
+
const prop = createUnionOrIntersectionProperty(c, t, name, skipObjectFunctionPropertyAugment);
|
|
1346
|
+
if (prop !== undefined) {
|
|
1347
|
+
// Creating the property may have created the holder and its caches.
|
|
1348
|
+
const side = unionOrIntersectionMembers(sideOf(c, t));
|
|
1349
|
+
let cache = skipObjectFunctionPropertyAugment
|
|
1350
|
+
? side.propertyCacheWithoutFunctionPropertyAugment
|
|
1351
|
+
: side.propertyCache;
|
|
1352
|
+
if (cache === undefined) {
|
|
1353
|
+
cache = new Map();
|
|
1354
|
+
if (skipObjectFunctionPropertyAugment)
|
|
1355
|
+
side.propertyCacheWithoutFunctionPropertyAugment = cache;
|
|
1356
|
+
else
|
|
1357
|
+
side.propertyCache = cache;
|
|
1358
|
+
}
|
|
1359
|
+
cache.set(name, prop);
|
|
1360
|
+
}
|
|
1361
|
+
return prop;
|
|
1362
|
+
}
|
|
1363
|
+
export function getDeclarationModifierFlagsFromSymbol(c, s, isWrite) {
|
|
1364
|
+
if (s.valueDeclaration !== undefined) {
|
|
1365
|
+
let declaration;
|
|
1366
|
+
if (isWrite)
|
|
1367
|
+
declaration = getDeclarationOfKind(s, 179 /* SyntaxKind.SetAccessor */);
|
|
1368
|
+
if (declaration === undefined && (s.flags & 32768 /* SymbolFlags.GetAccessor */) !== 0)
|
|
1369
|
+
declaration = getDeclarationOfKind(s, 178 /* SyntaxKind.GetAccessor */);
|
|
1370
|
+
if (declaration === undefined)
|
|
1371
|
+
declaration = s.valueDeclaration;
|
|
1372
|
+
const flags = getCombinedModifierFlags(declaration);
|
|
1373
|
+
return s.parent !== undefined && (s.parent.flags & 32 /* SymbolFlags.Class */) !== 0
|
|
1374
|
+
? flags
|
|
1375
|
+
: flags & ~7 /* ModifierFlags.AccessibilityModifier */;
|
|
1376
|
+
}
|
|
1377
|
+
if ((s.checkFlags & 6 /* CheckFlags.Synthetic */) !== 0) {
|
|
1378
|
+
const access = (s.checkFlags & 1024 /* CheckFlags.ContainsPrivate */) !== 0
|
|
1379
|
+
? 2 /* ModifierFlags.Private */
|
|
1380
|
+
: (s.checkFlags & 256 /* CheckFlags.ContainsPublic */) !== 0
|
|
1381
|
+
? 1 /* ModifierFlags.Public */
|
|
1382
|
+
: 4 /* ModifierFlags.Protected */;
|
|
1383
|
+
const staticModifier = (s.checkFlags & 2048 /* CheckFlags.ContainsStatic */) !== 0 ? 256 /* ModifierFlags.Static */ : 0;
|
|
1384
|
+
return access | staticModifier;
|
|
1385
|
+
}
|
|
1386
|
+
if ((s.flags & 4194304 /* SymbolFlags.Prototype */) !== 0)
|
|
1387
|
+
return 1 /* ModifierFlags.Public */ | 256 /* ModifierFlags.Static */;
|
|
1388
|
+
return 0;
|
|
1389
|
+
}
|
|
1390
|
+
export function createUnionOrIntersectionProperty(c, containingType, name, skipObjectFunctionPropertyAugment) {
|
|
1391
|
+
let propFlags = 0 /* SymbolFlags.None */;
|
|
1392
|
+
let singleProp;
|
|
1393
|
+
let propSet;
|
|
1394
|
+
const indexTypes = [];
|
|
1395
|
+
const isUnion = (containingType.flags & 134217728 /* TypeFlags.Union */) !== 0;
|
|
1396
|
+
// Flags propagated when present in every constituent.
|
|
1397
|
+
let checkFlags = isUnion ? 0 /* CheckFlags.None */ : 8 /* CheckFlags.Readonly */;
|
|
1398
|
+
let optionalFlag = isUnion ? 0 /* SymbolFlags.None */ : 16777216 /* SymbolFlags.Optional */;
|
|
1399
|
+
let syntheticFlag = 4 /* CheckFlags.SyntheticMethod */;
|
|
1400
|
+
let mergedInstantiations = false;
|
|
1401
|
+
for (const current of containingType.types) {
|
|
1402
|
+
const t = getApparentType(c, current);
|
|
1403
|
+
if (isErrorType(c, t) || (t.flags & 262144 /* TypeFlags.Never */) !== 0)
|
|
1404
|
+
continue;
|
|
1405
|
+
const prop = getPropertyOfTypeEx(c, t, name, skipObjectFunctionPropertyAugment, false);
|
|
1406
|
+
if (prop !== undefined) {
|
|
1407
|
+
const modifiers = getDeclarationModifierFlagsFromSymbol(c, prop, false);
|
|
1408
|
+
if ((prop.flags & 106500 /* SymbolFlags.ClassMember */) !== 0) {
|
|
1409
|
+
if (isUnion)
|
|
1410
|
+
optionalFlag |= prop.flags & 16777216 /* SymbolFlags.Optional */;
|
|
1411
|
+
else
|
|
1412
|
+
optionalFlag &= prop.flags;
|
|
1413
|
+
}
|
|
1414
|
+
if (singleProp === undefined) {
|
|
1415
|
+
singleProp = prop;
|
|
1416
|
+
propFlags = prop.flags & 98304 /* SymbolFlags.Accessor */ || 4 /* SymbolFlags.Property */;
|
|
1417
|
+
}
|
|
1418
|
+
else if (prop !== singleProp) {
|
|
1419
|
+
const isInstantiation = getTargetSymbol(c, prop) === getTargetSymbol(c, singleProp);
|
|
1420
|
+
// Instantiations with identical types are equivalent; keep the first.
|
|
1421
|
+
if (isInstantiation && compareProperties(c, singleProp, prop, 3 /* ComparerKind.Equal */) === -1 /* Ternary.True */) {
|
|
1422
|
+
mergedInstantiations =
|
|
1423
|
+
singleProp.parent !== undefined &&
|
|
1424
|
+
getLocalTypeParametersOfClassOrInterfaceOrTypeAlias(c, singleProp.parent).length !== 0;
|
|
1425
|
+
}
|
|
1426
|
+
else {
|
|
1427
|
+
if (propSet === undefined)
|
|
1428
|
+
propSet = [singleProp];
|
|
1429
|
+
if (!propSet.includes(prop))
|
|
1430
|
+
propSet.push(prop);
|
|
1431
|
+
}
|
|
1432
|
+
// Accessor flags survive only when the same in all constituents.
|
|
1433
|
+
if ((propFlags & 98304 /* SymbolFlags.Accessor */) !== 0 &&
|
|
1434
|
+
(prop.flags & 98304 /* SymbolFlags.Accessor */) !== (propFlags & 98304 /* SymbolFlags.Accessor */))
|
|
1435
|
+
propFlags = (propFlags & ~98304 /* SymbolFlags.Accessor */) | 4 /* SymbolFlags.Property */;
|
|
1436
|
+
}
|
|
1437
|
+
if (isUnion && isReadonlySymbol(c, prop))
|
|
1438
|
+
checkFlags |= 8 /* CheckFlags.Readonly */;
|
|
1439
|
+
else if (!isUnion && !isReadonlySymbol(c, prop))
|
|
1440
|
+
checkFlags &= ~8 /* CheckFlags.Readonly */;
|
|
1441
|
+
if ((modifiers & 6 /* ModifierFlags.NonPublicAccessibilityModifier */) === 0)
|
|
1442
|
+
checkFlags |= 256 /* CheckFlags.ContainsPublic */;
|
|
1443
|
+
if ((modifiers & 4 /* ModifierFlags.Protected */) !== 0)
|
|
1444
|
+
checkFlags |= 512 /* CheckFlags.ContainsProtected */;
|
|
1445
|
+
if ((modifiers & 2 /* ModifierFlags.Private */) !== 0)
|
|
1446
|
+
checkFlags |= 1024 /* CheckFlags.ContainsPrivate */;
|
|
1447
|
+
if ((modifiers & 256 /* ModifierFlags.Static */) !== 0)
|
|
1448
|
+
checkFlags |= 2048 /* CheckFlags.ContainsStatic */;
|
|
1449
|
+
if (!isPrototypeProperty(prop))
|
|
1450
|
+
syntheticFlag = 2 /* CheckFlags.SyntheticProperty */;
|
|
1451
|
+
}
|
|
1452
|
+
else if (isUnion) {
|
|
1453
|
+
const indexInfo = !isLateBoundName(name) ? getApplicableIndexInfoForName(c, t, name) : undefined;
|
|
1454
|
+
if (indexInfo !== undefined) {
|
|
1455
|
+
propFlags = (propFlags & ~98304 /* SymbolFlags.Accessor */) | 4 /* SymbolFlags.Property */;
|
|
1456
|
+
checkFlags |= 32 /* CheckFlags.WritePartial */ | (indexInfo.isReadonly ? 8 /* CheckFlags.Readonly */ : 0);
|
|
1457
|
+
indexTypes.push(isTupleType(t) ? (getRestTypeOfTupleType(c, t) ?? c.undefinedType) : indexInfo.valueType);
|
|
1458
|
+
}
|
|
1459
|
+
else if (isObjectLiteralType(t) && (t.objectFlags & 4194304 /* ObjectFlags.ContainsSpread */) === 0) {
|
|
1460
|
+
checkFlags |= 32 /* CheckFlags.WritePartial */;
|
|
1461
|
+
indexTypes.push(c.undefinedType);
|
|
1462
|
+
}
|
|
1463
|
+
else
|
|
1464
|
+
checkFlags |= 16 /* CheckFlags.ReadPartial */;
|
|
1465
|
+
}
|
|
1466
|
+
}
|
|
1467
|
+
if (singleProp === undefined ||
|
|
1468
|
+
(isUnion &&
|
|
1469
|
+
(propSet !== undefined || (checkFlags & 48 /* CheckFlags.Partial */) !== 0) &&
|
|
1470
|
+
(checkFlags & (1024 /* CheckFlags.ContainsPrivate */ | 512 /* CheckFlags.ContainsProtected */)) !== 0 &&
|
|
1471
|
+
!(propSet !== undefined && hasCommonDeclaration(propSet))))
|
|
1472
|
+
// Missing, or private/protected in one constituent but missing or different in another.
|
|
1473
|
+
return undefined;
|
|
1474
|
+
if (propSet === undefined && (checkFlags & 16 /* CheckFlags.ReadPartial */) === 0 && indexTypes.length === 0) {
|
|
1475
|
+
if (!mergedInstantiations)
|
|
1476
|
+
return singleProp;
|
|
1477
|
+
// Merged instantiations get a clone without a union parent, so `Array<T>.length` prints as such.
|
|
1478
|
+
let singlePropType;
|
|
1479
|
+
let singlePropMapper;
|
|
1480
|
+
if ((singleProp.flags & 33554432 /* SymbolFlags.Transient */) !== 0) {
|
|
1481
|
+
const id = getSymbolId(singleProp);
|
|
1482
|
+
singlePropType = c.symbolTypes.get(id);
|
|
1483
|
+
singlePropMapper = c.symbolMappers.get(id);
|
|
1484
|
+
}
|
|
1485
|
+
const clone = createSymbolWithType(c, singleProp, singlePropType);
|
|
1486
|
+
if (singleProp.valueDeclaration !== undefined)
|
|
1487
|
+
clone.parent = getSymbol(singleProp.valueDeclaration)?.parent;
|
|
1488
|
+
const links = c.symbolLinks(clone);
|
|
1489
|
+
c.symbolContainingTypes.set(clone.id, containingType);
|
|
1490
|
+
c.symbolMappers.set(clone.id, singlePropMapper);
|
|
1491
|
+
links.writeType = getWriteTypeOfSymbol(c, singleProp);
|
|
1492
|
+
return clone;
|
|
1493
|
+
}
|
|
1494
|
+
const props = propSet ?? [singleProp];
|
|
1495
|
+
const declarations = [];
|
|
1496
|
+
let firstType;
|
|
1497
|
+
let nameType;
|
|
1498
|
+
const propTypes = [];
|
|
1499
|
+
let writeTypes;
|
|
1500
|
+
let firstValueDeclaration;
|
|
1501
|
+
let hasNonUniformValueDeclaration = false;
|
|
1502
|
+
for (const prop of props) {
|
|
1503
|
+
if (firstValueDeclaration === undefined)
|
|
1504
|
+
firstValueDeclaration = prop.valueDeclaration;
|
|
1505
|
+
else if (prop.valueDeclaration !== undefined && prop.valueDeclaration !== firstValueDeclaration)
|
|
1506
|
+
hasNonUniformValueDeclaration = true;
|
|
1507
|
+
for (const d of getDeclarations(prop))
|
|
1508
|
+
declarations.push(d);
|
|
1509
|
+
const t = getTypeOfSymbol(c, prop);
|
|
1510
|
+
if (firstType === undefined) {
|
|
1511
|
+
firstType = t;
|
|
1512
|
+
nameType = c.symbolNameTypes.get(getSymbolId(prop));
|
|
1513
|
+
}
|
|
1514
|
+
const writeType = getWriteTypeOfSymbol(c, prop);
|
|
1515
|
+
if (writeTypes !== undefined || writeType !== t) {
|
|
1516
|
+
if (writeTypes === undefined)
|
|
1517
|
+
writeTypes = propTypes.slice();
|
|
1518
|
+
writeTypes.push(writeType);
|
|
1519
|
+
}
|
|
1520
|
+
if (t !== firstType)
|
|
1521
|
+
checkFlags |= 64 /* CheckFlags.HasNonUniformType */;
|
|
1522
|
+
if (isLiteralType(t) || isPatternLiteralType(c, t))
|
|
1523
|
+
checkFlags |= 128 /* CheckFlags.HasLiteralType */;
|
|
1524
|
+
if ((t.flags & 262144 /* TypeFlags.Never */) !== 0 && t !== c.uniqueLiteralType)
|
|
1525
|
+
checkFlags |= 131072 /* CheckFlags.HasNeverType */;
|
|
1526
|
+
propTypes.push(t);
|
|
1527
|
+
}
|
|
1528
|
+
for (const t of indexTypes)
|
|
1529
|
+
propTypes.push(t);
|
|
1530
|
+
const result = c.newSymbolWithCheckFlags(propFlags | optionalFlag, name, checkFlags | syntheticFlag);
|
|
1531
|
+
setDeclarations(result, declarations);
|
|
1532
|
+
if (!hasNonUniformValueDeclaration && firstValueDeclaration !== undefined) {
|
|
1533
|
+
result.valueDeclaration = firstValueDeclaration;
|
|
1534
|
+
result.parent = getSymbol(firstValueDeclaration)?.parent;
|
|
1535
|
+
}
|
|
1536
|
+
const id = getSymbolId(result);
|
|
1537
|
+
c.symbolContainingTypes.set(id, containingType);
|
|
1538
|
+
c.symbolNameTypes.set(id, nameType);
|
|
1539
|
+
if (propTypes.length > 2) {
|
|
1540
|
+
// Defer normalization of possibly large constituent lists.
|
|
1541
|
+
result.checkFlags |= 65536 /* CheckFlags.DeferredType */;
|
|
1542
|
+
const links = c.symbolLinks(result);
|
|
1543
|
+
links.deferralParent = containingType;
|
|
1544
|
+
links.deferralConstituents = propTypes;
|
|
1545
|
+
links.deferralWriteConstituents = writeTypes;
|
|
1546
|
+
return result;
|
|
1547
|
+
}
|
|
1548
|
+
c.symbolTypes.set(id, isUnion ? getUnionType(c, propTypes) : getIntersectionType(c, propTypes));
|
|
1549
|
+
if (writeTypes !== undefined)
|
|
1550
|
+
c.symbolLinks(result).writeType = isUnion ? getUnionType(c, writeTypes) : getIntersectionType(c, writeTypes);
|
|
1551
|
+
return result;
|
|
1552
|
+
}
|
|
1553
|
+
export function isObjectLiteralType(t) {
|
|
1554
|
+
return (t.objectFlags & 128 /* ObjectFlags.ObjectLiteral */) !== 0;
|
|
1555
|
+
}
|
|
1556
|
+
export function getTargetSymbol(c, s) {
|
|
1557
|
+
return (s.checkFlags & 1 /* CheckFlags.Instantiated */) !== 0 ? c.symbolTargets.get(getSymbolId(s)) : s;
|
|
1558
|
+
}
|
|
1559
|
+
export function isPrototypeProperty(symbol) {
|
|
1560
|
+
return (symbol.flags & 8192 /* SymbolFlags.Method */) !== 0 || (symbol.checkFlags & 4 /* CheckFlags.SyntheticMethod */) !== 0;
|
|
1561
|
+
}
|
|
1562
|
+
function hasCommonDeclaration(symbols) {
|
|
1563
|
+
let common;
|
|
1564
|
+
for (const symbol of symbols) {
|
|
1565
|
+
if (declarationCount(symbol) === 0)
|
|
1566
|
+
return false;
|
|
1567
|
+
if (common === undefined) {
|
|
1568
|
+
common = new Set(getDeclarations(symbol));
|
|
1569
|
+
continue;
|
|
1570
|
+
}
|
|
1571
|
+
const next = new Set();
|
|
1572
|
+
for (const d of getDeclarations(symbol))
|
|
1573
|
+
if (common.has(d))
|
|
1574
|
+
next.add(d);
|
|
1575
|
+
if (next.size === 0)
|
|
1576
|
+
return false;
|
|
1577
|
+
common = next;
|
|
1578
|
+
}
|
|
1579
|
+
return common !== undefined && common.size !== 0;
|
|
1580
|
+
}
|
|
1581
|
+
export function createSymbolWithType(c, source, t) {
|
|
1582
|
+
const symbol = c.newSymbolWithCheckFlags(source.flags, source.name, source.checkFlags & 8 /* CheckFlags.Readonly */);
|
|
1583
|
+
copyDeclarations(symbol, source);
|
|
1584
|
+
symbol.parent = source.parent;
|
|
1585
|
+
symbol.valueDeclaration = source.valueDeclaration;
|
|
1586
|
+
const id = getSymbolId(symbol);
|
|
1587
|
+
c.symbolTypes.set(id, t);
|
|
1588
|
+
c.symbolTargets.set(id, source);
|
|
1589
|
+
c.symbolNameTypes.set(id, c.symbolNameTypes.get(getSymbolId(source)));
|
|
1590
|
+
return symbol;
|
|
1591
|
+
}
|
|
1592
|
+
// ---- Signatures and index infos
|
|
1593
|
+
export function getSignaturesOfType(c, t, kind) {
|
|
1594
|
+
return getSignaturesOfStructuredType(c, isOwnReducedApparentType(t) ? t : getReducedApparentTypeWorker(c, t), kind);
|
|
1595
|
+
}
|
|
1596
|
+
export function getSignaturesOfStructuredType(c, t, kind) {
|
|
1597
|
+
if ((t.flags & 403701760 /* TypeFlags.StructuredType */) === 0)
|
|
1598
|
+
return emptySignatures;
|
|
1599
|
+
const resolved = resolveStructuredTypeMembers(c, t);
|
|
1600
|
+
return kind === 0 /* SignatureKind.Call */ ? resolved.callSignatures : resolved.constructSignatures;
|
|
1601
|
+
}
|
|
1602
|
+
export function getIndexInfosOfType(c, t) {
|
|
1603
|
+
return getIndexInfosOfStructuredType(c, isOwnReducedApparentType(t) ? t : getReducedApparentTypeWorker(c, t));
|
|
1604
|
+
}
|
|
1605
|
+
export function getIndexInfosOfStructuredType(c, t) {
|
|
1606
|
+
return (t.flags & 403701760 /* TypeFlags.StructuredType */) !== 0 ? resolveStructuredTypeMembers(c, t).indexInfos : emptyIndexInfos;
|
|
1607
|
+
}
|
|
1608
|
+
export function getIndexInfoOfType(c, t, keyType) {
|
|
1609
|
+
return findIndexInfo(getIndexInfosOfType(c, t), keyType);
|
|
1610
|
+
}
|
|
1611
|
+
export function getIndexTypeOfType(c, t, keyType) {
|
|
1612
|
+
const info = getIndexInfoOfType(c, t, keyType);
|
|
1613
|
+
return info !== undefined ? info.valueType : undefined;
|
|
1614
|
+
}
|
|
1615
|
+
export function getApplicableIndexInfo(c, t, keyType) {
|
|
1616
|
+
return findApplicableIndexInfo(c, getIndexInfosOfType(c, t), keyType);
|
|
1617
|
+
}
|
|
1618
|
+
export function getApplicableIndexInfoForName(c, t, name) {
|
|
1619
|
+
return getApplicableIndexInfo(c, t, isLateBoundName(name) ? c.esSymbolType : getStringLiteralType(c, name));
|
|
1620
|
+
}
|
|
1621
|
+
export function findApplicableIndexInfo(c, indexInfos, keyType) {
|
|
1622
|
+
// `string` index signatures apply only when no other one does.
|
|
1623
|
+
let stringIndexInfo;
|
|
1624
|
+
// The list of applicable infos is built only when more than one applies.
|
|
1625
|
+
let first;
|
|
1626
|
+
let applicable;
|
|
1627
|
+
for (const info of indexInfos) {
|
|
1628
|
+
if (info.keyType === c.stringType)
|
|
1629
|
+
stringIndexInfo = info;
|
|
1630
|
+
else if (isApplicableIndexType(c, keyType, info.keyType)) {
|
|
1631
|
+
if (first === undefined)
|
|
1632
|
+
first = info;
|
|
1633
|
+
else if (applicable === undefined)
|
|
1634
|
+
applicable = [first, info];
|
|
1635
|
+
else
|
|
1636
|
+
applicable.push(info);
|
|
1637
|
+
}
|
|
1638
|
+
}
|
|
1639
|
+
if (first === undefined)
|
|
1640
|
+
return stringIndexInfo !== undefined && isApplicableIndexType(c, keyType, c.stringType)
|
|
1641
|
+
? stringIndexInfo
|
|
1642
|
+
: undefined;
|
|
1643
|
+
if (applicable === undefined)
|
|
1644
|
+
return first;
|
|
1645
|
+
// Several apply: a synthetic info; its key type is unused.
|
|
1646
|
+
let isReadonly = true;
|
|
1647
|
+
const types = [];
|
|
1648
|
+
for (const info of applicable) {
|
|
1649
|
+
types.push(info.valueType);
|
|
1650
|
+
if (!info.isReadonly)
|
|
1651
|
+
isReadonly = false;
|
|
1652
|
+
}
|
|
1653
|
+
return new IndexInfo(c.unknownType, getIntersectionType(c, types), isReadonly, undefined, []);
|
|
1654
|
+
}
|
|
1655
|
+
export function isApplicableIndexType(c, source, target) {
|
|
1656
|
+
// Types with many template literal index signatures would relate most pairs of their keys only
|
|
1657
|
+
// to find that the start or end texts differ.
|
|
1658
|
+
if ((target.flags & 4194304 /* TypeFlags.TemplateLiteral */) !== 0 &&
|
|
1659
|
+
isUnmatchedTemplateLiteralKey(source, target))
|
|
1660
|
+
return false;
|
|
1661
|
+
// `string` applies to keys assignable to string or number; `number` to numeric strings too.
|
|
1662
|
+
return (isTypeAssignableTo(c, source, target) ||
|
|
1663
|
+
(target === c.stringType && isTypeAssignableTo(c, source, c.numberType)) ||
|
|
1664
|
+
(target === c.numberType &&
|
|
1665
|
+
(source === c.numericStringType ||
|
|
1666
|
+
((source.flags & 1024 /* TypeFlags.StringLiteral */) !== 0 && isNumericLiteralName(source.stringValue)))));
|
|
1667
|
+
}
|
|
1668
|
+
export function isArrayLikeType(c, t) {
|
|
1669
|
+
// Readonly arrays are array-like: anything assignable to `readonly any[]`.
|
|
1670
|
+
return (isArrayType(c, t) || ((t.flags & 12 /* TypeFlags.Nullable */) === 0 && isTypeAssignableTo(c, t, c.anyReadonlyArrayType)));
|
|
1671
|
+
}
|
|
1672
|
+
function isArrayType(c, t) {
|
|
1673
|
+
if ((t.objectFlags & 4 /* ObjectFlags.Reference */) === 0)
|
|
1674
|
+
return false;
|
|
1675
|
+
const target = t.target;
|
|
1676
|
+
return target === c.globalArrayType || target === c.globalReadonlyArrayType;
|
|
1677
|
+
}
|
|
1678
|
+
// ---- Apparent and reduced types
|
|
1679
|
+
/**
|
|
1680
|
+
* Type parameters' base constraints; primitives' wrapper object types; otherwise the type itself.
|
|
1681
|
+
* Most types are the last case: that test is small enough to inline into callers.
|
|
1682
|
+
*/
|
|
1683
|
+
export function getApparentType(c, t) {
|
|
1684
|
+
return isOwnApparentType(t) ? t : getApparentTypeWorker(c, t);
|
|
1685
|
+
}
|
|
1686
|
+
/**
|
|
1687
|
+
* Whether getApparentType returns `t` itself because no rule applies to it: no constraint, wrapper
|
|
1688
|
+
* type, mapped type or intersection, and not `unknown` (whose apparent type depends on the options).
|
|
1689
|
+
*/
|
|
1690
|
+
function isOwnApparentType(t) {
|
|
1691
|
+
const flags = t.flags;
|
|
1692
|
+
return ((flags &
|
|
1693
|
+
(132644864 /* TypeFlags.Instantiable */ |
|
|
1694
|
+
268435456 /* TypeFlags.Intersection */ |
|
|
1695
|
+
12583968 /* TypeFlags.StringLike */ |
|
|
1696
|
+
67648 /* TypeFlags.NumberLike */ |
|
|
1697
|
+
4224 /* TypeFlags.BigIntLike */ |
|
|
1698
|
+
8448 /* TypeFlags.BooleanLike */ |
|
|
1699
|
+
16896 /* TypeFlags.ESSymbolLike */ |
|
|
1700
|
+
131072 /* TypeFlags.NonPrimitive */ |
|
|
1701
|
+
2097152 /* TypeFlags.Index */ |
|
|
1702
|
+
2 /* TypeFlags.Unknown */)) ===
|
|
1703
|
+
0 &&
|
|
1704
|
+
((flags & 1048576 /* TypeFlags.Object */) === 0 || (t.objectFlags & 32 /* ObjectFlags.Mapped */) === 0));
|
|
1705
|
+
}
|
|
1706
|
+
function getApparentTypeWorker(c, t) {
|
|
1707
|
+
const originalType = t;
|
|
1708
|
+
if ((t.flags & 132644864 /* TypeFlags.Instantiable */) !== 0)
|
|
1709
|
+
t = getBaseConstraintOfType(c, t) ?? c.unknownType;
|
|
1710
|
+
const flags = t.flags;
|
|
1711
|
+
if ((t.objectFlags & 32 /* ObjectFlags.Mapped */) !== 0 && (flags & 1048576 /* TypeFlags.Object */) !== 0)
|
|
1712
|
+
return getApparentTypeOfMappedType(c, t);
|
|
1713
|
+
if ((t.objectFlags & 4 /* ObjectFlags.Reference */) !== 0 && (flags & 1048576 /* TypeFlags.Object */) !== 0 && t !== originalType)
|
|
1714
|
+
return getTypeWithThisArgument(c, t, originalType, false);
|
|
1715
|
+
if ((flags & 268435456 /* TypeFlags.Intersection */) !== 0)
|
|
1716
|
+
return getApparentTypeOfIntersectionType(c, t, originalType);
|
|
1717
|
+
if ((flags & 12583968 /* TypeFlags.StringLike */) !== 0)
|
|
1718
|
+
return c.globalStringType;
|
|
1719
|
+
if ((flags & 67648 /* TypeFlags.NumberLike */) !== 0)
|
|
1720
|
+
return c.globalNumberType;
|
|
1721
|
+
if ((flags & 4224 /* TypeFlags.BigIntLike */) !== 0)
|
|
1722
|
+
return getGlobalBigIntType(c);
|
|
1723
|
+
if ((flags & 8448 /* TypeFlags.BooleanLike */) !== 0)
|
|
1724
|
+
return c.globalBooleanType;
|
|
1725
|
+
if ((flags & 16896 /* TypeFlags.ESSymbolLike */) !== 0)
|
|
1726
|
+
return getGlobalESSymbolType(c);
|
|
1727
|
+
if ((flags & 131072 /* TypeFlags.NonPrimitive */) !== 0)
|
|
1728
|
+
return c.emptyObjectType;
|
|
1729
|
+
if ((flags & 2097152 /* TypeFlags.Index */) !== 0)
|
|
1730
|
+
return c.stringNumberSymbolType;
|
|
1731
|
+
if ((flags & 2 /* TypeFlags.Unknown */) !== 0 && !c.strictNullChecks)
|
|
1732
|
+
return c.emptyObjectType;
|
|
1733
|
+
return t;
|
|
1734
|
+
}
|
|
1735
|
+
function getApparentTypeOfMappedType(c, t) {
|
|
1736
|
+
const side = sideOf(c, t);
|
|
1737
|
+
if (side.resolvedApparentType === undefined)
|
|
1738
|
+
side.resolvedApparentType = getResolvedApparentTypeOfMappedType(c, t);
|
|
1739
|
+
return side.resolvedApparentType;
|
|
1740
|
+
}
|
|
1741
|
+
function getResolvedApparentTypeOfMappedType(c, t) {
|
|
1742
|
+
const target = mappedTypeTarget(t);
|
|
1743
|
+
const typeVariable = getHomomorphicTypeVariable(c, target);
|
|
1744
|
+
if (typeVariable !== undefined && target.declaration.nameType === undefined) {
|
|
1745
|
+
// A homomorphic mapped type over an array or tuple constraint maps the constraint.
|
|
1746
|
+
const modifiersType = getModifiersTypeFromMappedType(c, t);
|
|
1747
|
+
const baseConstraint = isGenericMappedType(c, modifiersType)
|
|
1748
|
+
? getApparentTypeOfMappedType(c, modifiersType)
|
|
1749
|
+
: getBaseConstraintOfType(c, modifiersType);
|
|
1750
|
+
if (baseConstraint !== undefined &&
|
|
1751
|
+
everyType(baseConstraint, (u) => isArrayOrTupleType(c, u) || isArrayOrTupleOrIntersection(c, u)))
|
|
1752
|
+
return instantiateType(c, target, prependTypeMapping(typeVariable, baseConstraint, t.mapper));
|
|
1753
|
+
}
|
|
1754
|
+
return t;
|
|
1755
|
+
}
|
|
1756
|
+
export function isArrayOrTupleOrIntersection(c, t) {
|
|
1757
|
+
if ((t.flags & 268435456 /* TypeFlags.Intersection */) === 0)
|
|
1758
|
+
return false;
|
|
1759
|
+
for (const u of typesOf(t))
|
|
1760
|
+
if (!isArrayOrTupleType(c, u))
|
|
1761
|
+
return false;
|
|
1762
|
+
return true;
|
|
1763
|
+
}
|
|
1764
|
+
function getApparentTypeOfIntersectionType(c, t, thisArgument) {
|
|
1765
|
+
if (t.id === thisArgument.id) {
|
|
1766
|
+
const side = sideOf(c, t);
|
|
1767
|
+
if (side.resolvedApparentType === undefined)
|
|
1768
|
+
side.resolvedApparentType = getTypeWithThisArgument(c, t, thisArgument, true);
|
|
1769
|
+
return side.resolvedApparentType;
|
|
1770
|
+
}
|
|
1771
|
+
const key = cachedTypeKey(4 /* CachedTypeKind.Apparent */, thisArgument.id);
|
|
1772
|
+
let result = c.cachedTypesById.get(key);
|
|
1773
|
+
if (result === undefined) {
|
|
1774
|
+
result = getTypeWithThisArgument(c, t, thisArgument, true);
|
|
1775
|
+
c.cachedTypesById.set(key, result);
|
|
1776
|
+
}
|
|
1777
|
+
return result;
|
|
1778
|
+
}
|
|
1779
|
+
export function getTypeWithThisArgument(c, t, thisArgument, needApparentType) {
|
|
1780
|
+
if ((t.objectFlags & 4 /* ObjectFlags.Reference */) !== 0 && (t.flags & 1048576 /* TypeFlags.Object */) !== 0) {
|
|
1781
|
+
const target = t.target;
|
|
1782
|
+
const typeArguments = getTypeArguments(c, t);
|
|
1783
|
+
const count = typeArguments.length;
|
|
1784
|
+
if (target.typeParameterCount() !== count)
|
|
1785
|
+
return t;
|
|
1786
|
+
const withThis = [];
|
|
1787
|
+
for (let i = 0; i < count; i++)
|
|
1788
|
+
withThis.push(typeArguments[i]);
|
|
1789
|
+
withThis.push(thisArgument ?? target.thisType);
|
|
1790
|
+
return createTypeReference(c, target, withThis);
|
|
1791
|
+
}
|
|
1792
|
+
if ((t.flags & 268435456 /* TypeFlags.Intersection */) !== 0) {
|
|
1793
|
+
const types = typesOf(t);
|
|
1794
|
+
let changed = false;
|
|
1795
|
+
const newTypes = [];
|
|
1796
|
+
for (const u of types) {
|
|
1797
|
+
const n = getTypeWithThisArgument(c, u, thisArgument, needApparentType);
|
|
1798
|
+
if (n !== u)
|
|
1799
|
+
changed = true;
|
|
1800
|
+
newTypes.push(n);
|
|
1801
|
+
}
|
|
1802
|
+
return changed ? getIntersectionType(c, newTypes) : t;
|
|
1803
|
+
}
|
|
1804
|
+
return needApparentType ? getApparentType(c, t) : t;
|
|
1805
|
+
}
|
|
1806
|
+
/**
|
|
1807
|
+
* Unions with reducible intersections are reduced; intersections with mutually exclusive
|
|
1808
|
+
* discriminants are `never`.
|
|
1809
|
+
*/
|
|
1810
|
+
export function getReducedType(c, t) {
|
|
1811
|
+
if ((t.flags & 134217728 /* TypeFlags.Union */) !== 0) {
|
|
1812
|
+
if ((t.objectFlags & 33554432 /* ObjectFlags.ContainsIntersections */) !== 0) {
|
|
1813
|
+
const side = sideOf(c, t);
|
|
1814
|
+
if (side.resolvedReducedType !== undefined)
|
|
1815
|
+
return side.resolvedReducedType;
|
|
1816
|
+
const reduced = getReducedUnionType(c, t);
|
|
1817
|
+
side.resolvedReducedType = reduced;
|
|
1818
|
+
return reduced;
|
|
1819
|
+
}
|
|
1820
|
+
}
|
|
1821
|
+
else if ((t.flags & 268435456 /* TypeFlags.Intersection */) !== 0) {
|
|
1822
|
+
const side = sideOf(c, t);
|
|
1823
|
+
if ((side.objectFlags & 33554432 /* ObjectFlags.IsNeverIntersectionComputed */) === 0) {
|
|
1824
|
+
side.objectFlags |= 33554432 /* ObjectFlags.IsNeverIntersectionComputed */;
|
|
1825
|
+
if (hasNeverReducedProperty(c, t))
|
|
1826
|
+
side.objectFlags |= 67108864 /* ObjectFlags.IsNeverIntersection */;
|
|
1827
|
+
}
|
|
1828
|
+
if ((side.objectFlags & 67108864 /* ObjectFlags.IsNeverIntersection */) !== 0)
|
|
1829
|
+
return c.neverType;
|
|
1830
|
+
}
|
|
1831
|
+
return t;
|
|
1832
|
+
}
|
|
1833
|
+
/**
|
|
1834
|
+
* Whether a property of the intersection `t` reduces it to never, without resolving all of its
|
|
1835
|
+
* properties. Such a property is one that createUnionOrIntersectionProperty combines from different
|
|
1836
|
+
* properties of two or more constituents, with a literal type among them (a discriminant whose
|
|
1837
|
+
* types intersect to never) or a private one (conflicting private properties); a property read from
|
|
1838
|
+
* a type is never one itself, since an intersection with one reduces to never and has no
|
|
1839
|
+
* properties. So only names with different properties in two constituents, one of them literal or
|
|
1840
|
+
* private, are combined, and the costliest constituent's properties are only looked up by name.
|
|
1841
|
+
*/
|
|
1842
|
+
function hasNeverReducedProperty(c, t) {
|
|
1843
|
+
const members = sideOf(c, t).membersOf;
|
|
1844
|
+
const resolved = members !== undefined ? members.resolvedProperties : undefined;
|
|
1845
|
+
if (resolved !== undefined) {
|
|
1846
|
+
for (const p of resolved)
|
|
1847
|
+
if (isNeverReducedProperty(c, p))
|
|
1848
|
+
return true;
|
|
1849
|
+
return false;
|
|
1850
|
+
}
|
|
1851
|
+
const skipped = getCostliestConstituent(c, t);
|
|
1852
|
+
// The other constituents' properties by name, without repeating a symbol.
|
|
1853
|
+
const byName = new Map();
|
|
1854
|
+
for (const current of t.types) {
|
|
1855
|
+
if (current === skipped)
|
|
1856
|
+
continue;
|
|
1857
|
+
for (const prop of getPropertiesOfType(c, current)) {
|
|
1858
|
+
const props = byName.get(prop.name);
|
|
1859
|
+
if (props === undefined)
|
|
1860
|
+
byName.set(prop.name, [prop]);
|
|
1861
|
+
else if (!props.includes(prop))
|
|
1862
|
+
props.push(prop);
|
|
1863
|
+
}
|
|
1864
|
+
}
|
|
1865
|
+
let skippedType;
|
|
1866
|
+
if (skipped !== undefined) {
|
|
1867
|
+
skippedType = getApparentType(c, skipped);
|
|
1868
|
+
if (isErrorType(c, skippedType) || (skippedType.flags & 262144 /* TypeFlags.Never */) !== 0)
|
|
1869
|
+
skippedType = undefined;
|
|
1870
|
+
}
|
|
1871
|
+
for (const [name, props] of byName) {
|
|
1872
|
+
if (skippedType !== undefined) {
|
|
1873
|
+
const prop = getPropertyOfTypeEx(c, skippedType, name, true, false);
|
|
1874
|
+
if (prop !== undefined && !props.includes(prop))
|
|
1875
|
+
props.push(prop);
|
|
1876
|
+
}
|
|
1877
|
+
if (props.length < 2 || !someLiteralOrPrivateProperty(c, props))
|
|
1878
|
+
continue;
|
|
1879
|
+
const combined = getPropertyOfUnionOrIntersectionType(c, t, name, true);
|
|
1880
|
+
if (combined !== undefined && isNeverReducedProperty(c, combined))
|
|
1881
|
+
return true;
|
|
1882
|
+
}
|
|
1883
|
+
return false;
|
|
1884
|
+
}
|
|
1885
|
+
/** Whether a property of `props` has a literal type or is private, as createUnionOrIntersectionProperty tests them. */
|
|
1886
|
+
function someLiteralOrPrivateProperty(c, props) {
|
|
1887
|
+
for (const prop of props) {
|
|
1888
|
+
if ((getDeclarationModifierFlagsFromSymbol(c, prop, false) & 2 /* ModifierFlags.Private */) !== 0)
|
|
1889
|
+
return true;
|
|
1890
|
+
const t = getTypeOfSymbol(c, prop);
|
|
1891
|
+
if (isLiteralType(t) || isPatternLiteralType(c, t))
|
|
1892
|
+
return true;
|
|
1893
|
+
}
|
|
1894
|
+
return false;
|
|
1895
|
+
}
|
|
1896
|
+
/**
|
|
1897
|
+
* The object constituent of `t` whose properties cost the most to read: the one with the most members
|
|
1898
|
+
* not instantiated yet, or else the one with the most properties.
|
|
1899
|
+
*/
|
|
1900
|
+
function getCostliestConstituent(c, t) {
|
|
1901
|
+
let costliest;
|
|
1902
|
+
let costliestPending = 0;
|
|
1903
|
+
let costliestProperties = 0;
|
|
1904
|
+
for (const current of t.types) {
|
|
1905
|
+
const apparent = getReducedApparentType(c, current);
|
|
1906
|
+
if ((apparent.flags & 1048576 /* TypeFlags.Object */) === 0)
|
|
1907
|
+
continue;
|
|
1908
|
+
const resolved = resolveStructuredTypeMembers(c, apparent);
|
|
1909
|
+
const pending = resolved.pendingMembers;
|
|
1910
|
+
if (pending !== undefined && pending.materializedProperties === undefined) {
|
|
1911
|
+
const size = pending.positions.size;
|
|
1912
|
+
if (size > costliestPending) {
|
|
1913
|
+
costliest = current;
|
|
1914
|
+
costliestPending = size;
|
|
1915
|
+
}
|
|
1916
|
+
}
|
|
1917
|
+
else if (costliestPending === 0 && resolved.propertiesValue.length > costliestProperties) {
|
|
1918
|
+
costliest = current;
|
|
1919
|
+
costliestProperties = resolved.propertiesValue.length;
|
|
1920
|
+
}
|
|
1921
|
+
}
|
|
1922
|
+
return costliest;
|
|
1923
|
+
}
|
|
1924
|
+
function getReducedUnionType(c, union) {
|
|
1925
|
+
let changed = false;
|
|
1926
|
+
const reducedTypes = [];
|
|
1927
|
+
for (const u of union.types) {
|
|
1928
|
+
const r = getReducedType(c, u);
|
|
1929
|
+
if (r !== u)
|
|
1930
|
+
changed = true;
|
|
1931
|
+
reducedTypes.push(r);
|
|
1932
|
+
}
|
|
1933
|
+
if (!changed)
|
|
1934
|
+
return union;
|
|
1935
|
+
const reduced = getUnionType(c, reducedTypes);
|
|
1936
|
+
if ((reduced.flags & 134217728 /* TypeFlags.Union */) !== 0)
|
|
1937
|
+
sideOf(c, reduced).resolvedReducedType = reduced;
|
|
1938
|
+
return reduced;
|
|
1939
|
+
}
|
|
1940
|
+
function isNeverReducedProperty(c, prop) {
|
|
1941
|
+
return isDiscriminantWithNeverType(c, prop) || isConflictingPrivateProperty(prop);
|
|
1942
|
+
}
|
|
1943
|
+
export function isDiscriminantWithNeverType(c, prop) {
|
|
1944
|
+
// A synthetic required property with non-uniform literal types, none never, reducing to never.
|
|
1945
|
+
return ((prop.flags & 16777216 /* SymbolFlags.Optional */) === 0 &&
|
|
1946
|
+
(prop.checkFlags & (192 /* CheckFlags.NonUniformAndLiteral */ | 131072 /* CheckFlags.HasNeverType */)) ===
|
|
1947
|
+
192 /* CheckFlags.NonUniformAndLiteral */ &&
|
|
1948
|
+
(getTypeOfSymbol(c, prop).flags & 262144 /* TypeFlags.Never */) !== 0);
|
|
1949
|
+
}
|
|
1950
|
+
export function isConflictingPrivateProperty(prop) {
|
|
1951
|
+
return prop.valueDeclaration === undefined && (prop.checkFlags & 1024 /* CheckFlags.ContainsPrivate */) !== 0;
|
|
1952
|
+
}
|
|
1953
|
+
export function getReducedApparentType(c, t) {
|
|
1954
|
+
return isOwnReducedApparentType(t) ? t : getReducedApparentTypeWorker(c, t);
|
|
1955
|
+
}
|
|
1956
|
+
/**
|
|
1957
|
+
* Whether getReducedApparentType returns `t` itself: it is its own apparent type, and no reduction
|
|
1958
|
+
* applies to it (getReducedType changes only intersections and unions with intersections). The hot
|
|
1959
|
+
* member lookups below test this inline before calling getReducedApparentTypeWorker.
|
|
1960
|
+
*/
|
|
1961
|
+
function isOwnReducedApparentType(t) {
|
|
1962
|
+
return (isOwnApparentType(t) &&
|
|
1963
|
+
((t.flags & 134217728 /* TypeFlags.Union */) === 0 || (t.objectFlags & 33554432 /* ObjectFlags.ContainsIntersections */) === 0));
|
|
1964
|
+
}
|
|
1965
|
+
function getReducedApparentTypeWorker(c, t) {
|
|
1966
|
+
// Apparent types may be unreduced, so reduce before and after. Reducing is idempotent, so an
|
|
1967
|
+
// apparent type that is the reduced type itself needs no second pass.
|
|
1968
|
+
const reduced = getReducedType(c, t);
|
|
1969
|
+
const apparent = getApparentType(c, reduced);
|
|
1970
|
+
return apparent === reduced ? reduced : getReducedType(c, apparent);
|
|
1971
|
+
}
|
|
1972
|
+
// ---- Base constraints
|
|
1973
|
+
export function getBaseConstraintOfType(c, t) {
|
|
1974
|
+
if ((t.flags &
|
|
1975
|
+
(117964800 /* TypeFlags.InstantiableNonPrimitive */ |
|
|
1976
|
+
402653184 /* TypeFlags.UnionOrIntersection */ |
|
|
1977
|
+
4194304 /* TypeFlags.TemplateLiteral */ |
|
|
1978
|
+
8388608 /* TypeFlags.StringMapping */ |
|
|
1979
|
+
2097152 /* TypeFlags.Index */)) !==
|
|
1980
|
+
0 ||
|
|
1981
|
+
isGenericTupleType(t)) {
|
|
1982
|
+
const constraint = getResolvedBaseConstraint(c, t);
|
|
1983
|
+
return constraint !== c.noConstraintType && constraint !== c.circularConstraintType ? constraint : undefined;
|
|
1984
|
+
}
|
|
1985
|
+
return undefined;
|
|
1986
|
+
}
|
|
1987
|
+
export function getBaseConstraintOrType(c, t) {
|
|
1988
|
+
return getBaseConstraintOfType(c, t) ?? t;
|
|
1989
|
+
}
|
|
1990
|
+
/** `t` with each constituent replaced by its base constraint. */
|
|
1991
|
+
export function mapToBaseConstraintOrType(c, t) {
|
|
1992
|
+
return mapType(c, t, (u) => getBaseConstraintOrType(c, u));
|
|
1993
|
+
}
|
|
1994
|
+
function hasConstrainedTypeData(t) {
|
|
1995
|
+
return ((t.flags & (393983 /* TypeFlags.Intrinsic */ | 15360 /* TypeFlags.Literal */ | 16384 /* TypeFlags.UniqueESSymbol */ | 65536 /* TypeFlags.Enum */)) === 0 ||
|
|
1996
|
+
(t.flags & 536346624 /* TypeFlags.StructuredOrInstantiable */) !== 0);
|
|
1997
|
+
}
|
|
1998
|
+
export function getResolvedBaseConstraint(c, t, stack) {
|
|
1999
|
+
if (!hasConstrainedTypeData(t))
|
|
2000
|
+
return t;
|
|
2001
|
+
if (t.resolvedBaseConstraint !== undefined)
|
|
2002
|
+
return t.resolvedBaseConstraint;
|
|
2003
|
+
const side = sideOf(c, t);
|
|
2004
|
+
if (side.resolvedBaseConstraint !== undefined)
|
|
2005
|
+
return side.resolvedBaseConstraint;
|
|
2006
|
+
if (!pushTypeResolution(c, t, 4 /* TypeSystemPropertyName.ResolvedBaseConstraint */))
|
|
2007
|
+
return c.circularConstraintType;
|
|
2008
|
+
let constraint;
|
|
2009
|
+
// At least 10 levels; up to 50 without deeply nested types on the stack.
|
|
2010
|
+
const identity = getRecursionIdentity(t);
|
|
2011
|
+
const current = stack ?? [];
|
|
2012
|
+
if (current.length < 10 || (current.length < 50 && !current.includes(identity)))
|
|
2013
|
+
constraint = computeBaseConstraint(c, getSimplifiedType(c, t, false), current.concat([identity]));
|
|
2014
|
+
if (!popTypeResolution(c)) {
|
|
2015
|
+
if ((t.flags & 524288 /* TypeFlags.TypeParameter */) !== 0) {
|
|
2016
|
+
const errorNode = getConstraintDeclaration(t);
|
|
2017
|
+
if (errorNode !== undefined)
|
|
2018
|
+
c.error(errorNode, 491 /* Diagnostics.Type_parameter_0_has_a_circular_constraint */, typeToString(c, t));
|
|
2019
|
+
}
|
|
2020
|
+
constraint = c.circularConstraintType;
|
|
2021
|
+
}
|
|
2022
|
+
if (constraint === undefined)
|
|
2023
|
+
constraint = c.noConstraintType;
|
|
2024
|
+
if (side.resolvedBaseConstraint === undefined)
|
|
2025
|
+
side.resolvedBaseConstraint = constraint;
|
|
2026
|
+
return constraint;
|
|
2027
|
+
}
|
|
2028
|
+
function computeBaseConstraint(c, t, stack) {
|
|
2029
|
+
const flags = t.flags;
|
|
2030
|
+
if ((flags & 524288 /* TypeFlags.TypeParameter */) !== 0) {
|
|
2031
|
+
const constraint = getConstraintFromTypeParameter(c, t);
|
|
2032
|
+
return t.isThisType ? constraint : getNextBaseConstraint(c, constraint, stack);
|
|
2033
|
+
}
|
|
2034
|
+
if ((flags & 402653184 /* TypeFlags.UnionOrIntersection */) !== 0) {
|
|
2035
|
+
const types = typesOf(t);
|
|
2036
|
+
const constraints = [];
|
|
2037
|
+
let different = false;
|
|
2038
|
+
for (const s of types) {
|
|
2039
|
+
const constraint = getNextBaseConstraint(c, s, stack);
|
|
2040
|
+
if (constraint !== undefined) {
|
|
2041
|
+
if (constraint !== s)
|
|
2042
|
+
different = true;
|
|
2043
|
+
constraints.push(constraint);
|
|
2044
|
+
}
|
|
2045
|
+
else
|
|
2046
|
+
different = true;
|
|
2047
|
+
}
|
|
2048
|
+
if (!different)
|
|
2049
|
+
return t;
|
|
2050
|
+
if ((flags & 134217728 /* TypeFlags.Union */) !== 0 && constraints.length === types.length)
|
|
2051
|
+
return getUnionType(c, constraints);
|
|
2052
|
+
if ((flags & 268435456 /* TypeFlags.Intersection */) !== 0 && constraints.length !== 0)
|
|
2053
|
+
return getIntersectionType(c, constraints);
|
|
2054
|
+
return undefined;
|
|
2055
|
+
}
|
|
2056
|
+
if ((flags & 2097152 /* TypeFlags.Index */) !== 0) {
|
|
2057
|
+
const target = t.target;
|
|
2058
|
+
if (isGenericMappedType(c, target)) {
|
|
2059
|
+
if (getNameTypeFromMappedType(c, target) !== undefined &&
|
|
2060
|
+
!isMappedTypeWithKeyofConstraintDeclaration(c, target))
|
|
2061
|
+
return getNextBaseConstraint(c, getIndexForMappedType(c, target), stack);
|
|
2062
|
+
}
|
|
2063
|
+
return c.stringNumberSymbolType;
|
|
2064
|
+
}
|
|
2065
|
+
if ((flags & 4194304 /* TypeFlags.TemplateLiteral */) !== 0) {
|
|
2066
|
+
const template = t;
|
|
2067
|
+
const constraints = [];
|
|
2068
|
+
for (const s of template.types) {
|
|
2069
|
+
const constraint = getNextBaseConstraint(c, s, stack);
|
|
2070
|
+
if (constraint !== undefined)
|
|
2071
|
+
constraints.push(constraint);
|
|
2072
|
+
}
|
|
2073
|
+
return constraints.length === template.types.length
|
|
2074
|
+
? getTemplateLiteralType(c, template.texts, constraints)
|
|
2075
|
+
: c.stringType;
|
|
2076
|
+
}
|
|
2077
|
+
if ((flags & 8388608 /* TypeFlags.StringMapping */) !== 0) {
|
|
2078
|
+
const target = t.target;
|
|
2079
|
+
const constraint = getNextBaseConstraint(c, target, stack);
|
|
2080
|
+
return constraint !== undefined && constraint !== target
|
|
2081
|
+
? getStringMappingType(c, t.symbol, constraint)
|
|
2082
|
+
: c.stringType;
|
|
2083
|
+
}
|
|
2084
|
+
if ((flags & 33554432 /* TypeFlags.IndexedAccess */) !== 0) {
|
|
2085
|
+
const access = t;
|
|
2086
|
+
if (isMappedTypeGenericIndexedAccess(c, t))
|
|
2087
|
+
return getNextBaseConstraint(c, substituteIndexedMappedType(c, access.objectType, access.indexType), stack);
|
|
2088
|
+
const baseObjectType = getNextBaseConstraint(c, access.objectType, stack);
|
|
2089
|
+
const baseIndexType = getNextBaseConstraint(c, access.indexType, stack);
|
|
2090
|
+
if (baseObjectType === undefined || baseIndexType === undefined)
|
|
2091
|
+
return undefined;
|
|
2092
|
+
return getNextBaseConstraint(c, getIndexedAccessTypeOrUndefined(c, baseObjectType, baseIndexType, access.accessFlags), stack);
|
|
2093
|
+
}
|
|
2094
|
+
if ((flags & 67108864 /* TypeFlags.Conditional */) !== 0) {
|
|
2095
|
+
if (c.conditionalConstraintDepth >= 100)
|
|
2096
|
+
return undefined;
|
|
2097
|
+
c.conditionalConstraintDepth++;
|
|
2098
|
+
const constraint = getConstraintFromConditionalType(c, t);
|
|
2099
|
+
c.conditionalConstraintDepth--;
|
|
2100
|
+
return getNextBaseConstraint(c, constraint, stack);
|
|
2101
|
+
}
|
|
2102
|
+
if ((flags & 16777216 /* TypeFlags.Substitution */) !== 0)
|
|
2103
|
+
return getNextBaseConstraint(c, getSubstitutionIntersection(c, t), stack);
|
|
2104
|
+
if (isGenericTupleType(t)) {
|
|
2105
|
+
// Substitute constraints of variadic elements only when they're arrays or non-variadic tuples.
|
|
2106
|
+
const elementTypes = getElementTypes(c, t);
|
|
2107
|
+
const infos = tupleTargetOf(t).elementInfos;
|
|
2108
|
+
const newElements = [];
|
|
2109
|
+
for (let i = 0; i < elementTypes.length; i++) {
|
|
2110
|
+
const v = elementTypes[i];
|
|
2111
|
+
let element = v;
|
|
2112
|
+
if ((v.flags & 524288 /* TypeFlags.TypeParameter */) !== 0 && (infos[i].flags & 8 /* ElementFlags.Variadic */) !== 0) {
|
|
2113
|
+
const constraint = getNextBaseConstraint(c, v, stack);
|
|
2114
|
+
if (constraint !== undefined &&
|
|
2115
|
+
constraint !== v &&
|
|
2116
|
+
everyType(constraint, (n) => isArrayOrTupleType(c, n) && !isGenericTupleType(n)))
|
|
2117
|
+
element = constraint;
|
|
2118
|
+
}
|
|
2119
|
+
newElements.push(element);
|
|
2120
|
+
}
|
|
2121
|
+
return createTupleTypeEx(c, newElements, infos, tupleTargetOf(t).readonly);
|
|
2122
|
+
}
|
|
2123
|
+
return t;
|
|
2124
|
+
}
|
|
2125
|
+
function getNextBaseConstraint(c, t, stack) {
|
|
2126
|
+
if (t === undefined)
|
|
2127
|
+
return undefined;
|
|
2128
|
+
const constraint = getResolvedBaseConstraint(c, t, stack);
|
|
2129
|
+
return constraint === c.noConstraintType || constraint === c.circularConstraintType ? undefined : constraint;
|
|
2130
|
+
}
|
|
2131
|
+
export function getConstraintOfType(c, t) {
|
|
2132
|
+
if ((t.flags & 524288 /* TypeFlags.TypeParameter */) !== 0)
|
|
2133
|
+
return getConstraintOfTypeParameterGuarded(c, t);
|
|
2134
|
+
if ((t.flags & 33554432 /* TypeFlags.IndexedAccess */) !== 0)
|
|
2135
|
+
return getConstraintOfIndexedAccess(c, t);
|
|
2136
|
+
if ((t.flags & 67108864 /* TypeFlags.Conditional */) !== 0)
|
|
2137
|
+
return getConstraintOfConditionalTypeLazy(c, t);
|
|
2138
|
+
return getBaseConstraintOfType(c, t);
|
|
2139
|
+
}
|
|
2140
|
+
import { getConstraintOfTypeParameter as getConstraintOfTypeParameterGuarded } from './checker-declared-types.js';
|
|
2141
|
+
import { getConstraintOfIndexedAccess, getConstraintOfConditionalType as getConstraintOfConditionalTypeLazy, } from './checker-type-operators.js';
|
|
2142
|
+
export function isReadonlyArray(c, t) {
|
|
2143
|
+
return isReadonlyArrayType(c, t);
|
|
2144
|
+
}
|
|
2145
|
+
export function getTypeFromNodeOrUndefined(c, node) {
|
|
2146
|
+
return node !== undefined ? getTypeFromTypeNode(c, node) : undefined;
|
|
2147
|
+
}
|
|
2148
|
+
export { getReturnTypeOfSignature, getSymbolOfDeclaration, getLateBoundSymbol, instantiateTypes, createSignatureInstantiation, getUnionTypeEx, mapType, };
|