From 8d62e2f175b592239096a450943d7f401c2925c2 Mon Sep 17 00:00:00 2001 From: Evan Wallace Date: Tue, 4 Jun 2024 13:40:50 -0700 Subject: [PATCH] Implement "Arbitrary Module Namespace Identifiers" (#58640) Co-authored-by: Ron Buckton --- src/compiler/binder.ts | 6 +- src/compiler/checker.ts | 131 +- src/compiler/diagnosticMessages.json | 4 + src/compiler/factory/nodeFactory.ts | 13 +- src/compiler/factory/nodeTests.ts | 5 + src/compiler/factory/utilities.ts | 3 + src/compiler/parser.ts | 56 +- src/compiler/transformers/module/module.ts | 75 +- src/compiler/transformers/module/system.ts | 33 +- src/compiler/transformers/utilities.ts | 55 +- src/compiler/types.ts | 24 +- src/compiler/utilities.ts | 24 +- src/compiler/visitorPublic.ts | 7 +- src/services/completions.ts | 49 +- src/services/findAllReferences.ts | 33 +- src/services/goToDefinition.ts | 8 +- src/services/importTracker.ts | 12 +- src/services/organizeImports.ts | 3 +- src/services/refactors/convertExport.ts | 5 +- src/services/refactors/convertImport.ts | 8 +- src/services/stringCompletions.ts | 21 + tests/baselines/reference/api/typescript.d.ts | 22 +- ...amespaceIdentifiers_exportEmpty.errors.txt | 13 + ...yModuleNamespaceIdentifiers_exportEmpty.js | 23 + ...leNamespaceIdentifiers_exportEmpty.symbols | 19 + ...duleNamespaceIdentifiers_exportEmpty.types | 27 + ...amespaceIdentifiers_importEmpty.errors.txt | 21 + ...yModuleNamespaceIdentifiers_importEmpty.js | 22 + ...leNamespaceIdentifiers_importEmpty.symbols | 22 + ...duleNamespaceIdentifiers_importEmpty.types | 31 + ...eIdentifiers_module(module=amd).errors.txt | 42 + ...NamespaceIdentifiers_module(module=amd).js | 69 + ...paceIdentifiers_module(module=amd).symbols | 82 + ...espaceIdentifiers_module(module=amd).types | 151 ++ ...tifiers_module(module=commonjs).errors.txt | 42 + ...paceIdentifiers_module(module=commonjs).js | 71 + ...dentifiers_module(module=commonjs).symbols | 82 + ...eIdentifiers_module(module=commonjs).types | 151 ++ ...entifiers_module(module=es2020).errors.txt | 84 + ...espaceIdentifiers_module(module=es2020).js | 67 + ...eIdentifiers_module(module=es2020).symbols | 82 + ...aceIdentifiers_module(module=es2020).types | 151 ++ ...entifiers_module(module=es2022).errors.txt | 42 + ...espaceIdentifiers_module(module=es2022).js | 67 + ...eIdentifiers_module(module=es2022).symbols | 82 + ...aceIdentifiers_module(module=es2022).types | 151 ++ ...eIdentifiers_module(module=es6).errors.txt | 84 + ...NamespaceIdentifiers_module(module=es6).js | 68 + ...paceIdentifiers_module(module=es6).symbols | 82 + ...espaceIdentifiers_module(module=es6).types | 151 ++ ...entifiers_module(module=esnext).errors.txt | 42 + ...espaceIdentifiers_module(module=esnext).js | 67 + ...eIdentifiers_module(module=esnext).symbols | 82 + ...aceIdentifiers_module(module=esnext).types | 151 ++ ...entifiers_module(module=node16).errors.txt | 42 + ...espaceIdentifiers_module(module=node16).js | 94 + ...eIdentifiers_module(module=node16).symbols | 82 + ...aceIdentifiers_module(module=node16).types | 151 ++ ...tifiers_module(module=nodenext).errors.txt | 42 + ...paceIdentifiers_module(module=nodenext).js | 94 + ...dentifiers_module(module=nodenext).symbols | 82 + ...eIdentifiers_module(module=nodenext).types | 151 ++ ...Identifiers_module(module=none).errors.txt | 42 + ...amespaceIdentifiers_module(module=none).js | 71 + ...aceIdentifiers_module(module=none).symbols | 82 + ...spaceIdentifiers_module(module=none).types | 151 ++ ...tifiers_module(module=preserve).errors.txt | 42 + ...paceIdentifiers_module(module=preserve).js | 67 + ...dentifiers_module(module=preserve).symbols | 82 + ...eIdentifiers_module(module=preserve).types | 151 ++ ...entifiers_module(module=system).errors.txt | 42 + ...espaceIdentifiers_module(module=system).js | 82 + ...eIdentifiers_module(module=system).symbols | 82 + ...aceIdentifiers_module(module=system).types | 151 ++ ...eIdentifiers_module(module=umd).errors.txt | 42 + ...NamespaceIdentifiers_module(module=umd).js | 81 + ...paceIdentifiers_module(module=umd).symbols | 82 + ...espaceIdentifiers_module(module=umd).types | 151 ++ ...duleNamespaceIdentifiers_syntax.errors.txt | 107 ++ ...itraryModuleNamespaceIdentifiers_syntax.js | 140 ++ ...yModuleNamespaceIdentifiers_syntax.symbols | 114 ++ ...aryModuleNamespaceIdentifiers_syntax.types | 160 ++ ...eNamespaceIdentifiers_types.baseline.jsonc | 1712 +++++++++++++++++ ...NamespaceIdentifiers_values.baseline.jsonc | 1628 ++++++++++++++++ ...yModuleNamespaceIdentifiers_exportEmpty.ts | 10 + ...yModuleNamespaceIdentifiers_importEmpty.ts | 12 + ...itraryModuleNamespaceIdentifiers_module.ts | 33 + ...itraryModuleNamespaceIdentifiers_syntax.ts | 64 + ...bitraryModuleNamespaceIdentifiers_types.ts | 19 + ...itraryModuleNamespaceIdentifiers_values.ts | 19 + .../completionsImportOrExportSpecifier.ts | 58 + ...ertImport_namedToNamespaceStringLiteral.ts | 17 + ...tringCompletionsImportOrExportSpecifier.ts | 52 + 93 files changed, 9016 insertions(+), 186 deletions(-) create mode 100644 tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_exportEmpty.errors.txt create mode 100644 tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_exportEmpty.js create mode 100644 tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_exportEmpty.symbols create mode 100644 tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_exportEmpty.types create mode 100644 tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_importEmpty.errors.txt create mode 100644 tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_importEmpty.js create mode 100644 tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_importEmpty.symbols create mode 100644 tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_importEmpty.types create mode 100644 tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=amd).errors.txt create mode 100644 tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=amd).js create mode 100644 tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=amd).symbols create mode 100644 tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=amd).types create mode 100644 tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=commonjs).errors.txt create mode 100644 tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=commonjs).js create mode 100644 tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=commonjs).symbols create mode 100644 tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=commonjs).types create mode 100644 tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=es2020).errors.txt create mode 100644 tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=es2020).js create mode 100644 tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=es2020).symbols create mode 100644 tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=es2020).types create mode 100644 tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=es2022).errors.txt create mode 100644 tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=es2022).js create mode 100644 tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=es2022).symbols create mode 100644 tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=es2022).types create mode 100644 tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=es6).errors.txt create mode 100644 tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=es6).js create mode 100644 tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=es6).symbols create mode 100644 tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=es6).types create mode 100644 tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=esnext).errors.txt create mode 100644 tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=esnext).js create mode 100644 tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=esnext).symbols create mode 100644 tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=esnext).types create mode 100644 tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=node16).errors.txt create mode 100644 tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=node16).js create mode 100644 tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=node16).symbols create mode 100644 tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=node16).types create mode 100644 tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=nodenext).errors.txt create mode 100644 tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=nodenext).js create mode 100644 tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=nodenext).symbols create mode 100644 tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=nodenext).types create mode 100644 tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=none).errors.txt create mode 100644 tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=none).js create mode 100644 tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=none).symbols create mode 100644 tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=none).types create mode 100644 tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=preserve).errors.txt create mode 100644 tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=preserve).js create mode 100644 tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=preserve).symbols create mode 100644 tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=preserve).types create mode 100644 tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=system).errors.txt create mode 100644 tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=system).js create mode 100644 tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=system).symbols create mode 100644 tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=system).types create mode 100644 tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=umd).errors.txt create mode 100644 tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=umd).js create mode 100644 tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=umd).symbols create mode 100644 tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=umd).types create mode 100644 tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_syntax.errors.txt create mode 100644 tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_syntax.js create mode 100644 tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_syntax.symbols create mode 100644 tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_syntax.types create mode 100644 tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_types.baseline.jsonc create mode 100644 tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_values.baseline.jsonc create mode 100644 tests/cases/conformance/es2022/arbitraryModuleNamespaceIdentifiers/arbitraryModuleNamespaceIdentifiers_exportEmpty.ts create mode 100644 tests/cases/conformance/es2022/arbitraryModuleNamespaceIdentifiers/arbitraryModuleNamespaceIdentifiers_importEmpty.ts create mode 100644 tests/cases/conformance/es2022/arbitraryModuleNamespaceIdentifiers/arbitraryModuleNamespaceIdentifiers_module.ts create mode 100644 tests/cases/conformance/es2022/arbitraryModuleNamespaceIdentifiers/arbitraryModuleNamespaceIdentifiers_syntax.ts create mode 100644 tests/cases/fourslash/arbitraryModuleNamespaceIdentifiers_types.ts create mode 100644 tests/cases/fourslash/arbitraryModuleNamespaceIdentifiers_values.ts create mode 100644 tests/cases/fourslash/completionsImportOrExportSpecifier.ts create mode 100644 tests/cases/fourslash/refactorConvertImport_namedToNamespaceStringLiteral.ts create mode 100644 tests/cases/fourslash/stringCompletionsImportOrExportSpecifier.ts diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index ea263f471cbdc..cab3c6911bf98 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -251,6 +251,7 @@ import { ModifierFlags, ModuleBlock, ModuleDeclaration, + moduleExportNameIsDefault, Mutable, NamespaceExportDeclaration, Node, @@ -433,6 +434,9 @@ function getModuleInstanceStateWorker(node: Node, visited: Map) { const name = specifier.propertyName || specifier.name; + if (name.kind !== SyntaxKind.Identifier) { + return ModuleInstanceState.Instantiated; // Skip for invalid syntax like this: export { "x" } + } let p: Node | undefined = specifier.parent; while (p) { if (isBlock(p) || isModuleBlock(p) || isSourceFile(p)) { @@ -759,7 +763,7 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void { function declareSymbol(symbolTable: SymbolTable, parent: Symbol | undefined, node: Declaration, includes: SymbolFlags, excludes: SymbolFlags, isReplaceableByMethod?: boolean, isComputedName?: boolean): Symbol { Debug.assert(isComputedName || !hasDynamicName(node)); - const isDefaultExport = hasSyntacticModifier(node, ModifierFlags.Default) || isExportSpecifier(node) && node.name.escapedText === "default"; + const isDefaultExport = hasSyntacticModifier(node, ModifierFlags.Default) || isExportSpecifier(node) && moduleExportNameIsDefault(node.name); // The exported symbol for an export default function/class node is always named "default" const name = isComputedName ? InternalSymbolName.Computed diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 51bbd6295c4ca..5cefd7aa08717 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -863,6 +863,10 @@ import { modifierToFlag, ModuleBlock, ModuleDeclaration, + ModuleExportName, + moduleExportNameIsDefault, + moduleExportNameTextEscaped, + moduleExportNameTextUnescaped, ModuleInstanceState, ModuleKind, ModuleResolutionKind, @@ -3629,7 +3633,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { : Diagnostics._0_was_imported_here; // TODO: how to get name for export *? - const name = typeOnlyDeclaration.kind === SyntaxKind.ExportDeclaration ? "*" : unescapeLeadingUnderscores(typeOnlyDeclaration.name.escapedText); + const name = typeOnlyDeclaration.kind === SyntaxKind.ExportDeclaration ? "*" : moduleExportNameTextUnescaped(typeOnlyDeclaration.name); addRelatedInfo(error(node.moduleReference, message), createDiagnosticForNode(typeOnlyDeclaration, relatedMessage, name)); } } @@ -3864,12 +3868,12 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { return result; } - function getExportOfModule(symbol: Symbol, name: Identifier, specifier: Declaration, dontResolveAlias: boolean): Symbol | undefined { + function getExportOfModule(symbol: Symbol, nameText: __String, specifier: Declaration, dontResolveAlias: boolean): Symbol | undefined { if (symbol.flags & SymbolFlags.Module) { - const exportSymbol = getExportsOfSymbol(symbol).get(name.escapedText); + const exportSymbol = getExportsOfSymbol(symbol).get(nameText); const resolved = resolveSymbol(exportSymbol, dontResolveAlias); - const exportStarDeclaration = getSymbolLinks(symbol).typeOnlyExportStarMap?.get(name.escapedText); - markSymbolOfAliasDeclarationIfTypeOnly(specifier, exportSymbol, resolved, /*overwriteEmpty*/ false, exportStarDeclaration, name.escapedText); + const exportStarDeclaration = getSymbolLinks(symbol).typeOnlyExportStarMap?.get(nameText); + markSymbolOfAliasDeclarationIfTypeOnly(specifier, exportSymbol, resolved, /*overwriteEmpty*/ false, exportStarDeclaration, nameText); return resolved; } } @@ -3887,13 +3891,19 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { const moduleSpecifier = getExternalModuleRequireArgument(node) || (node as ImportDeclaration | ExportDeclaration | JSDocImportTag).moduleSpecifier!; const moduleSymbol = resolveExternalModuleName(node, moduleSpecifier)!; // TODO: GH#18217 const name = !isPropertyAccessExpression(specifier) && specifier.propertyName || specifier.name; - if (!isIdentifier(name)) { + if (!isIdentifier(name) && name.kind !== SyntaxKind.StringLiteral) { return undefined; } - const suppressInteropError = name.escapedText === InternalSymbolName.Default && allowSyntheticDefaultImports; + const nameText = moduleExportNameTextEscaped(name); + const suppressInteropError = nameText === InternalSymbolName.Default && allowSyntheticDefaultImports; const targetSymbol = resolveESModuleSymbol(moduleSymbol, moduleSpecifier, /*dontResolveAlias*/ false, suppressInteropError); if (targetSymbol) { - if (name.escapedText) { + // Note: The empty string is a valid module export name: + // + // import { "" as foo } from "./foo"; + // export { foo as "" }; + // + if (nameText || name.kind === SyntaxKind.StringLiteral) { if (isShorthandAmbientModuleSymbol(moduleSymbol)) { return moduleSymbol; } @@ -3901,16 +3911,16 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { let symbolFromVariable: Symbol | undefined; // First check if module was specified with "export=". If so, get the member from the resolved type if (moduleSymbol && moduleSymbol.exports && moduleSymbol.exports.get(InternalSymbolName.ExportEquals)) { - symbolFromVariable = getPropertyOfType(getTypeOfSymbol(targetSymbol), name.escapedText, /*skipObjectFunctionPropertyAugment*/ true); + symbolFromVariable = getPropertyOfType(getTypeOfSymbol(targetSymbol), nameText, /*skipObjectFunctionPropertyAugment*/ true); } else { - symbolFromVariable = getPropertyOfVariable(targetSymbol, name.escapedText); + symbolFromVariable = getPropertyOfVariable(targetSymbol, nameText); } // if symbolFromVariable is export - get its final target symbolFromVariable = resolveSymbol(symbolFromVariable, dontResolveAlias); - let symbolFromModule = getExportOfModule(targetSymbol, name, specifier, dontResolveAlias); - if (symbolFromModule === undefined && name.escapedText === InternalSymbolName.Default) { + let symbolFromModule = getExportOfModule(targetSymbol, nameText, specifier, dontResolveAlias); + if (symbolFromModule === undefined && nameText === InternalSymbolName.Default) { const file = moduleSymbol.declarations?.find(isSourceFile); if (isOnlyImportableAsDefault(moduleSpecifier) || canHaveSyntheticDefault(file, moduleSymbol, dontResolveAlias, moduleSpecifier)) { symbolFromModule = resolveExternalModuleSymbol(moduleSymbol, dontResolveAlias) || resolveSymbol(moduleSymbol, dontResolveAlias); @@ -3928,10 +3938,10 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { } } - function errorNoModuleMemberSymbol(moduleSymbol: Symbol, targetSymbol: Symbol, node: Node, name: Identifier) { + function errorNoModuleMemberSymbol(moduleSymbol: Symbol, targetSymbol: Symbol, node: Node, name: ModuleExportName) { const moduleName = getFullyQualifiedName(moduleSymbol, node); const declarationName = declarationNameToString(name); - const suggestion = getSuggestedSymbolForNonexistentModule(name, targetSymbol); + const suggestion = isIdentifier(name) ? getSuggestedSymbolForNonexistentModule(name, targetSymbol) : undefined; if (suggestion !== undefined) { const suggestionName = symbolToString(suggestion); const diagnostic = error(name, Diagnostics._0_has_no_exported_member_named_1_Did_you_mean_2, moduleName, declarationName, suggestionName); @@ -3954,8 +3964,8 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { } } - function reportNonExportedMember(node: Node, name: Identifier, declarationName: string, moduleSymbol: Symbol, moduleName: string): void { - const localSymbol = tryCast(moduleSymbol.valueDeclaration, canHaveLocals)?.locals?.get(name.escapedText); + function reportNonExportedMember(node: Node, name: ModuleExportName, declarationName: string, moduleSymbol: Symbol, moduleName: string): void { + const localSymbol = tryCast(moduleSymbol.valueDeclaration, canHaveLocals)?.locals?.get(moduleExportNameTextEscaped(name)); const exports = moduleSymbol.exports; if (localSymbol) { const exportedEqualsSymbol = exports?.get(InternalSymbolName.ExportEquals); @@ -3977,7 +3987,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { } } - function reportInvalidImportEqualsExportMember(node: Node, name: Identifier, declarationName: string, moduleName: string) { + function reportInvalidImportEqualsExportMember(node: Node, name: ModuleExportName, declarationName: string, moduleName: string) { if (moduleKind >= ModuleKind.ES2015) { const message = getESModuleInterop(compilerOptions) ? Diagnostics._0_can_only_be_imported_by_using_a_default_import : Diagnostics._0_can_only_be_imported_by_turning_on_the_esModuleInterop_flag_and_using_a_default_import; @@ -3998,7 +4008,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { } function getTargetOfImportSpecifier(node: ImportSpecifier | BindingElement, dontResolveAlias: boolean): Symbol | undefined { - if (isImportSpecifier(node) && idText(node.propertyName || node.name) === InternalSymbolName.Default) { + if (isImportSpecifier(node) && moduleExportNameIsDefault(node.propertyName || node.name)) { const specifier = getModuleSpecifierForImportOrExport(node); const moduleSymbol = specifier && resolveExternalModuleName(node, specifier); if (moduleSymbol) { @@ -4031,7 +4041,8 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { } function getTargetOfExportSpecifier(node: ExportSpecifier, meaning: SymbolFlags, dontResolveAlias?: boolean) { - if (idText(node.propertyName || node.name) === InternalSymbolName.Default) { + const name = node.propertyName || node.name; + if (moduleExportNameIsDefault(name)) { const specifier = getModuleSpecifierForImportOrExport(node); const moduleSymbol = specifier && resolveExternalModuleName(node, specifier); if (moduleSymbol) { @@ -4040,7 +4051,8 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { } const resolved = node.parent.parent.moduleSpecifier ? getExternalModuleMember(node.parent.parent, node, dontResolveAlias) : - resolveEntityName(node.propertyName || node.name, meaning, /*ignoreErrors*/ false, dontResolveAlias); + name.kind === SyntaxKind.StringLiteral ? undefined : // Skip for invalid syntax like this: export { "x" } + resolveEntityName(name, meaning, /*ignoreErrors*/ false, dontResolveAlias); markSymbolOfAliasDeclarationIfTypeOnly(node, /*immediateTarget*/ undefined, resolved, /*overwriteEmpty*/ false); return resolved; } @@ -9182,10 +9194,11 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { if (index >= 0) { const exportDecl = statements[index] as ExportDeclaration & { readonly exportClause: NamedExports; }; const replacements = mapDefined(exportDecl.exportClause.elements, e => { - if (!e.propertyName) { + if (!e.propertyName && e.name.kind !== SyntaxKind.StringLiteral) { // export {name} - look thru `statements` for `name`, and if all results can take an `export` modifier, do so and filter it + const name = e.name; const indices = indicesOf(statements); - const associatedIndices = filter(indices, i => nodeHasName(statements[i], e.name)); + const associatedIndices = filter(indices, i => nodeHasName(statements[i], name)); if (length(associatedIndices) && every(associatedIndices, i => canHaveExportModifier(statements[i]))) { for (const index of associatedIndices) { statements[index] = addExportModifier(statements[index] as Extract); @@ -9884,7 +9897,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { function getSomeTargetNameFromDeclarations(declarations: Declaration[] | undefined) { return firstDefined(declarations, d => { if (isImportSpecifier(d) || isExportSpecifier(d)) { - return idText(d.propertyName || d.name); + return moduleExportNameTextUnescaped(d.propertyName || d.name); } if (isBinaryExpression(d) || isExportAssignment(d)) { const expression = isExportAssignment(d) ? d.expression : d.right; @@ -10088,8 +10101,11 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { // does not use localName because the symbol name in this case refers to the name in the exports table, // which we must exactly preserve const specifier = (node.parent.parent as ExportDeclaration).moduleSpecifier; - if (specifier && (node as ExportSpecifier).propertyName?.escapedText === InternalSymbolName.Default) { - verbatimTargetName = InternalSymbolName.Default; + if (specifier) { + const propertyName = (node as ExportSpecifier).propertyName; + if (propertyName && moduleExportNameIsDefault(propertyName)) { + verbatimTargetName = InternalSymbolName.Default; + } } // targetName is only used when the target is local, as otherwise the target is an alias that points at // another file @@ -10862,9 +10878,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { } } - function collectLinkedAliases(node: Identifier, setVisibility?: boolean): Node[] | undefined { + function collectLinkedAliases(node: ModuleExportName, setVisibility?: boolean): Node[] | undefined { let exportSymbol: Symbol | undefined; - if (node.parent && node.parent.kind === SyntaxKind.ExportAssignment) { + if (node.kind !== SyntaxKind.StringLiteral && node.parent && node.parent.kind === SyntaxKind.ExportAssignment) { exportSymbol = resolveName(node, node, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace | SymbolFlags.Alias, /*nameNotFoundMessage*/ undefined, /*isUse*/ false); } else if (node.parent.kind === SyntaxKind.ExportSpecifier) { @@ -29472,8 +29488,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { return; case SyntaxKind.ExportSpecifier: const exportDeclaration = (node as ExportSpecifier).parent.parent; - if (!(node as ExportSpecifier).isTypeOnly && !exportDeclaration.isTypeOnly && !exportDeclaration.moduleSpecifier) { - const symbol = resolveEntityName((node as ExportSpecifier).propertyName || (node as ExportSpecifier).name, SymbolFlags.Value, /*ignoreErrors*/ true, /*dontResolveAlias*/ true); + const name = (node as ExportSpecifier).propertyName || (node as ExportSpecifier).name; + if (!(node as ExportSpecifier).isTypeOnly && !exportDeclaration.isTypeOnly && !exportDeclaration.moduleSpecifier && name.kind !== SyntaxKind.StringLiteral) { + const symbol = resolveEntityName(name, SymbolFlags.Value, /*ignoreErrors*/ true, /*dontResolveAlias*/ true); if (symbol && isParameterOrMutableLocalVariable(symbol)) { symbol.lastAssignmentPos = Number.MAX_VALUE; } @@ -29856,6 +29873,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { function markExportSpecifierAliasReferenced(location: ExportSpecifier) { if (!location.parent.parent.moduleSpecifier && !location.isTypeOnly && !location.parent.parent.isTypeOnly) { const exportedName = location.propertyName || location.name; + if (exportedName.kind === SyntaxKind.StringLiteral) { + return; // Skip for invalid syntax like this: export { "x" } + } const symbol = resolveName(exportedName, exportedName.escapedText, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace | SymbolFlags.Alias, /*nameNotFoundMessage*/ undefined, /*isUse*/ true); if (symbol && (symbol === undefinedSymbol || symbol === globalThisSymbol || symbol.declarations && isGlobalSourceFile(getDeclarationContainer(symbol.declarations[0])))) { // Do nothing, non-local symbol @@ -29864,7 +29884,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { const target = symbol && (symbol.flags & SymbolFlags.Alias ? resolveAlias(symbol) : symbol); if (!target || getSymbolFlags(target) & SymbolFlags.Value) { markExportAsReferenced(location); // marks export as used - markIdentifierAliasReferenced(location.propertyName || location.name); // marks target of export as used + markIdentifierAliasReferenced(exportedName); // marks target of export as used } } return; @@ -46833,6 +46853,18 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { return true; } + function checkModuleExportName(name: ModuleExportName | undefined, allowStringLiteral = true) { + if (name === undefined || name.kind !== SyntaxKind.StringLiteral) { + return; + } + if (!allowStringLiteral) { + grammarErrorOnNode(name, Diagnostics.Identifier_expected); + } + else if (moduleKind === ModuleKind.ES2015 || moduleKind === ModuleKind.ES2020) { + grammarErrorOnNode(name, Diagnostics.String_literal_import_and_export_names_are_not_supported_when_the_module_flag_is_set_to_es2015_or_es2020); + } + } + function checkAliasSymbol(node: AliasDeclarationNode) { let symbol = getSymbolOfDeclaration(node); const target = resolveAlias(symbol); @@ -46855,7 +46887,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { Debug.assert(node.kind !== SyntaxKind.NamespaceExport); if (node.kind === SyntaxKind.ExportSpecifier) { const diag = error(errorNode, Diagnostics.Types_cannot_appear_in_export_declarations_in_JavaScript_files); - const alreadyExportedSymbol = getSourceFileOfNode(node).symbol?.exports?.get((node.propertyName || node.name).escapedText); + const alreadyExportedSymbol = getSourceFileOfNode(node).symbol?.exports?.get(moduleExportNameTextEscaped(node.propertyName || node.name)); if (alreadyExportedSymbol === target) { const exportingDeclaration = alreadyExportedSymbol.declarations?.find(isJSDocNode); if (exportingDeclaration) { @@ -46928,7 +46960,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { : isType ? Diagnostics._0_is_a_type_and_must_be_imported_using_a_type_only_import_when_verbatimModuleSyntax_is_enabled : Diagnostics._0_resolves_to_a_type_only_declaration_and_must_be_imported_using_a_type_only_import_when_verbatimModuleSyntax_is_enabled; - const name = idText(node.kind === SyntaxKind.ImportSpecifier ? node.propertyName || node.name : node.name); + const name = moduleExportNameTextUnescaped(node.kind === SyntaxKind.ImportSpecifier ? node.propertyName || node.name : node.name); addTypeOnlyDeclarationRelatedInfo( error(node, message, name), isType ? undefined : typeOnlyAlias, @@ -46945,7 +46977,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { // The exception is that `import type { A } from './a'; export { A }` is allowed // because single-file analysis can determine that the export should be dropped. if (compilerOptions.verbatimModuleSyntax || getSourceFileOfNode(typeOnlyAlias) !== getSourceFileOfNode(node)) { - const name = idText(node.propertyName || node.name); + const name = moduleExportNameTextUnescaped(node.propertyName || node.name); const diagnostic = isType ? error(node, Diagnostics.Re_exporting_a_type_when_0_is_enabled_requires_using_export_type, isolatedModulesLikeFlagName) : error(node, Diagnostics._0_resolves_to_a_type_only_declaration_and_must_be_re_exported_using_a_type_only_re_export_when_1_is_enabled, name, isolatedModulesLikeFlagName); @@ -47020,13 +47052,15 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { function checkImportBinding(node: ImportEqualsDeclaration | ImportClause | NamespaceImport | ImportSpecifier) { checkCollisionsForDeclarationName(node, node.name); checkAliasSymbol(node); - if ( - node.kind === SyntaxKind.ImportSpecifier && - idText(node.propertyName || node.name) === "default" && - getESModuleInterop(compilerOptions) && - host.getEmitModuleFormatOfFile(getSourceFileOfNode(node)) < ModuleKind.System - ) { - checkExternalEmitHelpers(node, ExternalEmitHelpers.ImportDefault); + if (node.kind === SyntaxKind.ImportSpecifier) { + checkModuleExportName(node.propertyName); + if ( + moduleExportNameIsDefault(node.propertyName || node.name) && + getESModuleInterop(compilerOptions) && + host.getEmitModuleFormatOfFile(getSourceFileOfNode(node)) < ModuleKind.System + ) { + checkExternalEmitHelpers(node, ExternalEmitHelpers.ImportDefault); + } } } @@ -47176,6 +47210,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { } else if (node.exportClause) { checkAliasSymbol(node.exportClause); + checkModuleExportName(node.exportClause.name); } if (host.getEmitModuleFormatOfFile(getSourceFileOfNode(node)) < ModuleKind.System) { if (node.exportClause) { @@ -47213,11 +47248,17 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { function checkExportSpecifier(node: ExportSpecifier) { checkAliasSymbol(node); + const hasModuleSpecifier = node.parent.parent.moduleSpecifier !== undefined; + checkModuleExportName(node.propertyName, hasModuleSpecifier); + checkModuleExportName(node.name); if (getEmitDeclarations(compilerOptions)) { collectLinkedAliases(node.propertyName || node.name, /*setVisibility*/ true); } - if (!node.parent.parent.moduleSpecifier) { + if (!hasModuleSpecifier) { const exportedName = node.propertyName || node.name; + if (exportedName.kind === SyntaxKind.StringLiteral) { + return; // Skip for invalid syntax like this: export { "x" } + } // find immediate value referenced by exported name (SymbolFlags.Alias is set so we don't chase down aliases) const symbol = resolveName(exportedName, exportedName.escapedText, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace | SymbolFlags.Alias, /*nameNotFoundMessage*/ undefined, /*isUse*/ true); if (symbol && (symbol === undefinedSymbol || symbol === globalThisSymbol || symbol.declarations && isGlobalSourceFile(getDeclarationContainer(symbol.declarations[0])))) { @@ -47231,7 +47272,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { if ( getESModuleInterop(compilerOptions) && host.getEmitModuleFormatOfFile(getSourceFileOfNode(node)) < ModuleKind.System && - idText(node.propertyName || node.name) === "default" + moduleExportNameIsDefault(node.propertyName || node.name) ) { checkExternalEmitHelpers(node, ExternalEmitHelpers.ImportDefault); } @@ -48610,9 +48651,11 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { /** Returns the target of an export specifier without following aliases */ function getExportSpecifierLocalTargetSymbol(node: ExportSpecifier | Identifier): Symbol | undefined { if (isExportSpecifier(node)) { + const name = node.propertyName || node.name; return node.parent.parent.moduleSpecifier ? getExternalModuleMember(node.parent.parent, node) : - resolveEntityName(node.propertyName || node.name, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace | SymbolFlags.Alias); + name.kind === SyntaxKind.StringLiteral ? undefined : // Skip for invalid syntax like this: export { "x" } + resolveEntityName(name, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace | SymbolFlags.Alias); } else { return resolveEntityName(node, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace | SymbolFlags.Alias); @@ -52003,7 +52046,7 @@ function isDeclarationNameOrImportPropertyName(name: Node): boolean { switch (name.parent.kind) { case SyntaxKind.ImportSpecifier: case SyntaxKind.ExportSpecifier: - return isIdentifier(name); + return isIdentifier(name) || name.kind === SyntaxKind.StringLiteral; default: return isDeclarationName(name); } diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index e74033719b5b8..92600da4d3861 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -8325,5 +8325,9 @@ "Enum member following a non-literal numeric member must have an initializer when 'isolatedModules' is enabled.": { "category": "Error", "code": 18056 + }, + "String literal import and export names are not supported when the '--module' flag is set to 'es2015' or 'es2020'.": { + "category": "Error", + "code": 18057 } } diff --git a/src/compiler/factory/nodeFactory.ts b/src/compiler/factory/nodeFactory.ts index 9fcd2a4acf7c1..024eaa5c7f687 100644 --- a/src/compiler/factory/nodeFactory.ts +++ b/src/compiler/factory/nodeFactory.ts @@ -309,6 +309,7 @@ import { ModuleBlock, ModuleBody, ModuleDeclaration, + ModuleExportName, ModuleName, ModuleReference, Mutable, @@ -4842,7 +4843,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode } // @api - function createNamespaceExport(name: Identifier): NamespaceExport { + function createNamespaceExport(name: ModuleExportName): NamespaceExport { const node = createBaseDeclaration(SyntaxKind.NamespaceExport); node.name = name; node.transformFlags |= propagateChildFlags(node.name) | @@ -4852,7 +4853,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode } // @api - function updateNamespaceExport(node: NamespaceExport, name: Identifier) { + function updateNamespaceExport(node: NamespaceExport, name: ModuleExportName) { return node.name !== name ? update(createNamespaceExport(name), node) : node; @@ -4875,7 +4876,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode } // @api - function createImportSpecifier(isTypeOnly: boolean, propertyName: Identifier | undefined, name: Identifier) { + function createImportSpecifier(isTypeOnly: boolean, propertyName: ModuleExportName | undefined, name: Identifier) { const node = createBaseDeclaration(SyntaxKind.ImportSpecifier); node.isTypeOnly = isTypeOnly; node.propertyName = propertyName; @@ -4887,7 +4888,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode } // @api - function updateImportSpecifier(node: ImportSpecifier, isTypeOnly: boolean, propertyName: Identifier | undefined, name: Identifier) { + function updateImportSpecifier(node: ImportSpecifier, isTypeOnly: boolean, propertyName: ModuleExportName | undefined, name: Identifier) { return node.isTypeOnly !== isTypeOnly || node.propertyName !== propertyName || node.name !== name @@ -4994,7 +4995,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode } // @api - function createExportSpecifier(isTypeOnly: boolean, propertyName: string | Identifier | undefined, name: string | Identifier) { + function createExportSpecifier(isTypeOnly: boolean, propertyName: string | ModuleExportName | undefined, name: string | ModuleExportName) { const node = createBaseNode(SyntaxKind.ExportSpecifier); node.isTypeOnly = isTypeOnly; node.propertyName = asName(propertyName); @@ -5008,7 +5009,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode } // @api - function updateExportSpecifier(node: ExportSpecifier, isTypeOnly: boolean, propertyName: Identifier | undefined, name: Identifier) { + function updateExportSpecifier(node: ExportSpecifier, isTypeOnly: boolean, propertyName: ModuleExportName | undefined, name: ModuleExportName) { return node.isTypeOnly !== isTypeOnly || node.propertyName !== propertyName || node.name !== name diff --git a/src/compiler/factory/nodeTests.ts b/src/compiler/factory/nodeTests.ts index cd31b63f81843..8aa4bb02e83d2 100644 --- a/src/compiler/factory/nodeTests.ts +++ b/src/compiler/factory/nodeTests.ts @@ -146,6 +146,7 @@ import { MissingDeclaration, ModuleBlock, ModuleDeclaration, + ModuleExportName, NamedExports, NamedImports, NamedTupleMember, @@ -898,6 +899,10 @@ export function isExportSpecifier(node: Node): node is ExportSpecifier { return node.kind === SyntaxKind.ExportSpecifier; } +export function isModuleExportName(node: Node): node is ModuleExportName { + return node.kind === SyntaxKind.Identifier || node.kind === SyntaxKind.StringLiteral; +} + export function isMissingDeclaration(node: Node): node is MissingDeclaration { return node.kind === SyntaxKind.MissingDeclaration; } diff --git a/src/compiler/factory/utilities.ts b/src/compiler/factory/utilities.ts index 502ffd17db5e0..a48270b6d47f5 100644 --- a/src/compiler/factory/utilities.ts +++ b/src/compiler/factory/utilities.ts @@ -802,6 +802,9 @@ export function getLocalNameForExternalImport(factory: NodeFactory, node: Import const namespaceDeclaration = getNamespaceDeclarationNode(node); if (namespaceDeclaration && !isDefaultImport(node) && !isExportNamespaceAsDefaultDeclaration(node)) { const name = namespaceDeclaration.name; + if (name.kind === SyntaxKind.StringLiteral) { + return factory.getGeneratedNameForNode(node); + } return isGeneratedIdentifier(name) ? name : factory.createIdentifier(getSourceTextOfNodeFromSourceFile(sourceFile, name) || idText(name)); } if (node.kind === SyntaxKind.ImportDeclaration && node.importClause) { diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 56b958bcf3b74..3cb942dfad62e 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -256,6 +256,7 @@ import { modifiersToFlags, ModuleBlock, ModuleDeclaration, + ModuleExportName, ModuleKind, Mutable, NamedExportBindings, @@ -2906,6 +2907,9 @@ namespace Parser { if (token() === SyntaxKind.FromKeyword && lookAhead(nextTokenIsStringLiteral)) { return false; } + if (token() === SyntaxKind.StringLiteral) { + return true; // For "arbitrary module namespace identifiers" + } return tokenIsIdentifierOrKeyword(token()); case ParsingContext.JsxAttributes: return tokenIsIdentifierOrKeyword(token()) || token() === SyntaxKind.OpenBraceToken; @@ -8504,6 +8508,14 @@ namespace Parser { return finishNode(factory.createNamespaceImport(name), pos); } + function canParseModuleExportName(): boolean { + return tokenIsIdentifierOrKeyword(token()) || token() === SyntaxKind.StringLiteral; + } + + function parseModuleExportName(parseName: () => Identifier): ModuleExportName { + return token() === SyntaxKind.StringLiteral ? parseLiteralNode() as StringLiteral : parseName(); + } + function parseNamedImportsOrExports(kind: SyntaxKind.NamedImports): NamedImports; function parseNamedImportsOrExports(kind: SyntaxKind.NamedExports): NamedExports; function parseNamedImportsOrExports(kind: SyntaxKind): NamedImportsOrExports { @@ -8536,18 +8548,18 @@ namespace Parser { const pos = getNodePos(); // ImportSpecifier: // BindingIdentifier - // IdentifierName as BindingIdentifier + // ModuleExportName as BindingIdentifier // ExportSpecifier: - // IdentifierName - // IdentifierName as IdentifierName + // ModuleExportName + // ModuleExportName as ModuleExportName let checkIdentifierIsKeyword = isKeyword(token()) && !isIdentifier(); let checkIdentifierStart = scanner.getTokenStart(); let checkIdentifierEnd = scanner.getTokenEnd(); let isTypeOnly = false; - let propertyName: Identifier | undefined; + let propertyName: ModuleExportName | undefined; let canParseAsKeyword = true; - let name = parseIdentifierName(); - if (name.escapedText === "type") { + let name = parseModuleExportName(parseIdentifierName); + if (name.kind === SyntaxKind.Identifier && name.escapedText === "type") { // If the first token of an import specifier is 'type', there are a lot of possibilities, // especially if we see 'as' afterwards: // @@ -8561,11 +8573,12 @@ namespace Parser { if (token() === SyntaxKind.AsKeyword) { // { type as as ...? } const secondAs = parseIdentifierName(); - if (tokenIsIdentifierOrKeyword(token())) { + if (canParseModuleExportName()) { // { type as as something } + // { type as as "something" } isTypeOnly = true; propertyName = firstAs; - name = parseNameWithKeywordCheck(); + name = parseModuleExportName(parseNameWithKeywordCheck); canParseAsKeyword = false; } else { @@ -8575,11 +8588,12 @@ namespace Parser { canParseAsKeyword = false; } } - else if (tokenIsIdentifierOrKeyword(token())) { + else if (canParseModuleExportName()) { // { type as something } + // { type as "something" } propertyName = name; canParseAsKeyword = false; - name = parseNameWithKeywordCheck(); + name = parseModuleExportName(parseNameWithKeywordCheck); } else { // { type as } @@ -8587,23 +8601,31 @@ namespace Parser { name = firstAs; } } - else if (tokenIsIdentifierOrKeyword(token())) { + else if (canParseModuleExportName()) { // { type something ...? } + // { type "something" ...? } isTypeOnly = true; - name = parseNameWithKeywordCheck(); + name = parseModuleExportName(parseNameWithKeywordCheck); } } if (canParseAsKeyword && token() === SyntaxKind.AsKeyword) { propertyName = name; parseExpected(SyntaxKind.AsKeyword); - name = parseNameWithKeywordCheck(); + name = parseModuleExportName(parseNameWithKeywordCheck); } - if (kind === SyntaxKind.ImportSpecifier && checkIdentifierIsKeyword) { - parseErrorAt(checkIdentifierStart, checkIdentifierEnd, Diagnostics.Identifier_expected); + if (kind === SyntaxKind.ImportSpecifier) { + if (name.kind !== SyntaxKind.Identifier) { + // ImportSpecifier casts "name" to Identifier below, so make sure it's an identifier + parseErrorAt(skipTrivia(sourceText, name.pos), name.end, Diagnostics.Identifier_expected); + name = setTextRangePosEnd(createMissingNode(SyntaxKind.Identifier, /*reportAtCurrentPosition*/ false), name.pos, name.pos); + } + else if (checkIdentifierIsKeyword) { + parseErrorAt(checkIdentifierStart, checkIdentifierEnd, Diagnostics.Identifier_expected); + } } const node = kind === SyntaxKind.ImportSpecifier - ? factory.createImportSpecifier(isTypeOnly, propertyName, name) + ? factory.createImportSpecifier(isTypeOnly, propertyName, name as Identifier) : factory.createExportSpecifier(isTypeOnly, propertyName, name); return finishNode(node, pos); @@ -8616,7 +8638,7 @@ namespace Parser { } function parseNamespaceExport(pos: number): NamespaceExport { - return finishNode(factory.createNamespaceExport(parseIdentifierName()), pos); + return finishNode(factory.createNamespaceExport(parseModuleExportName(parseIdentifierName)), pos); } function parseExportDeclaration(pos: number, hasJSDoc: boolean, modifiers: NodeArray | undefined): ExportDeclaration { diff --git a/src/compiler/transformers/module/module.ts b/src/compiler/transformers/module/module.ts index 92b214276e533..dc30bca2bb8d2 100644 --- a/src/compiler/transformers/module/module.ts +++ b/src/compiler/transformers/module/module.ts @@ -121,7 +121,10 @@ import { mapDefined, Modifier, ModifierFlags, + ModuleExportName, + moduleExportNameIsDefault, ModuleKind, + NamespaceImport, Node, NodeArray, NodeFlags, @@ -276,7 +279,10 @@ export function transformModule(context: TransformationContext): (x: SourceFile factory.createExpressionStatement( reduceLeft( currentModuleInfo.exportedNames.slice(i, i + chunkSize), - (prev, nextId) => factory.createAssignment(factory.createPropertyAccessExpression(factory.createIdentifier("exports"), factory.createIdentifier(idText(nextId))), prev), + (prev, nextId) => + nextId.kind === SyntaxKind.StringLiteral + ? factory.createAssignment(factory.createElementAccessExpression(factory.createIdentifier("exports"), factory.createStringLiteral(nextId.text)), prev) + : factory.createAssignment(factory.createPropertyAccessExpression(factory.createIdentifier("exports"), factory.createIdentifier(idText(nextId))), prev), factory.createVoidZero() as Expression, ), ), @@ -609,7 +615,13 @@ export function transformModule(context: TransformationContext): (x: SourceFile append(statements, createUnderscoreUnderscoreESModule()); } if (some(currentModuleInfo.exportedNames)) { - append(statements, factory.createExpressionStatement(reduceLeft(currentModuleInfo.exportedNames, (prev, nextId) => factory.createAssignment(factory.createPropertyAccessExpression(factory.createIdentifier("exports"), factory.createIdentifier(idText(nextId))), prev), factory.createVoidZero() as Expression))); + append( + statements, + factory.createExpressionStatement(reduceLeft(currentModuleInfo.exportedNames, (prev, nextId) => + nextId.kind === SyntaxKind.StringLiteral + ? factory.createAssignment(factory.createElementAccessExpression(factory.createIdentifier("exports"), factory.createStringLiteral(nextId.text)), prev) + : factory.createAssignment(factory.createPropertyAccessExpression(factory.createIdentifier("exports"), factory.createIdentifier(idText(nextId))), prev), factory.createVoidZero() as Expression)), + ); } for (const f of currentModuleInfo.exportedFunctions) { appendExportsOfHoistedDeclaration(statements, f); @@ -1385,7 +1397,7 @@ export function transformModule(context: TransformationContext): (x: SourceFile */ function visitTopLevelImportDeclaration(node: ImportDeclaration): VisitResult { let statements: Statement[] | undefined; - const namespaceDeclaration = getNamespaceDeclarationNode(node); + const namespaceDeclaration = getNamespaceDeclarationNode(node) as NamespaceImport | undefined; if (moduleKind !== ModuleKind.AMD) { if (!node.importClause) { // import "mod"; @@ -1607,18 +1619,24 @@ export function transformModule(context: TransformationContext): (x: SourceFile ); } for (const specifier of node.exportClause.elements) { + const specifierName = specifier.propertyName || specifier.name; const exportNeedsImportDefault = !!getESModuleInterop(compilerOptions) && !(getInternalEmitFlags(node) & InternalEmitFlags.NeverApplyImportHelper) && - idText(specifier.propertyName || specifier.name) === "default"; - const exportedValue = factory.createPropertyAccessExpression( - exportNeedsImportDefault ? emitHelpers().createImportDefaultHelper(generatedName) : generatedName, - specifier.propertyName || specifier.name, - ); + moduleExportNameIsDefault(specifierName); + const target = exportNeedsImportDefault ? emitHelpers().createImportDefaultHelper(generatedName) : generatedName; + const exportedValue = specifierName.kind === SyntaxKind.StringLiteral + ? factory.createElementAccessExpression(target, specifierName) + : factory.createPropertyAccessExpression(target, specifierName); statements.push( setOriginalNode( setTextRange( factory.createExpressionStatement( - createExportExpression(factory.getExportName(specifier), exportedValue, /*location*/ undefined, /*liveBinding*/ true), + createExportExpression( + specifier.name.kind === SyntaxKind.StringLiteral ? factory.cloneNode(specifier.name) : factory.getExportName(specifier), + exportedValue, + /*location*/ undefined, + /*liveBinding*/ true, + ), ), specifier, ), @@ -1644,6 +1662,7 @@ export function transformModule(context: TransformationContext): (x: SourceFile moduleKind !== ModuleKind.AMD ? createRequireCall(node) : isExportNamespaceAsDefaultDeclaration(node) ? generatedName : + node.exportClause.name.kind === SyntaxKind.StringLiteral ? generatedName : factory.createIdentifier(idText(node.exportClause.name)), ), ), @@ -2070,11 +2089,14 @@ export function transformModule(context: TransformationContext): (x: SourceFile * @param location The location to use for source maps and comments for the export. * @param allowComments Whether to allow comments on the export. */ - function appendExportStatement(statements: Statement[] | undefined, seen: IdentifierNameMap, exportName: Identifier, expression: Expression, location?: TextRange, allowComments?: boolean, liveBinding?: boolean): Statement[] | undefined { - if (!seen.has(exportName)) { + function appendExportStatement(statements: Statement[] | undefined, seen: IdentifierNameMap, exportName: ModuleExportName, expression: Expression, location?: TextRange, allowComments?: boolean, liveBinding?: boolean): Statement[] | undefined { + if (exportName.kind !== SyntaxKind.StringLiteral) { + if (seen.has(exportName)) { + return statements; + } seen.set(exportName, true); - statements = append(statements, createExportStatement(exportName, expression, location, allowComments, liveBinding)); } + statements = append(statements, createExportStatement(exportName, expression, location, allowComments, liveBinding)); return statements; } @@ -2104,7 +2126,7 @@ export function transformModule(context: TransformationContext): (x: SourceFile * @param location The location to use for source maps and comments for the export. * @param allowComments An optional value indicating whether to emit comments for the statement. */ - function createExportStatement(name: Identifier, value: Expression, location?: TextRange, allowComments?: boolean, liveBinding?: boolean) { + function createExportStatement(name: ModuleExportName, value: Expression, location?: TextRange, allowComments?: boolean, liveBinding?: boolean) { const statement = setTextRange(factory.createExpressionStatement(createExportExpression(name, value, /*location*/ undefined, liveBinding)), location); startOnNewLine(statement); if (!allowComments) { @@ -2121,7 +2143,7 @@ export function transformModule(context: TransformationContext): (x: SourceFile * @param value The exported value. * @param location The location to use for source maps and comments for the export. */ - function createExportExpression(name: Identifier, value: Expression, location?: TextRange, liveBinding?: boolean) { + function createExportExpression(name: ModuleExportName, value: Expression, location?: TextRange, liveBinding?: boolean) { return setTextRange( liveBinding ? factory.createCallExpression( factory.createPropertyAccessExpression( @@ -2149,10 +2171,15 @@ export function transformModule(context: TransformationContext): (x: SourceFile ]), ], ) : factory.createAssignment( - factory.createPropertyAccessExpression( - factory.createIdentifier("exports"), - factory.cloneNode(name), - ), + name.kind === SyntaxKind.StringLiteral + ? factory.createElementAccessExpression( + factory.createIdentifier("exports"), + factory.cloneNode(name), + ) + : factory.createPropertyAccessExpression( + factory.createIdentifier("exports"), + factory.cloneNode(name), + ), value, ), location, @@ -2338,11 +2365,11 @@ export function transformModule(context: TransformationContext): (x: SourceFile } else if (isImportSpecifier(importDeclaration)) { const name = importDeclaration.propertyName || importDeclaration.name; + const target = factory.getGeneratedNameForNode(importDeclaration.parent?.parent?.parent || importDeclaration); return setTextRange( - factory.createPropertyAccessExpression( - factory.getGeneratedNameForNode(importDeclaration.parent?.parent?.parent || importDeclaration), - factory.cloneNode(name), - ), + name.kind === SyntaxKind.StringLiteral + ? factory.createElementAccessExpression(target, factory.cloneNode(name)) + : factory.createPropertyAccessExpression(target, factory.cloneNode(name)), /*location*/ node, ); } @@ -2391,7 +2418,7 @@ export function transformModule(context: TransformationContext): (x: SourceFile * * @param name The name. */ - function getExports(name: Identifier): Identifier[] | undefined { + function getExports(name: Identifier): ModuleExportName[] | undefined { if (!isGeneratedIdentifier(name)) { const importDeclaration = resolver.getReferencedImportDeclaration(name); if (importDeclaration) { @@ -2419,7 +2446,7 @@ export function transformModule(context: TransformationContext): (x: SourceFile else if (isFileLevelReservedGeneratedIdentifier(name)) { const exportSpecifiers = currentModuleInfo?.exportSpecifiers.get(name); if (exportSpecifiers) { - const exportedNames: Identifier[] = []; + const exportedNames: ModuleExportName[] = []; for (const exportSpecifier of exportSpecifiers) { exportedNames.push(exportSpecifier.name); } diff --git a/src/compiler/transformers/module/system.ts b/src/compiler/transformers/module/system.ts index f03ad63a1c0ca..442af8707fbd1 100644 --- a/src/compiler/transformers/module/system.ts +++ b/src/compiler/transformers/module/system.ts @@ -92,6 +92,9 @@ import { map, MetaProperty, ModifierFlags, + ModuleExportName, + moduleExportNameIsDefault, + moduleExportNameTextUnescaped, moveEmitHelpers, Node, NodeFlags, @@ -455,7 +458,7 @@ export function transformSystemModule(context: TransformationContext): (x: Sourc const exportedNames: ObjectLiteralElementLike[] = []; if (moduleInfo.exportedNames) { for (const exportedLocalName of moduleInfo.exportedNames) { - if (exportedLocalName.escapedText === "default") { + if (moduleExportNameIsDefault(exportedLocalName)) { continue; } @@ -644,10 +647,10 @@ export function transformSystemModule(context: TransformationContext): (x: Sourc for (const e of entry.exportClause.elements) { properties.push( factory.createPropertyAssignment( - factory.createStringLiteral(idText(e.name)), + factory.createStringLiteral(moduleExportNameTextUnescaped(e.name)), factory.createElementAccessExpression( parameterName, - factory.createStringLiteral(idText(e.propertyName || e.name)), + factory.createStringLiteral(moduleExportNameTextUnescaped(e.propertyName || e.name)), ), ), ); @@ -670,7 +673,7 @@ export function transformSystemModule(context: TransformationContext): (x: Sourc exportFunction, /*typeArguments*/ undefined, [ - factory.createStringLiteral(idText(entry.exportClause.name)), + factory.createStringLiteral(moduleExportNameTextUnescaped(entry.exportClause.name)), parameterName, ], ), @@ -1163,7 +1166,7 @@ export function transformSystemModule(context: TransformationContext): (x: Sourc const exportSpecifiers = moduleInfo.exportSpecifiers.get(name); if (exportSpecifiers) { for (const exportSpecifier of exportSpecifiers) { - if (exportSpecifier.name.escapedText !== excludeName) { + if (moduleExportNameTextUnescaped(exportSpecifier.name) !== excludeName) { statements = appendExportStatement(statements, exportSpecifier.name, name); } } @@ -1851,13 +1854,14 @@ export function transformSystemModule(context: TransformationContext): (x: Sourc ); } else if (isImportSpecifier(importDeclaration)) { + const importedName = importDeclaration.propertyName || importDeclaration.name; + const target = factory.getGeneratedNameForNode(importDeclaration.parent?.parent?.parent || importDeclaration); return setTextRange( factory.createPropertyAssignment( factory.cloneNode(name), - factory.createPropertyAccessExpression( - factory.getGeneratedNameForNode(importDeclaration.parent?.parent?.parent || importDeclaration), - factory.cloneNode(importDeclaration.propertyName || importDeclaration.name), - ), + importedName.kind === SyntaxKind.StringLiteral + ? factory.createElementAccessExpression(target, factory.cloneNode(importedName)) + : factory.createPropertyAccessExpression(target, factory.cloneNode(importedName)), ), /*location*/ node, ); @@ -1919,11 +1923,12 @@ export function transformSystemModule(context: TransformationContext): (x: Sourc ); } else if (isImportSpecifier(importDeclaration)) { + const importedName = importDeclaration.propertyName || importDeclaration.name; + const target = factory.getGeneratedNameForNode(importDeclaration.parent?.parent?.parent || importDeclaration); return setTextRange( - factory.createPropertyAccessExpression( - factory.getGeneratedNameForNode(importDeclaration.parent?.parent?.parent || importDeclaration), - factory.cloneNode(importDeclaration.propertyName || importDeclaration.name), - ), + importedName.kind === SyntaxKind.StringLiteral + ? factory.createElementAccessExpression(target, factory.cloneNode(importedName)) + : factory.createPropertyAccessExpression(target, factory.cloneNode(importedName)), /*location*/ node, ); } @@ -1992,7 +1997,7 @@ export function transformSystemModule(context: TransformationContext): (x: Sourc else if (isGeneratedIdentifier(name) && isFileLevelReservedGeneratedIdentifier(name)) { const exportSpecifiers = moduleInfo?.exportSpecifiers.get(name); if (exportSpecifiers) { - const exportedNames: Identifier[] = []; + const exportedNames: ModuleExportName[] = []; for (const exportSpecifier of exportSpecifiers) { exportedNames.push(exportSpecifier.name); } diff --git a/src/compiler/transformers/utilities.ts b/src/compiler/transformers/utilities.ts index 8f5f2b257a004..33def985547b4 100644 --- a/src/compiler/transformers/utilities.ts +++ b/src/compiler/transformers/utilities.ts @@ -42,7 +42,6 @@ import { ImportEqualsDeclaration, ImportSpecifier, InitializedPropertyDeclaration, - InternalSymbolName, isAutoAccessorPropertyDeclaration, isBindingPattern, isClassStaticBlockDeclaration, @@ -68,6 +67,9 @@ import { map, MethodDeclaration, ModifierFlags, + ModuleExportName, + moduleExportNameIsDefault, + moduleExportNameTextUnescaped, NamedExportBindings, NamedImportBindings, NamespaceExport, @@ -104,7 +106,7 @@ export interface ExternalModuleInfo { externalHelpersImportDeclaration: ImportDeclaration | undefined; // import of external helpers exportSpecifiers: IdentifierNameMap; // file-local export specifiers by name (no reexports) exportedBindings: Identifier[][]; // exported names of local declarations - exportedNames: Identifier[] | undefined; // all exported names in the module, both local and reexported, excluding the names of locally exported function declarations + exportedNames: ModuleExportName[] | undefined; // all exported names in the module, both local and reexported, excluding the names of locally exported function declarations exportedFunctions: Set; // all of the top-level exported function declarations exportEquals: ExportAssignment | undefined; // an export= declaration if one was present hasExportStarsToExportValues: boolean; // whether this module contains export* @@ -117,9 +119,7 @@ function containsDefaultReference(node: NamedImportBindings | NamedExportBinding } function isNamedDefaultReference(e: ImportSpecifier | ExportSpecifier): boolean { - return e.propertyName !== undefined ? - e.propertyName.escapedText === InternalSymbolName.Default : - e.name.escapedText === InternalSymbolName.Default; + return moduleExportNameIsDefault(e.propertyName || e.name); } /** @internal */ @@ -175,7 +175,7 @@ export function collectExternalModuleInfo(context: TransformationContext, source const exportedBindings: Identifier[][] = []; const uniqueExports = new Map(); const exportedFunctions = new Set(); - let exportedNames: Identifier[] | undefined; + let exportedNames: ModuleExportName[] | undefined; let hasExportDefault = false; let exportEquals: ExportAssignment | undefined; let hasExportStarsToExportValues = false; @@ -223,9 +223,10 @@ export function collectExternalModuleInfo(context: TransformationContext, source } else { const name = ((node as ExportDeclaration).exportClause as NamespaceExport).name; - if (!uniqueExports.get(idText(name))) { + const nameText = moduleExportNameTextUnescaped(name); + if (!uniqueExports.get(nameText)) { multiMapSparseArrayAdd(exportedBindings, getOriginalNodeId(node), name); - uniqueExports.set(idText(name), true); + uniqueExports.set(nameText, true); exportedNames = append(exportedNames, name); } // we use the same helpers for `export * as ns` as we do for `import * as ns` @@ -292,31 +293,34 @@ export function collectExternalModuleInfo(context: TransformationContext, source function addExportedNamesForExportDeclaration(node: ExportDeclaration) { for (const specifier of cast(node.exportClause, isNamedExports).elements) { - if (!uniqueExports.get(idText(specifier.name))) { + const specifierNameText = moduleExportNameTextUnescaped(specifier.name); + if (!uniqueExports.get(specifierNameText)) { const name = specifier.propertyName || specifier.name; - if (!node.moduleSpecifier) { - exportSpecifiers.add(name, specifier); - } + if (name.kind !== SyntaxKind.StringLiteral) { + if (!node.moduleSpecifier) { + exportSpecifiers.add(name, specifier); + } - const decl = resolver.getReferencedImportDeclaration(name) - || resolver.getReferencedValueDeclaration(name); + const decl = resolver.getReferencedImportDeclaration(name) + || resolver.getReferencedValueDeclaration(name); - if (decl) { - if (decl.kind === SyntaxKind.FunctionDeclaration) { - addExportedFunctionDeclaration(decl as FunctionDeclaration, specifier.name, specifier.name.escapedText === InternalSymbolName.Default); - continue; - } + if (decl) { + if (decl.kind === SyntaxKind.FunctionDeclaration) { + addExportedFunctionDeclaration(decl as FunctionDeclaration, specifier.name, moduleExportNameIsDefault(specifier.name)); + continue; + } - multiMapSparseArrayAdd(exportedBindings, getOriginalNodeId(decl), specifier.name); + multiMapSparseArrayAdd(exportedBindings, getOriginalNodeId(decl), specifier.name); + } } - uniqueExports.set(idText(specifier.name), true); + uniqueExports.set(specifierNameText, true); exportedNames = append(exportedNames, specifier.name); } } } - function addExportedFunctionDeclaration(node: FunctionDeclaration, name: Identifier | undefined, isDefault: boolean) { + function addExportedFunctionDeclaration(node: FunctionDeclaration, name: ModuleExportName | undefined, isDefault: boolean) { exportedFunctions.add(node); if (isDefault) { // export default function() { } @@ -330,15 +334,16 @@ export function collectExternalModuleInfo(context: TransformationContext, source // export function x() { } // function x() { } + export { x } name ??= node.name!; - if (!uniqueExports.get(idText(name))) { + const nameText = moduleExportNameTextUnescaped(name); + if (!uniqueExports.get(nameText)) { multiMapSparseArrayAdd(exportedBindings, getOriginalNodeId(node), name); - uniqueExports.set(idText(name), true); + uniqueExports.set(nameText, true); } } } } -function collectExportedVariableInfo(decl: VariableDeclaration | BindingElement, uniqueExports: Map, exportedNames: Identifier[] | undefined, exportedBindings: Identifier[][]) { +function collectExportedVariableInfo(decl: VariableDeclaration | BindingElement, uniqueExports: Map, exportedNames: ModuleExportName[] | undefined, exportedBindings: Identifier[][]) { if (isBindingPattern(decl.name)) { for (const element of decl.name.elements) { if (!isOmittedExpression(element)) { diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 7388c9c94e235..d15d4bca93c58 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -3717,7 +3717,7 @@ export interface NamespaceImport extends NamedDeclaration { export interface NamespaceExport extends NamedDeclaration { readonly kind: SyntaxKind.NamespaceExport; readonly parent: ExportDeclaration; - readonly name: Identifier; + readonly name: ModuleExportName; } export interface NamespaceExportDeclaration extends DeclarationStatement, JSDocContainer { @@ -3758,7 +3758,7 @@ export type NamedImportsOrExports = NamedImports | NamedExports; export interface ImportSpecifier extends NamedDeclaration { readonly kind: SyntaxKind.ImportSpecifier; readonly parent: NamedImports; - readonly propertyName?: Identifier; // Name preceding "as" keyword (or undefined when "as" is absent) + readonly propertyName?: ModuleExportName; // Name preceding "as" keyword (or undefined when "as" is absent) readonly name: Identifier; // Declared name readonly isTypeOnly: boolean; } @@ -3767,10 +3767,12 @@ export interface ExportSpecifier extends NamedDeclaration, JSDocContainer { readonly kind: SyntaxKind.ExportSpecifier; readonly parent: NamedExports; readonly isTypeOnly: boolean; - readonly propertyName?: Identifier; // Name preceding "as" keyword (or undefined when "as" is absent) - readonly name: Identifier; // Declared name + readonly propertyName?: ModuleExportName; // Name preceding "as" keyword (or undefined when "as" is absent) + readonly name: ModuleExportName; // Declared name } +export type ModuleExportName = Identifier | StringLiteral; + export type ImportOrExportSpecifier = | ImportSpecifier | ExportSpecifier; @@ -5782,7 +5784,7 @@ export interface EmitResolver { hasNodeCheckFlag(node: Node, flags: LazyNodeCheckFlags): boolean; isDeclarationVisible(node: Declaration | AnyImportSyntax): boolean; isLateBound(node: Declaration): node is LateBoundDeclaration; - collectLinkedAliases(node: Identifier, setVisibility?: boolean): Node[] | undefined; + collectLinkedAliases(node: ModuleExportName, setVisibility?: boolean): Node[] | undefined; markLinkedReferences(node: Node): void; isImplementationOfOverload(node: SignatureDeclaration): boolean | undefined; requiresAddingImplicitUndefined(node: ParameterDeclaration): boolean; @@ -8914,20 +8916,20 @@ export interface NodeFactory { updateImportAttribute(node: ImportAttribute, name: ImportAttributeName, value: Expression): ImportAttribute; createNamespaceImport(name: Identifier): NamespaceImport; updateNamespaceImport(node: NamespaceImport, name: Identifier): NamespaceImport; - createNamespaceExport(name: Identifier): NamespaceExport; - updateNamespaceExport(node: NamespaceExport, name: Identifier): NamespaceExport; + createNamespaceExport(name: ModuleExportName): NamespaceExport; + updateNamespaceExport(node: NamespaceExport, name: ModuleExportName): NamespaceExport; createNamedImports(elements: readonly ImportSpecifier[]): NamedImports; updateNamedImports(node: NamedImports, elements: readonly ImportSpecifier[]): NamedImports; - createImportSpecifier(isTypeOnly: boolean, propertyName: Identifier | undefined, name: Identifier): ImportSpecifier; - updateImportSpecifier(node: ImportSpecifier, isTypeOnly: boolean, propertyName: Identifier | undefined, name: Identifier): ImportSpecifier; + createImportSpecifier(isTypeOnly: boolean, propertyName: ModuleExportName | undefined, name: Identifier): ImportSpecifier; + updateImportSpecifier(node: ImportSpecifier, isTypeOnly: boolean, propertyName: ModuleExportName | undefined, name: Identifier): ImportSpecifier; createExportAssignment(modifiers: readonly ModifierLike[] | undefined, isExportEquals: boolean | undefined, expression: Expression): ExportAssignment; updateExportAssignment(node: ExportAssignment, modifiers: readonly ModifierLike[] | undefined, expression: Expression): ExportAssignment; createExportDeclaration(modifiers: readonly ModifierLike[] | undefined, isTypeOnly: boolean, exportClause: NamedExportBindings | undefined, moduleSpecifier?: Expression, attributes?: ImportAttributes): ExportDeclaration; updateExportDeclaration(node: ExportDeclaration, modifiers: readonly ModifierLike[] | undefined, isTypeOnly: boolean, exportClause: NamedExportBindings | undefined, moduleSpecifier: Expression | undefined, attributes: ImportAttributes | undefined): ExportDeclaration; createNamedExports(elements: readonly ExportSpecifier[]): NamedExports; updateNamedExports(node: NamedExports, elements: readonly ExportSpecifier[]): NamedExports; - createExportSpecifier(isTypeOnly: boolean, propertyName: string | Identifier | undefined, name: string | Identifier): ExportSpecifier; - updateExportSpecifier(node: ExportSpecifier, isTypeOnly: boolean, propertyName: Identifier | undefined, name: Identifier): ExportSpecifier; + createExportSpecifier(isTypeOnly: boolean, propertyName: string | ModuleExportName | undefined, name: string | ModuleExportName): ExportSpecifier; + updateExportSpecifier(node: ExportSpecifier, isTypeOnly: boolean, propertyName: ModuleExportName | undefined, name: ModuleExportName): ExportSpecifier; /** @internal */ createMissingDeclaration(): MissingDeclaration; // diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index c7170af2355a4..0da394ac80d56 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -420,6 +420,7 @@ import { ModuleBlock, ModuleDeclaration, ModuleDetectionKind, + ModuleExportName, ModuleKind, ModuleResolutionKind, moduleResolutionOptionDeclarations, @@ -1218,7 +1219,28 @@ function isJSDocTypeExpressionOrChild(node: Node): boolean { /** @internal */ export function isExportNamespaceAsDefaultDeclaration(node: Node): boolean { - return !!(isExportDeclaration(node) && node.exportClause && isNamespaceExport(node.exportClause) && node.exportClause.name.escapedText === "default"); + return !!(isExportDeclaration(node) && node.exportClause && isNamespaceExport(node.exportClause) && moduleExportNameIsDefault(node.exportClause.name)); +} + +/** @internal */ +export function moduleExportNameTextUnescaped(node: ModuleExportName): string { + return node.kind === SyntaxKind.StringLiteral ? node.text : unescapeLeadingUnderscores(node.escapedText); +} + +/** @internal */ +export function moduleExportNameTextEscaped(node: ModuleExportName): __String { + return node.kind === SyntaxKind.StringLiteral ? escapeLeadingUnderscores(node.text) : node.escapedText; +} + +/** + * Equality checks against a keyword without underscores don't need to bother + * to turn "__" into "___" or vice versa, since they will never be equal in + * either case. So we can ignore those cases to improve performance. + * + * @internal + */ +export function moduleExportNameIsDefault(node: ModuleExportName): boolean { + return (node.kind === SyntaxKind.StringLiteral ? node.text : node.escapedText) === InternalSymbolName.Default; } /** @internal */ diff --git a/src/compiler/visitorPublic.ts b/src/compiler/visitorPublic.ts index 21e477329270e..f3e71e026d9be 100644 --- a/src/compiler/visitorPublic.ts +++ b/src/compiler/visitorPublic.ts @@ -59,6 +59,7 @@ import { isModifier, isModifierLike, isModuleBody, + isModuleExportName, isModuleName, isModuleReference, isNamedExportBindings, @@ -1579,7 +1580,7 @@ const visitEachChildTable: VisitEachChildTable = { return context.factory.updateImportSpecifier( node, node.isTypeOnly, - nodeVisitor(node.propertyName, visitor, isIdentifier), + nodeVisitor(node.propertyName, visitor, isModuleExportName), Debug.checkDefined(nodeVisitor(node.name, visitor, isIdentifier)), ); }, @@ -1614,8 +1615,8 @@ const visitEachChildTable: VisitEachChildTable = { return context.factory.updateExportSpecifier( node, node.isTypeOnly, - nodeVisitor(node.propertyName, visitor, isIdentifier), - Debug.checkDefined(nodeVisitor(node.name, visitor, isIdentifier)), + nodeVisitor(node.propertyName, visitor, isModuleExportName), + Debug.checkDefined(nodeVisitor(node.name, visitor, isModuleExportName)), ); }, diff --git a/src/services/completions.ts b/src/services/completions.ts index c8b676315ef03..92884a0ad1cca 100644 --- a/src/services/completions.ts +++ b/src/services/completions.ts @@ -170,6 +170,8 @@ import { isFunctionTypeNode, isGetAccessorDeclaration, isIdentifier, + isIdentifierPart, + isIdentifierStart, isIdentifierText, isImportableFile, isImportAttributes, @@ -297,6 +299,7 @@ import { ModifierSyntaxKind, modifierToFlag, ModuleDeclaration, + moduleExportNameTextEscaped, ModuleReference, moduleResolutionSupportsPackageJsonExportsAndImports, NamedImportBindings, @@ -1836,10 +1839,19 @@ function createCompletionEntry( } const parentNamedImportOrExport = findAncestor(location, isNamedImportsOrExports); - if (parentNamedImportOrExport?.kind === SyntaxKind.NamedImports) { - const possibleToken = stringToToken(name); - if (parentNamedImportOrExport && possibleToken && (possibleToken === SyntaxKind.AwaitKeyword || isNonContextualKeyword(possibleToken))) { - insertText = `${name} as ${name}_`; + if (parentNamedImportOrExport) { + const languageVersion = getEmitScriptTarget(host.getCompilationSettings()); + if (!isIdentifierText(name, languageVersion)) { + insertText = JSON.stringify(name); + if (parentNamedImportOrExport.kind === SyntaxKind.NamedImports) { + insertText += " as " + generateIdentifierForArbitraryString(name, languageVersion); + } + } + else if (parentNamedImportOrExport.kind === SyntaxKind.NamedImports) { + const possibleToken = stringToToken(name); + if (possibleToken && (possibleToken === SyntaxKind.AwaitKeyword || isNonContextualKeyword(possibleToken))) { + insertText = `${name} as ${name}_`; + } } } @@ -1872,6 +1884,29 @@ function createCompletionEntry( }; } +function generateIdentifierForArbitraryString(text: string, languageVersion: ScriptTarget | undefined): string { + let needsUnderscore = false; + let identifier = ""; + let ch: number | undefined; + + // Convert "(example, text)" into "_example_text_" + for (let i = 0; i < text.length; i += ch !== undefined && ch >= 0x10000 ? 2 : 1) { + ch = text.codePointAt(i); + if (ch !== undefined && (i === 0 ? isIdentifierStart(ch, languageVersion) : isIdentifierPart(ch, languageVersion))) { + if (needsUnderscore) identifier += "_"; + identifier += String.fromCodePoint(ch); + needsUnderscore = false; + } + else { + needsUnderscore = true; + } + } + if (needsUnderscore) identifier += "_"; + + // Default to "_" if the provided text was empty + return identifier || "_"; +} + function isClassLikeMemberCompletion(symbol: Symbol, location: Node, sourceFile: SourceFile): boolean { // TODO: support JS files. if (isInJSFile(location)) { @@ -4497,7 +4532,7 @@ function getCompletionData( completionKind = CompletionKind.MemberLike; isNewIdentifierLocation = false; const exports = typeChecker.getExportsAndPropertiesOfModule(moduleSpecifierSymbol); - const existing = new Set((namedImportsOrExports.elements as NodeArray).filter(n => !isCurrentlyEditingNode(n)).map(n => (n.propertyName || n.name).escapedText)); + const existing = new Set((namedImportsOrExports.elements as NodeArray).filter(n => !isCurrentlyEditingNode(n)).map(n => moduleExportNameTextEscaped(n.propertyName || n.name))); const uniques = exports.filter(e => e.escapedName !== InternalSymbolName.Default && !existing.has(e.escapedName)); symbols = concatenate(symbols, uniques); if (!uniques.length) { @@ -5250,6 +5285,10 @@ function getCompletionEntryDisplayNameForSymbol( if (isIdentifierText(name, target, jsxIdentifierExpected ? LanguageVariant.JSX : LanguageVariant.Standard) || symbol.valueDeclaration && isPrivateIdentifierClassElementDeclaration(symbol.valueDeclaration)) { return validNameResult; } + if (symbol.flags & SymbolFlags.Alias) { + // Allow non-identifier import/export aliases since we can insert them as string literals + return { name, needsConvertPropertyAccess: true }; + } switch (kind) { case CompletionKind.MemberLike: return originIsComputedPropertyName(origin) ? { name: origin.symbolName, needsConvertPropertyAccess: false } : undefined; diff --git a/src/services/findAllReferences.ts b/src/services/findAllReferences.ts index 7abf2257b6386..39a43d55ed639 100644 --- a/src/services/findAllReferences.ts +++ b/src/services/findAllReferences.ts @@ -208,6 +208,8 @@ import { MethodDeclaration, ModifierFlags, ModuleDeclaration, + ModuleExportName, + moduleExportNameIsDefault, MultiMap, NamedDeclaration, Node, @@ -1563,7 +1565,7 @@ export namespace Core { exportingModuleSymbol: Symbol, exportName: string, isDefaultExport: boolean, - cb: (ref: Identifier) => void, + cb: (ref: ModuleExportName) => void, ): void { const importTracker = createImportTracker(sourceFiles, new Set(sourceFiles.map(f => f.fileName)), checker, cancellationToken); const { importSearches, indirectUsers, singleReferences } = importTracker(exportSymbol, { exportKind: isDefaultExport ? ExportKind.Default : ExportKind.Named, exportingModuleSymbol }, /*isForRename*/ false); @@ -1591,9 +1593,9 @@ export namespace Core { if (!hasMatchingMeaning(singleRef, state)) return false; if (state.options.use !== FindReferencesUse.Rename) return true; // Don't rename an import type `import("./module-name")` when renaming `name` in `export = name;` - if (!isIdentifier(singleRef)) return false; + if (!isIdentifier(singleRef) && !isImportOrExportSpecifier(singleRef.parent)) return false; // At `default` in `import { default as x }` or `export { default as x }`, do add a reference, but do not rename. - return !(isImportOrExportSpecifier(singleRef.parent) && singleRef.escapedText === InternalSymbolName.Default); + return !(isImportOrExportSpecifier(singleRef.parent) && moduleExportNameIsDefault(singleRef)); } // Go to the symbol we imported from and find references for it. @@ -1840,8 +1842,13 @@ export namespace Core { case SyntaxKind.NoSubstitutionTemplateLiteral: case SyntaxKind.StringLiteral: { const str = node as StringLiteralLike; - return (isLiteralNameOfPropertyDeclarationOrIndexAccess(str) || isNameOfModuleDeclaration(node) || isExpressionOfExternalModuleImportEqualsDeclaration(node) || (isCallExpression(node.parent) && isBindableObjectDefinePropertyCall(node.parent) && node.parent.arguments[1] === node)) && - str.text.length === searchSymbolName.length; + return str.text.length === searchSymbolName.length && ( + isLiteralNameOfPropertyDeclarationOrIndexAccess(str) || + isNameOfModuleDeclaration(node) || + isExpressionOfExternalModuleImportEqualsDeclaration(node) || + (isCallExpression(node.parent) && isBindableObjectDefinePropertyCall(node.parent) && node.parent.arguments[1] === node) || + isImportOrExportSpecifier(node.parent) + ); } case SyntaxKind.NumericLiteral: @@ -1936,8 +1943,8 @@ export namespace Core { } if (isExportSpecifier(parent)) { - Debug.assert(referenceLocation.kind === SyntaxKind.Identifier); - getReferencesAtExportSpecifier(referenceLocation as Identifier, referenceSymbol, parent, search, state, addReferencesHere); + Debug.assert(referenceLocation.kind === SyntaxKind.Identifier || referenceLocation.kind === SyntaxKind.StringLiteral); + getReferencesAtExportSpecifier(referenceLocation as Identifier | StringLiteral, referenceSymbol, parent, search, state, addReferencesHere); return; } @@ -1997,7 +2004,7 @@ export namespace Core { } function getReferencesAtExportSpecifier( - referenceLocation: Identifier, + referenceLocation: ModuleExportName, referenceSymbol: Symbol, exportSpecifier: ExportSpecifier, search: Search, @@ -2016,7 +2023,7 @@ export namespace Core { if (!propertyName) { // Don't rename at `export { default } from "m";`. (but do continue to search for imports of the re-export) - if (!(state.options.use === FindReferencesUse.Rename && (name.escapedText === InternalSymbolName.Default))) { + if (!(state.options.use === FindReferencesUse.Rename && moduleExportNameIsDefault(name))) { addRef(); } } @@ -2039,8 +2046,8 @@ export namespace Core { // For `export { foo as bar }`, rename `foo`, but not `bar`. if (!isForRenameWithPrefixAndSuffixText(state.options) || alwaysGetReferences) { - const isDefaultExport = referenceLocation.escapedText === "default" - || exportSpecifier.name.escapedText === "default"; + const isDefaultExport = moduleExportNameIsDefault(referenceLocation) + || moduleExportNameIsDefault(exportSpecifier.name); const exportKind = isDefaultExport ? ExportKind.Default : ExportKind.Named; const exportSymbol = Debug.checkDefined(exportSpecifier.symbol); const exportInfo = getExportInfo(exportSymbol, exportKind, state.checker); @@ -2060,11 +2067,11 @@ export namespace Core { } } - function getLocalSymbolForExportSpecifier(referenceLocation: Identifier, referenceSymbol: Symbol, exportSpecifier: ExportSpecifier, checker: TypeChecker): Symbol { + function getLocalSymbolForExportSpecifier(referenceLocation: ModuleExportName, referenceSymbol: Symbol, exportSpecifier: ExportSpecifier, checker: TypeChecker): Symbol { return isExportSpecifierAlias(referenceLocation, exportSpecifier) && checker.getExportSpecifierLocalTargetSymbol(exportSpecifier) || referenceSymbol; } - function isExportSpecifierAlias(referenceLocation: Identifier, exportSpecifier: ExportSpecifier): boolean { + function isExportSpecifierAlias(referenceLocation: ModuleExportName, exportSpecifier: ExportSpecifier): boolean { const { parent, propertyName, name } = exportSpecifier; Debug.assert(propertyName === referenceLocation || name === referenceLocation); if (propertyName) { diff --git a/src/services/goToDefinition.ts b/src/services/goToDefinition.ts index a576f684ede54..c1993137ec76e 100644 --- a/src/services/goToDefinition.ts +++ b/src/services/goToDefinition.ts @@ -59,6 +59,7 @@ import { isFunctionTypeNode, isIdentifier, isImportMeta, + isImportOrExportSpecifier, isJSDocOverrideTag, isJsxOpeningLikeElement, isJumpStatementTarget, @@ -539,7 +540,12 @@ function getSymbol(node: Node, checker: TypeChecker, stopAtAlias: boolean | unde // (2) when the aliased symbol is originating from an import. // function shouldSkipAlias(node: Node, declaration: Node): boolean { - if (node.kind !== SyntaxKind.Identifier) { + // Note: Import aliases can be strings: + // + // import { "an alias" as foo } from "./foo"; + // export { foo as "an alias" }; + // + if (node.kind !== SyntaxKind.Identifier && (node.kind !== SyntaxKind.StringLiteral || !isImportOrExportSpecifier(node.parent))) { return false; } if (node.parent === declaration) { diff --git a/src/services/importTracker.ts b/src/services/importTracker.ts index ade3cd39edd2a..ab08c18985723 100644 --- a/src/services/importTracker.ts +++ b/src/services/importTracker.ts @@ -62,6 +62,8 @@ import { ModifierFlags, ModuleBlock, ModuleDeclaration, + ModuleExportName, + moduleExportNameTextEscaped, NamedImportsOrExports, NamespaceImport, Node, @@ -90,7 +92,7 @@ import { /** @internal */ export interface ImportsResult { /** For every import of the symbol, the location and local symbol for the import. */ - importSearches: readonly [Identifier, Symbol][]; + importSearches: readonly [ModuleExportName, Symbol][]; /** For rename imports/exports `{ foo as bar }`, `foo` is not a local, so it may be added as a reference immediately without further searching. */ singleReferences: readonly (Identifier | StringLiteral)[]; /** List of source files that may (or may not) use the symbol via a namespace. (For UMD modules this is every file.) */ @@ -319,9 +321,9 @@ function getImportersForExport( * But re-exports will be placed in 'singleReferences' since they cannot be locally referenced. */ function getSearchesFromDirectImports(directImports: Importer[], exportSymbol: Symbol, exportKind: ExportKind, checker: TypeChecker, isForRename: boolean): Pick { - const importSearches: [Identifier, Symbol][] = []; + const importSearches: [ModuleExportName, Symbol][] = []; const singleReferences: (Identifier | StringLiteral)[] = []; - function addSearch(location: Identifier, symbol: Symbol): void { + function addSearch(location: ModuleExportName, symbol: Symbol): void { importSearches.push([location, symbol]); } @@ -417,7 +419,7 @@ function getSearchesFromDirectImports(directImports: Importer[], exportSymbol: S for (const element of namedBindings.elements) { const { name, propertyName } = element; - if (!isNameMatch((propertyName || name).escapedText)) { + if (!isNameMatch(moduleExportNameTextEscaped(propertyName || name))) { continue; } @@ -426,7 +428,7 @@ function getSearchesFromDirectImports(directImports: Importer[], exportSymbol: S singleReferences.push(propertyName); // If renaming `{ foo as bar }`, don't touch `bar`, just `foo`. // But do rename `foo` in ` { default as foo }` if that's the original export name. - if (!isForRename || name.escapedText === exportSymbol.escapedName) { + if (!isForRename || moduleExportNameTextEscaped(name) === exportSymbol.escapedName) { // Search locally for `bar`. addSearch(name, checker.getSymbolAtLocation(name)!); } diff --git a/src/services/organizeImports.ts b/src/services/organizeImports.ts index facc06742ded7..a5b366281de57 100644 --- a/src/services/organizeImports.ts +++ b/src/services/organizeImports.ts @@ -45,6 +45,7 @@ import { LanguageServiceHost, length, map, + moduleExportNameTextEscaped, NamedImportBindings, NamedImports, NamespaceImport, @@ -690,7 +691,7 @@ function hasModuleDeclarationMatchingSpecifier(sourceFile: SourceFile, moduleSpe function getNewImportSpecifiers(namedImports: ImportDeclaration[]) { return flatMap(namedImports, namedImport => map(tryGetNamedBindingElements(namedImport), importSpecifier => - importSpecifier.name && importSpecifier.propertyName && importSpecifier.name.escapedText === importSpecifier.propertyName.escapedText + importSpecifier.name && importSpecifier.propertyName && moduleExportNameTextEscaped(importSpecifier.name) === moduleExportNameTextEscaped(importSpecifier.propertyName) ? factory.updateImportSpecifier(importSpecifier, importSpecifier.isTypeOnly, /*propertyName*/ undefined, importSpecifier.name) : importSpecifier)); } diff --git a/src/services/refactors/convertExport.ts b/src/services/refactors/convertExport.ts index 5e722c083a9a0..547403bfb07d0 100644 --- a/src/services/refactors/convertExport.ts +++ b/src/services/refactors/convertExport.ts @@ -34,6 +34,7 @@ import { makeImport, ModifierFlags, ModuleBlock, + ModuleExportName, NamespaceDeclaration, Node, NodeFlags, @@ -236,7 +237,7 @@ function changeImports(program: Program, { wasDefault, exportName, exportingModu }); } -function changeDefaultToNamedImport(importingSourceFile: SourceFile, ref: Identifier, changes: textChanges.ChangeTracker, exportName: string): void { +function changeDefaultToNamedImport(importingSourceFile: SourceFile, ref: ModuleExportName, changes: textChanges.ChangeTracker, exportName: string): void { const { parent } = ref; switch (parent.kind) { case SyntaxKind.PropertyAccessExpression: @@ -282,7 +283,7 @@ function changeDefaultToNamedImport(importingSourceFile: SourceFile, ref: Identi } } -function changeNamedToDefaultImport(importingSourceFile: SourceFile, ref: Identifier, changes: textChanges.ChangeTracker): void { +function changeNamedToDefaultImport(importingSourceFile: SourceFile, ref: ModuleExportName, changes: textChanges.ChangeTracker): void { const parent = ref.parent as PropertyAccessExpression | ImportSpecifier | ExportSpecifier; switch (parent.kind) { case SyntaxKind.PropertyAccessExpression: diff --git a/src/services/refactors/convertImport.ts b/src/services/refactors/convertImport.ts index 55e14b576e1f7..b0071598b3bb7 100644 --- a/src/services/refactors/convertImport.ts +++ b/src/services/refactors/convertImport.ts @@ -247,9 +247,11 @@ export function doChangeNamedToNamespaceOrDefault(sourceFile: SourceFile, progra const neededNamedImports = new Set(); for (const element of toConvert.elements) { - const propertyName = (element.propertyName || element.name).text; + const propertyName = element.propertyName || element.name; FindAllReferences.Core.eachSymbolReferenceInFile(element.name, checker, sourceFile, id => { - const access = factory.createPropertyAccessExpression(factory.createIdentifier(namespaceImportName), propertyName); + const access = propertyName.kind === SyntaxKind.StringLiteral + ? factory.createElementAccessExpression(factory.createIdentifier(namespaceImportName), factory.cloneNode(propertyName)) + : factory.createPropertyAccessExpression(factory.createIdentifier(namespaceImportName), factory.cloneNode(propertyName)); if (isShorthandPropertyAssignment(id.parent)) { changes.replaceNode(sourceFile, id.parent, factory.createPropertyAssignment(id.text, access)); } @@ -271,7 +273,7 @@ export function doChangeNamedToNamespaceOrDefault(sourceFile: SourceFile, progra ); if (neededNamedImports.size && isImportDeclaration(importDecl)) { - const newNamedImports: ImportSpecifier[] = arrayFrom(neededNamedImports.values(), element => factory.createImportSpecifier(element.isTypeOnly, element.propertyName && factory.createIdentifier(element.propertyName.text), factory.createIdentifier(element.name.text))); + const newNamedImports: ImportSpecifier[] = arrayFrom(neededNamedImports.values(), element => factory.createImportSpecifier(element.isTypeOnly, element.propertyName && factory.cloneNode(element.propertyName), factory.cloneNode(element.name))); changes.insertNodeAfter(sourceFile, toConvert.parent.parent, createImport(importDecl, /*defaultImportName*/ undefined, newNamedImports)); } } diff --git a/src/services/stringCompletions.ts b/src/services/stringCompletions.ts index 0b1747fd07bd8..b96e06138dee3 100644 --- a/src/services/stringCompletions.ts +++ b/src/services/stringCompletions.ts @@ -77,7 +77,9 @@ import { hasProperty, hasTrailingDirectorySeparator, hostGetCanonicalFileName, + ImportOrExportSpecifier, IndexedAccessTypeNode, + InternalSymbolName, isApplicableVersionedTypesKey, isArray, isCallExpression, @@ -104,6 +106,7 @@ import { LiteralTypeNode, mapDefined, MapLike, + moduleExportNameTextEscaped, moduleResolutionUsesNodeModules, ModuleSpecifierEnding, moduleSpecifiers, @@ -434,6 +437,24 @@ function getStringLiteralCompletionEntries(sourceFile: SourceFile, node: StringL } const literals = contextualTypes.types.filter(literal => !tracker.hasValue(literal.value)); return { kind: StringLiteralCompletionKind.Types, types: literals, isNewIdentifier: false }; + + case SyntaxKind.ImportSpecifier: + case SyntaxKind.ExportSpecifier: + // Complete string aliases in `import { "|" } from` and `export { "|" } from` + const specifier = parent as ImportOrExportSpecifier; + if (specifier.propertyName && node !== specifier.propertyName) { + return; // Don't complete in `export { "..." as "|" } from` + } + const namedImportsOrExports = specifier.parent; + const { moduleSpecifier } = namedImportsOrExports.kind === SyntaxKind.NamedImports ? namedImportsOrExports.parent.parent : namedImportsOrExports.parent; + if (!moduleSpecifier) return; + const moduleSpecifierSymbol = typeChecker.getSymbolAtLocation(moduleSpecifier); // TODO: GH#18217 + if (!moduleSpecifierSymbol) return; + const exports = typeChecker.getExportsAndPropertiesOfModule(moduleSpecifierSymbol); + const existing = new Set(namedImportsOrExports.elements.map(n => moduleExportNameTextEscaped(n.propertyName || n.name))); + const uniques = exports.filter(e => e.escapedName !== InternalSymbolName.Default && !existing.has(e.escapedName)); + return { kind: StringLiteralCompletionKind.Properties, symbols: uniques, hasIndexSignature: false }; + default: return fromContextualType() || fromContextualType(ContextFlags.None); } diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index a4903113b8dff..1752b0ef02e32 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -5517,7 +5517,7 @@ declare namespace ts { interface NamespaceExport extends NamedDeclaration { readonly kind: SyntaxKind.NamespaceExport; readonly parent: ExportDeclaration; - readonly name: Identifier; + readonly name: ModuleExportName; } interface NamespaceExportDeclaration extends DeclarationStatement, JSDocContainer { readonly kind: SyntaxKind.NamespaceExportDeclaration; @@ -5549,7 +5549,7 @@ declare namespace ts { interface ImportSpecifier extends NamedDeclaration { readonly kind: SyntaxKind.ImportSpecifier; readonly parent: NamedImports; - readonly propertyName?: Identifier; + readonly propertyName?: ModuleExportName; readonly name: Identifier; readonly isTypeOnly: boolean; } @@ -5557,9 +5557,10 @@ declare namespace ts { readonly kind: SyntaxKind.ExportSpecifier; readonly parent: NamedExports; readonly isTypeOnly: boolean; - readonly propertyName?: Identifier; - readonly name: Identifier; + readonly propertyName?: ModuleExportName; + readonly name: ModuleExportName; } + type ModuleExportName = Identifier | StringLiteral; type ImportOrExportSpecifier = ImportSpecifier | ExportSpecifier; type TypeOnlyCompatibleAliasDeclaration = ImportClause | ImportEqualsDeclaration | NamespaceImport | ImportOrExportSpecifier | ExportDeclaration | NamespaceExport; type TypeOnlyImportDeclaration = @@ -7661,20 +7662,20 @@ declare namespace ts { updateImportAttribute(node: ImportAttribute, name: ImportAttributeName, value: Expression): ImportAttribute; createNamespaceImport(name: Identifier): NamespaceImport; updateNamespaceImport(node: NamespaceImport, name: Identifier): NamespaceImport; - createNamespaceExport(name: Identifier): NamespaceExport; - updateNamespaceExport(node: NamespaceExport, name: Identifier): NamespaceExport; + createNamespaceExport(name: ModuleExportName): NamespaceExport; + updateNamespaceExport(node: NamespaceExport, name: ModuleExportName): NamespaceExport; createNamedImports(elements: readonly ImportSpecifier[]): NamedImports; updateNamedImports(node: NamedImports, elements: readonly ImportSpecifier[]): NamedImports; - createImportSpecifier(isTypeOnly: boolean, propertyName: Identifier | undefined, name: Identifier): ImportSpecifier; - updateImportSpecifier(node: ImportSpecifier, isTypeOnly: boolean, propertyName: Identifier | undefined, name: Identifier): ImportSpecifier; + createImportSpecifier(isTypeOnly: boolean, propertyName: ModuleExportName | undefined, name: Identifier): ImportSpecifier; + updateImportSpecifier(node: ImportSpecifier, isTypeOnly: boolean, propertyName: ModuleExportName | undefined, name: Identifier): ImportSpecifier; createExportAssignment(modifiers: readonly ModifierLike[] | undefined, isExportEquals: boolean | undefined, expression: Expression): ExportAssignment; updateExportAssignment(node: ExportAssignment, modifiers: readonly ModifierLike[] | undefined, expression: Expression): ExportAssignment; createExportDeclaration(modifiers: readonly ModifierLike[] | undefined, isTypeOnly: boolean, exportClause: NamedExportBindings | undefined, moduleSpecifier?: Expression, attributes?: ImportAttributes): ExportDeclaration; updateExportDeclaration(node: ExportDeclaration, modifiers: readonly ModifierLike[] | undefined, isTypeOnly: boolean, exportClause: NamedExportBindings | undefined, moduleSpecifier: Expression | undefined, attributes: ImportAttributes | undefined): ExportDeclaration; createNamedExports(elements: readonly ExportSpecifier[]): NamedExports; updateNamedExports(node: NamedExports, elements: readonly ExportSpecifier[]): NamedExports; - createExportSpecifier(isTypeOnly: boolean, propertyName: string | Identifier | undefined, name: string | Identifier): ExportSpecifier; - updateExportSpecifier(node: ExportSpecifier, isTypeOnly: boolean, propertyName: Identifier | undefined, name: Identifier): ExportSpecifier; + createExportSpecifier(isTypeOnly: boolean, propertyName: string | ModuleExportName | undefined, name: string | ModuleExportName): ExportSpecifier; + updateExportSpecifier(node: ExportSpecifier, isTypeOnly: boolean, propertyName: ModuleExportName | undefined, name: ModuleExportName): ExportSpecifier; createExternalModuleReference(expression: Expression): ExternalModuleReference; updateExternalModuleReference(node: ExternalModuleReference, expression: Expression): ExternalModuleReference; createJSDocAllType(): JSDocAllType; @@ -8992,6 +8993,7 @@ declare namespace ts { function isExportDeclaration(node: Node): node is ExportDeclaration; function isNamedExports(node: Node): node is NamedExports; function isExportSpecifier(node: Node): node is ExportSpecifier; + function isModuleExportName(node: Node): node is ModuleExportName; function isMissingDeclaration(node: Node): node is MissingDeclaration; function isNotEmittedStatement(node: Node): node is NotEmittedStatement; function isExternalModuleReference(node: Node): node is ExternalModuleReference; diff --git a/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_exportEmpty.errors.txt b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_exportEmpty.errors.txt new file mode 100644 index 0000000000000..b29a1f103c52e --- /dev/null +++ b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_exportEmpty.errors.txt @@ -0,0 +1,13 @@ +arbitraryModuleNamespaceIdentifiers_exportEmpty.ts(6,7): error TS2322: Type '"empty"' is not assignable to type '"type error expected here"'. + + +==== arbitraryModuleNamespaceIdentifiers_exportEmpty.ts (1 errors) ==== + // This should result in a type error. In particular, the empty string is a now + // a valid module export name, and should be treated as such here. + const empty = "empty"; + export { empty as "" }; + import { "" as foo } from "./arbitraryModuleNamespaceIdentifiers_exportEmpty"; + const bar: "type error expected here" = foo; + ~~~ +!!! error TS2322: Type '"empty"' is not assignable to type '"type error expected here"'. + \ No newline at end of file diff --git a/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_exportEmpty.js b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_exportEmpty.js new file mode 100644 index 0000000000000..a04910b7933be --- /dev/null +++ b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_exportEmpty.js @@ -0,0 +1,23 @@ +//// [tests/cases/conformance/es2022/arbitraryModuleNamespaceIdentifiers/arbitraryModuleNamespaceIdentifiers_exportEmpty.ts] //// + +//// [arbitraryModuleNamespaceIdentifiers_exportEmpty.ts] +// This should result in a type error. In particular, the empty string is a now +// a valid module export name, and should be treated as such here. +const empty = "empty"; +export { empty as "" }; +import { "" as foo } from "./arbitraryModuleNamespaceIdentifiers_exportEmpty"; +const bar: "type error expected here" = foo; + + +//// [arbitraryModuleNamespaceIdentifiers_exportEmpty.js] +// This should result in a type error. In particular, the empty string is a now +// a valid module export name, and should be treated as such here. +const empty = "empty"; +export { empty as "" }; +import { "" as foo } from "./arbitraryModuleNamespaceIdentifiers_exportEmpty"; +const bar = foo; + + +//// [arbitraryModuleNamespaceIdentifiers_exportEmpty.d.ts] +declare const empty = "empty"; +export { empty as "" }; diff --git a/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_exportEmpty.symbols b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_exportEmpty.symbols new file mode 100644 index 0000000000000..9baebaf89baff --- /dev/null +++ b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_exportEmpty.symbols @@ -0,0 +1,19 @@ +//// [tests/cases/conformance/es2022/arbitraryModuleNamespaceIdentifiers/arbitraryModuleNamespaceIdentifiers_exportEmpty.ts] //// + +=== arbitraryModuleNamespaceIdentifiers_exportEmpty.ts === +// This should result in a type error. In particular, the empty string is a now +// a valid module export name, and should be treated as such here. +const empty = "empty"; +>empty : Symbol(empty, Decl(arbitraryModuleNamespaceIdentifiers_exportEmpty.ts, 2, 5)) + +export { empty as "" }; +>empty : Symbol(empty, Decl(arbitraryModuleNamespaceIdentifiers_exportEmpty.ts, 2, 5)) +>"" : Symbol("", Decl(arbitraryModuleNamespaceIdentifiers_exportEmpty.ts, 3, 8)) + +import { "" as foo } from "./arbitraryModuleNamespaceIdentifiers_exportEmpty"; +>foo : Symbol(foo, Decl(arbitraryModuleNamespaceIdentifiers_exportEmpty.ts, 4, 8)) + +const bar: "type error expected here" = foo; +>bar : Symbol(bar, Decl(arbitraryModuleNamespaceIdentifiers_exportEmpty.ts, 5, 5)) +>foo : Symbol(foo, Decl(arbitraryModuleNamespaceIdentifiers_exportEmpty.ts, 4, 8)) + diff --git a/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_exportEmpty.types b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_exportEmpty.types new file mode 100644 index 0000000000000..d2f63f672fbfb --- /dev/null +++ b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_exportEmpty.types @@ -0,0 +1,27 @@ +//// [tests/cases/conformance/es2022/arbitraryModuleNamespaceIdentifiers/arbitraryModuleNamespaceIdentifiers_exportEmpty.ts] //// + +=== arbitraryModuleNamespaceIdentifiers_exportEmpty.ts === +// This should result in a type error. In particular, the empty string is a now +// a valid module export name, and should be treated as such here. +const empty = "empty"; +>empty : "empty" +> : ^^^^^^^ +>"empty" : "empty" +> : ^^^^^^^ + +export { empty as "" }; +>empty : "empty" +> : ^^^^^^^ +>"" : "empty" +> : ^^^^^^^ + +import { "" as foo } from "./arbitraryModuleNamespaceIdentifiers_exportEmpty"; +>foo : "empty" +> : ^^^^^^^ + +const bar: "type error expected here" = foo; +>bar : "type error expected here" +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^ +>foo : "empty" +> : ^^^^^^^ + diff --git a/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_importEmpty.errors.txt b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_importEmpty.errors.txt new file mode 100644 index 0000000000000..5f29972f17ae3 --- /dev/null +++ b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_importEmpty.errors.txt @@ -0,0 +1,21 @@ +arbitraryModuleNamespaceIdentifiers_importEmpty.ts(4,3): error TS2305: Module '"./arbitraryModuleNamespaceIdentifiers_importEmpty"' has no exported member '"missing"'. +arbitraryModuleNamespaceIdentifiers_importEmpty.ts(5,3): error TS2305: Module '"./arbitraryModuleNamespaceIdentifiers_importEmpty"' has no exported member '"(missing)"'. +arbitraryModuleNamespaceIdentifiers_importEmpty.ts(6,3): error TS2305: Module '"./arbitraryModuleNamespaceIdentifiers_importEmpty"' has no exported member '""'. + + +==== arbitraryModuleNamespaceIdentifiers_importEmpty.ts (3 errors) ==== + // These should all be errors. In particular, the empty string is a now a valid + // module export name, and should be treated as such here. + import { + "missing" as x, + ~~~~~~~~~ +!!! error TS2305: Module '"./arbitraryModuleNamespaceIdentifiers_importEmpty"' has no exported member '"missing"'. + "(missing)" as y, + ~~~~~~~~~~~ +!!! error TS2305: Module '"./arbitraryModuleNamespaceIdentifiers_importEmpty"' has no exported member '"(missing)"'. + "" as z, + ~~ +!!! error TS2305: Module '"./arbitraryModuleNamespaceIdentifiers_importEmpty"' has no exported member '""'. + } from "./arbitraryModuleNamespaceIdentifiers_importEmpty"; + const xyz = [x, y, z]; + \ No newline at end of file diff --git a/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_importEmpty.js b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_importEmpty.js new file mode 100644 index 0000000000000..4a0e326417031 --- /dev/null +++ b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_importEmpty.js @@ -0,0 +1,22 @@ +//// [tests/cases/conformance/es2022/arbitraryModuleNamespaceIdentifiers/arbitraryModuleNamespaceIdentifiers_importEmpty.ts] //// + +//// [arbitraryModuleNamespaceIdentifiers_importEmpty.ts] +// These should all be errors. In particular, the empty string is a now a valid +// module export name, and should be treated as such here. +import { + "missing" as x, + "(missing)" as y, + "" as z, +} from "./arbitraryModuleNamespaceIdentifiers_importEmpty"; +const xyz = [x, y, z]; + + +//// [arbitraryModuleNamespaceIdentifiers_importEmpty.js] +// These should all be errors. In particular, the empty string is a now a valid +// module export name, and should be treated as such here. +import { "missing" as x, "(missing)" as y, "" as z, } from "./arbitraryModuleNamespaceIdentifiers_importEmpty"; +const xyz = [x, y, z]; + + +//// [arbitraryModuleNamespaceIdentifiers_importEmpty.d.ts] +export {}; diff --git a/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_importEmpty.symbols b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_importEmpty.symbols new file mode 100644 index 0000000000000..663d32df19eae --- /dev/null +++ b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_importEmpty.symbols @@ -0,0 +1,22 @@ +//// [tests/cases/conformance/es2022/arbitraryModuleNamespaceIdentifiers/arbitraryModuleNamespaceIdentifiers_importEmpty.ts] //// + +=== arbitraryModuleNamespaceIdentifiers_importEmpty.ts === +// These should all be errors. In particular, the empty string is a now a valid +// module export name, and should be treated as such here. +import { + "missing" as x, +>x : Symbol(x, Decl(arbitraryModuleNamespaceIdentifiers_importEmpty.ts, 2, 8)) + + "(missing)" as y, +>y : Symbol(y, Decl(arbitraryModuleNamespaceIdentifiers_importEmpty.ts, 3, 17)) + + "" as z, +>z : Symbol(z, Decl(arbitraryModuleNamespaceIdentifiers_importEmpty.ts, 4, 19)) + +} from "./arbitraryModuleNamespaceIdentifiers_importEmpty"; +const xyz = [x, y, z]; +>xyz : Symbol(xyz, Decl(arbitraryModuleNamespaceIdentifiers_importEmpty.ts, 7, 5)) +>x : Symbol(x, Decl(arbitraryModuleNamespaceIdentifiers_importEmpty.ts, 2, 8)) +>y : Symbol(y, Decl(arbitraryModuleNamespaceIdentifiers_importEmpty.ts, 3, 17)) +>z : Symbol(z, Decl(arbitraryModuleNamespaceIdentifiers_importEmpty.ts, 4, 19)) + diff --git a/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_importEmpty.types b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_importEmpty.types new file mode 100644 index 0000000000000..20059408b0e68 --- /dev/null +++ b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_importEmpty.types @@ -0,0 +1,31 @@ +//// [tests/cases/conformance/es2022/arbitraryModuleNamespaceIdentifiers/arbitraryModuleNamespaceIdentifiers_importEmpty.ts] //// + +=== arbitraryModuleNamespaceIdentifiers_importEmpty.ts === +// These should all be errors. In particular, the empty string is a now a valid +// module export name, and should be treated as such here. +import { + "missing" as x, +>x : any +> : ^^^ + + "(missing)" as y, +>y : any +> : ^^^ + + "" as z, +>z : any +> : ^^^ + +} from "./arbitraryModuleNamespaceIdentifiers_importEmpty"; +const xyz = [x, y, z]; +>xyz : any[] +> : ^^^^^ +>[x, y, z] : any[] +> : ^^^^^ +>x : any +> : ^^^ +>y : any +> : ^^^ +>z : any +> : ^^^ + diff --git a/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=amd).errors.txt b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=amd).errors.txt new file mode 100644 index 0000000000000..cc359bceb4904 --- /dev/null +++ b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=amd).errors.txt @@ -0,0 +1,42 @@ +arbitraryModuleNamespaceIdentifiers_module.ts(20,7): error TS2322: Type '"expect error about someType"' is not assignable to type '"someType"'. +arbitraryModuleNamespaceIdentifiers_module.ts(24,7): error TS2322: Type '"expect error about someType"' is not assignable to type '"someType"'. +arbitraryModuleNamespaceIdentifiers_module.ts(29,7): error TS2322: Type '"expect error about otherType"' is not assignable to type '"otherType"'. + + +==== arbitraryModuleNamespaceIdentifiers_module.ts (3 errors) ==== + const someValue = "someValue"; + type someType = "someType"; + + export { someValue as "" }; + import { "" as valueX } from "./arbitraryModuleNamespaceIdentifiers_module"; + if (valueX !== "someValue") throw "should be someValue"; + + export { "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; + import { "" as valueY } from "./arbitraryModuleNamespaceIdentifiers_module"; + if (valueY !== "someValue") throw "should be someValue"; + + export * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; + import { "" as valueZ } from "./arbitraryModuleNamespaceIdentifiers_module"; + if (valueZ[""] !== "someValue") throw "should be someValue"; + if (valueZ[""] !== "someValue") throw "should be someValue"; + if (valueZ[""] !== valueZ) throw "should be export namespace"; + + export { type someType as "" }; + import { type "" as typeA } from "./arbitraryModuleNamespaceIdentifiers_module"; + const importTest: typeA = "expect error about someType"; + ~~~~~~~~~~ +!!! error TS2322: Type '"expect error about someType"' is not assignable to type '"someType"'. + + export { type "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; + import { type "" as typeB } from "./arbitraryModuleNamespaceIdentifiers_module"; + const reimportTest: typeB = "expect error about someType"; + ~~~~~~~~~~~~ +!!! error TS2322: Type '"expect error about someType"' is not assignable to type '"someType"'. + + export type * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; + import { type "" as typeC } from "./arbitraryModuleNamespaceIdentifiers_module"; + export type otherType = "otherType"; + const importStarTestA: typeC.otherType = "expect error about otherType"; + ~~~~~~~~~~~~~~~ +!!! error TS2322: Type '"expect error about otherType"' is not assignable to type '"otherType"'. + \ No newline at end of file diff --git a/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=amd).js b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=amd).js new file mode 100644 index 0000000000000..1a72c31df4c08 --- /dev/null +++ b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=amd).js @@ -0,0 +1,69 @@ +//// [tests/cases/conformance/es2022/arbitraryModuleNamespaceIdentifiers/arbitraryModuleNamespaceIdentifiers_module.ts] //// + +//// [arbitraryModuleNamespaceIdentifiers_module.ts] +const someValue = "someValue"; +type someType = "someType"; + +export { someValue as "" }; +import { "" as valueX } from "./arbitraryModuleNamespaceIdentifiers_module"; +if (valueX !== "someValue") throw "should be someValue"; + +export { "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; +import { "" as valueY } from "./arbitraryModuleNamespaceIdentifiers_module"; +if (valueY !== "someValue") throw "should be someValue"; + +export * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; +import { "" as valueZ } from "./arbitraryModuleNamespaceIdentifiers_module"; +if (valueZ[""] !== "someValue") throw "should be someValue"; +if (valueZ[""] !== "someValue") throw "should be someValue"; +if (valueZ[""] !== valueZ) throw "should be export namespace"; + +export { type someType as "" }; +import { type "" as typeA } from "./arbitraryModuleNamespaceIdentifiers_module"; +const importTest: typeA = "expect error about someType"; + +export { type "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; +import { type "" as typeB } from "./arbitraryModuleNamespaceIdentifiers_module"; +const reimportTest: typeB = "expect error about someType"; + +export type * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; +import { type "" as typeC } from "./arbitraryModuleNamespaceIdentifiers_module"; +export type otherType = "otherType"; +const importStarTestA: typeC.otherType = "expect error about otherType"; + + +//// [arbitraryModuleNamespaceIdentifiers_module.js] +define(["require", "exports", "./arbitraryModuleNamespaceIdentifiers_module", "./arbitraryModuleNamespaceIdentifiers_module", "./arbitraryModuleNamespaceIdentifiers_module", "./arbitraryModuleNamespaceIdentifiers_module", "./arbitraryModuleNamespaceIdentifiers_module"], function (require, exports, arbitraryModuleNamespaceIdentifiers_module_1, arbitraryModuleNamespaceIdentifiers_module_2, arbitraryModuleNamespaceIdentifiers_module_3, arbitraryModuleNamespaceIdentifiers_module_4, arbitraryModuleNamespaceIdentifiers_module_5) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + exports[""] = exports[""] = exports[""] = void 0; + const someValue = "someValue"; + exports[""] = someValue; + if (arbitraryModuleNamespaceIdentifiers_module_1[""] !== "someValue") + throw "should be someValue"; + Object.defineProperty(exports, "", { enumerable: true, get: function () { return arbitraryModuleNamespaceIdentifiers_module_2[""]; } }); + if (arbitraryModuleNamespaceIdentifiers_module_3[""] !== "someValue") + throw "should be someValue"; + exports[""] = arbitraryModuleNamespaceIdentifiers_module_4; + if (arbitraryModuleNamespaceIdentifiers_module_5[""][""] !== "someValue") + throw "should be someValue"; + if (arbitraryModuleNamespaceIdentifiers_module_5[""][""] !== "someValue") + throw "should be someValue"; + if (arbitraryModuleNamespaceIdentifiers_module_5[""][""] !== arbitraryModuleNamespaceIdentifiers_module_5[""]) + throw "should be export namespace"; + const importTest = "expect error about someType"; + const reimportTest = "expect error about someType"; + const importStarTestA = "expect error about otherType"; +}); + + +//// [arbitraryModuleNamespaceIdentifiers_module.d.ts] +declare const someValue = "someValue"; +type someType = "someType"; +export { someValue as "" }; +export { "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; +export * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; +export { type someType as "" }; +export { type "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; +export type * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; +export type otherType = "otherType"; diff --git a/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=amd).symbols b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=amd).symbols new file mode 100644 index 0000000000000..a792b7d3f5280 --- /dev/null +++ b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=amd).symbols @@ -0,0 +1,82 @@ +//// [tests/cases/conformance/es2022/arbitraryModuleNamespaceIdentifiers/arbitraryModuleNamespaceIdentifiers_module.ts] //// + +=== arbitraryModuleNamespaceIdentifiers_module.ts === +const someValue = "someValue"; +>someValue : Symbol(someValue, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 0, 5)) + +type someType = "someType"; +>someType : Symbol(someType, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 0, 30)) + +export { someValue as "" }; +>someValue : Symbol(someValue, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 0, 5)) +>"" : Symbol(valueZ[""], Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 3, 8)) + +import { "" as valueX } from "./arbitraryModuleNamespaceIdentifiers_module"; +>valueX : Symbol(valueX, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 4, 8)) + +if (valueX !== "someValue") throw "should be someValue"; +>valueX : Symbol(valueX, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 4, 8)) + +export { "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; +>"" : Symbol(valueZ[""], Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 7, 8)) + +import { "" as valueY } from "./arbitraryModuleNamespaceIdentifiers_module"; +>valueY : Symbol(valueY, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 8, 8)) + +if (valueY !== "someValue") throw "should be someValue"; +>valueY : Symbol(valueY, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 8, 8)) + +export * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; +>"" : Symbol(valueZ[""], Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 11, 6)) + +import { "" as valueZ } from "./arbitraryModuleNamespaceIdentifiers_module"; +>valueZ : Symbol(valueZ, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 12, 8)) + +if (valueZ[""] !== "someValue") throw "should be someValue"; +>valueZ : Symbol(valueZ, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 12, 8)) +>"" : Symbol(valueZ[""], Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 3, 8)) + +if (valueZ[""] !== "someValue") throw "should be someValue"; +>valueZ : Symbol(valueZ, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 12, 8)) +>"" : Symbol(valueZ[""], Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 7, 8)) + +if (valueZ[""] !== valueZ) throw "should be export namespace"; +>valueZ : Symbol(valueZ, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 12, 8)) +>"" : Symbol(valueZ[""], Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 11, 6)) +>valueZ : Symbol(valueZ, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 12, 8)) + +export { type someType as "" }; +>someType : Symbol(someType, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 0, 30)) +>"" : Symbol(valueZ[""], Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 17, 8)) + +import { type "" as typeA } from "./arbitraryModuleNamespaceIdentifiers_module"; +>typeA : Symbol(typeA, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 18, 8)) + +const importTest: typeA = "expect error about someType"; +>importTest : Symbol(importTest, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 19, 5)) +>typeA : Symbol(typeA, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 18, 8)) + +export { type "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; +>"" : Symbol(valueZ[""], Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 21, 8)) + +import { type "" as typeB } from "./arbitraryModuleNamespaceIdentifiers_module"; +>typeB : Symbol(typeB, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 22, 8)) + +const reimportTest: typeB = "expect error about someType"; +>reimportTest : Symbol(reimportTest, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 23, 5)) +>typeB : Symbol(typeB, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 22, 8)) + +export type * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; +>"" : Symbol(valueZ[""], Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 25, 11)) + +import { type "" as typeC } from "./arbitraryModuleNamespaceIdentifiers_module"; +>typeC : Symbol(typeC, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 26, 8)) + +export type otherType = "otherType"; +>otherType : Symbol(valueZ.otherType, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 26, 83)) + +const importStarTestA: typeC.otherType = "expect error about otherType"; +>importStarTestA : Symbol(importStarTestA, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 28, 5)) +>typeC : Symbol(typeC, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 26, 8)) +>otherType : Symbol(valueZ.otherType, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 26, 83)) + diff --git a/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=amd).types b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=amd).types new file mode 100644 index 0000000000000..4574f9754d0b4 --- /dev/null +++ b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=amd).types @@ -0,0 +1,151 @@ +//// [tests/cases/conformance/es2022/arbitraryModuleNamespaceIdentifiers/arbitraryModuleNamespaceIdentifiers_module.ts] //// + +=== arbitraryModuleNamespaceIdentifiers_module.ts === +const someValue = "someValue"; +>someValue : "someValue" +> : ^^^^^^^^^^^ +>"someValue" : "someValue" +> : ^^^^^^^^^^^ + +type someType = "someType"; +>someType : "someType" +> : ^^^^^^^^^^ + +export { someValue as "" }; +>someValue : "someValue" +> : ^^^^^^^^^^^ +>"" : "someValue" +> : ^^^^^^^^^^^ + +import { "" as valueX } from "./arbitraryModuleNamespaceIdentifiers_module"; +>valueX : "someValue" +> : ^^^^^^^^^^^ + +if (valueX !== "someValue") throw "should be someValue"; +>valueX !== "someValue" : boolean +> : ^^^^^^^ +>valueX : "someValue" +> : ^^^^^^^^^^^ +>"someValue" : "someValue" +> : ^^^^^^^^^^^ +>"should be someValue" : "should be someValue" +> : ^^^^^^^^^^^^^^^^^^^^^ + +export { "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; +>"" : "someValue" +> : ^^^^^^^^^^^ + +import { "" as valueY } from "./arbitraryModuleNamespaceIdentifiers_module"; +>valueY : "someValue" +> : ^^^^^^^^^^^ + +if (valueY !== "someValue") throw "should be someValue"; +>valueY !== "someValue" : boolean +> : ^^^^^^^ +>valueY : "someValue" +> : ^^^^^^^^^^^ +>"someValue" : "someValue" +> : ^^^^^^^^^^^ +>"should be someValue" : "should be someValue" +> : ^^^^^^^^^^^^^^^^^^^^^ + +export * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; +>"" : typeof valueZ +> : ^^^^^^^^^^^^^ + +import { "" as valueZ } from "./arbitraryModuleNamespaceIdentifiers_module"; +>valueZ : typeof valueZ +> : ^^^^^^^^^^^^^ + +if (valueZ[""] !== "someValue") throw "should be someValue"; +>valueZ[""] !== "someValue" : boolean +> : ^^^^^^^ +>valueZ[""] : "someValue" +> : ^^^^^^^^^^^ +>valueZ : typeof valueZ +> : ^^^^^^^^^^^^^ +>"" : "" +> : ^^^^^ +>"someValue" : "someValue" +> : ^^^^^^^^^^^ +>"should be someValue" : "should be someValue" +> : ^^^^^^^^^^^^^^^^^^^^^ + +if (valueZ[""] !== "someValue") throw "should be someValue"; +>valueZ[""] !== "someValue" : boolean +> : ^^^^^^^ +>valueZ[""] : "someValue" +> : ^^^^^^^^^^^ +>valueZ : typeof valueZ +> : ^^^^^^^^^^^^^ +>"" : "" +> : ^^^^^ +>"someValue" : "someValue" +> : ^^^^^^^^^^^ +>"should be someValue" : "should be someValue" +> : ^^^^^^^^^^^^^^^^^^^^^ + +if (valueZ[""] !== valueZ) throw "should be export namespace"; +>valueZ[""] !== valueZ : boolean +> : ^^^^^^^ +>valueZ[""] : typeof valueZ +> : ^^^^^^^^^^^^^ +>valueZ : typeof valueZ +> : ^^^^^^^^^^^^^ +>"" : "" +> : ^^^^^ +>valueZ : typeof valueZ +> : ^^^^^^^^^^^^^ +>"should be export namespace" : "should be export namespace" +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +export { type someType as "" }; +>someType : any +> : ^^^ +>"" : any +> : ^^^ + +import { type "" as typeA } from "./arbitraryModuleNamespaceIdentifiers_module"; +>typeA : any +> : ^^^ + +const importTest: typeA = "expect error about someType"; +>importTest : "someType" +> : ^^^^^^^^^^ +>"expect error about someType" : "expect error about someType" +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +export { type "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; +>"" : any +> : ^^^ + +import { type "" as typeB } from "./arbitraryModuleNamespaceIdentifiers_module"; +>typeB : any +> : ^^^ + +const reimportTest: typeB = "expect error about someType"; +>reimportTest : "someType" +> : ^^^^^^^^^^ +>"expect error about someType" : "expect error about someType" +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +export type * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; +>"" : typeof valueZ +> : ^^^^^^^^^^^^^ + +import { type "" as typeC } from "./arbitraryModuleNamespaceIdentifiers_module"; +>typeC : typeof valueZ +> : ^^^^^^^^^^^^^ + +export type otherType = "otherType"; +>otherType : "otherType" +> : ^^^^^^^^^^^ + +const importStarTestA: typeC.otherType = "expect error about otherType"; +>importStarTestA : "otherType" +> : ^^^^^^^^^^^ +>typeC : any +> : ^^^ +>"expect error about otherType" : "expect error about otherType" +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + diff --git a/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=commonjs).errors.txt b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=commonjs).errors.txt new file mode 100644 index 0000000000000..cc359bceb4904 --- /dev/null +++ b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=commonjs).errors.txt @@ -0,0 +1,42 @@ +arbitraryModuleNamespaceIdentifiers_module.ts(20,7): error TS2322: Type '"expect error about someType"' is not assignable to type '"someType"'. +arbitraryModuleNamespaceIdentifiers_module.ts(24,7): error TS2322: Type '"expect error about someType"' is not assignable to type '"someType"'. +arbitraryModuleNamespaceIdentifiers_module.ts(29,7): error TS2322: Type '"expect error about otherType"' is not assignable to type '"otherType"'. + + +==== arbitraryModuleNamespaceIdentifiers_module.ts (3 errors) ==== + const someValue = "someValue"; + type someType = "someType"; + + export { someValue as "" }; + import { "" as valueX } from "./arbitraryModuleNamespaceIdentifiers_module"; + if (valueX !== "someValue") throw "should be someValue"; + + export { "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; + import { "" as valueY } from "./arbitraryModuleNamespaceIdentifiers_module"; + if (valueY !== "someValue") throw "should be someValue"; + + export * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; + import { "" as valueZ } from "./arbitraryModuleNamespaceIdentifiers_module"; + if (valueZ[""] !== "someValue") throw "should be someValue"; + if (valueZ[""] !== "someValue") throw "should be someValue"; + if (valueZ[""] !== valueZ) throw "should be export namespace"; + + export { type someType as "" }; + import { type "" as typeA } from "./arbitraryModuleNamespaceIdentifiers_module"; + const importTest: typeA = "expect error about someType"; + ~~~~~~~~~~ +!!! error TS2322: Type '"expect error about someType"' is not assignable to type '"someType"'. + + export { type "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; + import { type "" as typeB } from "./arbitraryModuleNamespaceIdentifiers_module"; + const reimportTest: typeB = "expect error about someType"; + ~~~~~~~~~~~~ +!!! error TS2322: Type '"expect error about someType"' is not assignable to type '"someType"'. + + export type * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; + import { type "" as typeC } from "./arbitraryModuleNamespaceIdentifiers_module"; + export type otherType = "otherType"; + const importStarTestA: typeC.otherType = "expect error about otherType"; + ~~~~~~~~~~~~~~~ +!!! error TS2322: Type '"expect error about otherType"' is not assignable to type '"otherType"'. + \ No newline at end of file diff --git a/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=commonjs).js b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=commonjs).js new file mode 100644 index 0000000000000..43f95451590dc --- /dev/null +++ b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=commonjs).js @@ -0,0 +1,71 @@ +//// [tests/cases/conformance/es2022/arbitraryModuleNamespaceIdentifiers/arbitraryModuleNamespaceIdentifiers_module.ts] //// + +//// [arbitraryModuleNamespaceIdentifiers_module.ts] +const someValue = "someValue"; +type someType = "someType"; + +export { someValue as "" }; +import { "" as valueX } from "./arbitraryModuleNamespaceIdentifiers_module"; +if (valueX !== "someValue") throw "should be someValue"; + +export { "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; +import { "" as valueY } from "./arbitraryModuleNamespaceIdentifiers_module"; +if (valueY !== "someValue") throw "should be someValue"; + +export * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; +import { "" as valueZ } from "./arbitraryModuleNamespaceIdentifiers_module"; +if (valueZ[""] !== "someValue") throw "should be someValue"; +if (valueZ[""] !== "someValue") throw "should be someValue"; +if (valueZ[""] !== valueZ) throw "should be export namespace"; + +export { type someType as "" }; +import { type "" as typeA } from "./arbitraryModuleNamespaceIdentifiers_module"; +const importTest: typeA = "expect error about someType"; + +export { type "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; +import { type "" as typeB } from "./arbitraryModuleNamespaceIdentifiers_module"; +const reimportTest: typeB = "expect error about someType"; + +export type * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; +import { type "" as typeC } from "./arbitraryModuleNamespaceIdentifiers_module"; +export type otherType = "otherType"; +const importStarTestA: typeC.otherType = "expect error about otherType"; + + +//// [arbitraryModuleNamespaceIdentifiers_module.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports[""] = exports[""] = exports[""] = void 0; +const someValue = "someValue"; +exports[""] = someValue; +const arbitraryModuleNamespaceIdentifiers_module_1 = require("./arbitraryModuleNamespaceIdentifiers_module"); +if (arbitraryModuleNamespaceIdentifiers_module_1[""] !== "someValue") + throw "should be someValue"; +var arbitraryModuleNamespaceIdentifiers_module_2 = require("./arbitraryModuleNamespaceIdentifiers_module"); +Object.defineProperty(exports, "", { enumerable: true, get: function () { return arbitraryModuleNamespaceIdentifiers_module_2[""]; } }); +const arbitraryModuleNamespaceIdentifiers_module_3 = require("./arbitraryModuleNamespaceIdentifiers_module"); +if (arbitraryModuleNamespaceIdentifiers_module_3[""] !== "someValue") + throw "should be someValue"; +exports[""] = require("./arbitraryModuleNamespaceIdentifiers_module"); +const arbitraryModuleNamespaceIdentifiers_module_4 = require("./arbitraryModuleNamespaceIdentifiers_module"); +if (arbitraryModuleNamespaceIdentifiers_module_4[""][""] !== "someValue") + throw "should be someValue"; +if (arbitraryModuleNamespaceIdentifiers_module_4[""][""] !== "someValue") + throw "should be someValue"; +if (arbitraryModuleNamespaceIdentifiers_module_4[""][""] !== arbitraryModuleNamespaceIdentifiers_module_4[""]) + throw "should be export namespace"; +const importTest = "expect error about someType"; +const reimportTest = "expect error about someType"; +const importStarTestA = "expect error about otherType"; + + +//// [arbitraryModuleNamespaceIdentifiers_module.d.ts] +declare const someValue = "someValue"; +type someType = "someType"; +export { someValue as "" }; +export { "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; +export * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; +export { type someType as "" }; +export { type "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; +export type * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; +export type otherType = "otherType"; diff --git a/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=commonjs).symbols b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=commonjs).symbols new file mode 100644 index 0000000000000..a792b7d3f5280 --- /dev/null +++ b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=commonjs).symbols @@ -0,0 +1,82 @@ +//// [tests/cases/conformance/es2022/arbitraryModuleNamespaceIdentifiers/arbitraryModuleNamespaceIdentifiers_module.ts] //// + +=== arbitraryModuleNamespaceIdentifiers_module.ts === +const someValue = "someValue"; +>someValue : Symbol(someValue, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 0, 5)) + +type someType = "someType"; +>someType : Symbol(someType, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 0, 30)) + +export { someValue as "" }; +>someValue : Symbol(someValue, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 0, 5)) +>"" : Symbol(valueZ[""], Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 3, 8)) + +import { "" as valueX } from "./arbitraryModuleNamespaceIdentifiers_module"; +>valueX : Symbol(valueX, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 4, 8)) + +if (valueX !== "someValue") throw "should be someValue"; +>valueX : Symbol(valueX, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 4, 8)) + +export { "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; +>"" : Symbol(valueZ[""], Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 7, 8)) + +import { "" as valueY } from "./arbitraryModuleNamespaceIdentifiers_module"; +>valueY : Symbol(valueY, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 8, 8)) + +if (valueY !== "someValue") throw "should be someValue"; +>valueY : Symbol(valueY, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 8, 8)) + +export * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; +>"" : Symbol(valueZ[""], Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 11, 6)) + +import { "" as valueZ } from "./arbitraryModuleNamespaceIdentifiers_module"; +>valueZ : Symbol(valueZ, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 12, 8)) + +if (valueZ[""] !== "someValue") throw "should be someValue"; +>valueZ : Symbol(valueZ, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 12, 8)) +>"" : Symbol(valueZ[""], Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 3, 8)) + +if (valueZ[""] !== "someValue") throw "should be someValue"; +>valueZ : Symbol(valueZ, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 12, 8)) +>"" : Symbol(valueZ[""], Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 7, 8)) + +if (valueZ[""] !== valueZ) throw "should be export namespace"; +>valueZ : Symbol(valueZ, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 12, 8)) +>"" : Symbol(valueZ[""], Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 11, 6)) +>valueZ : Symbol(valueZ, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 12, 8)) + +export { type someType as "" }; +>someType : Symbol(someType, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 0, 30)) +>"" : Symbol(valueZ[""], Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 17, 8)) + +import { type "" as typeA } from "./arbitraryModuleNamespaceIdentifiers_module"; +>typeA : Symbol(typeA, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 18, 8)) + +const importTest: typeA = "expect error about someType"; +>importTest : Symbol(importTest, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 19, 5)) +>typeA : Symbol(typeA, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 18, 8)) + +export { type "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; +>"" : Symbol(valueZ[""], Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 21, 8)) + +import { type "" as typeB } from "./arbitraryModuleNamespaceIdentifiers_module"; +>typeB : Symbol(typeB, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 22, 8)) + +const reimportTest: typeB = "expect error about someType"; +>reimportTest : Symbol(reimportTest, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 23, 5)) +>typeB : Symbol(typeB, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 22, 8)) + +export type * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; +>"" : Symbol(valueZ[""], Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 25, 11)) + +import { type "" as typeC } from "./arbitraryModuleNamespaceIdentifiers_module"; +>typeC : Symbol(typeC, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 26, 8)) + +export type otherType = "otherType"; +>otherType : Symbol(valueZ.otherType, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 26, 83)) + +const importStarTestA: typeC.otherType = "expect error about otherType"; +>importStarTestA : Symbol(importStarTestA, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 28, 5)) +>typeC : Symbol(typeC, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 26, 8)) +>otherType : Symbol(valueZ.otherType, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 26, 83)) + diff --git a/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=commonjs).types b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=commonjs).types new file mode 100644 index 0000000000000..4574f9754d0b4 --- /dev/null +++ b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=commonjs).types @@ -0,0 +1,151 @@ +//// [tests/cases/conformance/es2022/arbitraryModuleNamespaceIdentifiers/arbitraryModuleNamespaceIdentifiers_module.ts] //// + +=== arbitraryModuleNamespaceIdentifiers_module.ts === +const someValue = "someValue"; +>someValue : "someValue" +> : ^^^^^^^^^^^ +>"someValue" : "someValue" +> : ^^^^^^^^^^^ + +type someType = "someType"; +>someType : "someType" +> : ^^^^^^^^^^ + +export { someValue as "" }; +>someValue : "someValue" +> : ^^^^^^^^^^^ +>"" : "someValue" +> : ^^^^^^^^^^^ + +import { "" as valueX } from "./arbitraryModuleNamespaceIdentifiers_module"; +>valueX : "someValue" +> : ^^^^^^^^^^^ + +if (valueX !== "someValue") throw "should be someValue"; +>valueX !== "someValue" : boolean +> : ^^^^^^^ +>valueX : "someValue" +> : ^^^^^^^^^^^ +>"someValue" : "someValue" +> : ^^^^^^^^^^^ +>"should be someValue" : "should be someValue" +> : ^^^^^^^^^^^^^^^^^^^^^ + +export { "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; +>"" : "someValue" +> : ^^^^^^^^^^^ + +import { "" as valueY } from "./arbitraryModuleNamespaceIdentifiers_module"; +>valueY : "someValue" +> : ^^^^^^^^^^^ + +if (valueY !== "someValue") throw "should be someValue"; +>valueY !== "someValue" : boolean +> : ^^^^^^^ +>valueY : "someValue" +> : ^^^^^^^^^^^ +>"someValue" : "someValue" +> : ^^^^^^^^^^^ +>"should be someValue" : "should be someValue" +> : ^^^^^^^^^^^^^^^^^^^^^ + +export * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; +>"" : typeof valueZ +> : ^^^^^^^^^^^^^ + +import { "" as valueZ } from "./arbitraryModuleNamespaceIdentifiers_module"; +>valueZ : typeof valueZ +> : ^^^^^^^^^^^^^ + +if (valueZ[""] !== "someValue") throw "should be someValue"; +>valueZ[""] !== "someValue" : boolean +> : ^^^^^^^ +>valueZ[""] : "someValue" +> : ^^^^^^^^^^^ +>valueZ : typeof valueZ +> : ^^^^^^^^^^^^^ +>"" : "" +> : ^^^^^ +>"someValue" : "someValue" +> : ^^^^^^^^^^^ +>"should be someValue" : "should be someValue" +> : ^^^^^^^^^^^^^^^^^^^^^ + +if (valueZ[""] !== "someValue") throw "should be someValue"; +>valueZ[""] !== "someValue" : boolean +> : ^^^^^^^ +>valueZ[""] : "someValue" +> : ^^^^^^^^^^^ +>valueZ : typeof valueZ +> : ^^^^^^^^^^^^^ +>"" : "" +> : ^^^^^ +>"someValue" : "someValue" +> : ^^^^^^^^^^^ +>"should be someValue" : "should be someValue" +> : ^^^^^^^^^^^^^^^^^^^^^ + +if (valueZ[""] !== valueZ) throw "should be export namespace"; +>valueZ[""] !== valueZ : boolean +> : ^^^^^^^ +>valueZ[""] : typeof valueZ +> : ^^^^^^^^^^^^^ +>valueZ : typeof valueZ +> : ^^^^^^^^^^^^^ +>"" : "" +> : ^^^^^ +>valueZ : typeof valueZ +> : ^^^^^^^^^^^^^ +>"should be export namespace" : "should be export namespace" +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +export { type someType as "" }; +>someType : any +> : ^^^ +>"" : any +> : ^^^ + +import { type "" as typeA } from "./arbitraryModuleNamespaceIdentifiers_module"; +>typeA : any +> : ^^^ + +const importTest: typeA = "expect error about someType"; +>importTest : "someType" +> : ^^^^^^^^^^ +>"expect error about someType" : "expect error about someType" +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +export { type "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; +>"" : any +> : ^^^ + +import { type "" as typeB } from "./arbitraryModuleNamespaceIdentifiers_module"; +>typeB : any +> : ^^^ + +const reimportTest: typeB = "expect error about someType"; +>reimportTest : "someType" +> : ^^^^^^^^^^ +>"expect error about someType" : "expect error about someType" +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +export type * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; +>"" : typeof valueZ +> : ^^^^^^^^^^^^^ + +import { type "" as typeC } from "./arbitraryModuleNamespaceIdentifiers_module"; +>typeC : typeof valueZ +> : ^^^^^^^^^^^^^ + +export type otherType = "otherType"; +>otherType : "otherType" +> : ^^^^^^^^^^^ + +const importStarTestA: typeC.otherType = "expect error about otherType"; +>importStarTestA : "otherType" +> : ^^^^^^^^^^^ +>typeC : any +> : ^^^ +>"expect error about otherType" : "expect error about otherType" +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + diff --git a/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=es2020).errors.txt b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=es2020).errors.txt new file mode 100644 index 0000000000000..e2a851b5a7bd3 --- /dev/null +++ b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=es2020).errors.txt @@ -0,0 +1,84 @@ +arbitraryModuleNamespaceIdentifiers_module.ts(4,23): error TS18057: String literal import and export names are not supported when the '--module' flag is set to 'es2015' or 'es2020'. +arbitraryModuleNamespaceIdentifiers_module.ts(5,10): error TS18057: String literal import and export names are not supported when the '--module' flag is set to 'es2015' or 'es2020'. +arbitraryModuleNamespaceIdentifiers_module.ts(8,10): error TS18057: String literal import and export names are not supported when the '--module' flag is set to 'es2015' or 'es2020'. +arbitraryModuleNamespaceIdentifiers_module.ts(8,19): error TS18057: String literal import and export names are not supported when the '--module' flag is set to 'es2015' or 'es2020'. +arbitraryModuleNamespaceIdentifiers_module.ts(9,10): error TS18057: String literal import and export names are not supported when the '--module' flag is set to 'es2015' or 'es2020'. +arbitraryModuleNamespaceIdentifiers_module.ts(12,13): error TS18057: String literal import and export names are not supported when the '--module' flag is set to 'es2015' or 'es2020'. +arbitraryModuleNamespaceIdentifiers_module.ts(13,10): error TS18057: String literal import and export names are not supported when the '--module' flag is set to 'es2015' or 'es2020'. +arbitraryModuleNamespaceIdentifiers_module.ts(18,27): error TS18057: String literal import and export names are not supported when the '--module' flag is set to 'es2015' or 'es2020'. +arbitraryModuleNamespaceIdentifiers_module.ts(19,15): error TS18057: String literal import and export names are not supported when the '--module' flag is set to 'es2015' or 'es2020'. +arbitraryModuleNamespaceIdentifiers_module.ts(20,7): error TS2322: Type '"expect error about someType"' is not assignable to type '"someType"'. +arbitraryModuleNamespaceIdentifiers_module.ts(22,15): error TS18057: String literal import and export names are not supported when the '--module' flag is set to 'es2015' or 'es2020'. +arbitraryModuleNamespaceIdentifiers_module.ts(22,24): error TS18057: String literal import and export names are not supported when the '--module' flag is set to 'es2015' or 'es2020'. +arbitraryModuleNamespaceIdentifiers_module.ts(23,15): error TS18057: String literal import and export names are not supported when the '--module' flag is set to 'es2015' or 'es2020'. +arbitraryModuleNamespaceIdentifiers_module.ts(24,7): error TS2322: Type '"expect error about someType"' is not assignable to type '"someType"'. +arbitraryModuleNamespaceIdentifiers_module.ts(26,18): error TS18057: String literal import and export names are not supported when the '--module' flag is set to 'es2015' or 'es2020'. +arbitraryModuleNamespaceIdentifiers_module.ts(27,15): error TS18057: String literal import and export names are not supported when the '--module' flag is set to 'es2015' or 'es2020'. +arbitraryModuleNamespaceIdentifiers_module.ts(29,7): error TS2322: Type '"expect error about otherType"' is not assignable to type '"otherType"'. + + +==== arbitraryModuleNamespaceIdentifiers_module.ts (17 errors) ==== + const someValue = "someValue"; + type someType = "someType"; + + export { someValue as "" }; + ~~~~~ +!!! error TS18057: String literal import and export names are not supported when the '--module' flag is set to 'es2015' or 'es2020'. + import { "" as valueX } from "./arbitraryModuleNamespaceIdentifiers_module"; + ~~~~~ +!!! error TS18057: String literal import and export names are not supported when the '--module' flag is set to 'es2015' or 'es2020'. + if (valueX !== "someValue") throw "should be someValue"; + + export { "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; + ~~~~~ +!!! error TS18057: String literal import and export names are not supported when the '--module' flag is set to 'es2015' or 'es2020'. + ~~~~~ +!!! error TS18057: String literal import and export names are not supported when the '--module' flag is set to 'es2015' or 'es2020'. + import { "" as valueY } from "./arbitraryModuleNamespaceIdentifiers_module"; + ~~~~~ +!!! error TS18057: String literal import and export names are not supported when the '--module' flag is set to 'es2015' or 'es2020'. + if (valueY !== "someValue") throw "should be someValue"; + + export * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; + ~~~~~ +!!! error TS18057: String literal import and export names are not supported when the '--module' flag is set to 'es2015' or 'es2020'. + import { "" as valueZ } from "./arbitraryModuleNamespaceIdentifiers_module"; + ~~~~~ +!!! error TS18057: String literal import and export names are not supported when the '--module' flag is set to 'es2015' or 'es2020'. + if (valueZ[""] !== "someValue") throw "should be someValue"; + if (valueZ[""] !== "someValue") throw "should be someValue"; + if (valueZ[""] !== valueZ) throw "should be export namespace"; + + export { type someType as "" }; + ~~~~~ +!!! error TS18057: String literal import and export names are not supported when the '--module' flag is set to 'es2015' or 'es2020'. + import { type "" as typeA } from "./arbitraryModuleNamespaceIdentifiers_module"; + ~~~~~ +!!! error TS18057: String literal import and export names are not supported when the '--module' flag is set to 'es2015' or 'es2020'. + const importTest: typeA = "expect error about someType"; + ~~~~~~~~~~ +!!! error TS2322: Type '"expect error about someType"' is not assignable to type '"someType"'. + + export { type "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; + ~~~~~ +!!! error TS18057: String literal import and export names are not supported when the '--module' flag is set to 'es2015' or 'es2020'. + ~~~~~ +!!! error TS18057: String literal import and export names are not supported when the '--module' flag is set to 'es2015' or 'es2020'. + import { type "" as typeB } from "./arbitraryModuleNamespaceIdentifiers_module"; + ~~~~~ +!!! error TS18057: String literal import and export names are not supported when the '--module' flag is set to 'es2015' or 'es2020'. + const reimportTest: typeB = "expect error about someType"; + ~~~~~~~~~~~~ +!!! error TS2322: Type '"expect error about someType"' is not assignable to type '"someType"'. + + export type * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; + ~~~~~ +!!! error TS18057: String literal import and export names are not supported when the '--module' flag is set to 'es2015' or 'es2020'. + import { type "" as typeC } from "./arbitraryModuleNamespaceIdentifiers_module"; + ~~~~~ +!!! error TS18057: String literal import and export names are not supported when the '--module' flag is set to 'es2015' or 'es2020'. + export type otherType = "otherType"; + const importStarTestA: typeC.otherType = "expect error about otherType"; + ~~~~~~~~~~~~~~~ +!!! error TS2322: Type '"expect error about otherType"' is not assignable to type '"otherType"'. + \ No newline at end of file diff --git a/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=es2020).js b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=es2020).js new file mode 100644 index 0000000000000..4964f684a1ed0 --- /dev/null +++ b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=es2020).js @@ -0,0 +1,67 @@ +//// [tests/cases/conformance/es2022/arbitraryModuleNamespaceIdentifiers/arbitraryModuleNamespaceIdentifiers_module.ts] //// + +//// [arbitraryModuleNamespaceIdentifiers_module.ts] +const someValue = "someValue"; +type someType = "someType"; + +export { someValue as "" }; +import { "" as valueX } from "./arbitraryModuleNamespaceIdentifiers_module"; +if (valueX !== "someValue") throw "should be someValue"; + +export { "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; +import { "" as valueY } from "./arbitraryModuleNamespaceIdentifiers_module"; +if (valueY !== "someValue") throw "should be someValue"; + +export * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; +import { "" as valueZ } from "./arbitraryModuleNamespaceIdentifiers_module"; +if (valueZ[""] !== "someValue") throw "should be someValue"; +if (valueZ[""] !== "someValue") throw "should be someValue"; +if (valueZ[""] !== valueZ) throw "should be export namespace"; + +export { type someType as "" }; +import { type "" as typeA } from "./arbitraryModuleNamespaceIdentifiers_module"; +const importTest: typeA = "expect error about someType"; + +export { type "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; +import { type "" as typeB } from "./arbitraryModuleNamespaceIdentifiers_module"; +const reimportTest: typeB = "expect error about someType"; + +export type * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; +import { type "" as typeC } from "./arbitraryModuleNamespaceIdentifiers_module"; +export type otherType = "otherType"; +const importStarTestA: typeC.otherType = "expect error about otherType"; + + +//// [arbitraryModuleNamespaceIdentifiers_module.js] +const someValue = "someValue"; +export { someValue as "" }; +import { "" as valueX } from "./arbitraryModuleNamespaceIdentifiers_module"; +if (valueX !== "someValue") + throw "should be someValue"; +export { "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; +import { "" as valueY } from "./arbitraryModuleNamespaceIdentifiers_module"; +if (valueY !== "someValue") + throw "should be someValue"; +export * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; +import { "" as valueZ } from "./arbitraryModuleNamespaceIdentifiers_module"; +if (valueZ[""] !== "someValue") + throw "should be someValue"; +if (valueZ[""] !== "someValue") + throw "should be someValue"; +if (valueZ[""] !== valueZ) + throw "should be export namespace"; +const importTest = "expect error about someType"; +const reimportTest = "expect error about someType"; +const importStarTestA = "expect error about otherType"; + + +//// [arbitraryModuleNamespaceIdentifiers_module.d.ts] +declare const someValue = "someValue"; +type someType = "someType"; +export { someValue as "" }; +export { "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; +export * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; +export { type someType as "" }; +export { type "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; +export type * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; +export type otherType = "otherType"; diff --git a/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=es2020).symbols b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=es2020).symbols new file mode 100644 index 0000000000000..a792b7d3f5280 --- /dev/null +++ b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=es2020).symbols @@ -0,0 +1,82 @@ +//// [tests/cases/conformance/es2022/arbitraryModuleNamespaceIdentifiers/arbitraryModuleNamespaceIdentifiers_module.ts] //// + +=== arbitraryModuleNamespaceIdentifiers_module.ts === +const someValue = "someValue"; +>someValue : Symbol(someValue, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 0, 5)) + +type someType = "someType"; +>someType : Symbol(someType, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 0, 30)) + +export { someValue as "" }; +>someValue : Symbol(someValue, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 0, 5)) +>"" : Symbol(valueZ[""], Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 3, 8)) + +import { "" as valueX } from "./arbitraryModuleNamespaceIdentifiers_module"; +>valueX : Symbol(valueX, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 4, 8)) + +if (valueX !== "someValue") throw "should be someValue"; +>valueX : Symbol(valueX, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 4, 8)) + +export { "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; +>"" : Symbol(valueZ[""], Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 7, 8)) + +import { "" as valueY } from "./arbitraryModuleNamespaceIdentifiers_module"; +>valueY : Symbol(valueY, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 8, 8)) + +if (valueY !== "someValue") throw "should be someValue"; +>valueY : Symbol(valueY, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 8, 8)) + +export * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; +>"" : Symbol(valueZ[""], Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 11, 6)) + +import { "" as valueZ } from "./arbitraryModuleNamespaceIdentifiers_module"; +>valueZ : Symbol(valueZ, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 12, 8)) + +if (valueZ[""] !== "someValue") throw "should be someValue"; +>valueZ : Symbol(valueZ, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 12, 8)) +>"" : Symbol(valueZ[""], Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 3, 8)) + +if (valueZ[""] !== "someValue") throw "should be someValue"; +>valueZ : Symbol(valueZ, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 12, 8)) +>"" : Symbol(valueZ[""], Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 7, 8)) + +if (valueZ[""] !== valueZ) throw "should be export namespace"; +>valueZ : Symbol(valueZ, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 12, 8)) +>"" : Symbol(valueZ[""], Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 11, 6)) +>valueZ : Symbol(valueZ, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 12, 8)) + +export { type someType as "" }; +>someType : Symbol(someType, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 0, 30)) +>"" : Symbol(valueZ[""], Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 17, 8)) + +import { type "" as typeA } from "./arbitraryModuleNamespaceIdentifiers_module"; +>typeA : Symbol(typeA, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 18, 8)) + +const importTest: typeA = "expect error about someType"; +>importTest : Symbol(importTest, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 19, 5)) +>typeA : Symbol(typeA, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 18, 8)) + +export { type "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; +>"" : Symbol(valueZ[""], Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 21, 8)) + +import { type "" as typeB } from "./arbitraryModuleNamespaceIdentifiers_module"; +>typeB : Symbol(typeB, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 22, 8)) + +const reimportTest: typeB = "expect error about someType"; +>reimportTest : Symbol(reimportTest, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 23, 5)) +>typeB : Symbol(typeB, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 22, 8)) + +export type * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; +>"" : Symbol(valueZ[""], Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 25, 11)) + +import { type "" as typeC } from "./arbitraryModuleNamespaceIdentifiers_module"; +>typeC : Symbol(typeC, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 26, 8)) + +export type otherType = "otherType"; +>otherType : Symbol(valueZ.otherType, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 26, 83)) + +const importStarTestA: typeC.otherType = "expect error about otherType"; +>importStarTestA : Symbol(importStarTestA, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 28, 5)) +>typeC : Symbol(typeC, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 26, 8)) +>otherType : Symbol(valueZ.otherType, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 26, 83)) + diff --git a/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=es2020).types b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=es2020).types new file mode 100644 index 0000000000000..4574f9754d0b4 --- /dev/null +++ b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=es2020).types @@ -0,0 +1,151 @@ +//// [tests/cases/conformance/es2022/arbitraryModuleNamespaceIdentifiers/arbitraryModuleNamespaceIdentifiers_module.ts] //// + +=== arbitraryModuleNamespaceIdentifiers_module.ts === +const someValue = "someValue"; +>someValue : "someValue" +> : ^^^^^^^^^^^ +>"someValue" : "someValue" +> : ^^^^^^^^^^^ + +type someType = "someType"; +>someType : "someType" +> : ^^^^^^^^^^ + +export { someValue as "" }; +>someValue : "someValue" +> : ^^^^^^^^^^^ +>"" : "someValue" +> : ^^^^^^^^^^^ + +import { "" as valueX } from "./arbitraryModuleNamespaceIdentifiers_module"; +>valueX : "someValue" +> : ^^^^^^^^^^^ + +if (valueX !== "someValue") throw "should be someValue"; +>valueX !== "someValue" : boolean +> : ^^^^^^^ +>valueX : "someValue" +> : ^^^^^^^^^^^ +>"someValue" : "someValue" +> : ^^^^^^^^^^^ +>"should be someValue" : "should be someValue" +> : ^^^^^^^^^^^^^^^^^^^^^ + +export { "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; +>"" : "someValue" +> : ^^^^^^^^^^^ + +import { "" as valueY } from "./arbitraryModuleNamespaceIdentifiers_module"; +>valueY : "someValue" +> : ^^^^^^^^^^^ + +if (valueY !== "someValue") throw "should be someValue"; +>valueY !== "someValue" : boolean +> : ^^^^^^^ +>valueY : "someValue" +> : ^^^^^^^^^^^ +>"someValue" : "someValue" +> : ^^^^^^^^^^^ +>"should be someValue" : "should be someValue" +> : ^^^^^^^^^^^^^^^^^^^^^ + +export * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; +>"" : typeof valueZ +> : ^^^^^^^^^^^^^ + +import { "" as valueZ } from "./arbitraryModuleNamespaceIdentifiers_module"; +>valueZ : typeof valueZ +> : ^^^^^^^^^^^^^ + +if (valueZ[""] !== "someValue") throw "should be someValue"; +>valueZ[""] !== "someValue" : boolean +> : ^^^^^^^ +>valueZ[""] : "someValue" +> : ^^^^^^^^^^^ +>valueZ : typeof valueZ +> : ^^^^^^^^^^^^^ +>"" : "" +> : ^^^^^ +>"someValue" : "someValue" +> : ^^^^^^^^^^^ +>"should be someValue" : "should be someValue" +> : ^^^^^^^^^^^^^^^^^^^^^ + +if (valueZ[""] !== "someValue") throw "should be someValue"; +>valueZ[""] !== "someValue" : boolean +> : ^^^^^^^ +>valueZ[""] : "someValue" +> : ^^^^^^^^^^^ +>valueZ : typeof valueZ +> : ^^^^^^^^^^^^^ +>"" : "" +> : ^^^^^ +>"someValue" : "someValue" +> : ^^^^^^^^^^^ +>"should be someValue" : "should be someValue" +> : ^^^^^^^^^^^^^^^^^^^^^ + +if (valueZ[""] !== valueZ) throw "should be export namespace"; +>valueZ[""] !== valueZ : boolean +> : ^^^^^^^ +>valueZ[""] : typeof valueZ +> : ^^^^^^^^^^^^^ +>valueZ : typeof valueZ +> : ^^^^^^^^^^^^^ +>"" : "" +> : ^^^^^ +>valueZ : typeof valueZ +> : ^^^^^^^^^^^^^ +>"should be export namespace" : "should be export namespace" +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +export { type someType as "" }; +>someType : any +> : ^^^ +>"" : any +> : ^^^ + +import { type "" as typeA } from "./arbitraryModuleNamespaceIdentifiers_module"; +>typeA : any +> : ^^^ + +const importTest: typeA = "expect error about someType"; +>importTest : "someType" +> : ^^^^^^^^^^ +>"expect error about someType" : "expect error about someType" +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +export { type "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; +>"" : any +> : ^^^ + +import { type "" as typeB } from "./arbitraryModuleNamespaceIdentifiers_module"; +>typeB : any +> : ^^^ + +const reimportTest: typeB = "expect error about someType"; +>reimportTest : "someType" +> : ^^^^^^^^^^ +>"expect error about someType" : "expect error about someType" +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +export type * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; +>"" : typeof valueZ +> : ^^^^^^^^^^^^^ + +import { type "" as typeC } from "./arbitraryModuleNamespaceIdentifiers_module"; +>typeC : typeof valueZ +> : ^^^^^^^^^^^^^ + +export type otherType = "otherType"; +>otherType : "otherType" +> : ^^^^^^^^^^^ + +const importStarTestA: typeC.otherType = "expect error about otherType"; +>importStarTestA : "otherType" +> : ^^^^^^^^^^^ +>typeC : any +> : ^^^ +>"expect error about otherType" : "expect error about otherType" +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + diff --git a/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=es2022).errors.txt b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=es2022).errors.txt new file mode 100644 index 0000000000000..cc359bceb4904 --- /dev/null +++ b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=es2022).errors.txt @@ -0,0 +1,42 @@ +arbitraryModuleNamespaceIdentifiers_module.ts(20,7): error TS2322: Type '"expect error about someType"' is not assignable to type '"someType"'. +arbitraryModuleNamespaceIdentifiers_module.ts(24,7): error TS2322: Type '"expect error about someType"' is not assignable to type '"someType"'. +arbitraryModuleNamespaceIdentifiers_module.ts(29,7): error TS2322: Type '"expect error about otherType"' is not assignable to type '"otherType"'. + + +==== arbitraryModuleNamespaceIdentifiers_module.ts (3 errors) ==== + const someValue = "someValue"; + type someType = "someType"; + + export { someValue as "" }; + import { "" as valueX } from "./arbitraryModuleNamespaceIdentifiers_module"; + if (valueX !== "someValue") throw "should be someValue"; + + export { "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; + import { "" as valueY } from "./arbitraryModuleNamespaceIdentifiers_module"; + if (valueY !== "someValue") throw "should be someValue"; + + export * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; + import { "" as valueZ } from "./arbitraryModuleNamespaceIdentifiers_module"; + if (valueZ[""] !== "someValue") throw "should be someValue"; + if (valueZ[""] !== "someValue") throw "should be someValue"; + if (valueZ[""] !== valueZ) throw "should be export namespace"; + + export { type someType as "" }; + import { type "" as typeA } from "./arbitraryModuleNamespaceIdentifiers_module"; + const importTest: typeA = "expect error about someType"; + ~~~~~~~~~~ +!!! error TS2322: Type '"expect error about someType"' is not assignable to type '"someType"'. + + export { type "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; + import { type "" as typeB } from "./arbitraryModuleNamespaceIdentifiers_module"; + const reimportTest: typeB = "expect error about someType"; + ~~~~~~~~~~~~ +!!! error TS2322: Type '"expect error about someType"' is not assignable to type '"someType"'. + + export type * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; + import { type "" as typeC } from "./arbitraryModuleNamespaceIdentifiers_module"; + export type otherType = "otherType"; + const importStarTestA: typeC.otherType = "expect error about otherType"; + ~~~~~~~~~~~~~~~ +!!! error TS2322: Type '"expect error about otherType"' is not assignable to type '"otherType"'. + \ No newline at end of file diff --git a/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=es2022).js b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=es2022).js new file mode 100644 index 0000000000000..4964f684a1ed0 --- /dev/null +++ b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=es2022).js @@ -0,0 +1,67 @@ +//// [tests/cases/conformance/es2022/arbitraryModuleNamespaceIdentifiers/arbitraryModuleNamespaceIdentifiers_module.ts] //// + +//// [arbitraryModuleNamespaceIdentifiers_module.ts] +const someValue = "someValue"; +type someType = "someType"; + +export { someValue as "" }; +import { "" as valueX } from "./arbitraryModuleNamespaceIdentifiers_module"; +if (valueX !== "someValue") throw "should be someValue"; + +export { "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; +import { "" as valueY } from "./arbitraryModuleNamespaceIdentifiers_module"; +if (valueY !== "someValue") throw "should be someValue"; + +export * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; +import { "" as valueZ } from "./arbitraryModuleNamespaceIdentifiers_module"; +if (valueZ[""] !== "someValue") throw "should be someValue"; +if (valueZ[""] !== "someValue") throw "should be someValue"; +if (valueZ[""] !== valueZ) throw "should be export namespace"; + +export { type someType as "" }; +import { type "" as typeA } from "./arbitraryModuleNamespaceIdentifiers_module"; +const importTest: typeA = "expect error about someType"; + +export { type "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; +import { type "" as typeB } from "./arbitraryModuleNamespaceIdentifiers_module"; +const reimportTest: typeB = "expect error about someType"; + +export type * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; +import { type "" as typeC } from "./arbitraryModuleNamespaceIdentifiers_module"; +export type otherType = "otherType"; +const importStarTestA: typeC.otherType = "expect error about otherType"; + + +//// [arbitraryModuleNamespaceIdentifiers_module.js] +const someValue = "someValue"; +export { someValue as "" }; +import { "" as valueX } from "./arbitraryModuleNamespaceIdentifiers_module"; +if (valueX !== "someValue") + throw "should be someValue"; +export { "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; +import { "" as valueY } from "./arbitraryModuleNamespaceIdentifiers_module"; +if (valueY !== "someValue") + throw "should be someValue"; +export * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; +import { "" as valueZ } from "./arbitraryModuleNamespaceIdentifiers_module"; +if (valueZ[""] !== "someValue") + throw "should be someValue"; +if (valueZ[""] !== "someValue") + throw "should be someValue"; +if (valueZ[""] !== valueZ) + throw "should be export namespace"; +const importTest = "expect error about someType"; +const reimportTest = "expect error about someType"; +const importStarTestA = "expect error about otherType"; + + +//// [arbitraryModuleNamespaceIdentifiers_module.d.ts] +declare const someValue = "someValue"; +type someType = "someType"; +export { someValue as "" }; +export { "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; +export * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; +export { type someType as "" }; +export { type "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; +export type * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; +export type otherType = "otherType"; diff --git a/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=es2022).symbols b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=es2022).symbols new file mode 100644 index 0000000000000..a792b7d3f5280 --- /dev/null +++ b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=es2022).symbols @@ -0,0 +1,82 @@ +//// [tests/cases/conformance/es2022/arbitraryModuleNamespaceIdentifiers/arbitraryModuleNamespaceIdentifiers_module.ts] //// + +=== arbitraryModuleNamespaceIdentifiers_module.ts === +const someValue = "someValue"; +>someValue : Symbol(someValue, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 0, 5)) + +type someType = "someType"; +>someType : Symbol(someType, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 0, 30)) + +export { someValue as "" }; +>someValue : Symbol(someValue, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 0, 5)) +>"" : Symbol(valueZ[""], Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 3, 8)) + +import { "" as valueX } from "./arbitraryModuleNamespaceIdentifiers_module"; +>valueX : Symbol(valueX, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 4, 8)) + +if (valueX !== "someValue") throw "should be someValue"; +>valueX : Symbol(valueX, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 4, 8)) + +export { "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; +>"" : Symbol(valueZ[""], Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 7, 8)) + +import { "" as valueY } from "./arbitraryModuleNamespaceIdentifiers_module"; +>valueY : Symbol(valueY, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 8, 8)) + +if (valueY !== "someValue") throw "should be someValue"; +>valueY : Symbol(valueY, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 8, 8)) + +export * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; +>"" : Symbol(valueZ[""], Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 11, 6)) + +import { "" as valueZ } from "./arbitraryModuleNamespaceIdentifiers_module"; +>valueZ : Symbol(valueZ, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 12, 8)) + +if (valueZ[""] !== "someValue") throw "should be someValue"; +>valueZ : Symbol(valueZ, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 12, 8)) +>"" : Symbol(valueZ[""], Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 3, 8)) + +if (valueZ[""] !== "someValue") throw "should be someValue"; +>valueZ : Symbol(valueZ, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 12, 8)) +>"" : Symbol(valueZ[""], Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 7, 8)) + +if (valueZ[""] !== valueZ) throw "should be export namespace"; +>valueZ : Symbol(valueZ, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 12, 8)) +>"" : Symbol(valueZ[""], Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 11, 6)) +>valueZ : Symbol(valueZ, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 12, 8)) + +export { type someType as "" }; +>someType : Symbol(someType, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 0, 30)) +>"" : Symbol(valueZ[""], Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 17, 8)) + +import { type "" as typeA } from "./arbitraryModuleNamespaceIdentifiers_module"; +>typeA : Symbol(typeA, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 18, 8)) + +const importTest: typeA = "expect error about someType"; +>importTest : Symbol(importTest, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 19, 5)) +>typeA : Symbol(typeA, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 18, 8)) + +export { type "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; +>"" : Symbol(valueZ[""], Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 21, 8)) + +import { type "" as typeB } from "./arbitraryModuleNamespaceIdentifiers_module"; +>typeB : Symbol(typeB, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 22, 8)) + +const reimportTest: typeB = "expect error about someType"; +>reimportTest : Symbol(reimportTest, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 23, 5)) +>typeB : Symbol(typeB, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 22, 8)) + +export type * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; +>"" : Symbol(valueZ[""], Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 25, 11)) + +import { type "" as typeC } from "./arbitraryModuleNamespaceIdentifiers_module"; +>typeC : Symbol(typeC, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 26, 8)) + +export type otherType = "otherType"; +>otherType : Symbol(valueZ.otherType, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 26, 83)) + +const importStarTestA: typeC.otherType = "expect error about otherType"; +>importStarTestA : Symbol(importStarTestA, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 28, 5)) +>typeC : Symbol(typeC, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 26, 8)) +>otherType : Symbol(valueZ.otherType, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 26, 83)) + diff --git a/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=es2022).types b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=es2022).types new file mode 100644 index 0000000000000..4574f9754d0b4 --- /dev/null +++ b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=es2022).types @@ -0,0 +1,151 @@ +//// [tests/cases/conformance/es2022/arbitraryModuleNamespaceIdentifiers/arbitraryModuleNamespaceIdentifiers_module.ts] //// + +=== arbitraryModuleNamespaceIdentifiers_module.ts === +const someValue = "someValue"; +>someValue : "someValue" +> : ^^^^^^^^^^^ +>"someValue" : "someValue" +> : ^^^^^^^^^^^ + +type someType = "someType"; +>someType : "someType" +> : ^^^^^^^^^^ + +export { someValue as "" }; +>someValue : "someValue" +> : ^^^^^^^^^^^ +>"" : "someValue" +> : ^^^^^^^^^^^ + +import { "" as valueX } from "./arbitraryModuleNamespaceIdentifiers_module"; +>valueX : "someValue" +> : ^^^^^^^^^^^ + +if (valueX !== "someValue") throw "should be someValue"; +>valueX !== "someValue" : boolean +> : ^^^^^^^ +>valueX : "someValue" +> : ^^^^^^^^^^^ +>"someValue" : "someValue" +> : ^^^^^^^^^^^ +>"should be someValue" : "should be someValue" +> : ^^^^^^^^^^^^^^^^^^^^^ + +export { "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; +>"" : "someValue" +> : ^^^^^^^^^^^ + +import { "" as valueY } from "./arbitraryModuleNamespaceIdentifiers_module"; +>valueY : "someValue" +> : ^^^^^^^^^^^ + +if (valueY !== "someValue") throw "should be someValue"; +>valueY !== "someValue" : boolean +> : ^^^^^^^ +>valueY : "someValue" +> : ^^^^^^^^^^^ +>"someValue" : "someValue" +> : ^^^^^^^^^^^ +>"should be someValue" : "should be someValue" +> : ^^^^^^^^^^^^^^^^^^^^^ + +export * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; +>"" : typeof valueZ +> : ^^^^^^^^^^^^^ + +import { "" as valueZ } from "./arbitraryModuleNamespaceIdentifiers_module"; +>valueZ : typeof valueZ +> : ^^^^^^^^^^^^^ + +if (valueZ[""] !== "someValue") throw "should be someValue"; +>valueZ[""] !== "someValue" : boolean +> : ^^^^^^^ +>valueZ[""] : "someValue" +> : ^^^^^^^^^^^ +>valueZ : typeof valueZ +> : ^^^^^^^^^^^^^ +>"" : "" +> : ^^^^^ +>"someValue" : "someValue" +> : ^^^^^^^^^^^ +>"should be someValue" : "should be someValue" +> : ^^^^^^^^^^^^^^^^^^^^^ + +if (valueZ[""] !== "someValue") throw "should be someValue"; +>valueZ[""] !== "someValue" : boolean +> : ^^^^^^^ +>valueZ[""] : "someValue" +> : ^^^^^^^^^^^ +>valueZ : typeof valueZ +> : ^^^^^^^^^^^^^ +>"" : "" +> : ^^^^^ +>"someValue" : "someValue" +> : ^^^^^^^^^^^ +>"should be someValue" : "should be someValue" +> : ^^^^^^^^^^^^^^^^^^^^^ + +if (valueZ[""] !== valueZ) throw "should be export namespace"; +>valueZ[""] !== valueZ : boolean +> : ^^^^^^^ +>valueZ[""] : typeof valueZ +> : ^^^^^^^^^^^^^ +>valueZ : typeof valueZ +> : ^^^^^^^^^^^^^ +>"" : "" +> : ^^^^^ +>valueZ : typeof valueZ +> : ^^^^^^^^^^^^^ +>"should be export namespace" : "should be export namespace" +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +export { type someType as "" }; +>someType : any +> : ^^^ +>"" : any +> : ^^^ + +import { type "" as typeA } from "./arbitraryModuleNamespaceIdentifiers_module"; +>typeA : any +> : ^^^ + +const importTest: typeA = "expect error about someType"; +>importTest : "someType" +> : ^^^^^^^^^^ +>"expect error about someType" : "expect error about someType" +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +export { type "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; +>"" : any +> : ^^^ + +import { type "" as typeB } from "./arbitraryModuleNamespaceIdentifiers_module"; +>typeB : any +> : ^^^ + +const reimportTest: typeB = "expect error about someType"; +>reimportTest : "someType" +> : ^^^^^^^^^^ +>"expect error about someType" : "expect error about someType" +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +export type * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; +>"" : typeof valueZ +> : ^^^^^^^^^^^^^ + +import { type "" as typeC } from "./arbitraryModuleNamespaceIdentifiers_module"; +>typeC : typeof valueZ +> : ^^^^^^^^^^^^^ + +export type otherType = "otherType"; +>otherType : "otherType" +> : ^^^^^^^^^^^ + +const importStarTestA: typeC.otherType = "expect error about otherType"; +>importStarTestA : "otherType" +> : ^^^^^^^^^^^ +>typeC : any +> : ^^^ +>"expect error about otherType" : "expect error about otherType" +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + diff --git a/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=es6).errors.txt b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=es6).errors.txt new file mode 100644 index 0000000000000..e2a851b5a7bd3 --- /dev/null +++ b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=es6).errors.txt @@ -0,0 +1,84 @@ +arbitraryModuleNamespaceIdentifiers_module.ts(4,23): error TS18057: String literal import and export names are not supported when the '--module' flag is set to 'es2015' or 'es2020'. +arbitraryModuleNamespaceIdentifiers_module.ts(5,10): error TS18057: String literal import and export names are not supported when the '--module' flag is set to 'es2015' or 'es2020'. +arbitraryModuleNamespaceIdentifiers_module.ts(8,10): error TS18057: String literal import and export names are not supported when the '--module' flag is set to 'es2015' or 'es2020'. +arbitraryModuleNamespaceIdentifiers_module.ts(8,19): error TS18057: String literal import and export names are not supported when the '--module' flag is set to 'es2015' or 'es2020'. +arbitraryModuleNamespaceIdentifiers_module.ts(9,10): error TS18057: String literal import and export names are not supported when the '--module' flag is set to 'es2015' or 'es2020'. +arbitraryModuleNamespaceIdentifiers_module.ts(12,13): error TS18057: String literal import and export names are not supported when the '--module' flag is set to 'es2015' or 'es2020'. +arbitraryModuleNamespaceIdentifiers_module.ts(13,10): error TS18057: String literal import and export names are not supported when the '--module' flag is set to 'es2015' or 'es2020'. +arbitraryModuleNamespaceIdentifiers_module.ts(18,27): error TS18057: String literal import and export names are not supported when the '--module' flag is set to 'es2015' or 'es2020'. +arbitraryModuleNamespaceIdentifiers_module.ts(19,15): error TS18057: String literal import and export names are not supported when the '--module' flag is set to 'es2015' or 'es2020'. +arbitraryModuleNamespaceIdentifiers_module.ts(20,7): error TS2322: Type '"expect error about someType"' is not assignable to type '"someType"'. +arbitraryModuleNamespaceIdentifiers_module.ts(22,15): error TS18057: String literal import and export names are not supported when the '--module' flag is set to 'es2015' or 'es2020'. +arbitraryModuleNamespaceIdentifiers_module.ts(22,24): error TS18057: String literal import and export names are not supported when the '--module' flag is set to 'es2015' or 'es2020'. +arbitraryModuleNamespaceIdentifiers_module.ts(23,15): error TS18057: String literal import and export names are not supported when the '--module' flag is set to 'es2015' or 'es2020'. +arbitraryModuleNamespaceIdentifiers_module.ts(24,7): error TS2322: Type '"expect error about someType"' is not assignable to type '"someType"'. +arbitraryModuleNamespaceIdentifiers_module.ts(26,18): error TS18057: String literal import and export names are not supported when the '--module' flag is set to 'es2015' or 'es2020'. +arbitraryModuleNamespaceIdentifiers_module.ts(27,15): error TS18057: String literal import and export names are not supported when the '--module' flag is set to 'es2015' or 'es2020'. +arbitraryModuleNamespaceIdentifiers_module.ts(29,7): error TS2322: Type '"expect error about otherType"' is not assignable to type '"otherType"'. + + +==== arbitraryModuleNamespaceIdentifiers_module.ts (17 errors) ==== + const someValue = "someValue"; + type someType = "someType"; + + export { someValue as "" }; + ~~~~~ +!!! error TS18057: String literal import and export names are not supported when the '--module' flag is set to 'es2015' or 'es2020'. + import { "" as valueX } from "./arbitraryModuleNamespaceIdentifiers_module"; + ~~~~~ +!!! error TS18057: String literal import and export names are not supported when the '--module' flag is set to 'es2015' or 'es2020'. + if (valueX !== "someValue") throw "should be someValue"; + + export { "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; + ~~~~~ +!!! error TS18057: String literal import and export names are not supported when the '--module' flag is set to 'es2015' or 'es2020'. + ~~~~~ +!!! error TS18057: String literal import and export names are not supported when the '--module' flag is set to 'es2015' or 'es2020'. + import { "" as valueY } from "./arbitraryModuleNamespaceIdentifiers_module"; + ~~~~~ +!!! error TS18057: String literal import and export names are not supported when the '--module' flag is set to 'es2015' or 'es2020'. + if (valueY !== "someValue") throw "should be someValue"; + + export * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; + ~~~~~ +!!! error TS18057: String literal import and export names are not supported when the '--module' flag is set to 'es2015' or 'es2020'. + import { "" as valueZ } from "./arbitraryModuleNamespaceIdentifiers_module"; + ~~~~~ +!!! error TS18057: String literal import and export names are not supported when the '--module' flag is set to 'es2015' or 'es2020'. + if (valueZ[""] !== "someValue") throw "should be someValue"; + if (valueZ[""] !== "someValue") throw "should be someValue"; + if (valueZ[""] !== valueZ) throw "should be export namespace"; + + export { type someType as "" }; + ~~~~~ +!!! error TS18057: String literal import and export names are not supported when the '--module' flag is set to 'es2015' or 'es2020'. + import { type "" as typeA } from "./arbitraryModuleNamespaceIdentifiers_module"; + ~~~~~ +!!! error TS18057: String literal import and export names are not supported when the '--module' flag is set to 'es2015' or 'es2020'. + const importTest: typeA = "expect error about someType"; + ~~~~~~~~~~ +!!! error TS2322: Type '"expect error about someType"' is not assignable to type '"someType"'. + + export { type "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; + ~~~~~ +!!! error TS18057: String literal import and export names are not supported when the '--module' flag is set to 'es2015' or 'es2020'. + ~~~~~ +!!! error TS18057: String literal import and export names are not supported when the '--module' flag is set to 'es2015' or 'es2020'. + import { type "" as typeB } from "./arbitraryModuleNamespaceIdentifiers_module"; + ~~~~~ +!!! error TS18057: String literal import and export names are not supported when the '--module' flag is set to 'es2015' or 'es2020'. + const reimportTest: typeB = "expect error about someType"; + ~~~~~~~~~~~~ +!!! error TS2322: Type '"expect error about someType"' is not assignable to type '"someType"'. + + export type * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; + ~~~~~ +!!! error TS18057: String literal import and export names are not supported when the '--module' flag is set to 'es2015' or 'es2020'. + import { type "" as typeC } from "./arbitraryModuleNamespaceIdentifiers_module"; + ~~~~~ +!!! error TS18057: String literal import and export names are not supported when the '--module' flag is set to 'es2015' or 'es2020'. + export type otherType = "otherType"; + const importStarTestA: typeC.otherType = "expect error about otherType"; + ~~~~~~~~~~~~~~~ +!!! error TS2322: Type '"expect error about otherType"' is not assignable to type '"otherType"'. + \ No newline at end of file diff --git a/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=es6).js b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=es6).js new file mode 100644 index 0000000000000..d6a75c346d677 --- /dev/null +++ b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=es6).js @@ -0,0 +1,68 @@ +//// [tests/cases/conformance/es2022/arbitraryModuleNamespaceIdentifiers/arbitraryModuleNamespaceIdentifiers_module.ts] //// + +//// [arbitraryModuleNamespaceIdentifiers_module.ts] +const someValue = "someValue"; +type someType = "someType"; + +export { someValue as "" }; +import { "" as valueX } from "./arbitraryModuleNamespaceIdentifiers_module"; +if (valueX !== "someValue") throw "should be someValue"; + +export { "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; +import { "" as valueY } from "./arbitraryModuleNamespaceIdentifiers_module"; +if (valueY !== "someValue") throw "should be someValue"; + +export * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; +import { "" as valueZ } from "./arbitraryModuleNamespaceIdentifiers_module"; +if (valueZ[""] !== "someValue") throw "should be someValue"; +if (valueZ[""] !== "someValue") throw "should be someValue"; +if (valueZ[""] !== valueZ) throw "should be export namespace"; + +export { type someType as "" }; +import { type "" as typeA } from "./arbitraryModuleNamespaceIdentifiers_module"; +const importTest: typeA = "expect error about someType"; + +export { type "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; +import { type "" as typeB } from "./arbitraryModuleNamespaceIdentifiers_module"; +const reimportTest: typeB = "expect error about someType"; + +export type * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; +import { type "" as typeC } from "./arbitraryModuleNamespaceIdentifiers_module"; +export type otherType = "otherType"; +const importStarTestA: typeC.otherType = "expect error about otherType"; + + +//// [arbitraryModuleNamespaceIdentifiers_module.js] +const someValue = "someValue"; +export { someValue as "" }; +import { "" as valueX } from "./arbitraryModuleNamespaceIdentifiers_module"; +if (valueX !== "someValue") + throw "should be someValue"; +export { "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; +import { "" as valueY } from "./arbitraryModuleNamespaceIdentifiers_module"; +if (valueY !== "someValue") + throw "should be someValue"; +import * as _a from "./arbitraryModuleNamespaceIdentifiers_module"; +export { _a as "" }; +import { "" as valueZ } from "./arbitraryModuleNamespaceIdentifiers_module"; +if (valueZ[""] !== "someValue") + throw "should be someValue"; +if (valueZ[""] !== "someValue") + throw "should be someValue"; +if (valueZ[""] !== valueZ) + throw "should be export namespace"; +const importTest = "expect error about someType"; +const reimportTest = "expect error about someType"; +const importStarTestA = "expect error about otherType"; + + +//// [arbitraryModuleNamespaceIdentifiers_module.d.ts] +declare const someValue = "someValue"; +type someType = "someType"; +export { someValue as "" }; +export { "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; +export * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; +export { type someType as "" }; +export { type "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; +export type * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; +export type otherType = "otherType"; diff --git a/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=es6).symbols b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=es6).symbols new file mode 100644 index 0000000000000..a792b7d3f5280 --- /dev/null +++ b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=es6).symbols @@ -0,0 +1,82 @@ +//// [tests/cases/conformance/es2022/arbitraryModuleNamespaceIdentifiers/arbitraryModuleNamespaceIdentifiers_module.ts] //// + +=== arbitraryModuleNamespaceIdentifiers_module.ts === +const someValue = "someValue"; +>someValue : Symbol(someValue, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 0, 5)) + +type someType = "someType"; +>someType : Symbol(someType, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 0, 30)) + +export { someValue as "" }; +>someValue : Symbol(someValue, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 0, 5)) +>"" : Symbol(valueZ[""], Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 3, 8)) + +import { "" as valueX } from "./arbitraryModuleNamespaceIdentifiers_module"; +>valueX : Symbol(valueX, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 4, 8)) + +if (valueX !== "someValue") throw "should be someValue"; +>valueX : Symbol(valueX, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 4, 8)) + +export { "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; +>"" : Symbol(valueZ[""], Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 7, 8)) + +import { "" as valueY } from "./arbitraryModuleNamespaceIdentifiers_module"; +>valueY : Symbol(valueY, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 8, 8)) + +if (valueY !== "someValue") throw "should be someValue"; +>valueY : Symbol(valueY, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 8, 8)) + +export * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; +>"" : Symbol(valueZ[""], Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 11, 6)) + +import { "" as valueZ } from "./arbitraryModuleNamespaceIdentifiers_module"; +>valueZ : Symbol(valueZ, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 12, 8)) + +if (valueZ[""] !== "someValue") throw "should be someValue"; +>valueZ : Symbol(valueZ, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 12, 8)) +>"" : Symbol(valueZ[""], Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 3, 8)) + +if (valueZ[""] !== "someValue") throw "should be someValue"; +>valueZ : Symbol(valueZ, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 12, 8)) +>"" : Symbol(valueZ[""], Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 7, 8)) + +if (valueZ[""] !== valueZ) throw "should be export namespace"; +>valueZ : Symbol(valueZ, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 12, 8)) +>"" : Symbol(valueZ[""], Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 11, 6)) +>valueZ : Symbol(valueZ, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 12, 8)) + +export { type someType as "" }; +>someType : Symbol(someType, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 0, 30)) +>"" : Symbol(valueZ[""], Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 17, 8)) + +import { type "" as typeA } from "./arbitraryModuleNamespaceIdentifiers_module"; +>typeA : Symbol(typeA, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 18, 8)) + +const importTest: typeA = "expect error about someType"; +>importTest : Symbol(importTest, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 19, 5)) +>typeA : Symbol(typeA, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 18, 8)) + +export { type "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; +>"" : Symbol(valueZ[""], Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 21, 8)) + +import { type "" as typeB } from "./arbitraryModuleNamespaceIdentifiers_module"; +>typeB : Symbol(typeB, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 22, 8)) + +const reimportTest: typeB = "expect error about someType"; +>reimportTest : Symbol(reimportTest, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 23, 5)) +>typeB : Symbol(typeB, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 22, 8)) + +export type * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; +>"" : Symbol(valueZ[""], Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 25, 11)) + +import { type "" as typeC } from "./arbitraryModuleNamespaceIdentifiers_module"; +>typeC : Symbol(typeC, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 26, 8)) + +export type otherType = "otherType"; +>otherType : Symbol(valueZ.otherType, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 26, 83)) + +const importStarTestA: typeC.otherType = "expect error about otherType"; +>importStarTestA : Symbol(importStarTestA, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 28, 5)) +>typeC : Symbol(typeC, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 26, 8)) +>otherType : Symbol(valueZ.otherType, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 26, 83)) + diff --git a/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=es6).types b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=es6).types new file mode 100644 index 0000000000000..4574f9754d0b4 --- /dev/null +++ b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=es6).types @@ -0,0 +1,151 @@ +//// [tests/cases/conformance/es2022/arbitraryModuleNamespaceIdentifiers/arbitraryModuleNamespaceIdentifiers_module.ts] //// + +=== arbitraryModuleNamespaceIdentifiers_module.ts === +const someValue = "someValue"; +>someValue : "someValue" +> : ^^^^^^^^^^^ +>"someValue" : "someValue" +> : ^^^^^^^^^^^ + +type someType = "someType"; +>someType : "someType" +> : ^^^^^^^^^^ + +export { someValue as "" }; +>someValue : "someValue" +> : ^^^^^^^^^^^ +>"" : "someValue" +> : ^^^^^^^^^^^ + +import { "" as valueX } from "./arbitraryModuleNamespaceIdentifiers_module"; +>valueX : "someValue" +> : ^^^^^^^^^^^ + +if (valueX !== "someValue") throw "should be someValue"; +>valueX !== "someValue" : boolean +> : ^^^^^^^ +>valueX : "someValue" +> : ^^^^^^^^^^^ +>"someValue" : "someValue" +> : ^^^^^^^^^^^ +>"should be someValue" : "should be someValue" +> : ^^^^^^^^^^^^^^^^^^^^^ + +export { "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; +>"" : "someValue" +> : ^^^^^^^^^^^ + +import { "" as valueY } from "./arbitraryModuleNamespaceIdentifiers_module"; +>valueY : "someValue" +> : ^^^^^^^^^^^ + +if (valueY !== "someValue") throw "should be someValue"; +>valueY !== "someValue" : boolean +> : ^^^^^^^ +>valueY : "someValue" +> : ^^^^^^^^^^^ +>"someValue" : "someValue" +> : ^^^^^^^^^^^ +>"should be someValue" : "should be someValue" +> : ^^^^^^^^^^^^^^^^^^^^^ + +export * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; +>"" : typeof valueZ +> : ^^^^^^^^^^^^^ + +import { "" as valueZ } from "./arbitraryModuleNamespaceIdentifiers_module"; +>valueZ : typeof valueZ +> : ^^^^^^^^^^^^^ + +if (valueZ[""] !== "someValue") throw "should be someValue"; +>valueZ[""] !== "someValue" : boolean +> : ^^^^^^^ +>valueZ[""] : "someValue" +> : ^^^^^^^^^^^ +>valueZ : typeof valueZ +> : ^^^^^^^^^^^^^ +>"" : "" +> : ^^^^^ +>"someValue" : "someValue" +> : ^^^^^^^^^^^ +>"should be someValue" : "should be someValue" +> : ^^^^^^^^^^^^^^^^^^^^^ + +if (valueZ[""] !== "someValue") throw "should be someValue"; +>valueZ[""] !== "someValue" : boolean +> : ^^^^^^^ +>valueZ[""] : "someValue" +> : ^^^^^^^^^^^ +>valueZ : typeof valueZ +> : ^^^^^^^^^^^^^ +>"" : "" +> : ^^^^^ +>"someValue" : "someValue" +> : ^^^^^^^^^^^ +>"should be someValue" : "should be someValue" +> : ^^^^^^^^^^^^^^^^^^^^^ + +if (valueZ[""] !== valueZ) throw "should be export namespace"; +>valueZ[""] !== valueZ : boolean +> : ^^^^^^^ +>valueZ[""] : typeof valueZ +> : ^^^^^^^^^^^^^ +>valueZ : typeof valueZ +> : ^^^^^^^^^^^^^ +>"" : "" +> : ^^^^^ +>valueZ : typeof valueZ +> : ^^^^^^^^^^^^^ +>"should be export namespace" : "should be export namespace" +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +export { type someType as "" }; +>someType : any +> : ^^^ +>"" : any +> : ^^^ + +import { type "" as typeA } from "./arbitraryModuleNamespaceIdentifiers_module"; +>typeA : any +> : ^^^ + +const importTest: typeA = "expect error about someType"; +>importTest : "someType" +> : ^^^^^^^^^^ +>"expect error about someType" : "expect error about someType" +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +export { type "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; +>"" : any +> : ^^^ + +import { type "" as typeB } from "./arbitraryModuleNamespaceIdentifiers_module"; +>typeB : any +> : ^^^ + +const reimportTest: typeB = "expect error about someType"; +>reimportTest : "someType" +> : ^^^^^^^^^^ +>"expect error about someType" : "expect error about someType" +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +export type * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; +>"" : typeof valueZ +> : ^^^^^^^^^^^^^ + +import { type "" as typeC } from "./arbitraryModuleNamespaceIdentifiers_module"; +>typeC : typeof valueZ +> : ^^^^^^^^^^^^^ + +export type otherType = "otherType"; +>otherType : "otherType" +> : ^^^^^^^^^^^ + +const importStarTestA: typeC.otherType = "expect error about otherType"; +>importStarTestA : "otherType" +> : ^^^^^^^^^^^ +>typeC : any +> : ^^^ +>"expect error about otherType" : "expect error about otherType" +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + diff --git a/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=esnext).errors.txt b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=esnext).errors.txt new file mode 100644 index 0000000000000..cc359bceb4904 --- /dev/null +++ b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=esnext).errors.txt @@ -0,0 +1,42 @@ +arbitraryModuleNamespaceIdentifiers_module.ts(20,7): error TS2322: Type '"expect error about someType"' is not assignable to type '"someType"'. +arbitraryModuleNamespaceIdentifiers_module.ts(24,7): error TS2322: Type '"expect error about someType"' is not assignable to type '"someType"'. +arbitraryModuleNamespaceIdentifiers_module.ts(29,7): error TS2322: Type '"expect error about otherType"' is not assignable to type '"otherType"'. + + +==== arbitraryModuleNamespaceIdentifiers_module.ts (3 errors) ==== + const someValue = "someValue"; + type someType = "someType"; + + export { someValue as "" }; + import { "" as valueX } from "./arbitraryModuleNamespaceIdentifiers_module"; + if (valueX !== "someValue") throw "should be someValue"; + + export { "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; + import { "" as valueY } from "./arbitraryModuleNamespaceIdentifiers_module"; + if (valueY !== "someValue") throw "should be someValue"; + + export * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; + import { "" as valueZ } from "./arbitraryModuleNamespaceIdentifiers_module"; + if (valueZ[""] !== "someValue") throw "should be someValue"; + if (valueZ[""] !== "someValue") throw "should be someValue"; + if (valueZ[""] !== valueZ) throw "should be export namespace"; + + export { type someType as "" }; + import { type "" as typeA } from "./arbitraryModuleNamespaceIdentifiers_module"; + const importTest: typeA = "expect error about someType"; + ~~~~~~~~~~ +!!! error TS2322: Type '"expect error about someType"' is not assignable to type '"someType"'. + + export { type "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; + import { type "" as typeB } from "./arbitraryModuleNamespaceIdentifiers_module"; + const reimportTest: typeB = "expect error about someType"; + ~~~~~~~~~~~~ +!!! error TS2322: Type '"expect error about someType"' is not assignable to type '"someType"'. + + export type * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; + import { type "" as typeC } from "./arbitraryModuleNamespaceIdentifiers_module"; + export type otherType = "otherType"; + const importStarTestA: typeC.otherType = "expect error about otherType"; + ~~~~~~~~~~~~~~~ +!!! error TS2322: Type '"expect error about otherType"' is not assignable to type '"otherType"'. + \ No newline at end of file diff --git a/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=esnext).js b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=esnext).js new file mode 100644 index 0000000000000..4964f684a1ed0 --- /dev/null +++ b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=esnext).js @@ -0,0 +1,67 @@ +//// [tests/cases/conformance/es2022/arbitraryModuleNamespaceIdentifiers/arbitraryModuleNamespaceIdentifiers_module.ts] //// + +//// [arbitraryModuleNamespaceIdentifiers_module.ts] +const someValue = "someValue"; +type someType = "someType"; + +export { someValue as "" }; +import { "" as valueX } from "./arbitraryModuleNamespaceIdentifiers_module"; +if (valueX !== "someValue") throw "should be someValue"; + +export { "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; +import { "" as valueY } from "./arbitraryModuleNamespaceIdentifiers_module"; +if (valueY !== "someValue") throw "should be someValue"; + +export * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; +import { "" as valueZ } from "./arbitraryModuleNamespaceIdentifiers_module"; +if (valueZ[""] !== "someValue") throw "should be someValue"; +if (valueZ[""] !== "someValue") throw "should be someValue"; +if (valueZ[""] !== valueZ) throw "should be export namespace"; + +export { type someType as "" }; +import { type "" as typeA } from "./arbitraryModuleNamespaceIdentifiers_module"; +const importTest: typeA = "expect error about someType"; + +export { type "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; +import { type "" as typeB } from "./arbitraryModuleNamespaceIdentifiers_module"; +const reimportTest: typeB = "expect error about someType"; + +export type * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; +import { type "" as typeC } from "./arbitraryModuleNamespaceIdentifiers_module"; +export type otherType = "otherType"; +const importStarTestA: typeC.otherType = "expect error about otherType"; + + +//// [arbitraryModuleNamespaceIdentifiers_module.js] +const someValue = "someValue"; +export { someValue as "" }; +import { "" as valueX } from "./arbitraryModuleNamespaceIdentifiers_module"; +if (valueX !== "someValue") + throw "should be someValue"; +export { "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; +import { "" as valueY } from "./arbitraryModuleNamespaceIdentifiers_module"; +if (valueY !== "someValue") + throw "should be someValue"; +export * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; +import { "" as valueZ } from "./arbitraryModuleNamespaceIdentifiers_module"; +if (valueZ[""] !== "someValue") + throw "should be someValue"; +if (valueZ[""] !== "someValue") + throw "should be someValue"; +if (valueZ[""] !== valueZ) + throw "should be export namespace"; +const importTest = "expect error about someType"; +const reimportTest = "expect error about someType"; +const importStarTestA = "expect error about otherType"; + + +//// [arbitraryModuleNamespaceIdentifiers_module.d.ts] +declare const someValue = "someValue"; +type someType = "someType"; +export { someValue as "" }; +export { "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; +export * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; +export { type someType as "" }; +export { type "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; +export type * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; +export type otherType = "otherType"; diff --git a/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=esnext).symbols b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=esnext).symbols new file mode 100644 index 0000000000000..a792b7d3f5280 --- /dev/null +++ b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=esnext).symbols @@ -0,0 +1,82 @@ +//// [tests/cases/conformance/es2022/arbitraryModuleNamespaceIdentifiers/arbitraryModuleNamespaceIdentifiers_module.ts] //// + +=== arbitraryModuleNamespaceIdentifiers_module.ts === +const someValue = "someValue"; +>someValue : Symbol(someValue, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 0, 5)) + +type someType = "someType"; +>someType : Symbol(someType, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 0, 30)) + +export { someValue as "" }; +>someValue : Symbol(someValue, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 0, 5)) +>"" : Symbol(valueZ[""], Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 3, 8)) + +import { "" as valueX } from "./arbitraryModuleNamespaceIdentifiers_module"; +>valueX : Symbol(valueX, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 4, 8)) + +if (valueX !== "someValue") throw "should be someValue"; +>valueX : Symbol(valueX, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 4, 8)) + +export { "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; +>"" : Symbol(valueZ[""], Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 7, 8)) + +import { "" as valueY } from "./arbitraryModuleNamespaceIdentifiers_module"; +>valueY : Symbol(valueY, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 8, 8)) + +if (valueY !== "someValue") throw "should be someValue"; +>valueY : Symbol(valueY, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 8, 8)) + +export * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; +>"" : Symbol(valueZ[""], Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 11, 6)) + +import { "" as valueZ } from "./arbitraryModuleNamespaceIdentifiers_module"; +>valueZ : Symbol(valueZ, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 12, 8)) + +if (valueZ[""] !== "someValue") throw "should be someValue"; +>valueZ : Symbol(valueZ, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 12, 8)) +>"" : Symbol(valueZ[""], Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 3, 8)) + +if (valueZ[""] !== "someValue") throw "should be someValue"; +>valueZ : Symbol(valueZ, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 12, 8)) +>"" : Symbol(valueZ[""], Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 7, 8)) + +if (valueZ[""] !== valueZ) throw "should be export namespace"; +>valueZ : Symbol(valueZ, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 12, 8)) +>"" : Symbol(valueZ[""], Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 11, 6)) +>valueZ : Symbol(valueZ, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 12, 8)) + +export { type someType as "" }; +>someType : Symbol(someType, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 0, 30)) +>"" : Symbol(valueZ[""], Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 17, 8)) + +import { type "" as typeA } from "./arbitraryModuleNamespaceIdentifiers_module"; +>typeA : Symbol(typeA, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 18, 8)) + +const importTest: typeA = "expect error about someType"; +>importTest : Symbol(importTest, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 19, 5)) +>typeA : Symbol(typeA, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 18, 8)) + +export { type "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; +>"" : Symbol(valueZ[""], Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 21, 8)) + +import { type "" as typeB } from "./arbitraryModuleNamespaceIdentifiers_module"; +>typeB : Symbol(typeB, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 22, 8)) + +const reimportTest: typeB = "expect error about someType"; +>reimportTest : Symbol(reimportTest, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 23, 5)) +>typeB : Symbol(typeB, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 22, 8)) + +export type * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; +>"" : Symbol(valueZ[""], Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 25, 11)) + +import { type "" as typeC } from "./arbitraryModuleNamespaceIdentifiers_module"; +>typeC : Symbol(typeC, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 26, 8)) + +export type otherType = "otherType"; +>otherType : Symbol(valueZ.otherType, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 26, 83)) + +const importStarTestA: typeC.otherType = "expect error about otherType"; +>importStarTestA : Symbol(importStarTestA, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 28, 5)) +>typeC : Symbol(typeC, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 26, 8)) +>otherType : Symbol(valueZ.otherType, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 26, 83)) + diff --git a/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=esnext).types b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=esnext).types new file mode 100644 index 0000000000000..4574f9754d0b4 --- /dev/null +++ b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=esnext).types @@ -0,0 +1,151 @@ +//// [tests/cases/conformance/es2022/arbitraryModuleNamespaceIdentifiers/arbitraryModuleNamespaceIdentifiers_module.ts] //// + +=== arbitraryModuleNamespaceIdentifiers_module.ts === +const someValue = "someValue"; +>someValue : "someValue" +> : ^^^^^^^^^^^ +>"someValue" : "someValue" +> : ^^^^^^^^^^^ + +type someType = "someType"; +>someType : "someType" +> : ^^^^^^^^^^ + +export { someValue as "" }; +>someValue : "someValue" +> : ^^^^^^^^^^^ +>"" : "someValue" +> : ^^^^^^^^^^^ + +import { "" as valueX } from "./arbitraryModuleNamespaceIdentifiers_module"; +>valueX : "someValue" +> : ^^^^^^^^^^^ + +if (valueX !== "someValue") throw "should be someValue"; +>valueX !== "someValue" : boolean +> : ^^^^^^^ +>valueX : "someValue" +> : ^^^^^^^^^^^ +>"someValue" : "someValue" +> : ^^^^^^^^^^^ +>"should be someValue" : "should be someValue" +> : ^^^^^^^^^^^^^^^^^^^^^ + +export { "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; +>"" : "someValue" +> : ^^^^^^^^^^^ + +import { "" as valueY } from "./arbitraryModuleNamespaceIdentifiers_module"; +>valueY : "someValue" +> : ^^^^^^^^^^^ + +if (valueY !== "someValue") throw "should be someValue"; +>valueY !== "someValue" : boolean +> : ^^^^^^^ +>valueY : "someValue" +> : ^^^^^^^^^^^ +>"someValue" : "someValue" +> : ^^^^^^^^^^^ +>"should be someValue" : "should be someValue" +> : ^^^^^^^^^^^^^^^^^^^^^ + +export * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; +>"" : typeof valueZ +> : ^^^^^^^^^^^^^ + +import { "" as valueZ } from "./arbitraryModuleNamespaceIdentifiers_module"; +>valueZ : typeof valueZ +> : ^^^^^^^^^^^^^ + +if (valueZ[""] !== "someValue") throw "should be someValue"; +>valueZ[""] !== "someValue" : boolean +> : ^^^^^^^ +>valueZ[""] : "someValue" +> : ^^^^^^^^^^^ +>valueZ : typeof valueZ +> : ^^^^^^^^^^^^^ +>"" : "" +> : ^^^^^ +>"someValue" : "someValue" +> : ^^^^^^^^^^^ +>"should be someValue" : "should be someValue" +> : ^^^^^^^^^^^^^^^^^^^^^ + +if (valueZ[""] !== "someValue") throw "should be someValue"; +>valueZ[""] !== "someValue" : boolean +> : ^^^^^^^ +>valueZ[""] : "someValue" +> : ^^^^^^^^^^^ +>valueZ : typeof valueZ +> : ^^^^^^^^^^^^^ +>"" : "" +> : ^^^^^ +>"someValue" : "someValue" +> : ^^^^^^^^^^^ +>"should be someValue" : "should be someValue" +> : ^^^^^^^^^^^^^^^^^^^^^ + +if (valueZ[""] !== valueZ) throw "should be export namespace"; +>valueZ[""] !== valueZ : boolean +> : ^^^^^^^ +>valueZ[""] : typeof valueZ +> : ^^^^^^^^^^^^^ +>valueZ : typeof valueZ +> : ^^^^^^^^^^^^^ +>"" : "" +> : ^^^^^ +>valueZ : typeof valueZ +> : ^^^^^^^^^^^^^ +>"should be export namespace" : "should be export namespace" +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +export { type someType as "" }; +>someType : any +> : ^^^ +>"" : any +> : ^^^ + +import { type "" as typeA } from "./arbitraryModuleNamespaceIdentifiers_module"; +>typeA : any +> : ^^^ + +const importTest: typeA = "expect error about someType"; +>importTest : "someType" +> : ^^^^^^^^^^ +>"expect error about someType" : "expect error about someType" +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +export { type "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; +>"" : any +> : ^^^ + +import { type "" as typeB } from "./arbitraryModuleNamespaceIdentifiers_module"; +>typeB : any +> : ^^^ + +const reimportTest: typeB = "expect error about someType"; +>reimportTest : "someType" +> : ^^^^^^^^^^ +>"expect error about someType" : "expect error about someType" +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +export type * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; +>"" : typeof valueZ +> : ^^^^^^^^^^^^^ + +import { type "" as typeC } from "./arbitraryModuleNamespaceIdentifiers_module"; +>typeC : typeof valueZ +> : ^^^^^^^^^^^^^ + +export type otherType = "otherType"; +>otherType : "otherType" +> : ^^^^^^^^^^^ + +const importStarTestA: typeC.otherType = "expect error about otherType"; +>importStarTestA : "otherType" +> : ^^^^^^^^^^^ +>typeC : any +> : ^^^ +>"expect error about otherType" : "expect error about otherType" +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + diff --git a/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=node16).errors.txt b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=node16).errors.txt new file mode 100644 index 0000000000000..cc359bceb4904 --- /dev/null +++ b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=node16).errors.txt @@ -0,0 +1,42 @@ +arbitraryModuleNamespaceIdentifiers_module.ts(20,7): error TS2322: Type '"expect error about someType"' is not assignable to type '"someType"'. +arbitraryModuleNamespaceIdentifiers_module.ts(24,7): error TS2322: Type '"expect error about someType"' is not assignable to type '"someType"'. +arbitraryModuleNamespaceIdentifiers_module.ts(29,7): error TS2322: Type '"expect error about otherType"' is not assignable to type '"otherType"'. + + +==== arbitraryModuleNamespaceIdentifiers_module.ts (3 errors) ==== + const someValue = "someValue"; + type someType = "someType"; + + export { someValue as "" }; + import { "" as valueX } from "./arbitraryModuleNamespaceIdentifiers_module"; + if (valueX !== "someValue") throw "should be someValue"; + + export { "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; + import { "" as valueY } from "./arbitraryModuleNamespaceIdentifiers_module"; + if (valueY !== "someValue") throw "should be someValue"; + + export * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; + import { "" as valueZ } from "./arbitraryModuleNamespaceIdentifiers_module"; + if (valueZ[""] !== "someValue") throw "should be someValue"; + if (valueZ[""] !== "someValue") throw "should be someValue"; + if (valueZ[""] !== valueZ) throw "should be export namespace"; + + export { type someType as "" }; + import { type "" as typeA } from "./arbitraryModuleNamespaceIdentifiers_module"; + const importTest: typeA = "expect error about someType"; + ~~~~~~~~~~ +!!! error TS2322: Type '"expect error about someType"' is not assignable to type '"someType"'. + + export { type "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; + import { type "" as typeB } from "./arbitraryModuleNamespaceIdentifiers_module"; + const reimportTest: typeB = "expect error about someType"; + ~~~~~~~~~~~~ +!!! error TS2322: Type '"expect error about someType"' is not assignable to type '"someType"'. + + export type * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; + import { type "" as typeC } from "./arbitraryModuleNamespaceIdentifiers_module"; + export type otherType = "otherType"; + const importStarTestA: typeC.otherType = "expect error about otherType"; + ~~~~~~~~~~~~~~~ +!!! error TS2322: Type '"expect error about otherType"' is not assignable to type '"otherType"'. + \ No newline at end of file diff --git a/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=node16).js b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=node16).js new file mode 100644 index 0000000000000..d209a96d665e4 --- /dev/null +++ b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=node16).js @@ -0,0 +1,94 @@ +//// [tests/cases/conformance/es2022/arbitraryModuleNamespaceIdentifiers/arbitraryModuleNamespaceIdentifiers_module.ts] //// + +//// [arbitraryModuleNamespaceIdentifiers_module.ts] +const someValue = "someValue"; +type someType = "someType"; + +export { someValue as "" }; +import { "" as valueX } from "./arbitraryModuleNamespaceIdentifiers_module"; +if (valueX !== "someValue") throw "should be someValue"; + +export { "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; +import { "" as valueY } from "./arbitraryModuleNamespaceIdentifiers_module"; +if (valueY !== "someValue") throw "should be someValue"; + +export * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; +import { "" as valueZ } from "./arbitraryModuleNamespaceIdentifiers_module"; +if (valueZ[""] !== "someValue") throw "should be someValue"; +if (valueZ[""] !== "someValue") throw "should be someValue"; +if (valueZ[""] !== valueZ) throw "should be export namespace"; + +export { type someType as "" }; +import { type "" as typeA } from "./arbitraryModuleNamespaceIdentifiers_module"; +const importTest: typeA = "expect error about someType"; + +export { type "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; +import { type "" as typeB } from "./arbitraryModuleNamespaceIdentifiers_module"; +const reimportTest: typeB = "expect error about someType"; + +export type * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; +import { type "" as typeC } from "./arbitraryModuleNamespaceIdentifiers_module"; +export type otherType = "otherType"; +const importStarTestA: typeC.otherType = "expect error about otherType"; + + +//// [arbitraryModuleNamespaceIdentifiers_module.js] +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports[""] = exports[""] = exports[""] = void 0; +const someValue = "someValue"; +exports[""] = someValue; +const arbitraryModuleNamespaceIdentifiers_module_1 = require("./arbitraryModuleNamespaceIdentifiers_module"); +if (arbitraryModuleNamespaceIdentifiers_module_1[""] !== "someValue") + throw "should be someValue"; +var arbitraryModuleNamespaceIdentifiers_module_2 = require("./arbitraryModuleNamespaceIdentifiers_module"); +Object.defineProperty(exports, "", { enumerable: true, get: function () { return arbitraryModuleNamespaceIdentifiers_module_2[""]; } }); +const arbitraryModuleNamespaceIdentifiers_module_3 = require("./arbitraryModuleNamespaceIdentifiers_module"); +if (arbitraryModuleNamespaceIdentifiers_module_3[""] !== "someValue") + throw "should be someValue"; +exports[""] = __importStar(require("./arbitraryModuleNamespaceIdentifiers_module")); +const arbitraryModuleNamespaceIdentifiers_module_4 = require("./arbitraryModuleNamespaceIdentifiers_module"); +if (arbitraryModuleNamespaceIdentifiers_module_4[""][""] !== "someValue") + throw "should be someValue"; +if (arbitraryModuleNamespaceIdentifiers_module_4[""][""] !== "someValue") + throw "should be someValue"; +if (arbitraryModuleNamespaceIdentifiers_module_4[""][""] !== arbitraryModuleNamespaceIdentifiers_module_4[""]) + throw "should be export namespace"; +const importTest = "expect error about someType"; +const reimportTest = "expect error about someType"; +const importStarTestA = "expect error about otherType"; + + +//// [arbitraryModuleNamespaceIdentifiers_module.d.ts] +declare const someValue = "someValue"; +type someType = "someType"; +export { someValue as "" }; +export { "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; +export * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; +export { type someType as "" }; +export { type "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; +export type * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; +export type otherType = "otherType"; diff --git a/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=node16).symbols b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=node16).symbols new file mode 100644 index 0000000000000..a792b7d3f5280 --- /dev/null +++ b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=node16).symbols @@ -0,0 +1,82 @@ +//// [tests/cases/conformance/es2022/arbitraryModuleNamespaceIdentifiers/arbitraryModuleNamespaceIdentifiers_module.ts] //// + +=== arbitraryModuleNamespaceIdentifiers_module.ts === +const someValue = "someValue"; +>someValue : Symbol(someValue, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 0, 5)) + +type someType = "someType"; +>someType : Symbol(someType, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 0, 30)) + +export { someValue as "" }; +>someValue : Symbol(someValue, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 0, 5)) +>"" : Symbol(valueZ[""], Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 3, 8)) + +import { "" as valueX } from "./arbitraryModuleNamespaceIdentifiers_module"; +>valueX : Symbol(valueX, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 4, 8)) + +if (valueX !== "someValue") throw "should be someValue"; +>valueX : Symbol(valueX, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 4, 8)) + +export { "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; +>"" : Symbol(valueZ[""], Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 7, 8)) + +import { "" as valueY } from "./arbitraryModuleNamespaceIdentifiers_module"; +>valueY : Symbol(valueY, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 8, 8)) + +if (valueY !== "someValue") throw "should be someValue"; +>valueY : Symbol(valueY, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 8, 8)) + +export * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; +>"" : Symbol(valueZ[""], Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 11, 6)) + +import { "" as valueZ } from "./arbitraryModuleNamespaceIdentifiers_module"; +>valueZ : Symbol(valueZ, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 12, 8)) + +if (valueZ[""] !== "someValue") throw "should be someValue"; +>valueZ : Symbol(valueZ, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 12, 8)) +>"" : Symbol(valueZ[""], Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 3, 8)) + +if (valueZ[""] !== "someValue") throw "should be someValue"; +>valueZ : Symbol(valueZ, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 12, 8)) +>"" : Symbol(valueZ[""], Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 7, 8)) + +if (valueZ[""] !== valueZ) throw "should be export namespace"; +>valueZ : Symbol(valueZ, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 12, 8)) +>"" : Symbol(valueZ[""], Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 11, 6)) +>valueZ : Symbol(valueZ, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 12, 8)) + +export { type someType as "" }; +>someType : Symbol(someType, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 0, 30)) +>"" : Symbol(valueZ[""], Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 17, 8)) + +import { type "" as typeA } from "./arbitraryModuleNamespaceIdentifiers_module"; +>typeA : Symbol(typeA, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 18, 8)) + +const importTest: typeA = "expect error about someType"; +>importTest : Symbol(importTest, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 19, 5)) +>typeA : Symbol(typeA, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 18, 8)) + +export { type "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; +>"" : Symbol(valueZ[""], Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 21, 8)) + +import { type "" as typeB } from "./arbitraryModuleNamespaceIdentifiers_module"; +>typeB : Symbol(typeB, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 22, 8)) + +const reimportTest: typeB = "expect error about someType"; +>reimportTest : Symbol(reimportTest, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 23, 5)) +>typeB : Symbol(typeB, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 22, 8)) + +export type * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; +>"" : Symbol(valueZ[""], Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 25, 11)) + +import { type "" as typeC } from "./arbitraryModuleNamespaceIdentifiers_module"; +>typeC : Symbol(typeC, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 26, 8)) + +export type otherType = "otherType"; +>otherType : Symbol(valueZ.otherType, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 26, 83)) + +const importStarTestA: typeC.otherType = "expect error about otherType"; +>importStarTestA : Symbol(importStarTestA, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 28, 5)) +>typeC : Symbol(typeC, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 26, 8)) +>otherType : Symbol(valueZ.otherType, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 26, 83)) + diff --git a/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=node16).types b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=node16).types new file mode 100644 index 0000000000000..4574f9754d0b4 --- /dev/null +++ b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=node16).types @@ -0,0 +1,151 @@ +//// [tests/cases/conformance/es2022/arbitraryModuleNamespaceIdentifiers/arbitraryModuleNamespaceIdentifiers_module.ts] //// + +=== arbitraryModuleNamespaceIdentifiers_module.ts === +const someValue = "someValue"; +>someValue : "someValue" +> : ^^^^^^^^^^^ +>"someValue" : "someValue" +> : ^^^^^^^^^^^ + +type someType = "someType"; +>someType : "someType" +> : ^^^^^^^^^^ + +export { someValue as "" }; +>someValue : "someValue" +> : ^^^^^^^^^^^ +>"" : "someValue" +> : ^^^^^^^^^^^ + +import { "" as valueX } from "./arbitraryModuleNamespaceIdentifiers_module"; +>valueX : "someValue" +> : ^^^^^^^^^^^ + +if (valueX !== "someValue") throw "should be someValue"; +>valueX !== "someValue" : boolean +> : ^^^^^^^ +>valueX : "someValue" +> : ^^^^^^^^^^^ +>"someValue" : "someValue" +> : ^^^^^^^^^^^ +>"should be someValue" : "should be someValue" +> : ^^^^^^^^^^^^^^^^^^^^^ + +export { "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; +>"" : "someValue" +> : ^^^^^^^^^^^ + +import { "" as valueY } from "./arbitraryModuleNamespaceIdentifiers_module"; +>valueY : "someValue" +> : ^^^^^^^^^^^ + +if (valueY !== "someValue") throw "should be someValue"; +>valueY !== "someValue" : boolean +> : ^^^^^^^ +>valueY : "someValue" +> : ^^^^^^^^^^^ +>"someValue" : "someValue" +> : ^^^^^^^^^^^ +>"should be someValue" : "should be someValue" +> : ^^^^^^^^^^^^^^^^^^^^^ + +export * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; +>"" : typeof valueZ +> : ^^^^^^^^^^^^^ + +import { "" as valueZ } from "./arbitraryModuleNamespaceIdentifiers_module"; +>valueZ : typeof valueZ +> : ^^^^^^^^^^^^^ + +if (valueZ[""] !== "someValue") throw "should be someValue"; +>valueZ[""] !== "someValue" : boolean +> : ^^^^^^^ +>valueZ[""] : "someValue" +> : ^^^^^^^^^^^ +>valueZ : typeof valueZ +> : ^^^^^^^^^^^^^ +>"" : "" +> : ^^^^^ +>"someValue" : "someValue" +> : ^^^^^^^^^^^ +>"should be someValue" : "should be someValue" +> : ^^^^^^^^^^^^^^^^^^^^^ + +if (valueZ[""] !== "someValue") throw "should be someValue"; +>valueZ[""] !== "someValue" : boolean +> : ^^^^^^^ +>valueZ[""] : "someValue" +> : ^^^^^^^^^^^ +>valueZ : typeof valueZ +> : ^^^^^^^^^^^^^ +>"" : "" +> : ^^^^^ +>"someValue" : "someValue" +> : ^^^^^^^^^^^ +>"should be someValue" : "should be someValue" +> : ^^^^^^^^^^^^^^^^^^^^^ + +if (valueZ[""] !== valueZ) throw "should be export namespace"; +>valueZ[""] !== valueZ : boolean +> : ^^^^^^^ +>valueZ[""] : typeof valueZ +> : ^^^^^^^^^^^^^ +>valueZ : typeof valueZ +> : ^^^^^^^^^^^^^ +>"" : "" +> : ^^^^^ +>valueZ : typeof valueZ +> : ^^^^^^^^^^^^^ +>"should be export namespace" : "should be export namespace" +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +export { type someType as "" }; +>someType : any +> : ^^^ +>"" : any +> : ^^^ + +import { type "" as typeA } from "./arbitraryModuleNamespaceIdentifiers_module"; +>typeA : any +> : ^^^ + +const importTest: typeA = "expect error about someType"; +>importTest : "someType" +> : ^^^^^^^^^^ +>"expect error about someType" : "expect error about someType" +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +export { type "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; +>"" : any +> : ^^^ + +import { type "" as typeB } from "./arbitraryModuleNamespaceIdentifiers_module"; +>typeB : any +> : ^^^ + +const reimportTest: typeB = "expect error about someType"; +>reimportTest : "someType" +> : ^^^^^^^^^^ +>"expect error about someType" : "expect error about someType" +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +export type * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; +>"" : typeof valueZ +> : ^^^^^^^^^^^^^ + +import { type "" as typeC } from "./arbitraryModuleNamespaceIdentifiers_module"; +>typeC : typeof valueZ +> : ^^^^^^^^^^^^^ + +export type otherType = "otherType"; +>otherType : "otherType" +> : ^^^^^^^^^^^ + +const importStarTestA: typeC.otherType = "expect error about otherType"; +>importStarTestA : "otherType" +> : ^^^^^^^^^^^ +>typeC : any +> : ^^^ +>"expect error about otherType" : "expect error about otherType" +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + diff --git a/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=nodenext).errors.txt b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=nodenext).errors.txt new file mode 100644 index 0000000000000..cc359bceb4904 --- /dev/null +++ b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=nodenext).errors.txt @@ -0,0 +1,42 @@ +arbitraryModuleNamespaceIdentifiers_module.ts(20,7): error TS2322: Type '"expect error about someType"' is not assignable to type '"someType"'. +arbitraryModuleNamespaceIdentifiers_module.ts(24,7): error TS2322: Type '"expect error about someType"' is not assignable to type '"someType"'. +arbitraryModuleNamespaceIdentifiers_module.ts(29,7): error TS2322: Type '"expect error about otherType"' is not assignable to type '"otherType"'. + + +==== arbitraryModuleNamespaceIdentifiers_module.ts (3 errors) ==== + const someValue = "someValue"; + type someType = "someType"; + + export { someValue as "" }; + import { "" as valueX } from "./arbitraryModuleNamespaceIdentifiers_module"; + if (valueX !== "someValue") throw "should be someValue"; + + export { "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; + import { "" as valueY } from "./arbitraryModuleNamespaceIdentifiers_module"; + if (valueY !== "someValue") throw "should be someValue"; + + export * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; + import { "" as valueZ } from "./arbitraryModuleNamespaceIdentifiers_module"; + if (valueZ[""] !== "someValue") throw "should be someValue"; + if (valueZ[""] !== "someValue") throw "should be someValue"; + if (valueZ[""] !== valueZ) throw "should be export namespace"; + + export { type someType as "" }; + import { type "" as typeA } from "./arbitraryModuleNamespaceIdentifiers_module"; + const importTest: typeA = "expect error about someType"; + ~~~~~~~~~~ +!!! error TS2322: Type '"expect error about someType"' is not assignable to type '"someType"'. + + export { type "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; + import { type "" as typeB } from "./arbitraryModuleNamespaceIdentifiers_module"; + const reimportTest: typeB = "expect error about someType"; + ~~~~~~~~~~~~ +!!! error TS2322: Type '"expect error about someType"' is not assignable to type '"someType"'. + + export type * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; + import { type "" as typeC } from "./arbitraryModuleNamespaceIdentifiers_module"; + export type otherType = "otherType"; + const importStarTestA: typeC.otherType = "expect error about otherType"; + ~~~~~~~~~~~~~~~ +!!! error TS2322: Type '"expect error about otherType"' is not assignable to type '"otherType"'. + \ No newline at end of file diff --git a/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=nodenext).js b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=nodenext).js new file mode 100644 index 0000000000000..d209a96d665e4 --- /dev/null +++ b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=nodenext).js @@ -0,0 +1,94 @@ +//// [tests/cases/conformance/es2022/arbitraryModuleNamespaceIdentifiers/arbitraryModuleNamespaceIdentifiers_module.ts] //// + +//// [arbitraryModuleNamespaceIdentifiers_module.ts] +const someValue = "someValue"; +type someType = "someType"; + +export { someValue as "" }; +import { "" as valueX } from "./arbitraryModuleNamespaceIdentifiers_module"; +if (valueX !== "someValue") throw "should be someValue"; + +export { "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; +import { "" as valueY } from "./arbitraryModuleNamespaceIdentifiers_module"; +if (valueY !== "someValue") throw "should be someValue"; + +export * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; +import { "" as valueZ } from "./arbitraryModuleNamespaceIdentifiers_module"; +if (valueZ[""] !== "someValue") throw "should be someValue"; +if (valueZ[""] !== "someValue") throw "should be someValue"; +if (valueZ[""] !== valueZ) throw "should be export namespace"; + +export { type someType as "" }; +import { type "" as typeA } from "./arbitraryModuleNamespaceIdentifiers_module"; +const importTest: typeA = "expect error about someType"; + +export { type "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; +import { type "" as typeB } from "./arbitraryModuleNamespaceIdentifiers_module"; +const reimportTest: typeB = "expect error about someType"; + +export type * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; +import { type "" as typeC } from "./arbitraryModuleNamespaceIdentifiers_module"; +export type otherType = "otherType"; +const importStarTestA: typeC.otherType = "expect error about otherType"; + + +//// [arbitraryModuleNamespaceIdentifiers_module.js] +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports[""] = exports[""] = exports[""] = void 0; +const someValue = "someValue"; +exports[""] = someValue; +const arbitraryModuleNamespaceIdentifiers_module_1 = require("./arbitraryModuleNamespaceIdentifiers_module"); +if (arbitraryModuleNamespaceIdentifiers_module_1[""] !== "someValue") + throw "should be someValue"; +var arbitraryModuleNamespaceIdentifiers_module_2 = require("./arbitraryModuleNamespaceIdentifiers_module"); +Object.defineProperty(exports, "", { enumerable: true, get: function () { return arbitraryModuleNamespaceIdentifiers_module_2[""]; } }); +const arbitraryModuleNamespaceIdentifiers_module_3 = require("./arbitraryModuleNamespaceIdentifiers_module"); +if (arbitraryModuleNamespaceIdentifiers_module_3[""] !== "someValue") + throw "should be someValue"; +exports[""] = __importStar(require("./arbitraryModuleNamespaceIdentifiers_module")); +const arbitraryModuleNamespaceIdentifiers_module_4 = require("./arbitraryModuleNamespaceIdentifiers_module"); +if (arbitraryModuleNamespaceIdentifiers_module_4[""][""] !== "someValue") + throw "should be someValue"; +if (arbitraryModuleNamespaceIdentifiers_module_4[""][""] !== "someValue") + throw "should be someValue"; +if (arbitraryModuleNamespaceIdentifiers_module_4[""][""] !== arbitraryModuleNamespaceIdentifiers_module_4[""]) + throw "should be export namespace"; +const importTest = "expect error about someType"; +const reimportTest = "expect error about someType"; +const importStarTestA = "expect error about otherType"; + + +//// [arbitraryModuleNamespaceIdentifiers_module.d.ts] +declare const someValue = "someValue"; +type someType = "someType"; +export { someValue as "" }; +export { "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; +export * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; +export { type someType as "" }; +export { type "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; +export type * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; +export type otherType = "otherType"; diff --git a/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=nodenext).symbols b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=nodenext).symbols new file mode 100644 index 0000000000000..a792b7d3f5280 --- /dev/null +++ b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=nodenext).symbols @@ -0,0 +1,82 @@ +//// [tests/cases/conformance/es2022/arbitraryModuleNamespaceIdentifiers/arbitraryModuleNamespaceIdentifiers_module.ts] //// + +=== arbitraryModuleNamespaceIdentifiers_module.ts === +const someValue = "someValue"; +>someValue : Symbol(someValue, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 0, 5)) + +type someType = "someType"; +>someType : Symbol(someType, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 0, 30)) + +export { someValue as "" }; +>someValue : Symbol(someValue, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 0, 5)) +>"" : Symbol(valueZ[""], Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 3, 8)) + +import { "" as valueX } from "./arbitraryModuleNamespaceIdentifiers_module"; +>valueX : Symbol(valueX, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 4, 8)) + +if (valueX !== "someValue") throw "should be someValue"; +>valueX : Symbol(valueX, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 4, 8)) + +export { "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; +>"" : Symbol(valueZ[""], Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 7, 8)) + +import { "" as valueY } from "./arbitraryModuleNamespaceIdentifiers_module"; +>valueY : Symbol(valueY, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 8, 8)) + +if (valueY !== "someValue") throw "should be someValue"; +>valueY : Symbol(valueY, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 8, 8)) + +export * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; +>"" : Symbol(valueZ[""], Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 11, 6)) + +import { "" as valueZ } from "./arbitraryModuleNamespaceIdentifiers_module"; +>valueZ : Symbol(valueZ, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 12, 8)) + +if (valueZ[""] !== "someValue") throw "should be someValue"; +>valueZ : Symbol(valueZ, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 12, 8)) +>"" : Symbol(valueZ[""], Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 3, 8)) + +if (valueZ[""] !== "someValue") throw "should be someValue"; +>valueZ : Symbol(valueZ, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 12, 8)) +>"" : Symbol(valueZ[""], Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 7, 8)) + +if (valueZ[""] !== valueZ) throw "should be export namespace"; +>valueZ : Symbol(valueZ, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 12, 8)) +>"" : Symbol(valueZ[""], Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 11, 6)) +>valueZ : Symbol(valueZ, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 12, 8)) + +export { type someType as "" }; +>someType : Symbol(someType, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 0, 30)) +>"" : Symbol(valueZ[""], Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 17, 8)) + +import { type "" as typeA } from "./arbitraryModuleNamespaceIdentifiers_module"; +>typeA : Symbol(typeA, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 18, 8)) + +const importTest: typeA = "expect error about someType"; +>importTest : Symbol(importTest, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 19, 5)) +>typeA : Symbol(typeA, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 18, 8)) + +export { type "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; +>"" : Symbol(valueZ[""], Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 21, 8)) + +import { type "" as typeB } from "./arbitraryModuleNamespaceIdentifiers_module"; +>typeB : Symbol(typeB, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 22, 8)) + +const reimportTest: typeB = "expect error about someType"; +>reimportTest : Symbol(reimportTest, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 23, 5)) +>typeB : Symbol(typeB, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 22, 8)) + +export type * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; +>"" : Symbol(valueZ[""], Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 25, 11)) + +import { type "" as typeC } from "./arbitraryModuleNamespaceIdentifiers_module"; +>typeC : Symbol(typeC, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 26, 8)) + +export type otherType = "otherType"; +>otherType : Symbol(valueZ.otherType, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 26, 83)) + +const importStarTestA: typeC.otherType = "expect error about otherType"; +>importStarTestA : Symbol(importStarTestA, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 28, 5)) +>typeC : Symbol(typeC, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 26, 8)) +>otherType : Symbol(valueZ.otherType, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 26, 83)) + diff --git a/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=nodenext).types b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=nodenext).types new file mode 100644 index 0000000000000..4574f9754d0b4 --- /dev/null +++ b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=nodenext).types @@ -0,0 +1,151 @@ +//// [tests/cases/conformance/es2022/arbitraryModuleNamespaceIdentifiers/arbitraryModuleNamespaceIdentifiers_module.ts] //// + +=== arbitraryModuleNamespaceIdentifiers_module.ts === +const someValue = "someValue"; +>someValue : "someValue" +> : ^^^^^^^^^^^ +>"someValue" : "someValue" +> : ^^^^^^^^^^^ + +type someType = "someType"; +>someType : "someType" +> : ^^^^^^^^^^ + +export { someValue as "" }; +>someValue : "someValue" +> : ^^^^^^^^^^^ +>"" : "someValue" +> : ^^^^^^^^^^^ + +import { "" as valueX } from "./arbitraryModuleNamespaceIdentifiers_module"; +>valueX : "someValue" +> : ^^^^^^^^^^^ + +if (valueX !== "someValue") throw "should be someValue"; +>valueX !== "someValue" : boolean +> : ^^^^^^^ +>valueX : "someValue" +> : ^^^^^^^^^^^ +>"someValue" : "someValue" +> : ^^^^^^^^^^^ +>"should be someValue" : "should be someValue" +> : ^^^^^^^^^^^^^^^^^^^^^ + +export { "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; +>"" : "someValue" +> : ^^^^^^^^^^^ + +import { "" as valueY } from "./arbitraryModuleNamespaceIdentifiers_module"; +>valueY : "someValue" +> : ^^^^^^^^^^^ + +if (valueY !== "someValue") throw "should be someValue"; +>valueY !== "someValue" : boolean +> : ^^^^^^^ +>valueY : "someValue" +> : ^^^^^^^^^^^ +>"someValue" : "someValue" +> : ^^^^^^^^^^^ +>"should be someValue" : "should be someValue" +> : ^^^^^^^^^^^^^^^^^^^^^ + +export * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; +>"" : typeof valueZ +> : ^^^^^^^^^^^^^ + +import { "" as valueZ } from "./arbitraryModuleNamespaceIdentifiers_module"; +>valueZ : typeof valueZ +> : ^^^^^^^^^^^^^ + +if (valueZ[""] !== "someValue") throw "should be someValue"; +>valueZ[""] !== "someValue" : boolean +> : ^^^^^^^ +>valueZ[""] : "someValue" +> : ^^^^^^^^^^^ +>valueZ : typeof valueZ +> : ^^^^^^^^^^^^^ +>"" : "" +> : ^^^^^ +>"someValue" : "someValue" +> : ^^^^^^^^^^^ +>"should be someValue" : "should be someValue" +> : ^^^^^^^^^^^^^^^^^^^^^ + +if (valueZ[""] !== "someValue") throw "should be someValue"; +>valueZ[""] !== "someValue" : boolean +> : ^^^^^^^ +>valueZ[""] : "someValue" +> : ^^^^^^^^^^^ +>valueZ : typeof valueZ +> : ^^^^^^^^^^^^^ +>"" : "" +> : ^^^^^ +>"someValue" : "someValue" +> : ^^^^^^^^^^^ +>"should be someValue" : "should be someValue" +> : ^^^^^^^^^^^^^^^^^^^^^ + +if (valueZ[""] !== valueZ) throw "should be export namespace"; +>valueZ[""] !== valueZ : boolean +> : ^^^^^^^ +>valueZ[""] : typeof valueZ +> : ^^^^^^^^^^^^^ +>valueZ : typeof valueZ +> : ^^^^^^^^^^^^^ +>"" : "" +> : ^^^^^ +>valueZ : typeof valueZ +> : ^^^^^^^^^^^^^ +>"should be export namespace" : "should be export namespace" +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +export { type someType as "" }; +>someType : any +> : ^^^ +>"" : any +> : ^^^ + +import { type "" as typeA } from "./arbitraryModuleNamespaceIdentifiers_module"; +>typeA : any +> : ^^^ + +const importTest: typeA = "expect error about someType"; +>importTest : "someType" +> : ^^^^^^^^^^ +>"expect error about someType" : "expect error about someType" +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +export { type "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; +>"" : any +> : ^^^ + +import { type "" as typeB } from "./arbitraryModuleNamespaceIdentifiers_module"; +>typeB : any +> : ^^^ + +const reimportTest: typeB = "expect error about someType"; +>reimportTest : "someType" +> : ^^^^^^^^^^ +>"expect error about someType" : "expect error about someType" +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +export type * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; +>"" : typeof valueZ +> : ^^^^^^^^^^^^^ + +import { type "" as typeC } from "./arbitraryModuleNamespaceIdentifiers_module"; +>typeC : typeof valueZ +> : ^^^^^^^^^^^^^ + +export type otherType = "otherType"; +>otherType : "otherType" +> : ^^^^^^^^^^^ + +const importStarTestA: typeC.otherType = "expect error about otherType"; +>importStarTestA : "otherType" +> : ^^^^^^^^^^^ +>typeC : any +> : ^^^ +>"expect error about otherType" : "expect error about otherType" +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + diff --git a/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=none).errors.txt b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=none).errors.txt new file mode 100644 index 0000000000000..cc359bceb4904 --- /dev/null +++ b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=none).errors.txt @@ -0,0 +1,42 @@ +arbitraryModuleNamespaceIdentifiers_module.ts(20,7): error TS2322: Type '"expect error about someType"' is not assignable to type '"someType"'. +arbitraryModuleNamespaceIdentifiers_module.ts(24,7): error TS2322: Type '"expect error about someType"' is not assignable to type '"someType"'. +arbitraryModuleNamespaceIdentifiers_module.ts(29,7): error TS2322: Type '"expect error about otherType"' is not assignable to type '"otherType"'. + + +==== arbitraryModuleNamespaceIdentifiers_module.ts (3 errors) ==== + const someValue = "someValue"; + type someType = "someType"; + + export { someValue as "" }; + import { "" as valueX } from "./arbitraryModuleNamespaceIdentifiers_module"; + if (valueX !== "someValue") throw "should be someValue"; + + export { "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; + import { "" as valueY } from "./arbitraryModuleNamespaceIdentifiers_module"; + if (valueY !== "someValue") throw "should be someValue"; + + export * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; + import { "" as valueZ } from "./arbitraryModuleNamespaceIdentifiers_module"; + if (valueZ[""] !== "someValue") throw "should be someValue"; + if (valueZ[""] !== "someValue") throw "should be someValue"; + if (valueZ[""] !== valueZ) throw "should be export namespace"; + + export { type someType as "" }; + import { type "" as typeA } from "./arbitraryModuleNamespaceIdentifiers_module"; + const importTest: typeA = "expect error about someType"; + ~~~~~~~~~~ +!!! error TS2322: Type '"expect error about someType"' is not assignable to type '"someType"'. + + export { type "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; + import { type "" as typeB } from "./arbitraryModuleNamespaceIdentifiers_module"; + const reimportTest: typeB = "expect error about someType"; + ~~~~~~~~~~~~ +!!! error TS2322: Type '"expect error about someType"' is not assignable to type '"someType"'. + + export type * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; + import { type "" as typeC } from "./arbitraryModuleNamespaceIdentifiers_module"; + export type otherType = "otherType"; + const importStarTestA: typeC.otherType = "expect error about otherType"; + ~~~~~~~~~~~~~~~ +!!! error TS2322: Type '"expect error about otherType"' is not assignable to type '"otherType"'. + \ No newline at end of file diff --git a/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=none).js b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=none).js new file mode 100644 index 0000000000000..43f95451590dc --- /dev/null +++ b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=none).js @@ -0,0 +1,71 @@ +//// [tests/cases/conformance/es2022/arbitraryModuleNamespaceIdentifiers/arbitraryModuleNamespaceIdentifiers_module.ts] //// + +//// [arbitraryModuleNamespaceIdentifiers_module.ts] +const someValue = "someValue"; +type someType = "someType"; + +export { someValue as "" }; +import { "" as valueX } from "./arbitraryModuleNamespaceIdentifiers_module"; +if (valueX !== "someValue") throw "should be someValue"; + +export { "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; +import { "" as valueY } from "./arbitraryModuleNamespaceIdentifiers_module"; +if (valueY !== "someValue") throw "should be someValue"; + +export * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; +import { "" as valueZ } from "./arbitraryModuleNamespaceIdentifiers_module"; +if (valueZ[""] !== "someValue") throw "should be someValue"; +if (valueZ[""] !== "someValue") throw "should be someValue"; +if (valueZ[""] !== valueZ) throw "should be export namespace"; + +export { type someType as "" }; +import { type "" as typeA } from "./arbitraryModuleNamespaceIdentifiers_module"; +const importTest: typeA = "expect error about someType"; + +export { type "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; +import { type "" as typeB } from "./arbitraryModuleNamespaceIdentifiers_module"; +const reimportTest: typeB = "expect error about someType"; + +export type * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; +import { type "" as typeC } from "./arbitraryModuleNamespaceIdentifiers_module"; +export type otherType = "otherType"; +const importStarTestA: typeC.otherType = "expect error about otherType"; + + +//// [arbitraryModuleNamespaceIdentifiers_module.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports[""] = exports[""] = exports[""] = void 0; +const someValue = "someValue"; +exports[""] = someValue; +const arbitraryModuleNamespaceIdentifiers_module_1 = require("./arbitraryModuleNamespaceIdentifiers_module"); +if (arbitraryModuleNamespaceIdentifiers_module_1[""] !== "someValue") + throw "should be someValue"; +var arbitraryModuleNamespaceIdentifiers_module_2 = require("./arbitraryModuleNamespaceIdentifiers_module"); +Object.defineProperty(exports, "", { enumerable: true, get: function () { return arbitraryModuleNamespaceIdentifiers_module_2[""]; } }); +const arbitraryModuleNamespaceIdentifiers_module_3 = require("./arbitraryModuleNamespaceIdentifiers_module"); +if (arbitraryModuleNamespaceIdentifiers_module_3[""] !== "someValue") + throw "should be someValue"; +exports[""] = require("./arbitraryModuleNamespaceIdentifiers_module"); +const arbitraryModuleNamespaceIdentifiers_module_4 = require("./arbitraryModuleNamespaceIdentifiers_module"); +if (arbitraryModuleNamespaceIdentifiers_module_4[""][""] !== "someValue") + throw "should be someValue"; +if (arbitraryModuleNamespaceIdentifiers_module_4[""][""] !== "someValue") + throw "should be someValue"; +if (arbitraryModuleNamespaceIdentifiers_module_4[""][""] !== arbitraryModuleNamespaceIdentifiers_module_4[""]) + throw "should be export namespace"; +const importTest = "expect error about someType"; +const reimportTest = "expect error about someType"; +const importStarTestA = "expect error about otherType"; + + +//// [arbitraryModuleNamespaceIdentifiers_module.d.ts] +declare const someValue = "someValue"; +type someType = "someType"; +export { someValue as "" }; +export { "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; +export * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; +export { type someType as "" }; +export { type "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; +export type * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; +export type otherType = "otherType"; diff --git a/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=none).symbols b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=none).symbols new file mode 100644 index 0000000000000..a792b7d3f5280 --- /dev/null +++ b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=none).symbols @@ -0,0 +1,82 @@ +//// [tests/cases/conformance/es2022/arbitraryModuleNamespaceIdentifiers/arbitraryModuleNamespaceIdentifiers_module.ts] //// + +=== arbitraryModuleNamespaceIdentifiers_module.ts === +const someValue = "someValue"; +>someValue : Symbol(someValue, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 0, 5)) + +type someType = "someType"; +>someType : Symbol(someType, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 0, 30)) + +export { someValue as "" }; +>someValue : Symbol(someValue, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 0, 5)) +>"" : Symbol(valueZ[""], Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 3, 8)) + +import { "" as valueX } from "./arbitraryModuleNamespaceIdentifiers_module"; +>valueX : Symbol(valueX, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 4, 8)) + +if (valueX !== "someValue") throw "should be someValue"; +>valueX : Symbol(valueX, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 4, 8)) + +export { "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; +>"" : Symbol(valueZ[""], Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 7, 8)) + +import { "" as valueY } from "./arbitraryModuleNamespaceIdentifiers_module"; +>valueY : Symbol(valueY, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 8, 8)) + +if (valueY !== "someValue") throw "should be someValue"; +>valueY : Symbol(valueY, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 8, 8)) + +export * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; +>"" : Symbol(valueZ[""], Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 11, 6)) + +import { "" as valueZ } from "./arbitraryModuleNamespaceIdentifiers_module"; +>valueZ : Symbol(valueZ, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 12, 8)) + +if (valueZ[""] !== "someValue") throw "should be someValue"; +>valueZ : Symbol(valueZ, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 12, 8)) +>"" : Symbol(valueZ[""], Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 3, 8)) + +if (valueZ[""] !== "someValue") throw "should be someValue"; +>valueZ : Symbol(valueZ, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 12, 8)) +>"" : Symbol(valueZ[""], Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 7, 8)) + +if (valueZ[""] !== valueZ) throw "should be export namespace"; +>valueZ : Symbol(valueZ, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 12, 8)) +>"" : Symbol(valueZ[""], Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 11, 6)) +>valueZ : Symbol(valueZ, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 12, 8)) + +export { type someType as "" }; +>someType : Symbol(someType, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 0, 30)) +>"" : Symbol(valueZ[""], Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 17, 8)) + +import { type "" as typeA } from "./arbitraryModuleNamespaceIdentifiers_module"; +>typeA : Symbol(typeA, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 18, 8)) + +const importTest: typeA = "expect error about someType"; +>importTest : Symbol(importTest, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 19, 5)) +>typeA : Symbol(typeA, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 18, 8)) + +export { type "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; +>"" : Symbol(valueZ[""], Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 21, 8)) + +import { type "" as typeB } from "./arbitraryModuleNamespaceIdentifiers_module"; +>typeB : Symbol(typeB, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 22, 8)) + +const reimportTest: typeB = "expect error about someType"; +>reimportTest : Symbol(reimportTest, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 23, 5)) +>typeB : Symbol(typeB, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 22, 8)) + +export type * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; +>"" : Symbol(valueZ[""], Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 25, 11)) + +import { type "" as typeC } from "./arbitraryModuleNamespaceIdentifiers_module"; +>typeC : Symbol(typeC, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 26, 8)) + +export type otherType = "otherType"; +>otherType : Symbol(valueZ.otherType, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 26, 83)) + +const importStarTestA: typeC.otherType = "expect error about otherType"; +>importStarTestA : Symbol(importStarTestA, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 28, 5)) +>typeC : Symbol(typeC, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 26, 8)) +>otherType : Symbol(valueZ.otherType, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 26, 83)) + diff --git a/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=none).types b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=none).types new file mode 100644 index 0000000000000..4574f9754d0b4 --- /dev/null +++ b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=none).types @@ -0,0 +1,151 @@ +//// [tests/cases/conformance/es2022/arbitraryModuleNamespaceIdentifiers/arbitraryModuleNamespaceIdentifiers_module.ts] //// + +=== arbitraryModuleNamespaceIdentifiers_module.ts === +const someValue = "someValue"; +>someValue : "someValue" +> : ^^^^^^^^^^^ +>"someValue" : "someValue" +> : ^^^^^^^^^^^ + +type someType = "someType"; +>someType : "someType" +> : ^^^^^^^^^^ + +export { someValue as "" }; +>someValue : "someValue" +> : ^^^^^^^^^^^ +>"" : "someValue" +> : ^^^^^^^^^^^ + +import { "" as valueX } from "./arbitraryModuleNamespaceIdentifiers_module"; +>valueX : "someValue" +> : ^^^^^^^^^^^ + +if (valueX !== "someValue") throw "should be someValue"; +>valueX !== "someValue" : boolean +> : ^^^^^^^ +>valueX : "someValue" +> : ^^^^^^^^^^^ +>"someValue" : "someValue" +> : ^^^^^^^^^^^ +>"should be someValue" : "should be someValue" +> : ^^^^^^^^^^^^^^^^^^^^^ + +export { "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; +>"" : "someValue" +> : ^^^^^^^^^^^ + +import { "" as valueY } from "./arbitraryModuleNamespaceIdentifiers_module"; +>valueY : "someValue" +> : ^^^^^^^^^^^ + +if (valueY !== "someValue") throw "should be someValue"; +>valueY !== "someValue" : boolean +> : ^^^^^^^ +>valueY : "someValue" +> : ^^^^^^^^^^^ +>"someValue" : "someValue" +> : ^^^^^^^^^^^ +>"should be someValue" : "should be someValue" +> : ^^^^^^^^^^^^^^^^^^^^^ + +export * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; +>"" : typeof valueZ +> : ^^^^^^^^^^^^^ + +import { "" as valueZ } from "./arbitraryModuleNamespaceIdentifiers_module"; +>valueZ : typeof valueZ +> : ^^^^^^^^^^^^^ + +if (valueZ[""] !== "someValue") throw "should be someValue"; +>valueZ[""] !== "someValue" : boolean +> : ^^^^^^^ +>valueZ[""] : "someValue" +> : ^^^^^^^^^^^ +>valueZ : typeof valueZ +> : ^^^^^^^^^^^^^ +>"" : "" +> : ^^^^^ +>"someValue" : "someValue" +> : ^^^^^^^^^^^ +>"should be someValue" : "should be someValue" +> : ^^^^^^^^^^^^^^^^^^^^^ + +if (valueZ[""] !== "someValue") throw "should be someValue"; +>valueZ[""] !== "someValue" : boolean +> : ^^^^^^^ +>valueZ[""] : "someValue" +> : ^^^^^^^^^^^ +>valueZ : typeof valueZ +> : ^^^^^^^^^^^^^ +>"" : "" +> : ^^^^^ +>"someValue" : "someValue" +> : ^^^^^^^^^^^ +>"should be someValue" : "should be someValue" +> : ^^^^^^^^^^^^^^^^^^^^^ + +if (valueZ[""] !== valueZ) throw "should be export namespace"; +>valueZ[""] !== valueZ : boolean +> : ^^^^^^^ +>valueZ[""] : typeof valueZ +> : ^^^^^^^^^^^^^ +>valueZ : typeof valueZ +> : ^^^^^^^^^^^^^ +>"" : "" +> : ^^^^^ +>valueZ : typeof valueZ +> : ^^^^^^^^^^^^^ +>"should be export namespace" : "should be export namespace" +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +export { type someType as "" }; +>someType : any +> : ^^^ +>"" : any +> : ^^^ + +import { type "" as typeA } from "./arbitraryModuleNamespaceIdentifiers_module"; +>typeA : any +> : ^^^ + +const importTest: typeA = "expect error about someType"; +>importTest : "someType" +> : ^^^^^^^^^^ +>"expect error about someType" : "expect error about someType" +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +export { type "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; +>"" : any +> : ^^^ + +import { type "" as typeB } from "./arbitraryModuleNamespaceIdentifiers_module"; +>typeB : any +> : ^^^ + +const reimportTest: typeB = "expect error about someType"; +>reimportTest : "someType" +> : ^^^^^^^^^^ +>"expect error about someType" : "expect error about someType" +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +export type * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; +>"" : typeof valueZ +> : ^^^^^^^^^^^^^ + +import { type "" as typeC } from "./arbitraryModuleNamespaceIdentifiers_module"; +>typeC : typeof valueZ +> : ^^^^^^^^^^^^^ + +export type otherType = "otherType"; +>otherType : "otherType" +> : ^^^^^^^^^^^ + +const importStarTestA: typeC.otherType = "expect error about otherType"; +>importStarTestA : "otherType" +> : ^^^^^^^^^^^ +>typeC : any +> : ^^^ +>"expect error about otherType" : "expect error about otherType" +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + diff --git a/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=preserve).errors.txt b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=preserve).errors.txt new file mode 100644 index 0000000000000..cc359bceb4904 --- /dev/null +++ b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=preserve).errors.txt @@ -0,0 +1,42 @@ +arbitraryModuleNamespaceIdentifiers_module.ts(20,7): error TS2322: Type '"expect error about someType"' is not assignable to type '"someType"'. +arbitraryModuleNamespaceIdentifiers_module.ts(24,7): error TS2322: Type '"expect error about someType"' is not assignable to type '"someType"'. +arbitraryModuleNamespaceIdentifiers_module.ts(29,7): error TS2322: Type '"expect error about otherType"' is not assignable to type '"otherType"'. + + +==== arbitraryModuleNamespaceIdentifiers_module.ts (3 errors) ==== + const someValue = "someValue"; + type someType = "someType"; + + export { someValue as "" }; + import { "" as valueX } from "./arbitraryModuleNamespaceIdentifiers_module"; + if (valueX !== "someValue") throw "should be someValue"; + + export { "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; + import { "" as valueY } from "./arbitraryModuleNamespaceIdentifiers_module"; + if (valueY !== "someValue") throw "should be someValue"; + + export * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; + import { "" as valueZ } from "./arbitraryModuleNamespaceIdentifiers_module"; + if (valueZ[""] !== "someValue") throw "should be someValue"; + if (valueZ[""] !== "someValue") throw "should be someValue"; + if (valueZ[""] !== valueZ) throw "should be export namespace"; + + export { type someType as "" }; + import { type "" as typeA } from "./arbitraryModuleNamespaceIdentifiers_module"; + const importTest: typeA = "expect error about someType"; + ~~~~~~~~~~ +!!! error TS2322: Type '"expect error about someType"' is not assignable to type '"someType"'. + + export { type "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; + import { type "" as typeB } from "./arbitraryModuleNamespaceIdentifiers_module"; + const reimportTest: typeB = "expect error about someType"; + ~~~~~~~~~~~~ +!!! error TS2322: Type '"expect error about someType"' is not assignable to type '"someType"'. + + export type * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; + import { type "" as typeC } from "./arbitraryModuleNamespaceIdentifiers_module"; + export type otherType = "otherType"; + const importStarTestA: typeC.otherType = "expect error about otherType"; + ~~~~~~~~~~~~~~~ +!!! error TS2322: Type '"expect error about otherType"' is not assignable to type '"otherType"'. + \ No newline at end of file diff --git a/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=preserve).js b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=preserve).js new file mode 100644 index 0000000000000..4964f684a1ed0 --- /dev/null +++ b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=preserve).js @@ -0,0 +1,67 @@ +//// [tests/cases/conformance/es2022/arbitraryModuleNamespaceIdentifiers/arbitraryModuleNamespaceIdentifiers_module.ts] //// + +//// [arbitraryModuleNamespaceIdentifiers_module.ts] +const someValue = "someValue"; +type someType = "someType"; + +export { someValue as "" }; +import { "" as valueX } from "./arbitraryModuleNamespaceIdentifiers_module"; +if (valueX !== "someValue") throw "should be someValue"; + +export { "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; +import { "" as valueY } from "./arbitraryModuleNamespaceIdentifiers_module"; +if (valueY !== "someValue") throw "should be someValue"; + +export * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; +import { "" as valueZ } from "./arbitraryModuleNamespaceIdentifiers_module"; +if (valueZ[""] !== "someValue") throw "should be someValue"; +if (valueZ[""] !== "someValue") throw "should be someValue"; +if (valueZ[""] !== valueZ) throw "should be export namespace"; + +export { type someType as "" }; +import { type "" as typeA } from "./arbitraryModuleNamespaceIdentifiers_module"; +const importTest: typeA = "expect error about someType"; + +export { type "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; +import { type "" as typeB } from "./arbitraryModuleNamespaceIdentifiers_module"; +const reimportTest: typeB = "expect error about someType"; + +export type * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; +import { type "" as typeC } from "./arbitraryModuleNamespaceIdentifiers_module"; +export type otherType = "otherType"; +const importStarTestA: typeC.otherType = "expect error about otherType"; + + +//// [arbitraryModuleNamespaceIdentifiers_module.js] +const someValue = "someValue"; +export { someValue as "" }; +import { "" as valueX } from "./arbitraryModuleNamespaceIdentifiers_module"; +if (valueX !== "someValue") + throw "should be someValue"; +export { "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; +import { "" as valueY } from "./arbitraryModuleNamespaceIdentifiers_module"; +if (valueY !== "someValue") + throw "should be someValue"; +export * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; +import { "" as valueZ } from "./arbitraryModuleNamespaceIdentifiers_module"; +if (valueZ[""] !== "someValue") + throw "should be someValue"; +if (valueZ[""] !== "someValue") + throw "should be someValue"; +if (valueZ[""] !== valueZ) + throw "should be export namespace"; +const importTest = "expect error about someType"; +const reimportTest = "expect error about someType"; +const importStarTestA = "expect error about otherType"; + + +//// [arbitraryModuleNamespaceIdentifiers_module.d.ts] +declare const someValue = "someValue"; +type someType = "someType"; +export { someValue as "" }; +export { "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; +export * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; +export { type someType as "" }; +export { type "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; +export type * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; +export type otherType = "otherType"; diff --git a/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=preserve).symbols b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=preserve).symbols new file mode 100644 index 0000000000000..a792b7d3f5280 --- /dev/null +++ b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=preserve).symbols @@ -0,0 +1,82 @@ +//// [tests/cases/conformance/es2022/arbitraryModuleNamespaceIdentifiers/arbitraryModuleNamespaceIdentifiers_module.ts] //// + +=== arbitraryModuleNamespaceIdentifiers_module.ts === +const someValue = "someValue"; +>someValue : Symbol(someValue, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 0, 5)) + +type someType = "someType"; +>someType : Symbol(someType, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 0, 30)) + +export { someValue as "" }; +>someValue : Symbol(someValue, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 0, 5)) +>"" : Symbol(valueZ[""], Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 3, 8)) + +import { "" as valueX } from "./arbitraryModuleNamespaceIdentifiers_module"; +>valueX : Symbol(valueX, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 4, 8)) + +if (valueX !== "someValue") throw "should be someValue"; +>valueX : Symbol(valueX, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 4, 8)) + +export { "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; +>"" : Symbol(valueZ[""], Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 7, 8)) + +import { "" as valueY } from "./arbitraryModuleNamespaceIdentifiers_module"; +>valueY : Symbol(valueY, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 8, 8)) + +if (valueY !== "someValue") throw "should be someValue"; +>valueY : Symbol(valueY, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 8, 8)) + +export * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; +>"" : Symbol(valueZ[""], Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 11, 6)) + +import { "" as valueZ } from "./arbitraryModuleNamespaceIdentifiers_module"; +>valueZ : Symbol(valueZ, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 12, 8)) + +if (valueZ[""] !== "someValue") throw "should be someValue"; +>valueZ : Symbol(valueZ, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 12, 8)) +>"" : Symbol(valueZ[""], Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 3, 8)) + +if (valueZ[""] !== "someValue") throw "should be someValue"; +>valueZ : Symbol(valueZ, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 12, 8)) +>"" : Symbol(valueZ[""], Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 7, 8)) + +if (valueZ[""] !== valueZ) throw "should be export namespace"; +>valueZ : Symbol(valueZ, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 12, 8)) +>"" : Symbol(valueZ[""], Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 11, 6)) +>valueZ : Symbol(valueZ, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 12, 8)) + +export { type someType as "" }; +>someType : Symbol(someType, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 0, 30)) +>"" : Symbol(valueZ[""], Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 17, 8)) + +import { type "" as typeA } from "./arbitraryModuleNamespaceIdentifiers_module"; +>typeA : Symbol(typeA, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 18, 8)) + +const importTest: typeA = "expect error about someType"; +>importTest : Symbol(importTest, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 19, 5)) +>typeA : Symbol(typeA, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 18, 8)) + +export { type "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; +>"" : Symbol(valueZ[""], Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 21, 8)) + +import { type "" as typeB } from "./arbitraryModuleNamespaceIdentifiers_module"; +>typeB : Symbol(typeB, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 22, 8)) + +const reimportTest: typeB = "expect error about someType"; +>reimportTest : Symbol(reimportTest, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 23, 5)) +>typeB : Symbol(typeB, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 22, 8)) + +export type * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; +>"" : Symbol(valueZ[""], Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 25, 11)) + +import { type "" as typeC } from "./arbitraryModuleNamespaceIdentifiers_module"; +>typeC : Symbol(typeC, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 26, 8)) + +export type otherType = "otherType"; +>otherType : Symbol(valueZ.otherType, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 26, 83)) + +const importStarTestA: typeC.otherType = "expect error about otherType"; +>importStarTestA : Symbol(importStarTestA, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 28, 5)) +>typeC : Symbol(typeC, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 26, 8)) +>otherType : Symbol(valueZ.otherType, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 26, 83)) + diff --git a/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=preserve).types b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=preserve).types new file mode 100644 index 0000000000000..4574f9754d0b4 --- /dev/null +++ b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=preserve).types @@ -0,0 +1,151 @@ +//// [tests/cases/conformance/es2022/arbitraryModuleNamespaceIdentifiers/arbitraryModuleNamespaceIdentifiers_module.ts] //// + +=== arbitraryModuleNamespaceIdentifiers_module.ts === +const someValue = "someValue"; +>someValue : "someValue" +> : ^^^^^^^^^^^ +>"someValue" : "someValue" +> : ^^^^^^^^^^^ + +type someType = "someType"; +>someType : "someType" +> : ^^^^^^^^^^ + +export { someValue as "" }; +>someValue : "someValue" +> : ^^^^^^^^^^^ +>"" : "someValue" +> : ^^^^^^^^^^^ + +import { "" as valueX } from "./arbitraryModuleNamespaceIdentifiers_module"; +>valueX : "someValue" +> : ^^^^^^^^^^^ + +if (valueX !== "someValue") throw "should be someValue"; +>valueX !== "someValue" : boolean +> : ^^^^^^^ +>valueX : "someValue" +> : ^^^^^^^^^^^ +>"someValue" : "someValue" +> : ^^^^^^^^^^^ +>"should be someValue" : "should be someValue" +> : ^^^^^^^^^^^^^^^^^^^^^ + +export { "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; +>"" : "someValue" +> : ^^^^^^^^^^^ + +import { "" as valueY } from "./arbitraryModuleNamespaceIdentifiers_module"; +>valueY : "someValue" +> : ^^^^^^^^^^^ + +if (valueY !== "someValue") throw "should be someValue"; +>valueY !== "someValue" : boolean +> : ^^^^^^^ +>valueY : "someValue" +> : ^^^^^^^^^^^ +>"someValue" : "someValue" +> : ^^^^^^^^^^^ +>"should be someValue" : "should be someValue" +> : ^^^^^^^^^^^^^^^^^^^^^ + +export * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; +>"" : typeof valueZ +> : ^^^^^^^^^^^^^ + +import { "" as valueZ } from "./arbitraryModuleNamespaceIdentifiers_module"; +>valueZ : typeof valueZ +> : ^^^^^^^^^^^^^ + +if (valueZ[""] !== "someValue") throw "should be someValue"; +>valueZ[""] !== "someValue" : boolean +> : ^^^^^^^ +>valueZ[""] : "someValue" +> : ^^^^^^^^^^^ +>valueZ : typeof valueZ +> : ^^^^^^^^^^^^^ +>"" : "" +> : ^^^^^ +>"someValue" : "someValue" +> : ^^^^^^^^^^^ +>"should be someValue" : "should be someValue" +> : ^^^^^^^^^^^^^^^^^^^^^ + +if (valueZ[""] !== "someValue") throw "should be someValue"; +>valueZ[""] !== "someValue" : boolean +> : ^^^^^^^ +>valueZ[""] : "someValue" +> : ^^^^^^^^^^^ +>valueZ : typeof valueZ +> : ^^^^^^^^^^^^^ +>"" : "" +> : ^^^^^ +>"someValue" : "someValue" +> : ^^^^^^^^^^^ +>"should be someValue" : "should be someValue" +> : ^^^^^^^^^^^^^^^^^^^^^ + +if (valueZ[""] !== valueZ) throw "should be export namespace"; +>valueZ[""] !== valueZ : boolean +> : ^^^^^^^ +>valueZ[""] : typeof valueZ +> : ^^^^^^^^^^^^^ +>valueZ : typeof valueZ +> : ^^^^^^^^^^^^^ +>"" : "" +> : ^^^^^ +>valueZ : typeof valueZ +> : ^^^^^^^^^^^^^ +>"should be export namespace" : "should be export namespace" +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +export { type someType as "" }; +>someType : any +> : ^^^ +>"" : any +> : ^^^ + +import { type "" as typeA } from "./arbitraryModuleNamespaceIdentifiers_module"; +>typeA : any +> : ^^^ + +const importTest: typeA = "expect error about someType"; +>importTest : "someType" +> : ^^^^^^^^^^ +>"expect error about someType" : "expect error about someType" +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +export { type "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; +>"" : any +> : ^^^ + +import { type "" as typeB } from "./arbitraryModuleNamespaceIdentifiers_module"; +>typeB : any +> : ^^^ + +const reimportTest: typeB = "expect error about someType"; +>reimportTest : "someType" +> : ^^^^^^^^^^ +>"expect error about someType" : "expect error about someType" +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +export type * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; +>"" : typeof valueZ +> : ^^^^^^^^^^^^^ + +import { type "" as typeC } from "./arbitraryModuleNamespaceIdentifiers_module"; +>typeC : typeof valueZ +> : ^^^^^^^^^^^^^ + +export type otherType = "otherType"; +>otherType : "otherType" +> : ^^^^^^^^^^^ + +const importStarTestA: typeC.otherType = "expect error about otherType"; +>importStarTestA : "otherType" +> : ^^^^^^^^^^^ +>typeC : any +> : ^^^ +>"expect error about otherType" : "expect error about otherType" +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + diff --git a/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=system).errors.txt b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=system).errors.txt new file mode 100644 index 0000000000000..cc359bceb4904 --- /dev/null +++ b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=system).errors.txt @@ -0,0 +1,42 @@ +arbitraryModuleNamespaceIdentifiers_module.ts(20,7): error TS2322: Type '"expect error about someType"' is not assignable to type '"someType"'. +arbitraryModuleNamespaceIdentifiers_module.ts(24,7): error TS2322: Type '"expect error about someType"' is not assignable to type '"someType"'. +arbitraryModuleNamespaceIdentifiers_module.ts(29,7): error TS2322: Type '"expect error about otherType"' is not assignable to type '"otherType"'. + + +==== arbitraryModuleNamespaceIdentifiers_module.ts (3 errors) ==== + const someValue = "someValue"; + type someType = "someType"; + + export { someValue as "" }; + import { "" as valueX } from "./arbitraryModuleNamespaceIdentifiers_module"; + if (valueX !== "someValue") throw "should be someValue"; + + export { "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; + import { "" as valueY } from "./arbitraryModuleNamespaceIdentifiers_module"; + if (valueY !== "someValue") throw "should be someValue"; + + export * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; + import { "" as valueZ } from "./arbitraryModuleNamespaceIdentifiers_module"; + if (valueZ[""] !== "someValue") throw "should be someValue"; + if (valueZ[""] !== "someValue") throw "should be someValue"; + if (valueZ[""] !== valueZ) throw "should be export namespace"; + + export { type someType as "" }; + import { type "" as typeA } from "./arbitraryModuleNamespaceIdentifiers_module"; + const importTest: typeA = "expect error about someType"; + ~~~~~~~~~~ +!!! error TS2322: Type '"expect error about someType"' is not assignable to type '"someType"'. + + export { type "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; + import { type "" as typeB } from "./arbitraryModuleNamespaceIdentifiers_module"; + const reimportTest: typeB = "expect error about someType"; + ~~~~~~~~~~~~ +!!! error TS2322: Type '"expect error about someType"' is not assignable to type '"someType"'. + + export type * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; + import { type "" as typeC } from "./arbitraryModuleNamespaceIdentifiers_module"; + export type otherType = "otherType"; + const importStarTestA: typeC.otherType = "expect error about otherType"; + ~~~~~~~~~~~~~~~ +!!! error TS2322: Type '"expect error about otherType"' is not assignable to type '"otherType"'. + \ No newline at end of file diff --git a/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=system).js b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=system).js new file mode 100644 index 0000000000000..c746a3ba3bf1d --- /dev/null +++ b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=system).js @@ -0,0 +1,82 @@ +//// [tests/cases/conformance/es2022/arbitraryModuleNamespaceIdentifiers/arbitraryModuleNamespaceIdentifiers_module.ts] //// + +//// [arbitraryModuleNamespaceIdentifiers_module.ts] +const someValue = "someValue"; +type someType = "someType"; + +export { someValue as "" }; +import { "" as valueX } from "./arbitraryModuleNamespaceIdentifiers_module"; +if (valueX !== "someValue") throw "should be someValue"; + +export { "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; +import { "" as valueY } from "./arbitraryModuleNamespaceIdentifiers_module"; +if (valueY !== "someValue") throw "should be someValue"; + +export * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; +import { "" as valueZ } from "./arbitraryModuleNamespaceIdentifiers_module"; +if (valueZ[""] !== "someValue") throw "should be someValue"; +if (valueZ[""] !== "someValue") throw "should be someValue"; +if (valueZ[""] !== valueZ) throw "should be export namespace"; + +export { type someType as "" }; +import { type "" as typeA } from "./arbitraryModuleNamespaceIdentifiers_module"; +const importTest: typeA = "expect error about someType"; + +export { type "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; +import { type "" as typeB } from "./arbitraryModuleNamespaceIdentifiers_module"; +const reimportTest: typeB = "expect error about someType"; + +export type * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; +import { type "" as typeC } from "./arbitraryModuleNamespaceIdentifiers_module"; +export type otherType = "otherType"; +const importStarTestA: typeC.otherType = "expect error about otherType"; + + +//// [arbitraryModuleNamespaceIdentifiers_module.js] +System.register(["./arbitraryModuleNamespaceIdentifiers_module"], function (exports_1, context_1) { + "use strict"; + var someValue, arbitraryModuleNamespaceIdentifiers_module_1, arbitraryModuleNamespaceIdentifiers_module_2, arbitraryModuleNamespaceIdentifiers_module_3, importTest, reimportTest, importStarTestA; + var __moduleName = context_1 && context_1.id; + return { + setters: [ + function (arbitraryModuleNamespaceIdentifiers_module_1_1) { + arbitraryModuleNamespaceIdentifiers_module_1 = arbitraryModuleNamespaceIdentifiers_module_1_1; + exports_1({ + "": arbitraryModuleNamespaceIdentifiers_module_1_1[""] + }); + arbitraryModuleNamespaceIdentifiers_module_2 = arbitraryModuleNamespaceIdentifiers_module_1_1; + exports_1("", arbitraryModuleNamespaceIdentifiers_module_1_1); + arbitraryModuleNamespaceIdentifiers_module_3 = arbitraryModuleNamespaceIdentifiers_module_1_1; + } + ], + execute: function () { + someValue = "someValue"; + exports_1("", someValue); + if (arbitraryModuleNamespaceIdentifiers_module_1[""] !== "someValue") + throw "should be someValue"; + if (arbitraryModuleNamespaceIdentifiers_module_2[""] !== "someValue") + throw "should be someValue"; + if (arbitraryModuleNamespaceIdentifiers_module_3[""][""] !== "someValue") + throw "should be someValue"; + if (arbitraryModuleNamespaceIdentifiers_module_3[""][""] !== "someValue") + throw "should be someValue"; + if (arbitraryModuleNamespaceIdentifiers_module_3[""][""] !== arbitraryModuleNamespaceIdentifiers_module_3[""]) + throw "should be export namespace"; + importTest = "expect error about someType"; + reimportTest = "expect error about someType"; + importStarTestA = "expect error about otherType"; + } + }; +}); + + +//// [arbitraryModuleNamespaceIdentifiers_module.d.ts] +declare const someValue = "someValue"; +type someType = "someType"; +export { someValue as "" }; +export { "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; +export * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; +export { type someType as "" }; +export { type "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; +export type * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; +export type otherType = "otherType"; diff --git a/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=system).symbols b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=system).symbols new file mode 100644 index 0000000000000..a792b7d3f5280 --- /dev/null +++ b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=system).symbols @@ -0,0 +1,82 @@ +//// [tests/cases/conformance/es2022/arbitraryModuleNamespaceIdentifiers/arbitraryModuleNamespaceIdentifiers_module.ts] //// + +=== arbitraryModuleNamespaceIdentifiers_module.ts === +const someValue = "someValue"; +>someValue : Symbol(someValue, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 0, 5)) + +type someType = "someType"; +>someType : Symbol(someType, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 0, 30)) + +export { someValue as "" }; +>someValue : Symbol(someValue, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 0, 5)) +>"" : Symbol(valueZ[""], Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 3, 8)) + +import { "" as valueX } from "./arbitraryModuleNamespaceIdentifiers_module"; +>valueX : Symbol(valueX, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 4, 8)) + +if (valueX !== "someValue") throw "should be someValue"; +>valueX : Symbol(valueX, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 4, 8)) + +export { "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; +>"" : Symbol(valueZ[""], Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 7, 8)) + +import { "" as valueY } from "./arbitraryModuleNamespaceIdentifiers_module"; +>valueY : Symbol(valueY, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 8, 8)) + +if (valueY !== "someValue") throw "should be someValue"; +>valueY : Symbol(valueY, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 8, 8)) + +export * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; +>"" : Symbol(valueZ[""], Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 11, 6)) + +import { "" as valueZ } from "./arbitraryModuleNamespaceIdentifiers_module"; +>valueZ : Symbol(valueZ, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 12, 8)) + +if (valueZ[""] !== "someValue") throw "should be someValue"; +>valueZ : Symbol(valueZ, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 12, 8)) +>"" : Symbol(valueZ[""], Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 3, 8)) + +if (valueZ[""] !== "someValue") throw "should be someValue"; +>valueZ : Symbol(valueZ, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 12, 8)) +>"" : Symbol(valueZ[""], Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 7, 8)) + +if (valueZ[""] !== valueZ) throw "should be export namespace"; +>valueZ : Symbol(valueZ, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 12, 8)) +>"" : Symbol(valueZ[""], Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 11, 6)) +>valueZ : Symbol(valueZ, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 12, 8)) + +export { type someType as "" }; +>someType : Symbol(someType, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 0, 30)) +>"" : Symbol(valueZ[""], Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 17, 8)) + +import { type "" as typeA } from "./arbitraryModuleNamespaceIdentifiers_module"; +>typeA : Symbol(typeA, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 18, 8)) + +const importTest: typeA = "expect error about someType"; +>importTest : Symbol(importTest, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 19, 5)) +>typeA : Symbol(typeA, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 18, 8)) + +export { type "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; +>"" : Symbol(valueZ[""], Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 21, 8)) + +import { type "" as typeB } from "./arbitraryModuleNamespaceIdentifiers_module"; +>typeB : Symbol(typeB, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 22, 8)) + +const reimportTest: typeB = "expect error about someType"; +>reimportTest : Symbol(reimportTest, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 23, 5)) +>typeB : Symbol(typeB, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 22, 8)) + +export type * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; +>"" : Symbol(valueZ[""], Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 25, 11)) + +import { type "" as typeC } from "./arbitraryModuleNamespaceIdentifiers_module"; +>typeC : Symbol(typeC, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 26, 8)) + +export type otherType = "otherType"; +>otherType : Symbol(valueZ.otherType, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 26, 83)) + +const importStarTestA: typeC.otherType = "expect error about otherType"; +>importStarTestA : Symbol(importStarTestA, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 28, 5)) +>typeC : Symbol(typeC, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 26, 8)) +>otherType : Symbol(valueZ.otherType, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 26, 83)) + diff --git a/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=system).types b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=system).types new file mode 100644 index 0000000000000..4574f9754d0b4 --- /dev/null +++ b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=system).types @@ -0,0 +1,151 @@ +//// [tests/cases/conformance/es2022/arbitraryModuleNamespaceIdentifiers/arbitraryModuleNamespaceIdentifiers_module.ts] //// + +=== arbitraryModuleNamespaceIdentifiers_module.ts === +const someValue = "someValue"; +>someValue : "someValue" +> : ^^^^^^^^^^^ +>"someValue" : "someValue" +> : ^^^^^^^^^^^ + +type someType = "someType"; +>someType : "someType" +> : ^^^^^^^^^^ + +export { someValue as "" }; +>someValue : "someValue" +> : ^^^^^^^^^^^ +>"" : "someValue" +> : ^^^^^^^^^^^ + +import { "" as valueX } from "./arbitraryModuleNamespaceIdentifiers_module"; +>valueX : "someValue" +> : ^^^^^^^^^^^ + +if (valueX !== "someValue") throw "should be someValue"; +>valueX !== "someValue" : boolean +> : ^^^^^^^ +>valueX : "someValue" +> : ^^^^^^^^^^^ +>"someValue" : "someValue" +> : ^^^^^^^^^^^ +>"should be someValue" : "should be someValue" +> : ^^^^^^^^^^^^^^^^^^^^^ + +export { "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; +>"" : "someValue" +> : ^^^^^^^^^^^ + +import { "" as valueY } from "./arbitraryModuleNamespaceIdentifiers_module"; +>valueY : "someValue" +> : ^^^^^^^^^^^ + +if (valueY !== "someValue") throw "should be someValue"; +>valueY !== "someValue" : boolean +> : ^^^^^^^ +>valueY : "someValue" +> : ^^^^^^^^^^^ +>"someValue" : "someValue" +> : ^^^^^^^^^^^ +>"should be someValue" : "should be someValue" +> : ^^^^^^^^^^^^^^^^^^^^^ + +export * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; +>"" : typeof valueZ +> : ^^^^^^^^^^^^^ + +import { "" as valueZ } from "./arbitraryModuleNamespaceIdentifiers_module"; +>valueZ : typeof valueZ +> : ^^^^^^^^^^^^^ + +if (valueZ[""] !== "someValue") throw "should be someValue"; +>valueZ[""] !== "someValue" : boolean +> : ^^^^^^^ +>valueZ[""] : "someValue" +> : ^^^^^^^^^^^ +>valueZ : typeof valueZ +> : ^^^^^^^^^^^^^ +>"" : "" +> : ^^^^^ +>"someValue" : "someValue" +> : ^^^^^^^^^^^ +>"should be someValue" : "should be someValue" +> : ^^^^^^^^^^^^^^^^^^^^^ + +if (valueZ[""] !== "someValue") throw "should be someValue"; +>valueZ[""] !== "someValue" : boolean +> : ^^^^^^^ +>valueZ[""] : "someValue" +> : ^^^^^^^^^^^ +>valueZ : typeof valueZ +> : ^^^^^^^^^^^^^ +>"" : "" +> : ^^^^^ +>"someValue" : "someValue" +> : ^^^^^^^^^^^ +>"should be someValue" : "should be someValue" +> : ^^^^^^^^^^^^^^^^^^^^^ + +if (valueZ[""] !== valueZ) throw "should be export namespace"; +>valueZ[""] !== valueZ : boolean +> : ^^^^^^^ +>valueZ[""] : typeof valueZ +> : ^^^^^^^^^^^^^ +>valueZ : typeof valueZ +> : ^^^^^^^^^^^^^ +>"" : "" +> : ^^^^^ +>valueZ : typeof valueZ +> : ^^^^^^^^^^^^^ +>"should be export namespace" : "should be export namespace" +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +export { type someType as "" }; +>someType : any +> : ^^^ +>"" : any +> : ^^^ + +import { type "" as typeA } from "./arbitraryModuleNamespaceIdentifiers_module"; +>typeA : any +> : ^^^ + +const importTest: typeA = "expect error about someType"; +>importTest : "someType" +> : ^^^^^^^^^^ +>"expect error about someType" : "expect error about someType" +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +export { type "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; +>"" : any +> : ^^^ + +import { type "" as typeB } from "./arbitraryModuleNamespaceIdentifiers_module"; +>typeB : any +> : ^^^ + +const reimportTest: typeB = "expect error about someType"; +>reimportTest : "someType" +> : ^^^^^^^^^^ +>"expect error about someType" : "expect error about someType" +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +export type * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; +>"" : typeof valueZ +> : ^^^^^^^^^^^^^ + +import { type "" as typeC } from "./arbitraryModuleNamespaceIdentifiers_module"; +>typeC : typeof valueZ +> : ^^^^^^^^^^^^^ + +export type otherType = "otherType"; +>otherType : "otherType" +> : ^^^^^^^^^^^ + +const importStarTestA: typeC.otherType = "expect error about otherType"; +>importStarTestA : "otherType" +> : ^^^^^^^^^^^ +>typeC : any +> : ^^^ +>"expect error about otherType" : "expect error about otherType" +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + diff --git a/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=umd).errors.txt b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=umd).errors.txt new file mode 100644 index 0000000000000..cc359bceb4904 --- /dev/null +++ b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=umd).errors.txt @@ -0,0 +1,42 @@ +arbitraryModuleNamespaceIdentifiers_module.ts(20,7): error TS2322: Type '"expect error about someType"' is not assignable to type '"someType"'. +arbitraryModuleNamespaceIdentifiers_module.ts(24,7): error TS2322: Type '"expect error about someType"' is not assignable to type '"someType"'. +arbitraryModuleNamespaceIdentifiers_module.ts(29,7): error TS2322: Type '"expect error about otherType"' is not assignable to type '"otherType"'. + + +==== arbitraryModuleNamespaceIdentifiers_module.ts (3 errors) ==== + const someValue = "someValue"; + type someType = "someType"; + + export { someValue as "" }; + import { "" as valueX } from "./arbitraryModuleNamespaceIdentifiers_module"; + if (valueX !== "someValue") throw "should be someValue"; + + export { "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; + import { "" as valueY } from "./arbitraryModuleNamespaceIdentifiers_module"; + if (valueY !== "someValue") throw "should be someValue"; + + export * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; + import { "" as valueZ } from "./arbitraryModuleNamespaceIdentifiers_module"; + if (valueZ[""] !== "someValue") throw "should be someValue"; + if (valueZ[""] !== "someValue") throw "should be someValue"; + if (valueZ[""] !== valueZ) throw "should be export namespace"; + + export { type someType as "" }; + import { type "" as typeA } from "./arbitraryModuleNamespaceIdentifiers_module"; + const importTest: typeA = "expect error about someType"; + ~~~~~~~~~~ +!!! error TS2322: Type '"expect error about someType"' is not assignable to type '"someType"'. + + export { type "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; + import { type "" as typeB } from "./arbitraryModuleNamespaceIdentifiers_module"; + const reimportTest: typeB = "expect error about someType"; + ~~~~~~~~~~~~ +!!! error TS2322: Type '"expect error about someType"' is not assignable to type '"someType"'. + + export type * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; + import { type "" as typeC } from "./arbitraryModuleNamespaceIdentifiers_module"; + export type otherType = "otherType"; + const importStarTestA: typeC.otherType = "expect error about otherType"; + ~~~~~~~~~~~~~~~ +!!! error TS2322: Type '"expect error about otherType"' is not assignable to type '"otherType"'. + \ No newline at end of file diff --git a/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=umd).js b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=umd).js new file mode 100644 index 0000000000000..a21466756821c --- /dev/null +++ b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=umd).js @@ -0,0 +1,81 @@ +//// [tests/cases/conformance/es2022/arbitraryModuleNamespaceIdentifiers/arbitraryModuleNamespaceIdentifiers_module.ts] //// + +//// [arbitraryModuleNamespaceIdentifiers_module.ts] +const someValue = "someValue"; +type someType = "someType"; + +export { someValue as "" }; +import { "" as valueX } from "./arbitraryModuleNamespaceIdentifiers_module"; +if (valueX !== "someValue") throw "should be someValue"; + +export { "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; +import { "" as valueY } from "./arbitraryModuleNamespaceIdentifiers_module"; +if (valueY !== "someValue") throw "should be someValue"; + +export * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; +import { "" as valueZ } from "./arbitraryModuleNamespaceIdentifiers_module"; +if (valueZ[""] !== "someValue") throw "should be someValue"; +if (valueZ[""] !== "someValue") throw "should be someValue"; +if (valueZ[""] !== valueZ) throw "should be export namespace"; + +export { type someType as "" }; +import { type "" as typeA } from "./arbitraryModuleNamespaceIdentifiers_module"; +const importTest: typeA = "expect error about someType"; + +export { type "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; +import { type "" as typeB } from "./arbitraryModuleNamespaceIdentifiers_module"; +const reimportTest: typeB = "expect error about someType"; + +export type * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; +import { type "" as typeC } from "./arbitraryModuleNamespaceIdentifiers_module"; +export type otherType = "otherType"; +const importStarTestA: typeC.otherType = "expect error about otherType"; + + +//// [arbitraryModuleNamespaceIdentifiers_module.js] +(function (factory) { + if (typeof module === "object" && typeof module.exports === "object") { + var v = factory(require, exports); + if (v !== undefined) module.exports = v; + } + else if (typeof define === "function" && define.amd) { + define(["require", "exports", "./arbitraryModuleNamespaceIdentifiers_module", "./arbitraryModuleNamespaceIdentifiers_module", "./arbitraryModuleNamespaceIdentifiers_module", "./arbitraryModuleNamespaceIdentifiers_module", "./arbitraryModuleNamespaceIdentifiers_module"], factory); + } +})(function (require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + exports[""] = exports[""] = exports[""] = void 0; + const someValue = "someValue"; + exports[""] = someValue; + const arbitraryModuleNamespaceIdentifiers_module_1 = require("./arbitraryModuleNamespaceIdentifiers_module"); + if (arbitraryModuleNamespaceIdentifiers_module_1[""] !== "someValue") + throw "should be someValue"; + var arbitraryModuleNamespaceIdentifiers_module_2 = require("./arbitraryModuleNamespaceIdentifiers_module"); + Object.defineProperty(exports, "", { enumerable: true, get: function () { return arbitraryModuleNamespaceIdentifiers_module_2[""]; } }); + const arbitraryModuleNamespaceIdentifiers_module_3 = require("./arbitraryModuleNamespaceIdentifiers_module"); + if (arbitraryModuleNamespaceIdentifiers_module_3[""] !== "someValue") + throw "should be someValue"; + exports[""] = require("./arbitraryModuleNamespaceIdentifiers_module"); + const arbitraryModuleNamespaceIdentifiers_module_4 = require("./arbitraryModuleNamespaceIdentifiers_module"); + if (arbitraryModuleNamespaceIdentifiers_module_4[""][""] !== "someValue") + throw "should be someValue"; + if (arbitraryModuleNamespaceIdentifiers_module_4[""][""] !== "someValue") + throw "should be someValue"; + if (arbitraryModuleNamespaceIdentifiers_module_4[""][""] !== arbitraryModuleNamespaceIdentifiers_module_4[""]) + throw "should be export namespace"; + const importTest = "expect error about someType"; + const reimportTest = "expect error about someType"; + const importStarTestA = "expect error about otherType"; +}); + + +//// [arbitraryModuleNamespaceIdentifiers_module.d.ts] +declare const someValue = "someValue"; +type someType = "someType"; +export { someValue as "" }; +export { "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; +export * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; +export { type someType as "" }; +export { type "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; +export type * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; +export type otherType = "otherType"; diff --git a/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=umd).symbols b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=umd).symbols new file mode 100644 index 0000000000000..a792b7d3f5280 --- /dev/null +++ b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=umd).symbols @@ -0,0 +1,82 @@ +//// [tests/cases/conformance/es2022/arbitraryModuleNamespaceIdentifiers/arbitraryModuleNamespaceIdentifiers_module.ts] //// + +=== arbitraryModuleNamespaceIdentifiers_module.ts === +const someValue = "someValue"; +>someValue : Symbol(someValue, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 0, 5)) + +type someType = "someType"; +>someType : Symbol(someType, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 0, 30)) + +export { someValue as "" }; +>someValue : Symbol(someValue, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 0, 5)) +>"" : Symbol(valueZ[""], Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 3, 8)) + +import { "" as valueX } from "./arbitraryModuleNamespaceIdentifiers_module"; +>valueX : Symbol(valueX, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 4, 8)) + +if (valueX !== "someValue") throw "should be someValue"; +>valueX : Symbol(valueX, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 4, 8)) + +export { "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; +>"" : Symbol(valueZ[""], Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 7, 8)) + +import { "" as valueY } from "./arbitraryModuleNamespaceIdentifiers_module"; +>valueY : Symbol(valueY, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 8, 8)) + +if (valueY !== "someValue") throw "should be someValue"; +>valueY : Symbol(valueY, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 8, 8)) + +export * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; +>"" : Symbol(valueZ[""], Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 11, 6)) + +import { "" as valueZ } from "./arbitraryModuleNamespaceIdentifiers_module"; +>valueZ : Symbol(valueZ, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 12, 8)) + +if (valueZ[""] !== "someValue") throw "should be someValue"; +>valueZ : Symbol(valueZ, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 12, 8)) +>"" : Symbol(valueZ[""], Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 3, 8)) + +if (valueZ[""] !== "someValue") throw "should be someValue"; +>valueZ : Symbol(valueZ, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 12, 8)) +>"" : Symbol(valueZ[""], Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 7, 8)) + +if (valueZ[""] !== valueZ) throw "should be export namespace"; +>valueZ : Symbol(valueZ, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 12, 8)) +>"" : Symbol(valueZ[""], Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 11, 6)) +>valueZ : Symbol(valueZ, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 12, 8)) + +export { type someType as "" }; +>someType : Symbol(someType, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 0, 30)) +>"" : Symbol(valueZ[""], Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 17, 8)) + +import { type "" as typeA } from "./arbitraryModuleNamespaceIdentifiers_module"; +>typeA : Symbol(typeA, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 18, 8)) + +const importTest: typeA = "expect error about someType"; +>importTest : Symbol(importTest, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 19, 5)) +>typeA : Symbol(typeA, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 18, 8)) + +export { type "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; +>"" : Symbol(valueZ[""], Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 21, 8)) + +import { type "" as typeB } from "./arbitraryModuleNamespaceIdentifiers_module"; +>typeB : Symbol(typeB, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 22, 8)) + +const reimportTest: typeB = "expect error about someType"; +>reimportTest : Symbol(reimportTest, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 23, 5)) +>typeB : Symbol(typeB, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 22, 8)) + +export type * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; +>"" : Symbol(valueZ[""], Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 25, 11)) + +import { type "" as typeC } from "./arbitraryModuleNamespaceIdentifiers_module"; +>typeC : Symbol(typeC, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 26, 8)) + +export type otherType = "otherType"; +>otherType : Symbol(valueZ.otherType, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 26, 83)) + +const importStarTestA: typeC.otherType = "expect error about otherType"; +>importStarTestA : Symbol(importStarTestA, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 28, 5)) +>typeC : Symbol(typeC, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 26, 8)) +>otherType : Symbol(valueZ.otherType, Decl(arbitraryModuleNamespaceIdentifiers_module.ts, 26, 83)) + diff --git a/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=umd).types b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=umd).types new file mode 100644 index 0000000000000..4574f9754d0b4 --- /dev/null +++ b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_module(module=umd).types @@ -0,0 +1,151 @@ +//// [tests/cases/conformance/es2022/arbitraryModuleNamespaceIdentifiers/arbitraryModuleNamespaceIdentifiers_module.ts] //// + +=== arbitraryModuleNamespaceIdentifiers_module.ts === +const someValue = "someValue"; +>someValue : "someValue" +> : ^^^^^^^^^^^ +>"someValue" : "someValue" +> : ^^^^^^^^^^^ + +type someType = "someType"; +>someType : "someType" +> : ^^^^^^^^^^ + +export { someValue as "" }; +>someValue : "someValue" +> : ^^^^^^^^^^^ +>"" : "someValue" +> : ^^^^^^^^^^^ + +import { "" as valueX } from "./arbitraryModuleNamespaceIdentifiers_module"; +>valueX : "someValue" +> : ^^^^^^^^^^^ + +if (valueX !== "someValue") throw "should be someValue"; +>valueX !== "someValue" : boolean +> : ^^^^^^^ +>valueX : "someValue" +> : ^^^^^^^^^^^ +>"someValue" : "someValue" +> : ^^^^^^^^^^^ +>"should be someValue" : "should be someValue" +> : ^^^^^^^^^^^^^^^^^^^^^ + +export { "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; +>"" : "someValue" +> : ^^^^^^^^^^^ + +import { "" as valueY } from "./arbitraryModuleNamespaceIdentifiers_module"; +>valueY : "someValue" +> : ^^^^^^^^^^^ + +if (valueY !== "someValue") throw "should be someValue"; +>valueY !== "someValue" : boolean +> : ^^^^^^^ +>valueY : "someValue" +> : ^^^^^^^^^^^ +>"someValue" : "someValue" +> : ^^^^^^^^^^^ +>"should be someValue" : "should be someValue" +> : ^^^^^^^^^^^^^^^^^^^^^ + +export * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; +>"" : typeof valueZ +> : ^^^^^^^^^^^^^ + +import { "" as valueZ } from "./arbitraryModuleNamespaceIdentifiers_module"; +>valueZ : typeof valueZ +> : ^^^^^^^^^^^^^ + +if (valueZ[""] !== "someValue") throw "should be someValue"; +>valueZ[""] !== "someValue" : boolean +> : ^^^^^^^ +>valueZ[""] : "someValue" +> : ^^^^^^^^^^^ +>valueZ : typeof valueZ +> : ^^^^^^^^^^^^^ +>"" : "" +> : ^^^^^ +>"someValue" : "someValue" +> : ^^^^^^^^^^^ +>"should be someValue" : "should be someValue" +> : ^^^^^^^^^^^^^^^^^^^^^ + +if (valueZ[""] !== "someValue") throw "should be someValue"; +>valueZ[""] !== "someValue" : boolean +> : ^^^^^^^ +>valueZ[""] : "someValue" +> : ^^^^^^^^^^^ +>valueZ : typeof valueZ +> : ^^^^^^^^^^^^^ +>"" : "" +> : ^^^^^ +>"someValue" : "someValue" +> : ^^^^^^^^^^^ +>"should be someValue" : "should be someValue" +> : ^^^^^^^^^^^^^^^^^^^^^ + +if (valueZ[""] !== valueZ) throw "should be export namespace"; +>valueZ[""] !== valueZ : boolean +> : ^^^^^^^ +>valueZ[""] : typeof valueZ +> : ^^^^^^^^^^^^^ +>valueZ : typeof valueZ +> : ^^^^^^^^^^^^^ +>"" : "" +> : ^^^^^ +>valueZ : typeof valueZ +> : ^^^^^^^^^^^^^ +>"should be export namespace" : "should be export namespace" +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +export { type someType as "" }; +>someType : any +> : ^^^ +>"" : any +> : ^^^ + +import { type "" as typeA } from "./arbitraryModuleNamespaceIdentifiers_module"; +>typeA : any +> : ^^^ + +const importTest: typeA = "expect error about someType"; +>importTest : "someType" +> : ^^^^^^^^^^ +>"expect error about someType" : "expect error about someType" +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +export { type "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; +>"" : any +> : ^^^ + +import { type "" as typeB } from "./arbitraryModuleNamespaceIdentifiers_module"; +>typeB : any +> : ^^^ + +const reimportTest: typeB = "expect error about someType"; +>reimportTest : "someType" +> : ^^^^^^^^^^ +>"expect error about someType" : "expect error about someType" +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +export type * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; +>"" : typeof valueZ +> : ^^^^^^^^^^^^^ + +import { type "" as typeC } from "./arbitraryModuleNamespaceIdentifiers_module"; +>typeC : typeof valueZ +> : ^^^^^^^^^^^^^ + +export type otherType = "otherType"; +>otherType : "otherType" +> : ^^^^^^^^^^^ + +const importStarTestA: typeC.otherType = "expect error about otherType"; +>importStarTestA : "otherType" +> : ^^^^^^^^^^^ +>typeC : any +> : ^^^ +>"expect error about otherType" : "expect error about otherType" +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + diff --git a/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_syntax.errors.txt b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_syntax.errors.txt new file mode 100644 index 0000000000000..e5307689df328 --- /dev/null +++ b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_syntax.errors.txt @@ -0,0 +1,107 @@ +type-clause-bad-export.ts(1,15): error TS1003: Identifier expected. +type-clause-bad-import.ts(1,22): error TS1003: Identifier expected. +type-clause-no-as.ts(1,15): error TS1003: Identifier expected. +type-clause-type-as-as.ts(1,15): error TS2305: Module '"./type-clause-valid"' has no exported member 'as'. +type-clause-type-as-as.ts(1,21): error TS1003: Identifier expected. +type-decls-bad-export.ts(1,15): error TS1003: Identifier expected. +type-decls-bad-import.ts(1,22): error TS1003: Identifier expected. +type-decls-no-as.ts(1,15): error TS1003: Identifier expected. +type-decls-type-as.ts(1,15): error TS2305: Module '"./type-decls-valid"' has no exported member 'type'. +type-decls-type-as.ts(1,23): error TS1003: Identifier expected. +values-bad-export.ts(1,10): error TS1003: Identifier expected. +values-bad-import.ts(1,17): error TS1003: Identifier expected. +values-no-as.ts(1,10): error TS1003: Identifier expected. +values-type-as.ts(1,10): error TS2305: Module '"./values-valid"' has no exported member 'type'. +values-type-as.ts(1,18): error TS1003: Identifier expected. + + +==== values-valid.ts (0 errors) ==== + export const foo = 123; + export { foo as "valid 1" }; + import { "valid 1" as bar } from "./values-valid"; + export { "valid 1" as "valid 2" } from "./values-valid"; + export { foo as "valid 3" } from "./values-valid"; + export * as "valid 4" from "./values-valid"; + +==== values-bad-import.ts (1 errors) ==== + import { foo as "invalid 2" } from "./values-valid"; + ~~~~~~~~~~~ +!!! error TS1003: Identifier expected. + +==== values-bad-export.ts (1 errors) ==== + export { "invalid 3" as baz }; + ~~~~~~~~~~~ +!!! error TS1003: Identifier expected. + +==== values-no-as.ts (1 errors) ==== + import { "invalid 1" } from "./values-valid"; + ~~~~~~~~~~~ +!!! error TS1003: Identifier expected. + +==== values-type-as.ts (2 errors) ==== + import { type as "invalid 4" } from "./values-valid"; + ~~~~ +!!! error TS2305: Module '"./values-valid"' has no exported member 'type'. + ~~~~~~~~~~~ +!!! error TS1003: Identifier expected. + + +==== type-decls-valid.ts (0 errors) ==== + export type foo = 123; + export type { foo as "valid 1" }; + import type { "valid 1" as bar } from "./type-decls-valid"; + export type { "valid 1" as "valid 2" } from "./type-decls-valid"; + export type { foo as "valid 3" } from "./type-decls-valid"; + export type * as "valid 4" from "./type-decls-valid"; + +==== type-decls-bad-import.ts (1 errors) ==== + import type { foo as "invalid 2" } from "./type-decls-valid"; + ~~~~~~~~~~~ +!!! error TS1003: Identifier expected. + +==== type-decls-bad-export.ts (1 errors) ==== + export type { "invalid 3" as baz }; + ~~~~~~~~~~~ +!!! error TS1003: Identifier expected. + +==== type-decls-no-as.ts (1 errors) ==== + import type { "invalid 1" } from "./type-decls-valid"; + ~~~~~~~~~~~ +!!! error TS1003: Identifier expected. + +==== type-decls-type-as.ts (2 errors) ==== + import type { type as "invalid 4" } from "./type-decls-valid"; + ~~~~ +!!! error TS2305: Module '"./type-decls-valid"' has no exported member 'type'. + ~~~~~~~~~~~ +!!! error TS1003: Identifier expected. + +==== type-clause-valid.ts (0 errors) ==== + export type foo = 123; + export { type foo as "valid 1" }; + import { type "valid 1" as bar } from "./type-clause-valid"; + export { type "valid 1" as "valid 2" } from "./type-clause-valid"; + export { type foo as "valid 3" } from "./type-clause-valid"; + +==== type-clause-bad-import.ts (1 errors) ==== + import { type foo as "invalid 2" } from "./type-clause-valid"; + ~~~~~~~~~~~ +!!! error TS1003: Identifier expected. + +==== type-clause-bad-export.ts (1 errors) ==== + export { type "invalid 3" as baz }; + ~~~~~~~~~~~ +!!! error TS1003: Identifier expected. + +==== type-clause-no-as.ts (1 errors) ==== + import { type "invalid 1" } from "./type-clause-valid"; + ~~~~~~~~~~~ +!!! error TS1003: Identifier expected. + +==== type-clause-type-as-as.ts (2 errors) ==== + import { type as as "invalid 4" } from "./type-clause-valid"; + ~~ +!!! error TS2305: Module '"./type-clause-valid"' has no exported member 'as'. + ~~~~~~~~~~~ +!!! error TS1003: Identifier expected. + \ No newline at end of file diff --git a/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_syntax.js b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_syntax.js new file mode 100644 index 0000000000000..03103be74bf13 --- /dev/null +++ b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_syntax.js @@ -0,0 +1,140 @@ +//// [tests/cases/conformance/es2022/arbitraryModuleNamespaceIdentifiers/arbitraryModuleNamespaceIdentifiers_syntax.ts] //// + +//// [values-valid.ts] +export const foo = 123; +export { foo as "valid 1" }; +import { "valid 1" as bar } from "./values-valid"; +export { "valid 1" as "valid 2" } from "./values-valid"; +export { foo as "valid 3" } from "./values-valid"; +export * as "valid 4" from "./values-valid"; + +//// [values-bad-import.ts] +import { foo as "invalid 2" } from "./values-valid"; + +//// [values-bad-export.ts] +export { "invalid 3" as baz }; + +//// [values-no-as.ts] +import { "invalid 1" } from "./values-valid"; + +//// [values-type-as.ts] +import { type as "invalid 4" } from "./values-valid"; + + +//// [type-decls-valid.ts] +export type foo = 123; +export type { foo as "valid 1" }; +import type { "valid 1" as bar } from "./type-decls-valid"; +export type { "valid 1" as "valid 2" } from "./type-decls-valid"; +export type { foo as "valid 3" } from "./type-decls-valid"; +export type * as "valid 4" from "./type-decls-valid"; + +//// [type-decls-bad-import.ts] +import type { foo as "invalid 2" } from "./type-decls-valid"; + +//// [type-decls-bad-export.ts] +export type { "invalid 3" as baz }; + +//// [type-decls-no-as.ts] +import type { "invalid 1" } from "./type-decls-valid"; + +//// [type-decls-type-as.ts] +import type { type as "invalid 4" } from "./type-decls-valid"; + +//// [type-clause-valid.ts] +export type foo = 123; +export { type foo as "valid 1" }; +import { type "valid 1" as bar } from "./type-clause-valid"; +export { type "valid 1" as "valid 2" } from "./type-clause-valid"; +export { type foo as "valid 3" } from "./type-clause-valid"; + +//// [type-clause-bad-import.ts] +import { type foo as "invalid 2" } from "./type-clause-valid"; + +//// [type-clause-bad-export.ts] +export { type "invalid 3" as baz }; + +//// [type-clause-no-as.ts] +import { type "invalid 1" } from "./type-clause-valid"; + +//// [type-clause-type-as-as.ts] +import { type as as "invalid 4" } from "./type-clause-valid"; + + +//// [values-valid.js] +export const foo = 123; +export { foo as "valid 1" }; +export { "valid 1" as "valid 2" } from "./values-valid"; +export { foo as "valid 3" } from "./values-valid"; +export * as "valid 4" from "./values-valid"; +//// [values-bad-import.js] +export {}; +//// [values-bad-export.js] +export { "invalid 3" as baz }; +//// [values-no-as.js] +export {}; +//// [values-type-as.js] +export {}; +//// [type-decls-valid.js] +export {}; +//// [type-decls-bad-import.js] +export {}; +//// [type-decls-bad-export.js] +export {}; +//// [type-decls-no-as.js] +export {}; +//// [type-decls-type-as.js] +export {}; +//// [type-clause-valid.js] +export {}; +//// [type-clause-bad-import.js] +export {}; +//// [type-clause-bad-export.js] +export {}; +//// [type-clause-no-as.js] +export {}; +//// [type-clause-type-as-as.js] +export {}; + + +//// [values-valid.d.ts] +export declare const foo = 123; +export { foo as "valid 1" }; +export { "valid 1" as "valid 2" } from "./values-valid"; +export { foo as "valid 3" } from "./values-valid"; +export * as "valid 4" from "./values-valid"; +//// [values-bad-import.d.ts] +export {}; +//// [values-bad-export.d.ts] +export { "invalid 3" as baz }; +//// [values-no-as.d.ts] +export {}; +//// [values-type-as.d.ts] +export {}; +//// [type-decls-valid.d.ts] +export type foo = 123; +export type { foo as "valid 1" }; +export type { "valid 1" as "valid 2" } from "./type-decls-valid"; +export type { foo as "valid 3" } from "./type-decls-valid"; +export type * as "valid 4" from "./type-decls-valid"; +//// [type-decls-bad-import.d.ts] +export {}; +//// [type-decls-bad-export.d.ts] +export type { "invalid 3" as baz }; +//// [type-decls-no-as.d.ts] +export {}; +//// [type-decls-type-as.d.ts] +export {}; +//// [type-clause-valid.d.ts] +export type foo = 123; +export { type foo as "valid 1" }; +export { type "valid 1" as "valid 2" } from "./type-clause-valid"; +export { type foo as "valid 3" } from "./type-clause-valid"; +//// [type-clause-bad-import.d.ts] +export {}; +//// [type-clause-bad-export.d.ts] +export { type "invalid 3" as baz }; +//// [type-clause-no-as.d.ts] +export {}; +//// [type-clause-type-as-as.d.ts] +export {}; diff --git a/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_syntax.symbols b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_syntax.symbols new file mode 100644 index 0000000000000..e1a127e15c91a --- /dev/null +++ b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_syntax.symbols @@ -0,0 +1,114 @@ +//// [tests/cases/conformance/es2022/arbitraryModuleNamespaceIdentifiers/arbitraryModuleNamespaceIdentifiers_syntax.ts] //// + +=== values-valid.ts === +export const foo = 123; +>foo : Symbol(foo, Decl(values-valid.ts, 0, 12)) + +export { foo as "valid 1" }; +>foo : Symbol(foo, Decl(values-valid.ts, 0, 12)) +>"valid 1" : Symbol("valid 1", Decl(values-valid.ts, 1, 8)) + +import { "valid 1" as bar } from "./values-valid"; +>bar : Symbol(bar, Decl(values-valid.ts, 2, 8)) + +export { "valid 1" as "valid 2" } from "./values-valid"; +>"valid 2" : Symbol("valid 2", Decl(values-valid.ts, 3, 8)) + +export { foo as "valid 3" } from "./values-valid"; +>foo : Symbol(foo, Decl(values-valid.ts, 0, 12)) +>"valid 3" : Symbol("valid 3", Decl(values-valid.ts, 4, 8)) + +export * as "valid 4" from "./values-valid"; +>"valid 4" : Symbol("valid 4", Decl(values-valid.ts, 5, 6)) + +=== values-bad-import.ts === +import { foo as "invalid 2" } from "./values-valid"; +>foo : Symbol((Missing), Decl(values-valid.ts, 0, 12)) +> : Symbol((Missing), Decl(values-bad-import.ts, 0, 8)) + +=== values-bad-export.ts === +export { "invalid 3" as baz }; +>baz : Symbol(baz, Decl(values-bad-export.ts, 0, 8)) + +=== values-no-as.ts === +import { "invalid 1" } from "./values-valid"; +> : Symbol((Missing), Decl(values-no-as.ts, 0, 8)) + +=== values-type-as.ts === +import { type as "invalid 4" } from "./values-valid"; +> : Symbol((Missing), Decl(values-type-as.ts, 0, 8)) + + +=== type-decls-valid.ts === +export type foo = 123; +>foo : Symbol(foo, Decl(type-decls-valid.ts, 0, 0)) + +export type { foo as "valid 1" }; +>foo : Symbol(foo, Decl(type-decls-valid.ts, 0, 0)) +>"valid 1" : Symbol("valid 1", Decl(type-decls-valid.ts, 1, 13)) + +import type { "valid 1" as bar } from "./type-decls-valid"; +>bar : Symbol(bar, Decl(type-decls-valid.ts, 2, 13)) + +export type { "valid 1" as "valid 2" } from "./type-decls-valid"; +>"valid 2" : Symbol("valid 2", Decl(type-decls-valid.ts, 3, 13)) + +export type { foo as "valid 3" } from "./type-decls-valid"; +>foo : Symbol(foo, Decl(type-decls-valid.ts, 0, 0)) +>"valid 3" : Symbol("valid 3", Decl(type-decls-valid.ts, 4, 13)) + +export type * as "valid 4" from "./type-decls-valid"; +>"valid 4" : Symbol("valid 4", Decl(type-decls-valid.ts, 5, 11)) + +=== type-decls-bad-import.ts === +import type { foo as "invalid 2" } from "./type-decls-valid"; +>foo : Symbol((Missing), Decl(type-decls-valid.ts, 0, 0)) +> : Symbol((Missing), Decl(type-decls-bad-import.ts, 0, 13)) + +=== type-decls-bad-export.ts === +export type { "invalid 3" as baz }; +>baz : Symbol(baz, Decl(type-decls-bad-export.ts, 0, 13)) + +=== type-decls-no-as.ts === +import type { "invalid 1" } from "./type-decls-valid"; +> : Symbol((Missing), Decl(type-decls-no-as.ts, 0, 13)) + +=== type-decls-type-as.ts === +import type { type as "invalid 4" } from "./type-decls-valid"; +> : Symbol((Missing), Decl(type-decls-type-as.ts, 0, 13)) + +=== type-clause-valid.ts === +export type foo = 123; +>foo : Symbol(foo, Decl(type-clause-valid.ts, 0, 0)) + +export { type foo as "valid 1" }; +>foo : Symbol(foo, Decl(type-clause-valid.ts, 0, 0)) +>"valid 1" : Symbol("valid 1", Decl(type-clause-valid.ts, 1, 8)) + +import { type "valid 1" as bar } from "./type-clause-valid"; +>bar : Symbol(bar, Decl(type-clause-valid.ts, 2, 8)) + +export { type "valid 1" as "valid 2" } from "./type-clause-valid"; +>"valid 2" : Symbol("valid 2", Decl(type-clause-valid.ts, 3, 8)) + +export { type foo as "valid 3" } from "./type-clause-valid"; +>foo : Symbol(foo, Decl(type-clause-valid.ts, 0, 0)) +>"valid 3" : Symbol("valid 3", Decl(type-clause-valid.ts, 4, 8)) + +=== type-clause-bad-import.ts === +import { type foo as "invalid 2" } from "./type-clause-valid"; +>foo : Symbol((Missing), Decl(type-clause-valid.ts, 0, 0)) +> : Symbol((Missing), Decl(type-clause-bad-import.ts, 0, 8)) + +=== type-clause-bad-export.ts === +export { type "invalid 3" as baz }; +>baz : Symbol(baz, Decl(type-clause-bad-export.ts, 0, 8)) + +=== type-clause-no-as.ts === +import { type "invalid 1" } from "./type-clause-valid"; +> : Symbol((Missing), Decl(type-clause-no-as.ts, 0, 8)) + +=== type-clause-type-as-as.ts === +import { type as as "invalid 4" } from "./type-clause-valid"; +> : Symbol((Missing), Decl(type-clause-type-as-as.ts, 0, 8)) + diff --git a/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_syntax.types b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_syntax.types new file mode 100644 index 0000000000000..6129efe319ab1 --- /dev/null +++ b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_syntax.types @@ -0,0 +1,160 @@ +//// [tests/cases/conformance/es2022/arbitraryModuleNamespaceIdentifiers/arbitraryModuleNamespaceIdentifiers_syntax.ts] //// + +=== values-valid.ts === +export const foo = 123; +>foo : 123 +> : ^^^ +>123 : 123 +> : ^^^ + +export { foo as "valid 1" }; +>foo : 123 +> : ^^^ +>"valid 1" : 123 +> : ^^^ + +import { "valid 1" as bar } from "./values-valid"; +>bar : 123 +> : ^^^ + +export { "valid 1" as "valid 2" } from "./values-valid"; +>"valid 2" : 123 +> : ^^^ + +export { foo as "valid 3" } from "./values-valid"; +>foo : 123 +> : ^^^ +>"valid 3" : 123 +> : ^^^ + +export * as "valid 4" from "./values-valid"; +>"valid 4" : typeof import("values-valid") +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +=== values-bad-import.ts === +import { foo as "invalid 2" } from "./values-valid"; +>foo : 123 +> : ^^^ +> : 123 +> : ^^^ + +=== values-bad-export.ts === +export { "invalid 3" as baz }; +>baz : any +> : ^^^ + +=== values-no-as.ts === +import { "invalid 1" } from "./values-valid"; +> : any +> : ^^^ + +=== values-type-as.ts === +import { type as "invalid 4" } from "./values-valid"; +>type : any +> : ^^^ +> : any +> : ^^^ + + +=== type-decls-valid.ts === +export type foo = 123; +>foo : 123 +> : ^^^ + +export type { foo as "valid 1" }; +>foo : any +> : ^^^ +>"valid 1" : any +> : ^^^ + +import type { "valid 1" as bar } from "./type-decls-valid"; +>bar : 123 +> : ^^^ + +export type { "valid 1" as "valid 2" } from "./type-decls-valid"; +>"valid 2" : any +> : ^^^ + +export type { foo as "valid 3" } from "./type-decls-valid"; +>foo : any +> : ^^^ +>"valid 3" : any +> : ^^^ + +export type * as "valid 4" from "./type-decls-valid"; +>"valid 4" : typeof import("type-decls-valid") +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +=== type-decls-bad-import.ts === +import type { foo as "invalid 2" } from "./type-decls-valid"; +>foo : any +> : ^^^ +> : 123 +> : ^^^ + +=== type-decls-bad-export.ts === +export type { "invalid 3" as baz }; +>baz : any +> : ^^^ + +=== type-decls-no-as.ts === +import type { "invalid 1" } from "./type-decls-valid"; +> : any +> : ^^^ + +=== type-decls-type-as.ts === +import type { type as "invalid 4" } from "./type-decls-valid"; +>type : any +> : ^^^ +> : any +> : ^^^ + +=== type-clause-valid.ts === +export type foo = 123; +>foo : 123 +> : ^^^ + +export { type foo as "valid 1" }; +>foo : any +> : ^^^ +>"valid 1" : any +> : ^^^ + +import { type "valid 1" as bar } from "./type-clause-valid"; +>bar : any +> : ^^^ + +export { type "valid 1" as "valid 2" } from "./type-clause-valid"; +>"valid 2" : any +> : ^^^ + +export { type foo as "valid 3" } from "./type-clause-valid"; +>foo : any +> : ^^^ +>"valid 3" : any +> : ^^^ + +=== type-clause-bad-import.ts === +import { type foo as "invalid 2" } from "./type-clause-valid"; +>foo : any +> : ^^^ +> : any +> : ^^^ + +=== type-clause-bad-export.ts === +export { type "invalid 3" as baz }; +>baz : any +> : ^^^ + +=== type-clause-no-as.ts === +import { type "invalid 1" } from "./type-clause-valid"; +> : any +> : ^^^ + +=== type-clause-type-as-as.ts === +import { type as as "invalid 4" } from "./type-clause-valid"; +>as : any +> : ^^^ +> : any +> : ^^^ + diff --git a/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_types.baseline.jsonc b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_types.baseline.jsonc new file mode 100644 index 0000000000000..544a2769add82 --- /dev/null +++ b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_types.baseline.jsonc @@ -0,0 +1,1712 @@ +// === findRenameLocations === +// === /foo.ts === +// type foo = "foo"; +// <|export { type foo as "/*RENAME*/[|__RENAME|]" };|> +// <|import { type "[|__RENAME|]" as bar } from "./foo";|> +// const testBar: bar = "foo"; + +// === /bar.ts === +// <|import { type "[|__RENAME|]" as first } from "./foo";|> +// <|export { type "[|__RENAME|]" as "" } from "./foo";|> +// import { type "" as second } from "./bar"; +// const testFirst: first = "foo"; +// const testSecond: second = "foo"; + + + +// === findRenameLocations === +// === /foo.ts === +// type foo = "foo"; +// <|export { type foo as "[|__RENAME|]" };|> +// <|import { type "/*RENAME*/[|__RENAME|]" as bar } from "./foo";|> +// const testBar: bar = "foo"; + +// === /bar.ts === +// <|import { type "[|__RENAME|]" as first } from "./foo";|> +// <|export { type "[|__RENAME|]" as "" } from "./foo";|> +// import { type "" as second } from "./bar"; +// const testFirst: first = "foo"; +// const testSecond: second = "foo"; + + + +// === findRenameLocations === +// === /foo.ts === +// type foo = "foo"; +// <|export { type foo as "[|__RENAME|]" };|> +// <|import { type "[|__RENAME|]" as bar } from "./foo";|> +// const testBar: bar = "foo"; + +// === /bar.ts === +// <|import { type "/*RENAME*/[|__RENAME|]" as first } from "./foo";|> +// <|export { type "[|__RENAME|]" as "" } from "./foo";|> +// import { type "" as second } from "./bar"; +// const testFirst: first = "foo"; +// const testSecond: second = "foo"; + + + +// === findRenameLocations === +// === /foo.ts === +// type foo = "foo"; +// <|export { type foo as "[|__RENAME|]" };|> +// <|import { type "[|__RENAME|]" as bar } from "./foo";|> +// const testBar: bar = "foo"; + +// === /bar.ts === +// <|import { type "[|__RENAME|]" as first } from "./foo";|> +// <|export { type "/*RENAME*/[|__RENAME|]" as "" } from "./foo";|> +// import { type "" as second } from "./bar"; +// const testFirst: first = "foo"; +// const testSecond: second = "foo"; + + + +// === goToDefinition === +// === /foo.ts === +// <|type [|foo|] = "foo";|> +// export { type foo as "/*GOTO DEF*/__" }; +// import { type "__" as bar } from "./foo"; +// const testBar: bar = "foo"; + + // === Details === + [ + { + "kind": "type", + "name": "foo", + "containerName": "", + "isLocal": true, + "isAmbient": false, + "unverified": false + } + ] + + + +// === goToDefinition === +// === /foo.ts === +// <|type [|foo|] = "foo";|> +// export { type foo as "__" }; +// import { type "/*GOTO DEF*/__" as bar } from "./foo"; +// const testBar: bar = "foo"; + + // === Details === + [ + { + "kind": "type", + "name": "foo", + "containerName": "", + "isLocal": true, + "isAmbient": false, + "unverified": false + } + ] + + + +// === goToDefinition === +// === /foo.ts === +// <|type [|foo|] = "foo";|> +// export { type foo as "__" }; +// import { type "__" as bar } from "./foo"; +// const testBar: bar = "foo"; + +// === /bar.ts === +// import { type [|"/*GOTO DEF*/__"|] as first } from "./foo"; +// export { type "__" as "" } from "./foo"; +// import { type "" as second } from "./bar"; +// const testFirst: first = "foo"; +// const testSecond: second = "foo"; + + // === Details === + [ + { + "kind": "type", + "name": "foo", + "containerName": "", + "isLocal": true, + "isAmbient": false, + "unverified": false + } + ] + + + +// === goToDefinition === +// === /foo.ts === +// <|type [|foo|] = "foo";|> +// export { type foo as "__" }; +// import { type "__" as bar } from "./foo"; +// const testBar: bar = "foo"; + +// === /bar.ts === +// import { type "__" as first } from "./foo"; +// export { type [|"/*GOTO DEF*/__"|] as "" } from "./foo"; +// import { type "" as second } from "./bar"; +// const testFirst: first = "foo"; +// const testSecond: second = "foo"; + + // === Details === + [ + { + "kind": "type", + "name": "foo", + "containerName": "", + "isLocal": true, + "isAmbient": false, + "unverified": false + } + ] + + + +// === findAllReferences === +// === /foo.ts === +// type foo = "foo"; +// <|export { type foo as "/*FIND ALL REFS*/[|{| defId: 0, isWriteAccess: true, isDefinition: true |}__|]" };|> +// <|<|import { type "[|{| contextId: 1, defId: 0 |}__|]" as [|{| contextId: 2, defId: 1, isWriteAccess: true |}bar|] } from "./foo";|>|> +// const testBar: [|{| defId: 1 |}bar|] = "foo"; + +// === /bar.ts === +// <|<|import { type "[|{| contextId: 3, defId: 0 |}__|]" as [|{| contextId: 4, defId: 2, isWriteAccess: true |}first|] } from "./foo";|>|> +// <|<|export { type "[|{| contextId: 5, defId: 0 |}__|]" as "[|{| contextId: 6, defId: 3, isWriteAccess: true |}|]" } from "./foo";|>|> +// <|<|import { type "[|{| contextId: 7, defId: 3 |}|]" as [|{| contextId: 8, defId: 4, isWriteAccess: true |}second|] } from "./bar";|>|> +// const testFirst: [|{| defId: 2 |}first|] = "foo"; +// const testSecond: [|{| defId: 4 |}second|] = "foo"; + + // === Definitions === + // === /foo.ts === + // type foo = "foo"; + // <|export { type foo as "/*FIND ALL REFS*/[|{| defId: 0 |}__|]" };|> + // <|import { type "__" as [|{| defId: 1 |}bar|] } from "./foo";|> + // const testBar: bar = "foo"; + + // === /bar.ts === + // <|import { type "__" as [|{| defId: 2 |}first|] } from "./foo";|> + // <|export { type "__" as "[|{| defId: 3 |}|]" } from "./foo";|> + // <|import { type "" as [|{| defId: 4 |}second|] } from "./bar";|> + // const testFirst: first = "foo"; + // const testSecond: second = "foo"; + + // === Details === + [ + { + "defId": 0, + "containerKind": "", + "containerName": "", + "kind": "alias", + "name": "(alias) type \"__\" = \"foo\"\nexport \"__\"", + "displayParts": [ + { + "text": "(", + "kind": "punctuation" + }, + { + "text": "alias", + "kind": "text" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "type", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "\"__\"", + "kind": "aliasName" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "=", + "kind": "operator" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "\"foo\"", + "kind": "stringLiteral" + }, + { + "text": "\n", + "kind": "lineBreak" + }, + { + "text": "export", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "\"__\"", + "kind": "aliasName" + } + ] + }, + { + "defId": 1, + "containerKind": "", + "containerName": "", + "kind": "alias", + "name": "(alias) type bar = \"foo\"\nimport bar", + "displayParts": [ + { + "text": "(", + "kind": "punctuation" + }, + { + "text": "alias", + "kind": "text" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "type", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "bar", + "kind": "aliasName" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "=", + "kind": "operator" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "\"foo\"", + "kind": "stringLiteral" + }, + { + "text": "\n", + "kind": "lineBreak" + }, + { + "text": "import", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "bar", + "kind": "aliasName" + } + ] + }, + { + "defId": 2, + "containerKind": "", + "containerName": "", + "kind": "alias", + "name": "(alias) type first = \"foo\"\nimport first", + "displayParts": [ + { + "text": "(", + "kind": "punctuation" + }, + { + "text": "alias", + "kind": "text" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "type", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "first", + "kind": "aliasName" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "=", + "kind": "operator" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "\"foo\"", + "kind": "stringLiteral" + }, + { + "text": "\n", + "kind": "lineBreak" + }, + { + "text": "import", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "first", + "kind": "aliasName" + } + ] + }, + { + "defId": 3, + "containerKind": "", + "containerName": "", + "kind": "alias", + "name": "(alias) type \"\" = \"foo\"\nexport \"\"", + "displayParts": [ + { + "text": "(", + "kind": "punctuation" + }, + { + "text": "alias", + "kind": "text" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "type", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "\"\"", + "kind": "aliasName" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "=", + "kind": "operator" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "\"foo\"", + "kind": "stringLiteral" + }, + { + "text": "\n", + "kind": "lineBreak" + }, + { + "text": "export", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "\"\"", + "kind": "aliasName" + } + ] + }, + { + "defId": 4, + "containerKind": "", + "containerName": "", + "kind": "alias", + "name": "(alias) type second = \"foo\"\nimport second", + "displayParts": [ + { + "text": "(", + "kind": "punctuation" + }, + { + "text": "alias", + "kind": "text" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "type", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "second", + "kind": "aliasName" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "=", + "kind": "operator" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "\"foo\"", + "kind": "stringLiteral" + }, + { + "text": "\n", + "kind": "lineBreak" + }, + { + "text": "import", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "second", + "kind": "aliasName" + } + ] + } + ] + + + +// === findAllReferences === +// === /foo.ts === +// type foo = "foo"; +// <|export { type foo as "[|{| defId: 0, isWriteAccess: true |}__|]" };|> +// <|<|import { type "/*FIND ALL REFS*/[|{| contextId: 1, defId: 0 |}__|]" as [|{| contextId: 2, defId: 1, isWriteAccess: true |}bar|] } from "./foo";|>|> +// const testBar: [|{| defId: 1 |}bar|] = "foo"; + +// === /bar.ts === +// <|<|import { type "[|{| contextId: 3, defId: 0 |}__|]" as [|{| contextId: 4, defId: 2, isWriteAccess: true |}first|] } from "./foo";|>|> +// <|<|export { type "[|{| contextId: 5, defId: 0 |}__|]" as "[|{| contextId: 6, defId: 3, isWriteAccess: true |}|]" } from "./foo";|>|> +// <|<|import { type "[|{| contextId: 7, defId: 3 |}|]" as [|{| contextId: 8, defId: 4, isWriteAccess: true |}second|] } from "./bar";|>|> +// const testFirst: [|{| defId: 2 |}first|] = "foo"; +// const testSecond: [|{| defId: 4 |}second|] = "foo"; + + // === Definitions === + // === /foo.ts === + // type foo = "foo"; + // <|export { type foo as "[|{| defId: 0 |}__|]" };|> + // <|import { type "/*FIND ALL REFS*/__" as [|{| defId: 1 |}bar|] } from "./foo";|> + // const testBar: bar = "foo"; + + // === /bar.ts === + // <|import { type "__" as [|{| defId: 2 |}first|] } from "./foo";|> + // <|export { type "__" as "[|{| defId: 3 |}|]" } from "./foo";|> + // <|import { type "" as [|{| defId: 4 |}second|] } from "./bar";|> + // const testFirst: first = "foo"; + // const testSecond: second = "foo"; + + // === Details === + [ + { + "defId": 0, + "containerKind": "", + "containerName": "", + "kind": "alias", + "name": "(alias) type \"__\" = \"foo\"\nexport \"__\"", + "displayParts": [ + { + "text": "(", + "kind": "punctuation" + }, + { + "text": "alias", + "kind": "text" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "type", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "\"__\"", + "kind": "aliasName" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "=", + "kind": "operator" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "\"foo\"", + "kind": "stringLiteral" + }, + { + "text": "\n", + "kind": "lineBreak" + }, + { + "text": "export", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "\"__\"", + "kind": "aliasName" + } + ] + }, + { + "defId": 1, + "containerKind": "", + "containerName": "", + "kind": "alias", + "name": "(alias) type bar = \"foo\"\nimport bar", + "displayParts": [ + { + "text": "(", + "kind": "punctuation" + }, + { + "text": "alias", + "kind": "text" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "type", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "bar", + "kind": "aliasName" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "=", + "kind": "operator" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "\"foo\"", + "kind": "stringLiteral" + }, + { + "text": "\n", + "kind": "lineBreak" + }, + { + "text": "import", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "bar", + "kind": "aliasName" + } + ] + }, + { + "defId": 2, + "containerKind": "", + "containerName": "", + "kind": "alias", + "name": "(alias) type first = \"foo\"\nimport first", + "displayParts": [ + { + "text": "(", + "kind": "punctuation" + }, + { + "text": "alias", + "kind": "text" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "type", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "first", + "kind": "aliasName" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "=", + "kind": "operator" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "\"foo\"", + "kind": "stringLiteral" + }, + { + "text": "\n", + "kind": "lineBreak" + }, + { + "text": "import", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "first", + "kind": "aliasName" + } + ] + }, + { + "defId": 3, + "containerKind": "", + "containerName": "", + "kind": "alias", + "name": "(alias) type \"\" = \"foo\"\nexport \"\"", + "displayParts": [ + { + "text": "(", + "kind": "punctuation" + }, + { + "text": "alias", + "kind": "text" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "type", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "\"\"", + "kind": "aliasName" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "=", + "kind": "operator" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "\"foo\"", + "kind": "stringLiteral" + }, + { + "text": "\n", + "kind": "lineBreak" + }, + { + "text": "export", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "\"\"", + "kind": "aliasName" + } + ] + }, + { + "defId": 4, + "containerKind": "", + "containerName": "", + "kind": "alias", + "name": "(alias) type second = \"foo\"\nimport second", + "displayParts": [ + { + "text": "(", + "kind": "punctuation" + }, + { + "text": "alias", + "kind": "text" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "type", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "second", + "kind": "aliasName" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "=", + "kind": "operator" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "\"foo\"", + "kind": "stringLiteral" + }, + { + "text": "\n", + "kind": "lineBreak" + }, + { + "text": "import", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "second", + "kind": "aliasName" + } + ] + } + ] + + + +// === findAllReferences === +// === /foo.ts === +// type foo = "foo"; +// <|export { type foo as "[|{| defId: 0, isWriteAccess: true |}__|]" };|> +// <|<|import { type "[|{| contextId: 1, defId: 0 |}__|]" as [|{| contextId: 2, defId: 1, isWriteAccess: true |}bar|] } from "./foo";|>|> +// const testBar: [|{| defId: 1 |}bar|] = "foo"; + +// === /bar.ts === +// <|<|import { type "/*FIND ALL REFS*/[|{| contextId: 3, defId: 0 |}__|]" as [|{| contextId: 4, defId: 2, isWriteAccess: true |}first|] } from "./foo";|>|> +// <|<|export { type "[|{| contextId: 5, defId: 0 |}__|]" as "[|{| contextId: 6, defId: 3, isWriteAccess: true |}|]" } from "./foo";|>|> +// <|<|import { type "[|{| contextId: 7, defId: 3 |}|]" as [|{| contextId: 8, defId: 4, isWriteAccess: true |}second|] } from "./bar";|>|> +// const testFirst: [|{| defId: 2 |}first|] = "foo"; +// const testSecond: [|{| defId: 4 |}second|] = "foo"; + + // === Definitions === + // === /foo.ts === + // type foo = "foo"; + // <|export { type foo as "[|{| defId: 0 |}__|]" };|> + // <|import { type "__" as [|{| defId: 1 |}bar|] } from "./foo";|> + // const testBar: bar = "foo"; + + // === /bar.ts === + // <|import { type "/*FIND ALL REFS*/__" as [|{| defId: 2 |}first|] } from "./foo";|> + // <|export { type "__" as "[|{| defId: 3 |}|]" } from "./foo";|> + // <|import { type "" as [|{| defId: 4 |}second|] } from "./bar";|> + // const testFirst: first = "foo"; + // const testSecond: second = "foo"; + + // === Details === + [ + { + "defId": 0, + "containerKind": "", + "containerName": "", + "kind": "alias", + "name": "(alias) type \"__\" = \"foo\"\nexport \"__\"", + "displayParts": [ + { + "text": "(", + "kind": "punctuation" + }, + { + "text": "alias", + "kind": "text" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "type", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "\"__\"", + "kind": "aliasName" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "=", + "kind": "operator" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "\"foo\"", + "kind": "stringLiteral" + }, + { + "text": "\n", + "kind": "lineBreak" + }, + { + "text": "export", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "\"__\"", + "kind": "aliasName" + } + ] + }, + { + "defId": 1, + "containerKind": "", + "containerName": "", + "kind": "alias", + "name": "(alias) type bar = \"foo\"\nimport bar", + "displayParts": [ + { + "text": "(", + "kind": "punctuation" + }, + { + "text": "alias", + "kind": "text" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "type", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "bar", + "kind": "aliasName" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "=", + "kind": "operator" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "\"foo\"", + "kind": "stringLiteral" + }, + { + "text": "\n", + "kind": "lineBreak" + }, + { + "text": "import", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "bar", + "kind": "aliasName" + } + ] + }, + { + "defId": 2, + "containerKind": "", + "containerName": "", + "kind": "alias", + "name": "(alias) type first = \"foo\"\nimport first", + "displayParts": [ + { + "text": "(", + "kind": "punctuation" + }, + { + "text": "alias", + "kind": "text" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "type", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "first", + "kind": "aliasName" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "=", + "kind": "operator" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "\"foo\"", + "kind": "stringLiteral" + }, + { + "text": "\n", + "kind": "lineBreak" + }, + { + "text": "import", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "first", + "kind": "aliasName" + } + ] + }, + { + "defId": 3, + "containerKind": "", + "containerName": "", + "kind": "alias", + "name": "(alias) type \"\" = \"foo\"\nexport \"\"", + "displayParts": [ + { + "text": "(", + "kind": "punctuation" + }, + { + "text": "alias", + "kind": "text" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "type", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "\"\"", + "kind": "aliasName" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "=", + "kind": "operator" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "\"foo\"", + "kind": "stringLiteral" + }, + { + "text": "\n", + "kind": "lineBreak" + }, + { + "text": "export", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "\"\"", + "kind": "aliasName" + } + ] + }, + { + "defId": 4, + "containerKind": "", + "containerName": "", + "kind": "alias", + "name": "(alias) type second = \"foo\"\nimport second", + "displayParts": [ + { + "text": "(", + "kind": "punctuation" + }, + { + "text": "alias", + "kind": "text" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "type", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "second", + "kind": "aliasName" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "=", + "kind": "operator" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "\"foo\"", + "kind": "stringLiteral" + }, + { + "text": "\n", + "kind": "lineBreak" + }, + { + "text": "import", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "second", + "kind": "aliasName" + } + ] + } + ] + + + +// === findAllReferences === +// === /foo.ts === +// <|type [|{| defId: 0, isWriteAccess: true |}foo|] = "foo";|> +// <|<|export { type [|{| contextId: 1, defId: 0 |}foo|] as "[|{| contextId: 2, defId: 1, isWriteAccess: true |}__|]" };|>|> +// <|<|import { type "[|{| contextId: 3, defId: 1 |}__|]" as [|{| contextId: 4, defId: 2, isWriteAccess: true |}bar|] } from "./foo";|>|> +// const testBar: [|{| defId: 2 |}bar|] = "foo"; + +// === /bar.ts === +// <|<|import { type "[|{| contextId: 5, defId: 1 |}__|]" as [|{| contextId: 6, defId: 3, isWriteAccess: true |}first|] } from "./foo";|>|> +// <|<|export { type "/*FIND ALL REFS*/[|{| contextId: 7, defId: 1 |}__|]" as "[|{| contextId: 8, defId: 4, isWriteAccess: true |}|]" } from "./foo";|>|> +// <|<|import { type "[|{| contextId: 9, defId: 4 |}|]" as [|{| contextId: 10, defId: 5, isWriteAccess: true |}second|] } from "./bar";|>|> +// const testFirst: [|{| defId: 3 |}first|] = "foo"; +// const testSecond: [|{| defId: 5 |}second|] = "foo"; + + // === Definitions === + // === /foo.ts === + // <|type [|{| defId: 0 |}foo|] = "foo";|> + // <|export { type foo as "[|{| defId: 1 |}__|]" };|> + // <|import { type "__" as [|{| defId: 2 |}bar|] } from "./foo";|> + // const testBar: bar = "foo"; + + // === /bar.ts === + // <|import { type "__" as [|{| defId: 3 |}first|] } from "./foo";|> + // <|export { type "/*FIND ALL REFS*/__" as "[|{| defId: 4 |}|]" } from "./foo";|> + // <|import { type "" as [|{| defId: 5 |}second|] } from "./bar";|> + // const testFirst: first = "foo"; + // const testSecond: second = "foo"; + + // === Details === + [ + { + "defId": 0, + "containerKind": "", + "containerName": "", + "kind": "type", + "name": "type foo = \"foo\"", + "displayParts": [ + { + "text": "type", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "foo", + "kind": "aliasName" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "=", + "kind": "operator" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "\"foo\"", + "kind": "stringLiteral" + } + ] + }, + { + "defId": 1, + "containerKind": "", + "containerName": "", + "kind": "alias", + "name": "(alias) type \"__\" = \"foo\"\nexport \"__\"", + "displayParts": [ + { + "text": "(", + "kind": "punctuation" + }, + { + "text": "alias", + "kind": "text" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "type", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "\"__\"", + "kind": "aliasName" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "=", + "kind": "operator" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "\"foo\"", + "kind": "stringLiteral" + }, + { + "text": "\n", + "kind": "lineBreak" + }, + { + "text": "export", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "\"__\"", + "kind": "aliasName" + } + ] + }, + { + "defId": 2, + "containerKind": "", + "containerName": "", + "kind": "alias", + "name": "(alias) type bar = \"foo\"\nimport bar", + "displayParts": [ + { + "text": "(", + "kind": "punctuation" + }, + { + "text": "alias", + "kind": "text" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "type", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "bar", + "kind": "aliasName" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "=", + "kind": "operator" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "\"foo\"", + "kind": "stringLiteral" + }, + { + "text": "\n", + "kind": "lineBreak" + }, + { + "text": "import", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "bar", + "kind": "aliasName" + } + ] + }, + { + "defId": 3, + "containerKind": "", + "containerName": "", + "kind": "alias", + "name": "(alias) type first = \"foo\"\nimport first", + "displayParts": [ + { + "text": "(", + "kind": "punctuation" + }, + { + "text": "alias", + "kind": "text" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "type", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "first", + "kind": "aliasName" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "=", + "kind": "operator" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "\"foo\"", + "kind": "stringLiteral" + }, + { + "text": "\n", + "kind": "lineBreak" + }, + { + "text": "import", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "first", + "kind": "aliasName" + } + ] + }, + { + "defId": 4, + "containerKind": "", + "containerName": "", + "kind": "alias", + "name": "(alias) type \"\" = \"foo\"\nexport \"\"", + "displayParts": [ + { + "text": "(", + "kind": "punctuation" + }, + { + "text": "alias", + "kind": "text" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "type", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "\"\"", + "kind": "aliasName" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "=", + "kind": "operator" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "\"foo\"", + "kind": "stringLiteral" + }, + { + "text": "\n", + "kind": "lineBreak" + }, + { + "text": "export", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "\"\"", + "kind": "aliasName" + } + ] + }, + { + "defId": 5, + "containerKind": "", + "containerName": "", + "kind": "alias", + "name": "(alias) type second = \"foo\"\nimport second", + "displayParts": [ + { + "text": "(", + "kind": "punctuation" + }, + { + "text": "alias", + "kind": "text" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "type", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "second", + "kind": "aliasName" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "=", + "kind": "operator" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "\"foo\"", + "kind": "stringLiteral" + }, + { + "text": "\n", + "kind": "lineBreak" + }, + { + "text": "import", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "second", + "kind": "aliasName" + } + ] + } + ] \ No newline at end of file diff --git a/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_values.baseline.jsonc b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_values.baseline.jsonc new file mode 100644 index 0000000000000..a992bc70499ea --- /dev/null +++ b/tests/baselines/reference/arbitraryModuleNamespaceIdentifiers_values.baseline.jsonc @@ -0,0 +1,1628 @@ +// === findRenameLocations === +// === /foo.ts === +// const foo = "foo"; +// <|export { foo as "/*RENAME*/[|__RENAME|]" };|> +// <|import { "[|__RENAME|]" as bar } from "./foo";|> +// if (bar !== "foo") throw bar; + +// === /bar.ts === +// <|import { "[|__RENAME|]" as first } from "./foo";|> +// <|export { "[|__RENAME|]" as "" } from "./foo";|> +// import { "" as second } from "./bar"; +// if (first !== "foo") throw first; +// if (second !== "foo") throw second; + + + +// === findRenameLocations === +// === /foo.ts === +// const foo = "foo"; +// <|export { foo as "[|__RENAME|]" };|> +// <|import { "/*RENAME*/[|__RENAME|]" as bar } from "./foo";|> +// if (bar !== "foo") throw bar; + +// === /bar.ts === +// <|import { "[|__RENAME|]" as first } from "./foo";|> +// <|export { "[|__RENAME|]" as "" } from "./foo";|> +// import { "" as second } from "./bar"; +// if (first !== "foo") throw first; +// if (second !== "foo") throw second; + + + +// === findRenameLocations === +// === /foo.ts === +// const foo = "foo"; +// <|export { foo as "[|__RENAME|]" };|> +// <|import { "[|__RENAME|]" as bar } from "./foo";|> +// if (bar !== "foo") throw bar; + +// === /bar.ts === +// <|import { "/*RENAME*/[|__RENAME|]" as first } from "./foo";|> +// <|export { "[|__RENAME|]" as "" } from "./foo";|> +// import { "" as second } from "./bar"; +// if (first !== "foo") throw first; +// if (second !== "foo") throw second; + + + +// === findRenameLocations === +// === /foo.ts === +// const foo = "foo"; +// <|export { foo as "[|__RENAME|]" };|> +// <|import { "[|__RENAME|]" as bar } from "./foo";|> +// if (bar !== "foo") throw bar; + +// === /bar.ts === +// <|import { "[|__RENAME|]" as first } from "./foo";|> +// <|export { "/*RENAME*/[|__RENAME|]" as "" } from "./foo";|> +// import { "" as second } from "./bar"; +// if (first !== "foo") throw first; +// if (second !== "foo") throw second; + + + +// === goToDefinition === +// === /foo.ts === +// <|const [|foo|] = "foo";|> +// export { foo as "/*GOTO DEF*/__" }; +// import { "__" as bar } from "./foo"; +// if (bar !== "foo") throw bar; + + // === Details === + [ + { + "kind": "const", + "name": "foo", + "containerName": "", + "isLocal": true, + "isAmbient": false, + "unverified": false + } + ] + + + +// === goToDefinition === +// === /foo.ts === +// <|const [|foo|] = "foo";|> +// export { foo as "__" }; +// import { "/*GOTO DEF*/__" as bar } from "./foo"; +// if (bar !== "foo") throw bar; + + // === Details === + [ + { + "kind": "const", + "name": "foo", + "containerName": "", + "isLocal": true, + "isAmbient": false, + "unverified": false + } + ] + + + +// === goToDefinition === +// === /foo.ts === +// <|const [|foo|] = "foo";|> +// export { foo as "__" }; +// import { "__" as bar } from "./foo"; +// if (bar !== "foo") throw bar; + +// === /bar.ts === +// import { [|"/*GOTO DEF*/__"|] as first } from "./foo"; +// export { "__" as "" } from "./foo"; +// import { "" as second } from "./bar"; +// if (first !== "foo") throw first; +// if (second !== "foo") throw second; + + // === Details === + [ + { + "kind": "const", + "name": "foo", + "containerName": "", + "isLocal": true, + "isAmbient": false, + "unverified": false + } + ] + + + +// === goToDefinition === +// === /foo.ts === +// <|const [|foo|] = "foo";|> +// export { foo as "__" }; +// import { "__" as bar } from "./foo"; +// if (bar !== "foo") throw bar; + +// === /bar.ts === +// import { "__" as first } from "./foo"; +// export { [|"/*GOTO DEF*/__"|] as "" } from "./foo"; +// import { "" as second } from "./bar"; +// if (first !== "foo") throw first; +// if (second !== "foo") throw second; + + // === Details === + [ + { + "kind": "const", + "name": "foo", + "containerName": "", + "isLocal": true, + "isAmbient": false, + "unverified": false + } + ] + + + +// === findAllReferences === +// === /foo.ts === +// const foo = "foo"; +// <|export { foo as "/*FIND ALL REFS*/[|{| defId: 0, isWriteAccess: true, isDefinition: true |}__|]" };|> +// <|<|import { "[|{| contextId: 1, defId: 0 |}__|]" as [|{| contextId: 2, defId: 1, isWriteAccess: true |}bar|] } from "./foo";|>|> +// if ([|{| defId: 1 |}bar|] !== "foo") throw [|{| defId: 1 |}bar|]; + +// === /bar.ts === +// <|<|import { "[|{| contextId: 3, defId: 0 |}__|]" as [|{| contextId: 4, defId: 2, isWriteAccess: true |}first|] } from "./foo";|>|> +// <|<|export { "[|{| contextId: 5, defId: 0 |}__|]" as "[|{| contextId: 6, defId: 3, isWriteAccess: true |}|]" } from "./foo";|>|> +// <|<|import { "[|{| contextId: 7, defId: 3 |}|]" as [|{| contextId: 8, defId: 4, isWriteAccess: true |}second|] } from "./bar";|>|> +// if ([|{| defId: 2 |}first|] !== "foo") throw [|{| defId: 2 |}first|]; +// if ([|{| defId: 4 |}second|] !== "foo") throw [|{| defId: 4 |}second|]; + + // === Definitions === + // === /foo.ts === + // const foo = "foo"; + // <|export { foo as "/*FIND ALL REFS*/[|{| defId: 0 |}__|]" };|> + // <|import { "__" as [|{| defId: 1 |}bar|] } from "./foo";|> + // if (bar !== "foo") throw bar; + + // === /bar.ts === + // <|import { "__" as [|{| defId: 2 |}first|] } from "./foo";|> + // <|export { "__" as "[|{| defId: 3 |}|]" } from "./foo";|> + // <|import { "" as [|{| defId: 4 |}second|] } from "./bar";|> + // if (first !== "foo") throw first; + // if (second !== "foo") throw second; + + // === Details === + [ + { + "defId": 0, + "containerKind": "", + "containerName": "", + "kind": "alias", + "name": "(alias) const \"__\": \"foo\"\nexport \"__\"", + "displayParts": [ + { + "text": "(", + "kind": "punctuation" + }, + { + "text": "alias", + "kind": "text" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "const", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "\"__\"", + "kind": "aliasName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "\"foo\"", + "kind": "stringLiteral" + }, + { + "text": "\n", + "kind": "lineBreak" + }, + { + "text": "export", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "\"__\"", + "kind": "aliasName" + } + ] + }, + { + "defId": 1, + "containerKind": "", + "containerName": "", + "kind": "alias", + "name": "(alias) const bar: \"foo\"\nimport bar", + "displayParts": [ + { + "text": "(", + "kind": "punctuation" + }, + { + "text": "alias", + "kind": "text" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "const", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "bar", + "kind": "aliasName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "\"foo\"", + "kind": "stringLiteral" + }, + { + "text": "\n", + "kind": "lineBreak" + }, + { + "text": "import", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "bar", + "kind": "aliasName" + } + ] + }, + { + "defId": 2, + "containerKind": "", + "containerName": "", + "kind": "alias", + "name": "(alias) const first: \"foo\"\nimport first", + "displayParts": [ + { + "text": "(", + "kind": "punctuation" + }, + { + "text": "alias", + "kind": "text" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "const", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "first", + "kind": "aliasName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "\"foo\"", + "kind": "stringLiteral" + }, + { + "text": "\n", + "kind": "lineBreak" + }, + { + "text": "import", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "first", + "kind": "aliasName" + } + ] + }, + { + "defId": 3, + "containerKind": "", + "containerName": "", + "kind": "alias", + "name": "(alias) const \"\": \"foo\"\nexport \"\"", + "displayParts": [ + { + "text": "(", + "kind": "punctuation" + }, + { + "text": "alias", + "kind": "text" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "const", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "\"\"", + "kind": "aliasName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "\"foo\"", + "kind": "stringLiteral" + }, + { + "text": "\n", + "kind": "lineBreak" + }, + { + "text": "export", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "\"\"", + "kind": "aliasName" + } + ] + }, + { + "defId": 4, + "containerKind": "", + "containerName": "", + "kind": "alias", + "name": "(alias) const second: \"foo\"\nimport second", + "displayParts": [ + { + "text": "(", + "kind": "punctuation" + }, + { + "text": "alias", + "kind": "text" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "const", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "second", + "kind": "aliasName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "\"foo\"", + "kind": "stringLiteral" + }, + { + "text": "\n", + "kind": "lineBreak" + }, + { + "text": "import", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "second", + "kind": "aliasName" + } + ] + } + ] + + + +// === findAllReferences === +// === /foo.ts === +// const foo = "foo"; +// <|export { foo as "[|{| defId: 0, isWriteAccess: true |}__|]" };|> +// <|<|import { "/*FIND ALL REFS*/[|{| contextId: 1, defId: 0 |}__|]" as [|{| contextId: 2, defId: 1, isWriteAccess: true |}bar|] } from "./foo";|>|> +// if ([|{| defId: 1 |}bar|] !== "foo") throw [|{| defId: 1 |}bar|]; + +// === /bar.ts === +// <|<|import { "[|{| contextId: 3, defId: 0 |}__|]" as [|{| contextId: 4, defId: 2, isWriteAccess: true |}first|] } from "./foo";|>|> +// <|<|export { "[|{| contextId: 5, defId: 0 |}__|]" as "[|{| contextId: 6, defId: 3, isWriteAccess: true |}|]" } from "./foo";|>|> +// <|<|import { "[|{| contextId: 7, defId: 3 |}|]" as [|{| contextId: 8, defId: 4, isWriteAccess: true |}second|] } from "./bar";|>|> +// if ([|{| defId: 2 |}first|] !== "foo") throw [|{| defId: 2 |}first|]; +// if ([|{| defId: 4 |}second|] !== "foo") throw [|{| defId: 4 |}second|]; + + // === Definitions === + // === /foo.ts === + // const foo = "foo"; + // <|export { foo as "[|{| defId: 0 |}__|]" };|> + // <|import { "/*FIND ALL REFS*/__" as [|{| defId: 1 |}bar|] } from "./foo";|> + // if (bar !== "foo") throw bar; + + // === /bar.ts === + // <|import { "__" as [|{| defId: 2 |}first|] } from "./foo";|> + // <|export { "__" as "[|{| defId: 3 |}|]" } from "./foo";|> + // <|import { "" as [|{| defId: 4 |}second|] } from "./bar";|> + // if (first !== "foo") throw first; + // if (second !== "foo") throw second; + + // === Details === + [ + { + "defId": 0, + "containerKind": "", + "containerName": "", + "kind": "alias", + "name": "(alias) const \"__\": \"foo\"\nexport \"__\"", + "displayParts": [ + { + "text": "(", + "kind": "punctuation" + }, + { + "text": "alias", + "kind": "text" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "const", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "\"__\"", + "kind": "aliasName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "\"foo\"", + "kind": "stringLiteral" + }, + { + "text": "\n", + "kind": "lineBreak" + }, + { + "text": "export", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "\"__\"", + "kind": "aliasName" + } + ] + }, + { + "defId": 1, + "containerKind": "", + "containerName": "", + "kind": "alias", + "name": "(alias) const bar: \"foo\"\nimport bar", + "displayParts": [ + { + "text": "(", + "kind": "punctuation" + }, + { + "text": "alias", + "kind": "text" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "const", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "bar", + "kind": "aliasName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "\"foo\"", + "kind": "stringLiteral" + }, + { + "text": "\n", + "kind": "lineBreak" + }, + { + "text": "import", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "bar", + "kind": "aliasName" + } + ] + }, + { + "defId": 2, + "containerKind": "", + "containerName": "", + "kind": "alias", + "name": "(alias) const first: \"foo\"\nimport first", + "displayParts": [ + { + "text": "(", + "kind": "punctuation" + }, + { + "text": "alias", + "kind": "text" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "const", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "first", + "kind": "aliasName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "\"foo\"", + "kind": "stringLiteral" + }, + { + "text": "\n", + "kind": "lineBreak" + }, + { + "text": "import", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "first", + "kind": "aliasName" + } + ] + }, + { + "defId": 3, + "containerKind": "", + "containerName": "", + "kind": "alias", + "name": "(alias) const \"\": \"foo\"\nexport \"\"", + "displayParts": [ + { + "text": "(", + "kind": "punctuation" + }, + { + "text": "alias", + "kind": "text" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "const", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "\"\"", + "kind": "aliasName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "\"foo\"", + "kind": "stringLiteral" + }, + { + "text": "\n", + "kind": "lineBreak" + }, + { + "text": "export", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "\"\"", + "kind": "aliasName" + } + ] + }, + { + "defId": 4, + "containerKind": "", + "containerName": "", + "kind": "alias", + "name": "(alias) const second: \"foo\"\nimport second", + "displayParts": [ + { + "text": "(", + "kind": "punctuation" + }, + { + "text": "alias", + "kind": "text" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "const", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "second", + "kind": "aliasName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "\"foo\"", + "kind": "stringLiteral" + }, + { + "text": "\n", + "kind": "lineBreak" + }, + { + "text": "import", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "second", + "kind": "aliasName" + } + ] + } + ] + + + +// === findAllReferences === +// === /foo.ts === +// const foo = "foo"; +// <|export { foo as "[|{| defId: 0, isWriteAccess: true |}__|]" };|> +// <|<|import { "[|{| contextId: 1, defId: 0 |}__|]" as [|{| contextId: 2, defId: 1, isWriteAccess: true |}bar|] } from "./foo";|>|> +// if ([|{| defId: 1 |}bar|] !== "foo") throw [|{| defId: 1 |}bar|]; + +// === /bar.ts === +// <|<|import { "/*FIND ALL REFS*/[|{| contextId: 3, defId: 0 |}__|]" as [|{| contextId: 4, defId: 2, isWriteAccess: true |}first|] } from "./foo";|>|> +// <|<|export { "[|{| contextId: 5, defId: 0 |}__|]" as "[|{| contextId: 6, defId: 3, isWriteAccess: true |}|]" } from "./foo";|>|> +// <|<|import { "[|{| contextId: 7, defId: 3 |}|]" as [|{| contextId: 8, defId: 4, isWriteAccess: true |}second|] } from "./bar";|>|> +// if ([|{| defId: 2 |}first|] !== "foo") throw [|{| defId: 2 |}first|]; +// if ([|{| defId: 4 |}second|] !== "foo") throw [|{| defId: 4 |}second|]; + + // === Definitions === + // === /foo.ts === + // const foo = "foo"; + // <|export { foo as "[|{| defId: 0 |}__|]" };|> + // <|import { "__" as [|{| defId: 1 |}bar|] } from "./foo";|> + // if (bar !== "foo") throw bar; + + // === /bar.ts === + // <|import { "/*FIND ALL REFS*/__" as [|{| defId: 2 |}first|] } from "./foo";|> + // <|export { "__" as "[|{| defId: 3 |}|]" } from "./foo";|> + // <|import { "" as [|{| defId: 4 |}second|] } from "./bar";|> + // if (first !== "foo") throw first; + // if (second !== "foo") throw second; + + // === Details === + [ + { + "defId": 0, + "containerKind": "", + "containerName": "", + "kind": "alias", + "name": "(alias) const \"__\": \"foo\"\nexport \"__\"", + "displayParts": [ + { + "text": "(", + "kind": "punctuation" + }, + { + "text": "alias", + "kind": "text" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "const", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "\"__\"", + "kind": "aliasName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "\"foo\"", + "kind": "stringLiteral" + }, + { + "text": "\n", + "kind": "lineBreak" + }, + { + "text": "export", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "\"__\"", + "kind": "aliasName" + } + ] + }, + { + "defId": 1, + "containerKind": "", + "containerName": "", + "kind": "alias", + "name": "(alias) const bar: \"foo\"\nimport bar", + "displayParts": [ + { + "text": "(", + "kind": "punctuation" + }, + { + "text": "alias", + "kind": "text" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "const", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "bar", + "kind": "aliasName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "\"foo\"", + "kind": "stringLiteral" + }, + { + "text": "\n", + "kind": "lineBreak" + }, + { + "text": "import", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "bar", + "kind": "aliasName" + } + ] + }, + { + "defId": 2, + "containerKind": "", + "containerName": "", + "kind": "alias", + "name": "(alias) const first: \"foo\"\nimport first", + "displayParts": [ + { + "text": "(", + "kind": "punctuation" + }, + { + "text": "alias", + "kind": "text" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "const", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "first", + "kind": "aliasName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "\"foo\"", + "kind": "stringLiteral" + }, + { + "text": "\n", + "kind": "lineBreak" + }, + { + "text": "import", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "first", + "kind": "aliasName" + } + ] + }, + { + "defId": 3, + "containerKind": "", + "containerName": "", + "kind": "alias", + "name": "(alias) const \"\": \"foo\"\nexport \"\"", + "displayParts": [ + { + "text": "(", + "kind": "punctuation" + }, + { + "text": "alias", + "kind": "text" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "const", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "\"\"", + "kind": "aliasName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "\"foo\"", + "kind": "stringLiteral" + }, + { + "text": "\n", + "kind": "lineBreak" + }, + { + "text": "export", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "\"\"", + "kind": "aliasName" + } + ] + }, + { + "defId": 4, + "containerKind": "", + "containerName": "", + "kind": "alias", + "name": "(alias) const second: \"foo\"\nimport second", + "displayParts": [ + { + "text": "(", + "kind": "punctuation" + }, + { + "text": "alias", + "kind": "text" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "const", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "second", + "kind": "aliasName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "\"foo\"", + "kind": "stringLiteral" + }, + { + "text": "\n", + "kind": "lineBreak" + }, + { + "text": "import", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "second", + "kind": "aliasName" + } + ] + } + ] + + + +// === findAllReferences === +// === /foo.ts === +// <|const [|{| defId: 0, isWriteAccess: true |}foo|] = "foo";|> +// <|<|export { [|{| contextId: 1, defId: 0 |}foo|] as "[|{| contextId: 2, defId: 1, isWriteAccess: true |}__|]" };|>|> +// <|<|import { "[|{| contextId: 3, defId: 1 |}__|]" as [|{| contextId: 4, defId: 2, isWriteAccess: true |}bar|] } from "./foo";|>|> +// if ([|{| defId: 2 |}bar|] !== "foo") throw [|{| defId: 2 |}bar|]; + +// === /bar.ts === +// <|<|import { "[|{| contextId: 5, defId: 1 |}__|]" as [|{| contextId: 6, defId: 3, isWriteAccess: true |}first|] } from "./foo";|>|> +// <|<|export { "/*FIND ALL REFS*/[|{| contextId: 7, defId: 1 |}__|]" as "[|{| contextId: 8, defId: 4, isWriteAccess: true |}|]" } from "./foo";|>|> +// <|<|import { "[|{| contextId: 9, defId: 4 |}|]" as [|{| contextId: 10, defId: 5, isWriteAccess: true |}second|] } from "./bar";|>|> +// if ([|{| defId: 3 |}first|] !== "foo") throw [|{| defId: 3 |}first|]; +// if ([|{| defId: 5 |}second|] !== "foo") throw [|{| defId: 5 |}second|]; + + // === Definitions === + // === /foo.ts === + // <|const [|{| defId: 0 |}foo|] = "foo";|> + // <|export { foo as "[|{| defId: 1 |}__|]" };|> + // <|import { "__" as [|{| defId: 2 |}bar|] } from "./foo";|> + // if (bar !== "foo") throw bar; + + // === /bar.ts === + // <|import { "__" as [|{| defId: 3 |}first|] } from "./foo";|> + // <|export { "/*FIND ALL REFS*/__" as "[|{| defId: 4 |}|]" } from "./foo";|> + // <|import { "" as [|{| defId: 5 |}second|] } from "./bar";|> + // if (first !== "foo") throw first; + // if (second !== "foo") throw second; + + // === Details === + [ + { + "defId": 0, + "containerKind": "", + "containerName": "", + "kind": "const", + "name": "const foo: \"foo\"", + "displayParts": [ + { + "text": "const", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "foo", + "kind": "localName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "\"foo\"", + "kind": "stringLiteral" + } + ] + }, + { + "defId": 1, + "containerKind": "", + "containerName": "", + "kind": "alias", + "name": "(alias) const \"__\": \"foo\"\nexport \"__\"", + "displayParts": [ + { + "text": "(", + "kind": "punctuation" + }, + { + "text": "alias", + "kind": "text" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "const", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "\"__\"", + "kind": "aliasName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "\"foo\"", + "kind": "stringLiteral" + }, + { + "text": "\n", + "kind": "lineBreak" + }, + { + "text": "export", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "\"__\"", + "kind": "aliasName" + } + ] + }, + { + "defId": 2, + "containerKind": "", + "containerName": "", + "kind": "alias", + "name": "(alias) const bar: \"foo\"\nimport bar", + "displayParts": [ + { + "text": "(", + "kind": "punctuation" + }, + { + "text": "alias", + "kind": "text" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "const", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "bar", + "kind": "aliasName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "\"foo\"", + "kind": "stringLiteral" + }, + { + "text": "\n", + "kind": "lineBreak" + }, + { + "text": "import", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "bar", + "kind": "aliasName" + } + ] + }, + { + "defId": 3, + "containerKind": "", + "containerName": "", + "kind": "alias", + "name": "(alias) const first: \"foo\"\nimport first", + "displayParts": [ + { + "text": "(", + "kind": "punctuation" + }, + { + "text": "alias", + "kind": "text" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "const", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "first", + "kind": "aliasName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "\"foo\"", + "kind": "stringLiteral" + }, + { + "text": "\n", + "kind": "lineBreak" + }, + { + "text": "import", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "first", + "kind": "aliasName" + } + ] + }, + { + "defId": 4, + "containerKind": "", + "containerName": "", + "kind": "alias", + "name": "(alias) const \"\": \"foo\"\nexport \"\"", + "displayParts": [ + { + "text": "(", + "kind": "punctuation" + }, + { + "text": "alias", + "kind": "text" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "const", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "\"\"", + "kind": "aliasName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "\"foo\"", + "kind": "stringLiteral" + }, + { + "text": "\n", + "kind": "lineBreak" + }, + { + "text": "export", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "\"\"", + "kind": "aliasName" + } + ] + }, + { + "defId": 5, + "containerKind": "", + "containerName": "", + "kind": "alias", + "name": "(alias) const second: \"foo\"\nimport second", + "displayParts": [ + { + "text": "(", + "kind": "punctuation" + }, + { + "text": "alias", + "kind": "text" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "const", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "second", + "kind": "aliasName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "\"foo\"", + "kind": "stringLiteral" + }, + { + "text": "\n", + "kind": "lineBreak" + }, + { + "text": "import", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "second", + "kind": "aliasName" + } + ] + } + ] \ No newline at end of file diff --git a/tests/cases/conformance/es2022/arbitraryModuleNamespaceIdentifiers/arbitraryModuleNamespaceIdentifiers_exportEmpty.ts b/tests/cases/conformance/es2022/arbitraryModuleNamespaceIdentifiers/arbitraryModuleNamespaceIdentifiers_exportEmpty.ts new file mode 100644 index 0000000000000..2f1d66936aaf1 --- /dev/null +++ b/tests/cases/conformance/es2022/arbitraryModuleNamespaceIdentifiers/arbitraryModuleNamespaceIdentifiers_exportEmpty.ts @@ -0,0 +1,10 @@ +//@module: ES2022 +//@target: ES2022 +//@declaration: true + +// This should result in a type error. In particular, the empty string is a now +// a valid module export name, and should be treated as such here. +const empty = "empty"; +export { empty as "" }; +import { "" as foo } from "./arbitraryModuleNamespaceIdentifiers_exportEmpty"; +const bar: "type error expected here" = foo; diff --git a/tests/cases/conformance/es2022/arbitraryModuleNamespaceIdentifiers/arbitraryModuleNamespaceIdentifiers_importEmpty.ts b/tests/cases/conformance/es2022/arbitraryModuleNamespaceIdentifiers/arbitraryModuleNamespaceIdentifiers_importEmpty.ts new file mode 100644 index 0000000000000..42023ae4411f8 --- /dev/null +++ b/tests/cases/conformance/es2022/arbitraryModuleNamespaceIdentifiers/arbitraryModuleNamespaceIdentifiers_importEmpty.ts @@ -0,0 +1,12 @@ +//@module: ES2022 +//@target: ES2022 +//@declaration: true + +// These should all be errors. In particular, the empty string is a now a valid +// module export name, and should be treated as such here. +import { + "missing" as x, + "(missing)" as y, + "" as z, +} from "./arbitraryModuleNamespaceIdentifiers_importEmpty"; +const xyz = [x, y, z]; diff --git a/tests/cases/conformance/es2022/arbitraryModuleNamespaceIdentifiers/arbitraryModuleNamespaceIdentifiers_module.ts b/tests/cases/conformance/es2022/arbitraryModuleNamespaceIdentifiers/arbitraryModuleNamespaceIdentifiers_module.ts new file mode 100644 index 0000000000000..e69f71ef71794 --- /dev/null +++ b/tests/cases/conformance/es2022/arbitraryModuleNamespaceIdentifiers/arbitraryModuleNamespaceIdentifiers_module.ts @@ -0,0 +1,33 @@ +//@module: * +//@target: ES2022 +//@declaration: true + +const someValue = "someValue"; +type someType = "someType"; + +export { someValue as "" }; +import { "" as valueX } from "./arbitraryModuleNamespaceIdentifiers_module"; +if (valueX !== "someValue") throw "should be someValue"; + +export { "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; +import { "" as valueY } from "./arbitraryModuleNamespaceIdentifiers_module"; +if (valueY !== "someValue") throw "should be someValue"; + +export * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; +import { "" as valueZ } from "./arbitraryModuleNamespaceIdentifiers_module"; +if (valueZ[""] !== "someValue") throw "should be someValue"; +if (valueZ[""] !== "someValue") throw "should be someValue"; +if (valueZ[""] !== valueZ) throw "should be export namespace"; + +export { type someType as "" }; +import { type "" as typeA } from "./arbitraryModuleNamespaceIdentifiers_module"; +const importTest: typeA = "expect error about someType"; + +export { type "" as "" } from "./arbitraryModuleNamespaceIdentifiers_module"; +import { type "" as typeB } from "./arbitraryModuleNamespaceIdentifiers_module"; +const reimportTest: typeB = "expect error about someType"; + +export type * as "" from "./arbitraryModuleNamespaceIdentifiers_module"; +import { type "" as typeC } from "./arbitraryModuleNamespaceIdentifiers_module"; +export type otherType = "otherType"; +const importStarTestA: typeC.otherType = "expect error about otherType"; diff --git a/tests/cases/conformance/es2022/arbitraryModuleNamespaceIdentifiers/arbitraryModuleNamespaceIdentifiers_syntax.ts b/tests/cases/conformance/es2022/arbitraryModuleNamespaceIdentifiers/arbitraryModuleNamespaceIdentifiers_syntax.ts new file mode 100644 index 0000000000000..d4bb2ffd3a328 --- /dev/null +++ b/tests/cases/conformance/es2022/arbitraryModuleNamespaceIdentifiers/arbitraryModuleNamespaceIdentifiers_syntax.ts @@ -0,0 +1,64 @@ +//@module: ES2022 +//@target: ES2022 +//@declaration: true + + +// @filename: values-valid.ts +export const foo = 123; +export { foo as "valid 1" }; +import { "valid 1" as bar } from "./values-valid"; +export { "valid 1" as "valid 2" } from "./values-valid"; +export { foo as "valid 3" } from "./values-valid"; +export * as "valid 4" from "./values-valid"; + +// @filename: values-bad-import.ts +import { foo as "invalid 2" } from "./values-valid"; + +// @filename: values-bad-export.ts +export { "invalid 3" as baz }; + +// @filename: values-no-as.ts +import { "invalid 1" } from "./values-valid"; + +// @filename: values-type-as.ts +import { type as "invalid 4" } from "./values-valid"; + + +// @filename: type-decls-valid.ts +export type foo = 123; +export type { foo as "valid 1" }; +import type { "valid 1" as bar } from "./type-decls-valid"; +export type { "valid 1" as "valid 2" } from "./type-decls-valid"; +export type { foo as "valid 3" } from "./type-decls-valid"; +export type * as "valid 4" from "./type-decls-valid"; + +// @filename: type-decls-bad-import.ts +import type { foo as "invalid 2" } from "./type-decls-valid"; + +// @filename: type-decls-bad-export.ts +export type { "invalid 3" as baz }; + +// @filename: type-decls-no-as.ts +import type { "invalid 1" } from "./type-decls-valid"; + +// @filename: type-decls-type-as.ts +import type { type as "invalid 4" } from "./type-decls-valid"; + +// @filename: type-clause-valid.ts +export type foo = 123; +export { type foo as "valid 1" }; +import { type "valid 1" as bar } from "./type-clause-valid"; +export { type "valid 1" as "valid 2" } from "./type-clause-valid"; +export { type foo as "valid 3" } from "./type-clause-valid"; + +// @filename: type-clause-bad-import.ts +import { type foo as "invalid 2" } from "./type-clause-valid"; + +// @filename: type-clause-bad-export.ts +export { type "invalid 3" as baz }; + +// @filename: type-clause-no-as.ts +import { type "invalid 1" } from "./type-clause-valid"; + +// @filename: type-clause-type-as-as.ts +import { type as as "invalid 4" } from "./type-clause-valid"; diff --git a/tests/cases/fourslash/arbitraryModuleNamespaceIdentifiers_types.ts b/tests/cases/fourslash/arbitraryModuleNamespaceIdentifiers_types.ts new file mode 100644 index 0000000000000..be380d0d590da --- /dev/null +++ b/tests/cases/fourslash/arbitraryModuleNamespaceIdentifiers_types.ts @@ -0,0 +1,19 @@ +/// + +// @Filename: /foo.ts +////type foo = "foo"; +////export { type foo as "[|__|]" }; +////import { type "[|__|]" as bar } from "./foo"; +////const testBar: bar = "foo"; + +// @Filename: /bar.ts +////import { type "[|__|]" as first } from "./foo"; +////export { type "[|__|]" as "" } from "./foo"; +////import { type "" as second } from "./bar"; +////const testFirst: first = "foo"; +////const testSecond: second = "foo"; + +verify.noErrors(); +verify.baselineRename(test.ranges()); +verify.baselineGoToDefinition(...test.ranges()); +verify.baselineFindAllReferences(...test.ranges()); diff --git a/tests/cases/fourslash/arbitraryModuleNamespaceIdentifiers_values.ts b/tests/cases/fourslash/arbitraryModuleNamespaceIdentifiers_values.ts new file mode 100644 index 0000000000000..bab23a9430be1 --- /dev/null +++ b/tests/cases/fourslash/arbitraryModuleNamespaceIdentifiers_values.ts @@ -0,0 +1,19 @@ +/// + +// @Filename: /foo.ts +////const foo = "foo"; +////export { foo as "[|__|]" }; +////import { "[|__|]" as bar } from "./foo"; +////if (bar !== "foo") throw bar; + +// @Filename: /bar.ts +////import { "[|__|]" as first } from "./foo"; +////export { "[|__|]" as "" } from "./foo"; +////import { "" as second } from "./bar"; +////if (first !== "foo") throw first; +////if (second !== "foo") throw second; + +verify.noErrors(); +verify.baselineRename(test.ranges()); +verify.baselineGoToDefinition(...test.ranges()); +verify.baselineFindAllReferences(...test.ranges()); diff --git a/tests/cases/fourslash/completionsImportOrExportSpecifier.ts b/tests/cases/fourslash/completionsImportOrExportSpecifier.ts new file mode 100644 index 0000000000000..533c6f315d031 --- /dev/null +++ b/tests/cases/fourslash/completionsImportOrExportSpecifier.ts @@ -0,0 +1,58 @@ +/// + +// @Filename: exports.ts +//// export let foo = 1; +//// let someValue = 2; +//// let someType = 3; +//// export { +//// someValue as "__some value", +//// someType as "__some type", +//// }; + +// @Filename: values.ts +//// import { /*valueImport0*/ } from "./exports"; +//// import { /*valueImport1*/ as valueImport1 } from "./exports"; +//// import { foo as /*valueImport2*/ } from "./exports"; +//// import { foo, /*valueImport3*/ as valueImport3 } from "./exports"; +//// +//// export { /*valueExport0*/ } from "./exports"; +//// export { /*valueExport1*/ as valueExport1 } from "./exports"; +//// export { foo as /*valueExport2*/ } from "./exports"; +//// export { foo, /*valueExport3*/ } from "./exports"; + +// @Filename: types.ts +//// import { type /*typeImport0*/ } from "./exports"; +//// import { type /*typeImport1*/ as typeImport1 } from "./exports"; +//// import { type foo as /*typeImport2*/ } from "./exports"; +//// import { type foo, type /*typeImport3*/ as typeImport3 } from "./exports"; +//// +//// export { type /*typeExport0*/ } from "./exports"; +//// export { type /*typeExport1*/ as typeExport1 } from "./exports"; +//// export { type foo as /*typeExport2*/ } from "./exports"; +//// export { type foo, type /*typeExport3*/ } from "./exports"; + +const __some_type = { name: "__some type", insertText: '"__some type"' } +const __some_value = { name: "__some value", insertText: '"__some value"' } +const __some_type_as = { name: "__some type", insertText: '"__some type" as __some_type' } +const __some_value_as = { name: "__some value", insertText: '"__some value" as __some_value' } +const typeKeyword = { name: "type", sortText: completion.SortText.GlobalsOrKeywords } + +verify.completions({ marker: "valueImport0", exact: [__some_type_as, __some_value_as, "foo", typeKeyword] }); +verify.completions({ marker: "valueImport1", exact: [__some_type_as, __some_value_as, "foo", typeKeyword] }); +verify.completions({ marker: "valueImport2", exact: [] }); +verify.completions({ marker: "valueImport3", exact: [__some_type_as, __some_value_as, typeKeyword] }); + +verify.completions({ marker: "valueExport0", exact: [__some_type, __some_value, "foo", typeKeyword] }); +verify.completions({ marker: "valueExport1", exact: [__some_type, __some_value, "foo", typeKeyword] }); +verify.completions({ marker: "valueExport2", exact: [] }); +verify.completions({ marker: "valueExport3", exact: [__some_type, __some_value, typeKeyword] }); + +verify.completions({ marker: "typeImport0", exact: [__some_type_as, __some_value_as, "foo"] }); +verify.completions({ marker: "typeImport1", exact: [__some_type_as, __some_value_as, "foo"] }); +verify.completions({ marker: "typeImport2", exact: [] }); +verify.completions({ marker: "typeImport3", exact: [__some_type_as, __some_value_as] }); + +verify.completions({ marker: "typeExport0", exact: [] }); +verify.completions({ marker: "typeExport1", exact: [__some_type, __some_value, "foo"] }); +verify.completions({ marker: "typeExport2", exact: [] }); +verify.completions({ marker: "typeExport3", exact: [] }); diff --git a/tests/cases/fourslash/refactorConvertImport_namedToNamespaceStringLiteral.ts b/tests/cases/fourslash/refactorConvertImport_namedToNamespaceStringLiteral.ts new file mode 100644 index 0000000000000..3cca0fe315be2 --- /dev/null +++ b/tests/cases/fourslash/refactorConvertImport_namedToNamespaceStringLiteral.ts @@ -0,0 +1,17 @@ +/// + +/////*a*/import { "__" as Value, "__" as Type } from "foo";/*b*/ +////export { Value, Type }; // Need a named import for this +////const foo: Type = Value; + +goTo.select("a", "b"); +edit.applyRefactor({ + refactorName: "Convert import", + actionName: "Convert named imports to namespace import", + actionDescription: "Convert named imports to namespace import", + newContent: +`import * as foo_1 from "foo"; +import { "__" as Value, "__" as Type } from "foo"; +export { Value, Type }; // Need a named import for this +const foo: foo_1["__"] = foo_1["__"];`, +}); diff --git a/tests/cases/fourslash/stringCompletionsImportOrExportSpecifier.ts b/tests/cases/fourslash/stringCompletionsImportOrExportSpecifier.ts new file mode 100644 index 0000000000000..ead04bb57a5a6 --- /dev/null +++ b/tests/cases/fourslash/stringCompletionsImportOrExportSpecifier.ts @@ -0,0 +1,52 @@ +/// + +// @Filename: exports.ts +//// export let foo = 1; +//// let someValue = 2; +//// let someType = 3; +//// export { +//// someValue as "__some value", +//// someType as "__some type", +//// }; + +// @Filename: values.ts +//// import { "/*valueImport0*/" } from "./exports"; +//// import { "/*valueImport1*/" as valueImport1 } from "./exports"; +//// import { foo as "/*valueImport2*/" } from "./exports"; +//// import { foo, "/*valueImport3*/" as valueImport3 } from "./exports"; +//// +//// export { "/*valueExport0*/" } from "./exports"; +//// export { "/*valueExport1*/" as valueExport1 } from "./exports"; +//// export { foo as "/*valueExport2*/" } from "./exports"; +//// export { foo, "/*valueExport3*/" } from "./exports"; + +// @Filename: types.ts +//// import { type "/*typeImport0*/" } from "./exports"; +//// import { type "/*typeImport1*/" as typeImport1 } from "./exports"; +//// import { type foo as "/*typeImport2*/" } from "./exports"; +//// import { type foo, type "/*typeImport3*/" as typeImport3 } from "./exports"; +//// +//// export { type "/*typeExport0*/" } from "./exports"; +//// export { type "/*typeExport1*/" as typeExport1 } from "./exports"; +//// export { type foo as "/*typeExport2*/" } from "./exports"; +//// export { type foo, type "/*typeExport3*/" } from "./exports"; + +verify.completions({ marker: "valueImport0", exact: ["__some type", "__some value", "foo"] }); +verify.completions({ marker: "valueImport1", exact: ["__some type", "__some value", "foo"] }); +verify.completions({ marker: "valueImport2", exact: [] }); +verify.completions({ marker: "valueImport3", exact: ["__some type", "__some value"] }); + +verify.completions({ marker: "valueExport0", exact: ["__some type", "__some value", "foo"] }); +verify.completions({ marker: "valueExport1", exact: ["__some type", "__some value", "foo"] }); +verify.completions({ marker: "valueExport2", exact: [] }); +verify.completions({ marker: "valueExport3", exact: ["__some type", "__some value"] }); + +verify.completions({ marker: "typeImport0", exact: ["__some type", "__some value", "foo"] }); +verify.completions({ marker: "typeImport1", exact: ["__some type", "__some value", "foo"] }); +verify.completions({ marker: "typeImport2", exact: [] }); +verify.completions({ marker: "typeImport3", exact: ["__some type", "__some value"] }); + +verify.completions({ marker: "typeExport0", exact: ["__some type", "__some value", "foo"] }); +verify.completions({ marker: "typeExport1", exact: ["__some type", "__some value", "foo"] }); +verify.completions({ marker: "typeExport2", exact: [] }); +verify.completions({ marker: "typeExport3", exact: ["__some type", "__some value"] });