tsc-ts 0.0.9 → 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 +2 -2
- 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 +22 -15
- package/dist/api/compiler/ast.js +1026 -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 +178 -124
- 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 +472 -440
- 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 -107
- 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 +212 -75
- 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 +145 -36
- 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 +104 -31
- package/dist/api/compiler/checker.js +181 -33
- 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 +42 -3
- package/dist/api/compiler/compile-program.js +139 -27
- package/dist/api/compiler/diagnostic-messages.d.ts +1849 -1774
- package/dist/api/compiler/diagnostic-messages.js +128 -122
- package/dist/api/compiler/diagnostics.d.ts +22 -0
- package/dist/api/compiler/diagnostics.js +93 -11
- 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 +21 -1
- package/dist/api/compiler/file-loader.js +201 -48
- 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/parallel-parse.d.ts +3 -2
- package/dist/api/compiler/parallel-parse.js +17 -5
- 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 +5 -1
- package/dist/api/compiler/printer/emit-context.js +20 -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 +49 -2
- package/dist/api/compiler/printer/printer.js +539 -293
- package/dist/api/compiler/printer/utilities.js +149 -147
- package/dist/api/compiler/program-checker.d.ts +12 -2
- package/dist/api/compiler/program-checker.js +88 -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 +4 -6
- package/dist/api/compiler/program.js +74 -87
- 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 +347 -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 +23 -14
- package/dist/api/compiler/symbol.js +23 -11
- 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 +58 -26
- package/src/compiler/binder.ts +39 -4
- package/src/compiler/character-codes.ts +2 -2
- package/src/compiler/checker-calls.ts +79 -9
- 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 +136 -62
- package/src/compiler/checker-heritage.ts +22 -21
- package/src/compiler/checker-inference.ts +514 -82
- 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 +200 -56
- 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 +124 -23
- 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 +203 -39
- package/src/compiler/command-line.ts +28 -28
- package/src/compiler/compile-program.ts +167 -27
- package/src/compiler/decoder.ts +13 -4
- package/src/compiler/diagnostic-messages.ts +1973 -1892
- package/src/compiler/diagnostics.ts +84 -3
- 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 +197 -38
- package/src/compiler/help.ts +10 -14
- package/src/compiler/incremental.ts +165 -30
- 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 +326 -52
- package/src/compiler/parallel-emit.ts +320 -0
- package/src/compiler/parallel-parse.ts +16 -5
- package/src/compiler/parse-thread.ts +3 -0
- package/src/compiler/parser.ts +156 -39
- package/src/compiler/path.ts +22 -2
- package/src/compiler/printer/emit-context.ts +21 -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 +266 -30
- package/src/compiler/printer/utilities.ts +8 -2
- package/src/compiler/program-checker.ts +57 -5
- package/src/compiler/program-utilities.ts +23 -10
- package/src/compiler/program.ts +18 -26
- package/src/compiler/pseudo-bigint.ts +17 -0
- package/src/compiler/regexp-checker.ts +63 -30
- package/src/compiler/relations.ts +240 -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 +46 -24
- package/src/compiler/syntax-kind.ts +188 -187
- package/src/compiler/thread-entry.ts +64 -4
- 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 +66 -9
- package/src/compiler/tsc-cli.ts +7 -0
- package/src/compiler/tsc-compile.ts +284 -4
- 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
|
@@ -36,11 +36,24 @@ import {
|
|
|
36
36
|
getSourceFileOfNode,
|
|
37
37
|
isModuleAugmentationExternal,
|
|
38
38
|
} from './binder-utilities.js';
|
|
39
|
-
import {
|
|
39
|
+
import {
|
|
40
|
+
getExternalModuleName,
|
|
41
|
+
isAmbientModule,
|
|
42
|
+
isGlobalScopeAugmentation,
|
|
43
|
+
isImportCall,
|
|
44
|
+
isRequireCall,
|
|
45
|
+
} from './ast-utilities.js';
|
|
40
46
|
import { getSymbolAtLocation } from './checker-services.js';
|
|
41
47
|
import { checkExpression } from './checker-expressions.js';
|
|
42
|
-
import { getExportsOfSymbol, getMembersOfSymbol,
|
|
43
|
-
import {
|
|
48
|
+
import { getExportsOfSymbol, getMembersOfSymbol, getMergedSymbol, resolveAlias } from './checker-symbols.js';
|
|
49
|
+
import {
|
|
50
|
+
getImportAttributesTypeForModuleSpecifier,
|
|
51
|
+
getTypeOfModuleImportAttributes,
|
|
52
|
+
resolveExternalModule,
|
|
53
|
+
} from './checker-modules.js';
|
|
54
|
+
import { getPropertiesOfType } from './checker-members.js';
|
|
55
|
+
import { getTypeOfSymbol } from './checker-symbol-types.js';
|
|
56
|
+
import { compareSymbols, isEmptyObjectType } from './checker-type-factory.js';
|
|
44
57
|
import { TypeFlags, type LiteralType, type Type } from './checker-types.js';
|
|
45
58
|
import { isLateBoundName } from './checker-utilities.js';
|
|
46
59
|
import { isExternalModuleNameRelative, pathIsRelative } from './path.js';
|
|
@@ -67,6 +80,7 @@ import {
|
|
|
67
80
|
getQualifiedLeftMeaning,
|
|
68
81
|
getSymbolIfSameReference,
|
|
69
82
|
hasNonGlobalAugmentationExternalModuleDeclaration,
|
|
83
|
+
isSymbolAccessibleByFlags,
|
|
70
84
|
needsQualification,
|
|
71
85
|
} from './symbol-accessibility.js';
|
|
72
86
|
import { SyntaxKind } from './syntax-kind.js';
|
|
@@ -82,6 +96,7 @@ import {
|
|
|
82
96
|
InternalSymbolName,
|
|
83
97
|
type Symbol,
|
|
84
98
|
SymbolFlags,
|
|
99
|
+
tryGetAmbientModuleNameFromSymbolName,
|
|
85
100
|
} from './symbol.js';
|
|
86
101
|
|
|
87
102
|
// ---- Symbol chains
|
|
@@ -94,6 +109,16 @@ export function lookupSymbolChain(
|
|
|
94
109
|
yieldModuleSymbol: boolean,
|
|
95
110
|
): Symbol[] {
|
|
96
111
|
b.trackSymbol(symbol, b.enclosingDeclaration, meaning);
|
|
112
|
+
return lookupSymbolChainWorker(b, symbol, meaning, yieldModuleSymbol);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** `lookupSymbolChain` without tracking the symbol's accessibility. */
|
|
116
|
+
function lookupSymbolChainWorker(
|
|
117
|
+
b: NodeBuilder,
|
|
118
|
+
symbol: Symbol,
|
|
119
|
+
meaning: SymbolFlags,
|
|
120
|
+
yieldModuleSymbol: boolean,
|
|
121
|
+
): Symbol[] {
|
|
97
122
|
// Qualified only with somewhere to qualify from, and never for type parameters.
|
|
98
123
|
if (
|
|
99
124
|
(symbol.flags & SymbolFlags.TypeParameter) === 0 &&
|
|
@@ -132,7 +157,7 @@ function getSymbolChain(
|
|
|
132
157
|
order.push(specifiers.length);
|
|
133
158
|
specifiers.push(
|
|
134
159
|
hasNonGlobalAugmentationExternalModuleDeclaration(p)
|
|
135
|
-
? getSpecifierForModuleSymbol(b, p, ModuleKind.None)
|
|
160
|
+
? getSpecifierForModuleSymbol(b, p, ModuleKind.None).specifier
|
|
136
161
|
: '',
|
|
137
162
|
);
|
|
138
163
|
}
|
|
@@ -197,8 +222,8 @@ export function symbolToTypeNode(
|
|
|
197
222
|
const nonRootParts =
|
|
198
223
|
chain.length > 1 ? createAccessFromSymbolChain(b, chain, chain.length - 1, 1, typeArguments) : undefined;
|
|
199
224
|
const typeParameterNodes = typeArguments ?? lookupTypeParameterNodes(b, chain, 0);
|
|
200
|
-
let specifier = '';
|
|
201
|
-
let
|
|
225
|
+
let specifier = new ModuleSpecifierResult('', undefined);
|
|
226
|
+
let importModeOverride = ModuleKind.None;
|
|
202
227
|
const c = b.c;
|
|
203
228
|
const resolution = getModuleResolutionKind(c.compilerOptions);
|
|
204
229
|
const nodeNext = resolution === ModuleResolutionKind.Node16 || resolution === ModuleResolutionKind.NodeNext;
|
|
@@ -213,29 +238,33 @@ export function symbolToTypeNode(
|
|
|
213
238
|
const targetFormat = c.host.getEmitModuleFormatOfFile(targetFile);
|
|
214
239
|
if (targetFormat === ModuleKind.ESNext && targetFormat !== c.host.getEmitModuleFormatOfFile(contextFile)) {
|
|
215
240
|
specifier = getSpecifierForModuleSymbol(b, chain[0]!, ModuleKind.ESNext);
|
|
216
|
-
|
|
241
|
+
importModeOverride = ModuleKind.ESNext;
|
|
217
242
|
}
|
|
218
243
|
}
|
|
219
244
|
}
|
|
220
|
-
if (specifier === '') specifier = getSpecifierForModuleSymbol(b, chain[0]!, ModuleKind.None);
|
|
221
|
-
if (
|
|
245
|
+
if (specifier.specifier === '') specifier = getSpecifierForModuleSymbol(b, chain[0]!, ModuleKind.None);
|
|
246
|
+
if (
|
|
247
|
+
(b.flags & NodeBuilderFlags.AllowNodeModulesRelativePaths) === 0 &&
|
|
248
|
+
specifier.specifier.includes('/node_modules/')
|
|
249
|
+
) {
|
|
222
250
|
const oldSpecifier = specifier;
|
|
223
251
|
if (nodeNext && contextFile !== undefined) {
|
|
224
252
|
// The other mode may reach the module portably.
|
|
225
253
|
const swappedMode =
|
|
226
254
|
c.host.getEmitModuleFormatOfFile(contextFile) === ModuleKind.ESNext ? ModuleKind.CommonJS : ModuleKind.ESNext;
|
|
227
255
|
specifier = getSpecifierForModuleSymbol(b, chain[0]!, swappedMode);
|
|
228
|
-
if (specifier.includes('/node_modules/')) specifier = oldSpecifier;
|
|
229
|
-
else
|
|
256
|
+
if (specifier.specifier.includes('/node_modules/')) specifier = oldSpecifier;
|
|
257
|
+
else importModeOverride = swappedMode;
|
|
230
258
|
}
|
|
231
|
-
if (
|
|
259
|
+
if (importModeOverride === ModuleKind.None) {
|
|
232
260
|
// A reference into `node_modules` is likely to break when published.
|
|
233
261
|
b.encounteredError = true;
|
|
234
|
-
b.tracker.reportLikelyUnsafeImportRequiredError(oldSpecifier, symbol.name);
|
|
262
|
+
b.tracker.reportLikelyUnsafeImportRequiredError(oldSpecifier.specifier, symbol.name);
|
|
235
263
|
}
|
|
236
264
|
}
|
|
237
|
-
const
|
|
238
|
-
b.
|
|
265
|
+
const attributes = createImportAttributesForModuleSpecifier(b, specifier, importModeOverride);
|
|
266
|
+
const literal = b.created(new LiteralTypeNode(b.stringLiteral(specifier.specifier, false)));
|
|
267
|
+
b.approximateLength += specifier.specifier.length + 10;
|
|
239
268
|
if (nonRootParts === undefined || isEntityName(nonRootParts))
|
|
240
269
|
return b.created(new ImportTypeNode(isTypeOf, literal, attributes, nonRootParts, typeParameterNodes));
|
|
241
270
|
const splitNode = getTopmostIndexedAccessType(nonRootParts as IndexedAccessTypeNode);
|
|
@@ -263,12 +292,48 @@ function isEntityName(node: Node): boolean {
|
|
|
263
292
|
return node.kind === SyntaxKind.Identifier || node.kind === SyntaxKind.QualifiedName;
|
|
264
293
|
}
|
|
265
294
|
|
|
266
|
-
/**
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
295
|
+
/**
|
|
296
|
+
* The attributes of an `import()` type: a `resolution-mode` for `importModeOverride`, then the
|
|
297
|
+
* string literal properties of the specifier's import attributes type, by name.
|
|
298
|
+
*/
|
|
299
|
+
function createImportAttributesForModuleSpecifier(
|
|
300
|
+
b: NodeBuilder,
|
|
301
|
+
result: ModuleSpecifierResult,
|
|
302
|
+
importModeOverride: ModuleKind,
|
|
303
|
+
): ImportAttributes | undefined {
|
|
304
|
+
const c = b.c;
|
|
305
|
+
const attributesType = result.importAttributesType;
|
|
306
|
+
const isEmptyAttributesType = attributesType === undefined || isEmptyObjectType(c, attributesType);
|
|
307
|
+
if (isEmptyAttributesType && importModeOverride === ModuleKind.None) return undefined;
|
|
308
|
+
const attributes: Node[] = [];
|
|
309
|
+
if (importModeOverride !== ModuleKind.None) {
|
|
310
|
+
const mode = importModeOverride === ModuleKind.ESNext ? 'import' : 'require';
|
|
311
|
+
attributes.push(
|
|
312
|
+
b.created(new ImportAttribute(b.stringLiteral('resolution-mode', false), b.stringLiteral(mode, false))),
|
|
313
|
+
);
|
|
314
|
+
b.approximateLength += 'resolution-mode'.length + mode.length + 6;
|
|
315
|
+
}
|
|
316
|
+
if (!isEmptyAttributesType) {
|
|
317
|
+
const properties = getPropertiesOfType(c, attributesType).slice();
|
|
318
|
+
properties.sort((x: Symbol, y: Symbol) => (x.name < y.name ? -1 : x.name > y.name ? 1 : 0));
|
|
319
|
+
for (const property of properties) {
|
|
320
|
+
const name = property.name;
|
|
321
|
+
const propertyType = getTypeOfSymbol(c, property);
|
|
322
|
+
if ((propertyType.flags & TypeFlags.StringLiteral) === 0) continue;
|
|
323
|
+
const value = (propertyType as LiteralType).stringValue;
|
|
324
|
+
let nameNode: Node;
|
|
325
|
+
if (isIdentifierText(name)) nameNode = b.factory.createIdentifier(name);
|
|
326
|
+
else {
|
|
327
|
+
nameNode = b.stringLiteral(name, false);
|
|
328
|
+
b.approximateLength += 2;
|
|
329
|
+
}
|
|
330
|
+
attributes.push(b.created(new ImportAttribute(nameNode, b.stringLiteral(value, false))));
|
|
331
|
+
b.approximateLength += name.length + value.length + 4;
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
if (attributes.length === 0) return undefined;
|
|
335
|
+
b.approximateLength += 16 + 2 * (attributes.length - 1);
|
|
336
|
+
return b.created(new ImportAttributes(SyntaxKind.WithKeyword, b.list(attributes), false));
|
|
272
337
|
}
|
|
273
338
|
|
|
274
339
|
function getTopmostIndexedAccessType(node: IndexedAccessTypeNode): IndexedAccessTypeNode {
|
|
@@ -355,7 +420,7 @@ function createAccessFromSymbolChain(
|
|
|
355
420
|
return b.created(new IndexedAccessTypeNode(b.created(new TypeReferenceNode(lhs, typeParameterNodes)), literal));
|
|
356
421
|
}
|
|
357
422
|
}
|
|
358
|
-
const identifier = b.
|
|
423
|
+
const identifier = b.symbolIdentifier(symbolName, symbol);
|
|
359
424
|
b.context.addEmitFlags(identifier, EmitFlags.NoAsciiEscaping);
|
|
360
425
|
if (index > stopper) {
|
|
361
426
|
const lhs = createAccessFromSymbolChain(b, chain, index - 1, stopper, overrideTypeArguments);
|
|
@@ -467,7 +532,7 @@ function createEntityNameFromSymbolChain(b: NodeBuilder, chain: Symbol[], index:
|
|
|
467
532
|
if (index === 0) b.flags |= NodeBuilderFlags.InInitialEntityName;
|
|
468
533
|
const symbolName = getNameOfSymbolAsWritten(b, symbol);
|
|
469
534
|
if (index === 0) b.flags ^= NodeBuilderFlags.InInitialEntityName;
|
|
470
|
-
const identifier = b.
|
|
535
|
+
const identifier = b.symbolIdentifier(symbolName, symbol);
|
|
471
536
|
b.context.addEmitFlags(identifier, EmitFlags.NoAsciiEscaping);
|
|
472
537
|
if (index > 0) return b.created(new QualifiedName(createEntityNameFromSymbolChain(b, chain, index - 1), identifier));
|
|
473
538
|
return identifier;
|
|
@@ -482,7 +547,13 @@ export function symbolToEntityNameNode(b: NodeBuilder, symbol: Symbol): Node {
|
|
|
482
547
|
}
|
|
483
548
|
|
|
484
549
|
export function symbolToExpression(b: NodeBuilder, symbol: Symbol, meaning: SymbolFlags): Node {
|
|
485
|
-
|
|
550
|
+
b.trackSymbol(symbol, b.enclosingDeclaration, meaning);
|
|
551
|
+
return symbolToExpressionWorker(b, symbol, meaning);
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
/** `symbolToExpression` without tracking the symbol's accessibility. */
|
|
555
|
+
function symbolToExpressionWorker(b: NodeBuilder, symbol: Symbol, meaning: SymbolFlags): Node {
|
|
556
|
+
const chain = lookupSymbolChainWorker(b, symbol, meaning, false);
|
|
486
557
|
return createExpressionFromSymbolChain(b, chain, chain.length - 1);
|
|
487
558
|
}
|
|
488
559
|
|
|
@@ -493,7 +564,7 @@ function createExpressionFromSymbolChain(b: NodeBuilder, chain: Symbol[], index:
|
|
|
493
564
|
let symbolName = getNameOfSymbolAsWritten(b, symbol);
|
|
494
565
|
if (index === 0) b.flags ^= NodeBuilderFlags.InInitialEntityName;
|
|
495
566
|
if (startsWithQuote(symbolName) && hasNonGlobalAugmentationExternalModuleDeclaration(symbol)) {
|
|
496
|
-
const specifier = getSpecifierForModuleSymbol(b, symbol, ModuleKind.None);
|
|
567
|
+
const specifier = getSpecifierForModuleSymbol(b, symbol, ModuleKind.None).specifier;
|
|
497
568
|
b.approximateLength += 2 + specifier.length;
|
|
498
569
|
return b.stringLiteral(specifier, false);
|
|
499
570
|
}
|
|
@@ -719,7 +790,11 @@ function isSingleQuotedStringNamed(d: Node): boolean {
|
|
|
719
790
|
}
|
|
720
791
|
|
|
721
792
|
/** The name node of a property. */
|
|
722
|
-
export function getPropertyNameNodeForSymbol(
|
|
793
|
+
export function getPropertyNameNodeForSymbol(
|
|
794
|
+
b: NodeBuilder,
|
|
795
|
+
symbol: Symbol,
|
|
796
|
+
enclosingDeclaration: Node | undefined,
|
|
797
|
+
): Node {
|
|
723
798
|
// A private name is the declaration's.
|
|
724
799
|
const valueDeclaration = symbol.valueDeclaration;
|
|
725
800
|
if (valueDeclaration !== undefined) {
|
|
@@ -741,7 +816,14 @@ export function getPropertyNameNodeForSymbol(b: NodeBuilder, symbol: Symbol): No
|
|
|
741
816
|
break;
|
|
742
817
|
}
|
|
743
818
|
const isMethod = (symbol.flags & SymbolFlags.Method) !== 0;
|
|
744
|
-
const fromNameType = getPropertyNameNodeForSymbolFromNameType(
|
|
819
|
+
const fromNameType = getPropertyNameNodeForSymbolFromNameType(
|
|
820
|
+
b,
|
|
821
|
+
symbol,
|
|
822
|
+
enclosingDeclaration,
|
|
823
|
+
singleQuote,
|
|
824
|
+
stringNamed,
|
|
825
|
+
isMethod,
|
|
826
|
+
);
|
|
745
827
|
if (fromNameType !== undefined) return fromNameType;
|
|
746
828
|
let name = symbol.name;
|
|
747
829
|
const privateNamePrefix = '#';
|
|
@@ -775,12 +857,28 @@ function createPropertyNameNodeForIdentifierOrLiteral(
|
|
|
775
857
|
function getPropertyNameNodeForSymbolFromNameType(
|
|
776
858
|
b: NodeBuilder,
|
|
777
859
|
symbol: Symbol,
|
|
860
|
+
enclosingDeclaration: Node | undefined,
|
|
778
861
|
singleQuote: boolean,
|
|
779
862
|
stringNamed: boolean,
|
|
780
863
|
isMethod: boolean,
|
|
781
864
|
): Node | undefined {
|
|
782
865
|
const nameType = b.c.symbolNameTypes.get(getSymbolId(symbol));
|
|
783
866
|
if (nameType === undefined) return undefined;
|
|
867
|
+
// A name from an enum member stays a computed name, `[E.A]`, where the enum can be named.
|
|
868
|
+
if ((nameType.flags & TypeFlags.EnumLiteral) !== 0) {
|
|
869
|
+
const enumEnclosingDeclaration = enclosingDeclaration !== undefined ? enclosingDeclaration : b.enclosingFile;
|
|
870
|
+
const enumSymbol = nameType.symbol!.parent !== undefined ? nameType.symbol!.parent : nameType.symbol!;
|
|
871
|
+
if (
|
|
872
|
+
enumEnclosingDeclaration !== undefined &&
|
|
873
|
+
isSymbolAccessibleByFlags(b.c, enumSymbol, enumEnclosingDeclaration, SymbolFlags.Value)
|
|
874
|
+
) {
|
|
875
|
+
const saveEnclosingDeclaration = b.enclosingDeclaration;
|
|
876
|
+
b.enclosingDeclaration = enumEnclosingDeclaration;
|
|
877
|
+
const result = b.created(new ComputedPropertyName(symbolToExpression(b, nameType.symbol!, SymbolFlags.Value)));
|
|
878
|
+
b.enclosingDeclaration = saveEnclosingDeclaration;
|
|
879
|
+
return result;
|
|
880
|
+
}
|
|
881
|
+
}
|
|
784
882
|
if ((nameType.flags & TypeFlags.StringOrNumberLiteral) !== 0) {
|
|
785
883
|
const literal = nameType as LiteralType;
|
|
786
884
|
const name = (nameType.flags & TypeFlags.StringLiteral) !== 0 ? literal.stringValue : String(literal.numberValue);
|
|
@@ -796,20 +894,44 @@ function getPropertyNameNodeForSymbolFromNameType(
|
|
|
796
894
|
);
|
|
797
895
|
return createPropertyNameNodeForIdentifierOrLiteral(b, name, singleQuote, stringNamed, isMethod);
|
|
798
896
|
}
|
|
897
|
+
// The reference is tracked where the name is used; spelling it here must not track it in this scope.
|
|
799
898
|
if ((nameType.flags & TypeFlags.UniqueESSymbol) !== 0)
|
|
800
|
-
return b.created(new ComputedPropertyName(
|
|
899
|
+
return b.created(new ComputedPropertyName(symbolToExpressionWorker(b, nameType.symbol!, SymbolFlags.Value)));
|
|
801
900
|
return undefined;
|
|
802
901
|
}
|
|
803
902
|
|
|
804
903
|
// ---- Module specifiers
|
|
805
904
|
|
|
905
|
+
/** A module specifier, and the import attributes type an `import()` type with it needs. */
|
|
906
|
+
export class ModuleSpecifierResult {
|
|
907
|
+
constructor(
|
|
908
|
+
readonly specifier: string,
|
|
909
|
+
readonly importAttributesType: Type | undefined,
|
|
910
|
+
) {}
|
|
911
|
+
}
|
|
912
|
+
|
|
806
913
|
/**
|
|
807
914
|
* The specifier an `import("…")` type names a module with: an ambient module's name, the file
|
|
808
915
|
* name without an enclosing file, else what module specifier generation gives for the enclosing
|
|
809
|
-
* file. `overrideImportMode` is `None` for the mode of the enclosing import or file.
|
|
916
|
+
* file. `overrideImportMode` is `None` for the mode of the enclosing import or file. A pattern
|
|
917
|
+
* ambient module's specifier comes with the attributes type that resolves it.
|
|
810
918
|
*/
|
|
811
|
-
export function getSpecifierForModuleSymbol(
|
|
919
|
+
export function getSpecifierForModuleSymbol(
|
|
920
|
+
b: NodeBuilder,
|
|
921
|
+
symbol: Symbol,
|
|
922
|
+
overrideImportMode: ModuleKind,
|
|
923
|
+
): ModuleSpecifierResult {
|
|
812
924
|
const c = b.c;
|
|
925
|
+
const enclosingDeclaration =
|
|
926
|
+
b.enclosingDeclaration === undefined ? undefined : b.context.mostOriginal(b.enclosingDeclaration);
|
|
927
|
+
const originalModuleSpecifier =
|
|
928
|
+
enclosingDeclaration !== undefined && canHaveModuleSpecifier(enclosingDeclaration)
|
|
929
|
+
? tryGetModuleSpecifierFromDeclaration(enclosingDeclaration)
|
|
930
|
+
: undefined;
|
|
931
|
+
const originalImportAttributesType =
|
|
932
|
+
originalModuleSpecifier !== undefined
|
|
933
|
+
? getImportAttributesTypeForModuleSpecifier(c, originalModuleSpecifier)
|
|
934
|
+
: undefined;
|
|
813
935
|
let file = asSourceFile(getDeclarationOfKind(symbol, SyntaxKind.SourceFile));
|
|
814
936
|
if (file === undefined)
|
|
815
937
|
for (const d of getDeclarations(symbol)) {
|
|
@@ -819,20 +941,27 @@ export function getSpecifierForModuleSymbol(b: NodeBuilder, symbol: Symbol, over
|
|
|
819
941
|
break;
|
|
820
942
|
}
|
|
821
943
|
}
|
|
822
|
-
if (file === undefined
|
|
823
|
-
|
|
944
|
+
if (file === undefined) {
|
|
945
|
+
for (const declaration of getDeclarations(symbol))
|
|
946
|
+
if (isModuleWithStringLiteralName(declaration)) {
|
|
947
|
+
const specifier = getText(getName(declaration)!);
|
|
948
|
+
if (
|
|
949
|
+
originalImportAttributesType !== undefined &&
|
|
950
|
+
moduleSpecifierResolvesToSymbol(b, specifier, originalImportAttributesType, symbol)
|
|
951
|
+
)
|
|
952
|
+
return new ModuleSpecifierResult(specifier, originalImportAttributesType);
|
|
953
|
+
return new ModuleSpecifierResult(specifier, getTypeOfModuleImportAttributes(c, symbol));
|
|
954
|
+
}
|
|
955
|
+
const ambientName = tryGetAmbientModuleNameFromSymbolName(symbol.name);
|
|
956
|
+
if (ambientName !== undefined) return new ModuleSpecifierResult(ambientName, undefined);
|
|
957
|
+
}
|
|
824
958
|
const contextFile = b.enclosingFile;
|
|
825
959
|
if (contextFile === undefined) {
|
|
826
|
-
|
|
960
|
+
const ambientName = tryGetAmbientModuleNameFromSymbolName(symbol.name);
|
|
961
|
+
if (ambientName !== undefined) return new ModuleSpecifierResult(ambientName, undefined);
|
|
827
962
|
const moduleFile = getSourceFileOfModule(symbol);
|
|
828
|
-
return moduleFile === undefined ? '' : moduleFile.fileName;
|
|
963
|
+
return new ModuleSpecifierResult(moduleFile === undefined ? '' : moduleFile.fileName, undefined);
|
|
829
964
|
}
|
|
830
|
-
const enclosingDeclaration =
|
|
831
|
-
b.enclosingDeclaration === undefined ? undefined : b.context.mostOriginal(b.enclosingDeclaration);
|
|
832
|
-
const originalModuleSpecifier =
|
|
833
|
-
enclosingDeclaration !== undefined && canHaveModuleSpecifier(enclosingDeclaration)
|
|
834
|
-
? tryGetModuleSpecifierFromDeclaration(enclosingDeclaration)
|
|
835
|
-
: undefined;
|
|
836
965
|
let resolutionMode = overrideImportMode;
|
|
837
966
|
if (resolutionMode === ModuleKind.None)
|
|
838
967
|
resolutionMode =
|
|
@@ -841,16 +970,57 @@ export function getSpecifierForModuleSymbol(b: NodeBuilder, symbol: Symbol, over
|
|
|
841
970
|
: c.host.getDefaultResolutionModeForFile(contextFile);
|
|
842
971
|
const key = getSymbolId(symbol) + '|' + contextFile.path + '|' + resolutionMode;
|
|
843
972
|
const cached = c.moduleSpecifiers.get(key);
|
|
844
|
-
if (cached !== undefined) return cached;
|
|
973
|
+
if (cached !== undefined) return moduleSpecifierResultForSymbol(b, cached, originalImportAttributesType, symbol);
|
|
845
974
|
// Declaration emit prefers project-relative specifiers, with `.js` extensions in ES modules.
|
|
846
975
|
const preferences = new ModuleSpecifierPreferences(
|
|
847
976
|
'project-relative',
|
|
848
977
|
resolutionMode === ModuleKind.ESNext ? 'js' : '',
|
|
849
978
|
);
|
|
850
|
-
const specifiers =
|
|
851
|
-
const
|
|
852
|
-
|
|
853
|
-
|
|
979
|
+
const specifiers = getModuleSpecifiersWithAmbientModule(c, symbol, contextFile, preferences, overrideImportMode);
|
|
980
|
+
const result = new ModuleSpecifierResult(
|
|
981
|
+
specifiers.specifiers.length > 0 ? specifiers.specifiers[0]! : '',
|
|
982
|
+
specifiers.ambientModuleSymbol !== undefined
|
|
983
|
+
? getTypeOfModuleImportAttributes(c, specifiers.ambientModuleSymbol)
|
|
984
|
+
: undefined,
|
|
985
|
+
);
|
|
986
|
+
c.moduleSpecifiers.set(key, result);
|
|
987
|
+
return moduleSpecifierResultForSymbol(b, result, originalImportAttributesType, symbol);
|
|
988
|
+
}
|
|
989
|
+
|
|
990
|
+
/** `result` with `importAttributesType`, if its specifier resolves to `symbol` with those attributes. */
|
|
991
|
+
function moduleSpecifierResultForSymbol(
|
|
992
|
+
b: NodeBuilder,
|
|
993
|
+
result: ModuleSpecifierResult,
|
|
994
|
+
importAttributesType: Type | undefined,
|
|
995
|
+
symbol: Symbol,
|
|
996
|
+
): ModuleSpecifierResult {
|
|
997
|
+
if (
|
|
998
|
+
importAttributesType !== undefined &&
|
|
999
|
+
moduleSpecifierResolvesToSymbol(b, result.specifier, importAttributesType, symbol)
|
|
1000
|
+
)
|
|
1001
|
+
return new ModuleSpecifierResult(result.specifier, importAttributesType);
|
|
1002
|
+
return result;
|
|
1003
|
+
}
|
|
1004
|
+
|
|
1005
|
+
function moduleSpecifierResolvesToSymbol(
|
|
1006
|
+
b: NodeBuilder,
|
|
1007
|
+
specifier: string,
|
|
1008
|
+
importAttributesType: Type,
|
|
1009
|
+
symbol: Symbol,
|
|
1010
|
+
): boolean {
|
|
1011
|
+
const location = b.enclosingDeclaration ?? b.enclosingFile;
|
|
1012
|
+
if (location === undefined) return false;
|
|
1013
|
+
const c = b.c;
|
|
1014
|
+
const resolved = resolveExternalModule(c, location, specifier, undefined, undefined, false, importAttributesType);
|
|
1015
|
+
return resolved !== undefined && getMergedSymbol(c, resolved) === getMergedSymbol(c, symbol);
|
|
1016
|
+
}
|
|
1017
|
+
|
|
1018
|
+
/** The specifiers of `getModuleSpecifiers`, and the ambient module symbol that gives an ambient module's name. */
|
|
1019
|
+
class ModuleSpecifiers {
|
|
1020
|
+
constructor(
|
|
1021
|
+
readonly specifiers: string[],
|
|
1022
|
+
readonly ambientModuleSymbol: Symbol | undefined,
|
|
1023
|
+
) {}
|
|
854
1024
|
}
|
|
855
1025
|
|
|
856
1026
|
/** Specifiers `importingFile` can import the module `moduleSymbol` with, best first. */
|
|
@@ -861,13 +1031,24 @@ export function getModuleSpecifiers(
|
|
|
861
1031
|
preferences: ModuleSpecifierPreferences,
|
|
862
1032
|
overrideImportMode: ModuleKind,
|
|
863
1033
|
): string[] {
|
|
1034
|
+
return getModuleSpecifiersWithAmbientModule(c, moduleSymbol, importingFile, preferences, overrideImportMode)
|
|
1035
|
+
.specifiers;
|
|
1036
|
+
}
|
|
1037
|
+
|
|
1038
|
+
function getModuleSpecifiersWithAmbientModule(
|
|
1039
|
+
c: Checker,
|
|
1040
|
+
moduleSymbol: Symbol,
|
|
1041
|
+
importingFile: SourceFile,
|
|
1042
|
+
preferences: ModuleSpecifierPreferences,
|
|
1043
|
+
overrideImportMode: ModuleKind,
|
|
1044
|
+
): ModuleSpecifiers {
|
|
864
1045
|
const ambient = tryGetModuleNameFromAmbientModule(c, moduleSymbol);
|
|
865
|
-
if (ambient !==
|
|
1046
|
+
if (ambient !== undefined) return new ModuleSpecifiers([getText(getName(ambient)!)], getSymbol(ambient));
|
|
866
1047
|
const moduleFile = getSourceFileOfModule(moduleSymbol);
|
|
867
|
-
if (moduleFile === undefined) return [];
|
|
1048
|
+
if (moduleFile === undefined) return new ModuleSpecifiers([], undefined);
|
|
868
1049
|
const host = getModuleSpecifierHost(c);
|
|
869
1050
|
// A referenced project's declaration output is named by its source.
|
|
870
|
-
|
|
1051
|
+
const specifiers = getModuleSpecifiersForFile(
|
|
871
1052
|
importingFile,
|
|
872
1053
|
host.getSourceOfProjectReferenceIfOutputIncluded(moduleFile),
|
|
873
1054
|
c.compilerOptions,
|
|
@@ -876,6 +1057,7 @@ export function getModuleSpecifiers(
|
|
|
876
1057
|
overrideImportMode,
|
|
877
1058
|
false,
|
|
878
1059
|
);
|
|
1060
|
+
return new ModuleSpecifiers(specifiers, undefined);
|
|
879
1061
|
}
|
|
880
1062
|
|
|
881
1063
|
function getModuleSpecifierHost(c: Checker): ModuleSpecifierHost {
|
|
@@ -890,12 +1072,12 @@ function getModuleSpecifierHost(c: Checker): ModuleSpecifierHost {
|
|
|
890
1072
|
return host;
|
|
891
1073
|
}
|
|
892
1074
|
|
|
893
|
-
/** The
|
|
894
|
-
function tryGetModuleNameFromAmbientModule(c: Checker, moduleSymbol: Symbol):
|
|
1075
|
+
/** The ambient module declaring `moduleSymbol`, or the one whose `export =` it is. */
|
|
1076
|
+
function tryGetModuleNameFromAmbientModule(c: Checker, moduleSymbol: Symbol): Node | undefined {
|
|
895
1077
|
for (const d of getDeclarations(moduleSymbol)) {
|
|
896
1078
|
const name = isModuleWithStringLiteralName(d) ? getName(d)! : undefined;
|
|
897
1079
|
if (name !== undefined && (!isModuleAugmentationExternal(d) || !isExternalModuleNameRelative(getText(name))))
|
|
898
|
-
return
|
|
1080
|
+
return d;
|
|
899
1081
|
}
|
|
900
1082
|
// A namespace exported with `export =` from an ambient module: `import { c } from "m"` names
|
|
901
1083
|
// `ns.c` for `declare module "m" { namespace ns { class c {} } export = ns; }`.
|
|
@@ -911,9 +1093,9 @@ function tryGetModuleNameFromAmbientModule(c: Checker, moduleSymbol: Symbol): st
|
|
|
911
1093
|
let exported = getSymbolAtLocation(c, getExpression(assignment)!);
|
|
912
1094
|
if (exported === undefined) continue;
|
|
913
1095
|
if ((exported.flags & SymbolFlags.Alias) !== 0) exported = resolveAlias(c, exported);
|
|
914
|
-
if (exported === getSymbol(d)) return
|
|
1096
|
+
if (exported === getSymbol(d)) return container;
|
|
915
1097
|
}
|
|
916
|
-
return
|
|
1098
|
+
return undefined;
|
|
917
1099
|
}
|
|
918
1100
|
|
|
919
1101
|
function isModuleWithStringLiteralName(node: Node): boolean {
|
|
@@ -945,7 +1127,7 @@ function tryGetModuleSpecifierFromDeclaration(node: Node): Node | undefined {
|
|
|
945
1127
|
case SyntaxKind.VariableDeclaration:
|
|
946
1128
|
case SyntaxKind.BindingElement: {
|
|
947
1129
|
let call = getInitializer(node);
|
|
948
|
-
while (call !== undefined && !isRequireCall(call, true)) call = call.parent;
|
|
1130
|
+
while (call !== undefined && !isRequireCall(call, true) && !isImportCall(call)) call = call.parent;
|
|
949
1131
|
specifier = call === undefined ? undefined : getArguments(call)!.nodes[0];
|
|
950
1132
|
break;
|
|
951
1133
|
}
|
|
@@ -33,7 +33,7 @@ import { isFunctionLike } from './ast-utilities.js';
|
|
|
33
33
|
import { getSourceFileOfNode, isEntityNameExpression } from './binder-utilities.js';
|
|
34
34
|
import type { Checker } from './checker.js';
|
|
35
35
|
import { ContextFlags, getContextualType, instantiateContextualType } from './checker-contextual.js';
|
|
36
|
-
import {
|
|
36
|
+
import { getTypeOfExpression, isConstContext, isLiteralOfContextualType } from './checker-expressions.js';
|
|
37
37
|
import { getTypeWithFacts, TypeFacts } from './checker-flow.js';
|
|
38
38
|
import { getPropertiesOfType, getPropertyOfType } from './checker-members.js';
|
|
39
39
|
import {
|
|
@@ -154,7 +154,8 @@ export function getRegularTypeOfExpression(c: Checker, node: Node): Type {
|
|
|
154
154
|
(parent instanceof PropertyAccessExpression && parent.name === node)
|
|
155
155
|
)
|
|
156
156
|
expr = parent;
|
|
157
|
-
|
|
157
|
+
// Rechecks the expression, as tsgo does, unless its type needed control flow analysis.
|
|
158
|
+
return getRegularTypeOfLiteralType(c, getTypeOfExpression(c, expr));
|
|
158
159
|
}
|
|
159
160
|
|
|
160
161
|
function keyword(b: NodeBuilder, kind: SyntaxKind): Node {
|
|
@@ -219,7 +220,7 @@ export function pseudoTypeToNode(b: NodeBuilder, t: PseudoType): Node | undefine
|
|
|
219
220
|
if (parent.kind === SyntaxKind.ArrowFunction && getBody(parent) === node)
|
|
220
221
|
return b.serializeReturnTypeForSignatureEx(getSignatureFromDeclaration(c, parent), false);
|
|
221
222
|
if (isDeclaration(parent)) return b.serializeTypeForDeclaration(parent, undefined, undefined, false);
|
|
222
|
-
return b.typeToTypeNode(
|
|
223
|
+
return b.typeToTypeNode(getTypeOfExpression(c, node));
|
|
223
224
|
}
|
|
224
225
|
case PseudoTypeKind.NoResult: {
|
|
225
226
|
const node = (t as NoResultType).declaration;
|
|
@@ -762,10 +763,6 @@ export function pseudoReturnTypeMatchesPredicate(b: NodeBuilder, rt: PseudoType,
|
|
|
762
763
|
return true;
|
|
763
764
|
}
|
|
764
765
|
|
|
765
|
-
function getTypeOfExpressionForPseudo(c: Checker, node: Node): Type {
|
|
766
|
-
return checkExpressionCached(c, node);
|
|
767
|
-
}
|
|
768
|
-
|
|
769
766
|
/** The type a pseudo-type denotes, for the kinds that map to one directly. */
|
|
770
767
|
export function pseudoTypeToType(b: NodeBuilder, t: PseudoType): Type | undefined {
|
|
771
768
|
const c = b.c;
|
|
@@ -82,6 +82,7 @@ import { BuilderTracker, type NodeBuilder, TrackedSymbol, canReuseExistingJSType
|
|
|
82
82
|
import { getSpecifierForModuleSymbol, lookupSymbolChain, symbolToTypeNode } from './node-builder-names.js';
|
|
83
83
|
import { getExternalModuleFileFromDeclaration } from './checker-modules.js';
|
|
84
84
|
import { getResolutionModeOverride } from './program-utilities.js';
|
|
85
|
+
import { getMappedType } from './checker-types.js';
|
|
85
86
|
|
|
86
87
|
/** Errors and names tracked while reusing a node, replayed only if the reuse succeeds. */
|
|
87
88
|
class RecoveryBoundary {
|
|
@@ -435,7 +436,7 @@ class ExistingNodeReuser extends VisitorBase {
|
|
|
435
436
|
if ((symbol.flags & SymbolFlags.TypeParameter) !== 0) {
|
|
436
437
|
const declaredType = getDeclaredTypeOfSymbol(b.c, symbol);
|
|
437
438
|
// A type parameter remapped by the scope.
|
|
438
|
-
if (b.mapper !== undefined && b.mapper
|
|
439
|
+
if (b.mapper !== undefined && getMappedType(declaredType, b.mapper) !== declaredType) return undefined;
|
|
439
440
|
}
|
|
440
441
|
if (!canReuseExistingJSTypeNode(b, node, b.getTypeFromTypeNode(node, false)!)) return undefined;
|
|
441
442
|
const name = this.trackExistingEntityName(node.typeName);
|
|
@@ -700,11 +701,11 @@ function getModuleSpecifierOverride(b: NodeBuilder, parent: ImportTypeNode, lite
|
|
|
700
701
|
? lookupSymbolChain(b, nodeSymbol, meaning, true)[0]
|
|
701
702
|
: undefined;
|
|
702
703
|
if (parentSymbol !== undefined && isExternalModuleSymbol(parentSymbol))
|
|
703
|
-
name = getSpecifierForModuleSymbol(b, parentSymbol, mode);
|
|
704
|
+
name = getSpecifierForModuleSymbol(b, parentSymbol, mode).specifier;
|
|
704
705
|
else {
|
|
705
706
|
const targetFile = getExternalModuleFileFromDeclaration(c, parent);
|
|
706
707
|
if (targetFile !== undefined && targetFile.symbol !== undefined)
|
|
707
|
-
name = getSpecifierForModuleSymbol(b, targetFile.symbol, mode);
|
|
708
|
+
name = getSpecifierForModuleSymbol(b, targetFile.symbol, mode).specifier;
|
|
708
709
|
}
|
|
709
710
|
if (name.includes('/node_modules/')) {
|
|
710
711
|
b.encounteredError = true;
|
|
@@ -714,7 +715,7 @@ function getModuleSpecifierOverride(b: NodeBuilder, parent: ImportTypeNode, lite
|
|
|
714
715
|
}
|
|
715
716
|
|
|
716
717
|
function isExternalModuleSymbol(symbol: Symbol): boolean {
|
|
717
|
-
return
|
|
718
|
+
return symbol.isExternalModule();
|
|
718
719
|
}
|
|
719
720
|
|
|
720
721
|
function isLiteralImportType(node: ImportTypeNode): boolean {
|