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,1582 @@
|
|
|
1
|
+
// Answers declaration emit's queries from syntax and the binder: visibility, aliases to keep,
|
|
2
|
+
// overloads and enum values exactly; types from annotations and the isolatedDeclarations
|
|
3
|
+
// rules (literals, `as const`, annotated function expressions). Types that need inference
|
|
4
|
+
// are reported to the tracker and written as `any`.
|
|
5
|
+
import { AsExpression, BigIntLiteral, ObjectLiteralExpression, BindingElement, BindingPattern, ComputedPropertyName, ElementAccessExpression, ExportDeclaration, ExportSpecifier, ExternalModuleReference, FunctionTypeNode, Identifier, ImportAttribute, ImportAttributes, ImportEqualsDeclaration, KeywordTypeNode, LiteralTypeNode, MethodSignatureDeclaration, ModuleDeclaration, NodeVisitor, NumericLiteral, ParameterDeclaration, PrefixUnaryExpression, PrivateIdentifier, PropertyAccessExpression, PropertySignatureDeclaration, QualifiedName, SetAccessorDeclaration, GetAccessorDeclaration, HeritageClause, StringLiteral, NoSubstitutionTemplateLiteral, TemplateMiddle, TemplateTail, TypePredicateNode, TupleTypeNode, TypeLiteralNode, TypeOperatorNode, TypeQueryNode, TypeReferenceNode, UnionTypeNode, VariableDeclaration, getAsteriskToken, getBody, getExpression, getInitializer, getMembers, getName, getText, getParameters, getSymbol, getType, } from '../ast.js';
|
|
6
|
+
import { isAmbientModule, isFunctionLike, nodeIsPresent } from '../ast-utilities.js';
|
|
7
|
+
import { getContainerFlags } from '../binder.js';
|
|
8
|
+
import { getCombinedModifierFlags, getCombinedNodeFlags, getRootDeclaration, getSourceFileOfNode, hasSyntacticModifier, isEntityNameExpression, isExternalOrCommonJSModule, isGlobalSourceFile, isIdentifierNamed, isModuleAugmentationExternal, isParameterPropertyDeclaration, isStringOrNumericLiteralLike, skipParentheses, } from '../binder-utilities.js';
|
|
9
|
+
import { NameResolver } from '../name-resolver.js';
|
|
10
|
+
import { ModuleKind as ModuleKinds } from '../options.js';
|
|
11
|
+
import { combinePaths, getDirectoryPath, getNormalizedAbsolutePath, normalizePath } from '../path.js';
|
|
12
|
+
import { isIdentifierText } from '../scanner.js';
|
|
13
|
+
import { Symbol, addDeclaration } from '../symbol.js';
|
|
14
|
+
import { DeclarationEmitResolver, SymbolAccessibilityResult, accessible, } from './declarations-resolver.js';
|
|
15
|
+
import { DirectType, InferredType, MaybeConstType, NoResultType, ObjectLiteralType, PseudoChecker, SignatureType, TupleType, UnionType, collectReturnStatements, couldAlreadyReferToUndefined, isConstTypeReference, isInConstContext, lastRequiredParameterIndex, typesOf, undefinedType, } from './declarations-pseudo.js';
|
|
16
|
+
const emptyTable = new Map();
|
|
17
|
+
/** Name resolution without module resolution: an import may name anything. */
|
|
18
|
+
class DeclarationNameResolver extends NameResolver {
|
|
19
|
+
/** Global symbols merged across files, by each file's symbol. */
|
|
20
|
+
mergedSymbols;
|
|
21
|
+
constructor(options, mergedSymbols) {
|
|
22
|
+
super(options);
|
|
23
|
+
this.mergedSymbols = mergedSymbols;
|
|
24
|
+
}
|
|
25
|
+
getSymbolOfDeclaration(node) {
|
|
26
|
+
const symbol = getSymbol(node);
|
|
27
|
+
return symbol === undefined ? undefined : (this.mergedSymbols.get(symbol) ?? symbol);
|
|
28
|
+
}
|
|
29
|
+
lookup(symbols, name, meaning) {
|
|
30
|
+
if ((meaning & 1073741823 /* SymbolFlags.All */) === 0)
|
|
31
|
+
return undefined;
|
|
32
|
+
const symbol = symbols.get(name);
|
|
33
|
+
if (symbol === undefined)
|
|
34
|
+
return undefined;
|
|
35
|
+
if ((symbol.flags & meaning) !== 0)
|
|
36
|
+
return symbol;
|
|
37
|
+
// The checker resolves the alias; an unresolvable one matches every meaning.
|
|
38
|
+
return (symbol.flags & 2097152 /* SymbolFlags.Alias */) !== 0 ? symbol : undefined;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/** How much of a file's declaration types needed inference. */
|
|
42
|
+
export class InferenceCounts {
|
|
43
|
+
/** Types without annotations or literal initializers. */
|
|
44
|
+
fallbacks;
|
|
45
|
+
/** Of those, the ones written as `any` because only the checker knows them. */
|
|
46
|
+
unresolved;
|
|
47
|
+
constructor() {
|
|
48
|
+
this.fallbacks = 0;
|
|
49
|
+
this.unresolved = 0;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* The files of a program by path and its globals merged across script files, as declaration emit
|
|
54
|
+
* without the checker resolves names. Read-only once built, so checker threads can share one.
|
|
55
|
+
*/
|
|
56
|
+
export class DeclarationGlobals {
|
|
57
|
+
filesByPath;
|
|
58
|
+
globals;
|
|
59
|
+
/** Global symbols merged across files, by each file's symbol. */
|
|
60
|
+
mergedSymbols;
|
|
61
|
+
constructor(files, currentDirectory) {
|
|
62
|
+
this.filesByPath = new Map();
|
|
63
|
+
this.globals = new Map();
|
|
64
|
+
this.mergedSymbols = new Map();
|
|
65
|
+
for (const file of files) {
|
|
66
|
+
this.filesByPath.set(getNormalizedAbsolutePath(file.fileName, currentDirectory), file);
|
|
67
|
+
if (!isExternalOrCommonJSModule(file) && file.locals !== undefined)
|
|
68
|
+
mergeInto(this.globals, file.locals, this.mergedSymbols);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
export class SyntacticDeclarationEmitResolver extends DeclarationEmitResolver {
|
|
73
|
+
options;
|
|
74
|
+
strictNullChecks;
|
|
75
|
+
emitResolver;
|
|
76
|
+
names;
|
|
77
|
+
pseudo;
|
|
78
|
+
filesByPath;
|
|
79
|
+
visibility;
|
|
80
|
+
aliasesMarked;
|
|
81
|
+
/** Inference counts by file. */
|
|
82
|
+
inference;
|
|
83
|
+
/**
|
|
84
|
+
* `emitResolver` answers the queries of JavaScript emit and enum values. `indexed` is the program's
|
|
85
|
+
* `DeclarationGlobals` if they were built before; otherwise they are built from `files`.
|
|
86
|
+
*/
|
|
87
|
+
constructor(options, files, currentDirectory, emitResolver, indexed = undefined) {
|
|
88
|
+
super();
|
|
89
|
+
this.options = options;
|
|
90
|
+
this.strictNullChecks =
|
|
91
|
+
options.strictNullChecks !== undefined ? options.strictNullChecks : options.strict !== false;
|
|
92
|
+
this.emitResolver = emitResolver;
|
|
93
|
+
const index = indexed !== undefined ? indexed : new DeclarationGlobals(files, currentDirectory);
|
|
94
|
+
this.names = new DeclarationNameResolver(options, index.mergedSymbols);
|
|
95
|
+
this.pseudo = new PseudoChecker(this.strictNullChecks, index.mergedSymbols, this.names);
|
|
96
|
+
this.filesByPath = index.filesByPath;
|
|
97
|
+
this.visibility = new Map();
|
|
98
|
+
this.aliasesMarked = new Set();
|
|
99
|
+
this.inference = new Map();
|
|
100
|
+
this.names.globals = index.globals;
|
|
101
|
+
}
|
|
102
|
+
// Emit queries
|
|
103
|
+
markLinkedReferences(file) {
|
|
104
|
+
return this.emitResolver.markLinkedReferences(file);
|
|
105
|
+
}
|
|
106
|
+
isReferencedAliasDeclaration(node) {
|
|
107
|
+
return this.emitResolver.isReferencedAliasDeclaration(node);
|
|
108
|
+
}
|
|
109
|
+
isValueAliasDeclaration(node) {
|
|
110
|
+
return this.emitResolver.isValueAliasDeclaration(node);
|
|
111
|
+
}
|
|
112
|
+
isTopLevelValueImportEqualsWithEntityName(node) {
|
|
113
|
+
return this.emitResolver.isTopLevelValueImportEqualsWithEntityName(node);
|
|
114
|
+
}
|
|
115
|
+
// Visibility
|
|
116
|
+
precalculateDeclarationEmitVisibility(file) {
|
|
117
|
+
if (this.aliasesMarked.has(file))
|
|
118
|
+
return false;
|
|
119
|
+
this.aliasesMarked.add(file);
|
|
120
|
+
file.forEachChild(new AliasMarker(this));
|
|
121
|
+
return true;
|
|
122
|
+
}
|
|
123
|
+
/** Marks the declarations an export names visible, following `import x = a.b` chains. */
|
|
124
|
+
markLinkedAliases(node) {
|
|
125
|
+
const meaning = 111551 /* SymbolFlags.Value */ | 788968 /* SymbolFlags.Type */ | 1920 /* SymbolFlags.Namespace */ | 2097152 /* SymbolFlags.Alias */;
|
|
126
|
+
const parent = node.parent;
|
|
127
|
+
let symbol = undefined;
|
|
128
|
+
if (node.kind !== 10 /* SyntaxKind.StringLiteral */ && parent.kind === 278 /* SyntaxKind.ExportAssignment */)
|
|
129
|
+
symbol = this.resolveName(node, getIdentifierText(node), meaning);
|
|
130
|
+
else if (parent instanceof ExportSpecifier) {
|
|
131
|
+
const declaration = parent.parent.parent;
|
|
132
|
+
if (declaration instanceof ExportDeclaration &&
|
|
133
|
+
declaration.moduleSpecifier === undefined &&
|
|
134
|
+
node instanceof Identifier &&
|
|
135
|
+
node.text !== 'default')
|
|
136
|
+
symbol = this.resolveName(node, node.text, meaning);
|
|
137
|
+
}
|
|
138
|
+
const visited = new Set();
|
|
139
|
+
while (symbol !== undefined && !visited.has(symbol)) {
|
|
140
|
+
visited.add(symbol);
|
|
141
|
+
let next = undefined;
|
|
142
|
+
for (const declaration of symbol.declarations) {
|
|
143
|
+
this.visibility.set(declaration, true);
|
|
144
|
+
if (declaration instanceof ImportEqualsDeclaration &&
|
|
145
|
+
!(declaration.moduleReference instanceof ExternalModuleReference)) {
|
|
146
|
+
const first = getFirstIdentifier(declaration.moduleReference);
|
|
147
|
+
next = this.resolveName(declaration, getIdentifierText(first), meaning);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
symbol = next;
|
|
151
|
+
}
|
|
152
|
+
return true;
|
|
153
|
+
}
|
|
154
|
+
isDeclarationVisible(node) {
|
|
155
|
+
if ((node.flags & 16 /* NodeFlags.Synthesized */) !== 0)
|
|
156
|
+
return false;
|
|
157
|
+
const cached = this.visibility.get(node);
|
|
158
|
+
if (cached !== undefined)
|
|
159
|
+
return cached;
|
|
160
|
+
const visible = this.determineIfDeclarationIsVisible(node);
|
|
161
|
+
this.visibility.set(node, visible);
|
|
162
|
+
return visible;
|
|
163
|
+
}
|
|
164
|
+
determineIfDeclarationIsVisible(node) {
|
|
165
|
+
switch (node.kind) {
|
|
166
|
+
case 331 /* SyntaxKind.JSDocCallbackTag */:
|
|
167
|
+
case 338 /* SyntaxKind.JSDocTypedefTag */: {
|
|
168
|
+
// Top-level JSDoc type aliases are exported.
|
|
169
|
+
const host = node.parent?.parent?.parent;
|
|
170
|
+
return host !== undefined && host.kind === 307 /* SyntaxKind.SourceFile */;
|
|
171
|
+
}
|
|
172
|
+
case 209 /* SyntaxKind.BindingElement */:
|
|
173
|
+
return this.isDeclarationVisible(node.parent.parent);
|
|
174
|
+
case 261 /* SyntaxKind.VariableDeclaration */:
|
|
175
|
+
case 268 /* SyntaxKind.ModuleDeclaration */:
|
|
176
|
+
case 264 /* SyntaxKind.ClassDeclaration */:
|
|
177
|
+
case 265 /* SyntaxKind.InterfaceDeclaration */:
|
|
178
|
+
case 266 /* SyntaxKind.TypeAliasDeclaration */:
|
|
179
|
+
case 345 /* SyntaxKind.JSTypeAliasDeclaration */:
|
|
180
|
+
case 263 /* SyntaxKind.FunctionDeclaration */:
|
|
181
|
+
case 267 /* SyntaxKind.EnumDeclaration */:
|
|
182
|
+
case 272 /* SyntaxKind.ImportEqualsDeclaration */: {
|
|
183
|
+
if (node instanceof VariableDeclaration &&
|
|
184
|
+
node.name instanceof BindingPattern &&
|
|
185
|
+
node.name.elements.nodes.length === 0)
|
|
186
|
+
return false;
|
|
187
|
+
if (isExternalModuleAugmentation(node) || isImplicitlyExportedJSDocDeclaration(node))
|
|
188
|
+
return true;
|
|
189
|
+
const parent = getDeclarationContainer(node);
|
|
190
|
+
// Unexported declarations are visible only in global files; ambient module members are exported.
|
|
191
|
+
if ((getCombinedModifierFlags(node) & 32 /* ModifierFlags.Export */) === 0 &&
|
|
192
|
+
!(node.kind !== 272 /* SyntaxKind.ImportEqualsDeclaration */ &&
|
|
193
|
+
parent.kind !== 307 /* SyntaxKind.SourceFile */ &&
|
|
194
|
+
(parent.flags & 8388608 /* NodeFlags.Ambient */) !== 0))
|
|
195
|
+
return isGlobalSourceFile(parent);
|
|
196
|
+
return this.isDeclarationVisible(parent);
|
|
197
|
+
}
|
|
198
|
+
case 173 /* SyntaxKind.PropertyDeclaration */:
|
|
199
|
+
case 172 /* SyntaxKind.PropertySignature */:
|
|
200
|
+
case 178 /* SyntaxKind.GetAccessor */:
|
|
201
|
+
case 179 /* SyntaxKind.SetAccessor */:
|
|
202
|
+
case 175 /* SyntaxKind.MethodDeclaration */:
|
|
203
|
+
case 174 /* SyntaxKind.MethodSignature */:
|
|
204
|
+
if (this.getEffectiveDeclarationFlags(node, 2 /* ModifierFlags.Private */ | 4 /* ModifierFlags.Protected */) !== 0)
|
|
205
|
+
return false;
|
|
206
|
+
return this.isDeclarationVisible(node.parent);
|
|
207
|
+
case 177 /* SyntaxKind.Constructor */:
|
|
208
|
+
case 181 /* SyntaxKind.ConstructSignature */:
|
|
209
|
+
case 180 /* SyntaxKind.CallSignature */:
|
|
210
|
+
case 182 /* SyntaxKind.IndexSignature */:
|
|
211
|
+
case 170 /* SyntaxKind.Parameter */:
|
|
212
|
+
case 269 /* SyntaxKind.ModuleBlock */:
|
|
213
|
+
case 185 /* SyntaxKind.FunctionType */:
|
|
214
|
+
case 186 /* SyntaxKind.ConstructorType */:
|
|
215
|
+
case 188 /* SyntaxKind.TypeLiteral */:
|
|
216
|
+
case 184 /* SyntaxKind.TypeReference */:
|
|
217
|
+
case 189 /* SyntaxKind.ArrayType */:
|
|
218
|
+
case 190 /* SyntaxKind.TupleType */:
|
|
219
|
+
case 193 /* SyntaxKind.UnionType */:
|
|
220
|
+
case 194 /* SyntaxKind.IntersectionType */:
|
|
221
|
+
case 197 /* SyntaxKind.ParenthesizedType */:
|
|
222
|
+
case 203 /* SyntaxKind.NamedTupleMember */:
|
|
223
|
+
return this.isDeclarationVisible(node.parent);
|
|
224
|
+
// Imports are visible only once something refers to them.
|
|
225
|
+
case 274 /* SyntaxKind.ImportClause */:
|
|
226
|
+
case 275 /* SyntaxKind.NamespaceImport */:
|
|
227
|
+
case 277 /* SyntaxKind.ImportSpecifier */:
|
|
228
|
+
return false;
|
|
229
|
+
case 169 /* SyntaxKind.TypeParameter */:
|
|
230
|
+
case 307 /* SyntaxKind.SourceFile */:
|
|
231
|
+
case 271 /* SyntaxKind.NamespaceExportDeclaration */:
|
|
232
|
+
return true;
|
|
233
|
+
case 278 /* SyntaxKind.ExportAssignment */:
|
|
234
|
+
return false;
|
|
235
|
+
case 282 /* SyntaxKind.ExportSpecifier */: {
|
|
236
|
+
const declaration = node.parent.parent;
|
|
237
|
+
if (declaration instanceof ExportDeclaration && declaration.moduleSpecifier === undefined)
|
|
238
|
+
return this.isDeclarationVisible(declaration.parent);
|
|
239
|
+
return false;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
return false;
|
|
243
|
+
}
|
|
244
|
+
isEntityNameVisible(entityName, enclosingDeclaration) {
|
|
245
|
+
if ((entityName.flags & 16 /* NodeFlags.Synthesized */) !== 0)
|
|
246
|
+
return new SymbolAccessibilityResult(1 /* SymbolAccessibility.NotAccessible */, [], '', undefined, '');
|
|
247
|
+
const meaning = getMeaningOfEntityNameReference(entityName);
|
|
248
|
+
const first = getFirstIdentifier(entityName);
|
|
249
|
+
const text = getIdentifierText(first);
|
|
250
|
+
const symbol = this.resolveName(enclosingDeclaration, text, meaning);
|
|
251
|
+
if (symbol !== undefined && (symbol.flags & 262144 /* SymbolFlags.TypeParameter */) !== 0 && (meaning & 788968 /* SymbolFlags.Type */) !== 0)
|
|
252
|
+
return accessible([]);
|
|
253
|
+
if (symbol === undefined && (first.kind === 109 /* SyntaxKind.ThisKeyword */ || text === 'this'))
|
|
254
|
+
return accessible([]);
|
|
255
|
+
if (symbol === undefined)
|
|
256
|
+
return new SymbolAccessibilityResult(3 /* SymbolAccessibility.NotResolved */, [], text, first, '');
|
|
257
|
+
const visible = this.hasVisibleDeclarations(symbol, true);
|
|
258
|
+
if (visible !== undefined)
|
|
259
|
+
return visible;
|
|
260
|
+
return new SymbolAccessibilityResult(1 /* SymbolAccessibility.NotAccessible */, [], text, first, '');
|
|
261
|
+
}
|
|
262
|
+
isSymbolAccessible(symbol, _enclosingDeclaration, _meaning, shouldComputeAliasesToMakeVisible) {
|
|
263
|
+
if ((symbol.flags & 262144 /* SymbolFlags.TypeParameter */) !== 0)
|
|
264
|
+
return accessible([]);
|
|
265
|
+
const visible = this.hasVisibleDeclarations(symbol, shouldComputeAliasesToMakeVisible);
|
|
266
|
+
if (visible !== undefined)
|
|
267
|
+
return visible;
|
|
268
|
+
return new SymbolAccessibilityResult(1 /* SymbolAccessibility.NotAccessible */, [], symbol.name, undefined, '');
|
|
269
|
+
}
|
|
270
|
+
/** Accessible if every declaration is visible or can be made so by keeping an unexported statement. */
|
|
271
|
+
hasVisibleDeclarations(symbol, shouldComputeAliasesToMakeVisible) {
|
|
272
|
+
const aliases = [];
|
|
273
|
+
for (const declaration of symbol.declarations) {
|
|
274
|
+
if (declaration.kind === 79 /* SyntaxKind.Identifier */ || this.isDeclarationVisible(declaration))
|
|
275
|
+
continue;
|
|
276
|
+
let statement = undefined;
|
|
277
|
+
// Imports and unexported declarations can name types if their parent is visible.
|
|
278
|
+
const anyImport = getAnyImportSyntax(declaration);
|
|
279
|
+
if (anyImport !== undefined &&
|
|
280
|
+
!hasSyntacticModifier(anyImport, 32 /* ModifierFlags.Export */) &&
|
|
281
|
+
this.isDeclarationVisible(anyImport.parent))
|
|
282
|
+
statement = anyImport;
|
|
283
|
+
else if (declaration instanceof VariableDeclaration &&
|
|
284
|
+
declaration.parent.parent.kind === 244 /* SyntaxKind.VariableStatement */ &&
|
|
285
|
+
!hasSyntacticModifier(declaration.parent.parent, 32 /* ModifierFlags.Export */) &&
|
|
286
|
+
this.isDeclarationVisible(declaration.parent.parent.parent))
|
|
287
|
+
statement = declaration.parent.parent;
|
|
288
|
+
else if (isLateVisibilityPaintedStatement(declaration) &&
|
|
289
|
+
!hasSyntacticModifier(declaration, 32 /* ModifierFlags.Export */) &&
|
|
290
|
+
this.isDeclarationVisible(declaration.parent))
|
|
291
|
+
statement = declaration;
|
|
292
|
+
else if (declaration instanceof BindingElement && (symbol.flags & 2 /* SymbolFlags.BlockScopedVariable */) !== 0) {
|
|
293
|
+
const root = getRootDeclaration(declaration);
|
|
294
|
+
if (root.kind === 170 /* SyntaxKind.Parameter */)
|
|
295
|
+
return undefined;
|
|
296
|
+
const variableStatement = root.parent?.parent;
|
|
297
|
+
if (variableStatement === undefined || variableStatement.kind !== 244 /* SyntaxKind.VariableStatement */)
|
|
298
|
+
return undefined;
|
|
299
|
+
// Already exported: nothing to keep.
|
|
300
|
+
if (hasSyntacticModifier(variableStatement, 32 /* ModifierFlags.Export */))
|
|
301
|
+
continue;
|
|
302
|
+
if (!this.isDeclarationVisible(variableStatement.parent))
|
|
303
|
+
return undefined;
|
|
304
|
+
statement = variableStatement;
|
|
305
|
+
}
|
|
306
|
+
if (statement === undefined)
|
|
307
|
+
return undefined;
|
|
308
|
+
if (shouldComputeAliasesToMakeVisible) {
|
|
309
|
+
this.visibility.set(declaration, true);
|
|
310
|
+
if (aliases.indexOf(statement) < 0)
|
|
311
|
+
aliases.push(statement);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
return accessible(aliases);
|
|
315
|
+
}
|
|
316
|
+
isNameResolvable(location, name) {
|
|
317
|
+
return this.resolveName(location, name, 111551 /* SymbolFlags.Value */ | 788968 /* SymbolFlags.Type */ | 1920 /* SymbolFlags.Namespace */) !== undefined;
|
|
318
|
+
}
|
|
319
|
+
// Modules aren't resolved, so no import is known to be needed by an augmentation.
|
|
320
|
+
isImportRequiredByAugmentation(_node) {
|
|
321
|
+
return false;
|
|
322
|
+
}
|
|
323
|
+
// Declarations
|
|
324
|
+
getEffectiveDeclarationFlags(node, flags) {
|
|
325
|
+
let result = getCombinedModifierFlags(node);
|
|
326
|
+
const parent = node.parent;
|
|
327
|
+
// Class and interface members are never implicitly exported or ambient.
|
|
328
|
+
if (parent !== undefined &&
|
|
329
|
+
parent.kind !== 265 /* SyntaxKind.InterfaceDeclaration */ &&
|
|
330
|
+
parent.kind !== 264 /* SyntaxKind.ClassDeclaration */ &&
|
|
331
|
+
parent.kind !== 232 /* SyntaxKind.ClassExpression */ &&
|
|
332
|
+
(node.flags & 8388608 /* NodeFlags.Ambient */) !== 0) {
|
|
333
|
+
const container = getEnclosingContainer(node);
|
|
334
|
+
if (container !== undefined &&
|
|
335
|
+
(container.flags & 64 /* NodeFlags.ExportContext */) !== 0 &&
|
|
336
|
+
(result & 128 /* ModifierFlags.Ambient */) === 0 &&
|
|
337
|
+
!(parent.kind === 269 /* SyntaxKind.ModuleBlock */ && isGlobalScopeAugmentation(parent.parent)))
|
|
338
|
+
result |= 32 /* ModifierFlags.Export */;
|
|
339
|
+
result |= 128 /* ModifierFlags.Ambient */;
|
|
340
|
+
}
|
|
341
|
+
return result & flags;
|
|
342
|
+
}
|
|
343
|
+
isImplementationOfOverload(node) {
|
|
344
|
+
if ((node.flags & 16 /* NodeFlags.Synthesized */) !== 0 || !nodeIsPresent(getBody(node)))
|
|
345
|
+
return false;
|
|
346
|
+
if (node.kind === 178 /* SyntaxKind.GetAccessor */ || node.kind === 179 /* SyntaxKind.SetAccessor */)
|
|
347
|
+
return false;
|
|
348
|
+
const symbol = this.getSymbolOfDeclaration(node);
|
|
349
|
+
if (symbol === undefined)
|
|
350
|
+
return false;
|
|
351
|
+
const signatures = [];
|
|
352
|
+
const declarations = symbol.declarations;
|
|
353
|
+
for (let i = 0; i < declarations.length; i++) {
|
|
354
|
+
const declaration = declarations[i];
|
|
355
|
+
if (!isFunctionLike(declaration))
|
|
356
|
+
continue;
|
|
357
|
+
// An implementation directly after an overload of the same kind isn't a signature.
|
|
358
|
+
if (i > 0 && getBody(declaration) !== undefined) {
|
|
359
|
+
const previous = declarations[i - 1];
|
|
360
|
+
if (declaration.parent === previous.parent &&
|
|
361
|
+
declaration.kind === previous.kind &&
|
|
362
|
+
declaration.pos === previous.end)
|
|
363
|
+
continue;
|
|
364
|
+
}
|
|
365
|
+
signatures.push(declaration);
|
|
366
|
+
}
|
|
367
|
+
if (signatures.length > 1)
|
|
368
|
+
return true;
|
|
369
|
+
return signatures.length === 1 && signatures[0] !== node && (signatures[0].flags & 4194304 /* NodeFlags.JSDoc */) === 0;
|
|
370
|
+
}
|
|
371
|
+
isLateBound(node) {
|
|
372
|
+
const name = getName(node);
|
|
373
|
+
if (!(name instanceof ComputedPropertyName))
|
|
374
|
+
return false;
|
|
375
|
+
return this.isLateBindableExpression(name.expression);
|
|
376
|
+
}
|
|
377
|
+
/** Whether a computed name's expression has a unique symbol or literal type, as far as declarations say. */
|
|
378
|
+
isLateBindableExpression(expression) {
|
|
379
|
+
if (!isEntityNameExpression(expression, false))
|
|
380
|
+
return false;
|
|
381
|
+
const declaration = this.getEntityDeclaration(expression);
|
|
382
|
+
return declaration !== undefined && hasLiteralOrUniqueSymbolType(declaration);
|
|
383
|
+
}
|
|
384
|
+
/** The declaration `a` or `a.b.c` names: a variable, a member of a namespace, class or enum, or of an object type or literal. */
|
|
385
|
+
getEntityDeclaration(node) {
|
|
386
|
+
if (node instanceof Identifier) {
|
|
387
|
+
const symbol = this.resolveName(node, node.text, 111551 /* SymbolFlags.Value */ | 1048576 /* SymbolFlags.ExportValue */);
|
|
388
|
+
if (symbol === undefined)
|
|
389
|
+
return undefined;
|
|
390
|
+
const resolved = symbol.exportSymbol ?? symbol;
|
|
391
|
+
return resolved.valueDeclaration ?? (resolved.declarations.length > 0 ? resolved.declarations[0] : undefined);
|
|
392
|
+
}
|
|
393
|
+
if (!(node instanceof PropertyAccessExpression) || !(node.name instanceof Identifier))
|
|
394
|
+
return undefined;
|
|
395
|
+
const name = node.name.text;
|
|
396
|
+
const left = node.expression;
|
|
397
|
+
if (left.kind === 79 /* SyntaxKind.Identifier */ || left.kind === 212 /* SyntaxKind.PropertyAccessExpression */) {
|
|
398
|
+
const symbol = this.resolveEntityNameExpression(left, 111551 /* SymbolFlags.Value */ | 1920 /* SymbolFlags.Namespace */);
|
|
399
|
+
if (symbol !== undefined && (symbol.flags & 2097152 /* SymbolFlags.Alias */) === 0) {
|
|
400
|
+
const member = (symbol.exports ?? emptyTable).get(name);
|
|
401
|
+
if (member !== undefined)
|
|
402
|
+
return member.valueDeclaration;
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
// A member of a variable's object type or object literal.
|
|
406
|
+
const container = this.getEntityDeclaration(left);
|
|
407
|
+
if (!(container instanceof VariableDeclaration))
|
|
408
|
+
return undefined;
|
|
409
|
+
const members = container.type instanceof TypeLiteralNode
|
|
410
|
+
? container.type.members.nodes
|
|
411
|
+
: container.initializer !== undefined
|
|
412
|
+
? objectLiteralProperties(container.initializer)
|
|
413
|
+
: [];
|
|
414
|
+
for (const member of members) {
|
|
415
|
+
const memberName = getName(member);
|
|
416
|
+
if (memberName !== undefined && tryGetTextOfPropertyName(memberName) === name)
|
|
417
|
+
return member;
|
|
418
|
+
}
|
|
419
|
+
return undefined;
|
|
420
|
+
}
|
|
421
|
+
isDefinitelyReferenceToGlobalSymbolObject(node) {
|
|
422
|
+
if (!(node instanceof PropertyAccessExpression) || !(node.name instanceof Identifier))
|
|
423
|
+
return false;
|
|
424
|
+
const expression = node.expression;
|
|
425
|
+
if (expression instanceof Identifier)
|
|
426
|
+
return expression.text === 'Symbol' && this.isGlobalValue(expression, 'Symbol');
|
|
427
|
+
if (!(expression instanceof PropertyAccessExpression) || !(expression.expression instanceof Identifier))
|
|
428
|
+
return false;
|
|
429
|
+
return (expression.expression.text === 'globalThis' &&
|
|
430
|
+
isIdentifierNamed(expression.name, 'Symbol') &&
|
|
431
|
+
this.resolveName(expression.expression, 'globalThis', 111551 /* SymbolFlags.Value */) === undefined);
|
|
432
|
+
}
|
|
433
|
+
/** Whether `name` at `location` resolves to a declaration of a global file. */
|
|
434
|
+
isGlobalValue(location, name) {
|
|
435
|
+
const symbol = this.resolveName(location, name, 111551 /* SymbolFlags.Value */);
|
|
436
|
+
return symbol !== undefined && this.pseudo.getMergedSymbol(symbol) === this.names.globals.get(name);
|
|
437
|
+
}
|
|
438
|
+
isLiteralConstDeclaration(node) {
|
|
439
|
+
if ((node.flags & 16 /* NodeFlags.Synthesized */) !== 0)
|
|
440
|
+
return false;
|
|
441
|
+
const isConst = node instanceof VariableDeclaration
|
|
442
|
+
? (getCombinedNodeFlags(node) & 2 /* NodeFlags.Const */) !== 0
|
|
443
|
+
: (getCombinedModifierFlags(node) & 8 /* ModifierFlags.Readonly */) !== 0 &&
|
|
444
|
+
!isParameterPropertyDeclaration(node, node.parent);
|
|
445
|
+
if (!isConst || getType(node) !== undefined)
|
|
446
|
+
return false;
|
|
447
|
+
const initializer = getInitializer(node);
|
|
448
|
+
// A fresh literal type; enum members are too, but need the checker to tell apart.
|
|
449
|
+
return initializer !== undefined && literalOf(skipParentheses(initializer)) !== undefined;
|
|
450
|
+
}
|
|
451
|
+
isOptionalParameter(node) {
|
|
452
|
+
if (!(node instanceof ParameterDeclaration))
|
|
453
|
+
return false;
|
|
454
|
+
if (node.questionToken !== undefined)
|
|
455
|
+
return true;
|
|
456
|
+
if (node.initializer === undefined)
|
|
457
|
+
return false;
|
|
458
|
+
const parameters = getParameters(node.parent).nodes;
|
|
459
|
+
return parameters.indexOf(node) >= lastRequiredParameterIndex(parameters);
|
|
460
|
+
}
|
|
461
|
+
requiresAddingImplicitUndefined(node, enclosingDeclaration) {
|
|
462
|
+
if (node === undefined || !(node instanceof ParameterDeclaration) || (node.flags & 16 /* NodeFlags.Synthesized */) !== 0)
|
|
463
|
+
return false;
|
|
464
|
+
const required = this.isRequiredInitializedParameter(node, enclosingDeclaration) ||
|
|
465
|
+
this.isOptionalUninitializedParameterProperty(node);
|
|
466
|
+
return required && !this.declaredTypeContainsUndefined(node);
|
|
467
|
+
}
|
|
468
|
+
isRequiredInitializedParameter(node, enclosingDeclaration) {
|
|
469
|
+
if (!this.strictNullChecks || this.isOptionalParameter(node) || node.initializer === undefined)
|
|
470
|
+
return false;
|
|
471
|
+
if (hasSyntacticModifier(node, 31 /* ModifierFlags.ParameterPropertyModifier */))
|
|
472
|
+
return enclosingDeclaration !== undefined && isFunctionLike(enclosingDeclaration);
|
|
473
|
+
return true;
|
|
474
|
+
}
|
|
475
|
+
isOptionalUninitializedParameterProperty(node) {
|
|
476
|
+
return (this.strictNullChecks &&
|
|
477
|
+
this.isOptionalParameter(node) &&
|
|
478
|
+
node.initializer === undefined &&
|
|
479
|
+
hasSyntacticModifier(node, 31 /* ModifierFlags.ParameterPropertyModifier */));
|
|
480
|
+
}
|
|
481
|
+
/** Whether an annotation includes `undefined`, or names something unresolved (an error type). */
|
|
482
|
+
declaredTypeContainsUndefined(node) {
|
|
483
|
+
const type = node.type;
|
|
484
|
+
return type !== undefined && this.typeContainsUndefined(type, node);
|
|
485
|
+
}
|
|
486
|
+
typeContainsUndefined(type, location) {
|
|
487
|
+
switch (type.kind) {
|
|
488
|
+
case 157 /* SyntaxKind.UndefinedKeyword */:
|
|
489
|
+
case 132 /* SyntaxKind.AnyKeyword */:
|
|
490
|
+
case 159 /* SyntaxKind.UnknownKeyword */:
|
|
491
|
+
return true;
|
|
492
|
+
case 197 /* SyntaxKind.ParenthesizedType */:
|
|
493
|
+
return this.typeContainsUndefined(getType(type), location);
|
|
494
|
+
case 193 /* SyntaxKind.UnionType */:
|
|
495
|
+
for (const member of typesOf(type))
|
|
496
|
+
if (this.typeContainsUndefined(member, location))
|
|
497
|
+
return true;
|
|
498
|
+
return false;
|
|
499
|
+
case 184 /* SyntaxKind.TypeReference */: {
|
|
500
|
+
// An unresolved name or import is an error type, which counts as containing `undefined`.
|
|
501
|
+
const symbol = this.resolveName(location, getIdentifierText(getFirstIdentifier(type.typeName)), 788968 /* SymbolFlags.Type */ | 1920 /* SymbolFlags.Namespace */);
|
|
502
|
+
return symbol === undefined || (symbol.flags & 2097152 /* SymbolFlags.Alias */) !== 0;
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
return false;
|
|
506
|
+
}
|
|
507
|
+
isExpandoFunctionDeclaration(node) {
|
|
508
|
+
return this.getExpandoPropertyDeclarations(node).length > 0;
|
|
509
|
+
}
|
|
510
|
+
getExpandoPropertyDeclarations(node) {
|
|
511
|
+
const result = [];
|
|
512
|
+
let host = node;
|
|
513
|
+
// Properties assigned to a function-valued variable are bound to the function.
|
|
514
|
+
if (node instanceof VariableDeclaration)
|
|
515
|
+
host = node.initializer;
|
|
516
|
+
else if (node.kind !== 263 /* SyntaxKind.FunctionDeclaration */)
|
|
517
|
+
host = undefined;
|
|
518
|
+
if (host === undefined || !isFunctionLike(host))
|
|
519
|
+
return result;
|
|
520
|
+
const symbol = getSymbol(host);
|
|
521
|
+
if (symbol === undefined || symbol.exports === undefined)
|
|
522
|
+
return result;
|
|
523
|
+
for (const property of symbol.exports.values())
|
|
524
|
+
if ((property.flags & 67108864 /* SymbolFlags.Assignment */) !== 0 && property.valueDeclaration !== undefined)
|
|
525
|
+
result.push(property.valueDeclaration);
|
|
526
|
+
return result;
|
|
527
|
+
}
|
|
528
|
+
// Emit queries answered by the reference resolver.
|
|
529
|
+
getReferencedExportContainer(node, prefixLocals) {
|
|
530
|
+
return this.emitResolver.getReferencedExportContainer(node, prefixLocals);
|
|
531
|
+
}
|
|
532
|
+
getReferencedImportDeclaration(node) {
|
|
533
|
+
return this.emitResolver.getReferencedImportDeclaration(node);
|
|
534
|
+
}
|
|
535
|
+
getReferencedValueDeclaration(node) {
|
|
536
|
+
return this.emitResolver.getReferencedValueDeclaration(node);
|
|
537
|
+
}
|
|
538
|
+
getReferencedValueDeclarations(node) {
|
|
539
|
+
return this.emitResolver.getReferencedValueDeclarations(node);
|
|
540
|
+
}
|
|
541
|
+
getEnumMemberValue(member) {
|
|
542
|
+
return this.emitResolver.getEnumMemberValue(member);
|
|
543
|
+
}
|
|
544
|
+
getConstantValue(node) {
|
|
545
|
+
return this.emitResolver.getConstantValue(node);
|
|
546
|
+
}
|
|
547
|
+
setReferencedImportDeclaration(name, declaration) {
|
|
548
|
+
this.emitResolver.setReferencedImportDeclaration(name, declaration);
|
|
549
|
+
}
|
|
550
|
+
getJsxFactoryEntity(file) {
|
|
551
|
+
return this.emitResolver.getJsxFactoryEntity(file);
|
|
552
|
+
}
|
|
553
|
+
getJsxFragmentFactoryEntity(file) {
|
|
554
|
+
return this.emitResolver.getJsxFragmentFactoryEntity(file);
|
|
555
|
+
}
|
|
556
|
+
getTypeReferenceSerializationKind(typeName, location) {
|
|
557
|
+
return this.emitResolver.getTypeReferenceSerializationKind(typeName, location);
|
|
558
|
+
}
|
|
559
|
+
getResolutionModeOverride(node) {
|
|
560
|
+
if (!(node instanceof ImportAttributes))
|
|
561
|
+
return undefined;
|
|
562
|
+
for (const element of node.attributes.nodes) {
|
|
563
|
+
if (!(element instanceof ImportAttribute))
|
|
564
|
+
continue;
|
|
565
|
+
const name = element.name;
|
|
566
|
+
if (name === undefined || (name.kind !== 10 /* SyntaxKind.StringLiteral */ && name.kind !== 79 /* SyntaxKind.Identifier */))
|
|
567
|
+
continue;
|
|
568
|
+
if (getText(name) !== 'resolution-mode')
|
|
569
|
+
continue;
|
|
570
|
+
const value = element.value;
|
|
571
|
+
if (!(value instanceof StringLiteral))
|
|
572
|
+
return undefined;
|
|
573
|
+
if (value.text === 'import')
|
|
574
|
+
return ModuleKinds.ESNext;
|
|
575
|
+
if (value.text === 'require')
|
|
576
|
+
return ModuleKinds.CommonJS;
|
|
577
|
+
}
|
|
578
|
+
return undefined;
|
|
579
|
+
}
|
|
580
|
+
getSourceFileFromReference(file, reference) {
|
|
581
|
+
const path = normalizePath(combinePaths(getDirectoryPath(file.fileName), reference.fileName));
|
|
582
|
+
for (const candidate of [path, path + '.ts', path + '.tsx', path + '.d.ts']) {
|
|
583
|
+
const found = this.filesByPath.get(candidate);
|
|
584
|
+
if (found !== undefined)
|
|
585
|
+
return found;
|
|
586
|
+
}
|
|
587
|
+
return undefined;
|
|
588
|
+
}
|
|
589
|
+
// JavaScript members need the checker.
|
|
590
|
+
getReferencedMemberValueDeclaration(node) {
|
|
591
|
+
const symbol = getSymbol(node);
|
|
592
|
+
return symbol === undefined ? undefined : symbol.valueDeclaration;
|
|
593
|
+
}
|
|
594
|
+
isThisPropertyAssignmentDeclarationRedundant(_node) {
|
|
595
|
+
return false;
|
|
596
|
+
}
|
|
597
|
+
getElementAccessExpressionName(node) {
|
|
598
|
+
if (!(node instanceof ElementAccessExpression))
|
|
599
|
+
return '';
|
|
600
|
+
const argument = node.argumentExpression;
|
|
601
|
+
return isStringOrNumericLiteralLike(argument) ? literalText(argument) : '';
|
|
602
|
+
}
|
|
603
|
+
// Type nodes
|
|
604
|
+
createTypeOfDeclaration(context, declaration, enclosingDeclaration, flags, tracker) {
|
|
605
|
+
if ((declaration.flags & 16 /* NodeFlags.Synthesized */) !== 0)
|
|
606
|
+
return undefined;
|
|
607
|
+
const writer = new PseudoTypeWriter(this, context, tracker, enclosingDeclaration, flags);
|
|
608
|
+
const isAccessor = declaration.kind === 178 /* SyntaxKind.GetAccessor */ || declaration.kind === 179 /* SyntaxKind.SetAccessor */;
|
|
609
|
+
this.pseudo.uncertain = 0;
|
|
610
|
+
let type = isAccessor ? this.pseudo.getTypeOfAccessor(declaration) : this.pseudo.getTypeOfDeclaration(declaration);
|
|
611
|
+
if (declaration.kind === 170 /* SyntaxKind.Parameter */ &&
|
|
612
|
+
this.requiresAddingImplicitUndefined(declaration, enclosingDeclaration) &&
|
|
613
|
+
!this.pseudoContainsUndefined(type))
|
|
614
|
+
type = new UnionType([type, undefinedType]);
|
|
615
|
+
const result = writer.write(type);
|
|
616
|
+
// Declarations merged across files have the type of their first declaration.
|
|
617
|
+
if (this.pseudo.uncertain > 0 || this.hasMergedDeclarations(declaration))
|
|
618
|
+
this.countFallback(declaration, true);
|
|
619
|
+
return result;
|
|
620
|
+
}
|
|
621
|
+
hasMergedDeclarations(declaration) {
|
|
622
|
+
const symbol = getSymbol(declaration);
|
|
623
|
+
return symbol !== undefined && this.pseudo.getMergedSymbol(symbol).declarations.length > symbol.declarations.length;
|
|
624
|
+
}
|
|
625
|
+
/** Whether a parameter's pseudo-type already has `undefined`, so none is added. */
|
|
626
|
+
pseudoContainsUndefined(type) {
|
|
627
|
+
if (type instanceof UnionType) {
|
|
628
|
+
for (const member of type.types)
|
|
629
|
+
if (this.pseudoContainsUndefined(member))
|
|
630
|
+
return true;
|
|
631
|
+
return false;
|
|
632
|
+
}
|
|
633
|
+
if (type instanceof DirectType)
|
|
634
|
+
return couldAlreadyReferToUndefined(type) && type.typeNode.kind !== 184 /* SyntaxKind.TypeReference */;
|
|
635
|
+
return type.kind === 5 /* PseudoTypeKind.Undefined */;
|
|
636
|
+
}
|
|
637
|
+
createReturnTypeOfSignatureDeclaration(context, signature, enclosingDeclaration, flags, tracker) {
|
|
638
|
+
if ((signature.flags & 16 /* NodeFlags.Synthesized */) !== 0)
|
|
639
|
+
return undefined;
|
|
640
|
+
const type = this.pseudo.getReturnTypeOfSignature(signature);
|
|
641
|
+
const writer = new PseudoTypeWriter(this, context, tracker, enclosingDeclaration, flags);
|
|
642
|
+
if (type instanceof InferredType && type.isSignatureReturn && type.errorNodes.length === 0) {
|
|
643
|
+
// A body without returned values is `void`, as the checker infers.
|
|
644
|
+
const inferredVoid = isTriviallyVoid(signature);
|
|
645
|
+
if (inferredVoid) {
|
|
646
|
+
writer.reportFallback(type, false);
|
|
647
|
+
return context.factory.created(new KeywordTypeNode(115 /* SyntaxKind.VoidKeyword */));
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
if (type instanceof NoResultType && getBody(signature) === undefined && signature.kind !== 178 /* SyntaxKind.GetAccessor */) {
|
|
651
|
+
// A signature without a body or annotation returns `any`.
|
|
652
|
+
writer.reportFallback(type, false);
|
|
653
|
+
return undefined;
|
|
654
|
+
}
|
|
655
|
+
return writer.write(type);
|
|
656
|
+
}
|
|
657
|
+
createTypeParametersOfSignatureDeclaration(_context, signature, _enclosingDeclaration, _flags, _tracker) {
|
|
658
|
+
this.countFallback(signature, true);
|
|
659
|
+
return undefined;
|
|
660
|
+
}
|
|
661
|
+
createLiteralConstValue(context, node, _tracker) {
|
|
662
|
+
const initializer = node.kind === 278 /* SyntaxKind.ExportAssignment */ ? getExpression(node) : getInitializer(node);
|
|
663
|
+
if (initializer === undefined)
|
|
664
|
+
return undefined;
|
|
665
|
+
const literal = literalOf(skipParentheses(initializer));
|
|
666
|
+
if (literal === undefined) {
|
|
667
|
+
this.countFallback(node, true);
|
|
668
|
+
return undefined;
|
|
669
|
+
}
|
|
670
|
+
const factory = context.factory;
|
|
671
|
+
switch (literal.kind) {
|
|
672
|
+
case 111 /* SyntaxKind.TrueKeyword */:
|
|
673
|
+
case 96 /* SyntaxKind.FalseKeyword */:
|
|
674
|
+
return factory.createKeywordExpression(literal.kind);
|
|
675
|
+
case 10 /* SyntaxKind.StringLiteral */:
|
|
676
|
+
case 14 /* SyntaxKind.NoSubstitutionTemplateLiteral */:
|
|
677
|
+
return factory.createStringLiteral(literalText(literal), 0 /* TokenFlags.None */);
|
|
678
|
+
case 9 /* SyntaxKind.BigIntLiteral */:
|
|
679
|
+
return factory.created(new BigIntLiteral(literal.text, 0 /* TokenFlags.None */));
|
|
680
|
+
case 8 /* SyntaxKind.NumericLiteral */:
|
|
681
|
+
return createNumberExpression(context, Number(literal.text));
|
|
682
|
+
case 225 /* SyntaxKind.PrefixUnaryExpression */: {
|
|
683
|
+
const unary = literal;
|
|
684
|
+
const operand = unary.operand;
|
|
685
|
+
if (operand instanceof BigIntLiteral)
|
|
686
|
+
return factory.created(new BigIntLiteral(unary.operator === 40 /* SyntaxKind.MinusToken */ ? '-' + operand.text : operand.text, 0 /* TokenFlags.None */));
|
|
687
|
+
const value = Number(operand.text);
|
|
688
|
+
return createNumberExpression(context, unary.operator === 40 /* SyntaxKind.MinusToken */ ? -value : value);
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
return undefined;
|
|
692
|
+
}
|
|
693
|
+
createTypeOfExpression(context, expression, enclosingDeclaration, flags, tracker) {
|
|
694
|
+
const writer = new PseudoTypeWriter(this, context, tracker, enclosingDeclaration, flags);
|
|
695
|
+
this.countFallback(expression, true);
|
|
696
|
+
// An expression's own type: literals aren't widened.
|
|
697
|
+
const type = this.pseudo.getTypeOfExpression(expression);
|
|
698
|
+
return writer.write(type instanceof MaybeConstType ? type.constType : type);
|
|
699
|
+
}
|
|
700
|
+
createLateBoundIndexSignatures(context, container, enclosingDeclaration, flags, tracker) {
|
|
701
|
+
// These come from computed names whose types aren't literals or unique symbols; only the
|
|
702
|
+
// checker knows them. Writing them reports their members' types that need inference.
|
|
703
|
+
const members = getMembers(container);
|
|
704
|
+
if (members === undefined)
|
|
705
|
+
return [];
|
|
706
|
+
const writer = new PseudoTypeWriter(this, context, tracker, enclosingDeclaration, flags);
|
|
707
|
+
for (const member of members.nodes) {
|
|
708
|
+
const name = getName(member);
|
|
709
|
+
if (!(name instanceof ComputedPropertyName) || !isEntityNameExpression(name.expression, false))
|
|
710
|
+
continue;
|
|
711
|
+
if (this.isLateBindableExpression(name.expression))
|
|
712
|
+
continue;
|
|
713
|
+
this.countFallback(member, true);
|
|
714
|
+
if (isFunctionLike(member) && getType(member) === undefined && member.kind !== 179 /* SyntaxKind.SetAccessor */)
|
|
715
|
+
writer.write(this.pseudo.getReturnTypeOfSignature(member));
|
|
716
|
+
else if (member.kind === 173 /* SyntaxKind.PropertyDeclaration */ && getType(member) === undefined)
|
|
717
|
+
writer.write(this.pseudo.getTypeOfDeclaration(member));
|
|
718
|
+
}
|
|
719
|
+
return [];
|
|
720
|
+
}
|
|
721
|
+
tryJSTypeNodeToTypeNode(_context, typeNode, _enclosingDeclaration, _flags, _tracker) {
|
|
722
|
+
// JSDoc types are rewritten with their meaning (`String` is `string`), which needs symbols.
|
|
723
|
+
this.countFallback(typeNode, true);
|
|
724
|
+
return undefined;
|
|
725
|
+
}
|
|
726
|
+
// Helpers
|
|
727
|
+
/** The symbol of a declaration, merged with same-named globals of other files. */
|
|
728
|
+
getSymbolOfDeclaration(node) {
|
|
729
|
+
const symbol = getSymbol(node);
|
|
730
|
+
return symbol === undefined ? undefined : this.pseudo.getMergedSymbol(symbol);
|
|
731
|
+
}
|
|
732
|
+
resolveName(location, name, meaning) {
|
|
733
|
+
return this.names.resolve(location, name, meaning, undefined, false, false);
|
|
734
|
+
}
|
|
735
|
+
/** The symbol of `a` or `a.b.c`, looking members up in namespace and enum exports. */
|
|
736
|
+
resolveEntityNameExpression(node, meaning) {
|
|
737
|
+
if (node instanceof Identifier)
|
|
738
|
+
return this.resolveName(node, node.text, meaning);
|
|
739
|
+
let left = undefined;
|
|
740
|
+
let right = undefined;
|
|
741
|
+
if (node instanceof PropertyAccessExpression) {
|
|
742
|
+
left = node.expression;
|
|
743
|
+
right = node.name;
|
|
744
|
+
}
|
|
745
|
+
else if (node instanceof QualifiedName) {
|
|
746
|
+
left = node.left;
|
|
747
|
+
right = node.right;
|
|
748
|
+
}
|
|
749
|
+
if (left !== undefined && right !== undefined) {
|
|
750
|
+
const namespace = this.resolveEntityNameExpression(left, 1920 /* SymbolFlags.Namespace */);
|
|
751
|
+
if (namespace === undefined || (namespace.flags & 2097152 /* SymbolFlags.Alias */) !== 0 || !(right instanceof Identifier))
|
|
752
|
+
return undefined;
|
|
753
|
+
const member = (namespace.exports ?? emptyTable).get(right.text);
|
|
754
|
+
return member !== undefined && (member.flags & meaning) !== 0 ? member : undefined;
|
|
755
|
+
}
|
|
756
|
+
return undefined;
|
|
757
|
+
}
|
|
758
|
+
/** Records a type that needed inference; `unresolved` if it's written as `any`. */
|
|
759
|
+
countFallback(node, unresolved) {
|
|
760
|
+
const file = getSourceFileOfNode(node);
|
|
761
|
+
let counts = this.inference.get(file);
|
|
762
|
+
if (counts === undefined) {
|
|
763
|
+
counts = new InferenceCounts();
|
|
764
|
+
this.inference.set(file, counts);
|
|
765
|
+
}
|
|
766
|
+
counts.fallbacks++;
|
|
767
|
+
if (unresolved)
|
|
768
|
+
counts.unresolved++;
|
|
769
|
+
return true;
|
|
770
|
+
}
|
|
771
|
+
}
|
|
772
|
+
/** Writes pseudo-types as type nodes; types that need inference make the result undefined. */
|
|
773
|
+
class PseudoTypeWriter {
|
|
774
|
+
resolver;
|
|
775
|
+
context;
|
|
776
|
+
tracker;
|
|
777
|
+
enclosingDeclaration;
|
|
778
|
+
flags;
|
|
779
|
+
/** Whether a reused node names something that can't be named where it's written. */
|
|
780
|
+
reuseFailed;
|
|
781
|
+
constructor(resolver, context, tracker, enclosingDeclaration, flags) {
|
|
782
|
+
this.resolver = resolver;
|
|
783
|
+
this.context = context;
|
|
784
|
+
this.tracker = tracker;
|
|
785
|
+
this.enclosingDeclaration = enclosingDeclaration;
|
|
786
|
+
this.flags = flags;
|
|
787
|
+
this.reuseFailed = false;
|
|
788
|
+
}
|
|
789
|
+
/** Reports where inference was needed, as the checker's node builder does. */
|
|
790
|
+
reportFallback(type, unresolved) {
|
|
791
|
+
let location;
|
|
792
|
+
if (type instanceof InferredType) {
|
|
793
|
+
if (type.errorNodes.length > 0) {
|
|
794
|
+
for (const node of type.errorNodes)
|
|
795
|
+
this.tracker.reportInferenceFallback(node);
|
|
796
|
+
return this.resolver.countFallback(type.errorNodes[0], unresolved);
|
|
797
|
+
}
|
|
798
|
+
const expression = type.expression;
|
|
799
|
+
const parent = expression.parent;
|
|
800
|
+
location =
|
|
801
|
+
isEntityNameExpression(expression, false) && parent !== undefined && isDeclarationKind(parent.kind)
|
|
802
|
+
? parent
|
|
803
|
+
: expression;
|
|
804
|
+
}
|
|
805
|
+
else if (type instanceof NoResultType)
|
|
806
|
+
location = type.declaration;
|
|
807
|
+
else
|
|
808
|
+
return false;
|
|
809
|
+
this.tracker.reportInferenceFallback(location);
|
|
810
|
+
return this.resolver.countFallback(location, unresolved);
|
|
811
|
+
}
|
|
812
|
+
write(type) {
|
|
813
|
+
const factory = this.context.factory;
|
|
814
|
+
switch (type.kind) {
|
|
815
|
+
case 0 /* PseudoTypeKind.Direct */:
|
|
816
|
+
return this.reuseTypeNode(type.typeNode);
|
|
817
|
+
case 1 /* PseudoTypeKind.Inferred */: {
|
|
818
|
+
const inferred = type;
|
|
819
|
+
// A body without returned values is `void`, as the checker infers.
|
|
820
|
+
if (inferred.isSignatureReturn && inferred.errorNodes.length === 0 && isTriviallyVoid(inferred.expression)) {
|
|
821
|
+
this.reportFallback(type, false);
|
|
822
|
+
return this.keyword(115 /* SyntaxKind.VoidKeyword */);
|
|
823
|
+
}
|
|
824
|
+
this.reportFallback(type, true);
|
|
825
|
+
return undefined;
|
|
826
|
+
}
|
|
827
|
+
case 2 /* PseudoTypeKind.NoResult */:
|
|
828
|
+
this.reportFallback(type, true);
|
|
829
|
+
return undefined;
|
|
830
|
+
case 3 /* PseudoTypeKind.MaybeConstLocation */: {
|
|
831
|
+
const maybe = type;
|
|
832
|
+
return this.write(isInConstContext(maybe.node) ? maybe.constType : maybe.regularType);
|
|
833
|
+
}
|
|
834
|
+
case 4 /* PseudoTypeKind.Union */:
|
|
835
|
+
if (type instanceof UnionType) {
|
|
836
|
+
const narrowed = type;
|
|
837
|
+
return this.writeUnion(narrowed);
|
|
838
|
+
}
|
|
839
|
+
break;
|
|
840
|
+
case 5 /* PseudoTypeKind.Undefined */:
|
|
841
|
+
return this.keyword(this.resolver.strictNullChecks ? 157 /* SyntaxKind.UndefinedKeyword */ : 132 /* SyntaxKind.AnyKeyword */);
|
|
842
|
+
case 6 /* PseudoTypeKind.Null */:
|
|
843
|
+
if (!this.resolver.strictNullChecks)
|
|
844
|
+
return this.keyword(132 /* SyntaxKind.AnyKeyword */);
|
|
845
|
+
return factory.created(new LiteralTypeNode(factory.createKeywordExpression(105 /* SyntaxKind.NullKeyword */)));
|
|
846
|
+
case 7 /* PseudoTypeKind.Any */:
|
|
847
|
+
return this.keyword(132 /* SyntaxKind.AnyKeyword */);
|
|
848
|
+
case 8 /* PseudoTypeKind.String */:
|
|
849
|
+
return this.keyword(154 /* SyntaxKind.StringKeyword */);
|
|
850
|
+
case 9 /* PseudoTypeKind.Number */:
|
|
851
|
+
return this.keyword(150 /* SyntaxKind.NumberKeyword */);
|
|
852
|
+
case 10 /* PseudoTypeKind.BigInt */:
|
|
853
|
+
return this.keyword(163 /* SyntaxKind.BigIntKeyword */);
|
|
854
|
+
case 11 /* PseudoTypeKind.Boolean */:
|
|
855
|
+
return this.keyword(135 /* SyntaxKind.BooleanKeyword */);
|
|
856
|
+
case 12 /* PseudoTypeKind.False */:
|
|
857
|
+
return factory.created(new LiteralTypeNode(factory.createKeywordExpression(96 /* SyntaxKind.FalseKeyword */)));
|
|
858
|
+
case 13 /* PseudoTypeKind.True */:
|
|
859
|
+
return factory.created(new LiteralTypeNode(factory.createKeywordExpression(111 /* SyntaxKind.TrueKeyword */)));
|
|
860
|
+
case 14 /* PseudoTypeKind.SingleCallSignature */:
|
|
861
|
+
if (type instanceof SignatureType) {
|
|
862
|
+
const narrowed = type;
|
|
863
|
+
return this.writeSignature(narrowed);
|
|
864
|
+
}
|
|
865
|
+
break;
|
|
866
|
+
case 15 /* PseudoTypeKind.Tuple */:
|
|
867
|
+
if (type instanceof TupleType) {
|
|
868
|
+
const narrowed = type;
|
|
869
|
+
return this.writeTuple(narrowed);
|
|
870
|
+
}
|
|
871
|
+
break;
|
|
872
|
+
case 16 /* PseudoTypeKind.ObjectLiteral */:
|
|
873
|
+
if (type instanceof ObjectLiteralType) {
|
|
874
|
+
const narrowed = type;
|
|
875
|
+
return this.writeObjectLiteral(narrowed);
|
|
876
|
+
}
|
|
877
|
+
break;
|
|
878
|
+
case 17 /* PseudoTypeKind.StringLiteral */:
|
|
879
|
+
case 18 /* PseudoTypeKind.NumericLiteral */:
|
|
880
|
+
case 19 /* PseudoTypeKind.BigIntLiteral */:
|
|
881
|
+
return factory.created(new LiteralTypeNode(this.reuseNode(type.node)));
|
|
882
|
+
}
|
|
883
|
+
return undefined;
|
|
884
|
+
}
|
|
885
|
+
keyword(kind) {
|
|
886
|
+
return this.context.factory.created(new KeywordTypeNode(kind));
|
|
887
|
+
}
|
|
888
|
+
writeUnion(type) {
|
|
889
|
+
const result = [];
|
|
890
|
+
let hasElided = false;
|
|
891
|
+
let failed = false;
|
|
892
|
+
for (const member of type.types) {
|
|
893
|
+
if (!this.resolver.strictNullChecks &&
|
|
894
|
+
(member.kind === 5 /* PseudoTypeKind.Undefined */ || member.kind === 6 /* PseudoTypeKind.Null */)) {
|
|
895
|
+
hasElided = true;
|
|
896
|
+
continue;
|
|
897
|
+
}
|
|
898
|
+
const node = this.write(member);
|
|
899
|
+
if (node === undefined)
|
|
900
|
+
failed = true;
|
|
901
|
+
else
|
|
902
|
+
appendUnionMember(result, node);
|
|
903
|
+
}
|
|
904
|
+
if (failed)
|
|
905
|
+
return undefined;
|
|
906
|
+
if (result.length === 1)
|
|
907
|
+
return result[0];
|
|
908
|
+
if (result.length === 0)
|
|
909
|
+
return this.keyword(hasElided ? 132 /* SyntaxKind.AnyKeyword */ : 146 /* SyntaxKind.NeverKeyword */);
|
|
910
|
+
return this.context.factory.created(new UnionTypeNode(this.context.factory.createNodeList(result)));
|
|
911
|
+
}
|
|
912
|
+
writeSignature(type) {
|
|
913
|
+
const factory = this.context.factory;
|
|
914
|
+
const typeParameters = [];
|
|
915
|
+
for (const parameter of type.typeParameters)
|
|
916
|
+
typeParameters.push(this.reuseNode(parameter));
|
|
917
|
+
const parameters = this.writeParameters(type.parameters);
|
|
918
|
+
const returnType = this.write(type.returnType);
|
|
919
|
+
if (parameters === undefined || returnType === undefined)
|
|
920
|
+
return undefined;
|
|
921
|
+
return factory.created(new FunctionTypeNode(typeParameters.length > 0 ? factory.createNodeList(typeParameters) : undefined, parameters, returnType));
|
|
922
|
+
}
|
|
923
|
+
// Writers of composite types write every part, so each part needing inference is reported.
|
|
924
|
+
writeParameters(parameters) {
|
|
925
|
+
const result = [];
|
|
926
|
+
let failed = false;
|
|
927
|
+
for (const parameter of parameters) {
|
|
928
|
+
const node = this.writeParameter(parameter);
|
|
929
|
+
if (node === undefined)
|
|
930
|
+
failed = true;
|
|
931
|
+
else
|
|
932
|
+
result.push(node);
|
|
933
|
+
}
|
|
934
|
+
return failed ? undefined : this.context.factory.createNodeList(result);
|
|
935
|
+
}
|
|
936
|
+
writeParameter(parameter) {
|
|
937
|
+
const factory = this.context.factory;
|
|
938
|
+
const type = this.write(parameter.type);
|
|
939
|
+
if (type === undefined)
|
|
940
|
+
return undefined;
|
|
941
|
+
const result = factory.created(new ParameterDeclaration(undefined, parameter.rest ? factory.createToken(25 /* SyntaxKind.DotDotDotToken */) : undefined, this.cloneParameterName(parameter.name), parameter.optional ? factory.createToken(57 /* SyntaxKind.QuestionToken */) : undefined, type, undefined));
|
|
942
|
+
const original = parameter.name.parent;
|
|
943
|
+
if (original !== undefined && original.kind === 170 /* SyntaxKind.Parameter */)
|
|
944
|
+
this.context.assignCommentRange(result, original);
|
|
945
|
+
return result;
|
|
946
|
+
}
|
|
947
|
+
/** Parameter names are rewritten from scratch: identifiers as is, binding patterns without initializers. */
|
|
948
|
+
cloneParameterName(name) {
|
|
949
|
+
// Rewritten names have no source positions.
|
|
950
|
+
const clone = name.deepClone();
|
|
951
|
+
clearPositions(clone);
|
|
952
|
+
if (clone instanceof BindingPattern) {
|
|
953
|
+
stripBindingInitializers(clone);
|
|
954
|
+
this.context.setEmitFlags(clone, 1 /* EmitFlags.SingleLine */ | 131072 /* EmitFlags.NoAsciiEscaping */);
|
|
955
|
+
}
|
|
956
|
+
else
|
|
957
|
+
this.context.setEmitFlags(clone, 131072 /* EmitFlags.NoAsciiEscaping */);
|
|
958
|
+
return clone;
|
|
959
|
+
}
|
|
960
|
+
writeTuple(type) {
|
|
961
|
+
const factory = this.context.factory;
|
|
962
|
+
const elements = [];
|
|
963
|
+
let failed = false;
|
|
964
|
+
for (const element of type.elements) {
|
|
965
|
+
const node = this.write(element);
|
|
966
|
+
if (node === undefined)
|
|
967
|
+
failed = true;
|
|
968
|
+
else
|
|
969
|
+
elements.push(node);
|
|
970
|
+
}
|
|
971
|
+
if (failed)
|
|
972
|
+
return undefined;
|
|
973
|
+
const tuple = factory.created(new TupleTypeNode(factory.createNodeList(elements)));
|
|
974
|
+
this.context.addEmitFlags(tuple, 1 /* EmitFlags.SingleLine */);
|
|
975
|
+
// `as const` arrays are readonly.
|
|
976
|
+
return factory.created(new TypeOperatorNode(148 /* SyntaxKind.ReadonlyKeyword */, tuple));
|
|
977
|
+
}
|
|
978
|
+
writeObjectLiteral(type) {
|
|
979
|
+
const factory = this.context.factory;
|
|
980
|
+
const members = type.members;
|
|
981
|
+
if (members.length === 0) {
|
|
982
|
+
const empty = factory.created(new TypeLiteralNode(factory.createNodeList([])));
|
|
983
|
+
this.context.addEmitFlags(empty, 1 /* EmitFlags.SingleLine */);
|
|
984
|
+
return empty;
|
|
985
|
+
}
|
|
986
|
+
const isConst = isInConstContext(members[0].name.parent.parent);
|
|
987
|
+
const result = [];
|
|
988
|
+
let failed = false;
|
|
989
|
+
for (const member of members) {
|
|
990
|
+
const modifiers = isConst || (member.kind === 1 /* PseudoMemberKind.Property */ && member.readonly)
|
|
991
|
+
? factory.createModifierList([factory.createToken(148 /* SyntaxKind.ReadonlyKeyword */)])
|
|
992
|
+
: undefined;
|
|
993
|
+
let node = undefined;
|
|
994
|
+
switch (member.kind) {
|
|
995
|
+
case 0 /* PseudoMemberKind.Method */: {
|
|
996
|
+
const typeParameters = [];
|
|
997
|
+
for (const parameter of member.typeParameters)
|
|
998
|
+
typeParameters.push(this.reuseNode(parameter));
|
|
999
|
+
const typeParameterList = typeParameters.length > 0 ? factory.createNodeList(typeParameters) : undefined;
|
|
1000
|
+
const parameters = this.writeParameters(member.parameters);
|
|
1001
|
+
const returnType = this.write(member.type);
|
|
1002
|
+
if (parameters === undefined || returnType === undefined)
|
|
1003
|
+
break;
|
|
1004
|
+
node = isConst
|
|
1005
|
+
? factory.created(new PropertySignatureDeclaration(modifiers, this.reuseName(member.name, false), undefined, factory.created(new FunctionTypeNode(typeParameterList, parameters, returnType)), undefined))
|
|
1006
|
+
: factory.created(new MethodSignatureDeclaration(modifiers, this.reuseName(member.name, true), undefined, typeParameterList, parameters, returnType));
|
|
1007
|
+
break;
|
|
1008
|
+
}
|
|
1009
|
+
case 1 /* PseudoMemberKind.Property */: {
|
|
1010
|
+
const propertyType = this.write(member.type);
|
|
1011
|
+
if (propertyType === undefined)
|
|
1012
|
+
break;
|
|
1013
|
+
node = factory.created(new PropertySignatureDeclaration(modifiers, this.reuseName(member.name, false), undefined, propertyType, undefined));
|
|
1014
|
+
break;
|
|
1015
|
+
}
|
|
1016
|
+
case 2 /* PseudoMemberKind.SetAccessor */: {
|
|
1017
|
+
const parameters = this.writeParameters(member.parameters);
|
|
1018
|
+
if (parameters === undefined)
|
|
1019
|
+
break;
|
|
1020
|
+
node = factory.created(new SetAccessorDeclaration(undefined, this.reuseName(member.name, false), undefined, parameters, undefined, undefined, undefined));
|
|
1021
|
+
break;
|
|
1022
|
+
}
|
|
1023
|
+
case 3 /* PseudoMemberKind.GetAccessor */: {
|
|
1024
|
+
const accessorType = this.write(member.type);
|
|
1025
|
+
if (accessorType === undefined)
|
|
1026
|
+
break;
|
|
1027
|
+
node = factory.created(new GetAccessorDeclaration(undefined, this.reuseName(member.name, false), undefined, factory.createNodeList([]), accessorType, undefined, undefined));
|
|
1028
|
+
break;
|
|
1029
|
+
}
|
|
1030
|
+
}
|
|
1031
|
+
if (node === undefined) {
|
|
1032
|
+
failed = true;
|
|
1033
|
+
continue;
|
|
1034
|
+
}
|
|
1035
|
+
const declaration = member.name.parent;
|
|
1036
|
+
this.context.setCommentRange(node, declaration.pos, declaration.end);
|
|
1037
|
+
result.push(node);
|
|
1038
|
+
}
|
|
1039
|
+
if (failed)
|
|
1040
|
+
return undefined;
|
|
1041
|
+
const literal = factory.created(new TypeLiteralNode(factory.createNodeList(result)));
|
|
1042
|
+
if ((this.flags & 1024 /* NodeBuilderFlags.MultilineObjectLiterals */) === 0)
|
|
1043
|
+
this.context.addEmitFlags(literal, 1 /* EmitFlags.SingleLine */);
|
|
1044
|
+
return literal;
|
|
1045
|
+
}
|
|
1046
|
+
/** A property name, as an identifier when it can be one. */
|
|
1047
|
+
reuseName(name, isMethod) {
|
|
1048
|
+
const result = this.reuseNode(name);
|
|
1049
|
+
const text = tryGetTextOfPropertyName(result);
|
|
1050
|
+
if (text === undefined)
|
|
1051
|
+
return result;
|
|
1052
|
+
const kind = classifyPropertyName(text, result.kind === 10 /* SyntaxKind.StringLiteral */, isMethod);
|
|
1053
|
+
if (result.kind === 79 /* SyntaxKind.Identifier */ && kind === 0 /* PropertyNameKind.Identifier */)
|
|
1054
|
+
return result;
|
|
1055
|
+
if (result.kind === 10 /* SyntaxKind.StringLiteral */ && kind === 2 /* PropertyNameKind.StringLiteral */)
|
|
1056
|
+
return result;
|
|
1057
|
+
let renamed;
|
|
1058
|
+
if (kind === 0 /* PropertyNameKind.Identifier */)
|
|
1059
|
+
renamed = this.context.factory.createIdentifier(text);
|
|
1060
|
+
else if (kind === 2 /* PropertyNameKind.StringLiteral */)
|
|
1061
|
+
renamed = this.context.factory.createStringLiteral(text, 0 /* TokenFlags.None */);
|
|
1062
|
+
else
|
|
1063
|
+
return result;
|
|
1064
|
+
this.context.setOriginal(renamed, result);
|
|
1065
|
+
renamed.pos = result.pos;
|
|
1066
|
+
renamed.end = result.end;
|
|
1067
|
+
return renamed;
|
|
1068
|
+
}
|
|
1069
|
+
/** A copy of an expression or type parameter from the source. */
|
|
1070
|
+
reuseNode(node) {
|
|
1071
|
+
this.trackEntityNames(node);
|
|
1072
|
+
const clone = node.deepClone();
|
|
1073
|
+
styleReusedNodes(this.context, clone);
|
|
1074
|
+
return clone;
|
|
1075
|
+
}
|
|
1076
|
+
/** A copy of an annotation, with the names it uses checked and their imports kept; undefined if one can't be named. */
|
|
1077
|
+
reuseTypeNode(node) {
|
|
1078
|
+
const failed = this.reuseFailed;
|
|
1079
|
+
this.reuseFailed = false;
|
|
1080
|
+
const result = this.reuseNode(node);
|
|
1081
|
+
const reused = !this.reuseFailed;
|
|
1082
|
+
this.reuseFailed = failed || !reused;
|
|
1083
|
+
if (reused)
|
|
1084
|
+
return result;
|
|
1085
|
+
// The checker writes the type the annotation denotes instead.
|
|
1086
|
+
this.tracker.reportInferenceFallback(node);
|
|
1087
|
+
this.resolver.countFallback(node, true);
|
|
1088
|
+
return undefined;
|
|
1089
|
+
}
|
|
1090
|
+
trackEntityNames(node) {
|
|
1091
|
+
this.markJSDocType(node);
|
|
1092
|
+
node.forEachChild(new EntityNameTracker(this));
|
|
1093
|
+
return this.trackEntityName(node);
|
|
1094
|
+
}
|
|
1095
|
+
/** JSDoc types such as `?T` can't be reused as written. */
|
|
1096
|
+
markJSDocType(node) {
|
|
1097
|
+
if (node.kind >= 308 /* SyntaxKind.FirstJSDocNode */ && node.kind <= 343 /* SyntaxKind.LastJSDocNode */)
|
|
1098
|
+
this.reuseFailed = true;
|
|
1099
|
+
return true;
|
|
1100
|
+
}
|
|
1101
|
+
trackEntityName(node) {
|
|
1102
|
+
let name = undefined;
|
|
1103
|
+
if (node instanceof TypeReferenceNode)
|
|
1104
|
+
name = node.typeName;
|
|
1105
|
+
else if (node instanceof TypeQueryNode)
|
|
1106
|
+
name = node.exprName;
|
|
1107
|
+
else if (node.kind === 234 /* SyntaxKind.ExpressionWithTypeArguments */)
|
|
1108
|
+
name = node.expression;
|
|
1109
|
+
if (name === undefined || !(isEntityNameExpression(name, false) || name instanceof QualifiedName))
|
|
1110
|
+
return false;
|
|
1111
|
+
const first = getFirstIdentifier(name);
|
|
1112
|
+
if (!(first instanceof Identifier))
|
|
1113
|
+
return false;
|
|
1114
|
+
const meaning = getMeaningOfEntityNameReference(name);
|
|
1115
|
+
const symbol = this.resolver.resolveName(first, first.text, meaning);
|
|
1116
|
+
if (symbol === undefined || isSignatureLocal(symbol))
|
|
1117
|
+
return false;
|
|
1118
|
+
// `typeof x` in the declaration of `x` is circular.
|
|
1119
|
+
const declaration = symbol.valueDeclaration;
|
|
1120
|
+
if (node instanceof TypeQueryNode &&
|
|
1121
|
+
declaration !== undefined &&
|
|
1122
|
+
declaration.pos <= node.pos &&
|
|
1123
|
+
node.end <= declaration.end &&
|
|
1124
|
+
getSourceFileOfNode(declaration) === getSourceFileOfNode(node)) {
|
|
1125
|
+
this.reuseFailed = true;
|
|
1126
|
+
return false;
|
|
1127
|
+
}
|
|
1128
|
+
const result = this.resolver.isSymbolAccessible(symbol, this.enclosingDeclaration, meaning, false);
|
|
1129
|
+
if (result.accessibility !== 0 /* SymbolAccessibility.Accessible */) {
|
|
1130
|
+
this.reuseFailed = true;
|
|
1131
|
+
return false;
|
|
1132
|
+
}
|
|
1133
|
+
return this.tracker.trackSymbol(symbol, this.enclosingDeclaration, meaning);
|
|
1134
|
+
}
|
|
1135
|
+
}
|
|
1136
|
+
/** Parameters and type parameters are in scope where the signature's types are written. */
|
|
1137
|
+
function isSignatureLocal(symbol) {
|
|
1138
|
+
const declaration = symbol.valueDeclaration ?? (symbol.declarations.length > 0 ? symbol.declarations[0] : undefined);
|
|
1139
|
+
return (declaration !== undefined &&
|
|
1140
|
+
(declaration.kind === 170 /* SyntaxKind.Parameter */ || declaration.kind === 169 /* SyntaxKind.TypeParameter */));
|
|
1141
|
+
}
|
|
1142
|
+
class EntityNameTracker extends NodeVisitor {
|
|
1143
|
+
writer;
|
|
1144
|
+
constructor(writer) {
|
|
1145
|
+
super();
|
|
1146
|
+
this.writer = writer;
|
|
1147
|
+
}
|
|
1148
|
+
visitNode(node) {
|
|
1149
|
+
this.writer.markJSDocType(node);
|
|
1150
|
+
this.writer.trackEntityName(node);
|
|
1151
|
+
return node.forEachChild(this);
|
|
1152
|
+
}
|
|
1153
|
+
}
|
|
1154
|
+
/** Single-line tuples and mapped types, and string literals without escapes, as tsgo's node reuse. */
|
|
1155
|
+
function styleReusedNodes(context, node) {
|
|
1156
|
+
const kind = node.kind;
|
|
1157
|
+
if (kind === 190 /* SyntaxKind.TupleType */ || kind === 201 /* SyntaxKind.MappedType */)
|
|
1158
|
+
context.addEmitFlags(node, 1 /* EmitFlags.SingleLine */);
|
|
1159
|
+
else if (kind === 10 /* SyntaxKind.StringLiteral */ || kind === 14 /* SyntaxKind.NoSubstitutionTemplateLiteral */)
|
|
1160
|
+
context.addEmitFlags(node, 131072 /* EmitFlags.NoAsciiEscaping */);
|
|
1161
|
+
node.forEachChild(new ReusedNodeStyler(context));
|
|
1162
|
+
return true;
|
|
1163
|
+
}
|
|
1164
|
+
class ReusedNodeStyler extends NodeVisitor {
|
|
1165
|
+
context;
|
|
1166
|
+
constructor(context) {
|
|
1167
|
+
super();
|
|
1168
|
+
this.context = context;
|
|
1169
|
+
}
|
|
1170
|
+
visitNode(node) {
|
|
1171
|
+
styleReusedNodes(this.context, node);
|
|
1172
|
+
return false;
|
|
1173
|
+
}
|
|
1174
|
+
}
|
|
1175
|
+
function clearPositions(node) {
|
|
1176
|
+
node.pos = -1;
|
|
1177
|
+
node.end = -1;
|
|
1178
|
+
node.forEachChild(new PositionClearer());
|
|
1179
|
+
return true;
|
|
1180
|
+
}
|
|
1181
|
+
class PositionClearer extends NodeVisitor {
|
|
1182
|
+
visitNode(node) {
|
|
1183
|
+
clearPositions(node);
|
|
1184
|
+
return false;
|
|
1185
|
+
}
|
|
1186
|
+
}
|
|
1187
|
+
function stripBindingInitializers(pattern) {
|
|
1188
|
+
for (const element of pattern.elements.nodes) {
|
|
1189
|
+
if (!(element instanceof BindingElement))
|
|
1190
|
+
continue;
|
|
1191
|
+
element.initializer = undefined;
|
|
1192
|
+
if (element.name instanceof BindingPattern)
|
|
1193
|
+
stripBindingInitializers(element.name);
|
|
1194
|
+
}
|
|
1195
|
+
return true;
|
|
1196
|
+
}
|
|
1197
|
+
function appendUnionMember(result, node) {
|
|
1198
|
+
if (node instanceof UnionTypeNode) {
|
|
1199
|
+
for (const member of node.types.nodes)
|
|
1200
|
+
appendUnionMember(result, member);
|
|
1201
|
+
return true;
|
|
1202
|
+
}
|
|
1203
|
+
if (node.kind === 157 /* SyntaxKind.UndefinedKeyword */)
|
|
1204
|
+
for (const existing of result)
|
|
1205
|
+
if (existing.kind === 157 /* SyntaxKind.UndefinedKeyword */)
|
|
1206
|
+
return false;
|
|
1207
|
+
result.push(node);
|
|
1208
|
+
return true;
|
|
1209
|
+
}
|
|
1210
|
+
function classifyPropertyName(name, stringNamed, isMethod) {
|
|
1211
|
+
if (isMethod && name === 'new')
|
|
1212
|
+
return 2 /* PropertyNameKind.StringLiteral */;
|
|
1213
|
+
if (isIdentifierText(name))
|
|
1214
|
+
return 0 /* PropertyNameKind.Identifier */;
|
|
1215
|
+
return !stringNamed && String(Number(name)) === name && Number(name) >= 0
|
|
1216
|
+
? 1 /* PropertyNameKind.NumericLiteral */
|
|
1217
|
+
: 2 /* PropertyNameKind.StringLiteral */;
|
|
1218
|
+
}
|
|
1219
|
+
export function tryGetTextOfPropertyName(name) {
|
|
1220
|
+
switch (name.kind) {
|
|
1221
|
+
case 79 /* SyntaxKind.Identifier */:
|
|
1222
|
+
case 80 /* SyntaxKind.PrivateIdentifier */:
|
|
1223
|
+
case 10 /* SyntaxKind.StringLiteral */:
|
|
1224
|
+
case 8 /* SyntaxKind.NumericLiteral */:
|
|
1225
|
+
case 14 /* SyntaxKind.NoSubstitutionTemplateLiteral */:
|
|
1226
|
+
return literalText(name);
|
|
1227
|
+
case 168 /* SyntaxKind.ComputedPropertyName */: {
|
|
1228
|
+
const expression = name.expression;
|
|
1229
|
+
return isStringOrNumericLiteralLike(expression) ? literalText(expression) : undefined;
|
|
1230
|
+
}
|
|
1231
|
+
}
|
|
1232
|
+
return undefined;
|
|
1233
|
+
}
|
|
1234
|
+
/** Whether a declaration's type is a literal or `unique symbol`: a computed name it names is late-bound. */
|
|
1235
|
+
function hasLiteralOrUniqueSymbolType(declaration) {
|
|
1236
|
+
if (declaration.kind === 306 /* SyntaxKind.EnumMember */)
|
|
1237
|
+
return true;
|
|
1238
|
+
const type = getType(declaration);
|
|
1239
|
+
if (type !== undefined)
|
|
1240
|
+
return ((type instanceof TypeOperatorNode && type.operator === 158 /* SyntaxKind.UniqueKeyword */) ||
|
|
1241
|
+
type.kind === 202 /* SyntaxKind.LiteralType */);
|
|
1242
|
+
const initializer = getInitializer(declaration);
|
|
1243
|
+
if (initializer === undefined)
|
|
1244
|
+
return false;
|
|
1245
|
+
const value = skipParentheses(initializer);
|
|
1246
|
+
// `x as const` has a literal type wherever it is.
|
|
1247
|
+
if (value instanceof AsExpression && isConstTypeReference(value.type))
|
|
1248
|
+
return isStringOrNumericLiteralLike(skipParentheses(value.expression));
|
|
1249
|
+
if (declaration instanceof VariableDeclaration) {
|
|
1250
|
+
if ((getCombinedNodeFlags(declaration) & 2 /* NodeFlags.Const */) === 0)
|
|
1251
|
+
return false;
|
|
1252
|
+
// `const sym = Symbol()` is a unique symbol.
|
|
1253
|
+
if (value.kind === 214 /* SyntaxKind.CallExpression */ && isIdentifierNamed(getExpression(value), 'Symbol'))
|
|
1254
|
+
return true;
|
|
1255
|
+
return isStringOrNumericLiteralLike(value);
|
|
1256
|
+
}
|
|
1257
|
+
if (declaration.kind === 173 /* SyntaxKind.PropertyDeclaration */)
|
|
1258
|
+
return hasSyntacticModifier(declaration, 8 /* ModifierFlags.Readonly */) && isStringOrNumericLiteralLike(value);
|
|
1259
|
+
if (declaration.kind === 303 /* SyntaxKind.PropertyAssignment */)
|
|
1260
|
+
return isInConstContext(value) && isStringOrNumericLiteralLike(value);
|
|
1261
|
+
return false;
|
|
1262
|
+
}
|
|
1263
|
+
/** The properties of an object literal, through `as const`. */
|
|
1264
|
+
function objectLiteralProperties(node) {
|
|
1265
|
+
let current = skipParentheses(node);
|
|
1266
|
+
if (current instanceof AsExpression && isConstTypeReference(current.type))
|
|
1267
|
+
current = skipParentheses(current.expression);
|
|
1268
|
+
return current instanceof ObjectLiteralExpression ? current.properties.nodes : [];
|
|
1269
|
+
}
|
|
1270
|
+
/** Whether a function's body returns no values, so its inferred return type is `void`. */
|
|
1271
|
+
function isTriviallyVoid(fn) {
|
|
1272
|
+
const body = getBody(fn);
|
|
1273
|
+
if (body === undefined || body.kind !== 242 /* SyntaxKind.Block */)
|
|
1274
|
+
return false;
|
|
1275
|
+
if (hasSyntacticModifier(fn, 1024 /* ModifierFlags.Async */) || getAsteriskToken(fn) !== undefined)
|
|
1276
|
+
return false;
|
|
1277
|
+
for (const statement of collectReturnStatements(body))
|
|
1278
|
+
if (statement.expression !== undefined)
|
|
1279
|
+
return false;
|
|
1280
|
+
switch (fn.kind) {
|
|
1281
|
+
case 263 /* SyntaxKind.FunctionDeclaration */:
|
|
1282
|
+
case 175 /* SyntaxKind.MethodDeclaration */:
|
|
1283
|
+
return true;
|
|
1284
|
+
case 219 /* SyntaxKind.FunctionExpression */:
|
|
1285
|
+
case 220 /* SyntaxKind.ArrowFunction */:
|
|
1286
|
+
// Without an implicit return, function expressions return `never`.
|
|
1287
|
+
return (fn.flags & 256 /* NodeFlags.HasImplicitReturn */) !== 0;
|
|
1288
|
+
}
|
|
1289
|
+
return false;
|
|
1290
|
+
}
|
|
1291
|
+
function createNumberExpression(context, value) {
|
|
1292
|
+
const factory = context.factory;
|
|
1293
|
+
if (value !== value)
|
|
1294
|
+
return factory.createIdentifier('NaN');
|
|
1295
|
+
if (value === Infinity)
|
|
1296
|
+
return factory.createIdentifier('Infinity');
|
|
1297
|
+
if (value === -Infinity)
|
|
1298
|
+
return factory.created(new PrefixUnaryExpression(40 /* SyntaxKind.MinusToken */, factory.createIdentifier('Infinity')));
|
|
1299
|
+
if (value < 0)
|
|
1300
|
+
return factory.created(new PrefixUnaryExpression(40 /* SyntaxKind.MinusToken */, factory.createNumericLiteral(String(-value))));
|
|
1301
|
+
return factory.createNumericLiteral(String(value));
|
|
1302
|
+
}
|
|
1303
|
+
/** The literal a const declaration's initializer is, if it has a literal type. */
|
|
1304
|
+
function literalOf(node) {
|
|
1305
|
+
switch (node.kind) {
|
|
1306
|
+
case 111 /* SyntaxKind.TrueKeyword */:
|
|
1307
|
+
case 96 /* SyntaxKind.FalseKeyword */:
|
|
1308
|
+
case 8 /* SyntaxKind.NumericLiteral */:
|
|
1309
|
+
case 10 /* SyntaxKind.StringLiteral */:
|
|
1310
|
+
case 14 /* SyntaxKind.NoSubstitutionTemplateLiteral */:
|
|
1311
|
+
case 9 /* SyntaxKind.BigIntLiteral */:
|
|
1312
|
+
return node;
|
|
1313
|
+
case 225 /* SyntaxKind.PrefixUnaryExpression */: {
|
|
1314
|
+
const unary = node;
|
|
1315
|
+
const operand = unary.operand.kind;
|
|
1316
|
+
if (unary.operator === 40 /* SyntaxKind.MinusToken */ &&
|
|
1317
|
+
(operand === 8 /* SyntaxKind.NumericLiteral */ || operand === 9 /* SyntaxKind.BigIntLiteral */))
|
|
1318
|
+
return node;
|
|
1319
|
+
if (unary.operator === 39 /* SyntaxKind.PlusToken */ && operand === 8 /* SyntaxKind.NumericLiteral */)
|
|
1320
|
+
return node;
|
|
1321
|
+
return undefined;
|
|
1322
|
+
}
|
|
1323
|
+
}
|
|
1324
|
+
return undefined;
|
|
1325
|
+
}
|
|
1326
|
+
function literalText(node) {
|
|
1327
|
+
if (node instanceof Identifier)
|
|
1328
|
+
return node.text;
|
|
1329
|
+
if (node instanceof PrivateIdentifier)
|
|
1330
|
+
return node.text;
|
|
1331
|
+
if (node instanceof StringLiteral)
|
|
1332
|
+
return node.text;
|
|
1333
|
+
if (node instanceof NumericLiteral)
|
|
1334
|
+
return node.text;
|
|
1335
|
+
if (node instanceof NoSubstitutionTemplateLiteral)
|
|
1336
|
+
return node.text;
|
|
1337
|
+
if (node instanceof BigIntLiteral)
|
|
1338
|
+
return node.text;
|
|
1339
|
+
if (node instanceof TemplateMiddle)
|
|
1340
|
+
return node.text;
|
|
1341
|
+
if (node instanceof TemplateTail)
|
|
1342
|
+
return node.text;
|
|
1343
|
+
return '';
|
|
1344
|
+
}
|
|
1345
|
+
function getIdentifierText(node) {
|
|
1346
|
+
return node instanceof Identifier ? node.text : '';
|
|
1347
|
+
}
|
|
1348
|
+
function getFirstIdentifier(node) {
|
|
1349
|
+
let current = node;
|
|
1350
|
+
for (;;) {
|
|
1351
|
+
if (current instanceof QualifiedName)
|
|
1352
|
+
current = current.left;
|
|
1353
|
+
else if (current instanceof PropertyAccessExpression)
|
|
1354
|
+
current = current.expression;
|
|
1355
|
+
else
|
|
1356
|
+
return current;
|
|
1357
|
+
}
|
|
1358
|
+
}
|
|
1359
|
+
/** What a reference to an entity name means: a value, a namespace or a type. */
|
|
1360
|
+
export function getMeaningOfEntityNameReference(entityName) {
|
|
1361
|
+
const parent = entityName.parent;
|
|
1362
|
+
if (parent.kind === 187 /* SyntaxKind.TypeQuery */ ||
|
|
1363
|
+
(parent.kind === 234 /* SyntaxKind.ExpressionWithTypeArguments */ && !isPartOfTypeNode(parent)) ||
|
|
1364
|
+
parent.kind === 168 /* SyntaxKind.ComputedPropertyName */ ||
|
|
1365
|
+
(parent.kind === 183 /* SyntaxKind.TypePredicate */ && getTypePredicateParameterName(parent) === entityName) ||
|
|
1366
|
+
parent.kind === 227 /* SyntaxKind.BinaryExpression */)
|
|
1367
|
+
return 111551 /* SymbolFlags.Value */ | 1048576 /* SymbolFlags.ExportValue */;
|
|
1368
|
+
if (entityName.kind === 167 /* SyntaxKind.QualifiedName */ ||
|
|
1369
|
+
entityName.kind === 212 /* SyntaxKind.PropertyAccessExpression */ ||
|
|
1370
|
+
parent.kind === 272 /* SyntaxKind.ImportEqualsDeclaration */ ||
|
|
1371
|
+
(parent instanceof QualifiedName && parent.left === entityName) ||
|
|
1372
|
+
(parent instanceof PropertyAccessExpression && parent.expression === entityName) ||
|
|
1373
|
+
(parent instanceof ElementAccessExpression && parent.expression === entityName))
|
|
1374
|
+
return 1920 /* SymbolFlags.Namespace */;
|
|
1375
|
+
return 788968 /* SymbolFlags.Type */;
|
|
1376
|
+
}
|
|
1377
|
+
function getTypePredicateParameterName(node) {
|
|
1378
|
+
return node instanceof TypePredicateNode ? node.parameterName : undefined;
|
|
1379
|
+
}
|
|
1380
|
+
/** Whether a heritage clause element is a type: an interface's `extends` or a class's `implements`. */
|
|
1381
|
+
function isPartOfTypeNode(node) {
|
|
1382
|
+
const parent = node.parent;
|
|
1383
|
+
if (parent === undefined)
|
|
1384
|
+
return false;
|
|
1385
|
+
if (parent instanceof HeritageClause)
|
|
1386
|
+
return (!(parent.parent.kind === 264 /* SyntaxKind.ClassDeclaration */ || parent.parent.kind === 232 /* SyntaxKind.ClassExpression */) ||
|
|
1387
|
+
parent.token === 118 /* SyntaxKind.ImplementsKeyword */);
|
|
1388
|
+
return (parent !== undefined &&
|
|
1389
|
+
(parent.kind === 324 /* SyntaxKind.JSDocImplementsTag */ || parent.kind === 323 /* SyntaxKind.JSDocAugmentsTag */));
|
|
1390
|
+
}
|
|
1391
|
+
function isDeclarationKind(kind) {
|
|
1392
|
+
switch (kind) {
|
|
1393
|
+
case 261 /* SyntaxKind.VariableDeclaration */:
|
|
1394
|
+
case 170 /* SyntaxKind.Parameter */:
|
|
1395
|
+
case 173 /* SyntaxKind.PropertyDeclaration */:
|
|
1396
|
+
case 172 /* SyntaxKind.PropertySignature */:
|
|
1397
|
+
case 303 /* SyntaxKind.PropertyAssignment */:
|
|
1398
|
+
case 304 /* SyntaxKind.ShorthandPropertyAssignment */:
|
|
1399
|
+
case 209 /* SyntaxKind.BindingElement */:
|
|
1400
|
+
case 278 /* SyntaxKind.ExportAssignment */:
|
|
1401
|
+
case 306 /* SyntaxKind.EnumMember */:
|
|
1402
|
+
return true;
|
|
1403
|
+
}
|
|
1404
|
+
return false;
|
|
1405
|
+
}
|
|
1406
|
+
export function getAnyImportSyntax(node) {
|
|
1407
|
+
switch (node.kind) {
|
|
1408
|
+
case 272 /* SyntaxKind.ImportEqualsDeclaration */:
|
|
1409
|
+
return node;
|
|
1410
|
+
case 274 /* SyntaxKind.ImportClause */:
|
|
1411
|
+
return node.parent;
|
|
1412
|
+
case 275 /* SyntaxKind.NamespaceImport */:
|
|
1413
|
+
return node.parent?.parent;
|
|
1414
|
+
case 277 /* SyntaxKind.ImportSpecifier */:
|
|
1415
|
+
return node.parent?.parent?.parent;
|
|
1416
|
+
}
|
|
1417
|
+
return undefined;
|
|
1418
|
+
}
|
|
1419
|
+
export function isLateVisibilityPaintedStatement(node) {
|
|
1420
|
+
switch (node.kind) {
|
|
1421
|
+
case 273 /* SyntaxKind.ImportDeclaration */:
|
|
1422
|
+
case 346 /* SyntaxKind.JSImportDeclaration */:
|
|
1423
|
+
case 272 /* SyntaxKind.ImportEqualsDeclaration */:
|
|
1424
|
+
case 244 /* SyntaxKind.VariableStatement */:
|
|
1425
|
+
case 264 /* SyntaxKind.ClassDeclaration */:
|
|
1426
|
+
case 263 /* SyntaxKind.FunctionDeclaration */:
|
|
1427
|
+
case 268 /* SyntaxKind.ModuleDeclaration */:
|
|
1428
|
+
case 266 /* SyntaxKind.TypeAliasDeclaration */:
|
|
1429
|
+
case 345 /* SyntaxKind.JSTypeAliasDeclaration */:
|
|
1430
|
+
case 265 /* SyntaxKind.InterfaceDeclaration */:
|
|
1431
|
+
case 267 /* SyntaxKind.EnumDeclaration */:
|
|
1432
|
+
return true;
|
|
1433
|
+
}
|
|
1434
|
+
return false;
|
|
1435
|
+
}
|
|
1436
|
+
/** The node whose scope holds a declaration: a source file, module block or other container. */
|
|
1437
|
+
export function getDeclarationContainer(node) {
|
|
1438
|
+
let current = getRootDeclaration(node);
|
|
1439
|
+
while (current !== undefined) {
|
|
1440
|
+
switch (current.kind) {
|
|
1441
|
+
case 261 /* SyntaxKind.VariableDeclaration */:
|
|
1442
|
+
case 262 /* SyntaxKind.VariableDeclarationList */:
|
|
1443
|
+
case 277 /* SyntaxKind.ImportSpecifier */:
|
|
1444
|
+
case 276 /* SyntaxKind.NamedImports */:
|
|
1445
|
+
case 275 /* SyntaxKind.NamespaceImport */:
|
|
1446
|
+
case 274 /* SyntaxKind.ImportClause */:
|
|
1447
|
+
current = current.parent;
|
|
1448
|
+
continue;
|
|
1449
|
+
}
|
|
1450
|
+
return current.parent;
|
|
1451
|
+
}
|
|
1452
|
+
throw new Error('A declaration has no container');
|
|
1453
|
+
}
|
|
1454
|
+
function getEnclosingContainer(node) {
|
|
1455
|
+
for (let current = node.parent; current !== undefined; current = current.parent)
|
|
1456
|
+
if ((getContainerFlags(current) & 1 /* ContainerFlags.IsContainer */) !== 0)
|
|
1457
|
+
return current;
|
|
1458
|
+
return undefined;
|
|
1459
|
+
}
|
|
1460
|
+
function isGlobalScopeAugmentation(node) {
|
|
1461
|
+
return node instanceof ModuleDeclaration && node.keyword === 162 /* SyntaxKind.GlobalKeyword */;
|
|
1462
|
+
}
|
|
1463
|
+
export function isExternalModuleAugmentation(node) {
|
|
1464
|
+
return isAmbientModule(node) && isModuleAugmentationExternal(node);
|
|
1465
|
+
}
|
|
1466
|
+
function isImplicitlyExportedJSDocDeclaration(node) {
|
|
1467
|
+
const parent = node.parent;
|
|
1468
|
+
if (parent === undefined || parent.kind !== 307 /* SyntaxKind.SourceFile */)
|
|
1469
|
+
return false;
|
|
1470
|
+
if (!isExternalOrCommonJSModule(parent))
|
|
1471
|
+
return false;
|
|
1472
|
+
if (node.kind === 345 /* SyntaxKind.JSTypeAliasDeclaration */)
|
|
1473
|
+
return true;
|
|
1474
|
+
return node.kind === 268 /* SyntaxKind.ModuleDeclaration */ && (node.flags & 8 /* NodeFlags.Reparsed */) !== 0;
|
|
1475
|
+
}
|
|
1476
|
+
/** Merges global symbol tables as the checker does; conflicting declarations stay apart. */
|
|
1477
|
+
function mergeInto(target, source, mergedSymbols) {
|
|
1478
|
+
for (const [name, symbol] of source) {
|
|
1479
|
+
const existing = target.get(name);
|
|
1480
|
+
if (existing === undefined) {
|
|
1481
|
+
target.set(name, symbol);
|
|
1482
|
+
continue;
|
|
1483
|
+
}
|
|
1484
|
+
if ((existing.flags & getExcludedSymbolFlags(symbol.flags)) !== 0 &&
|
|
1485
|
+
((existing.flags | symbol.flags) & 67108864 /* SymbolFlags.Assignment */) === 0)
|
|
1486
|
+
continue;
|
|
1487
|
+
let merged = existing;
|
|
1488
|
+
if (mergedSymbols.get(existing) !== existing) {
|
|
1489
|
+
// The first merge replaces the first file's symbol with a copy.
|
|
1490
|
+
merged = new Symbol(existing.flags, name);
|
|
1491
|
+
merged.declarations = existing.declarations.slice();
|
|
1492
|
+
merged.valueDeclaration = existing.valueDeclaration;
|
|
1493
|
+
merged.exports = copyTable(existing.exports);
|
|
1494
|
+
merged.members = copyTable(existing.members);
|
|
1495
|
+
mergedSymbols.set(existing, merged);
|
|
1496
|
+
mergedSymbols.set(merged, merged);
|
|
1497
|
+
target.set(name, merged);
|
|
1498
|
+
}
|
|
1499
|
+
merged.flags |= symbol.flags;
|
|
1500
|
+
for (const declaration of symbol.declarations)
|
|
1501
|
+
addDeclaration(merged, declaration);
|
|
1502
|
+
merged.valueDeclaration ??= symbol.valueDeclaration;
|
|
1503
|
+
if (symbol.exports !== undefined) {
|
|
1504
|
+
merged.exports ??= new Map();
|
|
1505
|
+
mergeInto(merged.exports, symbol.exports, mergedSymbols);
|
|
1506
|
+
}
|
|
1507
|
+
if (symbol.members !== undefined) {
|
|
1508
|
+
merged.members ??= new Map();
|
|
1509
|
+
mergeInto(merged.members, symbol.members, mergedSymbols);
|
|
1510
|
+
}
|
|
1511
|
+
mergedSymbols.set(symbol, merged);
|
|
1512
|
+
}
|
|
1513
|
+
return true;
|
|
1514
|
+
}
|
|
1515
|
+
function copyTable(table) {
|
|
1516
|
+
return table === undefined ? undefined : new Map(table);
|
|
1517
|
+
}
|
|
1518
|
+
/** The flags a declaration with `flags` conflicts with. */
|
|
1519
|
+
function getExcludedSymbolFlags(flags) {
|
|
1520
|
+
let result = 0 /* SymbolFlags.None */;
|
|
1521
|
+
if ((flags & 2 /* SymbolFlags.BlockScopedVariable */) !== 0)
|
|
1522
|
+
result |= 111551 /* SymbolFlags.BlockScopedVariableExcludes */;
|
|
1523
|
+
if ((flags & 1 /* SymbolFlags.FunctionScopedVariable */) !== 0)
|
|
1524
|
+
result |= 111550 /* SymbolFlags.FunctionScopedVariableExcludes */;
|
|
1525
|
+
if ((flags & 4 /* SymbolFlags.Property */) !== 0)
|
|
1526
|
+
result |= 13243 /* SymbolFlags.PropertyExcludes */;
|
|
1527
|
+
if ((flags & 8 /* SymbolFlags.EnumMember */) !== 0)
|
|
1528
|
+
result |= 900095 /* SymbolFlags.EnumMemberExcludes */;
|
|
1529
|
+
if ((flags & 16 /* SymbolFlags.Function */) !== 0)
|
|
1530
|
+
result |= 110991 /* SymbolFlags.FunctionExcludes */;
|
|
1531
|
+
if ((flags & 32 /* SymbolFlags.Class */) !== 0)
|
|
1532
|
+
result |= 899503 /* SymbolFlags.ClassExcludes */;
|
|
1533
|
+
if ((flags & 64 /* SymbolFlags.Interface */) !== 0)
|
|
1534
|
+
result |= 788872 /* SymbolFlags.InterfaceExcludes */;
|
|
1535
|
+
if ((flags & 256 /* SymbolFlags.RegularEnum */) !== 0)
|
|
1536
|
+
result |= 899327 /* SymbolFlags.RegularEnumExcludes */;
|
|
1537
|
+
if ((flags & 128 /* SymbolFlags.ConstEnum */) !== 0)
|
|
1538
|
+
result |= 899967 /* SymbolFlags.ConstEnumExcludes */;
|
|
1539
|
+
if ((flags & 512 /* SymbolFlags.ValueModule */) !== 0)
|
|
1540
|
+
result |= 110735 /* SymbolFlags.ValueModuleExcludes */;
|
|
1541
|
+
if ((flags & 8192 /* SymbolFlags.Method */) !== 0)
|
|
1542
|
+
result |= 103359 /* SymbolFlags.MethodExcludes */;
|
|
1543
|
+
if ((flags & 32768 /* SymbolFlags.GetAccessor */) !== 0)
|
|
1544
|
+
result |= 46011 /* SymbolFlags.GetAccessorExcludes */;
|
|
1545
|
+
if ((flags & 65536 /* SymbolFlags.SetAccessor */) !== 0)
|
|
1546
|
+
result |= 78779 /* SymbolFlags.SetAccessorExcludes */;
|
|
1547
|
+
if ((flags & 262144 /* SymbolFlags.TypeParameter */) !== 0)
|
|
1548
|
+
result |= 526824 /* SymbolFlags.TypeParameterExcludes */;
|
|
1549
|
+
if ((flags & 524288 /* SymbolFlags.TypeAlias */) !== 0)
|
|
1550
|
+
result |= 788968 /* SymbolFlags.TypeAliasExcludes */;
|
|
1551
|
+
if ((flags & 2097152 /* SymbolFlags.Alias */) !== 0)
|
|
1552
|
+
result |= 2097152 /* SymbolFlags.AliasExcludes */;
|
|
1553
|
+
return result;
|
|
1554
|
+
}
|
|
1555
|
+
class AliasMarker extends NodeVisitor {
|
|
1556
|
+
resolver;
|
|
1557
|
+
constructor(resolver) {
|
|
1558
|
+
super();
|
|
1559
|
+
this.resolver = resolver;
|
|
1560
|
+
}
|
|
1561
|
+
visitNode(node) {
|
|
1562
|
+
switch (node.kind) {
|
|
1563
|
+
case 278 /* SyntaxKind.ExportAssignment */: {
|
|
1564
|
+
const expression = getExpression(node);
|
|
1565
|
+
if (expression instanceof Identifier)
|
|
1566
|
+
this.resolver.markLinkedAliases(expression);
|
|
1567
|
+
return false;
|
|
1568
|
+
}
|
|
1569
|
+
case 282 /* SyntaxKind.ExportSpecifier */:
|
|
1570
|
+
if (node instanceof ExportSpecifier)
|
|
1571
|
+
this.resolver.markLinkedAliases(node.propertyName ?? node.name);
|
|
1572
|
+
return false;
|
|
1573
|
+
// Exports are statements of files and namespaces.
|
|
1574
|
+
case 268 /* SyntaxKind.ModuleDeclaration */:
|
|
1575
|
+
case 269 /* SyntaxKind.ModuleBlock */:
|
|
1576
|
+
case 279 /* SyntaxKind.ExportDeclaration */:
|
|
1577
|
+
case 280 /* SyntaxKind.NamedExports */:
|
|
1578
|
+
return node.forEachChild(this);
|
|
1579
|
+
}
|
|
1580
|
+
return false;
|
|
1581
|
+
}
|
|
1582
|
+
}
|