tsc-ts 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +33 -1
- package/dist/api/compiler/ast-utilities.d.ts +82 -0
- package/dist/api/compiler/ast-utilities.js +462 -0
- package/dist/api/compiler/ast.d.ts +2350 -0
- package/dist/api/compiler/ast.js +11206 -0
- package/dist/api/compiler/astnav.d.ts +37 -0
- package/dist/api/compiler/astnav.js +767 -0
- package/dist/api/compiler/binder-utilities.d.ts +182 -0
- package/dist/api/compiler/binder-utilities.js +1240 -0
- package/dist/api/compiler/binder.d.ts +33 -0
- package/dist/api/compiler/binder.js +2358 -0
- package/dist/api/compiler/character-codes.d.ts +161 -0
- package/dist/api/compiler/character-codes.js +160 -0
- package/dist/api/compiler/checker-calls.d.ts +46 -0
- package/dist/api/compiler/checker-calls.js +1640 -0
- package/dist/api/compiler/checker-classes.d.ts +30 -0
- package/dist/api/compiler/checker-classes.js +582 -0
- package/dist/api/compiler/checker-contextual.d.ts +77 -0
- package/dist/api/compiler/checker-contextual.js +1136 -0
- package/dist/api/compiler/checker-declaration-order.d.ts +12 -0
- package/dist/api/compiler/checker-declaration-order.js +356 -0
- package/dist/api/compiler/checker-declarations.d.ts +33 -0
- package/dist/api/compiler/checker-declarations.js +888 -0
- package/dist/api/compiler/checker-declared-types.d.ts +48 -0
- package/dist/api/compiler/checker-declared-types.js +787 -0
- package/dist/api/compiler/checker-decorators.d.ts +26 -0
- package/dist/api/compiler/checker-decorators.js +562 -0
- package/dist/api/compiler/checker-deprecation.d.ts +33 -0
- package/dist/api/compiler/checker-deprecation.js +315 -0
- package/dist/api/compiler/checker-destructuring.d.ts +34 -0
- package/dist/api/compiler/checker-destructuring.js +584 -0
- package/dist/api/compiler/checker-elaboration.d.ts +15 -0
- package/dist/api/compiler/checker-elaboration.js +290 -0
- package/dist/api/compiler/checker-emit-helpers.d.ts +58 -0
- package/dist/api/compiler/checker-emit-helpers.js +154 -0
- package/dist/api/compiler/checker-emit-resolver.d.ts +75 -0
- package/dist/api/compiler/checker-emit-resolver.js +579 -0
- package/dist/api/compiler/checker-evaluator.d.ts +27 -0
- package/dist/api/compiler/checker-evaluator.js +188 -0
- package/dist/api/compiler/checker-expressions.d.ts +67 -0
- package/dist/api/compiler/checker-expressions.js +1351 -0
- package/dist/api/compiler/checker-features.d.ts +6 -0
- package/dist/api/compiler/checker-features.js +354 -0
- package/dist/api/compiler/checker-flow.d.ts +86 -0
- package/dist/api/compiler/checker-flow.js +169 -0
- package/dist/api/compiler/checker-functions.d.ts +43 -0
- package/dist/api/compiler/checker-functions.js +1002 -0
- package/dist/api/compiler/checker-generated-code.d.ts +25 -0
- package/dist/api/compiler/checker-generated-code.js +168 -0
- package/dist/api/compiler/checker-globals.d.ts +14 -0
- package/dist/api/compiler/checker-globals.js +37 -0
- package/dist/api/compiler/checker-grammar.d.ts +35 -0
- package/dist/api/compiler/checker-grammar.js +2573 -0
- package/dist/api/compiler/checker-heritage.d.ts +28 -0
- package/dist/api/compiler/checker-heritage.js +900 -0
- package/dist/api/compiler/checker-inference.d.ts +179 -0
- package/dist/api/compiler/checker-inference.js +2105 -0
- package/dist/api/compiler/checker-iteration.d.ts +115 -0
- package/dist/api/compiler/checker-iteration.js +857 -0
- package/dist/api/compiler/checker-javascript.d.ts +42 -0
- package/dist/api/compiler/checker-javascript.js +441 -0
- package/dist/api/compiler/checker-jsdoc.d.ts +30 -0
- package/dist/api/compiler/checker-jsdoc.js +320 -0
- package/dist/api/compiler/checker-jsx.d.ts +94 -0
- package/dist/api/compiler/checker-jsx.js +1433 -0
- package/dist/api/compiler/checker-literals.d.ts +6 -0
- package/dist/api/compiler/checker-literals.js +43 -0
- package/dist/api/compiler/checker-members.d.ts +198 -0
- package/dist/api/compiler/checker-members.js +2126 -0
- package/dist/api/compiler/checker-modules.d.ts +85 -0
- package/dist/api/compiler/checker-modules.js +2141 -0
- package/dist/api/compiler/checker-narrowing.d.ts +120 -0
- package/dist/api/compiler/checker-narrowing.js +2797 -0
- package/dist/api/compiler/checker-object-literals.d.ts +14 -0
- package/dist/api/compiler/checker-object-literals.js +479 -0
- package/dist/api/compiler/checker-operators.d.ts +33 -0
- package/dist/api/compiler/checker-operators.js +1040 -0
- package/dist/api/compiler/checker-overloads.d.ts +7 -0
- package/dist/api/compiler/checker-overloads.js +270 -0
- package/dist/api/compiler/checker-property-access.d.ts +34 -0
- package/dist/api/compiler/checker-property-access.js +672 -0
- package/dist/api/compiler/checker-services.d.ts +49 -0
- package/dist/api/compiler/checker-services.js +995 -0
- package/dist/api/compiler/checker-signatures.d.ts +55 -0
- package/dist/api/compiler/checker-signatures.js +788 -0
- package/dist/api/compiler/checker-source-file.d.ts +27 -0
- package/dist/api/compiler/checker-source-file.js +619 -0
- package/dist/api/compiler/checker-statements.d.ts +18 -0
- package/dist/api/compiler/checker-statements.js +226 -0
- package/dist/api/compiler/checker-super.d.ts +13 -0
- package/dist/api/compiler/checker-super.js +241 -0
- package/dist/api/compiler/checker-symbol-types.d.ts +67 -0
- package/dist/api/compiler/checker-symbol-types.js +1885 -0
- package/dist/api/compiler/checker-symbols.d.ts +181 -0
- package/dist/api/compiler/checker-symbols.js +1782 -0
- package/dist/api/compiler/checker-type-factory.d.ts +142 -0
- package/dist/api/compiler/checker-type-factory.js +2501 -0
- package/dist/api/compiler/checker-type-nodes.d.ts +26 -0
- package/dist/api/compiler/checker-type-nodes.js +828 -0
- package/dist/api/compiler/checker-type-operators.d.ts +109 -0
- package/dist/api/compiler/checker-type-operators.js +1842 -0
- package/dist/api/compiler/checker-types.d.ts +1027 -0
- package/dist/api/compiler/checker-types.js +1697 -0
- package/dist/api/compiler/checker-unused.d.ts +19 -0
- package/dist/api/compiler/checker-unused.js +524 -0
- package/dist/api/compiler/checker-utilities.d.ts +33 -0
- package/dist/api/compiler/checker-utilities.js +141 -0
- package/dist/api/compiler/checker.d.ts +491 -0
- package/dist/api/compiler/checker.js +912 -0
- package/dist/api/compiler/command-line.d.ts +32 -0
- package/dist/api/compiler/command-line.js +383 -0
- package/dist/api/compiler/compile-program.d.ts +118 -0
- package/dist/api/compiler/compile-program.js +384 -0
- package/dist/api/compiler/diagnostic-locales.d.ts +22 -0
- package/dist/api/compiler/diagnostic-locales.js +64 -0
- package/dist/api/compiler/diagnostic-messages.d.ts +2166 -0
- package/dist/api/compiler/diagnostic-messages.js +184 -0
- package/dist/api/compiler/diagnostics.d.ts +167 -0
- package/dist/api/compiler/diagnostics.js +820 -0
- package/dist/api/compiler/emitter.d.ts +71 -0
- package/dist/api/compiler/emitter.js +327 -0
- package/dist/api/compiler/file-include.d.ts +117 -0
- package/dist/api/compiler/file-include.js +536 -0
- package/dist/api/compiler/file-loader.d.ts +261 -0
- package/dist/api/compiler/file-loader.js +1257 -0
- package/dist/api/compiler/file-system.d.ts +51 -0
- package/dist/api/compiler/file-system.js +132 -0
- package/dist/api/compiler/flow.d.ts +60 -0
- package/dist/api/compiler/flow.js +45 -0
- package/dist/api/compiler/instantiation.d.ts +74 -0
- package/dist/api/compiler/instantiation.js +799 -0
- package/dist/api/compiler/jsdoc.d.ts +75 -0
- package/dist/api/compiler/jsdoc.js +1229 -0
- package/dist/api/compiler/link-tables.d.ts +36 -0
- package/dist/api/compiler/link-tables.js +83 -0
- package/dist/api/compiler/locale-data.d.ts +24 -0
- package/dist/api/compiler/locale-data.js +183 -0
- package/dist/api/compiler/locale.d.ts +4 -0
- package/dist/api/compiler/locale.js +317 -0
- package/dist/api/compiler/locales/cs-CZ.d.ts +2 -0
- package/dist/api/compiler/locales/cs-CZ.js +3 -0
- package/dist/api/compiler/locales/de-DE.d.ts +2 -0
- package/dist/api/compiler/locales/de-DE.js +3 -0
- package/dist/api/compiler/locales/es-ES.d.ts +2 -0
- package/dist/api/compiler/locales/es-ES.js +3 -0
- package/dist/api/compiler/locales/fr-FR.d.ts +2 -0
- package/dist/api/compiler/locales/fr-FR.js +3 -0
- package/dist/api/compiler/locales/it-IT.d.ts +2 -0
- package/dist/api/compiler/locales/it-IT.js +3 -0
- package/dist/api/compiler/locales/ja-JP.d.ts +2 -0
- package/dist/api/compiler/locales/ja-JP.js +3 -0
- package/dist/api/compiler/locales/ko-KR.d.ts +2 -0
- package/dist/api/compiler/locales/ko-KR.js +3 -0
- package/dist/api/compiler/locales/pl-PL.d.ts +2 -0
- package/dist/api/compiler/locales/pl-PL.js +3 -0
- package/dist/api/compiler/locales/pt-BR.d.ts +2 -0
- package/dist/api/compiler/locales/pt-BR.js +3 -0
- package/dist/api/compiler/locales/ru-RU.d.ts +2 -0
- package/dist/api/compiler/locales/ru-RU.js +3 -0
- package/dist/api/compiler/locales/tr-TR.d.ts +2 -0
- package/dist/api/compiler/locales/tr-TR.js +3 -0
- package/dist/api/compiler/locales/zh-CN.d.ts +2 -0
- package/dist/api/compiler/locales/zh-CN.js +3 -0
- package/dist/api/compiler/locales/zh-TW.d.ts +2 -0
- package/dist/api/compiler/locales/zh-TW.js +3 -0
- package/dist/api/compiler/module-resolution-types.d.ts +83 -0
- package/dist/api/compiler/module-resolution-types.js +176 -0
- package/dist/api/compiler/module-resolution.d.ts +71 -0
- package/dist/api/compiler/module-resolution.js +1598 -0
- package/dist/api/compiler/module-specifiers.d.ts +64 -0
- package/dist/api/compiler/module-specifiers.js +1101 -0
- package/dist/api/compiler/name-resolver.d.ts +43 -0
- package/dist/api/compiler/name-resolver.js +509 -0
- package/dist/api/compiler/node-builder-names.d.ts +32 -0
- package/dist/api/compiler/node-builder-names.js +854 -0
- package/dist/api/compiler/node-builder-pseudo.d.ts +36 -0
- package/dist/api/compiler/node-builder-pseudo.js +744 -0
- package/dist/api/compiler/node-builder-reuse.d.ts +4 -0
- package/dist/api/compiler/node-builder-reuse.js +647 -0
- package/dist/api/compiler/node-builder.d.ts +270 -0
- package/dist/api/compiler/node-builder.js +2645 -0
- package/dist/api/compiler/option-declarations.d.ts +90 -0
- package/dist/api/compiler/option-declarations.js +1460 -0
- package/dist/api/compiler/options.d.ts +289 -0
- package/dist/api/compiler/options.js +1197 -0
- package/dist/api/compiler/output-paths.d.ts +42 -0
- package/dist/api/compiler/output-paths.js +195 -0
- package/dist/api/compiler/package-json.d.ts +175 -0
- package/dist/api/compiler/package-json.js +1015 -0
- package/dist/api/compiler/parallel-parse.d.ts +219 -0
- package/dist/api/compiler/parallel-parse.js +537 -0
- package/dist/api/compiler/parser.d.ts +587 -0
- package/dist/api/compiler/parser.js +6407 -0
- package/dist/api/compiler/path.d.ts +91 -0
- package/dist/api/compiler/path.js +705 -0
- package/dist/api/compiler/printer/async-helpers.d.ts +22 -0
- package/dist/api/compiler/printer/async-helpers.js +91 -0
- package/dist/api/compiler/printer/auto-generate.d.ts +13 -0
- package/dist/api/compiler/printer/auto-generate.js +20 -0
- package/dist/api/compiler/printer/decorator-helpers.d.ts +24 -0
- package/dist/api/compiler/printer/decorator-helpers.js +118 -0
- package/dist/api/compiler/printer/emit-context.d.ts +154 -0
- package/dist/api/compiler/printer/emit-context.js +576 -0
- package/dist/api/compiler/printer/emit-flags.d.ts +60 -0
- package/dist/api/compiler/printer/emit-flags.js +2 -0
- package/dist/api/compiler/printer/factory-base.d.ts +171 -0
- package/dist/api/compiler/printer/factory-base.js +1505 -0
- package/dist/api/compiler/printer/factory.d.ts +147 -0
- package/dist/api/compiler/printer/factory.js +542 -0
- package/dist/api/compiler/printer/helpers.d.ts +27 -0
- package/dist/api/compiler/printer/helpers.js +164 -0
- package/dist/api/compiler/printer/name-generator.d.ts +41 -0
- package/dist/api/compiler/printer/name-generator.js +283 -0
- package/dist/api/compiler/printer/printer.d.ts +411 -0
- package/dist/api/compiler/printer/printer.js +4517 -0
- package/dist/api/compiler/printer/text-writer.d.ts +46 -0
- package/dist/api/compiler/printer/text-writer.js +172 -0
- package/dist/api/compiler/printer/utilities.d.ts +82 -0
- package/dist/api/compiler/printer/utilities.js +817 -0
- package/dist/api/compiler/program-checker.d.ts +156 -0
- package/dist/api/compiler/program-checker.js +526 -0
- package/dist/api/compiler/program-utilities.d.ts +52 -0
- package/dist/api/compiler/program-utilities.js +365 -0
- package/dist/api/compiler/program.d.ts +180 -0
- package/dist/api/compiler/program.js +1011 -0
- package/dist/api/compiler/pseudo-bigint.d.ts +5 -0
- package/dist/api/compiler/pseudo-bigint.js +61 -0
- package/dist/api/compiler/regexp-checker.d.ts +38 -0
- package/dist/api/compiler/regexp-checker.js +942 -0
- package/dist/api/compiler/relations.d.ts +263 -0
- package/dist/api/compiler/relations.js +4002 -0
- package/dist/api/compiler/reparser.d.ts +48 -0
- package/dist/api/compiler/reparser.js +1323 -0
- package/dist/api/compiler/scanner.d.ts +256 -0
- package/dist/api/compiler/scanner.js +2853 -0
- package/dist/api/compiler/side-state.d.ts +16 -0
- package/dist/api/compiler/side-state.js +89 -0
- package/dist/api/compiler/sourcemap.d.ts +55 -0
- package/dist/api/compiler/sourcemap.js +340 -0
- package/dist/api/compiler/spelling.d.ts +14 -0
- package/dist/api/compiler/spelling.js +128 -0
- package/dist/api/compiler/symbol-accessibility.d.ts +57 -0
- package/dist/api/compiler/symbol-accessibility.js +894 -0
- package/dist/api/compiler/symbol.d.ts +240 -0
- package/dist/api/compiler/symbol.js +228 -0
- package/dist/api/compiler/symlinks.d.ts +32 -0
- package/dist/api/compiler/symlinks.js +114 -0
- package/dist/api/compiler/syntax-kind.d.ts +389 -0
- package/dist/api/compiler/syntax-kind.js +2 -0
- package/dist/api/compiler/timeline.d.ts +9 -0
- package/dist/api/compiler/timeline.js +54 -0
- package/dist/api/compiler/transformers/alias-references.d.ts +39 -0
- package/dist/api/compiler/transformers/alias-references.js +676 -0
- package/dist/api/compiler/transformers/async-utilities.d.ts +51 -0
- package/dist/api/compiler/transformers/async-utilities.js +260 -0
- package/dist/api/compiler/transformers/async.d.ts +53 -0
- package/dist/api/compiler/transformers/async.js +645 -0
- package/dist/api/compiler/transformers/class-fields.d.ts +206 -0
- package/dist/api/compiler/transformers/class-fields.js +2418 -0
- package/dist/api/compiler/transformers/class-utilities.d.ts +46 -0
- package/dist/api/compiler/transformers/class-utilities.js +261 -0
- package/dist/api/compiler/transformers/commonjs-module.d.ts +103 -0
- package/dist/api/compiler/transformers/commonjs-module.js +1180 -0
- package/dist/api/compiler/transformers/const-enum-inliner.d.ts +11 -0
- package/dist/api/compiler/transformers/const-enum-inliner.js +36 -0
- package/dist/api/compiler/transformers/declarations-diagnostics.d.ts +52 -0
- package/dist/api/compiler/transformers/declarations-diagnostics.js +538 -0
- package/dist/api/compiler/transformers/declarations-pseudo.d.ts +160 -0
- package/dist/api/compiler/transformers/declarations-pseudo.js +797 -0
- package/dist/api/compiler/transformers/declarations-resolver.d.ts +152 -0
- package/dist/api/compiler/transformers/declarations-resolver.js +35 -0
- package/dist/api/compiler/transformers/declarations-syntactic.d.ts +119 -0
- package/dist/api/compiler/transformers/declarations-syntactic.js +1582 -0
- package/dist/api/compiler/transformers/declarations-tracker.d.ts +46 -0
- package/dist/api/compiler/transformers/declarations-tracker.js +197 -0
- package/dist/api/compiler/transformers/declarations.d.ts +175 -0
- package/dist/api/compiler/transformers/declarations.js +2380 -0
- package/dist/api/compiler/transformers/decorator-metadata.d.ts +54 -0
- package/dist/api/compiler/transformers/decorator-metadata.js +554 -0
- package/dist/api/compiler/transformers/decorator-utilities.d.ts +38 -0
- package/dist/api/compiler/transformers/decorator-utilities.js +238 -0
- package/dist/api/compiler/transformers/destructuring.d.ts +25 -0
- package/dist/api/compiler/transformers/destructuring.js +626 -0
- package/dist/api/compiler/transformers/downlevel.d.ts +6 -0
- package/dist/api/compiler/transformers/downlevel.js +45 -0
- package/dist/api/compiler/transformers/emit-resolver.d.ts +61 -0
- package/dist/api/compiler/transformers/emit-resolver.js +197 -0
- package/dist/api/compiler/transformers/es-decorators.d.ts +118 -0
- package/dist/api/compiler/transformers/es-decorators.js +1901 -0
- package/dist/api/compiler/transformers/exponentiation.d.ts +11 -0
- package/dist/api/compiler/transformers/exponentiation.js +76 -0
- package/dist/api/compiler/transformers/external-module-info.d.ts +35 -0
- package/dist/api/compiler/transformers/external-module-info.js +351 -0
- package/dist/api/compiler/transformers/for-await.d.ts +43 -0
- package/dist/api/compiler/transformers/for-await.js +469 -0
- package/dist/api/compiler/transformers/import-elision.d.ts +16 -0
- package/dist/api/compiler/transformers/import-elision.js +124 -0
- package/dist/api/compiler/transformers/jsx-entities.d.ts +1 -0
- package/dist/api/compiler/transformers/jsx-entities.js +256 -0
- package/dist/api/compiler/transformers/jsx.d.ts +71 -0
- package/dist/api/compiler/transformers/jsx.js +700 -0
- package/dist/api/compiler/transformers/legacy-decorators.d.ts +56 -0
- package/dist/api/compiler/transformers/legacy-decorators.js +564 -0
- package/dist/api/compiler/transformers/logical-assignment.d.ts +14 -0
- package/dist/api/compiler/transformers/logical-assignment.js +62 -0
- package/dist/api/compiler/transformers/module-utilities.d.ts +9 -0
- package/dist/api/compiler/transformers/module-utilities.js +36 -0
- package/dist/api/compiler/transformers/module.d.ts +49 -0
- package/dist/api/compiler/transformers/module.js +296 -0
- package/dist/api/compiler/transformers/named-evaluation.d.ts +26 -0
- package/dist/api/compiler/transformers/named-evaluation.js +266 -0
- package/dist/api/compiler/transformers/nullish-coalescing.d.ts +9 -0
- package/dist/api/compiler/transformers/nullish-coalescing.js +26 -0
- package/dist/api/compiler/transformers/object-rest-spread.d.ts +34 -0
- package/dist/api/compiler/transformers/object-rest-spread.js +411 -0
- package/dist/api/compiler/transformers/optional-catch.d.ts +9 -0
- package/dist/api/compiler/transformers/optional-catch.js +20 -0
- package/dist/api/compiler/transformers/optional-chain.d.ts +14 -0
- package/dist/api/compiler/transformers/optional-chain.js +188 -0
- package/dist/api/compiler/transformers/reference-resolver.d.ts +128 -0
- package/dist/api/compiler/transformers/reference-resolver.js +1155 -0
- package/dist/api/compiler/transformers/runtime-syntax.d.ts +71 -0
- package/dist/api/compiler/transformers/runtime-syntax.js +753 -0
- package/dist/api/compiler/transformers/subtree-facts.d.ts +9 -0
- package/dist/api/compiler/transformers/subtree-facts.js +203 -0
- package/dist/api/compiler/transformers/syntax-facts.d.ts +51 -0
- package/dist/api/compiler/transformers/syntax-facts.js +254 -0
- package/dist/api/compiler/transformers/tagged-template.d.ts +17 -0
- package/dist/api/compiler/transformers/tagged-template.js +148 -0
- package/dist/api/compiler/transformers/transformer.d.ts +17 -0
- package/dist/api/compiler/transformers/transformer.js +54 -0
- package/dist/api/compiler/transformers/type-eraser.d.ts +21 -0
- package/dist/api/compiler/transformers/type-eraser.js +346 -0
- package/dist/api/compiler/transformers/type-serialization.d.ts +20 -0
- package/dist/api/compiler/transformers/type-serialization.js +347 -0
- package/dist/api/compiler/transformers/using.d.ts +56 -0
- package/dist/api/compiler/transformers/using.js +453 -0
- package/dist/api/compiler/transformers/utilities.d.ts +50 -0
- package/dist/api/compiler/transformers/utilities.js +347 -0
- package/dist/api/compiler/transformers/visitor-base.d.ts +6 -0
- package/dist/api/compiler/transformers/visitor-base.js +817 -0
- package/dist/api/compiler/transformers/visitor-hooks.d.ts +29 -0
- package/dist/api/compiler/transformers/visitor-hooks.js +189 -0
- package/dist/api/compiler/tsconfig.d.ts +177 -0
- package/dist/api/compiler/tsconfig.js +1311 -0
- package/dist/api/compiler/type-printer.d.ts +15 -0
- package/dist/api/compiler/type-printer.js +74 -0
- package/dist/api/compiler/types.d.ts +87 -0
- package/dist/api/compiler/types.js +23 -0
- package/dist/api/compiler/unicode-identifiers.d.ts +2 -0
- package/dist/api/compiler/unicode-identifiers.js +209 -0
- package/dist/api/compiler/unicode-properties.d.ts +8 -0
- package/dist/api/compiler/unicode-properties.js +531 -0
- package/dist/api/compiler/vfs-match.d.ts +24 -0
- package/dist/api/compiler/vfs-match.js +587 -0
- package/dist/api/library/ast.d.ts +3 -2
- package/dist/api/library/ast.generated.d.ts +127 -139
- package/dist/api/library/checker.d.ts +51 -0
- package/dist/api/library/checker.js +318 -0
- package/dist/api/library/diagnostics.d.ts +13 -0
- package/dist/api/library/diagnostics.js +50 -0
- package/dist/api/library/disk.d.ts +13 -0
- package/dist/api/library/disk.js +66 -0
- package/dist/api/library/errors.d.ts +13 -0
- package/dist/api/library/errors.js +24 -0
- package/dist/api/library/host.d.ts +24 -0
- package/dist/api/library/host.js +52 -0
- package/dist/api/library/index.d.ts +5 -1
- package/dist/api/library/index.js +4 -0
- package/dist/api/library/nodes.d.ts +51 -0
- package/dist/api/library/nodes.js +196 -0
- package/dist/api/library/options.d.ts +144 -0
- package/dist/api/library/options.js +308 -0
- package/dist/api/library/parse.d.ts +19 -0
- package/dist/api/library/parse.js +41 -0
- package/dist/api/library/program.d.ts +21 -0
- package/dist/api/library/program.js +234 -0
- package/dist/api/library/types.d.ts +14 -1
- package/package.json +12 -8
- package/src/compiler/ast-utilities.ts +548 -0
- package/src/compiler/ast.ts +12862 -0
- package/src/compiler/astnav.ts +799 -0
- package/src/compiler/binder-utilities.ts +1392 -0
- package/src/compiler/binder.ts +2703 -0
- package/src/compiler/build-info.ts +1197 -0
- package/src/compiler/character-codes.ts +323 -0
- package/src/compiler/checker-calls.ts +2155 -0
- package/src/compiler/checker-classes.ts +706 -0
- package/src/compiler/checker-contextual.ts +1457 -0
- package/src/compiler/checker-declaration-order.ts +438 -0
- package/src/compiler/checker-declarations.ts +1194 -0
- package/src/compiler/checker-declared-types.ts +919 -0
- package/src/compiler/checker-decorators.ts +694 -0
- package/src/compiler/checker-deprecation.ts +359 -0
- package/src/compiler/checker-destructuring.ts +805 -0
- package/src/compiler/checker-elaboration.ts +477 -0
- package/src/compiler/checker-emit-helpers.ts +224 -0
- package/src/compiler/checker-emit-resolver.ts +769 -0
- package/src/compiler/checker-evaluator.ts +243 -0
- package/src/compiler/checker-expressions.ts +1831 -0
- package/src/compiler/checker-features.ts +361 -0
- package/src/compiler/checker-flow.ts +394 -0
- package/src/compiler/checker-functions.ts +1296 -0
- package/src/compiler/checker-generated-code.ts +227 -0
- package/src/compiler/checker-globals.ts +52 -0
- package/src/compiler/checker-grammar.ts +3584 -0
- package/src/compiler/checker-heritage.ts +1233 -0
- package/src/compiler/checker-inference.ts +2576 -0
- package/src/compiler/checker-iteration.ts +1206 -0
- package/src/compiler/checker-javascript.ts +502 -0
- package/src/compiler/checker-jsdoc.ts +360 -0
- package/src/compiler/checker-jsx.ts +1924 -0
- package/src/compiler/checker-literals.ts +61 -0
- package/src/compiler/checker-members.ts +2436 -0
- package/src/compiler/checker-modules.ts +2886 -0
- package/src/compiler/checker-narrowing.ts +3230 -0
- package/src/compiler/checker-object-literals.ts +575 -0
- package/src/compiler/checker-operators.ts +1422 -0
- package/src/compiler/checker-overloads.ts +328 -0
- package/src/compiler/checker-property-access.ts +906 -0
- package/src/compiler/checker-services.ts +1149 -0
- package/src/compiler/checker-signatures.ts +1032 -0
- package/src/compiler/checker-source-file.ts +732 -0
- package/src/compiler/checker-statements.ts +292 -0
- package/src/compiler/checker-super.ts +261 -0
- package/src/compiler/checker-symbol-types.ts +2107 -0
- package/src/compiler/checker-symbols.ts +2150 -0
- package/src/compiler/checker-type-factory.ts +2579 -0
- package/src/compiler/checker-type-nodes.ts +1033 -0
- package/src/compiler/checker-type-operators.ts +2502 -0
- package/src/compiler/checker-types.ts +2340 -0
- package/src/compiler/checker-unused.ts +642 -0
- package/src/compiler/checker-utilities.ts +161 -0
- package/src/compiler/checker.ts +1116 -0
- package/src/compiler/command-line.ts +436 -0
- package/src/compiler/compile-program.ts +439 -0
- package/src/compiler/decoder.ts +1209 -0
- package/src/compiler/diagnostic-locales.ts +86 -0
- package/src/compiler/diagnostic-messages.ts +2349 -0
- package/src/compiler/diagnostics.ts +897 -0
- package/src/compiler/emitter.ts +434 -0
- package/src/compiler/encoder.ts +1945 -0
- package/src/compiler/file-include.ts +673 -0
- package/src/compiler/file-loader.ts +1528 -0
- package/src/compiler/file-system.ts +143 -0
- package/src/compiler/flow.ts +89 -0
- package/src/compiler/help.ts +473 -0
- package/src/compiler/incremental.ts +2784 -0
- package/src/compiler/init.ts +141 -0
- package/src/compiler/instantiation.ts +894 -0
- package/src/compiler/jsdoc.ts +1386 -0
- package/src/compiler/link-tables.ts +98 -0
- package/src/compiler/locale-data.ts +203 -0
- package/src/compiler/locale.ts +307 -0
- package/src/compiler/locales/cs-CZ.ts +5 -0
- package/src/compiler/locales/de-DE.ts +5 -0
- package/src/compiler/locales/es-ES.ts +5 -0
- package/src/compiler/locales/fr-FR.ts +5 -0
- package/src/compiler/locales/it-IT.ts +5 -0
- package/src/compiler/locales/ja-JP.ts +5 -0
- package/src/compiler/locales/ko-KR.ts +5 -0
- package/src/compiler/locales/pl-PL.ts +5 -0
- package/src/compiler/locales/pt-BR.ts +5 -0
- package/src/compiler/locales/ru-RU.ts +5 -0
- package/src/compiler/locales/tr-TR.ts +5 -0
- package/src/compiler/locales/zh-CN.ts +5 -0
- package/src/compiler/locales/zh-TW.ts +5 -0
- package/src/compiler/module-resolution-types.ts +243 -0
- package/src/compiler/module-resolution.ts +2072 -0
- package/src/compiler/module-specifiers.ts +1491 -0
- package/src/compiler/name-resolver.ts +646 -0
- package/src/compiler/node-builder-names.ts +1069 -0
- package/src/compiler/node-builder-pseudo.ts +892 -0
- package/src/compiler/node-builder-reuse.ts +764 -0
- package/src/compiler/node-builder.ts +3425 -0
- package/src/compiler/option-declarations.ts +1560 -0
- package/src/compiler/options.ts +1576 -0
- package/src/compiler/output-paths.ts +334 -0
- package/src/compiler/package-json.ts +1083 -0
- package/src/compiler/parallel-check.ts +1951 -0
- package/src/compiler/parallel-parse.ts +590 -0
- package/src/compiler/parse-thread.ts +140 -0
- package/src/compiler/parser.ts +7716 -0
- package/src/compiler/path.ts +717 -0
- package/src/compiler/printer/async-helpers.ts +183 -0
- package/src/compiler/printer/auto-generate.ts +27 -0
- package/src/compiler/printer/decorator-helpers.ts +218 -0
- package/src/compiler/printer/emit-context.ts +679 -0
- package/src/compiler/printer/emit-flags.ts +64 -0
- package/src/compiler/printer/factory-base.ts +2577 -0
- package/src/compiler/printer/factory.ts +764 -0
- package/src/compiler/printer/helpers.ts +291 -0
- package/src/compiler/printer/name-generator.ts +372 -0
- package/src/compiler/printer/printer.ts +5072 -0
- package/src/compiler/printer/text-writer.ts +183 -0
- package/src/compiler/printer/utilities.ts +884 -0
- package/src/compiler/program-checker.ts +592 -0
- package/src/compiler/program-utilities.ts +435 -0
- package/src/compiler/program.ts +1419 -0
- package/src/compiler/pseudo-bigint.ts +62 -0
- package/src/compiler/regexp-checker.ts +1142 -0
- package/src/compiler/relations.ts +5149 -0
- package/src/compiler/reparser.ts +1566 -0
- package/src/compiler/scanner.ts +2951 -0
- package/src/compiler/show-config.ts +239 -0
- package/src/compiler/side-state.ts +125 -0
- package/src/compiler/sourcemap.ts +366 -0
- package/src/compiler/spelling.ts +122 -0
- package/src/compiler/symbol-accessibility.ts +1071 -0
- package/src/compiler/symbol.ts +439 -0
- package/src/compiler/symlinks.ts +137 -0
- package/src/compiler/syntax-kind.ts +391 -0
- package/src/compiler/thread-entry.ts +191 -0
- package/src/compiler/timeline.ts +53 -0
- package/src/compiler/transformers/alias-references.ts +757 -0
- package/src/compiler/transformers/async-utilities.ts +335 -0
- package/src/compiler/transformers/async.ts +838 -0
- package/src/compiler/transformers/class-fields.ts +2967 -0
- package/src/compiler/transformers/class-utilities.ts +324 -0
- package/src/compiler/transformers/commonjs-module.ts +1621 -0
- package/src/compiler/transformers/const-enum-inliner.ts +50 -0
- package/src/compiler/transformers/declarations-diagnostics.ts +832 -0
- package/src/compiler/transformers/declarations-pseudo.ts +966 -0
- package/src/compiler/transformers/declarations-resolver.ts +249 -0
- package/src/compiler/transformers/declarations-syntactic.ts +1859 -0
- package/src/compiler/transformers/declarations-tracker.ts +269 -0
- package/src/compiler/transformers/declarations.ts +3120 -0
- package/src/compiler/transformers/decorator-metadata.ts +697 -0
- package/src/compiler/transformers/decorator-utilities.ts +283 -0
- package/src/compiler/transformers/destructuring.ts +708 -0
- package/src/compiler/transformers/downlevel.ts +50 -0
- package/src/compiler/transformers/emit-resolver.ts +258 -0
- package/src/compiler/transformers/es-decorators.ts +2682 -0
- package/src/compiler/transformers/exponentiation.ts +80 -0
- package/src/compiler/transformers/external-module-info.ts +412 -0
- package/src/compiler/transformers/for-await.ts +687 -0
- package/src/compiler/transformers/import-elision.ts +152 -0
- package/src/compiler/transformers/jsx-entities.ts +256 -0
- package/src/compiler/transformers/jsx.ts +824 -0
- package/src/compiler/transformers/legacy-decorators.ts +726 -0
- package/src/compiler/transformers/logical-assignment.ts +75 -0
- package/src/compiler/transformers/module-utilities.ts +42 -0
- package/src/compiler/transformers/module.ts +474 -0
- package/src/compiler/transformers/named-evaluation.ts +389 -0
- package/src/compiler/transformers/nullish-coalescing.ts +35 -0
- package/src/compiler/transformers/object-rest-spread.ts +577 -0
- package/src/compiler/transformers/optional-catch.ts +29 -0
- package/src/compiler/transformers/optional-chain.ts +246 -0
- package/src/compiler/transformers/reference-resolver.ts +1201 -0
- package/src/compiler/transformers/runtime-syntax.ts +942 -0
- package/src/compiler/transformers/subtree-facts.ts +245 -0
- package/src/compiler/transformers/syntax-facts.ts +353 -0
- package/src/compiler/transformers/tagged-template.ts +167 -0
- package/src/compiler/transformers/transformer.ts +56 -0
- package/src/compiler/transformers/type-eraser.ts +520 -0
- package/src/compiler/transformers/type-serialization.ts +374 -0
- package/src/compiler/transformers/using.ts +613 -0
- package/src/compiler/transformers/utilities.ts +419 -0
- package/src/compiler/transformers/visitor-base.ts +1601 -0
- package/src/compiler/transformers/visitor-hooks.ts +252 -0
- package/src/compiler/tsc-build.ts +1418 -0
- package/src/compiler/tsc-cli.ts +666 -0
- package/src/compiler/tsc-compile.ts +437 -0
- package/src/compiler/tsc-watch.ts +854 -0
- package/src/compiler/tsconfig.ts +1574 -0
- package/src/compiler/type-printer.ts +110 -0
- package/src/compiler/types.ts +115 -0
- package/src/compiler/unicode-identifiers.ts +212 -0
- package/src/compiler/unicode-properties.ts +537 -0
- package/src/compiler/vfs-match.ts +597 -0
- package/src/compiler/xxh3.ts +650 -0
- package/src/library/ast.generated.ts +141 -167
- package/src/library/ast.ts +4 -1
- package/src/library/checker.ts +384 -0
- package/src/library/diagnostics.ts +72 -0
- package/src/library/disk.ts +73 -0
- package/src/library/errors.ts +26 -0
- package/src/library/host.ts +63 -0
- package/src/library/index.ts +21 -0
- package/src/library/nodes.ts +232 -0
- package/src/library/options.ts +449 -0
- package/src/library/parse.ts +63 -0
- package/src/library/program.ts +293 -0
- package/src/library/types.ts +14 -1
|
@@ -0,0 +1,1155 @@
|
|
|
1
|
+
// Name resolution for emit without a checker: which declaration an identifier refers to, the
|
|
2
|
+
// container exporting it, and constant values of enum members, from the binder's symbols with
|
|
3
|
+
// global declarations merged across script files and imports resolved between program files.
|
|
4
|
+
import { ElementAccessExpression, EnumDeclaration, EnumMember, ExportAssignment, ExportDeclaration, ExportSpecifier, Identifier, ImportClause, ImportDeclaration, ImportEqualsDeclaration, ImportSpecifier, ModuleDeclaration, NamespaceImport, NumericLiteral, ParenthesizedExpression, PrefixUnaryExpression, PropertyAccessExpression, QualifiedName, SourceFile, BinaryExpression, NoSubstitutionTemplateLiteral, StringLiteral, TemplateExpression, TemplateMiddle, TemplateSpan, TemplateTail, VariableDeclaration, ExternalModuleReference, getInitializer, getIsTypeOnly, getModuleSpecifier, getLocals, getName, getSymbol, getType, } from '../ast.js';
|
|
5
|
+
import { isFunctionLike } from '../ast-utilities.js';
|
|
6
|
+
import { getCombinedNodeFlags, getRootDeclaration, getSourceFileOfNode, isEnumConst, isExternalOrCommonJSModule, } from '../binder-utilities.js';
|
|
7
|
+
import { NameResolver } from '../name-resolver.js';
|
|
8
|
+
import { isSameNode } from './utilities.js';
|
|
9
|
+
import { pathIsRelative } from '../path.js';
|
|
10
|
+
import { shouldPreserveConstEnums } from '../options.js';
|
|
11
|
+
import { Symbol, addDeclaration } from '../symbol.js';
|
|
12
|
+
/** The result of evaluating a constant expression, as the checker's evaluator returns it. */
|
|
13
|
+
export class Evaluation {
|
|
14
|
+
kind;
|
|
15
|
+
number;
|
|
16
|
+
string;
|
|
17
|
+
isSyntacticallyString;
|
|
18
|
+
resolvedOtherFiles;
|
|
19
|
+
hasExternalReferences;
|
|
20
|
+
constructor(kind, numberValue, stringValue, isSyntacticallyString, resolvedOtherFiles, hasExternalReferences) {
|
|
21
|
+
this.kind = kind;
|
|
22
|
+
this.number = numberValue;
|
|
23
|
+
this.string = stringValue;
|
|
24
|
+
this.isSyntacticallyString = isSyntacticallyString;
|
|
25
|
+
this.resolvedOtherFiles = resolvedOtherFiles;
|
|
26
|
+
this.hasExternalReferences = hasExternalReferences;
|
|
27
|
+
}
|
|
28
|
+
/** The value as a string, as `+` concatenates it. */
|
|
29
|
+
text() {
|
|
30
|
+
return this.kind === 2 /* ConstantKind.String */ ? this.string : String(this.number);
|
|
31
|
+
}
|
|
32
|
+
withFlags(isSyntacticallyString, resolvedOtherFiles, hasExternalReferences) {
|
|
33
|
+
return new Evaluation(this.kind, this.number, this.string, isSyntacticallyString, resolvedOtherFiles, hasExternalReferences);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
export function numberEvaluation(value) {
|
|
37
|
+
return new Evaluation(1 /* ConstantKind.Number */, value, '', false, false, false);
|
|
38
|
+
}
|
|
39
|
+
export function stringEvaluation(value, isSyntacticallyString) {
|
|
40
|
+
return new Evaluation(2 /* ConstantKind.String */, 0, value, isSyntacticallyString, false, false);
|
|
41
|
+
}
|
|
42
|
+
export const noEvaluation = new Evaluation(0 /* ConstantKind.None */, 0, '', false, false, false);
|
|
43
|
+
function noValue(isSyntacticallyString, resolvedOtherFiles, hasExternalReferences) {
|
|
44
|
+
return new Evaluation(0 /* ConstantKind.None */, 0, '', isSyntacticallyString, resolvedOtherFiles, hasExternalReferences);
|
|
45
|
+
}
|
|
46
|
+
/** Finds the program file a module specifier names. */
|
|
47
|
+
export class ModuleLookup {
|
|
48
|
+
}
|
|
49
|
+
class NoModules extends ModuleLookup {
|
|
50
|
+
resolveModule(_location, _file, _specifier) {
|
|
51
|
+
return undefined;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/** The global symbol table, with declarations of script files merged as the checker merges them. */
|
|
55
|
+
export class MergedGlobals {
|
|
56
|
+
table;
|
|
57
|
+
merged;
|
|
58
|
+
aliases;
|
|
59
|
+
constructor() {
|
|
60
|
+
this.table = new Map();
|
|
61
|
+
this.merged = new Map();
|
|
62
|
+
this.aliases = undefined;
|
|
63
|
+
}
|
|
64
|
+
/** Merges the globals of `files`, resolving aliases they merge with through `aliases`. */
|
|
65
|
+
merge(files, aliases) {
|
|
66
|
+
this.aliases = aliases;
|
|
67
|
+
this.mergeFiles(files);
|
|
68
|
+
// Aliases are resolved only while merging: resolvers of other threads can share the tables.
|
|
69
|
+
this.aliases = undefined;
|
|
70
|
+
return true;
|
|
71
|
+
}
|
|
72
|
+
mergeFiles(files) {
|
|
73
|
+
for (const file of files) {
|
|
74
|
+
if (isExternalOrCommonJSModule(file))
|
|
75
|
+
continue;
|
|
76
|
+
const locals = getLocals(file);
|
|
77
|
+
if (locals !== undefined)
|
|
78
|
+
this.mergeTable(this.table, locals, undefined);
|
|
79
|
+
}
|
|
80
|
+
for (const file of files) {
|
|
81
|
+
for (const augmentation of file.moduleAugmentations) {
|
|
82
|
+
const declaration = augmentation.parent;
|
|
83
|
+
if (!(declaration instanceof ModuleDeclaration) || declaration.keyword !== 162 /* SyntaxKind.GlobalKeyword */)
|
|
84
|
+
continue;
|
|
85
|
+
const symbol = getSymbol(declaration);
|
|
86
|
+
if (symbol !== undefined && symbol.exports !== undefined)
|
|
87
|
+
this.mergeTable(this.table, symbol.exports, undefined);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return true;
|
|
91
|
+
}
|
|
92
|
+
getMergedSymbol(symbol) {
|
|
93
|
+
const merged = this.merged.get(symbol);
|
|
94
|
+
return merged !== undefined ? merged : symbol;
|
|
95
|
+
}
|
|
96
|
+
mergeTable(target, source, parent) {
|
|
97
|
+
for (const [name, sourceSymbol] of source) {
|
|
98
|
+
const targetSymbol = target.get(name);
|
|
99
|
+
if (targetSymbol === undefined) {
|
|
100
|
+
target.set(name, this.getMergedSymbol(sourceSymbol));
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
const merged = this.mergeSymbol(targetSymbol, sourceSymbol);
|
|
104
|
+
if (parent !== undefined && (merged.flags & 33554432 /* SymbolFlags.Transient */) !== 0)
|
|
105
|
+
merged.parent = parent;
|
|
106
|
+
target.set(name, merged);
|
|
107
|
+
}
|
|
108
|
+
return true;
|
|
109
|
+
}
|
|
110
|
+
mergeSymbol(target, source) {
|
|
111
|
+
if ((target.flags & excludedSymbolFlags(source.flags)) !== 0 &&
|
|
112
|
+
((source.flags | target.flags) & 67108864 /* SymbolFlags.Assignment */) === 0)
|
|
113
|
+
return target;
|
|
114
|
+
if (source === target)
|
|
115
|
+
return target;
|
|
116
|
+
let result = target;
|
|
117
|
+
if ((target.flags & 33554432 /* SymbolFlags.Transient */) === 0) {
|
|
118
|
+
// Like the checker, an alias merges by its target: the merge clones what it resolves to.
|
|
119
|
+
let resolved = target;
|
|
120
|
+
if ((target.flags & 2097152 /* SymbolFlags.Alias */) !== 0 && this.aliases !== undefined)
|
|
121
|
+
resolved = this.aliases.resolveAlias(target);
|
|
122
|
+
if (resolved === undefined)
|
|
123
|
+
return source;
|
|
124
|
+
// A conflict with what an alias resolves to replaces the alias.
|
|
125
|
+
if ((resolved.flags & excludedSymbolFlags(source.flags)) !== 0 &&
|
|
126
|
+
((source.flags | resolved.flags) & 67108864 /* SymbolFlags.Assignment */) === 0)
|
|
127
|
+
return source;
|
|
128
|
+
result = new Symbol(resolved.flags | 33554432 /* SymbolFlags.Transient */, resolved.name);
|
|
129
|
+
result.declarations = resolved.declarations.slice();
|
|
130
|
+
result.parent = resolved.parent;
|
|
131
|
+
result.valueDeclaration = resolved.valueDeclaration;
|
|
132
|
+
result.members = resolved.members === undefined ? undefined : new Map(resolved.members);
|
|
133
|
+
result.exports = resolved.exports === undefined ? undefined : new Map(resolved.exports);
|
|
134
|
+
this.merged.set(resolved, result);
|
|
135
|
+
}
|
|
136
|
+
if ((source.flags & 512 /* SymbolFlags.ValueModule */) !== 0 &&
|
|
137
|
+
(result.flags & 512 /* SymbolFlags.ValueModule */) !== 0 &&
|
|
138
|
+
(result.flags & 268435456 /* SymbolFlags.ConstEnumOnlyModule */) !== 0 &&
|
|
139
|
+
(source.flags & 268435456 /* SymbolFlags.ConstEnumOnlyModule */) === 0)
|
|
140
|
+
result.flags &= ~268435456 /* SymbolFlags.ConstEnumOnlyModule */;
|
|
141
|
+
let sourceFlags = source.flags;
|
|
142
|
+
if ((result.flags & 268435456 /* SymbolFlags.ConstEnumOnlyModule */) === 0)
|
|
143
|
+
sourceFlags &= ~268435456 /* SymbolFlags.ConstEnumOnlyModule */;
|
|
144
|
+
result.flags |= sourceFlags;
|
|
145
|
+
if (source.valueDeclaration !== undefined)
|
|
146
|
+
setValueDeclaration(result, source.valueDeclaration);
|
|
147
|
+
for (let i = 0; i < source.declarations.length; i++)
|
|
148
|
+
addDeclaration(result, source.declarations[i]);
|
|
149
|
+
if (source.members !== undefined) {
|
|
150
|
+
if (result.members === undefined)
|
|
151
|
+
result.members = new Map();
|
|
152
|
+
this.mergeTable(result.members, source.members, undefined);
|
|
153
|
+
}
|
|
154
|
+
if (source.exports !== undefined) {
|
|
155
|
+
if (result.exports === undefined)
|
|
156
|
+
result.exports = new Map();
|
|
157
|
+
this.mergeTable(result.exports, source.exports, result);
|
|
158
|
+
}
|
|
159
|
+
this.merged.set(source, result);
|
|
160
|
+
return result;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
function setValueDeclaration(symbol, node) {
|
|
164
|
+
const current = symbol.valueDeclaration;
|
|
165
|
+
if (current === undefined ||
|
|
166
|
+
(!((node.flags & 8388608 /* NodeFlags.Ambient */) !== 0 && (current.flags & 8388608 /* NodeFlags.Ambient */) === 0) &&
|
|
167
|
+
current.kind !== node.kind &&
|
|
168
|
+
current.kind === 268 /* SyntaxKind.ModuleDeclaration */))
|
|
169
|
+
symbol.valueDeclaration = node;
|
|
170
|
+
return true;
|
|
171
|
+
}
|
|
172
|
+
function excludedSymbolFlags(flags) {
|
|
173
|
+
let result = 0 /* SymbolFlags.None */;
|
|
174
|
+
if ((flags & 2 /* SymbolFlags.BlockScopedVariable */) !== 0)
|
|
175
|
+
result |= 111551 /* SymbolFlags.BlockScopedVariableExcludes */;
|
|
176
|
+
if ((flags & 1 /* SymbolFlags.FunctionScopedVariable */) !== 0)
|
|
177
|
+
result |= 111550 /* SymbolFlags.FunctionScopedVariableExcludes */;
|
|
178
|
+
if ((flags & 4 /* SymbolFlags.Property */) !== 0)
|
|
179
|
+
result |= 13243 /* SymbolFlags.PropertyExcludes */;
|
|
180
|
+
if ((flags & 8 /* SymbolFlags.EnumMember */) !== 0)
|
|
181
|
+
result |= 900095 /* SymbolFlags.EnumMemberExcludes */;
|
|
182
|
+
if ((flags & 16 /* SymbolFlags.Function */) !== 0)
|
|
183
|
+
result |= 110991 /* SymbolFlags.FunctionExcludes */;
|
|
184
|
+
if ((flags & 32 /* SymbolFlags.Class */) !== 0)
|
|
185
|
+
result |= 899503 /* SymbolFlags.ClassExcludes */;
|
|
186
|
+
if ((flags & 64 /* SymbolFlags.Interface */) !== 0)
|
|
187
|
+
result |= 788872 /* SymbolFlags.InterfaceExcludes */;
|
|
188
|
+
if ((flags & 256 /* SymbolFlags.RegularEnum */) !== 0)
|
|
189
|
+
result |= 899327 /* SymbolFlags.RegularEnumExcludes */;
|
|
190
|
+
if ((flags & 128 /* SymbolFlags.ConstEnum */) !== 0)
|
|
191
|
+
result |= 899967 /* SymbolFlags.ConstEnumExcludes */;
|
|
192
|
+
if ((flags & 512 /* SymbolFlags.ValueModule */) !== 0)
|
|
193
|
+
result |= 110735 /* SymbolFlags.ValueModuleExcludes */;
|
|
194
|
+
if ((flags & 8192 /* SymbolFlags.Method */) !== 0)
|
|
195
|
+
result |= 103359 /* SymbolFlags.MethodExcludes */;
|
|
196
|
+
if ((flags & 32768 /* SymbolFlags.GetAccessor */) !== 0)
|
|
197
|
+
result |= 46011 /* SymbolFlags.GetAccessorExcludes */;
|
|
198
|
+
if ((flags & 65536 /* SymbolFlags.SetAccessor */) !== 0)
|
|
199
|
+
result |= 78779 /* SymbolFlags.SetAccessorExcludes */;
|
|
200
|
+
if ((flags & 262144 /* SymbolFlags.TypeParameter */) !== 0)
|
|
201
|
+
result |= 526824 /* SymbolFlags.TypeParameterExcludes */;
|
|
202
|
+
if ((flags & 524288 /* SymbolFlags.TypeAlias */) !== 0)
|
|
203
|
+
result |= 788968 /* SymbolFlags.TypeAliasExcludes */;
|
|
204
|
+
if ((flags & 2097152 /* SymbolFlags.Alias */) !== 0)
|
|
205
|
+
result |= 2097152 /* SymbolFlags.AliasExcludes */;
|
|
206
|
+
return result;
|
|
207
|
+
}
|
|
208
|
+
/** Resolves names against merged symbols. */
|
|
209
|
+
class MergedNameResolver extends NameResolver {
|
|
210
|
+
merged;
|
|
211
|
+
aliases;
|
|
212
|
+
constructor(options, merged) {
|
|
213
|
+
super(options);
|
|
214
|
+
this.merged = merged;
|
|
215
|
+
this.globals = merged.table;
|
|
216
|
+
this.aliases = undefined;
|
|
217
|
+
}
|
|
218
|
+
getSymbolOfDeclaration(node) {
|
|
219
|
+
const symbol = getSymbol(node);
|
|
220
|
+
return symbol === undefined ? undefined : this.merged.getMergedSymbol(symbol);
|
|
221
|
+
}
|
|
222
|
+
/** As the checker: an alias has the meanings of what it resolves to. */
|
|
223
|
+
lookup(symbols, name, meaning) {
|
|
224
|
+
if (meaning === 0 /* SymbolFlags.None */)
|
|
225
|
+
return undefined;
|
|
226
|
+
const symbol = symbols.get(name);
|
|
227
|
+
if (symbol === undefined)
|
|
228
|
+
return undefined;
|
|
229
|
+
if ((symbol.flags & meaning) !== 0)
|
|
230
|
+
return symbol;
|
|
231
|
+
const aliases = this.aliases;
|
|
232
|
+
if ((symbol.flags & 2097152 /* SymbolFlags.Alias */) !== 0 && aliases !== undefined)
|
|
233
|
+
return (aliases.getSymbolFlags(symbol, false, false) & meaning) !== 0 ? symbol : undefined;
|
|
234
|
+
return undefined;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
const valueMeaning = 1048576 /* SymbolFlags.ExportValue */ | 111551 /* SymbolFlags.Value */ | 2097152 /* SymbolFlags.Alias */;
|
|
238
|
+
const maxAliasDepth = 64;
|
|
239
|
+
export class ReferenceResolver {
|
|
240
|
+
options;
|
|
241
|
+
merged;
|
|
242
|
+
names;
|
|
243
|
+
modules;
|
|
244
|
+
enumValues;
|
|
245
|
+
computedEnums;
|
|
246
|
+
aliasTargets;
|
|
247
|
+
/** Value symbols of identifiers resolved as expressions, as the checker caches them. */
|
|
248
|
+
resolvedSymbols;
|
|
249
|
+
unresolvedReferences;
|
|
250
|
+
unresolvedAliases;
|
|
251
|
+
resolvingAliases;
|
|
252
|
+
/** The module each module specifier names (`null` for none), by specifier. */
|
|
253
|
+
specifierModules;
|
|
254
|
+
/** Results of `isTypeOnlyAliasChain`, for queries outside alias resolution. */
|
|
255
|
+
typeOnlyChains;
|
|
256
|
+
/** With `merged`, the globals of `files` as another resolver merged them (`EmitIndexes`), not merged again. */
|
|
257
|
+
constructor(options, files, modules, merged = undefined) {
|
|
258
|
+
this.options = options;
|
|
259
|
+
this.merged = merged !== undefined ? merged : new MergedGlobals();
|
|
260
|
+
this.names = new MergedNameResolver(options, this.merged);
|
|
261
|
+
this.modules = modules !== undefined ? modules : new NoModules();
|
|
262
|
+
this.enumValues = new Map();
|
|
263
|
+
this.computedEnums = new Set();
|
|
264
|
+
this.aliasTargets = new Map();
|
|
265
|
+
this.resolvedSymbols = new Map();
|
|
266
|
+
this.unresolvedReferences = new Set();
|
|
267
|
+
this.unresolvedAliases = new Set();
|
|
268
|
+
this.resolvingAliases = new Set();
|
|
269
|
+
this.specifierModules = new Map();
|
|
270
|
+
this.typeOnlyChains = new Map();
|
|
271
|
+
this.names.aliases = this;
|
|
272
|
+
if (merged === undefined)
|
|
273
|
+
this.merged.merge(files, this);
|
|
274
|
+
}
|
|
275
|
+
getMergedSymbol(symbol) {
|
|
276
|
+
return this.merged.getMergedSymbol(symbol);
|
|
277
|
+
}
|
|
278
|
+
getSymbolOfDeclaration(node) {
|
|
279
|
+
return this.names.getSymbolOfDeclaration(node);
|
|
280
|
+
}
|
|
281
|
+
resolveName(location, name, meaning) {
|
|
282
|
+
return this.names.resolve(location, name, meaning, undefined, false, false);
|
|
283
|
+
}
|
|
284
|
+
/** The value an identifier in an expression refers to, cached for later queries of the identifier. */
|
|
285
|
+
getResolvedSymbol(node) {
|
|
286
|
+
const cached = this.resolvedSymbols.get(node);
|
|
287
|
+
if (cached !== undefined)
|
|
288
|
+
return cached;
|
|
289
|
+
if (this.unresolvedReferences.has(node))
|
|
290
|
+
return undefined;
|
|
291
|
+
const symbol = this.resolveName(node, node.text, 111551 /* SymbolFlags.Value */ | 1048576 /* SymbolFlags.ExportValue */);
|
|
292
|
+
if (symbol === undefined)
|
|
293
|
+
this.unresolvedReferences.add(node);
|
|
294
|
+
else
|
|
295
|
+
this.resolvedSymbols.set(node, symbol);
|
|
296
|
+
return symbol;
|
|
297
|
+
}
|
|
298
|
+
getReferencedValueSymbol(reference, startInDeclarationContainer) {
|
|
299
|
+
// An identifier resolved as an expression keeps that meaning, as with the checker's cache.
|
|
300
|
+
const cached = this.resolvedSymbols.get(reference);
|
|
301
|
+
if (cached !== undefined)
|
|
302
|
+
return cached;
|
|
303
|
+
if (this.unresolvedReferences.has(reference))
|
|
304
|
+
return undefined;
|
|
305
|
+
let location = reference;
|
|
306
|
+
const parent = reference.parent;
|
|
307
|
+
if (startInDeclarationContainer && parent !== undefined && isSameNode(getName(parent), reference)) {
|
|
308
|
+
const container = getDeclarationContainer(parent);
|
|
309
|
+
if (container !== undefined)
|
|
310
|
+
location = container;
|
|
311
|
+
}
|
|
312
|
+
return this.resolveName(location, reference.text, valueMeaning);
|
|
313
|
+
}
|
|
314
|
+
getParentOfSymbol(symbol) {
|
|
315
|
+
const parent = symbol.parent;
|
|
316
|
+
return parent === undefined ? undefined : this.getMergedSymbol(parent);
|
|
317
|
+
}
|
|
318
|
+
getExportSymbolOfValueSymbolIfExported(symbol) {
|
|
319
|
+
const exportSymbol = symbol.exportSymbol;
|
|
320
|
+
if ((symbol.flags & 1048576 /* SymbolFlags.ExportValue */) !== 0 && exportSymbol !== undefined)
|
|
321
|
+
return this.getMergedSymbol(exportSymbol);
|
|
322
|
+
return this.getMergedSymbol(symbol);
|
|
323
|
+
}
|
|
324
|
+
/** The source file, namespace or enum whose export `node` refers to, if it refers to an export. */
|
|
325
|
+
getReferencedExportContainer(node, prefixLocals) {
|
|
326
|
+
const parent = node.parent;
|
|
327
|
+
const startInDeclarationContainer = parent !== undefined &&
|
|
328
|
+
(parent.kind === 268 /* SyntaxKind.ModuleDeclaration */ || parent.kind === 267 /* SyntaxKind.EnumDeclaration */) &&
|
|
329
|
+
isSameNode(getName(parent), node);
|
|
330
|
+
let symbol = this.getReferencedValueSymbol(node, startInDeclarationContainer);
|
|
331
|
+
if (symbol === undefined)
|
|
332
|
+
return undefined;
|
|
333
|
+
if ((symbol.flags & 1048576 /* SymbolFlags.ExportValue */) !== 0) {
|
|
334
|
+
const local = symbol.exportSymbol;
|
|
335
|
+
if (local === undefined)
|
|
336
|
+
return undefined;
|
|
337
|
+
const exportSymbol = this.getMergedSymbol(local);
|
|
338
|
+
if (!prefixLocals &&
|
|
339
|
+
(exportSymbol.flags & 944 /* SymbolFlags.ExportHasLocal */) !== 0 &&
|
|
340
|
+
(exportSymbol.flags & 3 /* SymbolFlags.Variable */) === 0)
|
|
341
|
+
return undefined;
|
|
342
|
+
symbol = exportSymbol;
|
|
343
|
+
}
|
|
344
|
+
const parentSymbol = this.getParentOfSymbol(symbol);
|
|
345
|
+
if (parentSymbol === undefined)
|
|
346
|
+
return undefined;
|
|
347
|
+
const valueDeclaration = parentSymbol.valueDeclaration;
|
|
348
|
+
if ((parentSymbol.flags & 512 /* SymbolFlags.ValueModule */) !== 0 &&
|
|
349
|
+
valueDeclaration !== undefined &&
|
|
350
|
+
valueDeclaration.kind === 307 /* SyntaxKind.SourceFile */)
|
|
351
|
+
return valueDeclaration === getSourceFileOfNode(node) ? valueDeclaration : undefined;
|
|
352
|
+
for (let current = node.parent; current !== undefined; current = current.parent) {
|
|
353
|
+
if ((current.kind === 268 /* SyntaxKind.ModuleDeclaration */ || current.kind === 267 /* SyntaxKind.EnumDeclaration */) &&
|
|
354
|
+
this.getSymbolOfDeclaration(current) === parentSymbol)
|
|
355
|
+
return current;
|
|
356
|
+
}
|
|
357
|
+
return undefined;
|
|
358
|
+
}
|
|
359
|
+
/** The import declaring the alias `node` refers to, unless a local value shadows it. */
|
|
360
|
+
getReferencedImportDeclaration(node) {
|
|
361
|
+
// As the checker: an identifier that didn't resolve as a value may still name an alias.
|
|
362
|
+
const reference = node;
|
|
363
|
+
let symbol = this.resolvedSymbols.get(reference);
|
|
364
|
+
if (symbol === undefined)
|
|
365
|
+
symbol = this.resolveName(node, node.text, valueMeaning);
|
|
366
|
+
if (symbol === undefined ||
|
|
367
|
+
!isNonLocalAlias(symbol, 111551 /* SymbolFlags.Value */) ||
|
|
368
|
+
this.getTypeOnlyAliasDeclarationFor(symbol, 111551 /* SymbolFlags.Value */))
|
|
369
|
+
return undefined;
|
|
370
|
+
return getDeclarationOfAliasSymbol(symbol);
|
|
371
|
+
}
|
|
372
|
+
/** Whether an alias reaches a type-only declaration before a symbol with `meaning`. */
|
|
373
|
+
getTypeOnlyAliasDeclarationFor(symbol, meaning) {
|
|
374
|
+
let current = symbol;
|
|
375
|
+
for (let depth = 0; depth < maxAliasDepth; depth++) {
|
|
376
|
+
if ((current.flags & 2097152 /* SymbolFlags.Alias */) === 0 || (current.flags & meaning) !== 0)
|
|
377
|
+
return false;
|
|
378
|
+
const resolved = this.resolveAlias(current);
|
|
379
|
+
if (this.isTypeOnlyAliasChain(current))
|
|
380
|
+
return true;
|
|
381
|
+
if (resolved === undefined || resolved === current)
|
|
382
|
+
return false;
|
|
383
|
+
current = resolved;
|
|
384
|
+
}
|
|
385
|
+
return false;
|
|
386
|
+
}
|
|
387
|
+
getReferencedValueDeclaration(node) {
|
|
388
|
+
const symbol = this.getReferencedValueSymbol(node, false);
|
|
389
|
+
return symbol === undefined ? undefined : this.getExportSymbolOfValueSymbolIfExported(symbol).valueDeclaration;
|
|
390
|
+
}
|
|
391
|
+
getReferencedValueDeclarations(node) {
|
|
392
|
+
const resolved = this.getReferencedValueSymbol(node, false);
|
|
393
|
+
if (resolved === undefined)
|
|
394
|
+
return undefined;
|
|
395
|
+
const symbol = this.getExportSymbolOfValueSymbolIfExported(resolved);
|
|
396
|
+
const declarations = [];
|
|
397
|
+
for (const declaration of symbol.declarations)
|
|
398
|
+
if (isValueDeclarationKind(declaration.kind))
|
|
399
|
+
declarations.push(declaration);
|
|
400
|
+
return declarations;
|
|
401
|
+
}
|
|
402
|
+
// Aliases
|
|
403
|
+
/** The export `name` of a namespace, enum or module. */
|
|
404
|
+
getExportOfSymbol(symbol, name) {
|
|
405
|
+
const declaration = symbol.valueDeclaration;
|
|
406
|
+
if (declaration instanceof SourceFile)
|
|
407
|
+
return this.getExportOfModule(symbol, name);
|
|
408
|
+
const exports = symbol.exports;
|
|
409
|
+
const member = exports === undefined ? undefined : exports.get(name);
|
|
410
|
+
return member === undefined ? undefined : this.getMergedSymbol(member);
|
|
411
|
+
}
|
|
412
|
+
isTypeOnlyAliasSymbol(symbol) {
|
|
413
|
+
return this.isTypeOnlyAlias(symbol);
|
|
414
|
+
}
|
|
415
|
+
/** Whether an alias is declared type-only; as in the checker, a default import counts only if its module resolves. */
|
|
416
|
+
isTypeOnlyAlias(symbol) {
|
|
417
|
+
const declaration = getDeclarationOfAliasSymbol(symbol);
|
|
418
|
+
if (declaration instanceof ImportClause) {
|
|
419
|
+
const importDeclaration = declaration.parent;
|
|
420
|
+
if (importDeclaration === undefined ||
|
|
421
|
+
this.resolveModuleSpecifier(declaration, getModuleSpecifierOf(importDeclaration)) === undefined)
|
|
422
|
+
return false;
|
|
423
|
+
}
|
|
424
|
+
if (isTypeOnlyAlias(symbol))
|
|
425
|
+
return true;
|
|
426
|
+
// An import found through `export type * from`.
|
|
427
|
+
if (declaration === undefined)
|
|
428
|
+
return false;
|
|
429
|
+
const imported = importedNameOf(declaration);
|
|
430
|
+
const moduleDeclaration = moduleDeclarationOfSpecifier(declaration);
|
|
431
|
+
if (imported === undefined || moduleDeclaration === undefined)
|
|
432
|
+
return false;
|
|
433
|
+
const moduleSymbol = this.resolveModuleSpecifier(declaration, getModuleSpecifierOf(moduleDeclaration));
|
|
434
|
+
return moduleSymbol !== undefined && this.isExportedThroughTypeOnlyStar(moduleSymbol, imported, new Set());
|
|
435
|
+
}
|
|
436
|
+
/** Whether a module's export `name` comes from another module through an `export type *` on the way. */
|
|
437
|
+
isExportedThroughTypeOnlyStar(moduleSymbol, name, visited) {
|
|
438
|
+
if (visited.has(moduleSymbol))
|
|
439
|
+
return false;
|
|
440
|
+
visited.add(moduleSymbol);
|
|
441
|
+
const exports = moduleSymbol.exports;
|
|
442
|
+
if (exports === undefined || exports.has(name) || name === "default" /* InternalSymbolName.Default */)
|
|
443
|
+
return false;
|
|
444
|
+
const star = exports.get("\uFFFEexport" /* InternalSymbolName.ExportStar */);
|
|
445
|
+
if (star === undefined)
|
|
446
|
+
return false;
|
|
447
|
+
for (const declaration of star.declarations) {
|
|
448
|
+
if (!(declaration instanceof ExportDeclaration))
|
|
449
|
+
continue;
|
|
450
|
+
const target = this.resolveExternalModuleSymbol(this.resolveModuleSpecifier(declaration, declaration.moduleSpecifier));
|
|
451
|
+
if (target === undefined || this.getExportFromTable(target, name, new Set()) === undefined)
|
|
452
|
+
continue;
|
|
453
|
+
return declaration.isTypeOnly || this.isExportedThroughTypeOnlyStar(target, name, visited);
|
|
454
|
+
}
|
|
455
|
+
return false;
|
|
456
|
+
}
|
|
457
|
+
/** Whether a symbol is declared in the global scope. */
|
|
458
|
+
isGlobalSymbol(symbol) {
|
|
459
|
+
if (symbol.declarations.length === 0)
|
|
460
|
+
return false;
|
|
461
|
+
const container = getDeclarationContainer(symbol.declarations[0]);
|
|
462
|
+
return container instanceof SourceFile && !isExternalOrCommonJSModule(container);
|
|
463
|
+
}
|
|
464
|
+
/** Whether a symbol is a value at runtime: const enums aren't unless preserved. */
|
|
465
|
+
isValueSymbol(symbol) {
|
|
466
|
+
return ((symbol.flags & 111551 /* SymbolFlags.Value */) !== 0 &&
|
|
467
|
+
(shouldPreserveConstEnums(this.options) ||
|
|
468
|
+
((symbol.flags & 128 /* SymbolFlags.ConstEnum */) === 0 && (symbol.flags & 268435456 /* SymbolFlags.ConstEnumOnlyModule */) === 0)));
|
|
469
|
+
}
|
|
470
|
+
/** Whether an alias refers to a value, counting unresolved aliases as values; `excludeTypeOnly` stops at type-only imports. */
|
|
471
|
+
isAliasResolvedToValue(symbol, excludeTypeOnly) {
|
|
472
|
+
const resolved = this.resolveAlias(symbol);
|
|
473
|
+
if (resolved === undefined)
|
|
474
|
+
return !excludeTypeOnly || !this.isTypeOnlyAliasChain(symbol);
|
|
475
|
+
const target = this.getExportSymbolOfValueSymbolIfExported(resolved);
|
|
476
|
+
return ((this.getSymbolFlags(symbol, excludeTypeOnly, true) & 111551 /* SymbolFlags.Value */) !== 0 &&
|
|
477
|
+
(shouldPreserveConstEnums(this.options) ||
|
|
478
|
+
((target.flags & 128 /* SymbolFlags.ConstEnum */) === 0 && (target.flags & 268435456 /* SymbolFlags.ConstEnumOnlyModule */) === 0)));
|
|
479
|
+
}
|
|
480
|
+
/**
|
|
481
|
+
* Whether an alias is type-only, itself or through the aliases it directly names. Cached unless an
|
|
482
|
+
* alias is being resolved, when the answer can depend on which.
|
|
483
|
+
*/
|
|
484
|
+
isTypeOnlyAliasChain(symbol) {
|
|
485
|
+
if (this.resolvingAliases.size > 0)
|
|
486
|
+
return this.computeTypeOnlyAliasChain(symbol);
|
|
487
|
+
let result = this.typeOnlyChains.get(symbol);
|
|
488
|
+
if (result === undefined) {
|
|
489
|
+
result = this.computeTypeOnlyAliasChain(symbol);
|
|
490
|
+
this.typeOnlyChains.set(symbol, result);
|
|
491
|
+
}
|
|
492
|
+
return result;
|
|
493
|
+
}
|
|
494
|
+
computeTypeOnlyAliasChain(symbol) {
|
|
495
|
+
let current = symbol;
|
|
496
|
+
for (let depth = 0; depth < maxAliasDepth && (current.flags & 2097152 /* SymbolFlags.Alias */) !== 0; depth++) {
|
|
497
|
+
if (this.isTypeOnlyAlias(current))
|
|
498
|
+
return true;
|
|
499
|
+
const declaration = getDeclarationOfAliasSymbol(current);
|
|
500
|
+
const next = declaration === undefined ? undefined : this.getTargetOfAliasDeclaration(declaration);
|
|
501
|
+
// Only a pure alias passes on its type-only-ness.
|
|
502
|
+
if (next === undefined || !isPureAlias(next))
|
|
503
|
+
return false;
|
|
504
|
+
current = next;
|
|
505
|
+
}
|
|
506
|
+
return false;
|
|
507
|
+
}
|
|
508
|
+
/** The symbol an alias ultimately refers to, or undefined if it can't be resolved. */
|
|
509
|
+
resolveAlias(symbol) {
|
|
510
|
+
if ((symbol.flags & 2097152 /* SymbolFlags.Alias */) === 0)
|
|
511
|
+
return symbol;
|
|
512
|
+
const cached = this.aliasTargets.get(symbol);
|
|
513
|
+
if (cached !== undefined)
|
|
514
|
+
return cached;
|
|
515
|
+
if (this.unresolvedAliases.has(symbol) || this.resolvingAliases.has(symbol))
|
|
516
|
+
return undefined;
|
|
517
|
+
this.resolvingAliases.add(symbol);
|
|
518
|
+
const declaration = getDeclarationOfAliasSymbol(symbol);
|
|
519
|
+
const next = declaration === undefined ? undefined : this.getTargetOfAliasDeclaration(declaration);
|
|
520
|
+
// Only a pure alias is followed; one merged with other meanings is the target itself.
|
|
521
|
+
const target = next === undefined ? undefined : isPureAlias(next) ? this.resolveAlias(next) : next;
|
|
522
|
+
this.resolvingAliases.delete(symbol);
|
|
523
|
+
if (target === undefined)
|
|
524
|
+
this.unresolvedAliases.add(symbol);
|
|
525
|
+
else
|
|
526
|
+
this.aliasTargets.set(symbol, target);
|
|
527
|
+
return target;
|
|
528
|
+
}
|
|
529
|
+
/** The flags of a symbol and the aliases it resolves through; all flags for an unresolved alias. */
|
|
530
|
+
getSymbolFlags(start, excludeTypeOnly, excludeLocal) {
|
|
531
|
+
let symbol = start;
|
|
532
|
+
let flags = excludeLocal ? 0 /* SymbolFlags.None */ : symbol.flags;
|
|
533
|
+
const seen = new Set();
|
|
534
|
+
while ((symbol.flags & 2097152 /* SymbolFlags.Alias */) !== 0) {
|
|
535
|
+
if (excludeTypeOnly && this.isTypeOnlyAliasChain(symbol))
|
|
536
|
+
break;
|
|
537
|
+
const resolved = this.resolveAlias(symbol);
|
|
538
|
+
if (resolved === undefined)
|
|
539
|
+
return 1073741823 /* SymbolFlags.All */;
|
|
540
|
+
const target = this.getExportSymbolOfValueSymbolIfExported(resolved);
|
|
541
|
+
if ((target.flags & 2097152 /* SymbolFlags.Alias */) !== 0) {
|
|
542
|
+
if (target === symbol || seen.has(target))
|
|
543
|
+
break;
|
|
544
|
+
seen.add(symbol);
|
|
545
|
+
seen.add(target);
|
|
546
|
+
}
|
|
547
|
+
flags |= target.flags;
|
|
548
|
+
symbol = target;
|
|
549
|
+
}
|
|
550
|
+
return flags;
|
|
551
|
+
}
|
|
552
|
+
getTargetOfAliasDeclaration(node) {
|
|
553
|
+
if (node instanceof ImportEqualsDeclaration) {
|
|
554
|
+
const reference = node.moduleReference;
|
|
555
|
+
if (reference instanceof ExternalModuleReference)
|
|
556
|
+
return this.resolveExternalModuleSymbol(this.resolveModuleSpecifier(node, reference.expression));
|
|
557
|
+
// `import a = b` names a namespace; `import a = b.c` anything.
|
|
558
|
+
const meaning = reference instanceof Identifier
|
|
559
|
+
? 1920 /* SymbolFlags.Namespace */
|
|
560
|
+
: 111551 /* SymbolFlags.Value */ | 788968 /* SymbolFlags.Type */ | 1920 /* SymbolFlags.Namespace */;
|
|
561
|
+
return this.resolveEntityName(reference, meaning, true);
|
|
562
|
+
}
|
|
563
|
+
if (node instanceof ImportClause) {
|
|
564
|
+
const declaration = node.parent;
|
|
565
|
+
if (declaration === undefined)
|
|
566
|
+
return undefined;
|
|
567
|
+
const moduleSymbol = this.resolveModuleSpecifier(node, getModuleSpecifierOf(declaration));
|
|
568
|
+
if (moduleSymbol === undefined)
|
|
569
|
+
return undefined;
|
|
570
|
+
const exported = this.getExportOfModule(moduleSymbol, "default" /* InternalSymbolName.Default */);
|
|
571
|
+
return exported !== undefined ? exported : this.resolveExternalModuleSymbol(moduleSymbol);
|
|
572
|
+
}
|
|
573
|
+
if (node instanceof NamespaceImport) {
|
|
574
|
+
const clause = node.parent;
|
|
575
|
+
const declaration = clause === undefined ? undefined : clause.parent;
|
|
576
|
+
if (declaration === undefined)
|
|
577
|
+
return undefined;
|
|
578
|
+
return this.resolveExternalModuleSymbol(this.resolveModuleSpecifier(node, getModuleSpecifierOf(declaration)));
|
|
579
|
+
}
|
|
580
|
+
if (node instanceof ImportSpecifier) {
|
|
581
|
+
const declaration = node.parent === undefined ? undefined : node.parent.parent;
|
|
582
|
+
const importDeclaration = declaration === undefined ? undefined : declaration.parent;
|
|
583
|
+
if (importDeclaration === undefined)
|
|
584
|
+
return undefined;
|
|
585
|
+
const moduleSymbol = this.resolveModuleSpecifier(node, getModuleSpecifierOf(importDeclaration));
|
|
586
|
+
if (moduleSymbol === undefined)
|
|
587
|
+
return undefined;
|
|
588
|
+
const name = node.propertyName !== undefined ? node.propertyName : node.name;
|
|
589
|
+
return this.getExportOfModule(moduleSymbol, moduleExportNameText(name));
|
|
590
|
+
}
|
|
591
|
+
if (node instanceof ExportSpecifier) {
|
|
592
|
+
const exportDeclaration = node.parent === undefined ? undefined : node.parent.parent;
|
|
593
|
+
const local = node.propertyName !== undefined ? node.propertyName : node.name;
|
|
594
|
+
if (exportDeclaration instanceof ExportDeclaration && exportDeclaration.moduleSpecifier !== undefined) {
|
|
595
|
+
const moduleSymbol = this.resolveModuleSpecifier(node, exportDeclaration.moduleSpecifier);
|
|
596
|
+
return moduleSymbol === undefined
|
|
597
|
+
? undefined
|
|
598
|
+
: this.getExportOfModule(moduleSymbol, moduleExportNameText(local));
|
|
599
|
+
}
|
|
600
|
+
if (!(local instanceof Identifier))
|
|
601
|
+
return undefined;
|
|
602
|
+
return this.resolveName(local, local.text, 111551 /* SymbolFlags.Value */ | 788968 /* SymbolFlags.Type */ | 1920 /* SymbolFlags.Namespace */);
|
|
603
|
+
}
|
|
604
|
+
if (node instanceof ExportAssignment) {
|
|
605
|
+
const expression = node.expression;
|
|
606
|
+
if (expression.kind === 79 /* SyntaxKind.Identifier */ || expression.kind === 212 /* SyntaxKind.PropertyAccessExpression */)
|
|
607
|
+
return this.resolveEntityName(expression, 111551 /* SymbolFlags.Value */ | 788968 /* SymbolFlags.Type */ | 1920 /* SymbolFlags.Namespace */, true);
|
|
608
|
+
return getSymbol(node);
|
|
609
|
+
}
|
|
610
|
+
return undefined;
|
|
611
|
+
}
|
|
612
|
+
/** The module an implicit import of `file`, such as the JSX runtime, refers to. */
|
|
613
|
+
resolveImplicitImport(file, name) {
|
|
614
|
+
const specifier = new StringLiteral(name, 0 /* TokenFlags.None */);
|
|
615
|
+
const declaration = new ImportDeclaration(273 /* SyntaxKind.ImportDeclaration */, undefined, undefined, specifier, undefined);
|
|
616
|
+
specifier.parent = declaration;
|
|
617
|
+
declaration.parent = file;
|
|
618
|
+
return this.resolveModuleSpecifier(specifier, specifier);
|
|
619
|
+
}
|
|
620
|
+
/** The module `specifier` names; `location` is in the same file. */
|
|
621
|
+
resolveModuleSpecifier(location, specifier) {
|
|
622
|
+
if (specifier === undefined)
|
|
623
|
+
return undefined;
|
|
624
|
+
const cached = this.specifierModules.get(specifier);
|
|
625
|
+
if (cached !== undefined)
|
|
626
|
+
return cached === null ? undefined : cached;
|
|
627
|
+
const result = this.computeModuleOfSpecifier(location, specifier);
|
|
628
|
+
this.specifierModules.set(specifier, result === undefined ? null : result);
|
|
629
|
+
return result;
|
|
630
|
+
}
|
|
631
|
+
computeModuleOfSpecifier(location, specifier) {
|
|
632
|
+
const name = stringLiteralText(specifier);
|
|
633
|
+
if (name === undefined)
|
|
634
|
+
return undefined;
|
|
635
|
+
// Ambient modules, `declare module "m"`, come first for names that aren't relative.
|
|
636
|
+
if (!pathIsRelative(name)) {
|
|
637
|
+
const ambient = this.merged.table.get('"' + name + '"');
|
|
638
|
+
if (ambient !== undefined && (ambient.flags & 1536 /* SymbolFlags.Module */) !== 0)
|
|
639
|
+
return ambient;
|
|
640
|
+
}
|
|
641
|
+
const file = this.modules.resolveModule(specifier, getSourceFileOfNode(location), name);
|
|
642
|
+
if (file === undefined)
|
|
643
|
+
return undefined;
|
|
644
|
+
const symbol = getSymbol(file);
|
|
645
|
+
return symbol === undefined ? undefined : this.getMergedSymbol(symbol);
|
|
646
|
+
}
|
|
647
|
+
/** The `export =` target of a module, or the module itself. */
|
|
648
|
+
resolveExternalModuleSymbol(moduleSymbol) {
|
|
649
|
+
if (moduleSymbol === undefined || moduleSymbol.exports === undefined)
|
|
650
|
+
return moduleSymbol;
|
|
651
|
+
const exportEquals = moduleSymbol.exports.get("export=" /* InternalSymbolName.ExportEquals */);
|
|
652
|
+
if (exportEquals === undefined)
|
|
653
|
+
return moduleSymbol;
|
|
654
|
+
const resolved = this.resolveAlias(exportEquals);
|
|
655
|
+
return resolved !== undefined ? resolved : exportEquals;
|
|
656
|
+
}
|
|
657
|
+
getExportOfModule(moduleSymbol, name) {
|
|
658
|
+
const target = this.resolveExternalModuleSymbol(moduleSymbol);
|
|
659
|
+
if (target === undefined)
|
|
660
|
+
return undefined;
|
|
661
|
+
const visited = new Set();
|
|
662
|
+
return this.getExportFromTable(target, name, visited);
|
|
663
|
+
}
|
|
664
|
+
getExportFromTable(moduleSymbol, name, visited) {
|
|
665
|
+
if (visited.has(moduleSymbol))
|
|
666
|
+
return undefined;
|
|
667
|
+
visited.add(moduleSymbol);
|
|
668
|
+
const exports = moduleSymbol.exports;
|
|
669
|
+
if (exports === undefined)
|
|
670
|
+
return undefined;
|
|
671
|
+
// The export itself, an alias the caller resolves, so type-only exports pass on.
|
|
672
|
+
const direct = exports.get(name);
|
|
673
|
+
if (direct !== undefined)
|
|
674
|
+
return this.getMergedSymbol(direct);
|
|
675
|
+
if (name === "default" /* InternalSymbolName.Default */)
|
|
676
|
+
return undefined;
|
|
677
|
+
const star = exports.get("\uFFFEexport" /* InternalSymbolName.ExportStar */);
|
|
678
|
+
if (star === undefined)
|
|
679
|
+
return undefined;
|
|
680
|
+
for (const declaration of star.declarations) {
|
|
681
|
+
if (!(declaration instanceof ExportDeclaration))
|
|
682
|
+
continue;
|
|
683
|
+
const target = this.resolveExternalModuleSymbol(this.resolveModuleSpecifier(declaration, declaration.moduleSpecifier));
|
|
684
|
+
if (target === undefined)
|
|
685
|
+
continue;
|
|
686
|
+
const found = this.getExportFromTable(target, name, visited);
|
|
687
|
+
if (found !== undefined)
|
|
688
|
+
return found;
|
|
689
|
+
}
|
|
690
|
+
return undefined;
|
|
691
|
+
}
|
|
692
|
+
/** The symbol an identifier or dotted name refers to with `meaning`, through aliases unless `dontResolveAlias`. */
|
|
693
|
+
resolveEntityName(name, meaning, dontResolveAlias) {
|
|
694
|
+
let symbol;
|
|
695
|
+
if (name instanceof Identifier) {
|
|
696
|
+
const resolved = this.resolveName(name, name.text, meaning | 2097152 /* SymbolFlags.Alias */);
|
|
697
|
+
symbol = resolved === undefined ? undefined : this.getMergedSymbol(resolved);
|
|
698
|
+
}
|
|
699
|
+
else if (name.kind === 167 /* SyntaxKind.QualifiedName */ || name.kind === 212 /* SyntaxKind.PropertyAccessExpression */) {
|
|
700
|
+
const left = entityNameLeft(name);
|
|
701
|
+
const right = entityNameRight(name);
|
|
702
|
+
if (left === undefined || !(right instanceof Identifier))
|
|
703
|
+
return undefined;
|
|
704
|
+
const namespace = this.resolveEntityName(left, 1920 /* SymbolFlags.Namespace */, false);
|
|
705
|
+
if (namespace === undefined)
|
|
706
|
+
return undefined;
|
|
707
|
+
const exports = namespace.exports;
|
|
708
|
+
let member = exports === undefined ? undefined : exports.get(right.text);
|
|
709
|
+
// A namespace merged with an alias also has the members of what the alias names, as its type does.
|
|
710
|
+
if (member === undefined && (namespace.flags & 2097152 /* SymbolFlags.Alias */) !== 0) {
|
|
711
|
+
const target = this.resolveAlias(namespace);
|
|
712
|
+
const targetExports = target === undefined ? undefined : target.exports;
|
|
713
|
+
if (targetExports !== undefined)
|
|
714
|
+
member = targetExports.get(right.text);
|
|
715
|
+
}
|
|
716
|
+
if (member === undefined || (member.flags & (meaning | 2097152 /* SymbolFlags.Alias */)) === 0)
|
|
717
|
+
return undefined;
|
|
718
|
+
symbol = this.getMergedSymbol(member);
|
|
719
|
+
}
|
|
720
|
+
else
|
|
721
|
+
return undefined;
|
|
722
|
+
if (symbol === undefined)
|
|
723
|
+
return undefined;
|
|
724
|
+
if (!dontResolveAlias && (symbol.flags & 2097152 /* SymbolFlags.Alias */) !== 0) {
|
|
725
|
+
const target = this.resolveAlias(symbol);
|
|
726
|
+
return target === undefined ? undefined : this.getMergedSymbol(target);
|
|
727
|
+
}
|
|
728
|
+
return symbol;
|
|
729
|
+
}
|
|
730
|
+
// Constant values
|
|
731
|
+
/** The value of an enum member, computing the values of its whole declaration. */
|
|
732
|
+
getEnumMemberValue(member) {
|
|
733
|
+
const declaration = member.parent;
|
|
734
|
+
if (declaration instanceof EnumDeclaration)
|
|
735
|
+
this.computeEnumMemberValues(declaration);
|
|
736
|
+
const value = this.enumValues.get(member);
|
|
737
|
+
return value !== undefined ? value : noEvaluation;
|
|
738
|
+
}
|
|
739
|
+
/** The inlined value of a const enum member access such as `E.A` or `E["A"]`. */
|
|
740
|
+
getConstantValue(node) {
|
|
741
|
+
if (node instanceof EnumMember)
|
|
742
|
+
return this.getEnumMemberValue(node);
|
|
743
|
+
let symbol;
|
|
744
|
+
if (node instanceof PropertyAccessExpression) {
|
|
745
|
+
if (isEntityNameExpressionNode(node))
|
|
746
|
+
symbol = this.resolveEntityName(node, 111551 /* SymbolFlags.Value */, false);
|
|
747
|
+
}
|
|
748
|
+
else if (node instanceof ElementAccessExpression) {
|
|
749
|
+
const argument = stringLiteralText(node.argumentExpression);
|
|
750
|
+
if (isEntityNameExpressionNode(node.expression) && argument !== undefined) {
|
|
751
|
+
const root = this.resolveEntityName(node.expression, 111551 /* SymbolFlags.Value */, false);
|
|
752
|
+
const exports = root === undefined ? undefined : root.exports;
|
|
753
|
+
const member = exports === undefined ? undefined : exports.get(argument);
|
|
754
|
+
if (member !== undefined)
|
|
755
|
+
symbol = this.getMergedSymbol(member);
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
if (symbol === undefined || (symbol.flags & 8 /* SymbolFlags.EnumMember */) === 0)
|
|
759
|
+
return noEvaluation;
|
|
760
|
+
const declaration = symbol.valueDeclaration;
|
|
761
|
+
if (declaration === undefined || declaration.parent === undefined || !isEnumConst(declaration.parent))
|
|
762
|
+
return noEvaluation;
|
|
763
|
+
return this.getEnumMemberValue(declaration);
|
|
764
|
+
}
|
|
765
|
+
computeEnumMemberValues(node) {
|
|
766
|
+
if (this.computedEnums.has(node))
|
|
767
|
+
return false;
|
|
768
|
+
this.computedEnums.add(node);
|
|
769
|
+
const members = node.members.nodes;
|
|
770
|
+
let hasAutoValue = true;
|
|
771
|
+
let autoValue = 0;
|
|
772
|
+
for (const member of members) {
|
|
773
|
+
let result = noEvaluation;
|
|
774
|
+
if (member instanceof EnumMember) {
|
|
775
|
+
if (member.initializer !== undefined)
|
|
776
|
+
result = this.evaluate(member.initializer, member);
|
|
777
|
+
else if ((node.flags & 8388608 /* NodeFlags.Ambient */) !== 0 && !isEnumConst(node))
|
|
778
|
+
result = noEvaluation;
|
|
779
|
+
else if (hasAutoValue)
|
|
780
|
+
result = numberEvaluation(autoValue);
|
|
781
|
+
}
|
|
782
|
+
this.enumValues.set(member, result);
|
|
783
|
+
hasAutoValue = result.kind === 1 /* ConstantKind.Number */;
|
|
784
|
+
if (hasAutoValue)
|
|
785
|
+
autoValue = result.number + 1;
|
|
786
|
+
}
|
|
787
|
+
return true;
|
|
788
|
+
}
|
|
789
|
+
/** Evaluates a constant expression at `location`, as the checker's evaluator does. */
|
|
790
|
+
evaluate(node, location) {
|
|
791
|
+
const expression = skipEvaluationParentheses(node);
|
|
792
|
+
if (expression instanceof PrefixUnaryExpression) {
|
|
793
|
+
const operand = this.evaluate(expression.operand, location);
|
|
794
|
+
if (operand.kind === 1 /* ConstantKind.Number */) {
|
|
795
|
+
const value = operand.number;
|
|
796
|
+
switch (expression.operator) {
|
|
797
|
+
case 39 /* SyntaxKind.PlusToken */:
|
|
798
|
+
return numberEvaluation(value).withFlags(false, operand.resolvedOtherFiles, operand.hasExternalReferences);
|
|
799
|
+
case 40 /* SyntaxKind.MinusToken */:
|
|
800
|
+
return numberEvaluation(-value).withFlags(false, operand.resolvedOtherFiles, operand.hasExternalReferences);
|
|
801
|
+
case 54 /* SyntaxKind.TildeToken */:
|
|
802
|
+
return numberEvaluation(~value).withFlags(false, operand.resolvedOtherFiles, operand.hasExternalReferences);
|
|
803
|
+
}
|
|
804
|
+
}
|
|
805
|
+
return noValue(false, operand.resolvedOtherFiles, operand.hasExternalReferences);
|
|
806
|
+
}
|
|
807
|
+
if (expression instanceof BinaryExpression)
|
|
808
|
+
return this.evaluateBinary(expression, location);
|
|
809
|
+
if (expression instanceof StringLiteral)
|
|
810
|
+
return stringEvaluation(expression.text, true);
|
|
811
|
+
if (expression instanceof NoSubstitutionTemplateLiteral)
|
|
812
|
+
return stringEvaluation(expression.text, true);
|
|
813
|
+
if (expression instanceof TemplateExpression)
|
|
814
|
+
return this.evaluateTemplate(expression, location);
|
|
815
|
+
if (expression instanceof NumericLiteral)
|
|
816
|
+
return numberEvaluation(Number(expression.text));
|
|
817
|
+
if (expression instanceof Identifier)
|
|
818
|
+
return this.evaluateEntity(expression, location);
|
|
819
|
+
if (expression instanceof PropertyAccessExpression) {
|
|
820
|
+
if (isEntityNameExpressionNode(expression.expression))
|
|
821
|
+
return this.evaluateEntity(expression, location);
|
|
822
|
+
}
|
|
823
|
+
else if (expression instanceof ElementAccessExpression) {
|
|
824
|
+
if (isEntityNameExpressionNode(expression.expression))
|
|
825
|
+
return this.evaluateEntity(expression, location);
|
|
826
|
+
}
|
|
827
|
+
return noEvaluation;
|
|
828
|
+
}
|
|
829
|
+
evaluateBinary(expression, location) {
|
|
830
|
+
const left = this.evaluate(expression.left, location);
|
|
831
|
+
const right = this.evaluate(expression.right, location);
|
|
832
|
+
const operator = expression.operatorToken.kind;
|
|
833
|
+
const isSyntacticallyString = (left.isSyntacticallyString || right.isSyntacticallyString) && operator === 39 /* SyntaxKind.PlusToken */;
|
|
834
|
+
const resolvedOtherFiles = left.resolvedOtherFiles || right.resolvedOtherFiles;
|
|
835
|
+
const hasExternalReferences = left.hasExternalReferences || right.hasExternalReferences;
|
|
836
|
+
if (left.kind === 1 /* ConstantKind.Number */ && right.kind === 1 /* ConstantKind.Number */) {
|
|
837
|
+
const value = binaryNumber(operator, left.number, right.number);
|
|
838
|
+
if (value.kind !== 0 /* ConstantKind.None */)
|
|
839
|
+
return value.withFlags(isSyntacticallyString, resolvedOtherFiles, hasExternalReferences);
|
|
840
|
+
}
|
|
841
|
+
if (left.kind !== 0 /* ConstantKind.None */ && right.kind !== 0 /* ConstantKind.None */ && operator === 39 /* SyntaxKind.PlusToken */)
|
|
842
|
+
return stringEvaluation(left.text() + right.text(), isSyntacticallyString).withFlags(isSyntacticallyString, resolvedOtherFiles, hasExternalReferences);
|
|
843
|
+
return noValue(isSyntacticallyString, resolvedOtherFiles, hasExternalReferences);
|
|
844
|
+
}
|
|
845
|
+
evaluateTemplate(expression, location) {
|
|
846
|
+
let text = expression.head.text;
|
|
847
|
+
let resolvedOtherFiles = false;
|
|
848
|
+
let hasExternalReferences = false;
|
|
849
|
+
const spans = expression.templateSpans.nodes;
|
|
850
|
+
for (const span of spans) {
|
|
851
|
+
if (!(span instanceof TemplateSpan))
|
|
852
|
+
return noValue(true, false, false);
|
|
853
|
+
const value = this.evaluate(span.expression, location);
|
|
854
|
+
if (value.kind === 0 /* ConstantKind.None */)
|
|
855
|
+
return noValue(true, false, false);
|
|
856
|
+
text += value.text() + literalText(span.literal);
|
|
857
|
+
resolvedOtherFiles = resolvedOtherFiles || value.resolvedOtherFiles;
|
|
858
|
+
hasExternalReferences = hasExternalReferences || value.hasExternalReferences;
|
|
859
|
+
}
|
|
860
|
+
return stringEvaluation(text, true).withFlags(true, resolvedOtherFiles, hasExternalReferences);
|
|
861
|
+
}
|
|
862
|
+
evaluateEntity(expression, location) {
|
|
863
|
+
if (expression instanceof ElementAccessExpression) {
|
|
864
|
+
const argument = stringLiteralText(expression.argumentExpression);
|
|
865
|
+
if (argument === undefined)
|
|
866
|
+
return noEvaluation;
|
|
867
|
+
const root = this.resolveEntityName(expression.expression, 111551 /* SymbolFlags.Value */, false);
|
|
868
|
+
if (root === undefined || (root.flags & 384 /* SymbolFlags.Enum */) === 0 || root.exports === undefined)
|
|
869
|
+
return noEvaluation;
|
|
870
|
+
const member = root.exports.get(argument);
|
|
871
|
+
if (member === undefined)
|
|
872
|
+
return noEvaluation;
|
|
873
|
+
return this.evaluateEnumMemberSymbol(this.getMergedSymbol(member), location);
|
|
874
|
+
}
|
|
875
|
+
const symbol = this.resolveEntityName(expression, 111551 /* SymbolFlags.Value */, false);
|
|
876
|
+
if (symbol === undefined)
|
|
877
|
+
return noEvaluation;
|
|
878
|
+
if (expression instanceof Identifier && (expression.text === 'Infinity' || expression.text === 'NaN')) {
|
|
879
|
+
// A global `Infinity` or `NaN`; without lib files these don't resolve at all.
|
|
880
|
+
if (symbol.declarations.length > 0 && isAmbientGlobal(symbol))
|
|
881
|
+
return numberEvaluation(expression.text === 'NaN' ? NaN : Infinity);
|
|
882
|
+
}
|
|
883
|
+
if ((symbol.flags & 8 /* SymbolFlags.EnumMember */) !== 0)
|
|
884
|
+
return this.evaluateEnumMemberSymbol(symbol, location);
|
|
885
|
+
if (isConstantVariable(symbol)) {
|
|
886
|
+
const declaration = symbol.valueDeclaration;
|
|
887
|
+
if (declaration instanceof VariableDeclaration &&
|
|
888
|
+
getType(declaration) === undefined &&
|
|
889
|
+
declaration.initializer !== undefined &&
|
|
890
|
+
(location === undefined || (declaration !== location && isDeclaredBeforeUse(declaration, location)))) {
|
|
891
|
+
const result = this.evaluate(declaration.initializer, declaration);
|
|
892
|
+
if (location !== undefined && getSourceFileOfNode(location) !== getSourceFileOfNode(declaration))
|
|
893
|
+
return result.withFlags(false, true, true);
|
|
894
|
+
return result.withFlags(result.isSyntacticallyString, result.resolvedOtherFiles, true);
|
|
895
|
+
}
|
|
896
|
+
}
|
|
897
|
+
return noEvaluation;
|
|
898
|
+
}
|
|
899
|
+
evaluateEnumMemberSymbol(symbol, location) {
|
|
900
|
+
const declaration = symbol.valueDeclaration;
|
|
901
|
+
if (location === undefined)
|
|
902
|
+
return declaration === undefined ? noEvaluation : this.getEnumMemberValue(declaration);
|
|
903
|
+
if (declaration === undefined || declaration === location)
|
|
904
|
+
return noEvaluation;
|
|
905
|
+
if (!isDeclaredBeforeUse(declaration, location))
|
|
906
|
+
return numberEvaluation(0);
|
|
907
|
+
const value = this.getEnumMemberValue(declaration);
|
|
908
|
+
if (location.parent !== declaration.parent)
|
|
909
|
+
return value.withFlags(value.isSyntacticallyString, value.resolvedOtherFiles, true);
|
|
910
|
+
return value;
|
|
911
|
+
}
|
|
912
|
+
}
|
|
913
|
+
function binaryNumber(operator, left, right) {
|
|
914
|
+
switch (operator) {
|
|
915
|
+
case 51 /* SyntaxKind.BarToken */:
|
|
916
|
+
return numberEvaluation(left | right);
|
|
917
|
+
case 50 /* SyntaxKind.AmpersandToken */:
|
|
918
|
+
return numberEvaluation(left & right);
|
|
919
|
+
case 48 /* SyntaxKind.GreaterThanGreaterThanToken */:
|
|
920
|
+
return numberEvaluation(left >> right);
|
|
921
|
+
case 49 /* SyntaxKind.GreaterThanGreaterThanGreaterThanToken */:
|
|
922
|
+
return numberEvaluation(left >>> right);
|
|
923
|
+
case 47 /* SyntaxKind.LessThanLessThanToken */:
|
|
924
|
+
return numberEvaluation(left << right);
|
|
925
|
+
case 52 /* SyntaxKind.CaretToken */:
|
|
926
|
+
return numberEvaluation(left ^ right);
|
|
927
|
+
case 41 /* SyntaxKind.AsteriskToken */:
|
|
928
|
+
return numberEvaluation(left * right);
|
|
929
|
+
case 43 /* SyntaxKind.SlashToken */:
|
|
930
|
+
return numberEvaluation(left / right);
|
|
931
|
+
case 39 /* SyntaxKind.PlusToken */:
|
|
932
|
+
return numberEvaluation(left + right);
|
|
933
|
+
case 40 /* SyntaxKind.MinusToken */:
|
|
934
|
+
return numberEvaluation(left - right);
|
|
935
|
+
case 44 /* SyntaxKind.PercentToken */:
|
|
936
|
+
return numberEvaluation(left % right);
|
|
937
|
+
case 42 /* SyntaxKind.AsteriskAsteriskToken */:
|
|
938
|
+
return numberEvaluation(left ** right);
|
|
939
|
+
}
|
|
940
|
+
return noEvaluation;
|
|
941
|
+
}
|
|
942
|
+
function literalText(node) {
|
|
943
|
+
if (node instanceof TemplateMiddle)
|
|
944
|
+
return node.text;
|
|
945
|
+
if (node instanceof TemplateTail)
|
|
946
|
+
return node.text;
|
|
947
|
+
return '';
|
|
948
|
+
}
|
|
949
|
+
/** Skips parentheses only: type assertions and `!` break evaluation, as in the checker. */
|
|
950
|
+
function skipEvaluationParentheses(node) {
|
|
951
|
+
let current = node;
|
|
952
|
+
while (current instanceof ParenthesizedExpression)
|
|
953
|
+
current = current.expression;
|
|
954
|
+
return current;
|
|
955
|
+
}
|
|
956
|
+
/** The text of a string literal or no-substitution template literal. */
|
|
957
|
+
export function stringLiteralText(node) {
|
|
958
|
+
if (node instanceof StringLiteral)
|
|
959
|
+
return node.text;
|
|
960
|
+
if (node instanceof NoSubstitutionTemplateLiteral)
|
|
961
|
+
return node.text;
|
|
962
|
+
return undefined;
|
|
963
|
+
}
|
|
964
|
+
function entityNameLeft(node) {
|
|
965
|
+
if (node instanceof QualifiedName)
|
|
966
|
+
return node.left;
|
|
967
|
+
if (node instanceof PropertyAccessExpression)
|
|
968
|
+
return node.expression;
|
|
969
|
+
return undefined;
|
|
970
|
+
}
|
|
971
|
+
function entityNameRight(node) {
|
|
972
|
+
if (node instanceof QualifiedName)
|
|
973
|
+
return node.right;
|
|
974
|
+
if (node instanceof PropertyAccessExpression)
|
|
975
|
+
return node.name;
|
|
976
|
+
return undefined;
|
|
977
|
+
}
|
|
978
|
+
export function isEntityNameExpressionNode(node) {
|
|
979
|
+
if (node instanceof Identifier)
|
|
980
|
+
return true;
|
|
981
|
+
if (node instanceof PropertyAccessExpression)
|
|
982
|
+
return node.name instanceof Identifier && isEntityNameExpressionNode(node.expression);
|
|
983
|
+
return false;
|
|
984
|
+
}
|
|
985
|
+
function isAmbientGlobal(symbol) {
|
|
986
|
+
for (let i = 0; i < symbol.declarations.length; i++)
|
|
987
|
+
if ((symbol.declarations[i].flags & 8388608 /* NodeFlags.Ambient */) === 0)
|
|
988
|
+
return false;
|
|
989
|
+
return true;
|
|
990
|
+
}
|
|
991
|
+
function isConstantVariable(symbol) {
|
|
992
|
+
if ((symbol.flags & 3 /* SymbolFlags.Variable */) === 0)
|
|
993
|
+
return false;
|
|
994
|
+
const declaration = symbol.valueDeclaration;
|
|
995
|
+
return declaration !== undefined && (getCombinedNodeFlags(declaration) & 6 /* NodeFlags.Constant */) !== 0;
|
|
996
|
+
}
|
|
997
|
+
/** Whether `declaration` precedes `usage`, or `usage` runs later, as for the checker's block-scoped use check. */
|
|
998
|
+
function isDeclaredBeforeUse(declaration, usage) {
|
|
999
|
+
if (getSourceFileOfNode(declaration) !== getSourceFileOfNode(usage))
|
|
1000
|
+
return true;
|
|
1001
|
+
if ((usage.flags & (4194304 /* NodeFlags.JSDoc */ | 8388608 /* NodeFlags.Ambient */)) !== 0)
|
|
1002
|
+
return true;
|
|
1003
|
+
if (declaration.pos <= usage.pos) {
|
|
1004
|
+
if (declaration.kind === 209 /* SyntaxKind.BindingElement */) {
|
|
1005
|
+
const root = getRootDeclaration(declaration);
|
|
1006
|
+
return root === declaration || isDeclaredBeforeUse(root, usage);
|
|
1007
|
+
}
|
|
1008
|
+
if (declaration instanceof VariableDeclaration)
|
|
1009
|
+
return !isInInitializerOf(declaration, usage);
|
|
1010
|
+
return true;
|
|
1011
|
+
}
|
|
1012
|
+
// A use inside a function or class body runs after the declaration.
|
|
1013
|
+
const container = declaration.parent;
|
|
1014
|
+
for (let current = usage.parent; current !== undefined && current !== container; current = current.parent)
|
|
1015
|
+
if (isFunctionLike(current))
|
|
1016
|
+
return true;
|
|
1017
|
+
return false;
|
|
1018
|
+
}
|
|
1019
|
+
function isInInitializerOf(declaration, usage) {
|
|
1020
|
+
const initializer = getInitializer(declaration);
|
|
1021
|
+
if (initializer === undefined)
|
|
1022
|
+
return false;
|
|
1023
|
+
for (let current = usage; current !== undefined; current = current.parent) {
|
|
1024
|
+
if (current === initializer)
|
|
1025
|
+
return true;
|
|
1026
|
+
if (isSameNode(current, declaration) || isFunctionLike(current))
|
|
1027
|
+
return false;
|
|
1028
|
+
}
|
|
1029
|
+
return false;
|
|
1030
|
+
}
|
|
1031
|
+
function getDeclarationContainer(node) {
|
|
1032
|
+
for (let current = getRootDeclaration(node); current !== undefined; current = current.parent) {
|
|
1033
|
+
switch (current.kind) {
|
|
1034
|
+
case 261 /* SyntaxKind.VariableDeclaration */:
|
|
1035
|
+
case 262 /* SyntaxKind.VariableDeclarationList */:
|
|
1036
|
+
case 277 /* SyntaxKind.ImportSpecifier */:
|
|
1037
|
+
case 276 /* SyntaxKind.NamedImports */:
|
|
1038
|
+
case 275 /* SyntaxKind.NamespaceImport */:
|
|
1039
|
+
case 274 /* SyntaxKind.ImportClause */:
|
|
1040
|
+
continue;
|
|
1041
|
+
}
|
|
1042
|
+
return current.parent;
|
|
1043
|
+
}
|
|
1044
|
+
return undefined;
|
|
1045
|
+
}
|
|
1046
|
+
/** An alias without other meanings. */
|
|
1047
|
+
function isPureAlias(symbol) {
|
|
1048
|
+
return isNonLocalAlias(symbol, 111551 /* SymbolFlags.Value */ | 788968 /* SymbolFlags.Type */ | 1920 /* SymbolFlags.Namespace */);
|
|
1049
|
+
}
|
|
1050
|
+
function isNonLocalAlias(symbol, excludes) {
|
|
1051
|
+
return (symbol.flags & (2097152 /* SymbolFlags.Alias */ | excludes)) === 2097152 /* SymbolFlags.Alias */;
|
|
1052
|
+
}
|
|
1053
|
+
function isAliasSymbolDeclaration(node) {
|
|
1054
|
+
switch (node.kind) {
|
|
1055
|
+
case 272 /* SyntaxKind.ImportEqualsDeclaration */:
|
|
1056
|
+
case 271 /* SyntaxKind.NamespaceExportDeclaration */:
|
|
1057
|
+
case 275 /* SyntaxKind.NamespaceImport */:
|
|
1058
|
+
case 281 /* SyntaxKind.NamespaceExport */:
|
|
1059
|
+
case 277 /* SyntaxKind.ImportSpecifier */:
|
|
1060
|
+
case 282 /* SyntaxKind.ExportSpecifier */:
|
|
1061
|
+
return true;
|
|
1062
|
+
case 274 /* SyntaxKind.ImportClause */:
|
|
1063
|
+
return node instanceof ImportClause && node.name !== undefined;
|
|
1064
|
+
case 278 /* SyntaxKind.ExportAssignment */:
|
|
1065
|
+
return true;
|
|
1066
|
+
}
|
|
1067
|
+
return false;
|
|
1068
|
+
}
|
|
1069
|
+
export function getDeclarationOfAliasSymbol(symbol) {
|
|
1070
|
+
for (let i = symbol.declarations.length - 1; i >= 0; i--) {
|
|
1071
|
+
const declaration = symbol.declarations[i];
|
|
1072
|
+
if (isAliasSymbolDeclaration(declaration))
|
|
1073
|
+
return declaration;
|
|
1074
|
+
}
|
|
1075
|
+
return undefined;
|
|
1076
|
+
}
|
|
1077
|
+
function isTypeOnlyAlias(symbol) {
|
|
1078
|
+
let node = getDeclarationOfAliasSymbol(symbol);
|
|
1079
|
+
while (node !== undefined) {
|
|
1080
|
+
switch (node.kind) {
|
|
1081
|
+
case 272 /* SyntaxKind.ImportEqualsDeclaration */:
|
|
1082
|
+
case 279 /* SyntaxKind.ExportDeclaration */:
|
|
1083
|
+
return getIsTypeOnly(node);
|
|
1084
|
+
case 274 /* SyntaxKind.ImportClause */:
|
|
1085
|
+
if (node instanceof ImportClause && node.phaseModifier === 156 /* SyntaxKind.TypeKeyword */)
|
|
1086
|
+
return true;
|
|
1087
|
+
node = node.parent;
|
|
1088
|
+
continue;
|
|
1089
|
+
case 277 /* SyntaxKind.ImportSpecifier */:
|
|
1090
|
+
case 282 /* SyntaxKind.ExportSpecifier */:
|
|
1091
|
+
if (getIsTypeOnly(node))
|
|
1092
|
+
return true;
|
|
1093
|
+
node = node.parent;
|
|
1094
|
+
continue;
|
|
1095
|
+
case 275 /* SyntaxKind.NamespaceImport */:
|
|
1096
|
+
case 281 /* SyntaxKind.NamespaceExport */:
|
|
1097
|
+
case 276 /* SyntaxKind.NamedImports */:
|
|
1098
|
+
case 280 /* SyntaxKind.NamedExports */:
|
|
1099
|
+
node = node.parent;
|
|
1100
|
+
continue;
|
|
1101
|
+
}
|
|
1102
|
+
return false;
|
|
1103
|
+
}
|
|
1104
|
+
return false;
|
|
1105
|
+
}
|
|
1106
|
+
function isValueDeclarationKind(kind) {
|
|
1107
|
+
switch (kind) {
|
|
1108
|
+
case 261 /* SyntaxKind.VariableDeclaration */:
|
|
1109
|
+
case 170 /* SyntaxKind.Parameter */:
|
|
1110
|
+
case 209 /* SyntaxKind.BindingElement */:
|
|
1111
|
+
case 173 /* SyntaxKind.PropertyDeclaration */:
|
|
1112
|
+
case 303 /* SyntaxKind.PropertyAssignment */:
|
|
1113
|
+
case 304 /* SyntaxKind.ShorthandPropertyAssignment */:
|
|
1114
|
+
case 306 /* SyntaxKind.EnumMember */:
|
|
1115
|
+
case 211 /* SyntaxKind.ObjectLiteralExpression */:
|
|
1116
|
+
case 263 /* SyntaxKind.FunctionDeclaration */:
|
|
1117
|
+
case 219 /* SyntaxKind.FunctionExpression */:
|
|
1118
|
+
case 220 /* SyntaxKind.ArrowFunction */:
|
|
1119
|
+
case 264 /* SyntaxKind.ClassDeclaration */:
|
|
1120
|
+
case 232 /* SyntaxKind.ClassExpression */:
|
|
1121
|
+
case 267 /* SyntaxKind.EnumDeclaration */:
|
|
1122
|
+
case 175 /* SyntaxKind.MethodDeclaration */:
|
|
1123
|
+
case 178 /* SyntaxKind.GetAccessor */:
|
|
1124
|
+
case 179 /* SyntaxKind.SetAccessor */:
|
|
1125
|
+
case 268 /* SyntaxKind.ModuleDeclaration */:
|
|
1126
|
+
return true;
|
|
1127
|
+
}
|
|
1128
|
+
return false;
|
|
1129
|
+
}
|
|
1130
|
+
/** The name an import or export specifier takes from its module. */
|
|
1131
|
+
function importedNameOf(node) {
|
|
1132
|
+
if (node instanceof ImportSpecifier)
|
|
1133
|
+
return moduleExportNameText(node.propertyName !== undefined ? node.propertyName : node.name);
|
|
1134
|
+
if (node instanceof ExportSpecifier)
|
|
1135
|
+
return moduleExportNameText(node.propertyName !== undefined ? node.propertyName : node.name);
|
|
1136
|
+
return undefined;
|
|
1137
|
+
}
|
|
1138
|
+
/** The import or export declaration of a specifier. */
|
|
1139
|
+
function moduleDeclarationOfSpecifier(node) {
|
|
1140
|
+
const list = node.parent;
|
|
1141
|
+
const clauseOrDeclaration = list === undefined ? undefined : list.parent;
|
|
1142
|
+
if (node instanceof ImportSpecifier)
|
|
1143
|
+
return clauseOrDeclaration === undefined ? undefined : clauseOrDeclaration.parent;
|
|
1144
|
+
return clauseOrDeclaration;
|
|
1145
|
+
}
|
|
1146
|
+
function getModuleSpecifierOf(declaration) {
|
|
1147
|
+
return getModuleSpecifier(declaration);
|
|
1148
|
+
}
|
|
1149
|
+
function moduleExportNameText(name) {
|
|
1150
|
+
if (name instanceof Identifier)
|
|
1151
|
+
return name.text;
|
|
1152
|
+
if (name instanceof StringLiteral)
|
|
1153
|
+
return name.text;
|
|
1154
|
+
return '';
|
|
1155
|
+
}
|