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
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
import { checkCollisionsForDeclarationName } from './checker-generated-code.js';
|
|
7
7
|
import { checkDeprecatedImportSpecifier } from './checker-deprecation.js';
|
|
8
8
|
import { getExpression, getInitializer, getIsTypeOnly, getLocals, getModuleSpecifier, getName, getPropertyName, getSymbol, getText, getType, } from './ast.js';
|
|
9
|
-
import { getExternalModuleName, isAmbientModule, isImportCall, isFunctionLike, isGlobalScopeAugmentation, isInJSFile, isLiteralImportTypeNode, isRequireCall, isStringLiteralLike, isTypeOnly, nodeIsMissing, } from './ast-utilities.js';
|
|
9
|
+
import { getExternalModuleName, isAmbientModule, isImportCall, isFunctionLike, isGlobalScopeAugmentation, isInJSFile, isLiteralImportTypeNode, isRequireCall, isStringLiteralLike, isTypeOnly, nodeIsMissing, isImportPhaseMetaProperty, isSourcePhaseImport, isSourcePhaseImportCall, } from './ast-utilities.js';
|
|
10
10
|
import { declarationNameToString, getDeclarationOfKind, getModifierFlags, isAccessExpression, getRootDeclaration, getSourceTextOfNode, getThisContainer, getSourceFileOfNode, hasSyntacticModifier, isGlobalSourceFile, isJsonSourceFile, isModuleAugmentationExternal, isPartOfTypeQuery, isVariableDeclarationInitializedToRequire, moduleExportNameIsDefault, } from './binder-utilities.js';
|
|
11
11
|
import { chainDiagnostic, RepopulateInfo, } from './diagnostics.js';
|
|
12
12
|
import { JsxEmit, ModuleKind, ModuleResolutionKind, getAllowImportingTsExtensions, getEmitModuleKind, getModuleResolutionKind, getResolveJsonModule, } from './options.js';
|
|
@@ -15,30 +15,32 @@ import { getResolutionModeOverride, moduleKindName } from './program-utilities.j
|
|
|
15
15
|
import { hasExtension } from './vfs-match.js';
|
|
16
16
|
import { isNodeCoreModule } from './parser.js';
|
|
17
17
|
import { combinePaths, extensionIsTs, fileExtensionIsOneOf, getDeclarationFileExtension, getDirectoryPath, getNormalizedAbsolutePath, isDeclarationFileName, isExternalModuleNameRelative, pathIsRelative, removeExtension, supportedTSExtensionsFlat, tryExtractTSExtension, tryGetExtensionFromPath, } from './path.js';
|
|
18
|
+
import { getContainerFlags } from './binder.js';
|
|
18
19
|
import { isExpressionNode } from './transformers/alias-references.js';
|
|
19
20
|
import { createDiagnosticForNode } from './checker.js';
|
|
20
21
|
import { checkExternalEmitHelpers } from './checker-emit-helpers.js';
|
|
21
|
-
import { createAnonymousType, getRegularTypeOfLiteralType, getStringLiteralType, isErrorType, } from './checker-type-factory.js';
|
|
22
|
+
import { createAnonymousType, getRegularTypeOfLiteralType, getStringLiteralType, isEmptyObjectType, isErrorType, } from './checker-type-factory.js';
|
|
22
23
|
import { getFullyQualifiedName, getMergedSymbol, getSpellingSuggestionForName, getSymbolFlags, getSymbolOfDeclaration, getSymbolOfMeaning, getDeclarationOfAliasSymbol, getExportSymbolOfValueSymbolIfExported, getExportsOfModule, getExportsOfSymbol, resolveAlias, resolveEntityName, resolveName, resolveSymbol, resolveSymbolEx, isNonLocalAlias, getCachedGlobalType, } from './checker-symbols.js';
|
|
23
24
|
import { getTypeOfSymbol, getNullableType } from './checker-symbol-types.js';
|
|
24
|
-
import { getPropertyOfType, getPropertyOfTypeEx, getSignaturesOfStructuredType, resolveStructuredTypeMembers, } from './checker-members.js';
|
|
25
|
+
import { getPropertyOfType, getPropertyOfTypeEx, getTypeOfPropertyOfType, getSignaturesOfStructuredType, resolveStructuredTypeMembers, } from './checker-members.js';
|
|
25
26
|
import { getTypeFromTypeNode, getTypeReferenceType } from './checker-type-nodes.js';
|
|
26
|
-
import {
|
|
27
|
-
import { isTypeAssignableTo, checkTypeAssignableTo } from './relations.js';
|
|
27
|
+
import { checkExpressionCached, getResolvedSymbol } from './checker-expressions.js';
|
|
28
|
+
import { isTypeAssignableTo, isTypeIdenticalTo, isTypeStrictSubtypeOf, checkTypeAssignableTo } from './relations.js';
|
|
28
29
|
import { getSpreadType } from './checker-object-literals.js';
|
|
29
30
|
import { checkExternalModuleExports, shouldCheckErasableSyntax } from './checker-declarations.js';
|
|
30
31
|
import { checkTypeNameIsReserved } from './checker-classes.js';
|
|
31
32
|
import { getDeclaredTypeOfSymbol } from './checker-declared-types.js';
|
|
32
33
|
import { isValidSpreadType } from './checker-destructuring.js';
|
|
33
34
|
import { createPromiseType } from './checker-iteration.js';
|
|
35
|
+
import { getInstantiationExpressionType } from './checker-calls.js';
|
|
34
36
|
import { symbolToString, typeToString } from './type-printer.js';
|
|
35
37
|
import { checkTypeAssignableToAndOptionallyElaborate } from './checker-expressions.js';
|
|
36
38
|
import { grammarErrorOnNode } from './checker-operators.js';
|
|
37
|
-
import { declarationAt, declarationCount, getDeclarations, getSymbolId, setDeclarations, } from './symbol.js';
|
|
39
|
+
import { declarationAt, declarationCount, getDeclarations, getSymbolId, setDeclarations, copyDeclarations, } from './symbol.js';
|
|
38
40
|
// ---- Resolution
|
|
39
41
|
/** The module symbol `moduleReference` names, reporting it when it isn't found unless `ignoreErrors`. */
|
|
40
|
-
export function resolveExternalModuleName(c, location, moduleReference, ignoreErrors) {
|
|
41
|
-
return resolveExternalModuleNameWorker(c, location, moduleReference, ignoreErrors ? undefined : getCannotResolveModuleNameError(c, moduleReference), ignoreErrors, false);
|
|
42
|
+
export function resolveExternalModuleName(c, location, moduleReference, ignoreErrors, importAttributesType) {
|
|
43
|
+
return resolveExternalModuleNameWorker(c, location, moduleReference, ignoreErrors ? undefined : getCannotResolveModuleNameError(c, moduleReference), ignoreErrors, false, importAttributesType);
|
|
42
44
|
}
|
|
43
45
|
/** Node core modules suggest installing `@types/node`. */
|
|
44
46
|
function getCannotResolveModuleNameError(c, moduleReference) {
|
|
@@ -47,26 +49,31 @@ function getCannotResolveModuleNameError(c, moduleReference) {
|
|
|
47
49
|
isNodeCoreModule(getText(moduleReference))) {
|
|
48
50
|
const types = c.compilerOptions.types;
|
|
49
51
|
return types !== undefined && types.includes('*')
|
|
50
|
-
?
|
|
51
|
-
:
|
|
52
|
+
? 737 /* Diagnostics.Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_node_Try_npm_i_save_dev_types_Slashnode */
|
|
53
|
+
: 746 /* Diagnostics.Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_node_Try_npm_i_save_dev_types_Slashnode_and_then_add_node_to_the_types_field_in_your_tsconfig */;
|
|
52
54
|
}
|
|
53
|
-
return
|
|
55
|
+
return 492 /* Diagnostics.Cannot_find_module_0_or_its_corresponding_type_declarations */;
|
|
54
56
|
}
|
|
55
|
-
export function resolveExternalModuleNameWorker(c, location, moduleReference, moduleNotFoundError, ignoreErrors, isForAugmentation) {
|
|
57
|
+
export function resolveExternalModuleNameWorker(c, location, moduleReference, moduleNotFoundError, ignoreErrors, isForAugmentation, importAttributesType) {
|
|
56
58
|
if (moduleReference === undefined || !isStringLiteralLike(moduleReference))
|
|
57
59
|
return undefined;
|
|
58
|
-
|
|
60
|
+
// A source phase import loads no module declarations.
|
|
61
|
+
if (isSourcePhaseImport(moduleReference.parent))
|
|
62
|
+
return undefined;
|
|
63
|
+
return resolveExternalModule(c, location, getText(moduleReference), moduleNotFoundError, ignoreErrors ? undefined : moduleReference, isForAugmentation, importAttributesType);
|
|
59
64
|
}
|
|
60
65
|
/** A `resolveExternalModule` result that reported nothing, and the arguments it was computed for. */
|
|
61
66
|
export class ModuleResolution {
|
|
62
67
|
moduleReference;
|
|
63
68
|
moduleNotFoundError;
|
|
64
69
|
isForAugmentation;
|
|
70
|
+
importAttributesType;
|
|
65
71
|
symbol;
|
|
66
|
-
constructor(moduleReference, moduleNotFoundError, isForAugmentation, symbol) {
|
|
72
|
+
constructor(moduleReference, moduleNotFoundError, isForAugmentation, importAttributesType, symbol) {
|
|
67
73
|
this.moduleReference = moduleReference;
|
|
68
74
|
this.moduleNotFoundError = moduleNotFoundError;
|
|
69
75
|
this.isForAugmentation = isForAugmentation;
|
|
76
|
+
this.importAttributesType = importAttributesType;
|
|
70
77
|
this.symbol = symbol;
|
|
71
78
|
}
|
|
72
79
|
}
|
|
@@ -76,7 +83,7 @@ export class ModuleResolution {
|
|
|
76
83
|
* with the same result and the same diagnostics: a result that reported nothing is kept for the
|
|
77
84
|
* specifier and returned to later calls from the same declaration (`sharesSpecifierContext`).
|
|
78
85
|
*/
|
|
79
|
-
export function resolveExternalModule(c, location, moduleReference, moduleNotFoundError, errorNode, isForAugmentation) {
|
|
86
|
+
export function resolveExternalModule(c, location, moduleReference, moduleNotFoundError, errorNode, isForAugmentation, importAttributesType) {
|
|
80
87
|
// An augmentation merged later can give the resolved module a new merged symbol, so results are
|
|
81
88
|
// kept only once every augmentation is merged.
|
|
82
89
|
const shared = c.modulesMerged && errorNode !== undefined && sharesSpecifierContext(location, errorNode);
|
|
@@ -85,13 +92,14 @@ export function resolveExternalModule(c, location, moduleReference, moduleNotFou
|
|
|
85
92
|
if (known !== undefined &&
|
|
86
93
|
known.moduleReference === moduleReference &&
|
|
87
94
|
known.moduleNotFoundError === moduleNotFoundError &&
|
|
88
|
-
known.isForAugmentation === isForAugmentation
|
|
95
|
+
known.isForAugmentation === isForAugmentation &&
|
|
96
|
+
known.importAttributesType === importAttributesType)
|
|
89
97
|
return known.symbol;
|
|
90
98
|
}
|
|
91
99
|
const reports = c.reports;
|
|
92
|
-
const symbol = resolveExternalModuleWorker(c, location, moduleReference, moduleNotFoundError, errorNode, isForAugmentation);
|
|
100
|
+
const symbol = resolveExternalModuleWorker(c, location, moduleReference, moduleNotFoundError, errorNode, isForAugmentation, importAttributesType ?? c.emptyObjectType);
|
|
93
101
|
if (shared && c.reports === reports)
|
|
94
|
-
c.moduleResolutions.set(errorNode, new ModuleResolution(moduleReference, moduleNotFoundError, isForAugmentation, symbol));
|
|
102
|
+
c.moduleResolutions.set(errorNode, new ModuleResolution(moduleReference, moduleNotFoundError, isForAugmentation, importAttributesType, symbol));
|
|
95
103
|
return symbol;
|
|
96
104
|
}
|
|
97
105
|
/**
|
|
@@ -103,24 +111,24 @@ export function resolveExternalModule(c, location, moduleReference, moduleNotFou
|
|
|
103
111
|
function sharesSpecifierContext(location, errorNode) {
|
|
104
112
|
const declaration = errorNode.parent;
|
|
105
113
|
if (declaration === undefined ||
|
|
106
|
-
(declaration.kind !==
|
|
107
|
-
declaration.kind !==
|
|
108
|
-
declaration.kind !==
|
|
114
|
+
(declaration.kind !== 274 /* SyntaxKind.ImportDeclaration */ &&
|
|
115
|
+
declaration.kind !== 347 /* SyntaxKind.JSImportDeclaration */ &&
|
|
116
|
+
declaration.kind !== 280 /* SyntaxKind.ExportDeclaration */) ||
|
|
109
117
|
getModuleSpecifier(declaration) !== errorNode)
|
|
110
118
|
return false;
|
|
111
119
|
for (let current = location; current !== undefined; current = current.parent)
|
|
112
120
|
switch (current.kind) {
|
|
113
|
-
case
|
|
114
|
-
case
|
|
115
|
-
case
|
|
121
|
+
case 274 /* SyntaxKind.ImportDeclaration */:
|
|
122
|
+
case 347 /* SyntaxKind.JSImportDeclaration */:
|
|
123
|
+
case 280 /* SyntaxKind.ExportDeclaration */:
|
|
116
124
|
return current === declaration;
|
|
117
|
-
case
|
|
118
|
-
case
|
|
119
|
-
case
|
|
120
|
-
case
|
|
121
|
-
case
|
|
122
|
-
case
|
|
123
|
-
case
|
|
125
|
+
case 275 /* SyntaxKind.ImportClause */:
|
|
126
|
+
case 277 /* SyntaxKind.NamedImports */:
|
|
127
|
+
case 276 /* SyntaxKind.NamespaceImport */:
|
|
128
|
+
case 278 /* SyntaxKind.ImportSpecifier */:
|
|
129
|
+
case 281 /* SyntaxKind.NamedExports */:
|
|
130
|
+
case 282 /* SyntaxKind.NamespaceExport */:
|
|
131
|
+
case 283 /* SyntaxKind.ExportSpecifier */:
|
|
124
132
|
break;
|
|
125
133
|
default:
|
|
126
134
|
if (current !== errorNode)
|
|
@@ -128,12 +136,12 @@ function sharesSpecifierContext(location, errorNode) {
|
|
|
128
136
|
}
|
|
129
137
|
return false;
|
|
130
138
|
}
|
|
131
|
-
function resolveExternalModuleWorker(c, location, moduleReference, moduleNotFoundError, errorNode, isForAugmentation) {
|
|
139
|
+
function resolveExternalModuleWorker(c, location, moduleReference, moduleNotFoundError, errorNode, isForAugmentation, importAttributesType) {
|
|
132
140
|
if (errorNode !== undefined && moduleReference.startsWith('@types/'))
|
|
133
|
-
c.error(errorNode,
|
|
141
|
+
c.error(errorNode, 1313 /* Diagnostics.Cannot_import_type_declaration_files_Consider_importing_0_instead_of_1 */, moduleReference.substring(7), moduleReference);
|
|
134
142
|
const ambient = tryFindAmbientModule(c, moduleReference, true);
|
|
135
143
|
if (ambient !== undefined)
|
|
136
|
-
return ambient;
|
|
144
|
+
return tryResolvePatternAmbientModule(c, ambient, moduleReference, importAttributesType);
|
|
137
145
|
const importingFile = getSourceFileOfNode(location);
|
|
138
146
|
const contextSpecifier = getContextSpecifier(location);
|
|
139
147
|
const mode = contextSpecifier !== undefined && isStringLiteralLike(contextSpecifier)
|
|
@@ -146,7 +154,7 @@ function resolveExternalModuleWorker(c, location, moduleReference, moduleNotFoun
|
|
|
146
154
|
: undefined;
|
|
147
155
|
const file = isResolved &&
|
|
148
156
|
(resolutionDiagnostic === undefined ||
|
|
149
|
-
resolutionDiagnostic ===
|
|
157
|
+
resolutionDiagnostic === 1318 /* Diagnostics.Module_0_was_resolved_to_1_but_jsx_is_not_set */)
|
|
150
158
|
? c.host.getSourceFileForResolvedModule(resolved.resolvedFileName)
|
|
151
159
|
: undefined;
|
|
152
160
|
if (file !== undefined) {
|
|
@@ -162,30 +170,25 @@ function resolveExternalModuleWorker(c, location, moduleReference, moduleNotFoun
|
|
|
162
170
|
errorOnImplicitAnyModule(c, false, errorNode, mode, resolved, moduleReference);
|
|
163
171
|
checkSyncImportOfESModule(c, location, moduleReference, importingFile, file, errorNode);
|
|
164
172
|
}
|
|
165
|
-
return getMergedSymbol(c, file.symbol);
|
|
173
|
+
return tryResolvePatternAmbientModule(c, getMergedSymbol(c, file.symbol), moduleReference, importAttributesType);
|
|
166
174
|
}
|
|
175
|
+
const patternModule = tryResolvePatternAmbientModule(c, undefined, moduleReference, importAttributesType);
|
|
176
|
+
if (patternModule !== undefined)
|
|
177
|
+
return patternModule;
|
|
167
178
|
if (errorNode !== undefined && moduleNotFoundError !== undefined && !isSideEffectImport(errorNode))
|
|
168
|
-
c.error(errorNode,
|
|
179
|
+
c.error(errorNode, 491 /* Diagnostics.File_0_is_not_a_module */, resolved.resolvedFileName);
|
|
169
180
|
return undefined;
|
|
170
181
|
}
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
for (const pattern of c.patternAmbientModules) {
|
|
175
|
-
if (pattern.matches(moduleReference) && pattern.starIndex > bestPrefix) {
|
|
176
|
-
bestPrefix = pattern.starIndex;
|
|
177
|
-
best = pattern.symbol;
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
if (best !== undefined)
|
|
181
|
-
return getMergedSymbol(c, c.patternAmbientModuleAugmentations.get(moduleReference) ?? best);
|
|
182
|
+
const patternModule = tryResolvePatternAmbientModule(c, undefined, moduleReference, importAttributesType);
|
|
183
|
+
if (patternModule !== undefined)
|
|
184
|
+
return patternModule;
|
|
182
185
|
if (errorNode === undefined)
|
|
183
186
|
return undefined;
|
|
184
187
|
// A module that resolved to JavaScript is untyped.
|
|
185
188
|
if ((isResolved && !resolutionExtensionIsTSOrJson(resolved.extension) && resolutionDiagnostic === undefined) ||
|
|
186
|
-
resolutionDiagnostic ===
|
|
189
|
+
resolutionDiagnostic === 1707 /* Diagnostics.Could_not_find_a_declaration_file_for_module_0_1_implicitly_has_an_any_type */) {
|
|
187
190
|
if (isForAugmentation)
|
|
188
|
-
c.error(errorNode,
|
|
191
|
+
c.error(errorNode, 806 /* Diagnostics.Invalid_module_name_in_augmentation_Module_0_resolves_to_an_untyped_module_at_1_which_cannot_be_augmented */, moduleReference, resolved.resolvedFileName);
|
|
189
192
|
else
|
|
190
193
|
errorOnImplicitAnyModule(c, c.noImplicitAny && moduleNotFoundError !== undefined, errorNode, mode, resolved, moduleReference);
|
|
191
194
|
return undefined;
|
|
@@ -196,7 +199,7 @@ function resolveExternalModuleWorker(c, location, moduleReference, moduleNotFoun
|
|
|
196
199
|
// A source file of a referenced project whose output hasn't been built.
|
|
197
200
|
const outputDts = c.host.getProjectReferenceOutputDts(resolved.resolvedFileName);
|
|
198
201
|
if (outputDts !== '') {
|
|
199
|
-
c.error(errorNode,
|
|
202
|
+
c.error(errorNode, 1455 /* Diagnostics.Output_file_0_has_not_been_built_from_source_file_1 */, outputDts, resolved.resolvedFileName);
|
|
200
203
|
return undefined;
|
|
201
204
|
}
|
|
202
205
|
}
|
|
@@ -206,7 +209,7 @@ function resolveExternalModuleWorker(c, location, moduleReference, moduleNotFoun
|
|
|
206
209
|
}
|
|
207
210
|
const resolution = getModuleResolutionKind(c.compilerOptions);
|
|
208
211
|
if (!getResolveJsonModule(c.compilerOptions) && moduleReference.endsWith('.json'))
|
|
209
|
-
c.error(errorNode,
|
|
212
|
+
c.error(errorNode, 871 /* Diagnostics.Cannot_find_module_0_Consider_using_resolveJsonModule_to_import_module_with_json_extension */, moduleReference);
|
|
210
213
|
else if (mode === ModuleKind.ESNext &&
|
|
211
214
|
(resolution === ModuleResolutionKind.Node16 || resolution === ModuleResolutionKind.NodeNext) &&
|
|
212
215
|
pathIsRelative(moduleReference) &&
|
|
@@ -214,9 +217,9 @@ function resolveExternalModuleWorker(c, location, moduleReference, moduleNotFoun
|
|
|
214
217
|
const absolute = getNormalizedAbsolutePath(moduleReference, getDirectoryPath(importingFile.fileName));
|
|
215
218
|
const extension = getSuggestedImportExtension(c, absolute);
|
|
216
219
|
if (extension !== '')
|
|
217
|
-
c.error(errorNode,
|
|
220
|
+
c.error(errorNode, 964 /* Diagnostics.Relative_import_paths_need_explicit_file_extensions_in_ECMAScript_imports_when_moduleResolution_is_node16_or_nodenext_Did_you_mean_0 */, moduleReference + extension);
|
|
218
221
|
else
|
|
219
|
-
c.error(errorNode,
|
|
222
|
+
c.error(errorNode, 963 /* Diagnostics.Relative_import_paths_need_explicit_file_extensions_in_ECMAScript_imports_when_moduleResolution_is_node16_or_nodenext_Consider_adding_an_extension_to_the_import_path */);
|
|
220
223
|
}
|
|
221
224
|
else if (resolved !== undefined && resolved.alternateResult !== '')
|
|
222
225
|
c.addDiagnostic(chainDiagnostic(createModuleNotFoundChain(c, errorNode, moduleReference, mode, moduleReference), moduleNotFoundError, moduleReference));
|
|
@@ -224,13 +227,76 @@ function resolveExternalModuleWorker(c, location, moduleReference, moduleNotFoun
|
|
|
224
227
|
c.error(errorNode, moduleNotFoundError, moduleReference);
|
|
225
228
|
return undefined;
|
|
226
229
|
}
|
|
230
|
+
/**
|
|
231
|
+
* The pattern ambient module `moduleReference` resolves to under `importAttributesType`, or
|
|
232
|
+
* `resolvedSymbol`. Without import attributes a module found by name or resolution wins. Among the
|
|
233
|
+
* patterns that match and accept the attributes, the one with the most specific attributes type wins,
|
|
234
|
+
* then the one with the longest prefix.
|
|
235
|
+
*/
|
|
236
|
+
function tryResolvePatternAmbientModule(c, resolvedSymbol, moduleReference, importAttributesType) {
|
|
237
|
+
if (resolvedSymbol !== undefined && isEmptyObjectType(c, importAttributesType))
|
|
238
|
+
return resolvedSymbol;
|
|
239
|
+
if (c.patternAmbientModules.length === 0)
|
|
240
|
+
return resolvedSymbol;
|
|
241
|
+
const candidates = [];
|
|
242
|
+
for (const pattern of c.patternAmbientModules)
|
|
243
|
+
if (pattern.matches(moduleReference) &&
|
|
244
|
+
isTypeAssignableTo(c, importAttributesType, getTypeOfModuleImportAttributes(c, pattern.symbol)))
|
|
245
|
+
candidates.push(pattern);
|
|
246
|
+
if (candidates.length === 0)
|
|
247
|
+
return resolvedSymbol;
|
|
248
|
+
let best = candidates[0];
|
|
249
|
+
if (candidates.length > 1) {
|
|
250
|
+
const bestTypeCandidates = [];
|
|
251
|
+
for (let i = 0; i < candidates.length; i++) {
|
|
252
|
+
const candidateType = getTypeOfModuleImportAttributes(c, candidates[i].symbol);
|
|
253
|
+
let isBest = true;
|
|
254
|
+
for (let j = 0; j < candidates.length && isBest; j++) {
|
|
255
|
+
const otherType = getTypeOfModuleImportAttributes(c, candidates[j].symbol);
|
|
256
|
+
if (i !== j &&
|
|
257
|
+
isTypeStrictSubtypeOf(c, otherType, candidateType) &&
|
|
258
|
+
!isTypeIdenticalTo(c, otherType, candidateType))
|
|
259
|
+
isBest = false;
|
|
260
|
+
}
|
|
261
|
+
if (isBest)
|
|
262
|
+
bestTypeCandidates.push(candidates[i]);
|
|
263
|
+
}
|
|
264
|
+
// The pattern with the longest prefix wins.
|
|
265
|
+
best = bestTypeCandidates[0];
|
|
266
|
+
for (const pattern of bestTypeCandidates)
|
|
267
|
+
if (pattern.starIndex > best.starIndex)
|
|
268
|
+
best = pattern;
|
|
269
|
+
}
|
|
270
|
+
const merged = getMergedSymbol(c, best.symbol);
|
|
271
|
+
const augmentation = c.patternAmbientModuleAugmentations.get(moduleReference);
|
|
272
|
+
if (augmentation !== undefined && c.patternAmbientModuleAugmentationTargets.get(moduleReference) === merged)
|
|
273
|
+
return getMergedSymbol(c, augmentation);
|
|
274
|
+
return merged;
|
|
275
|
+
}
|
|
276
|
+
/** The import attributes type an ambient module declares, or the empty object type. */
|
|
277
|
+
export function getTypeOfModuleImportAttributes(c, symbol) {
|
|
278
|
+
let result = c.moduleImportAttributesTypes.get(symbol);
|
|
279
|
+
if (result === undefined) {
|
|
280
|
+
result = c.emptyObjectType;
|
|
281
|
+
for (const declaration of getDeclarations(symbol))
|
|
282
|
+
if (declaration.kind === 269 /* SyntaxKind.ModuleDeclaration */ &&
|
|
283
|
+
getName(declaration).kind === 10 /* SyntaxKind.StringLiteral */) {
|
|
284
|
+
const attributes = declaration.attributes;
|
|
285
|
+
if (attributes !== undefined)
|
|
286
|
+
result = getTypeFromTypeNode(c, attributes);
|
|
287
|
+
break;
|
|
288
|
+
}
|
|
289
|
+
c.moduleImportAttributesTypes.set(symbol, result);
|
|
290
|
+
}
|
|
291
|
+
return result;
|
|
292
|
+
}
|
|
227
293
|
/** The module specifier that decides the resolution mode of a module reference at `location`. */
|
|
228
294
|
function getContextSpecifier(location) {
|
|
229
295
|
const parent = location.parent;
|
|
230
296
|
if (isStringLiteralLike(location) ||
|
|
231
|
-
(parent !== undefined && parent.kind ===
|
|
297
|
+
(parent !== undefined && parent.kind === 269 /* SyntaxKind.ModuleDeclaration */ && getName(parent) === location))
|
|
232
298
|
return location;
|
|
233
|
-
if (location.kind ===
|
|
299
|
+
if (location.kind === 269 /* SyntaxKind.ModuleDeclaration */)
|
|
234
300
|
return getName(location);
|
|
235
301
|
if (isLiteralImportTypeNode(location))
|
|
236
302
|
return location.argument.literal;
|
|
@@ -241,21 +307,21 @@ function getContextSpecifier(location) {
|
|
|
241
307
|
if (isImportCall(current))
|
|
242
308
|
return current.arguments.nodes[0];
|
|
243
309
|
for (let current = location; current !== undefined; current = current.parent)
|
|
244
|
-
if (current.kind ===
|
|
310
|
+
if (current.kind === 274 /* SyntaxKind.ImportDeclaration */ || current.kind === 347 /* SyntaxKind.JSImportDeclaration */)
|
|
245
311
|
return getModuleSpecifier(current);
|
|
246
312
|
for (let current = location; current !== undefined; current = current.parent)
|
|
247
|
-
if (current.kind ===
|
|
313
|
+
if (current.kind === 280 /* SyntaxKind.ExportDeclaration */)
|
|
248
314
|
return getModuleSpecifier(current);
|
|
249
315
|
for (let current = location; current !== undefined; current = current.parent)
|
|
250
|
-
if (current.kind ===
|
|
316
|
+
if (current.kind === 273 /* SyntaxKind.ImportEqualsDeclaration */) {
|
|
251
317
|
const reference = current.moduleReference;
|
|
252
|
-
return reference.kind ===
|
|
318
|
+
return reference.kind === 285 /* SyntaxKind.ExternalModuleReference */ ? getExpression(reference) : undefined;
|
|
253
319
|
}
|
|
254
320
|
return undefined;
|
|
255
321
|
}
|
|
256
322
|
/** The specifier of `const x = require("m")` or `const x = require("m").a.b` in JavaScript. */
|
|
257
323
|
function getModuleSpecifierOfBareOrAccessedRequire(node) {
|
|
258
|
-
if (node.kind !==
|
|
324
|
+
if (node.kind !== 262 /* SyntaxKind.VariableDeclaration */ || !isInJSFile(node))
|
|
259
325
|
return undefined;
|
|
260
326
|
const declaration = node;
|
|
261
327
|
let initializer = declaration.initializer;
|
|
@@ -276,7 +342,7 @@ function checkResolvedModuleExtension(c, location, moduleReference, resolved, im
|
|
|
276
342
|
return;
|
|
277
343
|
if (isDeclarationFileName(moduleReference)) {
|
|
278
344
|
if (isInEmittableImport(location))
|
|
279
|
-
c.error(errorNode,
|
|
345
|
+
c.error(errorNode, 974 /* Diagnostics.A_declaration_file_cannot_be_imported_without_import_type_Did_you_mean_to_import_an_implementation_file_0_instead */, getSuggestedImportSource(c, moduleReference, tryExtractTSExtension(moduleReference), mode));
|
|
280
346
|
}
|
|
281
347
|
else if (!getAllowImportingTsExtensions(c.compilerOptions) &&
|
|
282
348
|
!isDeclarationFileName(importingFile.fileName) &&
|
|
@@ -289,24 +355,24 @@ function checkResolvedModuleExtension(c, location, moduleReference, resolved, im
|
|
|
289
355
|
extension = candidate;
|
|
290
356
|
break;
|
|
291
357
|
}
|
|
292
|
-
c.error(errorNode,
|
|
358
|
+
c.error(errorNode, 1178 /* Diagnostics.An_import_path_can_only_end_with_a_0_extension_when_allowImportingTsExtensions_is_enabled */, extension);
|
|
293
359
|
}
|
|
294
360
|
}
|
|
295
361
|
function isInEmittableImport(location) {
|
|
296
362
|
for (let current = location; current !== undefined; current = current.parent) {
|
|
297
363
|
switch (current.kind) {
|
|
298
|
-
case
|
|
364
|
+
case 274 /* SyntaxKind.ImportDeclaration */: {
|
|
299
365
|
const clause = current.importClause;
|
|
300
366
|
if (clause !== undefined && !isTypeOnly(clause))
|
|
301
367
|
return true;
|
|
302
368
|
break;
|
|
303
369
|
}
|
|
304
|
-
case
|
|
305
|
-
case
|
|
370
|
+
case 280 /* SyntaxKind.ExportDeclaration */:
|
|
371
|
+
case 273 /* SyntaxKind.ImportEqualsDeclaration */:
|
|
306
372
|
if (!getIsTypeOnly(current))
|
|
307
373
|
return true;
|
|
308
374
|
break;
|
|
309
|
-
case
|
|
375
|
+
case 215 /* SyntaxKind.CallExpression */:
|
|
310
376
|
if (isImportCall(current))
|
|
311
377
|
return true;
|
|
312
378
|
break;
|
|
@@ -355,7 +421,7 @@ function checkSyncImportOfESModule(c, location, moduleReference, importingFile,
|
|
|
355
421
|
const moduleKind = getEmitModuleKind(c.compilerOptions);
|
|
356
422
|
if (moduleKind !== ModuleKind.Node16 && moduleKind !== ModuleKind.Node18)
|
|
357
423
|
return;
|
|
358
|
-
const importEquals = findAncestorOfKind(location,
|
|
424
|
+
const importEquals = findAncestorOfKind(location, 273 /* SyntaxKind.ImportEqualsDeclaration */);
|
|
359
425
|
const isSyncImport = (c.host.getDefaultResolutionModeForFile(importingFile) === ModuleKind.CommonJS && !isInImportCall(location)) ||
|
|
360
426
|
importEquals !== undefined;
|
|
361
427
|
if (!isSyncImport || c.host.getDefaultResolutionModeForFile(file) !== ModuleKind.ESNext)
|
|
@@ -364,7 +430,7 @@ function checkSyncImportOfESModule(c, location, moduleReference, importingFile,
|
|
|
364
430
|
if (overrideHost !== undefined && hasResolutionModeOverride(overrideHost))
|
|
365
431
|
return;
|
|
366
432
|
if (importEquals !== undefined) {
|
|
367
|
-
c.error(errorNode,
|
|
433
|
+
c.error(errorNode, 384 /* Diagnostics.Module_0_cannot_be_imported_using_this_construct_The_specifier_only_resolves_to_an_ES_module_which_cannot_be_imported_with_require_Use_an_ECMAScript_import_instead */, moduleReference);
|
|
368
434
|
return;
|
|
369
435
|
}
|
|
370
436
|
let details;
|
|
@@ -373,16 +439,16 @@ function checkSyncImportOfESModule(c, location, moduleReference, importingFile,
|
|
|
373
439
|
details = detailsAt(errorNode, modeMismatchDetails(c.host, importingFile));
|
|
374
440
|
details.repopulateInfo = new RepopulateInfo(1 /* RepopulateKind.ModeMismatch */);
|
|
375
441
|
}
|
|
376
|
-
let message =
|
|
377
|
-
if (overrideHost !== undefined && overrideHost.kind ===
|
|
442
|
+
let message = 392 /* Diagnostics.The_current_file_is_a_CommonJS_module_whose_imports_will_produce_require_calls_however_the_referenced_file_is_an_ECMAScript_module_and_cannot_be_imported_with_require_Consider_writing_a_dynamic_import_0_call_instead */;
|
|
443
|
+
if (overrideHost !== undefined && overrideHost.kind === 274 /* SyntaxKind.ImportDeclaration */) {
|
|
378
444
|
const clause = overrideHost.importClause;
|
|
379
445
|
if (clause !== undefined && isTypeOnly(clause))
|
|
380
446
|
message =
|
|
381
|
-
|
|
447
|
+
454 /* Diagnostics.Type_only_import_of_an_ECMAScript_module_from_a_CommonJS_module_must_have_a_resolution_mode_attribute */;
|
|
382
448
|
}
|
|
383
|
-
else if (overrideHost !== undefined && overrideHost.kind ===
|
|
449
|
+
else if (overrideHost !== undefined && overrideHost.kind === 207 /* SyntaxKind.ImportType */)
|
|
384
450
|
message =
|
|
385
|
-
|
|
451
|
+
455 /* Diagnostics.Type_import_of_an_ECMAScript_module_from_a_CommonJS_module_must_have_a_resolution_mode_attribute */;
|
|
386
452
|
c.addDiagnostic(details !== undefined
|
|
387
453
|
? chainDiagnostic(details, message, moduleReference)
|
|
388
454
|
: createDiagnosticForNode(errorNode, message, [moduleReference]));
|
|
@@ -402,19 +468,19 @@ function isInImportCall(node) {
|
|
|
402
468
|
function findResolutionModeOverrideHost(node) {
|
|
403
469
|
for (let current = node; current !== undefined; current = current.parent)
|
|
404
470
|
switch (current.kind) {
|
|
405
|
-
case
|
|
406
|
-
case
|
|
407
|
-
case
|
|
408
|
-
case
|
|
471
|
+
case 207 /* SyntaxKind.ImportType */:
|
|
472
|
+
case 280 /* SyntaxKind.ExportDeclaration */:
|
|
473
|
+
case 274 /* SyntaxKind.ImportDeclaration */:
|
|
474
|
+
case 347 /* SyntaxKind.JSImportDeclaration */:
|
|
409
475
|
return current;
|
|
410
476
|
}
|
|
411
477
|
return undefined;
|
|
412
478
|
}
|
|
413
479
|
function hasResolutionModeOverride(node) {
|
|
414
480
|
let attributes;
|
|
415
|
-
if (node.kind ===
|
|
481
|
+
if (node.kind === 207 /* SyntaxKind.ImportType */)
|
|
416
482
|
attributes = node.attributes;
|
|
417
|
-
else if (node.kind ===
|
|
483
|
+
else if (node.kind === 280 /* SyntaxKind.ExportDeclaration */)
|
|
418
484
|
attributes = node.attributes;
|
|
419
485
|
else
|
|
420
486
|
attributes = node.attributes;
|
|
@@ -444,12 +510,12 @@ export function modeMismatchDetails(host, file) {
|
|
|
444
510
|
if (packageJsonDirectory !== '' && metadata.packageJsonType === '') {
|
|
445
511
|
const packageJson = combinePaths(packageJsonDirectory, 'package.json');
|
|
446
512
|
return targetExtension !== ''
|
|
447
|
-
? new DiagnosticDetails(
|
|
448
|
-
: new DiagnosticDetails(
|
|
513
|
+
? new DiagnosticDetails(394 /* Diagnostics.To_convert_this_file_to_an_ECMAScript_module_change_its_file_extension_to_0_or_add_the_field_type_Colon_module_to_1 */, [targetExtension, packageJson])
|
|
514
|
+
: new DiagnosticDetails(395 /* Diagnostics.To_convert_this_file_to_an_ECMAScript_module_add_the_field_type_Colon_module_to_0 */, [packageJson]);
|
|
449
515
|
}
|
|
450
516
|
return targetExtension !== ''
|
|
451
|
-
? new DiagnosticDetails(
|
|
452
|
-
: new DiagnosticDetails(
|
|
517
|
+
? new DiagnosticDetails(393 /* Diagnostics.To_convert_this_file_to_an_ECMAScript_module_change_its_file_extension_to_0_or_create_a_local_package_json_file_with_type_Colon_module */, [targetExtension])
|
|
518
|
+
: new DiagnosticDetails(396 /* Diagnostics.To_convert_this_file_to_an_ECMAScript_module_create_a_local_package_json_file_with_type_Colon_module */, []);
|
|
453
519
|
}
|
|
454
520
|
/** Reports a module without types: an error under `noImplicitAny`, otherwise a suggestion. */
|
|
455
521
|
function errorOnImplicitAnyModule(c, isError, errorNode, mode, resolved, moduleReference) {
|
|
@@ -459,7 +525,7 @@ function errorOnImplicitAnyModule(c, isError, errorNode, mode, resolved, moduleR
|
|
|
459
525
|
const chain = !isExternalModuleNameRelative(moduleReference) && packageName !== ''
|
|
460
526
|
? createModuleNotFoundChain(c, errorNode, moduleReference, mode, packageName)
|
|
461
527
|
: undefined;
|
|
462
|
-
const message =
|
|
528
|
+
const message = 1707 /* Diagnostics.Could_not_find_a_declaration_file_for_module_0_1_implicitly_has_an_any_type */;
|
|
463
529
|
c.addErrorOrSuggestion(isError, chain !== undefined
|
|
464
530
|
? chainDiagnostic(chain, message, moduleReference, resolved.resolvedFileName)
|
|
465
531
|
: createDiagnosticForNode(errorNode, message, [moduleReference, resolved.resolvedFileName]));
|
|
@@ -481,18 +547,18 @@ export function moduleNotFoundDetails(host, file, moduleReference, mode, package
|
|
|
481
547
|
if (resolved !== undefined && resolved.alternateResult !== '') {
|
|
482
548
|
if (resolved.alternateResult.includes('/node_modules/@types/'))
|
|
483
549
|
packageName = '@types/' + mangleScopedPackageName(packageName);
|
|
484
|
-
return new DiagnosticDetails(
|
|
550
|
+
return new DiagnosticDetails(1438 /* Diagnostics.There_are_types_at_0_but_this_result_could_not_be_resolved_when_respecting_package_json_exports_The_1_library_may_need_to_update_its_package_json_or_typings */, [resolved.alternateResult, packageName]);
|
|
485
551
|
}
|
|
486
552
|
const packages = host.getPackagesMap();
|
|
487
553
|
if (packages.has(getTypesPackageName(packageName)))
|
|
488
|
-
return new DiagnosticDetails(
|
|
554
|
+
return new DiagnosticDetails(1730 /* Diagnostics.If_the_0_package_actually_exposes_this_module_consider_sending_a_pull_request_to_amend_https_Colon_Slash_Slashgithub_com_SlashDefinitelyTyped_SlashDefinitelyTyped_Slashtree_Slashmaster_Slashtypes_Slash_1 */, [packageName, mangleScopedPackageName(packageName)]);
|
|
489
555
|
if (packages.get(packageName) === true)
|
|
490
|
-
return new DiagnosticDetails(
|
|
491
|
-
return new DiagnosticDetails(
|
|
556
|
+
return new DiagnosticDetails(1748 /* Diagnostics.If_the_0_package_actually_exposes_this_module_try_adding_a_new_declaration_d_ts_file_containing_declare_module_1 */, [packageName, moduleReference]);
|
|
557
|
+
return new DiagnosticDetails(1725 /* Diagnostics.Try_npm_i_save_dev_types_Slash_1_if_it_exists_or_add_a_new_declaration_d_ts_file_containing_declare_module_0 */, [moduleReference, mangleScopedPackageName(packageName)]);
|
|
492
558
|
}
|
|
493
559
|
function isSideEffectImport(node) {
|
|
494
560
|
let current = node;
|
|
495
|
-
while (current !== undefined && current.kind !==
|
|
561
|
+
while (current !== undefined && current.kind !== 274 /* SyntaxKind.ImportDeclaration */)
|
|
496
562
|
current = current.parent;
|
|
497
563
|
return current !== undefined && current.importClause === undefined;
|
|
498
564
|
}
|
|
@@ -521,14 +587,14 @@ export function resolveESModuleSymbol(c, moduleSymbol, node, moduleSpecifier) {
|
|
|
521
587
|
if (symbol === undefined || moduleSymbol === undefined)
|
|
522
588
|
return symbol;
|
|
523
589
|
const referenceParent = moduleSpecifier.parent;
|
|
524
|
-
const namespaceImport = referenceParent.kind ===
|
|
590
|
+
const namespaceImport = referenceParent.kind === 274 /* SyntaxKind.ImportDeclaration */ ? getNamespaceImport(referenceParent) : undefined;
|
|
525
591
|
if (namespaceImport === undefined && !isImportCall(referenceParent))
|
|
526
592
|
return symbol;
|
|
527
593
|
const reference = isImportCall(referenceParent)
|
|
528
594
|
? referenceParent.arguments.nodes[0]
|
|
529
595
|
: getModuleSpecifier(referenceParent);
|
|
530
596
|
const type = getTypeOfSymbol(c, symbol);
|
|
531
|
-
const defaultOnlyType = getTypeWithSyntheticDefaultOnly(c, type, symbol, moduleSymbol, reference);
|
|
597
|
+
const defaultOnlyType = getTypeWithSyntheticDefaultOnly(c, type, symbol, moduleSymbol, reference, getImportAttributesTypeForModuleSpecifier(c, reference));
|
|
532
598
|
if (defaultOnlyType !== undefined)
|
|
533
599
|
return cloneTypeAsModuleType(c, symbol, defaultOnlyType);
|
|
534
600
|
if (hasSignatures(c, type) || getPropertyOfTypeEx(c, type, "default" /* InternalSymbolName.Default */, true, false) !== undefined) {
|
|
@@ -542,7 +608,7 @@ export function resolveESModuleSymbol(c, moduleSymbol, node, moduleSpecifier) {
|
|
|
542
608
|
function getNamespaceImport(declaration) {
|
|
543
609
|
const clause = declaration.importClause;
|
|
544
610
|
const bindings = clause?.namedBindings;
|
|
545
|
-
return bindings !== undefined && bindings.kind ===
|
|
611
|
+
return bindings !== undefined && bindings.kind === 276 /* SyntaxKind.NamespaceImport */ ? bindings : undefined;
|
|
546
612
|
}
|
|
547
613
|
function hasSignatures(c, type) {
|
|
548
614
|
return (getSignaturesOfStructuredType(c, type, 0 /* SignatureKind.Call */).length > 0 ||
|
|
@@ -552,13 +618,13 @@ function hasSignatures(c, type) {
|
|
|
552
618
|
* Whether the module `usage` names is a JSON module imported into an ES module under `--module node16` to
|
|
553
619
|
* `nodenext`, which Node.js gives only a default export.
|
|
554
620
|
*/
|
|
555
|
-
function isOnlyImportableAsDefault(c, usage, resolvedModule) {
|
|
621
|
+
function isOnlyImportableAsDefault(c, usage, resolvedModule, importAttributesType) {
|
|
556
622
|
const moduleKind = getEmitModuleKind(c.compilerOptions);
|
|
557
623
|
if (moduleKind < ModuleKind.Node16 || moduleKind > ModuleKind.NodeNext)
|
|
558
624
|
return false;
|
|
559
625
|
if (getEmitSyntaxForModuleSpecifierExpression(c, usage) !== ModuleKind.ESNext)
|
|
560
626
|
return false;
|
|
561
|
-
const moduleSymbol = resolvedModule ?? resolveExternalModuleName(c, usage, usage, true);
|
|
627
|
+
const moduleSymbol = resolvedModule ?? resolveExternalModuleName(c, usage, usage, true, importAttributesType);
|
|
562
628
|
const targetFile = moduleSymbol !== undefined ? getSourceFileOfModuleSymbol(moduleSymbol) : undefined;
|
|
563
629
|
return (targetFile !== undefined &&
|
|
564
630
|
(isJsonSourceFile(targetFile) ||
|
|
@@ -576,8 +642,8 @@ function getSourceFileOfModuleSymbol(symbol) {
|
|
|
576
642
|
return declaration !== undefined ? getSourceFileOfNode(declaration) : undefined;
|
|
577
643
|
}
|
|
578
644
|
/** For a module only importable as default, the type of its namespace: an object with only `default`. */
|
|
579
|
-
function getTypeWithSyntheticDefaultOnly(c, type, symbol, originalSymbol, moduleSpecifier) {
|
|
580
|
-
if (!isOnlyImportableAsDefault(c, moduleSpecifier, undefined) || isErrorType(c, type))
|
|
645
|
+
function getTypeWithSyntheticDefaultOnly(c, type, symbol, originalSymbol, moduleSpecifier, importAttributesType) {
|
|
646
|
+
if (!isOnlyImportableAsDefault(c, moduleSpecifier, undefined, importAttributesType) || isErrorType(c, type))
|
|
581
647
|
return undefined;
|
|
582
648
|
const key = 'defaultOnly:' + type.id;
|
|
583
649
|
const cached = c.moduleTypeCache.get(key);
|
|
@@ -599,6 +665,7 @@ function getTypeWithSyntheticDefaultImportType(c, type, symbol, originalSymbol,
|
|
|
599
665
|
let result = type;
|
|
600
666
|
if (canHaveSyntheticDefault(c, file, originalSymbol, false, moduleSpecifier)) {
|
|
601
667
|
const anonymousSymbol = c.newSymbol(2048 /* SymbolFlags.TypeLiteral */, "\uFFFEtype" /* InternalSymbolName.Type */);
|
|
668
|
+
copyDeclarations(anonymousSymbol, originalSymbol);
|
|
602
669
|
const defaultContainingObject = createDefaultPropertyWrapperForModule(c, symbol, originalSymbol, anonymousSymbol);
|
|
603
670
|
c.symbolTypes.set(getSymbolId(anonymousSymbol), defaultContainingObject);
|
|
604
671
|
result = isValidSpreadType(c, type)
|
|
@@ -617,6 +684,10 @@ function createDefaultPropertyWrapperForModule(c, symbol, originalSymbol, anonym
|
|
|
617
684
|
links.aliasTarget = resolveSymbol(c, symbol);
|
|
618
685
|
const members = new Map();
|
|
619
686
|
members.set("default" /* InternalSymbolName.Default */, defaultSymbol);
|
|
687
|
+
if (anonymousSymbol === undefined && originalSymbol !== undefined) {
|
|
688
|
+
anonymousSymbol = c.newSymbol(4096 /* SymbolFlags.ObjectLiteral */, "\uFFFEobject" /* InternalSymbolName.Object */);
|
|
689
|
+
copyDeclarations(anonymousSymbol, originalSymbol);
|
|
690
|
+
}
|
|
620
691
|
return createAnonymousType(c, anonymousSymbol, members, [], [], []);
|
|
621
692
|
}
|
|
622
693
|
function cloneTypeAsModuleType(c, symbol, moduleType) {
|
|
@@ -636,12 +707,12 @@ function getSourceFileDeclaration(symbol) {
|
|
|
636
707
|
if (symbol === undefined)
|
|
637
708
|
return undefined;
|
|
638
709
|
for (const d of getDeclarations(symbol))
|
|
639
|
-
if (d.kind ===
|
|
710
|
+
if (d.kind === 308 /* SyntaxKind.SourceFile */)
|
|
640
711
|
return d;
|
|
641
712
|
return undefined;
|
|
642
713
|
}
|
|
643
714
|
/** The module syntax of the import or export containing `usage`, or `None` for non-literals. */
|
|
644
|
-
function getEmitSyntaxForModuleSpecifierExpression(c, usage) {
|
|
715
|
+
export function getEmitSyntaxForModuleSpecifierExpression(c, usage) {
|
|
645
716
|
return isStringLiteralLike(usage)
|
|
646
717
|
? c.host.getEmitSyntaxForUsageLocation(getSourceFileOfNode(usage), usage)
|
|
647
718
|
: ModuleKind.None;
|
|
@@ -683,17 +754,17 @@ function hasSyntacticDefault(symbol) {
|
|
|
683
754
|
return false;
|
|
684
755
|
}
|
|
685
756
|
function isSyntacticDefault(node) {
|
|
686
|
-
return ((node.kind ===
|
|
757
|
+
return ((node.kind === 279 /* SyntaxKind.ExportAssignment */ && !node.isExportEquals) ||
|
|
687
758
|
hasSyntacticModifier(node, 2048 /* ModifierFlags.Default */) ||
|
|
688
|
-
node.kind ===
|
|
689
|
-
node.kind ===
|
|
759
|
+
node.kind === 283 /* SyntaxKind.ExportSpecifier */ ||
|
|
760
|
+
node.kind === 282 /* SyntaxKind.NamespaceExport */);
|
|
690
761
|
}
|
|
691
762
|
function hasExportAssignmentSymbol(moduleSymbol) {
|
|
692
763
|
return moduleSymbol.exports?.get("export=" /* InternalSymbolName.ExportEquals */) !== undefined;
|
|
693
764
|
}
|
|
694
765
|
function isShorthandAmbientModuleSymbol(symbol) {
|
|
695
766
|
const d = symbol?.valueDeclaration;
|
|
696
|
-
return d !== undefined && d.kind ===
|
|
767
|
+
return d !== undefined && d.kind === 269 /* SyntaxKind.ModuleDeclaration */ && d.body === undefined;
|
|
697
768
|
}
|
|
698
769
|
// ---- Alias targets
|
|
699
770
|
/** The symbol an alias declaration refers to, without resolving further aliases. */
|
|
@@ -701,38 +772,41 @@ export function getTargetOfAliasDeclaration(c, node) {
|
|
|
701
772
|
if (node === undefined)
|
|
702
773
|
return undefined;
|
|
703
774
|
switch (node.kind) {
|
|
704
|
-
case
|
|
705
|
-
case
|
|
775
|
+
case 273 /* SyntaxKind.ImportEqualsDeclaration */:
|
|
776
|
+
case 262 /* SyntaxKind.VariableDeclaration */:
|
|
706
777
|
return getTargetOfImportEqualsDeclaration(c, node);
|
|
707
|
-
case
|
|
778
|
+
case 275 /* SyntaxKind.ImportClause */:
|
|
708
779
|
return getTargetOfImportClause(c, node);
|
|
709
|
-
case
|
|
780
|
+
case 276 /* SyntaxKind.NamespaceImport */:
|
|
710
781
|
return getTargetOfNamespaceImport(c, node);
|
|
711
|
-
case
|
|
782
|
+
case 282 /* SyntaxKind.NamespaceExport */:
|
|
712
783
|
return getTargetOfNamespaceExport(c, node);
|
|
713
|
-
case
|
|
714
|
-
case
|
|
784
|
+
case 278 /* SyntaxKind.ImportSpecifier */:
|
|
785
|
+
case 210 /* SyntaxKind.BindingElement */:
|
|
715
786
|
return getTargetOfImportSpecifier(c, node);
|
|
716
|
-
case
|
|
787
|
+
case 283 /* SyntaxKind.ExportSpecifier */:
|
|
717
788
|
return getTargetOfExportSpecifier(c, node, 111551 /* SymbolFlags.Value */ | 788968 /* SymbolFlags.Type */ | 1920 /* SymbolFlags.Namespace */, true);
|
|
718
|
-
case
|
|
789
|
+
case 279 /* SyntaxKind.ExportAssignment */:
|
|
790
|
+
// An export assignment in a namespace is an error, and its expression is not resolved.
|
|
791
|
+
if (isContainedByNamespace(node))
|
|
792
|
+
return undefined;
|
|
719
793
|
return withTypeOnlyMark(c, node, getTargetOfAliasLikeExpression(c, getExpression(node)));
|
|
720
|
-
case
|
|
794
|
+
case 228 /* SyntaxKind.BinaryExpression */:
|
|
721
795
|
return withTypeOnlyMark(c, node, getTargetOfAliasLikeExpression(c, node.right));
|
|
722
|
-
case
|
|
796
|
+
case 272 /* SyntaxKind.NamespaceExportDeclaration */: {
|
|
723
797
|
const resolved = resolveExternalModuleSymbol(c, getSymbol(node.parent), true);
|
|
724
798
|
markSymbolOfAliasDeclarationIfTypeOnly(c, node, undefined);
|
|
725
799
|
return resolved;
|
|
726
800
|
}
|
|
727
|
-
case
|
|
801
|
+
case 305 /* SyntaxKind.ShorthandPropertyAssignment */:
|
|
728
802
|
return resolveEntityName(c, getName(node), 111551 /* SymbolFlags.Value */ | 788968 /* SymbolFlags.Type */ | 1920 /* SymbolFlags.Namespace */, true, true, undefined);
|
|
729
|
-
case
|
|
803
|
+
case 304 /* SyntaxKind.PropertyAssignment */:
|
|
730
804
|
return getTargetOfAliasLikeExpression(c, getInitializer(node));
|
|
731
|
-
case
|
|
732
|
-
case
|
|
805
|
+
case 214 /* SyntaxKind.ElementAccessExpression */:
|
|
806
|
+
case 213 /* SyntaxKind.PropertyAccessExpression */: {
|
|
733
807
|
const parent = node.parent;
|
|
734
808
|
if (parent !== undefined &&
|
|
735
|
-
parent.kind ===
|
|
809
|
+
parent.kind === 228 /* SyntaxKind.BinaryExpression */ &&
|
|
736
810
|
parent.left === node &&
|
|
737
811
|
parent.operatorToken.kind === 63 /* SyntaxKind.EqualsToken */)
|
|
738
812
|
return getTargetOfAliasLikeExpression(c, parent.right);
|
|
@@ -746,11 +820,11 @@ function withTypeOnlyMark(c, node, resolved) {
|
|
|
746
820
|
return resolved;
|
|
747
821
|
}
|
|
748
822
|
function getTargetOfImportEqualsDeclaration(c, node) {
|
|
749
|
-
if (node.kind ===
|
|
823
|
+
if (node.kind === 262 /* SyntaxKind.VariableDeclaration */ || isExternalModuleImportEquals(node)) {
|
|
750
824
|
const moduleReference = isVariableDeclarationInitializedToRequire(node)
|
|
751
825
|
? getInitializer(node).arguments.nodes[0]
|
|
752
826
|
: getExpression(node.moduleReference);
|
|
753
|
-
const immediate = resolveExternalModuleName(c, node, moduleReference, false);
|
|
827
|
+
const immediate = resolveExternalModuleName(c, node, moduleReference, false, undefined);
|
|
754
828
|
const resolved = resolveExternalModuleSymbol(c, immediate, true);
|
|
755
829
|
const moduleKind = getEmitModuleKind(c.compilerOptions);
|
|
756
830
|
if (resolved !== undefined && moduleKind >= ModuleKind.Node20 && moduleKind <= ModuleKind.NodeNext) {
|
|
@@ -766,8 +840,8 @@ function getTargetOfImportEqualsDeclaration(c, node) {
|
|
|
766
840
|
return resolved;
|
|
767
841
|
}
|
|
768
842
|
function isExternalModuleImportEquals(node) {
|
|
769
|
-
return (node.kind ===
|
|
770
|
-
node.moduleReference.kind ===
|
|
843
|
+
return (node.kind === 273 /* SyntaxKind.ImportEqualsDeclaration */ &&
|
|
844
|
+
node.moduleReference.kind === 285 /* SyntaxKind.ExternalModuleReference */);
|
|
771
845
|
}
|
|
772
846
|
/**
|
|
773
847
|
* Resolves the entity name of `import a = b.c`: `b` alone or the left part of a longer name is a
|
|
@@ -776,10 +850,10 @@ function isExternalModuleImportEquals(node) {
|
|
|
776
850
|
export function getSymbolOfPartOfRightHandSideOfImportEquals(c, entityName) {
|
|
777
851
|
if (entityName.kind === 79 /* SyntaxKind.Identifier */ &&
|
|
778
852
|
entityName.parent !== undefined &&
|
|
779
|
-
entityName.parent.kind ===
|
|
853
|
+
entityName.parent.kind === 168 /* SyntaxKind.QualifiedName */ &&
|
|
780
854
|
entityName.parent.right === entityName)
|
|
781
855
|
entityName = entityName.parent;
|
|
782
|
-
if (entityName.kind === 79 /* SyntaxKind.Identifier */ || entityName.parent.kind ===
|
|
856
|
+
if (entityName.kind === 79 /* SyntaxKind.Identifier */ || entityName.parent.kind === 168 /* SyntaxKind.QualifiedName */)
|
|
783
857
|
return resolveEntityName(c, entityName, 1920 /* SymbolFlags.Namespace */, false, true, undefined);
|
|
784
858
|
return resolveEntityName(c, entityName, 111551 /* SymbolFlags.Value */ | 788968 /* SymbolFlags.Type */ | 1920 /* SymbolFlags.Namespace */, false, true, undefined);
|
|
785
859
|
}
|
|
@@ -788,28 +862,40 @@ function checkAndReportErrorForResolvingImportAliasToTypeOnlySymbol(c, node) {
|
|
|
788
862
|
for (;;) {
|
|
789
863
|
const typeOnlyDeclaration = getTypeOnlyDeclarationOfEntityName(c, name);
|
|
790
864
|
if (typeOnlyDeclaration !== undefined) {
|
|
791
|
-
const isExport = typeOnlyDeclaration.kind ===
|
|
792
|
-
typeOnlyDeclaration.kind ===
|
|
865
|
+
const isExport = typeOnlyDeclaration.kind === 283 /* SyntaxKind.ExportSpecifier */ ||
|
|
866
|
+
typeOnlyDeclaration.kind === 280 /* SyntaxKind.ExportDeclaration */;
|
|
793
867
|
const diagnostic = c.error(node.moduleReference, isExport
|
|
794
868
|
? 308 /* Diagnostics.An_import_alias_cannot_reference_a_declaration_that_was_exported_using_export_type */
|
|
795
869
|
: 309 /* Diagnostics.An_import_alias_cannot_reference_a_declaration_that_was_imported_using_import_type */);
|
|
796
|
-
const typeOnlyName = typeOnlyDeclaration.kind ===
|
|
870
|
+
const typeOnlyName = typeOnlyDeclaration.kind === 280 /* SyntaxKind.ExportDeclaration */ ? '*' : getText(getName(typeOnlyDeclaration));
|
|
797
871
|
diagnostic.addRelatedInfo(createDiagnosticForNode(typeOnlyDeclaration, isExport ? 306 /* Diagnostics.X_0_was_exported_here */ : 305 /* Diagnostics.X_0_was_imported_here */, [typeOnlyName]));
|
|
798
872
|
return;
|
|
799
873
|
}
|
|
800
|
-
if (name.kind !==
|
|
874
|
+
if (name.kind !== 168 /* SyntaxKind.QualifiedName */)
|
|
801
875
|
return;
|
|
802
876
|
name = name.left;
|
|
803
877
|
}
|
|
804
878
|
}
|
|
805
879
|
function getTypeOnlyDeclarationOfEntityName(c, name) {
|
|
806
|
-
if (name.kind !== 79 /* SyntaxKind.Identifier */ && name.kind !==
|
|
880
|
+
if (name.kind !== 79 /* SyntaxKind.Identifier */ && name.kind !== 168 /* SyntaxKind.QualifiedName */)
|
|
807
881
|
return undefined;
|
|
808
882
|
const symbol = resolveEntityName(c, name, 111551 /* SymbolFlags.Value */ | 788968 /* SymbolFlags.Type */ | 1920 /* SymbolFlags.Namespace */, true, true, undefined);
|
|
809
883
|
return symbol !== undefined ? getTypeOnlyAliasDeclaration(c, symbol) : undefined;
|
|
810
884
|
}
|
|
811
885
|
function getTargetOfImportClause(c, node) {
|
|
812
|
-
|
|
886
|
+
// `import source x from "m"` binds a module source object, not the module's default export.
|
|
887
|
+
if (node.phaseModifier === 167 /* SyntaxKind.SourceKeyword */) {
|
|
888
|
+
const alias = getSymbolOfDeclaration(c, node);
|
|
889
|
+
const links = c.symbolLinks(alias);
|
|
890
|
+
if (links.immediateTarget === undefined) {
|
|
891
|
+
const symbol = c.newSymbol(1 /* SymbolFlags.FunctionScopedVariable */, getText(node.name));
|
|
892
|
+
setDeclarations(symbol, getDeclarations(alias).slice());
|
|
893
|
+
c.symbolTypes.set(getSymbolId(symbol), getGlobalAbstractModuleSourceType(c));
|
|
894
|
+
links.immediateTarget = symbol;
|
|
895
|
+
}
|
|
896
|
+
return links.immediateTarget;
|
|
897
|
+
}
|
|
898
|
+
const moduleSymbol = resolveExternalModuleName(c, node, getModuleSpecifier(node.parent), false, getTypeFromImportAttributes(c, getImportAttributes(node.parent)));
|
|
813
899
|
return moduleSymbol !== undefined ? getTargetOfModuleDefault(c, moduleSymbol, node, true) : undefined;
|
|
814
900
|
}
|
|
815
901
|
function getTargetOfModuleDefault(c, moduleSymbol, node, dontResolveAlias) {
|
|
@@ -820,13 +906,20 @@ function getTargetOfModuleDefault(c, moduleSymbol, node, dontResolveAlias) {
|
|
|
820
906
|
: resolveExportByName(c, moduleSymbol, "default" /* InternalSymbolName.Default */, node, dontResolveAlias);
|
|
821
907
|
if (specifier === undefined)
|
|
822
908
|
return exportDefaultSymbol;
|
|
823
|
-
|
|
909
|
+
let attributes;
|
|
910
|
+
if (node.kind === 275 /* SyntaxKind.ImportClause */)
|
|
911
|
+
attributes = getImportAttributes(node.parent);
|
|
912
|
+
else if (node.kind === 278 /* SyntaxKind.ImportSpecifier */)
|
|
913
|
+
attributes = getImportAttributes(node.parent.parent.parent);
|
|
914
|
+
else if (node.kind === 283 /* SyntaxKind.ExportSpecifier */)
|
|
915
|
+
attributes = getImportAttributes(node.parent.parent);
|
|
916
|
+
const hasDefaultOnly = isOnlyImportableAsDefault(c, specifier, moduleSymbol, getTypeFromImportAttributes(c, attributes));
|
|
824
917
|
const hasSyntheticDefault = canHaveSyntheticDefault(c, file, moduleSymbol, dontResolveAlias, specifier);
|
|
825
918
|
if (exportDefaultSymbol === undefined && !hasSyntheticDefault && !hasDefaultOnly) {
|
|
826
|
-
if (node.kind ===
|
|
919
|
+
if (node.kind === 275 /* SyntaxKind.ImportClause */)
|
|
827
920
|
reportNonDefaultExport(c, moduleSymbol, node);
|
|
828
921
|
else {
|
|
829
|
-
const name = node.kind ===
|
|
922
|
+
const name = node.kind === 278 /* SyntaxKind.ImportSpecifier */ || node.kind === 283 /* SyntaxKind.ExportSpecifier */
|
|
830
923
|
? getPropertyNameOrName(node)
|
|
831
924
|
: getName(node);
|
|
832
925
|
errorNoModuleMemberSymbol(c, moduleSymbol, moduleSymbol, node, name);
|
|
@@ -845,7 +938,7 @@ function getTargetOfModuleDefault(c, moduleSymbol, node, dontResolveAlias) {
|
|
|
845
938
|
function reportNonDefaultExport(c, moduleSymbol, node) {
|
|
846
939
|
const local = getSymbol(node);
|
|
847
940
|
if (moduleSymbol.exports?.get(local.name) !== undefined) {
|
|
848
|
-
c.error(node,
|
|
941
|
+
c.error(node, 764 /* Diagnostics.Module_0_has_no_default_export_Did_you_mean_to_use_import_1_from_0_instead */, symbolToString(c, moduleSymbol), symbolToString(c, local));
|
|
849
942
|
return;
|
|
850
943
|
}
|
|
851
944
|
const diagnostic = c.error(getName(node), 148 /* Diagnostics.Module_0_has_no_default_export */, symbolToString(c, moduleSymbol));
|
|
@@ -854,9 +947,9 @@ function reportNonDefaultExport(c, moduleSymbol, node) {
|
|
|
854
947
|
return;
|
|
855
948
|
for (const d of getDeclarations(exportStar)) {
|
|
856
949
|
const specifier = getModuleSpecifier(d);
|
|
857
|
-
if (d.kind !==
|
|
950
|
+
if (d.kind !== 280 /* SyntaxKind.ExportDeclaration */ || specifier === undefined)
|
|
858
951
|
continue;
|
|
859
|
-
const resolved = resolveExternalModuleName(c, d, specifier, false);
|
|
952
|
+
const resolved = resolveExternalModuleName(c, d, specifier, false, getTypeFromImportAttributes(c, getImportAttributes(d)));
|
|
860
953
|
if (resolved !== undefined && resolved.exports?.get("default" /* InternalSymbolName.Default */) !== undefined) {
|
|
861
954
|
diagnostic.addRelatedInfo(createDiagnosticForNode(d, 151 /* Diagnostics.X_export_Asterisk_does_not_re_export_a_default */, []));
|
|
862
955
|
return;
|
|
@@ -874,7 +967,7 @@ function resolveExportByName(c, moduleSymbol, name, sourceNode, dontResolveAlias
|
|
|
874
967
|
}
|
|
875
968
|
function getTargetOfNamespaceImport(c, node) {
|
|
876
969
|
const moduleSpecifier = getModuleSpecifierForImportOrExport(node);
|
|
877
|
-
const immediate = resolveExternalModuleName(c, node, moduleSpecifier, false);
|
|
970
|
+
const immediate = resolveExternalModuleName(c, node, moduleSpecifier, false, getTypeFromImportAttributes(c, getImportAttributes(node.parent.parent)));
|
|
878
971
|
const resolved = resolveESModuleSymbol(c, immediate, node, moduleSpecifier);
|
|
879
972
|
markSymbolOfAliasDeclarationIfTypeOnly(c, node, undefined);
|
|
880
973
|
return resolved;
|
|
@@ -883,22 +976,22 @@ function getTargetOfNamespaceExport(c, node) {
|
|
|
883
976
|
const moduleSpecifier = getModuleSpecifierForImportOrExport(node);
|
|
884
977
|
if (moduleSpecifier === undefined)
|
|
885
978
|
return undefined;
|
|
886
|
-
const immediate = resolveExternalModuleName(c, node, moduleSpecifier, false);
|
|
979
|
+
const immediate = resolveExternalModuleName(c, node, moduleSpecifier, false, getTypeFromImportAttributes(c, getImportAttributes(node.parent)));
|
|
887
980
|
const resolved = resolveESModuleSymbol(c, immediate, node, moduleSpecifier);
|
|
888
981
|
markSymbolOfAliasDeclarationIfTypeOnly(c, node, undefined);
|
|
889
982
|
return resolved;
|
|
890
983
|
}
|
|
891
984
|
function getTargetOfImportSpecifier(c, node) {
|
|
892
985
|
const name = getPropertyNameOrName(node);
|
|
893
|
-
if (node.kind ===
|
|
986
|
+
if (node.kind === 278 /* SyntaxKind.ImportSpecifier */ && moduleExportNameIsDefault(name)) {
|
|
894
987
|
const specifier = getModuleSpecifierForImportOrExport(node);
|
|
895
988
|
if (specifier !== undefined) {
|
|
896
|
-
const moduleSymbol = resolveExternalModuleName(c, node, specifier, false);
|
|
989
|
+
const moduleSymbol = resolveExternalModuleName(c, node, specifier, false, getTypeFromImportAttributes(c, getImportAttributes(node.parent.parent.parent)));
|
|
897
990
|
if (moduleSymbol !== undefined)
|
|
898
991
|
return getTargetOfModuleDefault(c, moduleSymbol, node, true);
|
|
899
992
|
}
|
|
900
993
|
}
|
|
901
|
-
const root = node.kind ===
|
|
994
|
+
const root = node.kind === 210 /* SyntaxKind.BindingElement */ ? getRootDeclaration(node) : node.parent.parent.parent;
|
|
902
995
|
const resolved = getExternalModuleMember(c, root, node, true);
|
|
903
996
|
markSymbolOfAliasDeclarationIfTypeOnly(c, node, undefined);
|
|
904
997
|
return resolved;
|
|
@@ -908,8 +1001,9 @@ export function getExternalModuleMember(c, node, specifier, dontResolveAlias) {
|
|
|
908
1001
|
const moduleSpecifier = isVariableDeclarationInitializedToRequire(node)
|
|
909
1002
|
? getInitializer(node).arguments.nodes[0]
|
|
910
1003
|
: getExternalModuleName(node);
|
|
911
|
-
const
|
|
912
|
-
const
|
|
1004
|
+
const importAttributesType = getTypeFromImportAttributes(c, getImportAttributes(node));
|
|
1005
|
+
const moduleSymbol = resolveExternalModuleName(c, node, moduleSpecifier, false, importAttributesType);
|
|
1006
|
+
const name = specifier.kind === 213 /* SyntaxKind.PropertyAccessExpression */ ? getName(specifier) : getPropertyNameOrName(specifier);
|
|
913
1007
|
if (name.kind !== 79 /* SyntaxKind.Identifier */ && name.kind !== 10 /* SyntaxKind.StringLiteral */)
|
|
914
1008
|
return undefined;
|
|
915
1009
|
const nameText = getText(name);
|
|
@@ -932,7 +1026,7 @@ export function getExternalModuleMember(c, node, specifier, dontResolveAlias) {
|
|
|
932
1026
|
let symbolFromModule = getExportOfModule(c, exportEquals ? moduleSymbol : targetSymbol, nameText, specifier, dontResolveAlias);
|
|
933
1027
|
if (symbolFromModule === undefined &&
|
|
934
1028
|
nameText === "default" /* InternalSymbolName.Default */ &&
|
|
935
|
-
(isOnlyImportableAsDefault(c, moduleSpecifier, moduleSymbol) ||
|
|
1029
|
+
(isOnlyImportableAsDefault(c, moduleSpecifier, moduleSymbol, importAttributesType) ||
|
|
936
1030
|
canHaveSyntheticDefault(c, getSourceFileDeclaration(moduleSymbol), moduleSymbol, dontResolveAlias, moduleSpecifier)))
|
|
937
1031
|
symbolFromModule =
|
|
938
1032
|
resolveExternalModuleSymbol(c, moduleSymbol, dontResolveAlias) ??
|
|
@@ -942,10 +1036,10 @@ export function getExternalModuleMember(c, node, specifier, dontResolveAlias) {
|
|
|
942
1036
|
: symbolFromVariable === undefined
|
|
943
1037
|
? symbolFromModule
|
|
944
1038
|
: combineValueAndTypeSymbols(c, symbolFromVariable, symbolFromModule);
|
|
945
|
-
if ((specifier.kind ===
|
|
1039
|
+
if ((specifier.kind === 278 /* SyntaxKind.ImportSpecifier */ || specifier.kind === 283 /* SyntaxKind.ExportSpecifier */) &&
|
|
946
1040
|
nameText !== "default" /* InternalSymbolName.Default */ &&
|
|
947
|
-
isOnlyImportableAsDefault(c, moduleSpecifier, moduleSymbol))
|
|
948
|
-
c.error(name,
|
|
1041
|
+
isOnlyImportableAsDefault(c, moduleSpecifier, moduleSymbol, importAttributesType))
|
|
1042
|
+
c.error(name, 457 /* Diagnostics.Named_imports_from_a_JSON_file_into_an_ECMAScript_module_are_not_allowed_when_module_is_set_to_0 */, moduleKindName(getEmitModuleKind(c.compilerOptions)));
|
|
949
1043
|
else if (symbol === undefined)
|
|
950
1044
|
errorNoModuleMemberSymbol(c, moduleSymbol, targetSymbol, node, name);
|
|
951
1045
|
return symbol;
|
|
@@ -998,13 +1092,13 @@ function errorNoModuleMemberSymbol(c, moduleSymbol, targetSymbol, node, name) {
|
|
|
998
1092
|
: undefined;
|
|
999
1093
|
if (suggestion !== undefined) {
|
|
1000
1094
|
const suggestionName = symbolToString(c, suggestion);
|
|
1001
|
-
const diagnostic = c.error(name,
|
|
1095
|
+
const diagnostic = c.error(name, 863 /* Diagnostics.X_0_has_no_exported_member_named_1_Did_you_mean_2 */, moduleName, declarationName, suggestionName);
|
|
1002
1096
|
if (suggestion.valueDeclaration !== undefined)
|
|
1003
|
-
diagnostic.addRelatedInfo(createDiagnosticForNode(suggestion.valueDeclaration,
|
|
1097
|
+
diagnostic.addRelatedInfo(createDiagnosticForNode(suggestion.valueDeclaration, 867 /* Diagnostics.X_0_is_declared_here */, [suggestionName]));
|
|
1004
1098
|
return;
|
|
1005
1099
|
}
|
|
1006
1100
|
if (moduleSymbol.exports?.get("default" /* InternalSymbolName.Default */) !== undefined) {
|
|
1007
|
-
c.error(name,
|
|
1101
|
+
c.error(name, 765 /* Diagnostics.Module_0_has_no_exported_member_1_Did_you_mean_to_use_import_1_from_0_instead */, moduleName, declarationName);
|
|
1008
1102
|
return;
|
|
1009
1103
|
}
|
|
1010
1104
|
reportNonExportedMember(c, name, declarationName, moduleSymbol, moduleName);
|
|
@@ -1013,7 +1107,7 @@ function reportNonExportedMember(c, name, declarationName, moduleSymbol, moduleN
|
|
|
1013
1107
|
const locals = moduleSymbol.valueDeclaration !== undefined ? getLocals(moduleSymbol.valueDeclaration) : undefined;
|
|
1014
1108
|
const localSymbol = locals?.get(getText(name));
|
|
1015
1109
|
if (localSymbol === undefined) {
|
|
1016
|
-
c.error(name,
|
|
1110
|
+
c.error(name, 490 /* Diagnostics.Module_0_has_no_exported_member_1 */, moduleName, declarationName);
|
|
1017
1111
|
return;
|
|
1018
1112
|
}
|
|
1019
1113
|
const exports = moduleSymbol.exports;
|
|
@@ -1022,7 +1116,7 @@ function reportNonExportedMember(c, name, declarationName, moduleSymbol, moduleN
|
|
|
1022
1116
|
if (isSameReference(c, exportEquals, localSymbol))
|
|
1023
1117
|
reportInvalidImportEqualsExportMember(c, name, declarationName, moduleName);
|
|
1024
1118
|
else
|
|
1025
|
-
c.error(name,
|
|
1119
|
+
c.error(name, 490 /* Diagnostics.Module_0_has_no_exported_member_1 */, moduleName, declarationName);
|
|
1026
1120
|
return;
|
|
1027
1121
|
}
|
|
1028
1122
|
let exportedSymbol;
|
|
@@ -1033,10 +1127,10 @@ function reportNonExportedMember(c, name, declarationName, moduleSymbol, moduleN
|
|
|
1033
1127
|
break;
|
|
1034
1128
|
}
|
|
1035
1129
|
const diagnostic = exportedSymbol !== undefined
|
|
1036
|
-
? c.error(name,
|
|
1037
|
-
: c.error(name,
|
|
1130
|
+
? c.error(name, 633 /* Diagnostics.Module_0_declares_1_locally_but_it_is_exported_as_2 */, moduleName, declarationName, symbolToString(c, exportedSymbol))
|
|
1131
|
+
: c.error(name, 632 /* Diagnostics.Module_0_declares_1_locally_but_it_is_not_exported */, moduleName, declarationName);
|
|
1038
1132
|
for (let i = 0; i < declarationCount(localSymbol); i++)
|
|
1039
|
-
diagnostic.addRelatedInfo(createDiagnosticForNode(declarationAt(localSymbol, i), i === 0 ?
|
|
1133
|
+
diagnostic.addRelatedInfo(createDiagnosticForNode(declarationAt(localSymbol, i), i === 0 ? 867 /* Diagnostics.X_0_is_declared_here */ : 1368 /* Diagnostics.X_and_here */, [declarationName]));
|
|
1040
1134
|
}
|
|
1041
1135
|
function isSameReference(c, s1, s2) {
|
|
1042
1136
|
return (getMergedSymbol(c, resolveSymbol(c, getMergedSymbol(c, s1))) ===
|
|
@@ -1044,18 +1138,18 @@ function isSameReference(c, s1, s2) {
|
|
|
1044
1138
|
}
|
|
1045
1139
|
function reportInvalidImportEqualsExportMember(c, name, declarationName, moduleName) {
|
|
1046
1140
|
if (getEmitModuleKind(c.compilerOptions) >= ModuleKind.ES2015)
|
|
1047
|
-
c.error(name,
|
|
1141
|
+
c.error(name, 750 /* Diagnostics.X_0_can_only_be_imported_by_using_a_default_import */, declarationName);
|
|
1048
1142
|
else if (isInJSFile(name))
|
|
1049
|
-
c.error(name,
|
|
1143
|
+
c.error(name, 752 /* Diagnostics.X_0_can_only_be_imported_by_using_a_require_call_or_by_using_a_default_import */, declarationName);
|
|
1050
1144
|
else
|
|
1051
|
-
c.error(name,
|
|
1145
|
+
c.error(name, 767 /* Diagnostics.X_0_can_only_be_imported_by_using_import_1_require_2_or_a_default_import */, declarationName, declarationName, moduleName);
|
|
1052
1146
|
}
|
|
1053
1147
|
export function getTargetOfExportSpecifier(c, node, meaning, dontResolveAlias) {
|
|
1054
1148
|
const name = getPropertyNameOrName(node);
|
|
1055
1149
|
if (moduleExportNameIsDefault(name)) {
|
|
1056
1150
|
const specifier = getModuleSpecifierForImportOrExport(node);
|
|
1057
1151
|
if (specifier !== undefined) {
|
|
1058
|
-
const moduleSymbol = resolveExternalModuleName(c, node, specifier, false);
|
|
1152
|
+
const moduleSymbol = resolveExternalModuleName(c, node, specifier, false, getTypeFromImportAttributes(c, getImportAttributes(node.parent.parent)));
|
|
1059
1153
|
if (moduleSymbol !== undefined)
|
|
1060
1154
|
return getTargetOfModuleDefault(c, moduleSymbol, node, dontResolveAlias);
|
|
1061
1155
|
}
|
|
@@ -1070,7 +1164,7 @@ export function getTargetOfExportSpecifier(c, node, meaning, dontResolveAlias) {
|
|
|
1070
1164
|
return resolved;
|
|
1071
1165
|
}
|
|
1072
1166
|
function getTargetOfAliasLikeExpression(c, expression) {
|
|
1073
|
-
if (expression.kind ===
|
|
1167
|
+
if (expression.kind === 233 /* SyntaxKind.ClassExpression */)
|
|
1074
1168
|
return checkExpressionCached(c, expression).symbol;
|
|
1075
1169
|
if (!isEntityNameOrEntityNameExpression(expression))
|
|
1076
1170
|
return undefined;
|
|
@@ -1083,9 +1177,9 @@ function getTargetOfAliasLikeExpression(c, expression) {
|
|
|
1083
1177
|
function isEntityNameOrEntityNameExpression(node) {
|
|
1084
1178
|
if (node.kind === 79 /* SyntaxKind.Identifier */)
|
|
1085
1179
|
return true;
|
|
1086
|
-
if (node.kind ===
|
|
1180
|
+
if (node.kind === 168 /* SyntaxKind.QualifiedName */)
|
|
1087
1181
|
return true;
|
|
1088
|
-
if (node.kind ===
|
|
1182
|
+
if (node.kind === 213 /* SyntaxKind.PropertyAccessExpression */) {
|
|
1089
1183
|
const name = getName(node);
|
|
1090
1184
|
return (name !== undefined &&
|
|
1091
1185
|
name.kind === 79 /* SyntaxKind.Identifier */ &&
|
|
@@ -1098,25 +1192,25 @@ function getPropertyNameOrName(node) {
|
|
|
1098
1192
|
}
|
|
1099
1193
|
function getModuleSpecifierForImportOrExport(node) {
|
|
1100
1194
|
switch (node.kind) {
|
|
1101
|
-
case
|
|
1195
|
+
case 275 /* SyntaxKind.ImportClause */:
|
|
1102
1196
|
return getModuleSpecifierOfDeclaration(node.parent);
|
|
1103
|
-
case
|
|
1197
|
+
case 273 /* SyntaxKind.ImportEqualsDeclaration */: {
|
|
1104
1198
|
const reference = node.moduleReference;
|
|
1105
|
-
return reference.kind ===
|
|
1199
|
+
return reference.kind === 285 /* SyntaxKind.ExternalModuleReference */ ? getExpression(reference) : undefined;
|
|
1106
1200
|
}
|
|
1107
|
-
case
|
|
1201
|
+
case 276 /* SyntaxKind.NamespaceImport */:
|
|
1108
1202
|
return getModuleSpecifierOfDeclaration(node.parent.parent);
|
|
1109
|
-
case
|
|
1203
|
+
case 278 /* SyntaxKind.ImportSpecifier */:
|
|
1110
1204
|
return getModuleSpecifierOfDeclaration(node.parent.parent.parent);
|
|
1111
|
-
case
|
|
1205
|
+
case 282 /* SyntaxKind.NamespaceExport */:
|
|
1112
1206
|
return getModuleSpecifierOfDeclaration(node.parent);
|
|
1113
|
-
case
|
|
1207
|
+
case 283 /* SyntaxKind.ExportSpecifier */:
|
|
1114
1208
|
return getModuleSpecifierOfDeclaration(node.parent.parent);
|
|
1115
1209
|
}
|
|
1116
1210
|
return undefined;
|
|
1117
1211
|
}
|
|
1118
1212
|
function getModuleSpecifierOfDeclaration(node) {
|
|
1119
|
-
if (node.kind ===
|
|
1213
|
+
if (node.kind === 280 /* SyntaxKind.ExportDeclaration */)
|
|
1120
1214
|
return node.moduleSpecifier;
|
|
1121
1215
|
return getModuleSpecifier(node);
|
|
1122
1216
|
}
|
|
@@ -1124,27 +1218,27 @@ function getModuleSpecifierOfDeclaration(node) {
|
|
|
1124
1218
|
/** Whether the declaration itself is written `import type` or `export type`. */
|
|
1125
1219
|
export function isTypeOnlyImportOrExportDeclaration(node) {
|
|
1126
1220
|
switch (node.kind) {
|
|
1127
|
-
case
|
|
1221
|
+
case 278 /* SyntaxKind.ImportSpecifier */:
|
|
1128
1222
|
return getIsTypeOnly(node) || isTypeOnlyImportClause(node.parent.parent);
|
|
1129
|
-
case
|
|
1223
|
+
case 276 /* SyntaxKind.NamespaceImport */:
|
|
1130
1224
|
return isTypeOnlyImportClause(node.parent);
|
|
1131
|
-
case
|
|
1225
|
+
case 275 /* SyntaxKind.ImportClause */:
|
|
1132
1226
|
return isTypeOnlyImportClause(node);
|
|
1133
|
-
case
|
|
1227
|
+
case 273 /* SyntaxKind.ImportEqualsDeclaration */:
|
|
1134
1228
|
return getIsTypeOnly(node);
|
|
1135
|
-
case
|
|
1229
|
+
case 283 /* SyntaxKind.ExportSpecifier */:
|
|
1136
1230
|
return getIsTypeOnly(node) || getIsTypeOnly(node.parent.parent);
|
|
1137
|
-
case
|
|
1231
|
+
case 280 /* SyntaxKind.ExportDeclaration */: {
|
|
1138
1232
|
const declaration = node;
|
|
1139
1233
|
return (declaration.isTypeOnly && declaration.moduleSpecifier !== undefined && declaration.exportClause === undefined);
|
|
1140
1234
|
}
|
|
1141
|
-
case
|
|
1235
|
+
case 282 /* SyntaxKind.NamespaceExport */:
|
|
1142
1236
|
return getIsTypeOnly(node.parent);
|
|
1143
1237
|
}
|
|
1144
1238
|
return false;
|
|
1145
1239
|
}
|
|
1146
1240
|
function isTypeOnlyImportClause(node) {
|
|
1147
|
-
return node.kind ===
|
|
1241
|
+
return node.kind === 275 /* SyntaxKind.ImportClause */ && node.phaseModifier === 156 /* SyntaxKind.TypeKeyword */;
|
|
1148
1242
|
}
|
|
1149
1243
|
/**
|
|
1150
1244
|
* Marks an alias declared `import type`/`export type`, or reached through a type-only `export *`,
|
|
@@ -1170,19 +1264,19 @@ function markSymbolOfAliasDeclarationIfTypeOnly(c, aliasDeclaration, exportStarD
|
|
|
1170
1264
|
/** Marks the alias declaration an entity name is part of, if it is type-only. */
|
|
1171
1265
|
export function markAliasDeclarationOfNameIfTypeOnly(c, name) {
|
|
1172
1266
|
let current = name;
|
|
1173
|
-
while (current.parent !== undefined && current.parent.kind ===
|
|
1267
|
+
while (current.parent !== undefined && current.parent.kind === 168 /* SyntaxKind.QualifiedName */)
|
|
1174
1268
|
current = current.parent;
|
|
1175
1269
|
const parent = current.parent;
|
|
1176
1270
|
if (parent === undefined)
|
|
1177
1271
|
return;
|
|
1178
1272
|
switch (parent.kind) {
|
|
1179
|
-
case
|
|
1180
|
-
case
|
|
1181
|
-
case
|
|
1182
|
-
case
|
|
1183
|
-
case
|
|
1184
|
-
case
|
|
1185
|
-
case
|
|
1273
|
+
case 275 /* SyntaxKind.ImportClause */:
|
|
1274
|
+
case 278 /* SyntaxKind.ImportSpecifier */:
|
|
1275
|
+
case 276 /* SyntaxKind.NamespaceImport */:
|
|
1276
|
+
case 283 /* SyntaxKind.ExportSpecifier */:
|
|
1277
|
+
case 279 /* SyntaxKind.ExportAssignment */:
|
|
1278
|
+
case 273 /* SyntaxKind.ImportEqualsDeclaration */:
|
|
1279
|
+
case 282 /* SyntaxKind.NamespaceExport */:
|
|
1186
1280
|
markSymbolOfAliasDeclarationIfTypeOnly(c, parent, undefined);
|
|
1187
1281
|
}
|
|
1188
1282
|
}
|
|
@@ -1217,9 +1311,9 @@ export function getTypeOnlyAliasDeclarationOfMeaning(c, symbol, meaning) {
|
|
|
1217
1311
|
function addTypeOnlyDeclarationRelatedInfo(diagnostic, typeOnlyDeclaration, name) {
|
|
1218
1312
|
if (typeOnlyDeclaration === undefined)
|
|
1219
1313
|
return;
|
|
1220
|
-
const isExport = typeOnlyDeclaration.kind ===
|
|
1221
|
-
typeOnlyDeclaration.kind ===
|
|
1222
|
-
typeOnlyDeclaration.kind ===
|
|
1314
|
+
const isExport = typeOnlyDeclaration.kind === 283 /* SyntaxKind.ExportSpecifier */ ||
|
|
1315
|
+
typeOnlyDeclaration.kind === 280 /* SyntaxKind.ExportDeclaration */ ||
|
|
1316
|
+
typeOnlyDeclaration.kind === 282 /* SyntaxKind.NamespaceExport */;
|
|
1223
1317
|
diagnostic.addRelatedInfo(createDiagnosticForNode(typeOnlyDeclaration, isExport ? 306 /* Diagnostics.X_0_was_exported_here */ : 305 /* Diagnostics.X_0_was_imported_here */, [name]));
|
|
1224
1318
|
}
|
|
1225
1319
|
/** Reports a value use of a name that only resolves to a value through a type-only import or export. */
|
|
@@ -1231,9 +1325,9 @@ export function checkTypeOnlyAliasUse(c, location, result, name) {
|
|
|
1231
1325
|
const typeOnlyDeclaration = getTypeOnlyAliasDeclarationOfMeaning(c, result, 111551 /* SymbolFlags.Value */);
|
|
1232
1326
|
if (typeOnlyDeclaration === undefined)
|
|
1233
1327
|
return;
|
|
1234
|
-
const isExport = typeOnlyDeclaration.kind ===
|
|
1235
|
-
typeOnlyDeclaration.kind ===
|
|
1236
|
-
typeOnlyDeclaration.kind ===
|
|
1328
|
+
const isExport = typeOnlyDeclaration.kind === 283 /* SyntaxKind.ExportSpecifier */ ||
|
|
1329
|
+
typeOnlyDeclaration.kind === 280 /* SyntaxKind.ExportDeclaration */ ||
|
|
1330
|
+
typeOnlyDeclaration.kind === 282 /* SyntaxKind.NamespaceExport */;
|
|
1237
1331
|
const diagnostic = c.error(location, isExport
|
|
1238
1332
|
? 296 /* Diagnostics.X_0_cannot_be_used_as_a_value_because_it_was_exported_using_export_type */
|
|
1239
1333
|
: 295 /* Diagnostics.X_0_cannot_be_used_as_a_value_because_it_was_imported_using_import_type */, name);
|
|
@@ -1250,26 +1344,26 @@ function isIdentifierInNonEmittingHeritageClause(node) {
|
|
|
1250
1344
|
if (node.kind !== 79 /* SyntaxKind.Identifier */)
|
|
1251
1345
|
return false;
|
|
1252
1346
|
let parent = node.parent;
|
|
1253
|
-
while (parent.kind ===
|
|
1347
|
+
while (parent.kind === 213 /* SyntaxKind.PropertyAccessExpression */ || parent.kind === 235 /* SyntaxKind.ExpressionWithTypeArguments */)
|
|
1254
1348
|
parent = parent.parent;
|
|
1255
|
-
return (parent.kind ===
|
|
1349
|
+
return (parent.kind === 300 /* SyntaxKind.HeritageClause */ &&
|
|
1256
1350
|
(parent.token === 118 /* SyntaxKind.ImplementsKeyword */ ||
|
|
1257
|
-
parent.parent.kind ===
|
|
1351
|
+
parent.parent.kind === 266 /* SyntaxKind.InterfaceDeclaration */));
|
|
1258
1352
|
}
|
|
1259
1353
|
function isPartOfPossiblyValidTypeOrAbstractComputedPropertyName(node) {
|
|
1260
1354
|
let current = node;
|
|
1261
|
-
while (current.kind === 79 /* SyntaxKind.Identifier */ || current.kind ===
|
|
1355
|
+
while (current.kind === 79 /* SyntaxKind.Identifier */ || current.kind === 213 /* SyntaxKind.PropertyAccessExpression */)
|
|
1262
1356
|
current = current.parent;
|
|
1263
|
-
if (current.kind !==
|
|
1357
|
+
if (current.kind !== 169 /* SyntaxKind.ComputedPropertyName */)
|
|
1264
1358
|
return false;
|
|
1265
1359
|
if (hasSyntacticModifier(current.parent, 64 /* ModifierFlags.Abstract */))
|
|
1266
1360
|
return true;
|
|
1267
1361
|
const container = current.parent.parent.kind;
|
|
1268
|
-
return container ===
|
|
1362
|
+
return container === 266 /* SyntaxKind.InterfaceDeclaration */ || container === 189 /* SyntaxKind.TypeLiteral */;
|
|
1269
1363
|
}
|
|
1270
1364
|
function isShorthandPropertyNameUseSite(useSite) {
|
|
1271
1365
|
return (useSite.kind === 79 /* SyntaxKind.Identifier */ &&
|
|
1272
|
-
useSite.parent.kind ===
|
|
1366
|
+
useSite.parent.kind === 305 /* SyntaxKind.ShorthandPropertyAssignment */ &&
|
|
1273
1367
|
getName(useSite.parent) === useSite);
|
|
1274
1368
|
}
|
|
1275
1369
|
// ---- Referenced aliases
|
|
@@ -1298,14 +1392,14 @@ function shouldMarkIdentifierAliasReferenced(node) {
|
|
|
1298
1392
|
if (parent === undefined)
|
|
1299
1393
|
return true;
|
|
1300
1394
|
// The left of a property access is marked with the property.
|
|
1301
|
-
if (parent.kind ===
|
|
1395
|
+
if (parent.kind === 213 /* SyntaxKind.PropertyAccessExpression */ && getExpression(parent) === node)
|
|
1302
1396
|
return false;
|
|
1303
1397
|
// Names of type-only exports aren't emitted.
|
|
1304
|
-
if (parent.kind ===
|
|
1398
|
+
if (parent.kind === 283 /* SyntaxKind.ExportSpecifier */ && getIsTypeOnly(parent))
|
|
1305
1399
|
return false;
|
|
1306
1400
|
const greatGrandparent = parent.parent?.parent;
|
|
1307
1401
|
return !(greatGrandparent !== undefined &&
|
|
1308
|
-
greatGrandparent.kind ===
|
|
1402
|
+
greatGrandparent.kind === 280 /* SyntaxKind.ExportDeclaration */ &&
|
|
1309
1403
|
getIsTypeOnly(greatGrandparent));
|
|
1310
1404
|
}
|
|
1311
1405
|
/**
|
|
@@ -1317,7 +1411,7 @@ export function markPropertyAliasReferenced(c, location, prop, leftType) {
|
|
|
1317
1411
|
return;
|
|
1318
1412
|
if ((location.flags & 8388608 /* NodeFlags.Ambient */) !== 0 || isPartOfImportEqualsModuleReference(location))
|
|
1319
1413
|
return;
|
|
1320
|
-
const left = location.kind ===
|
|
1414
|
+
const left = location.kind === 213 /* SyntaxKind.PropertyAccessExpression */ ? getExpression(location) : location.left;
|
|
1321
1415
|
if (left.kind !== 79 /* SyntaxKind.Identifier */ || getText(left) === 'this')
|
|
1322
1416
|
return;
|
|
1323
1417
|
const parentSymbol = getResolvedSymbol(c, left);
|
|
@@ -1332,13 +1426,13 @@ export function markPropertyAliasReferenced(c, location, prop, leftType) {
|
|
|
1332
1426
|
}
|
|
1333
1427
|
if (prop !== undefined &&
|
|
1334
1428
|
(isConstEnumOrConstEnumOnlyModule(prop) ||
|
|
1335
|
-
((prop.flags & 8 /* SymbolFlags.EnumMember */) !== 0 && location.parent.kind ===
|
|
1429
|
+
((prop.flags & 8 /* SymbolFlags.EnumMember */) !== 0 && location.parent.kind === 307 /* SyntaxKind.EnumMember */)))
|
|
1336
1430
|
return;
|
|
1337
1431
|
markAliasReferenced(c, parentSymbol, location);
|
|
1338
1432
|
}
|
|
1339
1433
|
function isPartOfImportEqualsModuleReference(location) {
|
|
1340
1434
|
let importEquals = location;
|
|
1341
|
-
while (importEquals !== undefined && importEquals.kind !==
|
|
1435
|
+
while (importEquals !== undefined && importEquals.kind !== 273 /* SyntaxKind.ImportEqualsDeclaration */)
|
|
1342
1436
|
importEquals = importEquals.parent;
|
|
1343
1437
|
if (importEquals === undefined)
|
|
1344
1438
|
return false;
|
|
@@ -1378,8 +1472,8 @@ function markAliasSymbolAsReferenced(c, symbol) {
|
|
|
1378
1472
|
links.aliasReferenced = true;
|
|
1379
1473
|
const node = getDeclarationOfAliasSymbol(symbol);
|
|
1380
1474
|
if (node !== undefined &&
|
|
1381
|
-
node.kind ===
|
|
1382
|
-
node.moduleReference.kind !==
|
|
1475
|
+
node.kind === 273 /* SyntaxKind.ImportEqualsDeclaration */ &&
|
|
1476
|
+
node.moduleReference.kind !== 285 /* SyntaxKind.ExternalModuleReference */ &&
|
|
1383
1477
|
(getSymbolFlags(c, resolveSymbol(c, symbol)) & 111551 /* SymbolFlags.Value */) !== 0)
|
|
1384
1478
|
markIdentifierAliasReferenced(c, getFirstIdentifierOfEntityName(node.moduleReference));
|
|
1385
1479
|
}
|
|
@@ -1416,9 +1510,9 @@ function isExportOrExportExpression(location) {
|
|
|
1416
1510
|
const parent = n.parent;
|
|
1417
1511
|
if (parent === undefined)
|
|
1418
1512
|
return false;
|
|
1419
|
-
if (parent.kind ===
|
|
1420
|
-
return (getExpression(parent) === n && isEntityNameOrEntityNameExpression(n) && n.kind !==
|
|
1421
|
-
if (parent.kind ===
|
|
1513
|
+
if (parent.kind === 279 /* SyntaxKind.ExportAssignment */)
|
|
1514
|
+
return (getExpression(parent) === n && isEntityNameOrEntityNameExpression(n) && n.kind !== 168 /* SyntaxKind.QualifiedName */);
|
|
1515
|
+
if (parent.kind === 283 /* SyntaxKind.ExportSpecifier */) {
|
|
1422
1516
|
if (getName(parent) === n || getPropertyName(parent) === n)
|
|
1423
1517
|
return true;
|
|
1424
1518
|
}
|
|
@@ -1510,7 +1604,7 @@ class ExportCollector {
|
|
|
1510
1604
|
const lookupTable = new Map();
|
|
1511
1605
|
for (const node of getDeclarations(exportStars)) {
|
|
1512
1606
|
const specifier = node.moduleSpecifier;
|
|
1513
|
-
const resolved = resolveExternalModuleName(this.c, node, specifier, false);
|
|
1607
|
+
const resolved = resolveExternalModuleName(this.c, node, specifier, false, getTypeFromImportAttributes(this.c, getImportAttributes(node)));
|
|
1514
1608
|
const exported = this.visit(resolved, node, isTypeOnly || getIsTypeOnly(node));
|
|
1515
1609
|
this.extendExportSymbols(nested, exported, lookupTable, node);
|
|
1516
1610
|
}
|
|
@@ -1519,7 +1613,7 @@ class ExportCollector {
|
|
|
1519
1613
|
if (id === "export=" /* InternalSymbolName.ExportEquals */ || collision.exportsWithDuplicate.length === 0 || symbols.has(id))
|
|
1520
1614
|
continue;
|
|
1521
1615
|
for (const node of collision.exportsWithDuplicate)
|
|
1522
|
-
this.c.error(node,
|
|
1616
|
+
this.c.error(node, 493 /* Diagnostics.Module_0_has_already_exported_a_member_named_1_Consider_explicitly_re_exporting_to_resolve_the_ambiguity */, collision.specifierText, id);
|
|
1523
1617
|
}
|
|
1524
1618
|
this.extendExportSymbols(symbols, nested, undefined, undefined);
|
|
1525
1619
|
}
|
|
@@ -1567,7 +1661,7 @@ export function getTypeFromImportTypeNode(c, node) {
|
|
|
1567
1661
|
}
|
|
1568
1662
|
const targetMeaning = importType.isTypeOf ? 111551 /* SymbolFlags.Value */ : 788968 /* SymbolFlags.Type */;
|
|
1569
1663
|
const literal = importType.argument.literal;
|
|
1570
|
-
const innerModuleSymbol = resolveExternalModuleName(c, node, literal, false);
|
|
1664
|
+
const innerModuleSymbol = resolveExternalModuleName(c, node, literal, false, getTypeFromImportAttributes(c, importType.attributes));
|
|
1571
1665
|
if (innerModuleSymbol === undefined) {
|
|
1572
1666
|
c.resolvedSymbols.set(node.id, c.unknownSymbol);
|
|
1573
1667
|
c.resolvedTypes.set(node.id, c.errorType);
|
|
@@ -1587,7 +1681,7 @@ export function getTypeFromImportTypeNode(c, node) {
|
|
|
1587
1681
|
? getPropertyOfTypeEx(c, getTypeOfSymbol(c, merged), text, false, true)
|
|
1588
1682
|
: getSymbolOfMeaning(c, getExportsOfSymbol(c, merged), text, meaning);
|
|
1589
1683
|
if (next === undefined) {
|
|
1590
|
-
c.error(current,
|
|
1684
|
+
c.error(current, 833 /* Diagnostics.Namespace_0_has_no_exported_member_1 */, getFullyQualifiedName(c, currentNamespace), declarationNameToString(getSourceFileOfNode(current), current));
|
|
1591
1685
|
c.resolvedTypes.set(node.id, c.errorType);
|
|
1592
1686
|
return c.resolvedTypes.get(node.id);
|
|
1593
1687
|
}
|
|
@@ -1619,9 +1713,9 @@ function getIdentifierChain(node) {
|
|
|
1619
1713
|
function resolveImportSymbolType(c, node, symbol, meaning) {
|
|
1620
1714
|
const resolvedSymbol = resolveSymbol(c, symbol);
|
|
1621
1715
|
c.resolvedSymbols.set(node.id, resolvedSymbol);
|
|
1622
|
-
//
|
|
1716
|
+
// A value's type comes from the alias, which caches it, instantiated with the node's type arguments.
|
|
1623
1717
|
if (meaning === 111551 /* SymbolFlags.Value */)
|
|
1624
|
-
return getTypeOfSymbol(c, symbol);
|
|
1718
|
+
return getInstantiationExpressionType(c, getTypeOfSymbol(c, symbol), node);
|
|
1625
1719
|
return getTypeReferenceType(c, node, resolvedSymbol);
|
|
1626
1720
|
}
|
|
1627
1721
|
/** `import(specifier, options)`: a promise of the module namespace. */
|
|
@@ -1636,49 +1730,57 @@ export function checkImportCallExpression(c, node) {
|
|
|
1636
1730
|
for (let i = 2; i < args.length; i++)
|
|
1637
1731
|
checkExpressionCached(c, args[i]);
|
|
1638
1732
|
if ((specifierType.flags & 12 /* TypeFlags.Nullable */) !== 0 || !isTypeAssignableTo(c, specifierType, c.stringType))
|
|
1639
|
-
c.error(specifier,
|
|
1733
|
+
c.error(specifier, 1726 /* Diagnostics.Dynamic_import_s_specifier_must_be_of_type_string_but_here_has_type_0 */, typeToString(c, specifierType));
|
|
1734
|
+
let importAttributesType;
|
|
1640
1735
|
if (optionsType !== undefined) {
|
|
1641
1736
|
const importCallOptionsType = getCachedGlobalType(c, 'ImportCallOptions', 0, true);
|
|
1642
1737
|
if (importCallOptionsType !== c.emptyObjectType)
|
|
1643
1738
|
checkTypeAssignableTo(c, optionsType, getNullableType(c, importCallOptionsType, 4 /* TypeFlags.Undefined */), args[1], undefined);
|
|
1644
|
-
if (args[1].kind ===
|
|
1739
|
+
if (args[1].kind === 212 /* SyntaxKind.ObjectLiteralExpression */)
|
|
1645
1740
|
for (const property of args[1].properties.nodes) {
|
|
1646
1741
|
const name = getName(property);
|
|
1647
|
-
if (property.kind ===
|
|
1742
|
+
if (property.kind === 304 /* SyntaxKind.PropertyAssignment */ &&
|
|
1648
1743
|
name !== undefined &&
|
|
1649
1744
|
name.kind === 79 /* SyntaxKind.Identifier */ &&
|
|
1650
1745
|
getText(name) === 'assert') {
|
|
1651
|
-
c.error(name,
|
|
1746
|
+
c.error(name, 1007 /* Diagnostics.Import_assertions_have_been_replaced_by_import_attributes_Use_with_instead_of_assert */);
|
|
1652
1747
|
break;
|
|
1653
1748
|
}
|
|
1654
1749
|
}
|
|
1750
|
+
importAttributesType = getTypeOfPropertyOfType(c, optionsType, 'with');
|
|
1655
1751
|
}
|
|
1656
|
-
|
|
1752
|
+
if (isSourcePhaseImportCall(node))
|
|
1753
|
+
return createPromiseReturnType(c, node, getGlobalAbstractModuleSourceType(c));
|
|
1754
|
+
const moduleSymbol = resolveExternalModuleName(c, node, specifier, false, importAttributesType);
|
|
1657
1755
|
if (moduleSymbol !== undefined) {
|
|
1658
1756
|
const esModuleSymbol = resolveExternalModuleSymbol(c, moduleSymbol, true);
|
|
1659
1757
|
if (esModuleSymbol !== undefined)
|
|
1660
|
-
return createPromiseReturnType(c, node, getTypeWithSyntheticDefaultOnly(c, getTypeOfSymbol(c, esModuleSymbol), esModuleSymbol, moduleSymbol, specifier) ??
|
|
1758
|
+
return createPromiseReturnType(c, node, getTypeWithSyntheticDefaultOnly(c, getTypeOfSymbol(c, esModuleSymbol), esModuleSymbol, moduleSymbol, specifier, importAttributesType) ??
|
|
1661
1759
|
getTypeWithSyntheticDefaultImportType(c, getTypeOfSymbol(c, esModuleSymbol), esModuleSymbol, moduleSymbol, specifier));
|
|
1662
1760
|
}
|
|
1663
1761
|
return createPromiseReturnType(c, node, c.anyType);
|
|
1664
1762
|
}
|
|
1763
|
+
/** `AbstractModuleSource`, the type of a source phase import's binding (lib.esnext.modulesource). */
|
|
1764
|
+
function getGlobalAbstractModuleSourceType(c) {
|
|
1765
|
+
return getCachedGlobalType(c, 'AbstractModuleSource', 0, true);
|
|
1766
|
+
}
|
|
1665
1767
|
function createPromiseReturnType(c, node, promisedType) {
|
|
1666
1768
|
const promiseType = createPromiseType(c, promisedType);
|
|
1667
1769
|
if (promiseType !== c.unknownType)
|
|
1668
1770
|
return promiseType;
|
|
1669
|
-
c.error(node,
|
|
1771
|
+
c.error(node, 850 /* Diagnostics.A_dynamic_import_call_returns_a_Promise_Make_sure_you_have_a_declaration_for_Promise_or_include_ES2015_in_your_lib_option */);
|
|
1670
1772
|
return c.errorType;
|
|
1671
1773
|
}
|
|
1672
1774
|
// ---- JSDoc links
|
|
1673
1775
|
/** The symbol a `{@link}` name refers to, as an entity or a member of one. */
|
|
1674
1776
|
export function resolveJSDocMemberName(c, name) {
|
|
1675
|
-
if (name === undefined || (name.kind !== 79 /* SyntaxKind.Identifier */ && name.kind !==
|
|
1777
|
+
if (name === undefined || (name.kind !== 79 /* SyntaxKind.Identifier */ && name.kind !== 168 /* SyntaxKind.QualifiedName */))
|
|
1676
1778
|
return undefined;
|
|
1677
1779
|
const meaning = 788968 /* SymbolFlags.Type */ | 1920 /* SymbolFlags.Namespace */ | 111551 /* SymbolFlags.Value */;
|
|
1678
1780
|
const symbol = resolveEntityName(c, name, meaning, true, true, getHostSignatureFromJSDoc(name));
|
|
1679
1781
|
if (symbol !== undefined)
|
|
1680
1782
|
return symbol;
|
|
1681
|
-
if (name.kind !==
|
|
1783
|
+
if (name.kind !== 168 /* SyntaxKind.QualifiedName */)
|
|
1682
1784
|
return undefined;
|
|
1683
1785
|
const left = resolveJSDocMemberName(c, name.left);
|
|
1684
1786
|
if (left === undefined)
|
|
@@ -1689,11 +1791,11 @@ export function resolveJSDocMemberName(c, name) {
|
|
|
1689
1791
|
if (prototype !== undefined)
|
|
1690
1792
|
type = getTypeOfSymbol(c, prototype);
|
|
1691
1793
|
}
|
|
1692
|
-
return getPropertyOfType(c, type ?? getDeclaredTypeOfSymbol(c, left), name.right
|
|
1794
|
+
return getPropertyOfType(c, type ?? getDeclaredTypeOfSymbol(c, left), getText(name.right));
|
|
1693
1795
|
}
|
|
1694
1796
|
export function getHostSignatureFromJSDoc(node) {
|
|
1695
1797
|
let current = node;
|
|
1696
|
-
while (current !== undefined && current.kind !==
|
|
1798
|
+
while (current !== undefined && current.kind !== 316 /* SyntaxKind.JSDoc */)
|
|
1697
1799
|
current = current.parent;
|
|
1698
1800
|
const host = current?.parent;
|
|
1699
1801
|
return host !== undefined && isFunctionLike(host) ? host : undefined;
|
|
@@ -1704,13 +1806,13 @@ export function checkMetaProperty(c, node) {
|
|
|
1704
1806
|
const meta = node;
|
|
1705
1807
|
if (meta.keywordToken === 104 /* SyntaxKind.NewKeyword */)
|
|
1706
1808
|
return checkNewTargetMetaProperty(c, node);
|
|
1707
|
-
// `import.defer`
|
|
1708
|
-
if (
|
|
1809
|
+
// `import.defer` and `import.source` are only valid as callees.
|
|
1810
|
+
if (isImportPhaseMetaProperty(node))
|
|
1709
1811
|
return c.errorType;
|
|
1710
1812
|
const moduleKind = getEmitModuleKind(c.compilerOptions);
|
|
1711
1813
|
if (moduleKind >= ModuleKind.Node16 && moduleKind <= ModuleKind.NodeNext) {
|
|
1712
1814
|
if (c.host.getImpliedNodeFormatForEmit(getSourceFileOfNode(node)) === ModuleKind.CommonJS)
|
|
1713
|
-
c.error(node,
|
|
1815
|
+
c.error(node, 383 /* Diagnostics.The_import_meta_meta_property_is_not_allowed_in_files_which_will_build_into_CommonJS_output */);
|
|
1714
1816
|
}
|
|
1715
1817
|
else if (moduleKind < ModuleKind.ES2020 && moduleKind !== ModuleKind.System)
|
|
1716
1818
|
c.error(node, 277 /* Diagnostics.The_import_meta_meta_property_is_only_allowed_when_the_module_option_is_es2020_es2022_esnext_system_node16_node18_node20_or_nodenext */);
|
|
@@ -1718,13 +1820,13 @@ export function checkMetaProperty(c, node) {
|
|
|
1718
1820
|
}
|
|
1719
1821
|
export function checkNewTargetMetaProperty(c, node) {
|
|
1720
1822
|
const container = getThisContainer(node, false, false);
|
|
1721
|
-
if (container.kind !==
|
|
1722
|
-
container.kind !==
|
|
1723
|
-
container.kind !==
|
|
1724
|
-
c.error(node,
|
|
1823
|
+
if (container.kind !== 178 /* SyntaxKind.Constructor */ &&
|
|
1824
|
+
container.kind !== 264 /* SyntaxKind.FunctionDeclaration */ &&
|
|
1825
|
+
container.kind !== 220 /* SyntaxKind.FunctionExpression */) {
|
|
1826
|
+
c.error(node, 1836 /* Diagnostics.Meta_property_0_is_only_allowed_in_the_body_of_a_function_declaration_function_expression_or_constructor */, 'new.target');
|
|
1725
1827
|
return c.errorType;
|
|
1726
1828
|
}
|
|
1727
|
-
const symbol = getSymbolOfDeclaration(c, container.kind ===
|
|
1829
|
+
const symbol = getSymbolOfDeclaration(c, container.kind === 178 /* SyntaxKind.Constructor */ ? container.parent : container);
|
|
1728
1830
|
return symbol !== undefined ? getTypeOfSymbol(c, symbol) : c.errorType;
|
|
1729
1831
|
}
|
|
1730
1832
|
// ---- Import and export declarations
|
|
@@ -1737,14 +1839,14 @@ function isValidExternalImportOrExportDeclaration(node) {
|
|
|
1737
1839
|
if (moduleName === undefined || nodeIsMissing(moduleName) || moduleName.kind !== 10 /* SyntaxKind.StringLiteral */)
|
|
1738
1840
|
return false;
|
|
1739
1841
|
const parent = node.parent;
|
|
1740
|
-
const inAmbientExternalModule = parent.kind ===
|
|
1741
|
-
if (parent.kind !==
|
|
1842
|
+
const inAmbientExternalModule = parent.kind === 270 /* SyntaxKind.ModuleBlock */ && isAmbientModule(parent.parent);
|
|
1843
|
+
if (parent.kind !== 308 /* SyntaxKind.SourceFile */ && !inAmbientExternalModule)
|
|
1742
1844
|
return false;
|
|
1743
1845
|
if (inAmbientExternalModule &&
|
|
1744
1846
|
isExternalModuleNameRelative(getText(moduleName)) &&
|
|
1745
1847
|
!isModuleAugmentationExternal(parent.parent))
|
|
1746
1848
|
return false;
|
|
1747
|
-
if (node.kind ===
|
|
1849
|
+
if (node.kind === 273 /* SyntaxKind.ImportEqualsDeclaration */)
|
|
1748
1850
|
return true;
|
|
1749
1851
|
const attributes = getImportAttributes(node);
|
|
1750
1852
|
if (attributes === undefined)
|
|
@@ -1754,14 +1856,33 @@ function isValidExternalImportOrExportDeclaration(node) {
|
|
|
1754
1856
|
return false;
|
|
1755
1857
|
return true;
|
|
1756
1858
|
}
|
|
1859
|
+
/**
|
|
1860
|
+
* Resolves the module an import or export in an illegal context names, when that context is still
|
|
1861
|
+
* in a file's global scope (a block), to report a missing module. A side-effect import isn't resolved.
|
|
1862
|
+
*/
|
|
1863
|
+
function checkExternalModuleNameInGlobalScope(c, node) {
|
|
1864
|
+
let container = node.parent;
|
|
1865
|
+
while (container !== undefined && (getContainerFlags(container) & 1 /* ContainerFlags.IsContainer */) === 0)
|
|
1866
|
+
container = container.parent;
|
|
1867
|
+
if (container === undefined || container.kind !== 308 /* SyntaxKind.SourceFile */)
|
|
1868
|
+
return;
|
|
1869
|
+
if ((node.kind === 274 /* SyntaxKind.ImportDeclaration */ || node.kind === 347 /* SyntaxKind.JSImportDeclaration */) &&
|
|
1870
|
+
node.importClause === undefined)
|
|
1871
|
+
return;
|
|
1872
|
+
const moduleName = getExternalModuleName(node);
|
|
1873
|
+
if (moduleName !== undefined)
|
|
1874
|
+
resolveExternalModuleName(c, node, moduleName, false, getTypeFromImportAttributes(c, getImportAttributes(node)));
|
|
1875
|
+
}
|
|
1757
1876
|
function isInModuleElementContext(node) {
|
|
1758
1877
|
const parent = node.parent.kind;
|
|
1759
|
-
return (parent ===
|
|
1878
|
+
return (parent === 308 /* SyntaxKind.SourceFile */ || parent === 270 /* SyntaxKind.ModuleBlock */ || parent === 269 /* SyntaxKind.ModuleDeclaration */);
|
|
1760
1879
|
}
|
|
1761
1880
|
function getImportAttributes(node) {
|
|
1762
|
-
if (node.kind ===
|
|
1881
|
+
if (node.kind === 274 /* SyntaxKind.ImportDeclaration */ || node.kind === 347 /* SyntaxKind.JSImportDeclaration */)
|
|
1882
|
+
return node.attributes;
|
|
1883
|
+
if (node.kind === 280 /* SyntaxKind.ExportDeclaration */)
|
|
1763
1884
|
return node.attributes;
|
|
1764
|
-
if (node.kind ===
|
|
1885
|
+
if (node.kind === 207 /* SyntaxKind.ImportType */)
|
|
1765
1886
|
return node.attributes;
|
|
1766
1887
|
return undefined;
|
|
1767
1888
|
}
|
|
@@ -1771,7 +1892,7 @@ function hasImportClauseGrammarError(c, node) {
|
|
|
1771
1892
|
if (node.phaseModifier === 156 /* SyntaxKind.TypeKeyword */) {
|
|
1772
1893
|
if ((node.flags & 4194304 /* NodeFlags.JSDoc */) === 0 && node.name !== undefined && namedBindings !== undefined)
|
|
1773
1894
|
return !hasParseErrors(node);
|
|
1774
|
-
if (namedBindings !== undefined && namedBindings.kind ===
|
|
1895
|
+
if (namedBindings !== undefined && namedBindings.kind === 277 /* SyntaxKind.NamedImports */)
|
|
1775
1896
|
for (const specifier of namedBindings.elements.nodes)
|
|
1776
1897
|
if (getIsTypeOnly(specifier))
|
|
1777
1898
|
return !hasParseErrors(node);
|
|
@@ -1779,7 +1900,7 @@ function hasImportClauseGrammarError(c, node) {
|
|
|
1779
1900
|
else if (node.phaseModifier === 166 /* SyntaxKind.DeferKeyword */) {
|
|
1780
1901
|
if (node.name !== undefined)
|
|
1781
1902
|
return !hasParseErrors(node);
|
|
1782
|
-
if (namedBindings !== undefined && namedBindings.kind ===
|
|
1903
|
+
if (namedBindings !== undefined && namedBindings.kind === 277 /* SyntaxKind.NamedImports */)
|
|
1783
1904
|
return !hasParseErrors(node);
|
|
1784
1905
|
const moduleKind = getEmitModuleKind(c.compilerOptions);
|
|
1785
1906
|
if (moduleKind !== ModuleKind.ESNext && moduleKind !== ModuleKind.Preserve)
|
|
@@ -1791,6 +1912,8 @@ function hasParseErrors(node) {
|
|
|
1791
1912
|
return getSourceFileOfNode(node).diagnostics.length > 0;
|
|
1792
1913
|
}
|
|
1793
1914
|
export function checkImportDeclaration(c, node) {
|
|
1915
|
+
if (!isInModuleElementContext(node))
|
|
1916
|
+
checkExternalModuleNameInGlobalScope(c, node);
|
|
1794
1917
|
if (!isInModuleElementContext(node) || !isValidExternalImportOrExportDeclaration(node)) {
|
|
1795
1918
|
checkImportAttributes(c, node);
|
|
1796
1919
|
return;
|
|
@@ -1805,7 +1928,7 @@ export function checkImportDeclaration(c, node) {
|
|
|
1805
1928
|
const emittedAsCommonJS = c.host.getEmitModuleFormatOfFile(getSourceFileOfNode(node)) === ModuleKind.CommonJS;
|
|
1806
1929
|
let needsImportStar = false;
|
|
1807
1930
|
if (namedBindings !== undefined) {
|
|
1808
|
-
if (namedBindings.kind ===
|
|
1931
|
+
if (namedBindings.kind === 276 /* SyntaxKind.NamespaceImport */) {
|
|
1809
1932
|
checkImportBinding(c, namedBindings);
|
|
1810
1933
|
if (emittedAsCommonJS) {
|
|
1811
1934
|
needsImportStar = true;
|
|
@@ -1813,7 +1936,7 @@ export function checkImportDeclaration(c, node) {
|
|
|
1813
1936
|
}
|
|
1814
1937
|
}
|
|
1815
1938
|
else {
|
|
1816
|
-
resolvedModule = resolveExternalModuleName(c, node, declaration.moduleSpecifier, false);
|
|
1939
|
+
resolvedModule = resolveExternalModuleName(c, node, declaration.moduleSpecifier, false, getTypeFromImportAttributes(c, declaration.attributes));
|
|
1817
1940
|
if (resolvedModule !== undefined)
|
|
1818
1941
|
for (const binding of namedBindings.elements.nodes)
|
|
1819
1942
|
checkImportBinding(c, binding);
|
|
@@ -1825,12 +1948,12 @@ export function checkImportDeclaration(c, node) {
|
|
|
1825
1948
|
if (!isTypeOnly(clause) &&
|
|
1826
1949
|
moduleKind >= ModuleKind.Node18 &&
|
|
1827
1950
|
moduleKind <= ModuleKind.NodeNext &&
|
|
1828
|
-
isOnlyImportableAsDefault(c, declaration.moduleSpecifier, resolvedModule) &&
|
|
1951
|
+
isOnlyImportableAsDefault(c, declaration.moduleSpecifier, resolvedModule, getTypeFromImportAttributes(c, declaration.attributes)) &&
|
|
1829
1952
|
!hasTypeJsonImportAttribute(declaration))
|
|
1830
|
-
c.error(declaration.moduleSpecifier,
|
|
1953
|
+
c.error(declaration.moduleSpecifier, 456 /* Diagnostics.Importing_a_JSON_file_into_an_ECMAScript_module_requires_a_type_Colon_json_import_attribute_when_module_is_set_to_0 */, moduleKindName(moduleKind));
|
|
1831
1954
|
}
|
|
1832
1955
|
else if (clause === undefined && c.compilerOptions.noUncheckedSideEffectImports !== false)
|
|
1833
|
-
resolveExternalModuleNameWorker(c, node, declaration.moduleSpecifier,
|
|
1956
|
+
resolveExternalModuleNameWorker(c, node, declaration.moduleSpecifier, 1009 /* Diagnostics.Cannot_find_module_or_type_declarations_for_side_effect_import_of_0 */, false, false, getTypeFromImportAttributes(c, declaration.attributes));
|
|
1834
1957
|
checkImportAttributes(c, node);
|
|
1835
1958
|
}
|
|
1836
1959
|
function hasTypeJsonImportAttribute(node) {
|
|
@@ -1847,28 +1970,57 @@ function hasTypeJsonImportAttribute(node) {
|
|
|
1847
1970
|
function checkImportBinding(c, node) {
|
|
1848
1971
|
checkCollisionsForDeclarationName(c, node, getName(node));
|
|
1849
1972
|
checkAliasSymbol(c, node);
|
|
1850
|
-
if (node.kind ===
|
|
1973
|
+
if (node.kind === 278 /* SyntaxKind.ImportSpecifier */ &&
|
|
1851
1974
|
moduleExportNameIsDefault(getPropertyNameOrName(node)) &&
|
|
1852
1975
|
c.host.getEmitModuleFormatOfFile(getSourceFileOfNode(node)) === ModuleKind.CommonJS)
|
|
1853
1976
|
checkExternalEmitHelpers(c, node, 2048 /* ExternalEmitHelpers.ImportDefault */);
|
|
1854
1977
|
}
|
|
1855
1978
|
/** Import attributes must be assignable to the global `ImportAttributes`. */
|
|
1856
|
-
function checkImportAttributes(c, declaration) {
|
|
1979
|
+
export function checkImportAttributes(c, declaration) {
|
|
1857
1980
|
const node = getImportAttributes(declaration);
|
|
1858
1981
|
if (node === undefined)
|
|
1859
1982
|
return;
|
|
1860
1983
|
const importAttributesType = getCachedGlobalType(c, 'ImportAttributes', 0, true);
|
|
1861
1984
|
if (importAttributesType !== c.emptyObjectType)
|
|
1862
|
-
checkTypeAssignableTo(c,
|
|
1985
|
+
checkTypeAssignableTo(c, checkImportAttributesExpression(c, node), getNullableType(c, importAttributesType, 4 /* TypeFlags.Undefined */), node, undefined);
|
|
1863
1986
|
}
|
|
1987
|
+
/** The type of import attributes, which resolution matches against the attributes types of pattern ambient modules. */
|
|
1864
1988
|
function getTypeFromImportAttributes(c, node) {
|
|
1989
|
+
if (node === undefined)
|
|
1990
|
+
return undefined;
|
|
1991
|
+
if (node.kind === 302 /* SyntaxKind.ImportAttributes */)
|
|
1992
|
+
return checkImportAttributesExpression(c, node);
|
|
1993
|
+
return checkExpressionCached(c, node);
|
|
1994
|
+
}
|
|
1995
|
+
/** The import attributes type of the declaration `node` is the module specifier of. */
|
|
1996
|
+
export function getImportAttributesTypeForModuleSpecifier(c, moduleSpecifier) {
|
|
1997
|
+
const parent = moduleSpecifier.parent;
|
|
1998
|
+
switch (parent.kind) {
|
|
1999
|
+
case 274 /* SyntaxKind.ImportDeclaration */:
|
|
2000
|
+
case 347 /* SyntaxKind.JSImportDeclaration */:
|
|
2001
|
+
case 280 /* SyntaxKind.ExportDeclaration */:
|
|
2002
|
+
return getTypeFromImportAttributes(c, getImportAttributes(parent));
|
|
2003
|
+
case 203 /* SyntaxKind.LiteralType */:
|
|
2004
|
+
if (parent.parent.kind === 207 /* SyntaxKind.ImportType */)
|
|
2005
|
+
return getTypeFromImportAttributes(c, parent.parent.attributes);
|
|
2006
|
+
return undefined;
|
|
2007
|
+
case 215 /* SyntaxKind.CallExpression */: {
|
|
2008
|
+
const args = parent.arguments.nodes;
|
|
2009
|
+
if (isImportCall(parent) && args.length > 1)
|
|
2010
|
+
return getTypeOfPropertyOfType(c, checkExpressionCached(c, args[1]), 'with');
|
|
2011
|
+
return undefined;
|
|
2012
|
+
}
|
|
2013
|
+
}
|
|
2014
|
+
return undefined;
|
|
2015
|
+
}
|
|
2016
|
+
export function checkImportAttributesExpression(c, node) {
|
|
1865
2017
|
if (c.resolvedTypes.get(node.id) === undefined) {
|
|
1866
2018
|
const symbol = c.newSymbol(4096 /* SymbolFlags.ObjectLiteral */, "\uFFFEimportAttributes" /* InternalSymbolName.ImportAttributes */);
|
|
1867
2019
|
const members = new Map();
|
|
1868
2020
|
for (const attribute of node.attributes.nodes) {
|
|
1869
2021
|
const name = getText(attribute.name);
|
|
1870
2022
|
const member = c.newSymbol(4 /* SymbolFlags.Property */, name);
|
|
1871
|
-
c.symbolTypes.set(getSymbolId(member), getRegularTypeOfLiteralType(c,
|
|
2023
|
+
c.symbolTypes.set(getSymbolId(member), getRegularTypeOfLiteralType(c, checkExpressionCached(c, attribute.value)));
|
|
1872
2024
|
members.set(name, member);
|
|
1873
2025
|
}
|
|
1874
2026
|
const type = createAnonymousType(c, symbol, members, [], [], []);
|
|
@@ -1878,11 +2030,13 @@ function getTypeFromImportAttributes(c, node) {
|
|
|
1878
2030
|
return c.resolvedTypes.get(node.id);
|
|
1879
2031
|
}
|
|
1880
2032
|
export function checkImportEqualsDeclaration(c, node) {
|
|
1881
|
-
if (!isInModuleElementContext(node))
|
|
2033
|
+
if (!isInModuleElementContext(node)) {
|
|
2034
|
+
checkExternalModuleNameInGlobalScope(c, node);
|
|
1882
2035
|
return;
|
|
2036
|
+
}
|
|
1883
2037
|
const declaration = node;
|
|
1884
2038
|
const reference = declaration.moduleReference;
|
|
1885
|
-
const isExternal = reference.kind ===
|
|
2039
|
+
const isExternal = reference.kind === 285 /* SyntaxKind.ExternalModuleReference */;
|
|
1886
2040
|
if (shouldCheckErasableSyntax(c, node) && (node.flags & 8388608 /* NodeFlags.Ambient */) === 0)
|
|
1887
2041
|
c.error(node, 243 /* Diagnostics.This_syntax_is_not_allowed_when_erasableSyntaxOnly_is_enabled */);
|
|
1888
2042
|
if (isExternal && !isValidExternalImportOrExportDeclaration(node))
|
|
@@ -1901,14 +2055,14 @@ export function checkImportEqualsDeclaration(c, node) {
|
|
|
1901
2055
|
const moduleName = getFirstIdentifierOfEntityName(reference);
|
|
1902
2056
|
const resolved = resolveEntityName(c, moduleName, 111551 /* SymbolFlags.Value */ | 1920 /* SymbolFlags.Namespace */, false, false, undefined);
|
|
1903
2057
|
if (resolved !== undefined && (resolved.flags & 1920 /* SymbolFlags.Namespace */) === 0)
|
|
1904
|
-
c.error(moduleName,
|
|
2058
|
+
c.error(moduleName, 612 /* Diagnostics.Module_0_is_hidden_by_a_local_declaration_with_the_same_name */, declarationNameToString(getSourceFileOfNode(moduleName), moduleName));
|
|
1905
2059
|
}
|
|
1906
2060
|
if ((targetFlags & 788968 /* SymbolFlags.Type */) !== 0)
|
|
1907
|
-
checkTypeNameIsReserved(c, declaration.name,
|
|
2061
|
+
checkTypeNameIsReserved(c, declaration.name, 613 /* Diagnostics.Import_name_cannot_be_0 */);
|
|
1908
2062
|
}
|
|
1909
2063
|
function getFirstIdentifierOfEntityName(node) {
|
|
1910
2064
|
let current = node;
|
|
1911
|
-
while (current.kind ===
|
|
2065
|
+
while (current.kind === 168 /* SyntaxKind.QualifiedName */)
|
|
1912
2066
|
current = current.left;
|
|
1913
2067
|
return current;
|
|
1914
2068
|
}
|
|
@@ -1919,22 +2073,24 @@ function checkNamespaceExportName(c, name) {
|
|
|
1919
2073
|
const moduleKind = getEmitModuleKind(c.compilerOptions);
|
|
1920
2074
|
if ((moduleKind === ModuleKind.ES2015 || moduleKind === ModuleKind.ES2020) &&
|
|
1921
2075
|
!getSourceFileOfNode(name).isDeclarationFile)
|
|
1922
|
-
grammarErrorOnNode(c, name,
|
|
2076
|
+
grammarErrorOnNode(c, name, 1892 /* Diagnostics.String_literal_import_and_export_names_are_not_supported_when_the_module_flag_is_set_to_es2015_or_es2020 */);
|
|
1923
2077
|
}
|
|
1924
2078
|
export function checkExportDeclaration(c, node) {
|
|
1925
|
-
if (!isInModuleElementContext(node))
|
|
2079
|
+
if (!isInModuleElementContext(node)) {
|
|
2080
|
+
checkExternalModuleNameInGlobalScope(c, node);
|
|
1926
2081
|
return;
|
|
2082
|
+
}
|
|
1927
2083
|
const declaration = node;
|
|
1928
2084
|
if (declaration.moduleSpecifier === undefined || isValidExternalImportOrExportDeclaration(node)) {
|
|
1929
2085
|
const clause = declaration.exportClause;
|
|
1930
|
-
if (clause !== undefined && clause.kind ===
|
|
2086
|
+
if (clause !== undefined && clause.kind === 281 /* SyntaxKind.NamedExports */) {
|
|
1931
2087
|
for (const specifier of clause.elements.nodes)
|
|
1932
2088
|
checkExportSpecifier(c, specifier);
|
|
1933
2089
|
}
|
|
1934
2090
|
else {
|
|
1935
|
-
const moduleSymbol = resolveExternalModuleName(c, node, declaration.moduleSpecifier, false);
|
|
2091
|
+
const moduleSymbol = resolveExternalModuleName(c, node, declaration.moduleSpecifier, false, getTypeFromImportAttributes(c, declaration.attributes));
|
|
1936
2092
|
if (moduleSymbol !== undefined && hasExportAssignmentSymbol(moduleSymbol))
|
|
1937
|
-
c.error(declaration.moduleSpecifier,
|
|
2093
|
+
c.error(declaration.moduleSpecifier, 665 /* Diagnostics.Module_0_uses_export_and_cannot_be_used_with_export_Asterisk */, symbolToString(c, moduleSymbol));
|
|
1938
2094
|
else if (clause !== undefined) {
|
|
1939
2095
|
checkAliasSymbol(c, clause);
|
|
1940
2096
|
checkNamespaceExportName(c, getName(clause));
|
|
@@ -1963,7 +2119,7 @@ function checkExportSpecifier(c, node) {
|
|
|
1963
2119
|
(symbol === c.undefinedSymbol ||
|
|
1964
2120
|
symbol === c.globalThisSymbol ||
|
|
1965
2121
|
(declarationCount(symbol) > 0 && isGlobalSourceFile(getDeclarationContainer(symbol.declaration)))))
|
|
1966
|
-
c.error(exportedName,
|
|
2122
|
+
c.error(exportedName, 802 /* Diagnostics.Cannot_export_0_Only_local_declarations_can_be_exported_from_a_module */, getText(exportedName));
|
|
1967
2123
|
else
|
|
1968
2124
|
markExportSpecifierAliasReferenced(c, node, symbol, exportedName);
|
|
1969
2125
|
}
|
|
@@ -1974,12 +2130,12 @@ export function getDeclarationContainer(node) {
|
|
|
1974
2130
|
if (parent === undefined)
|
|
1975
2131
|
return current;
|
|
1976
2132
|
switch (current.kind) {
|
|
1977
|
-
case
|
|
1978
|
-
case
|
|
1979
|
-
case
|
|
1980
|
-
case
|
|
1981
|
-
case
|
|
1982
|
-
case
|
|
2133
|
+
case 262 /* SyntaxKind.VariableDeclaration */:
|
|
2134
|
+
case 263 /* SyntaxKind.VariableDeclarationList */:
|
|
2135
|
+
case 278 /* SyntaxKind.ImportSpecifier */:
|
|
2136
|
+
case 277 /* SyntaxKind.NamedImports */:
|
|
2137
|
+
case 276 /* SyntaxKind.NamespaceImport */:
|
|
2138
|
+
case 275 /* SyntaxKind.ImportClause */:
|
|
1983
2139
|
current = parent;
|
|
1984
2140
|
continue;
|
|
1985
2141
|
}
|
|
@@ -1987,17 +2143,24 @@ export function getDeclarationContainer(node) {
|
|
|
1987
2143
|
}
|
|
1988
2144
|
}
|
|
1989
2145
|
/** `export = e` and `export default e`; the grammar checker reports misplaced ones. */
|
|
2146
|
+
/** Whether an export assignment is in a namespace, rather than a file or an ambient module. */
|
|
2147
|
+
function isContainedByNamespace(node) {
|
|
2148
|
+
const container = node.parent.kind === 308 /* SyntaxKind.SourceFile */ ? node.parent : node.parent.parent;
|
|
2149
|
+
return container.kind === 269 /* SyntaxKind.ModuleDeclaration */ && !isAmbientModule(container);
|
|
2150
|
+
}
|
|
1990
2151
|
export function checkExportAssignment(c, node) {
|
|
2152
|
+
const declaration = node;
|
|
2153
|
+
// The expression is checked also where an export assignment is a grammar error.
|
|
2154
|
+
const exprType = checkExpressionCached(c, declaration.expression);
|
|
1991
2155
|
if (!isInModuleElementContext(node))
|
|
1992
2156
|
return;
|
|
1993
|
-
const declaration = node;
|
|
1994
2157
|
const isExportEquals = declaration.isExportEquals;
|
|
1995
2158
|
const ambient = (node.flags & 8388608 /* NodeFlags.Ambient */) !== 0;
|
|
1996
2159
|
if (shouldCheckErasableSyntax(c, node) && isExportEquals && !ambient)
|
|
1997
2160
|
c.error(node, 243 /* Diagnostics.This_syntax_is_not_allowed_when_erasableSyntaxOnly_is_enabled */);
|
|
1998
|
-
|
|
1999
|
-
if (container.kind === 268 /* SyntaxKind.ModuleDeclaration */ && !isAmbientModule(container))
|
|
2161
|
+
if (isContainedByNamespace(node))
|
|
2000
2162
|
return;
|
|
2163
|
+
const container = node.parent.kind === 308 /* SyntaxKind.SourceFile */ ? node.parent : node.parent.parent;
|
|
2001
2164
|
const verbatimModuleSyntax = c.compilerOptions.verbatimModuleSyntax === true;
|
|
2002
2165
|
const isIllegalExportDefaultInCJS = !isExportEquals &&
|
|
2003
2166
|
!ambient &&
|
|
@@ -2015,7 +2178,6 @@ export function checkExportAssignment(c, node) {
|
|
|
2015
2178
|
const name = getText(id);
|
|
2016
2179
|
// A non-value is exported as a type, like `export { Id as default }`.
|
|
2017
2180
|
if ((getSymbolFlags(c, sym) & 111551 /* SymbolFlags.Value */) !== 0) {
|
|
2018
|
-
checkExpressionCached(c, id);
|
|
2019
2181
|
if (!isIllegalExportDefaultInCJS && !ambient && verbatimModuleSyntax && typeOnlyDeclaration !== undefined)
|
|
2020
2182
|
c.error(id, isExportEquals
|
|
2021
2183
|
? 232 /* Diagnostics.An_export_declaration_must_reference_a_real_value_when_verbatimModuleSyntax_is_enabled_but_0_resolves_to_a_type_only_declaration */
|
|
@@ -2028,11 +2190,7 @@ export function checkExportAssignment(c, node) {
|
|
|
2028
2190
|
if (!isIllegalExportDefaultInCJS && !ambient && c.isolatedModules && (sym.flags & 111551 /* SymbolFlags.Value */) === 0)
|
|
2029
2191
|
checkIsolatedModulesExportAssignment(c, node, sym, typeOnlyDeclaration, isExportEquals);
|
|
2030
2192
|
}
|
|
2031
|
-
else
|
|
2032
|
-
checkExpressionCached(c, id);
|
|
2033
2193
|
}
|
|
2034
|
-
else
|
|
2035
|
-
checkExpressionCached(c, expression);
|
|
2036
2194
|
if (isIllegalExportDefaultInCJS)
|
|
2037
2195
|
c.error(node, verbatimModuleSyntaxErrorMessage(node));
|
|
2038
2196
|
checkExternalModuleExports(c, container);
|
|
@@ -2040,7 +2198,7 @@ export function checkExportAssignment(c, node) {
|
|
|
2040
2198
|
const typeNode = getType(node);
|
|
2041
2199
|
if (typeNode !== undefined) {
|
|
2042
2200
|
const expr = getExpression(node);
|
|
2043
|
-
checkTypeAssignableToAndOptionallyElaborate(c,
|
|
2201
|
+
checkTypeAssignableToAndOptionallyElaborate(c, exprType, getTypeFromTypeNode(c, typeNode), expr, expr);
|
|
2044
2202
|
}
|
|
2045
2203
|
}
|
|
2046
2204
|
function checkIsolatedModulesExportAssignment(c, node, sym, typeOnlyDeclaration, isExportEquals) {
|
|
@@ -2080,36 +2238,36 @@ export function checkAliasSymbol(c, node) {
|
|
|
2080
2238
|
((symbol.flags & 788968 /* SymbolFlags.Type */) !== 0 ? 788968 /* SymbolFlags.Type */ : 0) |
|
|
2081
2239
|
((symbol.flags & 1920 /* SymbolFlags.Namespace */) !== 0 ? 1920 /* SymbolFlags.Namespace */ : 0);
|
|
2082
2240
|
if ((targetFlags & excludedMeanings) !== 0)
|
|
2083
|
-
c.error(node, node.kind ===
|
|
2084
|
-
?
|
|
2085
|
-
:
|
|
2086
|
-
else if (node.kind !==
|
|
2241
|
+
c.error(node, node.kind === 283 /* SyntaxKind.ExportSpecifier */
|
|
2242
|
+
? 653 /* Diagnostics.Export_declaration_conflicts_with_exported_declaration_of_0 */
|
|
2243
|
+
: 615 /* Diagnostics.Import_declaration_conflicts_with_local_declaration_of_0 */, symbolToString(c, symbol));
|
|
2244
|
+
else if (node.kind !== 283 /* SyntaxKind.ExportSpecifier */ &&
|
|
2087
2245
|
c.compilerOptions.isolatedModules === true &&
|
|
2088
2246
|
!isPartOfTypeOnlyImportOrExportDeclaration(node) &&
|
|
2089
2247
|
(symbol.flags & (111551 /* SymbolFlags.Value */ | 1048576 /* SymbolFlags.ExportValue */)) !== 0)
|
|
2090
2248
|
// A transpiler sees a value import that collides with the local value.
|
|
2091
|
-
c.error(node,
|
|
2249
|
+
c.error(node, 992 /* Diagnostics.Import_0_conflicts_with_local_value_so_must_be_declared_with_a_type_only_import_when_isolatedModules_is_enabled */, symbolToString(c, symbol), getIsolatedModulesLikeFlagName(c));
|
|
2092
2250
|
if (c.isolatedModules && !isTypeOnlyImportOrExportDeclaration(node) && (node.flags & 8388608 /* NodeFlags.Ambient */) === 0)
|
|
2093
2251
|
checkIsolatedModulesAlias(c, node, symbol, target, targetFlags);
|
|
2094
|
-
if (node.kind ===
|
|
2252
|
+
if (node.kind === 278 /* SyntaxKind.ImportSpecifier */)
|
|
2095
2253
|
checkDeprecatedImportSpecifier(c, node, symbol);
|
|
2096
2254
|
}
|
|
2097
2255
|
function reportJSTypeAlias(c, node, symbol) {
|
|
2098
2256
|
const errorNode = getPropertyName(node) ?? getName(node) ?? node;
|
|
2099
|
-
if (node.kind ===
|
|
2100
|
-
c.error(errorNode,
|
|
2257
|
+
if (node.kind === 283 /* SyntaxKind.ExportSpecifier */) {
|
|
2258
|
+
c.error(errorNode, 1879 /* Diagnostics.Types_cannot_appear_in_export_declarations_in_JavaScript_files */);
|
|
2101
2259
|
return;
|
|
2102
2260
|
}
|
|
2103
2261
|
const identifierText = errorNode.kind === 79 /* SyntaxKind.Identifier */ ? getText(errorNode) : symbol.name;
|
|
2104
2262
|
let specifierText = '...';
|
|
2105
2263
|
let declaration = node;
|
|
2106
2264
|
while (declaration !== undefined &&
|
|
2107
|
-
declaration.kind !==
|
|
2108
|
-
declaration.kind !==
|
|
2109
|
-
declaration.kind !==
|
|
2265
|
+
declaration.kind !== 274 /* SyntaxKind.ImportDeclaration */ &&
|
|
2266
|
+
declaration.kind !== 273 /* SyntaxKind.ImportEqualsDeclaration */ &&
|
|
2267
|
+
declaration.kind !== 262 /* SyntaxKind.VariableDeclaration */)
|
|
2110
2268
|
declaration = declaration.parent;
|
|
2111
2269
|
if (declaration !== undefined) {
|
|
2112
|
-
const specifier = declaration.kind ===
|
|
2270
|
+
const specifier = declaration.kind === 262 /* SyntaxKind.VariableDeclaration */
|
|
2113
2271
|
? isVariableDeclarationInitializedToRequire(declaration)
|
|
2114
2272
|
? getInitializer(declaration).arguments.nodes[0]
|
|
2115
2273
|
: undefined
|
|
@@ -2118,9 +2276,9 @@ function reportJSTypeAlias(c, node, symbol) {
|
|
|
2118
2276
|
specifierText = getText(specifier);
|
|
2119
2277
|
}
|
|
2120
2278
|
let importText = 'import("' + specifierText + '")';
|
|
2121
|
-
if (node.kind ===
|
|
2279
|
+
if (node.kind === 278 /* SyntaxKind.ImportSpecifier */)
|
|
2122
2280
|
importText += '.' + identifierText;
|
|
2123
|
-
c.error(errorNode,
|
|
2281
|
+
c.error(errorNode, 1878 /* Diagnostics.X_0_is_a_type_and_cannot_be_imported_in_JavaScript_files_Use_1_in_a_JSDoc_type_annotation */, identifierText, importText);
|
|
2124
2282
|
}
|
|
2125
2283
|
function checkIsolatedModulesAlias(c, node, symbol, target, targetFlags) {
|
|
2126
2284
|
const verbatimModuleSyntax = c.compilerOptions.verbatimModuleSyntax === true;
|
|
@@ -2128,26 +2286,26 @@ function checkIsolatedModulesAlias(c, node, symbol, target, targetFlags) {
|
|
|
2128
2286
|
const isType = (targetFlags & 111551 /* SymbolFlags.Value */) === 0;
|
|
2129
2287
|
if (isType || typeOnlyAlias !== undefined) {
|
|
2130
2288
|
switch (node.kind) {
|
|
2131
|
-
case
|
|
2132
|
-
case
|
|
2133
|
-
case
|
|
2289
|
+
case 275 /* SyntaxKind.ImportClause */:
|
|
2290
|
+
case 278 /* SyntaxKind.ImportSpecifier */:
|
|
2291
|
+
case 273 /* SyntaxKind.ImportEqualsDeclaration */: {
|
|
2134
2292
|
if (verbatimModuleSyntax) {
|
|
2135
|
-
const message = node.kind ===
|
|
2136
|
-
node.moduleReference.kind !==
|
|
2293
|
+
const message = node.kind === 273 /* SyntaxKind.ImportEqualsDeclaration */ &&
|
|
2294
|
+
node.moduleReference.kind !== 285 /* SyntaxKind.ExternalModuleReference */
|
|
2137
2295
|
? 237 /* Diagnostics.An_import_alias_cannot_resolve_to_a_type_or_type_only_declaration_when_verbatimModuleSyntax_is_enabled */
|
|
2138
2296
|
: isType
|
|
2139
|
-
?
|
|
2140
|
-
:
|
|
2297
|
+
? 397 /* Diagnostics.X_0_is_a_type_and_must_be_imported_using_a_type_only_import_when_verbatimModuleSyntax_is_enabled */
|
|
2298
|
+
: 398 /* Diagnostics.X_0_resolves_to_a_type_only_declaration_and_must_be_imported_using_a_type_only_import_when_verbatimModuleSyntax_is_enabled */;
|
|
2141
2299
|
const name = getText(getPropertyNameOrName(node));
|
|
2142
2300
|
addTypeOnlyDeclarationRelatedInfo(c.error(node, message, name), isType ? undefined : typeOnlyAlias, name);
|
|
2143
2301
|
}
|
|
2144
2302
|
if (isType &&
|
|
2145
|
-
node.kind ===
|
|
2303
|
+
node.kind === 273 /* SyntaxKind.ImportEqualsDeclaration */ &&
|
|
2146
2304
|
hasSyntacticModifier(node, 32 /* ModifierFlags.Export */))
|
|
2147
2305
|
c.error(node, 218 /* Diagnostics.Cannot_use_export_import_on_a_type_or_type_only_namespace_when_0_is_enabled */, getIsolatedModulesLikeFlagName(c));
|
|
2148
2306
|
break;
|
|
2149
2307
|
}
|
|
2150
|
-
case
|
|
2308
|
+
case 283 /* SyntaxKind.ExportSpecifier */:
|
|
2151
2309
|
// `import type { A } from './a'; export { A }` is fine: one file shows the export is a type.
|
|
2152
2310
|
if (verbatimModuleSyntax ||
|
|
2153
2311
|
typeOnlyAlias === undefined ||
|
|
@@ -2162,13 +2320,14 @@ function checkIsolatedModulesAlias(c, node, symbol, target, targetFlags) {
|
|
|
2162
2320
|
}
|
|
2163
2321
|
}
|
|
2164
2322
|
if (verbatimModuleSyntax &&
|
|
2165
|
-
node.kind !==
|
|
2323
|
+
node.kind !== 273 /* SyntaxKind.ImportEqualsDeclaration */ &&
|
|
2166
2324
|
!isInJSFile(node) &&
|
|
2167
2325
|
c.host.getEmitModuleFormatOfFile(getSourceFileOfNode(node)) === ModuleKind.CommonJS)
|
|
2168
2326
|
c.error(node, verbatimModuleSyntaxErrorMessage(node));
|
|
2169
2327
|
else if (getEmitModuleKind(c.compilerOptions) === ModuleKind.Preserve &&
|
|
2170
|
-
node.kind !==
|
|
2171
|
-
node.kind !==
|
|
2328
|
+
node.kind !== 273 /* SyntaxKind.ImportEqualsDeclaration */ &&
|
|
2329
|
+
node.kind !== 262 /* SyntaxKind.VariableDeclaration */ &&
|
|
2330
|
+
node.kind !== 210 /* SyntaxKind.BindingElement */ &&
|
|
2172
2331
|
c.host.getEmitModuleFormatOfFile(getSourceFileOfNode(node)) === ModuleKind.CommonJS)
|
|
2173
2332
|
// Under `--module preserve` ESM syntax emits as ESM, so it is an error in a file that is CommonJS (.cts, .cjs).
|
|
2174
2333
|
c.error(node, 242 /* Diagnostics.ECMAScript_module_syntax_is_not_allowed_in_a_CommonJS_module_when_module_is_set_to_preserve */);
|
|
@@ -2176,7 +2335,7 @@ function checkIsolatedModulesAlias(c, node, symbol, target, targetFlags) {
|
|
|
2176
2335
|
(targetFlags & 128 /* SymbolFlags.ConstEnum */) !== 0 &&
|
|
2177
2336
|
target.valueDeclaration !== undefined &&
|
|
2178
2337
|
(target.valueDeclaration.flags & 8388608 /* NodeFlags.Ambient */) !== 0)
|
|
2179
|
-
c.error(node,
|
|
2338
|
+
c.error(node, 887 /* Diagnostics.Cannot_access_ambient_const_enums_when_0_is_enabled */, getIsolatedModulesLikeFlagName(c));
|
|
2180
2339
|
}
|
|
2181
2340
|
/** The error for ESM syntax in a CommonJS file under `verbatimModuleSyntax`: shorter in a .cts or .cjs file. */
|
|
2182
2341
|
function verbatimModuleSyntaxErrorMessage(node) {
|
|
@@ -2196,7 +2355,7 @@ export function getIsolatedModulesLikeFlagName(c) {
|
|
|
2196
2355
|
/** The file a module declaration or import names. */
|
|
2197
2356
|
export function getExternalModuleFileFromDeclaration(c, declaration) {
|
|
2198
2357
|
let specifier = undefined;
|
|
2199
|
-
if (declaration.kind ===
|
|
2358
|
+
if (declaration.kind === 269 /* SyntaxKind.ModuleDeclaration */) {
|
|
2200
2359
|
const name = getName(declaration);
|
|
2201
2360
|
if (name !== undefined && name.kind === 10 /* SyntaxKind.StringLiteral */)
|
|
2202
2361
|
specifier = name;
|
|
@@ -2205,9 +2364,10 @@ export function getExternalModuleFileFromDeclaration(c, declaration) {
|
|
|
2205
2364
|
specifier = getExternalModuleName(declaration);
|
|
2206
2365
|
if (specifier === undefined)
|
|
2207
2366
|
return undefined;
|
|
2208
|
-
|
|
2367
|
+
// Used by emit and type printing after checking reported any resolution errors, so it adds none.
|
|
2368
|
+
const moduleSymbol = resolveExternalModuleNameWorker(c, specifier, specifier, undefined, true, false, getTypeFromImportAttributes(c, getImportAttributes(declaration)));
|
|
2209
2369
|
if (moduleSymbol === undefined)
|
|
2210
2370
|
return undefined;
|
|
2211
|
-
const file = getDeclarationOfKind(moduleSymbol,
|
|
2371
|
+
const file = getDeclarationOfKind(moduleSymbol, 308 /* SyntaxKind.SourceFile */);
|
|
2212
2372
|
return file === undefined ? undefined : file;
|
|
2213
2373
|
}
|