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,2141 @@
|
|
|
1
|
+
// External modules: resolving module specifiers, alias targets of imports and exports, module
|
|
2
|
+
// exports, import types, dynamic imports, and the semantic checks of import and export declarations.
|
|
3
|
+
//
|
|
4
|
+
// Module-not-found errors are reported on every resolution with an error node, as tsgo does: an
|
|
5
|
+
// unresolved `import { a } from "m"` reports once for the declaration and again for each use of `a`.
|
|
6
|
+
import { checkCollisionsForDeclarationName } from './checker-generated-code.js';
|
|
7
|
+
import { checkDeprecatedImportSpecifier } from './checker-deprecation.js';
|
|
8
|
+
import { getExpression, getInitializer, getIsTypeOnly, getLocals, getModuleSpecifier, getName, getPropertyName, getSymbol, getText, getType, } from './ast.js';
|
|
9
|
+
import { getExternalModuleName, isAmbientModule, isImportCall, isFunctionLike, isGlobalScopeAugmentation, isInJSFile, isLiteralImportTypeNode, isRequireCall, isStringLiteralLike, isTypeOnly, nodeIsMissing, } from './ast-utilities.js';
|
|
10
|
+
import { declarationNameToString, getDeclarationOfKind, getModifierFlags, isAccessExpression, getRootDeclaration, getSourceTextOfNode, getThisContainer, getSourceFileOfNode, hasSyntacticModifier, isGlobalSourceFile, isJsonSourceFile, isModuleAugmentationExternal, isPartOfTypeQuery, isVariableDeclarationInitializedToRequire, moduleExportNameIsDefault, } from './binder-utilities.js';
|
|
11
|
+
import { chainDiagnostic, RepopulateInfo, } from './diagnostics.js';
|
|
12
|
+
import { JsxEmit, ModuleKind, ModuleResolutionKind, getAllowImportingTsExtensions, getEmitModuleKind, getModuleResolutionKind, getResolveJsonModule, } from './options.js';
|
|
13
|
+
import { getResolutionDiagnostic, getTypesPackageName, mangleScopedPackageName, } from './module-resolution-types.js';
|
|
14
|
+
import { getResolutionModeOverride, moduleKindName } from './program-utilities.js';
|
|
15
|
+
import { hasExtension } from './vfs-match.js';
|
|
16
|
+
import { isNodeCoreModule } from './parser.js';
|
|
17
|
+
import { combinePaths, extensionIsTs, fileExtensionIsOneOf, getDeclarationFileExtension, getDirectoryPath, getNormalizedAbsolutePath, isDeclarationFileName, isExternalModuleNameRelative, pathIsRelative, removeExtension, supportedTSExtensionsFlat, tryExtractTSExtension, tryGetExtensionFromPath, } from './path.js';
|
|
18
|
+
import { getSymbolId } from './symbol.js';
|
|
19
|
+
import { isExpressionNode } from './transformers/alias-references.js';
|
|
20
|
+
import { createDiagnosticForNode } from './checker.js';
|
|
21
|
+
import { checkExternalEmitHelpers } from './checker-emit-helpers.js';
|
|
22
|
+
import { createAnonymousType, getRegularTypeOfLiteralType, getStringLiteralType, isErrorType, } from './checker-type-factory.js';
|
|
23
|
+
import { getFullyQualifiedName, getMergedSymbol, getSpellingSuggestionForName, getSymbolFlags, getSymbolOfDeclaration, getSymbolOfMeaning, getDeclarationOfAliasSymbol, getExportSymbolOfValueSymbolIfExported, getExportsOfModule, getExportsOfSymbol, resolveAlias, resolveEntityName, resolveName, resolveSymbol, resolveSymbolEx, isNonLocalAlias, getCachedGlobalType, } from './checker-symbols.js';
|
|
24
|
+
import { getTypeOfSymbol, getNullableType } from './checker-symbol-types.js';
|
|
25
|
+
import { getPropertyOfType, getPropertyOfTypeEx, getSignaturesOfStructuredType, resolveStructuredTypeMembers, } from './checker-members.js';
|
|
26
|
+
import { getTypeFromTypeNode, getTypeReferenceType } from './checker-type-nodes.js';
|
|
27
|
+
import { checkExpression, checkExpressionCached, getResolvedSymbol } from './checker-expressions.js';
|
|
28
|
+
import { isTypeAssignableTo, checkTypeAssignableTo } from './relations.js';
|
|
29
|
+
import { getSpreadType } from './checker-object-literals.js';
|
|
30
|
+
import { checkExternalModuleExports, shouldCheckErasableSyntax } from './checker-declarations.js';
|
|
31
|
+
import { checkTypeNameIsReserved } from './checker-classes.js';
|
|
32
|
+
import { getDeclaredTypeOfSymbol } from './checker-declared-types.js';
|
|
33
|
+
import { isValidSpreadType } from './checker-destructuring.js';
|
|
34
|
+
import { createPromiseType } from './checker-iteration.js';
|
|
35
|
+
import { symbolToString, typeToString } from './type-printer.js';
|
|
36
|
+
import { checkTypeAssignableToAndOptionallyElaborate } from './checker-expressions.js';
|
|
37
|
+
import { grammarErrorOnNode } from './checker-operators.js';
|
|
38
|
+
// ---- Resolution
|
|
39
|
+
/** The module symbol `moduleReference` names, reporting it when it isn't found unless `ignoreErrors`. */
|
|
40
|
+
export function resolveExternalModuleName(c, location, moduleReference, ignoreErrors) {
|
|
41
|
+
return resolveExternalModuleNameWorker(c, location, moduleReference, ignoreErrors ? undefined : getCannotResolveModuleNameError(c, moduleReference), ignoreErrors, false);
|
|
42
|
+
}
|
|
43
|
+
/** Node core modules suggest installing `@types/node`. */
|
|
44
|
+
function getCannotResolveModuleNameError(c, moduleReference) {
|
|
45
|
+
if (moduleReference !== undefined &&
|
|
46
|
+
moduleReference.kind === 10 /* SyntaxKind.StringLiteral */ &&
|
|
47
|
+
isNodeCoreModule(getText(moduleReference))) {
|
|
48
|
+
const types = c.compilerOptions.types;
|
|
49
|
+
return types !== undefined && types.includes('*')
|
|
50
|
+
? 730 /* Diagnostics.Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_node_Try_npm_i_save_dev_types_Slashnode */
|
|
51
|
+
: 739 /* Diagnostics.Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_node_Try_npm_i_save_dev_types_Slashnode_and_then_add_node_to_the_types_field_in_your_tsconfig */;
|
|
52
|
+
}
|
|
53
|
+
return 485 /* Diagnostics.Cannot_find_module_0_or_its_corresponding_type_declarations */;
|
|
54
|
+
}
|
|
55
|
+
export function resolveExternalModuleNameWorker(c, location, moduleReference, moduleNotFoundError, ignoreErrors, isForAugmentation) {
|
|
56
|
+
if (moduleReference === undefined || !isStringLiteralLike(moduleReference))
|
|
57
|
+
return undefined;
|
|
58
|
+
return resolveExternalModule(c, location, getText(moduleReference), moduleNotFoundError, ignoreErrors ? undefined : moduleReference, isForAugmentation);
|
|
59
|
+
}
|
|
60
|
+
export function resolveExternalModule(c, location, moduleReference, moduleNotFoundError, errorNode, isForAugmentation) {
|
|
61
|
+
if (errorNode !== undefined && moduleReference.startsWith('@types/'))
|
|
62
|
+
c.error(errorNode, 1302 /* Diagnostics.Cannot_import_type_declaration_files_Consider_importing_0_instead_of_1 */, moduleReference.substring(7), moduleReference);
|
|
63
|
+
const ambient = tryFindAmbientModule(c, moduleReference, true);
|
|
64
|
+
if (ambient !== undefined)
|
|
65
|
+
return ambient;
|
|
66
|
+
const importingFile = getSourceFileOfNode(location);
|
|
67
|
+
const contextSpecifier = getContextSpecifier(location);
|
|
68
|
+
const mode = contextSpecifier !== undefined && isStringLiteralLike(contextSpecifier)
|
|
69
|
+
? c.host.getModeForUsageLocation(importingFile, contextSpecifier)
|
|
70
|
+
: c.host.getDefaultResolutionModeForFile(importingFile);
|
|
71
|
+
const resolved = c.host.getResolvedModule(importingFile, moduleReference, mode);
|
|
72
|
+
const isResolved = resolved !== undefined && resolved.resolvedFileName !== '';
|
|
73
|
+
const resolutionDiagnostic = errorNode !== undefined && isResolved
|
|
74
|
+
? getResolutionDiagnostic(c.compilerOptions, resolved, importingFile.isDeclarationFile)
|
|
75
|
+
: undefined;
|
|
76
|
+
const file = isResolved &&
|
|
77
|
+
(resolutionDiagnostic === undefined ||
|
|
78
|
+
resolutionDiagnostic === 1307 /* Diagnostics.Module_0_was_resolved_to_1_but_jsx_is_not_set */)
|
|
79
|
+
? c.host.getSourceFileForResolvedModule(resolved.resolvedFileName)
|
|
80
|
+
: undefined;
|
|
81
|
+
if (file !== undefined) {
|
|
82
|
+
if (errorNode !== undefined) {
|
|
83
|
+
// A resolution error is reported even though the file was found.
|
|
84
|
+
if (resolutionDiagnostic !== undefined)
|
|
85
|
+
c.error(errorNode, resolutionDiagnostic, moduleReference, resolved.resolvedFileName);
|
|
86
|
+
checkResolvedModuleExtension(c, location, moduleReference, resolved, importingFile, mode, errorNode);
|
|
87
|
+
}
|
|
88
|
+
if (file.symbol !== undefined) {
|
|
89
|
+
if (errorNode !== undefined) {
|
|
90
|
+
if (resolved.isExternalLibraryImport && !resolutionExtensionIsTSOrJson(resolved.extension))
|
|
91
|
+
errorOnImplicitAnyModule(c, false, errorNode, mode, resolved, moduleReference);
|
|
92
|
+
checkSyncImportOfESModule(c, location, moduleReference, importingFile, file, errorNode);
|
|
93
|
+
}
|
|
94
|
+
return getMergedSymbol(c, file.symbol);
|
|
95
|
+
}
|
|
96
|
+
if (errorNode !== undefined && moduleNotFoundError !== undefined && !isSideEffectImport(errorNode))
|
|
97
|
+
c.error(errorNode, 484 /* Diagnostics.File_0_is_not_a_module */, resolved.resolvedFileName);
|
|
98
|
+
return undefined;
|
|
99
|
+
}
|
|
100
|
+
// The pattern with the longest prefix wins.
|
|
101
|
+
let best;
|
|
102
|
+
let bestPrefix = -1;
|
|
103
|
+
for (const pattern of c.patternAmbientModules) {
|
|
104
|
+
if (pattern.matches(moduleReference) && pattern.starIndex > bestPrefix) {
|
|
105
|
+
bestPrefix = pattern.starIndex;
|
|
106
|
+
best = pattern.symbol;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
if (best !== undefined)
|
|
110
|
+
return getMergedSymbol(c, c.patternAmbientModuleAugmentations.get(moduleReference) ?? best);
|
|
111
|
+
if (errorNode === undefined)
|
|
112
|
+
return undefined;
|
|
113
|
+
// A module that resolved to JavaScript is untyped.
|
|
114
|
+
if ((isResolved && !resolutionExtensionIsTSOrJson(resolved.extension) && resolutionDiagnostic === undefined) ||
|
|
115
|
+
resolutionDiagnostic === 1688 /* Diagnostics.Could_not_find_a_declaration_file_for_module_0_1_implicitly_has_an_any_type */) {
|
|
116
|
+
if (isForAugmentation)
|
|
117
|
+
c.error(errorNode, 799 /* Diagnostics.Invalid_module_name_in_augmentation_Module_0_resolves_to_an_untyped_module_at_1_which_cannot_be_augmented */, moduleReference, resolved.resolvedFileName);
|
|
118
|
+
else
|
|
119
|
+
errorOnImplicitAnyModule(c, c.noImplicitAny && moduleNotFoundError !== undefined, errorNode, mode, resolved, moduleReference);
|
|
120
|
+
return undefined;
|
|
121
|
+
}
|
|
122
|
+
if (moduleNotFoundError === undefined)
|
|
123
|
+
return undefined;
|
|
124
|
+
if (isResolved) {
|
|
125
|
+
// A source file of a referenced project whose output hasn't been built.
|
|
126
|
+
const outputDts = c.host.getProjectReferenceOutputDts(resolved.resolvedFileName);
|
|
127
|
+
if (outputDts !== '') {
|
|
128
|
+
c.error(errorNode, 1444 /* Diagnostics.Output_file_0_has_not_been_built_from_source_file_1 */, outputDts, resolved.resolvedFileName);
|
|
129
|
+
return undefined;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
if (resolutionDiagnostic !== undefined) {
|
|
133
|
+
c.error(errorNode, resolutionDiagnostic, moduleReference, resolved.resolvedFileName);
|
|
134
|
+
return undefined;
|
|
135
|
+
}
|
|
136
|
+
const resolution = getModuleResolutionKind(c.compilerOptions);
|
|
137
|
+
if (!getResolveJsonModule(c.compilerOptions) && moduleReference.endsWith('.json'))
|
|
138
|
+
c.error(errorNode, 864 /* Diagnostics.Cannot_find_module_0_Consider_using_resolveJsonModule_to_import_module_with_json_extension */, moduleReference);
|
|
139
|
+
else if (mode === ModuleKind.ESNext &&
|
|
140
|
+
(resolution === ModuleResolutionKind.Node16 || resolution === ModuleResolutionKind.NodeNext) &&
|
|
141
|
+
pathIsRelative(moduleReference) &&
|
|
142
|
+
!hasExtension(moduleReference)) {
|
|
143
|
+
const absolute = getNormalizedAbsolutePath(moduleReference, getDirectoryPath(importingFile.fileName));
|
|
144
|
+
const extension = getSuggestedImportExtension(c, absolute);
|
|
145
|
+
if (extension !== '')
|
|
146
|
+
c.error(errorNode, 957 /* Diagnostics.Relative_import_paths_need_explicit_file_extensions_in_ECMAScript_imports_when_moduleResolution_is_node16_or_nodenext_Did_you_mean_0 */, moduleReference + extension);
|
|
147
|
+
else
|
|
148
|
+
c.error(errorNode, 956 /* Diagnostics.Relative_import_paths_need_explicit_file_extensions_in_ECMAScript_imports_when_moduleResolution_is_node16_or_nodenext_Consider_adding_an_extension_to_the_import_path */);
|
|
149
|
+
}
|
|
150
|
+
else if (resolved !== undefined && resolved.alternateResult !== '')
|
|
151
|
+
c.addDiagnostic(chainDiagnostic(createModuleNotFoundChain(c, errorNode, moduleReference, mode, moduleReference), moduleNotFoundError, moduleReference));
|
|
152
|
+
else
|
|
153
|
+
c.error(errorNode, moduleNotFoundError, moduleReference);
|
|
154
|
+
return undefined;
|
|
155
|
+
}
|
|
156
|
+
/** The module specifier that decides the resolution mode of a module reference at `location`. */
|
|
157
|
+
function getContextSpecifier(location) {
|
|
158
|
+
const parent = location.parent;
|
|
159
|
+
if (isStringLiteralLike(location) ||
|
|
160
|
+
(parent !== undefined && parent.kind === 268 /* SyntaxKind.ModuleDeclaration */ && getName(parent) === location))
|
|
161
|
+
return location;
|
|
162
|
+
if (location.kind === 268 /* SyntaxKind.ModuleDeclaration */)
|
|
163
|
+
return getName(location);
|
|
164
|
+
if (isLiteralImportTypeNode(location))
|
|
165
|
+
return location.argument.literal;
|
|
166
|
+
const requireSpecifier = getModuleSpecifierOfBareOrAccessedRequire(location);
|
|
167
|
+
if (requireSpecifier !== undefined)
|
|
168
|
+
return requireSpecifier;
|
|
169
|
+
for (let current = location; current !== undefined; current = current.parent)
|
|
170
|
+
if (isImportCall(current))
|
|
171
|
+
return current.arguments.nodes[0];
|
|
172
|
+
for (let current = location; current !== undefined; current = current.parent)
|
|
173
|
+
if (current.kind === 273 /* SyntaxKind.ImportDeclaration */ || current.kind === 346 /* SyntaxKind.JSImportDeclaration */)
|
|
174
|
+
return getModuleSpecifier(current);
|
|
175
|
+
for (let current = location; current !== undefined; current = current.parent)
|
|
176
|
+
if (current.kind === 279 /* SyntaxKind.ExportDeclaration */)
|
|
177
|
+
return getModuleSpecifier(current);
|
|
178
|
+
for (let current = location; current !== undefined; current = current.parent)
|
|
179
|
+
if (current.kind === 272 /* SyntaxKind.ImportEqualsDeclaration */) {
|
|
180
|
+
const reference = current.moduleReference;
|
|
181
|
+
return reference.kind === 284 /* SyntaxKind.ExternalModuleReference */ ? getExpression(reference) : undefined;
|
|
182
|
+
}
|
|
183
|
+
return undefined;
|
|
184
|
+
}
|
|
185
|
+
/** The specifier of `const x = require("m")` or `const x = require("m").a.b` in JavaScript. */
|
|
186
|
+
function getModuleSpecifierOfBareOrAccessedRequire(node) {
|
|
187
|
+
if (node.kind !== 261 /* SyntaxKind.VariableDeclaration */ || !isInJSFile(node))
|
|
188
|
+
return undefined;
|
|
189
|
+
const declaration = node;
|
|
190
|
+
let initializer = declaration.initializer;
|
|
191
|
+
if (initializer === undefined || declaration.type !== undefined)
|
|
192
|
+
return undefined;
|
|
193
|
+
if ((getModifierFlags(declaration.parent.parent) & 32 /* ModifierFlags.Export */) !== 0)
|
|
194
|
+
return undefined;
|
|
195
|
+
while (isAccessExpression(initializer))
|
|
196
|
+
initializer = getExpression(initializer);
|
|
197
|
+
return isRequireCall(initializer, true) ? initializer.arguments.nodes[0] : undefined;
|
|
198
|
+
}
|
|
199
|
+
function resolutionExtensionIsTSOrJson(extension) {
|
|
200
|
+
return extensionIsTs(extension) || extension === '.json';
|
|
201
|
+
}
|
|
202
|
+
/** Imports that name a `.ts` file need `allowImportingTsExtensions`, and declaration files can't be imported. */
|
|
203
|
+
function checkResolvedModuleExtension(c, location, moduleReference, resolved, importingFile, mode, errorNode) {
|
|
204
|
+
if (!resolved.resolvedUsingTsExtension)
|
|
205
|
+
return;
|
|
206
|
+
if (isDeclarationFileName(moduleReference)) {
|
|
207
|
+
if (isInEmittableImport(location))
|
|
208
|
+
c.error(errorNode, 967 /* Diagnostics.A_declaration_file_cannot_be_imported_without_import_type_Did_you_mean_to_import_an_implementation_file_0_instead */, getSuggestedImportSource(c, moduleReference, tryExtractTSExtension(moduleReference), mode));
|
|
209
|
+
}
|
|
210
|
+
else if (!getAllowImportingTsExtensions(c.compilerOptions) &&
|
|
211
|
+
!isDeclarationFileName(importingFile.fileName) &&
|
|
212
|
+
isInEmittableImport(location)) {
|
|
213
|
+
let extension = tryExtractTSExtension(moduleReference);
|
|
214
|
+
// A wildcard pattern can match a `.ts` extension that doesn't end the specifier.
|
|
215
|
+
if (extension === '')
|
|
216
|
+
for (const candidate of supportedTSExtensionsFlat)
|
|
217
|
+
if (moduleReference.includes(candidate)) {
|
|
218
|
+
extension = candidate;
|
|
219
|
+
break;
|
|
220
|
+
}
|
|
221
|
+
c.error(errorNode, 1171 /* Diagnostics.An_import_path_can_only_end_with_a_0_extension_when_allowImportingTsExtensions_is_enabled */, extension);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
function isInEmittableImport(location) {
|
|
225
|
+
for (let current = location; current !== undefined; current = current.parent) {
|
|
226
|
+
switch (current.kind) {
|
|
227
|
+
case 273 /* SyntaxKind.ImportDeclaration */: {
|
|
228
|
+
const clause = current.importClause;
|
|
229
|
+
if (clause !== undefined && !isTypeOnly(clause))
|
|
230
|
+
return true;
|
|
231
|
+
break;
|
|
232
|
+
}
|
|
233
|
+
case 279 /* SyntaxKind.ExportDeclaration */:
|
|
234
|
+
case 272 /* SyntaxKind.ImportEqualsDeclaration */:
|
|
235
|
+
if (!getIsTypeOnly(current))
|
|
236
|
+
return true;
|
|
237
|
+
break;
|
|
238
|
+
case 214 /* SyntaxKind.CallExpression */:
|
|
239
|
+
if (isImportCall(current))
|
|
240
|
+
return true;
|
|
241
|
+
break;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
return false;
|
|
245
|
+
}
|
|
246
|
+
/** The specifier to import instead of a declaration file: its `.js` counterpart when emitting ES modules. */
|
|
247
|
+
function getSuggestedImportSource(c, moduleReference, tsExtension, mode) {
|
|
248
|
+
const withoutExtension = removeExtension(moduleReference, tsExtension);
|
|
249
|
+
const moduleKind = getEmitModuleKind(c.compilerOptions);
|
|
250
|
+
if ((ModuleKind.ES2015 <= moduleKind && moduleKind <= ModuleKind.ESNext) || mode === ModuleKind.ESNext) {
|
|
251
|
+
const preferTs = isDeclarationFileName(moduleReference) && getAllowImportingTsExtensions(c.compilerOptions);
|
|
252
|
+
if (tsExtension === '.mts' || tsExtension === '.d.mts')
|
|
253
|
+
return withoutExtension + (preferTs ? '.mts' : '.mjs');
|
|
254
|
+
if (tsExtension === '.cts' || tsExtension === '.d.cts')
|
|
255
|
+
return withoutExtension + (preferTs ? '.cts' : '.cjs');
|
|
256
|
+
return withoutExtension + (preferTs ? '.ts' : '.js');
|
|
257
|
+
}
|
|
258
|
+
return withoutExtension;
|
|
259
|
+
}
|
|
260
|
+
function getSuggestedImportExtension(c, extensionlessPath) {
|
|
261
|
+
const host = c.host;
|
|
262
|
+
if (host.fileExists(extensionlessPath + '.mts'))
|
|
263
|
+
return '.mjs';
|
|
264
|
+
if (host.fileExists(extensionlessPath + '.ts'))
|
|
265
|
+
return '.js';
|
|
266
|
+
if (host.fileExists(extensionlessPath + '.cts'))
|
|
267
|
+
return '.cjs';
|
|
268
|
+
if (host.fileExists(extensionlessPath + '.mjs'))
|
|
269
|
+
return '.mjs';
|
|
270
|
+
if (host.fileExists(extensionlessPath + '.js'))
|
|
271
|
+
return '.js';
|
|
272
|
+
if (host.fileExists(extensionlessPath + '.cjs'))
|
|
273
|
+
return '.cjs';
|
|
274
|
+
if (host.fileExists(extensionlessPath + '.tsx'))
|
|
275
|
+
return c.compilerOptions.jsx === JsxEmit.Preserve ? '.jsx' : '.js';
|
|
276
|
+
if (host.fileExists(extensionlessPath + '.jsx'))
|
|
277
|
+
return '.jsx';
|
|
278
|
+
if (host.fileExists(extensionlessPath + '.json'))
|
|
279
|
+
return '.json';
|
|
280
|
+
return '';
|
|
281
|
+
}
|
|
282
|
+
/** Under node16 and node18, a synchronous import of an ES module from a CommonJS file fails at run time. */
|
|
283
|
+
function checkSyncImportOfESModule(c, location, moduleReference, importingFile, file, errorNode) {
|
|
284
|
+
const moduleKind = getEmitModuleKind(c.compilerOptions);
|
|
285
|
+
if (moduleKind !== ModuleKind.Node16 && moduleKind !== ModuleKind.Node18)
|
|
286
|
+
return;
|
|
287
|
+
const importEquals = findAncestorOfKind(location, 272 /* SyntaxKind.ImportEqualsDeclaration */);
|
|
288
|
+
const isSyncImport = (c.host.getDefaultResolutionModeForFile(importingFile) === ModuleKind.CommonJS && !isInImportCall(location)) ||
|
|
289
|
+
importEquals !== undefined;
|
|
290
|
+
if (!isSyncImport || c.host.getDefaultResolutionModeForFile(file) !== ModuleKind.ESNext)
|
|
291
|
+
return;
|
|
292
|
+
const overrideHost = findResolutionModeOverrideHost(location);
|
|
293
|
+
if (overrideHost !== undefined && hasResolutionModeOverride(overrideHost))
|
|
294
|
+
return;
|
|
295
|
+
if (importEquals !== undefined) {
|
|
296
|
+
c.error(errorNode, 386 /* Diagnostics.Module_0_cannot_be_imported_using_this_construct_The_specifier_only_resolves_to_an_ES_module_which_cannot_be_imported_with_require_Use_an_ECMAScript_import_instead */, moduleReference);
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
299
|
+
let details;
|
|
300
|
+
const extension = tryGetExtensionFromPath(importingFile.fileName);
|
|
301
|
+
if (extension === '.ts' || extension === '.js' || extension === '.tsx' || extension === '.jsx') {
|
|
302
|
+
details = detailsAt(errorNode, modeMismatchDetails(c.host, importingFile));
|
|
303
|
+
details.repopulateInfo = new RepopulateInfo(1 /* RepopulateKind.ModeMismatch */);
|
|
304
|
+
}
|
|
305
|
+
let message = 394 /* Diagnostics.The_current_file_is_a_CommonJS_module_whose_imports_will_produce_require_calls_however_the_referenced_file_is_an_ECMAScript_module_and_cannot_be_imported_with_require_Consider_writing_a_dynamic_import_0_call_instead */;
|
|
306
|
+
if (overrideHost !== undefined && overrideHost.kind === 273 /* SyntaxKind.ImportDeclaration */) {
|
|
307
|
+
const clause = overrideHost.importClause;
|
|
308
|
+
if (clause !== undefined && isTypeOnly(clause))
|
|
309
|
+
message =
|
|
310
|
+
456 /* Diagnostics.Type_only_import_of_an_ECMAScript_module_from_a_CommonJS_module_must_have_a_resolution_mode_attribute */;
|
|
311
|
+
}
|
|
312
|
+
else if (overrideHost !== undefined && overrideHost.kind === 206 /* SyntaxKind.ImportType */)
|
|
313
|
+
message =
|
|
314
|
+
457 /* Diagnostics.Type_import_of_an_ECMAScript_module_from_a_CommonJS_module_must_have_a_resolution_mode_attribute */;
|
|
315
|
+
c.addDiagnostic(details !== undefined
|
|
316
|
+
? chainDiagnostic(details, message, moduleReference)
|
|
317
|
+
: createDiagnosticForNode(errorNode, message, [moduleReference]));
|
|
318
|
+
}
|
|
319
|
+
function findAncestorOfKind(node, kind) {
|
|
320
|
+
for (let current = node; current !== undefined; current = current.parent)
|
|
321
|
+
if (current.kind === kind)
|
|
322
|
+
return current;
|
|
323
|
+
return undefined;
|
|
324
|
+
}
|
|
325
|
+
function isInImportCall(node) {
|
|
326
|
+
for (let current = node; current !== undefined; current = current.parent)
|
|
327
|
+
if (isImportCall(current))
|
|
328
|
+
return true;
|
|
329
|
+
return false;
|
|
330
|
+
}
|
|
331
|
+
function findResolutionModeOverrideHost(node) {
|
|
332
|
+
for (let current = node; current !== undefined; current = current.parent)
|
|
333
|
+
switch (current.kind) {
|
|
334
|
+
case 206 /* SyntaxKind.ImportType */:
|
|
335
|
+
case 279 /* SyntaxKind.ExportDeclaration */:
|
|
336
|
+
case 273 /* SyntaxKind.ImportDeclaration */:
|
|
337
|
+
case 346 /* SyntaxKind.JSImportDeclaration */:
|
|
338
|
+
return current;
|
|
339
|
+
}
|
|
340
|
+
return undefined;
|
|
341
|
+
}
|
|
342
|
+
function hasResolutionModeOverride(node) {
|
|
343
|
+
let attributes;
|
|
344
|
+
if (node.kind === 206 /* SyntaxKind.ImportType */)
|
|
345
|
+
attributes = node.attributes;
|
|
346
|
+
else if (node.kind === 279 /* SyntaxKind.ExportDeclaration */)
|
|
347
|
+
attributes = node.attributes;
|
|
348
|
+
else
|
|
349
|
+
attributes = node.attributes;
|
|
350
|
+
return attributes !== undefined && getResolutionModeOverride(attributes) !== ModuleKind.None;
|
|
351
|
+
}
|
|
352
|
+
/** A message with its arguments, the elaboration of a diagnostic before it has a location. */
|
|
353
|
+
export class DiagnosticDetails {
|
|
354
|
+
message;
|
|
355
|
+
args;
|
|
356
|
+
constructor(message, args) {
|
|
357
|
+
this.message = message;
|
|
358
|
+
this.args = args;
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
function detailsAt(node, details) {
|
|
362
|
+
return createDiagnosticForNode(node, details.message, details.args);
|
|
363
|
+
}
|
|
364
|
+
/**
|
|
365
|
+
* How to make the CommonJS file `file` an ES module, elaborating an error about importing one from
|
|
366
|
+
* it; also what an incremental build recomputes for a stored diagnostic (`RepopulateKind.ModeMismatch`).
|
|
367
|
+
*/
|
|
368
|
+
export function modeMismatchDetails(host, file) {
|
|
369
|
+
const extension = tryGetExtensionFromPath(file.fileName);
|
|
370
|
+
const targetExtension = extension === '.ts' ? '.mts' : extension === '.js' ? '.mjs' : '';
|
|
371
|
+
const metadata = host.getSourceFileMetadata(file);
|
|
372
|
+
const packageJsonDirectory = metadata !== undefined ? metadata.packageJsonDirectory : '';
|
|
373
|
+
if (packageJsonDirectory !== '' && metadata.packageJsonType === '') {
|
|
374
|
+
const packageJson = combinePaths(packageJsonDirectory, 'package.json');
|
|
375
|
+
return targetExtension !== ''
|
|
376
|
+
? new DiagnosticDetails(396 /* Diagnostics.To_convert_this_file_to_an_ECMAScript_module_change_its_file_extension_to_0_or_add_the_field_type_Colon_module_to_1 */, [targetExtension, packageJson])
|
|
377
|
+
: new DiagnosticDetails(397 /* Diagnostics.To_convert_this_file_to_an_ECMAScript_module_add_the_field_type_Colon_module_to_0 */, [packageJson]);
|
|
378
|
+
}
|
|
379
|
+
return targetExtension !== ''
|
|
380
|
+
? new DiagnosticDetails(395 /* Diagnostics.To_convert_this_file_to_an_ECMAScript_module_change_its_file_extension_to_0_or_create_a_local_package_json_file_with_type_Colon_module */, [targetExtension])
|
|
381
|
+
: new DiagnosticDetails(398 /* Diagnostics.To_convert_this_file_to_an_ECMAScript_module_create_a_local_package_json_file_with_type_Colon_module */, []);
|
|
382
|
+
}
|
|
383
|
+
/** Reports a module without types: an error under `noImplicitAny`, otherwise a suggestion. */
|
|
384
|
+
function errorOnImplicitAnyModule(c, isError, errorNode, mode, resolved, moduleReference) {
|
|
385
|
+
if (isSideEffectImport(errorNode))
|
|
386
|
+
return;
|
|
387
|
+
const packageName = resolved.packageId !== undefined ? resolved.packageId.name : '';
|
|
388
|
+
const chain = !isExternalModuleNameRelative(moduleReference) && packageName !== ''
|
|
389
|
+
? createModuleNotFoundChain(c, errorNode, moduleReference, mode, packageName)
|
|
390
|
+
: undefined;
|
|
391
|
+
const message = 1688 /* Diagnostics.Could_not_find_a_declaration_file_for_module_0_1_implicitly_has_an_any_type */;
|
|
392
|
+
c.addErrorOrSuggestion(isError, chain !== undefined
|
|
393
|
+
? chainDiagnostic(chain, message, moduleReference, resolved.resolvedFileName)
|
|
394
|
+
: createDiagnosticForNode(errorNode, message, [moduleReference, resolved.resolvedFileName]));
|
|
395
|
+
}
|
|
396
|
+
/** Where types for a module might come from, elaborating an error about a module without them. */
|
|
397
|
+
function createModuleNotFoundChain(c, errorNode, moduleReference, mode, packageName) {
|
|
398
|
+
const file = getSourceFileOfNode(errorNode);
|
|
399
|
+
const result = detailsAt(errorNode, moduleNotFoundDetails(c.host, file, moduleReference, mode, packageName));
|
|
400
|
+
result.repopulateInfo = new RepopulateInfo(2 /* RepopulateKind.ModuleNotFound */, moduleReference, mode, packageName === moduleReference ? '' : packageName);
|
|
401
|
+
return result;
|
|
402
|
+
}
|
|
403
|
+
/**
|
|
404
|
+
* Where types for `moduleReference`, imported by `file`, might come from; also what an incremental
|
|
405
|
+
* build recomputes for a stored diagnostic (`RepopulateKind.ModuleNotFound`).
|
|
406
|
+
*/
|
|
407
|
+
export function moduleNotFoundDetails(host, file, moduleReference, mode, packageNameIn) {
|
|
408
|
+
let packageName = packageNameIn;
|
|
409
|
+
const resolved = host.getResolvedModule(file, moduleReference, mode);
|
|
410
|
+
if (resolved !== undefined && resolved.alternateResult !== '') {
|
|
411
|
+
if (resolved.alternateResult.includes('/node_modules/@types/'))
|
|
412
|
+
packageName = '@types/' + mangleScopedPackageName(packageName);
|
|
413
|
+
return new DiagnosticDetails(1427 /* Diagnostics.There_are_types_at_0_but_this_result_could_not_be_resolved_when_respecting_package_json_exports_The_1_library_may_need_to_update_its_package_json_or_typings */, [resolved.alternateResult, packageName]);
|
|
414
|
+
}
|
|
415
|
+
const packages = host.getPackagesMap();
|
|
416
|
+
if (packages.has(getTypesPackageName(packageName)))
|
|
417
|
+
return new DiagnosticDetails(1711 /* Diagnostics.If_the_0_package_actually_exposes_this_module_consider_sending_a_pull_request_to_amend_https_Colon_Slash_Slashgithub_com_SlashDefinitelyTyped_SlashDefinitelyTyped_Slashtree_Slashmaster_Slashtypes_Slash_1 */, [packageName, mangleScopedPackageName(packageName)]);
|
|
418
|
+
if (packages.get(packageName) === true)
|
|
419
|
+
return new DiagnosticDetails(1729 /* Diagnostics.If_the_0_package_actually_exposes_this_module_try_adding_a_new_declaration_d_ts_file_containing_declare_module_1 */, [packageName, moduleReference]);
|
|
420
|
+
return new DiagnosticDetails(1706 /* Diagnostics.Try_npm_i_save_dev_types_Slash_1_if_it_exists_or_add_a_new_declaration_d_ts_file_containing_declare_module_0 */, [moduleReference, mangleScopedPackageName(packageName)]);
|
|
421
|
+
}
|
|
422
|
+
function isSideEffectImport(node) {
|
|
423
|
+
let current = node;
|
|
424
|
+
while (current !== undefined && current.kind !== 273 /* SyntaxKind.ImportDeclaration */)
|
|
425
|
+
current = current.parent;
|
|
426
|
+
return current !== undefined && current.importClause === undefined;
|
|
427
|
+
}
|
|
428
|
+
export function tryFindAmbientModule(c, moduleName, withAugmentations) {
|
|
429
|
+
if (isExternalModuleNameRelative(moduleName))
|
|
430
|
+
return undefined;
|
|
431
|
+
const symbol = getSymbolOfMeaning(c, c.globals, '"' + moduleName + '"', 512 /* SymbolFlags.ValueModule */);
|
|
432
|
+
return symbol !== undefined && withAugmentations ? getMergedSymbol(c, symbol) : symbol;
|
|
433
|
+
}
|
|
434
|
+
/** The `export =` target of a module, or the module itself. */
|
|
435
|
+
export function resolveExternalModuleSymbol(c, moduleSymbol, dontResolveAlias) {
|
|
436
|
+
if (moduleSymbol === undefined)
|
|
437
|
+
return undefined;
|
|
438
|
+
const exportEquals = moduleSymbol.exports?.get("export=" /* InternalSymbolName.ExportEquals */);
|
|
439
|
+
if (exportEquals === undefined)
|
|
440
|
+
return moduleSymbol;
|
|
441
|
+
return getMergedSymbol(c, resolveSymbolEx(c, exportEquals, dontResolveAlias));
|
|
442
|
+
}
|
|
443
|
+
/** The module as a namespace: removes call and construct signatures, or wraps it with a synthetic default. */
|
|
444
|
+
export function resolveESModuleSymbol(c, moduleSymbol, node, moduleSpecifier) {
|
|
445
|
+
let symbol = resolveExternalModuleSymbol(c, moduleSymbol, true);
|
|
446
|
+
if (symbol !== undefined && isNonLocalAlias(symbol, 111551 /* SymbolFlags.Value */ | 788968 /* SymbolFlags.Type */ | 1920 /* SymbolFlags.Namespace */)) {
|
|
447
|
+
const source = getSymbolOfDeclaration(c, node);
|
|
448
|
+
symbol = getMergedSymbol(c, source !== undefined ? resolveIndirectionAlias(c, source, symbol) : resolveAlias(c, symbol));
|
|
449
|
+
}
|
|
450
|
+
if (symbol === undefined || moduleSymbol === undefined)
|
|
451
|
+
return symbol;
|
|
452
|
+
const referenceParent = moduleSpecifier.parent;
|
|
453
|
+
const namespaceImport = referenceParent.kind === 273 /* SyntaxKind.ImportDeclaration */ ? getNamespaceImport(referenceParent) : undefined;
|
|
454
|
+
if (namespaceImport === undefined && !isImportCall(referenceParent))
|
|
455
|
+
return symbol;
|
|
456
|
+
const reference = isImportCall(referenceParent)
|
|
457
|
+
? referenceParent.arguments.nodes[0]
|
|
458
|
+
: getModuleSpecifier(referenceParent);
|
|
459
|
+
const type = getTypeOfSymbol(c, symbol);
|
|
460
|
+
const defaultOnlyType = getTypeWithSyntheticDefaultOnly(c, type, symbol, moduleSymbol, reference);
|
|
461
|
+
if (defaultOnlyType !== undefined)
|
|
462
|
+
return cloneTypeAsModuleType(c, symbol, defaultOnlyType);
|
|
463
|
+
if (hasSignatures(c, type) || getPropertyOfTypeEx(c, type, "default" /* InternalSymbolName.Default */, true, false) !== undefined) {
|
|
464
|
+
const moduleType = (type.flags & 403701760 /* TypeFlags.StructuredType */) !== 0
|
|
465
|
+
? getTypeWithSyntheticDefaultImportType(c, type, symbol, moduleSymbol, reference)
|
|
466
|
+
: createDefaultPropertyWrapperForModule(c, symbol, symbol.parent, undefined);
|
|
467
|
+
return cloneTypeAsModuleType(c, symbol, moduleType);
|
|
468
|
+
}
|
|
469
|
+
return symbol;
|
|
470
|
+
}
|
|
471
|
+
function getNamespaceImport(declaration) {
|
|
472
|
+
const clause = declaration.importClause;
|
|
473
|
+
const bindings = clause?.namedBindings;
|
|
474
|
+
return bindings !== undefined && bindings.kind === 275 /* SyntaxKind.NamespaceImport */ ? bindings : undefined;
|
|
475
|
+
}
|
|
476
|
+
function hasSignatures(c, type) {
|
|
477
|
+
return (getSignaturesOfStructuredType(c, type, 0 /* SignatureKind.Call */).length > 0 ||
|
|
478
|
+
getSignaturesOfStructuredType(c, type, 1 /* SignatureKind.Construct */).length > 0);
|
|
479
|
+
}
|
|
480
|
+
/**
|
|
481
|
+
* Whether the module `usage` names is a JSON module imported into an ES module under `--module node16` to
|
|
482
|
+
* `nodenext`, which Node.js gives only a default export.
|
|
483
|
+
*/
|
|
484
|
+
function isOnlyImportableAsDefault(c, usage, resolvedModule) {
|
|
485
|
+
const moduleKind = getEmitModuleKind(c.compilerOptions);
|
|
486
|
+
if (moduleKind < ModuleKind.Node16 || moduleKind > ModuleKind.NodeNext)
|
|
487
|
+
return false;
|
|
488
|
+
if (getEmitSyntaxForModuleSpecifierExpression(c, usage) !== ModuleKind.ESNext)
|
|
489
|
+
return false;
|
|
490
|
+
const moduleSymbol = resolvedModule ?? resolveExternalModuleName(c, usage, usage, true);
|
|
491
|
+
const targetFile = moduleSymbol !== undefined ? getSourceFileOfModuleSymbol(moduleSymbol) : undefined;
|
|
492
|
+
return (targetFile !== undefined &&
|
|
493
|
+
(isJsonSourceFile(targetFile) || getDeclarationFileExtension(targetFile.fileName) === '.d.json.ts'));
|
|
494
|
+
}
|
|
495
|
+
/** The source file that declares a module: its value declaration, or its first declaration that is not an augmentation. */
|
|
496
|
+
function getSourceFileOfModuleSymbol(symbol) {
|
|
497
|
+
let declaration = symbol.valueDeclaration;
|
|
498
|
+
if (declaration === undefined)
|
|
499
|
+
for (const d of symbol.declarations)
|
|
500
|
+
if (!(isAmbientModule(d) && isModuleAugmentationExternal(d)) && !isGlobalScopeAugmentation(d)) {
|
|
501
|
+
declaration = d;
|
|
502
|
+
break;
|
|
503
|
+
}
|
|
504
|
+
return declaration !== undefined ? getSourceFileOfNode(declaration) : undefined;
|
|
505
|
+
}
|
|
506
|
+
/** For a module only importable as default, the type of its namespace: an object with only `default`. */
|
|
507
|
+
function getTypeWithSyntheticDefaultOnly(c, type, symbol, originalSymbol, moduleSpecifier) {
|
|
508
|
+
if (!isOnlyImportableAsDefault(c, moduleSpecifier, undefined) || isErrorType(c, type))
|
|
509
|
+
return undefined;
|
|
510
|
+
const key = 'defaultOnly:' + type.id;
|
|
511
|
+
const cached = c.moduleTypeCache.get(key);
|
|
512
|
+
if (cached !== undefined)
|
|
513
|
+
return cached;
|
|
514
|
+
const result = createDefaultPropertyWrapperForModule(c, symbol, originalSymbol, undefined);
|
|
515
|
+
c.moduleTypeCache.set(key, result);
|
|
516
|
+
return result;
|
|
517
|
+
}
|
|
518
|
+
/** `type` with a `default` member for the module, when the module may not have a real one. */
|
|
519
|
+
function getTypeWithSyntheticDefaultImportType(c, type, symbol, originalSymbol, moduleSpecifier) {
|
|
520
|
+
if (isErrorType(c, type))
|
|
521
|
+
return type;
|
|
522
|
+
const key = 'synthetic:' + type.id;
|
|
523
|
+
const cached = c.moduleTypeCache.get(key);
|
|
524
|
+
if (cached !== undefined)
|
|
525
|
+
return cached;
|
|
526
|
+
const file = getSourceFileDeclaration(originalSymbol);
|
|
527
|
+
let result = type;
|
|
528
|
+
if (canHaveSyntheticDefault(c, file, originalSymbol, false, moduleSpecifier)) {
|
|
529
|
+
const anonymousSymbol = c.newSymbol(2048 /* SymbolFlags.TypeLiteral */, "\uFFFEtype" /* InternalSymbolName.Type */);
|
|
530
|
+
const defaultContainingObject = createDefaultPropertyWrapperForModule(c, symbol, originalSymbol, anonymousSymbol);
|
|
531
|
+
c.symbolTypes.set(getSymbolId(anonymousSymbol), defaultContainingObject);
|
|
532
|
+
result = isValidSpreadType(c, type)
|
|
533
|
+
? getSpreadType(c, type, defaultContainingObject, anonymousSymbol, 0 /* ObjectFlags.None */, false)
|
|
534
|
+
: defaultContainingObject;
|
|
535
|
+
}
|
|
536
|
+
c.moduleTypeCache.set(key, result);
|
|
537
|
+
return result;
|
|
538
|
+
}
|
|
539
|
+
function createDefaultPropertyWrapperForModule(c, symbol, originalSymbol, anonymousSymbol) {
|
|
540
|
+
const defaultSymbol = c.newSymbol(2097152 /* SymbolFlags.Alias */, "default" /* InternalSymbolName.Default */);
|
|
541
|
+
defaultSymbol.parent = originalSymbol;
|
|
542
|
+
const links = c.symbolLinks(defaultSymbol);
|
|
543
|
+
const id = defaultSymbol.id;
|
|
544
|
+
c.symbolNameTypes.set(id, getStringLiteralType(c, 'default'));
|
|
545
|
+
links.aliasTarget = resolveSymbol(c, symbol);
|
|
546
|
+
const members = new Map();
|
|
547
|
+
members.set("default" /* InternalSymbolName.Default */, defaultSymbol);
|
|
548
|
+
return createAnonymousType(c, anonymousSymbol, members, [], [], []);
|
|
549
|
+
}
|
|
550
|
+
function cloneTypeAsModuleType(c, symbol, moduleType) {
|
|
551
|
+
const result = c.newSymbol(symbol.flags, symbol.name);
|
|
552
|
+
result.declarations = symbol.declarations.slice();
|
|
553
|
+
result.valueDeclaration = symbol.valueDeclaration;
|
|
554
|
+
if (symbol.members !== undefined)
|
|
555
|
+
result.members = new Map(symbol.members);
|
|
556
|
+
if (symbol.exports !== undefined)
|
|
557
|
+
result.exports = new Map(symbol.exports);
|
|
558
|
+
result.parent = symbol.parent;
|
|
559
|
+
const resolved = resolveStructuredTypeMembers(c, moduleType);
|
|
560
|
+
c.symbolTypes.set(getSymbolId(result), createAnonymousType(c, result, resolved.members, [], [], resolved.indexInfos));
|
|
561
|
+
return result;
|
|
562
|
+
}
|
|
563
|
+
function getSourceFileDeclaration(symbol) {
|
|
564
|
+
if (symbol === undefined)
|
|
565
|
+
return undefined;
|
|
566
|
+
for (const d of symbol.declarations)
|
|
567
|
+
if (d.kind === 307 /* SyntaxKind.SourceFile */)
|
|
568
|
+
return d;
|
|
569
|
+
return undefined;
|
|
570
|
+
}
|
|
571
|
+
/** The module syntax of the import or export containing `usage`, or `None` for non-literals. */
|
|
572
|
+
function getEmitSyntaxForModuleSpecifierExpression(c, usage) {
|
|
573
|
+
return isStringLiteralLike(usage)
|
|
574
|
+
? c.host.getEmitSyntaxForUsageLocation(getSourceFileOfNode(usage), usage)
|
|
575
|
+
: ModuleKind.None;
|
|
576
|
+
}
|
|
577
|
+
/** Whether a default import of the module gets the module itself, as interop helpers make it. */
|
|
578
|
+
function canHaveSyntheticDefault(c, file, moduleSymbol, dontResolveAlias, usage) {
|
|
579
|
+
const usageMode = file !== undefined ? getEmitSyntaxForModuleSpecifierExpression(c, usage) : ModuleKind.None;
|
|
580
|
+
if (file !== undefined && usageMode !== ModuleKind.None) {
|
|
581
|
+
const targetMode = c.host.getImpliedNodeFormatForEmit(file);
|
|
582
|
+
const moduleKind = getEmitModuleKind(c.compilerOptions);
|
|
583
|
+
// In Node.js, CommonJS modules always have a synthetic default when imported into ESM.
|
|
584
|
+
if (usageMode === ModuleKind.ESNext &&
|
|
585
|
+
targetMode === ModuleKind.CommonJS &&
|
|
586
|
+
moduleKind >= ModuleKind.Node16 &&
|
|
587
|
+
moduleKind <= ModuleKind.NodeNext)
|
|
588
|
+
return true;
|
|
589
|
+
// Two ES modules never have a synthetic default.
|
|
590
|
+
if (usageMode === ModuleKind.ESNext && targetMode === ModuleKind.ESNext)
|
|
591
|
+
return false;
|
|
592
|
+
}
|
|
593
|
+
if (file === undefined || file.isDeclarationFile) {
|
|
594
|
+
// A syntactic default export or an `__esModule` marker rules it out.
|
|
595
|
+
const defaultExport = resolveExportByName(c, moduleSymbol, "default" /* InternalSymbolName.Default */, undefined, true);
|
|
596
|
+
if (defaultExport !== undefined && hasSyntacticDefault(defaultExport))
|
|
597
|
+
return false;
|
|
598
|
+
return resolveExportByName(c, moduleSymbol, '__esModule', undefined, dontResolveAlias) === undefined;
|
|
599
|
+
}
|
|
600
|
+
// TypeScript files are emitted with `__esModule` unless they use `export =`.
|
|
601
|
+
if (!isInJSFile(file))
|
|
602
|
+
return hasExportAssignmentSymbol(moduleSymbol);
|
|
603
|
+
// JavaScript files without ES module syntax or an `__esModule` marker have one.
|
|
604
|
+
return ((file.externalModuleIndicator === undefined || file.externalModuleIndicator === file) &&
|
|
605
|
+
resolveExportByName(c, moduleSymbol, '__esModule', undefined, dontResolveAlias) === undefined);
|
|
606
|
+
}
|
|
607
|
+
function hasSyntacticDefault(symbol) {
|
|
608
|
+
for (const d of symbol.declarations)
|
|
609
|
+
if (isSyntacticDefault(d))
|
|
610
|
+
return true;
|
|
611
|
+
return false;
|
|
612
|
+
}
|
|
613
|
+
function isSyntacticDefault(node) {
|
|
614
|
+
return ((node.kind === 278 /* SyntaxKind.ExportAssignment */ && !node.isExportEquals) ||
|
|
615
|
+
hasSyntacticModifier(node, 2048 /* ModifierFlags.Default */) ||
|
|
616
|
+
node.kind === 282 /* SyntaxKind.ExportSpecifier */ ||
|
|
617
|
+
node.kind === 281 /* SyntaxKind.NamespaceExport */);
|
|
618
|
+
}
|
|
619
|
+
function hasExportAssignmentSymbol(moduleSymbol) {
|
|
620
|
+
return moduleSymbol.exports?.get("export=" /* InternalSymbolName.ExportEquals */) !== undefined;
|
|
621
|
+
}
|
|
622
|
+
function isShorthandAmbientModuleSymbol(symbol) {
|
|
623
|
+
const d = symbol?.valueDeclaration;
|
|
624
|
+
return d !== undefined && d.kind === 268 /* SyntaxKind.ModuleDeclaration */ && d.body === undefined;
|
|
625
|
+
}
|
|
626
|
+
// ---- Alias targets
|
|
627
|
+
/** The symbol an alias declaration refers to, without resolving further aliases. */
|
|
628
|
+
export function getTargetOfAliasDeclaration(c, node) {
|
|
629
|
+
if (node === undefined)
|
|
630
|
+
return undefined;
|
|
631
|
+
switch (node.kind) {
|
|
632
|
+
case 272 /* SyntaxKind.ImportEqualsDeclaration */:
|
|
633
|
+
case 261 /* SyntaxKind.VariableDeclaration */:
|
|
634
|
+
return getTargetOfImportEqualsDeclaration(c, node);
|
|
635
|
+
case 274 /* SyntaxKind.ImportClause */:
|
|
636
|
+
return getTargetOfImportClause(c, node);
|
|
637
|
+
case 275 /* SyntaxKind.NamespaceImport */:
|
|
638
|
+
return getTargetOfNamespaceImport(c, node);
|
|
639
|
+
case 281 /* SyntaxKind.NamespaceExport */:
|
|
640
|
+
return getTargetOfNamespaceExport(c, node);
|
|
641
|
+
case 277 /* SyntaxKind.ImportSpecifier */:
|
|
642
|
+
case 209 /* SyntaxKind.BindingElement */:
|
|
643
|
+
return getTargetOfImportSpecifier(c, node);
|
|
644
|
+
case 282 /* SyntaxKind.ExportSpecifier */:
|
|
645
|
+
return getTargetOfExportSpecifier(c, node, 111551 /* SymbolFlags.Value */ | 788968 /* SymbolFlags.Type */ | 1920 /* SymbolFlags.Namespace */, true);
|
|
646
|
+
case 278 /* SyntaxKind.ExportAssignment */:
|
|
647
|
+
return withTypeOnlyMark(c, node, getTargetOfAliasLikeExpression(c, getExpression(node)));
|
|
648
|
+
case 227 /* SyntaxKind.BinaryExpression */:
|
|
649
|
+
return withTypeOnlyMark(c, node, getTargetOfAliasLikeExpression(c, node.right));
|
|
650
|
+
case 271 /* SyntaxKind.NamespaceExportDeclaration */: {
|
|
651
|
+
const resolved = resolveExternalModuleSymbol(c, getSymbol(node.parent), true);
|
|
652
|
+
markSymbolOfAliasDeclarationIfTypeOnly(c, node, undefined);
|
|
653
|
+
return resolved;
|
|
654
|
+
}
|
|
655
|
+
case 304 /* SyntaxKind.ShorthandPropertyAssignment */:
|
|
656
|
+
return resolveEntityName(c, getName(node), 111551 /* SymbolFlags.Value */ | 788968 /* SymbolFlags.Type */ | 1920 /* SymbolFlags.Namespace */, true, true, undefined);
|
|
657
|
+
case 303 /* SyntaxKind.PropertyAssignment */:
|
|
658
|
+
return getTargetOfAliasLikeExpression(c, getInitializer(node));
|
|
659
|
+
case 213 /* SyntaxKind.ElementAccessExpression */:
|
|
660
|
+
case 212 /* SyntaxKind.PropertyAccessExpression */: {
|
|
661
|
+
const parent = node.parent;
|
|
662
|
+
if (parent !== undefined &&
|
|
663
|
+
parent.kind === 227 /* SyntaxKind.BinaryExpression */ &&
|
|
664
|
+
parent.left === node &&
|
|
665
|
+
parent.operatorToken.kind === 63 /* SyntaxKind.EqualsToken */)
|
|
666
|
+
return getTargetOfAliasLikeExpression(c, parent.right);
|
|
667
|
+
return undefined;
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
return undefined;
|
|
671
|
+
}
|
|
672
|
+
function withTypeOnlyMark(c, node, resolved) {
|
|
673
|
+
markSymbolOfAliasDeclarationIfTypeOnly(c, node, undefined);
|
|
674
|
+
return resolved;
|
|
675
|
+
}
|
|
676
|
+
function getTargetOfImportEqualsDeclaration(c, node) {
|
|
677
|
+
if (node.kind === 261 /* SyntaxKind.VariableDeclaration */ || isExternalModuleImportEquals(node)) {
|
|
678
|
+
const moduleReference = isVariableDeclarationInitializedToRequire(node)
|
|
679
|
+
? getInitializer(node).arguments.nodes[0]
|
|
680
|
+
: getExpression(node.moduleReference);
|
|
681
|
+
const immediate = resolveExternalModuleName(c, node, moduleReference, false);
|
|
682
|
+
const resolved = resolveExternalModuleSymbol(c, immediate, true);
|
|
683
|
+
const moduleKind = getEmitModuleKind(c.compilerOptions);
|
|
684
|
+
if (resolved !== undefined && moduleKind >= ModuleKind.Node20 && moduleKind <= ModuleKind.NodeNext) {
|
|
685
|
+
const moduleExports = getExportOfModule(c, resolved, "module.exports" /* InternalSymbolName.ModuleExports */, node, true);
|
|
686
|
+
if (moduleExports !== undefined)
|
|
687
|
+
return moduleExports;
|
|
688
|
+
}
|
|
689
|
+
markSymbolOfAliasDeclarationIfTypeOnly(c, node, undefined);
|
|
690
|
+
return resolved;
|
|
691
|
+
}
|
|
692
|
+
const resolved = getSymbolOfPartOfRightHandSideOfImportEquals(c, node.moduleReference);
|
|
693
|
+
checkAndReportErrorForResolvingImportAliasToTypeOnlySymbol(c, node);
|
|
694
|
+
return resolved;
|
|
695
|
+
}
|
|
696
|
+
function isExternalModuleImportEquals(node) {
|
|
697
|
+
return (node.kind === 272 /* SyntaxKind.ImportEqualsDeclaration */ &&
|
|
698
|
+
node.moduleReference.kind === 284 /* SyntaxKind.ExternalModuleReference */);
|
|
699
|
+
}
|
|
700
|
+
/**
|
|
701
|
+
* Resolves the entity name of `import a = b.c`: `b` alone or the left part of a longer name is a
|
|
702
|
+
* namespace, the whole name any meaning.
|
|
703
|
+
*/
|
|
704
|
+
export function getSymbolOfPartOfRightHandSideOfImportEquals(c, entityName) {
|
|
705
|
+
if (entityName.kind === 79 /* SyntaxKind.Identifier */ &&
|
|
706
|
+
entityName.parent !== undefined &&
|
|
707
|
+
entityName.parent.kind === 167 /* SyntaxKind.QualifiedName */ &&
|
|
708
|
+
entityName.parent.right === entityName)
|
|
709
|
+
entityName = entityName.parent;
|
|
710
|
+
if (entityName.kind === 79 /* SyntaxKind.Identifier */ || entityName.parent.kind === 167 /* SyntaxKind.QualifiedName */)
|
|
711
|
+
return resolveEntityName(c, entityName, 1920 /* SymbolFlags.Namespace */, false, true, undefined);
|
|
712
|
+
return resolveEntityName(c, entityName, 111551 /* SymbolFlags.Value */ | 788968 /* SymbolFlags.Type */ | 1920 /* SymbolFlags.Namespace */, false, true, undefined);
|
|
713
|
+
}
|
|
714
|
+
function checkAndReportErrorForResolvingImportAliasToTypeOnlySymbol(c, node) {
|
|
715
|
+
let name = node.moduleReference;
|
|
716
|
+
for (;;) {
|
|
717
|
+
const typeOnlyDeclaration = getTypeOnlyDeclarationOfEntityName(c, name);
|
|
718
|
+
if (typeOnlyDeclaration !== undefined) {
|
|
719
|
+
const isExport = typeOnlyDeclaration.kind === 282 /* SyntaxKind.ExportSpecifier */ ||
|
|
720
|
+
typeOnlyDeclaration.kind === 279 /* SyntaxKind.ExportDeclaration */;
|
|
721
|
+
const diagnostic = c.error(node.moduleReference, isExport
|
|
722
|
+
? 308 /* Diagnostics.An_import_alias_cannot_reference_a_declaration_that_was_exported_using_export_type */
|
|
723
|
+
: 309 /* Diagnostics.An_import_alias_cannot_reference_a_declaration_that_was_imported_using_import_type */);
|
|
724
|
+
const typeOnlyName = typeOnlyDeclaration.kind === 279 /* SyntaxKind.ExportDeclaration */ ? '*' : getText(getName(typeOnlyDeclaration));
|
|
725
|
+
diagnostic.addRelatedInfo(createDiagnosticForNode(typeOnlyDeclaration, isExport ? 306 /* Diagnostics.X_0_was_exported_here */ : 305 /* Diagnostics.X_0_was_imported_here */, [typeOnlyName]));
|
|
726
|
+
return;
|
|
727
|
+
}
|
|
728
|
+
if (name.kind !== 167 /* SyntaxKind.QualifiedName */)
|
|
729
|
+
return;
|
|
730
|
+
name = name.left;
|
|
731
|
+
}
|
|
732
|
+
}
|
|
733
|
+
function getTypeOnlyDeclarationOfEntityName(c, name) {
|
|
734
|
+
if (name.kind !== 79 /* SyntaxKind.Identifier */ && name.kind !== 167 /* SyntaxKind.QualifiedName */)
|
|
735
|
+
return undefined;
|
|
736
|
+
const symbol = resolveEntityName(c, name, 111551 /* SymbolFlags.Value */ | 788968 /* SymbolFlags.Type */ | 1920 /* SymbolFlags.Namespace */, true, true, undefined);
|
|
737
|
+
return symbol !== undefined ? getTypeOnlyAliasDeclaration(c, symbol) : undefined;
|
|
738
|
+
}
|
|
739
|
+
function getTargetOfImportClause(c, node) {
|
|
740
|
+
const moduleSymbol = resolveExternalModuleName(c, node, getModuleSpecifier(node.parent), false);
|
|
741
|
+
return moduleSymbol !== undefined ? getTargetOfModuleDefault(c, moduleSymbol, node, true) : undefined;
|
|
742
|
+
}
|
|
743
|
+
function getTargetOfModuleDefault(c, moduleSymbol, node, dontResolveAlias) {
|
|
744
|
+
const file = getSourceFileDeclaration(moduleSymbol);
|
|
745
|
+
const specifier = getModuleSpecifierForImportOrExport(node);
|
|
746
|
+
const exportDefaultSymbol = isShorthandAmbientModuleSymbol(moduleSymbol)
|
|
747
|
+
? undefined
|
|
748
|
+
: resolveExportByName(c, moduleSymbol, "default" /* InternalSymbolName.Default */, node, dontResolveAlias);
|
|
749
|
+
if (specifier === undefined)
|
|
750
|
+
return exportDefaultSymbol;
|
|
751
|
+
const hasDefaultOnly = isOnlyImportableAsDefault(c, specifier, moduleSymbol);
|
|
752
|
+
const hasSyntheticDefault = canHaveSyntheticDefault(c, file, moduleSymbol, dontResolveAlias, specifier);
|
|
753
|
+
if (exportDefaultSymbol === undefined && !hasSyntheticDefault && !hasDefaultOnly) {
|
|
754
|
+
if (node.kind === 274 /* SyntaxKind.ImportClause */)
|
|
755
|
+
reportNonDefaultExport(c, moduleSymbol, node);
|
|
756
|
+
else {
|
|
757
|
+
const name = node.kind === 277 /* SyntaxKind.ImportSpecifier */ || node.kind === 282 /* SyntaxKind.ExportSpecifier */
|
|
758
|
+
? getPropertyNameOrName(node)
|
|
759
|
+
: getName(node);
|
|
760
|
+
errorNoModuleMemberSymbol(c, moduleSymbol, moduleSymbol, node, name);
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
else if (hasSyntheticDefault || hasDefaultOnly) {
|
|
764
|
+
// A synthetic default overrides a real `default` member without an `__esModule` marker.
|
|
765
|
+
const resolved = resolveExternalModuleSymbol(c, moduleSymbol, dontResolveAlias) ??
|
|
766
|
+
resolveSymbolEx(c, moduleSymbol, dontResolveAlias);
|
|
767
|
+
markSymbolOfAliasDeclarationIfTypeOnly(c, node, undefined);
|
|
768
|
+
return resolved;
|
|
769
|
+
}
|
|
770
|
+
markSymbolOfAliasDeclarationIfTypeOnly(c, node, undefined);
|
|
771
|
+
return exportDefaultSymbol;
|
|
772
|
+
}
|
|
773
|
+
function reportNonDefaultExport(c, moduleSymbol, node) {
|
|
774
|
+
const local = getSymbol(node);
|
|
775
|
+
if (moduleSymbol.exports?.get(local.name) !== undefined) {
|
|
776
|
+
c.error(node, 757 /* Diagnostics.Module_0_has_no_default_export_Did_you_mean_to_use_import_1_from_0_instead */, symbolToString(c, moduleSymbol), symbolToString(c, local));
|
|
777
|
+
return;
|
|
778
|
+
}
|
|
779
|
+
const diagnostic = c.error(getName(node), 148 /* Diagnostics.Module_0_has_no_default_export */, symbolToString(c, moduleSymbol));
|
|
780
|
+
const exportStar = moduleSymbol.exports?.get("\uFFFEexport" /* InternalSymbolName.ExportStar */);
|
|
781
|
+
if (exportStar === undefined)
|
|
782
|
+
return;
|
|
783
|
+
for (const d of exportStar.declarations) {
|
|
784
|
+
const specifier = getModuleSpecifier(d);
|
|
785
|
+
if (d.kind !== 279 /* SyntaxKind.ExportDeclaration */ || specifier === undefined)
|
|
786
|
+
continue;
|
|
787
|
+
const resolved = resolveExternalModuleName(c, d, specifier, false);
|
|
788
|
+
if (resolved !== undefined && resolved.exports?.get("default" /* InternalSymbolName.Default */) !== undefined) {
|
|
789
|
+
diagnostic.addRelatedInfo(createDiagnosticForNode(d, 151 /* Diagnostics.X_export_Asterisk_does_not_re_export_a_default */, []));
|
|
790
|
+
return;
|
|
791
|
+
}
|
|
792
|
+
}
|
|
793
|
+
}
|
|
794
|
+
function resolveExportByName(c, moduleSymbol, name, sourceNode, dontResolveAlias) {
|
|
795
|
+
const exportValue = moduleSymbol.exports?.get("export=" /* InternalSymbolName.ExportEquals */);
|
|
796
|
+
const exportSymbol = exportValue !== undefined
|
|
797
|
+
? getPropertyOfTypeEx(c, getTypeOfSymbol(c, exportValue), name, true, false)
|
|
798
|
+
: moduleSymbol.exports?.get(name);
|
|
799
|
+
const resolved = exportSymbol !== undefined ? resolveSymbolEx(c, exportSymbol, dontResolveAlias) : undefined;
|
|
800
|
+
markSymbolOfAliasDeclarationIfTypeOnly(c, sourceNode, undefined);
|
|
801
|
+
return resolved;
|
|
802
|
+
}
|
|
803
|
+
function getTargetOfNamespaceImport(c, node) {
|
|
804
|
+
const moduleSpecifier = getModuleSpecifierForImportOrExport(node);
|
|
805
|
+
const immediate = resolveExternalModuleName(c, node, moduleSpecifier, false);
|
|
806
|
+
const resolved = resolveESModuleSymbol(c, immediate, node, moduleSpecifier);
|
|
807
|
+
markSymbolOfAliasDeclarationIfTypeOnly(c, node, undefined);
|
|
808
|
+
return resolved;
|
|
809
|
+
}
|
|
810
|
+
function getTargetOfNamespaceExport(c, node) {
|
|
811
|
+
const moduleSpecifier = getModuleSpecifierForImportOrExport(node);
|
|
812
|
+
if (moduleSpecifier === undefined)
|
|
813
|
+
return undefined;
|
|
814
|
+
const immediate = resolveExternalModuleName(c, node, moduleSpecifier, false);
|
|
815
|
+
const resolved = resolveESModuleSymbol(c, immediate, node, moduleSpecifier);
|
|
816
|
+
markSymbolOfAliasDeclarationIfTypeOnly(c, node, undefined);
|
|
817
|
+
return resolved;
|
|
818
|
+
}
|
|
819
|
+
function getTargetOfImportSpecifier(c, node) {
|
|
820
|
+
const name = getPropertyNameOrName(node);
|
|
821
|
+
if (node.kind === 277 /* SyntaxKind.ImportSpecifier */ && moduleExportNameIsDefault(name)) {
|
|
822
|
+
const specifier = getModuleSpecifierForImportOrExport(node);
|
|
823
|
+
if (specifier !== undefined) {
|
|
824
|
+
const moduleSymbol = resolveExternalModuleName(c, node, specifier, false);
|
|
825
|
+
if (moduleSymbol !== undefined)
|
|
826
|
+
return getTargetOfModuleDefault(c, moduleSymbol, node, true);
|
|
827
|
+
}
|
|
828
|
+
}
|
|
829
|
+
const root = node.kind === 209 /* SyntaxKind.BindingElement */ ? getRootDeclaration(node) : node.parent.parent.parent;
|
|
830
|
+
const resolved = getExternalModuleMember(c, root, node, true);
|
|
831
|
+
markSymbolOfAliasDeclarationIfTypeOnly(c, node, undefined);
|
|
832
|
+
return resolved;
|
|
833
|
+
}
|
|
834
|
+
/** The export `specifier` names from the module of the import or export declaration `node`. */
|
|
835
|
+
export function getExternalModuleMember(c, node, specifier, dontResolveAlias) {
|
|
836
|
+
const moduleSpecifier = isVariableDeclarationInitializedToRequire(node)
|
|
837
|
+
? getInitializer(node).arguments.nodes[0]
|
|
838
|
+
: getExternalModuleName(node);
|
|
839
|
+
const moduleSymbol = resolveExternalModuleName(c, node, moduleSpecifier, false);
|
|
840
|
+
const name = specifier.kind === 212 /* SyntaxKind.PropertyAccessExpression */ ? getName(specifier) : getPropertyNameOrName(specifier);
|
|
841
|
+
if (name.kind !== 79 /* SyntaxKind.Identifier */ && name.kind !== 10 /* SyntaxKind.StringLiteral */)
|
|
842
|
+
return undefined;
|
|
843
|
+
const nameText = getText(name);
|
|
844
|
+
const targetSymbol = moduleSpecifier !== undefined ? resolveESModuleSymbol(c, moduleSymbol, specifier, moduleSpecifier) : undefined;
|
|
845
|
+
// The empty string is a valid module export name.
|
|
846
|
+
if (targetSymbol === undefined ||
|
|
847
|
+
moduleSymbol === undefined ||
|
|
848
|
+
(nameText === '' && name.kind !== 10 /* SyntaxKind.StringLiteral */))
|
|
849
|
+
return undefined;
|
|
850
|
+
if (isShorthandAmbientModuleSymbol(moduleSymbol))
|
|
851
|
+
return moduleSymbol;
|
|
852
|
+
// An `export =` module exports the members of its target's type.
|
|
853
|
+
const exportEquals = hasExportAssignmentSymbol(moduleSymbol);
|
|
854
|
+
let symbolFromVariable = exportEquals
|
|
855
|
+
? getPropertyOfTypeEx(c, getTypeOfSymbol(c, targetSymbol), nameText, true, false)
|
|
856
|
+
: getPropertyOfVariable(c, targetSymbol, nameText);
|
|
857
|
+
if (symbolFromVariable !== undefined)
|
|
858
|
+
symbolFromVariable = resolveSymbolEx(c, symbolFromVariable, dontResolveAlias);
|
|
859
|
+
// Types and namespaces of an `export =` module live on the module symbol.
|
|
860
|
+
let symbolFromModule = getExportOfModule(c, exportEquals ? moduleSymbol : targetSymbol, nameText, specifier, dontResolveAlias);
|
|
861
|
+
if (symbolFromModule === undefined &&
|
|
862
|
+
nameText === "default" /* InternalSymbolName.Default */ &&
|
|
863
|
+
(isOnlyImportableAsDefault(c, moduleSpecifier, moduleSymbol) ||
|
|
864
|
+
canHaveSyntheticDefault(c, getSourceFileDeclaration(moduleSymbol), moduleSymbol, dontResolveAlias, moduleSpecifier)))
|
|
865
|
+
symbolFromModule =
|
|
866
|
+
resolveExternalModuleSymbol(c, moduleSymbol, dontResolveAlias) ??
|
|
867
|
+
resolveSymbolEx(c, moduleSymbol, dontResolveAlias);
|
|
868
|
+
const symbol = symbolFromModule === undefined
|
|
869
|
+
? symbolFromVariable
|
|
870
|
+
: symbolFromVariable === undefined
|
|
871
|
+
? symbolFromModule
|
|
872
|
+
: combineValueAndTypeSymbols(c, symbolFromVariable, symbolFromModule);
|
|
873
|
+
if ((specifier.kind === 277 /* SyntaxKind.ImportSpecifier */ || specifier.kind === 282 /* SyntaxKind.ExportSpecifier */) &&
|
|
874
|
+
nameText !== "default" /* InternalSymbolName.Default */ &&
|
|
875
|
+
isOnlyImportableAsDefault(c, moduleSpecifier, moduleSymbol))
|
|
876
|
+
c.error(name, 459 /* Diagnostics.Named_imports_from_a_JSON_file_into_an_ECMAScript_module_are_not_allowed_when_module_is_set_to_0 */, moduleKindName(getEmitModuleKind(c.compilerOptions)));
|
|
877
|
+
else if (symbol === undefined)
|
|
878
|
+
errorNoModuleMemberSymbol(c, moduleSymbol, targetSymbol, node, name);
|
|
879
|
+
return symbol;
|
|
880
|
+
}
|
|
881
|
+
function getPropertyOfVariable(c, symbol, name) {
|
|
882
|
+
if ((symbol.flags & 3 /* SymbolFlags.Variable */) === 0)
|
|
883
|
+
return undefined;
|
|
884
|
+
const declaration = symbol.valueDeclaration;
|
|
885
|
+
const typeAnnotation = declaration !== undefined ? getType(declaration) : undefined;
|
|
886
|
+
if (typeAnnotation === undefined)
|
|
887
|
+
return undefined;
|
|
888
|
+
return resolveSymbol(c, getPropertyOfType(c, getTypeFromTypeNode(c, typeAnnotation), name));
|
|
889
|
+
}
|
|
890
|
+
/** A symbol with the value side of `valueSymbol` and the type and namespace sides of `typeSymbol`. */
|
|
891
|
+
function combineValueAndTypeSymbols(c, valueSymbol, typeSymbol) {
|
|
892
|
+
if (valueSymbol === c.unknownSymbol && typeSymbol === c.unknownSymbol)
|
|
893
|
+
return c.unknownSymbol;
|
|
894
|
+
if ((typeSymbol.flags & 111551 /* SymbolFlags.Value */) !== 0)
|
|
895
|
+
return typeSymbol;
|
|
896
|
+
if ((valueSymbol.flags & (788968 /* SymbolFlags.Type */ | 1920 /* SymbolFlags.Namespace */)) !== 0)
|
|
897
|
+
return valueSymbol;
|
|
898
|
+
const result = c.newSymbol(valueSymbol.flags | typeSymbol.flags, valueSymbol.name);
|
|
899
|
+
const declarations = valueSymbol.declarations.slice();
|
|
900
|
+
for (const d of typeSymbol.declarations)
|
|
901
|
+
if (!declarations.includes(d))
|
|
902
|
+
declarations.push(d);
|
|
903
|
+
result.declarations = declarations;
|
|
904
|
+
result.parent = valueSymbol.parent ?? typeSymbol.parent;
|
|
905
|
+
result.valueDeclaration = valueSymbol.valueDeclaration;
|
|
906
|
+
if (typeSymbol.members !== undefined)
|
|
907
|
+
result.members = new Map(typeSymbol.members);
|
|
908
|
+
if (valueSymbol.exports !== undefined)
|
|
909
|
+
result.exports = new Map(valueSymbol.exports);
|
|
910
|
+
return result;
|
|
911
|
+
}
|
|
912
|
+
function getExportOfModule(c, symbol, nameText, specifier, dontResolveAlias) {
|
|
913
|
+
if ((symbol.flags & 1536 /* SymbolFlags.Module */) === 0)
|
|
914
|
+
return undefined;
|
|
915
|
+
const exportSymbol = getExportsOfSymbol(c, symbol).get(nameText);
|
|
916
|
+
const resolved = exportSymbol !== undefined ? resolveSymbolEx(c, exportSymbol, dontResolveAlias) : undefined;
|
|
917
|
+
const exportStarDeclaration = c.symbolLinks(symbol).typeOnlyExportStarMap?.get(nameText);
|
|
918
|
+
markSymbolOfAliasDeclarationIfTypeOnly(c, specifier, exportStarDeclaration);
|
|
919
|
+
return resolved;
|
|
920
|
+
}
|
|
921
|
+
function errorNoModuleMemberSymbol(c, moduleSymbol, targetSymbol, node, name) {
|
|
922
|
+
const moduleName = getFullyQualifiedName(c, moduleSymbol, node);
|
|
923
|
+
const declarationName = declarationNameToString(getSourceFileOfNode(name), name);
|
|
924
|
+
const suggestion = name.kind === 79 /* SyntaxKind.Identifier */
|
|
925
|
+
? getSpellingSuggestionForName(c, getText(name), Array.from(getExportsOfModule(c, targetSymbol).values()), 2623475 /* SymbolFlags.ModuleMember */)
|
|
926
|
+
: undefined;
|
|
927
|
+
if (suggestion !== undefined) {
|
|
928
|
+
const suggestionName = symbolToString(c, suggestion);
|
|
929
|
+
const diagnostic = c.error(name, 856 /* Diagnostics.X_0_has_no_exported_member_named_1_Did_you_mean_2 */, moduleName, declarationName, suggestionName);
|
|
930
|
+
if (suggestion.valueDeclaration !== undefined)
|
|
931
|
+
diagnostic.addRelatedInfo(createDiagnosticForNode(suggestion.valueDeclaration, 860 /* Diagnostics.X_0_is_declared_here */, [suggestionName]));
|
|
932
|
+
return;
|
|
933
|
+
}
|
|
934
|
+
if (moduleSymbol.exports?.get("default" /* InternalSymbolName.Default */) !== undefined) {
|
|
935
|
+
c.error(name, 758 /* Diagnostics.Module_0_has_no_exported_member_1_Did_you_mean_to_use_import_1_from_0_instead */, moduleName, declarationName);
|
|
936
|
+
return;
|
|
937
|
+
}
|
|
938
|
+
reportNonExportedMember(c, name, declarationName, moduleSymbol, moduleName);
|
|
939
|
+
}
|
|
940
|
+
function reportNonExportedMember(c, name, declarationName, moduleSymbol, moduleName) {
|
|
941
|
+
const locals = moduleSymbol.valueDeclaration !== undefined ? getLocals(moduleSymbol.valueDeclaration) : undefined;
|
|
942
|
+
const localSymbol = locals?.get(getText(name));
|
|
943
|
+
if (localSymbol === undefined) {
|
|
944
|
+
c.error(name, 483 /* Diagnostics.Module_0_has_no_exported_member_1 */, moduleName, declarationName);
|
|
945
|
+
return;
|
|
946
|
+
}
|
|
947
|
+
const exports = moduleSymbol.exports;
|
|
948
|
+
const exportEquals = exports?.get("export=" /* InternalSymbolName.ExportEquals */);
|
|
949
|
+
if (exportEquals !== undefined) {
|
|
950
|
+
if (isSameReference(c, exportEquals, localSymbol))
|
|
951
|
+
reportInvalidImportEqualsExportMember(c, name, declarationName, moduleName);
|
|
952
|
+
else
|
|
953
|
+
c.error(name, 483 /* Diagnostics.Module_0_has_no_exported_member_1 */, moduleName, declarationName);
|
|
954
|
+
return;
|
|
955
|
+
}
|
|
956
|
+
let exportedSymbol;
|
|
957
|
+
if (exports !== undefined)
|
|
958
|
+
for (const s of exports.values())
|
|
959
|
+
if (isSameReference(c, s, localSymbol)) {
|
|
960
|
+
exportedSymbol = s;
|
|
961
|
+
break;
|
|
962
|
+
}
|
|
963
|
+
const diagnostic = exportedSymbol !== undefined
|
|
964
|
+
? c.error(name, 626 /* Diagnostics.Module_0_declares_1_locally_but_it_is_exported_as_2 */, moduleName, declarationName, symbolToString(c, exportedSymbol))
|
|
965
|
+
: c.error(name, 625 /* Diagnostics.Module_0_declares_1_locally_but_it_is_not_exported */, moduleName, declarationName);
|
|
966
|
+
for (let i = 0; i < localSymbol.declarations.length; i++)
|
|
967
|
+
diagnostic.addRelatedInfo(createDiagnosticForNode(localSymbol.declarations[i], i === 0 ? 860 /* Diagnostics.X_0_is_declared_here */ : 1357 /* Diagnostics.X_and_here */, [declarationName]));
|
|
968
|
+
}
|
|
969
|
+
function isSameReference(c, s1, s2) {
|
|
970
|
+
return (getMergedSymbol(c, resolveSymbol(c, getMergedSymbol(c, s1))) ===
|
|
971
|
+
getMergedSymbol(c, resolveSymbol(c, getMergedSymbol(c, s2))));
|
|
972
|
+
}
|
|
973
|
+
function reportInvalidImportEqualsExportMember(c, name, declarationName, moduleName) {
|
|
974
|
+
if (getEmitModuleKind(c.compilerOptions) >= ModuleKind.ES2015)
|
|
975
|
+
c.error(name, 743 /* Diagnostics.X_0_can_only_be_imported_by_using_a_default_import */, declarationName);
|
|
976
|
+
else if (isInJSFile(name))
|
|
977
|
+
c.error(name, 745 /* Diagnostics.X_0_can_only_be_imported_by_using_a_require_call_or_by_using_a_default_import */, declarationName);
|
|
978
|
+
else
|
|
979
|
+
c.error(name, 760 /* Diagnostics.X_0_can_only_be_imported_by_using_import_1_require_2_or_a_default_import */, declarationName, declarationName, moduleName);
|
|
980
|
+
}
|
|
981
|
+
export function getTargetOfExportSpecifier(c, node, meaning, dontResolveAlias) {
|
|
982
|
+
const name = getPropertyNameOrName(node);
|
|
983
|
+
if (moduleExportNameIsDefault(name)) {
|
|
984
|
+
const specifier = getModuleSpecifierForImportOrExport(node);
|
|
985
|
+
if (specifier !== undefined) {
|
|
986
|
+
const moduleSymbol = resolveExternalModuleName(c, node, specifier, false);
|
|
987
|
+
if (moduleSymbol !== undefined)
|
|
988
|
+
return getTargetOfModuleDefault(c, moduleSymbol, node, dontResolveAlias);
|
|
989
|
+
}
|
|
990
|
+
}
|
|
991
|
+
const exportDeclaration = node.parent.parent;
|
|
992
|
+
let resolved;
|
|
993
|
+
if (exportDeclaration.moduleSpecifier !== undefined)
|
|
994
|
+
resolved = getExternalModuleMember(c, exportDeclaration, node, dontResolveAlias);
|
|
995
|
+
else if (name.kind !== 10 /* SyntaxKind.StringLiteral */)
|
|
996
|
+
resolved = resolveEntityName(c, name, meaning, false, dontResolveAlias, undefined);
|
|
997
|
+
markSymbolOfAliasDeclarationIfTypeOnly(c, node, undefined);
|
|
998
|
+
return resolved;
|
|
999
|
+
}
|
|
1000
|
+
function getTargetOfAliasLikeExpression(c, expression) {
|
|
1001
|
+
if (expression.kind === 232 /* SyntaxKind.ClassExpression */)
|
|
1002
|
+
return checkExpressionCached(c, expression).symbol;
|
|
1003
|
+
if (!isEntityNameOrEntityNameExpression(expression))
|
|
1004
|
+
return undefined;
|
|
1005
|
+
const aliasLike = resolveEntityName(c, expression, 111551 /* SymbolFlags.Value */ | 788968 /* SymbolFlags.Type */ | 1920 /* SymbolFlags.Namespace */, true, true, undefined);
|
|
1006
|
+
if (aliasLike !== undefined)
|
|
1007
|
+
return aliasLike;
|
|
1008
|
+
checkExpressionCached(c, expression);
|
|
1009
|
+
return c.resolvedSymbols.get(expression.id);
|
|
1010
|
+
}
|
|
1011
|
+
function isEntityNameOrEntityNameExpression(node) {
|
|
1012
|
+
if (node.kind === 79 /* SyntaxKind.Identifier */)
|
|
1013
|
+
return true;
|
|
1014
|
+
if (node.kind === 167 /* SyntaxKind.QualifiedName */)
|
|
1015
|
+
return true;
|
|
1016
|
+
if (node.kind === 212 /* SyntaxKind.PropertyAccessExpression */) {
|
|
1017
|
+
const name = getName(node);
|
|
1018
|
+
return (name !== undefined &&
|
|
1019
|
+
name.kind === 79 /* SyntaxKind.Identifier */ &&
|
|
1020
|
+
isEntityNameOrEntityNameExpression(getExpression(node)));
|
|
1021
|
+
}
|
|
1022
|
+
return false;
|
|
1023
|
+
}
|
|
1024
|
+
function getPropertyNameOrName(node) {
|
|
1025
|
+
return getPropertyName(node) ?? getName(node);
|
|
1026
|
+
}
|
|
1027
|
+
function getModuleSpecifierForImportOrExport(node) {
|
|
1028
|
+
switch (node.kind) {
|
|
1029
|
+
case 274 /* SyntaxKind.ImportClause */:
|
|
1030
|
+
return getModuleSpecifierOfDeclaration(node.parent);
|
|
1031
|
+
case 272 /* SyntaxKind.ImportEqualsDeclaration */: {
|
|
1032
|
+
const reference = node.moduleReference;
|
|
1033
|
+
return reference.kind === 284 /* SyntaxKind.ExternalModuleReference */ ? getExpression(reference) : undefined;
|
|
1034
|
+
}
|
|
1035
|
+
case 275 /* SyntaxKind.NamespaceImport */:
|
|
1036
|
+
return getModuleSpecifierOfDeclaration(node.parent.parent);
|
|
1037
|
+
case 277 /* SyntaxKind.ImportSpecifier */:
|
|
1038
|
+
return getModuleSpecifierOfDeclaration(node.parent.parent.parent);
|
|
1039
|
+
case 281 /* SyntaxKind.NamespaceExport */:
|
|
1040
|
+
return getModuleSpecifierOfDeclaration(node.parent);
|
|
1041
|
+
case 282 /* SyntaxKind.ExportSpecifier */:
|
|
1042
|
+
return getModuleSpecifierOfDeclaration(node.parent.parent);
|
|
1043
|
+
}
|
|
1044
|
+
return undefined;
|
|
1045
|
+
}
|
|
1046
|
+
function getModuleSpecifierOfDeclaration(node) {
|
|
1047
|
+
if (node.kind === 279 /* SyntaxKind.ExportDeclaration */)
|
|
1048
|
+
return node.moduleSpecifier;
|
|
1049
|
+
return getModuleSpecifier(node);
|
|
1050
|
+
}
|
|
1051
|
+
// ---- Type-only aliases
|
|
1052
|
+
/** Whether the declaration itself is written `import type` or `export type`. */
|
|
1053
|
+
export function isTypeOnlyImportOrExportDeclaration(node) {
|
|
1054
|
+
switch (node.kind) {
|
|
1055
|
+
case 277 /* SyntaxKind.ImportSpecifier */:
|
|
1056
|
+
return getIsTypeOnly(node) || isTypeOnlyImportClause(node.parent.parent);
|
|
1057
|
+
case 275 /* SyntaxKind.NamespaceImport */:
|
|
1058
|
+
return isTypeOnlyImportClause(node.parent);
|
|
1059
|
+
case 274 /* SyntaxKind.ImportClause */:
|
|
1060
|
+
return isTypeOnlyImportClause(node);
|
|
1061
|
+
case 272 /* SyntaxKind.ImportEqualsDeclaration */:
|
|
1062
|
+
return getIsTypeOnly(node);
|
|
1063
|
+
case 282 /* SyntaxKind.ExportSpecifier */:
|
|
1064
|
+
return getIsTypeOnly(node) || getIsTypeOnly(node.parent.parent);
|
|
1065
|
+
case 279 /* SyntaxKind.ExportDeclaration */: {
|
|
1066
|
+
const declaration = node;
|
|
1067
|
+
return (declaration.isTypeOnly && declaration.moduleSpecifier !== undefined && declaration.exportClause === undefined);
|
|
1068
|
+
}
|
|
1069
|
+
case 281 /* SyntaxKind.NamespaceExport */:
|
|
1070
|
+
return getIsTypeOnly(node.parent);
|
|
1071
|
+
}
|
|
1072
|
+
return false;
|
|
1073
|
+
}
|
|
1074
|
+
function isTypeOnlyImportClause(node) {
|
|
1075
|
+
return node.kind === 274 /* SyntaxKind.ImportClause */ && node.phaseModifier === 156 /* SyntaxKind.TypeKeyword */;
|
|
1076
|
+
}
|
|
1077
|
+
/**
|
|
1078
|
+
* Marks an alias declared `import type`/`export type`, or reached through a type-only `export *`,
|
|
1079
|
+
* as type-only; returns whether it is.
|
|
1080
|
+
*/
|
|
1081
|
+
function markSymbolOfAliasDeclarationIfTypeOnly(c, aliasDeclaration, exportStarDeclaration) {
|
|
1082
|
+
if (aliasDeclaration === undefined)
|
|
1083
|
+
return false;
|
|
1084
|
+
const sourceSymbol = getSymbol(aliasDeclaration);
|
|
1085
|
+
if (sourceSymbol === undefined)
|
|
1086
|
+
return false;
|
|
1087
|
+
const links = c.symbolLinks(getMergedSymbol(c, sourceSymbol));
|
|
1088
|
+
if (links.typeOnlyDeclaration === undefined && isTypeOnlyImportOrExportDeclaration(aliasDeclaration)) {
|
|
1089
|
+
links.typeOnlyDeclaration = aliasDeclaration;
|
|
1090
|
+
return true;
|
|
1091
|
+
}
|
|
1092
|
+
if (links.typeOnlyDeclaration === undefined && exportStarDeclaration !== undefined) {
|
|
1093
|
+
links.typeOnlyDeclaration = exportStarDeclaration;
|
|
1094
|
+
return true;
|
|
1095
|
+
}
|
|
1096
|
+
return links.typeOnlyDeclaration !== undefined;
|
|
1097
|
+
}
|
|
1098
|
+
/** Marks the alias declaration an entity name is part of, if it is type-only. */
|
|
1099
|
+
export function markAliasDeclarationOfNameIfTypeOnly(c, name) {
|
|
1100
|
+
let current = name;
|
|
1101
|
+
while (current.parent !== undefined && current.parent.kind === 167 /* SyntaxKind.QualifiedName */)
|
|
1102
|
+
current = current.parent;
|
|
1103
|
+
const parent = current.parent;
|
|
1104
|
+
if (parent === undefined)
|
|
1105
|
+
return;
|
|
1106
|
+
switch (parent.kind) {
|
|
1107
|
+
case 274 /* SyntaxKind.ImportClause */:
|
|
1108
|
+
case 277 /* SyntaxKind.ImportSpecifier */:
|
|
1109
|
+
case 275 /* SyntaxKind.NamespaceImport */:
|
|
1110
|
+
case 282 /* SyntaxKind.ExportSpecifier */:
|
|
1111
|
+
case 278 /* SyntaxKind.ExportAssignment */:
|
|
1112
|
+
case 272 /* SyntaxKind.ImportEqualsDeclaration */:
|
|
1113
|
+
case 281 /* SyntaxKind.NamespaceExport */:
|
|
1114
|
+
markSymbolOfAliasDeclarationIfTypeOnly(c, parent, undefined);
|
|
1115
|
+
}
|
|
1116
|
+
}
|
|
1117
|
+
/** Resolves an alias whose target is an alias, carrying over the target's type-only declaration. */
|
|
1118
|
+
export function resolveIndirectionAlias(c, source, target) {
|
|
1119
|
+
const result = getMergedSymbol(c, resolveAlias(c, target));
|
|
1120
|
+
const targetDeclaration = c.symbolLinks(target).typeOnlyDeclaration;
|
|
1121
|
+
if (targetDeclaration !== undefined) {
|
|
1122
|
+
const sourceLinks = c.symbolLinks(source);
|
|
1123
|
+
if (sourceLinks.typeOnlyDeclaration === undefined)
|
|
1124
|
+
sourceLinks.typeOnlyDeclaration = targetDeclaration;
|
|
1125
|
+
}
|
|
1126
|
+
return result;
|
|
1127
|
+
}
|
|
1128
|
+
export function getTypeOnlyAliasDeclaration(c, symbol) {
|
|
1129
|
+
if ((symbol.flags & 2097152 /* SymbolFlags.Alias */) === 0)
|
|
1130
|
+
return undefined;
|
|
1131
|
+
resolveAlias(c, symbol);
|
|
1132
|
+
return c.symbolLinks(symbol).typeOnlyDeclaration;
|
|
1133
|
+
}
|
|
1134
|
+
/** The first type-only declaration along the alias chain of `symbol` before one with `meaning`. */
|
|
1135
|
+
export function getTypeOnlyAliasDeclarationOfMeaning(c, symbol, meaning) {
|
|
1136
|
+
while ((symbol.flags & 2097152 /* SymbolFlags.Alias */) !== 0 && (symbol.flags & meaning) === 0) {
|
|
1137
|
+
const resolved = resolveAlias(c, symbol);
|
|
1138
|
+
const declaration = c.symbolLinks(symbol).typeOnlyDeclaration;
|
|
1139
|
+
if (declaration !== undefined)
|
|
1140
|
+
return declaration;
|
|
1141
|
+
symbol = resolved;
|
|
1142
|
+
}
|
|
1143
|
+
return undefined;
|
|
1144
|
+
}
|
|
1145
|
+
function addTypeOnlyDeclarationRelatedInfo(diagnostic, typeOnlyDeclaration, name) {
|
|
1146
|
+
if (typeOnlyDeclaration === undefined)
|
|
1147
|
+
return;
|
|
1148
|
+
const isExport = typeOnlyDeclaration.kind === 282 /* SyntaxKind.ExportSpecifier */ ||
|
|
1149
|
+
typeOnlyDeclaration.kind === 279 /* SyntaxKind.ExportDeclaration */ ||
|
|
1150
|
+
typeOnlyDeclaration.kind === 281 /* SyntaxKind.NamespaceExport */;
|
|
1151
|
+
diagnostic.addRelatedInfo(createDiagnosticForNode(typeOnlyDeclaration, isExport ? 306 /* Diagnostics.X_0_was_exported_here */ : 305 /* Diagnostics.X_0_was_imported_here */, [name]));
|
|
1152
|
+
}
|
|
1153
|
+
/** Reports a value use of a name that only resolves to a value through a type-only import or export. */
|
|
1154
|
+
export function checkTypeOnlyAliasUse(c, location, result, name) {
|
|
1155
|
+
if ((result.flags & 2097152 /* SymbolFlags.Alias */) === 0 ||
|
|
1156
|
+
(result.flags & 111551 /* SymbolFlags.Value */) !== 0 ||
|
|
1157
|
+
isValidTypeOnlyAliasUseSite(location))
|
|
1158
|
+
return;
|
|
1159
|
+
const typeOnlyDeclaration = getTypeOnlyAliasDeclarationOfMeaning(c, result, 111551 /* SymbolFlags.Value */);
|
|
1160
|
+
if (typeOnlyDeclaration === undefined)
|
|
1161
|
+
return;
|
|
1162
|
+
const isExport = typeOnlyDeclaration.kind === 282 /* SyntaxKind.ExportSpecifier */ ||
|
|
1163
|
+
typeOnlyDeclaration.kind === 279 /* SyntaxKind.ExportDeclaration */ ||
|
|
1164
|
+
typeOnlyDeclaration.kind === 281 /* SyntaxKind.NamespaceExport */;
|
|
1165
|
+
const diagnostic = c.error(location, isExport
|
|
1166
|
+
? 296 /* Diagnostics.X_0_cannot_be_used_as_a_value_because_it_was_exported_using_export_type */
|
|
1167
|
+
: 295 /* Diagnostics.X_0_cannot_be_used_as_a_value_because_it_was_imported_using_import_type */, name);
|
|
1168
|
+
addTypeOnlyDeclarationRelatedInfo(diagnostic, typeOnlyDeclaration, name);
|
|
1169
|
+
}
|
|
1170
|
+
export function isValidTypeOnlyAliasUseSite(useSite) {
|
|
1171
|
+
return ((useSite.flags & (8388608 /* NodeFlags.Ambient */ | 4194304 /* NodeFlags.JSDoc */)) !== 0 ||
|
|
1172
|
+
isPartOfTypeQuery(useSite) ||
|
|
1173
|
+
isIdentifierInNonEmittingHeritageClause(useSite) ||
|
|
1174
|
+
isPartOfPossiblyValidTypeOrAbstractComputedPropertyName(useSite) ||
|
|
1175
|
+
!(isExpressionNode(useSite) || isShorthandPropertyNameUseSite(useSite)));
|
|
1176
|
+
}
|
|
1177
|
+
function isIdentifierInNonEmittingHeritageClause(node) {
|
|
1178
|
+
if (node.kind !== 79 /* SyntaxKind.Identifier */)
|
|
1179
|
+
return false;
|
|
1180
|
+
let parent = node.parent;
|
|
1181
|
+
while (parent.kind === 212 /* SyntaxKind.PropertyAccessExpression */ || parent.kind === 234 /* SyntaxKind.ExpressionWithTypeArguments */)
|
|
1182
|
+
parent = parent.parent;
|
|
1183
|
+
return (parent.kind === 299 /* SyntaxKind.HeritageClause */ &&
|
|
1184
|
+
(parent.token === 118 /* SyntaxKind.ImplementsKeyword */ ||
|
|
1185
|
+
parent.parent.kind === 265 /* SyntaxKind.InterfaceDeclaration */));
|
|
1186
|
+
}
|
|
1187
|
+
function isPartOfPossiblyValidTypeOrAbstractComputedPropertyName(node) {
|
|
1188
|
+
let current = node;
|
|
1189
|
+
while (current.kind === 79 /* SyntaxKind.Identifier */ || current.kind === 212 /* SyntaxKind.PropertyAccessExpression */)
|
|
1190
|
+
current = current.parent;
|
|
1191
|
+
if (current.kind !== 168 /* SyntaxKind.ComputedPropertyName */)
|
|
1192
|
+
return false;
|
|
1193
|
+
if (hasSyntacticModifier(current.parent, 64 /* ModifierFlags.Abstract */))
|
|
1194
|
+
return true;
|
|
1195
|
+
const container = current.parent.parent.kind;
|
|
1196
|
+
return container === 265 /* SyntaxKind.InterfaceDeclaration */ || container === 188 /* SyntaxKind.TypeLiteral */;
|
|
1197
|
+
}
|
|
1198
|
+
function isShorthandPropertyNameUseSite(useSite) {
|
|
1199
|
+
return (useSite.kind === 79 /* SyntaxKind.Identifier */ &&
|
|
1200
|
+
useSite.parent.kind === 304 /* SyntaxKind.ShorthandPropertyAssignment */ &&
|
|
1201
|
+
getName(useSite.parent) === useSite);
|
|
1202
|
+
}
|
|
1203
|
+
// ---- Referenced aliases
|
|
1204
|
+
/**
|
|
1205
|
+
* Whether aliases are marked as referenced, which decides the imports emit keeps. Under
|
|
1206
|
+
* verbatimModuleSyntax, emit keeps every import that isn't type-only, so they aren't.
|
|
1207
|
+
*/
|
|
1208
|
+
function marksReferencedAliases(c) {
|
|
1209
|
+
return c.compilerOptions.verbatimModuleSyntax !== true;
|
|
1210
|
+
}
|
|
1211
|
+
/** Marks the aliases an identifier in an expression uses as referenced. */
|
|
1212
|
+
export function markIdentifierAliasReferencedInExpression(c, node) {
|
|
1213
|
+
if (!marksReferencedAliases(c))
|
|
1214
|
+
return;
|
|
1215
|
+
if ((node.flags & 8388608 /* NodeFlags.Ambient */) !== 0 || !shouldMarkIdentifierAliasReferenced(node))
|
|
1216
|
+
return;
|
|
1217
|
+
markIdentifierAliasReferenced(c, node);
|
|
1218
|
+
}
|
|
1219
|
+
/** Resolves the alias side of a referenced symbol, which may also be a local variable. */
|
|
1220
|
+
export function resolveAliasOfReference(c, symbol) {
|
|
1221
|
+
if ((symbol.flags & 2097152 /* SymbolFlags.Alias */) !== 0 && getDeclarationOfAliasSymbol(symbol) !== undefined)
|
|
1222
|
+
resolveAlias(c, symbol);
|
|
1223
|
+
}
|
|
1224
|
+
function shouldMarkIdentifierAliasReferenced(node) {
|
|
1225
|
+
const parent = node.parent;
|
|
1226
|
+
if (parent === undefined)
|
|
1227
|
+
return true;
|
|
1228
|
+
// The left of a property access is marked with the property.
|
|
1229
|
+
if (parent.kind === 212 /* SyntaxKind.PropertyAccessExpression */ && getExpression(parent) === node)
|
|
1230
|
+
return false;
|
|
1231
|
+
// Names of type-only exports aren't emitted.
|
|
1232
|
+
if (parent.kind === 282 /* SyntaxKind.ExportSpecifier */ && getIsTypeOnly(parent))
|
|
1233
|
+
return false;
|
|
1234
|
+
const greatGrandparent = parent.parent?.parent;
|
|
1235
|
+
return !(greatGrandparent !== undefined &&
|
|
1236
|
+
greatGrandparent.kind === 279 /* SyntaxKind.ExportDeclaration */ &&
|
|
1237
|
+
getIsTypeOnly(greatGrandparent));
|
|
1238
|
+
}
|
|
1239
|
+
/**
|
|
1240
|
+
* Marks the alias on the left of a property access as referenced, unless the access reads a const
|
|
1241
|
+
* enum (or a module of only const enums) that is inlined.
|
|
1242
|
+
*/
|
|
1243
|
+
export function markPropertyAliasReferenced(c, location, prop, leftType) {
|
|
1244
|
+
if (!marksReferencedAliases(c))
|
|
1245
|
+
return;
|
|
1246
|
+
if ((location.flags & 8388608 /* NodeFlags.Ambient */) !== 0 || isPartOfImportEqualsModuleReference(location))
|
|
1247
|
+
return;
|
|
1248
|
+
const left = location.kind === 212 /* SyntaxKind.PropertyAccessExpression */ ? getExpression(location) : location.left;
|
|
1249
|
+
if (left.kind !== 79 /* SyntaxKind.Identifier */ || getText(left) === 'this')
|
|
1250
|
+
return;
|
|
1251
|
+
const parentSymbol = getResolvedSymbol(c, left);
|
|
1252
|
+
if (parentSymbol === c.unknownSymbol)
|
|
1253
|
+
return;
|
|
1254
|
+
if (c.isolatedModules ||
|
|
1255
|
+
(c.preserveConstEnums && isExportOrExportExpression(location)) ||
|
|
1256
|
+
(leftType.flags & 1 /* TypeFlags.Any */) !== 0 ||
|
|
1257
|
+
leftType === c.silentNeverType) {
|
|
1258
|
+
markAliasReferenced(c, parentSymbol, location);
|
|
1259
|
+
return;
|
|
1260
|
+
}
|
|
1261
|
+
if (prop !== undefined &&
|
|
1262
|
+
(isConstEnumOrConstEnumOnlyModule(prop) ||
|
|
1263
|
+
((prop.flags & 8 /* SymbolFlags.EnumMember */) !== 0 && location.parent.kind === 306 /* SyntaxKind.EnumMember */)))
|
|
1264
|
+
return;
|
|
1265
|
+
markAliasReferenced(c, parentSymbol, location);
|
|
1266
|
+
}
|
|
1267
|
+
function isPartOfImportEqualsModuleReference(location) {
|
|
1268
|
+
let importEquals = location;
|
|
1269
|
+
while (importEquals !== undefined && importEquals.kind !== 272 /* SyntaxKind.ImportEqualsDeclaration */)
|
|
1270
|
+
importEquals = importEquals.parent;
|
|
1271
|
+
if (importEquals === undefined)
|
|
1272
|
+
return false;
|
|
1273
|
+
const reference = importEquals.moduleReference;
|
|
1274
|
+
for (let node = location; node !== undefined && node !== importEquals; node = node.parent)
|
|
1275
|
+
if (node === reference)
|
|
1276
|
+
return true;
|
|
1277
|
+
return false;
|
|
1278
|
+
}
|
|
1279
|
+
function markIdentifierAliasReferenced(c, location) {
|
|
1280
|
+
const symbol = getResolvedSymbol(c, location);
|
|
1281
|
+
if (symbol !== c.argumentsSymbol && symbol !== c.unknownSymbol)
|
|
1282
|
+
markAliasReferenced(c, symbol, location);
|
|
1283
|
+
}
|
|
1284
|
+
function markAliasReferenced(c, symbol, location) {
|
|
1285
|
+
if (!marksReferencedAliases(c))
|
|
1286
|
+
return;
|
|
1287
|
+
if (!isNonLocalAlias(symbol, 111551 /* SymbolFlags.Value */) || isPartOfTypeQuery(location))
|
|
1288
|
+
return;
|
|
1289
|
+
const target = resolveAlias(c, symbol);
|
|
1290
|
+
if ((getSymbolFlagsExcludingTypeOnly(c, symbol) & (111551 /* SymbolFlags.Value */ | 1048576 /* SymbolFlags.ExportValue */)) === 0)
|
|
1291
|
+
return;
|
|
1292
|
+
// An alias of a const enum can be elided unless the enum is kept.
|
|
1293
|
+
if (c.isolatedModules ||
|
|
1294
|
+
(c.preserveConstEnums && isExportOrExportExpression(location)) ||
|
|
1295
|
+
!isConstEnumOrConstEnumOnlyModule(getExportSymbolOfValueSymbolIfExported(c, target)))
|
|
1296
|
+
markAliasSymbolAsReferenced(c, symbol);
|
|
1297
|
+
}
|
|
1298
|
+
/**
|
|
1299
|
+
* Marks an alias as referenced; an `import a = b.c` whose target is a value then references `b`,
|
|
1300
|
+
* resolving it as a value.
|
|
1301
|
+
*/
|
|
1302
|
+
function markAliasSymbolAsReferenced(c, symbol) {
|
|
1303
|
+
const links = c.symbolLinks(symbol);
|
|
1304
|
+
if (links.aliasReferenced)
|
|
1305
|
+
return;
|
|
1306
|
+
links.aliasReferenced = true;
|
|
1307
|
+
const node = getDeclarationOfAliasSymbol(symbol);
|
|
1308
|
+
if (node !== undefined &&
|
|
1309
|
+
node.kind === 272 /* SyntaxKind.ImportEqualsDeclaration */ &&
|
|
1310
|
+
node.moduleReference.kind !== 284 /* SyntaxKind.ExternalModuleReference */ &&
|
|
1311
|
+
(getSymbolFlags(c, resolveSymbol(c, symbol)) & 111551 /* SymbolFlags.Value */) !== 0)
|
|
1312
|
+
markIdentifierAliasReferenced(c, getFirstIdentifierOfEntityName(node.moduleReference));
|
|
1313
|
+
}
|
|
1314
|
+
function markExportAsReferenced(c, node) {
|
|
1315
|
+
if (!marksReferencedAliases(c))
|
|
1316
|
+
return;
|
|
1317
|
+
const symbol = getSymbolOfDeclaration(c, node);
|
|
1318
|
+
if (symbol === undefined)
|
|
1319
|
+
return;
|
|
1320
|
+
const target = resolveAlias(c, symbol);
|
|
1321
|
+
if (target === c.unknownSymbol ||
|
|
1322
|
+
((getSymbolFlagsExcludingTypeOnly(c, symbol) & 111551 /* SymbolFlags.Value */) !== 0 &&
|
|
1323
|
+
!isConstEnumOrConstEnumOnlyModule(target)))
|
|
1324
|
+
markAliasSymbolAsReferenced(c, symbol);
|
|
1325
|
+
}
|
|
1326
|
+
function markExportSpecifierAliasReferenced(c, node, symbol, exportedName) {
|
|
1327
|
+
if (!marksReferencedAliases(c))
|
|
1328
|
+
return;
|
|
1329
|
+
if ((node.flags & 8388608 /* NodeFlags.Ambient */) !== 0 || getIsTypeOnly(node) || getIsTypeOnly(node.parent.parent))
|
|
1330
|
+
return;
|
|
1331
|
+
let target = symbol;
|
|
1332
|
+
if (target !== undefined && (target.flags & 2097152 /* SymbolFlags.Alias */) !== 0)
|
|
1333
|
+
target = resolveAlias(c, target);
|
|
1334
|
+
if (target === undefined || (getSymbolFlags(c, target) & 111551 /* SymbolFlags.Value */) !== 0) {
|
|
1335
|
+
markExportAsReferenced(c, node);
|
|
1336
|
+
markIdentifierAliasReferenced(c, exportedName);
|
|
1337
|
+
}
|
|
1338
|
+
}
|
|
1339
|
+
function isConstEnumOrConstEnumOnlyModule(symbol) {
|
|
1340
|
+
return (symbol.flags & (128 /* SymbolFlags.ConstEnum */ | 268435456 /* SymbolFlags.ConstEnumOnlyModule */)) !== 0;
|
|
1341
|
+
}
|
|
1342
|
+
function isExportOrExportExpression(location) {
|
|
1343
|
+
for (let n = location; n !== undefined; n = n.parent) {
|
|
1344
|
+
const parent = n.parent;
|
|
1345
|
+
if (parent === undefined)
|
|
1346
|
+
return false;
|
|
1347
|
+
if (parent.kind === 278 /* SyntaxKind.ExportAssignment */)
|
|
1348
|
+
return (getExpression(parent) === n && isEntityNameOrEntityNameExpression(n) && n.kind !== 167 /* SyntaxKind.QualifiedName */);
|
|
1349
|
+
if (parent.kind === 282 /* SyntaxKind.ExportSpecifier */) {
|
|
1350
|
+
if (getName(parent) === n || getPropertyName(parent) === n)
|
|
1351
|
+
return true;
|
|
1352
|
+
}
|
|
1353
|
+
}
|
|
1354
|
+
return false;
|
|
1355
|
+
}
|
|
1356
|
+
/** `getSymbolFlags`, stopping at the first type-only alias along the chain. */
|
|
1357
|
+
function getSymbolFlagsExcludingTypeOnly(c, symbol) {
|
|
1358
|
+
return getSymbolFlagsEx(c, symbol, true, false);
|
|
1359
|
+
}
|
|
1360
|
+
/** `getSymbolFlags`, optionally stopping at type-only aliases or leaving out the symbol's own flags. */
|
|
1361
|
+
function getSymbolFlagsEx(c, symbol, excludeTypeOnlyMeanings, excludeLocalMeanings) {
|
|
1362
|
+
const seen = new Set();
|
|
1363
|
+
let flags = excludeLocalMeanings ? 0 /* SymbolFlags.None */ : symbol.flags;
|
|
1364
|
+
while ((symbol.flags & 2097152 /* SymbolFlags.Alias */) !== 0) {
|
|
1365
|
+
if (excludeTypeOnlyMeanings && getTypeOnlyAliasDeclaration(c, symbol) !== undefined)
|
|
1366
|
+
break;
|
|
1367
|
+
const target = getExportSymbolOfValueSymbolIfExported(c, resolveAlias(c, symbol));
|
|
1368
|
+
if (target === c.unknownSymbol)
|
|
1369
|
+
return 1073741823 /* SymbolFlags.All */;
|
|
1370
|
+
if ((target.flags & 2097152 /* SymbolFlags.Alias */) !== 0) {
|
|
1371
|
+
if (target === symbol || seen.has(target))
|
|
1372
|
+
break;
|
|
1373
|
+
seen.add(symbol);
|
|
1374
|
+
seen.add(target);
|
|
1375
|
+
}
|
|
1376
|
+
flags |= target.flags;
|
|
1377
|
+
symbol = target;
|
|
1378
|
+
}
|
|
1379
|
+
return flags;
|
|
1380
|
+
}
|
|
1381
|
+
// ---- Module exports
|
|
1382
|
+
/** Own exports plus those re-exported with `export *`; own exports shadow re-exported ones. */
|
|
1383
|
+
export function getExportsOfModuleWorker(c, moduleSymbol) {
|
|
1384
|
+
const collector = new ExportCollector(c);
|
|
1385
|
+
const exportEquals = moduleSymbol.exports?.get("export=" /* InternalSymbolName.ExportEquals */);
|
|
1386
|
+
const originalModule = exportEquals !== undefined && resolveSymbolEx(c, exportEquals, false) !== undefined ? moduleSymbol : undefined;
|
|
1387
|
+
const resolvedModule = resolveExternalModuleSymbol(c, moduleSymbol, false);
|
|
1388
|
+
const exports = collector.visit(resolvedModule, undefined, false) ?? new Map();
|
|
1389
|
+
// A CommonJS module with `export =` may also export types, stored on the original module.
|
|
1390
|
+
if (originalModule !== undefined && originalModule.exports !== undefined && originalModule.exports.size > 1) {
|
|
1391
|
+
for (const symbol of originalModule.exports.values()) {
|
|
1392
|
+
if (symbol.name === "export=" /* InternalSymbolName.ExportEquals */ || symbol.name === "\uFFFEexport" /* InternalSymbolName.ExportStar */)
|
|
1393
|
+
continue;
|
|
1394
|
+
const flags = getSymbolFlags(c, symbol);
|
|
1395
|
+
if ((flags & (788968 /* SymbolFlags.Type */ | 1920 /* SymbolFlags.Namespace */)) !== 0 &&
|
|
1396
|
+
(flags & 111551 /* SymbolFlags.Value */) === 0 &&
|
|
1397
|
+
!exports.has(symbol.name))
|
|
1398
|
+
exports.set(symbol.name, symbol);
|
|
1399
|
+
}
|
|
1400
|
+
}
|
|
1401
|
+
const typeOnlyExportStarMap = collector.typeOnlyExportStarMap;
|
|
1402
|
+
if (typeOnlyExportStarMap !== undefined) {
|
|
1403
|
+
for (const name of collector.nonTypeOnlyNames)
|
|
1404
|
+
typeOnlyExportStarMap.delete(name);
|
|
1405
|
+
c.symbolLinks(moduleSymbol).typeOnlyExportStarMap = typeOnlyExportStarMap;
|
|
1406
|
+
}
|
|
1407
|
+
return exports;
|
|
1408
|
+
}
|
|
1409
|
+
/** A name re-exported by several `export *` declarations. */
|
|
1410
|
+
class ExportCollision {
|
|
1411
|
+
specifierText;
|
|
1412
|
+
exportsWithDuplicate = [];
|
|
1413
|
+
constructor(specifierText) {
|
|
1414
|
+
this.specifierText = specifierText;
|
|
1415
|
+
}
|
|
1416
|
+
}
|
|
1417
|
+
class ExportCollector {
|
|
1418
|
+
c;
|
|
1419
|
+
visited = [];
|
|
1420
|
+
nonTypeOnlyNames = new Set();
|
|
1421
|
+
typeOnlyExportStarMap = undefined;
|
|
1422
|
+
constructor(c) {
|
|
1423
|
+
this.c = c;
|
|
1424
|
+
}
|
|
1425
|
+
// Modules may re-export each other circularly.
|
|
1426
|
+
visit(symbol, exportStar, isTypeOnly) {
|
|
1427
|
+
if (!isTypeOnly && symbol !== undefined && symbol.exports !== undefined)
|
|
1428
|
+
// Added before the visited check: `export *` overrides an earlier `export type *` of the same module.
|
|
1429
|
+
for (const name of symbol.exports.keys())
|
|
1430
|
+
this.nonTypeOnlyNames.add(name);
|
|
1431
|
+
if (symbol === undefined || symbol.exports === undefined || this.visited.includes(symbol))
|
|
1432
|
+
return undefined;
|
|
1433
|
+
this.visited.push(symbol);
|
|
1434
|
+
const symbols = new Map(symbol.exports);
|
|
1435
|
+
const exportStars = symbol.exports.get("\uFFFEexport" /* InternalSymbolName.ExportStar */);
|
|
1436
|
+
if (exportStars !== undefined) {
|
|
1437
|
+
const nested = new Map();
|
|
1438
|
+
const lookupTable = new Map();
|
|
1439
|
+
for (const node of exportStars.declarations) {
|
|
1440
|
+
const specifier = node.moduleSpecifier;
|
|
1441
|
+
const resolved = resolveExternalModuleName(this.c, node, specifier, false);
|
|
1442
|
+
const exported = this.visit(resolved, node, isTypeOnly || getIsTypeOnly(node));
|
|
1443
|
+
this.extendExportSymbols(nested, exported, lookupTable, node);
|
|
1444
|
+
}
|
|
1445
|
+
for (const [id, collision] of lookupTable) {
|
|
1446
|
+
// A module that exports the name itself resolves the ambiguity.
|
|
1447
|
+
if (id === "export=" /* InternalSymbolName.ExportEquals */ || collision.exportsWithDuplicate.length === 0 || symbols.has(id))
|
|
1448
|
+
continue;
|
|
1449
|
+
for (const node of collision.exportsWithDuplicate)
|
|
1450
|
+
this.c.error(node, 486 /* Diagnostics.Module_0_has_already_exported_a_member_named_1_Consider_explicitly_re_exporting_to_resolve_the_ambiguity */, collision.specifierText, id);
|
|
1451
|
+
}
|
|
1452
|
+
this.extendExportSymbols(symbols, nested, undefined, undefined);
|
|
1453
|
+
}
|
|
1454
|
+
if (exportStar !== undefined && getIsTypeOnly(exportStar)) {
|
|
1455
|
+
if (this.typeOnlyExportStarMap === undefined)
|
|
1456
|
+
this.typeOnlyExportStarMap = new Map();
|
|
1457
|
+
for (const name of symbols.keys())
|
|
1458
|
+
this.typeOnlyExportStarMap.set(name, exportStar);
|
|
1459
|
+
}
|
|
1460
|
+
return symbols;
|
|
1461
|
+
}
|
|
1462
|
+
extendExportSymbols(target, source, lookupTable, exportNode) {
|
|
1463
|
+
if (source === undefined)
|
|
1464
|
+
return;
|
|
1465
|
+
for (const [id, sourceSymbol] of source) {
|
|
1466
|
+
if (id === "default" /* InternalSymbolName.Default */)
|
|
1467
|
+
continue;
|
|
1468
|
+
const targetSymbol = target.get(id);
|
|
1469
|
+
if (targetSymbol === undefined) {
|
|
1470
|
+
target.set(id, sourceSymbol);
|
|
1471
|
+
if (lookupTable !== undefined && exportNode !== undefined) {
|
|
1472
|
+
const specifier = exportNode.moduleSpecifier;
|
|
1473
|
+
lookupTable.set(id, new ExportCollision(getSourceTextOfNode(getSourceFileOfNode(specifier), specifier)));
|
|
1474
|
+
}
|
|
1475
|
+
}
|
|
1476
|
+
else if (lookupTable !== undefined &&
|
|
1477
|
+
exportNode !== undefined &&
|
|
1478
|
+
resolveSymbol(this.c, targetSymbol) !== resolveSymbol(this.c, sourceSymbol))
|
|
1479
|
+
lookupTable.get(id)?.exportsWithDuplicate.push(exportNode);
|
|
1480
|
+
}
|
|
1481
|
+
}
|
|
1482
|
+
}
|
|
1483
|
+
// ---- Import types and dynamic imports
|
|
1484
|
+
/** The type of `import("m")`, `import("m").T` or `typeof import("m").v`. */
|
|
1485
|
+
export function getTypeFromImportTypeNode(c, node) {
|
|
1486
|
+
const type = c.resolvedTypes.get(node.id);
|
|
1487
|
+
if (type !== undefined)
|
|
1488
|
+
return type;
|
|
1489
|
+
const importType = node;
|
|
1490
|
+
if (!isLiteralImportTypeNode(node)) {
|
|
1491
|
+
c.error(importType.argument, 107 /* Diagnostics.String_literal_expected */);
|
|
1492
|
+
c.resolvedSymbols.set(node.id, c.unknownSymbol);
|
|
1493
|
+
c.resolvedTypes.set(node.id, c.errorType);
|
|
1494
|
+
return c.resolvedTypes.get(node.id);
|
|
1495
|
+
}
|
|
1496
|
+
const targetMeaning = importType.isTypeOf ? 111551 /* SymbolFlags.Value */ : 788968 /* SymbolFlags.Type */;
|
|
1497
|
+
const literal = importType.argument.literal;
|
|
1498
|
+
const innerModuleSymbol = resolveExternalModuleName(c, node, literal, false);
|
|
1499
|
+
if (innerModuleSymbol === undefined) {
|
|
1500
|
+
c.resolvedSymbols.set(node.id, c.unknownSymbol);
|
|
1501
|
+
c.resolvedTypes.set(node.id, c.errorType);
|
|
1502
|
+
return c.resolvedTypes.get(node.id);
|
|
1503
|
+
}
|
|
1504
|
+
const moduleSymbol = resolveExternalModuleSymbol(c, innerModuleSymbol, false);
|
|
1505
|
+
const qualifier = importType.qualifier;
|
|
1506
|
+
if (qualifier !== undefined && !nodeIsMissing(qualifier)) {
|
|
1507
|
+
const nameChain = getIdentifierChain(qualifier);
|
|
1508
|
+
let currentNamespace = moduleSymbol;
|
|
1509
|
+
for (let i = 0; i < nameChain.length; i++) {
|
|
1510
|
+
const current = nameChain[i];
|
|
1511
|
+
const meaning = i === nameChain.length - 1 ? targetMeaning : 1920 /* SymbolFlags.Namespace */;
|
|
1512
|
+
const merged = getMergedSymbol(c, resolveSymbol(c, currentNamespace));
|
|
1513
|
+
const text = getText(current);
|
|
1514
|
+
const next = importType.isTypeOf
|
|
1515
|
+
? getPropertyOfTypeEx(c, getTypeOfSymbol(c, merged), text, false, true)
|
|
1516
|
+
: getSymbolOfMeaning(c, getExportsOfSymbol(c, merged), text, meaning);
|
|
1517
|
+
if (next === undefined) {
|
|
1518
|
+
c.error(current, 826 /* Diagnostics.Namespace_0_has_no_exported_member_1 */, getFullyQualifiedName(c, currentNamespace), declarationNameToString(getSourceFileOfNode(current), current));
|
|
1519
|
+
c.resolvedTypes.set(node.id, c.errorType);
|
|
1520
|
+
return c.resolvedTypes.get(node.id);
|
|
1521
|
+
}
|
|
1522
|
+
c.resolvedSymbols.set(current.id, next);
|
|
1523
|
+
c.resolvedSymbols.set(current.parent.id, next);
|
|
1524
|
+
currentNamespace = next;
|
|
1525
|
+
}
|
|
1526
|
+
c.resolvedTypes.set(node.id, resolveImportSymbolType(c, node, currentNamespace, targetMeaning));
|
|
1527
|
+
}
|
|
1528
|
+
else if ((getSymbolFlags(c, moduleSymbol) & targetMeaning) !== 0) {
|
|
1529
|
+
c.resolvedTypes.set(node.id, resolveImportSymbolType(c, node, moduleSymbol, targetMeaning));
|
|
1530
|
+
}
|
|
1531
|
+
else {
|
|
1532
|
+
c.error(node, targetMeaning === 111551 /* SymbolFlags.Value */
|
|
1533
|
+
? 274 /* Diagnostics.Module_0_does_not_refer_to_a_value_but_is_used_as_a_value_here */
|
|
1534
|
+
: 275 /* Diagnostics.Module_0_does_not_refer_to_a_type_but_is_used_as_a_type_here_Did_you_mean_typeof_import_0 */, getText(literal));
|
|
1535
|
+
c.resolvedSymbols.set(node.id, c.unknownSymbol);
|
|
1536
|
+
c.resolvedTypes.set(node.id, c.errorType);
|
|
1537
|
+
}
|
|
1538
|
+
return c.resolvedTypes.get(node.id);
|
|
1539
|
+
}
|
|
1540
|
+
function getIdentifierChain(node) {
|
|
1541
|
+
if (node.kind === 79 /* SyntaxKind.Identifier */)
|
|
1542
|
+
return [node];
|
|
1543
|
+
const chain = getIdentifierChain(node.left);
|
|
1544
|
+
chain.push(node.right);
|
|
1545
|
+
return chain;
|
|
1546
|
+
}
|
|
1547
|
+
function resolveImportSymbolType(c, node, symbol, meaning) {
|
|
1548
|
+
const resolvedSymbol = resolveSymbol(c, symbol);
|
|
1549
|
+
c.resolvedSymbols.set(node.id, resolvedSymbol);
|
|
1550
|
+
// The alias itself caches the type of a value.
|
|
1551
|
+
if (meaning === 111551 /* SymbolFlags.Value */)
|
|
1552
|
+
return getTypeOfSymbol(c, symbol);
|
|
1553
|
+
return getTypeReferenceType(c, node, resolvedSymbol);
|
|
1554
|
+
}
|
|
1555
|
+
/** `import(specifier, options)`: a promise of the module namespace. */
|
|
1556
|
+
export function checkImportCallExpression(c, node) {
|
|
1557
|
+
const args = node.arguments.nodes;
|
|
1558
|
+
if (args.length === 0)
|
|
1559
|
+
return createPromiseReturnType(c, node, c.anyType);
|
|
1560
|
+
const specifier = args[0];
|
|
1561
|
+
const specifierType = checkExpressionCached(c, specifier);
|
|
1562
|
+
const optionsType = args.length > 1 ? checkExpressionCached(c, args[1]) : undefined;
|
|
1563
|
+
// Extra arguments are a grammar error; check them for completions.
|
|
1564
|
+
for (let i = 2; i < args.length; i++)
|
|
1565
|
+
checkExpressionCached(c, args[i]);
|
|
1566
|
+
if ((specifierType.flags & 12 /* TypeFlags.Nullable */) !== 0 || !isTypeAssignableTo(c, specifierType, c.stringType))
|
|
1567
|
+
c.error(specifier, 1707 /* Diagnostics.Dynamic_import_s_specifier_must_be_of_type_string_but_here_has_type_0 */, typeToString(c, specifierType));
|
|
1568
|
+
if (optionsType !== undefined) {
|
|
1569
|
+
const importCallOptionsType = getCachedGlobalType(c, 'ImportCallOptions', 0, true);
|
|
1570
|
+
if (importCallOptionsType !== c.emptyObjectType)
|
|
1571
|
+
checkTypeAssignableTo(c, optionsType, getNullableType(c, importCallOptionsType, 4 /* TypeFlags.Undefined */), args[1], undefined);
|
|
1572
|
+
if (args[1].kind === 211 /* SyntaxKind.ObjectLiteralExpression */)
|
|
1573
|
+
for (const property of args[1].properties.nodes) {
|
|
1574
|
+
const name = getName(property);
|
|
1575
|
+
if (property.kind === 303 /* SyntaxKind.PropertyAssignment */ &&
|
|
1576
|
+
name !== undefined &&
|
|
1577
|
+
name.kind === 79 /* SyntaxKind.Identifier */ &&
|
|
1578
|
+
getText(name) === 'assert') {
|
|
1579
|
+
c.error(name, 1000 /* Diagnostics.Import_assertions_have_been_replaced_by_import_attributes_Use_with_instead_of_assert */);
|
|
1580
|
+
break;
|
|
1581
|
+
}
|
|
1582
|
+
}
|
|
1583
|
+
}
|
|
1584
|
+
const moduleSymbol = resolveExternalModuleName(c, node, specifier, false);
|
|
1585
|
+
if (moduleSymbol !== undefined) {
|
|
1586
|
+
const esModuleSymbol = resolveExternalModuleSymbol(c, moduleSymbol, true);
|
|
1587
|
+
if (esModuleSymbol !== undefined)
|
|
1588
|
+
return createPromiseReturnType(c, node, getTypeWithSyntheticDefaultOnly(c, getTypeOfSymbol(c, esModuleSymbol), esModuleSymbol, moduleSymbol, specifier) ??
|
|
1589
|
+
getTypeWithSyntheticDefaultImportType(c, getTypeOfSymbol(c, esModuleSymbol), esModuleSymbol, moduleSymbol, specifier));
|
|
1590
|
+
}
|
|
1591
|
+
return createPromiseReturnType(c, node, c.anyType);
|
|
1592
|
+
}
|
|
1593
|
+
function createPromiseReturnType(c, node, promisedType) {
|
|
1594
|
+
const promiseType = createPromiseType(c, promisedType);
|
|
1595
|
+
if (promiseType !== c.unknownType)
|
|
1596
|
+
return promiseType;
|
|
1597
|
+
c.error(node, 843 /* Diagnostics.A_dynamic_import_call_returns_a_Promise_Make_sure_you_have_a_declaration_for_Promise_or_include_ES2015_in_your_lib_option */);
|
|
1598
|
+
return c.errorType;
|
|
1599
|
+
}
|
|
1600
|
+
// ---- JSDoc links
|
|
1601
|
+
/** The symbol a `{@link}` name refers to, as an entity or a member of one. */
|
|
1602
|
+
export function resolveJSDocMemberName(c, name) {
|
|
1603
|
+
if (name === undefined || (name.kind !== 79 /* SyntaxKind.Identifier */ && name.kind !== 167 /* SyntaxKind.QualifiedName */))
|
|
1604
|
+
return undefined;
|
|
1605
|
+
const meaning = 788968 /* SymbolFlags.Type */ | 1920 /* SymbolFlags.Namespace */ | 111551 /* SymbolFlags.Value */;
|
|
1606
|
+
const symbol = resolveEntityName(c, name, meaning, true, true, getHostSignatureFromJSDoc(name));
|
|
1607
|
+
if (symbol !== undefined)
|
|
1608
|
+
return symbol;
|
|
1609
|
+
if (name.kind !== 167 /* SyntaxKind.QualifiedName */)
|
|
1610
|
+
return undefined;
|
|
1611
|
+
const left = resolveJSDocMemberName(c, name.left);
|
|
1612
|
+
if (left === undefined)
|
|
1613
|
+
return undefined;
|
|
1614
|
+
let type;
|
|
1615
|
+
if ((left.flags & 111551 /* SymbolFlags.Value */) !== 0) {
|
|
1616
|
+
const prototype = getPropertyOfType(c, getTypeOfSymbol(c, left), 'prototype');
|
|
1617
|
+
if (prototype !== undefined)
|
|
1618
|
+
type = getTypeOfSymbol(c, prototype);
|
|
1619
|
+
}
|
|
1620
|
+
return getPropertyOfType(c, type ?? getDeclaredTypeOfSymbol(c, left), name.right.text);
|
|
1621
|
+
}
|
|
1622
|
+
export function getHostSignatureFromJSDoc(node) {
|
|
1623
|
+
let current = node;
|
|
1624
|
+
while (current !== undefined && current.kind !== 315 /* SyntaxKind.JSDoc */)
|
|
1625
|
+
current = current.parent;
|
|
1626
|
+
const host = current?.parent;
|
|
1627
|
+
return host !== undefined && isFunctionLike(host) ? host : undefined;
|
|
1628
|
+
}
|
|
1629
|
+
// ---- Meta properties
|
|
1630
|
+
/** `import.meta` and `new.target`. */
|
|
1631
|
+
export function checkMetaProperty(c, node) {
|
|
1632
|
+
const meta = node;
|
|
1633
|
+
if (meta.keywordToken === 104 /* SyntaxKind.NewKeyword */)
|
|
1634
|
+
return checkNewTargetMetaProperty(c, node);
|
|
1635
|
+
// `import.defer` is only valid as a callee.
|
|
1636
|
+
if (meta.name.text === 'defer')
|
|
1637
|
+
return c.errorType;
|
|
1638
|
+
const moduleKind = getEmitModuleKind(c.compilerOptions);
|
|
1639
|
+
if (moduleKind >= ModuleKind.Node16 && moduleKind <= ModuleKind.NodeNext) {
|
|
1640
|
+
if (c.host.getImpliedNodeFormatForEmit(getSourceFileOfNode(node)) === ModuleKind.CommonJS)
|
|
1641
|
+
c.error(node, 385 /* Diagnostics.The_import_meta_meta_property_is_not_allowed_in_files_which_will_build_into_CommonJS_output */);
|
|
1642
|
+
}
|
|
1643
|
+
else if (moduleKind < ModuleKind.ES2020 && moduleKind !== ModuleKind.System)
|
|
1644
|
+
c.error(node, 277 /* Diagnostics.The_import_meta_meta_property_is_only_allowed_when_the_module_option_is_es2020_es2022_esnext_system_node16_node18_node20_or_nodenext */);
|
|
1645
|
+
return meta.name.text === 'meta' ? getCachedGlobalType(c, 'ImportMeta', 0, true) : c.errorType;
|
|
1646
|
+
}
|
|
1647
|
+
export function checkNewTargetMetaProperty(c, node) {
|
|
1648
|
+
const container = getThisContainer(node, false, false);
|
|
1649
|
+
if (container.kind !== 177 /* SyntaxKind.Constructor */ &&
|
|
1650
|
+
container.kind !== 263 /* SyntaxKind.FunctionDeclaration */ &&
|
|
1651
|
+
container.kind !== 219 /* SyntaxKind.FunctionExpression */) {
|
|
1652
|
+
c.error(node, 1816 /* Diagnostics.Meta_property_0_is_only_allowed_in_the_body_of_a_function_declaration_function_expression_or_constructor */, 'new.target');
|
|
1653
|
+
return c.errorType;
|
|
1654
|
+
}
|
|
1655
|
+
const symbol = getSymbolOfDeclaration(c, container.kind === 177 /* SyntaxKind.Constructor */ ? container.parent : container);
|
|
1656
|
+
return symbol !== undefined ? getTypeOfSymbol(c, symbol) : c.errorType;
|
|
1657
|
+
}
|
|
1658
|
+
// ---- Import and export declarations
|
|
1659
|
+
/**
|
|
1660
|
+
* Whether an import or export with a module specifier is in a valid place with a valid specifier;
|
|
1661
|
+
* the grammar checker reports the errors.
|
|
1662
|
+
*/
|
|
1663
|
+
function isValidExternalImportOrExportDeclaration(node) {
|
|
1664
|
+
const moduleName = getExternalModuleName(node);
|
|
1665
|
+
if (moduleName === undefined || nodeIsMissing(moduleName) || moduleName.kind !== 10 /* SyntaxKind.StringLiteral */)
|
|
1666
|
+
return false;
|
|
1667
|
+
const parent = node.parent;
|
|
1668
|
+
const inAmbientExternalModule = parent.kind === 269 /* SyntaxKind.ModuleBlock */ && isAmbientModule(parent.parent);
|
|
1669
|
+
if (parent.kind !== 307 /* SyntaxKind.SourceFile */ && !inAmbientExternalModule)
|
|
1670
|
+
return false;
|
|
1671
|
+
if (inAmbientExternalModule &&
|
|
1672
|
+
isExternalModuleNameRelative(getText(moduleName)) &&
|
|
1673
|
+
!isModuleAugmentationExternal(parent.parent))
|
|
1674
|
+
return false;
|
|
1675
|
+
if (node.kind === 272 /* SyntaxKind.ImportEqualsDeclaration */)
|
|
1676
|
+
return true;
|
|
1677
|
+
const attributes = getImportAttributes(node);
|
|
1678
|
+
if (attributes === undefined)
|
|
1679
|
+
return true;
|
|
1680
|
+
for (const attribute of attributes.attributes.nodes)
|
|
1681
|
+
if (attribute.value.kind !== 10 /* SyntaxKind.StringLiteral */)
|
|
1682
|
+
return false;
|
|
1683
|
+
return true;
|
|
1684
|
+
}
|
|
1685
|
+
function isInModuleElementContext(node) {
|
|
1686
|
+
const parent = node.parent.kind;
|
|
1687
|
+
return (parent === 307 /* SyntaxKind.SourceFile */ || parent === 269 /* SyntaxKind.ModuleBlock */ || parent === 268 /* SyntaxKind.ModuleDeclaration */);
|
|
1688
|
+
}
|
|
1689
|
+
function getImportAttributes(node) {
|
|
1690
|
+
if (node.kind === 273 /* SyntaxKind.ImportDeclaration */ || node.kind === 346 /* SyntaxKind.JSImportDeclaration */)
|
|
1691
|
+
return node.attributes;
|
|
1692
|
+
if (node.kind === 279 /* SyntaxKind.ExportDeclaration */)
|
|
1693
|
+
return node.attributes;
|
|
1694
|
+
return undefined;
|
|
1695
|
+
}
|
|
1696
|
+
/** Whether the grammar checker reports the import clause, which skips its bindings. */
|
|
1697
|
+
function hasImportClauseGrammarError(c, node) {
|
|
1698
|
+
const namedBindings = node.namedBindings;
|
|
1699
|
+
if (node.phaseModifier === 156 /* SyntaxKind.TypeKeyword */) {
|
|
1700
|
+
if ((node.flags & 4194304 /* NodeFlags.JSDoc */) === 0 && node.name !== undefined && namedBindings !== undefined)
|
|
1701
|
+
return !hasParseErrors(node);
|
|
1702
|
+
if (namedBindings !== undefined && namedBindings.kind === 276 /* SyntaxKind.NamedImports */)
|
|
1703
|
+
for (const specifier of namedBindings.elements.nodes)
|
|
1704
|
+
if (getIsTypeOnly(specifier))
|
|
1705
|
+
return !hasParseErrors(node);
|
|
1706
|
+
}
|
|
1707
|
+
else if (node.phaseModifier === 166 /* SyntaxKind.DeferKeyword */) {
|
|
1708
|
+
if (node.name !== undefined)
|
|
1709
|
+
return !hasParseErrors(node);
|
|
1710
|
+
if (namedBindings !== undefined && namedBindings.kind === 276 /* SyntaxKind.NamedImports */)
|
|
1711
|
+
return !hasParseErrors(node);
|
|
1712
|
+
const moduleKind = getEmitModuleKind(c.compilerOptions);
|
|
1713
|
+
if (moduleKind !== ModuleKind.ESNext && moduleKind !== ModuleKind.Preserve)
|
|
1714
|
+
return !hasParseErrors(node);
|
|
1715
|
+
}
|
|
1716
|
+
return false;
|
|
1717
|
+
}
|
|
1718
|
+
function hasParseErrors(node) {
|
|
1719
|
+
return getSourceFileOfNode(node).diagnostics.length > 0;
|
|
1720
|
+
}
|
|
1721
|
+
export function checkImportDeclaration(c, node) {
|
|
1722
|
+
if (!isInModuleElementContext(node) || !isValidExternalImportOrExportDeclaration(node)) {
|
|
1723
|
+
checkImportAttributes(c, node);
|
|
1724
|
+
return;
|
|
1725
|
+
}
|
|
1726
|
+
const declaration = node;
|
|
1727
|
+
const clause = declaration.importClause;
|
|
1728
|
+
if (clause !== undefined && !hasImportClauseGrammarError(c, clause)) {
|
|
1729
|
+
if (clause.name !== undefined)
|
|
1730
|
+
checkImportBinding(c, clause);
|
|
1731
|
+
const namedBindings = clause.namedBindings;
|
|
1732
|
+
let resolvedModule;
|
|
1733
|
+
const emittedAsCommonJS = c.host.getEmitModuleFormatOfFile(getSourceFileOfNode(node)) === ModuleKind.CommonJS;
|
|
1734
|
+
let needsImportStar = false;
|
|
1735
|
+
if (namedBindings !== undefined) {
|
|
1736
|
+
if (namedBindings.kind === 275 /* SyntaxKind.NamespaceImport */) {
|
|
1737
|
+
checkImportBinding(c, namedBindings);
|
|
1738
|
+
if (emittedAsCommonJS) {
|
|
1739
|
+
needsImportStar = true;
|
|
1740
|
+
checkExternalEmitHelpers(c, node, 1024 /* ExternalEmitHelpers.ImportStar */);
|
|
1741
|
+
}
|
|
1742
|
+
}
|
|
1743
|
+
else {
|
|
1744
|
+
resolvedModule = resolveExternalModuleName(c, node, declaration.moduleSpecifier, false);
|
|
1745
|
+
if (resolvedModule !== undefined)
|
|
1746
|
+
for (const binding of namedBindings.elements.nodes)
|
|
1747
|
+
checkImportBinding(c, binding);
|
|
1748
|
+
}
|
|
1749
|
+
}
|
|
1750
|
+
if (clause.name !== undefined && !needsImportStar && emittedAsCommonJS)
|
|
1751
|
+
checkExternalEmitHelpers(c, node, 2048 /* ExternalEmitHelpers.ImportDefault */);
|
|
1752
|
+
const moduleKind = getEmitModuleKind(c.compilerOptions);
|
|
1753
|
+
if (!isTypeOnly(clause) &&
|
|
1754
|
+
moduleKind >= ModuleKind.Node18 &&
|
|
1755
|
+
moduleKind <= ModuleKind.NodeNext &&
|
|
1756
|
+
isOnlyImportableAsDefault(c, declaration.moduleSpecifier, resolvedModule) &&
|
|
1757
|
+
!hasTypeJsonImportAttribute(declaration))
|
|
1758
|
+
c.error(declaration.moduleSpecifier, 458 /* Diagnostics.Importing_a_JSON_file_into_an_ECMAScript_module_requires_a_type_Colon_json_import_attribute_when_module_is_set_to_0 */, moduleKindName(moduleKind));
|
|
1759
|
+
}
|
|
1760
|
+
else if (clause === undefined && c.compilerOptions.noUncheckedSideEffectImports !== false)
|
|
1761
|
+
resolveExternalModuleNameWorker(c, node, declaration.moduleSpecifier, 1002 /* Diagnostics.Cannot_find_module_or_type_declarations_for_side_effect_import_of_0 */, false, false);
|
|
1762
|
+
checkImportAttributes(c, node);
|
|
1763
|
+
}
|
|
1764
|
+
function hasTypeJsonImportAttribute(node) {
|
|
1765
|
+
const attributes = getImportAttributes(node);
|
|
1766
|
+
if (attributes === undefined)
|
|
1767
|
+
return false;
|
|
1768
|
+
for (const attribute of attributes.attributes.nodes) {
|
|
1769
|
+
const value = attribute.value;
|
|
1770
|
+
if (getText(getName(attribute)) === 'type' && isStringLiteralLike(value) && getText(value) === 'json')
|
|
1771
|
+
return true;
|
|
1772
|
+
}
|
|
1773
|
+
return false;
|
|
1774
|
+
}
|
|
1775
|
+
function checkImportBinding(c, node) {
|
|
1776
|
+
checkCollisionsForDeclarationName(c, node, getName(node));
|
|
1777
|
+
checkAliasSymbol(c, node);
|
|
1778
|
+
if (node.kind === 277 /* SyntaxKind.ImportSpecifier */ &&
|
|
1779
|
+
moduleExportNameIsDefault(getPropertyNameOrName(node)) &&
|
|
1780
|
+
c.host.getEmitModuleFormatOfFile(getSourceFileOfNode(node)) === ModuleKind.CommonJS)
|
|
1781
|
+
checkExternalEmitHelpers(c, node, 2048 /* ExternalEmitHelpers.ImportDefault */);
|
|
1782
|
+
}
|
|
1783
|
+
/** Import attributes must be assignable to the global `ImportAttributes`. */
|
|
1784
|
+
function checkImportAttributes(c, declaration) {
|
|
1785
|
+
const node = getImportAttributes(declaration);
|
|
1786
|
+
if (node === undefined)
|
|
1787
|
+
return;
|
|
1788
|
+
const importAttributesType = getCachedGlobalType(c, 'ImportAttributes', 0, true);
|
|
1789
|
+
if (importAttributesType !== c.emptyObjectType)
|
|
1790
|
+
checkTypeAssignableTo(c, getTypeFromImportAttributes(c, node), getNullableType(c, importAttributesType, 4 /* TypeFlags.Undefined */), node, undefined);
|
|
1791
|
+
}
|
|
1792
|
+
function getTypeFromImportAttributes(c, node) {
|
|
1793
|
+
if (c.resolvedTypes.get(node.id) === undefined) {
|
|
1794
|
+
const symbol = c.newSymbol(4096 /* SymbolFlags.ObjectLiteral */, "\uFFFEimportAttributes" /* InternalSymbolName.ImportAttributes */);
|
|
1795
|
+
const members = new Map();
|
|
1796
|
+
for (const attribute of node.attributes.nodes) {
|
|
1797
|
+
const name = getText(attribute.name);
|
|
1798
|
+
const member = c.newSymbol(4 /* SymbolFlags.Property */, name);
|
|
1799
|
+
c.symbolTypes.set(getSymbolId(member), getRegularTypeOfLiteralType(c, checkExpression(c, attribute.value)));
|
|
1800
|
+
members.set(name, member);
|
|
1801
|
+
}
|
|
1802
|
+
const type = createAnonymousType(c, symbol, members, [], [], []);
|
|
1803
|
+
type.objectFlags |= 128 /* ObjectFlags.ObjectLiteral */ | 262144 /* ObjectFlags.NonInferrableType */;
|
|
1804
|
+
c.resolvedTypes.set(node.id, type);
|
|
1805
|
+
}
|
|
1806
|
+
return c.resolvedTypes.get(node.id);
|
|
1807
|
+
}
|
|
1808
|
+
export function checkImportEqualsDeclaration(c, node) {
|
|
1809
|
+
if (!isInModuleElementContext(node))
|
|
1810
|
+
return;
|
|
1811
|
+
const declaration = node;
|
|
1812
|
+
const reference = declaration.moduleReference;
|
|
1813
|
+
const isExternal = reference.kind === 284 /* SyntaxKind.ExternalModuleReference */;
|
|
1814
|
+
if (shouldCheckErasableSyntax(c, node) && (node.flags & 8388608 /* NodeFlags.Ambient */) === 0)
|
|
1815
|
+
c.error(node, 243 /* Diagnostics.This_syntax_is_not_allowed_when_erasableSyntaxOnly_is_enabled */);
|
|
1816
|
+
if (isExternal && !isValidExternalImportOrExportDeclaration(node))
|
|
1817
|
+
return;
|
|
1818
|
+
checkImportBinding(c, node);
|
|
1819
|
+
if (hasSyntacticModifier(node, 32 /* ModifierFlags.Export */) && (node.flags & 8388608 /* NodeFlags.Ambient */) === 0)
|
|
1820
|
+
markExportAsReferenced(c, node);
|
|
1821
|
+
if (isExternal)
|
|
1822
|
+
return;
|
|
1823
|
+
const target = resolveAlias(c, getSymbolOfDeclaration(c, node));
|
|
1824
|
+
if (target === c.unknownSymbol)
|
|
1825
|
+
return;
|
|
1826
|
+
const targetFlags = getSymbolFlags(c, target);
|
|
1827
|
+
if ((targetFlags & 111551 /* SymbolFlags.Value */) !== 0) {
|
|
1828
|
+
// A value target must not be hidden by a local declaration of the same name.
|
|
1829
|
+
const moduleName = getFirstIdentifierOfEntityName(reference);
|
|
1830
|
+
const resolved = resolveEntityName(c, moduleName, 111551 /* SymbolFlags.Value */ | 1920 /* SymbolFlags.Namespace */, false, false, undefined);
|
|
1831
|
+
if (resolved !== undefined && (resolved.flags & 1920 /* SymbolFlags.Namespace */) === 0)
|
|
1832
|
+
c.error(moduleName, 605 /* Diagnostics.Module_0_is_hidden_by_a_local_declaration_with_the_same_name */, declarationNameToString(getSourceFileOfNode(moduleName), moduleName));
|
|
1833
|
+
}
|
|
1834
|
+
if ((targetFlags & 788968 /* SymbolFlags.Type */) !== 0)
|
|
1835
|
+
checkTypeNameIsReserved(c, declaration.name, 606 /* Diagnostics.Import_name_cannot_be_0 */);
|
|
1836
|
+
}
|
|
1837
|
+
function getFirstIdentifierOfEntityName(node) {
|
|
1838
|
+
let current = node;
|
|
1839
|
+
while (current.kind === 167 /* SyntaxKind.QualifiedName */)
|
|
1840
|
+
current = current.left;
|
|
1841
|
+
return current;
|
|
1842
|
+
}
|
|
1843
|
+
/** The string literal name of `export * as "x" from`, which module es2015 and es2020 don't support. */
|
|
1844
|
+
function checkNamespaceExportName(c, name) {
|
|
1845
|
+
if (name === undefined || name.kind !== 10 /* SyntaxKind.StringLiteral */)
|
|
1846
|
+
return;
|
|
1847
|
+
const moduleKind = getEmitModuleKind(c.compilerOptions);
|
|
1848
|
+
if ((moduleKind === ModuleKind.ES2015 || moduleKind === ModuleKind.ES2020) &&
|
|
1849
|
+
!getSourceFileOfNode(name).isDeclarationFile)
|
|
1850
|
+
grammarErrorOnNode(c, name, 1872 /* Diagnostics.String_literal_import_and_export_names_are_not_supported_when_the_module_flag_is_set_to_es2015_or_es2020 */);
|
|
1851
|
+
}
|
|
1852
|
+
export function checkExportDeclaration(c, node) {
|
|
1853
|
+
if (!isInModuleElementContext(node))
|
|
1854
|
+
return;
|
|
1855
|
+
const declaration = node;
|
|
1856
|
+
if (declaration.moduleSpecifier === undefined || isValidExternalImportOrExportDeclaration(node)) {
|
|
1857
|
+
const clause = declaration.exportClause;
|
|
1858
|
+
if (clause !== undefined && clause.kind === 280 /* SyntaxKind.NamedExports */) {
|
|
1859
|
+
for (const specifier of clause.elements.nodes)
|
|
1860
|
+
checkExportSpecifier(c, specifier);
|
|
1861
|
+
}
|
|
1862
|
+
else {
|
|
1863
|
+
const moduleSymbol = resolveExternalModuleName(c, node, declaration.moduleSpecifier, false);
|
|
1864
|
+
if (moduleSymbol !== undefined && hasExportAssignmentSymbol(moduleSymbol))
|
|
1865
|
+
c.error(declaration.moduleSpecifier, 658 /* Diagnostics.Module_0_uses_export_and_cannot_be_used_with_export_Asterisk */, symbolToString(c, moduleSymbol));
|
|
1866
|
+
else if (clause !== undefined) {
|
|
1867
|
+
checkAliasSymbol(c, clause);
|
|
1868
|
+
checkNamespaceExportName(c, getName(clause));
|
|
1869
|
+
}
|
|
1870
|
+
if (c.host.getEmitModuleFormatOfFile(getSourceFileOfNode(node)) === ModuleKind.CommonJS)
|
|
1871
|
+
checkExternalEmitHelpers(c, node, clause !== undefined ? 1024 /* ExternalEmitHelpers.ImportStar */ : 512 /* ExternalEmitHelpers.ExportStar */);
|
|
1872
|
+
}
|
|
1873
|
+
}
|
|
1874
|
+
checkImportAttributes(c, node);
|
|
1875
|
+
}
|
|
1876
|
+
function checkExportSpecifier(c, node) {
|
|
1877
|
+
checkAliasSymbol(c, node);
|
|
1878
|
+
if (node.parent.parent.moduleSpecifier !== undefined) {
|
|
1879
|
+
if (c.host.getEmitModuleFormatOfFile(getSourceFileOfNode(node)) === ModuleKind.CommonJS &&
|
|
1880
|
+
moduleExportNameIsDefault(getPropertyNameOrName(node)))
|
|
1881
|
+
checkExternalEmitHelpers(c, node, 2048 /* ExternalEmitHelpers.ImportDefault */);
|
|
1882
|
+
return;
|
|
1883
|
+
}
|
|
1884
|
+
const exportedName = getPropertyNameOrName(node);
|
|
1885
|
+
// `export { "x" }` is a syntax error.
|
|
1886
|
+
if (exportedName.kind === 10 /* SyntaxKind.StringLiteral */)
|
|
1887
|
+
return;
|
|
1888
|
+
// The immediate symbol of the name, without following aliases.
|
|
1889
|
+
const symbol = resolveName(c, exportedName, getText(exportedName), 111551 /* SymbolFlags.Value */ | 788968 /* SymbolFlags.Type */ | 1920 /* SymbolFlags.Namespace */ | 2097152 /* SymbolFlags.Alias */, undefined, true, false);
|
|
1890
|
+
if (symbol !== undefined &&
|
|
1891
|
+
(symbol === c.undefinedSymbol ||
|
|
1892
|
+
symbol === c.globalThisSymbol ||
|
|
1893
|
+
(symbol.declarations.length > 0 && isGlobalSourceFile(getDeclarationContainer(symbol.declarations[0])))))
|
|
1894
|
+
c.error(exportedName, 795 /* Diagnostics.Cannot_export_0_Only_local_declarations_can_be_exported_from_a_module */, getText(exportedName));
|
|
1895
|
+
else
|
|
1896
|
+
markExportSpecifierAliasReferenced(c, node, symbol, exportedName);
|
|
1897
|
+
}
|
|
1898
|
+
export function getDeclarationContainer(node) {
|
|
1899
|
+
let current = getRootDeclaration(node);
|
|
1900
|
+
for (;;) {
|
|
1901
|
+
const parent = current.parent;
|
|
1902
|
+
if (parent === undefined)
|
|
1903
|
+
return current;
|
|
1904
|
+
switch (current.kind) {
|
|
1905
|
+
case 261 /* SyntaxKind.VariableDeclaration */:
|
|
1906
|
+
case 262 /* SyntaxKind.VariableDeclarationList */:
|
|
1907
|
+
case 277 /* SyntaxKind.ImportSpecifier */:
|
|
1908
|
+
case 276 /* SyntaxKind.NamedImports */:
|
|
1909
|
+
case 275 /* SyntaxKind.NamespaceImport */:
|
|
1910
|
+
case 274 /* SyntaxKind.ImportClause */:
|
|
1911
|
+
current = parent;
|
|
1912
|
+
continue;
|
|
1913
|
+
}
|
|
1914
|
+
return parent;
|
|
1915
|
+
}
|
|
1916
|
+
}
|
|
1917
|
+
/** `export = e` and `export default e`; the grammar checker reports misplaced ones. */
|
|
1918
|
+
export function checkExportAssignment(c, node) {
|
|
1919
|
+
if (!isInModuleElementContext(node))
|
|
1920
|
+
return;
|
|
1921
|
+
const declaration = node;
|
|
1922
|
+
const isExportEquals = declaration.isExportEquals;
|
|
1923
|
+
const ambient = (node.flags & 8388608 /* NodeFlags.Ambient */) !== 0;
|
|
1924
|
+
if (shouldCheckErasableSyntax(c, node) && isExportEquals && !ambient)
|
|
1925
|
+
c.error(node, 243 /* Diagnostics.This_syntax_is_not_allowed_when_erasableSyntaxOnly_is_enabled */);
|
|
1926
|
+
const container = node.parent.kind === 307 /* SyntaxKind.SourceFile */ ? node.parent : node.parent.parent;
|
|
1927
|
+
if (container.kind === 268 /* SyntaxKind.ModuleDeclaration */ && !isAmbientModule(container))
|
|
1928
|
+
return;
|
|
1929
|
+
const verbatimModuleSyntax = c.compilerOptions.verbatimModuleSyntax === true;
|
|
1930
|
+
const isIllegalExportDefaultInCJS = !isExportEquals &&
|
|
1931
|
+
!ambient &&
|
|
1932
|
+
verbatimModuleSyntax &&
|
|
1933
|
+
c.host.getEmitModuleFormatOfFile(getSourceFileOfNode(node)) === ModuleKind.CommonJS;
|
|
1934
|
+
const expression = declaration.expression;
|
|
1935
|
+
if (expression.kind === 79 /* SyntaxKind.Identifier */) {
|
|
1936
|
+
const id = expression;
|
|
1937
|
+
const resolved = resolveEntityName(c, id, 1073741823 /* SymbolFlags.All */, true, true, node);
|
|
1938
|
+
if (resolved !== undefined) {
|
|
1939
|
+
const sym = getExportSymbolOfValueSymbolIfExported(c, resolved);
|
|
1940
|
+
if (!ambient)
|
|
1941
|
+
markAliasReferenced(c, sym, id);
|
|
1942
|
+
const typeOnlyDeclaration = getTypeOnlyAliasDeclarationOfMeaning(c, sym, 111551 /* SymbolFlags.Value */);
|
|
1943
|
+
const name = getText(id);
|
|
1944
|
+
// A non-value is exported as a type, like `export { Id as default }`.
|
|
1945
|
+
if ((getSymbolFlags(c, sym) & 111551 /* SymbolFlags.Value */) !== 0) {
|
|
1946
|
+
checkExpressionCached(c, id);
|
|
1947
|
+
if (!isIllegalExportDefaultInCJS && !ambient && verbatimModuleSyntax && typeOnlyDeclaration !== undefined)
|
|
1948
|
+
c.error(id, isExportEquals
|
|
1949
|
+
? 232 /* Diagnostics.An_export_declaration_must_reference_a_real_value_when_verbatimModuleSyntax_is_enabled_but_0_resolves_to_a_type_only_declaration */
|
|
1950
|
+
: 234 /* Diagnostics.An_export_default_must_reference_a_real_value_when_verbatimModuleSyntax_is_enabled_but_0_resolves_to_a_type_only_declaration */, name);
|
|
1951
|
+
}
|
|
1952
|
+
else if (!isIllegalExportDefaultInCJS && !ambient && verbatimModuleSyntax)
|
|
1953
|
+
c.error(id, isExportEquals
|
|
1954
|
+
? 231 /* Diagnostics.An_export_declaration_must_reference_a_value_when_verbatimModuleSyntax_is_enabled_but_0_only_refers_to_a_type */
|
|
1955
|
+
: 233 /* Diagnostics.An_export_default_must_reference_a_value_when_verbatimModuleSyntax_is_enabled_but_0_only_refers_to_a_type */, name);
|
|
1956
|
+
if (!isIllegalExportDefaultInCJS && !ambient && c.isolatedModules && (sym.flags & 111551 /* SymbolFlags.Value */) === 0)
|
|
1957
|
+
checkIsolatedModulesExportAssignment(c, node, sym, typeOnlyDeclaration, isExportEquals);
|
|
1958
|
+
}
|
|
1959
|
+
else
|
|
1960
|
+
checkExpressionCached(c, id);
|
|
1961
|
+
}
|
|
1962
|
+
else
|
|
1963
|
+
checkExpressionCached(c, expression);
|
|
1964
|
+
if (isIllegalExportDefaultInCJS)
|
|
1965
|
+
c.error(node, verbatimModuleSyntaxErrorMessage(node));
|
|
1966
|
+
checkExternalModuleExports(c, container);
|
|
1967
|
+
// A JSDoc `@type` on `export default`.
|
|
1968
|
+
const typeNode = getType(node);
|
|
1969
|
+
if (typeNode !== undefined) {
|
|
1970
|
+
const expr = getExpression(node);
|
|
1971
|
+
checkTypeAssignableToAndOptionallyElaborate(c, checkExpressionCached(c, expr), getTypeFromTypeNode(c, typeNode), expr, expr);
|
|
1972
|
+
}
|
|
1973
|
+
}
|
|
1974
|
+
function checkIsolatedModulesExportAssignment(c, node, sym, typeOnlyDeclaration, isExportEquals) {
|
|
1975
|
+
const id = getExpression(node);
|
|
1976
|
+
const name = getText(id);
|
|
1977
|
+
const nonLocalMeanings = getSymbolFlagsEx(c, sym, false, true);
|
|
1978
|
+
const sameFile = typeOnlyDeclaration !== undefined && getSourceFileOfNode(typeOnlyDeclaration) === getSourceFileOfNode(node);
|
|
1979
|
+
if ((sym.flags & 2097152 /* SymbolFlags.Alias */) !== 0 &&
|
|
1980
|
+
(nonLocalMeanings & 788968 /* SymbolFlags.Type */) !== 0 &&
|
|
1981
|
+
(nonLocalMeanings & 111551 /* SymbolFlags.Value */) === 0 &&
|
|
1982
|
+
!sameFile)
|
|
1983
|
+
c.error(id, isExportEquals
|
|
1984
|
+
? 240 /* Diagnostics.X_0_resolves_to_a_type_and_must_be_marked_type_only_in_this_file_before_re_exporting_when_1_is_enabled_Consider_using_import_type_where_0_is_imported */
|
|
1985
|
+
: 241 /* Diagnostics.X_0_resolves_to_a_type_and_must_be_marked_type_only_in_this_file_before_re_exporting_when_1_is_enabled_Consider_using_export_type_0_as_default */, name, getIsolatedModulesLikeFlagName(c));
|
|
1986
|
+
else if (typeOnlyDeclaration !== undefined && !sameFile)
|
|
1987
|
+
addTypeOnlyDeclarationRelatedInfo(c.error(id, isExportEquals
|
|
1988
|
+
? 238 /* Diagnostics.X_0_resolves_to_a_type_only_declaration_and_must_be_marked_type_only_in_this_file_before_re_exporting_when_1_is_enabled_Consider_using_import_type_where_0_is_imported */
|
|
1989
|
+
: 239 /* Diagnostics.X_0_resolves_to_a_type_only_declaration_and_must_be_marked_type_only_in_this_file_before_re_exporting_when_1_is_enabled_Consider_using_export_type_0_as_default */, name, getIsolatedModulesLikeFlagName(c)), typeOnlyDeclaration, name);
|
|
1990
|
+
}
|
|
1991
|
+
/** Reports aliases that conflict with local declarations, and type-only rules of isolated modules. */
|
|
1992
|
+
export function checkAliasSymbol(c, node) {
|
|
1993
|
+
const aliasSymbol = getSymbolOfDeclaration(c, node);
|
|
1994
|
+
if (aliasSymbol === undefined)
|
|
1995
|
+
return;
|
|
1996
|
+
const target = resolveAlias(c, aliasSymbol);
|
|
1997
|
+
if (target === c.unknownSymbol)
|
|
1998
|
+
return;
|
|
1999
|
+
// The local symbol merges other local (and exported) declarations, whose meanings the target can't have.
|
|
2000
|
+
const symbol = getMergedSymbol(c, aliasSymbol.exportSymbol ?? aliasSymbol);
|
|
2001
|
+
const targetFlags = getSymbolFlags(c, target);
|
|
2002
|
+
// Type-only imports and exports are grammar errors in JavaScript.
|
|
2003
|
+
if (isInJSFile(node) && (targetFlags & 111551 /* SymbolFlags.Value */) === 0 && !isTypeOnlyImportOrExportDeclaration(node)) {
|
|
2004
|
+
reportJSTypeAlias(c, node, symbol);
|
|
2005
|
+
return;
|
|
2006
|
+
}
|
|
2007
|
+
const excludedMeanings = ((symbol.flags & (111551 /* SymbolFlags.Value */ | 1048576 /* SymbolFlags.ExportValue */)) !== 0 ? 111551 /* SymbolFlags.Value */ : 0) |
|
|
2008
|
+
((symbol.flags & 788968 /* SymbolFlags.Type */) !== 0 ? 788968 /* SymbolFlags.Type */ : 0) |
|
|
2009
|
+
((symbol.flags & 1920 /* SymbolFlags.Namespace */) !== 0 ? 1920 /* SymbolFlags.Namespace */ : 0);
|
|
2010
|
+
if ((targetFlags & excludedMeanings) !== 0)
|
|
2011
|
+
c.error(node, node.kind === 282 /* SyntaxKind.ExportSpecifier */
|
|
2012
|
+
? 646 /* Diagnostics.Export_declaration_conflicts_with_exported_declaration_of_0 */
|
|
2013
|
+
: 608 /* Diagnostics.Import_declaration_conflicts_with_local_declaration_of_0 */, symbolToString(c, symbol));
|
|
2014
|
+
else if (node.kind !== 282 /* SyntaxKind.ExportSpecifier */ &&
|
|
2015
|
+
c.compilerOptions.isolatedModules === true &&
|
|
2016
|
+
!isPartOfTypeOnlyImportOrExportDeclaration(node) &&
|
|
2017
|
+
(symbol.flags & (111551 /* SymbolFlags.Value */ | 1048576 /* SymbolFlags.ExportValue */)) !== 0)
|
|
2018
|
+
// A transpiler sees a value import that collides with the local value.
|
|
2019
|
+
c.error(node, 985 /* Diagnostics.Import_0_conflicts_with_local_value_so_must_be_declared_with_a_type_only_import_when_isolatedModules_is_enabled */, symbolToString(c, symbol), getIsolatedModulesLikeFlagName(c));
|
|
2020
|
+
if (c.isolatedModules && !isTypeOnlyImportOrExportDeclaration(node) && (node.flags & 8388608 /* NodeFlags.Ambient */) === 0)
|
|
2021
|
+
checkIsolatedModulesAlias(c, node, symbol, target, targetFlags);
|
|
2022
|
+
if (node.kind === 277 /* SyntaxKind.ImportSpecifier */)
|
|
2023
|
+
checkDeprecatedImportSpecifier(c, node, symbol);
|
|
2024
|
+
}
|
|
2025
|
+
function reportJSTypeAlias(c, node, symbol) {
|
|
2026
|
+
const errorNode = getPropertyName(node) ?? getName(node) ?? node;
|
|
2027
|
+
if (node.kind === 282 /* SyntaxKind.ExportSpecifier */) {
|
|
2028
|
+
c.error(errorNode, 1859 /* Diagnostics.Types_cannot_appear_in_export_declarations_in_JavaScript_files */);
|
|
2029
|
+
return;
|
|
2030
|
+
}
|
|
2031
|
+
const identifierText = errorNode.kind === 79 /* SyntaxKind.Identifier */ ? getText(errorNode) : symbol.name;
|
|
2032
|
+
let specifierText = '...';
|
|
2033
|
+
let declaration = node;
|
|
2034
|
+
while (declaration !== undefined &&
|
|
2035
|
+
declaration.kind !== 273 /* SyntaxKind.ImportDeclaration */ &&
|
|
2036
|
+
declaration.kind !== 272 /* SyntaxKind.ImportEqualsDeclaration */ &&
|
|
2037
|
+
declaration.kind !== 261 /* SyntaxKind.VariableDeclaration */)
|
|
2038
|
+
declaration = declaration.parent;
|
|
2039
|
+
if (declaration !== undefined) {
|
|
2040
|
+
const specifier = declaration.kind === 261 /* SyntaxKind.VariableDeclaration */
|
|
2041
|
+
? isVariableDeclarationInitializedToRequire(declaration)
|
|
2042
|
+
? getInitializer(declaration).arguments.nodes[0]
|
|
2043
|
+
: undefined
|
|
2044
|
+
: getExternalModuleName(declaration);
|
|
2045
|
+
if (specifier !== undefined && isStringLiteralLike(specifier))
|
|
2046
|
+
specifierText = getText(specifier);
|
|
2047
|
+
}
|
|
2048
|
+
let importText = 'import("' + specifierText + '")';
|
|
2049
|
+
if (node.kind === 277 /* SyntaxKind.ImportSpecifier */)
|
|
2050
|
+
importText += '.' + identifierText;
|
|
2051
|
+
c.error(errorNode, 1858 /* Diagnostics.X_0_is_a_type_and_cannot_be_imported_in_JavaScript_files_Use_1_in_a_JSDoc_type_annotation */, identifierText, importText);
|
|
2052
|
+
}
|
|
2053
|
+
function checkIsolatedModulesAlias(c, node, symbol, target, targetFlags) {
|
|
2054
|
+
const verbatimModuleSyntax = c.compilerOptions.verbatimModuleSyntax === true;
|
|
2055
|
+
const typeOnlyAlias = getTypeOnlyAliasDeclaration(c, symbol);
|
|
2056
|
+
const isType = (targetFlags & 111551 /* SymbolFlags.Value */) === 0;
|
|
2057
|
+
if (isType || typeOnlyAlias !== undefined) {
|
|
2058
|
+
switch (node.kind) {
|
|
2059
|
+
case 274 /* SyntaxKind.ImportClause */:
|
|
2060
|
+
case 277 /* SyntaxKind.ImportSpecifier */:
|
|
2061
|
+
case 272 /* SyntaxKind.ImportEqualsDeclaration */: {
|
|
2062
|
+
if (verbatimModuleSyntax) {
|
|
2063
|
+
const message = node.kind === 272 /* SyntaxKind.ImportEqualsDeclaration */ &&
|
|
2064
|
+
node.moduleReference.kind !== 284 /* SyntaxKind.ExternalModuleReference */
|
|
2065
|
+
? 237 /* Diagnostics.An_import_alias_cannot_resolve_to_a_type_or_type_only_declaration_when_verbatimModuleSyntax_is_enabled */
|
|
2066
|
+
: isType
|
|
2067
|
+
? 399 /* Diagnostics.X_0_is_a_type_and_must_be_imported_using_a_type_only_import_when_verbatimModuleSyntax_is_enabled */
|
|
2068
|
+
: 400 /* Diagnostics.X_0_resolves_to_a_type_only_declaration_and_must_be_imported_using_a_type_only_import_when_verbatimModuleSyntax_is_enabled */;
|
|
2069
|
+
const name = getText(getPropertyNameOrName(node));
|
|
2070
|
+
addTypeOnlyDeclarationRelatedInfo(c.error(node, message, name), isType ? undefined : typeOnlyAlias, name);
|
|
2071
|
+
}
|
|
2072
|
+
if (isType &&
|
|
2073
|
+
node.kind === 272 /* SyntaxKind.ImportEqualsDeclaration */ &&
|
|
2074
|
+
hasSyntacticModifier(node, 32 /* ModifierFlags.Export */))
|
|
2075
|
+
c.error(node, 218 /* Diagnostics.Cannot_use_export_import_on_a_type_or_type_only_namespace_when_0_is_enabled */, getIsolatedModulesLikeFlagName(c));
|
|
2076
|
+
break;
|
|
2077
|
+
}
|
|
2078
|
+
case 282 /* SyntaxKind.ExportSpecifier */:
|
|
2079
|
+
// `import type { A } from './a'; export { A }` is fine: one file shows the export is a type.
|
|
2080
|
+
if (verbatimModuleSyntax ||
|
|
2081
|
+
typeOnlyAlias === undefined ||
|
|
2082
|
+
getSourceFileOfNode(typeOnlyAlias) !== getSourceFileOfNode(node)) {
|
|
2083
|
+
const name = getText(getPropertyNameOrName(node));
|
|
2084
|
+
const diagnostic = isType
|
|
2085
|
+
? c.error(node, 159 /* Diagnostics.Re_exporting_a_type_when_0_is_enabled_requires_using_export_type */, getIsolatedModulesLikeFlagName(c))
|
|
2086
|
+
: c.error(node, 370 /* Diagnostics.X_0_resolves_to_a_type_only_declaration_and_must_be_re_exported_using_a_type_only_re_export_when_1_is_enabled */, name, getIsolatedModulesLikeFlagName(c));
|
|
2087
|
+
addTypeOnlyDeclarationRelatedInfo(diagnostic, isType ? undefined : typeOnlyAlias, name);
|
|
2088
|
+
}
|
|
2089
|
+
break;
|
|
2090
|
+
}
|
|
2091
|
+
}
|
|
2092
|
+
if (verbatimModuleSyntax &&
|
|
2093
|
+
node.kind !== 272 /* SyntaxKind.ImportEqualsDeclaration */ &&
|
|
2094
|
+
!isInJSFile(node) &&
|
|
2095
|
+
c.host.getEmitModuleFormatOfFile(getSourceFileOfNode(node)) === ModuleKind.CommonJS)
|
|
2096
|
+
c.error(node, verbatimModuleSyntaxErrorMessage(node));
|
|
2097
|
+
else if (getEmitModuleKind(c.compilerOptions) === ModuleKind.Preserve &&
|
|
2098
|
+
node.kind !== 272 /* SyntaxKind.ImportEqualsDeclaration */ &&
|
|
2099
|
+
node.kind !== 261 /* SyntaxKind.VariableDeclaration */ &&
|
|
2100
|
+
c.host.getEmitModuleFormatOfFile(getSourceFileOfNode(node)) === ModuleKind.CommonJS)
|
|
2101
|
+
// Under `--module preserve` ESM syntax emits as ESM, so it is an error in a file that is CommonJS (.cts, .cjs).
|
|
2102
|
+
c.error(node, 242 /* Diagnostics.ECMAScript_module_syntax_is_not_allowed_in_a_CommonJS_module_when_module_is_set_to_preserve */);
|
|
2103
|
+
if (verbatimModuleSyntax &&
|
|
2104
|
+
(targetFlags & 128 /* SymbolFlags.ConstEnum */) !== 0 &&
|
|
2105
|
+
target.valueDeclaration !== undefined &&
|
|
2106
|
+
(target.valueDeclaration.flags & 8388608 /* NodeFlags.Ambient */) !== 0)
|
|
2107
|
+
c.error(node, 880 /* Diagnostics.Cannot_access_ambient_const_enums_when_0_is_enabled */, getIsolatedModulesLikeFlagName(c));
|
|
2108
|
+
}
|
|
2109
|
+
/** The error for ESM syntax in a CommonJS file under `verbatimModuleSyntax`: shorter in a .cts or .cjs file. */
|
|
2110
|
+
function verbatimModuleSyntaxErrorMessage(node) {
|
|
2111
|
+
return fileExtensionIsOneOf(getSourceFileOfNode(node).fileName, ['.cts', '.cjs'])
|
|
2112
|
+
? 235 /* Diagnostics.ECMAScript_imports_and_exports_cannot_be_written_in_a_CommonJS_file_under_verbatimModuleSyntax */
|
|
2113
|
+
: 244 /* Diagnostics.ECMAScript_imports_and_exports_cannot_be_written_in_a_CommonJS_file_under_verbatimModuleSyntax_Adjust_the_type_field_in_the_nearest_package_json_to_make_this_file_an_ECMAScript_module_or_adjust_your_verbatimModuleSyntax_module_and_moduleResolution_settings_in_TypeScript */;
|
|
2114
|
+
}
|
|
2115
|
+
function isPartOfTypeOnlyImportOrExportDeclaration(node) {
|
|
2116
|
+
for (let current = node; current !== undefined; current = current.parent)
|
|
2117
|
+
if (isTypeOnlyImportOrExportDeclaration(current))
|
|
2118
|
+
return true;
|
|
2119
|
+
return false;
|
|
2120
|
+
}
|
|
2121
|
+
export function getIsolatedModulesLikeFlagName(c) {
|
|
2122
|
+
return c.compilerOptions.verbatimModuleSyntax === true ? 'verbatimModuleSyntax' : 'isolatedModules';
|
|
2123
|
+
}
|
|
2124
|
+
/** The file a module declaration or import names. */
|
|
2125
|
+
export function getExternalModuleFileFromDeclaration(c, declaration) {
|
|
2126
|
+
let specifier = undefined;
|
|
2127
|
+
if (declaration.kind === 268 /* SyntaxKind.ModuleDeclaration */) {
|
|
2128
|
+
const name = getName(declaration);
|
|
2129
|
+
if (name !== undefined && name.kind === 10 /* SyntaxKind.StringLiteral */)
|
|
2130
|
+
specifier = name;
|
|
2131
|
+
}
|
|
2132
|
+
else
|
|
2133
|
+
specifier = getExternalModuleName(declaration);
|
|
2134
|
+
if (specifier === undefined)
|
|
2135
|
+
return undefined;
|
|
2136
|
+
const moduleSymbol = resolveExternalModuleNameWorker(c, specifier, specifier, undefined, false, false);
|
|
2137
|
+
if (moduleSymbol === undefined)
|
|
2138
|
+
return undefined;
|
|
2139
|
+
const file = getDeclarationOfKind(moduleSymbol, 307 /* SyntaxKind.SourceFile */);
|
|
2140
|
+
return file === undefined ? undefined : file;
|
|
2141
|
+
}
|