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