tsc-ts 0.0.4 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +34 -2
- package/dist/api/compiler/ast-utilities.d.ts +82 -0
- package/dist/api/compiler/ast-utilities.js +462 -0
- package/dist/api/compiler/ast.d.ts +2351 -0
- package/dist/api/compiler/ast.js +11212 -0
- package/dist/api/compiler/astnav.d.ts +37 -0
- package/dist/api/compiler/astnav.js +767 -0
- package/dist/api/compiler/binder-utilities.d.ts +182 -0
- package/dist/api/compiler/binder-utilities.js +1241 -0
- package/dist/api/compiler/binder.d.ts +33 -0
- package/dist/api/compiler/binder.js +2359 -0
- package/dist/api/compiler/character-codes.d.ts +161 -0
- package/dist/api/compiler/character-codes.js +160 -0
- package/dist/api/compiler/checker-calls.d.ts +46 -0
- package/dist/api/compiler/checker-calls.js +1641 -0
- package/dist/api/compiler/checker-classes.d.ts +30 -0
- package/dist/api/compiler/checker-classes.js +582 -0
- package/dist/api/compiler/checker-contextual.d.ts +77 -0
- package/dist/api/compiler/checker-contextual.js +1136 -0
- package/dist/api/compiler/checker-declaration-order.d.ts +12 -0
- package/dist/api/compiler/checker-declaration-order.js +357 -0
- package/dist/api/compiler/checker-declarations.d.ts +33 -0
- package/dist/api/compiler/checker-declarations.js +888 -0
- package/dist/api/compiler/checker-declared-types.d.ts +48 -0
- package/dist/api/compiler/checker-declared-types.js +788 -0
- package/dist/api/compiler/checker-decorators.d.ts +26 -0
- package/dist/api/compiler/checker-decorators.js +562 -0
- package/dist/api/compiler/checker-deprecation.d.ts +33 -0
- package/dist/api/compiler/checker-deprecation.js +314 -0
- package/dist/api/compiler/checker-destructuring.d.ts +34 -0
- package/dist/api/compiler/checker-destructuring.js +584 -0
- package/dist/api/compiler/checker-elaboration.d.ts +15 -0
- package/dist/api/compiler/checker-elaboration.js +291 -0
- package/dist/api/compiler/checker-emit-helpers.d.ts +58 -0
- package/dist/api/compiler/checker-emit-helpers.js +154 -0
- package/dist/api/compiler/checker-emit-resolver.d.ts +75 -0
- package/dist/api/compiler/checker-emit-resolver.js +580 -0
- package/dist/api/compiler/checker-evaluator.d.ts +27 -0
- package/dist/api/compiler/checker-evaluator.js +188 -0
- package/dist/api/compiler/checker-expressions.d.ts +67 -0
- package/dist/api/compiler/checker-expressions.js +1351 -0
- package/dist/api/compiler/checker-features.d.ts +6 -0
- package/dist/api/compiler/checker-features.js +354 -0
- package/dist/api/compiler/checker-flow.d.ts +86 -0
- package/dist/api/compiler/checker-flow.js +169 -0
- package/dist/api/compiler/checker-functions.d.ts +43 -0
- package/dist/api/compiler/checker-functions.js +1002 -0
- package/dist/api/compiler/checker-generated-code.d.ts +25 -0
- package/dist/api/compiler/checker-generated-code.js +168 -0
- package/dist/api/compiler/checker-globals.d.ts +14 -0
- package/dist/api/compiler/checker-globals.js +37 -0
- package/dist/api/compiler/checker-grammar.d.ts +35 -0
- package/dist/api/compiler/checker-grammar.js +2587 -0
- package/dist/api/compiler/checker-heritage.d.ts +28 -0
- package/dist/api/compiler/checker-heritage.js +901 -0
- package/dist/api/compiler/checker-inference.d.ts +179 -0
- package/dist/api/compiler/checker-inference.js +2105 -0
- package/dist/api/compiler/checker-iteration.d.ts +115 -0
- package/dist/api/compiler/checker-iteration.js +857 -0
- package/dist/api/compiler/checker-javascript.d.ts +42 -0
- package/dist/api/compiler/checker-javascript.js +442 -0
- package/dist/api/compiler/checker-jsdoc.d.ts +30 -0
- package/dist/api/compiler/checker-jsdoc.js +320 -0
- package/dist/api/compiler/checker-jsx.d.ts +94 -0
- package/dist/api/compiler/checker-jsx.js +1433 -0
- package/dist/api/compiler/checker-literals.d.ts +6 -0
- package/dist/api/compiler/checker-literals.js +43 -0
- package/dist/api/compiler/checker-members.d.ts +200 -0
- package/dist/api/compiler/checker-members.js +2148 -0
- package/dist/api/compiler/checker-modules.d.ts +85 -0
- package/dist/api/compiler/checker-modules.js +2141 -0
- package/dist/api/compiler/checker-narrowing.d.ts +120 -0
- package/dist/api/compiler/checker-narrowing.js +2797 -0
- package/dist/api/compiler/checker-object-literals.d.ts +14 -0
- package/dist/api/compiler/checker-object-literals.js +483 -0
- package/dist/api/compiler/checker-operators.d.ts +33 -0
- package/dist/api/compiler/checker-operators.js +1040 -0
- package/dist/api/compiler/checker-overloads.d.ts +7 -0
- package/dist/api/compiler/checker-overloads.js +271 -0
- package/dist/api/compiler/checker-property-access.d.ts +34 -0
- package/dist/api/compiler/checker-property-access.js +672 -0
- package/dist/api/compiler/checker-services.d.ts +49 -0
- package/dist/api/compiler/checker-services.js +995 -0
- package/dist/api/compiler/checker-signatures.d.ts +55 -0
- package/dist/api/compiler/checker-signatures.js +789 -0
- package/dist/api/compiler/checker-source-file.d.ts +27 -0
- package/dist/api/compiler/checker-source-file.js +619 -0
- package/dist/api/compiler/checker-statements.d.ts +18 -0
- package/dist/api/compiler/checker-statements.js +226 -0
- package/dist/api/compiler/checker-super.d.ts +13 -0
- package/dist/api/compiler/checker-super.js +241 -0
- package/dist/api/compiler/checker-symbol-types.d.ts +51 -0
- package/dist/api/compiler/checker-symbol-types.js +955 -0
- package/dist/api/compiler/checker-symbols.d.ts +181 -0
- package/dist/api/compiler/checker-symbols.js +1784 -0
- package/dist/api/compiler/checker-type-factory.d.ts +142 -0
- package/dist/api/compiler/checker-type-factory.js +2542 -0
- package/dist/api/compiler/checker-type-nodes.d.ts +26 -0
- package/dist/api/compiler/checker-type-nodes.js +828 -0
- package/dist/api/compiler/checker-type-operators.d.ts +109 -0
- package/dist/api/compiler/checker-type-operators.js +1842 -0
- package/dist/api/compiler/checker-types.d.ts +1093 -0
- package/dist/api/compiler/checker-types.js +1874 -0
- package/dist/api/compiler/checker-unused.d.ts +19 -0
- package/dist/api/compiler/checker-unused.js +524 -0
- package/dist/api/compiler/checker-utilities.d.ts +33 -0
- package/dist/api/compiler/checker-utilities.js +141 -0
- package/dist/api/compiler/checker.d.ts +512 -0
- package/dist/api/compiler/checker.js +932 -0
- package/dist/api/compiler/command-line.d.ts +32 -0
- package/dist/api/compiler/command-line.js +383 -0
- package/dist/api/compiler/compile-program.d.ts +118 -0
- package/dist/api/compiler/compile-program.js +384 -0
- package/dist/api/compiler/diagnostic-locales.d.ts +22 -0
- package/dist/api/compiler/diagnostic-locales.js +64 -0
- package/dist/api/compiler/diagnostic-messages.d.ts +2166 -0
- package/dist/api/compiler/diagnostic-messages.js +184 -0
- package/dist/api/compiler/diagnostics.d.ts +161 -0
- package/dist/api/compiler/diagnostics.js +784 -0
- package/dist/api/compiler/emitter.d.ts +71 -0
- package/dist/api/compiler/emitter.js +327 -0
- package/dist/api/compiler/file-include.d.ts +144 -0
- package/dist/api/compiler/file-include.js +599 -0
- package/dist/api/compiler/file-loader.d.ts +290 -0
- package/dist/api/compiler/file-loader.js +1323 -0
- package/dist/api/compiler/file-system.d.ts +51 -0
- package/dist/api/compiler/file-system.js +132 -0
- package/dist/api/compiler/flow.d.ts +60 -0
- package/dist/api/compiler/flow.js +45 -0
- package/dist/api/compiler/instantiation.d.ts +74 -0
- package/dist/api/compiler/instantiation.js +835 -0
- package/dist/api/compiler/jsdoc.d.ts +75 -0
- package/dist/api/compiler/jsdoc.js +1229 -0
- package/dist/api/compiler/link-tables.d.ts +105 -0
- package/dist/api/compiler/link-tables.js +319 -0
- package/dist/api/compiler/locale-data.d.ts +24 -0
- package/dist/api/compiler/locale-data.js +183 -0
- package/dist/api/compiler/locale.d.ts +4 -0
- package/dist/api/compiler/locale.js +317 -0
- package/dist/api/compiler/locales/cs-CZ.d.ts +2 -0
- package/dist/api/compiler/locales/cs-CZ.js +3 -0
- package/dist/api/compiler/locales/de-DE.d.ts +2 -0
- package/dist/api/compiler/locales/de-DE.js +3 -0
- package/dist/api/compiler/locales/es-ES.d.ts +2 -0
- package/dist/api/compiler/locales/es-ES.js +3 -0
- package/dist/api/compiler/locales/fr-FR.d.ts +2 -0
- package/dist/api/compiler/locales/fr-FR.js +3 -0
- package/dist/api/compiler/locales/it-IT.d.ts +2 -0
- package/dist/api/compiler/locales/it-IT.js +3 -0
- package/dist/api/compiler/locales/ja-JP.d.ts +2 -0
- package/dist/api/compiler/locales/ja-JP.js +3 -0
- package/dist/api/compiler/locales/ko-KR.d.ts +2 -0
- package/dist/api/compiler/locales/ko-KR.js +3 -0
- package/dist/api/compiler/locales/pl-PL.d.ts +2 -0
- package/dist/api/compiler/locales/pl-PL.js +3 -0
- package/dist/api/compiler/locales/pt-BR.d.ts +2 -0
- package/dist/api/compiler/locales/pt-BR.js +3 -0
- package/dist/api/compiler/locales/ru-RU.d.ts +2 -0
- package/dist/api/compiler/locales/ru-RU.js +3 -0
- package/dist/api/compiler/locales/tr-TR.d.ts +2 -0
- package/dist/api/compiler/locales/tr-TR.js +3 -0
- package/dist/api/compiler/locales/zh-CN.d.ts +2 -0
- package/dist/api/compiler/locales/zh-CN.js +3 -0
- package/dist/api/compiler/locales/zh-TW.d.ts +2 -0
- package/dist/api/compiler/locales/zh-TW.js +3 -0
- package/dist/api/compiler/module-resolution-types.d.ts +83 -0
- package/dist/api/compiler/module-resolution-types.js +176 -0
- package/dist/api/compiler/module-resolution.d.ts +71 -0
- package/dist/api/compiler/module-resolution.js +1598 -0
- package/dist/api/compiler/module-specifiers.d.ts +64 -0
- package/dist/api/compiler/module-specifiers.js +1101 -0
- package/dist/api/compiler/name-resolver.d.ts +43 -0
- package/dist/api/compiler/name-resolver.js +509 -0
- package/dist/api/compiler/node-builder-names.d.ts +32 -0
- package/dist/api/compiler/node-builder-names.js +854 -0
- package/dist/api/compiler/node-builder-pseudo.d.ts +36 -0
- package/dist/api/compiler/node-builder-pseudo.js +745 -0
- package/dist/api/compiler/node-builder-reuse.d.ts +4 -0
- package/dist/api/compiler/node-builder-reuse.js +647 -0
- package/dist/api/compiler/node-builder.d.ts +270 -0
- package/dist/api/compiler/node-builder.js +2645 -0
- package/dist/api/compiler/option-declarations.d.ts +90 -0
- package/dist/api/compiler/option-declarations.js +1460 -0
- package/dist/api/compiler/options.d.ts +289 -0
- package/dist/api/compiler/options.js +1197 -0
- package/dist/api/compiler/output-paths.d.ts +42 -0
- package/dist/api/compiler/output-paths.js +195 -0
- package/dist/api/compiler/package-json.d.ts +175 -0
- package/dist/api/compiler/package-json.js +1015 -0
- package/dist/api/compiler/parallel-parse.d.ts +221 -0
- package/dist/api/compiler/parallel-parse.js +541 -0
- package/dist/api/compiler/parser.d.ts +604 -0
- package/dist/api/compiler/parser.js +6426 -0
- package/dist/api/compiler/path.d.ts +91 -0
- package/dist/api/compiler/path.js +705 -0
- package/dist/api/compiler/printer/async-helpers.d.ts +22 -0
- package/dist/api/compiler/printer/async-helpers.js +91 -0
- package/dist/api/compiler/printer/auto-generate.d.ts +13 -0
- package/dist/api/compiler/printer/auto-generate.js +20 -0
- package/dist/api/compiler/printer/decorator-helpers.d.ts +24 -0
- package/dist/api/compiler/printer/decorator-helpers.js +118 -0
- package/dist/api/compiler/printer/emit-context.d.ts +157 -0
- package/dist/api/compiler/printer/emit-context.js +582 -0
- package/dist/api/compiler/printer/emit-flags.d.ts +60 -0
- package/dist/api/compiler/printer/emit-flags.js +2 -0
- package/dist/api/compiler/printer/factory-base.d.ts +171 -0
- package/dist/api/compiler/printer/factory-base.js +1505 -0
- package/dist/api/compiler/printer/factory.d.ts +147 -0
- package/dist/api/compiler/printer/factory.js +542 -0
- package/dist/api/compiler/printer/helpers.d.ts +27 -0
- package/dist/api/compiler/printer/helpers.js +164 -0
- package/dist/api/compiler/printer/name-generator.d.ts +41 -0
- package/dist/api/compiler/printer/name-generator.js +283 -0
- package/dist/api/compiler/printer/printer.d.ts +411 -0
- package/dist/api/compiler/printer/printer.js +4517 -0
- package/dist/api/compiler/printer/text-writer.d.ts +46 -0
- package/dist/api/compiler/printer/text-writer.js +172 -0
- package/dist/api/compiler/printer/utilities.d.ts +82 -0
- package/dist/api/compiler/printer/utilities.js +817 -0
- package/dist/api/compiler/program-checker.d.ts +156 -0
- package/dist/api/compiler/program-checker.js +529 -0
- package/dist/api/compiler/program-utilities.d.ts +52 -0
- package/dist/api/compiler/program-utilities.js +365 -0
- package/dist/api/compiler/program.d.ts +180 -0
- package/dist/api/compiler/program.js +1019 -0
- package/dist/api/compiler/pseudo-bigint.d.ts +5 -0
- package/dist/api/compiler/pseudo-bigint.js +61 -0
- package/dist/api/compiler/regexp-checker.d.ts +38 -0
- package/dist/api/compiler/regexp-checker.js +942 -0
- package/dist/api/compiler/relations.d.ts +263 -0
- package/dist/api/compiler/relations.js +4002 -0
- package/dist/api/compiler/reparser.d.ts +48 -0
- package/dist/api/compiler/reparser.js +1323 -0
- package/dist/api/compiler/scanner.d.ts +256 -0
- package/dist/api/compiler/scanner.js +2853 -0
- package/dist/api/compiler/side-state.d.ts +16 -0
- package/dist/api/compiler/side-state.js +89 -0
- package/dist/api/compiler/sourcemap.d.ts +55 -0
- package/dist/api/compiler/sourcemap.js +340 -0
- package/dist/api/compiler/spelling.d.ts +14 -0
- package/dist/api/compiler/spelling.js +128 -0
- package/dist/api/compiler/symbol-accessibility.d.ts +57 -0
- package/dist/api/compiler/symbol-accessibility.js +991 -0
- package/dist/api/compiler/symbol.d.ts +282 -0
- package/dist/api/compiler/symbol.js +339 -0
- package/dist/api/compiler/symlinks.d.ts +32 -0
- package/dist/api/compiler/symlinks.js +114 -0
- package/dist/api/compiler/syntax-kind.d.ts +389 -0
- package/dist/api/compiler/syntax-kind.js +2 -0
- package/dist/api/compiler/timeline.d.ts +9 -0
- package/dist/api/compiler/timeline.js +54 -0
- package/dist/api/compiler/transformers/alias-references.d.ts +39 -0
- package/dist/api/compiler/transformers/alias-references.js +677 -0
- package/dist/api/compiler/transformers/async-utilities.d.ts +51 -0
- package/dist/api/compiler/transformers/async-utilities.js +260 -0
- package/dist/api/compiler/transformers/async.d.ts +53 -0
- package/dist/api/compiler/transformers/async.js +645 -0
- package/dist/api/compiler/transformers/class-fields.d.ts +206 -0
- package/dist/api/compiler/transformers/class-fields.js +2418 -0
- package/dist/api/compiler/transformers/class-utilities.d.ts +46 -0
- package/dist/api/compiler/transformers/class-utilities.js +261 -0
- package/dist/api/compiler/transformers/commonjs-module.d.ts +103 -0
- package/dist/api/compiler/transformers/commonjs-module.js +1180 -0
- package/dist/api/compiler/transformers/const-enum-inliner.d.ts +11 -0
- package/dist/api/compiler/transformers/const-enum-inliner.js +36 -0
- package/dist/api/compiler/transformers/declarations-diagnostics.d.ts +52 -0
- package/dist/api/compiler/transformers/declarations-diagnostics.js +539 -0
- package/dist/api/compiler/transformers/declarations-pseudo.d.ts +160 -0
- package/dist/api/compiler/transformers/declarations-pseudo.js +799 -0
- package/dist/api/compiler/transformers/declarations-resolver.d.ts +152 -0
- package/dist/api/compiler/transformers/declarations-resolver.js +35 -0
- package/dist/api/compiler/transformers/declarations-syntactic.d.ts +119 -0
- package/dist/api/compiler/transformers/declarations-syntactic.js +1582 -0
- package/dist/api/compiler/transformers/declarations-tracker.d.ts +46 -0
- package/dist/api/compiler/transformers/declarations-tracker.js +198 -0
- package/dist/api/compiler/transformers/declarations.d.ts +175 -0
- package/dist/api/compiler/transformers/declarations.js +2381 -0
- package/dist/api/compiler/transformers/decorator-metadata.d.ts +54 -0
- package/dist/api/compiler/transformers/decorator-metadata.js +554 -0
- package/dist/api/compiler/transformers/decorator-utilities.d.ts +38 -0
- package/dist/api/compiler/transformers/decorator-utilities.js +238 -0
- package/dist/api/compiler/transformers/destructuring.d.ts +25 -0
- package/dist/api/compiler/transformers/destructuring.js +626 -0
- package/dist/api/compiler/transformers/downlevel.d.ts +6 -0
- package/dist/api/compiler/transformers/downlevel.js +45 -0
- package/dist/api/compiler/transformers/emit-resolver.d.ts +61 -0
- package/dist/api/compiler/transformers/emit-resolver.js +197 -0
- package/dist/api/compiler/transformers/es-decorators.d.ts +118 -0
- package/dist/api/compiler/transformers/es-decorators.js +1901 -0
- package/dist/api/compiler/transformers/exponentiation.d.ts +11 -0
- package/dist/api/compiler/transformers/exponentiation.js +76 -0
- package/dist/api/compiler/transformers/external-module-info.d.ts +35 -0
- package/dist/api/compiler/transformers/external-module-info.js +351 -0
- package/dist/api/compiler/transformers/for-await.d.ts +43 -0
- package/dist/api/compiler/transformers/for-await.js +469 -0
- package/dist/api/compiler/transformers/import-elision.d.ts +16 -0
- package/dist/api/compiler/transformers/import-elision.js +124 -0
- package/dist/api/compiler/transformers/jsx-entities.d.ts +1 -0
- package/dist/api/compiler/transformers/jsx-entities.js +256 -0
- package/dist/api/compiler/transformers/jsx.d.ts +71 -0
- package/dist/api/compiler/transformers/jsx.js +700 -0
- package/dist/api/compiler/transformers/legacy-decorators.d.ts +56 -0
- package/dist/api/compiler/transformers/legacy-decorators.js +564 -0
- package/dist/api/compiler/transformers/logical-assignment.d.ts +14 -0
- package/dist/api/compiler/transformers/logical-assignment.js +62 -0
- package/dist/api/compiler/transformers/module-utilities.d.ts +9 -0
- package/dist/api/compiler/transformers/module-utilities.js +36 -0
- package/dist/api/compiler/transformers/module.d.ts +49 -0
- package/dist/api/compiler/transformers/module.js +296 -0
- package/dist/api/compiler/transformers/named-evaluation.d.ts +26 -0
- package/dist/api/compiler/transformers/named-evaluation.js +266 -0
- package/dist/api/compiler/transformers/nullish-coalescing.d.ts +9 -0
- package/dist/api/compiler/transformers/nullish-coalescing.js +26 -0
- package/dist/api/compiler/transformers/object-rest-spread.d.ts +34 -0
- package/dist/api/compiler/transformers/object-rest-spread.js +411 -0
- package/dist/api/compiler/transformers/optional-catch.d.ts +9 -0
- package/dist/api/compiler/transformers/optional-catch.js +20 -0
- package/dist/api/compiler/transformers/optional-chain.d.ts +14 -0
- package/dist/api/compiler/transformers/optional-chain.js +188 -0
- package/dist/api/compiler/transformers/reference-resolver.d.ts +129 -0
- package/dist/api/compiler/transformers/reference-resolver.js +1157 -0
- package/dist/api/compiler/transformers/runtime-syntax.d.ts +71 -0
- package/dist/api/compiler/transformers/runtime-syntax.js +753 -0
- package/dist/api/compiler/transformers/subtree-facts.d.ts +10 -0
- package/dist/api/compiler/transformers/subtree-facts.js +205 -0
- package/dist/api/compiler/transformers/syntax-facts.d.ts +52 -0
- package/dist/api/compiler/transformers/syntax-facts.js +258 -0
- package/dist/api/compiler/transformers/tagged-template.d.ts +17 -0
- package/dist/api/compiler/transformers/tagged-template.js +148 -0
- package/dist/api/compiler/transformers/transformer.d.ts +17 -0
- package/dist/api/compiler/transformers/transformer.js +54 -0
- package/dist/api/compiler/transformers/type-eraser.d.ts +21 -0
- package/dist/api/compiler/transformers/type-eraser.js +346 -0
- package/dist/api/compiler/transformers/type-serialization.d.ts +20 -0
- package/dist/api/compiler/transformers/type-serialization.js +347 -0
- package/dist/api/compiler/transformers/using.d.ts +56 -0
- package/dist/api/compiler/transformers/using.js +453 -0
- package/dist/api/compiler/transformers/utilities.d.ts +50 -0
- package/dist/api/compiler/transformers/utilities.js +347 -0
- package/dist/api/compiler/transformers/visitor-base.d.ts +6 -0
- package/dist/api/compiler/transformers/visitor-base.js +817 -0
- package/dist/api/compiler/transformers/visitor-hooks.d.ts +29 -0
- package/dist/api/compiler/transformers/visitor-hooks.js +189 -0
- package/dist/api/compiler/tsconfig.d.ts +177 -0
- package/dist/api/compiler/tsconfig.js +1311 -0
- package/dist/api/compiler/type-printer.d.ts +15 -0
- package/dist/api/compiler/type-printer.js +74 -0
- package/dist/api/compiler/types.d.ts +87 -0
- package/dist/api/compiler/types.js +23 -0
- package/dist/api/compiler/unicode-identifiers.d.ts +2 -0
- package/dist/api/compiler/unicode-identifiers.js +209 -0
- package/dist/api/compiler/unicode-properties.d.ts +8 -0
- package/dist/api/compiler/unicode-properties.js +531 -0
- package/dist/api/compiler/vfs-match.d.ts +24 -0
- package/dist/api/compiler/vfs-match.js +587 -0
- package/dist/api/library/ast.d.ts +3 -2
- package/dist/api/library/ast.generated.d.ts +127 -139
- package/dist/api/library/checker.d.ts +51 -0
- package/dist/api/library/checker.js +318 -0
- package/dist/api/library/diagnostics.d.ts +13 -0
- package/dist/api/library/diagnostics.js +50 -0
- package/dist/api/library/disk.d.ts +13 -0
- package/dist/api/library/disk.js +66 -0
- package/dist/api/library/errors.d.ts +13 -0
- package/dist/api/library/errors.js +24 -0
- package/dist/api/library/host.d.ts +24 -0
- package/dist/api/library/host.js +52 -0
- package/dist/api/library/index.d.ts +5 -1
- package/dist/api/library/index.js +4 -0
- package/dist/api/library/nodes.d.ts +51 -0
- package/dist/api/library/nodes.js +196 -0
- package/dist/api/library/options.d.ts +144 -0
- package/dist/api/library/options.js +308 -0
- package/dist/api/library/parse.d.ts +19 -0
- package/dist/api/library/parse.js +41 -0
- package/dist/api/library/program.d.ts +21 -0
- package/dist/api/library/program.js +234 -0
- package/dist/api/library/types.d.ts +14 -1
- package/package.json +12 -8
- package/src/compiler/ast-utilities.ts +548 -0
- package/src/compiler/ast.ts +12870 -0
- package/src/compiler/astnav.ts +799 -0
- package/src/compiler/binder-utilities.ts +1392 -0
- package/src/compiler/binder.ts +2707 -0
- package/src/compiler/build-info.ts +1197 -0
- package/src/compiler/character-codes.ts +323 -0
- package/src/compiler/checker-calls.ts +2155 -0
- package/src/compiler/checker-classes.ts +706 -0
- package/src/compiler/checker-contextual.ts +1457 -0
- package/src/compiler/checker-declaration-order.ts +438 -0
- package/src/compiler/checker-declarations.ts +1201 -0
- package/src/compiler/checker-declared-types.ts +919 -0
- package/src/compiler/checker-decorators.ts +694 -0
- package/src/compiler/checker-deprecation.ts +355 -0
- package/src/compiler/checker-destructuring.ts +805 -0
- package/src/compiler/checker-elaboration.ts +477 -0
- package/src/compiler/checker-emit-helpers.ts +224 -0
- package/src/compiler/checker-emit-resolver.ts +769 -0
- package/src/compiler/checker-evaluator.ts +243 -0
- package/src/compiler/checker-expressions.ts +1831 -0
- package/src/compiler/checker-features.ts +361 -0
- package/src/compiler/checker-flow.ts +394 -0
- package/src/compiler/checker-functions.ts +1296 -0
- package/src/compiler/checker-generated-code.ts +227 -0
- package/src/compiler/checker-globals.ts +52 -0
- package/src/compiler/checker-grammar.ts +3596 -0
- package/src/compiler/checker-heritage.ts +1240 -0
- package/src/compiler/checker-inference.ts +2584 -0
- package/src/compiler/checker-iteration.ts +1206 -0
- package/src/compiler/checker-javascript.ts +502 -0
- package/src/compiler/checker-jsdoc.ts +360 -0
- package/src/compiler/checker-jsx.ts +1928 -0
- package/src/compiler/checker-literals.ts +61 -0
- package/src/compiler/checker-members.ts +2480 -0
- package/src/compiler/checker-modules.ts +2896 -0
- package/src/compiler/checker-narrowing.ts +3230 -0
- package/src/compiler/checker-object-literals.ts +591 -0
- package/src/compiler/checker-operators.ts +1422 -0
- package/src/compiler/checker-overloads.ts +328 -0
- package/src/compiler/checker-property-access.ts +906 -0
- package/src/compiler/checker-services.ts +1149 -0
- package/src/compiler/checker-signatures.ts +1032 -0
- package/src/compiler/checker-source-file.ts +732 -0
- package/src/compiler/checker-statements.ts +292 -0
- package/src/compiler/checker-super.ts +261 -0
- package/src/compiler/checker-symbol-types.ts +1187 -0
- package/src/compiler/checker-symbols.ts +2157 -0
- package/src/compiler/checker-type-factory.ts +2616 -0
- package/src/compiler/checker-type-nodes.ts +1033 -0
- package/src/compiler/checker-type-operators.ts +2510 -0
- package/src/compiler/checker-types.ts +2520 -0
- package/src/compiler/checker-unused.ts +642 -0
- package/src/compiler/checker-utilities.ts +161 -0
- package/src/compiler/checker.ts +1138 -0
- package/src/compiler/command-line.ts +436 -0
- package/src/compiler/compile-program.ts +439 -0
- package/src/compiler/decoder.ts +1209 -0
- package/src/compiler/diagnostic-locales.ts +86 -0
- package/src/compiler/diagnostic-messages.ts +2349 -0
- package/src/compiler/diagnostics.ts +858 -0
- package/src/compiler/emitter.ts +434 -0
- package/src/compiler/encoder.ts +1945 -0
- package/src/compiler/file-include.ts +741 -0
- package/src/compiler/file-loader.ts +1597 -0
- package/src/compiler/file-system.ts +143 -0
- package/src/compiler/flow.ts +89 -0
- package/src/compiler/help.ts +473 -0
- package/src/compiler/incremental.ts +2818 -0
- package/src/compiler/init.ts +141 -0
- package/src/compiler/instantiation.ts +938 -0
- package/src/compiler/jsdoc.ts +1386 -0
- package/src/compiler/link-tables.ts +343 -0
- package/src/compiler/locale-data.ts +203 -0
- package/src/compiler/locale.ts +307 -0
- package/src/compiler/locales/cs-CZ.ts +5 -0
- package/src/compiler/locales/de-DE.ts +5 -0
- package/src/compiler/locales/es-ES.ts +5 -0
- package/src/compiler/locales/fr-FR.ts +5 -0
- package/src/compiler/locales/it-IT.ts +5 -0
- package/src/compiler/locales/ja-JP.ts +5 -0
- package/src/compiler/locales/ko-KR.ts +5 -0
- package/src/compiler/locales/pl-PL.ts +5 -0
- package/src/compiler/locales/pt-BR.ts +5 -0
- package/src/compiler/locales/ru-RU.ts +5 -0
- package/src/compiler/locales/tr-TR.ts +5 -0
- package/src/compiler/locales/zh-CN.ts +5 -0
- package/src/compiler/locales/zh-TW.ts +5 -0
- package/src/compiler/module-resolution-types.ts +243 -0
- package/src/compiler/module-resolution.ts +2072 -0
- package/src/compiler/module-specifiers.ts +1491 -0
- package/src/compiler/name-resolver.ts +646 -0
- package/src/compiler/node-builder-names.ts +1071 -0
- package/src/compiler/node-builder-pseudo.ts +892 -0
- package/src/compiler/node-builder-reuse.ts +764 -0
- package/src/compiler/node-builder.ts +3433 -0
- package/src/compiler/option-declarations.ts +1560 -0
- package/src/compiler/options.ts +1576 -0
- package/src/compiler/output-paths.ts +334 -0
- package/src/compiler/package-json.ts +1083 -0
- package/src/compiler/parallel-check.ts +1954 -0
- package/src/compiler/parallel-parse.ts +595 -0
- package/src/compiler/parse-thread.ts +136 -0
- package/src/compiler/parser.ts +7766 -0
- package/src/compiler/path.ts +717 -0
- package/src/compiler/printer/async-helpers.ts +183 -0
- package/src/compiler/printer/auto-generate.ts +27 -0
- package/src/compiler/printer/decorator-helpers.ts +218 -0
- package/src/compiler/printer/emit-context.ts +684 -0
- package/src/compiler/printer/emit-flags.ts +64 -0
- package/src/compiler/printer/factory-base.ts +2577 -0
- package/src/compiler/printer/factory.ts +764 -0
- package/src/compiler/printer/helpers.ts +291 -0
- package/src/compiler/printer/name-generator.ts +372 -0
- package/src/compiler/printer/printer.ts +5072 -0
- package/src/compiler/printer/text-writer.ts +183 -0
- package/src/compiler/printer/utilities.ts +884 -0
- package/src/compiler/program-checker.ts +594 -0
- package/src/compiler/program-utilities.ts +435 -0
- package/src/compiler/program.ts +1426 -0
- package/src/compiler/pseudo-bigint.ts +62 -0
- package/src/compiler/regexp-checker.ts +1142 -0
- package/src/compiler/relations.ts +5149 -0
- package/src/compiler/reparser.ts +1566 -0
- package/src/compiler/scanner.ts +2951 -0
- package/src/compiler/show-config.ts +239 -0
- package/src/compiler/side-state.ts +125 -0
- package/src/compiler/sourcemap.ts +366 -0
- package/src/compiler/spelling.ts +122 -0
- package/src/compiler/symbol-accessibility.ts +1166 -0
- package/src/compiler/symbol.ts +557 -0
- package/src/compiler/symlinks.ts +137 -0
- package/src/compiler/syntax-kind.ts +391 -0
- package/src/compiler/thread-entry.ts +191 -0
- package/src/compiler/timeline.ts +53 -0
- package/src/compiler/transformers/alias-references.ts +757 -0
- package/src/compiler/transformers/async-utilities.ts +335 -0
- package/src/compiler/transformers/async.ts +838 -0
- package/src/compiler/transformers/class-fields.ts +2967 -0
- package/src/compiler/transformers/class-utilities.ts +324 -0
- package/src/compiler/transformers/commonjs-module.ts +1621 -0
- package/src/compiler/transformers/const-enum-inliner.ts +50 -0
- package/src/compiler/transformers/declarations-diagnostics.ts +833 -0
- package/src/compiler/transformers/declarations-pseudo.ts +969 -0
- package/src/compiler/transformers/declarations-resolver.ts +249 -0
- package/src/compiler/transformers/declarations-syntactic.ts +1867 -0
- package/src/compiler/transformers/declarations-tracker.ts +269 -0
- package/src/compiler/transformers/declarations.ts +3120 -0
- package/src/compiler/transformers/decorator-metadata.ts +697 -0
- package/src/compiler/transformers/decorator-utilities.ts +283 -0
- package/src/compiler/transformers/destructuring.ts +708 -0
- package/src/compiler/transformers/downlevel.ts +50 -0
- package/src/compiler/transformers/emit-resolver.ts +258 -0
- package/src/compiler/transformers/es-decorators.ts +2682 -0
- package/src/compiler/transformers/exponentiation.ts +80 -0
- package/src/compiler/transformers/external-module-info.ts +412 -0
- package/src/compiler/transformers/for-await.ts +687 -0
- package/src/compiler/transformers/import-elision.ts +152 -0
- package/src/compiler/transformers/jsx-entities.ts +256 -0
- package/src/compiler/transformers/jsx.ts +824 -0
- package/src/compiler/transformers/legacy-decorators.ts +726 -0
- package/src/compiler/transformers/logical-assignment.ts +75 -0
- package/src/compiler/transformers/module-utilities.ts +42 -0
- package/src/compiler/transformers/module.ts +474 -0
- package/src/compiler/transformers/named-evaluation.ts +389 -0
- package/src/compiler/transformers/nullish-coalescing.ts +35 -0
- package/src/compiler/transformers/object-rest-spread.ts +577 -0
- package/src/compiler/transformers/optional-catch.ts +29 -0
- package/src/compiler/transformers/optional-chain.ts +246 -0
- package/src/compiler/transformers/reference-resolver.ts +1213 -0
- package/src/compiler/transformers/runtime-syntax.ts +942 -0
- package/src/compiler/transformers/subtree-facts.ts +253 -0
- package/src/compiler/transformers/syntax-facts.ts +358 -0
- package/src/compiler/transformers/tagged-template.ts +167 -0
- package/src/compiler/transformers/transformer.ts +56 -0
- package/src/compiler/transformers/type-eraser.ts +520 -0
- package/src/compiler/transformers/type-serialization.ts +374 -0
- package/src/compiler/transformers/using.ts +613 -0
- package/src/compiler/transformers/utilities.ts +419 -0
- package/src/compiler/transformers/visitor-base.ts +1601 -0
- package/src/compiler/transformers/visitor-hooks.ts +252 -0
- package/src/compiler/tsc-build.ts +1422 -0
- package/src/compiler/tsc-cli.ts +669 -0
- package/src/compiler/tsc-compile.ts +446 -0
- package/src/compiler/tsc-watch.ts +922 -0
- package/src/compiler/tsconfig.ts +1574 -0
- package/src/compiler/type-printer.ts +110 -0
- package/src/compiler/types.ts +115 -0
- package/src/compiler/unicode-identifiers.ts +212 -0
- package/src/compiler/unicode-properties.ts +537 -0
- package/src/compiler/vfs-match.ts +597 -0
- package/src/compiler/xxh3.ts +650 -0
- package/src/library/ast.generated.ts +141 -167
- package/src/library/ast.ts +4 -1
- package/src/library/checker.ts +384 -0
- package/src/library/diagnostics.ts +72 -0
- package/src/library/disk.ts +73 -0
- package/src/library/errors.ts +26 -0
- package/src/library/host.ts +63 -0
- package/src/library/index.ts +21 -0
- package/src/library/nodes.ts +232 -0
- package/src/library/options.ts +449 -0
- package/src/library/parse.ts +63 -0
- package/src/library/program.ts +293 -0
- package/src/library/types.ts +14 -1
|
@@ -0,0 +1,991 @@
|
|
|
1
|
+
// Whether a symbol can be named from a location, and the chain of symbols that names it:
|
|
2
|
+
// `getAccessibleSymbolChain` and `isSymbolAccessible`, as the node builder and declaration
|
|
3
|
+
// emit use them.
|
|
4
|
+
import { BinaryExpression, BindingElement, BindingPattern, ClassExpression, ExportDeclaration, ImportEqualsDeclaration, VariableDeclaration, getExpression, getInitializer, getLocals, getName, getNodeId, getText, getType, } from './ast.js';
|
|
5
|
+
import { isAmbientModule, isInJSFile } from './ast-utilities.js';
|
|
6
|
+
import { getCombinedModifierFlags, getRootDeclaration, getSourceFileOfNode, hasSyntacticModifier, isAccessExpression, isEntityNameExpression, isExportsIdentifier, isExternalModule, isExternalOrCommonJSModule, isGlobalSourceFile, isModuleExportsAccessExpression, } from './binder-utilities.js';
|
|
7
|
+
import { ExternalModuleContainerIndex, SymbolAccessibilityCaches, fileIndexScale } from './checker.js';
|
|
8
|
+
import { getEffectiveDeclarationFlags } from './checker-declarations.js';
|
|
9
|
+
import { getDeclaredTypeOfSymbol } from './checker-declared-types.js';
|
|
10
|
+
import { checkExpressionCached } from './checker-expressions.js';
|
|
11
|
+
import { resolveExternalModuleName, resolveExternalModuleSymbol } from './checker-modules.js';
|
|
12
|
+
import { getExportsOfSymbol, getMergedSymbol, getParentOfSymbol, getSymbolFlags, getSymbolOfDeclaration, resolveAlias, resolveSymbol, } from './checker-symbols.js';
|
|
13
|
+
import { getTypeOfSymbol } from './checker-symbol-types.js';
|
|
14
|
+
import { compareSymbols } from './checker-type-factory.js';
|
|
15
|
+
import { SymbolAccessibilityResult, accessible } from './transformers/declarations-resolver.js';
|
|
16
|
+
import { getAnyImportSyntax, getDeclarationContainer, isExternalModuleAugmentation, isLateVisibilityPaintedStatement, } from './transformers/declarations-syntactic.js';
|
|
17
|
+
import { isImplicitlyExportedJSDocDeclaration } from './binder-utilities.js';
|
|
18
|
+
import { symbolToString } from './type-printer.js';
|
|
19
|
+
import { declarationCount, getDeclarations, getSymbolId, } from './symbol.js';
|
|
20
|
+
const tableKindScale = 2 ** 44;
|
|
21
|
+
function tableId(kind, id) {
|
|
22
|
+
return kind * tableKindScale + id;
|
|
23
|
+
}
|
|
24
|
+
function tableKindOf(id) {
|
|
25
|
+
return Math.floor(id / tableKindScale);
|
|
26
|
+
}
|
|
27
|
+
function caches(c) {
|
|
28
|
+
let result = c.symbolAccessibilityCaches;
|
|
29
|
+
if (result === undefined) {
|
|
30
|
+
result = new SymbolAccessibilityCaches();
|
|
31
|
+
c.symbolAccessibilityCaches = result;
|
|
32
|
+
}
|
|
33
|
+
return result;
|
|
34
|
+
}
|
|
35
|
+
// ---- Accessibility
|
|
36
|
+
export function isTypeSymbolAccessible(c, symbol, enclosingDeclaration) {
|
|
37
|
+
return (isSymbolAccessibleWorker(c, symbol, enclosingDeclaration, 788968 /* SymbolFlags.Type */, false, true).accessibility ===
|
|
38
|
+
0 /* SymbolAccessibility.Accessible */);
|
|
39
|
+
}
|
|
40
|
+
export function isValueSymbolAccessible(c, symbol, enclosingDeclaration) {
|
|
41
|
+
return (isSymbolAccessibleWorker(c, symbol, enclosingDeclaration, 111551 /* SymbolFlags.Value */, false, true).accessibility ===
|
|
42
|
+
0 /* SymbolAccessibility.Accessible */);
|
|
43
|
+
}
|
|
44
|
+
export function isSymbolAccessibleByFlags(c, symbol, enclosingDeclaration, flags) {
|
|
45
|
+
return (isSymbolAccessibleWorker(c, symbol, enclosingDeclaration, flags, false, false).accessibility ===
|
|
46
|
+
0 /* SymbolAccessibility.Accessible */);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Whether `symbol` can be named with `meaning` from `enclosingDeclaration`; with
|
|
50
|
+
* `shouldComputeAliasesToMakeVisible`, the unexported imports and statements naming it are
|
|
51
|
+
* marked visible and returned.
|
|
52
|
+
*/
|
|
53
|
+
export function isSymbolAccessible(c, symbol, enclosingDeclaration, meaning, shouldComputeAliasesToMakeVisible) {
|
|
54
|
+
return isSymbolAccessibleWorker(c, symbol, enclosingDeclaration, meaning, shouldComputeAliasesToMakeVisible, true);
|
|
55
|
+
}
|
|
56
|
+
function isSymbolAccessibleWorker(c, symbol, enclosingDeclaration, meaning, shouldComputeAliasesToMakeVisible, allowModules) {
|
|
57
|
+
if (symbol === undefined || enclosingDeclaration === undefined)
|
|
58
|
+
return accessible([]);
|
|
59
|
+
const result = isAnySymbolAccessible(c, [symbol], enclosingDeclaration, symbol, meaning, shouldComputeAliasesToMakeVisible, allowModules);
|
|
60
|
+
if (result !== undefined)
|
|
61
|
+
return result;
|
|
62
|
+
// A symbol not exported from its module, or from another module without an alias, can't be named.
|
|
63
|
+
let symbolExternalModule = undefined;
|
|
64
|
+
for (const d of getDeclarations(symbol)) {
|
|
65
|
+
symbolExternalModule = getExternalModuleContainer(c, d);
|
|
66
|
+
if (symbolExternalModule !== undefined)
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
if (symbolExternalModule !== undefined) {
|
|
70
|
+
const enclosingExternalModule = getExternalModuleContainer(c, enclosingDeclaration);
|
|
71
|
+
if (symbolExternalModule !== enclosingExternalModule)
|
|
72
|
+
return new SymbolAccessibilityResult(2 /* SymbolAccessibility.CannotBeNamed */, [], symbolToString(c, symbol), isInJSFile(enclosingDeclaration) ? enclosingDeclaration : undefined, symbolToString(c, symbolExternalModule));
|
|
73
|
+
}
|
|
74
|
+
return new SymbolAccessibilityResult(1 /* SymbolAccessibility.NotAccessible */, [], symbolToString(c, symbol), undefined, '');
|
|
75
|
+
}
|
|
76
|
+
function isAnySymbolAccessible(c, symbols, enclosingDeclaration, initialSymbol, meaning, shouldComputeAliasesToMakeVisible, allowModules) {
|
|
77
|
+
if (symbols.length === 0)
|
|
78
|
+
return undefined;
|
|
79
|
+
let hadAccessibleChain = undefined;
|
|
80
|
+
let earlyModuleBail = false;
|
|
81
|
+
for (const symbol of symbols) {
|
|
82
|
+
// Accessible by itself.
|
|
83
|
+
const chain = getAccessibleSymbolChain(c, symbol, enclosingDeclaration, meaning, false);
|
|
84
|
+
if (chain.length > 0) {
|
|
85
|
+
hadAccessibleChain = symbol;
|
|
86
|
+
const visible = hasVisibleDeclarations(c, chain[0], shouldComputeAliasesToMakeVisible);
|
|
87
|
+
if (visible !== undefined)
|
|
88
|
+
return visible;
|
|
89
|
+
}
|
|
90
|
+
if (allowModules && hasNonGlobalAugmentationExternalModuleDeclaration(symbol)) {
|
|
91
|
+
if (shouldComputeAliasesToMakeVisible) {
|
|
92
|
+
// Prefer existing aliases of the module, which declaration emit must keep.
|
|
93
|
+
earlyModuleBail = true;
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
// Any meaning of a module is accessible through an `import` type.
|
|
97
|
+
return accessible([]);
|
|
98
|
+
}
|
|
99
|
+
// A qualified name is accessible when its container is: `m.c` with `m` in scope.
|
|
100
|
+
const containers = getContainersOfSymbol(c, symbol, enclosingDeclaration, meaning);
|
|
101
|
+
const parentResult = isAnySymbolAccessible(c, containers, enclosingDeclaration, initialSymbol, initialSymbol === symbol ? getQualifiedLeftMeaning(meaning) : meaning, shouldComputeAliasesToMakeVisible, allowModules);
|
|
102
|
+
if (parentResult !== undefined)
|
|
103
|
+
return parentResult;
|
|
104
|
+
}
|
|
105
|
+
if (earlyModuleBail)
|
|
106
|
+
return accessible([]);
|
|
107
|
+
if (hadAccessibleChain !== undefined)
|
|
108
|
+
return new SymbolAccessibilityResult(1 /* SymbolAccessibility.NotAccessible */, [], symbolToString(c, initialSymbol), undefined, hadAccessibleChain !== initialSymbol ? symbolToString(c, hadAccessibleChain) : '');
|
|
109
|
+
return undefined;
|
|
110
|
+
}
|
|
111
|
+
export function hasNonGlobalAugmentationExternalModuleDeclaration(symbol) {
|
|
112
|
+
for (const d of getDeclarations(symbol))
|
|
113
|
+
if (hasNonGlobalAugmentationExternalModuleSymbol(d))
|
|
114
|
+
return true;
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
export function hasNonGlobalAugmentationExternalModuleSymbol(declaration) {
|
|
118
|
+
return (isModuleWithStringLiteralName(declaration) ||
|
|
119
|
+
(declaration.kind === 307 /* SyntaxKind.SourceFile */ && isExternalOrCommonJSModule(declaration)));
|
|
120
|
+
}
|
|
121
|
+
function isModuleWithStringLiteralName(node) {
|
|
122
|
+
if (node.kind !== 268 /* SyntaxKind.ModuleDeclaration */)
|
|
123
|
+
return false;
|
|
124
|
+
const name = getName(node);
|
|
125
|
+
return name !== undefined && name.kind === 10 /* SyntaxKind.StringLiteral */;
|
|
126
|
+
}
|
|
127
|
+
/** In value space the left of a qualified name is a value; otherwise a namespace. */
|
|
128
|
+
export function getQualifiedLeftMeaning(rightMeaning) {
|
|
129
|
+
return rightMeaning === 111551 /* SymbolFlags.Value */ ? 111551 /* SymbolFlags.Value */ : 1920 /* SymbolFlags.Namespace */;
|
|
130
|
+
}
|
|
131
|
+
/** The merged symbol `symbol` resolves to through aliases. */
|
|
132
|
+
function getResolvedTarget(c, symbol) {
|
|
133
|
+
const resolved = resolveSymbol(c, getMergedSymbol(c, symbol));
|
|
134
|
+
return resolved !== undefined ? getMergedSymbol(c, resolved) : undefined;
|
|
135
|
+
}
|
|
136
|
+
/** `s1` if both symbols resolve to the same symbol, else undefined. */
|
|
137
|
+
export function getSymbolIfSameReference(c, s1, s2) {
|
|
138
|
+
const r1 = getResolvedTarget(c, s1);
|
|
139
|
+
if (r1 !== undefined && r1 === getResolvedTarget(c, s2))
|
|
140
|
+
return s1;
|
|
141
|
+
return undefined;
|
|
142
|
+
}
|
|
143
|
+
// ---- Containers
|
|
144
|
+
function getWithAlternativeContainers(c, container, symbol, enclosingDeclaration, meaning) {
|
|
145
|
+
const additionalContainers = [];
|
|
146
|
+
for (const d of getDeclarations(container)) {
|
|
147
|
+
const fileSymbol = getFileSymbolIfFileSymbolExportEqualsContainer(c, d, container);
|
|
148
|
+
if (fileSymbol !== undefined)
|
|
149
|
+
additionalContainers.push(fileSymbol);
|
|
150
|
+
}
|
|
151
|
+
const reexportContainers = enclosingDeclaration !== undefined ? getAlternativeContainingModules(c, symbol, enclosingDeclaration) : [];
|
|
152
|
+
const objectLiteralContainer = getVariableDeclarationOfObjectLiteral(c, container, meaning);
|
|
153
|
+
const leftMeaning = getQualifiedLeftMeaning(meaning);
|
|
154
|
+
if (enclosingDeclaration !== undefined &&
|
|
155
|
+
(container.flags & leftMeaning) !== 0 &&
|
|
156
|
+
getAccessibleSymbolChain(c, container, enclosingDeclaration, 1920 /* SymbolFlags.Namespace */, false).length > 0) {
|
|
157
|
+
// Prefer the real container when it's in scope.
|
|
158
|
+
const result = [container];
|
|
159
|
+
for (const s of additionalContainers)
|
|
160
|
+
result.push(s);
|
|
161
|
+
for (const s of reexportContainers)
|
|
162
|
+
result.push(s);
|
|
163
|
+
if (objectLiteralContainer !== undefined)
|
|
164
|
+
result.push(objectLiteralContainer);
|
|
165
|
+
return result;
|
|
166
|
+
}
|
|
167
|
+
// A member of an instance type may be reached through a variable of that type, as
|
|
168
|
+
// `Symbol.toStringTag` through the `Symbol` variable.
|
|
169
|
+
const variableMatches = [];
|
|
170
|
+
if (meaning === 111551 /* SymbolFlags.Value */ &&
|
|
171
|
+
(container.flags & leftMeaning) === 0 &&
|
|
172
|
+
(container.flags & 788968 /* SymbolFlags.Type */) !== 0 &&
|
|
173
|
+
(getDeclaredTypeOfSymbol(c, container).flags & 1048576 /* TypeFlags.Object */) !== 0) {
|
|
174
|
+
const declaredType = getDeclaredTypeOfSymbol(c, container);
|
|
175
|
+
someSymbolTableInScope(c, enclosingDeclaration, (table) => {
|
|
176
|
+
let found = false;
|
|
177
|
+
for (const s of table.values()) {
|
|
178
|
+
if ((s.flags & leftMeaning) !== 0 && getTypeOfSymbol(c, s) === declaredType) {
|
|
179
|
+
variableMatches.push(s);
|
|
180
|
+
found = true;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
return found;
|
|
184
|
+
});
|
|
185
|
+
variableMatches.sort((a, b) => compareSymbols(c, a, b));
|
|
186
|
+
}
|
|
187
|
+
const result = variableMatches;
|
|
188
|
+
for (const s of additionalContainers)
|
|
189
|
+
result.push(s);
|
|
190
|
+
result.push(container);
|
|
191
|
+
if (objectLiteralContainer !== undefined)
|
|
192
|
+
result.push(objectLiteralContainer);
|
|
193
|
+
for (const s of reexportContainers)
|
|
194
|
+
result.push(s);
|
|
195
|
+
return result;
|
|
196
|
+
}
|
|
197
|
+
/** Modules other than its own that export `symbol`: first those `enclosingDeclaration`'s file imports. */
|
|
198
|
+
function getAlternativeContainingModules(c, symbol, enclosingDeclaration) {
|
|
199
|
+
const containingFile = getSourceFileOfNode(enclosingDeclaration);
|
|
200
|
+
const fileId = getNodeId(containingFile);
|
|
201
|
+
const symbolId = getSymbolId(symbol);
|
|
202
|
+
const cache = caches(c);
|
|
203
|
+
let byFile = cache.containersByFile.get(symbolId);
|
|
204
|
+
if (byFile === undefined) {
|
|
205
|
+
byFile = new Map();
|
|
206
|
+
cache.containersByFile.set(symbolId, byFile);
|
|
207
|
+
}
|
|
208
|
+
const existing = byFile.get(fileId);
|
|
209
|
+
if (existing !== undefined && existing.length > 0)
|
|
210
|
+
return existing;
|
|
211
|
+
const results = [];
|
|
212
|
+
if (containingFile.imports.length > 0) {
|
|
213
|
+
for (const importRef of containingFile.imports) {
|
|
214
|
+
// Synthesized specifiers can't be resolved.
|
|
215
|
+
if ((importRef.flags & 16 /* NodeFlags.Synthesized */) !== 0)
|
|
216
|
+
continue;
|
|
217
|
+
const resolvedModule = resolveExternalModuleName(c, enclosingDeclaration, importRef, true);
|
|
218
|
+
if (resolvedModule === undefined)
|
|
219
|
+
continue;
|
|
220
|
+
if (getAliasForSymbolInContainer(c, resolvedModule, symbol) === undefined)
|
|
221
|
+
continue;
|
|
222
|
+
results.push(resolvedModule);
|
|
223
|
+
}
|
|
224
|
+
if (results.length > 0) {
|
|
225
|
+
byFile.set(fileId, results);
|
|
226
|
+
return results;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
const cached = cache.containers.get(symbolId);
|
|
230
|
+
if (cached !== undefined)
|
|
231
|
+
return cached;
|
|
232
|
+
// Search every module; independent of the location.
|
|
233
|
+
const containers = getExternalModuleContainers(c, symbol);
|
|
234
|
+
cache.containers.set(symbolId, containers);
|
|
235
|
+
return containers;
|
|
236
|
+
}
|
|
237
|
+
/** The modules that export `symbol`, and its parent module, in program order. */
|
|
238
|
+
function getExternalModuleContainers(c, symbol) {
|
|
239
|
+
const cache = caches(c);
|
|
240
|
+
if (cache.externalModuleContainers === undefined)
|
|
241
|
+
buildExternalModuleContainerIndex(c);
|
|
242
|
+
const index = cache.externalModuleContainers;
|
|
243
|
+
// Re-entered from an alias resolved while building the index, or too many files to index.
|
|
244
|
+
if (!index.complete)
|
|
245
|
+
return scanExternalModuleContainers(c, symbol);
|
|
246
|
+
// The parent module contains the symbol even when the symbol is absent from its exports.
|
|
247
|
+
const parent = getParentOfSymbol(c, symbol);
|
|
248
|
+
let parentIndex = externalModuleFileIndex(c, parent);
|
|
249
|
+
const result = [];
|
|
250
|
+
const target = getResolvedTarget(c, symbol);
|
|
251
|
+
if (target !== undefined) {
|
|
252
|
+
const keys = index.keys;
|
|
253
|
+
const first = getSymbolId(target) * fileIndexScale;
|
|
254
|
+
let low = 0;
|
|
255
|
+
let high = keys.length;
|
|
256
|
+
while (low < high) {
|
|
257
|
+
const mid = (low + high) >>> 1;
|
|
258
|
+
if (keys[mid] < first)
|
|
259
|
+
low = mid + 1;
|
|
260
|
+
else
|
|
261
|
+
high = mid;
|
|
262
|
+
}
|
|
263
|
+
for (let i = low; i < keys.length && keys[i] < first + fileIndexScale; i++) {
|
|
264
|
+
const fileIndex = keys[i] - first;
|
|
265
|
+
if (parentIndex >= 0 && parentIndex <= fileIndex) {
|
|
266
|
+
if (parentIndex < fileIndex)
|
|
267
|
+
result.push(parent);
|
|
268
|
+
parentIndex = -1;
|
|
269
|
+
}
|
|
270
|
+
// `as`: scriptc passes an element of a subclass array only as that class.
|
|
271
|
+
result.push(getSymbolOfDeclaration(c, c.files[fileIndex]));
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
if (parentIndex >= 0)
|
|
275
|
+
result.push(parent);
|
|
276
|
+
return result;
|
|
277
|
+
}
|
|
278
|
+
/** The position in `Checker.files` of the external module `symbol`, or -1 for any other symbol. */
|
|
279
|
+
function externalModuleFileIndex(c, symbol) {
|
|
280
|
+
if (symbol === undefined || (symbol.flags & 512 /* SymbolFlags.ValueModule */) === 0)
|
|
281
|
+
return -1;
|
|
282
|
+
for (const declaration of getDeclarations(symbol)) {
|
|
283
|
+
if (declaration.kind !== 307 /* SyntaxKind.SourceFile */)
|
|
284
|
+
continue;
|
|
285
|
+
const file = declaration;
|
|
286
|
+
if (isExternalModule(file) && getSymbolOfDeclaration(c, declaration) === symbol)
|
|
287
|
+
return c.fileIndex.get(file) ?? -1;
|
|
288
|
+
}
|
|
289
|
+
return -1;
|
|
290
|
+
}
|
|
291
|
+
function buildExternalModuleContainerIndex(c) {
|
|
292
|
+
const index = new ExternalModuleContainerIndex();
|
|
293
|
+
caches(c).externalModuleContainers = index;
|
|
294
|
+
if (c.files.length > fileIndexScale)
|
|
295
|
+
return;
|
|
296
|
+
const keys = [];
|
|
297
|
+
for (let fileIndex = 0; fileIndex < c.files.length; fileIndex++) {
|
|
298
|
+
const file = c.files[fileIndex];
|
|
299
|
+
if (!isExternalModule(file))
|
|
300
|
+
continue;
|
|
301
|
+
// `as`: scriptc passes an element of a subclass array only as that class.
|
|
302
|
+
const container = getSymbolOfDeclaration(c, file);
|
|
303
|
+
if (container === undefined)
|
|
304
|
+
continue;
|
|
305
|
+
for (const exported of getExportsOfSymbol(c, container).values()) {
|
|
306
|
+
const target = getResolvedTarget(c, exported);
|
|
307
|
+
if (target !== undefined)
|
|
308
|
+
keys.push(getSymbolId(target) * fileIndexScale + fileIndex);
|
|
309
|
+
}
|
|
310
|
+
const exportEquals = container.exports?.get("export=" /* InternalSymbolName.ExportEquals */);
|
|
311
|
+
const target = exportEquals !== undefined ? getResolvedTarget(c, exportEquals) : undefined;
|
|
312
|
+
if (target !== undefined)
|
|
313
|
+
keys.push(getSymbolId(target) * fileIndexScale + fileIndex);
|
|
314
|
+
}
|
|
315
|
+
keys.sort((a, b) => a - b);
|
|
316
|
+
// A module that exports a symbol under several names gives it one key.
|
|
317
|
+
let kept = 0;
|
|
318
|
+
for (let i = 0; i < keys.length; i++)
|
|
319
|
+
if (kept === 0 || keys[i] !== keys[kept - 1])
|
|
320
|
+
keys[kept++] = keys[i];
|
|
321
|
+
// An exact-size copy: each checker keeps its own index for the rest of the compilation.
|
|
322
|
+
index.keys = keys.slice(0, kept);
|
|
323
|
+
index.complete = true;
|
|
324
|
+
}
|
|
325
|
+
/** The modules that export `symbol`, found by checking every module. */
|
|
326
|
+
function scanExternalModuleContainers(c, symbol) {
|
|
327
|
+
const containers = [];
|
|
328
|
+
for (const file of c.host.getSourceFiles()) {
|
|
329
|
+
if (!isExternalModule(file))
|
|
330
|
+
continue;
|
|
331
|
+
// `as`: scriptc passes a for-of element of a subclass array only as that class.
|
|
332
|
+
const container = getSymbolOfDeclaration(c, file);
|
|
333
|
+
if (container !== undefined && getAliasForSymbolInContainer(c, container, symbol) !== undefined)
|
|
334
|
+
containers.push(container);
|
|
335
|
+
}
|
|
336
|
+
return containers;
|
|
337
|
+
}
|
|
338
|
+
/** The variable `var a = { x: 1 }` declares, for the anonymous `__object` symbol of its literal. */
|
|
339
|
+
function getVariableDeclarationOfObjectLiteral(c, symbol, meaning) {
|
|
340
|
+
if ((meaning & 111551 /* SymbolFlags.Value */) === 0 || declarationCount(symbol) === 0)
|
|
341
|
+
return undefined;
|
|
342
|
+
const firstDecl = symbol.declaration;
|
|
343
|
+
const parent = firstDecl.parent;
|
|
344
|
+
if (parent === undefined || !(parent instanceof VariableDeclaration))
|
|
345
|
+
return undefined;
|
|
346
|
+
if ((firstDecl.kind === 211 /* SyntaxKind.ObjectLiteralExpression */ && firstDecl === getInitializer(parent)) ||
|
|
347
|
+
(firstDecl.kind === 188 /* SyntaxKind.TypeLiteral */ && firstDecl === getType(parent)))
|
|
348
|
+
return getSymbolOfDeclaration(c, parent);
|
|
349
|
+
return undefined;
|
|
350
|
+
}
|
|
351
|
+
function hasExternalModuleSymbol(declaration) {
|
|
352
|
+
return (isAmbientModule(declaration) ||
|
|
353
|
+
(declaration.kind === 307 /* SyntaxKind.SourceFile */ && isExternalOrCommonJSModule(declaration)));
|
|
354
|
+
}
|
|
355
|
+
function getExternalModuleContainer(c, declaration) {
|
|
356
|
+
for (let node = declaration; node !== undefined; node = node.parent)
|
|
357
|
+
if (hasExternalModuleSymbol(node))
|
|
358
|
+
return getSymbolOfDeclaration(c, node);
|
|
359
|
+
return undefined;
|
|
360
|
+
}
|
|
361
|
+
/** The module of `d` if its `export =` names `container`. */
|
|
362
|
+
export function getFileSymbolIfFileSymbolExportEqualsContainer(c, d, container) {
|
|
363
|
+
const fileSymbol = getExternalModuleContainer(c, d);
|
|
364
|
+
if (fileSymbol === undefined || fileSymbol.exports === undefined)
|
|
365
|
+
return undefined;
|
|
366
|
+
const exported = fileSymbol.exports.get("export=" /* InternalSymbolName.ExportEquals */);
|
|
367
|
+
if (exported === undefined)
|
|
368
|
+
return undefined;
|
|
369
|
+
return getSymbolIfSameReference(c, exported, container) !== undefined ? fileSymbol : undefined;
|
|
370
|
+
}
|
|
371
|
+
/** The symbols `symbol` can be reached through: usually its parent, else the modules exporting a local. */
|
|
372
|
+
export function getContainersOfSymbol(c, symbol, enclosingDeclaration, meaning) {
|
|
373
|
+
const container = getParentOfSymbol(c, symbol);
|
|
374
|
+
// Type parameters are in `members` but not visible outside.
|
|
375
|
+
if (container !== undefined && (symbol.flags & 262144 /* SymbolFlags.TypeParameter */) === 0)
|
|
376
|
+
return getWithAlternativeContainers(c, container, symbol, enclosingDeclaration, meaning);
|
|
377
|
+
const candidates = [];
|
|
378
|
+
const addCandidate = (s) => {
|
|
379
|
+
if (s !== undefined && candidates.indexOf(s) < 0)
|
|
380
|
+
candidates.push(s);
|
|
381
|
+
};
|
|
382
|
+
for (const d of getDeclarations(symbol)) {
|
|
383
|
+
const parent = d.parent;
|
|
384
|
+
if (!isAmbientModule(d) && parent !== undefined) {
|
|
385
|
+
// A direct child of a module.
|
|
386
|
+
if (hasNonGlobalAugmentationExternalModuleSymbol(parent)) {
|
|
387
|
+
addCandidate(getSymbolOfDeclaration(c, parent));
|
|
388
|
+
continue;
|
|
389
|
+
}
|
|
390
|
+
// The `export =` of an ambient module.
|
|
391
|
+
if (parent.kind === 269 /* SyntaxKind.ModuleBlock */ &&
|
|
392
|
+
parent.parent !== undefined &&
|
|
393
|
+
resolveExternalModuleSymbol(c, getSymbolOfDeclaration(c, parent.parent), false) === symbol) {
|
|
394
|
+
addCandidate(getSymbolOfDeclaration(c, parent.parent));
|
|
395
|
+
continue;
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
if (d instanceof ClassExpression && parent instanceof BinaryExpression) {
|
|
399
|
+
const left = parent.left;
|
|
400
|
+
if (parent.operatorToken.kind !== 63 /* SyntaxKind.EqualsToken */ || !isAccessExpression(left))
|
|
401
|
+
continue;
|
|
402
|
+
const target = getExpression(left);
|
|
403
|
+
if (!isEntityNameExpression(target, false))
|
|
404
|
+
continue;
|
|
405
|
+
if (isModuleExportsAccessExpression(left) || isExportsIdentifier(target)) {
|
|
406
|
+
addCandidate(getSymbolOfDeclaration(c, getSourceFileOfNode(d)));
|
|
407
|
+
continue;
|
|
408
|
+
}
|
|
409
|
+
checkExpressionCached(c, target);
|
|
410
|
+
addCandidate(c.resolvedSymbols.get(target.id));
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
if (candidates.length === 0)
|
|
414
|
+
return [];
|
|
415
|
+
const best = [];
|
|
416
|
+
const alternatives = [];
|
|
417
|
+
for (const candidate of candidates) {
|
|
418
|
+
if (getAliasForSymbolInContainer(c, candidate, symbol) === undefined)
|
|
419
|
+
continue;
|
|
420
|
+
const all = getWithAlternativeContainers(c, candidate, symbol, enclosingDeclaration, meaning);
|
|
421
|
+
if (all.length === 0)
|
|
422
|
+
continue;
|
|
423
|
+
best.push(all[0]);
|
|
424
|
+
for (let i = 1; i < all.length; i++)
|
|
425
|
+
alternatives.push(all[i]);
|
|
426
|
+
}
|
|
427
|
+
for (const s of alternatives)
|
|
428
|
+
best.push(s);
|
|
429
|
+
return best;
|
|
430
|
+
}
|
|
431
|
+
/** The export of `container` that names `symbol`, if any. */
|
|
432
|
+
export function getAliasForSymbolInContainer(c, container, symbol) {
|
|
433
|
+
// The fast path: `symbol` is already the export.
|
|
434
|
+
if (container === getParentOfSymbol(c, symbol))
|
|
435
|
+
return symbol;
|
|
436
|
+
// A module whose `export =` is the symbol stands for it.
|
|
437
|
+
if (container.exports !== undefined) {
|
|
438
|
+
const exportEquals = container.exports.get("export=" /* InternalSymbolName.ExportEquals */);
|
|
439
|
+
if (exportEquals !== undefined && getSymbolIfSameReference(c, exportEquals, symbol) !== undefined)
|
|
440
|
+
return container;
|
|
441
|
+
}
|
|
442
|
+
const exports = getExportsOfSymbol(c, container);
|
|
443
|
+
const quick = exports.get(symbol.name);
|
|
444
|
+
if (quick !== undefined && getSymbolIfSameReference(c, quick, symbol) !== undefined)
|
|
445
|
+
return quick;
|
|
446
|
+
const candidates = [];
|
|
447
|
+
for (const exported of exports.values())
|
|
448
|
+
if (getSymbolIfSameReference(c, exported, symbol) !== undefined)
|
|
449
|
+
candidates.push(exported);
|
|
450
|
+
if (candidates.length === 0)
|
|
451
|
+
return undefined;
|
|
452
|
+
candidates.sort((a, b) => compareSymbols(c, a, b));
|
|
453
|
+
return candidates[0];
|
|
454
|
+
}
|
|
455
|
+
// ---- Accessible symbol chains
|
|
456
|
+
/** One search for the chain of names reaching a symbol. */
|
|
457
|
+
class ChainSearch {
|
|
458
|
+
c;
|
|
459
|
+
symbol;
|
|
460
|
+
enclosingDeclaration;
|
|
461
|
+
meaning;
|
|
462
|
+
useOnlyExternalAliasing;
|
|
463
|
+
/** Tables being searched, by symbol id, to stop cycles through exports. */
|
|
464
|
+
visitedTables;
|
|
465
|
+
constructor(c, symbol, enclosingDeclaration, meaning, useOnlyExternalAliasing, visitedTables) {
|
|
466
|
+
this.c = c;
|
|
467
|
+
this.symbol = symbol;
|
|
468
|
+
this.enclosingDeclaration = enclosingDeclaration;
|
|
469
|
+
this.meaning = meaning;
|
|
470
|
+
this.useOnlyExternalAliasing = useOnlyExternalAliasing;
|
|
471
|
+
this.visitedTables = visitedTables;
|
|
472
|
+
}
|
|
473
|
+
run() {
|
|
474
|
+
const c = this.c;
|
|
475
|
+
if (isPropertyOrMethodDeclarationSymbol(this.symbol))
|
|
476
|
+
return [];
|
|
477
|
+
// Key the cache by the first scope searched so it's shared more.
|
|
478
|
+
let firstRelevantLocation = undefined;
|
|
479
|
+
someSymbolTableInScope(c, this.enclosingDeclaration, (_table, _id, _isLocal, node) => {
|
|
480
|
+
firstRelevantLocation = node;
|
|
481
|
+
return true;
|
|
482
|
+
});
|
|
483
|
+
const symbolId = getSymbolId(this.symbol);
|
|
484
|
+
const cache = caches(c);
|
|
485
|
+
let byKey = cache.accessibleChains.get(symbolId);
|
|
486
|
+
if (byKey === undefined) {
|
|
487
|
+
byKey = new Map();
|
|
488
|
+
cache.accessibleChains.set(symbolId, byKey);
|
|
489
|
+
}
|
|
490
|
+
// `!`: scriptc keeps the callback's optional scope optional after narrowing.
|
|
491
|
+
const location = firstRelevantLocation;
|
|
492
|
+
const key = (this.useOnlyExternalAliasing ? '1:' : '0:') +
|
|
493
|
+
(location === undefined ? 0 : getNodeId(location)) +
|
|
494
|
+
':' +
|
|
495
|
+
this.meaning;
|
|
496
|
+
const existing = byKey.get(key);
|
|
497
|
+
if (existing !== undefined)
|
|
498
|
+
return existing;
|
|
499
|
+
let result = [];
|
|
500
|
+
someSymbolTableInScope(c, this.enclosingDeclaration, (table, id, isLocalNameLookup) => {
|
|
501
|
+
const found = this.fromSymbolTable(table, id, false, isLocalNameLookup);
|
|
502
|
+
if (found.length > 0) {
|
|
503
|
+
result = found;
|
|
504
|
+
return true;
|
|
505
|
+
}
|
|
506
|
+
return false;
|
|
507
|
+
});
|
|
508
|
+
byKey.set(key, result);
|
|
509
|
+
return result;
|
|
510
|
+
}
|
|
511
|
+
/** `ignoreQualification`: looking through another symbol's exports, which qualify the name already. */
|
|
512
|
+
fromSymbolTable(table, id, ignoreQualification, isLocalNameLookup) {
|
|
513
|
+
const symbolId = getSymbolId(this.symbol);
|
|
514
|
+
let visited = this.visitedTables.get(symbolId);
|
|
515
|
+
if (visited === undefined) {
|
|
516
|
+
visited = new Set();
|
|
517
|
+
this.visitedTables.set(symbolId, visited);
|
|
518
|
+
}
|
|
519
|
+
if (visited.has(id))
|
|
520
|
+
return [];
|
|
521
|
+
visited.add(id);
|
|
522
|
+
const result = this.trySymbolTable(table, id, ignoreQualification, isLocalNameLookup);
|
|
523
|
+
visited.delete(id);
|
|
524
|
+
return result;
|
|
525
|
+
}
|
|
526
|
+
trySymbolTable(table, id, ignoreQualification, isLocalNameLookup) {
|
|
527
|
+
const c = this.c;
|
|
528
|
+
const symbol = this.symbol;
|
|
529
|
+
// Directly available by its name.
|
|
530
|
+
const direct = table.get(symbol.name);
|
|
531
|
+
if (direct !== undefined && this.isAccessible(direct, undefined, ignoreQualification))
|
|
532
|
+
return [symbol];
|
|
533
|
+
const candidateChains = [];
|
|
534
|
+
if (direct !== undefined && direct.exportSymbol !== undefined) {
|
|
535
|
+
if (this.isAccessible(getMergedSymbol(c, direct.exportSymbol), undefined, ignoreQualification))
|
|
536
|
+
candidateChains.push([symbol]);
|
|
537
|
+
}
|
|
538
|
+
for (const fromTable of getSymbolTableAliases(c, table, id)) {
|
|
539
|
+
// Any non-default, non-`export =` alias in scope may name the symbol or chain to it.
|
|
540
|
+
if (fromTable.name === "export=" /* InternalSymbolName.ExportEquals */ ||
|
|
541
|
+
fromTable.name === "default" /* InternalSymbolName.Default */ ||
|
|
542
|
+
(isUMDExportSymbol(fromTable) &&
|
|
543
|
+
this.enclosingDeclaration !== undefined &&
|
|
544
|
+
isExternalModule(getSourceFileOfNode(this.enclosingDeclaration))) ||
|
|
545
|
+
(this.useOnlyExternalAliasing && !hasExternalModuleImportEqualsDeclaration(fromTable)) ||
|
|
546
|
+
(isLocalNameLookup && hasNamespaceReexportDeclaration(fromTable)) ||
|
|
547
|
+
// Exports are in scope, but export specifiers aren't.
|
|
548
|
+
(!ignoreQualification && getDeclarations(fromTable).some((d) => d.kind === 282 /* SyntaxKind.ExportSpecifier */)))
|
|
549
|
+
continue;
|
|
550
|
+
const resolved = resolveAlias(c, fromTable);
|
|
551
|
+
const candidate = this.candidateListForSymbol(fromTable, resolved, ignoreQualification);
|
|
552
|
+
if (candidate.length > 0)
|
|
553
|
+
candidateChains.push(candidate);
|
|
554
|
+
}
|
|
555
|
+
if (candidateChains.length > 0) {
|
|
556
|
+
// The first of the shortest.
|
|
557
|
+
let best = candidateChains[0];
|
|
558
|
+
for (let i = 1; i < candidateChains.length; i++)
|
|
559
|
+
if (compareSymbolChains(c, candidateChains[i], best) < 0)
|
|
560
|
+
best = candidateChains[i];
|
|
561
|
+
return best;
|
|
562
|
+
}
|
|
563
|
+
// Treat `globalThis` like an alias in the global table.
|
|
564
|
+
if (tableKindOf(id) === 4 /* TableKind.Globals */)
|
|
565
|
+
return this.candidateListForSymbol(c.globalThisSymbol, c.globalThisSymbol, ignoreQualification);
|
|
566
|
+
return [];
|
|
567
|
+
}
|
|
568
|
+
candidateListForSymbol(fromTable, resolved, ignoreQualification) {
|
|
569
|
+
if (this.isAccessible(fromTable, resolved, ignoreQualification))
|
|
570
|
+
return [fromTable];
|
|
571
|
+
// Reachable through the exports of `fromTable`, if `fromTable` can be qualified.
|
|
572
|
+
const candidateTable = getExportsOfSymbol(this.c, resolved);
|
|
573
|
+
const fromExports = this.fromSymbolTable(candidateTable, tableId(5 /* TableKind.ResolvedExports */, getSymbolId(resolved)), true, false);
|
|
574
|
+
if (fromExports.length === 0)
|
|
575
|
+
return [];
|
|
576
|
+
if (!this.canQualifySymbol(fromTable, getQualifiedLeftMeaning(this.meaning)))
|
|
577
|
+
return [];
|
|
578
|
+
return [fromTable].concat(fromExports);
|
|
579
|
+
}
|
|
580
|
+
isAccessible(fromTable, resolvedAlias, ignoreQualification) {
|
|
581
|
+
const c = this.c;
|
|
582
|
+
const symbol = getMergedSymbol(c, this.symbol);
|
|
583
|
+
const likeSymbols = this.symbol === resolvedAlias ||
|
|
584
|
+
this.symbol === fromTable ||
|
|
585
|
+
(resolvedAlias !== undefined && symbol === getMergedSymbol(c, resolvedAlias)) ||
|
|
586
|
+
symbol === getMergedSymbol(c, fromTable);
|
|
587
|
+
if (!likeSymbols)
|
|
588
|
+
return false;
|
|
589
|
+
// An external module in the global table isn't accessible by name; otherwise the name must be qualifiable.
|
|
590
|
+
return (!hasNonGlobalAugmentationExternalModuleDeclaration(fromTable) &&
|
|
591
|
+
(ignoreQualification || this.canQualifySymbol(getMergedSymbol(c, fromTable), this.meaning)));
|
|
592
|
+
}
|
|
593
|
+
canQualifySymbol(fromTable, meaning) {
|
|
594
|
+
const c = this.c;
|
|
595
|
+
if (!needsQualification(c, fromTable, this.enclosingDeclaration, meaning))
|
|
596
|
+
return true;
|
|
597
|
+
// Qualified through its parent, if the parent is accessible.
|
|
598
|
+
const parent = fromTable.parent;
|
|
599
|
+
if (parent === undefined)
|
|
600
|
+
return false;
|
|
601
|
+
return (new ChainSearch(c, parent, this.enclosingDeclaration, getQualifiedLeftMeaning(meaning), this.useOnlyExternalAliasing, this.visitedTables).run().length > 0);
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
/** The shortest chain of names reaching `symbol` from `enclosingDeclaration`, or empty if none. */
|
|
605
|
+
export function getAccessibleSymbolChain(c, symbol, enclosingDeclaration, meaning, useOnlyExternalAliasing) {
|
|
606
|
+
if (symbol === undefined)
|
|
607
|
+
return [];
|
|
608
|
+
return new ChainSearch(c, symbol, enclosingDeclaration, meaning, useOnlyExternalAliasing, new Map()).run();
|
|
609
|
+
}
|
|
610
|
+
/** The alias symbols of a table; cached for globals and exports, which are large and revisited. */
|
|
611
|
+
function getSymbolTableAliases(c, table, id) {
|
|
612
|
+
const kind = tableKindOf(id);
|
|
613
|
+
// Members tables only hold types, never aliases.
|
|
614
|
+
if (kind === 3 /* TableKind.Members */)
|
|
615
|
+
return [];
|
|
616
|
+
const cacheable = kind === 4 /* TableKind.Globals */ || kind === 2 /* TableKind.Exports */ || kind === 5 /* TableKind.ResolvedExports */;
|
|
617
|
+
const cache = caches(c);
|
|
618
|
+
if (cacheable) {
|
|
619
|
+
const cached = cache.tableAliases.get(id);
|
|
620
|
+
if (cached !== undefined)
|
|
621
|
+
return cached;
|
|
622
|
+
}
|
|
623
|
+
const aliases = [];
|
|
624
|
+
for (const s of table.values())
|
|
625
|
+
if ((s.flags & 2097152 /* SymbolFlags.Alias */) !== 0)
|
|
626
|
+
aliases.push(s);
|
|
627
|
+
if (cacheable)
|
|
628
|
+
cache.tableAliases.set(id, aliases);
|
|
629
|
+
return aliases;
|
|
630
|
+
}
|
|
631
|
+
function compareSymbolChains(c, a, b) {
|
|
632
|
+
if (a.length !== b.length)
|
|
633
|
+
return a.length - b.length;
|
|
634
|
+
for (let i = 0; i < a.length; i++) {
|
|
635
|
+
const comparison = compareSymbols(c, a[i], b[i]);
|
|
636
|
+
if (comparison !== 0)
|
|
637
|
+
return comparison;
|
|
638
|
+
}
|
|
639
|
+
return 0;
|
|
640
|
+
}
|
|
641
|
+
function isUMDExportSymbol(symbol) {
|
|
642
|
+
return declarationCount(symbol) > 0 && symbol.declaration.kind === 271 /* SyntaxKind.NamespaceExportDeclaration */;
|
|
643
|
+
}
|
|
644
|
+
function hasNamespaceReexportDeclaration(symbol) {
|
|
645
|
+
for (const d of getDeclarations(symbol))
|
|
646
|
+
if (isNamespaceReexportDeclaration(d))
|
|
647
|
+
return true;
|
|
648
|
+
return false;
|
|
649
|
+
}
|
|
650
|
+
function isNamespaceReexportDeclaration(node) {
|
|
651
|
+
return (node.kind === 281 /* SyntaxKind.NamespaceExport */ &&
|
|
652
|
+
node.parent instanceof ExportDeclaration &&
|
|
653
|
+
node.parent.moduleSpecifier !== undefined);
|
|
654
|
+
}
|
|
655
|
+
function hasExternalModuleImportEqualsDeclaration(symbol) {
|
|
656
|
+
for (const d of getDeclarations(symbol))
|
|
657
|
+
if (isExternalModuleImportEqualsDeclaration(d))
|
|
658
|
+
return true;
|
|
659
|
+
return false;
|
|
660
|
+
}
|
|
661
|
+
function isExternalModuleImportEqualsDeclaration(node) {
|
|
662
|
+
return node instanceof ImportEqualsDeclaration && node.moduleReference.kind === 284 /* SyntaxKind.ExternalModuleReference */;
|
|
663
|
+
}
|
|
664
|
+
/** Whether another symbol of the same name and meaning shadows `symbol` at `enclosingDeclaration`. */
|
|
665
|
+
export function needsQualification(c, symbol, enclosingDeclaration, meaning) {
|
|
666
|
+
let qualify = false;
|
|
667
|
+
someSymbolTableInScope(c, enclosingDeclaration, (table) => {
|
|
668
|
+
const found = table.get(symbol.name);
|
|
669
|
+
if (found === undefined)
|
|
670
|
+
return false;
|
|
671
|
+
let fromTable = getMergedSymbol(c, found);
|
|
672
|
+
if (fromTable === symbol)
|
|
673
|
+
return true;
|
|
674
|
+
// Qualify if the symbol of this name has the meaning sought.
|
|
675
|
+
const shouldResolveAlias = (fromTable.flags & 2097152 /* SymbolFlags.Alias */) !== 0 &&
|
|
676
|
+
!getDeclarations(fromTable).some((d) => d.kind === 282 /* SyntaxKind.ExportSpecifier */);
|
|
677
|
+
if (shouldResolveAlias)
|
|
678
|
+
fromTable = resolveAlias(c, fromTable);
|
|
679
|
+
const flags = shouldResolveAlias ? getSymbolFlags(c, fromTable) : fromTable.flags;
|
|
680
|
+
if ((flags & meaning) !== 0) {
|
|
681
|
+
qualify = true;
|
|
682
|
+
return true;
|
|
683
|
+
}
|
|
684
|
+
return false;
|
|
685
|
+
});
|
|
686
|
+
return qualify;
|
|
687
|
+
}
|
|
688
|
+
function isPropertyOrMethodDeclarationSymbol(symbol) {
|
|
689
|
+
if (declarationCount(symbol) === 0)
|
|
690
|
+
return false;
|
|
691
|
+
for (const declaration of getDeclarations(symbol)) {
|
|
692
|
+
switch (declaration.kind) {
|
|
693
|
+
case 173 /* SyntaxKind.PropertyDeclaration */:
|
|
694
|
+
case 175 /* SyntaxKind.MethodDeclaration */:
|
|
695
|
+
case 178 /* SyntaxKind.GetAccessor */:
|
|
696
|
+
case 179 /* SyntaxKind.SetAccessor */:
|
|
697
|
+
continue;
|
|
698
|
+
default:
|
|
699
|
+
return false;
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
return true;
|
|
703
|
+
}
|
|
704
|
+
/**
|
|
705
|
+
* Calls `callback` with each symbol table in scope at `enclosingDeclaration`, innermost first and
|
|
706
|
+
* the globals last, until it returns true.
|
|
707
|
+
*/
|
|
708
|
+
export function someSymbolTableInScope(c, enclosingDeclaration, callback) {
|
|
709
|
+
for (let location = enclosingDeclaration; location !== undefined; location = location.parent) {
|
|
710
|
+
// Locals of a script are merged into the globals.
|
|
711
|
+
const locals = getLocals(location);
|
|
712
|
+
if (locals !== undefined && !isGlobalSourceFile(location)) {
|
|
713
|
+
if (callback(locals, tableId(1 /* TableKind.Locals */, getNodeId(location)), true, location))
|
|
714
|
+
return true;
|
|
715
|
+
}
|
|
716
|
+
switch (location.kind) {
|
|
717
|
+
case 307 /* SyntaxKind.SourceFile */:
|
|
718
|
+
case 268 /* SyntaxKind.ModuleDeclaration */: {
|
|
719
|
+
if (location.kind === 307 /* SyntaxKind.SourceFile */ && !isExternalOrCommonJSModule(location))
|
|
720
|
+
break;
|
|
721
|
+
const symbol = getSymbolOfDeclaration(c, location);
|
|
722
|
+
if (symbol === undefined)
|
|
723
|
+
break;
|
|
724
|
+
const exports = symbol.exports ?? emptyTable;
|
|
725
|
+
if (callback(exports, tableId(2 /* TableKind.Exports */, getSymbolId(symbol)), true, location))
|
|
726
|
+
return true;
|
|
727
|
+
break;
|
|
728
|
+
}
|
|
729
|
+
case 264 /* SyntaxKind.ClassDeclaration */:
|
|
730
|
+
case 232 /* SyntaxKind.ClassExpression */:
|
|
731
|
+
case 265 /* SyntaxKind.InterfaceDeclaration */: {
|
|
732
|
+
// Type parameters are bound in `members` so they merge across declarations, but act like
|
|
733
|
+
// locals. Raw members suffice: they're never late bound.
|
|
734
|
+
const symbol = getSymbolOfDeclaration(c, location);
|
|
735
|
+
if (symbol === undefined)
|
|
736
|
+
break;
|
|
737
|
+
let table = undefined;
|
|
738
|
+
if (symbol.members !== undefined)
|
|
739
|
+
for (const [key, member] of symbol.members) {
|
|
740
|
+
if ((member.flags & (788968 /* SymbolFlags.Type */ & ~67108864 /* SymbolFlags.Assignment */)) === 0)
|
|
741
|
+
continue;
|
|
742
|
+
if (table === undefined)
|
|
743
|
+
table = new Map();
|
|
744
|
+
table.set(key, member);
|
|
745
|
+
}
|
|
746
|
+
if (table !== undefined && callback(table, tableId(3 /* TableKind.Members */, getSymbolId(symbol)), false, location))
|
|
747
|
+
return true;
|
|
748
|
+
// A class expression's own name is in no scope table.
|
|
749
|
+
if (location instanceof ClassExpression && location.name !== undefined) {
|
|
750
|
+
const nameTable = getClassExpressionNameTable(c, location);
|
|
751
|
+
if (nameTable !== undefined &&
|
|
752
|
+
callback(nameTable, tableId(1 /* TableKind.Locals */, getNodeId(location)), true, location))
|
|
753
|
+
return true;
|
|
754
|
+
}
|
|
755
|
+
break;
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
return callback(c.globals, tableId(4 /* TableKind.Globals */, 0), true, undefined);
|
|
760
|
+
}
|
|
761
|
+
const emptyTable = new Map();
|
|
762
|
+
function getClassExpressionNameTable(c, location) {
|
|
763
|
+
const id = getNodeId(location);
|
|
764
|
+
const cache = caches(c);
|
|
765
|
+
const cached = cache.classExpressionNames.get(id);
|
|
766
|
+
if (cached !== undefined)
|
|
767
|
+
return cached;
|
|
768
|
+
const classSymbol = getSymbolOfDeclaration(c, location);
|
|
769
|
+
const nameText = location.name === undefined ? '' : getText(location.name);
|
|
770
|
+
if (nameText.length === 0 || classSymbol === undefined)
|
|
771
|
+
return undefined;
|
|
772
|
+
const table = new Map();
|
|
773
|
+
table.set(nameText, classSymbol);
|
|
774
|
+
cache.classExpressionNames.set(id, table);
|
|
775
|
+
return table;
|
|
776
|
+
}
|
|
777
|
+
// ---- Declaration visibility
|
|
778
|
+
/**
|
|
779
|
+
* Whether a declaration is visible outside its file: exported, global, or part of a visible declaration.
|
|
780
|
+
*
|
|
781
|
+
* tsgo caches this per checker and lets declaration emit mark declarations visible. Only marks made
|
|
782
|
+
* while emitting files of the current checker slot count (see beginDeclarationEmitVisibility), and
|
|
783
|
+
* leaving a slot forgets the cached visibility of the declarations it marked. Rather than undoing and
|
|
784
|
+
* redoing those marks at every file, a node keeps the slots it was marked in, and a cached result is
|
|
785
|
+
* stale if one of those slots was left after it was computed.
|
|
786
|
+
*/
|
|
787
|
+
export function isDeclarationVisible(c, node) {
|
|
788
|
+
if ((node.flags & 16 /* NodeFlags.Synthesized */) !== 0)
|
|
789
|
+
return false;
|
|
790
|
+
const cache = caches(c);
|
|
791
|
+
const id = getNodeId(node);
|
|
792
|
+
const marks = cache.markedSlots.get(id);
|
|
793
|
+
if ((marks & slotBit(cache.markedSlot)) !== 0)
|
|
794
|
+
return true;
|
|
795
|
+
const cached = cache.declarationVisibility.get(id);
|
|
796
|
+
if (cached !== 0 && (marks === 0 || !leftSince(cache.slotsLeftAt, marks, cached >> 2)))
|
|
797
|
+
return (cached & 1) !== 0;
|
|
798
|
+
const visible = determineIfDeclarationIsVisible(c, node);
|
|
799
|
+
// Bit 0 is the result, bit 1 marks the entry computed, the rest is the epoch it was computed in.
|
|
800
|
+
cache.declarationVisibility.set(id, (cache.visibilityEpoch << 2) | 2 | (visible ? 1 : 0));
|
|
801
|
+
return visible;
|
|
802
|
+
}
|
|
803
|
+
/** The bit of a checker slot (-1 before declaration emit) in `markedSlots`. */
|
|
804
|
+
function slotBit(slot) {
|
|
805
|
+
return 1 << (slot + 1);
|
|
806
|
+
}
|
|
807
|
+
/** Whether one of the slots in `marks` was left after `epoch`. */
|
|
808
|
+
function leftSince(slotsLeftAt, marks, epoch) {
|
|
809
|
+
for (let index = 0; index < slotsLeftAt.length; index++)
|
|
810
|
+
if ((marks & (1 << index)) !== 0 && slotsLeftAt[index] > epoch)
|
|
811
|
+
return true;
|
|
812
|
+
return false;
|
|
813
|
+
}
|
|
814
|
+
export function markDeclarationVisible(c, node) {
|
|
815
|
+
const cache = caches(c);
|
|
816
|
+
const id = getNodeId(node);
|
|
817
|
+
cache.markedSlots.set(id, cache.markedSlots.get(id) | slotBit(cache.markedSlot));
|
|
818
|
+
}
|
|
819
|
+
/** Checkers tsgo spreads a program's files over, round robin. */
|
|
820
|
+
const checkerCount = 4;
|
|
821
|
+
/** The number of checkers tsgo spreads the program's files over: file `i` goes to checker `i % n`. */
|
|
822
|
+
export function tsgoCheckerSlots(c) {
|
|
823
|
+
return Math.max(1, Math.min(checkerCount, c.files.length));
|
|
824
|
+
}
|
|
825
|
+
/**
|
|
826
|
+
* Starts the declaration emit of `file`. tsgo emits each file with one of its checkers, so only
|
|
827
|
+
* declarations marked visible while emitting files of the same checker stay marked.
|
|
828
|
+
*/
|
|
829
|
+
export function beginDeclarationEmitVisibility(c, file) {
|
|
830
|
+
const cache = caches(c);
|
|
831
|
+
const index = c.fileIndex.get(file);
|
|
832
|
+
const slot = index === undefined ? -1 : index % tsgoCheckerSlots(c);
|
|
833
|
+
if (slot === cache.markedSlot)
|
|
834
|
+
return;
|
|
835
|
+
cache.visibilityEpoch++;
|
|
836
|
+
cache.slotsLeftAt[cache.markedSlot + 1] = cache.visibilityEpoch;
|
|
837
|
+
cache.markedSlot = slot;
|
|
838
|
+
}
|
|
839
|
+
function determineIfDeclarationIsVisible(c, node) {
|
|
840
|
+
switch (node.kind) {
|
|
841
|
+
case 331 /* SyntaxKind.JSDocCallbackTag */:
|
|
842
|
+
case 338 /* SyntaxKind.JSDocTypedefTag */: {
|
|
843
|
+
// Top-level JSDoc type aliases are exported.
|
|
844
|
+
const host = node.parent?.parent?.parent;
|
|
845
|
+
return host !== undefined && host.kind === 307 /* SyntaxKind.SourceFile */;
|
|
846
|
+
}
|
|
847
|
+
case 209 /* SyntaxKind.BindingElement */:
|
|
848
|
+
return isDeclarationVisible(c, node.parent.parent);
|
|
849
|
+
case 261 /* SyntaxKind.VariableDeclaration */:
|
|
850
|
+
case 268 /* SyntaxKind.ModuleDeclaration */:
|
|
851
|
+
case 264 /* SyntaxKind.ClassDeclaration */:
|
|
852
|
+
case 265 /* SyntaxKind.InterfaceDeclaration */:
|
|
853
|
+
case 266 /* SyntaxKind.TypeAliasDeclaration */:
|
|
854
|
+
case 345 /* SyntaxKind.JSTypeAliasDeclaration */:
|
|
855
|
+
case 263 /* SyntaxKind.FunctionDeclaration */:
|
|
856
|
+
case 267 /* SyntaxKind.EnumDeclaration */:
|
|
857
|
+
case 272 /* SyntaxKind.ImportEqualsDeclaration */: {
|
|
858
|
+
if (node instanceof VariableDeclaration) {
|
|
859
|
+
const name = node.name;
|
|
860
|
+
if (name instanceof BindingPattern && name.elements.nodes.length === 0)
|
|
861
|
+
return false;
|
|
862
|
+
}
|
|
863
|
+
if (isExternalModuleAugmentation(node) || isImplicitlyExportedJSDocDeclaration(node))
|
|
864
|
+
return true;
|
|
865
|
+
const parent = getDeclarationContainer(node);
|
|
866
|
+
// Unexported declarations are visible only in global files; ambient module members are exported.
|
|
867
|
+
if ((getCombinedModifierFlags(node) & 32 /* ModifierFlags.Export */) === 0 &&
|
|
868
|
+
!(node.kind !== 272 /* SyntaxKind.ImportEqualsDeclaration */ &&
|
|
869
|
+
parent.kind !== 307 /* SyntaxKind.SourceFile */ &&
|
|
870
|
+
(parent.flags & 8388608 /* NodeFlags.Ambient */) !== 0))
|
|
871
|
+
return isGlobalSourceFile(parent);
|
|
872
|
+
return isDeclarationVisible(c, parent);
|
|
873
|
+
}
|
|
874
|
+
case 173 /* SyntaxKind.PropertyDeclaration */:
|
|
875
|
+
case 172 /* SyntaxKind.PropertySignature */:
|
|
876
|
+
case 178 /* SyntaxKind.GetAccessor */:
|
|
877
|
+
case 179 /* SyntaxKind.SetAccessor */:
|
|
878
|
+
case 175 /* SyntaxKind.MethodDeclaration */:
|
|
879
|
+
case 174 /* SyntaxKind.MethodSignature */:
|
|
880
|
+
if (getEffectiveDeclarationFlags(node, 2 /* ModifierFlags.Private */ | 4 /* ModifierFlags.Protected */) !== 0)
|
|
881
|
+
return false;
|
|
882
|
+
return isDeclarationVisible(c, node.parent);
|
|
883
|
+
case 177 /* SyntaxKind.Constructor */:
|
|
884
|
+
case 181 /* SyntaxKind.ConstructSignature */:
|
|
885
|
+
case 180 /* SyntaxKind.CallSignature */:
|
|
886
|
+
case 182 /* SyntaxKind.IndexSignature */:
|
|
887
|
+
case 170 /* SyntaxKind.Parameter */:
|
|
888
|
+
case 269 /* SyntaxKind.ModuleBlock */:
|
|
889
|
+
case 185 /* SyntaxKind.FunctionType */:
|
|
890
|
+
case 186 /* SyntaxKind.ConstructorType */:
|
|
891
|
+
case 188 /* SyntaxKind.TypeLiteral */:
|
|
892
|
+
case 184 /* SyntaxKind.TypeReference */:
|
|
893
|
+
case 189 /* SyntaxKind.ArrayType */:
|
|
894
|
+
case 190 /* SyntaxKind.TupleType */:
|
|
895
|
+
case 193 /* SyntaxKind.UnionType */:
|
|
896
|
+
case 194 /* SyntaxKind.IntersectionType */:
|
|
897
|
+
case 197 /* SyntaxKind.ParenthesizedType */:
|
|
898
|
+
case 203 /* SyntaxKind.NamedTupleMember */:
|
|
899
|
+
return isDeclarationVisible(c, node.parent);
|
|
900
|
+
// Imports are visible only once something refers to them.
|
|
901
|
+
case 274 /* SyntaxKind.ImportClause */:
|
|
902
|
+
case 275 /* SyntaxKind.NamespaceImport */:
|
|
903
|
+
case 277 /* SyntaxKind.ImportSpecifier */:
|
|
904
|
+
return false;
|
|
905
|
+
case 169 /* SyntaxKind.TypeParameter */:
|
|
906
|
+
case 307 /* SyntaxKind.SourceFile */:
|
|
907
|
+
case 271 /* SyntaxKind.NamespaceExportDeclaration */:
|
|
908
|
+
return true;
|
|
909
|
+
case 278 /* SyntaxKind.ExportAssignment */:
|
|
910
|
+
return false;
|
|
911
|
+
// `export { x }` without a module specifier re-exports `x` visibly.
|
|
912
|
+
case 282 /* SyntaxKind.ExportSpecifier */: {
|
|
913
|
+
const exportDeclaration = node.parent.parent;
|
|
914
|
+
if (exportDeclaration instanceof ExportDeclaration && exportDeclaration.moduleSpecifier === undefined)
|
|
915
|
+
return isDeclarationVisible(c, exportDeclaration.parent);
|
|
916
|
+
return false;
|
|
917
|
+
}
|
|
918
|
+
}
|
|
919
|
+
return false;
|
|
920
|
+
}
|
|
921
|
+
/**
|
|
922
|
+
* Accessible if every declaration of `symbol` is visible, or can be made so by keeping an
|
|
923
|
+
* unexported import or statement; those are marked visible with `shouldComputeAliasesToMakeVisible`.
|
|
924
|
+
*/
|
|
925
|
+
export function hasVisibleDeclarations(c, symbol, shouldComputeAliasesToMakeVisible) {
|
|
926
|
+
const aliases = [];
|
|
927
|
+
const addVisibleAlias = (declaration, statement) => {
|
|
928
|
+
if (!shouldComputeAliasesToMakeVisible)
|
|
929
|
+
return;
|
|
930
|
+
markDeclarationVisible(c, declaration);
|
|
931
|
+
if (aliases.indexOf(statement) < 0)
|
|
932
|
+
aliases.push(statement);
|
|
933
|
+
};
|
|
934
|
+
for (const declaration of getDeclarations(symbol)) {
|
|
935
|
+
if (declaration.kind === 79 /* SyntaxKind.Identifier */ || isDeclarationVisible(c, declaration))
|
|
936
|
+
continue;
|
|
937
|
+
// Unexported imports can name types if their parent is visible.
|
|
938
|
+
const anyImport = getAnyImportSyntax(declaration);
|
|
939
|
+
if (anyImport !== undefined &&
|
|
940
|
+
!hasSyntacticModifier(anyImport, 32 /* ModifierFlags.Export */) &&
|
|
941
|
+
isDeclarationVisible(c, anyImport.parent)) {
|
|
942
|
+
addVisibleAlias(declaration, anyImport);
|
|
943
|
+
continue;
|
|
944
|
+
}
|
|
945
|
+
if (declaration instanceof VariableDeclaration &&
|
|
946
|
+
declaration.parent.parent.kind === 244 /* SyntaxKind.VariableStatement */ &&
|
|
947
|
+
!hasSyntacticModifier(declaration.parent.parent, 32 /* ModifierFlags.Export */) &&
|
|
948
|
+
isDeclarationVisible(c, declaration.parent.parent.parent)) {
|
|
949
|
+
addVisibleAlias(declaration, declaration.parent.parent);
|
|
950
|
+
continue;
|
|
951
|
+
}
|
|
952
|
+
if (isLateVisibilityPaintedStatement(declaration) &&
|
|
953
|
+
!hasSyntacticModifier(declaration, 32 /* ModifierFlags.Export */) &&
|
|
954
|
+
isDeclarationVisible(c, declaration.parent)) {
|
|
955
|
+
addVisibleAlias(declaration, declaration);
|
|
956
|
+
continue;
|
|
957
|
+
}
|
|
958
|
+
if (declaration instanceof BindingElement) {
|
|
959
|
+
if ((symbol.flags & 2097152 /* SymbolFlags.Alias */) !== 0 && isInJSFile(declaration)) {
|
|
960
|
+
// An unexported top-level `const { x } = require('y')`.
|
|
961
|
+
const statement = declaration.parent?.parent?.parent?.parent;
|
|
962
|
+
if (declaration.parent?.parent instanceof VariableDeclaration &&
|
|
963
|
+
statement !== undefined &&
|
|
964
|
+
statement.kind === 244 /* SyntaxKind.VariableStatement */ &&
|
|
965
|
+
!hasSyntacticModifier(statement, 32 /* ModifierFlags.Export */) &&
|
|
966
|
+
statement.parent !== undefined &&
|
|
967
|
+
isDeclarationVisible(c, statement.parent)) {
|
|
968
|
+
addVisibleAlias(declaration, statement);
|
|
969
|
+
continue;
|
|
970
|
+
}
|
|
971
|
+
}
|
|
972
|
+
if ((symbol.flags & 2 /* SymbolFlags.BlockScopedVariable */) !== 0) {
|
|
973
|
+
const root = getRootDeclaration(declaration);
|
|
974
|
+
if (root.kind === 170 /* SyntaxKind.Parameter */)
|
|
975
|
+
return undefined;
|
|
976
|
+
const variableStatement = root.parent?.parent;
|
|
977
|
+
if (variableStatement === undefined || variableStatement.kind !== 244 /* SyntaxKind.VariableStatement */)
|
|
978
|
+
return undefined;
|
|
979
|
+
// Already exported: nothing to keep.
|
|
980
|
+
if (hasSyntacticModifier(variableStatement, 32 /* ModifierFlags.Export */))
|
|
981
|
+
continue;
|
|
982
|
+
if (!isDeclarationVisible(c, variableStatement.parent))
|
|
983
|
+
return undefined;
|
|
984
|
+
addVisibleAlias(declaration, variableStatement);
|
|
985
|
+
continue;
|
|
986
|
+
}
|
|
987
|
+
}
|
|
988
|
+
return undefined;
|
|
989
|
+
}
|
|
990
|
+
return accessible(aliases);
|
|
991
|
+
}
|