tsc-ts 0.0.3 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +46 -0
- package/dist/api/compiler/ast-utilities.d.ts +82 -0
- package/dist/api/compiler/ast-utilities.js +462 -0
- package/dist/api/compiler/ast.d.ts +2350 -0
- package/dist/api/compiler/ast.js +11206 -0
- package/dist/api/compiler/astnav.d.ts +37 -0
- package/dist/api/compiler/astnav.js +767 -0
- package/dist/api/compiler/binder-utilities.d.ts +182 -0
- package/dist/api/compiler/binder-utilities.js +1240 -0
- package/dist/api/compiler/binder.d.ts +33 -0
- package/dist/api/compiler/binder.js +2358 -0
- package/dist/api/compiler/character-codes.d.ts +161 -0
- package/dist/api/compiler/character-codes.js +160 -0
- package/dist/api/compiler/checker-calls.d.ts +46 -0
- package/dist/api/compiler/checker-calls.js +1640 -0
- package/dist/api/compiler/checker-classes.d.ts +30 -0
- package/dist/api/compiler/checker-classes.js +582 -0
- package/dist/api/compiler/checker-contextual.d.ts +77 -0
- package/dist/api/compiler/checker-contextual.js +1136 -0
- package/dist/api/compiler/checker-declaration-order.d.ts +12 -0
- package/dist/api/compiler/checker-declaration-order.js +356 -0
- package/dist/api/compiler/checker-declarations.d.ts +33 -0
- package/dist/api/compiler/checker-declarations.js +888 -0
- package/dist/api/compiler/checker-declared-types.d.ts +48 -0
- package/dist/api/compiler/checker-declared-types.js +787 -0
- package/dist/api/compiler/checker-decorators.d.ts +26 -0
- package/dist/api/compiler/checker-decorators.js +562 -0
- package/dist/api/compiler/checker-deprecation.d.ts +33 -0
- package/dist/api/compiler/checker-deprecation.js +315 -0
- package/dist/api/compiler/checker-destructuring.d.ts +34 -0
- package/dist/api/compiler/checker-destructuring.js +584 -0
- package/dist/api/compiler/checker-elaboration.d.ts +15 -0
- package/dist/api/compiler/checker-elaboration.js +290 -0
- package/dist/api/compiler/checker-emit-helpers.d.ts +58 -0
- package/dist/api/compiler/checker-emit-helpers.js +154 -0
- package/dist/api/compiler/checker-emit-resolver.d.ts +75 -0
- package/dist/api/compiler/checker-emit-resolver.js +579 -0
- package/dist/api/compiler/checker-evaluator.d.ts +27 -0
- package/dist/api/compiler/checker-evaluator.js +188 -0
- package/dist/api/compiler/checker-expressions.d.ts +67 -0
- package/dist/api/compiler/checker-expressions.js +1351 -0
- package/dist/api/compiler/checker-features.d.ts +6 -0
- package/dist/api/compiler/checker-features.js +354 -0
- package/dist/api/compiler/checker-flow.d.ts +86 -0
- package/dist/api/compiler/checker-flow.js +169 -0
- package/dist/api/compiler/checker-functions.d.ts +43 -0
- package/dist/api/compiler/checker-functions.js +1002 -0
- package/dist/api/compiler/checker-generated-code.d.ts +25 -0
- package/dist/api/compiler/checker-generated-code.js +168 -0
- package/dist/api/compiler/checker-globals.d.ts +14 -0
- package/dist/api/compiler/checker-globals.js +37 -0
- package/dist/api/compiler/checker-grammar.d.ts +35 -0
- package/dist/api/compiler/checker-grammar.js +2573 -0
- package/dist/api/compiler/checker-heritage.d.ts +28 -0
- package/dist/api/compiler/checker-heritage.js +900 -0
- package/dist/api/compiler/checker-inference.d.ts +179 -0
- package/dist/api/compiler/checker-inference.js +2105 -0
- package/dist/api/compiler/checker-iteration.d.ts +115 -0
- package/dist/api/compiler/checker-iteration.js +857 -0
- package/dist/api/compiler/checker-javascript.d.ts +42 -0
- package/dist/api/compiler/checker-javascript.js +441 -0
- package/dist/api/compiler/checker-jsdoc.d.ts +30 -0
- package/dist/api/compiler/checker-jsdoc.js +320 -0
- package/dist/api/compiler/checker-jsx.d.ts +94 -0
- package/dist/api/compiler/checker-jsx.js +1433 -0
- package/dist/api/compiler/checker-literals.d.ts +6 -0
- package/dist/api/compiler/checker-literals.js +43 -0
- package/dist/api/compiler/checker-members.d.ts +198 -0
- package/dist/api/compiler/checker-members.js +2126 -0
- package/dist/api/compiler/checker-modules.d.ts +85 -0
- package/dist/api/compiler/checker-modules.js +2141 -0
- package/dist/api/compiler/checker-narrowing.d.ts +120 -0
- package/dist/api/compiler/checker-narrowing.js +2797 -0
- package/dist/api/compiler/checker-object-literals.d.ts +14 -0
- package/dist/api/compiler/checker-object-literals.js +479 -0
- package/dist/api/compiler/checker-operators.d.ts +33 -0
- package/dist/api/compiler/checker-operators.js +1040 -0
- package/dist/api/compiler/checker-overloads.d.ts +7 -0
- package/dist/api/compiler/checker-overloads.js +270 -0
- package/dist/api/compiler/checker-property-access.d.ts +34 -0
- package/dist/api/compiler/checker-property-access.js +672 -0
- package/dist/api/compiler/checker-services.d.ts +49 -0
- package/dist/api/compiler/checker-services.js +995 -0
- package/dist/api/compiler/checker-signatures.d.ts +55 -0
- package/dist/api/compiler/checker-signatures.js +788 -0
- package/dist/api/compiler/checker-source-file.d.ts +27 -0
- package/dist/api/compiler/checker-source-file.js +619 -0
- package/dist/api/compiler/checker-statements.d.ts +18 -0
- package/dist/api/compiler/checker-statements.js +226 -0
- package/dist/api/compiler/checker-super.d.ts +13 -0
- package/dist/api/compiler/checker-super.js +241 -0
- package/dist/api/compiler/checker-symbol-types.d.ts +67 -0
- package/dist/api/compiler/checker-symbol-types.js +1885 -0
- package/dist/api/compiler/checker-symbols.d.ts +181 -0
- package/dist/api/compiler/checker-symbols.js +1782 -0
- package/dist/api/compiler/checker-type-factory.d.ts +142 -0
- package/dist/api/compiler/checker-type-factory.js +2501 -0
- package/dist/api/compiler/checker-type-nodes.d.ts +26 -0
- package/dist/api/compiler/checker-type-nodes.js +828 -0
- package/dist/api/compiler/checker-type-operators.d.ts +109 -0
- package/dist/api/compiler/checker-type-operators.js +1842 -0
- package/dist/api/compiler/checker-types.d.ts +1027 -0
- package/dist/api/compiler/checker-types.js +1697 -0
- package/dist/api/compiler/checker-unused.d.ts +19 -0
- package/dist/api/compiler/checker-unused.js +524 -0
- package/dist/api/compiler/checker-utilities.d.ts +33 -0
- package/dist/api/compiler/checker-utilities.js +141 -0
- package/dist/api/compiler/checker.d.ts +491 -0
- package/dist/api/compiler/checker.js +912 -0
- package/dist/api/compiler/command-line.d.ts +32 -0
- package/dist/api/compiler/command-line.js +383 -0
- package/dist/api/compiler/compile-program.d.ts +118 -0
- package/dist/api/compiler/compile-program.js +384 -0
- package/dist/api/compiler/diagnostic-locales.d.ts +22 -0
- package/dist/api/compiler/diagnostic-locales.js +64 -0
- package/dist/api/compiler/diagnostic-messages.d.ts +2166 -0
- package/dist/api/compiler/diagnostic-messages.js +184 -0
- package/dist/api/compiler/diagnostics.d.ts +167 -0
- package/dist/api/compiler/diagnostics.js +820 -0
- package/dist/api/compiler/emitter.d.ts +71 -0
- package/dist/api/compiler/emitter.js +327 -0
- package/dist/api/compiler/file-include.d.ts +117 -0
- package/dist/api/compiler/file-include.js +536 -0
- package/dist/api/compiler/file-loader.d.ts +261 -0
- package/dist/api/compiler/file-loader.js +1257 -0
- package/dist/api/compiler/file-system.d.ts +51 -0
- package/dist/api/compiler/file-system.js +132 -0
- package/dist/api/compiler/flow.d.ts +60 -0
- package/dist/api/compiler/flow.js +45 -0
- package/dist/api/compiler/instantiation.d.ts +74 -0
- package/dist/api/compiler/instantiation.js +799 -0
- package/dist/api/compiler/jsdoc.d.ts +75 -0
- package/dist/api/compiler/jsdoc.js +1229 -0
- package/dist/api/compiler/link-tables.d.ts +36 -0
- package/dist/api/compiler/link-tables.js +83 -0
- package/dist/api/compiler/locale-data.d.ts +24 -0
- package/dist/api/compiler/locale-data.js +183 -0
- package/dist/api/compiler/locale.d.ts +4 -0
- package/dist/api/compiler/locale.js +317 -0
- package/dist/api/compiler/locales/cs-CZ.d.ts +2 -0
- package/dist/api/compiler/locales/cs-CZ.js +3 -0
- package/dist/api/compiler/locales/de-DE.d.ts +2 -0
- package/dist/api/compiler/locales/de-DE.js +3 -0
- package/dist/api/compiler/locales/es-ES.d.ts +2 -0
- package/dist/api/compiler/locales/es-ES.js +3 -0
- package/dist/api/compiler/locales/fr-FR.d.ts +2 -0
- package/dist/api/compiler/locales/fr-FR.js +3 -0
- package/dist/api/compiler/locales/it-IT.d.ts +2 -0
- package/dist/api/compiler/locales/it-IT.js +3 -0
- package/dist/api/compiler/locales/ja-JP.d.ts +2 -0
- package/dist/api/compiler/locales/ja-JP.js +3 -0
- package/dist/api/compiler/locales/ko-KR.d.ts +2 -0
- package/dist/api/compiler/locales/ko-KR.js +3 -0
- package/dist/api/compiler/locales/pl-PL.d.ts +2 -0
- package/dist/api/compiler/locales/pl-PL.js +3 -0
- package/dist/api/compiler/locales/pt-BR.d.ts +2 -0
- package/dist/api/compiler/locales/pt-BR.js +3 -0
- package/dist/api/compiler/locales/ru-RU.d.ts +2 -0
- package/dist/api/compiler/locales/ru-RU.js +3 -0
- package/dist/api/compiler/locales/tr-TR.d.ts +2 -0
- package/dist/api/compiler/locales/tr-TR.js +3 -0
- package/dist/api/compiler/locales/zh-CN.d.ts +2 -0
- package/dist/api/compiler/locales/zh-CN.js +3 -0
- package/dist/api/compiler/locales/zh-TW.d.ts +2 -0
- package/dist/api/compiler/locales/zh-TW.js +3 -0
- package/dist/api/compiler/module-resolution-types.d.ts +83 -0
- package/dist/api/compiler/module-resolution-types.js +176 -0
- package/dist/api/compiler/module-resolution.d.ts +71 -0
- package/dist/api/compiler/module-resolution.js +1598 -0
- package/dist/api/compiler/module-specifiers.d.ts +64 -0
- package/dist/api/compiler/module-specifiers.js +1101 -0
- package/dist/api/compiler/name-resolver.d.ts +43 -0
- package/dist/api/compiler/name-resolver.js +509 -0
- package/dist/api/compiler/node-builder-names.d.ts +32 -0
- package/dist/api/compiler/node-builder-names.js +854 -0
- package/dist/api/compiler/node-builder-pseudo.d.ts +36 -0
- package/dist/api/compiler/node-builder-pseudo.js +744 -0
- package/dist/api/compiler/node-builder-reuse.d.ts +4 -0
- package/dist/api/compiler/node-builder-reuse.js +647 -0
- package/dist/api/compiler/node-builder.d.ts +270 -0
- package/dist/api/compiler/node-builder.js +2645 -0
- package/dist/api/compiler/option-declarations.d.ts +90 -0
- package/dist/api/compiler/option-declarations.js +1460 -0
- package/dist/api/compiler/options.d.ts +289 -0
- package/dist/api/compiler/options.js +1197 -0
- package/dist/api/compiler/output-paths.d.ts +42 -0
- package/dist/api/compiler/output-paths.js +195 -0
- package/dist/api/compiler/package-json.d.ts +175 -0
- package/dist/api/compiler/package-json.js +1015 -0
- package/dist/api/compiler/parallel-parse.d.ts +219 -0
- package/dist/api/compiler/parallel-parse.js +537 -0
- package/dist/api/compiler/parser.d.ts +587 -0
- package/dist/api/compiler/parser.js +6407 -0
- package/dist/api/compiler/path.d.ts +91 -0
- package/dist/api/compiler/path.js +705 -0
- package/dist/api/compiler/printer/async-helpers.d.ts +22 -0
- package/dist/api/compiler/printer/async-helpers.js +91 -0
- package/dist/api/compiler/printer/auto-generate.d.ts +13 -0
- package/dist/api/compiler/printer/auto-generate.js +20 -0
- package/dist/api/compiler/printer/decorator-helpers.d.ts +24 -0
- package/dist/api/compiler/printer/decorator-helpers.js +118 -0
- package/dist/api/compiler/printer/emit-context.d.ts +154 -0
- package/dist/api/compiler/printer/emit-context.js +576 -0
- package/dist/api/compiler/printer/emit-flags.d.ts +60 -0
- package/dist/api/compiler/printer/emit-flags.js +2 -0
- package/dist/api/compiler/printer/factory-base.d.ts +171 -0
- package/dist/api/compiler/printer/factory-base.js +1505 -0
- package/dist/api/compiler/printer/factory.d.ts +147 -0
- package/dist/api/compiler/printer/factory.js +542 -0
- package/dist/api/compiler/printer/helpers.d.ts +27 -0
- package/dist/api/compiler/printer/helpers.js +164 -0
- package/dist/api/compiler/printer/name-generator.d.ts +41 -0
- package/dist/api/compiler/printer/name-generator.js +283 -0
- package/dist/api/compiler/printer/printer.d.ts +411 -0
- package/dist/api/compiler/printer/printer.js +4517 -0
- package/dist/api/compiler/printer/text-writer.d.ts +46 -0
- package/dist/api/compiler/printer/text-writer.js +172 -0
- package/dist/api/compiler/printer/utilities.d.ts +82 -0
- package/dist/api/compiler/printer/utilities.js +817 -0
- package/dist/api/compiler/program-checker.d.ts +156 -0
- package/dist/api/compiler/program-checker.js +526 -0
- package/dist/api/compiler/program-utilities.d.ts +52 -0
- package/dist/api/compiler/program-utilities.js +365 -0
- package/dist/api/compiler/program.d.ts +180 -0
- package/dist/api/compiler/program.js +1011 -0
- package/dist/api/compiler/pseudo-bigint.d.ts +5 -0
- package/dist/api/compiler/pseudo-bigint.js +61 -0
- package/dist/api/compiler/regexp-checker.d.ts +38 -0
- package/dist/api/compiler/regexp-checker.js +942 -0
- package/dist/api/compiler/relations.d.ts +263 -0
- package/dist/api/compiler/relations.js +4002 -0
- package/dist/api/compiler/reparser.d.ts +48 -0
- package/dist/api/compiler/reparser.js +1323 -0
- package/dist/api/compiler/scanner.d.ts +256 -0
- package/dist/api/compiler/scanner.js +2853 -0
- package/dist/api/compiler/side-state.d.ts +16 -0
- package/dist/api/compiler/side-state.js +89 -0
- package/dist/api/compiler/sourcemap.d.ts +55 -0
- package/dist/api/compiler/sourcemap.js +340 -0
- package/dist/api/compiler/spelling.d.ts +14 -0
- package/dist/api/compiler/spelling.js +128 -0
- package/dist/api/compiler/symbol-accessibility.d.ts +57 -0
- package/dist/api/compiler/symbol-accessibility.js +894 -0
- package/dist/api/compiler/symbol.d.ts +240 -0
- package/dist/api/compiler/symbol.js +228 -0
- package/dist/api/compiler/symlinks.d.ts +32 -0
- package/dist/api/compiler/symlinks.js +114 -0
- package/dist/api/compiler/syntax-kind.d.ts +389 -0
- package/dist/api/compiler/syntax-kind.js +2 -0
- package/dist/api/compiler/timeline.d.ts +9 -0
- package/dist/api/compiler/timeline.js +54 -0
- package/dist/api/compiler/transformers/alias-references.d.ts +39 -0
- package/dist/api/compiler/transformers/alias-references.js +676 -0
- package/dist/api/compiler/transformers/async-utilities.d.ts +51 -0
- package/dist/api/compiler/transformers/async-utilities.js +260 -0
- package/dist/api/compiler/transformers/async.d.ts +53 -0
- package/dist/api/compiler/transformers/async.js +645 -0
- package/dist/api/compiler/transformers/class-fields.d.ts +206 -0
- package/dist/api/compiler/transformers/class-fields.js +2418 -0
- package/dist/api/compiler/transformers/class-utilities.d.ts +46 -0
- package/dist/api/compiler/transformers/class-utilities.js +261 -0
- package/dist/api/compiler/transformers/commonjs-module.d.ts +103 -0
- package/dist/api/compiler/transformers/commonjs-module.js +1180 -0
- package/dist/api/compiler/transformers/const-enum-inliner.d.ts +11 -0
- package/dist/api/compiler/transformers/const-enum-inliner.js +36 -0
- package/dist/api/compiler/transformers/declarations-diagnostics.d.ts +52 -0
- package/dist/api/compiler/transformers/declarations-diagnostics.js +538 -0
- package/dist/api/compiler/transformers/declarations-pseudo.d.ts +160 -0
- package/dist/api/compiler/transformers/declarations-pseudo.js +797 -0
- package/dist/api/compiler/transformers/declarations-resolver.d.ts +152 -0
- package/dist/api/compiler/transformers/declarations-resolver.js +35 -0
- package/dist/api/compiler/transformers/declarations-syntactic.d.ts +119 -0
- package/dist/api/compiler/transformers/declarations-syntactic.js +1582 -0
- package/dist/api/compiler/transformers/declarations-tracker.d.ts +46 -0
- package/dist/api/compiler/transformers/declarations-tracker.js +197 -0
- package/dist/api/compiler/transformers/declarations.d.ts +175 -0
- package/dist/api/compiler/transformers/declarations.js +2380 -0
- package/dist/api/compiler/transformers/decorator-metadata.d.ts +54 -0
- package/dist/api/compiler/transformers/decorator-metadata.js +554 -0
- package/dist/api/compiler/transformers/decorator-utilities.d.ts +38 -0
- package/dist/api/compiler/transformers/decorator-utilities.js +238 -0
- package/dist/api/compiler/transformers/destructuring.d.ts +25 -0
- package/dist/api/compiler/transformers/destructuring.js +626 -0
- package/dist/api/compiler/transformers/downlevel.d.ts +6 -0
- package/dist/api/compiler/transformers/downlevel.js +45 -0
- package/dist/api/compiler/transformers/emit-resolver.d.ts +61 -0
- package/dist/api/compiler/transformers/emit-resolver.js +197 -0
- package/dist/api/compiler/transformers/es-decorators.d.ts +118 -0
- package/dist/api/compiler/transformers/es-decorators.js +1901 -0
- package/dist/api/compiler/transformers/exponentiation.d.ts +11 -0
- package/dist/api/compiler/transformers/exponentiation.js +76 -0
- package/dist/api/compiler/transformers/external-module-info.d.ts +35 -0
- package/dist/api/compiler/transformers/external-module-info.js +351 -0
- package/dist/api/compiler/transformers/for-await.d.ts +43 -0
- package/dist/api/compiler/transformers/for-await.js +469 -0
- package/dist/api/compiler/transformers/import-elision.d.ts +16 -0
- package/dist/api/compiler/transformers/import-elision.js +124 -0
- package/dist/api/compiler/transformers/jsx-entities.d.ts +1 -0
- package/dist/api/compiler/transformers/jsx-entities.js +256 -0
- package/dist/api/compiler/transformers/jsx.d.ts +71 -0
- package/dist/api/compiler/transformers/jsx.js +700 -0
- package/dist/api/compiler/transformers/legacy-decorators.d.ts +56 -0
- package/dist/api/compiler/transformers/legacy-decorators.js +564 -0
- package/dist/api/compiler/transformers/logical-assignment.d.ts +14 -0
- package/dist/api/compiler/transformers/logical-assignment.js +62 -0
- package/dist/api/compiler/transformers/module-utilities.d.ts +9 -0
- package/dist/api/compiler/transformers/module-utilities.js +36 -0
- package/dist/api/compiler/transformers/module.d.ts +49 -0
- package/dist/api/compiler/transformers/module.js +296 -0
- package/dist/api/compiler/transformers/named-evaluation.d.ts +26 -0
- package/dist/api/compiler/transformers/named-evaluation.js +266 -0
- package/dist/api/compiler/transformers/nullish-coalescing.d.ts +9 -0
- package/dist/api/compiler/transformers/nullish-coalescing.js +26 -0
- package/dist/api/compiler/transformers/object-rest-spread.d.ts +34 -0
- package/dist/api/compiler/transformers/object-rest-spread.js +411 -0
- package/dist/api/compiler/transformers/optional-catch.d.ts +9 -0
- package/dist/api/compiler/transformers/optional-catch.js +20 -0
- package/dist/api/compiler/transformers/optional-chain.d.ts +14 -0
- package/dist/api/compiler/transformers/optional-chain.js +188 -0
- package/dist/api/compiler/transformers/reference-resolver.d.ts +128 -0
- package/dist/api/compiler/transformers/reference-resolver.js +1155 -0
- package/dist/api/compiler/transformers/runtime-syntax.d.ts +71 -0
- package/dist/api/compiler/transformers/runtime-syntax.js +753 -0
- package/dist/api/compiler/transformers/subtree-facts.d.ts +9 -0
- package/dist/api/compiler/transformers/subtree-facts.js +203 -0
- package/dist/api/compiler/transformers/syntax-facts.d.ts +51 -0
- package/dist/api/compiler/transformers/syntax-facts.js +254 -0
- package/dist/api/compiler/transformers/tagged-template.d.ts +17 -0
- package/dist/api/compiler/transformers/tagged-template.js +148 -0
- package/dist/api/compiler/transformers/transformer.d.ts +17 -0
- package/dist/api/compiler/transformers/transformer.js +54 -0
- package/dist/api/compiler/transformers/type-eraser.d.ts +21 -0
- package/dist/api/compiler/transformers/type-eraser.js +346 -0
- package/dist/api/compiler/transformers/type-serialization.d.ts +20 -0
- package/dist/api/compiler/transformers/type-serialization.js +347 -0
- package/dist/api/compiler/transformers/using.d.ts +56 -0
- package/dist/api/compiler/transformers/using.js +453 -0
- package/dist/api/compiler/transformers/utilities.d.ts +50 -0
- package/dist/api/compiler/transformers/utilities.js +347 -0
- package/dist/api/compiler/transformers/visitor-base.d.ts +6 -0
- package/dist/api/compiler/transformers/visitor-base.js +817 -0
- package/dist/api/compiler/transformers/visitor-hooks.d.ts +29 -0
- package/dist/api/compiler/transformers/visitor-hooks.js +189 -0
- package/dist/api/compiler/tsconfig.d.ts +177 -0
- package/dist/api/compiler/tsconfig.js +1311 -0
- package/dist/api/compiler/type-printer.d.ts +15 -0
- package/dist/api/compiler/type-printer.js +74 -0
- package/dist/api/compiler/types.d.ts +87 -0
- package/dist/api/compiler/types.js +23 -0
- package/dist/api/compiler/unicode-identifiers.d.ts +2 -0
- package/dist/api/compiler/unicode-identifiers.js +209 -0
- package/dist/api/compiler/unicode-properties.d.ts +8 -0
- package/dist/api/compiler/unicode-properties.js +531 -0
- package/dist/api/compiler/vfs-match.d.ts +24 -0
- package/dist/api/compiler/vfs-match.js +587 -0
- package/dist/api/library/ast.d.ts +74 -0
- package/dist/api/library/ast.generated.d.ts +1145 -0
- package/dist/api/library/ast.generated.js +3 -0
- package/dist/api/library/ast.js +5 -0
- package/dist/api/library/checker.d.ts +51 -0
- package/dist/api/library/checker.js +318 -0
- package/dist/api/library/compiler-options.generated.d.ts +108 -0
- package/dist/api/library/compiler-options.generated.js +3 -0
- package/dist/api/library/diagnostics.d.ts +13 -0
- package/dist/api/library/diagnostics.js +50 -0
- package/dist/api/library/disk.d.ts +13 -0
- package/dist/api/library/disk.js +66 -0
- package/dist/api/library/enums.generated.d.ts +891 -0
- package/dist/api/library/enums.generated.js +916 -0
- package/dist/api/library/errors.d.ts +13 -0
- package/dist/api/library/errors.js +24 -0
- package/dist/api/library/host.d.ts +24 -0
- package/dist/api/library/host.js +52 -0
- package/dist/api/library/index.d.ts +14 -0
- package/dist/api/library/index.js +15 -0
- package/dist/api/library/nodes.d.ts +51 -0
- package/dist/api/library/nodes.js +196 -0
- package/dist/api/library/options.d.ts +144 -0
- package/dist/api/library/options.js +308 -0
- package/dist/api/library/parse.d.ts +19 -0
- package/dist/api/library/parse.js +41 -0
- package/dist/api/library/program.d.ts +21 -0
- package/dist/api/library/program.js +234 -0
- package/dist/api/library/symbols.d.ts +8 -0
- package/dist/api/library/symbols.js +11 -0
- package/dist/api/library/types.d.ts +313 -0
- package/dist/api/library/types.js +6 -0
- package/package.json +22 -8
- package/src/compiler/ast-utilities.ts +548 -0
- package/src/compiler/ast.ts +12862 -0
- package/src/compiler/astnav.ts +799 -0
- package/src/compiler/binder-utilities.ts +1392 -0
- package/src/compiler/binder.ts +2703 -0
- package/src/compiler/build-info.ts +1197 -0
- package/src/compiler/character-codes.ts +323 -0
- package/src/compiler/checker-calls.ts +2155 -0
- package/src/compiler/checker-classes.ts +706 -0
- package/src/compiler/checker-contextual.ts +1457 -0
- package/src/compiler/checker-declaration-order.ts +438 -0
- package/src/compiler/checker-declarations.ts +1194 -0
- package/src/compiler/checker-declared-types.ts +919 -0
- package/src/compiler/checker-decorators.ts +694 -0
- package/src/compiler/checker-deprecation.ts +359 -0
- package/src/compiler/checker-destructuring.ts +805 -0
- package/src/compiler/checker-elaboration.ts +477 -0
- package/src/compiler/checker-emit-helpers.ts +224 -0
- package/src/compiler/checker-emit-resolver.ts +769 -0
- package/src/compiler/checker-evaluator.ts +243 -0
- package/src/compiler/checker-expressions.ts +1831 -0
- package/src/compiler/checker-features.ts +361 -0
- package/src/compiler/checker-flow.ts +394 -0
- package/src/compiler/checker-functions.ts +1296 -0
- package/src/compiler/checker-generated-code.ts +227 -0
- package/src/compiler/checker-globals.ts +52 -0
- package/src/compiler/checker-grammar.ts +3584 -0
- package/src/compiler/checker-heritage.ts +1233 -0
- package/src/compiler/checker-inference.ts +2576 -0
- package/src/compiler/checker-iteration.ts +1206 -0
- package/src/compiler/checker-javascript.ts +502 -0
- package/src/compiler/checker-jsdoc.ts +360 -0
- package/src/compiler/checker-jsx.ts +1924 -0
- package/src/compiler/checker-literals.ts +61 -0
- package/src/compiler/checker-members.ts +2436 -0
- package/src/compiler/checker-modules.ts +2886 -0
- package/src/compiler/checker-narrowing.ts +3230 -0
- package/src/compiler/checker-object-literals.ts +575 -0
- package/src/compiler/checker-operators.ts +1422 -0
- package/src/compiler/checker-overloads.ts +328 -0
- package/src/compiler/checker-property-access.ts +906 -0
- package/src/compiler/checker-services.ts +1149 -0
- package/src/compiler/checker-signatures.ts +1032 -0
- package/src/compiler/checker-source-file.ts +732 -0
- package/src/compiler/checker-statements.ts +292 -0
- package/src/compiler/checker-super.ts +261 -0
- package/src/compiler/checker-symbol-types.ts +2107 -0
- package/src/compiler/checker-symbols.ts +2150 -0
- package/src/compiler/checker-type-factory.ts +2579 -0
- package/src/compiler/checker-type-nodes.ts +1033 -0
- package/src/compiler/checker-type-operators.ts +2502 -0
- package/src/compiler/checker-types.ts +2340 -0
- package/src/compiler/checker-unused.ts +642 -0
- package/src/compiler/checker-utilities.ts +161 -0
- package/src/compiler/checker.ts +1116 -0
- package/src/compiler/command-line.ts +436 -0
- package/src/compiler/compile-program.ts +439 -0
- package/src/compiler/decoder.ts +1209 -0
- package/src/compiler/diagnostic-locales.ts +86 -0
- package/src/compiler/diagnostic-messages.ts +2349 -0
- package/src/compiler/diagnostics.ts +897 -0
- package/src/compiler/emitter.ts +434 -0
- package/src/compiler/encoder.ts +1945 -0
- package/src/compiler/file-include.ts +673 -0
- package/src/compiler/file-loader.ts +1528 -0
- package/src/compiler/file-system.ts +143 -0
- package/src/compiler/flow.ts +89 -0
- package/src/compiler/help.ts +473 -0
- package/src/compiler/incremental.ts +2784 -0
- package/src/compiler/init.ts +141 -0
- package/src/compiler/instantiation.ts +894 -0
- package/src/compiler/jsdoc.ts +1386 -0
- package/src/compiler/link-tables.ts +98 -0
- package/src/compiler/locale-data.ts +203 -0
- package/src/compiler/locale.ts +307 -0
- package/src/compiler/locales/cs-CZ.ts +5 -0
- package/src/compiler/locales/de-DE.ts +5 -0
- package/src/compiler/locales/es-ES.ts +5 -0
- package/src/compiler/locales/fr-FR.ts +5 -0
- package/src/compiler/locales/it-IT.ts +5 -0
- package/src/compiler/locales/ja-JP.ts +5 -0
- package/src/compiler/locales/ko-KR.ts +5 -0
- package/src/compiler/locales/pl-PL.ts +5 -0
- package/src/compiler/locales/pt-BR.ts +5 -0
- package/src/compiler/locales/ru-RU.ts +5 -0
- package/src/compiler/locales/tr-TR.ts +5 -0
- package/src/compiler/locales/zh-CN.ts +5 -0
- package/src/compiler/locales/zh-TW.ts +5 -0
- package/src/compiler/module-resolution-types.ts +243 -0
- package/src/compiler/module-resolution.ts +2072 -0
- package/src/compiler/module-specifiers.ts +1491 -0
- package/src/compiler/name-resolver.ts +646 -0
- package/src/compiler/node-builder-names.ts +1069 -0
- package/src/compiler/node-builder-pseudo.ts +892 -0
- package/src/compiler/node-builder-reuse.ts +764 -0
- package/src/compiler/node-builder.ts +3425 -0
- package/src/compiler/option-declarations.ts +1560 -0
- package/src/compiler/options.ts +1576 -0
- package/src/compiler/output-paths.ts +334 -0
- package/src/compiler/package-json.ts +1083 -0
- package/src/compiler/parallel-check.ts +1951 -0
- package/src/compiler/parallel-parse.ts +590 -0
- package/src/compiler/parse-thread.ts +140 -0
- package/src/compiler/parser.ts +7716 -0
- package/src/compiler/path.ts +717 -0
- package/src/compiler/printer/async-helpers.ts +183 -0
- package/src/compiler/printer/auto-generate.ts +27 -0
- package/src/compiler/printer/decorator-helpers.ts +218 -0
- package/src/compiler/printer/emit-context.ts +679 -0
- package/src/compiler/printer/emit-flags.ts +64 -0
- package/src/compiler/printer/factory-base.ts +2577 -0
- package/src/compiler/printer/factory.ts +764 -0
- package/src/compiler/printer/helpers.ts +291 -0
- package/src/compiler/printer/name-generator.ts +372 -0
- package/src/compiler/printer/printer.ts +5072 -0
- package/src/compiler/printer/text-writer.ts +183 -0
- package/src/compiler/printer/utilities.ts +884 -0
- package/src/compiler/program-checker.ts +592 -0
- package/src/compiler/program-utilities.ts +435 -0
- package/src/compiler/program.ts +1419 -0
- package/src/compiler/pseudo-bigint.ts +62 -0
- package/src/compiler/regexp-checker.ts +1142 -0
- package/src/compiler/relations.ts +5149 -0
- package/src/compiler/reparser.ts +1566 -0
- package/src/compiler/scanner.ts +2951 -0
- package/src/compiler/show-config.ts +239 -0
- package/src/compiler/side-state.ts +125 -0
- package/src/compiler/sourcemap.ts +366 -0
- package/src/compiler/spelling.ts +122 -0
- package/src/compiler/symbol-accessibility.ts +1071 -0
- package/src/compiler/symbol.ts +439 -0
- package/src/compiler/symlinks.ts +137 -0
- package/src/compiler/syntax-kind.ts +391 -0
- package/src/compiler/thread-entry.ts +191 -0
- package/src/compiler/timeline.ts +53 -0
- package/src/compiler/transformers/alias-references.ts +757 -0
- package/src/compiler/transformers/async-utilities.ts +335 -0
- package/src/compiler/transformers/async.ts +838 -0
- package/src/compiler/transformers/class-fields.ts +2967 -0
- package/src/compiler/transformers/class-utilities.ts +324 -0
- package/src/compiler/transformers/commonjs-module.ts +1621 -0
- package/src/compiler/transformers/const-enum-inliner.ts +50 -0
- package/src/compiler/transformers/declarations-diagnostics.ts +832 -0
- package/src/compiler/transformers/declarations-pseudo.ts +966 -0
- package/src/compiler/transformers/declarations-resolver.ts +249 -0
- package/src/compiler/transformers/declarations-syntactic.ts +1859 -0
- package/src/compiler/transformers/declarations-tracker.ts +269 -0
- package/src/compiler/transformers/declarations.ts +3120 -0
- package/src/compiler/transformers/decorator-metadata.ts +697 -0
- package/src/compiler/transformers/decorator-utilities.ts +283 -0
- package/src/compiler/transformers/destructuring.ts +708 -0
- package/src/compiler/transformers/downlevel.ts +50 -0
- package/src/compiler/transformers/emit-resolver.ts +258 -0
- package/src/compiler/transformers/es-decorators.ts +2682 -0
- package/src/compiler/transformers/exponentiation.ts +80 -0
- package/src/compiler/transformers/external-module-info.ts +412 -0
- package/src/compiler/transformers/for-await.ts +687 -0
- package/src/compiler/transformers/import-elision.ts +152 -0
- package/src/compiler/transformers/jsx-entities.ts +256 -0
- package/src/compiler/transformers/jsx.ts +824 -0
- package/src/compiler/transformers/legacy-decorators.ts +726 -0
- package/src/compiler/transformers/logical-assignment.ts +75 -0
- package/src/compiler/transformers/module-utilities.ts +42 -0
- package/src/compiler/transformers/module.ts +474 -0
- package/src/compiler/transformers/named-evaluation.ts +389 -0
- package/src/compiler/transformers/nullish-coalescing.ts +35 -0
- package/src/compiler/transformers/object-rest-spread.ts +577 -0
- package/src/compiler/transformers/optional-catch.ts +29 -0
- package/src/compiler/transformers/optional-chain.ts +246 -0
- package/src/compiler/transformers/reference-resolver.ts +1201 -0
- package/src/compiler/transformers/runtime-syntax.ts +942 -0
- package/src/compiler/transformers/subtree-facts.ts +245 -0
- package/src/compiler/transformers/syntax-facts.ts +353 -0
- package/src/compiler/transformers/tagged-template.ts +167 -0
- package/src/compiler/transformers/transformer.ts +56 -0
- package/src/compiler/transformers/type-eraser.ts +520 -0
- package/src/compiler/transformers/type-serialization.ts +374 -0
- package/src/compiler/transformers/using.ts +613 -0
- package/src/compiler/transformers/utilities.ts +419 -0
- package/src/compiler/transformers/visitor-base.ts +1601 -0
- package/src/compiler/transformers/visitor-hooks.ts +252 -0
- package/src/compiler/tsc-build.ts +1418 -0
- package/src/compiler/tsc-cli.ts +666 -0
- package/src/compiler/tsc-compile.ts +437 -0
- package/src/compiler/tsc-watch.ts +854 -0
- package/src/compiler/tsconfig.ts +1574 -0
- package/src/compiler/type-printer.ts +110 -0
- package/src/compiler/types.ts +115 -0
- package/src/compiler/unicode-identifiers.ts +212 -0
- package/src/compiler/unicode-properties.ts +537 -0
- package/src/compiler/vfs-match.ts +597 -0
- package/src/compiler/xxh3.ts +650 -0
- package/src/library/ast.generated.ts +1685 -0
- package/src/library/ast.ts +104 -0
- package/src/library/checker.ts +384 -0
- package/src/library/compiler-options.generated.ts +114 -0
- package/src/library/diagnostics.ts +72 -0
- package/src/library/disk.ts +73 -0
- package/src/library/enums.generated.ts +1024 -0
- package/src/library/errors.ts +26 -0
- package/src/library/host.ts +63 -0
- package/src/library/index.ts +71 -0
- package/src/library/nodes.ts +232 -0
- package/src/library/options.ts +449 -0
- package/src/library/parse.ts +63 -0
- package/src/library/program.ts +293 -0
- package/src/library/symbols.ts +15 -0
- package/src/library/types.ts +359 -0
|
@@ -0,0 +1,797 @@
|
|
|
1
|
+
// Pseudo-types: the types of declarations as far as syntax decides them, following tsgo's
|
|
2
|
+
// pseudochecker and the isolatedDeclarations rules. Annotations, literals, `as const` values
|
|
3
|
+
// and function expressions with annotated returns have pseudo-types; everything else is
|
|
4
|
+
// "inferred" and needs the checker.
|
|
5
|
+
import { ArrayLiteralExpression, ArrowFunction, FunctionExpression, MethodDeclaration, GetAccessorDeclaration, NodeVisitor, ObjectLiteralExpression, ParameterDeclaration, PrefixUnaryExpression, PropertyAssignment, PropertyDeclaration, ReturnStatement, SetAccessorDeclaration, TypeReferenceNode, VariableDeclaration, UnionTypeNode, IntersectionTypeNode, getAsteriskToken, getBody, getExpression, getName, getParameters, getPostfixToken, getSymbol, getType, getTypeParameters, } from '../ast.js';
|
|
6
|
+
import { isFunctionLike, nodeIsMissing } from '../ast-utilities.js';
|
|
7
|
+
import { getCombinedNodeFlags, hasSyntacticModifier, isIdentifierNamed } from '../binder-utilities.js';
|
|
8
|
+
import { getAllAccessorDeclarations } from './declarations-diagnostics.js';
|
|
9
|
+
export class PseudoType {
|
|
10
|
+
kind;
|
|
11
|
+
constructor(kind) {
|
|
12
|
+
this.kind = kind;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
export class DirectType extends PseudoType {
|
|
16
|
+
typeNode;
|
|
17
|
+
constructor(typeNode) {
|
|
18
|
+
super(0 /* PseudoTypeKind.Direct */);
|
|
19
|
+
this.typeNode = typeNode;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
export class InferredType extends PseudoType {
|
|
23
|
+
expression;
|
|
24
|
+
/** Nodes to report isolatedDeclarations errors on, such as spreads; the expression if empty. */
|
|
25
|
+
errorNodes;
|
|
26
|
+
isSignatureReturn;
|
|
27
|
+
constructor(expression, isSignatureReturn, errorNodes) {
|
|
28
|
+
super(1 /* PseudoTypeKind.Inferred */);
|
|
29
|
+
this.expression = expression;
|
|
30
|
+
this.isSignatureReturn = isSignatureReturn;
|
|
31
|
+
this.errorNodes = errorNodes;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
export class NoResultType extends PseudoType {
|
|
35
|
+
declaration;
|
|
36
|
+
constructor(declaration) {
|
|
37
|
+
super(2 /* PseudoTypeKind.NoResult */);
|
|
38
|
+
this.declaration = declaration;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
export class MaybeConstType extends PseudoType {
|
|
42
|
+
node;
|
|
43
|
+
constType;
|
|
44
|
+
regularType;
|
|
45
|
+
constructor(node, constType, regularType) {
|
|
46
|
+
super(3 /* PseudoTypeKind.MaybeConstLocation */);
|
|
47
|
+
this.node = node;
|
|
48
|
+
this.constType = constType;
|
|
49
|
+
this.regularType = regularType;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
export class UnionType extends PseudoType {
|
|
53
|
+
types;
|
|
54
|
+
constructor(types) {
|
|
55
|
+
super(4 /* PseudoTypeKind.Union */);
|
|
56
|
+
this.types = types;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
export class PseudoParameter {
|
|
60
|
+
rest;
|
|
61
|
+
name;
|
|
62
|
+
optional;
|
|
63
|
+
type;
|
|
64
|
+
constructor(rest, name, optional, type) {
|
|
65
|
+
this.rest = rest;
|
|
66
|
+
this.name = name;
|
|
67
|
+
this.optional = optional;
|
|
68
|
+
this.type = type;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
export class SignatureType extends PseudoType {
|
|
72
|
+
signature;
|
|
73
|
+
parameters;
|
|
74
|
+
typeParameters;
|
|
75
|
+
returnType;
|
|
76
|
+
constructor(signature, parameters, typeParameters, returnType) {
|
|
77
|
+
super(14 /* PseudoTypeKind.SingleCallSignature */);
|
|
78
|
+
this.signature = signature;
|
|
79
|
+
this.parameters = parameters;
|
|
80
|
+
this.typeParameters = typeParameters;
|
|
81
|
+
this.returnType = returnType;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
export class TupleType extends PseudoType {
|
|
85
|
+
elements;
|
|
86
|
+
constructor(elements) {
|
|
87
|
+
super(15 /* PseudoTypeKind.Tuple */);
|
|
88
|
+
this.elements = elements;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
/** A member of an object literal type. */
|
|
92
|
+
export class PseudoMember {
|
|
93
|
+
kind;
|
|
94
|
+
name;
|
|
95
|
+
optional;
|
|
96
|
+
readonly;
|
|
97
|
+
/** The method or accessor declaration; undefined for properties. */
|
|
98
|
+
signature;
|
|
99
|
+
typeParameters;
|
|
100
|
+
parameters;
|
|
101
|
+
/** The property or get accessor type, or the method's return type. */
|
|
102
|
+
type;
|
|
103
|
+
constructor(kind, name, optional, readonly, signature, typeParameters, parameters, type) {
|
|
104
|
+
this.kind = kind;
|
|
105
|
+
this.name = name;
|
|
106
|
+
this.optional = optional;
|
|
107
|
+
this.readonly = readonly;
|
|
108
|
+
this.signature = signature;
|
|
109
|
+
this.typeParameters = typeParameters;
|
|
110
|
+
this.parameters = parameters;
|
|
111
|
+
this.type = type;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
export class ObjectLiteralType extends PseudoType {
|
|
115
|
+
members;
|
|
116
|
+
constructor(members) {
|
|
117
|
+
super(16 /* PseudoTypeKind.ObjectLiteral */);
|
|
118
|
+
this.members = members;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
/** A string, numeric or bigint literal type. */
|
|
122
|
+
export class LiteralType extends PseudoType {
|
|
123
|
+
node;
|
|
124
|
+
constructor(kind, node) {
|
|
125
|
+
super(kind);
|
|
126
|
+
this.node = node;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
export const undefinedType = new PseudoType(5 /* PseudoTypeKind.Undefined */);
|
|
130
|
+
export const nullType = new PseudoType(6 /* PseudoTypeKind.Null */);
|
|
131
|
+
export const anyType = new PseudoType(7 /* PseudoTypeKind.Any */);
|
|
132
|
+
export const stringType = new PseudoType(8 /* PseudoTypeKind.String */);
|
|
133
|
+
export const numberType = new PseudoType(9 /* PseudoTypeKind.Number */);
|
|
134
|
+
export const bigintType = new PseudoType(10 /* PseudoTypeKind.BigInt */);
|
|
135
|
+
export const booleanType = new PseudoType(11 /* PseudoTypeKind.Boolean */);
|
|
136
|
+
export const falseType = new PseudoType(12 /* PseudoTypeKind.False */);
|
|
137
|
+
export const trueType = new PseudoType(13 /* PseudoTypeKind.True */);
|
|
138
|
+
function inferred(expression, isSignatureReturn) {
|
|
139
|
+
return new InferredType(expression, isSignatureReturn, []);
|
|
140
|
+
}
|
|
141
|
+
/** Whether a pseudo-type is inferred without nodes to report errors on. */
|
|
142
|
+
function isBareInferred(type) {
|
|
143
|
+
return type instanceof InferredType && type.errorNodes.length === 0;
|
|
144
|
+
}
|
|
145
|
+
export class PseudoChecker {
|
|
146
|
+
strictNullChecks;
|
|
147
|
+
/** Global symbols merged across files, by each file's symbol. */
|
|
148
|
+
mergedSymbols;
|
|
149
|
+
/** Resolves `undefined`, which a declaration can shadow. */
|
|
150
|
+
names;
|
|
151
|
+
constructor(strictNullChecks, mergedSymbols, names) {
|
|
152
|
+
this.strictNullChecks = strictNullChecks;
|
|
153
|
+
this.mergedSymbols = mergedSymbols;
|
|
154
|
+
this.names = names;
|
|
155
|
+
}
|
|
156
|
+
/** How many `| undefined` additions only the checker can decide; reset by callers. */
|
|
157
|
+
uncertain = 0;
|
|
158
|
+
/** Adds `| undefined` unless the type may already include it; counts the cases that need types to tell. */
|
|
159
|
+
addUndefined(type) {
|
|
160
|
+
if (couldAlreadyReferToUndefined(type) && !definitelyHasUndefined(type))
|
|
161
|
+
this.uncertain++;
|
|
162
|
+
return addUndefinedIfDefinitelyRequired(type);
|
|
163
|
+
}
|
|
164
|
+
getMergedSymbol(symbol) {
|
|
165
|
+
return this.mergedSymbols.get(symbol) ?? symbol;
|
|
166
|
+
}
|
|
167
|
+
getReturnTypeOfSignature(signature) {
|
|
168
|
+
if (signature.kind === 178 /* SyntaxKind.GetAccessor */)
|
|
169
|
+
return this.getTypeOfAccessor(signature);
|
|
170
|
+
return this.createReturnFromSignature(signature);
|
|
171
|
+
}
|
|
172
|
+
getTypeOfAccessor(accessor) {
|
|
173
|
+
const accessors = getAllAccessorDeclarations(accessor);
|
|
174
|
+
const annotation = this.getAccessorAnnotation(accessor, accessors.firstAccessor, accessors.secondAccessor);
|
|
175
|
+
if (annotation !== undefined && annotation.kind !== 183 /* SyntaxKind.TypePredicate */)
|
|
176
|
+
return new DirectType(annotation);
|
|
177
|
+
const getter = accessors.getAccessor;
|
|
178
|
+
if (getter !== undefined) {
|
|
179
|
+
const result = this.createReturnFromSignature(getter);
|
|
180
|
+
if (result instanceof InferredType && result.errorNodes.length === 0) {
|
|
181
|
+
// The error is reported on the accessors.
|
|
182
|
+
const errorNodes = [getter];
|
|
183
|
+
if (accessors.setAccessor !== undefined)
|
|
184
|
+
errorNodes.push(accessors.setAccessor);
|
|
185
|
+
return new InferredType(result.expression, result.isSignatureReturn, errorNodes);
|
|
186
|
+
}
|
|
187
|
+
return result;
|
|
188
|
+
}
|
|
189
|
+
return new NoResultType(accessor);
|
|
190
|
+
}
|
|
191
|
+
getAccessorAnnotation(node, first, second) {
|
|
192
|
+
let annotation = accessorAnnotation(node);
|
|
193
|
+
if (annotation === undefined && node !== first)
|
|
194
|
+
annotation = accessorAnnotation(first);
|
|
195
|
+
if (annotation === undefined && second !== undefined && node !== second)
|
|
196
|
+
annotation = accessorAnnotation(second);
|
|
197
|
+
return annotation;
|
|
198
|
+
}
|
|
199
|
+
getTypeOfExpression(node) {
|
|
200
|
+
return this.typeFromExpression(node);
|
|
201
|
+
}
|
|
202
|
+
getTypeOfDeclaration(node) {
|
|
203
|
+
switch (node.kind) {
|
|
204
|
+
case 170 /* SyntaxKind.Parameter */:
|
|
205
|
+
if (node instanceof ParameterDeclaration) {
|
|
206
|
+
const narrowed = node;
|
|
207
|
+
return this.typeFromParameter(narrowed);
|
|
208
|
+
}
|
|
209
|
+
break;
|
|
210
|
+
case 261 /* SyntaxKind.VariableDeclaration */:
|
|
211
|
+
if (node instanceof VariableDeclaration) {
|
|
212
|
+
const narrowed = node;
|
|
213
|
+
return this.typeFromVariable(narrowed);
|
|
214
|
+
}
|
|
215
|
+
break;
|
|
216
|
+
case 172 /* SyntaxKind.PropertySignature */:
|
|
217
|
+
case 173 /* SyntaxKind.PropertyDeclaration */:
|
|
218
|
+
case 340 /* SyntaxKind.JSDocPropertyTag */:
|
|
219
|
+
return this.typeFromProperty(node);
|
|
220
|
+
case 278 /* SyntaxKind.ExportAssignment */:
|
|
221
|
+
return this.typeFromExpression(getExpression(node));
|
|
222
|
+
case 212 /* SyntaxKind.PropertyAccessExpression */:
|
|
223
|
+
case 213 /* SyntaxKind.ElementAccessExpression */:
|
|
224
|
+
case 227 /* SyntaxKind.BinaryExpression */: {
|
|
225
|
+
const type = getType(node);
|
|
226
|
+
return type !== undefined ? new DirectType(type) : new NoResultType(node);
|
|
227
|
+
}
|
|
228
|
+
case 303 /* SyntaxKind.PropertyAssignment */:
|
|
229
|
+
case 304 /* SyntaxKind.ShorthandPropertyAssignment */:
|
|
230
|
+
return this.typeFromPropertyAssignment(node);
|
|
231
|
+
}
|
|
232
|
+
return new NoResultType(node);
|
|
233
|
+
}
|
|
234
|
+
typeFromPropertyAssignment(node) {
|
|
235
|
+
const annotation = getType(node);
|
|
236
|
+
if (annotation !== undefined)
|
|
237
|
+
return new DirectType(annotation);
|
|
238
|
+
if (node instanceof PropertyAssignment) {
|
|
239
|
+
const result = this.typeFromExpression(node.initializer);
|
|
240
|
+
if (!isBareInferred(result))
|
|
241
|
+
return result;
|
|
242
|
+
}
|
|
243
|
+
return new NoResultType(node);
|
|
244
|
+
}
|
|
245
|
+
typeFromProperty(node) {
|
|
246
|
+
const annotation = getType(node);
|
|
247
|
+
if (annotation !== undefined)
|
|
248
|
+
return new DirectType(annotation);
|
|
249
|
+
// A property declared more than once has the type of its first declaration; only the checker
|
|
250
|
+
// knows which, so the type is still written from this one but counted as uncertain.
|
|
251
|
+
const symbol = getSymbol(node);
|
|
252
|
+
if (symbol !== undefined && symbol.declarations.length > 1)
|
|
253
|
+
this.uncertain++;
|
|
254
|
+
if (node instanceof PropertyDeclaration) {
|
|
255
|
+
const initializer = node.initializer;
|
|
256
|
+
if (initializer !== undefined && !isContextuallyTyped(node)) {
|
|
257
|
+
// Readonly template literals may become literal types, so they aren't inferred.
|
|
258
|
+
if (hasSyntacticModifier(node, 8 /* ModifierFlags.Readonly */) && initializer.kind === 229 /* SyntaxKind.TemplateExpression */)
|
|
259
|
+
return new NoResultType(node);
|
|
260
|
+
const result = this.typeFromExpression(initializer);
|
|
261
|
+
if (!isBareInferred(result)) {
|
|
262
|
+
const postfix = node.postfixToken;
|
|
263
|
+
// `x? = value` has `| undefined` in its type.
|
|
264
|
+
if (result.kind !== 0 /* PseudoTypeKind.Direct */ &&
|
|
265
|
+
postfix !== undefined &&
|
|
266
|
+
postfix.kind === 57 /* SyntaxKind.QuestionToken */)
|
|
267
|
+
return this.addUndefined(result);
|
|
268
|
+
return result;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
return new NoResultType(node);
|
|
273
|
+
}
|
|
274
|
+
typeFromVariable(declaration) {
|
|
275
|
+
if (declaration.type !== undefined)
|
|
276
|
+
return new DirectType(declaration.type);
|
|
277
|
+
const initializer = declaration.initializer;
|
|
278
|
+
// As tsgo, the file's own declarations; merged ones are left to the checker's type comparison.
|
|
279
|
+
const symbol = declaration.symbol;
|
|
280
|
+
if (initializer !== undefined && (symbol === undefined || countVariableDeclarations(symbol.declarations) === 1)) {
|
|
281
|
+
if (!isContextuallyTyped(declaration)) {
|
|
282
|
+
// Const template literals may become literal types, so they aren't inferred.
|
|
283
|
+
if ((getCombinedNodeFlags(declaration) & 2 /* NodeFlags.Const */) !== 0 &&
|
|
284
|
+
initializer.kind === 229 /* SyntaxKind.TemplateExpression */)
|
|
285
|
+
return new NoResultType(declaration);
|
|
286
|
+
const result = this.typeFromExpression(initializer);
|
|
287
|
+
if (!isBareInferred(result))
|
|
288
|
+
return result;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
return new NoResultType(declaration);
|
|
292
|
+
}
|
|
293
|
+
/** The return type of a signature; `NoResult` or `Inferred` when unknown. */
|
|
294
|
+
createReturnFromSignature(fn) {
|
|
295
|
+
if (isFunctionLike(fn)) {
|
|
296
|
+
const type = getType(fn);
|
|
297
|
+
if (type !== undefined)
|
|
298
|
+
return new DirectType(type);
|
|
299
|
+
}
|
|
300
|
+
if (isValueSignatureDeclaration(fn))
|
|
301
|
+
return this.typeFromSingleReturnExpression(fn);
|
|
302
|
+
return new NoResultType(fn);
|
|
303
|
+
}
|
|
304
|
+
typeFromSingleReturnExpression(fn) {
|
|
305
|
+
let candidate = undefined;
|
|
306
|
+
const body = getBody(fn);
|
|
307
|
+
if (body !== undefined && !nodeIsMissing(body)) {
|
|
308
|
+
// An async function or generator returns a promise or generator of its returned values.
|
|
309
|
+
if (hasSyntacticModifier(fn, 1024 /* ModifierFlags.Async */) || getAsteriskToken(fn) !== undefined)
|
|
310
|
+
return inferred(fn, true);
|
|
311
|
+
if (body.kind === 242 /* SyntaxKind.Block */) {
|
|
312
|
+
const returns = collectReturnStatements(body);
|
|
313
|
+
// Only a single return directly in the body.
|
|
314
|
+
if (returns.length === 1 && returns[0].parent === body)
|
|
315
|
+
candidate = returns[0].expression;
|
|
316
|
+
}
|
|
317
|
+
else
|
|
318
|
+
candidate = body;
|
|
319
|
+
}
|
|
320
|
+
if (candidate !== undefined) {
|
|
321
|
+
if (!isContextuallyTyped(candidate))
|
|
322
|
+
return this.typeFromExpression(candidate);
|
|
323
|
+
let type = undefined;
|
|
324
|
+
if (candidate.kind === 217 /* SyntaxKind.TypeAssertionExpression */ || candidate.kind === 235 /* SyntaxKind.AsExpression */)
|
|
325
|
+
type = getType(candidate);
|
|
326
|
+
if (type !== undefined && !isConstTypeReference(type))
|
|
327
|
+
return new DirectType(type);
|
|
328
|
+
}
|
|
329
|
+
return inferred(fn, true);
|
|
330
|
+
}
|
|
331
|
+
/** `checkExpression` for pseudo-types. */
|
|
332
|
+
typeFromExpression(node) {
|
|
333
|
+
switch (node.kind) {
|
|
334
|
+
case 233 /* SyntaxKind.OmittedExpression */:
|
|
335
|
+
return undefinedType;
|
|
336
|
+
case 218 /* SyntaxKind.ParenthesizedExpression */:
|
|
337
|
+
return this.typeFromExpression(getExpression(node));
|
|
338
|
+
case 79 /* SyntaxKind.Identifier */:
|
|
339
|
+
// A declaration named `undefined` shadows it.
|
|
340
|
+
if (isIdentifierNamed(node, 'undefined'))
|
|
341
|
+
return this.names.resolve(node, 'undefined', 111551 /* SymbolFlags.Value */, undefined, false, false) === undefined
|
|
342
|
+
? undefinedType
|
|
343
|
+
: inferred(node, false);
|
|
344
|
+
break;
|
|
345
|
+
case 105 /* SyntaxKind.NullKeyword */:
|
|
346
|
+
return nullType;
|
|
347
|
+
case 220 /* SyntaxKind.ArrowFunction */:
|
|
348
|
+
case 219 /* SyntaxKind.FunctionExpression */:
|
|
349
|
+
return this.typeFromFunctionLikeExpression(node);
|
|
350
|
+
case 217 /* SyntaxKind.TypeAssertionExpression */:
|
|
351
|
+
case 235 /* SyntaxKind.AsExpression */: {
|
|
352
|
+
const type = getType(node);
|
|
353
|
+
if (isConstTypeReference(type))
|
|
354
|
+
return this.typeFromExpression(getExpression(node));
|
|
355
|
+
return new DirectType(type);
|
|
356
|
+
}
|
|
357
|
+
case 225 /* SyntaxKind.PrefixUnaryExpression */:
|
|
358
|
+
if (node instanceof PrefixUnaryExpression) {
|
|
359
|
+
const unary = node;
|
|
360
|
+
if (isSignedNumericLiteral(unary))
|
|
361
|
+
return typeFromSignedLiteral(unary);
|
|
362
|
+
}
|
|
363
|
+
break;
|
|
364
|
+
case 210 /* SyntaxKind.ArrayLiteralExpression */:
|
|
365
|
+
if (node instanceof ArrayLiteralExpression) {
|
|
366
|
+
const narrowed = node;
|
|
367
|
+
return this.typeFromArrayLiteral(narrowed);
|
|
368
|
+
}
|
|
369
|
+
break;
|
|
370
|
+
case 211 /* SyntaxKind.ObjectLiteralExpression */:
|
|
371
|
+
if (node instanceof ObjectLiteralExpression) {
|
|
372
|
+
const narrowed = node;
|
|
373
|
+
return this.typeFromObjectLiteral(narrowed);
|
|
374
|
+
}
|
|
375
|
+
break;
|
|
376
|
+
case 232 /* SyntaxKind.ClassExpression */:
|
|
377
|
+
return new InferredType(node, false, [node]);
|
|
378
|
+
case 229 /* SyntaxKind.TemplateExpression */:
|
|
379
|
+
// Templates with substitutions aren't literal types, but `as const` would make them one.
|
|
380
|
+
if (isInConstContext(node))
|
|
381
|
+
return inferred(node, false);
|
|
382
|
+
return new MaybeConstType(node, inferred(node, false), stringType);
|
|
383
|
+
case 8 /* SyntaxKind.NumericLiteral */:
|
|
384
|
+
return new MaybeConstType(node, new LiteralType(18 /* PseudoTypeKind.NumericLiteral */, node), numberType);
|
|
385
|
+
case 14 /* SyntaxKind.NoSubstitutionTemplateLiteral */:
|
|
386
|
+
case 10 /* SyntaxKind.StringLiteral */:
|
|
387
|
+
return new MaybeConstType(node, new LiteralType(17 /* PseudoTypeKind.StringLiteral */, node), stringType);
|
|
388
|
+
case 9 /* SyntaxKind.BigIntLiteral */:
|
|
389
|
+
return new MaybeConstType(node, new LiteralType(19 /* PseudoTypeKind.BigIntLiteral */, node), bigintType);
|
|
390
|
+
case 111 /* SyntaxKind.TrueKeyword */:
|
|
391
|
+
return new MaybeConstType(node, trueType, booleanType);
|
|
392
|
+
case 96 /* SyntaxKind.FalseKeyword */:
|
|
393
|
+
return new MaybeConstType(node, falseType, booleanType);
|
|
394
|
+
}
|
|
395
|
+
return inferred(node, false);
|
|
396
|
+
}
|
|
397
|
+
typeFromObjectLiteral(node) {
|
|
398
|
+
const errorNodes = objectLiteralErrorNodes(node);
|
|
399
|
+
if (errorNodes.length > 0)
|
|
400
|
+
return new InferredType(node, false, errorNodes);
|
|
401
|
+
const members = [];
|
|
402
|
+
for (const property of node.properties.nodes) {
|
|
403
|
+
switch (property.kind) {
|
|
404
|
+
case 175 /* SyntaxKind.MethodDeclaration */: {
|
|
405
|
+
const postfix = getPostfixToken(property);
|
|
406
|
+
const optional = postfix !== undefined && postfix.kind === 57 /* SyntaxKind.QuestionToken */;
|
|
407
|
+
const fullSignature = getFullSignature(property);
|
|
408
|
+
if (fullSignature !== undefined) {
|
|
409
|
+
members.push(new PseudoMember(1 /* PseudoMemberKind.Property */, getName(property), optional, false, undefined, [], [], new DirectType(fullSignature)));
|
|
410
|
+
break;
|
|
411
|
+
}
|
|
412
|
+
members.push(new PseudoMember(0 /* PseudoMemberKind.Method */, getName(property), optional, false, property, nodesOf(getTypeParameters(property)), this.cloneParameters(getParameters(property).nodes), this.createReturnFromSignature(property)));
|
|
413
|
+
break;
|
|
414
|
+
}
|
|
415
|
+
case 303 /* SyntaxKind.PropertyAssignment */: {
|
|
416
|
+
const assignment = property;
|
|
417
|
+
const postfix = assignment.postfixToken;
|
|
418
|
+
members.push(new PseudoMember(1 /* PseudoMemberKind.Property */, assignment.name, postfix !== undefined && postfix.kind === 57 /* SyntaxKind.QuestionToken */, false, undefined, [], [], this.typeFromExpression(assignment.initializer)));
|
|
419
|
+
break;
|
|
420
|
+
}
|
|
421
|
+
case 179 /* SyntaxKind.SetAccessor */:
|
|
422
|
+
case 178 /* SyntaxKind.GetAccessor */: {
|
|
423
|
+
const member = this.getAccessorMember(property);
|
|
424
|
+
if (member !== undefined)
|
|
425
|
+
members.push(member);
|
|
426
|
+
break;
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
return new ObjectLiteralType(members);
|
|
431
|
+
}
|
|
432
|
+
getAccessorMember(accessor) {
|
|
433
|
+
const accessors = getAllAccessorDeclarations(accessor);
|
|
434
|
+
const name = getName(accessor);
|
|
435
|
+
const getter = accessors.getAccessor;
|
|
436
|
+
const setter = accessors.setAccessor;
|
|
437
|
+
// With both accessors annotated, their types may differ, so both are kept.
|
|
438
|
+
if (getter instanceof GetAccessorDeclaration &&
|
|
439
|
+
getter.type !== undefined &&
|
|
440
|
+
setter instanceof SetAccessorDeclaration &&
|
|
441
|
+
setter.parameters.nodes.length > 0 &&
|
|
442
|
+
getType(setter.parameters.nodes[0]) !== undefined) {
|
|
443
|
+
if (accessor.kind === 178 /* SyntaxKind.GetAccessor */)
|
|
444
|
+
return new PseudoMember(3 /* PseudoMemberKind.GetAccessor */, name, false, false, accessor, [], [], this.getTypeOfAccessor(accessor));
|
|
445
|
+
const parameters = this.cloneParameters(accessor.parameters.nodes);
|
|
446
|
+
return new PseudoMember(2 /* PseudoMemberKind.SetAccessor */, name, false, false, accessor, [], parameters, anyType);
|
|
447
|
+
}
|
|
448
|
+
// Otherwise the first accessor is a property, `readonly` for a lone getter.
|
|
449
|
+
if (accessor === accessors.firstAccessor)
|
|
450
|
+
return new PseudoMember(1 /* PseudoMemberKind.Property */, name, false, accessor.kind === 178 /* SyntaxKind.GetAccessor */ && accessors.secondAccessor === undefined, undefined, [], [], this.getTypeOfAccessor(accessor));
|
|
451
|
+
return undefined;
|
|
452
|
+
}
|
|
453
|
+
typeFromArrayLiteral(node) {
|
|
454
|
+
if (!isInConstContext(node))
|
|
455
|
+
return new InferredType(node, false, [node]);
|
|
456
|
+
for (const element of node.elements.nodes)
|
|
457
|
+
if (element.kind === 231 /* SyntaxKind.SpreadElement */)
|
|
458
|
+
return new InferredType(node, false, [element]);
|
|
459
|
+
// An `as const` array with a contextual type may or may not be readonly.
|
|
460
|
+
if (isContextuallyTyped(node))
|
|
461
|
+
return inferred(node, false);
|
|
462
|
+
const elements = [];
|
|
463
|
+
for (const element of node.elements.nodes)
|
|
464
|
+
elements.push(this.typeFromExpression(element));
|
|
465
|
+
return new TupleType(elements);
|
|
466
|
+
}
|
|
467
|
+
typeFromFunctionLikeExpression(node) {
|
|
468
|
+
const fullSignature = getFullSignature(node);
|
|
469
|
+
if (fullSignature !== undefined)
|
|
470
|
+
return new DirectType(fullSignature);
|
|
471
|
+
return new SignatureType(node, this.cloneParameters(getParameters(node).nodes), nodesOf(getTypeParameters(node)), this.createReturnFromSignature(node));
|
|
472
|
+
}
|
|
473
|
+
typeFromParameter(node) {
|
|
474
|
+
const parent = node.parent;
|
|
475
|
+
if (parent.kind === 179 /* SyntaxKind.SetAccessor */)
|
|
476
|
+
return this.getTypeOfAccessor(parent);
|
|
477
|
+
if (node.initializer === undefined)
|
|
478
|
+
return node.type !== undefined ? new DirectType(node.type) : new NoResultType(node);
|
|
479
|
+
const parameters = getParameters(parent).nodes;
|
|
480
|
+
return this.typeFromParameterAt(node, parameters.indexOf(node), lastRequiredParameterIndex(parameters));
|
|
481
|
+
}
|
|
482
|
+
typeFromParameterAt(node, index, lastRequired) {
|
|
483
|
+
const parent = node.parent;
|
|
484
|
+
if (parent.kind === 179 /* SyntaxKind.SetAccessor */)
|
|
485
|
+
return this.getTypeOfAccessor(parent);
|
|
486
|
+
const hasRequiredAfter = index < lastRequired - 1;
|
|
487
|
+
if (node.type !== undefined) {
|
|
488
|
+
const result = new DirectType(node.type);
|
|
489
|
+
// An initialized parameter before a required one has `| undefined` in its type.
|
|
490
|
+
if (this.strictNullChecks && node.initializer !== undefined && hasRequiredAfter)
|
|
491
|
+
return this.addUndefined(result);
|
|
492
|
+
return result;
|
|
493
|
+
}
|
|
494
|
+
if (node.initializer !== undefined && node.name.kind === 79 /* SyntaxKind.Identifier */ && !isContextuallyTyped(node)) {
|
|
495
|
+
let result = this.typeFromExpression(node.initializer);
|
|
496
|
+
// The error is reported on the parameter.
|
|
497
|
+
if (isBareInferred(result))
|
|
498
|
+
result = new InferredType(result.expression, false, [node]);
|
|
499
|
+
if (!this.strictNullChecks || !hasRequiredAfter)
|
|
500
|
+
return result;
|
|
501
|
+
return this.addUndefined(result);
|
|
502
|
+
}
|
|
503
|
+
// Types aren't inferred from binding patterns.
|
|
504
|
+
return new NoResultType(node);
|
|
505
|
+
}
|
|
506
|
+
cloneParameters(nodes) {
|
|
507
|
+
const result = [];
|
|
508
|
+
const lastRequired = lastRequiredParameterIndex(nodes);
|
|
509
|
+
for (let i = 0; i < nodes.length; i++) {
|
|
510
|
+
const parameter = nodes[i];
|
|
511
|
+
let optional = parameter.questionToken !== undefined;
|
|
512
|
+
// An initialized parameter is optional when no required one follows.
|
|
513
|
+
if (!optional && parameter.initializer !== undefined)
|
|
514
|
+
optional = i >= lastRequired - 1;
|
|
515
|
+
result.push(new PseudoParameter(parameter.dotDotDotToken !== undefined, parameter.name, optional, this.typeFromParameterAt(parameter, i, lastRequired)));
|
|
516
|
+
}
|
|
517
|
+
return result;
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
function nodesOf(list) {
|
|
521
|
+
return list === undefined ? [] : list.nodes;
|
|
522
|
+
}
|
|
523
|
+
function accessorAnnotation(node) {
|
|
524
|
+
if (node instanceof GetAccessorDeclaration)
|
|
525
|
+
return node.type;
|
|
526
|
+
if (node instanceof SetAccessorDeclaration) {
|
|
527
|
+
const parameters = node.parameters.nodes;
|
|
528
|
+
return parameters.length > 0 ? getType(parameters[0]) : undefined;
|
|
529
|
+
}
|
|
530
|
+
return undefined;
|
|
531
|
+
}
|
|
532
|
+
function countVariableDeclarations(declarations) {
|
|
533
|
+
if (declarations.length === 1)
|
|
534
|
+
return 1;
|
|
535
|
+
let count = 0;
|
|
536
|
+
for (const declaration of declarations)
|
|
537
|
+
if (declaration.kind === 261 /* SyntaxKind.VariableDeclaration */)
|
|
538
|
+
count++;
|
|
539
|
+
return count;
|
|
540
|
+
}
|
|
541
|
+
function isValueSignatureDeclaration(node) {
|
|
542
|
+
switch (node.kind) {
|
|
543
|
+
case 219 /* SyntaxKind.FunctionExpression */:
|
|
544
|
+
case 220 /* SyntaxKind.ArrowFunction */:
|
|
545
|
+
case 175 /* SyntaxKind.MethodDeclaration */:
|
|
546
|
+
case 178 /* SyntaxKind.GetAccessor */:
|
|
547
|
+
case 179 /* SyntaxKind.SetAccessor */:
|
|
548
|
+
case 263 /* SyntaxKind.FunctionDeclaration */:
|
|
549
|
+
case 177 /* SyntaxKind.Constructor */:
|
|
550
|
+
return true;
|
|
551
|
+
}
|
|
552
|
+
return false;
|
|
553
|
+
}
|
|
554
|
+
/** The return statements of a function body, outside nested functions. */
|
|
555
|
+
export function collectReturnStatements(body) {
|
|
556
|
+
const collector = new ReturnCollector();
|
|
557
|
+
collector.visitNode(body);
|
|
558
|
+
return collector.statements;
|
|
559
|
+
}
|
|
560
|
+
class ReturnCollector extends NodeVisitor {
|
|
561
|
+
statements = [];
|
|
562
|
+
visitNode(node) {
|
|
563
|
+
switch (node.kind) {
|
|
564
|
+
case 254 /* SyntaxKind.ReturnStatement */:
|
|
565
|
+
if (node instanceof ReturnStatement)
|
|
566
|
+
this.statements.push(node);
|
|
567
|
+
return false;
|
|
568
|
+
case 270 /* SyntaxKind.CaseBlock */:
|
|
569
|
+
case 242 /* SyntaxKind.Block */:
|
|
570
|
+
case 246 /* SyntaxKind.IfStatement */:
|
|
571
|
+
case 247 /* SyntaxKind.DoStatement */:
|
|
572
|
+
case 248 /* SyntaxKind.WhileStatement */:
|
|
573
|
+
case 249 /* SyntaxKind.ForStatement */:
|
|
574
|
+
case 250 /* SyntaxKind.ForInStatement */:
|
|
575
|
+
case 251 /* SyntaxKind.ForOfStatement */:
|
|
576
|
+
case 255 /* SyntaxKind.WithStatement */:
|
|
577
|
+
case 256 /* SyntaxKind.SwitchStatement */:
|
|
578
|
+
case 297 /* SyntaxKind.CaseClause */:
|
|
579
|
+
case 298 /* SyntaxKind.DefaultClause */:
|
|
580
|
+
case 257 /* SyntaxKind.LabeledStatement */:
|
|
581
|
+
case 259 /* SyntaxKind.TryStatement */:
|
|
582
|
+
case 300 /* SyntaxKind.CatchClause */:
|
|
583
|
+
return node.forEachChild(this);
|
|
584
|
+
}
|
|
585
|
+
return false;
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
function isSignedNumericLiteral(node) {
|
|
589
|
+
const operand = node.operand.kind;
|
|
590
|
+
if (node.operator === 40 /* SyntaxKind.MinusToken */)
|
|
591
|
+
return operand === 8 /* SyntaxKind.NumericLiteral */ || operand === 9 /* SyntaxKind.BigIntLiteral */;
|
|
592
|
+
return node.operator === 39 /* SyntaxKind.PlusToken */ && operand === 8 /* SyntaxKind.NumericLiteral */;
|
|
593
|
+
}
|
|
594
|
+
function typeFromSignedLiteral(node) {
|
|
595
|
+
const literal = node.operator === 39 /* SyntaxKind.PlusToken */ ? node.operand : node;
|
|
596
|
+
if (node.operand.kind === 9 /* SyntaxKind.BigIntLiteral */)
|
|
597
|
+
return new MaybeConstType(node, new LiteralType(19 /* PseudoTypeKind.BigIntLiteral */, literal), bigintType);
|
|
598
|
+
return new MaybeConstType(node, new LiteralType(18 /* PseudoTypeKind.NumericLiteral */, literal), numberType);
|
|
599
|
+
}
|
|
600
|
+
export function isConstTypeReference(node) {
|
|
601
|
+
return (node instanceof TypeReferenceNode &&
|
|
602
|
+
(node.typeArguments === undefined || node.typeArguments.nodes.length === 0) &&
|
|
603
|
+
isIdentifierNamed(node.typeName, 'const'));
|
|
604
|
+
}
|
|
605
|
+
function isConstAssertionNode(node) {
|
|
606
|
+
return ((node.kind === 235 /* SyntaxKind.AsExpression */ || node.kind === 217 /* SyntaxKind.TypeAssertionExpression */) &&
|
|
607
|
+
isConstTypeReference(getType(node)));
|
|
608
|
+
}
|
|
609
|
+
/** Whether a nested expression is inside an `as const`, as far as syntax decides. */
|
|
610
|
+
export function isInConstContext(node) {
|
|
611
|
+
let current = node.parent;
|
|
612
|
+
while (current !== undefined) {
|
|
613
|
+
switch (current.kind) {
|
|
614
|
+
case 235 /* SyntaxKind.AsExpression */:
|
|
615
|
+
case 217 /* SyntaxKind.TypeAssertionExpression */:
|
|
616
|
+
return isConstAssertionNode(current);
|
|
617
|
+
case 210 /* SyntaxKind.ArrayLiteralExpression */:
|
|
618
|
+
case 211 /* SyntaxKind.ObjectLiteralExpression */:
|
|
619
|
+
case 218 /* SyntaxKind.ParenthesizedExpression */:
|
|
620
|
+
case 231 /* SyntaxKind.SpreadElement */:
|
|
621
|
+
case 303 /* SyntaxKind.PropertyAssignment */:
|
|
622
|
+
case 304 /* SyntaxKind.ShorthandPropertyAssignment */:
|
|
623
|
+
case 240 /* SyntaxKind.TemplateSpan */:
|
|
624
|
+
case 225 /* SyntaxKind.PrefixUnaryExpression */:
|
|
625
|
+
current = current.parent;
|
|
626
|
+
continue;
|
|
627
|
+
}
|
|
628
|
+
return false;
|
|
629
|
+
}
|
|
630
|
+
return false;
|
|
631
|
+
}
|
|
632
|
+
/** Whether calls, `satisfies` or annotations around a node can change its type. */
|
|
633
|
+
function isContextuallyTyped(node) {
|
|
634
|
+
for (let current = node.parent; current !== undefined; current = current.parent) {
|
|
635
|
+
switch (current.kind) {
|
|
636
|
+
case 214 /* SyntaxKind.CallExpression */:
|
|
637
|
+
case 239 /* SyntaxKind.SatisfiesExpression */:
|
|
638
|
+
case 285 /* SyntaxKind.JsxElement */:
|
|
639
|
+
case 295 /* SyntaxKind.JsxExpression */:
|
|
640
|
+
return true;
|
|
641
|
+
case 261 /* SyntaxKind.VariableDeclaration */:
|
|
642
|
+
case 170 /* SyntaxKind.Parameter */:
|
|
643
|
+
case 173 /* SyntaxKind.PropertyDeclaration */:
|
|
644
|
+
case 172 /* SyntaxKind.PropertySignature */:
|
|
645
|
+
case 235 /* SyntaxKind.AsExpression */:
|
|
646
|
+
case 217 /* SyntaxKind.TypeAssertionExpression */:
|
|
647
|
+
if (getType(current) !== undefined && !isConstAssertionNode(current))
|
|
648
|
+
return true;
|
|
649
|
+
break;
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
return false;
|
|
653
|
+
}
|
|
654
|
+
function objectLiteralErrorNodes(node) {
|
|
655
|
+
const errorNodes = [];
|
|
656
|
+
for (const property of node.properties.nodes) {
|
|
657
|
+
if ((property.flags & 32768 /* NodeFlags.ThisNodeHasError */) !== 0) {
|
|
658
|
+
errorNodes.push(property);
|
|
659
|
+
continue;
|
|
660
|
+
}
|
|
661
|
+
if (property.kind === 304 /* SyntaxKind.ShorthandPropertyAssignment */ || property.kind === 305 /* SyntaxKind.SpreadAssignment */) {
|
|
662
|
+
errorNodes.push(property);
|
|
663
|
+
continue;
|
|
664
|
+
}
|
|
665
|
+
const name = getName(property);
|
|
666
|
+
if ((name.flags & 32768 /* NodeFlags.ThisNodeHasError */) !== 0)
|
|
667
|
+
errorNodes.push(name);
|
|
668
|
+
else if (name.kind === 80 /* SyntaxKind.PrivateIdentifier */)
|
|
669
|
+
errorNodes.push(property);
|
|
670
|
+
else if (name.kind === 168 /* SyntaxKind.ComputedPropertyName */ && !isPrimitiveLiteral(getExpression(name)))
|
|
671
|
+
errorNodes.push(name);
|
|
672
|
+
}
|
|
673
|
+
return errorNodes;
|
|
674
|
+
}
|
|
675
|
+
function isPrimitiveLiteral(node) {
|
|
676
|
+
switch (node.kind) {
|
|
677
|
+
case 111 /* SyntaxKind.TrueKeyword */:
|
|
678
|
+
case 96 /* SyntaxKind.FalseKeyword */:
|
|
679
|
+
case 8 /* SyntaxKind.NumericLiteral */:
|
|
680
|
+
case 10 /* SyntaxKind.StringLiteral */:
|
|
681
|
+
case 14 /* SyntaxKind.NoSubstitutionTemplateLiteral */:
|
|
682
|
+
return true;
|
|
683
|
+
case 225 /* SyntaxKind.PrefixUnaryExpression */: {
|
|
684
|
+
const unary = node;
|
|
685
|
+
return ((unary.operator === 40 /* SyntaxKind.MinusToken */ || unary.operator === 39 /* SyntaxKind.PlusToken */) &&
|
|
686
|
+
unary.operand.kind === 8 /* SyntaxKind.NumericLiteral */);
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
return false;
|
|
690
|
+
}
|
|
691
|
+
/** The index just past the last parameter without `?`, initializer or `...`. */
|
|
692
|
+
export function lastRequiredParameterIndex(parameters) {
|
|
693
|
+
for (let i = parameters.length - 1; i >= 0; i--) {
|
|
694
|
+
const parameter = parameters[i];
|
|
695
|
+
if (parameter.dotDotDotToken === undefined &&
|
|
696
|
+
parameter.initializer === undefined &&
|
|
697
|
+
parameter.questionToken === undefined)
|
|
698
|
+
return i + 1;
|
|
699
|
+
}
|
|
700
|
+
return 0;
|
|
701
|
+
}
|
|
702
|
+
function typeNodeCouldReferToUndefined(node) {
|
|
703
|
+
let current = node;
|
|
704
|
+
while (current.kind === 197 /* SyntaxKind.ParenthesizedType */)
|
|
705
|
+
current = getType(current);
|
|
706
|
+
switch (current.kind) {
|
|
707
|
+
// These need symbols or types to know.
|
|
708
|
+
case 184 /* SyntaxKind.TypeReference */:
|
|
709
|
+
case 200 /* SyntaxKind.IndexedAccessType */:
|
|
710
|
+
case 187 /* SyntaxKind.TypeQuery */:
|
|
711
|
+
case 191 /* SyntaxKind.OptionalType */:
|
|
712
|
+
case 192 /* SyntaxKind.RestType */:
|
|
713
|
+
case 206 /* SyntaxKind.ImportType */:
|
|
714
|
+
case 195 /* SyntaxKind.ConditionalType */:
|
|
715
|
+
case 199 /* SyntaxKind.TypeOperator */:
|
|
716
|
+
case 183 /* SyntaxKind.TypePredicate */:
|
|
717
|
+
case 157 /* SyntaxKind.UndefinedKeyword */:
|
|
718
|
+
return true;
|
|
719
|
+
case 193 /* SyntaxKind.UnionType */:
|
|
720
|
+
case 194 /* SyntaxKind.IntersectionType */:
|
|
721
|
+
// Intersections are treated like unions, as tsgo does.
|
|
722
|
+
for (const type of typesOf(current))
|
|
723
|
+
if (typeNodeCouldReferToUndefined(type))
|
|
724
|
+
return true;
|
|
725
|
+
return false;
|
|
726
|
+
}
|
|
727
|
+
return false;
|
|
728
|
+
}
|
|
729
|
+
/** Whether a pseudo-type may already include `undefined`. */
|
|
730
|
+
export function couldAlreadyReferToUndefined(type) {
|
|
731
|
+
if (type instanceof NoResultType || type instanceof InferredType || isUndefinedType(type))
|
|
732
|
+
return true;
|
|
733
|
+
if (type instanceof MaybeConstType)
|
|
734
|
+
return couldAlreadyReferToUndefined(type.regularType);
|
|
735
|
+
if (type instanceof DirectType)
|
|
736
|
+
return typeNodeCouldReferToUndefined(type.typeNode);
|
|
737
|
+
if (type instanceof UnionType) {
|
|
738
|
+
for (const member of type.types)
|
|
739
|
+
if (couldAlreadyReferToUndefined(member))
|
|
740
|
+
return true;
|
|
741
|
+
return false;
|
|
742
|
+
}
|
|
743
|
+
return false;
|
|
744
|
+
}
|
|
745
|
+
function isUndefinedType(type) {
|
|
746
|
+
return type.kind === 5 /* PseudoTypeKind.Undefined */ || (type instanceof MaybeConstType && isUndefinedType(type.constType));
|
|
747
|
+
}
|
|
748
|
+
function definitelyHasUndefined(type) {
|
|
749
|
+
if (isUndefinedType(type))
|
|
750
|
+
return true;
|
|
751
|
+
if (type instanceof UnionType) {
|
|
752
|
+
for (const member of type.types)
|
|
753
|
+
if (definitelyHasUndefined(member))
|
|
754
|
+
return true;
|
|
755
|
+
return false;
|
|
756
|
+
}
|
|
757
|
+
if (type instanceof DirectType)
|
|
758
|
+
return typeNodeHasUndefined(type.typeNode);
|
|
759
|
+
return false;
|
|
760
|
+
}
|
|
761
|
+
function typeNodeHasUndefined(node) {
|
|
762
|
+
if (node.kind === 157 /* SyntaxKind.UndefinedKeyword */ ||
|
|
763
|
+
node.kind === 132 /* SyntaxKind.AnyKeyword */ ||
|
|
764
|
+
node.kind === 159 /* SyntaxKind.UnknownKeyword */)
|
|
765
|
+
return true;
|
|
766
|
+
if (node.kind === 197 /* SyntaxKind.ParenthesizedType */)
|
|
767
|
+
return typeNodeHasUndefined(getType(node));
|
|
768
|
+
if (node instanceof UnionTypeNode) {
|
|
769
|
+
for (const member of node.types.nodes)
|
|
770
|
+
if (typeNodeHasUndefined(member))
|
|
771
|
+
return true;
|
|
772
|
+
}
|
|
773
|
+
return false;
|
|
774
|
+
}
|
|
775
|
+
function addUndefinedIfDefinitelyRequired(type) {
|
|
776
|
+
if (couldAlreadyReferToUndefined(type))
|
|
777
|
+
return type;
|
|
778
|
+
return new UnionType([type, undefinedType]);
|
|
779
|
+
}
|
|
780
|
+
/** The members of a union or intersection type node. */
|
|
781
|
+
export function typesOf(node) {
|
|
782
|
+
if (node instanceof UnionTypeNode)
|
|
783
|
+
return node.types.nodes;
|
|
784
|
+
if (node instanceof IntersectionTypeNode)
|
|
785
|
+
return node.types.nodes;
|
|
786
|
+
return [];
|
|
787
|
+
}
|
|
788
|
+
/** The JSDoc `@type` signature of a function expression, arrow function or method. */
|
|
789
|
+
function getFullSignature(node) {
|
|
790
|
+
if (node instanceof ArrowFunction)
|
|
791
|
+
return node.fullSignature;
|
|
792
|
+
if (node instanceof FunctionExpression)
|
|
793
|
+
return node.fullSignature;
|
|
794
|
+
if (node instanceof MethodDeclaration)
|
|
795
|
+
return node.fullSignature;
|
|
796
|
+
return undefined;
|
|
797
|
+
}
|