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,1782 @@
|
|
|
1
|
+
// Symbols: merging globals and augmentations, merged and late-bound symbols, aliases, exports,
|
|
2
|
+
// entity names and the checker's name resolver.
|
|
3
|
+
import { sideOf, signatureSideOf } from './side-state.js';
|
|
4
|
+
import { isTypeAssignableToKindEx } from './checker-type-operators.js';
|
|
5
|
+
import { BinaryExpression, getExpression, getInitializer, getMembers as getMemberNodes, getName, getSymbol, getText, getIsTypeOnly, getProperties, getType, getLocals, } from './ast.js';
|
|
6
|
+
import { isAmbientModule, isGlobalScopeAugmentation, nodeIsMissing } from './ast-utilities.js';
|
|
7
|
+
import { CodePoints, distanceToCandidate, utf8Length } from './spelling.js';
|
|
8
|
+
import { setValueDeclaration } from './binder.js';
|
|
9
|
+
import { checkResolvedBlockScopedVariable, getEmitStandardClassFields } from './checker-declaration-order.js';
|
|
10
|
+
import { declarationNameToString, getNameOfDeclaration, getRootDeclaration, getSourceFileOfNode, getSourceTextOfNode, getDeclarationOfKind, getThisContainer, hasStaticModifier, isClassLike, isEntityNameExpression, isExternalOrCommonJSModule, isPartOfTypeQuery, isStatic, } from './binder-utilities.js';
|
|
11
|
+
import { compareDiagnostics } from './diagnostics.js';
|
|
12
|
+
import { NameResolver } from './name-resolver.js';
|
|
13
|
+
import { Symbol, addDeclaration, getSymbolId, } from './symbol.js';
|
|
14
|
+
import { createDiagnosticForNode } from './checker.js';
|
|
15
|
+
import { compareSymbols } from './checker-type-factory.js';
|
|
16
|
+
import { getDeclaredTypeOfSymbol } from './checker-declared-types.js';
|
|
17
|
+
import { symbolToString } from './type-printer.js';
|
|
18
|
+
import { getTypeOfSymbol } from './checker-symbol-types.js';
|
|
19
|
+
import { getPropertyOfType } from './checker-members.js';
|
|
20
|
+
import { checkComputedPropertyName, checkExpressionCached, entityNameToString } from './checker-expressions.js';
|
|
21
|
+
import { getLateBindableNameOfDeclaration, getPropertyNameFromType, isTypeUsableAsPropertyName, hasLateBindableName, hasLateBindableIndexSignature, } from './checker-utilities.js';
|
|
22
|
+
import { checkTypeOnlyAliasUse, markAliasDeclarationOfNameIfTypeOnly, getExportsOfModuleWorker, getTargetOfAliasDeclaration, getTypeOnlyAliasDeclaration, isTypeOnlyImportOrExportDeclaration, resolveExternalModuleNameWorker, resolveExternalModuleSymbol, resolveIndirectionAlias, } from './checker-modules.js';
|
|
23
|
+
import { isJSAliasDeclaration } from './checker-javascript.js';
|
|
24
|
+
import { getFeatureMap } from './checker-features.js';
|
|
25
|
+
// ---- Name resolution
|
|
26
|
+
/** The binder's name resolver with the checker's merging, alias handling and errors. */
|
|
27
|
+
export class CheckerNameResolver extends NameResolver {
|
|
28
|
+
checker;
|
|
29
|
+
constructor(checker) {
|
|
30
|
+
super(checker.compilerOptions);
|
|
31
|
+
this.checker = checker;
|
|
32
|
+
this.globals = checker.globals;
|
|
33
|
+
this.argumentsSymbol = checker.argumentsSymbol;
|
|
34
|
+
this.requireSymbol = checker.requireSymbol;
|
|
35
|
+
}
|
|
36
|
+
lookup(symbols, name, meaning) {
|
|
37
|
+
return getSymbolOfMeaning(this.checker, symbols, name, meaning);
|
|
38
|
+
}
|
|
39
|
+
getSymbolOfDeclaration(node) {
|
|
40
|
+
return getSymbolOfDeclaration(this.checker, node);
|
|
41
|
+
}
|
|
42
|
+
error(location, message, args) {
|
|
43
|
+
this.checker.error(location, message, ...args);
|
|
44
|
+
}
|
|
45
|
+
symbolReferenced(symbol, meaning) {
|
|
46
|
+
const kinds = this.checker.symbolReferenceKinds;
|
|
47
|
+
const id = getSymbolId(symbol);
|
|
48
|
+
kinds.set(id, kinds.get(id) | meaning);
|
|
49
|
+
}
|
|
50
|
+
getRequiresScopeChangeCache(node) {
|
|
51
|
+
return (this.checker.existingNodeLinks(node)?.declarationRequiresScopeChange ?? 0);
|
|
52
|
+
}
|
|
53
|
+
setRequiresScopeChangeCache(node, value) {
|
|
54
|
+
this.checker.nodeLinks(node).declarationRequiresScopeChange = value;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* A property initializer that references a local of the constructor, where the initializer is emitted
|
|
58
|
+
* when class fields aren't standard: reports a missing `this.` when the name resolves to nothing, else
|
|
59
|
+
* that the initializer (or the property's type) can't reference it.
|
|
60
|
+
*/
|
|
61
|
+
onPropertyWithInvalidInitializer(location, name, declaration, result) {
|
|
62
|
+
const c = this.checker;
|
|
63
|
+
if (getEmitStandardClassFields(c))
|
|
64
|
+
return false;
|
|
65
|
+
if (result === undefined && checkAndReportErrorForMissingPrefix(c, location, name))
|
|
66
|
+
return true;
|
|
67
|
+
const typeNode = getType(declaration);
|
|
68
|
+
const inType = typeNode !== undefined && typeNode.pos <= location.pos && location.pos <= typeNode.end;
|
|
69
|
+
c.error(location, inType
|
|
70
|
+
? 965 /* Diagnostics.Type_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor */
|
|
71
|
+
: 479 /* Diagnostics.Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor */, declarationNameToString(getSourceFileOfNode(declaration), getName(declaration)), name);
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
onFailedToResolveSymbol(location, name, meaning, message) {
|
|
75
|
+
onFailedToResolveSymbol(this.checker, location, name, meaning, message);
|
|
76
|
+
}
|
|
77
|
+
onSuccessfullyResolvedSymbol(location, result, meaning, lastLocation, associatedDeclarationForContainingInitializerOrBindingName, withinDeferredContext) {
|
|
78
|
+
const c = this.checker;
|
|
79
|
+
const isInExternalModule = lastLocation !== undefined &&
|
|
80
|
+
lastLocation.kind === 307 /* SyntaxKind.SourceFile */ &&
|
|
81
|
+
isExternalOrCommonJSModule(lastLocation);
|
|
82
|
+
// Only names in value positions check block-scoped declaration order: a symbol may be both a
|
|
83
|
+
// block-scoped variable and a namespace, as in `const foo: foo.bar`.
|
|
84
|
+
if (location !== undefined &&
|
|
85
|
+
((meaning & 2 /* SymbolFlags.BlockScopedVariable */) !== 0 ||
|
|
86
|
+
((meaning & (32 /* SymbolFlags.Class */ | 384 /* SymbolFlags.Enum */)) !== 0 &&
|
|
87
|
+
(meaning & 111551 /* SymbolFlags.Value */) === 111551 /* SymbolFlags.Value */)))
|
|
88
|
+
checkResolvedBlockScopedVariable(this.checker, result, location);
|
|
89
|
+
// A module can't reference the value of a UMD global (`export as namespace`).
|
|
90
|
+
if (isInExternalModule &&
|
|
91
|
+
location !== undefined &&
|
|
92
|
+
(meaning & 111551 /* SymbolFlags.Value */) === 111551 /* SymbolFlags.Value */ &&
|
|
93
|
+
(location.flags & 4194304 /* NodeFlags.JSDoc */) === 0) {
|
|
94
|
+
const merged = getMergedSymbol(c, result);
|
|
95
|
+
if (merged.declarations.length !== 0 &&
|
|
96
|
+
merged.declarations.every((d) => d.kind === 271 /* SyntaxKind.NamespaceExportDeclaration */ ||
|
|
97
|
+
(d.kind === 307 /* SyntaxKind.SourceFile */ && d.globalExports !== undefined)))
|
|
98
|
+
c.addErrorOrSuggestion(c.compilerOptions.allowUmdGlobalAccess !== true, createDiagnosticForNode(location, 819 /* Diagnostics.X_0_refers_to_a_UMD_global_but_the_current_file_is_a_module_Consider_adding_an_import_instead */, [result.name]));
|
|
99
|
+
}
|
|
100
|
+
// A parameter initializer or binding name can't reference its own parameter or the ones after it.
|
|
101
|
+
const associated = associatedDeclarationForContainingInitializerOrBindingName;
|
|
102
|
+
if (location !== undefined &&
|
|
103
|
+
associated !== undefined &&
|
|
104
|
+
!withinDeferredContext &&
|
|
105
|
+
(meaning & 111551 /* SymbolFlags.Value */) === 111551 /* SymbolFlags.Value */) {
|
|
106
|
+
const candidate = getMergedSymbol(c, getLateBoundSymbol(c, result));
|
|
107
|
+
const root = getRootDeclaration(associated);
|
|
108
|
+
const file = getSourceFileOfNode(associated);
|
|
109
|
+
if (candidate === getSymbolOfDeclaration(c, associated))
|
|
110
|
+
c.error(location, 546 /* Diagnostics.Parameter_0_cannot_reference_itself */, declarationNameToString(file, getName(associated)));
|
|
111
|
+
else if (candidate.valueDeclaration !== undefined &&
|
|
112
|
+
candidate.valueDeclaration.pos > associated.pos &&
|
|
113
|
+
getLocals(root.parent) !== undefined &&
|
|
114
|
+
getSymbolOfMeaning(c, getLocals(root.parent), candidate.name, meaning) === candidate)
|
|
115
|
+
c.error(location, 547 /* Diagnostics.Parameter_0_cannot_reference_identifier_1_declared_after_it */, declarationNameToString(file, getName(associated)), declarationNameToString(file, location));
|
|
116
|
+
}
|
|
117
|
+
if (location !== undefined && (meaning & 111551 /* SymbolFlags.Value */) !== 0)
|
|
118
|
+
checkTypeOnlyAliasUse(this.checker, location, result, result.name);
|
|
119
|
+
// Under isolatedModules, a value import named like a global value that the file uses must be type-only.
|
|
120
|
+
if (c.compilerOptions.isolatedModules === true &&
|
|
121
|
+
isInExternalModule &&
|
|
122
|
+
(meaning & 111551 /* SymbolFlags.Value */) === 111551 /* SymbolFlags.Value */) {
|
|
123
|
+
const name = result.name;
|
|
124
|
+
const isGlobal = getSymbolOfMeaning(c, c.globals, name, meaning) === result;
|
|
125
|
+
const locals = isGlobal ? getLocals(lastLocation) : undefined;
|
|
126
|
+
const nonValueSymbol = locals !== undefined ? getSymbolOfMeaning(c, locals, name, ~111551 /* SymbolFlags.Value */) : undefined;
|
|
127
|
+
if (nonValueSymbol !== undefined) {
|
|
128
|
+
const importDeclaration = nonValueSymbol.declarations.find((d) => d.kind === 277 /* SyntaxKind.ImportSpecifier */ ||
|
|
129
|
+
d.kind === 274 /* SyntaxKind.ImportClause */ ||
|
|
130
|
+
d.kind === 275 /* SyntaxKind.NamespaceImport */ ||
|
|
131
|
+
d.kind === 272 /* SyntaxKind.ImportEqualsDeclaration */);
|
|
132
|
+
if (importDeclaration !== undefined && !isTypeOnlyImportOrExportDeclaration(importDeclaration))
|
|
133
|
+
c.error(importDeclaration, 986 /* Diagnostics.Import_0_conflicts_with_global_value_used_in_this_file_so_must_be_declared_with_a_type_only_import_when_isolatedModules_is_enabled */, name);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
export function resolveName(c, location, name, meaning, nameNotFoundMessage, isUse, excludeGlobals) {
|
|
139
|
+
return c.resolver.resolve(location, name, meaning, nameNotFoundMessage, isUse, excludeGlobals);
|
|
140
|
+
}
|
|
141
|
+
/** `symbols[name]` (merged) if it has `meaning`, directly or through an alias. */
|
|
142
|
+
export function getSymbolOfMeaning(c, symbols, name, meaning) {
|
|
143
|
+
if ((meaning & 1073741823 /* SymbolFlags.All */) === 0)
|
|
144
|
+
return undefined;
|
|
145
|
+
const found = symbols.get(name);
|
|
146
|
+
if (found === undefined)
|
|
147
|
+
return undefined;
|
|
148
|
+
const symbol = getMergedSymbol(c, found);
|
|
149
|
+
if ((symbol.flags & meaning) !== 0)
|
|
150
|
+
return symbol;
|
|
151
|
+
// getSymbolFlags is All when alias resolution failed, which avoids cascading errors.
|
|
152
|
+
if ((symbol.flags & 2097152 /* SymbolFlags.Alias */) !== 0 && (getSymbolFlags(c, symbol) & meaning) !== 0)
|
|
153
|
+
return symbol;
|
|
154
|
+
return undefined;
|
|
155
|
+
}
|
|
156
|
+
function isPrimitiveTypeName(name) {
|
|
157
|
+
return (name === 'any' ||
|
|
158
|
+
name === 'string' ||
|
|
159
|
+
name === 'number' ||
|
|
160
|
+
name === 'boolean' ||
|
|
161
|
+
name === 'never' ||
|
|
162
|
+
name === 'unknown');
|
|
163
|
+
}
|
|
164
|
+
function isES2015OrLaterConstructorName(name) {
|
|
165
|
+
return (name === 'Promise' ||
|
|
166
|
+
name === 'Symbol' ||
|
|
167
|
+
name === 'Map' ||
|
|
168
|
+
name === 'WeakMap' ||
|
|
169
|
+
name === 'Set' ||
|
|
170
|
+
name === 'WeakSet');
|
|
171
|
+
}
|
|
172
|
+
function onFailedToResolveSymbol(c, location, name, meaning, message) {
|
|
173
|
+
let declarationName = name;
|
|
174
|
+
if (location !== undefined) {
|
|
175
|
+
if (location.parent !== undefined && location.parent.kind === 319 /* SyntaxKind.JSDocLink */)
|
|
176
|
+
return;
|
|
177
|
+
if (checkAndReportErrorForMissingPrefix(c, location, name) ||
|
|
178
|
+
checkAndReportErrorForExtendingInterface(c, location) ||
|
|
179
|
+
checkAndReportErrorForUsingTypeAsNamespace(c, location, name, meaning) ||
|
|
180
|
+
checkAndReportErrorForExportingPrimitiveType(c, location, name) ||
|
|
181
|
+
checkAndReportErrorForUsingNamespaceAsTypeOrValue(c, location, name, meaning) ||
|
|
182
|
+
checkAndReportErrorForUsingTypeAsValue(c, location, name, meaning) ||
|
|
183
|
+
checkAndReportErrorForUsingValueAsType(c, location, name, meaning))
|
|
184
|
+
return;
|
|
185
|
+
if (location.kind === 79 /* SyntaxKind.Identifier */ && getText(location) === name)
|
|
186
|
+
declarationName = declarationNameToString(getSourceFileOfNode(location), location);
|
|
187
|
+
}
|
|
188
|
+
// A missing library comes before spelling suggestions.
|
|
189
|
+
const features = getFeatureMap().get(name);
|
|
190
|
+
if (features !== undefined) {
|
|
191
|
+
c.error(location, message, declarationName, features[0].lib);
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
const suggestion = c.suggestionResolver.resolve(location, name, meaning, undefined, false, false);
|
|
195
|
+
if (suggestion !== undefined &&
|
|
196
|
+
!(suggestion.valueDeclaration !== undefined &&
|
|
197
|
+
isAmbientModule(suggestion.valueDeclaration) &&
|
|
198
|
+
isGlobalScopeAugmentation(suggestion.valueDeclaration))) {
|
|
199
|
+
const suggestionName = symbolToString(c, suggestion);
|
|
200
|
+
const diagnostic = createDiagnosticForNode(location, meaning === 1920 /* SymbolFlags.Namespace */
|
|
201
|
+
? 955 /* Diagnostics.Cannot_find_namespace_0_Did_you_mean_1 */
|
|
202
|
+
: 707 /* Diagnostics.Cannot_find_name_0_Did_you_mean_1 */, [declarationName, suggestionName]);
|
|
203
|
+
if (suggestion.valueDeclaration !== undefined)
|
|
204
|
+
diagnostic.addRelatedInfo(createDiagnosticForNode(suggestion.valueDeclaration, 860 /* Diagnostics.X_0_is_declared_here */, [suggestionName]));
|
|
205
|
+
c.addDiagnostic(diagnostic);
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
c.error(location, message, declarationName);
|
|
209
|
+
}
|
|
210
|
+
function checkAndReportErrorForMissingPrefix(c, location, name) {
|
|
211
|
+
if (location.kind !== 79 /* SyntaxKind.Identifier */ ||
|
|
212
|
+
getText(location) !== name ||
|
|
213
|
+
isTypeReferenceIdentifier(location) ||
|
|
214
|
+
isPartOfTypeQuery(location))
|
|
215
|
+
return false;
|
|
216
|
+
const container = getThisContainer(location, false, false);
|
|
217
|
+
for (let current = container; current.parent !== undefined; current = current.parent) {
|
|
218
|
+
if (!isClassLike(current.parent))
|
|
219
|
+
continue;
|
|
220
|
+
const classSymbol = getSymbolOfDeclaration(c, current.parent);
|
|
221
|
+
if (classSymbol === undefined)
|
|
222
|
+
break;
|
|
223
|
+
if (getPropertyOfType(c, getTypeOfSymbol(c, classSymbol), name) !== undefined) {
|
|
224
|
+
c.error(location, 796 /* Diagnostics.Cannot_find_name_0_Did_you_mean_the_static_member_1_0 */, name, symbolToString(c, classSymbol));
|
|
225
|
+
return true;
|
|
226
|
+
}
|
|
227
|
+
if (current === container && !isStatic(current)) {
|
|
228
|
+
const thisType = getDeclaredTypeOfSymbol(c, classSymbol).thisType;
|
|
229
|
+
if (thisType !== undefined && getPropertyOfType(c, thisType, name) !== undefined) {
|
|
230
|
+
c.error(location, 797 /* Diagnostics.Cannot_find_name_0_Did_you_mean_the_instance_member_this_0 */, name);
|
|
231
|
+
return true;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
return false;
|
|
236
|
+
}
|
|
237
|
+
function isTypeReferenceIdentifier(node) {
|
|
238
|
+
let current = node;
|
|
239
|
+
while (current.parent !== undefined && current.parent.kind === 167 /* SyntaxKind.QualifiedName */)
|
|
240
|
+
current = current.parent;
|
|
241
|
+
return current.parent !== undefined && current.parent.kind === 184 /* SyntaxKind.TypeReference */;
|
|
242
|
+
}
|
|
243
|
+
function checkAndReportErrorForExtendingInterface(c, location) {
|
|
244
|
+
const expression = getEntityNameForExtendingInterface(location);
|
|
245
|
+
if (expression !== undefined &&
|
|
246
|
+
resolveEntityName(c, expression, 64 /* SymbolFlags.Interface */, true, false, undefined) !== undefined) {
|
|
247
|
+
c.error(location, 822 /* Diagnostics.Cannot_extend_an_interface_0_Did_you_mean_implements */, getSourceTextOfNode(getSourceFileOfNode(expression), expression));
|
|
248
|
+
return true;
|
|
249
|
+
}
|
|
250
|
+
return false;
|
|
251
|
+
}
|
|
252
|
+
function getEntityNameForExtendingInterface(node) {
|
|
253
|
+
switch (node.kind) {
|
|
254
|
+
case 79 /* SyntaxKind.Identifier */:
|
|
255
|
+
case 212 /* SyntaxKind.PropertyAccessExpression */:
|
|
256
|
+
return node.parent !== undefined ? getEntityNameForExtendingInterface(node.parent) : undefined;
|
|
257
|
+
case 234 /* SyntaxKind.ExpressionWithTypeArguments */: {
|
|
258
|
+
const expression = getExpression(node);
|
|
259
|
+
return isEntityNameExpression(expression, false) ? expression : undefined;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
return undefined;
|
|
263
|
+
}
|
|
264
|
+
/** Resolves names to their closest misspelling in scope, for "Did you mean" suggestions. */
|
|
265
|
+
export class SuggestionNameResolver extends CheckerNameResolver {
|
|
266
|
+
lookup(symbols, name, meaning) {
|
|
267
|
+
const symbol = getSymbolOfMeaning(this.checker, symbols, name, meaning);
|
|
268
|
+
if (symbol !== undefined)
|
|
269
|
+
return symbol;
|
|
270
|
+
const candidates = [];
|
|
271
|
+
for (const s of symbols.values())
|
|
272
|
+
candidates.push(s);
|
|
273
|
+
if ((meaning & 1073741824 /* SymbolFlags.GlobalLookup */) !== 0) {
|
|
274
|
+
for (const builtin of primitiveBuiltins.split(' '))
|
|
275
|
+
if (symbols.has(builtin))
|
|
276
|
+
candidates.push(getPrimitiveTypeAliasSuggestion(this.checker, primitiveTypeAliasFor(builtin)));
|
|
277
|
+
}
|
|
278
|
+
return getSpellingSuggestionForName(this.checker, name, candidates, meaning);
|
|
279
|
+
}
|
|
280
|
+
error(_location, _message, _args) { }
|
|
281
|
+
symbolReferenced(_symbol, _meaning) { }
|
|
282
|
+
onFailedToResolveSymbol(_location, _name, _meaning, _message) { }
|
|
283
|
+
}
|
|
284
|
+
/** The primitive type alias suggested for a misspelled builtin wrapper name, or ''. */
|
|
285
|
+
function primitiveTypeAliasFor(builtin) {
|
|
286
|
+
switch (builtin) {
|
|
287
|
+
case 'String':
|
|
288
|
+
return 'string';
|
|
289
|
+
case 'Number':
|
|
290
|
+
return 'number';
|
|
291
|
+
case 'Boolean':
|
|
292
|
+
return 'boolean';
|
|
293
|
+
case 'Object':
|
|
294
|
+
return 'object';
|
|
295
|
+
case 'BigInt':
|
|
296
|
+
return 'bigint';
|
|
297
|
+
case 'Symbol':
|
|
298
|
+
return 'symbol';
|
|
299
|
+
}
|
|
300
|
+
return '';
|
|
301
|
+
}
|
|
302
|
+
const primitiveBuiltins = 'String Number Boolean Object BigInt Symbol';
|
|
303
|
+
function getPrimitiveTypeAliasSuggestion(c, name) {
|
|
304
|
+
let symbol = c.primitiveTypeAliasSuggestions.get(name);
|
|
305
|
+
if (symbol === undefined) {
|
|
306
|
+
symbol = c.newSymbol(524288 /* SymbolFlags.TypeAlias */, name);
|
|
307
|
+
c.primitiveTypeAliasSuggestions.set(name, symbol);
|
|
308
|
+
}
|
|
309
|
+
return symbol;
|
|
310
|
+
}
|
|
311
|
+
/** The symbol whose name is closest to `name` and that has `meaning`, if close enough. */
|
|
312
|
+
export function getSpellingSuggestionForName(c, name, symbols, meaning) {
|
|
313
|
+
const nameCodePoints = new CodePoints();
|
|
314
|
+
nameCodePoints.set(name);
|
|
315
|
+
const maximumLengthDifference = Math.max(2, Math.floor(nameCodePoints.length * 0.34));
|
|
316
|
+
let bestDistance = Math.floor(nameCodePoints.length * 0.4) + 0.9;
|
|
317
|
+
let best = undefined;
|
|
318
|
+
const lowerName = name.toLowerCase();
|
|
319
|
+
for (const candidate of symbols) {
|
|
320
|
+
const candidateName = getCandidateName(c, candidate, meaning);
|
|
321
|
+
if (candidateName === '')
|
|
322
|
+
continue;
|
|
323
|
+
// tsgo measures candidates in bytes and the name in code points. A candidate has at least as
|
|
324
|
+
// many bytes as UTF-16 units, so most long candidates are out without measuring them.
|
|
325
|
+
if (candidateName.length - nameCodePoints.length > maximumLengthDifference)
|
|
326
|
+
continue;
|
|
327
|
+
const candidateLength = utf8Length(candidateName);
|
|
328
|
+
if (Math.max(candidateLength, nameCodePoints.length) - Math.min(candidateLength, nameCodePoints.length) >
|
|
329
|
+
maximumLengthDifference)
|
|
330
|
+
continue;
|
|
331
|
+
if (candidateName === name)
|
|
332
|
+
continue;
|
|
333
|
+
if (candidateLength < 3 && candidateName.toLowerCase() !== lowerName)
|
|
334
|
+
continue;
|
|
335
|
+
const distance = distanceToCandidate(nameCodePoints, candidateName, bestDistance);
|
|
336
|
+
if (distance < 0)
|
|
337
|
+
continue;
|
|
338
|
+
if (distance < bestDistance) {
|
|
339
|
+
bestDistance = distance;
|
|
340
|
+
best = candidate;
|
|
341
|
+
}
|
|
342
|
+
else if (best === undefined || compareSymbols(c, candidate, best) < 0)
|
|
343
|
+
best = candidate;
|
|
344
|
+
}
|
|
345
|
+
return best;
|
|
346
|
+
}
|
|
347
|
+
function getCandidateName(c, candidate, meaning) {
|
|
348
|
+
const name = candidate.name;
|
|
349
|
+
if (name.length === 0 || name.charCodeAt(0) === 0x22 || name.charCodeAt(0) === 0xfffe)
|
|
350
|
+
return '';
|
|
351
|
+
if ((candidate.flags & meaning) !== 0)
|
|
352
|
+
return name;
|
|
353
|
+
if ((candidate.flags & 2097152 /* SymbolFlags.Alias */) !== 0) {
|
|
354
|
+
const target = tryResolveAlias(c, candidate);
|
|
355
|
+
if (target !== undefined && (target.flags & meaning) !== 0)
|
|
356
|
+
return name;
|
|
357
|
+
}
|
|
358
|
+
return '';
|
|
359
|
+
}
|
|
360
|
+
function checkAndReportErrorForUsingTypeAsNamespace(c, location, name, meaning) {
|
|
361
|
+
if (meaning !== 1920 /* SymbolFlags.Namespace */)
|
|
362
|
+
return false;
|
|
363
|
+
const symbol = resolveSymbol(c, resolveName(c, location, name, 788968 /* SymbolFlags.Type */ & ~1920 /* SymbolFlags.Namespace */, undefined, false, false));
|
|
364
|
+
if (symbol === undefined)
|
|
365
|
+
return false;
|
|
366
|
+
const parent = location.parent;
|
|
367
|
+
if (parent !== undefined && parent.kind === 167 /* SyntaxKind.QualifiedName */) {
|
|
368
|
+
const propName = parent.right.text;
|
|
369
|
+
if (getPropertyOfType(c, getDeclaredTypeOfSymbol(c, symbol), propName) !== undefined) {
|
|
370
|
+
c.error(parent, 845 /* Diagnostics.Cannot_access_0_1_because_0_is_a_type_but_not_a_namespace_Did_you_mean_to_retrieve_the_type_of_the_property_1_in_0_with_0_1 */, name, propName);
|
|
371
|
+
return true;
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
c.error(location, 834 /* Diagnostics.X_0_only_refers_to_a_type_but_is_being_used_as_a_namespace_here */, name);
|
|
375
|
+
return true;
|
|
376
|
+
}
|
|
377
|
+
function checkAndReportErrorForExportingPrimitiveType(c, location, name) {
|
|
378
|
+
if (isPrimitiveTypeName(name) &&
|
|
379
|
+
location.parent !== undefined &&
|
|
380
|
+
location.parent.kind === 282 /* SyntaxKind.ExportSpecifier */) {
|
|
381
|
+
c.error(location, 795 /* Diagnostics.Cannot_export_0_Only_local_declarations_can_be_exported_from_a_module */, name);
|
|
382
|
+
return true;
|
|
383
|
+
}
|
|
384
|
+
return false;
|
|
385
|
+
}
|
|
386
|
+
function checkAndReportErrorForUsingNamespaceAsTypeOrValue(c, location, name, meaning) {
|
|
387
|
+
if ((meaning & (111551 /* SymbolFlags.Value */ & ~788968 /* SymbolFlags.Type */)) !== 0) {
|
|
388
|
+
const symbol = resolveSymbol(c, resolveName(c, location, name, 1024 /* SymbolFlags.NamespaceModule */, undefined, false, false));
|
|
389
|
+
if (symbol !== undefined) {
|
|
390
|
+
c.error(location, 840 /* Diagnostics.Cannot_use_namespace_0_as_a_value */, name);
|
|
391
|
+
return true;
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
else if ((meaning & (788968 /* SymbolFlags.Type */ & ~111551 /* SymbolFlags.Value */)) !== 0) {
|
|
395
|
+
const symbol = resolveSymbol(c, resolveName(c, location, name, 1536 /* SymbolFlags.Module */, undefined, false, false));
|
|
396
|
+
if (symbol !== undefined) {
|
|
397
|
+
c.error(location, 841 /* Diagnostics.Cannot_use_namespace_0_as_a_type */, name);
|
|
398
|
+
return true;
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
return false;
|
|
402
|
+
}
|
|
403
|
+
function checkAndReportErrorForUsingTypeAsValue(c, location, name, meaning) {
|
|
404
|
+
if ((meaning & 111551 /* SymbolFlags.Value */) === 0)
|
|
405
|
+
return false;
|
|
406
|
+
if (isPrimitiveTypeName(name)) {
|
|
407
|
+
const grandparent = location.parent?.parent;
|
|
408
|
+
if (grandparent !== undefined &&
|
|
409
|
+
grandparent.parent !== undefined &&
|
|
410
|
+
grandparent.kind === 299 /* SyntaxKind.HeritageClause */) {
|
|
411
|
+
const heritageKind = grandparent.token;
|
|
412
|
+
const containerKind = grandparent.parent.kind;
|
|
413
|
+
const isClass = containerKind === 264 /* SyntaxKind.ClassDeclaration */ || containerKind === 232 /* SyntaxKind.ClassExpression */;
|
|
414
|
+
if (containerKind === 265 /* SyntaxKind.InterfaceDeclaration */ && heritageKind === 95 /* SyntaxKind.ExtendsKeyword */)
|
|
415
|
+
c.error(location, 962 /* Diagnostics.An_interface_cannot_extend_a_primitive_type_like_0_It_can_only_extend_other_named_object_types */, name);
|
|
416
|
+
else if (isClass && heritageKind === 95 /* SyntaxKind.ExtendsKeyword */)
|
|
417
|
+
c.error(location, 983 /* Diagnostics.A_class_cannot_extend_a_primitive_type_like_0_Classes_can_only_extend_constructable_values */, name);
|
|
418
|
+
else if (isClass && heritageKind === 118 /* SyntaxKind.ImplementsKeyword */)
|
|
419
|
+
c.error(location, 984 /* Diagnostics.A_class_cannot_implement_a_primitive_type_like_0_It_can_only_implement_other_named_object_types */, name);
|
|
420
|
+
}
|
|
421
|
+
else
|
|
422
|
+
c.error(location, 825 /* Diagnostics.X_0_only_refers_to_a_type_but_is_being_used_as_a_value_here */, name);
|
|
423
|
+
return true;
|
|
424
|
+
}
|
|
425
|
+
const symbol = resolveSymbol(c, resolveName(c, location, name, 788968 /* SymbolFlags.Type */ & ~111551 /* SymbolFlags.Value */, undefined, false, false));
|
|
426
|
+
if (symbol !== undefined && (getSymbolFlags(c, symbol) & 111551 /* SymbolFlags.Value */) === 0) {
|
|
427
|
+
if (isES2015OrLaterConstructorName(name))
|
|
428
|
+
c.error(location, 735 /* Diagnostics.X_0_only_refers_to_a_type_but_is_being_used_as_a_value_here_Do_you_need_to_change_your_target_library_Try_changing_the_lib_compiler_option_to_es2015_or_later */, name);
|
|
429
|
+
else if (maybeMappedType(c, location, symbol))
|
|
430
|
+
c.error(location, 823 /* Diagnostics.X_0_only_refers_to_a_type_but_is_being_used_as_a_value_here_Did_you_mean_to_use_1_in_0 */, name, name === 'K' ? 'P' : 'K');
|
|
431
|
+
else
|
|
432
|
+
c.error(location, 825 /* Diagnostics.X_0_only_refers_to_a_type_but_is_being_used_as_a_value_here */, name);
|
|
433
|
+
return true;
|
|
434
|
+
}
|
|
435
|
+
return false;
|
|
436
|
+
}
|
|
437
|
+
function maybeMappedType(c, node, symbol) {
|
|
438
|
+
let container = node.parent;
|
|
439
|
+
while (container !== undefined &&
|
|
440
|
+
(container.kind === 168 /* SyntaxKind.ComputedPropertyName */ || container.kind === 172 /* SyntaxKind.PropertySignature */))
|
|
441
|
+
container = container.parent;
|
|
442
|
+
if (container === undefined || container.kind !== 188 /* SyntaxKind.TypeLiteral */)
|
|
443
|
+
return false;
|
|
444
|
+
const members = getMemberNodes(container);
|
|
445
|
+
if (members === undefined || members.nodes.length !== 1)
|
|
446
|
+
return false;
|
|
447
|
+
const type = getDeclaredTypeOfSymbol(c, symbol);
|
|
448
|
+
if ((type.flags & 134217728 /* TypeFlags.Union */) === 0)
|
|
449
|
+
return false;
|
|
450
|
+
for (const t of type.types)
|
|
451
|
+
if (!isTypeAssignableToKindEx(c, t, 3072 /* TypeFlags.StringOrNumberLiteral */, true))
|
|
452
|
+
return false;
|
|
453
|
+
return true;
|
|
454
|
+
}
|
|
455
|
+
function checkAndReportErrorForUsingValueAsType(c, location, name, meaning) {
|
|
456
|
+
if ((meaning & (788968 /* SymbolFlags.Type */ & ~1920 /* SymbolFlags.Namespace */)) === 0)
|
|
457
|
+
return false;
|
|
458
|
+
const symbol = resolveSymbol(c, resolveName(c, location, name, ~788968 /* SymbolFlags.Type */ & 111551 /* SymbolFlags.Value */, undefined, false, false));
|
|
459
|
+
if (symbol !== undefined && (symbol.flags & 1920 /* SymbolFlags.Namespace */) === 0) {
|
|
460
|
+
c.error(location, 881 /* Diagnostics.X_0_refers_to_a_value_but_is_being_used_as_a_type_here_Did_you_mean_typeof_0 */, name);
|
|
461
|
+
return true;
|
|
462
|
+
}
|
|
463
|
+
return false;
|
|
464
|
+
}
|
|
465
|
+
// ---- Merging
|
|
466
|
+
function mergeFileGlobals(c, file) {
|
|
467
|
+
if (!isExternalOrCommonJSModule(file)) {
|
|
468
|
+
const locals = file.locals;
|
|
469
|
+
if (locals !== undefined) {
|
|
470
|
+
const fileGlobalThis = locals.get('globalThis');
|
|
471
|
+
if (fileGlobalThis !== undefined)
|
|
472
|
+
for (const d of fileGlobalThis.declarations)
|
|
473
|
+
c.addDiagnostic(createDiagnosticForNode(d, 568 /* Diagnostics.Declaration_name_conflicts_with_built_in_global_identifier_0 */, [
|
|
474
|
+
'globalThis',
|
|
475
|
+
]));
|
|
476
|
+
for (const symbol of locals.values()) {
|
|
477
|
+
if ((symbol.flags & 1536 /* SymbolFlags.Module */) !== 0 && isAmbientModuleSymbolName(symbol.name))
|
|
478
|
+
c.ambientModuleSymbols.push(symbol);
|
|
479
|
+
else
|
|
480
|
+
mergeGlobalSymbol(c, symbol);
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
for (const pattern of file.patternAmbientModules)
|
|
485
|
+
c.patternAmbientModules.push(pattern);
|
|
486
|
+
if (file.symbol !== undefined && file.globalExports !== undefined)
|
|
487
|
+
// UMD exports, first in wins.
|
|
488
|
+
for (const [name, symbol] of file.globalExports)
|
|
489
|
+
if (!c.globals.has(name))
|
|
490
|
+
setGlobal(c, name, symbol);
|
|
491
|
+
}
|
|
492
|
+
/** Changes to a map, recorded so that they can be undone. */
|
|
493
|
+
export class TableChanges {
|
|
494
|
+
added = new Set();
|
|
495
|
+
replaced = new Map();
|
|
496
|
+
set(table, key, value) {
|
|
497
|
+
const previous = table.get(key);
|
|
498
|
+
if (previous === undefined)
|
|
499
|
+
this.added.add(key);
|
|
500
|
+
else if (!this.added.has(key) && !this.replaced.has(key))
|
|
501
|
+
this.replaced.set(key, previous);
|
|
502
|
+
table.set(key, value);
|
|
503
|
+
}
|
|
504
|
+
/** Restores `table`, or a copy of it, to its state before the changes. */
|
|
505
|
+
undo(table) {
|
|
506
|
+
for (const key of this.added)
|
|
507
|
+
table.delete(key);
|
|
508
|
+
for (const [key, value] of this.replaced)
|
|
509
|
+
table.set(key, value);
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
/**
|
|
513
|
+
* Globals merged from the locals of a program's leading default libraries. Checkers of programs
|
|
514
|
+
* with the same libraries start from them; a later merge into a shared symbol merges into a copy.
|
|
515
|
+
* One checker at a time borrows the tables and changes them in place; the others copy them.
|
|
516
|
+
*/
|
|
517
|
+
export class LibGlobals {
|
|
518
|
+
files;
|
|
519
|
+
globals;
|
|
520
|
+
mergedSymbols;
|
|
521
|
+
ambientModuleSymbols;
|
|
522
|
+
patternAmbientModules;
|
|
523
|
+
/** Ids of the symbols merged into each shared symbol. */
|
|
524
|
+
sources = new Map();
|
|
525
|
+
/** The checker using `globals` and `mergedSymbols` in place. */
|
|
526
|
+
borrower = undefined;
|
|
527
|
+
constructor(c, files) {
|
|
528
|
+
this.files = files;
|
|
529
|
+
this.globals = new Map(c.globals);
|
|
530
|
+
// Each checker sets its own `globalThis`, keeping it first.
|
|
531
|
+
this.globals.set(c.globalThisSymbol.name, new Symbol(0 /* SymbolFlags.None */, 'globalThis'));
|
|
532
|
+
this.mergedSymbols = new Map(c.mergedSymbols);
|
|
533
|
+
this.ambientModuleSymbols = c.ambientModuleSymbols.slice();
|
|
534
|
+
this.patternAmbientModules = c.patternAmbientModules.slice();
|
|
535
|
+
for (const [id, target] of this.mergedSymbols) {
|
|
536
|
+
let ids = this.sources.get(target);
|
|
537
|
+
if (ids === undefined) {
|
|
538
|
+
ids = [];
|
|
539
|
+
this.sources.set(target, ids);
|
|
540
|
+
}
|
|
541
|
+
ids.push(id);
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
copyGlobals() {
|
|
545
|
+
const globals = new Map(this.globals);
|
|
546
|
+
if (this.borrower !== undefined)
|
|
547
|
+
this.borrower.globalChanges.undo(globals);
|
|
548
|
+
return globals;
|
|
549
|
+
}
|
|
550
|
+
copyMergedSymbols() {
|
|
551
|
+
const mergedSymbols = new Map(this.mergedSymbols);
|
|
552
|
+
if (this.borrower !== undefined)
|
|
553
|
+
this.borrower.mergedSymbolChanges.undo(mergedSymbols);
|
|
554
|
+
return mergedSymbols;
|
|
555
|
+
}
|
|
556
|
+
/** Whether `files` starts with exactly these `count` libraries. */
|
|
557
|
+
matches(files, count) {
|
|
558
|
+
if (count !== this.files.length)
|
|
559
|
+
return false;
|
|
560
|
+
for (let i = 0; i < count; i++)
|
|
561
|
+
if (files[i] !== this.files[i])
|
|
562
|
+
return false;
|
|
563
|
+
return true;
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
/**
|
|
567
|
+
* The globals, merged symbols and module augmentations of a whole program, as one checker merged
|
|
568
|
+
* them before checker threads share the program (parallel-check.ts). Other checkers of the program
|
|
569
|
+
* start from copies of the tables and add the diagnostics the merges reported; the merged symbols
|
|
570
|
+
* are shared, and a later merge into one merges into a copy.
|
|
571
|
+
*/
|
|
572
|
+
export class MergedGlobals {
|
|
573
|
+
globals;
|
|
574
|
+
mergedSymbols;
|
|
575
|
+
ambientModuleSymbols;
|
|
576
|
+
patternAmbientModules;
|
|
577
|
+
patternAmbientModuleAugmentations;
|
|
578
|
+
/** Whether the global `undefined` is the checker's own (no declaration of `undefined` merged). */
|
|
579
|
+
ownUndefined;
|
|
580
|
+
/** Ids of the symbols merged into each shared symbol. */
|
|
581
|
+
sources = new Map();
|
|
582
|
+
/** Copies of the checker's `mergeDiagnostics`. */
|
|
583
|
+
diagnostics = [];
|
|
584
|
+
constructor(c) {
|
|
585
|
+
this.globals = new Map(c.globals);
|
|
586
|
+
// Each checker sets its own `globalThis` and `undefined`, in the same places in the table.
|
|
587
|
+
this.globals.set(c.globalThisSymbol.name, new Symbol(0 /* SymbolFlags.None */, 'globalThis'));
|
|
588
|
+
this.ownUndefined = c.globals.get('undefined') === c.undefinedSymbol;
|
|
589
|
+
if (this.ownUndefined)
|
|
590
|
+
this.globals.set('undefined', new Symbol(0 /* SymbolFlags.None */, 'undefined'));
|
|
591
|
+
for (const symbol of this.globals.values())
|
|
592
|
+
getSymbolId(symbol);
|
|
593
|
+
this.mergedSymbols = new Map(c.mergedSymbols);
|
|
594
|
+
this.ambientModuleSymbols = c.ambientModuleSymbols.slice();
|
|
595
|
+
this.patternAmbientModules = c.patternAmbientModules.slice();
|
|
596
|
+
this.patternAmbientModuleAugmentations = new Map(c.patternAmbientModuleAugmentations);
|
|
597
|
+
for (const [id, target] of this.mergedSymbols) {
|
|
598
|
+
let ids = this.sources.get(target);
|
|
599
|
+
if (ids === undefined) {
|
|
600
|
+
// Shared symbols are never written, so they need their ids now.
|
|
601
|
+
getSymbolId(target);
|
|
602
|
+
ids = [];
|
|
603
|
+
this.sources.set(target, ids);
|
|
604
|
+
}
|
|
605
|
+
ids.push(id);
|
|
606
|
+
}
|
|
607
|
+
// The checker can add related information to its diagnostics later.
|
|
608
|
+
for (const list of c.mergeDiagnostics)
|
|
609
|
+
this.diagnostics.push(copyDiagnostics(list));
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
function copyDiagnostics(list) {
|
|
613
|
+
const result = [];
|
|
614
|
+
for (const diagnostic of list) {
|
|
615
|
+
const copy = diagnostic.clone();
|
|
616
|
+
copy.relatedInformation = diagnostic.relatedInformation.slice();
|
|
617
|
+
result.push(copy);
|
|
618
|
+
}
|
|
619
|
+
return result;
|
|
620
|
+
}
|
|
621
|
+
/** Adds the diagnostics and suggestions of `merged`'s merge `step` (0: globals, 1: augmentations). */
|
|
622
|
+
function addMergeDiagnostics(c, merged, step) {
|
|
623
|
+
for (const diagnostic of copyDiagnostics(merged.diagnostics[2 * step]))
|
|
624
|
+
c.diagnostics.add(diagnostic);
|
|
625
|
+
for (const diagnostic of copyDiagnostics(merged.diagnostics[2 * step + 1]))
|
|
626
|
+
c.suggestionDiagnostics.add(diagnostic);
|
|
627
|
+
}
|
|
628
|
+
/**
|
|
629
|
+
* Shares the globals and module augmentations `c` merged with the other checkers of its program;
|
|
630
|
+
* `c` treats its merged symbols as shared from now on.
|
|
631
|
+
*/
|
|
632
|
+
export function shareMergedGlobals(c) {
|
|
633
|
+
const merged = new MergedGlobals(c);
|
|
634
|
+
c.mergedGlobals = merged;
|
|
635
|
+
return merged;
|
|
636
|
+
}
|
|
637
|
+
/** The ids of the symbols merged into `symbol`, if it is shared with other checkers. */
|
|
638
|
+
function sharedSources(c, symbol) {
|
|
639
|
+
const merged = c.mergedGlobals;
|
|
640
|
+
const ids = merged !== undefined ? merged.sources.get(symbol) : undefined;
|
|
641
|
+
if (ids !== undefined)
|
|
642
|
+
return ids;
|
|
643
|
+
const libs = c.libGlobals;
|
|
644
|
+
return libs !== undefined ? libs.sources.get(symbol) : undefined;
|
|
645
|
+
}
|
|
646
|
+
const libGlobalsCache = [];
|
|
647
|
+
/** Drops the shared library globals (a rebuild reparses the library files). */
|
|
648
|
+
export function clearLibGlobalsCache() {
|
|
649
|
+
libGlobalsCache.length = 0;
|
|
650
|
+
}
|
|
651
|
+
/** Drops the shared library globals merged from any of `files`, for a program that is no longer used. */
|
|
652
|
+
export function dropLibGlobals(files) {
|
|
653
|
+
const dropped = new Set(files);
|
|
654
|
+
for (let i = libGlobalsCache.length - 1; i >= 0; i--)
|
|
655
|
+
if (dropped.has(libGlobalsCache[i].files[0]))
|
|
656
|
+
libGlobalsCache.splice(i, 1);
|
|
657
|
+
}
|
|
658
|
+
/** Number of leading default library files, whose merged locals can be shared. */
|
|
659
|
+
function getLibraryCount(c) {
|
|
660
|
+
const files = c.files;
|
|
661
|
+
let count = 0;
|
|
662
|
+
while (count < files.length && c.host.isSourceFileDefaultLibrary(files[count]))
|
|
663
|
+
count++;
|
|
664
|
+
return count;
|
|
665
|
+
}
|
|
666
|
+
/** The shared globals of the checker's default libraries, if another checker merged them. */
|
|
667
|
+
export function findLibGlobals(c) {
|
|
668
|
+
const count = getLibraryCount(c);
|
|
669
|
+
if (count > 0)
|
|
670
|
+
for (const libs of libGlobalsCache)
|
|
671
|
+
if (libs.matches(c.files, count))
|
|
672
|
+
return libs;
|
|
673
|
+
return undefined;
|
|
674
|
+
}
|
|
675
|
+
export function borrowLibGlobals(c, libs) {
|
|
676
|
+
libs.borrower = c;
|
|
677
|
+
c.globalChanges = new TableChanges();
|
|
678
|
+
c.mergedSymbolChanges = new TableChanges();
|
|
679
|
+
}
|
|
680
|
+
/** Undoes a disposed checker's changes to the tables it borrowed. */
|
|
681
|
+
export function returnLibGlobals(c) {
|
|
682
|
+
const libs = c.libGlobals;
|
|
683
|
+
c.globalChanges.undo(libs.globals);
|
|
684
|
+
c.mergedSymbolChanges.undo(libs.mergedSymbols);
|
|
685
|
+
c.globalChanges = undefined;
|
|
686
|
+
c.mergedSymbolChanges = undefined;
|
|
687
|
+
libs.borrower = undefined;
|
|
688
|
+
}
|
|
689
|
+
export function setGlobal(c, name, symbol) {
|
|
690
|
+
if (c.globalChanges !== undefined)
|
|
691
|
+
c.globalChanges.set(c.globals, name, symbol);
|
|
692
|
+
else
|
|
693
|
+
c.globals.set(name, symbol);
|
|
694
|
+
}
|
|
695
|
+
function setMergedSymbol(c, id, target) {
|
|
696
|
+
if (c.mergedSymbolChanges !== undefined)
|
|
697
|
+
c.mergedSymbolChanges.set(c.mergedSymbols, id, target);
|
|
698
|
+
else
|
|
699
|
+
c.mergedSymbols.set(id, target);
|
|
700
|
+
}
|
|
701
|
+
/** Merges script locals into globals; ambient modules and augmentations wait for global types. */
|
|
702
|
+
export function initializeGlobals(c) {
|
|
703
|
+
const globals = c.globals;
|
|
704
|
+
const merged = c.mergedGlobals;
|
|
705
|
+
if (merged !== undefined) {
|
|
706
|
+
// The constructor copied the globals and merged symbols.
|
|
707
|
+
for (const symbol of merged.ambientModuleSymbols)
|
|
708
|
+
c.ambientModuleSymbols.push(symbol);
|
|
709
|
+
for (const pattern of merged.patternAmbientModules)
|
|
710
|
+
c.patternAmbientModules.push(pattern);
|
|
711
|
+
for (const [name, symbol] of merged.patternAmbientModuleAugmentations)
|
|
712
|
+
c.patternAmbientModuleAugmentations.set(name, symbol);
|
|
713
|
+
addMergeDiagnostics(c, merged, 0);
|
|
714
|
+
if (merged.ownUndefined)
|
|
715
|
+
setGlobal(c, 'undefined', c.undefinedSymbol);
|
|
716
|
+
return;
|
|
717
|
+
}
|
|
718
|
+
const libraryCount = getLibraryCount(c);
|
|
719
|
+
const libs = c.libGlobals;
|
|
720
|
+
if (libs !== undefined) {
|
|
721
|
+
// The constructor copied the globals and merged symbols.
|
|
722
|
+
for (const symbol of libs.ambientModuleSymbols)
|
|
723
|
+
c.ambientModuleSymbols.push(symbol);
|
|
724
|
+
for (const pattern of libs.patternAmbientModules)
|
|
725
|
+
c.patternAmbientModules.push(pattern);
|
|
726
|
+
}
|
|
727
|
+
else if (libraryCount > 0) {
|
|
728
|
+
const diagnosticCount = c.diagnostics.count();
|
|
729
|
+
for (let i = 0; i < libraryCount; i++)
|
|
730
|
+
mergeFileGlobals(c, c.files[i]);
|
|
731
|
+
// Diagnostics belong to one checker, so libraries that report any aren't shared.
|
|
732
|
+
if (c.diagnostics.count() === diagnosticCount) {
|
|
733
|
+
c.libGlobals = new LibGlobals(c, c.files.slice(0, libraryCount));
|
|
734
|
+
libGlobalsCache.push(c.libGlobals);
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
for (let i = libraryCount; i < c.files.length; i++)
|
|
738
|
+
mergeFileGlobals(c, c.files[i]);
|
|
739
|
+
for (const file of c.files)
|
|
740
|
+
for (const augmentation of file.moduleAugmentations)
|
|
741
|
+
if (augmentation.parent !== undefined && isGlobalScopeAugmentation(augmentation.parent))
|
|
742
|
+
mergeModuleAugmentation(c, augmentation);
|
|
743
|
+
// addUndefinedToGlobalsOrErrorOnRedeclaration
|
|
744
|
+
const target = globals.get('undefined');
|
|
745
|
+
if (target !== undefined) {
|
|
746
|
+
for (const declaration of target.declarations)
|
|
747
|
+
if (!isTypeDeclaration(declaration))
|
|
748
|
+
c.addDiagnostic(createDiagnosticForNode(declaration, 568 /* Diagnostics.Declaration_name_conflicts_with_built_in_global_identifier_0 */, ['undefined']));
|
|
749
|
+
}
|
|
750
|
+
else
|
|
751
|
+
setGlobal(c, 'undefined', c.undefinedSymbol);
|
|
752
|
+
}
|
|
753
|
+
export function mergeAmbientModulesAndAugmentations(c) {
|
|
754
|
+
const merged = c.mergedGlobals;
|
|
755
|
+
if (merged !== undefined) {
|
|
756
|
+
addMergeDiagnostics(c, merged, 1);
|
|
757
|
+
return;
|
|
758
|
+
}
|
|
759
|
+
for (const symbol of c.ambientModuleSymbols)
|
|
760
|
+
mergeGlobalSymbol(c, symbol);
|
|
761
|
+
for (const file of c.files)
|
|
762
|
+
for (const augmentation of file.moduleAugmentations)
|
|
763
|
+
if (augmentation.parent !== undefined && !isGlobalScopeAugmentation(augmentation.parent))
|
|
764
|
+
mergeModuleAugmentation(c, augmentation);
|
|
765
|
+
}
|
|
766
|
+
export function isAmbientModuleSymbolName(name) {
|
|
767
|
+
return name.length >= 2 && name.charCodeAt(0) === 0x22 && name.charCodeAt(name.length - 1) === 0x22;
|
|
768
|
+
}
|
|
769
|
+
function isTypeDeclaration(node) {
|
|
770
|
+
switch (node.kind) {
|
|
771
|
+
case 169 /* SyntaxKind.TypeParameter */:
|
|
772
|
+
case 264 /* SyntaxKind.ClassDeclaration */:
|
|
773
|
+
case 265 /* SyntaxKind.InterfaceDeclaration */:
|
|
774
|
+
case 266 /* SyntaxKind.TypeAliasDeclaration */:
|
|
775
|
+
case 345 /* SyntaxKind.JSTypeAliasDeclaration */:
|
|
776
|
+
case 267 /* SyntaxKind.EnumDeclaration */:
|
|
777
|
+
return true;
|
|
778
|
+
case 274 /* SyntaxKind.ImportClause */:
|
|
779
|
+
return getIsTypeOnly(node);
|
|
780
|
+
case 277 /* SyntaxKind.ImportSpecifier */:
|
|
781
|
+
case 282 /* SyntaxKind.ExportSpecifier */:
|
|
782
|
+
return getIsTypeOnly(node);
|
|
783
|
+
}
|
|
784
|
+
return false;
|
|
785
|
+
}
|
|
786
|
+
function mergeGlobalSymbol(c, symbol) {
|
|
787
|
+
const globalSymbol = c.globals.get(symbol.name);
|
|
788
|
+
setGlobal(c, symbol.name, globalSymbol !== undefined ? mergeSymbol(c, globalSymbol, symbol, false) : getMergedSymbol(c, symbol));
|
|
789
|
+
}
|
|
790
|
+
function mergeModuleAugmentation(c, moduleName) {
|
|
791
|
+
const moduleNode = moduleName.parent;
|
|
792
|
+
const augmentationSymbol = moduleNode.symbol;
|
|
793
|
+
// Several augmentations in one file share a symbol; merge it once.
|
|
794
|
+
if (augmentationSymbol.declarations[0] !== moduleNode)
|
|
795
|
+
return;
|
|
796
|
+
if (isGlobalScopeAugmentation(moduleNode)) {
|
|
797
|
+
if (augmentationSymbol.exports !== undefined)
|
|
798
|
+
mergeSymbolTable(c, c.globals, augmentationSymbol.exports, false, undefined);
|
|
799
|
+
return;
|
|
800
|
+
}
|
|
801
|
+
const moduleNotFoundError = (moduleNode.parent.flags & 8388608 /* NodeFlags.Ambient */) === 0
|
|
802
|
+
? 798 /* Diagnostics.Invalid_module_name_in_augmentation_module_0_cannot_be_found */
|
|
803
|
+
: undefined;
|
|
804
|
+
let mainModule = resolveExternalModuleNameWorker(c, moduleName, moduleName, moduleNotFoundError, false, true);
|
|
805
|
+
if (mainModule === undefined)
|
|
806
|
+
return;
|
|
807
|
+
mainModule = resolveExternalModuleSymbol(c, mainModule, false);
|
|
808
|
+
if ((mainModule.flags & 1920 /* SymbolFlags.Namespace */) !== 0) {
|
|
809
|
+
for (const pattern of c.patternAmbientModules)
|
|
810
|
+
if (pattern.symbol === mainModule) {
|
|
811
|
+
const merged = mergeSymbol(c, augmentationSymbol, mainModule, true);
|
|
812
|
+
c.patternAmbientModuleAugmentations.set(getText(moduleName), merged);
|
|
813
|
+
return;
|
|
814
|
+
}
|
|
815
|
+
// Exports the module gets through `export *` live on the re-exported symbols; merge into those.
|
|
816
|
+
const mainExports = mainModule.exports;
|
|
817
|
+
const exports = augmentationSymbol.exports;
|
|
818
|
+
if (mainExports !== undefined &&
|
|
819
|
+
mainExports.has("\uFFFEexport" /* InternalSymbolName.ExportStar */) &&
|
|
820
|
+
exports !== undefined &&
|
|
821
|
+
exports.size > 0) {
|
|
822
|
+
const resolvedExports = getExportsOfModuleWorker(c, mainModule);
|
|
823
|
+
for (const [id, symbol] of exports) {
|
|
824
|
+
const resolved = resolvedExports.get(id);
|
|
825
|
+
if (resolved !== undefined && !mainExports.has(id))
|
|
826
|
+
mergeSymbol(c, resolved, symbol, false);
|
|
827
|
+
}
|
|
828
|
+
}
|
|
829
|
+
mergeSymbol(c, mainModule, augmentationSymbol, false);
|
|
830
|
+
}
|
|
831
|
+
else
|
|
832
|
+
c.error(moduleName, 805 /* Diagnostics.Cannot_augment_module_0_because_it_resolves_to_a_non_module_entity */, getText(moduleName));
|
|
833
|
+
}
|
|
834
|
+
export function mergeSymbolTable(c, target, source, unidirectional, mergedParent) {
|
|
835
|
+
for (const [id, sourceSymbol] of source) {
|
|
836
|
+
const targetSymbol = target.get(id);
|
|
837
|
+
const merged = targetSymbol !== undefined
|
|
838
|
+
? mergeSymbol(c, targetSymbol, sourceSymbol, unidirectional)
|
|
839
|
+
: getMergedSymbol(c, sourceSymbol);
|
|
840
|
+
// A merged symbol takes the parent that initiated the merge of its exports.
|
|
841
|
+
if (mergedParent !== undefined && targetSymbol !== undefined && (merged.flags & 33554432 /* SymbolFlags.Transient */) !== 0)
|
|
842
|
+
merged.parent = mergedParent;
|
|
843
|
+
if (target === c.globals)
|
|
844
|
+
setGlobal(c, id, merged);
|
|
845
|
+
else
|
|
846
|
+
target.set(id, merged);
|
|
847
|
+
}
|
|
848
|
+
}
|
|
849
|
+
/** Merges `source` into `target`, cloning a non-transient target first. */
|
|
850
|
+
export function mergeSymbol(c, target, source, unidirectional) {
|
|
851
|
+
if ((target.flags & getExcludedSymbolFlags(source.flags)) === 0 ||
|
|
852
|
+
((source.flags | target.flags) & 67108864 /* SymbolFlags.Assignment */) !== 0) {
|
|
853
|
+
if (source === target)
|
|
854
|
+
return target;
|
|
855
|
+
if ((target.flags & 33554432 /* SymbolFlags.Transient */) === 0) {
|
|
856
|
+
const resolvedTarget = resolveSymbol(c, target);
|
|
857
|
+
if (resolvedTarget === c.unknownSymbol)
|
|
858
|
+
return source;
|
|
859
|
+
if ((resolvedTarget.flags & getExcludedSymbolFlags(source.flags)) === 0 ||
|
|
860
|
+
((source.flags | resolvedTarget.flags) & 67108864 /* SymbolFlags.Assignment */) !== 0)
|
|
861
|
+
target = cloneSymbol(c, resolvedTarget);
|
|
862
|
+
else {
|
|
863
|
+
reportMergeSymbolError(c, target, source);
|
|
864
|
+
return source;
|
|
865
|
+
}
|
|
866
|
+
}
|
|
867
|
+
else if (sharedSources(c, target) !== undefined)
|
|
868
|
+
target = copySharedSymbol(c, target);
|
|
869
|
+
if ((source.flags & 512 /* SymbolFlags.ValueModule */) !== 0 &&
|
|
870
|
+
(target.flags & 512 /* SymbolFlags.ValueModule */) !== 0 &&
|
|
871
|
+
(target.flags & 268435456 /* SymbolFlags.ConstEnumOnlyModule */) !== 0 &&
|
|
872
|
+
(source.flags & 268435456 /* SymbolFlags.ConstEnumOnlyModule */) === 0)
|
|
873
|
+
target.flags &= ~268435456 /* SymbolFlags.ConstEnumOnlyModule */;
|
|
874
|
+
let sourceFlags = source.flags;
|
|
875
|
+
if ((target.flags & 268435456 /* SymbolFlags.ConstEnumOnlyModule */) === 0)
|
|
876
|
+
sourceFlags &= ~268435456 /* SymbolFlags.ConstEnumOnlyModule */;
|
|
877
|
+
target.flags |= sourceFlags;
|
|
878
|
+
if (source.valueDeclaration !== undefined)
|
|
879
|
+
setValueDeclaration(target, source.valueDeclaration);
|
|
880
|
+
for (const d of source.declarations)
|
|
881
|
+
addDeclaration(target, d);
|
|
882
|
+
if (source.members !== undefined) {
|
|
883
|
+
if (target.members === undefined)
|
|
884
|
+
target.members = new Map();
|
|
885
|
+
mergeSymbolTable(c, target.members, source.members, unidirectional, undefined);
|
|
886
|
+
}
|
|
887
|
+
if (source.exports !== undefined) {
|
|
888
|
+
if (target.exports === undefined)
|
|
889
|
+
target.exports = new Map();
|
|
890
|
+
mergeSymbolTable(c, target.exports, source.exports, unidirectional, target);
|
|
891
|
+
}
|
|
892
|
+
if (!unidirectional)
|
|
893
|
+
recordMergedSymbol(c, target, source);
|
|
894
|
+
}
|
|
895
|
+
else if ((target.flags & 1024 /* SymbolFlags.NamespaceModule */) !== 0) {
|
|
896
|
+
// `var globalThis` already reports a conflict with the built-in.
|
|
897
|
+
if (target !== c.globalThisSymbol)
|
|
898
|
+
c.error(getNameOfDeclaration(source.declarations[0]), 783 /* Diagnostics.Cannot_augment_module_0_with_value_exports_because_it_resolves_to_a_non_module_entity */, symbolToString(c, target));
|
|
899
|
+
}
|
|
900
|
+
else
|
|
901
|
+
reportMergeSymbolError(c, target, source);
|
|
902
|
+
return target;
|
|
903
|
+
}
|
|
904
|
+
function reportMergeSymbolError(c, target, source) {
|
|
905
|
+
const isEitherEnum = ((target.flags | source.flags) & 384 /* SymbolFlags.Enum */) !== 0;
|
|
906
|
+
const isEitherBlockScoped = ((target.flags | source.flags) & 2 /* SymbolFlags.BlockScopedVariable */) !== 0;
|
|
907
|
+
const message = isEitherEnum
|
|
908
|
+
? 721 /* Diagnostics.Enum_declarations_can_only_merge_with_namespace_or_other_enum_declarations */
|
|
909
|
+
: isEitherBlockScoped
|
|
910
|
+
? 619 /* Diagnostics.Cannot_redeclare_block_scoped_variable_0 */
|
|
911
|
+
: 478 /* Diagnostics.Duplicate_identifier_0 */;
|
|
912
|
+
const name = symbolToString(c, source);
|
|
913
|
+
if (!isPlainJSFile(source))
|
|
914
|
+
addDuplicateDeclarationErrors(c, source, message, name, target);
|
|
915
|
+
if (!isPlainJSFile(target))
|
|
916
|
+
addDuplicateDeclarationErrors(c, target, message, name, source);
|
|
917
|
+
}
|
|
918
|
+
function isPlainJSFile(symbol) {
|
|
919
|
+
if (symbol.declarations.length === 0)
|
|
920
|
+
return false;
|
|
921
|
+
const file = getSourceFileOfNode(symbol.declarations[0]);
|
|
922
|
+
return file.isJS() && file.checkJsDirective === undefined;
|
|
923
|
+
}
|
|
924
|
+
function addDuplicateDeclarationErrors(c, target, message, name, source) {
|
|
925
|
+
for (const node of target.declarations)
|
|
926
|
+
addDuplicateDeclarationError(c, node, message, name, source.declarations);
|
|
927
|
+
}
|
|
928
|
+
export function addDuplicateDeclarationError(c, node, message, name, relatedNodes) {
|
|
929
|
+
const errorNode = getNameOfDeclaration(node) ?? node;
|
|
930
|
+
const error = lookupOrIssueError(c, errorNode, message, [name]);
|
|
931
|
+
for (const relatedNode of relatedNodes) {
|
|
932
|
+
const adjusted = getNameOfDeclaration(relatedNode) ?? relatedNode;
|
|
933
|
+
if (adjusted === errorNode)
|
|
934
|
+
continue;
|
|
935
|
+
const leading = createDiagnosticForNode(adjusted, 1356 /* Diagnostics.X_0_was_also_declared_here */, [name]);
|
|
936
|
+
const followOn = createDiagnosticForNode(adjusted, 1357 /* Diagnostics.X_and_here */, []);
|
|
937
|
+
const related = error.relatedInformation;
|
|
938
|
+
if (related.length >= 5 || hasMatchingDiagnostic(related, leading, followOn))
|
|
939
|
+
continue;
|
|
940
|
+
error.addRelatedInfo(related.length === 0 ? leading : followOn);
|
|
941
|
+
}
|
|
942
|
+
}
|
|
943
|
+
function hasMatchingDiagnostic(diagnostics, a, b) {
|
|
944
|
+
for (const d of diagnostics)
|
|
945
|
+
if (compareDiagnostics(d, b) === 0 || compareDiagnostics(d, a) === 0)
|
|
946
|
+
return true;
|
|
947
|
+
return false;
|
|
948
|
+
}
|
|
949
|
+
function lookupOrIssueError(c, location, message, args) {
|
|
950
|
+
const diagnostic = createDiagnosticForNode(location, message, args);
|
|
951
|
+
const existing = c.diagnostics.lookup(diagnostic);
|
|
952
|
+
if (existing !== undefined)
|
|
953
|
+
return existing;
|
|
954
|
+
c.addDiagnostic(diagnostic);
|
|
955
|
+
return diagnostic;
|
|
956
|
+
}
|
|
957
|
+
export function getExcludedSymbolFlags(flags) {
|
|
958
|
+
let result = 0;
|
|
959
|
+
if ((flags & 2 /* SymbolFlags.BlockScopedVariable */) !== 0)
|
|
960
|
+
result |= 111551 /* SymbolFlags.BlockScopedVariableExcludes */;
|
|
961
|
+
if ((flags & 1 /* SymbolFlags.FunctionScopedVariable */) !== 0)
|
|
962
|
+
result |= 111550 /* SymbolFlags.FunctionScopedVariableExcludes */;
|
|
963
|
+
if ((flags & 4 /* SymbolFlags.Property */) !== 0)
|
|
964
|
+
result |= 13243 /* SymbolFlags.PropertyExcludes */;
|
|
965
|
+
if ((flags & 8 /* SymbolFlags.EnumMember */) !== 0)
|
|
966
|
+
result |= 900095 /* SymbolFlags.EnumMemberExcludes */;
|
|
967
|
+
if ((flags & 16 /* SymbolFlags.Function */) !== 0)
|
|
968
|
+
result |= 110991 /* SymbolFlags.FunctionExcludes */;
|
|
969
|
+
if ((flags & 32 /* SymbolFlags.Class */) !== 0)
|
|
970
|
+
result |= 899503 /* SymbolFlags.ClassExcludes */;
|
|
971
|
+
if ((flags & 64 /* SymbolFlags.Interface */) !== 0)
|
|
972
|
+
result |= 788872 /* SymbolFlags.InterfaceExcludes */;
|
|
973
|
+
if ((flags & 256 /* SymbolFlags.RegularEnum */) !== 0)
|
|
974
|
+
result |= 899327 /* SymbolFlags.RegularEnumExcludes */;
|
|
975
|
+
if ((flags & 128 /* SymbolFlags.ConstEnum */) !== 0)
|
|
976
|
+
result |= 899967 /* SymbolFlags.ConstEnumExcludes */;
|
|
977
|
+
if ((flags & 512 /* SymbolFlags.ValueModule */) !== 0)
|
|
978
|
+
result |= 110735 /* SymbolFlags.ValueModuleExcludes */;
|
|
979
|
+
if ((flags & 8192 /* SymbolFlags.Method */) !== 0)
|
|
980
|
+
result |= 103359 /* SymbolFlags.MethodExcludes */;
|
|
981
|
+
if ((flags & 32768 /* SymbolFlags.GetAccessor */) !== 0)
|
|
982
|
+
result |= 46011 /* SymbolFlags.GetAccessorExcludes */;
|
|
983
|
+
if ((flags & 65536 /* SymbolFlags.SetAccessor */) !== 0)
|
|
984
|
+
result |= 78779 /* SymbolFlags.SetAccessorExcludes */;
|
|
985
|
+
if ((flags & 262144 /* SymbolFlags.TypeParameter */) !== 0)
|
|
986
|
+
result |= 526824 /* SymbolFlags.TypeParameterExcludes */;
|
|
987
|
+
if ((flags & 524288 /* SymbolFlags.TypeAlias */) !== 0)
|
|
988
|
+
result |= 788968 /* SymbolFlags.TypeAliasExcludes */;
|
|
989
|
+
if ((flags & 2097152 /* SymbolFlags.Alias */) !== 0)
|
|
990
|
+
result |= 2097152 /* SymbolFlags.AliasExcludes */;
|
|
991
|
+
if ((flags & 536870912 /* SymbolFlags.ReplaceableByMethod */) !== 0)
|
|
992
|
+
result &= ~8192 /* SymbolFlags.Method */;
|
|
993
|
+
return result;
|
|
994
|
+
}
|
|
995
|
+
export function cloneSymbol(c, symbol) {
|
|
996
|
+
const result = c.newSymbol(symbol.flags, symbol.name);
|
|
997
|
+
result.declarations = symbol.declarations.slice();
|
|
998
|
+
result.parent = symbol.parent;
|
|
999
|
+
result.valueDeclaration = symbol.valueDeclaration;
|
|
1000
|
+
if (symbol.members !== undefined)
|
|
1001
|
+
result.members = new Map(symbol.members);
|
|
1002
|
+
if (symbol.exports !== undefined)
|
|
1003
|
+
result.exports = new Map(symbol.exports);
|
|
1004
|
+
recordMergedSymbol(c, result, symbol);
|
|
1005
|
+
return result;
|
|
1006
|
+
}
|
|
1007
|
+
/**
|
|
1008
|
+
* A checker's own copy of a symbol shared through `LibGlobals`, which stands for it: the symbols
|
|
1009
|
+
* merged into the shared one, and the shared one itself, now merge into the copy.
|
|
1010
|
+
*/
|
|
1011
|
+
function copySharedSymbol(c, shared) {
|
|
1012
|
+
const result = c.newSymbol(shared.flags, shared.name);
|
|
1013
|
+
result.declarations = shared.declarations.slice();
|
|
1014
|
+
result.parent = shared.parent;
|
|
1015
|
+
result.valueDeclaration = shared.valueDeclaration;
|
|
1016
|
+
if (shared.members !== undefined)
|
|
1017
|
+
result.members = new Map(shared.members);
|
|
1018
|
+
if (shared.exports !== undefined)
|
|
1019
|
+
result.exports = new Map(shared.exports);
|
|
1020
|
+
c.sharedSymbolCopies.set(result, shared);
|
|
1021
|
+
recordMergedSymbol(c, result, result);
|
|
1022
|
+
return result;
|
|
1023
|
+
}
|
|
1024
|
+
function recordMergedSymbol(c, target, source) {
|
|
1025
|
+
setMergedSymbol(c, getSymbolId(source), target);
|
|
1026
|
+
// Merging a copy merges what it stands for.
|
|
1027
|
+
const shared = c.sharedSymbolCopies.get(source);
|
|
1028
|
+
if (shared !== undefined) {
|
|
1029
|
+
setMergedSymbol(c, getSymbolId(shared), target);
|
|
1030
|
+
for (const id of sharedSources(c, shared))
|
|
1031
|
+
setMergedSymbol(c, id, target);
|
|
1032
|
+
}
|
|
1033
|
+
}
|
|
1034
|
+
export function getMergedSymbol(c, symbol) {
|
|
1035
|
+
const id = symbol.id;
|
|
1036
|
+
if (id !== 0) {
|
|
1037
|
+
const merged = c.mergedSymbols.get(id);
|
|
1038
|
+
if (merged !== undefined)
|
|
1039
|
+
return merged;
|
|
1040
|
+
}
|
|
1041
|
+
return symbol;
|
|
1042
|
+
}
|
|
1043
|
+
export function getParentOfSymbol(c, symbol) {
|
|
1044
|
+
return symbol.parent !== undefined ? getMergedSymbol(c, getLateBoundSymbol(c, symbol.parent)) : undefined;
|
|
1045
|
+
}
|
|
1046
|
+
export function getExportSymbolOfValueSymbolIfExported(c, symbol) {
|
|
1047
|
+
if ((symbol.flags & 1048576 /* SymbolFlags.ExportValue */) !== 0 && symbol.exportSymbol !== undefined)
|
|
1048
|
+
symbol = symbol.exportSymbol;
|
|
1049
|
+
return getMergedSymbol(c, symbol);
|
|
1050
|
+
}
|
|
1051
|
+
export function getSymbolOfDeclaration(c, node) {
|
|
1052
|
+
const symbol = getSymbol(node);
|
|
1053
|
+
return symbol !== undefined ? getMergedSymbol(c, getLateBoundSymbol(c, symbol)) : undefined;
|
|
1054
|
+
}
|
|
1055
|
+
function hasStaticDeclaration(symbol) {
|
|
1056
|
+
for (const d of symbol.declarations)
|
|
1057
|
+
if (hasStaticModifier(d))
|
|
1058
|
+
return true;
|
|
1059
|
+
return false;
|
|
1060
|
+
}
|
|
1061
|
+
export function getLateBoundSymbol(c, symbol) {
|
|
1062
|
+
if ((symbol.flags & 106500 /* SymbolFlags.ClassMember */) === 0 || symbol.name !== "\uFFFEcomputed" /* InternalSymbolName.Computed */)
|
|
1063
|
+
return symbol;
|
|
1064
|
+
const links = c.symbolLinks(symbol);
|
|
1065
|
+
if (links.lateSymbol === undefined && hasLateBindableDeclaration(c, symbol)) {
|
|
1066
|
+
// Force late binding of the parent's members or exports, which sets lateSymbol.
|
|
1067
|
+
if (symbol.parent !== undefined) {
|
|
1068
|
+
const parent = getMergedSymbol(c, symbol.parent);
|
|
1069
|
+
if (hasStaticDeclaration(symbol))
|
|
1070
|
+
getExportsOfSymbol(c, parent);
|
|
1071
|
+
else
|
|
1072
|
+
getMembersOfSymbol(c, parent);
|
|
1073
|
+
}
|
|
1074
|
+
else {
|
|
1075
|
+
// An `F[name] = …` assignment in a script has no parent. Checking its target late-binds it
|
|
1076
|
+
// with the members of the function it's assigned to.
|
|
1077
|
+
for (const declaration of symbol.declarations)
|
|
1078
|
+
if (declaration instanceof BinaryExpression)
|
|
1079
|
+
checkExpressionCached(c, declaration.left);
|
|
1080
|
+
}
|
|
1081
|
+
}
|
|
1082
|
+
if (links.lateSymbol === undefined)
|
|
1083
|
+
links.lateSymbol = symbol;
|
|
1084
|
+
return links.lateSymbol;
|
|
1085
|
+
}
|
|
1086
|
+
function hasLateBindableDeclaration(c, symbol) {
|
|
1087
|
+
for (const declaration of symbol.declarations)
|
|
1088
|
+
if (hasLateBindableName(c, declaration))
|
|
1089
|
+
return true;
|
|
1090
|
+
return false;
|
|
1091
|
+
}
|
|
1092
|
+
// ---- Global types
|
|
1093
|
+
export function getGlobalSymbol(c, name, meaning, diagnostic) {
|
|
1094
|
+
// Without a location, missing globals are global diagnostics.
|
|
1095
|
+
return resolveName(c, undefined, name, meaning, diagnostic, false, false);
|
|
1096
|
+
}
|
|
1097
|
+
function getGlobalTypeDeclaration(symbol) {
|
|
1098
|
+
for (const d of symbol.declarations) {
|
|
1099
|
+
switch (d.kind) {
|
|
1100
|
+
case 264 /* SyntaxKind.ClassDeclaration */:
|
|
1101
|
+
case 265 /* SyntaxKind.InterfaceDeclaration */:
|
|
1102
|
+
case 267 /* SyntaxKind.EnumDeclaration */:
|
|
1103
|
+
case 266 /* SyntaxKind.TypeAliasDeclaration */:
|
|
1104
|
+
return d;
|
|
1105
|
+
}
|
|
1106
|
+
}
|
|
1107
|
+
return undefined;
|
|
1108
|
+
}
|
|
1109
|
+
/** The global class or interface `name` with `arity` type parameters, or the empty (generic) object type. */
|
|
1110
|
+
export function getGlobalType(c, name, arity, reportErrors) {
|
|
1111
|
+
const symbol = getGlobalSymbol(c, name, 788968 /* SymbolFlags.Type */, reportErrors ? 496 /* Diagnostics.Cannot_find_global_type_0 */ : undefined);
|
|
1112
|
+
if (symbol !== undefined) {
|
|
1113
|
+
if ((symbol.flags & (32 /* SymbolFlags.Class */ | 64 /* SymbolFlags.Interface */)) !== 0) {
|
|
1114
|
+
const type = getDeclaredTypeOfSymbol(c, symbol);
|
|
1115
|
+
if (type.typeParameterCount() === arity)
|
|
1116
|
+
return type;
|
|
1117
|
+
if (reportErrors)
|
|
1118
|
+
c.error(getGlobalTypeDeclaration(symbol), 495 /* Diagnostics.Global_type_0_must_have_1_type_parameter_s */, symbol.name, String(arity));
|
|
1119
|
+
}
|
|
1120
|
+
else if (reportErrors)
|
|
1121
|
+
c.error(getGlobalTypeDeclaration(symbol), 494 /* Diagnostics.Global_type_0_must_be_a_class_or_interface_type */, symbol.name);
|
|
1122
|
+
}
|
|
1123
|
+
return arity !== 0 ? c.emptyGenericType : c.emptyObjectType;
|
|
1124
|
+
}
|
|
1125
|
+
/** Memoized `getGlobalType`, keyed by name, arity and whether errors were reported. */
|
|
1126
|
+
export function getCachedGlobalType(c, name, arity, reportErrors) {
|
|
1127
|
+
// By name, then by arity and whether errors are reported: callers pass literal names.
|
|
1128
|
+
let byArity = c.globalTypeCache.get(name);
|
|
1129
|
+
if (byArity === undefined) {
|
|
1130
|
+
byArity = new Map();
|
|
1131
|
+
c.globalTypeCache.set(name, byArity);
|
|
1132
|
+
}
|
|
1133
|
+
const slot = arity * 2 + (reportErrors ? 1 : 0);
|
|
1134
|
+
let type = byArity.get(slot);
|
|
1135
|
+
if (type === undefined) {
|
|
1136
|
+
type = getGlobalType(c, name, arity, reportErrors);
|
|
1137
|
+
byArity.set(slot, type);
|
|
1138
|
+
}
|
|
1139
|
+
return type;
|
|
1140
|
+
}
|
|
1141
|
+
export function getGlobalTypeAliasSymbol(c, name, arity, reportErrors) {
|
|
1142
|
+
const key = 'alias:' + name + '/' + arity + (reportErrors ? '!' : '');
|
|
1143
|
+
const cached = c.globalSymbolCache.get(key);
|
|
1144
|
+
if (cached !== undefined)
|
|
1145
|
+
return cached === null ? undefined : cached;
|
|
1146
|
+
let symbol = getGlobalSymbol(c, name, 524288 /* SymbolFlags.TypeAlias */, reportErrors ? 496 /* Diagnostics.Cannot_find_global_type_0 */ : undefined);
|
|
1147
|
+
if (symbol !== undefined) {
|
|
1148
|
+
getDeclaredTypeOfSymbol(c, symbol);
|
|
1149
|
+
const typeParameters = c.symbolLinks(symbol).typeParameters;
|
|
1150
|
+
if ((typeParameters === undefined ? 0 : typeParameters.length) !== arity) {
|
|
1151
|
+
if (reportErrors) {
|
|
1152
|
+
c.error(getDeclarationOfKind(symbol, 266 /* SyntaxKind.TypeAliasDeclaration */), 495 /* Diagnostics.Global_type_0_must_have_1_type_parameter_s */, symbol.name, String(arity));
|
|
1153
|
+
}
|
|
1154
|
+
symbol = undefined;
|
|
1155
|
+
}
|
|
1156
|
+
}
|
|
1157
|
+
c.globalSymbolCache.set(key, symbol === undefined ? null : symbol);
|
|
1158
|
+
return symbol;
|
|
1159
|
+
}
|
|
1160
|
+
export function getGlobalValueSymbol(c, name, reportErrors) {
|
|
1161
|
+
const key = 'value:' + name + (reportErrors ? '!' : '');
|
|
1162
|
+
const cached = c.globalSymbolCache.get(key);
|
|
1163
|
+
if (cached !== undefined)
|
|
1164
|
+
return cached === null ? undefined : cached;
|
|
1165
|
+
const symbol = getGlobalSymbol(c, name, 111551 /* SymbolFlags.Value */, reportErrors ? 634 /* Diagnostics.Cannot_find_global_value_0 */ : undefined);
|
|
1166
|
+
c.globalSymbolCache.set(key, symbol === undefined ? null : symbol);
|
|
1167
|
+
return symbol;
|
|
1168
|
+
}
|
|
1169
|
+
export function getGlobalStrictFunctionType(c, name) {
|
|
1170
|
+
return c.strictBindCallApply ? getGlobalType(c, name, 0, true) : c.globalFunctionType;
|
|
1171
|
+
}
|
|
1172
|
+
// ---- Aliases
|
|
1173
|
+
export function isNonLocalAlias(symbol, excludes) {
|
|
1174
|
+
if (symbol === undefined)
|
|
1175
|
+
return false;
|
|
1176
|
+
return ((symbol.flags & (2097152 /* SymbolFlags.Alias */ | excludes)) === 2097152 /* SymbolFlags.Alias */ ||
|
|
1177
|
+
((symbol.flags & 2097152 /* SymbolFlags.Alias */) !== 0 && (symbol.flags & 67108864 /* SymbolFlags.Assignment */) !== 0));
|
|
1178
|
+
}
|
|
1179
|
+
export function resolveSymbol(c, symbol) {
|
|
1180
|
+
if (symbol !== undefined && isNonLocalAlias(symbol, 111551 /* SymbolFlags.Value */ | 788968 /* SymbolFlags.Type */ | 1920 /* SymbolFlags.Namespace */))
|
|
1181
|
+
return resolveAlias(c, symbol);
|
|
1182
|
+
return symbol;
|
|
1183
|
+
}
|
|
1184
|
+
export function resolveSymbolEx(c, symbol, dontResolveAlias) {
|
|
1185
|
+
if (!dontResolveAlias && isNonLocalAlias(symbol, 111551 /* SymbolFlags.Value */ | 788968 /* SymbolFlags.Type */ | 1920 /* SymbolFlags.Namespace */))
|
|
1186
|
+
return resolveAlias(c, symbol);
|
|
1187
|
+
return symbol;
|
|
1188
|
+
}
|
|
1189
|
+
export function getDeclarationOfAliasSymbol(symbol) {
|
|
1190
|
+
for (let i = symbol.declarations.length - 1; i >= 0; i--) {
|
|
1191
|
+
const d = symbol.declarations[i];
|
|
1192
|
+
if (isAliasSymbolDeclaration(d))
|
|
1193
|
+
return d;
|
|
1194
|
+
}
|
|
1195
|
+
return undefined;
|
|
1196
|
+
}
|
|
1197
|
+
export function isAliasSymbolDeclaration(node) {
|
|
1198
|
+
switch (node.kind) {
|
|
1199
|
+
case 272 /* SyntaxKind.ImportEqualsDeclaration */:
|
|
1200
|
+
case 271 /* SyntaxKind.NamespaceExportDeclaration */:
|
|
1201
|
+
case 275 /* SyntaxKind.NamespaceImport */:
|
|
1202
|
+
case 281 /* SyntaxKind.NamespaceExport */:
|
|
1203
|
+
case 277 /* SyntaxKind.ImportSpecifier */:
|
|
1204
|
+
case 282 /* SyntaxKind.ExportSpecifier */:
|
|
1205
|
+
return true;
|
|
1206
|
+
case 274 /* SyntaxKind.ImportClause */:
|
|
1207
|
+
return getName(node) !== undefined;
|
|
1208
|
+
case 278 /* SyntaxKind.ExportAssignment */: {
|
|
1209
|
+
const e = getExpression(node);
|
|
1210
|
+
return e !== undefined && isEntityNameExpressionNode(e);
|
|
1211
|
+
}
|
|
1212
|
+
case 261 /* SyntaxKind.VariableDeclaration */:
|
|
1213
|
+
case 209 /* SyntaxKind.BindingElement */:
|
|
1214
|
+
case 227 /* SyntaxKind.BinaryExpression */:
|
|
1215
|
+
return isJSAliasDeclaration(node);
|
|
1216
|
+
}
|
|
1217
|
+
return false;
|
|
1218
|
+
}
|
|
1219
|
+
function isEntityNameExpressionNode(node) {
|
|
1220
|
+
if (node.kind === 79 /* SyntaxKind.Identifier */)
|
|
1221
|
+
return true;
|
|
1222
|
+
if (node.kind === 212 /* SyntaxKind.PropertyAccessExpression */) {
|
|
1223
|
+
const e = getExpression(node);
|
|
1224
|
+
const name = getName(node);
|
|
1225
|
+
return name !== undefined && name.kind === 79 /* SyntaxKind.Identifier */ && isEntityNameExpressionNode(e);
|
|
1226
|
+
}
|
|
1227
|
+
return false;
|
|
1228
|
+
}
|
|
1229
|
+
/** The alias target, unless resolving it now would be circular. */
|
|
1230
|
+
export function tryResolveAlias(c, symbol) {
|
|
1231
|
+
if (c.symbolLinks(symbol).aliasTarget !== undefined ||
|
|
1232
|
+
findResolutionCycleStartIndex(c, symbol, 9 /* TypeSystemPropertyName.AliasTarget */) < 0)
|
|
1233
|
+
return resolveAlias(c, symbol);
|
|
1234
|
+
return undefined;
|
|
1235
|
+
}
|
|
1236
|
+
export function resolveAlias(c, symbol) {
|
|
1237
|
+
const links = c.symbolLinks(symbol);
|
|
1238
|
+
let target = links.aliasTarget;
|
|
1239
|
+
if (target !== undefined)
|
|
1240
|
+
return target;
|
|
1241
|
+
if (!pushTypeResolution(c, symbol, 9 /* TypeSystemPropertyName.AliasTarget */))
|
|
1242
|
+
return c.unknownSymbol;
|
|
1243
|
+
const node = getDeclarationOfAliasSymbol(symbol);
|
|
1244
|
+
let resolved = getTargetOfAliasDeclaration(c, node);
|
|
1245
|
+
// A pure alias target is resolved transitively, carrying over its type-only declaration.
|
|
1246
|
+
if (resolved !== undefined && isNonLocalAlias(resolved, 111551 /* SymbolFlags.Value */ | 788968 /* SymbolFlags.Type */ | 1920 /* SymbolFlags.Namespace */))
|
|
1247
|
+
resolved = resolveIndirectionAlias(c, symbol, resolved);
|
|
1248
|
+
target = resolved ?? c.unknownSymbol;
|
|
1249
|
+
links.aliasTarget = target;
|
|
1250
|
+
if (!popTypeResolution(c)) {
|
|
1251
|
+
c.error(node, 481 /* Diagnostics.Circular_definition_of_import_alias_0 */, symbolToString(c, symbol));
|
|
1252
|
+
links.aliasTarget = c.unknownSymbol;
|
|
1253
|
+
}
|
|
1254
|
+
return links.aliasTarget;
|
|
1255
|
+
}
|
|
1256
|
+
/**
|
|
1257
|
+
* The combined flags of `symbol` and every alias target; All when an alias resolves to unknown. With
|
|
1258
|
+
* `excludeTypeOnlyMeanings`, the chain stops at the first alias with a type-only declaration.
|
|
1259
|
+
*/
|
|
1260
|
+
export function getSymbolFlags(c, symbol, excludeTypeOnlyMeanings = false) {
|
|
1261
|
+
let flags = symbol.flags;
|
|
1262
|
+
// Created for the first alias of an alias, as tsgo's zero-value set.
|
|
1263
|
+
let seen = undefined;
|
|
1264
|
+
while ((symbol.flags & 2097152 /* SymbolFlags.Alias */) !== 0) {
|
|
1265
|
+
if (excludeTypeOnlyMeanings && getTypeOnlyAliasDeclaration(c, symbol) !== undefined)
|
|
1266
|
+
break;
|
|
1267
|
+
const target = getExportSymbolOfValueSymbolIfExported(c, resolveAlias(c, symbol));
|
|
1268
|
+
if (target === c.unknownSymbol)
|
|
1269
|
+
return 1073741823 /* SymbolFlags.All */;
|
|
1270
|
+
if ((target.flags & 2097152 /* SymbolFlags.Alias */) !== 0) {
|
|
1271
|
+
if (target === symbol || (seen !== undefined && seen.has(target)))
|
|
1272
|
+
break;
|
|
1273
|
+
if (seen === undefined)
|
|
1274
|
+
seen = new Set();
|
|
1275
|
+
seen.add(symbol);
|
|
1276
|
+
seen.add(target);
|
|
1277
|
+
}
|
|
1278
|
+
flags |= target.flags;
|
|
1279
|
+
symbol = target;
|
|
1280
|
+
}
|
|
1281
|
+
return flags;
|
|
1282
|
+
}
|
|
1283
|
+
// ---- Members and exports
|
|
1284
|
+
export function getExportsOfSymbol(c, symbol) {
|
|
1285
|
+
if ((symbol.flags & 6256 /* SymbolFlags.LateBindingContainer */) !== 0)
|
|
1286
|
+
return getResolvedMembersOrExports(c, symbol, true);
|
|
1287
|
+
if ((symbol.flags & 1536 /* SymbolFlags.Module */) !== 0)
|
|
1288
|
+
return getExportsOfModule(c, symbol);
|
|
1289
|
+
return symbol.exports ?? emptySymbolTable;
|
|
1290
|
+
}
|
|
1291
|
+
export const emptySymbolTable = new Map();
|
|
1292
|
+
export function getExportsOfModule(c, moduleSymbol) {
|
|
1293
|
+
// Late-bound members share the cache.
|
|
1294
|
+
if ((moduleSymbol.flags & 6256 /* SymbolFlags.LateBindingContainer */) !== 0)
|
|
1295
|
+
return getResolvedMembersOrExports(c, moduleSymbol, true);
|
|
1296
|
+
const links = c.symbolLinks(moduleSymbol);
|
|
1297
|
+
let exports = links.resolvedExports;
|
|
1298
|
+
if (exports === undefined) {
|
|
1299
|
+
exports = getExportsOfModuleWorker(c, moduleSymbol);
|
|
1300
|
+
links.resolvedExports = exports;
|
|
1301
|
+
}
|
|
1302
|
+
return exports;
|
|
1303
|
+
}
|
|
1304
|
+
export function getMembersOfSymbol(c, symbol) {
|
|
1305
|
+
if ((symbol.flags & 6256 /* SymbolFlags.LateBindingContainer */) !== 0)
|
|
1306
|
+
return getResolvedMembersOrExports(c, symbol, false);
|
|
1307
|
+
return symbol.members ?? emptySymbolTable;
|
|
1308
|
+
}
|
|
1309
|
+
function getResolvedMembersOrExports(c, symbol, isStatic) {
|
|
1310
|
+
const links = c.symbolLinks(symbol);
|
|
1311
|
+
const cached = isStatic ? links.resolvedExports : links.resolvedMembers;
|
|
1312
|
+
if (cached !== undefined)
|
|
1313
|
+
return cached;
|
|
1314
|
+
let early;
|
|
1315
|
+
if (!isStatic)
|
|
1316
|
+
early = symbol.members ?? emptySymbolTable;
|
|
1317
|
+
else if ((symbol.flags & 1536 /* SymbolFlags.Module */) !== 0)
|
|
1318
|
+
early = getExportsOfModuleWorker(c, symbol);
|
|
1319
|
+
else
|
|
1320
|
+
early = symbol.exports ?? emptySymbolTable;
|
|
1321
|
+
if (isStatic)
|
|
1322
|
+
links.resolvedExports = early;
|
|
1323
|
+
else
|
|
1324
|
+
links.resolvedMembers = early;
|
|
1325
|
+
let late;
|
|
1326
|
+
for (const decl of symbol.declarations) {
|
|
1327
|
+
const members = getMembersOfDeclaration(decl);
|
|
1328
|
+
if (members === undefined)
|
|
1329
|
+
continue;
|
|
1330
|
+
for (const member of members) {
|
|
1331
|
+
if (isStatic !== hasStaticModifier(member))
|
|
1332
|
+
continue;
|
|
1333
|
+
if (hasLateBindableName(c, member)) {
|
|
1334
|
+
if (late === undefined)
|
|
1335
|
+
late = new Map();
|
|
1336
|
+
lateBindMember(c, symbol, early, late, member);
|
|
1337
|
+
}
|
|
1338
|
+
else if (hasLateBindableIndexSignature(c, member)) {
|
|
1339
|
+
if (late === undefined)
|
|
1340
|
+
late = new Map();
|
|
1341
|
+
lateBindIndexSignature(c, early, late, member);
|
|
1342
|
+
}
|
|
1343
|
+
}
|
|
1344
|
+
}
|
|
1345
|
+
// JavaScript `F[name] = …` assignments with late-bindable names.
|
|
1346
|
+
const assignments = isStatic ? symbol.exports?.get("\uFFFEassignment" /* InternalSymbolName.AssignmentDeclaration */) : undefined;
|
|
1347
|
+
if (assignments !== undefined)
|
|
1348
|
+
for (const member of assignments.declarations)
|
|
1349
|
+
if (hasLateBindableName(c, member)) {
|
|
1350
|
+
if (late === undefined)
|
|
1351
|
+
late = new Map();
|
|
1352
|
+
lateBindMember(c, symbol, early, late, member);
|
|
1353
|
+
}
|
|
1354
|
+
const result = late === undefined ? early : combineSymbolTables(c, early, late);
|
|
1355
|
+
if (isStatic)
|
|
1356
|
+
links.resolvedExports = result;
|
|
1357
|
+
else
|
|
1358
|
+
links.resolvedMembers = result;
|
|
1359
|
+
return result;
|
|
1360
|
+
}
|
|
1361
|
+
function getMembersOfDeclaration(decl) {
|
|
1362
|
+
switch (decl.kind) {
|
|
1363
|
+
case 264 /* SyntaxKind.ClassDeclaration */:
|
|
1364
|
+
case 232 /* SyntaxKind.ClassExpression */:
|
|
1365
|
+
case 265 /* SyntaxKind.InterfaceDeclaration */:
|
|
1366
|
+
case 188 /* SyntaxKind.TypeLiteral */:
|
|
1367
|
+
return getMemberNodes(decl)?.nodes;
|
|
1368
|
+
case 211 /* SyntaxKind.ObjectLiteralExpression */:
|
|
1369
|
+
return getProperties(decl).nodes;
|
|
1370
|
+
}
|
|
1371
|
+
return undefined;
|
|
1372
|
+
}
|
|
1373
|
+
export function combineSymbolTables(c, first, second) {
|
|
1374
|
+
if (first.size === 0)
|
|
1375
|
+
return second;
|
|
1376
|
+
if (second.size === 0)
|
|
1377
|
+
return first;
|
|
1378
|
+
const combined = new Map();
|
|
1379
|
+
mergeSymbolTable(c, combined, first, false, undefined);
|
|
1380
|
+
mergeSymbolTable(c, combined, second, false, undefined);
|
|
1381
|
+
return combined;
|
|
1382
|
+
}
|
|
1383
|
+
/** Binds a member with a computed name whose type is a literal or unique symbol under that name. */
|
|
1384
|
+
function lateBindMember(c, parent, early, late, decl) {
|
|
1385
|
+
const cached = c.resolvedSymbols.get(decl.id);
|
|
1386
|
+
if (cached !== undefined)
|
|
1387
|
+
return cached;
|
|
1388
|
+
// A recursive request falls back to the early-bound symbol.
|
|
1389
|
+
c.resolvedSymbols.set(decl.id, getSymbol(decl));
|
|
1390
|
+
const declName = getLateBindableNameOfDeclaration(decl);
|
|
1391
|
+
const type = declName.kind === 213 /* SyntaxKind.ElementAccessExpression */
|
|
1392
|
+
? checkExpressionCached(c, declName.argumentExpression)
|
|
1393
|
+
: checkComputedPropertyName(c, declName);
|
|
1394
|
+
if (isTypeUsableAsPropertyName(type)) {
|
|
1395
|
+
const memberName = getPropertyNameFromType(type);
|
|
1396
|
+
const symbolFlags = getSymbol(decl).flags;
|
|
1397
|
+
let lateSymbol = late.get(memberName);
|
|
1398
|
+
if (lateSymbol === undefined) {
|
|
1399
|
+
lateSymbol = c.newSymbolWithCheckFlags(0 /* SymbolFlags.None */, memberName, 4096 /* CheckFlags.Late */);
|
|
1400
|
+
late.set(memberName, lateSymbol);
|
|
1401
|
+
}
|
|
1402
|
+
const earlySymbol = early.get(memberName);
|
|
1403
|
+
if ((lateSymbol.flags & getExcludedSymbolFlags(symbolFlags)) !== 0) {
|
|
1404
|
+
const declarations = earlySymbol !== undefined ? earlySymbol.declarations.concat(lateSymbol.declarations) : lateSymbol.declarations;
|
|
1405
|
+
const name = (type.flags & 16384) !== 0 ? declarationNameToString(getSourceFileOfNode(declName), declName) : memberName;
|
|
1406
|
+
for (const d of declarations)
|
|
1407
|
+
c.error(getNameOfDeclaration(d) ?? d, 478 /* Diagnostics.Duplicate_identifier_0 */, name);
|
|
1408
|
+
c.error(declName, 478 /* Diagnostics.Duplicate_identifier_0 */, name);
|
|
1409
|
+
lateSymbol = c.newSymbolWithCheckFlags(0 /* SymbolFlags.None */, memberName, 4096 /* CheckFlags.Late */);
|
|
1410
|
+
}
|
|
1411
|
+
c.symbolNameTypes.set(getSymbolId(lateSymbol), type);
|
|
1412
|
+
addDeclarationToLateBoundSymbol(c, lateSymbol, decl, symbolFlags);
|
|
1413
|
+
if (lateSymbol.parent === undefined)
|
|
1414
|
+
lateSymbol.parent = parent;
|
|
1415
|
+
c.resolvedSymbols.set(decl.id, lateSymbol);
|
|
1416
|
+
}
|
|
1417
|
+
return c.resolvedSymbols.get(decl.id);
|
|
1418
|
+
}
|
|
1419
|
+
/** Adds a member whose computed name has a non-literal key type to the index symbol. */
|
|
1420
|
+
function lateBindIndexSignature(c, early, late, decl) {
|
|
1421
|
+
let indexSymbol = late.get("\uFFFEindex" /* InternalSymbolName.Index */);
|
|
1422
|
+
if (indexSymbol === undefined) {
|
|
1423
|
+
const earlyIndex = early.get("\uFFFEindex" /* InternalSymbolName.Index */);
|
|
1424
|
+
if (earlyIndex === undefined)
|
|
1425
|
+
indexSymbol = c.newSymbolWithCheckFlags(0 /* SymbolFlags.None */, "\uFFFEindex" /* InternalSymbolName.Index */, 4096 /* CheckFlags.Late */);
|
|
1426
|
+
else {
|
|
1427
|
+
indexSymbol = cloneSymbol(c, earlyIndex);
|
|
1428
|
+
indexSymbol.checkFlags |= 4096 /* CheckFlags.Late */;
|
|
1429
|
+
}
|
|
1430
|
+
late.set("\uFFFEindex" /* InternalSymbolName.Index */, indexSymbol);
|
|
1431
|
+
}
|
|
1432
|
+
// Unlike late-bound members, `decl` gets no late symbol: the index symbol isn't one property.
|
|
1433
|
+
if (indexSymbol.declarations.length === 0 || (getSymbol(decl).flags & 536870912 /* SymbolFlags.ReplaceableByMethod */) === 0)
|
|
1434
|
+
addDeclaration(indexSymbol, decl);
|
|
1435
|
+
}
|
|
1436
|
+
function addDeclarationToLateBoundSymbol(c, symbol, member, symbolFlags) {
|
|
1437
|
+
const memberSymbol = getSymbol(member);
|
|
1438
|
+
c.symbolLinks(memberSymbol).lateSymbol = symbol;
|
|
1439
|
+
if (symbol.declarations.length === 0 || (memberSymbol.flags & 536870912 /* SymbolFlags.ReplaceableByMethod */) === 0) {
|
|
1440
|
+
symbol.flags |= symbolFlags;
|
|
1441
|
+
addDeclaration(symbol, member);
|
|
1442
|
+
}
|
|
1443
|
+
if ((symbolFlags & 111551 /* SymbolFlags.Value */) !== 0)
|
|
1444
|
+
setValueDeclaration(symbol, member);
|
|
1445
|
+
}
|
|
1446
|
+
export function isReservedMemberName(name) {
|
|
1447
|
+
if (name.length < 2 || name.charCodeAt(0) !== 0xfffe)
|
|
1448
|
+
return false;
|
|
1449
|
+
const second = name.charCodeAt(1);
|
|
1450
|
+
return second !== 0x40 && second !== 0x23;
|
|
1451
|
+
}
|
|
1452
|
+
/** Whether `symbol` has a value meaning; one reached through a type-only alias doesn't count. */
|
|
1453
|
+
export function symbolIsValue(c, symbol) {
|
|
1454
|
+
return ((symbol.flags & 111551 /* SymbolFlags.Value */) !== 0 ||
|
|
1455
|
+
((symbol.flags & 2097152 /* SymbolFlags.Alias */) !== 0 && (getSymbolFlags(c, symbol, true) & 111551 /* SymbolFlags.Value */) !== 0));
|
|
1456
|
+
}
|
|
1457
|
+
function isDeclarationContainedBy(symbol, container) {
|
|
1458
|
+
const declaration = symbol.valueDeclaration;
|
|
1459
|
+
if (declaration !== undefined)
|
|
1460
|
+
for (const d of container.declarations)
|
|
1461
|
+
if (declaration.pos >= d.pos && declaration.end <= d.end)
|
|
1462
|
+
return true;
|
|
1463
|
+
return false;
|
|
1464
|
+
}
|
|
1465
|
+
/** Value members other than signatures and index signatures, declared ones first, each part ordered by declaration. */
|
|
1466
|
+
export function getNamedMembers(c, members, container) {
|
|
1467
|
+
if (members === undefined || members.size === 0)
|
|
1468
|
+
return [];
|
|
1469
|
+
const isClassOrInterface = container !== undefined && (container.flags & (32 /* SymbolFlags.Class */ | 64 /* SymbolFlags.Interface */)) !== 0;
|
|
1470
|
+
const contained = [];
|
|
1471
|
+
const rest = [];
|
|
1472
|
+
for (const [id, symbol] of members) {
|
|
1473
|
+
if (isReservedMemberName(id) || !symbolIsValue(c, symbol))
|
|
1474
|
+
continue;
|
|
1475
|
+
if (isClassOrInterface && isDeclarationContainedBy(symbol, container))
|
|
1476
|
+
contained.push(symbol);
|
|
1477
|
+
else
|
|
1478
|
+
rest.push(symbol);
|
|
1479
|
+
}
|
|
1480
|
+
sortSymbols(c, contained);
|
|
1481
|
+
sortSymbols(c, rest);
|
|
1482
|
+
return contained.length === 0 ? rest : contained.concat(rest);
|
|
1483
|
+
}
|
|
1484
|
+
/** Sorts symbols by declaration order; members are usually in that order already. */
|
|
1485
|
+
function sortSymbols(c, symbols) {
|
|
1486
|
+
for (let i = 1; i < symbols.length; i++)
|
|
1487
|
+
if (compareSymbols(c, symbols[i - 1], symbols[i]) > 0) {
|
|
1488
|
+
symbols.sort((a, b) => compareSymbols(c, a, b));
|
|
1489
|
+
return;
|
|
1490
|
+
}
|
|
1491
|
+
}
|
|
1492
|
+
// ---- Entity names
|
|
1493
|
+
export function getFirstIdentifier(node) {
|
|
1494
|
+
let current = node;
|
|
1495
|
+
for (;;) {
|
|
1496
|
+
if (current.kind === 167 /* SyntaxKind.QualifiedName */)
|
|
1497
|
+
current = current.left;
|
|
1498
|
+
else if (current.kind === 212 /* SyntaxKind.PropertyAccessExpression */)
|
|
1499
|
+
current = getExpression(current);
|
|
1500
|
+
else
|
|
1501
|
+
return current;
|
|
1502
|
+
}
|
|
1503
|
+
}
|
|
1504
|
+
export function resolveEntityName(c, name, meaning, ignoreErrors, dontResolveAlias, location) {
|
|
1505
|
+
if (nodeIsMissing(name))
|
|
1506
|
+
return undefined;
|
|
1507
|
+
let symbol;
|
|
1508
|
+
if (name.kind === 79 /* SyntaxKind.Identifier */) {
|
|
1509
|
+
const message = ignoreErrors
|
|
1510
|
+
? undefined
|
|
1511
|
+
: meaning === 1920 /* SymbolFlags.Namespace */ || (name.flags & 16 /* NodeFlags.Synthesized */) !== 0
|
|
1512
|
+
? 663 /* Diagnostics.Cannot_find_namespace_0 */
|
|
1513
|
+
: getCannotFindNameDiagnosticForName(c, getFirstIdentifier(name));
|
|
1514
|
+
const resolveLocation = location ?? name;
|
|
1515
|
+
const text = getText(name);
|
|
1516
|
+
if (meaning === 1920 /* SymbolFlags.Namespace */) {
|
|
1517
|
+
const found = resolveName(c, resolveLocation, text, meaning, undefined, true, false);
|
|
1518
|
+
symbol = found !== undefined ? getMergedSymbol(c, found) : undefined;
|
|
1519
|
+
if (symbol === undefined) {
|
|
1520
|
+
// Typedefs exported from CommonJS are stored on the module symbol, the parent of its `export=`. The
|
|
1521
|
+
// lookup also marks an alias of the name as referenced.
|
|
1522
|
+
const alias = resolveName(c, resolveLocation, text, 2097152 /* SymbolFlags.Alias */, undefined, true, false);
|
|
1523
|
+
if (alias !== undefined && getMergedSymbol(c, alias).name === "export=" /* InternalSymbolName.ExportEquals */)
|
|
1524
|
+
symbol = getMergedSymbol(c, alias).parent;
|
|
1525
|
+
}
|
|
1526
|
+
if (symbol === undefined && message !== undefined)
|
|
1527
|
+
resolveName(c, resolveLocation, text, meaning, message, true, false);
|
|
1528
|
+
}
|
|
1529
|
+
else {
|
|
1530
|
+
const found = resolveName(c, resolveLocation, text, meaning, message, true, false);
|
|
1531
|
+
symbol = found !== undefined ? getMergedSymbol(c, found) : undefined;
|
|
1532
|
+
}
|
|
1533
|
+
}
|
|
1534
|
+
else if (name.kind === 167 /* SyntaxKind.QualifiedName */) {
|
|
1535
|
+
const qualified = name;
|
|
1536
|
+
symbol = resolveQualifiedName(c, name, qualified.left, qualified.right, meaning, ignoreErrors, location);
|
|
1537
|
+
}
|
|
1538
|
+
else if (name.kind === 212 /* SyntaxKind.PropertyAccessExpression */) {
|
|
1539
|
+
symbol = resolveQualifiedName(c, name, getExpression(name), getName(name), meaning, ignoreErrors, location);
|
|
1540
|
+
}
|
|
1541
|
+
else
|
|
1542
|
+
return undefined;
|
|
1543
|
+
if (symbol !== undefined && symbol !== c.unknownSymbol) {
|
|
1544
|
+
if ((name.flags & 16 /* NodeFlags.Synthesized */) === 0 &&
|
|
1545
|
+
name.kind !== 212 /* SyntaxKind.PropertyAccessExpression */ &&
|
|
1546
|
+
((symbol.flags & 2097152 /* SymbolFlags.Alias */) !== 0 ||
|
|
1547
|
+
(name.parent !== undefined && name.parent.kind === 278 /* SyntaxKind.ExportAssignment */)))
|
|
1548
|
+
markAliasDeclarationOfNameIfTypeOnly(c, name);
|
|
1549
|
+
// Resolve along the alias chain to the symbol with the meaning.
|
|
1550
|
+
while ((symbol.flags & meaning) === 0 && !dontResolveAlias && (symbol.flags & 2097152 /* SymbolFlags.Alias */) !== 0)
|
|
1551
|
+
symbol = resolveAlias(c, symbol);
|
|
1552
|
+
}
|
|
1553
|
+
return symbol;
|
|
1554
|
+
}
|
|
1555
|
+
function resolveQualifiedName(c, name, left, right, meaning, ignoreErrors, location) {
|
|
1556
|
+
const namespace = resolveEntityName(c, left, 1920 /* SymbolFlags.Namespace */, ignoreErrors, false, location);
|
|
1557
|
+
if (namespace === undefined || nodeIsMissing(right))
|
|
1558
|
+
return undefined;
|
|
1559
|
+
if (namespace === c.unknownSymbol)
|
|
1560
|
+
return namespace;
|
|
1561
|
+
const text = getText(right);
|
|
1562
|
+
let found = getSymbolOfMeaning(c, getExportsOfSymbol(c, namespace), text, meaning);
|
|
1563
|
+
// A namespace merged with a re-export resolves further.
|
|
1564
|
+
if (found === undefined && (namespace.flags & 2097152 /* SymbolFlags.Alias */) !== 0)
|
|
1565
|
+
found = getSymbolOfMeaning(c, getExportsOfSymbol(c, resolveAlias(c, namespace)), text, meaning);
|
|
1566
|
+
if (found !== undefined)
|
|
1567
|
+
return getMergedSymbol(c, found);
|
|
1568
|
+
if (ignoreErrors)
|
|
1569
|
+
return undefined;
|
|
1570
|
+
const namespaceName = getFullyQualifiedName(c, namespace);
|
|
1571
|
+
const declarationName = declarationNameToString(getSourceFileOfNode(right), right);
|
|
1572
|
+
const suggestion = getSpellingSuggestionForName(c, text, Array.from(getExportsOfModule(c, namespace).values()), 2623475 /* SymbolFlags.ModuleMember */);
|
|
1573
|
+
if (suggestion !== undefined) {
|
|
1574
|
+
c.error(right, 856 /* Diagnostics.X_0_has_no_exported_member_named_1_Did_you_mean_2 */, namespaceName, declarationName, symbolToString(c, suggestion));
|
|
1575
|
+
return undefined;
|
|
1576
|
+
}
|
|
1577
|
+
let containingQualifiedName;
|
|
1578
|
+
if (name.kind === 167 /* SyntaxKind.QualifiedName */) {
|
|
1579
|
+
containingQualifiedName = name;
|
|
1580
|
+
while (containingQualifiedName.parent.kind === 167 /* SyntaxKind.QualifiedName */)
|
|
1581
|
+
containingQualifiedName = containingQualifiedName.parent;
|
|
1582
|
+
}
|
|
1583
|
+
if (
|
|
1584
|
+
// Not while the checker is being created, before global types are known.
|
|
1585
|
+
c.hasGlobalObjectType &&
|
|
1586
|
+
(meaning & 788968 /* SymbolFlags.Type */) !== 0 &&
|
|
1587
|
+
containingQualifiedName !== undefined &&
|
|
1588
|
+
containingQualifiedName.parent.kind !== 222 /* SyntaxKind.TypeOfExpression */ &&
|
|
1589
|
+
tryGetQualifiedNameAsValue(c, containingQualifiedName) !== undefined) {
|
|
1590
|
+
c.error(containingQualifiedName, 881 /* Diagnostics.X_0_refers_to_a_value_but_is_being_used_as_a_type_here_Did_you_mean_typeof_0 */, entityNameToString(containingQualifiedName));
|
|
1591
|
+
return undefined;
|
|
1592
|
+
}
|
|
1593
|
+
if ((meaning & 1920 /* SymbolFlags.Namespace */) !== 0 &&
|
|
1594
|
+
name.parent !== undefined &&
|
|
1595
|
+
name.parent.kind === 167 /* SyntaxKind.QualifiedName */) {
|
|
1596
|
+
const exportedType = getSymbolOfMeaning(c, getExportsOfSymbol(c, namespace), text, 788968 /* SymbolFlags.Type */);
|
|
1597
|
+
if (exportedType !== undefined) {
|
|
1598
|
+
const qualified = name.parent;
|
|
1599
|
+
c.error(qualified.right, 845 /* Diagnostics.Cannot_access_0_1_because_0_is_a_type_but_not_a_namespace_Did_you_mean_to_retrieve_the_type_of_the_property_1_in_0_with_0_1 */, symbolToString(c, getMergedSymbol(c, exportedType)), qualified.right.text);
|
|
1600
|
+
return undefined;
|
|
1601
|
+
}
|
|
1602
|
+
}
|
|
1603
|
+
c.error(right, 826 /* Diagnostics.Namespace_0_has_no_exported_member_1 */, namespaceName, declarationName);
|
|
1604
|
+
return undefined;
|
|
1605
|
+
}
|
|
1606
|
+
/** The value a qualified name denotes as a property access, if any. */
|
|
1607
|
+
function tryGetQualifiedNameAsValue(c, node) {
|
|
1608
|
+
const id = getFirstIdentifier(node);
|
|
1609
|
+
let symbol = resolveName(c, id, getText(id), 111551 /* SymbolFlags.Value */, undefined, true, false);
|
|
1610
|
+
if (symbol === undefined)
|
|
1611
|
+
return undefined;
|
|
1612
|
+
let current = id;
|
|
1613
|
+
while (current.parent.kind === 167 /* SyntaxKind.QualifiedName */) {
|
|
1614
|
+
symbol = getPropertyOfType(c, getTypeOfSymbol(c, symbol), current.parent.right.text);
|
|
1615
|
+
if (symbol === undefined)
|
|
1616
|
+
return undefined;
|
|
1617
|
+
current = current.parent;
|
|
1618
|
+
}
|
|
1619
|
+
return symbol;
|
|
1620
|
+
}
|
|
1621
|
+
/**
|
|
1622
|
+
* `symbol` qualified by its parents. The outermost one is written as seen from `containingLocation`
|
|
1623
|
+
* if given, so that a module is named by a specifier the containing file could import it with.
|
|
1624
|
+
*/
|
|
1625
|
+
export function getFullyQualifiedName(c, symbol, containingLocation) {
|
|
1626
|
+
return symbol.parent !== undefined
|
|
1627
|
+
? getFullyQualifiedName(c, symbol.parent, containingLocation) + '.' + symbolToString(c, symbol)
|
|
1628
|
+
: symbolToString(c, symbol, containingLocation, 4 /* NodeBuilderInternalFlags.DoNotIncludeSymbolChain */);
|
|
1629
|
+
}
|
|
1630
|
+
export function getCannotFindNameDiagnosticForName(c, node) {
|
|
1631
|
+
const wildcard = c.compilerOptions.types !== undefined && c.compilerOptions.types.includes('*');
|
|
1632
|
+
switch (getText(node)) {
|
|
1633
|
+
case 'document':
|
|
1634
|
+
case 'console':
|
|
1635
|
+
return 734 /* Diagnostics.Cannot_find_name_0_Do_you_need_to_change_your_target_library_Try_changing_the_lib_compiler_option_to_include_dom */;
|
|
1636
|
+
case '$':
|
|
1637
|
+
return wildcard
|
|
1638
|
+
? 731 /* Diagnostics.Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_jQuery_Try_npm_i_save_dev_types_Slashjquery */
|
|
1639
|
+
: 740 /* Diagnostics.Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_jQuery_Try_npm_i_save_dev_types_Slashjquery_and_then_add_jquery_to_the_types_field_in_your_tsconfig */;
|
|
1640
|
+
case 'beforeEach':
|
|
1641
|
+
case 'describe':
|
|
1642
|
+
case 'suite':
|
|
1643
|
+
case 'it':
|
|
1644
|
+
case 'test':
|
|
1645
|
+
return wildcard
|
|
1646
|
+
? 732 /* Diagnostics.Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_a_test_runner_Try_npm_i_save_dev_types_Slashjest_or_npm_i_save_dev_types_Slashmocha */
|
|
1647
|
+
: 741 /* Diagnostics.Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_a_test_runner_Try_npm_i_save_dev_types_Slashjest_or_npm_i_save_dev_types_Slashmocha_and_then_add_jest_or_mocha_to_the_types_field_in_your_tsconfig */;
|
|
1648
|
+
case 'process':
|
|
1649
|
+
case 'require':
|
|
1650
|
+
case 'Buffer':
|
|
1651
|
+
case 'module':
|
|
1652
|
+
case 'NodeJS':
|
|
1653
|
+
return wildcard
|
|
1654
|
+
? 730 /* Diagnostics.Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_node_Try_npm_i_save_dev_types_Slashnode */
|
|
1655
|
+
: 739 /* Diagnostics.Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_node_Try_npm_i_save_dev_types_Slashnode_and_then_add_node_to_the_types_field_in_your_tsconfig */;
|
|
1656
|
+
case 'Bun':
|
|
1657
|
+
return wildcard
|
|
1658
|
+
? 987 /* Diagnostics.Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_Bun_Try_npm_i_save_dev_types_Slashbun */
|
|
1659
|
+
: 988 /* Diagnostics.Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_Bun_Try_npm_i_save_dev_types_Slashbun_and_then_add_bun_to_the_types_field_in_your_tsconfig */;
|
|
1660
|
+
// tsgo lists `ast.Symbol` here rather than `Symbol`.
|
|
1661
|
+
case 'Map':
|
|
1662
|
+
case 'Set':
|
|
1663
|
+
case 'Promise':
|
|
1664
|
+
case 'WeakMap':
|
|
1665
|
+
case 'WeakSet':
|
|
1666
|
+
case 'Iterator':
|
|
1667
|
+
case 'AsyncIterator':
|
|
1668
|
+
case 'SharedArrayBuffer':
|
|
1669
|
+
case 'Atomics':
|
|
1670
|
+
case 'AsyncIterable':
|
|
1671
|
+
case 'AsyncIterableIterator':
|
|
1672
|
+
case 'AsyncGenerator':
|
|
1673
|
+
case 'AsyncGeneratorFunction':
|
|
1674
|
+
case 'BigInt':
|
|
1675
|
+
case 'Reflect':
|
|
1676
|
+
case 'BigInt64Array':
|
|
1677
|
+
case 'BigUint64Array':
|
|
1678
|
+
return 733 /* Diagnostics.Cannot_find_name_0_Do_you_need_to_change_your_target_library_Try_changing_the_lib_compiler_option_to_1_or_later */;
|
|
1679
|
+
case 'await':
|
|
1680
|
+
if (node.parent !== undefined && node.parent.kind === 214 /* SyntaxKind.CallExpression */)
|
|
1681
|
+
return 489 /* Diagnostics.Cannot_find_name_0_Did_you_mean_to_write_this_in_an_async_function */;
|
|
1682
|
+
break;
|
|
1683
|
+
}
|
|
1684
|
+
if (node.parent !== undefined && node.parent.kind === 304 /* SyntaxKind.ShorthandPropertyAssignment */)
|
|
1685
|
+
return 1828 /* Diagnostics.No_value_exists_in_scope_for_the_shorthand_property_0_Either_declare_one_or_provide_an_initializer */;
|
|
1686
|
+
return 482 /* Diagnostics.Cannot_find_name_0 */;
|
|
1687
|
+
}
|
|
1688
|
+
/**
|
|
1689
|
+
* Pushes a resolution of `propertyName` on `target`. When the same resolution is already on the
|
|
1690
|
+
* stack with no resolved entries above it, marks the cycle and returns false.
|
|
1691
|
+
*/
|
|
1692
|
+
export function pushTypeResolution(c, target, propertyName) {
|
|
1693
|
+
const start = findResolutionCycleStartIndex(c, target, propertyName);
|
|
1694
|
+
if (start >= 0) {
|
|
1695
|
+
c.resolutionCycleCount++;
|
|
1696
|
+
for (let i = start; i < c.resolutionDepth; i++)
|
|
1697
|
+
c.resolutionResults[i] = false;
|
|
1698
|
+
return false;
|
|
1699
|
+
}
|
|
1700
|
+
const depth = c.resolutionDepth;
|
|
1701
|
+
if (depth < c.resolutionTargets.length) {
|
|
1702
|
+
c.resolutionTargets[depth] = target;
|
|
1703
|
+
c.resolutionPropertyNames[depth] = propertyName;
|
|
1704
|
+
c.resolutionResults[depth] = true;
|
|
1705
|
+
}
|
|
1706
|
+
else {
|
|
1707
|
+
c.resolutionTargets.push(target);
|
|
1708
|
+
c.resolutionPropertyNames.push(propertyName);
|
|
1709
|
+
c.resolutionResults.push(true);
|
|
1710
|
+
}
|
|
1711
|
+
c.resolutionDepth = depth + 1;
|
|
1712
|
+
return true;
|
|
1713
|
+
}
|
|
1714
|
+
/** Pops the last resolution; false if it was part of a cycle. */
|
|
1715
|
+
export function popTypeResolution(c) {
|
|
1716
|
+
const depth = c.resolutionDepth - 1;
|
|
1717
|
+
c.resolutionDepth = depth;
|
|
1718
|
+
return c.resolutionResults[depth];
|
|
1719
|
+
}
|
|
1720
|
+
export function findResolutionCycleStartIndex(c, target, propertyName) {
|
|
1721
|
+
for (let i = c.resolutionDepth - 1; i >= c.resolutionStart; i--) {
|
|
1722
|
+
if (resolutionHasProperty(c, c.resolutionTargets[i], c.resolutionPropertyNames[i]))
|
|
1723
|
+
return -1;
|
|
1724
|
+
if (c.resolutionTargets[i] === target && c.resolutionPropertyNames[i] === propertyName)
|
|
1725
|
+
return i;
|
|
1726
|
+
}
|
|
1727
|
+
return -1;
|
|
1728
|
+
}
|
|
1729
|
+
function resolutionHasProperty(c, target, propertyName) {
|
|
1730
|
+
switch (propertyName) {
|
|
1731
|
+
case 0 /* TypeSystemPropertyName.Type */:
|
|
1732
|
+
return c.symbolTypes.get(getSymbolId(target)) !== undefined;
|
|
1733
|
+
case 2 /* TypeSystemPropertyName.DeclaredType */:
|
|
1734
|
+
return c.symbolLinks(target).declaredType !== undefined;
|
|
1735
|
+
case 5 /* TypeSystemPropertyName.ResolvedTypeArguments */:
|
|
1736
|
+
return (typeReferenceOf(target).resolvedTypeArguments !== undefined ||
|
|
1737
|
+
sideOf(c, typeReferenceOf(target)).resolvedTypeArguments !== undefined);
|
|
1738
|
+
case 6 /* TypeSystemPropertyName.ResolvedBaseTypes */:
|
|
1739
|
+
return sideOf(c, interfaceTypeOf(target)).baseTypesResolved;
|
|
1740
|
+
case 1 /* TypeSystemPropertyName.ResolvedBaseConstructorType */:
|
|
1741
|
+
return sideOf(c, interfaceTypeOf(target)).resolvedBaseConstructorType !== undefined;
|
|
1742
|
+
case 3 /* TypeSystemPropertyName.ResolvedReturnType */:
|
|
1743
|
+
return (target.resolvedReturnType !== undefined ||
|
|
1744
|
+
signatureSideOf(c, target).resolvedReturnType !== undefined);
|
|
1745
|
+
case 4 /* TypeSystemPropertyName.ResolvedBaseConstraint */:
|
|
1746
|
+
return (target.resolvedBaseConstraint !== undefined ||
|
|
1747
|
+
sideOf(c, target).resolvedBaseConstraint !== undefined);
|
|
1748
|
+
case 8 /* TypeSystemPropertyName.InitializerIsUndefined */:
|
|
1749
|
+
return ((c.existingNodeLinks(target)?.flags ?? 0) & (1 << 25)) !== 0;
|
|
1750
|
+
case 7 /* TypeSystemPropertyName.WriteType */:
|
|
1751
|
+
return c.symbolLinks(target).writeType !== undefined;
|
|
1752
|
+
case 9 /* TypeSystemPropertyName.AliasTarget */:
|
|
1753
|
+
return c.symbolLinks(target).aliasTarget !== undefined;
|
|
1754
|
+
}
|
|
1755
|
+
return false;
|
|
1756
|
+
}
|
|
1757
|
+
function typeReferenceOf(t) {
|
|
1758
|
+
return t;
|
|
1759
|
+
}
|
|
1760
|
+
function interfaceTypeOf(t) {
|
|
1761
|
+
return t;
|
|
1762
|
+
}
|
|
1763
|
+
export function reportCircularityError(c, symbol) {
|
|
1764
|
+
const declaration = symbol.valueDeclaration;
|
|
1765
|
+
if (declaration !== undefined) {
|
|
1766
|
+
if (getType(declaration) !== undefined) {
|
|
1767
|
+
c.error(declaration, 662 /* Diagnostics.X_0_is_referenced_directly_or_indirectly_in_its_own_type_annotation */, symbolToString(c, symbol));
|
|
1768
|
+
return c.errorType;
|
|
1769
|
+
}
|
|
1770
|
+
if (c.noImplicitAny && (declaration.kind !== 170 /* SyntaxKind.Parameter */ || getInitializer(declaration) !== undefined))
|
|
1771
|
+
c.error(declaration, 1693 /* Diagnostics.X_0_implicitly_has_type_any_because_it_does_not_have_a_type_annotation_and_is_referenced_directly_or_indirectly_in_its_own_initializer */, symbolToString(c, symbol));
|
|
1772
|
+
}
|
|
1773
|
+
else if ((symbol.flags & 2097152 /* SymbolFlags.Alias */) !== 0) {
|
|
1774
|
+
const node = getDeclarationOfAliasSymbol(symbol);
|
|
1775
|
+
if (node !== undefined)
|
|
1776
|
+
c.error(node, 481 /* Diagnostics.Circular_definition_of_import_alias_0 */, symbolToString(c, symbol));
|
|
1777
|
+
}
|
|
1778
|
+
// Circularities could also result from parameters in function expressions that end up having themselves as
|
|
1779
|
+
// contextual types. Those are reported elsewhere.
|
|
1780
|
+
return c.anyType;
|
|
1781
|
+
}
|
|
1782
|
+
export { getTypeOfSymbol, getSourceFileOfNode };
|