tsc-ts 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +33 -1
- package/dist/api/compiler/ast-utilities.d.ts +82 -0
- package/dist/api/compiler/ast-utilities.js +462 -0
- package/dist/api/compiler/ast.d.ts +2350 -0
- package/dist/api/compiler/ast.js +11206 -0
- package/dist/api/compiler/astnav.d.ts +37 -0
- package/dist/api/compiler/astnav.js +767 -0
- package/dist/api/compiler/binder-utilities.d.ts +182 -0
- package/dist/api/compiler/binder-utilities.js +1240 -0
- package/dist/api/compiler/binder.d.ts +33 -0
- package/dist/api/compiler/binder.js +2358 -0
- package/dist/api/compiler/character-codes.d.ts +161 -0
- package/dist/api/compiler/character-codes.js +160 -0
- package/dist/api/compiler/checker-calls.d.ts +46 -0
- package/dist/api/compiler/checker-calls.js +1640 -0
- package/dist/api/compiler/checker-classes.d.ts +30 -0
- package/dist/api/compiler/checker-classes.js +582 -0
- package/dist/api/compiler/checker-contextual.d.ts +77 -0
- package/dist/api/compiler/checker-contextual.js +1136 -0
- package/dist/api/compiler/checker-declaration-order.d.ts +12 -0
- package/dist/api/compiler/checker-declaration-order.js +356 -0
- package/dist/api/compiler/checker-declarations.d.ts +33 -0
- package/dist/api/compiler/checker-declarations.js +888 -0
- package/dist/api/compiler/checker-declared-types.d.ts +48 -0
- package/dist/api/compiler/checker-declared-types.js +787 -0
- package/dist/api/compiler/checker-decorators.d.ts +26 -0
- package/dist/api/compiler/checker-decorators.js +562 -0
- package/dist/api/compiler/checker-deprecation.d.ts +33 -0
- package/dist/api/compiler/checker-deprecation.js +315 -0
- package/dist/api/compiler/checker-destructuring.d.ts +34 -0
- package/dist/api/compiler/checker-destructuring.js +584 -0
- package/dist/api/compiler/checker-elaboration.d.ts +15 -0
- package/dist/api/compiler/checker-elaboration.js +290 -0
- package/dist/api/compiler/checker-emit-helpers.d.ts +58 -0
- package/dist/api/compiler/checker-emit-helpers.js +154 -0
- package/dist/api/compiler/checker-emit-resolver.d.ts +75 -0
- package/dist/api/compiler/checker-emit-resolver.js +579 -0
- package/dist/api/compiler/checker-evaluator.d.ts +27 -0
- package/dist/api/compiler/checker-evaluator.js +188 -0
- package/dist/api/compiler/checker-expressions.d.ts +67 -0
- package/dist/api/compiler/checker-expressions.js +1351 -0
- package/dist/api/compiler/checker-features.d.ts +6 -0
- package/dist/api/compiler/checker-features.js +354 -0
- package/dist/api/compiler/checker-flow.d.ts +86 -0
- package/dist/api/compiler/checker-flow.js +169 -0
- package/dist/api/compiler/checker-functions.d.ts +43 -0
- package/dist/api/compiler/checker-functions.js +1002 -0
- package/dist/api/compiler/checker-generated-code.d.ts +25 -0
- package/dist/api/compiler/checker-generated-code.js +168 -0
- package/dist/api/compiler/checker-globals.d.ts +14 -0
- package/dist/api/compiler/checker-globals.js +37 -0
- package/dist/api/compiler/checker-grammar.d.ts +35 -0
- package/dist/api/compiler/checker-grammar.js +2573 -0
- package/dist/api/compiler/checker-heritage.d.ts +28 -0
- package/dist/api/compiler/checker-heritage.js +900 -0
- package/dist/api/compiler/checker-inference.d.ts +179 -0
- package/dist/api/compiler/checker-inference.js +2105 -0
- package/dist/api/compiler/checker-iteration.d.ts +115 -0
- package/dist/api/compiler/checker-iteration.js +857 -0
- package/dist/api/compiler/checker-javascript.d.ts +42 -0
- package/dist/api/compiler/checker-javascript.js +441 -0
- package/dist/api/compiler/checker-jsdoc.d.ts +30 -0
- package/dist/api/compiler/checker-jsdoc.js +320 -0
- package/dist/api/compiler/checker-jsx.d.ts +94 -0
- package/dist/api/compiler/checker-jsx.js +1433 -0
- package/dist/api/compiler/checker-literals.d.ts +6 -0
- package/dist/api/compiler/checker-literals.js +43 -0
- package/dist/api/compiler/checker-members.d.ts +198 -0
- package/dist/api/compiler/checker-members.js +2126 -0
- package/dist/api/compiler/checker-modules.d.ts +85 -0
- package/dist/api/compiler/checker-modules.js +2141 -0
- package/dist/api/compiler/checker-narrowing.d.ts +120 -0
- package/dist/api/compiler/checker-narrowing.js +2797 -0
- package/dist/api/compiler/checker-object-literals.d.ts +14 -0
- package/dist/api/compiler/checker-object-literals.js +479 -0
- package/dist/api/compiler/checker-operators.d.ts +33 -0
- package/dist/api/compiler/checker-operators.js +1040 -0
- package/dist/api/compiler/checker-overloads.d.ts +7 -0
- package/dist/api/compiler/checker-overloads.js +270 -0
- package/dist/api/compiler/checker-property-access.d.ts +34 -0
- package/dist/api/compiler/checker-property-access.js +672 -0
- package/dist/api/compiler/checker-services.d.ts +49 -0
- package/dist/api/compiler/checker-services.js +995 -0
- package/dist/api/compiler/checker-signatures.d.ts +55 -0
- package/dist/api/compiler/checker-signatures.js +788 -0
- package/dist/api/compiler/checker-source-file.d.ts +27 -0
- package/dist/api/compiler/checker-source-file.js +619 -0
- package/dist/api/compiler/checker-statements.d.ts +18 -0
- package/dist/api/compiler/checker-statements.js +226 -0
- package/dist/api/compiler/checker-super.d.ts +13 -0
- package/dist/api/compiler/checker-super.js +241 -0
- package/dist/api/compiler/checker-symbol-types.d.ts +67 -0
- package/dist/api/compiler/checker-symbol-types.js +1885 -0
- package/dist/api/compiler/checker-symbols.d.ts +181 -0
- package/dist/api/compiler/checker-symbols.js +1782 -0
- package/dist/api/compiler/checker-type-factory.d.ts +142 -0
- package/dist/api/compiler/checker-type-factory.js +2501 -0
- package/dist/api/compiler/checker-type-nodes.d.ts +26 -0
- package/dist/api/compiler/checker-type-nodes.js +828 -0
- package/dist/api/compiler/checker-type-operators.d.ts +109 -0
- package/dist/api/compiler/checker-type-operators.js +1842 -0
- package/dist/api/compiler/checker-types.d.ts +1027 -0
- package/dist/api/compiler/checker-types.js +1697 -0
- package/dist/api/compiler/checker-unused.d.ts +19 -0
- package/dist/api/compiler/checker-unused.js +524 -0
- package/dist/api/compiler/checker-utilities.d.ts +33 -0
- package/dist/api/compiler/checker-utilities.js +141 -0
- package/dist/api/compiler/checker.d.ts +491 -0
- package/dist/api/compiler/checker.js +912 -0
- package/dist/api/compiler/command-line.d.ts +32 -0
- package/dist/api/compiler/command-line.js +383 -0
- package/dist/api/compiler/compile-program.d.ts +118 -0
- package/dist/api/compiler/compile-program.js +384 -0
- package/dist/api/compiler/diagnostic-locales.d.ts +22 -0
- package/dist/api/compiler/diagnostic-locales.js +64 -0
- package/dist/api/compiler/diagnostic-messages.d.ts +2166 -0
- package/dist/api/compiler/diagnostic-messages.js +184 -0
- package/dist/api/compiler/diagnostics.d.ts +167 -0
- package/dist/api/compiler/diagnostics.js +820 -0
- package/dist/api/compiler/emitter.d.ts +71 -0
- package/dist/api/compiler/emitter.js +327 -0
- package/dist/api/compiler/file-include.d.ts +117 -0
- package/dist/api/compiler/file-include.js +536 -0
- package/dist/api/compiler/file-loader.d.ts +261 -0
- package/dist/api/compiler/file-loader.js +1257 -0
- package/dist/api/compiler/file-system.d.ts +51 -0
- package/dist/api/compiler/file-system.js +132 -0
- package/dist/api/compiler/flow.d.ts +60 -0
- package/dist/api/compiler/flow.js +45 -0
- package/dist/api/compiler/instantiation.d.ts +74 -0
- package/dist/api/compiler/instantiation.js +799 -0
- package/dist/api/compiler/jsdoc.d.ts +75 -0
- package/dist/api/compiler/jsdoc.js +1229 -0
- package/dist/api/compiler/link-tables.d.ts +36 -0
- package/dist/api/compiler/link-tables.js +83 -0
- package/dist/api/compiler/locale-data.d.ts +24 -0
- package/dist/api/compiler/locale-data.js +183 -0
- package/dist/api/compiler/locale.d.ts +4 -0
- package/dist/api/compiler/locale.js +317 -0
- package/dist/api/compiler/locales/cs-CZ.d.ts +2 -0
- package/dist/api/compiler/locales/cs-CZ.js +3 -0
- package/dist/api/compiler/locales/de-DE.d.ts +2 -0
- package/dist/api/compiler/locales/de-DE.js +3 -0
- package/dist/api/compiler/locales/es-ES.d.ts +2 -0
- package/dist/api/compiler/locales/es-ES.js +3 -0
- package/dist/api/compiler/locales/fr-FR.d.ts +2 -0
- package/dist/api/compiler/locales/fr-FR.js +3 -0
- package/dist/api/compiler/locales/it-IT.d.ts +2 -0
- package/dist/api/compiler/locales/it-IT.js +3 -0
- package/dist/api/compiler/locales/ja-JP.d.ts +2 -0
- package/dist/api/compiler/locales/ja-JP.js +3 -0
- package/dist/api/compiler/locales/ko-KR.d.ts +2 -0
- package/dist/api/compiler/locales/ko-KR.js +3 -0
- package/dist/api/compiler/locales/pl-PL.d.ts +2 -0
- package/dist/api/compiler/locales/pl-PL.js +3 -0
- package/dist/api/compiler/locales/pt-BR.d.ts +2 -0
- package/dist/api/compiler/locales/pt-BR.js +3 -0
- package/dist/api/compiler/locales/ru-RU.d.ts +2 -0
- package/dist/api/compiler/locales/ru-RU.js +3 -0
- package/dist/api/compiler/locales/tr-TR.d.ts +2 -0
- package/dist/api/compiler/locales/tr-TR.js +3 -0
- package/dist/api/compiler/locales/zh-CN.d.ts +2 -0
- package/dist/api/compiler/locales/zh-CN.js +3 -0
- package/dist/api/compiler/locales/zh-TW.d.ts +2 -0
- package/dist/api/compiler/locales/zh-TW.js +3 -0
- package/dist/api/compiler/module-resolution-types.d.ts +83 -0
- package/dist/api/compiler/module-resolution-types.js +176 -0
- package/dist/api/compiler/module-resolution.d.ts +71 -0
- package/dist/api/compiler/module-resolution.js +1598 -0
- package/dist/api/compiler/module-specifiers.d.ts +64 -0
- package/dist/api/compiler/module-specifiers.js +1101 -0
- package/dist/api/compiler/name-resolver.d.ts +43 -0
- package/dist/api/compiler/name-resolver.js +509 -0
- package/dist/api/compiler/node-builder-names.d.ts +32 -0
- package/dist/api/compiler/node-builder-names.js +854 -0
- package/dist/api/compiler/node-builder-pseudo.d.ts +36 -0
- package/dist/api/compiler/node-builder-pseudo.js +744 -0
- package/dist/api/compiler/node-builder-reuse.d.ts +4 -0
- package/dist/api/compiler/node-builder-reuse.js +647 -0
- package/dist/api/compiler/node-builder.d.ts +270 -0
- package/dist/api/compiler/node-builder.js +2645 -0
- package/dist/api/compiler/option-declarations.d.ts +90 -0
- package/dist/api/compiler/option-declarations.js +1460 -0
- package/dist/api/compiler/options.d.ts +289 -0
- package/dist/api/compiler/options.js +1197 -0
- package/dist/api/compiler/output-paths.d.ts +42 -0
- package/dist/api/compiler/output-paths.js +195 -0
- package/dist/api/compiler/package-json.d.ts +175 -0
- package/dist/api/compiler/package-json.js +1015 -0
- package/dist/api/compiler/parallel-parse.d.ts +219 -0
- package/dist/api/compiler/parallel-parse.js +537 -0
- package/dist/api/compiler/parser.d.ts +587 -0
- package/dist/api/compiler/parser.js +6407 -0
- package/dist/api/compiler/path.d.ts +91 -0
- package/dist/api/compiler/path.js +705 -0
- package/dist/api/compiler/printer/async-helpers.d.ts +22 -0
- package/dist/api/compiler/printer/async-helpers.js +91 -0
- package/dist/api/compiler/printer/auto-generate.d.ts +13 -0
- package/dist/api/compiler/printer/auto-generate.js +20 -0
- package/dist/api/compiler/printer/decorator-helpers.d.ts +24 -0
- package/dist/api/compiler/printer/decorator-helpers.js +118 -0
- package/dist/api/compiler/printer/emit-context.d.ts +154 -0
- package/dist/api/compiler/printer/emit-context.js +576 -0
- package/dist/api/compiler/printer/emit-flags.d.ts +60 -0
- package/dist/api/compiler/printer/emit-flags.js +2 -0
- package/dist/api/compiler/printer/factory-base.d.ts +171 -0
- package/dist/api/compiler/printer/factory-base.js +1505 -0
- package/dist/api/compiler/printer/factory.d.ts +147 -0
- package/dist/api/compiler/printer/factory.js +542 -0
- package/dist/api/compiler/printer/helpers.d.ts +27 -0
- package/dist/api/compiler/printer/helpers.js +164 -0
- package/dist/api/compiler/printer/name-generator.d.ts +41 -0
- package/dist/api/compiler/printer/name-generator.js +283 -0
- package/dist/api/compiler/printer/printer.d.ts +411 -0
- package/dist/api/compiler/printer/printer.js +4517 -0
- package/dist/api/compiler/printer/text-writer.d.ts +46 -0
- package/dist/api/compiler/printer/text-writer.js +172 -0
- package/dist/api/compiler/printer/utilities.d.ts +82 -0
- package/dist/api/compiler/printer/utilities.js +817 -0
- package/dist/api/compiler/program-checker.d.ts +156 -0
- package/dist/api/compiler/program-checker.js +526 -0
- package/dist/api/compiler/program-utilities.d.ts +52 -0
- package/dist/api/compiler/program-utilities.js +365 -0
- package/dist/api/compiler/program.d.ts +180 -0
- package/dist/api/compiler/program.js +1011 -0
- package/dist/api/compiler/pseudo-bigint.d.ts +5 -0
- package/dist/api/compiler/pseudo-bigint.js +61 -0
- package/dist/api/compiler/regexp-checker.d.ts +38 -0
- package/dist/api/compiler/regexp-checker.js +942 -0
- package/dist/api/compiler/relations.d.ts +263 -0
- package/dist/api/compiler/relations.js +4002 -0
- package/dist/api/compiler/reparser.d.ts +48 -0
- package/dist/api/compiler/reparser.js +1323 -0
- package/dist/api/compiler/scanner.d.ts +256 -0
- package/dist/api/compiler/scanner.js +2853 -0
- package/dist/api/compiler/side-state.d.ts +16 -0
- package/dist/api/compiler/side-state.js +89 -0
- package/dist/api/compiler/sourcemap.d.ts +55 -0
- package/dist/api/compiler/sourcemap.js +340 -0
- package/dist/api/compiler/spelling.d.ts +14 -0
- package/dist/api/compiler/spelling.js +128 -0
- package/dist/api/compiler/symbol-accessibility.d.ts +57 -0
- package/dist/api/compiler/symbol-accessibility.js +894 -0
- package/dist/api/compiler/symbol.d.ts +240 -0
- package/dist/api/compiler/symbol.js +228 -0
- package/dist/api/compiler/symlinks.d.ts +32 -0
- package/dist/api/compiler/symlinks.js +114 -0
- package/dist/api/compiler/syntax-kind.d.ts +389 -0
- package/dist/api/compiler/syntax-kind.js +2 -0
- package/dist/api/compiler/timeline.d.ts +9 -0
- package/dist/api/compiler/timeline.js +54 -0
- package/dist/api/compiler/transformers/alias-references.d.ts +39 -0
- package/dist/api/compiler/transformers/alias-references.js +676 -0
- package/dist/api/compiler/transformers/async-utilities.d.ts +51 -0
- package/dist/api/compiler/transformers/async-utilities.js +260 -0
- package/dist/api/compiler/transformers/async.d.ts +53 -0
- package/dist/api/compiler/transformers/async.js +645 -0
- package/dist/api/compiler/transformers/class-fields.d.ts +206 -0
- package/dist/api/compiler/transformers/class-fields.js +2418 -0
- package/dist/api/compiler/transformers/class-utilities.d.ts +46 -0
- package/dist/api/compiler/transformers/class-utilities.js +261 -0
- package/dist/api/compiler/transformers/commonjs-module.d.ts +103 -0
- package/dist/api/compiler/transformers/commonjs-module.js +1180 -0
- package/dist/api/compiler/transformers/const-enum-inliner.d.ts +11 -0
- package/dist/api/compiler/transformers/const-enum-inliner.js +36 -0
- package/dist/api/compiler/transformers/declarations-diagnostics.d.ts +52 -0
- package/dist/api/compiler/transformers/declarations-diagnostics.js +538 -0
- package/dist/api/compiler/transformers/declarations-pseudo.d.ts +160 -0
- package/dist/api/compiler/transformers/declarations-pseudo.js +797 -0
- package/dist/api/compiler/transformers/declarations-resolver.d.ts +152 -0
- package/dist/api/compiler/transformers/declarations-resolver.js +35 -0
- package/dist/api/compiler/transformers/declarations-syntactic.d.ts +119 -0
- package/dist/api/compiler/transformers/declarations-syntactic.js +1582 -0
- package/dist/api/compiler/transformers/declarations-tracker.d.ts +46 -0
- package/dist/api/compiler/transformers/declarations-tracker.js +197 -0
- package/dist/api/compiler/transformers/declarations.d.ts +175 -0
- package/dist/api/compiler/transformers/declarations.js +2380 -0
- package/dist/api/compiler/transformers/decorator-metadata.d.ts +54 -0
- package/dist/api/compiler/transformers/decorator-metadata.js +554 -0
- package/dist/api/compiler/transformers/decorator-utilities.d.ts +38 -0
- package/dist/api/compiler/transformers/decorator-utilities.js +238 -0
- package/dist/api/compiler/transformers/destructuring.d.ts +25 -0
- package/dist/api/compiler/transformers/destructuring.js +626 -0
- package/dist/api/compiler/transformers/downlevel.d.ts +6 -0
- package/dist/api/compiler/transformers/downlevel.js +45 -0
- package/dist/api/compiler/transformers/emit-resolver.d.ts +61 -0
- package/dist/api/compiler/transformers/emit-resolver.js +197 -0
- package/dist/api/compiler/transformers/es-decorators.d.ts +118 -0
- package/dist/api/compiler/transformers/es-decorators.js +1901 -0
- package/dist/api/compiler/transformers/exponentiation.d.ts +11 -0
- package/dist/api/compiler/transformers/exponentiation.js +76 -0
- package/dist/api/compiler/transformers/external-module-info.d.ts +35 -0
- package/dist/api/compiler/transformers/external-module-info.js +351 -0
- package/dist/api/compiler/transformers/for-await.d.ts +43 -0
- package/dist/api/compiler/transformers/for-await.js +469 -0
- package/dist/api/compiler/transformers/import-elision.d.ts +16 -0
- package/dist/api/compiler/transformers/import-elision.js +124 -0
- package/dist/api/compiler/transformers/jsx-entities.d.ts +1 -0
- package/dist/api/compiler/transformers/jsx-entities.js +256 -0
- package/dist/api/compiler/transformers/jsx.d.ts +71 -0
- package/dist/api/compiler/transformers/jsx.js +700 -0
- package/dist/api/compiler/transformers/legacy-decorators.d.ts +56 -0
- package/dist/api/compiler/transformers/legacy-decorators.js +564 -0
- package/dist/api/compiler/transformers/logical-assignment.d.ts +14 -0
- package/dist/api/compiler/transformers/logical-assignment.js +62 -0
- package/dist/api/compiler/transformers/module-utilities.d.ts +9 -0
- package/dist/api/compiler/transformers/module-utilities.js +36 -0
- package/dist/api/compiler/transformers/module.d.ts +49 -0
- package/dist/api/compiler/transformers/module.js +296 -0
- package/dist/api/compiler/transformers/named-evaluation.d.ts +26 -0
- package/dist/api/compiler/transformers/named-evaluation.js +266 -0
- package/dist/api/compiler/transformers/nullish-coalescing.d.ts +9 -0
- package/dist/api/compiler/transformers/nullish-coalescing.js +26 -0
- package/dist/api/compiler/transformers/object-rest-spread.d.ts +34 -0
- package/dist/api/compiler/transformers/object-rest-spread.js +411 -0
- package/dist/api/compiler/transformers/optional-catch.d.ts +9 -0
- package/dist/api/compiler/transformers/optional-catch.js +20 -0
- package/dist/api/compiler/transformers/optional-chain.d.ts +14 -0
- package/dist/api/compiler/transformers/optional-chain.js +188 -0
- package/dist/api/compiler/transformers/reference-resolver.d.ts +128 -0
- package/dist/api/compiler/transformers/reference-resolver.js +1155 -0
- package/dist/api/compiler/transformers/runtime-syntax.d.ts +71 -0
- package/dist/api/compiler/transformers/runtime-syntax.js +753 -0
- package/dist/api/compiler/transformers/subtree-facts.d.ts +9 -0
- package/dist/api/compiler/transformers/subtree-facts.js +203 -0
- package/dist/api/compiler/transformers/syntax-facts.d.ts +51 -0
- package/dist/api/compiler/transformers/syntax-facts.js +254 -0
- package/dist/api/compiler/transformers/tagged-template.d.ts +17 -0
- package/dist/api/compiler/transformers/tagged-template.js +148 -0
- package/dist/api/compiler/transformers/transformer.d.ts +17 -0
- package/dist/api/compiler/transformers/transformer.js +54 -0
- package/dist/api/compiler/transformers/type-eraser.d.ts +21 -0
- package/dist/api/compiler/transformers/type-eraser.js +346 -0
- package/dist/api/compiler/transformers/type-serialization.d.ts +20 -0
- package/dist/api/compiler/transformers/type-serialization.js +347 -0
- package/dist/api/compiler/transformers/using.d.ts +56 -0
- package/dist/api/compiler/transformers/using.js +453 -0
- package/dist/api/compiler/transformers/utilities.d.ts +50 -0
- package/dist/api/compiler/transformers/utilities.js +347 -0
- package/dist/api/compiler/transformers/visitor-base.d.ts +6 -0
- package/dist/api/compiler/transformers/visitor-base.js +817 -0
- package/dist/api/compiler/transformers/visitor-hooks.d.ts +29 -0
- package/dist/api/compiler/transformers/visitor-hooks.js +189 -0
- package/dist/api/compiler/tsconfig.d.ts +177 -0
- package/dist/api/compiler/tsconfig.js +1311 -0
- package/dist/api/compiler/type-printer.d.ts +15 -0
- package/dist/api/compiler/type-printer.js +74 -0
- package/dist/api/compiler/types.d.ts +87 -0
- package/dist/api/compiler/types.js +23 -0
- package/dist/api/compiler/unicode-identifiers.d.ts +2 -0
- package/dist/api/compiler/unicode-identifiers.js +209 -0
- package/dist/api/compiler/unicode-properties.d.ts +8 -0
- package/dist/api/compiler/unicode-properties.js +531 -0
- package/dist/api/compiler/vfs-match.d.ts +24 -0
- package/dist/api/compiler/vfs-match.js +587 -0
- package/dist/api/library/ast.d.ts +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 +12862 -0
- package/src/compiler/astnav.ts +799 -0
- package/src/compiler/binder-utilities.ts +1392 -0
- package/src/compiler/binder.ts +2703 -0
- package/src/compiler/build-info.ts +1197 -0
- package/src/compiler/character-codes.ts +323 -0
- package/src/compiler/checker-calls.ts +2155 -0
- package/src/compiler/checker-classes.ts +706 -0
- package/src/compiler/checker-contextual.ts +1457 -0
- package/src/compiler/checker-declaration-order.ts +438 -0
- package/src/compiler/checker-declarations.ts +1194 -0
- package/src/compiler/checker-declared-types.ts +919 -0
- package/src/compiler/checker-decorators.ts +694 -0
- package/src/compiler/checker-deprecation.ts +359 -0
- package/src/compiler/checker-destructuring.ts +805 -0
- package/src/compiler/checker-elaboration.ts +477 -0
- package/src/compiler/checker-emit-helpers.ts +224 -0
- package/src/compiler/checker-emit-resolver.ts +769 -0
- package/src/compiler/checker-evaluator.ts +243 -0
- package/src/compiler/checker-expressions.ts +1831 -0
- package/src/compiler/checker-features.ts +361 -0
- package/src/compiler/checker-flow.ts +394 -0
- package/src/compiler/checker-functions.ts +1296 -0
- package/src/compiler/checker-generated-code.ts +227 -0
- package/src/compiler/checker-globals.ts +52 -0
- package/src/compiler/checker-grammar.ts +3584 -0
- package/src/compiler/checker-heritage.ts +1233 -0
- package/src/compiler/checker-inference.ts +2576 -0
- package/src/compiler/checker-iteration.ts +1206 -0
- package/src/compiler/checker-javascript.ts +502 -0
- package/src/compiler/checker-jsdoc.ts +360 -0
- package/src/compiler/checker-jsx.ts +1924 -0
- package/src/compiler/checker-literals.ts +61 -0
- package/src/compiler/checker-members.ts +2436 -0
- package/src/compiler/checker-modules.ts +2886 -0
- package/src/compiler/checker-narrowing.ts +3230 -0
- package/src/compiler/checker-object-literals.ts +575 -0
- package/src/compiler/checker-operators.ts +1422 -0
- package/src/compiler/checker-overloads.ts +328 -0
- package/src/compiler/checker-property-access.ts +906 -0
- package/src/compiler/checker-services.ts +1149 -0
- package/src/compiler/checker-signatures.ts +1032 -0
- package/src/compiler/checker-source-file.ts +732 -0
- package/src/compiler/checker-statements.ts +292 -0
- package/src/compiler/checker-super.ts +261 -0
- package/src/compiler/checker-symbol-types.ts +2107 -0
- package/src/compiler/checker-symbols.ts +2150 -0
- package/src/compiler/checker-type-factory.ts +2579 -0
- package/src/compiler/checker-type-nodes.ts +1033 -0
- package/src/compiler/checker-type-operators.ts +2502 -0
- package/src/compiler/checker-types.ts +2340 -0
- package/src/compiler/checker-unused.ts +642 -0
- package/src/compiler/checker-utilities.ts +161 -0
- package/src/compiler/checker.ts +1116 -0
- package/src/compiler/command-line.ts +436 -0
- package/src/compiler/compile-program.ts +439 -0
- package/src/compiler/decoder.ts +1209 -0
- package/src/compiler/diagnostic-locales.ts +86 -0
- package/src/compiler/diagnostic-messages.ts +2349 -0
- package/src/compiler/diagnostics.ts +897 -0
- package/src/compiler/emitter.ts +434 -0
- package/src/compiler/encoder.ts +1945 -0
- package/src/compiler/file-include.ts +673 -0
- package/src/compiler/file-loader.ts +1528 -0
- package/src/compiler/file-system.ts +143 -0
- package/src/compiler/flow.ts +89 -0
- package/src/compiler/help.ts +473 -0
- package/src/compiler/incremental.ts +2784 -0
- package/src/compiler/init.ts +141 -0
- package/src/compiler/instantiation.ts +894 -0
- package/src/compiler/jsdoc.ts +1386 -0
- package/src/compiler/link-tables.ts +98 -0
- package/src/compiler/locale-data.ts +203 -0
- package/src/compiler/locale.ts +307 -0
- package/src/compiler/locales/cs-CZ.ts +5 -0
- package/src/compiler/locales/de-DE.ts +5 -0
- package/src/compiler/locales/es-ES.ts +5 -0
- package/src/compiler/locales/fr-FR.ts +5 -0
- package/src/compiler/locales/it-IT.ts +5 -0
- package/src/compiler/locales/ja-JP.ts +5 -0
- package/src/compiler/locales/ko-KR.ts +5 -0
- package/src/compiler/locales/pl-PL.ts +5 -0
- package/src/compiler/locales/pt-BR.ts +5 -0
- package/src/compiler/locales/ru-RU.ts +5 -0
- package/src/compiler/locales/tr-TR.ts +5 -0
- package/src/compiler/locales/zh-CN.ts +5 -0
- package/src/compiler/locales/zh-TW.ts +5 -0
- package/src/compiler/module-resolution-types.ts +243 -0
- package/src/compiler/module-resolution.ts +2072 -0
- package/src/compiler/module-specifiers.ts +1491 -0
- package/src/compiler/name-resolver.ts +646 -0
- package/src/compiler/node-builder-names.ts +1069 -0
- package/src/compiler/node-builder-pseudo.ts +892 -0
- package/src/compiler/node-builder-reuse.ts +764 -0
- package/src/compiler/node-builder.ts +3425 -0
- package/src/compiler/option-declarations.ts +1560 -0
- package/src/compiler/options.ts +1576 -0
- package/src/compiler/output-paths.ts +334 -0
- package/src/compiler/package-json.ts +1083 -0
- package/src/compiler/parallel-check.ts +1951 -0
- package/src/compiler/parallel-parse.ts +590 -0
- package/src/compiler/parse-thread.ts +140 -0
- package/src/compiler/parser.ts +7716 -0
- package/src/compiler/path.ts +717 -0
- package/src/compiler/printer/async-helpers.ts +183 -0
- package/src/compiler/printer/auto-generate.ts +27 -0
- package/src/compiler/printer/decorator-helpers.ts +218 -0
- package/src/compiler/printer/emit-context.ts +679 -0
- package/src/compiler/printer/emit-flags.ts +64 -0
- package/src/compiler/printer/factory-base.ts +2577 -0
- package/src/compiler/printer/factory.ts +764 -0
- package/src/compiler/printer/helpers.ts +291 -0
- package/src/compiler/printer/name-generator.ts +372 -0
- package/src/compiler/printer/printer.ts +5072 -0
- package/src/compiler/printer/text-writer.ts +183 -0
- package/src/compiler/printer/utilities.ts +884 -0
- package/src/compiler/program-checker.ts +592 -0
- package/src/compiler/program-utilities.ts +435 -0
- package/src/compiler/program.ts +1419 -0
- package/src/compiler/pseudo-bigint.ts +62 -0
- package/src/compiler/regexp-checker.ts +1142 -0
- package/src/compiler/relations.ts +5149 -0
- package/src/compiler/reparser.ts +1566 -0
- package/src/compiler/scanner.ts +2951 -0
- package/src/compiler/show-config.ts +239 -0
- package/src/compiler/side-state.ts +125 -0
- package/src/compiler/sourcemap.ts +366 -0
- package/src/compiler/spelling.ts +122 -0
- package/src/compiler/symbol-accessibility.ts +1071 -0
- package/src/compiler/symbol.ts +439 -0
- package/src/compiler/symlinks.ts +137 -0
- package/src/compiler/syntax-kind.ts +391 -0
- package/src/compiler/thread-entry.ts +191 -0
- package/src/compiler/timeline.ts +53 -0
- package/src/compiler/transformers/alias-references.ts +757 -0
- package/src/compiler/transformers/async-utilities.ts +335 -0
- package/src/compiler/transformers/async.ts +838 -0
- package/src/compiler/transformers/class-fields.ts +2967 -0
- package/src/compiler/transformers/class-utilities.ts +324 -0
- package/src/compiler/transformers/commonjs-module.ts +1621 -0
- package/src/compiler/transformers/const-enum-inliner.ts +50 -0
- package/src/compiler/transformers/declarations-diagnostics.ts +832 -0
- package/src/compiler/transformers/declarations-pseudo.ts +966 -0
- package/src/compiler/transformers/declarations-resolver.ts +249 -0
- package/src/compiler/transformers/declarations-syntactic.ts +1859 -0
- package/src/compiler/transformers/declarations-tracker.ts +269 -0
- package/src/compiler/transformers/declarations.ts +3120 -0
- package/src/compiler/transformers/decorator-metadata.ts +697 -0
- package/src/compiler/transformers/decorator-utilities.ts +283 -0
- package/src/compiler/transformers/destructuring.ts +708 -0
- package/src/compiler/transformers/downlevel.ts +50 -0
- package/src/compiler/transformers/emit-resolver.ts +258 -0
- package/src/compiler/transformers/es-decorators.ts +2682 -0
- package/src/compiler/transformers/exponentiation.ts +80 -0
- package/src/compiler/transformers/external-module-info.ts +412 -0
- package/src/compiler/transformers/for-await.ts +687 -0
- package/src/compiler/transformers/import-elision.ts +152 -0
- package/src/compiler/transformers/jsx-entities.ts +256 -0
- package/src/compiler/transformers/jsx.ts +824 -0
- package/src/compiler/transformers/legacy-decorators.ts +726 -0
- package/src/compiler/transformers/logical-assignment.ts +75 -0
- package/src/compiler/transformers/module-utilities.ts +42 -0
- package/src/compiler/transformers/module.ts +474 -0
- package/src/compiler/transformers/named-evaluation.ts +389 -0
- package/src/compiler/transformers/nullish-coalescing.ts +35 -0
- package/src/compiler/transformers/object-rest-spread.ts +577 -0
- package/src/compiler/transformers/optional-catch.ts +29 -0
- package/src/compiler/transformers/optional-chain.ts +246 -0
- package/src/compiler/transformers/reference-resolver.ts +1201 -0
- package/src/compiler/transformers/runtime-syntax.ts +942 -0
- package/src/compiler/transformers/subtree-facts.ts +245 -0
- package/src/compiler/transformers/syntax-facts.ts +353 -0
- package/src/compiler/transformers/tagged-template.ts +167 -0
- package/src/compiler/transformers/transformer.ts +56 -0
- package/src/compiler/transformers/type-eraser.ts +520 -0
- package/src/compiler/transformers/type-serialization.ts +374 -0
- package/src/compiler/transformers/using.ts +613 -0
- package/src/compiler/transformers/utilities.ts +419 -0
- package/src/compiler/transformers/visitor-base.ts +1601 -0
- package/src/compiler/transformers/visitor-hooks.ts +252 -0
- package/src/compiler/tsc-build.ts +1418 -0
- package/src/compiler/tsc-cli.ts +666 -0
- package/src/compiler/tsc-compile.ts +437 -0
- package/src/compiler/tsc-watch.ts +854 -0
- package/src/compiler/tsconfig.ts +1574 -0
- package/src/compiler/type-printer.ts +110 -0
- package/src/compiler/types.ts +115 -0
- package/src/compiler/unicode-identifiers.ts +212 -0
- package/src/compiler/unicode-properties.ts +537 -0
- package/src/compiler/vfs-match.ts +597 -0
- package/src/compiler/xxh3.ts +650 -0
- package/src/library/ast.generated.ts +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,744 @@
|
|
|
1
|
+
// Writing pseudo-types (types as far as syntax decides them) as type nodes, checked against the
|
|
2
|
+
// checker's types: declaration emit reuses what the source wrote where it denotes the same type,
|
|
3
|
+
// and reports what isolatedDeclarations can't write without inference.
|
|
4
|
+
import { FunctionTypeNode, GetAccessorDeclaration, Identifier, KeywordTypeNode, LiteralTypeNode, MethodSignatureDeclaration, ParameterDeclaration, PropertyAccessExpression, PropertySignatureDeclaration, QualifiedName, SetAccessorDeclaration, StringLiteral, TupleTypeNode, TypeLiteralNode, TypeOperatorNode, TypePredicateNode, UnionTypeNode, getBody, getName, getPostfixToken, getQuestionToken, getSymbol, getText, isDeclarationNode, } from './ast.js';
|
|
5
|
+
import { isFunctionLike } from './ast-utilities.js';
|
|
6
|
+
import { getSourceFileOfNode, isEntityNameExpression } from './binder-utilities.js';
|
|
7
|
+
import { getContextualType, instantiateContextualType } from './checker-contextual.js';
|
|
8
|
+
import { checkExpressionCached, isConstContext, isLiteralOfContextualType } from './checker-expressions.js';
|
|
9
|
+
import { getTypeWithFacts } from './checker-flow.js';
|
|
10
|
+
import { getPropertiesOfType, getPropertyOfType } from './checker-members.js';
|
|
11
|
+
import { getReturnTypeOfSignature, getSignatureFromDeclaration, getSingleCallSignature, getTypePredicateOfSignature, } from './checker-signatures.js';
|
|
12
|
+
import { getTypeOfParameter, getTypeOfSymbol, getWidenedType, getWriteTypeOfSymbol, removeMissingType, } from './checker-symbol-types.js';
|
|
13
|
+
import { getRegularTypeOfLiteralType, getTypeArguments, getUnionType, isErrorType, isTupleType, } from './checker-type-factory.js';
|
|
14
|
+
import { getTypeFromTypeNode } from './checker-type-nodes.js';
|
|
15
|
+
import { NameResolver } from './name-resolver.js';
|
|
16
|
+
import { getSymbolOfDeclaration } from './checker-symbols.js';
|
|
17
|
+
import { canReuseExistingJSTypeNode, classifyPropertyName, getExpandedParameters, isOptionalParameter, requiresAddingImplicitUndefined, } from './node-builder.js';
|
|
18
|
+
import { tryReuseExistingNode } from './node-builder-reuse.js';
|
|
19
|
+
import { compareTypesIdentical } from './relations.js';
|
|
20
|
+
import { DirectType, InferredType, PseudoChecker, isInConstContext, } from './transformers/declarations-pseudo.js';
|
|
21
|
+
import { tryGetTextOfPropertyName } from './transformers/declarations-syntactic.js';
|
|
22
|
+
/** Resolves no names: `undefined` in an expression is the undefined value, as tsgo's pseudochecker assumes. */
|
|
23
|
+
class NoNames extends NameResolver {
|
|
24
|
+
resolve(_location, _name, _meaning, _nameNotFoundMessage, _isUse, _excludeGlobals) {
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/** A pseudochecker for declaration emit with the checker. */
|
|
29
|
+
export function newPseudoChecker(c) {
|
|
30
|
+
return new PseudoChecker(c.strictNullChecks, new Map(), new NoNames(c.compilerOptions));
|
|
31
|
+
}
|
|
32
|
+
function isDeclaration(node) {
|
|
33
|
+
if (node.kind === 169 /* SyntaxKind.TypeParameter */)
|
|
34
|
+
return node.parent !== undefined;
|
|
35
|
+
return isDeclarationNode(node);
|
|
36
|
+
}
|
|
37
|
+
function getContainingFunction(node) {
|
|
38
|
+
for (let current = node.parent; current !== undefined; current = current.parent)
|
|
39
|
+
if (isFunctionLike(current))
|
|
40
|
+
return current;
|
|
41
|
+
return undefined;
|
|
42
|
+
}
|
|
43
|
+
export function containsNonMissingUndefinedType(c, t) {
|
|
44
|
+
const candidate = (t.flags & 134217728 /* TypeFlags.Union */) !== 0 ? typesOfUnion(t)[0] : t;
|
|
45
|
+
return (candidate.flags & 4 /* TypeFlags.Undefined */) !== 0 && candidate !== c.missingType;
|
|
46
|
+
}
|
|
47
|
+
function typesOfUnion(t) {
|
|
48
|
+
return t.types;
|
|
49
|
+
}
|
|
50
|
+
export function getRegularTypeOfExpression(c, node) {
|
|
51
|
+
const parent = node.parent;
|
|
52
|
+
let expr = node;
|
|
53
|
+
if ((parent instanceof QualifiedName && parent.right === node) ||
|
|
54
|
+
(parent instanceof PropertyAccessExpression && parent.name === node))
|
|
55
|
+
expr = parent;
|
|
56
|
+
return getRegularTypeOfLiteralType(c, checkExpressionCached(c, expr));
|
|
57
|
+
}
|
|
58
|
+
function keyword(b, kind) {
|
|
59
|
+
return b.created(new KeywordTypeNode(kind));
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Like `pseudoTypeToNode`, but an inferred pseudo-type (or an annotation that can't be reused)
|
|
63
|
+
* reports its fallback and is written from the checker's type.
|
|
64
|
+
*/
|
|
65
|
+
export function pseudoTypeToNodeWithCheckerFallback(b, t, checkerType) {
|
|
66
|
+
if (t instanceof InferredType) {
|
|
67
|
+
if (!b.suppressReportInferenceFallback) {
|
|
68
|
+
if (t.errorNodes.length > 0)
|
|
69
|
+
for (const n of t.errorNodes)
|
|
70
|
+
b.tracker.reportInferenceFallback(n);
|
|
71
|
+
else
|
|
72
|
+
b.tracker.reportInferenceFallback(t.expression);
|
|
73
|
+
}
|
|
74
|
+
return typeToTypeNodeSuppressed(b, checkerType);
|
|
75
|
+
}
|
|
76
|
+
if (t instanceof DirectType) {
|
|
77
|
+
if (!canReuseExistingJSTypeNode(b, t.typeNode, checkerType)) {
|
|
78
|
+
if (!b.suppressReportInferenceFallback)
|
|
79
|
+
b.tracker.reportInferenceFallback(t.typeNode);
|
|
80
|
+
return typeToTypeNodeSuppressed(b, checkerType);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return pseudoTypeToNode(b, t);
|
|
84
|
+
}
|
|
85
|
+
function typeToTypeNodeSuppressed(b, t) {
|
|
86
|
+
const old = b.suppressReportInferenceFallback;
|
|
87
|
+
b.suppressReportInferenceFallback = true;
|
|
88
|
+
const result = b.typeToTypeNode(t);
|
|
89
|
+
b.suppressReportInferenceFallback = old;
|
|
90
|
+
return result;
|
|
91
|
+
}
|
|
92
|
+
/** The type node of a pseudo-type, reporting the fallbacks its structure implies. */
|
|
93
|
+
export function pseudoTypeToNode(b, t) {
|
|
94
|
+
const c = b.c;
|
|
95
|
+
switch (t.kind) {
|
|
96
|
+
case 0 /* PseudoTypeKind.Direct */:
|
|
97
|
+
return reuseTypeNode(b, t.typeNode);
|
|
98
|
+
case 1 /* PseudoTypeKind.Inferred */: {
|
|
99
|
+
const inferred = t;
|
|
100
|
+
const node = inferred.expression;
|
|
101
|
+
if (inferred.errorNodes.length > 0)
|
|
102
|
+
for (const n of inferred.errorNodes)
|
|
103
|
+
b.tracker.reportInferenceFallback(n);
|
|
104
|
+
else if (isEntityNameExpression(node, false) && node.parent !== undefined && isDeclaration(node.parent))
|
|
105
|
+
b.tracker.reportInferenceFallback(node.parent);
|
|
106
|
+
else
|
|
107
|
+
b.tracker.reportInferenceFallback(node);
|
|
108
|
+
if (inferred.isSignatureReturn)
|
|
109
|
+
return b.serializeReturnTypeForSignatureEx(getSignatureFromDeclaration(c, node), false);
|
|
110
|
+
const parent = node.parent;
|
|
111
|
+
// The declaration's type is widened as the checker widens it.
|
|
112
|
+
if (parent.kind === 254 /* SyntaxKind.ReturnStatement */) {
|
|
113
|
+
const enclosing = getContainingFunction(node);
|
|
114
|
+
if (isAccessorKind(enclosing))
|
|
115
|
+
return b.serializeTypeForDeclaration(enclosing, undefined, undefined, false);
|
|
116
|
+
return b.serializeReturnTypeForSignatureEx(getSignatureFromDeclaration(c, enclosing), false);
|
|
117
|
+
}
|
|
118
|
+
if (parent.kind === 220 /* SyntaxKind.ArrowFunction */ && getBody(parent) === node)
|
|
119
|
+
return b.serializeReturnTypeForSignatureEx(getSignatureFromDeclaration(c, parent), false);
|
|
120
|
+
if (isDeclaration(parent))
|
|
121
|
+
return b.serializeTypeForDeclaration(parent, undefined, undefined, false);
|
|
122
|
+
return b.typeToTypeNode(getTypeOfExpressionForPseudo(c, node));
|
|
123
|
+
}
|
|
124
|
+
case 2 /* PseudoTypeKind.NoResult */: {
|
|
125
|
+
const node = t.declaration;
|
|
126
|
+
b.tracker.reportInferenceFallback(node);
|
|
127
|
+
if (isFunctionLike(node) && !isAccessorKind(node))
|
|
128
|
+
return b.serializeReturnTypeForSignatureEx(getSignatureFromDeclaration(c, node), false);
|
|
129
|
+
return b.serializeTypeForDeclaration(node, undefined, undefined, false);
|
|
130
|
+
}
|
|
131
|
+
case 3 /* PseudoTypeKind.MaybeConstLocation */: {
|
|
132
|
+
const d = t;
|
|
133
|
+
let inConstContext = isConstContext(c, d.node);
|
|
134
|
+
if (!inConstContext && isInConstContext(d.node)) {
|
|
135
|
+
// The contextual type only counts where syntax also finds a const context.
|
|
136
|
+
const contextualType = getContextualType(c, d.node);
|
|
137
|
+
const constType = pseudoTypeToType(b, d.constType);
|
|
138
|
+
if (constType !== undefined &&
|
|
139
|
+
isLiteralOfContextualType(c, constType, instantiateContextualType(c, contextualType, d.node, 0 /* ContextFlags.None */)))
|
|
140
|
+
inConstContext = true;
|
|
141
|
+
}
|
|
142
|
+
return pseudoTypeToNode(b, inConstContext ? d.constType : d.regularType);
|
|
143
|
+
}
|
|
144
|
+
case 4 /* PseudoTypeKind.Union */: {
|
|
145
|
+
const res = [];
|
|
146
|
+
let hasElidedType = false;
|
|
147
|
+
let hasUndefined = false;
|
|
148
|
+
const append = (node) => {
|
|
149
|
+
if (node === undefined)
|
|
150
|
+
return;
|
|
151
|
+
if (node instanceof UnionTypeNode) {
|
|
152
|
+
for (const member of node.types.nodes)
|
|
153
|
+
append(member);
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
if (node.kind === 157 /* SyntaxKind.UndefinedKeyword */) {
|
|
157
|
+
if (hasUndefined)
|
|
158
|
+
return;
|
|
159
|
+
hasUndefined = true;
|
|
160
|
+
}
|
|
161
|
+
res.push(node);
|
|
162
|
+
};
|
|
163
|
+
for (const m of t.types) {
|
|
164
|
+
if (!c.strictNullChecks && (m.kind === 5 /* PseudoTypeKind.Undefined */ || m.kind === 6 /* PseudoTypeKind.Null */)) {
|
|
165
|
+
hasElidedType = true;
|
|
166
|
+
continue;
|
|
167
|
+
}
|
|
168
|
+
append(pseudoTypeToNode(b, m));
|
|
169
|
+
}
|
|
170
|
+
if (res.length === 1)
|
|
171
|
+
return res[0];
|
|
172
|
+
if (res.length === 0)
|
|
173
|
+
return keyword(b, hasElidedType ? 132 /* SyntaxKind.AnyKeyword */ : 146 /* SyntaxKind.NeverKeyword */);
|
|
174
|
+
return b.created(new UnionTypeNode(b.list(res)));
|
|
175
|
+
}
|
|
176
|
+
case 5 /* PseudoTypeKind.Undefined */:
|
|
177
|
+
return keyword(b, c.strictNullChecks ? 157 /* SyntaxKind.UndefinedKeyword */ : 132 /* SyntaxKind.AnyKeyword */);
|
|
178
|
+
case 6 /* PseudoTypeKind.Null */:
|
|
179
|
+
if (!c.strictNullChecks)
|
|
180
|
+
return keyword(b, 132 /* SyntaxKind.AnyKeyword */);
|
|
181
|
+
return b.created(new LiteralTypeNode(b.factory.createKeywordExpression(105 /* SyntaxKind.NullKeyword */)));
|
|
182
|
+
case 7 /* PseudoTypeKind.Any */:
|
|
183
|
+
return keyword(b, 132 /* SyntaxKind.AnyKeyword */);
|
|
184
|
+
case 8 /* PseudoTypeKind.String */:
|
|
185
|
+
return keyword(b, 154 /* SyntaxKind.StringKeyword */);
|
|
186
|
+
case 9 /* PseudoTypeKind.Number */:
|
|
187
|
+
return keyword(b, 150 /* SyntaxKind.NumberKeyword */);
|
|
188
|
+
case 10 /* PseudoTypeKind.BigInt */:
|
|
189
|
+
return keyword(b, 163 /* SyntaxKind.BigIntKeyword */);
|
|
190
|
+
case 11 /* PseudoTypeKind.Boolean */:
|
|
191
|
+
return keyword(b, 135 /* SyntaxKind.BooleanKeyword */);
|
|
192
|
+
case 12 /* PseudoTypeKind.False */:
|
|
193
|
+
return b.created(new LiteralTypeNode(b.factory.createKeywordExpression(96 /* SyntaxKind.FalseKeyword */)));
|
|
194
|
+
case 13 /* PseudoTypeKind.True */:
|
|
195
|
+
return b.created(new LiteralTypeNode(b.factory.createKeywordExpression(111 /* SyntaxKind.TrueKeyword */)));
|
|
196
|
+
case 14 /* PseudoTypeKind.SingleCallSignature */: {
|
|
197
|
+
const d = t;
|
|
198
|
+
const signature = getSignatureFromDeclaration(c, d.signature);
|
|
199
|
+
const expandedParams = getExpandedParameters(c, signature, true)[0];
|
|
200
|
+
const cleanup = b.enterNewScope(d.signature, expandedParams, signature.typeParameters, signature.parameters, signature.mapper);
|
|
201
|
+
const typeParams = reuseTypeParameters(b, d.typeParameters);
|
|
202
|
+
const params = pseudoParametersToNodes(b, d.parameters);
|
|
203
|
+
const returnType = pseudoTypeToNode(b, d.returnType);
|
|
204
|
+
cleanup();
|
|
205
|
+
return b.created(new FunctionTypeNode(typeParams, b.list(params), returnType));
|
|
206
|
+
}
|
|
207
|
+
case 15 /* PseudoTypeKind.Tuple */: {
|
|
208
|
+
const res = [];
|
|
209
|
+
for (const e of t.elements) {
|
|
210
|
+
const node = pseudoTypeToNode(b, e);
|
|
211
|
+
if (node !== undefined)
|
|
212
|
+
res.push(node);
|
|
213
|
+
}
|
|
214
|
+
// `as const` arrays are readonly.
|
|
215
|
+
const result = b.created(new TupleTypeNode(b.list(res)));
|
|
216
|
+
b.context.addEmitFlags(result, 1 /* EmitFlags.SingleLine */);
|
|
217
|
+
return b.created(new TypeOperatorNode(148 /* SyntaxKind.ReadonlyKeyword */, result));
|
|
218
|
+
}
|
|
219
|
+
case 16 /* PseudoTypeKind.ObjectLiteral */:
|
|
220
|
+
return objectLiteralToNode(b, t);
|
|
221
|
+
case 17 /* PseudoTypeKind.StringLiteral */:
|
|
222
|
+
case 18 /* PseudoTypeKind.NumericLiteral */:
|
|
223
|
+
case 19 /* PseudoTypeKind.BigIntLiteral */: {
|
|
224
|
+
const reused = reuseNode(b, t.node);
|
|
225
|
+
return reused === undefined ? undefined : b.created(new LiteralTypeNode(reused));
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
return undefined;
|
|
229
|
+
}
|
|
230
|
+
function objectLiteralToNode(b, t) {
|
|
231
|
+
const c = b.c;
|
|
232
|
+
const elements = t.members;
|
|
233
|
+
if (elements.length === 0) {
|
|
234
|
+
const empty = b.created(new TypeLiteralNode(b.list([])));
|
|
235
|
+
b.context.addEmitFlags(empty, 1 /* EmitFlags.SingleLine */);
|
|
236
|
+
return empty;
|
|
237
|
+
}
|
|
238
|
+
// The checker's const context, which includes const type parameters' contexts.
|
|
239
|
+
const isConst = isConstContext(c, elements[0].name.parent.parent);
|
|
240
|
+
const newElements = [];
|
|
241
|
+
const savedFlags = b.flags;
|
|
242
|
+
// As `createTypeNodeFromObjectType`, so inaccessible `this` in members is reported.
|
|
243
|
+
b.flags |= 4194304 /* NodeBuilderFlags.InObjectTypeLiteral */;
|
|
244
|
+
for (const e of elements) {
|
|
245
|
+
const modifiers = isConst || (e.kind === 1 /* PseudoMemberKind.Property */ && e.readonly)
|
|
246
|
+
? b.modifierList([b.token(148 /* SyntaxKind.ReadonlyKeyword */)])
|
|
247
|
+
: undefined;
|
|
248
|
+
let cleanup = undefined;
|
|
249
|
+
if (e.kind !== 1 /* PseudoMemberKind.Property */ && e.signature !== undefined) {
|
|
250
|
+
const signature = getSignatureFromDeclaration(c, e.signature);
|
|
251
|
+
const expandedParams = getExpandedParameters(c, signature, true)[0];
|
|
252
|
+
cleanup = b.enterNewScope(e.signature, expandedParams, signature.typeParameters, signature.parameters, signature.mapper);
|
|
253
|
+
}
|
|
254
|
+
let newProp;
|
|
255
|
+
switch (e.kind) {
|
|
256
|
+
case 0 /* PseudoMemberKind.Method */: {
|
|
257
|
+
const typeParams = reuseTypeParameters(b, e.typeParameters);
|
|
258
|
+
if (isConst) {
|
|
259
|
+
newProp = b.created(new PropertySignatureDeclaration(modifiers, reuseName(b, e.name, false), undefined, b.created(new FunctionTypeNode(typeParams, b.list(pseudoParametersToNodes(b, e.parameters)), pseudoTypeToNode(b, e.type))), undefined));
|
|
260
|
+
break;
|
|
261
|
+
}
|
|
262
|
+
newProp = b.created(new MethodSignatureDeclaration(modifiers, reuseName(b, e.name, true), undefined, typeParams, b.list(pseudoParametersToNodes(b, e.parameters)), pseudoTypeToNode(b, e.type)));
|
|
263
|
+
break;
|
|
264
|
+
}
|
|
265
|
+
case 1 /* PseudoMemberKind.Property */:
|
|
266
|
+
newProp = b.created(new PropertySignatureDeclaration(modifiers, reuseName(b, e.name, false), undefined, pseudoTypeToNode(b, e.type), undefined));
|
|
267
|
+
break;
|
|
268
|
+
case 2 /* PseudoMemberKind.SetAccessor */:
|
|
269
|
+
newProp = b.created(new SetAccessorDeclaration(undefined, reuseName(b, e.name, false), undefined, b.list(e.parameters.length > 0 ? [pseudoParameterToNode(b, e.parameters[0])] : []), undefined, undefined, undefined));
|
|
270
|
+
break;
|
|
271
|
+
default:
|
|
272
|
+
newProp = b.created(new GetAccessorDeclaration(undefined, reuseName(b, e.name, false), undefined, b.list([]), pseudoTypeToNode(b, e.type), undefined, undefined));
|
|
273
|
+
break;
|
|
274
|
+
}
|
|
275
|
+
if (b.enclosingFile === getSourceFileOfNode(e.name)) {
|
|
276
|
+
const declaration = e.name.parent;
|
|
277
|
+
b.context.setCommentRange(newProp, declaration.pos, declaration.end);
|
|
278
|
+
}
|
|
279
|
+
newElements.push(newProp);
|
|
280
|
+
if (cleanup !== undefined)
|
|
281
|
+
cleanup();
|
|
282
|
+
}
|
|
283
|
+
b.flags = savedFlags;
|
|
284
|
+
const result = b.created(new TypeLiteralNode(b.list(newElements)));
|
|
285
|
+
if ((b.flags & 1024 /* NodeBuilderFlags.MultilineObjectLiterals */) === 0)
|
|
286
|
+
b.context.addEmitFlags(result, 1 /* EmitFlags.SingleLine */);
|
|
287
|
+
return result;
|
|
288
|
+
}
|
|
289
|
+
function reuseTypeParameters(b, typeParameters) {
|
|
290
|
+
if (typeParameters.length === 0)
|
|
291
|
+
return undefined;
|
|
292
|
+
const res = [];
|
|
293
|
+
for (const tp of typeParameters) {
|
|
294
|
+
const reused = reuseNode(b, tp);
|
|
295
|
+
if (reused !== undefined)
|
|
296
|
+
res.push(reused);
|
|
297
|
+
}
|
|
298
|
+
return b.list(res);
|
|
299
|
+
}
|
|
300
|
+
function pseudoParametersToNodes(b, params) {
|
|
301
|
+
const res = [];
|
|
302
|
+
for (const p of params)
|
|
303
|
+
res.push(pseudoParameterToNode(b, p));
|
|
304
|
+
return res;
|
|
305
|
+
}
|
|
306
|
+
function pseudoParameterToNode(b, p) {
|
|
307
|
+
const original = p.name.parent;
|
|
308
|
+
const parameter = b.created(new ParameterDeclaration(undefined, p.rest ? b.token(25 /* SyntaxKind.DotDotDotToken */) : undefined,
|
|
309
|
+
// Parameter names are always written from scratch.
|
|
310
|
+
b.parameterToParameterDeclarationName(getSymbol(original), original), p.optional ? b.token(57 /* SyntaxKind.QuestionToken */) : undefined, pseudoTypeToNode(b, p.type), undefined));
|
|
311
|
+
if (original.kind === 170 /* SyntaxKind.Parameter */)
|
|
312
|
+
b.setCommentRange(parameter, original);
|
|
313
|
+
return parameter;
|
|
314
|
+
}
|
|
315
|
+
function reuseNode(b, node) {
|
|
316
|
+
return tryReuseExistingNode(b, node);
|
|
317
|
+
}
|
|
318
|
+
function reuseName(b, node, isMethod) {
|
|
319
|
+
const res = reuseNode(b, node);
|
|
320
|
+
if (res === undefined)
|
|
321
|
+
return node;
|
|
322
|
+
const text = tryGetTextOfPropertyName(res);
|
|
323
|
+
if (text === undefined)
|
|
324
|
+
return res;
|
|
325
|
+
const kind = classifyPropertyName(text, res.kind === 10 /* SyntaxKind.StringLiteral */, isMethod);
|
|
326
|
+
if (res.kind === 79 /* SyntaxKind.Identifier */ && kind === 0 /* PropertyNameKind.Identifier */)
|
|
327
|
+
return res;
|
|
328
|
+
if (res.kind === 10 /* SyntaxKind.StringLiteral */ && kind === 2 /* PropertyNameKind.StringLiteral */)
|
|
329
|
+
return res;
|
|
330
|
+
let renamed;
|
|
331
|
+
if (kind === 0 /* PropertyNameKind.Identifier */)
|
|
332
|
+
renamed = b.identifier(text);
|
|
333
|
+
else if (kind === 2 /* PropertyNameKind.StringLiteral */)
|
|
334
|
+
renamed = b.created(new StringLiteral(text, 0 /* TokenFlags.None */));
|
|
335
|
+
else
|
|
336
|
+
return res;
|
|
337
|
+
b.context.setOriginal(renamed, res);
|
|
338
|
+
return b.setTextRange(renamed, res);
|
|
339
|
+
}
|
|
340
|
+
/** A copy of an annotation; when its names can't be written here, the type it denotes. */
|
|
341
|
+
function reuseTypeNode(b, node) {
|
|
342
|
+
const r = reuseNode(b, node);
|
|
343
|
+
if (r !== undefined)
|
|
344
|
+
return r;
|
|
345
|
+
b.tracker.reportInferenceFallback(node);
|
|
346
|
+
const t = b.getTypeFromTypeNode(node, false);
|
|
347
|
+
return b.typeToTypeNode(t);
|
|
348
|
+
}
|
|
349
|
+
/**
|
|
350
|
+
* Whether a pseudo-type denotes `type_`. Reports the parts that need inference when
|
|
351
|
+
* `reportErrors`; an error type matches anything.
|
|
352
|
+
*/
|
|
353
|
+
export function pseudoTypeEquivalentToType(b, t, type_, isOptionalAnnotated, reportErrors) {
|
|
354
|
+
const c = b.c;
|
|
355
|
+
if (type_ !== undefined && isErrorType(c, type_))
|
|
356
|
+
return true;
|
|
357
|
+
const typeFromPseudo = pseudoTypeToType(b, t);
|
|
358
|
+
if (typeFromPseudo === type_)
|
|
359
|
+
return true;
|
|
360
|
+
let undefinedStripped = type_;
|
|
361
|
+
if (isOptionalAnnotated && type_ !== undefined)
|
|
362
|
+
undefinedStripped = getTypeWithFacts(c, type_, 524288 /* TypeFacts.NEUndefined */);
|
|
363
|
+
if (typeFromPseudo !== undefined && type_ !== undefined) {
|
|
364
|
+
if (isOptionalAnnotated) {
|
|
365
|
+
if (undefinedStripped === typeFromPseudo)
|
|
366
|
+
return true;
|
|
367
|
+
if ((typeFromPseudo.flags & 134217728 /* TypeFlags.Union */) !== 0 &&
|
|
368
|
+
(undefinedStripped.flags & 134217728 /* TypeFlags.Union */) !== 0 &&
|
|
369
|
+
compareTypesIdentical(c, typeFromPseudo, undefinedStripped) === -1 /* Ternary.True */)
|
|
370
|
+
return true;
|
|
371
|
+
}
|
|
372
|
+
// Freshness differs, such as `true` in `as const`.
|
|
373
|
+
if (getRegularTypeOfLiteralType(c, typeFromPseudo) === getRegularTypeOfLiteralType(c, type_))
|
|
374
|
+
return true;
|
|
375
|
+
if ((typeFromPseudo.flags & 134217728 /* TypeFlags.Union */) !== 0 &&
|
|
376
|
+
(type_.flags & 134217728 /* TypeFlags.Union */) !== 0 &&
|
|
377
|
+
compareTypesIdentical(c, typeFromPseudo, type_) === -1 /* Ternary.True */)
|
|
378
|
+
return true;
|
|
379
|
+
}
|
|
380
|
+
switch (t.kind) {
|
|
381
|
+
case 1 /* PseudoTypeKind.Inferred */: {
|
|
382
|
+
const inferred = t;
|
|
383
|
+
if (reportErrors) {
|
|
384
|
+
if (inferred.errorNodes.length > 0)
|
|
385
|
+
for (const n of inferred.errorNodes)
|
|
386
|
+
b.tracker.reportInferenceFallback(n);
|
|
387
|
+
else
|
|
388
|
+
b.tracker.reportInferenceFallback(inferred.expression);
|
|
389
|
+
}
|
|
390
|
+
return false;
|
|
391
|
+
}
|
|
392
|
+
case 16 /* PseudoTypeKind.ObjectLiteral */: {
|
|
393
|
+
if (undefinedStripped === undefined)
|
|
394
|
+
return false;
|
|
395
|
+
const pt = t;
|
|
396
|
+
const targetProps = getPropertiesOfType(c, undefinedStripped);
|
|
397
|
+
// Accessor pairs are two members but one property.
|
|
398
|
+
let targetDeclCount = 0;
|
|
399
|
+
for (const prop of targetProps)
|
|
400
|
+
targetDeclCount += prop.declarations.length;
|
|
401
|
+
if (pt.members.length !== targetDeclCount)
|
|
402
|
+
return false;
|
|
403
|
+
for (const e of pt.members) {
|
|
404
|
+
let targetProp = undefined;
|
|
405
|
+
const elemSymbol = getSymbol(e.name.parent);
|
|
406
|
+
if (elemSymbol !== undefined)
|
|
407
|
+
targetProp = getPropertyOfType(c, undefinedStripped, elemSymbol.name);
|
|
408
|
+
if (targetProp === undefined) {
|
|
409
|
+
for (const prop of targetProps) {
|
|
410
|
+
const vd = prop.valueDeclaration;
|
|
411
|
+
if (vd !== undefined && getName(vd) === e.name) {
|
|
412
|
+
targetProp = prop;
|
|
413
|
+
break;
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
if (targetProp === undefined) {
|
|
417
|
+
if (reportErrors)
|
|
418
|
+
b.tracker.reportInferenceFallback(e.name.parent);
|
|
419
|
+
return false;
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
const targetIsOptional = (targetProp.flags & 16777216 /* SymbolFlags.Optional */) !== 0;
|
|
423
|
+
if (e.optional !== targetIsOptional) {
|
|
424
|
+
if (reportErrors)
|
|
425
|
+
b.tracker.reportInferenceFallback(e.name.parent);
|
|
426
|
+
return false;
|
|
427
|
+
}
|
|
428
|
+
const propType = removeMissingType(c, getTypeOfSymbol(c, targetProp), targetIsOptional);
|
|
429
|
+
switch (e.kind) {
|
|
430
|
+
case 1 /* PseudoMemberKind.Property */:
|
|
431
|
+
if (!pseudoTypeEquivalentToType(b, e.type, propType, e.optional, false)) {
|
|
432
|
+
if (reportErrors) {
|
|
433
|
+
if (e.type instanceof InferredType && e.type.errorNodes.length > 0)
|
|
434
|
+
for (const n of e.type.errorNodes)
|
|
435
|
+
b.tracker.reportInferenceFallback(n);
|
|
436
|
+
else if (!isStructuralPseudoType(e.type))
|
|
437
|
+
b.tracker.reportInferenceFallback(e.name.parent);
|
|
438
|
+
}
|
|
439
|
+
return false;
|
|
440
|
+
}
|
|
441
|
+
break;
|
|
442
|
+
case 0 /* PseudoMemberKind.Method */: {
|
|
443
|
+
const targetSig = getSingleCallSignature(c, propType);
|
|
444
|
+
if (targetSig === undefined)
|
|
445
|
+
continue;
|
|
446
|
+
if (!pseudoParametersEquivalentToParameters(b, e.parameters, targetSig, reportErrors, e.name.parent))
|
|
447
|
+
return false;
|
|
448
|
+
const targetPredicate = getTypePredicateOfSignature(c, targetSig);
|
|
449
|
+
if (targetPredicate !== undefined) {
|
|
450
|
+
if (!pseudoReturnTypeMatchesPredicate(b, e.type, targetPredicate)) {
|
|
451
|
+
if (reportErrors)
|
|
452
|
+
b.tracker.reportInferenceFallback(e.name.parent);
|
|
453
|
+
return false;
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
else if (!pseudoTypeEquivalentToType(b, e.type, getReturnTypeOfSignature(c, targetSig), false, false)) {
|
|
457
|
+
if (reportErrors)
|
|
458
|
+
b.tracker.reportInferenceFallback(e.name.parent);
|
|
459
|
+
return false;
|
|
460
|
+
}
|
|
461
|
+
break;
|
|
462
|
+
}
|
|
463
|
+
case 3 /* PseudoMemberKind.GetAccessor */:
|
|
464
|
+
if (!pseudoTypeEquivalentToType(b, e.type, propType, false, false)) {
|
|
465
|
+
if (reportErrors)
|
|
466
|
+
b.tracker.reportInferenceFallback(e.name.parent);
|
|
467
|
+
return false;
|
|
468
|
+
}
|
|
469
|
+
break;
|
|
470
|
+
case 2 /* PseudoMemberKind.SetAccessor */: {
|
|
471
|
+
const writeType = getWriteTypeOfSymbol(c, targetProp);
|
|
472
|
+
const parameterType = e.parameters.length > 0 ? e.parameters[0].type : undefined;
|
|
473
|
+
if (parameterType === undefined || !pseudoTypeEquivalentToType(b, parameterType, writeType, false, false)) {
|
|
474
|
+
if (reportErrors)
|
|
475
|
+
b.tracker.reportInferenceFallback(e.name.parent);
|
|
476
|
+
return false;
|
|
477
|
+
}
|
|
478
|
+
break;
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
return true;
|
|
483
|
+
}
|
|
484
|
+
case 15 /* PseudoTypeKind.Tuple */: {
|
|
485
|
+
if (undefinedStripped === undefined || !isTupleType(undefinedStripped))
|
|
486
|
+
return false;
|
|
487
|
+
const pt = t;
|
|
488
|
+
const tupleTarget = undefinedStripped.target;
|
|
489
|
+
// `as const` arrays have only required elements.
|
|
490
|
+
if ((tupleTarget.combinedFlags & 14 /* ElementFlags.NonRequired */) !== 0)
|
|
491
|
+
return false;
|
|
492
|
+
const elementTypes = getTypeArguments(c, undefinedStripped);
|
|
493
|
+
if (pt.elements.length !== elementTypes.length)
|
|
494
|
+
return false;
|
|
495
|
+
for (let i = 0; i < pt.elements.length; i++)
|
|
496
|
+
if (!pseudoTypeEquivalentToType(b, pt.elements[i], elementTypes[i], false, reportErrors))
|
|
497
|
+
return false;
|
|
498
|
+
return true;
|
|
499
|
+
}
|
|
500
|
+
case 14 /* PseudoTypeKind.SingleCallSignature */: {
|
|
501
|
+
if (undefinedStripped === undefined)
|
|
502
|
+
return false;
|
|
503
|
+
const targetSig = getSingleCallSignature(c, undefinedStripped);
|
|
504
|
+
if (targetSig === undefined)
|
|
505
|
+
return false;
|
|
506
|
+
const pt = t;
|
|
507
|
+
const targetTypeParameters = targetSig.typeParameters;
|
|
508
|
+
if ((targetTypeParameters === undefined ? 0 : targetTypeParameters.length) !== pt.typeParameters.length) {
|
|
509
|
+
if (reportErrors)
|
|
510
|
+
b.tracker.reportInferenceFallback(pt.signature);
|
|
511
|
+
return false;
|
|
512
|
+
}
|
|
513
|
+
if (!pseudoParametersEquivalentToParameters(b, pt.parameters, targetSig, reportErrors, pt.signature))
|
|
514
|
+
return false;
|
|
515
|
+
const targetPredicate = getTypePredicateOfSignature(c, targetSig);
|
|
516
|
+
if (targetPredicate !== undefined) {
|
|
517
|
+
if (!pseudoReturnTypeMatchesPredicate(b, pt.returnType, targetPredicate)) {
|
|
518
|
+
if (reportErrors)
|
|
519
|
+
b.tracker.reportInferenceFallback(pt.signature);
|
|
520
|
+
return false;
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
else if (!pseudoTypeEquivalentToType(b, pt.returnType, getReturnTypeOfSignature(c, targetSig), false, reportErrors))
|
|
524
|
+
return false;
|
|
525
|
+
return true;
|
|
526
|
+
}
|
|
527
|
+
case 2 /* PseudoTypeKind.NoResult */:
|
|
528
|
+
if (reportErrors)
|
|
529
|
+
b.tracker.reportInferenceFallback(t.declaration);
|
|
530
|
+
return false;
|
|
531
|
+
}
|
|
532
|
+
return false;
|
|
533
|
+
}
|
|
534
|
+
function pseudoParametersEquivalentToParameters(b, paramsIn, targetSig, reportErrors, nonParamErrorLocation) {
|
|
535
|
+
const c = b.c;
|
|
536
|
+
let params = paramsIn;
|
|
537
|
+
const thisParameter = targetSig.thisParameter;
|
|
538
|
+
if (thisParameter !== undefined && params.length === 0) {
|
|
539
|
+
if (reportErrors)
|
|
540
|
+
b.tracker.reportInferenceFallback(nonParamErrorLocation);
|
|
541
|
+
return false;
|
|
542
|
+
}
|
|
543
|
+
else if (thisParameter !== undefined && isThisIdentifier(params[0].name)) {
|
|
544
|
+
const paramType = getTypeOfParameter(c, thisParameter);
|
|
545
|
+
if (!pseudoTypeEquivalentToType(b, params[0].type, paramType, params[0].optional, false)) {
|
|
546
|
+
if (reportErrors)
|
|
547
|
+
b.tracker.reportInferenceFallback(params[0].name.parent);
|
|
548
|
+
return false;
|
|
549
|
+
}
|
|
550
|
+
params = params.slice(1);
|
|
551
|
+
}
|
|
552
|
+
else if (thisParameter !== undefined) {
|
|
553
|
+
if (reportErrors)
|
|
554
|
+
b.tracker.reportInferenceFallback(nonParamErrorLocation);
|
|
555
|
+
return false;
|
|
556
|
+
}
|
|
557
|
+
if (targetSig.parameters.length !== params.length) {
|
|
558
|
+
if (reportErrors)
|
|
559
|
+
b.tracker.reportInferenceFallback(nonParamErrorLocation);
|
|
560
|
+
return false;
|
|
561
|
+
}
|
|
562
|
+
for (let i = 0; i < params.length; i++) {
|
|
563
|
+
const p = params[i];
|
|
564
|
+
const targetParam = targetSig.parameters[i];
|
|
565
|
+
const vd = targetParam.valueDeclaration;
|
|
566
|
+
if (p.optional !== (vd !== undefined && isOptionalParameter(c, vd))) {
|
|
567
|
+
if (reportErrors)
|
|
568
|
+
b.tracker.reportInferenceFallback(p.name.parent);
|
|
569
|
+
return false;
|
|
570
|
+
}
|
|
571
|
+
const paramType = getTypeOfParameter(c, targetParam);
|
|
572
|
+
if (!pseudoTypeEquivalentToType(b, p.type, paramType, p.optional, false)) {
|
|
573
|
+
if (reportErrors)
|
|
574
|
+
b.tracker.reportInferenceFallback(p.name.parent);
|
|
575
|
+
return false;
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
return true;
|
|
579
|
+
}
|
|
580
|
+
function isThisIdentifier(node) {
|
|
581
|
+
return node instanceof Identifier && getText(node) === 'this';
|
|
582
|
+
}
|
|
583
|
+
function isStructuralPseudoType(t) {
|
|
584
|
+
switch (t.kind) {
|
|
585
|
+
case 16 /* PseudoTypeKind.ObjectLiteral */:
|
|
586
|
+
case 15 /* PseudoTypeKind.Tuple */:
|
|
587
|
+
case 14 /* PseudoTypeKind.SingleCallSignature */:
|
|
588
|
+
return true;
|
|
589
|
+
case 3 /* PseudoTypeKind.MaybeConstLocation */: {
|
|
590
|
+
const d = t;
|
|
591
|
+
return isStructuralPseudoType(d.constType) || isStructuralPseudoType(d.regularType);
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
return false;
|
|
595
|
+
}
|
|
596
|
+
/** Whether a pseudo return type is a type predicate annotation matching `predicate`. */
|
|
597
|
+
export function pseudoReturnTypeMatchesPredicate(b, rt, predicate) {
|
|
598
|
+
if (!(rt instanceof DirectType))
|
|
599
|
+
return false;
|
|
600
|
+
const node = rt.typeNode;
|
|
601
|
+
if (!(node instanceof TypePredicateNode))
|
|
602
|
+
return false;
|
|
603
|
+
const isAsserts = node.assertsModifier !== undefined;
|
|
604
|
+
const predicateIsAsserts = predicate.kind === 2 /* TypePredicateKind.AssertsThis */ || predicate.kind === 3 /* TypePredicateKind.AssertsIdentifier */;
|
|
605
|
+
if (isAsserts !== predicateIsAsserts)
|
|
606
|
+
return false;
|
|
607
|
+
const isThis = node.parameterName.kind === 198 /* SyntaxKind.ThisType */;
|
|
608
|
+
const predicateIsThis = predicate.kind === 0 /* TypePredicateKind.This */ || predicate.kind === 2 /* TypePredicateKind.AssertsThis */;
|
|
609
|
+
if (isThis !== predicateIsThis)
|
|
610
|
+
return false;
|
|
611
|
+
if (!isThis && getText(node.parameterName) !== predicate.parameterName)
|
|
612
|
+
return false;
|
|
613
|
+
if (predicate.type !== undefined) {
|
|
614
|
+
if (node.type === undefined)
|
|
615
|
+
return false;
|
|
616
|
+
const fromNode = getTypeFromTypeNode(b.c, node.type);
|
|
617
|
+
if (fromNode !== predicate.type && compareTypesIdentical(b.c, fromNode, predicate.type) !== -1 /* Ternary.True */)
|
|
618
|
+
return false;
|
|
619
|
+
}
|
|
620
|
+
else if (node.type !== undefined)
|
|
621
|
+
return false;
|
|
622
|
+
return true;
|
|
623
|
+
}
|
|
624
|
+
function getTypeOfExpressionForPseudo(c, node) {
|
|
625
|
+
return checkExpressionCached(c, node);
|
|
626
|
+
}
|
|
627
|
+
/** The type a pseudo-type denotes, for the kinds that map to one directly. */
|
|
628
|
+
export function pseudoTypeToType(b, t) {
|
|
629
|
+
const c = b.c;
|
|
630
|
+
switch (t.kind) {
|
|
631
|
+
case 0 /* PseudoTypeKind.Direct */:
|
|
632
|
+
return getTypeFromTypeNode(c, t.typeNode);
|
|
633
|
+
case 1 /* PseudoTypeKind.Inferred */: {
|
|
634
|
+
const inferred = t;
|
|
635
|
+
if (inferred.isSignatureReturn)
|
|
636
|
+
return getReturnTypeOfSignature(c, getSignatureFromDeclaration(c, inferred.expression));
|
|
637
|
+
return getWidenedType(c, getRegularTypeOfExpression(c, inferred.expression));
|
|
638
|
+
}
|
|
639
|
+
case 2 /* PseudoTypeKind.NoResult */:
|
|
640
|
+
return undefined;
|
|
641
|
+
case 3 /* PseudoTypeKind.MaybeConstLocation */: {
|
|
642
|
+
const d = t;
|
|
643
|
+
return pseudoTypeToType(b, isConstContext(c, d.node) ? d.constType : d.regularType);
|
|
644
|
+
}
|
|
645
|
+
case 4 /* PseudoTypeKind.Union */: {
|
|
646
|
+
const res = [];
|
|
647
|
+
let hasElidedType = false;
|
|
648
|
+
for (const m of t.types) {
|
|
649
|
+
if (!c.strictNullChecks && (m.kind === 5 /* PseudoTypeKind.Undefined */ || m.kind === 6 /* PseudoTypeKind.Null */)) {
|
|
650
|
+
hasElidedType = true;
|
|
651
|
+
continue;
|
|
652
|
+
}
|
|
653
|
+
const mt = pseudoTypeToType(b, m);
|
|
654
|
+
if (mt === undefined)
|
|
655
|
+
return undefined;
|
|
656
|
+
res.push(mt);
|
|
657
|
+
}
|
|
658
|
+
if (res.length === 1)
|
|
659
|
+
return res[0];
|
|
660
|
+
if (res.length === 0)
|
|
661
|
+
return hasElidedType ? c.anyType : c.neverType;
|
|
662
|
+
return getUnionType(c, res);
|
|
663
|
+
}
|
|
664
|
+
case 5 /* PseudoTypeKind.Undefined */:
|
|
665
|
+
return c.undefinedWideningType;
|
|
666
|
+
case 6 /* PseudoTypeKind.Null */:
|
|
667
|
+
return c.nullWideningType;
|
|
668
|
+
case 7 /* PseudoTypeKind.Any */:
|
|
669
|
+
return c.anyType;
|
|
670
|
+
case 8 /* PseudoTypeKind.String */:
|
|
671
|
+
return c.stringType;
|
|
672
|
+
case 9 /* PseudoTypeKind.Number */:
|
|
673
|
+
return c.numberType;
|
|
674
|
+
case 10 /* PseudoTypeKind.BigInt */:
|
|
675
|
+
return c.bigintType;
|
|
676
|
+
case 11 /* PseudoTypeKind.Boolean */:
|
|
677
|
+
return c.booleanType;
|
|
678
|
+
case 12 /* PseudoTypeKind.False */:
|
|
679
|
+
return c.falseType;
|
|
680
|
+
case 13 /* PseudoTypeKind.True */:
|
|
681
|
+
return c.trueType;
|
|
682
|
+
case 17 /* PseudoTypeKind.StringLiteral */:
|
|
683
|
+
case 18 /* PseudoTypeKind.NumericLiteral */:
|
|
684
|
+
case 19 /* PseudoTypeKind.BigIntLiteral */:
|
|
685
|
+
return getRegularTypeOfExpression(c, t.node);
|
|
686
|
+
}
|
|
687
|
+
return undefined;
|
|
688
|
+
}
|
|
689
|
+
/**
|
|
690
|
+
* Whether the type written for a parameter or property needs `| undefined`: a parameter
|
|
691
|
+
* initialized before a required one, or an optional property of a reverse mapped type.
|
|
692
|
+
*/
|
|
693
|
+
export function requiresAddingImplicitUndefinedForDeclaration(c, declaration, symbolIn, enclosingDeclaration) {
|
|
694
|
+
if ((declaration.flags & 16 /* NodeFlags.Synthesized */) !== 0)
|
|
695
|
+
return false;
|
|
696
|
+
switch (declaration.kind) {
|
|
697
|
+
case 173 /* SyntaxKind.PropertyDeclaration */:
|
|
698
|
+
case 172 /* SyntaxKind.PropertySignature */:
|
|
699
|
+
case 340 /* SyntaxKind.JSDocPropertyTag */: {
|
|
700
|
+
const symbol = symbolIn ?? getSymbolOfDeclaration(c, declaration);
|
|
701
|
+
if (symbol === undefined)
|
|
702
|
+
return false;
|
|
703
|
+
const t = getTypeOfSymbol(c, symbol);
|
|
704
|
+
return ((symbol.flags & 4 /* SymbolFlags.Property */) !== 0 &&
|
|
705
|
+
(symbol.flags & 16777216 /* SymbolFlags.Optional */) !== 0 &&
|
|
706
|
+
hasQuestionToken(declaration) &&
|
|
707
|
+
(symbol.checkFlags & 8192 /* CheckFlags.ReverseMapped */) !== 0 &&
|
|
708
|
+
c.symbolLinks(symbol).reverseMappedMappedType !== undefined &&
|
|
709
|
+
containsNonMissingUndefinedType(c, t));
|
|
710
|
+
}
|
|
711
|
+
case 170 /* SyntaxKind.Parameter */:
|
|
712
|
+
return requiresAddingImplicitUndefined(c, declaration, enclosingDeclaration);
|
|
713
|
+
}
|
|
714
|
+
return false;
|
|
715
|
+
}
|
|
716
|
+
/** Declarations whose type the builder writes from the declaration, as tsgo's `HasInferredType`. */
|
|
717
|
+
export function hasInferredTypeKind(node) {
|
|
718
|
+
switch (node.kind) {
|
|
719
|
+
case 170 /* SyntaxKind.Parameter */:
|
|
720
|
+
case 172 /* SyntaxKind.PropertySignature */:
|
|
721
|
+
case 173 /* SyntaxKind.PropertyDeclaration */:
|
|
722
|
+
case 209 /* SyntaxKind.BindingElement */:
|
|
723
|
+
case 212 /* SyntaxKind.PropertyAccessExpression */:
|
|
724
|
+
case 213 /* SyntaxKind.ElementAccessExpression */:
|
|
725
|
+
case 227 /* SyntaxKind.BinaryExpression */:
|
|
726
|
+
case 214 /* SyntaxKind.CallExpression */:
|
|
727
|
+
case 261 /* SyntaxKind.VariableDeclaration */:
|
|
728
|
+
case 278 /* SyntaxKind.ExportAssignment */:
|
|
729
|
+
case 303 /* SyntaxKind.PropertyAssignment */:
|
|
730
|
+
case 304 /* SyntaxKind.ShorthandPropertyAssignment */:
|
|
731
|
+
case 333 /* SyntaxKind.JSDocParameterTag */:
|
|
732
|
+
case 340 /* SyntaxKind.JSDocPropertyTag */:
|
|
733
|
+
return true;
|
|
734
|
+
}
|
|
735
|
+
return false;
|
|
736
|
+
}
|
|
737
|
+
export function isAccessorKind(node) {
|
|
738
|
+
return node.kind === 178 /* SyntaxKind.GetAccessor */ || node.kind === 179 /* SyntaxKind.SetAccessor */;
|
|
739
|
+
}
|
|
740
|
+
/** Whether a declaration is marked optional with `?`, as tsgo's `HasQuestionToken`. */
|
|
741
|
+
export function hasQuestionToken(node) {
|
|
742
|
+
const token = getQuestionToken(node) ?? getPostfixToken(node);
|
|
743
|
+
return token !== undefined && token.kind === 57 /* SyntaxKind.QuestionToken */;
|
|
744
|
+
}
|