tsc-ts 0.0.10 → 0.1.0
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 +1 -1
- package/bin/tsc-ts.js +70 -1
- package/dist/api/compiler/ast-utilities.d.ts +19 -1
- package/dist/api/compiler/ast-utilities.js +180 -95
- package/dist/api/compiler/ast.d.ts +20 -15
- package/dist/api/compiler/ast.js +1023 -995
- package/dist/api/compiler/astnav.js +15 -15
- package/dist/api/compiler/binder-utilities.js +186 -186
- package/dist/api/compiler/binder.js +290 -263
- package/dist/api/compiler/character-codes.js +2 -2
- package/dist/api/compiler/checker-calls.js +173 -123
- package/dist/api/compiler/checker-classes.d.ts +14 -3
- package/dist/api/compiler/checker-classes.js +134 -90
- package/dist/api/compiler/checker-contextual.js +64 -61
- package/dist/api/compiler/checker-declaration-order.js +79 -79
- package/dist/api/compiler/checker-declarations.d.ts +1 -0
- package/dist/api/compiler/checker-declarations.js +160 -136
- package/dist/api/compiler/checker-declared-types.js +67 -65
- package/dist/api/compiler/checker-decorators.js +77 -77
- package/dist/api/compiler/checker-deprecation.d.ts +8 -3
- package/dist/api/compiler/checker-deprecation.js +76 -55
- package/dist/api/compiler/checker-destructuring.js +47 -45
- package/dist/api/compiler/checker-elaboration.js +24 -24
- package/dist/api/compiler/checker-emit-helpers.js +4 -4
- package/dist/api/compiler/checker-emit-resolver.d.ts +4 -2
- package/dist/api/compiler/checker-emit-resolver.js +25 -13
- package/dist/api/compiler/checker-evaluator.js +9 -9
- package/dist/api/compiler/checker-expressions.js +244 -211
- package/dist/api/compiler/checker-functions.js +113 -107
- package/dist/api/compiler/checker-generated-code.d.ts +0 -11
- package/dist/api/compiler/checker-generated-code.js +28 -52
- package/dist/api/compiler/checker-grammar.d.ts +1 -0
- package/dist/api/compiler/checker-grammar.js +469 -438
- package/dist/api/compiler/checker-heritage.js +91 -93
- package/dist/api/compiler/checker-inference.d.ts +77 -5
- package/dist/api/compiler/checker-inference.js +487 -113
- package/dist/api/compiler/checker-iteration.d.ts +0 -10
- package/dist/api/compiler/checker-iteration.js +35 -52
- package/dist/api/compiler/checker-javascript.js +14 -14
- package/dist/api/compiler/checker-jsdoc.d.ts +8 -10
- package/dist/api/compiler/checker-jsdoc.js +67 -58
- package/dist/api/compiler/checker-jsx.js +105 -88
- package/dist/api/compiler/checker-members.d.ts +9 -2
- package/dist/api/compiler/checker-members.js +210 -74
- package/dist/api/compiler/checker-modules.d.ts +15 -6
- package/dist/api/compiler/checker-modules.js +469 -309
- package/dist/api/compiler/checker-narrowing.js +273 -189
- package/dist/api/compiler/checker-object-literals.js +25 -22
- package/dist/api/compiler/checker-operators.js +126 -118
- package/dist/api/compiler/checker-overloads.js +27 -27
- package/dist/api/compiler/checker-property-access.js +59 -55
- package/dist/api/compiler/checker-services.d.ts +1 -0
- package/dist/api/compiler/checker-services.js +222 -210
- package/dist/api/compiler/checker-signatures.js +65 -49
- package/dist/api/compiler/checker-source-file.d.ts +5 -0
- package/dist/api/compiler/checker-source-file.js +154 -130
- package/dist/api/compiler/checker-statements.js +33 -32
- package/dist/api/compiler/checker-super.js +50 -50
- package/dist/api/compiler/checker-symbol-types.js +109 -93
- package/dist/api/compiler/checker-symbols.d.ts +13 -1
- package/dist/api/compiler/checker-symbols.js +264 -149
- package/dist/api/compiler/checker-type-factory.d.ts +5 -0
- package/dist/api/compiler/checker-type-factory.js +137 -34
- package/dist/api/compiler/checker-type-nodes.d.ts +1 -0
- package/dist/api/compiler/checker-type-nodes.js +179 -141
- package/dist/api/compiler/checker-type-operators.d.ts +2 -0
- package/dist/api/compiler/checker-type-operators.js +110 -63
- package/dist/api/compiler/checker-types.d.ts +80 -3
- package/dist/api/compiler/checker-types.js +121 -2
- package/dist/api/compiler/checker-unused.js +114 -118
- package/dist/api/compiler/checker-utilities.js +11 -11
- package/dist/api/compiler/checker.d.ts +93 -31
- package/dist/api/compiler/checker.js +143 -35
- package/dist/api/compiler/command-line.d.ts +1 -3
- package/dist/api/compiler/command-line.js +47 -44
- package/dist/api/compiler/compile-program.d.ts +19 -4
- package/dist/api/compiler/compile-program.js +45 -26
- package/dist/api/compiler/diagnostic-messages.d.ts +1849 -1774
- package/dist/api/compiler/diagnostic-messages.js +128 -122
- package/dist/api/compiler/diagnostics.js +7 -7
- package/dist/api/compiler/emitter.d.ts +7 -1
- package/dist/api/compiler/emitter.js +53 -11
- package/dist/api/compiler/file-include.d.ts +2 -1
- package/dist/api/compiler/file-include.js +11 -7
- package/dist/api/compiler/file-loader.d.ts +10 -0
- package/dist/api/compiler/file-loader.js +138 -41
- package/dist/api/compiler/instantiation.d.ts +7 -0
- package/dist/api/compiler/instantiation.js +101 -49
- package/dist/api/compiler/jsdoc.js +23 -23
- package/dist/api/compiler/link-tables.d.ts +48 -18
- package/dist/api/compiler/link-tables.js +80 -37
- package/dist/api/compiler/locales/cs-CZ.d.ts +1 -1
- package/dist/api/compiler/locales/cs-CZ.js +1 -1
- package/dist/api/compiler/locales/de-DE.d.ts +1 -1
- package/dist/api/compiler/locales/de-DE.js +1 -1
- package/dist/api/compiler/locales/es-ES.d.ts +1 -1
- package/dist/api/compiler/locales/es-ES.js +1 -1
- package/dist/api/compiler/locales/fr-FR.d.ts +1 -1
- package/dist/api/compiler/locales/fr-FR.js +1 -1
- package/dist/api/compiler/locales/it-IT.d.ts +1 -1
- package/dist/api/compiler/locales/it-IT.js +1 -1
- package/dist/api/compiler/locales/ja-JP.d.ts +1 -1
- package/dist/api/compiler/locales/ja-JP.js +1 -1
- package/dist/api/compiler/locales/ko-KR.d.ts +1 -1
- package/dist/api/compiler/locales/ko-KR.js +1 -1
- package/dist/api/compiler/locales/pl-PL.d.ts +1 -1
- package/dist/api/compiler/locales/pl-PL.js +1 -1
- package/dist/api/compiler/locales/pt-BR.d.ts +1 -1
- package/dist/api/compiler/locales/pt-BR.js +1 -1
- package/dist/api/compiler/locales/ru-RU.d.ts +1 -1
- package/dist/api/compiler/locales/ru-RU.js +1 -1
- package/dist/api/compiler/locales/tr-TR.d.ts +1 -1
- package/dist/api/compiler/locales/tr-TR.js +1 -1
- package/dist/api/compiler/locales/zh-CN.d.ts +1 -1
- package/dist/api/compiler/locales/zh-CN.js +1 -1
- package/dist/api/compiler/locales/zh-TW.d.ts +1 -1
- package/dist/api/compiler/locales/zh-TW.js +1 -1
- package/dist/api/compiler/module-resolution-types.js +6 -6
- package/dist/api/compiler/module-resolution.d.ts +10 -1
- package/dist/api/compiler/module-resolution.js +115 -84
- package/dist/api/compiler/module-specifiers.d.ts +15 -0
- package/dist/api/compiler/module-specifiers.js +24 -18
- package/dist/api/compiler/name-resolver.js +74 -65
- package/dist/api/compiler/node-builder-names.d.ts +11 -3
- package/dist/api/compiler/node-builder-names.js +210 -90
- package/dist/api/compiler/node-builder-pseudo.js +29 -31
- package/dist/api/compiler/node-builder-reuse.js +23 -22
- package/dist/api/compiler/node-builder.d.ts +18 -1
- package/dist/api/compiler/node-builder.js +191 -102
- package/dist/api/compiler/option-declarations.d.ts +2 -6
- package/dist/api/compiler/option-declarations.js +315 -375
- package/dist/api/compiler/options.d.ts +15 -33
- package/dist/api/compiler/options.js +21 -54
- package/dist/api/compiler/output-paths.d.ts +4 -1
- package/dist/api/compiler/output-paths.js +6 -11
- package/dist/api/compiler/package-json.d.ts +3 -3
- package/dist/api/compiler/package-json.js +11 -10
- package/dist/api/compiler/parser.d.ts +40 -19
- package/dist/api/compiler/parser.js +308 -216
- package/dist/api/compiler/path.d.ts +9 -0
- package/dist/api/compiler/path.js +20 -3
- package/dist/api/compiler/printer/emit-context.d.ts +3 -1
- package/dist/api/compiler/printer/emit-context.js +16 -1
- package/dist/api/compiler/printer/factory-base.d.ts +2 -2
- package/dist/api/compiler/printer/factory-base.js +7 -3
- package/dist/api/compiler/printer/factory.js +3 -1
- package/dist/api/compiler/printer/helpers.js +10 -1
- package/dist/api/compiler/printer/name-generator.d.ts +1 -1
- package/dist/api/compiler/printer/name-generator.js +35 -16
- package/dist/api/compiler/printer/printer.d.ts +1 -0
- package/dist/api/compiler/printer/printer.js +303 -281
- package/dist/api/compiler/printer/utilities.js +149 -147
- package/dist/api/compiler/program-checker.d.ts +8 -2
- package/dist/api/compiler/program-checker.js +84 -34
- package/dist/api/compiler/program-utilities.d.ts +3 -1
- package/dist/api/compiler/program-utilities.js +28 -15
- package/dist/api/compiler/program.d.ts +2 -0
- package/dist/api/compiler/program.js +69 -57
- package/dist/api/compiler/pseudo-bigint.d.ts +2 -0
- package/dist/api/compiler/pseudo-bigint.js +18 -0
- package/dist/api/compiler/regexp-checker.d.ts +1 -1
- package/dist/api/compiler/regexp-checker.js +93 -76
- package/dist/api/compiler/relations.d.ts +27 -4
- package/dist/api/compiler/relations.js +337 -180
- package/dist/api/compiler/reparser.js +60 -56
- package/dist/api/compiler/scanner.d.ts +19 -2
- package/dist/api/compiler/scanner.js +123 -108
- package/dist/api/compiler/shared-results.d.ts +463 -0
- package/dist/api/compiler/shared-results.js +2128 -0
- package/dist/api/compiler/sourcemap.js +2 -2
- package/dist/api/compiler/symbol-accessibility.js +87 -74
- package/dist/api/compiler/symbol.d.ts +22 -13
- package/dist/api/compiler/symbol.js +15 -1
- package/dist/api/compiler/syntax-kind.d.ts +198 -197
- package/dist/api/compiler/transformers/alias-references.js +247 -139
- package/dist/api/compiler/transformers/async-utilities.js +25 -25
- package/dist/api/compiler/transformers/async.d.ts +0 -1
- package/dist/api/compiler/transformers/async.js +64 -77
- package/dist/api/compiler/transformers/class-fields.d.ts +1 -0
- package/dist/api/compiler/transformers/class-fields.js +81 -78
- package/dist/api/compiler/transformers/commonjs-module.js +18 -15
- package/dist/api/compiler/transformers/const-enum-inliner.js +1 -1
- package/dist/api/compiler/transformers/declarations-diagnostics.js +247 -244
- package/dist/api/compiler/transformers/declarations-pseudo.js +100 -100
- package/dist/api/compiler/transformers/declarations-resolver.d.ts +0 -3
- package/dist/api/compiler/transformers/declarations-syntactic.d.ts +1 -2
- package/dist/api/compiler/transformers/declarations-syntactic.js +134 -156
- package/dist/api/compiler/transformers/declarations-tracker.js +18 -18
- package/dist/api/compiler/transformers/declarations.d.ts +4 -1
- package/dist/api/compiler/transformers/declarations.js +305 -238
- package/dist/api/compiler/transformers/decorator-metadata.d.ts +1 -1
- package/dist/api/compiler/transformers/decorator-metadata.js +53 -45
- package/dist/api/compiler/transformers/decorator-utilities.js +24 -24
- package/dist/api/compiler/transformers/destructuring.js +19 -18
- package/dist/api/compiler/transformers/emit-resolver.js +1 -1
- package/dist/api/compiler/transformers/es-decorators.js +55 -55
- package/dist/api/compiler/transformers/external-module-info.js +3 -3
- package/dist/api/compiler/transformers/for-await.js +25 -25
- package/dist/api/compiler/transformers/import-elision.js +14 -14
- package/dist/api/compiler/transformers/jsx.js +12 -12
- package/dist/api/compiler/transformers/legacy-decorators.js +17 -17
- package/dist/api/compiler/transformers/module.js +8 -8
- package/dist/api/compiler/transformers/named-evaluation.js +4 -4
- package/dist/api/compiler/transformers/object-rest-spread.js +20 -20
- package/dist/api/compiler/transformers/optional-chain.js +10 -10
- package/dist/api/compiler/transformers/reference-resolver.d.ts +12 -1
- package/dist/api/compiler/transformers/reference-resolver.js +131 -69
- package/dist/api/compiler/transformers/runtime-syntax.js +35 -31
- package/dist/api/compiler/transformers/subtree-facts.js +47 -47
- package/dist/api/compiler/transformers/syntax-facts.js +56 -58
- package/dist/api/compiler/transformers/type-eraser.js +73 -66
- package/dist/api/compiler/transformers/type-serialization.js +24 -24
- package/dist/api/compiler/transformers/using.js +12 -12
- package/dist/api/compiler/transformers/utilities.js +77 -77
- package/dist/api/compiler/transformers/visitor-base.js +172 -172
- package/dist/api/compiler/transformers/visitor-hooks.js +6 -2
- package/dist/api/compiler/tsconfig.d.ts +10 -2
- package/dist/api/compiler/tsconfig.js +136 -48
- package/dist/api/compiler/type-printer.js +40 -3
- package/dist/api/compiler/types.d.ts +2 -1
- package/dist/api/library/ast.generated.d.ts +42 -39
- package/dist/api/library/ast.generated.js +1 -1
- package/dist/api/library/compiler-options.generated.d.ts +111 -100
- package/dist/api/library/compiler-options.generated.js +1 -1
- package/dist/api/library/disk.js +12 -1
- package/dist/api/library/enums.generated.d.ts +206 -206
- package/dist/api/library/enums.generated.js +206 -206
- package/dist/api/library/nodes.js +26 -26
- package/package.json +9 -9
- package/src/compiler/ast-utilities.ts +99 -7
- package/src/compiler/ast.ts +55 -26
- package/src/compiler/binder.ts +39 -4
- package/src/compiler/character-codes.ts +2 -2
- package/src/compiler/checker-calls.ts +76 -8
- package/src/compiler/checker-classes.ts +78 -24
- package/src/compiler/checker-contextual.ts +6 -1
- package/src/compiler/checker-declarations.ts +31 -4
- package/src/compiler/checker-declared-types.ts +8 -5
- package/src/compiler/checker-decorators.ts +1 -1
- package/src/compiler/checker-deprecation.ts +29 -8
- package/src/compiler/checker-destructuring.ts +10 -3
- package/src/compiler/checker-emit-helpers.ts +1 -0
- package/src/compiler/checker-emit-resolver.ts +16 -6
- package/src/compiler/checker-expressions.ts +79 -46
- package/src/compiler/checker-functions.ts +21 -6
- package/src/compiler/checker-generated-code.ts +2 -22
- package/src/compiler/checker-grammar.ts +133 -60
- package/src/compiler/checker-heritage.ts +22 -21
- package/src/compiler/checker-inference.ts +514 -87
- package/src/compiler/checker-iteration.ts +18 -31
- package/src/compiler/checker-javascript.ts +1 -1
- package/src/compiler/checker-jsdoc.ts +50 -27
- package/src/compiler/checker-jsx.ts +26 -4
- package/src/compiler/checker-members.ts +197 -55
- package/src/compiler/checker-modules.ts +332 -65
- package/src/compiler/checker-narrowing.ts +98 -19
- package/src/compiler/checker-object-literals.ts +3 -0
- package/src/compiler/checker-operators.ts +11 -4
- package/src/compiler/checker-property-access.ts +7 -2
- package/src/compiler/checker-services.ts +39 -12
- package/src/compiler/checker-signatures.ts +15 -1
- package/src/compiler/checker-source-file.ts +39 -13
- package/src/compiler/checker-statements.ts +3 -2
- package/src/compiler/checker-symbol-types.ts +29 -6
- package/src/compiler/checker-symbols.ts +158 -15
- package/src/compiler/checker-type-factory.ts +120 -21
- package/src/compiler/checker-type-nodes.ts +46 -3
- package/src/compiler/checker-type-operators.ts +83 -26
- package/src/compiler/checker-types.ts +147 -4
- package/src/compiler/checker-unused.ts +9 -14
- package/src/compiler/checker.ts +168 -41
- package/src/compiler/command-line.ts +28 -28
- package/src/compiler/compile-program.ts +51 -25
- package/src/compiler/decoder.ts +13 -4
- package/src/compiler/diagnostic-messages.ts +1973 -1892
- package/src/compiler/emitter.ts +57 -8
- package/src/compiler/encoder.ts +23 -8
- package/src/compiler/file-include.ts +9 -3
- package/src/compiler/file-loader.ts +139 -32
- package/src/compiler/help.ts +10 -14
- package/src/compiler/incremental.ts +86 -18
- package/src/compiler/init.ts +2 -7
- package/src/compiler/instantiation.ts +77 -22
- package/src/compiler/jsdoc.ts +3 -1
- package/src/compiler/link-tables.ts +82 -37
- package/src/compiler/locales/cs-CZ.ts +1 -1
- package/src/compiler/locales/de-DE.ts +1 -1
- package/src/compiler/locales/es-ES.ts +1 -1
- package/src/compiler/locales/fr-FR.ts +1 -1
- package/src/compiler/locales/it-IT.ts +1 -1
- package/src/compiler/locales/ja-JP.ts +1 -1
- package/src/compiler/locales/ko-KR.ts +1 -1
- package/src/compiler/locales/pl-PL.ts +1 -1
- package/src/compiler/locales/pt-BR.ts +1 -1
- package/src/compiler/locales/ru-RU.ts +1 -1
- package/src/compiler/locales/tr-TR.ts +1 -1
- package/src/compiler/locales/zh-CN.ts +1 -1
- package/src/compiler/locales/zh-TW.ts +1 -1
- package/src/compiler/module-resolution.ts +44 -8
- package/src/compiler/module-specifiers.ts +62 -20
- package/src/compiler/name-resolver.ts +9 -1
- package/src/compiler/node-builder-names.ts +236 -54
- package/src/compiler/node-builder-pseudo.ts +4 -7
- package/src/compiler/node-builder-reuse.ts +5 -4
- package/src/compiler/node-builder.ts +130 -31
- package/src/compiler/option-declarations.ts +33 -103
- package/src/compiler/options.ts +23 -62
- package/src/compiler/output-paths.ts +5 -18
- package/src/compiler/package-entrypoints.ts +345 -0
- package/src/compiler/package-json.ts +4 -4
- package/src/compiler/parallel-check.ts +197 -8
- package/src/compiler/parallel-emit.ts +1 -1
- package/src/compiler/parser.ts +156 -39
- package/src/compiler/path.ts +22 -2
- package/src/compiler/printer/emit-context.ts +16 -0
- package/src/compiler/printer/factory-base.ts +10 -3
- package/src/compiler/printer/factory.ts +4 -1
- package/src/compiler/printer/helpers.ts +10 -1
- package/src/compiler/printer/name-generator.ts +24 -2
- package/src/compiler/printer/printer.ts +35 -14
- package/src/compiler/printer/utilities.ts +8 -2
- package/src/compiler/program-checker.ts +53 -5
- package/src/compiler/program-utilities.ts +23 -10
- package/src/compiler/program.ts +13 -1
- package/src/compiler/pseudo-bigint.ts +17 -0
- package/src/compiler/regexp-checker.ts +63 -30
- package/src/compiler/relations.ts +233 -77
- package/src/compiler/reparser.ts +7 -2
- package/src/compiler/scanner.ts +109 -79
- package/src/compiler/shared-results.ts +2414 -0
- package/src/compiler/show-config.ts +18 -1
- package/src/compiler/sourcemap.ts +2 -2
- package/src/compiler/symbol-accessibility.ts +26 -3
- package/src/compiler/symbol.ts +31 -14
- package/src/compiler/syntax-kind.ts +188 -187
- package/src/compiler/thread-entry.ts +19 -2
- package/src/compiler/transformers/alias-references.ts +123 -4
- package/src/compiler/transformers/async.ts +2 -17
- package/src/compiler/transformers/class-fields.ts +13 -12
- package/src/compiler/transformers/commonjs-module.ts +11 -7
- package/src/compiler/transformers/declarations-diagnostics.ts +5 -3
- package/src/compiler/transformers/declarations-pseudo.ts +2 -4
- package/src/compiler/transformers/declarations-resolver.ts +0 -3
- package/src/compiler/transformers/declarations-syntactic.ts +1 -21
- package/src/compiler/transformers/declarations.ts +134 -48
- package/src/compiler/transformers/decorator-metadata.ts +9 -1
- package/src/compiler/transformers/destructuring.ts +4 -3
- package/src/compiler/transformers/external-module-info.ts +1 -1
- package/src/compiler/transformers/jsx.ts +2 -1
- package/src/compiler/transformers/reference-resolver.ts +83 -19
- package/src/compiler/transformers/runtime-syntax.ts +6 -1
- package/src/compiler/transformers/syntax-facts.ts +2 -7
- package/src/compiler/transformers/type-eraser.ts +10 -1
- package/src/compiler/transformers/type-serialization.ts +3 -2
- package/src/compiler/transformers/visitor-base.ts +2 -1
- package/src/compiler/transformers/visitor-hooks.ts +9 -4
- package/src/compiler/tsc-build.ts +3 -0
- package/src/compiler/tsc-cli.ts +2 -0
- package/src/compiler/tsc-compile.ts +7 -2
- package/src/compiler/tsc-watch.ts +74 -45
- package/src/compiler/tsconfig.ts +176 -19
- package/src/compiler/type-printer.ts +36 -2
- package/src/compiler/types.ts +2 -1
- package/src/library/ast.generated.ts +57 -41
- package/src/library/compiler-options.generated.ts +117 -103
- package/src/library/disk.ts +10 -1
- package/src/library/enums.generated.ts +196 -196
|
@@ -2,24 +2,31 @@
|
|
|
2
2
|
// declaration, written as an entity name, `import("…")` type, indexed access or expression.
|
|
3
3
|
import { ComputedPropertyName, ElementAccessExpression, ExpressionWithTypeArguments, ImportAttribute, ImportAttributes, ImportTypeNode, IndexedAccessTypeNode, LiteralTypeNode, ParenthesizedTypeNode, PrefixUnaryExpression, PropertyAccessExpression, QualifiedName, SourceFile, StringLiteral, TypeQueryNode, TypeReferenceNode, getArguments, getExpression, getInitializer, getModuleSpecifier, getName, getSymbol, getText, } from './ast.js';
|
|
4
4
|
import { declarationNameToString, getDeclarationOfKind, getNameOfDeclaration, getSourceFileOfNode, isModuleAugmentationExternal, } from './binder-utilities.js';
|
|
5
|
-
import { getExternalModuleName, isAmbientModule, isGlobalScopeAugmentation, isRequireCall } from './ast-utilities.js';
|
|
5
|
+
import { getExternalModuleName, isAmbientModule, isGlobalScopeAugmentation, isImportCall, isRequireCall, } from './ast-utilities.js';
|
|
6
6
|
import { getSymbolAtLocation } from './checker-services.js';
|
|
7
7
|
import { checkExpression } from './checker-expressions.js';
|
|
8
|
-
import { getExportsOfSymbol, getMembersOfSymbol,
|
|
9
|
-
import {
|
|
8
|
+
import { getExportsOfSymbol, getMembersOfSymbol, getMergedSymbol, resolveAlias } from './checker-symbols.js';
|
|
9
|
+
import { getImportAttributesTypeForModuleSpecifier, getTypeOfModuleImportAttributes, resolveExternalModule, } from './checker-modules.js';
|
|
10
|
+
import { getPropertiesOfType } from './checker-members.js';
|
|
11
|
+
import { getTypeOfSymbol } from './checker-symbol-types.js';
|
|
12
|
+
import { compareSymbols, isEmptyObjectType } from './checker-type-factory.js';
|
|
10
13
|
import { isLateBoundName } from './checker-utilities.js';
|
|
11
14
|
import { isExternalModuleNameRelative, pathIsRelative } from './path.js';
|
|
12
15
|
import { ModuleSpecifierHost, ModuleSpecifierPreferences, countPathComponents, getModuleSpecifiersForFile, } from './module-specifiers.js';
|
|
13
16
|
import { ModuleKind, ModuleResolutionKind, getModuleResolutionKind } from './options.js';
|
|
14
17
|
import { isExternalModuleAugmentation } from './transformers/declarations-syntactic.js';
|
|
15
18
|
import { isIdentifierText } from './scanner.js';
|
|
16
|
-
import { getAccessibleSymbolChain, getAliasForSymbolInContainer, getContainersOfSymbol, getFileSymbolIfFileSymbolExportEqualsContainer, getQualifiedLeftMeaning, getSymbolIfSameReference, hasNonGlobalAugmentationExternalModuleDeclaration, needsQualification, } from './symbol-accessibility.js';
|
|
19
|
+
import { getAccessibleSymbolChain, getAliasForSymbolInContainer, getContainersOfSymbol, getFileSymbolIfFileSymbolExportEqualsContainer, getQualifiedLeftMeaning, getSymbolIfSameReference, hasNonGlobalAugmentationExternalModuleDeclaration, isSymbolAccessibleByFlags, needsQualification, } from './symbol-accessibility.js';
|
|
17
20
|
import { classifyPropertyName, isNumericLiteralName } from './node-builder.js';
|
|
18
|
-
import { declarationCount, escapeInternalSymbolName, getDeclarations, getSymbolId, } from './symbol.js';
|
|
21
|
+
import { declarationCount, escapeInternalSymbolName, getDeclarations, getSymbolId, tryGetAmbientModuleNameFromSymbolName, } from './symbol.js';
|
|
19
22
|
// ---- Symbol chains
|
|
20
23
|
/** The chain of symbols naming `symbol`, reported to the tracker. */
|
|
21
24
|
export function lookupSymbolChain(b, symbol, meaning, yieldModuleSymbol) {
|
|
22
25
|
b.trackSymbol(symbol, b.enclosingDeclaration, meaning);
|
|
26
|
+
return lookupSymbolChainWorker(b, symbol, meaning, yieldModuleSymbol);
|
|
27
|
+
}
|
|
28
|
+
/** `lookupSymbolChain` without tracking the symbol's accessibility. */
|
|
29
|
+
function lookupSymbolChainWorker(b, symbol, meaning, yieldModuleSymbol) {
|
|
23
30
|
// Qualified only with somewhere to qualify from, and never for type parameters.
|
|
24
31
|
if ((symbol.flags & 262144 /* SymbolFlags.TypeParameter */) === 0 &&
|
|
25
32
|
(b.enclosingDeclaration !== undefined || (b.flags & 64 /* NodeBuilderFlags.UseFullyQualifiedType */) !== 0) &&
|
|
@@ -42,7 +49,7 @@ function getSymbolChain(b, symbol, meaning, endOfChain, yieldModuleSymbol) {
|
|
|
42
49
|
for (const p of parents) {
|
|
43
50
|
order.push(specifiers.length);
|
|
44
51
|
specifiers.push(hasNonGlobalAugmentationExternalModuleDeclaration(p)
|
|
45
|
-
? getSpecifierForModuleSymbol(b, p, ModuleKind.None)
|
|
52
|
+
? getSpecifierForModuleSymbol(b, p, ModuleKind.None).specifier
|
|
46
53
|
: '');
|
|
47
54
|
}
|
|
48
55
|
order.sort((x, y) => compareByBestName(b, parents[x], specifiers[x], parents[y], specifiers[y]) || x - y);
|
|
@@ -95,8 +102,8 @@ export function symbolToTypeNode(b, symbol, mask, typeArguments) {
|
|
|
95
102
|
// A module root needs an `import` type.
|
|
96
103
|
const nonRootParts = chain.length > 1 ? createAccessFromSymbolChain(b, chain, chain.length - 1, 1, typeArguments) : undefined;
|
|
97
104
|
const typeParameterNodes = typeArguments ?? lookupTypeParameterNodes(b, chain, 0);
|
|
98
|
-
let specifier = '';
|
|
99
|
-
let
|
|
105
|
+
let specifier = new ModuleSpecifierResult('', undefined);
|
|
106
|
+
let importModeOverride = ModuleKind.None;
|
|
100
107
|
const c = b.c;
|
|
101
108
|
const resolution = getModuleResolutionKind(c.compilerOptions);
|
|
102
109
|
const nodeNext = resolution === ModuleResolutionKind.Node16 || resolution === ModuleResolutionKind.NodeNext;
|
|
@@ -110,31 +117,33 @@ export function symbolToTypeNode(b, symbol, mask, typeArguments) {
|
|
|
110
117
|
const targetFormat = c.host.getEmitModuleFormatOfFile(targetFile);
|
|
111
118
|
if (targetFormat === ModuleKind.ESNext && targetFormat !== c.host.getEmitModuleFormatOfFile(contextFile)) {
|
|
112
119
|
specifier = getSpecifierForModuleSymbol(b, chain[0], ModuleKind.ESNext);
|
|
113
|
-
|
|
120
|
+
importModeOverride = ModuleKind.ESNext;
|
|
114
121
|
}
|
|
115
122
|
}
|
|
116
123
|
}
|
|
117
|
-
if (specifier === '')
|
|
124
|
+
if (specifier.specifier === '')
|
|
118
125
|
specifier = getSpecifierForModuleSymbol(b, chain[0], ModuleKind.None);
|
|
119
|
-
if ((b.flags & 67108864 /* NodeBuilderFlags.AllowNodeModulesRelativePaths */) === 0 &&
|
|
126
|
+
if ((b.flags & 67108864 /* NodeBuilderFlags.AllowNodeModulesRelativePaths */) === 0 &&
|
|
127
|
+
specifier.specifier.includes('/node_modules/')) {
|
|
120
128
|
const oldSpecifier = specifier;
|
|
121
129
|
if (nodeNext && contextFile !== undefined) {
|
|
122
130
|
// The other mode may reach the module portably.
|
|
123
131
|
const swappedMode = c.host.getEmitModuleFormatOfFile(contextFile) === ModuleKind.ESNext ? ModuleKind.CommonJS : ModuleKind.ESNext;
|
|
124
132
|
specifier = getSpecifierForModuleSymbol(b, chain[0], swappedMode);
|
|
125
|
-
if (specifier.includes('/node_modules/'))
|
|
133
|
+
if (specifier.specifier.includes('/node_modules/'))
|
|
126
134
|
specifier = oldSpecifier;
|
|
127
135
|
else
|
|
128
|
-
|
|
136
|
+
importModeOverride = swappedMode;
|
|
129
137
|
}
|
|
130
|
-
if (
|
|
138
|
+
if (importModeOverride === ModuleKind.None) {
|
|
131
139
|
// A reference into `node_modules` is likely to break when published.
|
|
132
140
|
b.encounteredError = true;
|
|
133
|
-
b.tracker.reportLikelyUnsafeImportRequiredError(oldSpecifier, symbol.name);
|
|
141
|
+
b.tracker.reportLikelyUnsafeImportRequiredError(oldSpecifier.specifier, symbol.name);
|
|
134
142
|
}
|
|
135
143
|
}
|
|
136
|
-
const
|
|
137
|
-
b.
|
|
144
|
+
const attributes = createImportAttributesForModuleSpecifier(b, specifier, importModeOverride);
|
|
145
|
+
const literal = b.created(new LiteralTypeNode(b.stringLiteral(specifier.specifier, false)));
|
|
146
|
+
b.approximateLength += specifier.specifier.length + 10;
|
|
138
147
|
if (nonRootParts === undefined || isEntityName(nonRootParts))
|
|
139
148
|
return b.created(new ImportTypeNode(isTypeOf, literal, attributes, nonRootParts, typeParameterNodes));
|
|
140
149
|
const splitNode = getTopmostIndexedAccessType(nonRootParts);
|
|
@@ -154,12 +163,48 @@ export function symbolToTypeNode(b, symbol, mask, typeArguments) {
|
|
|
154
163
|
return entityName;
|
|
155
164
|
}
|
|
156
165
|
function isEntityName(node) {
|
|
157
|
-
return node.kind === 79 /* SyntaxKind.Identifier */ || node.kind ===
|
|
166
|
+
return node.kind === 79 /* SyntaxKind.Identifier */ || node.kind === 168 /* SyntaxKind.QualifiedName */;
|
|
158
167
|
}
|
|
159
|
-
/**
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
168
|
+
/**
|
|
169
|
+
* The attributes of an `import()` type: a `resolution-mode` for `importModeOverride`, then the
|
|
170
|
+
* string literal properties of the specifier's import attributes type, by name.
|
|
171
|
+
*/
|
|
172
|
+
function createImportAttributesForModuleSpecifier(b, result, importModeOverride) {
|
|
173
|
+
const c = b.c;
|
|
174
|
+
const attributesType = result.importAttributesType;
|
|
175
|
+
const isEmptyAttributesType = attributesType === undefined || isEmptyObjectType(c, attributesType);
|
|
176
|
+
if (isEmptyAttributesType && importModeOverride === ModuleKind.None)
|
|
177
|
+
return undefined;
|
|
178
|
+
const attributes = [];
|
|
179
|
+
if (importModeOverride !== ModuleKind.None) {
|
|
180
|
+
const mode = importModeOverride === ModuleKind.ESNext ? 'import' : 'require';
|
|
181
|
+
attributes.push(b.created(new ImportAttribute(b.stringLiteral('resolution-mode', false), b.stringLiteral(mode, false))));
|
|
182
|
+
b.approximateLength += 'resolution-mode'.length + mode.length + 6;
|
|
183
|
+
}
|
|
184
|
+
if (!isEmptyAttributesType) {
|
|
185
|
+
const properties = getPropertiesOfType(c, attributesType).slice();
|
|
186
|
+
properties.sort((x, y) => (x.name < y.name ? -1 : x.name > y.name ? 1 : 0));
|
|
187
|
+
for (const property of properties) {
|
|
188
|
+
const name = property.name;
|
|
189
|
+
const propertyType = getTypeOfSymbol(c, property);
|
|
190
|
+
if ((propertyType.flags & 1024 /* TypeFlags.StringLiteral */) === 0)
|
|
191
|
+
continue;
|
|
192
|
+
const value = propertyType.stringValue;
|
|
193
|
+
let nameNode;
|
|
194
|
+
if (isIdentifierText(name))
|
|
195
|
+
nameNode = b.factory.createIdentifier(name);
|
|
196
|
+
else {
|
|
197
|
+
nameNode = b.stringLiteral(name, false);
|
|
198
|
+
b.approximateLength += 2;
|
|
199
|
+
}
|
|
200
|
+
attributes.push(b.created(new ImportAttribute(nameNode, b.stringLiteral(value, false))));
|
|
201
|
+
b.approximateLength += name.length + value.length + 4;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
if (attributes.length === 0)
|
|
205
|
+
return undefined;
|
|
206
|
+
b.approximateLength += 16 + 2 * (attributes.length - 1);
|
|
207
|
+
return b.created(new ImportAttributes(117 /* SyntaxKind.WithKeyword */, b.list(attributes), false));
|
|
163
208
|
}
|
|
164
209
|
function getTopmostIndexedAccessType(node) {
|
|
165
210
|
const objectType = node.objectType;
|
|
@@ -212,7 +257,7 @@ function createAccessFromSymbolChain(b, chain, index, stopper, overrideTypeArgum
|
|
|
212
257
|
if (name !== undefined)
|
|
213
258
|
break;
|
|
214
259
|
}
|
|
215
|
-
if (name !== undefined && name.kind ===
|
|
260
|
+
if (name !== undefined && name.kind === 169 /* SyntaxKind.ComputedPropertyName */ && isEntityName(getExpression(name))) {
|
|
216
261
|
const lhs = createAccessFromSymbolChain(b, chain, index - 1, stopper, overrideTypeArguments);
|
|
217
262
|
if (isEntityName(lhs))
|
|
218
263
|
return b.created(new IndexedAccessTypeNode(b.created(new ParenthesizedTypeNode(b.created(new TypeQueryNode(lhs, undefined)))), b.created(new TypeQueryNode(getExpression(name), undefined))));
|
|
@@ -232,7 +277,7 @@ function createAccessFromSymbolChain(b, chain, index, stopper, overrideTypeArgum
|
|
|
232
277
|
return b.created(new IndexedAccessTypeNode(b.created(new TypeReferenceNode(lhs, typeParameterNodes)), literal));
|
|
233
278
|
}
|
|
234
279
|
}
|
|
235
|
-
const identifier = b.
|
|
280
|
+
const identifier = b.symbolIdentifier(symbolName, symbol);
|
|
236
281
|
b.context.addEmitFlags(identifier, 131072 /* EmitFlags.NoAsciiEscaping */);
|
|
237
282
|
if (index > stopper) {
|
|
238
283
|
const lhs = createAccessFromSymbolChain(b, chain, index - 1, stopper, overrideTypeArguments);
|
|
@@ -316,7 +361,7 @@ function createEntityNameFromSymbolChain(b, chain, index) {
|
|
|
316
361
|
const symbolName = getNameOfSymbolAsWritten(b, symbol);
|
|
317
362
|
if (index === 0)
|
|
318
363
|
b.flags ^= 16777216 /* NodeBuilderFlags.InInitialEntityName */;
|
|
319
|
-
const identifier = b.
|
|
364
|
+
const identifier = b.symbolIdentifier(symbolName, symbol);
|
|
320
365
|
b.context.addEmitFlags(identifier, 131072 /* EmitFlags.NoAsciiEscaping */);
|
|
321
366
|
if (index > 0)
|
|
322
367
|
return b.created(new QualifiedName(createEntityNameFromSymbolChain(b, chain, index - 1), identifier));
|
|
@@ -330,7 +375,12 @@ export function symbolToEntityNameNode(b, symbol) {
|
|
|
330
375
|
return identifier;
|
|
331
376
|
}
|
|
332
377
|
export function symbolToExpression(b, symbol, meaning) {
|
|
333
|
-
|
|
378
|
+
b.trackSymbol(symbol, b.enclosingDeclaration, meaning);
|
|
379
|
+
return symbolToExpressionWorker(b, symbol, meaning);
|
|
380
|
+
}
|
|
381
|
+
/** `symbolToExpression` without tracking the symbol's accessibility. */
|
|
382
|
+
function symbolToExpressionWorker(b, symbol, meaning) {
|
|
383
|
+
const chain = lookupSymbolChainWorker(b, symbol, meaning, false);
|
|
334
384
|
return createExpressionFromSymbolChain(b, chain, chain.length - 1);
|
|
335
385
|
}
|
|
336
386
|
function createExpressionFromSymbolChain(b, chain, index) {
|
|
@@ -342,7 +392,7 @@ function createExpressionFromSymbolChain(b, chain, index) {
|
|
|
342
392
|
if (index === 0)
|
|
343
393
|
b.flags ^= 16777216 /* NodeBuilderFlags.InInitialEntityName */;
|
|
344
394
|
if (startsWithQuote(symbolName) && hasNonGlobalAugmentationExternalModuleDeclaration(symbol)) {
|
|
345
|
-
const specifier = getSpecifierForModuleSymbol(b, symbol, ModuleKind.None);
|
|
395
|
+
const specifier = getSpecifierForModuleSymbol(b, symbol, ModuleKind.None).specifier;
|
|
346
396
|
b.approximateLength += 2 + specifier.length;
|
|
347
397
|
return b.stringLiteral(specifier, false);
|
|
348
398
|
}
|
|
@@ -449,7 +499,7 @@ function lookupExpressionChainTypeArgumentNodes(b, chain, index) {
|
|
|
449
499
|
}
|
|
450
500
|
// ---- Names as written
|
|
451
501
|
function isDefaultBindingContext(node) {
|
|
452
|
-
return node.kind ===
|
|
502
|
+
return node.kind === 308 /* SyntaxKind.SourceFile */ || isAmbientModule(node);
|
|
453
503
|
}
|
|
454
504
|
function findDefaultBindingContext(node) {
|
|
455
505
|
for (let current = node; current !== undefined; current = current.parent)
|
|
@@ -502,7 +552,7 @@ export function getNameOfSymbolAsWritten(b, symbol) {
|
|
|
502
552
|
break;
|
|
503
553
|
}
|
|
504
554
|
if (name !== undefined) {
|
|
505
|
-
if (name.kind ===
|
|
555
|
+
if (name.kind === 169 /* SyntaxKind.ComputedPropertyName */ && (symbol.checkFlags & 32768 /* CheckFlags.Late */) === 0) {
|
|
506
556
|
const nameType = b.c.symbolNameTypes.get(getSymbolId(symbol));
|
|
507
557
|
if (nameType !== undefined && (nameType.flags & 3072 /* TypeFlags.StringOrNumberLiteral */) !== 0) {
|
|
508
558
|
const result = getNameOfSymbolFromNameType(b, symbol);
|
|
@@ -514,17 +564,17 @@ export function getNameOfSymbolAsWritten(b, symbol) {
|
|
|
514
564
|
}
|
|
515
565
|
const declaration = symbol.declaration;
|
|
516
566
|
const parent = declaration.parent;
|
|
517
|
-
if (parent !== undefined && parent.kind ===
|
|
567
|
+
if (parent !== undefined && parent.kind === 262 /* SyntaxKind.VariableDeclaration */) {
|
|
518
568
|
const parentName = getName(parent);
|
|
519
569
|
return declarationNameToString(getSourceFileOfNode(parentName), parentName);
|
|
520
570
|
}
|
|
521
571
|
switch (declaration.kind) {
|
|
522
|
-
case
|
|
523
|
-
case
|
|
524
|
-
case
|
|
572
|
+
case 233 /* SyntaxKind.ClassExpression */:
|
|
573
|
+
case 220 /* SyntaxKind.FunctionExpression */:
|
|
574
|
+
case 221 /* SyntaxKind.ArrowFunction */:
|
|
525
575
|
if (!b.encounteredError && (b.flags & 131072 /* NodeBuilderFlags.AllowAnonymousIdentifier */) === 0)
|
|
526
576
|
b.encounteredError = true;
|
|
527
|
-
return declaration.kind ===
|
|
577
|
+
return declaration.kind === 233 /* SyntaxKind.ClassExpression */ ? '(Anonymous class)' : '(Anonymous function)';
|
|
528
578
|
}
|
|
529
579
|
}
|
|
530
580
|
const name = getNameOfSymbolFromNameType(b, symbol);
|
|
@@ -548,7 +598,7 @@ function isSingleQuotedStringNamed(d) {
|
|
|
548
598
|
return name instanceof StringLiteral && (name.tokenFlags & 65536 /* TokenFlags.SingleQuote */) !== 0;
|
|
549
599
|
}
|
|
550
600
|
/** The name node of a property. */
|
|
551
|
-
export function getPropertyNameNodeForSymbol(b, symbol) {
|
|
601
|
+
export function getPropertyNameNodeForSymbol(b, symbol, enclosingDeclaration) {
|
|
552
602
|
// A private name is the declaration's.
|
|
553
603
|
const valueDeclaration = symbol.valueDeclaration;
|
|
554
604
|
if (valueDeclaration !== undefined) {
|
|
@@ -570,7 +620,7 @@ export function getPropertyNameNodeForSymbol(b, symbol) {
|
|
|
570
620
|
break;
|
|
571
621
|
}
|
|
572
622
|
const isMethod = (symbol.flags & 8192 /* SymbolFlags.Method */) !== 0;
|
|
573
|
-
const fromNameType = getPropertyNameNodeForSymbolFromNameType(b, symbol, singleQuote, stringNamed, isMethod);
|
|
623
|
+
const fromNameType = getPropertyNameNodeForSymbolFromNameType(b, symbol, enclosingDeclaration, singleQuote, stringNamed, isMethod);
|
|
574
624
|
if (fromNameType !== undefined)
|
|
575
625
|
return fromNameType;
|
|
576
626
|
let name = symbol.name;
|
|
@@ -595,10 +645,23 @@ function createPropertyNameNodeForIdentifierOrLiteral(b, name, singleQuote, stri
|
|
|
595
645
|
}
|
|
596
646
|
return b.factory.createStringLiteral(name, singleQuote ? 65536 /* TokenFlags.SingleQuote */ : 0 /* TokenFlags.None */);
|
|
597
647
|
}
|
|
598
|
-
function getPropertyNameNodeForSymbolFromNameType(b, symbol, singleQuote, stringNamed, isMethod) {
|
|
648
|
+
function getPropertyNameNodeForSymbolFromNameType(b, symbol, enclosingDeclaration, singleQuote, stringNamed, isMethod) {
|
|
599
649
|
const nameType = b.c.symbolNameTypes.get(getSymbolId(symbol));
|
|
600
650
|
if (nameType === undefined)
|
|
601
651
|
return undefined;
|
|
652
|
+
// A name from an enum member stays a computed name, `[E.A]`, where the enum can be named.
|
|
653
|
+
if ((nameType.flags & 32768 /* TypeFlags.EnumLiteral */) !== 0) {
|
|
654
|
+
const enumEnclosingDeclaration = enclosingDeclaration !== undefined ? enclosingDeclaration : b.enclosingFile;
|
|
655
|
+
const enumSymbol = nameType.symbol.parent !== undefined ? nameType.symbol.parent : nameType.symbol;
|
|
656
|
+
if (enumEnclosingDeclaration !== undefined &&
|
|
657
|
+
isSymbolAccessibleByFlags(b.c, enumSymbol, enumEnclosingDeclaration, 111551 /* SymbolFlags.Value */)) {
|
|
658
|
+
const saveEnclosingDeclaration = b.enclosingDeclaration;
|
|
659
|
+
b.enclosingDeclaration = enumEnclosingDeclaration;
|
|
660
|
+
const result = b.created(new ComputedPropertyName(symbolToExpression(b, nameType.symbol, 111551 /* SymbolFlags.Value */)));
|
|
661
|
+
b.enclosingDeclaration = saveEnclosingDeclaration;
|
|
662
|
+
return result;
|
|
663
|
+
}
|
|
664
|
+
}
|
|
602
665
|
if ((nameType.flags & 3072 /* TypeFlags.StringOrNumberLiteral */) !== 0) {
|
|
603
666
|
const literal = nameType;
|
|
604
667
|
const name = (nameType.flags & 1024 /* TypeFlags.StringLiteral */) !== 0 ? literal.stringValue : String(literal.numberValue);
|
|
@@ -608,40 +671,66 @@ function getPropertyNameNodeForSymbolFromNameType(b, symbol, singleQuote, string
|
|
|
608
671
|
return b.created(new ComputedPropertyName(b.created(new PrefixUnaryExpression(40 /* SyntaxKind.MinusToken */, b.factory.createNumericLiteral(name.substring(1))))));
|
|
609
672
|
return createPropertyNameNodeForIdentifierOrLiteral(b, name, singleQuote, stringNamed, isMethod);
|
|
610
673
|
}
|
|
674
|
+
// The reference is tracked where the name is used; spelling it here must not track it in this scope.
|
|
611
675
|
if ((nameType.flags & 16384 /* TypeFlags.UniqueESSymbol */) !== 0)
|
|
612
|
-
return b.created(new ComputedPropertyName(
|
|
676
|
+
return b.created(new ComputedPropertyName(symbolToExpressionWorker(b, nameType.symbol, 111551 /* SymbolFlags.Value */)));
|
|
613
677
|
return undefined;
|
|
614
678
|
}
|
|
615
679
|
// ---- Module specifiers
|
|
680
|
+
/** A module specifier, and the import attributes type an `import()` type with it needs. */
|
|
681
|
+
export class ModuleSpecifierResult {
|
|
682
|
+
specifier;
|
|
683
|
+
importAttributesType;
|
|
684
|
+
constructor(specifier, importAttributesType) {
|
|
685
|
+
this.specifier = specifier;
|
|
686
|
+
this.importAttributesType = importAttributesType;
|
|
687
|
+
}
|
|
688
|
+
}
|
|
616
689
|
/**
|
|
617
690
|
* The specifier an `import("…")` type names a module with: an ambient module's name, the file
|
|
618
691
|
* name without an enclosing file, else what module specifier generation gives for the enclosing
|
|
619
|
-
* file. `overrideImportMode` is `None` for the mode of the enclosing import or file.
|
|
692
|
+
* file. `overrideImportMode` is `None` for the mode of the enclosing import or file. A pattern
|
|
693
|
+
* ambient module's specifier comes with the attributes type that resolves it.
|
|
620
694
|
*/
|
|
621
695
|
export function getSpecifierForModuleSymbol(b, symbol, overrideImportMode) {
|
|
622
696
|
const c = b.c;
|
|
623
|
-
|
|
697
|
+
const enclosingDeclaration = b.enclosingDeclaration === undefined ? undefined : b.context.mostOriginal(b.enclosingDeclaration);
|
|
698
|
+
const originalModuleSpecifier = enclosingDeclaration !== undefined && canHaveModuleSpecifier(enclosingDeclaration)
|
|
699
|
+
? tryGetModuleSpecifierFromDeclaration(enclosingDeclaration)
|
|
700
|
+
: undefined;
|
|
701
|
+
const originalImportAttributesType = originalModuleSpecifier !== undefined
|
|
702
|
+
? getImportAttributesTypeForModuleSpecifier(c, originalModuleSpecifier)
|
|
703
|
+
: undefined;
|
|
704
|
+
let file = asSourceFile(getDeclarationOfKind(symbol, 308 /* SyntaxKind.SourceFile */));
|
|
624
705
|
if (file === undefined)
|
|
625
706
|
for (const d of getDeclarations(symbol)) {
|
|
626
707
|
const equivalent = getFileSymbolIfFileSymbolExportEqualsContainer(c, d, symbol);
|
|
627
708
|
if (equivalent !== undefined) {
|
|
628
|
-
file = asSourceFile(getDeclarationOfKind(equivalent,
|
|
709
|
+
file = asSourceFile(getDeclarationOfKind(equivalent, 308 /* SyntaxKind.SourceFile */));
|
|
629
710
|
break;
|
|
630
711
|
}
|
|
631
712
|
}
|
|
632
|
-
if (file === undefined
|
|
633
|
-
|
|
713
|
+
if (file === undefined) {
|
|
714
|
+
for (const declaration of getDeclarations(symbol))
|
|
715
|
+
if (isModuleWithStringLiteralName(declaration)) {
|
|
716
|
+
const specifier = getText(getName(declaration));
|
|
717
|
+
if (originalImportAttributesType !== undefined &&
|
|
718
|
+
moduleSpecifierResolvesToSymbol(b, specifier, originalImportAttributesType, symbol))
|
|
719
|
+
return new ModuleSpecifierResult(specifier, originalImportAttributesType);
|
|
720
|
+
return new ModuleSpecifierResult(specifier, getTypeOfModuleImportAttributes(c, symbol));
|
|
721
|
+
}
|
|
722
|
+
const ambientName = tryGetAmbientModuleNameFromSymbolName(symbol.name);
|
|
723
|
+
if (ambientName !== undefined)
|
|
724
|
+
return new ModuleSpecifierResult(ambientName, undefined);
|
|
725
|
+
}
|
|
634
726
|
const contextFile = b.enclosingFile;
|
|
635
727
|
if (contextFile === undefined) {
|
|
636
|
-
|
|
637
|
-
|
|
728
|
+
const ambientName = tryGetAmbientModuleNameFromSymbolName(symbol.name);
|
|
729
|
+
if (ambientName !== undefined)
|
|
730
|
+
return new ModuleSpecifierResult(ambientName, undefined);
|
|
638
731
|
const moduleFile = getSourceFileOfModule(symbol);
|
|
639
|
-
return moduleFile === undefined ? '' : moduleFile.fileName;
|
|
732
|
+
return new ModuleSpecifierResult(moduleFile === undefined ? '' : moduleFile.fileName, undefined);
|
|
640
733
|
}
|
|
641
|
-
const enclosingDeclaration = b.enclosingDeclaration === undefined ? undefined : b.context.mostOriginal(b.enclosingDeclaration);
|
|
642
|
-
const originalModuleSpecifier = enclosingDeclaration !== undefined && canHaveModuleSpecifier(enclosingDeclaration)
|
|
643
|
-
? tryGetModuleSpecifierFromDeclaration(enclosingDeclaration)
|
|
644
|
-
: undefined;
|
|
645
734
|
let resolutionMode = overrideImportMode;
|
|
646
735
|
if (resolutionMode === ModuleKind.None)
|
|
647
736
|
resolutionMode =
|
|
@@ -651,25 +740,56 @@ export function getSpecifierForModuleSymbol(b, symbol, overrideImportMode) {
|
|
|
651
740
|
const key = getSymbolId(symbol) + '|' + contextFile.path + '|' + resolutionMode;
|
|
652
741
|
const cached = c.moduleSpecifiers.get(key);
|
|
653
742
|
if (cached !== undefined)
|
|
654
|
-
return cached;
|
|
743
|
+
return moduleSpecifierResultForSymbol(b, cached, originalImportAttributesType, symbol);
|
|
655
744
|
// Declaration emit prefers project-relative specifiers, with `.js` extensions in ES modules.
|
|
656
745
|
const preferences = new ModuleSpecifierPreferences('project-relative', resolutionMode === ModuleKind.ESNext ? 'js' : '');
|
|
657
|
-
const specifiers =
|
|
658
|
-
const
|
|
659
|
-
|
|
660
|
-
|
|
746
|
+
const specifiers = getModuleSpecifiersWithAmbientModule(c, symbol, contextFile, preferences, overrideImportMode);
|
|
747
|
+
const result = new ModuleSpecifierResult(specifiers.specifiers.length > 0 ? specifiers.specifiers[0] : '', specifiers.ambientModuleSymbol !== undefined
|
|
748
|
+
? getTypeOfModuleImportAttributes(c, specifiers.ambientModuleSymbol)
|
|
749
|
+
: undefined);
|
|
750
|
+
c.moduleSpecifiers.set(key, result);
|
|
751
|
+
return moduleSpecifierResultForSymbol(b, result, originalImportAttributesType, symbol);
|
|
752
|
+
}
|
|
753
|
+
/** `result` with `importAttributesType`, if its specifier resolves to `symbol` with those attributes. */
|
|
754
|
+
function moduleSpecifierResultForSymbol(b, result, importAttributesType, symbol) {
|
|
755
|
+
if (importAttributesType !== undefined &&
|
|
756
|
+
moduleSpecifierResolvesToSymbol(b, result.specifier, importAttributesType, symbol))
|
|
757
|
+
return new ModuleSpecifierResult(result.specifier, importAttributesType);
|
|
758
|
+
return result;
|
|
759
|
+
}
|
|
760
|
+
function moduleSpecifierResolvesToSymbol(b, specifier, importAttributesType, symbol) {
|
|
761
|
+
const location = b.enclosingDeclaration ?? b.enclosingFile;
|
|
762
|
+
if (location === undefined)
|
|
763
|
+
return false;
|
|
764
|
+
const c = b.c;
|
|
765
|
+
const resolved = resolveExternalModule(c, location, specifier, undefined, undefined, false, importAttributesType);
|
|
766
|
+
return resolved !== undefined && getMergedSymbol(c, resolved) === getMergedSymbol(c, symbol);
|
|
767
|
+
}
|
|
768
|
+
/** The specifiers of `getModuleSpecifiers`, and the ambient module symbol that gives an ambient module's name. */
|
|
769
|
+
class ModuleSpecifiers {
|
|
770
|
+
specifiers;
|
|
771
|
+
ambientModuleSymbol;
|
|
772
|
+
constructor(specifiers, ambientModuleSymbol) {
|
|
773
|
+
this.specifiers = specifiers;
|
|
774
|
+
this.ambientModuleSymbol = ambientModuleSymbol;
|
|
775
|
+
}
|
|
661
776
|
}
|
|
662
777
|
/** Specifiers `importingFile` can import the module `moduleSymbol` with, best first. */
|
|
663
778
|
export function getModuleSpecifiers(c, moduleSymbol, importingFile, preferences, overrideImportMode) {
|
|
779
|
+
return getModuleSpecifiersWithAmbientModule(c, moduleSymbol, importingFile, preferences, overrideImportMode)
|
|
780
|
+
.specifiers;
|
|
781
|
+
}
|
|
782
|
+
function getModuleSpecifiersWithAmbientModule(c, moduleSymbol, importingFile, preferences, overrideImportMode) {
|
|
664
783
|
const ambient = tryGetModuleNameFromAmbientModule(c, moduleSymbol);
|
|
665
|
-
if (ambient !==
|
|
666
|
-
return [ambient];
|
|
784
|
+
if (ambient !== undefined)
|
|
785
|
+
return new ModuleSpecifiers([getText(getName(ambient))], getSymbol(ambient));
|
|
667
786
|
const moduleFile = getSourceFileOfModule(moduleSymbol);
|
|
668
787
|
if (moduleFile === undefined)
|
|
669
|
-
return [];
|
|
788
|
+
return new ModuleSpecifiers([], undefined);
|
|
670
789
|
const host = getModuleSpecifierHost(c);
|
|
671
790
|
// A referenced project's declaration output is named by its source.
|
|
672
|
-
|
|
791
|
+
const specifiers = getModuleSpecifiersForFile(importingFile, host.getSourceOfProjectReferenceIfOutputIncluded(moduleFile), c.compilerOptions, host, preferences, overrideImportMode, false);
|
|
792
|
+
return new ModuleSpecifiers(specifiers, undefined);
|
|
673
793
|
}
|
|
674
794
|
function getModuleSpecifierHost(c) {
|
|
675
795
|
let host = c.host.getModuleSpecifierHost();
|
|
@@ -682,26 +802,26 @@ function getModuleSpecifierHost(c) {
|
|
|
682
802
|
}
|
|
683
803
|
return host;
|
|
684
804
|
}
|
|
685
|
-
/** The
|
|
805
|
+
/** The ambient module declaring `moduleSymbol`, or the one whose `export =` it is. */
|
|
686
806
|
function tryGetModuleNameFromAmbientModule(c, moduleSymbol) {
|
|
687
807
|
for (const d of getDeclarations(moduleSymbol)) {
|
|
688
808
|
const name = isModuleWithStringLiteralName(d) ? getName(d) : undefined;
|
|
689
809
|
if (name !== undefined && (!isModuleAugmentationExternal(d) || !isExternalModuleNameRelative(getText(name))))
|
|
690
|
-
return
|
|
810
|
+
return d;
|
|
691
811
|
}
|
|
692
812
|
// A namespace exported with `export =` from an ambient module: `import { c } from "m"` names
|
|
693
813
|
// `ns.c` for `declare module "m" { namespace ns { class c {} } export = ns; }`.
|
|
694
814
|
for (const d of getDeclarations(moduleSymbol)) {
|
|
695
|
-
if (d.kind !==
|
|
815
|
+
if (d.kind !== 269 /* SyntaxKind.ModuleDeclaration */)
|
|
696
816
|
continue;
|
|
697
817
|
let container = d;
|
|
698
818
|
while (container !== undefined && !isModuleWithStringLiteralName(container))
|
|
699
819
|
container = container.parent;
|
|
700
|
-
if (container === undefined || container.parent === undefined || container.parent.kind !==
|
|
820
|
+
if (container === undefined || container.parent === undefined || container.parent.kind !== 308 /* SyntaxKind.SourceFile */)
|
|
701
821
|
continue;
|
|
702
822
|
const exportEquals = getSymbol(container)?.exports?.get("export=" /* InternalSymbolName.ExportEquals */);
|
|
703
823
|
const assignment = exportEquals?.valueDeclaration;
|
|
704
|
-
if (assignment === undefined || assignment.kind !==
|
|
824
|
+
if (assignment === undefined || assignment.kind !== 279 /* SyntaxKind.ExportAssignment */)
|
|
705
825
|
continue;
|
|
706
826
|
let exported = getSymbolAtLocation(c, getExpression(assignment));
|
|
707
827
|
if (exported === undefined)
|
|
@@ -709,26 +829,26 @@ function tryGetModuleNameFromAmbientModule(c, moduleSymbol) {
|
|
|
709
829
|
if ((exported.flags & 2097152 /* SymbolFlags.Alias */) !== 0)
|
|
710
830
|
exported = resolveAlias(c, exported);
|
|
711
831
|
if (exported === getSymbol(d))
|
|
712
|
-
return
|
|
832
|
+
return container;
|
|
713
833
|
}
|
|
714
|
-
return
|
|
834
|
+
return undefined;
|
|
715
835
|
}
|
|
716
836
|
function isModuleWithStringLiteralName(node) {
|
|
717
|
-
return node.kind ===
|
|
837
|
+
return node.kind === 269 /* SyntaxKind.ModuleDeclaration */ && getName(node)?.kind === 10 /* SyntaxKind.StringLiteral */;
|
|
718
838
|
}
|
|
719
839
|
function canHaveModuleSpecifier(node) {
|
|
720
840
|
switch (node.kind) {
|
|
721
|
-
case
|
|
722
|
-
case
|
|
723
|
-
case
|
|
724
|
-
case
|
|
725
|
-
case
|
|
726
|
-
case
|
|
727
|
-
case
|
|
728
|
-
case
|
|
729
|
-
case
|
|
730
|
-
case
|
|
731
|
-
case
|
|
841
|
+
case 262 /* SyntaxKind.VariableDeclaration */:
|
|
842
|
+
case 210 /* SyntaxKind.BindingElement */:
|
|
843
|
+
case 274 /* SyntaxKind.ImportDeclaration */:
|
|
844
|
+
case 280 /* SyntaxKind.ExportDeclaration */:
|
|
845
|
+
case 273 /* SyntaxKind.ImportEqualsDeclaration */:
|
|
846
|
+
case 275 /* SyntaxKind.ImportClause */:
|
|
847
|
+
case 282 /* SyntaxKind.NamespaceExport */:
|
|
848
|
+
case 276 /* SyntaxKind.NamespaceImport */:
|
|
849
|
+
case 283 /* SyntaxKind.ExportSpecifier */:
|
|
850
|
+
case 278 /* SyntaxKind.ImportSpecifier */:
|
|
851
|
+
case 207 /* SyntaxKind.ImportType */:
|
|
732
852
|
return true;
|
|
733
853
|
}
|
|
734
854
|
return false;
|
|
@@ -737,33 +857,33 @@ function canHaveModuleSpecifier(node) {
|
|
|
737
857
|
function tryGetModuleSpecifierFromDeclaration(node) {
|
|
738
858
|
let specifier;
|
|
739
859
|
switch (node.kind) {
|
|
740
|
-
case
|
|
741
|
-
case
|
|
860
|
+
case 262 /* SyntaxKind.VariableDeclaration */:
|
|
861
|
+
case 210 /* SyntaxKind.BindingElement */: {
|
|
742
862
|
let call = getInitializer(node);
|
|
743
|
-
while (call !== undefined && !isRequireCall(call, true))
|
|
863
|
+
while (call !== undefined && !isRequireCall(call, true) && !isImportCall(call))
|
|
744
864
|
call = call.parent;
|
|
745
865
|
specifier = call === undefined ? undefined : getArguments(call).nodes[0];
|
|
746
866
|
break;
|
|
747
867
|
}
|
|
748
|
-
case
|
|
749
|
-
case
|
|
868
|
+
case 274 /* SyntaxKind.ImportDeclaration */:
|
|
869
|
+
case 280 /* SyntaxKind.ExportDeclaration */:
|
|
750
870
|
specifier = getModuleSpecifier(node);
|
|
751
871
|
break;
|
|
752
|
-
case
|
|
872
|
+
case 273 /* SyntaxKind.ImportEqualsDeclaration */:
|
|
753
873
|
specifier = getExternalModuleName(node);
|
|
754
874
|
break;
|
|
755
|
-
case
|
|
756
|
-
case
|
|
875
|
+
case 275 /* SyntaxKind.ImportClause */:
|
|
876
|
+
case 282 /* SyntaxKind.NamespaceExport */:
|
|
757
877
|
specifier = getModuleSpecifier(node.parent);
|
|
758
878
|
break;
|
|
759
|
-
case
|
|
760
|
-
case
|
|
879
|
+
case 276 /* SyntaxKind.NamespaceImport */:
|
|
880
|
+
case 283 /* SyntaxKind.ExportSpecifier */:
|
|
761
881
|
specifier = getModuleSpecifier(node.parent.parent);
|
|
762
882
|
break;
|
|
763
|
-
case
|
|
883
|
+
case 278 /* SyntaxKind.ImportSpecifier */:
|
|
764
884
|
specifier = getModuleSpecifier(node.parent.parent.parent);
|
|
765
885
|
break;
|
|
766
|
-
case
|
|
886
|
+
case 207 /* SyntaxKind.ImportType */: {
|
|
767
887
|
const argument = node.argument;
|
|
768
888
|
specifier = argument instanceof LiteralTypeNode ? argument.literal : undefined;
|
|
769
889
|
break;
|