From b3cb74f493bf0533e2705732ab32197b01443a3d Mon Sep 17 00:00:00 2001 From: kingwl Date: Tue, 5 Nov 2019 00:16:45 +0800 Subject: [PATCH 01/29] init export start as decl --- src/compiler/binder.ts | 6 ++++-- src/compiler/checker.ts | 2 ++ src/compiler/emitter.ts | 13 +++++++++++++ src/compiler/factory.ts | 16 ++++++++++++++-- src/compiler/parser.ts | 9 +++++++++ src/compiler/transformers/utilities.ts | 3 ++- src/compiler/types.ts | 10 +++++++++- src/compiler/utilities.ts | 7 +++++++ src/compiler/visitor.ts | 7 ++++++- 9 files changed, 66 insertions(+), 7 deletions(-) diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 50551759c2c6f..02caf699a2e00 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -55,9 +55,10 @@ namespace ts { break; // 4. Export alias declarations pointing at only uninstantiated modules or things uninstantiated modules contain case SyntaxKind.ExportDeclaration: - if (!(node as ExportDeclaration).moduleSpecifier && !!(node as ExportDeclaration).exportClause) { + const exportDeclaration = (node as ExportDeclaration); + if (!exportDeclaration.moduleSpecifier && exportDeclaration.exportClause && exportDeclaration.exportClause.kind === SyntaxKind.NamedExports) { let state = ModuleInstanceState.NonInstantiated; - for (const specifier of (node as ExportDeclaration).exportClause!.elements) { + for (const specifier of exportDeclaration.exportClause.elements) { const specifierState = getModuleInstanceStateForAliasTarget(specifier, visited); if (specifierState > state) { state = specifierState; @@ -2504,6 +2505,7 @@ namespace ts { // Imports and exports case SyntaxKind.ImportEqualsDeclaration: case SyntaxKind.NamespaceImport: + case SyntaxKind.NamespaceExport: case SyntaxKind.ImportSpecifier: case SyntaxKind.ExportSpecifier: return declareSymbolAndAddToSymbolTable(node, SymbolFlags.Alias, SymbolFlags.AliasExcludes); diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index ace3d5ee8cfe2..9cd264d208250 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -6585,6 +6585,7 @@ namespace ts { case SyntaxKind.ImportSpecifier: case SyntaxKind.NamedImports: case SyntaxKind.NamespaceImport: + case SyntaxKind.NamespaceExport: case SyntaxKind.ImportClause: return false; default: @@ -32561,6 +32562,7 @@ namespace ts { if (node.exportClause) { // export { x, y } // export { x, y } from "foo" + // export * as ns from "foo" forEach(node.exportClause.elements, checkExportSpecifier); const inAmbientExternalModule = node.parent.kind === SyntaxKind.ModuleBlock && isAmbientModule(node.parent.parent); diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index cbff1fb2512f7..223dcbd935460 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -1433,6 +1433,8 @@ namespace ts { return emitImportClause(node); case SyntaxKind.NamespaceImport: return emitNamespaceImport(node); + case SyntaxKind.NamespaceExport: + return emitNamespaceExport(node); case SyntaxKind.NamedImports: return emitNamedImports(node); case SyntaxKind.ImportSpecifier: @@ -3101,6 +3103,14 @@ namespace ts { writeTrailingSemicolon(); } + function emitNamespaceExport(node: NamespaceExport) { + const asPos = emitTokenWithComment(SyntaxKind.AsteriskToken, node.pos, writePunctuation, node); + writeSpace(); + emitTokenWithComment(SyntaxKind.AsKeyword, asPos, writeKeyword, node); + writeSpace(); + emit(node.name); + } + function emitNamedExports(node: NamedExports) { emitNamedImportsOrExports(node); } @@ -4405,6 +4415,9 @@ namespace ts { case SyntaxKind.NamespaceImport: generateNameIfNeeded((node).name); break; + case SyntaxKind.NamespaceExport: + generateNameIfNeeded((node).name); + break; case SyntaxKind.NamedImports: forEach((node).elements, generateNames); break; diff --git a/src/compiler/factory.ts b/src/compiler/factory.ts index d54244c083260..c79dafc6cfc33 100644 --- a/src/compiler/factory.ts +++ b/src/compiler/factory.ts @@ -2191,6 +2191,18 @@ namespace ts { : node; } + export function createNamespaceExport(name: string | Identifier) { + const node = createSynthesizedNode(SyntaxKind.NamespaceExport); + node.name = asName(name); + return node; + } + + export function updateNamespaceExport(node: NamespaceExport, name: Identifier) { + return node.name !== name + ? updateNode(createNamespaceExport(name), node) + : node; + } + export function createImportEqualsDeclaration(decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, name: string | Identifier, moduleReference: ModuleReference) { const node = createSynthesizedNode(SyntaxKind.ImportEqualsDeclaration); node.decorators = asNodeArray(decorators); @@ -2305,7 +2317,7 @@ namespace ts { : node; } - export function createExportDeclaration(decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, exportClause: NamedExports | undefined, moduleSpecifier?: Expression) { + export function createExportDeclaration(decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, exportClause: NamedExportBindings | undefined, moduleSpecifier?: Expression) { const node = createSynthesizedNode(SyntaxKind.ExportDeclaration); node.decorators = asNodeArray(decorators); node.modifiers = asNodeArray(modifiers); @@ -2318,7 +2330,7 @@ namespace ts { node: ExportDeclaration, decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, - exportClause: NamedExports | undefined, + exportClause: NamedExportBindings | undefined, moduleSpecifier: Expression | undefined) { return node.decorators !== decorators || node.modifiers !== modifiers diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 146b74c3cb898..7b99453b46d6f 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -6465,9 +6465,18 @@ namespace ts { return finishNode(node); } + function parseNamespaceExport(): NamespaceExport { + const node = createNode(SyntaxKind.NamespaceExport); + node.name = parseIdentifier(); + return finishNode(node); + } + function parseExportDeclaration(node: ExportDeclaration): ExportDeclaration { node.kind = SyntaxKind.ExportDeclaration; if (parseOptional(SyntaxKind.AsteriskToken)) { + if (parseOptional(SyntaxKind.AsKeyword)) { + node.exportClause = parseNamespaceExport(); + } parseExpected(SyntaxKind.FromKeyword); node.moduleSpecifier = parseModuleSpecifier(); } diff --git a/src/compiler/transformers/utilities.ts b/src/compiler/transformers/utilities.ts index e2029ff7b602e..63ca99919de2a 100644 --- a/src/compiler/transformers/utilities.ts +++ b/src/compiler/transformers/utilities.ts @@ -105,13 +105,14 @@ namespace ts { hasExportStarsToExportValues = true; } else { + // export * as ns from "mod" // export { x, y } from "mod" externalImports.push(node); } } else { // export { x, y } - for (const specifier of (node).exportClause!.elements) { + for (const specifier of cast((node).exportClause, isNamedExports).elements) { if (!uniqueExports.get(idText(specifier.name))) { const name = specifier.propertyName || specifier.name; exportSpecifiers.add(idText(name), specifier); diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 08cc7343ccaea..4d33b623d7bcc 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -403,6 +403,7 @@ namespace ts { ExportAssignment, ExportDeclaration, NamedExports, + NamespaceExport, ExportSpecifier, MissingDeclaration, @@ -2430,6 +2431,7 @@ namespace ts { } export type NamedImportBindings = NamespaceImport | NamedImports; + export type NamedExportBindings = NamespaceExport | NamedExports; // In case of: // import d from "mod" => name = d, namedBinding = undefined @@ -2450,6 +2452,12 @@ namespace ts { name: Identifier; } + export interface NamespaceExport extends NamedDeclaration { + kind: SyntaxKind.NamespaceExport; + parent: ExportDeclaration; + name: Identifier + } + export interface NamespaceExportDeclaration extends DeclarationStatement { kind: SyntaxKind.NamespaceExportDeclaration; name: Identifier; @@ -2459,7 +2467,7 @@ namespace ts { kind: SyntaxKind.ExportDeclaration; parent: SourceFile | ModuleBlock; /** Will not be assigned in the case of `export * from "foo";` */ - exportClause?: NamedExports; + exportClause?: NamedExportBindings; /** If this is not a StringLiteral it will be a grammar error. */ moduleSpecifier?: Expression; } diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 7ee5dcd8278e0..f1d9799f2d501 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -7093,6 +7093,13 @@ namespace ts { || kind === SyntaxKind.NamespaceImport; } + /* @internal */ + export function isNamedExportBindings(node: Node): node is NamedExportBindings { + const kind = node.kind; + return kind === SyntaxKind.NamedExports + || kind === SyntaxKind.NamespaceExport; + } + /* @internal */ export function isModuleOrEnumDeclaration(node: Node): node is ModuleDeclaration | EnumDeclaration { return node.kind === SyntaxKind.ModuleDeclaration || node.kind === SyntaxKind.EnumDeclaration; diff --git a/src/compiler/visitor.ts b/src/compiler/visitor.ts index 4f36ccb1b900f..bef2f66a61c8d 100644 --- a/src/compiler/visitor.ts +++ b/src/compiler/visitor.ts @@ -816,9 +816,14 @@ namespace ts { return updateExportDeclaration(node, nodesVisitor((node).decorators, visitor, isDecorator), nodesVisitor((node).modifiers, visitor, isModifier), - visitNode((node).exportClause, visitor, isNamedExports), + visitNode((node).exportClause, visitor, isNamedExportBindings), visitNode((node).moduleSpecifier, visitor, isExpression)); + case SyntaxKind.NamespaceExport: + return updateNamespaceExport(node, + visitNode((node).name, visitor, isIdentifier) + ) + case SyntaxKind.NamedExports: return updateNamedExports(node, nodesVisitor((node).elements, visitor, isExportSpecifier)); From a106216d19b0f04a504c615cac540e0178f2bdde Mon Sep 17 00:00:00 2001 From: kingwl Date: Tue, 5 Nov 2019 01:31:59 +0800 Subject: [PATCH 02/29] fix some broken --- src/compiler/checker.ts | 24 ++++++---- src/compiler/transformers/module/module.ts | 56 +++++++++++++++++++++- src/compiler/transformers/module/system.ts | 4 +- src/compiler/transformers/utilities.ts | 7 +++ src/compiler/utilities.ts | 8 +++- src/services/importTracker.ts | 4 +- src/services/organizeImports.ts | 8 +++- src/services/services.ts | 10 +++- 8 files changed, 100 insertions(+), 21 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 9cd264d208250..476f61959bfd8 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5067,18 +5067,18 @@ namespace ts { function mergeExportDeclarations(statements: Statement[]) { // Pass 2: Combine all `export {}` declarations - const exports = filter(statements, d => isExportDeclaration(d) && !d.moduleSpecifier && !!d.exportClause) as ExportDeclaration[]; + const exports = filter(statements, d => isExportDeclaration(d) && !d.moduleSpecifier && !!d.exportClause && isNamedExports(d.exportClause)) as ExportDeclaration[]; if (length(exports) > 1) { const nonExports = filter(statements, d => !isExportDeclaration(d) || !!d.moduleSpecifier || !d.exportClause); statements = [...nonExports, createExportDeclaration( /*decorators*/ undefined, /*modifiers*/ undefined, - createNamedExports(flatMap(exports, e => e.exportClause!.elements)), + createNamedExports(flatMap(exports, e => cast(e.exportClause, isNamedExports).elements)), /*moduleSpecifier*/ undefined )]; } // Pass 2b: Also combine all `export {} from "..."` declarations as needed - const reexports = filter(statements, d => isExportDeclaration(d) && !!d.moduleSpecifier && !!d.exportClause) as ExportDeclaration[]; + const reexports = filter(statements, d => isExportDeclaration(d) && !!d.moduleSpecifier && !!d.exportClause && isNamedExports(d.exportClause)) as ExportDeclaration[]; if (length(reexports) > 1) { const groups = group(reexports, decl => isStringLiteral(decl.moduleSpecifier!) ? ">" + decl.moduleSpecifier.text : ">"); if (groups.length !== reexports.length) { @@ -5090,7 +5090,7 @@ namespace ts { createExportDeclaration( /*decorators*/ undefined, /*modifiers*/ undefined, - createNamedExports(flatMap(group, e => e.exportClause!.elements)), + createNamedExports(flatMap(group, e => cast(e.exportClause, isNamedExports).elements)), group[0].moduleSpecifier ) ]; @@ -5104,8 +5104,8 @@ namespace ts { function inlineExportModifiers(statements: Statement[]) { // Pass 3: Move all `export {}`'s to `export` modifiers where possible const exportDecl = find(statements, d => isExportDeclaration(d) && !d.moduleSpecifier && !!d.exportClause) as ExportDeclaration | undefined; - if (exportDecl) { - const replacements = mapDefined(exportDecl.exportClause!.elements, e => { + if (exportDecl && exportDecl.exportClause && isNamedExports(exportDecl.exportClause)) { + const replacements = mapDefined(exportDecl.exportClause.elements, e => { if (!e.propertyName) { // export {name} - look thru `statements` for `name`, and if all results can take an `export` modifier, do so and filter it const associated = filter(statements, s => nodeHasName(s, e.name)); @@ -5123,7 +5123,7 @@ namespace ts { else { // some items filtered, others not - update the export declaration // (mutating because why not, we're building a whole new tree here anyway) - exportDecl.exportClause!.elements = createNodeArray(replacements); + exportDecl.exportClause.elements = createNodeArray(replacements); } } return statements; @@ -32443,7 +32443,7 @@ namespace ts { return true; } - function checkAliasSymbol(node: ImportEqualsDeclaration | ImportClause | NamespaceImport | ImportSpecifier | ExportSpecifier) { + function checkAliasSymbol(node: ImportEqualsDeclaration | ImportClause | NamespaceImport | ImportSpecifier | ExportSpecifier | NamespaceExport) { let symbol = getSymbolOfNode(node); const target = resolveAlias(symbol); @@ -32483,6 +32483,10 @@ namespace ts { checkAliasSymbol(node); } + function checkNamespaceExport(node: NamespaceExport) { + checkAliasSymbol(node); + } + function checkImportDeclaration(node: ImportDeclaration) { if (checkGrammarModuleElementContext(node, Diagnostics.An_import_declaration_can_only_be_used_in_a_namespace_or_module)) { // If we hit an import declaration in an illegal context, just bail out to avoid cascading errors. @@ -32563,7 +32567,7 @@ namespace ts { // export { x, y } // export { x, y } from "foo" // export * as ns from "foo" - forEach(node.exportClause.elements, checkExportSpecifier); + isNamedExports(node.exportClause) ? forEach(node.exportClause.elements, checkExportSpecifier) : checkNamespaceExport(node.exportClause); const inAmbientExternalModule = node.parent.kind === SyntaxKind.ModuleBlock && isAmbientModule(node.parent.parent); const inAmbientNamespaceDeclaration = !inAmbientExternalModule && node.parent.kind === SyntaxKind.ModuleBlock && @@ -33990,7 +33994,7 @@ namespace ts { return isAliasResolvedToValue(getSymbolOfNode(node) || unknownSymbol); case SyntaxKind.ExportDeclaration: const exportClause = (node).exportClause; - return !!exportClause && some(exportClause.elements, isValueAliasDeclaration); + return !!exportClause && isNamedExports(exportClause) && some(exportClause.elements, isValueAliasDeclaration); case SyntaxKind.ExportAssignment: return (node).expression && (node).expression.kind === SyntaxKind.Identifier ? isAliasResolvedToValue(getSymbolOfNode(node) || unknownSymbol) : diff --git a/src/compiler/transformers/module/module.ts b/src/compiler/transformers/module/module.ts index 9726c6402e168..0fa7bd831b3ce 100644 --- a/src/compiler/transformers/module/module.ts +++ b/src/compiler/transformers/module/module.ts @@ -747,6 +747,17 @@ namespace ts { return createCall(createPropertyAccess(promiseResolveCall, "then"), /*typeArguments*/ undefined, [func]); } + function getHelperExpressionForExport(node:ExportDeclaration, innerExpr: Expression) { + if (!compilerOptions.esModuleInterop || getEmitFlags(node) & EmitFlags.NeverApplyImportHelper) { + return innerExpr; + } + if (getExportNeedsImportStarHelper(node)) { + context.requestEmitHelper(importStarHelper); + return createCall(getUnscopedHelperName("__importStar"), /*typeArguments*/ undefined, [innerExpr]); + } + return innerExpr; + } + function getHelperExpressionForImport(node: ImportDeclaration, innerExpr: Expression) { if (!compilerOptions.esModuleInterop || getEmitFlags(node) & EmitFlags.NeverApplyImportHelper) { return innerExpr; @@ -967,7 +978,7 @@ namespace ts { const generatedName = getGeneratedNameForNode(node); - if (node.exportClause) { + if (node.exportClause && isNamedExports(node.exportClause)) { const statements: Statement[] = []; // export { x, y } from "mod"; if (moduleKind !== ModuleKind.AMD) { @@ -1008,6 +1019,49 @@ namespace ts { return singleOrMany(statements); } + else if (node.exportClause) { + const statements: Statement[] = []; + // export * as ns from "mod"; + statements.push( + setOriginalNode( + setTextRange( + createVariableStatement( + /*modifiers*/ undefined, + createVariableDeclarationList([ + createVariableDeclaration( + generatedName, + /*type*/ undefined, + getHelperExpressionForExport(node, createRequireCall(node)) + ) + ]) + ), + /*location*/ node.exportClause.name), + /* original */ node.exportClause.name + ) + ) + + statements.push( + setOriginalNode( + setTextRange( + createExpressionStatement( + createExportExpression(node.exportClause.name, generatedName) + ), + node), + node + ) + ); + + setOriginalNode( + setTextRange( + createExpressionStatement( + createExportStarHelper(context, moduleKind !== ModuleKind.AMD ? createRequireCall(node) : generatedName) + ), + node), + node + ); + + return singleOrMany(statements); + } else { // export * from "mod"; return setOriginalNode( diff --git a/src/compiler/transformers/module/system.ts b/src/compiler/transformers/module/system.ts index 731ed6ef4fefe..1da8e1afec026 100644 --- a/src/compiler/transformers/module/system.ts +++ b/src/compiler/transformers/module/system.ts @@ -341,7 +341,7 @@ namespace ts { continue; } - if (!externalImport.exportClause) { + if (!externalImport.exportClause || !isNamedExports(externalImport.exportClause)) { // export * from ... continue; } @@ -488,7 +488,7 @@ namespace ts { case SyntaxKind.ExportDeclaration: Debug.assert(importVariableName !== undefined); - if (entry.exportClause) { + if (entry.exportClause && isNamedExports(entry.exportClause)) { // export {a, b as c} from 'foo' // // emit as: diff --git a/src/compiler/transformers/utilities.ts b/src/compiler/transformers/utilities.ts index 63ca99919de2a..ee56e608fa813 100644 --- a/src/compiler/transformers/utilities.ts +++ b/src/compiler/transformers/utilities.ts @@ -37,10 +37,17 @@ namespace ts { } } + export function getExportNeedsImportStarHelper(node: ExportDeclaration): boolean { + return !!getNamespaceDeclarationNode(node); + } + export function getImportNeedsImportStarHelper(node: ImportDeclaration): boolean { if (!!getNamespaceDeclarationNode(node)) { return true; } + if (isExportDeclaration(node)) { + return false; + } const bindings = node.importClause && node.importClause.namedBindings; if (!bindings) { return false; diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index f1d9799f2d501..ba724ff925915 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -2253,14 +2253,14 @@ namespace ts { } } - export function getNamespaceDeclarationNode(node: ImportDeclaration | ImportEqualsDeclaration | ExportDeclaration): ImportEqualsDeclaration | NamespaceImport | undefined { + export function getNamespaceDeclarationNode(node: ImportDeclaration | ImportEqualsDeclaration | ExportDeclaration): ImportEqualsDeclaration | NamespaceImport | NamespaceExport | undefined { switch (node.kind) { case SyntaxKind.ImportDeclaration: return node.importClause && tryCast(node.importClause.namedBindings, isNamespaceImport); case SyntaxKind.ImportEqualsDeclaration: return node; case SyntaxKind.ExportDeclaration: - return undefined; + return node.exportClause && tryCast(node.exportClause, isNamespaceExport); default: return Debug.assertNever(node); } @@ -6240,6 +6240,10 @@ namespace ts { return node.kind === SyntaxKind.NamespaceImport; } + export function isNamespaceExport(node: Node): node is NamespaceExport { + return node.kind === SyntaxKind.NamespaceExport; + } + export function isNamedImports(node: Node): node is NamedImports { return node.kind === SyntaxKind.NamedImports; } diff --git a/src/services/importTracker.ts b/src/services/importTracker.ts index 85d2027603c7f..165470e02d93e 100644 --- a/src/services/importTracker.ts +++ b/src/services/importTracker.ts @@ -237,7 +237,7 @@ namespace ts.FindAllReferences { } if (decl.kind === SyntaxKind.ExportDeclaration) { - searchForNamedImport(decl.exportClause); + decl.exportClause && isNamedExports(decl.exportClause) && searchForNamedImport(decl.exportClause); return; } @@ -323,7 +323,7 @@ namespace ts.FindAllReferences { return !!forEachPossibleImportOrExportStatement(sourceFileLike, statement => { if (!isExportDeclaration(statement)) return; const { exportClause, moduleSpecifier } = statement; - return !moduleSpecifier && exportClause && + return !moduleSpecifier && exportClause && isNamedExports(exportClause) && exportClause.elements.some(element => checker.getExportSpecifierLocalTargetSymbol(element) === namespaceImportSymbol); }); } diff --git a/src/services/organizeImports.ts b/src/services/organizeImports.ts index 6db5c9eeadc8c..f3e89219febd6 100644 --- a/src/services/organizeImports.ts +++ b/src/services/organizeImports.ts @@ -307,7 +307,7 @@ namespace ts.OrganizeImports { } const newExportSpecifiers: ExportSpecifier[] = []; - newExportSpecifiers.push(...flatMap(namedExports, i => (i.exportClause!).elements)); + newExportSpecifiers.push(...flatMap(namedExports, i => i.exportClause && isNamedExports(i.exportClause) ? i.exportClause.elements : [])); const sortedExportSpecifiers = sortSpecifiers(newExportSpecifiers); @@ -317,7 +317,11 @@ namespace ts.OrganizeImports { exportDecl, exportDecl.decorators, exportDecl.modifiers, - updateNamedExports(exportDecl.exportClause!, sortedExportSpecifiers), + exportDecl.exportClause && ( + isNamedExports(exportDecl.exportClause) ? + updateNamedExports(exportDecl.exportClause, sortedExportSpecifiers) : + updateNamespaceExport(exportDecl.exportClause, exportDecl.exportClause.name) + ), exportDecl.moduleSpecifier)); return coalescedExports; diff --git a/src/services/services.ts b/src/services/services.ts index a9bdcef8c5f7b..ab83d22b2ee2b 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -752,8 +752,14 @@ namespace ts { case SyntaxKind.ExportDeclaration: // Handle named exports case e.g.: // export {a, b as B} from "mod"; - if ((node).exportClause) { - forEach((node).exportClause!.elements, visit); + const exportDeclaration = (node) + if (exportDeclaration.exportClause) { + if (isNamedExports(exportDeclaration.exportClause)) { + forEach(exportDeclaration.exportClause.elements, visit); + } + else { + visit(exportDeclaration.exportClause.name); + } } break; From 8f56361a2122dc2e783a876a84345e9b77b2e310 Mon Sep 17 00:00:00 2001 From: kingwl Date: Tue, 5 Nov 2019 19:08:25 +0800 Subject: [PATCH 03/29] fix more case --- src/compiler/checker.ts | 7 +++++++ src/compiler/utilities.ts | 1 + .../es2020/modules/exportAsNamespace1.ts | 16 ++++++++++++++++ 3 files changed, 24 insertions(+) create mode 100644 tests/cases/conformance/es2020/modules/exportAsNamespace1.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 476f61959bfd8..b76dd2f38dbad 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -2221,6 +2221,11 @@ namespace ts { return resolveESModuleSymbol(resolveExternalModuleName(node, moduleSpecifier), moduleSpecifier, dontResolveAlias, /*suppressUsageError*/ false); } + function getTargetOfNamespaceExport(node: NamespaceExport, dontResolveAlias: boolean): Symbol | undefined { + const moduleSpecifier = node.parent.moduleSpecifier; + return moduleSpecifier && resolveESModuleSymbol(resolveExternalModuleName(node, moduleSpecifier), moduleSpecifier, dontResolveAlias, /*suppressUsageError*/ false); + } + // This function creates a synthetic symbol that combines the value side of one symbol with the // type/namespace side of another symbol. Consider this example: // @@ -2386,6 +2391,8 @@ namespace ts { return getTargetOfImportClause(node, dontRecursivelyResolve); case SyntaxKind.NamespaceImport: return getTargetOfNamespaceImport(node, dontRecursivelyResolve); + case SyntaxKind.NamespaceExport: + return getTargetOfNamespaceExport(node, dontRecursivelyResolve); case SyntaxKind.ImportSpecifier: return getTargetOfImportSpecifier(node, dontRecursivelyResolve); case SyntaxKind.ExportSpecifier: diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index ba724ff925915..fbabba7c4071c 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -2703,6 +2703,7 @@ namespace ts { node.kind === SyntaxKind.NamespaceExportDeclaration || node.kind === SyntaxKind.ImportClause && !!(node).name || node.kind === SyntaxKind.NamespaceImport || + node.kind === SyntaxKind.NamespaceExport || node.kind === SyntaxKind.ImportSpecifier || node.kind === SyntaxKind.ExportSpecifier || node.kind === SyntaxKind.ExportAssignment && exportAssignmentIsAlias(node) || diff --git a/tests/cases/conformance/es2020/modules/exportAsNamespace1.ts b/tests/cases/conformance/es2020/modules/exportAsNamespace1.ts new file mode 100644 index 0000000000000..b3af0c7543e70 --- /dev/null +++ b/tests/cases/conformance/es2020/modules/exportAsNamespace1.ts @@ -0,0 +1,16 @@ +// @module: esnext +// @target: esnext +// @filename: 0.ts +export const a = 1; +export const b = 2; + +// @filename: 1.ts +export * as ns from './0'; +ns.a; +ns.b; + +// @filename: 2.ts +import * as foo from './1' + +foo.ns.a; +foo.ns.b; \ No newline at end of file From 1b7c88b97bedf839ea53c85eebedc8a1a26a837a Mon Sep 17 00:00:00 2001 From: kingwl Date: Wed, 6 Nov 2019 01:30:17 +0800 Subject: [PATCH 04/29] fix more and more case --- src/compiler/binder.ts | 7 +++++++ src/compiler/checker.ts | 14 +++++++++++++- src/compiler/parser.ts | 2 ++ src/compiler/transformers/ts.ts | 10 +++++++++- src/compiler/utilities.ts | 1 + src/services/utilities.ts | 1 + 6 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 02caf699a2e00..3474b676a07ef 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -2623,6 +2623,9 @@ namespace ts { // All export * declarations are collected in an __export symbol declareSymbol(container.symbol.exports, container.symbol, node, SymbolFlags.ExportStar, SymbolFlags.None); } + else { + declareSymbol(container.symbol.exports, container.symbol, node, SymbolFlags.ExportStar, SymbolFlags.None); + } } function bindImportClause(node: ImportClause) { @@ -4155,6 +4158,10 @@ namespace ts { case SyntaxKind.SourceFile: break; + case SyntaxKind.NamespaceExport: + transformFlags |= TransformFlags.AssertESNext; + break; + case SyntaxKind.ReturnStatement: // Return statements may require an `await` in ES2018. transformFlags |= TransformFlags.ContainsHoistedDeclarationOrCompletion | TransformFlags.AssertES2018; diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index b76dd2f38dbad..9504fdb810e98 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5646,6 +5646,14 @@ namespace ts { createLiteral(getSpecifierForModuleSymbol(target, context)) ), ModifierFlags.None); break; + case SyntaxKind.NamespaceExport: + addResult(createExportDeclaration( + /*decorators*/ undefined, + /*modifiers*/ undefined, + createNamespaceExport(createIdentifier(localName)), + createLiteral(getSpecifierForModuleSymbol(target, context)) + ), ModifierFlags.None); + break; case SyntaxKind.ImportSpecifier: addResult(createImportDeclaration( /*decorators*/ undefined, @@ -34001,7 +34009,10 @@ namespace ts { return isAliasResolvedToValue(getSymbolOfNode(node) || unknownSymbol); case SyntaxKind.ExportDeclaration: const exportClause = (node).exportClause; - return !!exportClause && isNamedExports(exportClause) && some(exportClause.elements, isValueAliasDeclaration); + return !!exportClause && ( + isNamespaceExport(exportClause) || + some(exportClause.elements, isValueAliasDeclaration) + ); case SyntaxKind.ExportAssignment: return (node).expression && (node).expression.kind === SyntaxKind.Identifier ? isAliasResolvedToValue(getSymbolOfNode(node) || unknownSymbol) : @@ -36191,6 +36202,7 @@ namespace ts { case SyntaxKind.ImportClause: // For default import case SyntaxKind.ImportEqualsDeclaration: case SyntaxKind.NamespaceImport: + case SyntaxKind.NamespaceExport: case SyntaxKind.ImportSpecifier: // For rename import `x as y` return true; case SyntaxKind.Identifier: diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 7b99453b46d6f..fc4ac13c41d1b 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -390,6 +390,8 @@ namespace ts { case SyntaxKind.NamespaceImport: return visitNode(cbNode, (node).name); + case SyntaxKind.NamespaceExport: + return visitNode(cbNode, (node).name); case SyntaxKind.NamedImports: case SyntaxKind.NamedExports: return visitNodes(cbNode, cbNodes, (node).elements); diff --git a/src/compiler/transformers/ts.ts b/src/compiler/transformers/ts.ts index d413a835d0d86..0c345559e061c 100644 --- a/src/compiler/transformers/ts.ts +++ b/src/compiler/transformers/ts.ts @@ -2845,7 +2845,7 @@ namespace ts { } // Elide the export declaration if all of its named exports are elided. - const exportClause = visitNode(node.exportClause, visitNamedExports, isNamedExports); + const exportClause = visitNode(node.exportClause, visitNamedExportBindings, isNamedImportBindings); return exportClause ? updateExportDeclaration( node, @@ -2868,6 +2868,14 @@ namespace ts { return some(elements) ? updateNamedExports(node, elements) : undefined; } + function visitNamespaceExports(node: NamespaceExport): VisitResult { + return updateNamespaceExport(node, visitNode(node.name, visitor, isIdentifier)) + } + + function visitNamedExportBindings(node: NamedExportBindings): VisitResult { + return isNamespaceExport(node) ? visitNamespaceExports(node) : visitNamedExports(node) + } + /** * Visits an export specifier, eliding it if it does not resolve to a value. * diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index fbabba7c4071c..6014197a8cc10 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -7132,6 +7132,7 @@ namespace ts { || kind === SyntaxKind.ModuleDeclaration || kind === SyntaxKind.NamespaceExportDeclaration || kind === SyntaxKind.NamespaceImport + || kind === SyntaxKind.NamespaceExport || kind === SyntaxKind.Parameter || kind === SyntaxKind.PropertyAssignment || kind === SyntaxKind.PropertyDeclaration diff --git a/src/services/utilities.ts b/src/services/utilities.ts index d0e75c5522fc9..6abc7b64d0b8c 100644 --- a/src/services/utilities.ts +++ b/src/services/utilities.ts @@ -372,6 +372,7 @@ namespace ts { case SyntaxKind.ImportSpecifier: case SyntaxKind.ExportSpecifier: case SyntaxKind.NamespaceImport: + case SyntaxKind.NamespaceExport: return ScriptElementKind.alias; case SyntaxKind.BinaryExpression: const kind = getAssignmentDeclarationKind(node as BinaryExpression); From fba692c88256f9bb05f94662df0255843bcd5240 Mon Sep 17 00:00:00 2001 From: kingwl Date: Wed, 6 Nov 2019 18:48:08 +0800 Subject: [PATCH 05/29] make it work --- src/compiler/binder.ts | 5 +-- .../baselines/reference/exportAsNamespace1.js | 28 +++++++++++++ .../reference/exportAsNamespace1.symbols | 39 ++++++++++++++++++ .../reference/exportAsNamespace1.types | 41 +++++++++++++++++++ 4 files changed, 110 insertions(+), 3 deletions(-) create mode 100644 tests/baselines/reference/exportAsNamespace1.js create mode 100644 tests/baselines/reference/exportAsNamespace1.symbols create mode 100644 tests/baselines/reference/exportAsNamespace1.types diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 3474b676a07ef..db627628dca87 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -2505,7 +2505,6 @@ namespace ts { // Imports and exports case SyntaxKind.ImportEqualsDeclaration: case SyntaxKind.NamespaceImport: - case SyntaxKind.NamespaceExport: case SyntaxKind.ImportSpecifier: case SyntaxKind.ExportSpecifier: return declareSymbolAndAddToSymbolTable(node, SymbolFlags.Alias, SymbolFlags.AliasExcludes); @@ -2623,8 +2622,8 @@ namespace ts { // All export * declarations are collected in an __export symbol declareSymbol(container.symbol.exports, container.symbol, node, SymbolFlags.ExportStar, SymbolFlags.None); } - else { - declareSymbol(container.symbol.exports, container.symbol, node, SymbolFlags.ExportStar, SymbolFlags.None); + else if (isNamespaceExport(node.exportClause)) { + declareSymbol(container.symbol.exports, container.symbol, node.exportClause, SymbolFlags.Alias, SymbolFlags.AliasExcludes); } } diff --git a/tests/baselines/reference/exportAsNamespace1.js b/tests/baselines/reference/exportAsNamespace1.js new file mode 100644 index 0000000000000..fe75357d95126 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace1.js @@ -0,0 +1,28 @@ +//// [tests/cases/conformance/es2020/modules/exportAsNamespace1.ts] //// + +//// [0.ts] +export const a = 1; +export const b = 2; + +//// [1.ts] +export * as ns from './0'; +ns.a; +ns.b; + +//// [2.ts] +import * as foo from './1' + +foo.ns.a; +foo.ns.b; + +//// [0.js] +export const a = 1; +export const b = 2; +//// [1.js] +export * as ns from './0'; +ns.a; +ns.b; +//// [2.js] +import * as foo from './1'; +foo.ns.a; +foo.ns.b; diff --git a/tests/baselines/reference/exportAsNamespace1.symbols b/tests/baselines/reference/exportAsNamespace1.symbols new file mode 100644 index 0000000000000..1ed5fa61afb25 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace1.symbols @@ -0,0 +1,39 @@ +=== tests/cases/conformance/es2020/modules/0.ts === +export const a = 1; +>a : Symbol(a, Decl(0.ts, 0, 12)) + +export const b = 2; +>b : Symbol(b, Decl(0.ts, 1, 12)) + +=== tests/cases/conformance/es2020/modules/1.ts === +export * as ns from './0'; +>ns : Symbol(ns, Decl(1.ts, 0, 11)) + +ns.a; +>ns.a : Symbol(ns.a, Decl(0.ts, 0, 12)) +>ns : Symbol(ns, Decl(1.ts, 0, 11)) +>a : Symbol(ns.a, Decl(0.ts, 0, 12)) + +ns.b; +>ns.b : Symbol(ns.b, Decl(0.ts, 1, 12)) +>ns : Symbol(ns, Decl(1.ts, 0, 11)) +>b : Symbol(ns.b, Decl(0.ts, 1, 12)) + +=== tests/cases/conformance/es2020/modules/2.ts === +import * as foo from './1' +>foo : Symbol(foo, Decl(2.ts, 0, 6)) + +foo.ns.a; +>foo.ns.a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo : Symbol(foo, Decl(2.ts, 0, 6)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) + +foo.ns.b; +>foo.ns.b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo : Symbol(foo, Decl(2.ts, 0, 6)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) + diff --git a/tests/baselines/reference/exportAsNamespace1.types b/tests/baselines/reference/exportAsNamespace1.types new file mode 100644 index 0000000000000..6e3ebceb001cd --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace1.types @@ -0,0 +1,41 @@ +=== tests/cases/conformance/es2020/modules/0.ts === +export const a = 1; +>a : 1 +>1 : 1 + +export const b = 2; +>b : 2 +>2 : 2 + +=== tests/cases/conformance/es2020/modules/1.ts === +export * as ns from './0'; +>ns : typeof ns + +ns.a; +>ns.a : 1 +>ns : typeof ns +>a : 1 + +ns.b; +>ns.b : 2 +>ns : typeof ns +>b : 2 + +=== tests/cases/conformance/es2020/modules/2.ts === +import * as foo from './1' +>foo : typeof foo + +foo.ns.a; +>foo.ns.a : 1 +>foo.ns : typeof foo.ns +>foo : typeof foo +>ns : typeof foo.ns +>a : 1 + +foo.ns.b; +>foo.ns.b : 2 +>foo.ns : typeof foo.ns +>foo : typeof foo +>ns : typeof foo.ns +>b : 2 + From 97d47f8dd7ef5c7bf4671f583530775e06234911 Mon Sep 17 00:00:00 2001 From: kingwl Date: Thu, 7 Nov 2019 00:07:48 +0800 Subject: [PATCH 06/29] make lint happy and accept baseline --- src/compiler/transformers/module/module.ts | 4 +- src/compiler/transformers/ts.ts | 4 +- src/compiler/transformers/utilities.ts | 3 - src/compiler/visitor.ts | 2 +- src/services/services.ts | 2 +- src/testRunner/parallel/host.ts | 4 +- .../reference/api/tsserverlibrary.d.ts | 152 ++++++++++-------- tests/baselines/reference/api/typescript.d.ts | 152 ++++++++++-------- 8 files changed, 170 insertions(+), 153 deletions(-) diff --git a/src/compiler/transformers/module/module.ts b/src/compiler/transformers/module/module.ts index 0fa7bd831b3ce..fb637cf9ee38c 100644 --- a/src/compiler/transformers/module/module.ts +++ b/src/compiler/transformers/module/module.ts @@ -747,7 +747,7 @@ namespace ts { return createCall(createPropertyAccess(promiseResolveCall, "then"), /*typeArguments*/ undefined, [func]); } - function getHelperExpressionForExport(node:ExportDeclaration, innerExpr: Expression) { + function getHelperExpressionForExport(node: ExportDeclaration, innerExpr: Expression) { if (!compilerOptions.esModuleInterop || getEmitFlags(node) & EmitFlags.NeverApplyImportHelper) { return innerExpr; } @@ -1038,7 +1038,7 @@ namespace ts { /*location*/ node.exportClause.name), /* original */ node.exportClause.name ) - ) + ); statements.push( setOriginalNode( diff --git a/src/compiler/transformers/ts.ts b/src/compiler/transformers/ts.ts index 0c345559e061c..2ac8845404f1e 100644 --- a/src/compiler/transformers/ts.ts +++ b/src/compiler/transformers/ts.ts @@ -2869,11 +2869,11 @@ namespace ts { } function visitNamespaceExports(node: NamespaceExport): VisitResult { - return updateNamespaceExport(node, visitNode(node.name, visitor, isIdentifier)) + return updateNamespaceExport(node, visitNode(node.name, visitor, isIdentifier)); } function visitNamedExportBindings(node: NamedExportBindings): VisitResult { - return isNamespaceExport(node) ? visitNamespaceExports(node) : visitNamedExports(node) + return isNamespaceExport(node) ? visitNamespaceExports(node) : visitNamedExports(node); } /** diff --git a/src/compiler/transformers/utilities.ts b/src/compiler/transformers/utilities.ts index ee56e608fa813..c47b033014b0b 100644 --- a/src/compiler/transformers/utilities.ts +++ b/src/compiler/transformers/utilities.ts @@ -45,9 +45,6 @@ namespace ts { if (!!getNamespaceDeclarationNode(node)) { return true; } - if (isExportDeclaration(node)) { - return false; - } const bindings = node.importClause && node.importClause.namedBindings; if (!bindings) { return false; diff --git a/src/compiler/visitor.ts b/src/compiler/visitor.ts index bef2f66a61c8d..baa684b3bf524 100644 --- a/src/compiler/visitor.ts +++ b/src/compiler/visitor.ts @@ -822,7 +822,7 @@ namespace ts { case SyntaxKind.NamespaceExport: return updateNamespaceExport(node, visitNode((node).name, visitor, isIdentifier) - ) + ); case SyntaxKind.NamedExports: return updateNamedExports(node, diff --git a/src/services/services.ts b/src/services/services.ts index ab83d22b2ee2b..929aefcc2ca18 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -752,7 +752,7 @@ namespace ts { case SyntaxKind.ExportDeclaration: // Handle named exports case e.g.: // export {a, b as B} from "mod"; - const exportDeclaration = (node) + const exportDeclaration = (node); if (exportDeclaration.exportClause) { if (isNamedExports(exportDeclaration.exportClause)) { forEach(exportDeclaration.exportClause.elements, visit); diff --git a/src/testRunner/parallel/host.ts b/src/testRunner/parallel/host.ts index 0273ad7ec4e6f..89264224c13a6 100644 --- a/src/testRunner/parallel/host.ts +++ b/src/testRunner/parallel/host.ts @@ -147,7 +147,7 @@ namespace Harness.Parallel.Host { } cursor.hide(); - readline.moveCursor(process.stdout, -process.stdout.columns, -this._lineCount); + readline.moveCursor(process.stdout, -process.stdout.columns!, -this._lineCount); let lineCount = 0; const numProgressBars = this._progressBars.length; for (let i = 0; i < numProgressBars; i++) { @@ -156,7 +156,7 @@ namespace Harness.Parallel.Host { process.stdout.write(this._progressBars[i].text + os.EOL); } else { - readline.moveCursor(process.stdout, -process.stdout.columns, +1); + readline.moveCursor(process.stdout, -process.stdout.columns!, +1); } lineCount++; diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index e775580c1fb32..6b477e1913d5d 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -338,70 +338,71 @@ declare namespace ts { ExportAssignment = 258, ExportDeclaration = 259, NamedExports = 260, - ExportSpecifier = 261, - MissingDeclaration = 262, - ExternalModuleReference = 263, - JsxElement = 264, - JsxSelfClosingElement = 265, - JsxOpeningElement = 266, - JsxClosingElement = 267, - JsxFragment = 268, - JsxOpeningFragment = 269, - JsxClosingFragment = 270, - JsxAttribute = 271, - JsxAttributes = 272, - JsxSpreadAttribute = 273, - JsxExpression = 274, - CaseClause = 275, - DefaultClause = 276, - HeritageClause = 277, - CatchClause = 278, - PropertyAssignment = 279, - ShorthandPropertyAssignment = 280, - SpreadAssignment = 281, - EnumMember = 282, - UnparsedPrologue = 283, - UnparsedPrepend = 284, - UnparsedText = 285, - UnparsedInternalText = 286, - UnparsedSyntheticReference = 287, - SourceFile = 288, - Bundle = 289, - UnparsedSource = 290, - InputFiles = 291, - JSDocTypeExpression = 292, - JSDocAllType = 293, - JSDocUnknownType = 294, - JSDocNullableType = 295, - JSDocNonNullableType = 296, - JSDocOptionalType = 297, - JSDocFunctionType = 298, - JSDocVariadicType = 299, - JSDocNamepathType = 300, - JSDocComment = 301, - JSDocTypeLiteral = 302, - JSDocSignature = 303, - JSDocTag = 304, - JSDocAugmentsTag = 305, - JSDocAuthorTag = 306, - JSDocClassTag = 307, - JSDocCallbackTag = 308, - JSDocEnumTag = 309, - JSDocParameterTag = 310, - JSDocReturnTag = 311, - JSDocThisTag = 312, - JSDocTypeTag = 313, - JSDocTemplateTag = 314, - JSDocTypedefTag = 315, - JSDocPropertyTag = 316, - SyntaxList = 317, - NotEmittedStatement = 318, - PartiallyEmittedExpression = 319, - CommaListExpression = 320, - MergeDeclarationMarker = 321, - EndOfDeclarationMarker = 322, - SyntheticReferenceExpression = 323, - Count = 324, + NamespaceExport = 261, + ExportSpecifier = 262, + MissingDeclaration = 263, + ExternalModuleReference = 264, + JsxElement = 265, + JsxSelfClosingElement = 266, + JsxOpeningElement = 267, + JsxClosingElement = 268, + JsxFragment = 269, + JsxOpeningFragment = 270, + JsxClosingFragment = 271, + JsxAttribute = 272, + JsxAttributes = 273, + JsxSpreadAttribute = 274, + JsxExpression = 275, + CaseClause = 276, + DefaultClause = 277, + HeritageClause = 278, + CatchClause = 279, + PropertyAssignment = 280, + ShorthandPropertyAssignment = 281, + SpreadAssignment = 282, + EnumMember = 283, + UnparsedPrologue = 284, + UnparsedPrepend = 285, + UnparsedText = 286, + UnparsedInternalText = 287, + UnparsedSyntheticReference = 288, + SourceFile = 289, + Bundle = 290, + UnparsedSource = 291, + InputFiles = 292, + JSDocTypeExpression = 293, + JSDocAllType = 294, + JSDocUnknownType = 295, + JSDocNullableType = 296, + JSDocNonNullableType = 297, + JSDocOptionalType = 298, + JSDocFunctionType = 299, + JSDocVariadicType = 300, + JSDocNamepathType = 301, + JSDocComment = 302, + JSDocTypeLiteral = 303, + JSDocSignature = 304, + JSDocTag = 305, + JSDocAugmentsTag = 306, + JSDocAuthorTag = 307, + JSDocClassTag = 308, + JSDocCallbackTag = 309, + JSDocEnumTag = 310, + JSDocParameterTag = 311, + JSDocReturnTag = 312, + JSDocThisTag = 313, + JSDocTypeTag = 314, + JSDocTemplateTag = 315, + JSDocTypedefTag = 316, + JSDocPropertyTag = 317, + SyntaxList = 318, + NotEmittedStatement = 319, + PartiallyEmittedExpression = 320, + CommaListExpression = 321, + MergeDeclarationMarker = 322, + EndOfDeclarationMarker = 323, + SyntheticReferenceExpression = 324, + Count = 325, FirstAssignment = 62, LastAssignment = 74, FirstCompoundAssignment = 63, @@ -429,10 +430,10 @@ declare namespace ts { FirstStatement = 224, LastStatement = 240, FirstNode = 152, - FirstJSDocNode = 292, - LastJSDocNode = 316, - FirstJSDocTagNode = 304, - LastJSDocTagNode = 316, + FirstJSDocNode = 293, + LastJSDocNode = 317, + FirstJSDocTagNode = 305, + LastJSDocTagNode = 317, } export enum NodeFlags { None = 0, @@ -1481,6 +1482,7 @@ declare namespace ts { moduleSpecifier: Expression; } export type NamedImportBindings = NamespaceImport | NamedImports; + export type NamedExportBindings = NamespaceExport | NamedExports; export interface ImportClause extends NamedDeclaration { kind: SyntaxKind.ImportClause; parent: ImportDeclaration; @@ -1492,6 +1494,11 @@ declare namespace ts { parent: ImportClause; name: Identifier; } + export interface NamespaceExport extends NamedDeclaration { + kind: SyntaxKind.NamespaceExport; + parent: ExportDeclaration; + name: Identifier; + } export interface NamespaceExportDeclaration extends DeclarationStatement { kind: SyntaxKind.NamespaceExportDeclaration; name: Identifier; @@ -1500,7 +1507,7 @@ declare namespace ts { kind: SyntaxKind.ExportDeclaration; parent: SourceFile | ModuleBlock; /** Will not be assigned in the case of `export * from "foo";` */ - exportClause?: NamedExports; + exportClause?: NamedExportBindings; /** If this is not a StringLiteral it will be a grammar error. */ moduleSpecifier?: Expression; } @@ -3589,6 +3596,7 @@ declare namespace ts { function isImportDeclaration(node: Node): node is ImportDeclaration; function isImportClause(node: Node): node is ImportClause; function isNamespaceImport(node: Node): node is NamespaceImport; + function isNamespaceExport(node: Node): node is NamespaceExport; function isNamedImports(node: Node): node is NamedImports; function isImportSpecifier(node: Node): node is ImportSpecifier; function isExportAssignment(node: Node): node is ExportAssignment; @@ -4099,6 +4107,8 @@ declare namespace ts { function updateCaseBlock(node: CaseBlock, clauses: readonly CaseOrDefaultClause[]): CaseBlock; function createNamespaceExportDeclaration(name: string | Identifier): NamespaceExportDeclaration; function updateNamespaceExportDeclaration(node: NamespaceExportDeclaration, name: Identifier): NamespaceExportDeclaration; + function createNamespaceExport(name: string | Identifier): NamespaceExport; + function updateNamespaceExport(node: NamespaceExport, name: Identifier): NamespaceExport; function createImportEqualsDeclaration(decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, name: string | Identifier, moduleReference: ModuleReference): ImportEqualsDeclaration; function updateImportEqualsDeclaration(node: ImportEqualsDeclaration, decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, name: Identifier, moduleReference: ModuleReference): ImportEqualsDeclaration; function createImportDeclaration(decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, importClause: ImportClause | undefined, moduleSpecifier: Expression): ImportDeclaration; @@ -4113,8 +4123,8 @@ declare namespace ts { function updateImportSpecifier(node: ImportSpecifier, propertyName: Identifier | undefined, name: Identifier): ImportSpecifier; function createExportAssignment(decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, isExportEquals: boolean | undefined, expression: Expression): ExportAssignment; function updateExportAssignment(node: ExportAssignment, decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, expression: Expression): ExportAssignment; - function createExportDeclaration(decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, exportClause: NamedExports | undefined, moduleSpecifier?: Expression): ExportDeclaration; - function updateExportDeclaration(node: ExportDeclaration, decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, exportClause: NamedExports | undefined, moduleSpecifier: Expression | undefined): ExportDeclaration; + function createExportDeclaration(decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, exportClause: NamedExportBindings | undefined, moduleSpecifier?: Expression): ExportDeclaration; + function updateExportDeclaration(node: ExportDeclaration, decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, exportClause: NamedExportBindings | undefined, moduleSpecifier: Expression | undefined): ExportDeclaration; function createNamedExports(elements: readonly ExportSpecifier[]): NamedExports; function updateNamedExports(node: NamedExports, elements: readonly ExportSpecifier[]): NamedExports; function createExportSpecifier(propertyName: string | Identifier | undefined, name: string | Identifier): ExportSpecifier; diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index fe23df054dac9..07c53081fc636 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -338,70 +338,71 @@ declare namespace ts { ExportAssignment = 258, ExportDeclaration = 259, NamedExports = 260, - ExportSpecifier = 261, - MissingDeclaration = 262, - ExternalModuleReference = 263, - JsxElement = 264, - JsxSelfClosingElement = 265, - JsxOpeningElement = 266, - JsxClosingElement = 267, - JsxFragment = 268, - JsxOpeningFragment = 269, - JsxClosingFragment = 270, - JsxAttribute = 271, - JsxAttributes = 272, - JsxSpreadAttribute = 273, - JsxExpression = 274, - CaseClause = 275, - DefaultClause = 276, - HeritageClause = 277, - CatchClause = 278, - PropertyAssignment = 279, - ShorthandPropertyAssignment = 280, - SpreadAssignment = 281, - EnumMember = 282, - UnparsedPrologue = 283, - UnparsedPrepend = 284, - UnparsedText = 285, - UnparsedInternalText = 286, - UnparsedSyntheticReference = 287, - SourceFile = 288, - Bundle = 289, - UnparsedSource = 290, - InputFiles = 291, - JSDocTypeExpression = 292, - JSDocAllType = 293, - JSDocUnknownType = 294, - JSDocNullableType = 295, - JSDocNonNullableType = 296, - JSDocOptionalType = 297, - JSDocFunctionType = 298, - JSDocVariadicType = 299, - JSDocNamepathType = 300, - JSDocComment = 301, - JSDocTypeLiteral = 302, - JSDocSignature = 303, - JSDocTag = 304, - JSDocAugmentsTag = 305, - JSDocAuthorTag = 306, - JSDocClassTag = 307, - JSDocCallbackTag = 308, - JSDocEnumTag = 309, - JSDocParameterTag = 310, - JSDocReturnTag = 311, - JSDocThisTag = 312, - JSDocTypeTag = 313, - JSDocTemplateTag = 314, - JSDocTypedefTag = 315, - JSDocPropertyTag = 316, - SyntaxList = 317, - NotEmittedStatement = 318, - PartiallyEmittedExpression = 319, - CommaListExpression = 320, - MergeDeclarationMarker = 321, - EndOfDeclarationMarker = 322, - SyntheticReferenceExpression = 323, - Count = 324, + NamespaceExport = 261, + ExportSpecifier = 262, + MissingDeclaration = 263, + ExternalModuleReference = 264, + JsxElement = 265, + JsxSelfClosingElement = 266, + JsxOpeningElement = 267, + JsxClosingElement = 268, + JsxFragment = 269, + JsxOpeningFragment = 270, + JsxClosingFragment = 271, + JsxAttribute = 272, + JsxAttributes = 273, + JsxSpreadAttribute = 274, + JsxExpression = 275, + CaseClause = 276, + DefaultClause = 277, + HeritageClause = 278, + CatchClause = 279, + PropertyAssignment = 280, + ShorthandPropertyAssignment = 281, + SpreadAssignment = 282, + EnumMember = 283, + UnparsedPrologue = 284, + UnparsedPrepend = 285, + UnparsedText = 286, + UnparsedInternalText = 287, + UnparsedSyntheticReference = 288, + SourceFile = 289, + Bundle = 290, + UnparsedSource = 291, + InputFiles = 292, + JSDocTypeExpression = 293, + JSDocAllType = 294, + JSDocUnknownType = 295, + JSDocNullableType = 296, + JSDocNonNullableType = 297, + JSDocOptionalType = 298, + JSDocFunctionType = 299, + JSDocVariadicType = 300, + JSDocNamepathType = 301, + JSDocComment = 302, + JSDocTypeLiteral = 303, + JSDocSignature = 304, + JSDocTag = 305, + JSDocAugmentsTag = 306, + JSDocAuthorTag = 307, + JSDocClassTag = 308, + JSDocCallbackTag = 309, + JSDocEnumTag = 310, + JSDocParameterTag = 311, + JSDocReturnTag = 312, + JSDocThisTag = 313, + JSDocTypeTag = 314, + JSDocTemplateTag = 315, + JSDocTypedefTag = 316, + JSDocPropertyTag = 317, + SyntaxList = 318, + NotEmittedStatement = 319, + PartiallyEmittedExpression = 320, + CommaListExpression = 321, + MergeDeclarationMarker = 322, + EndOfDeclarationMarker = 323, + SyntheticReferenceExpression = 324, + Count = 325, FirstAssignment = 62, LastAssignment = 74, FirstCompoundAssignment = 63, @@ -429,10 +430,10 @@ declare namespace ts { FirstStatement = 224, LastStatement = 240, FirstNode = 152, - FirstJSDocNode = 292, - LastJSDocNode = 316, - FirstJSDocTagNode = 304, - LastJSDocTagNode = 316, + FirstJSDocNode = 293, + LastJSDocNode = 317, + FirstJSDocTagNode = 305, + LastJSDocTagNode = 317, } export enum NodeFlags { None = 0, @@ -1481,6 +1482,7 @@ declare namespace ts { moduleSpecifier: Expression; } export type NamedImportBindings = NamespaceImport | NamedImports; + export type NamedExportBindings = NamespaceExport | NamedExports; export interface ImportClause extends NamedDeclaration { kind: SyntaxKind.ImportClause; parent: ImportDeclaration; @@ -1492,6 +1494,11 @@ declare namespace ts { parent: ImportClause; name: Identifier; } + export interface NamespaceExport extends NamedDeclaration { + kind: SyntaxKind.NamespaceExport; + parent: ExportDeclaration; + name: Identifier; + } export interface NamespaceExportDeclaration extends DeclarationStatement { kind: SyntaxKind.NamespaceExportDeclaration; name: Identifier; @@ -1500,7 +1507,7 @@ declare namespace ts { kind: SyntaxKind.ExportDeclaration; parent: SourceFile | ModuleBlock; /** Will not be assigned in the case of `export * from "foo";` */ - exportClause?: NamedExports; + exportClause?: NamedExportBindings; /** If this is not a StringLiteral it will be a grammar error. */ moduleSpecifier?: Expression; } @@ -3589,6 +3596,7 @@ declare namespace ts { function isImportDeclaration(node: Node): node is ImportDeclaration; function isImportClause(node: Node): node is ImportClause; function isNamespaceImport(node: Node): node is NamespaceImport; + function isNamespaceExport(node: Node): node is NamespaceExport; function isNamedImports(node: Node): node is NamedImports; function isImportSpecifier(node: Node): node is ImportSpecifier; function isExportAssignment(node: Node): node is ExportAssignment; @@ -4099,6 +4107,8 @@ declare namespace ts { function updateCaseBlock(node: CaseBlock, clauses: readonly CaseOrDefaultClause[]): CaseBlock; function createNamespaceExportDeclaration(name: string | Identifier): NamespaceExportDeclaration; function updateNamespaceExportDeclaration(node: NamespaceExportDeclaration, name: Identifier): NamespaceExportDeclaration; + function createNamespaceExport(name: string | Identifier): NamespaceExport; + function updateNamespaceExport(node: NamespaceExport, name: Identifier): NamespaceExport; function createImportEqualsDeclaration(decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, name: string | Identifier, moduleReference: ModuleReference): ImportEqualsDeclaration; function updateImportEqualsDeclaration(node: ImportEqualsDeclaration, decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, name: Identifier, moduleReference: ModuleReference): ImportEqualsDeclaration; function createImportDeclaration(decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, importClause: ImportClause | undefined, moduleSpecifier: Expression): ImportDeclaration; @@ -4113,8 +4123,8 @@ declare namespace ts { function updateImportSpecifier(node: ImportSpecifier, propertyName: Identifier | undefined, name: Identifier): ImportSpecifier; function createExportAssignment(decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, isExportEquals: boolean | undefined, expression: Expression): ExportAssignment; function updateExportAssignment(node: ExportAssignment, decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, expression: Expression): ExportAssignment; - function createExportDeclaration(decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, exportClause: NamedExports | undefined, moduleSpecifier?: Expression): ExportDeclaration; - function updateExportDeclaration(node: ExportDeclaration, decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, exportClause: NamedExports | undefined, moduleSpecifier: Expression | undefined): ExportDeclaration; + function createExportDeclaration(decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, exportClause: NamedExportBindings | undefined, moduleSpecifier?: Expression): ExportDeclaration; + function updateExportDeclaration(node: ExportDeclaration, decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, exportClause: NamedExportBindings | undefined, moduleSpecifier: Expression | undefined): ExportDeclaration; function createNamedExports(elements: readonly ExportSpecifier[]): NamedExports; function updateNamedExports(node: NamedExports, elements: readonly ExportSpecifier[]): NamedExports; function createExportSpecifier(propertyName: string | Identifier | undefined, name: string | Identifier): ExportSpecifier; From 20dc2738c779d5b10537b6773f5cb977af4e407e Mon Sep 17 00:00:00 2001 From: kingwl Date: Thu, 7 Nov 2019 01:14:35 +0800 Subject: [PATCH 07/29] add more tests --- src/compiler/checker.ts | 16 ++--- src/compiler/transformers/module/module.ts | 45 ++++++------- .../baselines/reference/exportAsNamespace1.js | 19 ++++-- .../reference/exportAsNamespace1_amd.js | 39 +++++++++++ .../reference/exportAsNamespace1_amd.symbols | 39 +++++++++++ .../reference/exportAsNamespace1_amd.types | 41 ++++++++++++ .../reference/exportAsNamespace1_esnext.js | 28 ++++++++ .../exportAsNamespace1_esnext.symbols | 39 +++++++++++ .../reference/exportAsNamespace1_esnext.types | 41 ++++++++++++ .../reference/exportAsNamespace1_umd.js | 65 +++++++++++++++++++ .../reference/exportAsNamespace1_umd.symbols | 39 +++++++++++ .../reference/exportAsNamespace1_umd.types | 41 ++++++++++++ .../es2020/modules/exportAsNamespace1.ts | 2 - .../es2020/modules/exportAsNamespace1_amd.ts | 15 +++++ .../modules/exportAsNamespace1_esnext.ts | 15 +++++ .../modules/exportAsNamespace1_system.ts | 15 +++++ .../es2020/modules/exportAsNamespace1_umd.ts | 15 +++++ 17 files changed, 470 insertions(+), 44 deletions(-) create mode 100644 tests/baselines/reference/exportAsNamespace1_amd.js create mode 100644 tests/baselines/reference/exportAsNamespace1_amd.symbols create mode 100644 tests/baselines/reference/exportAsNamespace1_amd.types create mode 100644 tests/baselines/reference/exportAsNamespace1_esnext.js create mode 100644 tests/baselines/reference/exportAsNamespace1_esnext.symbols create mode 100644 tests/baselines/reference/exportAsNamespace1_esnext.types create mode 100644 tests/baselines/reference/exportAsNamespace1_umd.js create mode 100644 tests/baselines/reference/exportAsNamespace1_umd.symbols create mode 100644 tests/baselines/reference/exportAsNamespace1_umd.types create mode 100644 tests/cases/conformance/es2020/modules/exportAsNamespace1_amd.ts create mode 100644 tests/cases/conformance/es2020/modules/exportAsNamespace1_esnext.ts create mode 100644 tests/cases/conformance/es2020/modules/exportAsNamespace1_system.ts create mode 100644 tests/cases/conformance/es2020/modules/exportAsNamespace1_umd.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 9504fdb810e98..a1c2b4cf08260 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -32492,16 +32492,12 @@ namespace ts { } } - function checkImportBinding(node: ImportEqualsDeclaration | ImportClause | NamespaceImport | ImportSpecifier) { + function checkImportOrExportBinding(node: ImportEqualsDeclaration | ImportClause | NamespaceImport | NamespaceExport | ImportSpecifier) { checkCollisionWithRequireExportsInGeneratedCode(node, node.name!); checkCollisionWithGlobalPromiseInGeneratedCode(node, node.name!); checkAliasSymbol(node); } - function checkNamespaceExport(node: NamespaceExport) { - checkAliasSymbol(node); - } - function checkImportDeclaration(node: ImportDeclaration) { if (checkGrammarModuleElementContext(node, Diagnostics.An_import_declaration_can_only_be_used_in_a_namespace_or_module)) { // If we hit an import declaration in an illegal context, just bail out to avoid cascading errors. @@ -32514,16 +32510,16 @@ namespace ts { const importClause = node.importClause; if (importClause) { if (importClause.name) { - checkImportBinding(importClause); + checkImportOrExportBinding(importClause); } if (importClause.namedBindings) { if (importClause.namedBindings.kind === SyntaxKind.NamespaceImport) { - checkImportBinding(importClause.namedBindings); + checkImportOrExportBinding(importClause.namedBindings); } else { const moduleExisted = resolveExternalModuleName(node, node.moduleSpecifier); if (moduleExisted) { - forEach(importClause.namedBindings.elements, checkImportBinding); + forEach(importClause.namedBindings.elements, checkImportOrExportBinding); } } } @@ -32539,7 +32535,7 @@ namespace ts { checkGrammarDecoratorsAndModifiers(node); if (isInternalModuleImportEqualsDeclaration(node) || checkExternalImportOrExportDeclaration(node)) { - checkImportBinding(node); + checkImportOrExportBinding(node); if (hasModifier(node, ModifierFlags.Export)) { markExportAsReferenced(node); } @@ -32582,7 +32578,7 @@ namespace ts { // export { x, y } // export { x, y } from "foo" // export * as ns from "foo" - isNamedExports(node.exportClause) ? forEach(node.exportClause.elements, checkExportSpecifier) : checkNamespaceExport(node.exportClause); + isNamedExports(node.exportClause) ? forEach(node.exportClause.elements, checkExportSpecifier) : checkImportOrExportBinding(node.exportClause); const inAmbientExternalModule = node.parent.kind === SyntaxKind.ModuleBlock && isAmbientModule(node.parent.parent); const inAmbientNamespaceDeclaration = !inAmbientExternalModule && node.parent.kind === SyntaxKind.ModuleBlock && diff --git a/src/compiler/transformers/module/module.ts b/src/compiler/transformers/module/module.ts index fb637cf9ee38c..f7edc6914bfca 100644 --- a/src/compiler/transformers/module/module.ts +++ b/src/compiler/transformers/module/module.ts @@ -1022,23 +1022,25 @@ namespace ts { else if (node.exportClause) { const statements: Statement[] = []; // export * as ns from "mod"; - statements.push( - setOriginalNode( - setTextRange( - createVariableStatement( - /*modifiers*/ undefined, - createVariableDeclarationList([ - createVariableDeclaration( - generatedName, - /*type*/ undefined, - getHelperExpressionForExport(node, createRequireCall(node)) - ) - ]) - ), - /*location*/ node.exportClause.name), - /* original */ node.exportClause.name - ) - ); + if (moduleKind !== ModuleKind.AMD) { + statements.push( + setOriginalNode( + setTextRange( + createVariableStatement( + /*modifiers*/ undefined, + createVariableDeclarationList([ + createVariableDeclaration( + generatedName, + /*type*/ undefined, + getHelperExpressionForExport(node, createRequireCall(node)) + ) + ]) + ), + /*location*/ node.exportClause.name), + /* original */ node.exportClause.name + ) + ); + } statements.push( setOriginalNode( @@ -1051,15 +1053,6 @@ namespace ts { ) ); - setOriginalNode( - setTextRange( - createExpressionStatement( - createExportStarHelper(context, moduleKind !== ModuleKind.AMD ? createRequireCall(node) : generatedName) - ), - node), - node - ); - return singleOrMany(statements); } else { diff --git a/tests/baselines/reference/exportAsNamespace1.js b/tests/baselines/reference/exportAsNamespace1.js index fe75357d95126..d9cc2b703a5ba 100644 --- a/tests/baselines/reference/exportAsNamespace1.js +++ b/tests/baselines/reference/exportAsNamespace1.js @@ -16,13 +16,20 @@ foo.ns.a; foo.ns.b; //// [0.js] -export const a = 1; -export const b = 2; +"use strict"; +exports.__esModule = true; +exports.a = 1; +exports.b = 2; //// [1.js] -export * as ns from './0'; -ns.a; -ns.b; +"use strict"; +exports.__esModule = true; +var _0_1 = require("./0"); +exports.ns = _0_1; +exports.ns.a; +exports.ns.b; //// [2.js] -import * as foo from './1'; +"use strict"; +exports.__esModule = true; +var foo = require("./1"); foo.ns.a; foo.ns.b; diff --git a/tests/baselines/reference/exportAsNamespace1_amd.js b/tests/baselines/reference/exportAsNamespace1_amd.js new file mode 100644 index 0000000000000..846340c06dbae --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace1_amd.js @@ -0,0 +1,39 @@ +//// [tests/cases/conformance/es2020/modules/exportAsNamespace1_amd.ts] //// + +//// [0.ts] +export const a = 1; +export const b = 2; + +//// [1.ts] +export * as ns from './0'; +ns.a; +ns.b; + +//// [2.ts] +import * as foo from './1' + +foo.ns.a; +foo.ns.b; + +//// [0.js] +define(["require", "exports"], function (require, exports) { + "use strict"; + exports.__esModule = true; + exports.a = 1; + exports.b = 2; +}); +//// [1.js] +define(["require", "exports", "./0"], function (require, exports, ns) { + "use strict"; + exports.__esModule = true; + exports.ns = _0_1; + exports.ns.a; + exports.ns.b; +}); +//// [2.js] +define(["require", "exports", "./1"], function (require, exports, foo) { + "use strict"; + exports.__esModule = true; + foo.ns.a; + foo.ns.b; +}); diff --git a/tests/baselines/reference/exportAsNamespace1_amd.symbols b/tests/baselines/reference/exportAsNamespace1_amd.symbols new file mode 100644 index 0000000000000..1ed5fa61afb25 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace1_amd.symbols @@ -0,0 +1,39 @@ +=== tests/cases/conformance/es2020/modules/0.ts === +export const a = 1; +>a : Symbol(a, Decl(0.ts, 0, 12)) + +export const b = 2; +>b : Symbol(b, Decl(0.ts, 1, 12)) + +=== tests/cases/conformance/es2020/modules/1.ts === +export * as ns from './0'; +>ns : Symbol(ns, Decl(1.ts, 0, 11)) + +ns.a; +>ns.a : Symbol(ns.a, Decl(0.ts, 0, 12)) +>ns : Symbol(ns, Decl(1.ts, 0, 11)) +>a : Symbol(ns.a, Decl(0.ts, 0, 12)) + +ns.b; +>ns.b : Symbol(ns.b, Decl(0.ts, 1, 12)) +>ns : Symbol(ns, Decl(1.ts, 0, 11)) +>b : Symbol(ns.b, Decl(0.ts, 1, 12)) + +=== tests/cases/conformance/es2020/modules/2.ts === +import * as foo from './1' +>foo : Symbol(foo, Decl(2.ts, 0, 6)) + +foo.ns.a; +>foo.ns.a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo : Symbol(foo, Decl(2.ts, 0, 6)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) + +foo.ns.b; +>foo.ns.b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo : Symbol(foo, Decl(2.ts, 0, 6)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) + diff --git a/tests/baselines/reference/exportAsNamespace1_amd.types b/tests/baselines/reference/exportAsNamespace1_amd.types new file mode 100644 index 0000000000000..6e3ebceb001cd --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace1_amd.types @@ -0,0 +1,41 @@ +=== tests/cases/conformance/es2020/modules/0.ts === +export const a = 1; +>a : 1 +>1 : 1 + +export const b = 2; +>b : 2 +>2 : 2 + +=== tests/cases/conformance/es2020/modules/1.ts === +export * as ns from './0'; +>ns : typeof ns + +ns.a; +>ns.a : 1 +>ns : typeof ns +>a : 1 + +ns.b; +>ns.b : 2 +>ns : typeof ns +>b : 2 + +=== tests/cases/conformance/es2020/modules/2.ts === +import * as foo from './1' +>foo : typeof foo + +foo.ns.a; +>foo.ns.a : 1 +>foo.ns : typeof foo.ns +>foo : typeof foo +>ns : typeof foo.ns +>a : 1 + +foo.ns.b; +>foo.ns.b : 2 +>foo.ns : typeof foo.ns +>foo : typeof foo +>ns : typeof foo.ns +>b : 2 + diff --git a/tests/baselines/reference/exportAsNamespace1_esnext.js b/tests/baselines/reference/exportAsNamespace1_esnext.js new file mode 100644 index 0000000000000..199b06d64a9f8 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace1_esnext.js @@ -0,0 +1,28 @@ +//// [tests/cases/conformance/es2020/modules/exportAsNamespace1_esnext.ts] //// + +//// [0.ts] +export const a = 1; +export const b = 2; + +//// [1.ts] +export * as ns from './0'; +ns.a; +ns.b; + +//// [2.ts] +import * as foo from './1' + +foo.ns.a; +foo.ns.b; + +//// [0.js] +export var a = 1; +export var b = 2; +//// [1.js] +export * as ns from './0'; +ns.a; +ns.b; +//// [2.js] +import * as foo from './1'; +foo.ns.a; +foo.ns.b; diff --git a/tests/baselines/reference/exportAsNamespace1_esnext.symbols b/tests/baselines/reference/exportAsNamespace1_esnext.symbols new file mode 100644 index 0000000000000..1ed5fa61afb25 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace1_esnext.symbols @@ -0,0 +1,39 @@ +=== tests/cases/conformance/es2020/modules/0.ts === +export const a = 1; +>a : Symbol(a, Decl(0.ts, 0, 12)) + +export const b = 2; +>b : Symbol(b, Decl(0.ts, 1, 12)) + +=== tests/cases/conformance/es2020/modules/1.ts === +export * as ns from './0'; +>ns : Symbol(ns, Decl(1.ts, 0, 11)) + +ns.a; +>ns.a : Symbol(ns.a, Decl(0.ts, 0, 12)) +>ns : Symbol(ns, Decl(1.ts, 0, 11)) +>a : Symbol(ns.a, Decl(0.ts, 0, 12)) + +ns.b; +>ns.b : Symbol(ns.b, Decl(0.ts, 1, 12)) +>ns : Symbol(ns, Decl(1.ts, 0, 11)) +>b : Symbol(ns.b, Decl(0.ts, 1, 12)) + +=== tests/cases/conformance/es2020/modules/2.ts === +import * as foo from './1' +>foo : Symbol(foo, Decl(2.ts, 0, 6)) + +foo.ns.a; +>foo.ns.a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo : Symbol(foo, Decl(2.ts, 0, 6)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) + +foo.ns.b; +>foo.ns.b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo : Symbol(foo, Decl(2.ts, 0, 6)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) + diff --git a/tests/baselines/reference/exportAsNamespace1_esnext.types b/tests/baselines/reference/exportAsNamespace1_esnext.types new file mode 100644 index 0000000000000..6e3ebceb001cd --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace1_esnext.types @@ -0,0 +1,41 @@ +=== tests/cases/conformance/es2020/modules/0.ts === +export const a = 1; +>a : 1 +>1 : 1 + +export const b = 2; +>b : 2 +>2 : 2 + +=== tests/cases/conformance/es2020/modules/1.ts === +export * as ns from './0'; +>ns : typeof ns + +ns.a; +>ns.a : 1 +>ns : typeof ns +>a : 1 + +ns.b; +>ns.b : 2 +>ns : typeof ns +>b : 2 + +=== tests/cases/conformance/es2020/modules/2.ts === +import * as foo from './1' +>foo : typeof foo + +foo.ns.a; +>foo.ns.a : 1 +>foo.ns : typeof foo.ns +>foo : typeof foo +>ns : typeof foo.ns +>a : 1 + +foo.ns.b; +>foo.ns.b : 2 +>foo.ns : typeof foo.ns +>foo : typeof foo +>ns : typeof foo.ns +>b : 2 + diff --git a/tests/baselines/reference/exportAsNamespace1_umd.js b/tests/baselines/reference/exportAsNamespace1_umd.js new file mode 100644 index 0000000000000..af235ff49dc42 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace1_umd.js @@ -0,0 +1,65 @@ +//// [tests/cases/conformance/es2020/modules/exportAsNamespace1_umd.ts] //// + +//// [0.ts] +export const a = 1; +export const b = 2; + +//// [1.ts] +export * as ns from './0'; +ns.a; +ns.b; + +//// [2.ts] +import * as foo from './1' + +foo.ns.a; +foo.ns.b; + +//// [0.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"], factory); + } +})(function (require, exports) { + "use strict"; + exports.__esModule = true; + exports.a = 1; + exports.b = 2; +}); +//// [1.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", "./0"], factory); + } +})(function (require, exports) { + "use strict"; + exports.__esModule = true; + var _0_1 = require("./0"); + exports.ns = _0_1; + exports.ns.a; + exports.ns.b; +}); +//// [2.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", "./1"], factory); + } +})(function (require, exports) { + "use strict"; + exports.__esModule = true; + var foo = require("./1"); + foo.ns.a; + foo.ns.b; +}); diff --git a/tests/baselines/reference/exportAsNamespace1_umd.symbols b/tests/baselines/reference/exportAsNamespace1_umd.symbols new file mode 100644 index 0000000000000..1ed5fa61afb25 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace1_umd.symbols @@ -0,0 +1,39 @@ +=== tests/cases/conformance/es2020/modules/0.ts === +export const a = 1; +>a : Symbol(a, Decl(0.ts, 0, 12)) + +export const b = 2; +>b : Symbol(b, Decl(0.ts, 1, 12)) + +=== tests/cases/conformance/es2020/modules/1.ts === +export * as ns from './0'; +>ns : Symbol(ns, Decl(1.ts, 0, 11)) + +ns.a; +>ns.a : Symbol(ns.a, Decl(0.ts, 0, 12)) +>ns : Symbol(ns, Decl(1.ts, 0, 11)) +>a : Symbol(ns.a, Decl(0.ts, 0, 12)) + +ns.b; +>ns.b : Symbol(ns.b, Decl(0.ts, 1, 12)) +>ns : Symbol(ns, Decl(1.ts, 0, 11)) +>b : Symbol(ns.b, Decl(0.ts, 1, 12)) + +=== tests/cases/conformance/es2020/modules/2.ts === +import * as foo from './1' +>foo : Symbol(foo, Decl(2.ts, 0, 6)) + +foo.ns.a; +>foo.ns.a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo : Symbol(foo, Decl(2.ts, 0, 6)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) + +foo.ns.b; +>foo.ns.b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo : Symbol(foo, Decl(2.ts, 0, 6)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) + diff --git a/tests/baselines/reference/exportAsNamespace1_umd.types b/tests/baselines/reference/exportAsNamespace1_umd.types new file mode 100644 index 0000000000000..6e3ebceb001cd --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace1_umd.types @@ -0,0 +1,41 @@ +=== tests/cases/conformance/es2020/modules/0.ts === +export const a = 1; +>a : 1 +>1 : 1 + +export const b = 2; +>b : 2 +>2 : 2 + +=== tests/cases/conformance/es2020/modules/1.ts === +export * as ns from './0'; +>ns : typeof ns + +ns.a; +>ns.a : 1 +>ns : typeof ns +>a : 1 + +ns.b; +>ns.b : 2 +>ns : typeof ns +>b : 2 + +=== tests/cases/conformance/es2020/modules/2.ts === +import * as foo from './1' +>foo : typeof foo + +foo.ns.a; +>foo.ns.a : 1 +>foo.ns : typeof foo.ns +>foo : typeof foo +>ns : typeof foo.ns +>a : 1 + +foo.ns.b; +>foo.ns.b : 2 +>foo.ns : typeof foo.ns +>foo : typeof foo +>ns : typeof foo.ns +>b : 2 + diff --git a/tests/cases/conformance/es2020/modules/exportAsNamespace1.ts b/tests/cases/conformance/es2020/modules/exportAsNamespace1.ts index b3af0c7543e70..63717c96fbd54 100644 --- a/tests/cases/conformance/es2020/modules/exportAsNamespace1.ts +++ b/tests/cases/conformance/es2020/modules/exportAsNamespace1.ts @@ -1,5 +1,3 @@ -// @module: esnext -// @target: esnext // @filename: 0.ts export const a = 1; export const b = 2; diff --git a/tests/cases/conformance/es2020/modules/exportAsNamespace1_amd.ts b/tests/cases/conformance/es2020/modules/exportAsNamespace1_amd.ts new file mode 100644 index 0000000000000..487240ba81a93 --- /dev/null +++ b/tests/cases/conformance/es2020/modules/exportAsNamespace1_amd.ts @@ -0,0 +1,15 @@ +// @module: amd +// @filename: 0.ts +export const a = 1; +export const b = 2; + +// @filename: 1.ts +export * as ns from './0'; +ns.a; +ns.b; + +// @filename: 2.ts +import * as foo from './1' + +foo.ns.a; +foo.ns.b; \ No newline at end of file diff --git a/tests/cases/conformance/es2020/modules/exportAsNamespace1_esnext.ts b/tests/cases/conformance/es2020/modules/exportAsNamespace1_esnext.ts new file mode 100644 index 0000000000000..4558e2201ea43 --- /dev/null +++ b/tests/cases/conformance/es2020/modules/exportAsNamespace1_esnext.ts @@ -0,0 +1,15 @@ +// @module: esnext +// @filename: 0.ts +export const a = 1; +export const b = 2; + +// @filename: 1.ts +export * as ns from './0'; +ns.a; +ns.b; + +// @filename: 2.ts +import * as foo from './1' + +foo.ns.a; +foo.ns.b; \ No newline at end of file diff --git a/tests/cases/conformance/es2020/modules/exportAsNamespace1_system.ts b/tests/cases/conformance/es2020/modules/exportAsNamespace1_system.ts new file mode 100644 index 0000000000000..0cf1c78240b4c --- /dev/null +++ b/tests/cases/conformance/es2020/modules/exportAsNamespace1_system.ts @@ -0,0 +1,15 @@ +// @module: system +// @filename: 0.ts +export const a = 1; +export const b = 2; + +// @filename: 1.ts +export * as ns from './0'; +ns.a; +ns.b; + +// @filename: 2.ts +import * as foo from './1' + +foo.ns.a; +foo.ns.b; \ No newline at end of file diff --git a/tests/cases/conformance/es2020/modules/exportAsNamespace1_umd.ts b/tests/cases/conformance/es2020/modules/exportAsNamespace1_umd.ts new file mode 100644 index 0000000000000..889933c8bff62 --- /dev/null +++ b/tests/cases/conformance/es2020/modules/exportAsNamespace1_umd.ts @@ -0,0 +1,15 @@ +// @module: umd +// @filename: 0.ts +export const a = 1; +export const b = 2; + +// @filename: 1.ts +export * as ns from './0'; +ns.a; +ns.b; + +// @filename: 2.ts +import * as foo from './1' + +foo.ns.a; +foo.ns.b; \ No newline at end of file From 8b3a5928e7c9360583eb3fc43d41f0716404e36d Mon Sep 17 00:00:00 2001 From: kingwl Date: Thu, 7 Nov 2019 04:12:40 +0800 Subject: [PATCH 08/29] fix system module --- src/compiler/transformers/module/module.ts | 28 +++-- src/compiler/transformers/module/system.ts | 100 ++++++++++++------ .../baselines/reference/exportAsNamespace1.js | 4 +- .../reference/exportAsNamespace1_amd.js | 2 +- .../reference/exportAsNamespace1_system.js | 65 ++++++++++++ .../exportAsNamespace1_system.symbols | 39 +++++++ .../reference/exportAsNamespace1_system.types | 41 +++++++ .../reference/exportAsNamespace1_umd.js | 4 +- 8 files changed, 227 insertions(+), 56 deletions(-) create mode 100644 tests/baselines/reference/exportAsNamespace1_system.js create mode 100644 tests/baselines/reference/exportAsNamespace1_system.symbols create mode 100644 tests/baselines/reference/exportAsNamespace1_system.types diff --git a/src/compiler/transformers/module/module.ts b/src/compiler/transformers/module/module.ts index f7edc6914bfca..9f49e762f8052 100644 --- a/src/compiler/transformers/module/module.ts +++ b/src/compiler/transformers/module/module.ts @@ -1024,20 +1024,15 @@ namespace ts { // export * as ns from "mod"; if (moduleKind !== ModuleKind.AMD) { statements.push( - setOriginalNode( - setTextRange( - createVariableStatement( - /*modifiers*/ undefined, - createVariableDeclarationList([ - createVariableDeclaration( - generatedName, - /*type*/ undefined, - getHelperExpressionForExport(node, createRequireCall(node)) - ) - ]) - ), - /*location*/ node.exportClause.name), - /* original */ node.exportClause.name + createVariableStatement( + /*modifiers*/ undefined, + createVariableDeclarationList([ + createVariableDeclaration( + getSynthesizedClone(node.exportClause.name), + /*type*/ undefined, + getHelperExpressionForExport(node, createRequireCall(node)) + ) + ]) ) ); } @@ -1046,10 +1041,11 @@ namespace ts { setOriginalNode( setTextRange( createExpressionStatement( - createExportExpression(node.exportClause.name, generatedName) + createExportExpression(getSynthesizedClone(node.exportClause.name), createIdentifier(idText(node.exportClause.name))) ), - node), node + ), + node ) ); diff --git a/src/compiler/transformers/module/system.ts b/src/compiler/transformers/module/system.ts index 1da8e1afec026..6282cf4818bbd 100644 --- a/src/compiler/transformers/module/system.ts +++ b/src/compiler/transformers/module/system.ts @@ -341,20 +341,30 @@ namespace ts { continue; } - if (!externalImport.exportClause || !isNamedExports(externalImport.exportClause)) { + if (!externalImport.exportClause) { // export * from ... continue; } - for (const element of externalImport.exportClause.elements) { - // write name of indirectly exported entry, i.e. 'export {x} from ...' + if (isNamedExports(externalImport.exportClause)) { + for (const element of externalImport.exportClause.elements) { + // write name of indirectly exported entry, i.e. 'export {x} from ...' + exportedNames.push( + createPropertyAssignment( + createLiteral(idText(element.name || element.propertyName)), + createTrue() + ) + ); + } + } + else { exportedNames.push( createPropertyAssignment( - createLiteral(idText(element.name || element.propertyName)), + createLiteral(idText(externalImport.exportClause.name)), createTrue() ) ); - } + } } const exportedNamesStorageRef = createUniqueName("exportedNames"); @@ -488,37 +498,52 @@ namespace ts { case SyntaxKind.ExportDeclaration: Debug.assert(importVariableName !== undefined); - if (entry.exportClause && isNamedExports(entry.exportClause)) { - // export {a, b as c} from 'foo' - // - // emit as: - // - // exports_({ - // "a": _["a"], - // "c": _["b"] - // }); - const properties: PropertyAssignment[] = []; - for (const e of entry.exportClause.elements) { - properties.push( - createPropertyAssignment( - createLiteral(idText(e.name)), - createElementAccess( - parameterName, - createLiteral(idText(e.propertyName || e.name)) + if (entry.exportClause) { + if (isNamedExports(entry.exportClause)) { + // export {a, b as c} from 'foo' + // + // emit as: + // + // exports_({ + // "a": _["a"], + // "c": _["b"] + // }); + const properties: PropertyAssignment[] = []; + for (const e of entry.exportClause.elements) { + properties.push( + createPropertyAssignment( + createLiteral(idText(e.name)), + createElementAccess( + parameterName, + createLiteral(idText(e.propertyName || e.name)) + ) + ) + ); + } + + statements.push( + createExpressionStatement( + createCall( + exportFunction, + /*typeArguments*/ undefined, + [createObjectLiteral(properties, /*multiline*/ true)] ) ) ); - } - - statements.push( - createExpressionStatement( - createCall( - exportFunction, - /*typeArguments*/ undefined, - [createObjectLiteral(properties, /*multiline*/ true)] + } else { + statements.push( + createExpressionStatement( + createCall( + exportFunction, + /*typeArguments*/ undefined, + [ + createLiteral(idText(entry.exportClause.name)), + createAssignment(importVariableName, parameterName) + ] + ) ) - ) - ); + ); + } } else { // export * from 'foo' @@ -574,9 +599,7 @@ namespace ts { return visitImportEqualsDeclaration(node); case SyntaxKind.ExportDeclaration: - // ExportDeclarations are elided as they are handled via - // `appendExportsOfDeclaration`. - return undefined; + return visitExportDeclaration(node); case SyntaxKind.ExportAssignment: return visitExportAssignment(node); @@ -609,6 +632,13 @@ namespace ts { return singleOrMany(statements); } + function visitExportDeclaration(node: ExportDeclaration): VisitResult { + if (node.exportClause && isNamespaceExport(node.exportClause)) { + hoistVariableDeclaration(getLocalNameForExternalImport(node, currentSourceFile)!); // TODO: GH#18217 + } + return undefined; + } + /** * Visits an ImportEqualsDeclaration node. * diff --git a/tests/baselines/reference/exportAsNamespace1.js b/tests/baselines/reference/exportAsNamespace1.js index d9cc2b703a5ba..dde773afda68b 100644 --- a/tests/baselines/reference/exportAsNamespace1.js +++ b/tests/baselines/reference/exportAsNamespace1.js @@ -23,8 +23,8 @@ exports.b = 2; //// [1.js] "use strict"; exports.__esModule = true; -var _0_1 = require("./0"); -exports.ns = _0_1; +var ns = require("./0"); +exports.ns = ns; exports.ns.a; exports.ns.b; //// [2.js] diff --git a/tests/baselines/reference/exportAsNamespace1_amd.js b/tests/baselines/reference/exportAsNamespace1_amd.js index 846340c06dbae..7cedfc0dbef37 100644 --- a/tests/baselines/reference/exportAsNamespace1_amd.js +++ b/tests/baselines/reference/exportAsNamespace1_amd.js @@ -26,7 +26,7 @@ define(["require", "exports"], function (require, exports) { define(["require", "exports", "./0"], function (require, exports, ns) { "use strict"; exports.__esModule = true; - exports.ns = _0_1; + exports.ns = ns; exports.ns.a; exports.ns.b; }); diff --git a/tests/baselines/reference/exportAsNamespace1_system.js b/tests/baselines/reference/exportAsNamespace1_system.js new file mode 100644 index 0000000000000..94c6aba209156 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace1_system.js @@ -0,0 +1,65 @@ +//// [tests/cases/conformance/es2020/modules/exportAsNamespace1_system.ts] //// + +//// [0.ts] +export const a = 1; +export const b = 2; + +//// [1.ts] +export * as ns from './0'; + +ns.a; +ns.b; + +//// [2.ts] +import * as foo from './1' + +foo.ns.a; +foo.ns.b; + +//// [0.js] +System.register([], function (exports_1, context_1) { + "use strict"; + var a, b; + var __moduleName = context_1 && context_1.id; + return { + setters: [], + execute: function () { + exports_1("a", a = 1); + exports_1("b", b = 2); + } + }; +}); +//// [1.js] +System.register(["./0"], function (exports_1, context_1) { + "use strict"; + var ns; + var __moduleName = context_1 && context_1.id; + return { + setters: [ + function (ns_1) { + exports_1("ns", ns = ns_1); + } + ], + execute: function () { + ns.a; + ns.b; + } + }; +}); +//// [2.js] +System.register(["./1"], function (exports_1, context_1) { + "use strict"; + var foo; + var __moduleName = context_1 && context_1.id; + return { + setters: [ + function (foo_1) { + foo = foo_1; + } + ], + execute: function () { + foo.ns.a; + foo.ns.b; + } + }; +}); diff --git a/tests/baselines/reference/exportAsNamespace1_system.symbols b/tests/baselines/reference/exportAsNamespace1_system.symbols new file mode 100644 index 0000000000000..1ed5fa61afb25 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace1_system.symbols @@ -0,0 +1,39 @@ +=== tests/cases/conformance/es2020/modules/0.ts === +export const a = 1; +>a : Symbol(a, Decl(0.ts, 0, 12)) + +export const b = 2; +>b : Symbol(b, Decl(0.ts, 1, 12)) + +=== tests/cases/conformance/es2020/modules/1.ts === +export * as ns from './0'; +>ns : Symbol(ns, Decl(1.ts, 0, 11)) + +ns.a; +>ns.a : Symbol(ns.a, Decl(0.ts, 0, 12)) +>ns : Symbol(ns, Decl(1.ts, 0, 11)) +>a : Symbol(ns.a, Decl(0.ts, 0, 12)) + +ns.b; +>ns.b : Symbol(ns.b, Decl(0.ts, 1, 12)) +>ns : Symbol(ns, Decl(1.ts, 0, 11)) +>b : Symbol(ns.b, Decl(0.ts, 1, 12)) + +=== tests/cases/conformance/es2020/modules/2.ts === +import * as foo from './1' +>foo : Symbol(foo, Decl(2.ts, 0, 6)) + +foo.ns.a; +>foo.ns.a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo : Symbol(foo, Decl(2.ts, 0, 6)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) + +foo.ns.b; +>foo.ns.b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo : Symbol(foo, Decl(2.ts, 0, 6)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) + diff --git a/tests/baselines/reference/exportAsNamespace1_system.types b/tests/baselines/reference/exportAsNamespace1_system.types new file mode 100644 index 0000000000000..6e3ebceb001cd --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace1_system.types @@ -0,0 +1,41 @@ +=== tests/cases/conformance/es2020/modules/0.ts === +export const a = 1; +>a : 1 +>1 : 1 + +export const b = 2; +>b : 2 +>2 : 2 + +=== tests/cases/conformance/es2020/modules/1.ts === +export * as ns from './0'; +>ns : typeof ns + +ns.a; +>ns.a : 1 +>ns : typeof ns +>a : 1 + +ns.b; +>ns.b : 2 +>ns : typeof ns +>b : 2 + +=== tests/cases/conformance/es2020/modules/2.ts === +import * as foo from './1' +>foo : typeof foo + +foo.ns.a; +>foo.ns.a : 1 +>foo.ns : typeof foo.ns +>foo : typeof foo +>ns : typeof foo.ns +>a : 1 + +foo.ns.b; +>foo.ns.b : 2 +>foo.ns : typeof foo.ns +>foo : typeof foo +>ns : typeof foo.ns +>b : 2 + diff --git a/tests/baselines/reference/exportAsNamespace1_umd.js b/tests/baselines/reference/exportAsNamespace1_umd.js index af235ff49dc42..f4671fc7b82b4 100644 --- a/tests/baselines/reference/exportAsNamespace1_umd.js +++ b/tests/baselines/reference/exportAsNamespace1_umd.js @@ -42,8 +42,8 @@ foo.ns.b; })(function (require, exports) { "use strict"; exports.__esModule = true; - var _0_1 = require("./0"); - exports.ns = _0_1; + var ns = require("./0"); + exports.ns = ns; exports.ns.a; exports.ns.b; }); From 8a362905eda9ca9a59d417b58b454e26ff5a216d Mon Sep 17 00:00:00 2001 From: kingwl Date: Thu, 7 Nov 2019 14:40:06 +0800 Subject: [PATCH 09/29] add more case --- .../es2020/modules/exportAsNamespace1.ts | 1 + .../es2020/modules/exportAsNamespace1_amd.ts | 1 + .../es2020/modules/exportAsNamespace1_esnext.ts | 1 + .../es2020/modules/exportAsNamespace1_system.ts | 1 + .../es2020/modules/exportAsNamespace1_umd.ts | 1 + .../es2020/modules/exportAsNamespace2.ts | 16 ++++++++++++++++ .../es2020/modules/exportAsNamespace2_amd.ts | 17 +++++++++++++++++ .../es2020/modules/exportAsNamespace2_esnext.ts | 17 +++++++++++++++++ .../es2020/modules/exportAsNamespace2_system.ts | 17 +++++++++++++++++ .../es2020/modules/exportAsNamespace2_umd.ts | 17 +++++++++++++++++ 10 files changed, 89 insertions(+) create mode 100644 tests/cases/conformance/es2020/modules/exportAsNamespace2.ts create mode 100644 tests/cases/conformance/es2020/modules/exportAsNamespace2_amd.ts create mode 100644 tests/cases/conformance/es2020/modules/exportAsNamespace2_esnext.ts create mode 100644 tests/cases/conformance/es2020/modules/exportAsNamespace2_system.ts create mode 100644 tests/cases/conformance/es2020/modules/exportAsNamespace2_umd.ts diff --git a/tests/cases/conformance/es2020/modules/exportAsNamespace1.ts b/tests/cases/conformance/es2020/modules/exportAsNamespace1.ts index 63717c96fbd54..d878d8b23a25c 100644 --- a/tests/cases/conformance/es2020/modules/exportAsNamespace1.ts +++ b/tests/cases/conformance/es2020/modules/exportAsNamespace1.ts @@ -1,4 +1,5 @@ // @filename: 0.ts +// @declaration: true export const a = 1; export const b = 2; diff --git a/tests/cases/conformance/es2020/modules/exportAsNamespace1_amd.ts b/tests/cases/conformance/es2020/modules/exportAsNamespace1_amd.ts index 487240ba81a93..9f3ae86d3146f 100644 --- a/tests/cases/conformance/es2020/modules/exportAsNamespace1_amd.ts +++ b/tests/cases/conformance/es2020/modules/exportAsNamespace1_amd.ts @@ -1,4 +1,5 @@ // @module: amd +// @declaration: true // @filename: 0.ts export const a = 1; export const b = 2; diff --git a/tests/cases/conformance/es2020/modules/exportAsNamespace1_esnext.ts b/tests/cases/conformance/es2020/modules/exportAsNamespace1_esnext.ts index 4558e2201ea43..89a81da3b3781 100644 --- a/tests/cases/conformance/es2020/modules/exportAsNamespace1_esnext.ts +++ b/tests/cases/conformance/es2020/modules/exportAsNamespace1_esnext.ts @@ -1,4 +1,5 @@ // @module: esnext +// @declaration: true // @filename: 0.ts export const a = 1; export const b = 2; diff --git a/tests/cases/conformance/es2020/modules/exportAsNamespace1_system.ts b/tests/cases/conformance/es2020/modules/exportAsNamespace1_system.ts index 0cf1c78240b4c..3b2be142e2431 100644 --- a/tests/cases/conformance/es2020/modules/exportAsNamespace1_system.ts +++ b/tests/cases/conformance/es2020/modules/exportAsNamespace1_system.ts @@ -1,4 +1,5 @@ // @module: system +// @declaration: true // @filename: 0.ts export const a = 1; export const b = 2; diff --git a/tests/cases/conformance/es2020/modules/exportAsNamespace1_umd.ts b/tests/cases/conformance/es2020/modules/exportAsNamespace1_umd.ts index 889933c8bff62..61f8556872d75 100644 --- a/tests/cases/conformance/es2020/modules/exportAsNamespace1_umd.ts +++ b/tests/cases/conformance/es2020/modules/exportAsNamespace1_umd.ts @@ -1,4 +1,5 @@ // @module: umd +// @declaration: true // @filename: 0.ts export const a = 1; export const b = 2; diff --git a/tests/cases/conformance/es2020/modules/exportAsNamespace2.ts b/tests/cases/conformance/es2020/modules/exportAsNamespace2.ts new file mode 100644 index 0000000000000..a39a88181b413 --- /dev/null +++ b/tests/cases/conformance/es2020/modules/exportAsNamespace2.ts @@ -0,0 +1,16 @@ +// @filename: 0.ts +// @declaration: true +// @esModuleInterop: true +export const a = 1; +export const b = 2; + +// @filename: 1.ts +export * as ns from './0'; +ns.a; +ns.b; + +// @filename: 2.ts +import * as foo from './1' + +foo.ns.a; +foo.ns.b; \ No newline at end of file diff --git a/tests/cases/conformance/es2020/modules/exportAsNamespace2_amd.ts b/tests/cases/conformance/es2020/modules/exportAsNamespace2_amd.ts new file mode 100644 index 0000000000000..7bf9dbd87b860 --- /dev/null +++ b/tests/cases/conformance/es2020/modules/exportAsNamespace2_amd.ts @@ -0,0 +1,17 @@ +// @module: amd +// @declaration: true +// @esModuleInterop: true +// @filename: 0.ts +export const a = 1; +export const b = 2; + +// @filename: 1.ts +export * as ns from './0'; +ns.a; +ns.b; + +// @filename: 2.ts +import * as foo from './1' + +foo.ns.a; +foo.ns.b; \ No newline at end of file diff --git a/tests/cases/conformance/es2020/modules/exportAsNamespace2_esnext.ts b/tests/cases/conformance/es2020/modules/exportAsNamespace2_esnext.ts new file mode 100644 index 0000000000000..9f8d4b7b63b41 --- /dev/null +++ b/tests/cases/conformance/es2020/modules/exportAsNamespace2_esnext.ts @@ -0,0 +1,17 @@ +// @module: esnext +// @declaration: true +// @esModuleInterop: true +// @filename: 0.ts +export const a = 1; +export const b = 2; + +// @filename: 1.ts +export * as ns from './0'; +ns.a; +ns.b; + +// @filename: 2.ts +import * as foo from './1' + +foo.ns.a; +foo.ns.b; \ No newline at end of file diff --git a/tests/cases/conformance/es2020/modules/exportAsNamespace2_system.ts b/tests/cases/conformance/es2020/modules/exportAsNamespace2_system.ts new file mode 100644 index 0000000000000..c6788455b5668 --- /dev/null +++ b/tests/cases/conformance/es2020/modules/exportAsNamespace2_system.ts @@ -0,0 +1,17 @@ +// @module: system +// @declaration: true +// @esModuleInterop: true +// @filename: 0.ts +export const a = 1; +export const b = 2; + +// @filename: 1.ts +export * as ns from './0'; +ns.a; +ns.b; + +// @filename: 2.ts +import * as foo from './1' + +foo.ns.a; +foo.ns.b; \ No newline at end of file diff --git a/tests/cases/conformance/es2020/modules/exportAsNamespace2_umd.ts b/tests/cases/conformance/es2020/modules/exportAsNamespace2_umd.ts new file mode 100644 index 0000000000000..483fa891be5d5 --- /dev/null +++ b/tests/cases/conformance/es2020/modules/exportAsNamespace2_umd.ts @@ -0,0 +1,17 @@ +// @module: umd +// @declaration: true +// @esModuleInterop: true +// @filename: 0.ts +export const a = 1; +export const b = 2; + +// @filename: 1.ts +export * as ns from './0'; +ns.a; +ns.b; + +// @filename: 2.ts +import * as foo from './1' + +foo.ns.a; +foo.ns.b; \ No newline at end of file From 2895f79084a66b47294385c5d6b0fee5b2aba7e3 Mon Sep 17 00:00:00 2001 From: kingwl Date: Thu, 7 Nov 2019 14:42:35 +0800 Subject: [PATCH 10/29] delete useless assert --- src/testRunner/parallel/host.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/testRunner/parallel/host.ts b/src/testRunner/parallel/host.ts index 89264224c13a6..0273ad7ec4e6f 100644 --- a/src/testRunner/parallel/host.ts +++ b/src/testRunner/parallel/host.ts @@ -147,7 +147,7 @@ namespace Harness.Parallel.Host { } cursor.hide(); - readline.moveCursor(process.stdout, -process.stdout.columns!, -this._lineCount); + readline.moveCursor(process.stdout, -process.stdout.columns, -this._lineCount); let lineCount = 0; const numProgressBars = this._progressBars.length; for (let i = 0; i < numProgressBars; i++) { @@ -156,7 +156,7 @@ namespace Harness.Parallel.Host { process.stdout.write(this._progressBars[i].text + os.EOL); } else { - readline.moveCursor(process.stdout, -process.stdout.columns!, +1); + readline.moveCursor(process.stdout, -process.stdout.columns, +1); } lineCount++; From 2ad4d1b954a97735f01cd679429112be8453fbae Mon Sep 17 00:00:00 2001 From: kingwl Date: Thu, 7 Nov 2019 15:01:03 +0800 Subject: [PATCH 11/29] accept baseline --- .../baselines/reference/exportAsNamespace1.js | 9 ++ .../reference/exportAsNamespace1_amd.js | 9 ++ .../reference/exportAsNamespace1_esnext.js | 9 ++ .../reference/exportAsNamespace1_system.js | 10 ++- .../reference/exportAsNamespace1_umd.js | 9 ++ .../baselines/reference/exportAsNamespace2.js | 58 ++++++++++++ .../reference/exportAsNamespace2.symbols | 39 ++++++++ .../reference/exportAsNamespace2.types | 41 +++++++++ .../reference/exportAsNamespace2_amd.js | 56 ++++++++++++ .../reference/exportAsNamespace2_amd.symbols | 39 ++++++++ .../reference/exportAsNamespace2_amd.types | 41 +++++++++ .../reference/exportAsNamespace2_esnext.js | 37 ++++++++ .../exportAsNamespace2_esnext.symbols | 39 ++++++++ .../reference/exportAsNamespace2_esnext.types | 41 +++++++++ .../reference/exportAsNamespace2_system.js | 73 +++++++++++++++ .../exportAsNamespace2_system.symbols | 39 ++++++++ .../reference/exportAsNamespace2_system.types | 41 +++++++++ .../reference/exportAsNamespace2_umd.js | 88 +++++++++++++++++++ .../reference/exportAsNamespace2_umd.symbols | 39 ++++++++ .../reference/exportAsNamespace2_umd.types | 41 +++++++++ 20 files changed, 757 insertions(+), 1 deletion(-) create mode 100644 tests/baselines/reference/exportAsNamespace2.js create mode 100644 tests/baselines/reference/exportAsNamespace2.symbols create mode 100644 tests/baselines/reference/exportAsNamespace2.types create mode 100644 tests/baselines/reference/exportAsNamespace2_amd.js create mode 100644 tests/baselines/reference/exportAsNamespace2_amd.symbols create mode 100644 tests/baselines/reference/exportAsNamespace2_amd.types create mode 100644 tests/baselines/reference/exportAsNamespace2_esnext.js create mode 100644 tests/baselines/reference/exportAsNamespace2_esnext.symbols create mode 100644 tests/baselines/reference/exportAsNamespace2_esnext.types create mode 100644 tests/baselines/reference/exportAsNamespace2_system.js create mode 100644 tests/baselines/reference/exportAsNamespace2_system.symbols create mode 100644 tests/baselines/reference/exportAsNamespace2_system.types create mode 100644 tests/baselines/reference/exportAsNamespace2_umd.js create mode 100644 tests/baselines/reference/exportAsNamespace2_umd.symbols create mode 100644 tests/baselines/reference/exportAsNamespace2_umd.types diff --git a/tests/baselines/reference/exportAsNamespace1.js b/tests/baselines/reference/exportAsNamespace1.js index dde773afda68b..45221d0c074e2 100644 --- a/tests/baselines/reference/exportAsNamespace1.js +++ b/tests/baselines/reference/exportAsNamespace1.js @@ -33,3 +33,12 @@ exports.__esModule = true; var foo = require("./1"); foo.ns.a; foo.ns.b; + + +//// [0.d.ts] +export declare const a = 1; +export declare const b = 2; +//// [1.d.ts] +export * as ns from './0'; +//// [2.d.ts] +export {}; diff --git a/tests/baselines/reference/exportAsNamespace1_amd.js b/tests/baselines/reference/exportAsNamespace1_amd.js index 7cedfc0dbef37..cb48151c6a172 100644 --- a/tests/baselines/reference/exportAsNamespace1_amd.js +++ b/tests/baselines/reference/exportAsNamespace1_amd.js @@ -37,3 +37,12 @@ define(["require", "exports", "./1"], function (require, exports, foo) { foo.ns.a; foo.ns.b; }); + + +//// [0.d.ts] +export declare const a = 1; +export declare const b = 2; +//// [1.d.ts] +export * as ns from './0'; +//// [2.d.ts] +export {}; diff --git a/tests/baselines/reference/exportAsNamespace1_esnext.js b/tests/baselines/reference/exportAsNamespace1_esnext.js index 199b06d64a9f8..e662998bb926f 100644 --- a/tests/baselines/reference/exportAsNamespace1_esnext.js +++ b/tests/baselines/reference/exportAsNamespace1_esnext.js @@ -26,3 +26,12 @@ ns.b; import * as foo from './1'; foo.ns.a; foo.ns.b; + + +//// [0.d.ts] +export declare const a = 1; +export declare const b = 2; +//// [1.d.ts] +export * as ns from './0'; +//// [2.d.ts] +export {}; diff --git a/tests/baselines/reference/exportAsNamespace1_system.js b/tests/baselines/reference/exportAsNamespace1_system.js index 94c6aba209156..a0359af5721e2 100644 --- a/tests/baselines/reference/exportAsNamespace1_system.js +++ b/tests/baselines/reference/exportAsNamespace1_system.js @@ -6,7 +6,6 @@ export const b = 2; //// [1.ts] export * as ns from './0'; - ns.a; ns.b; @@ -63,3 +62,12 @@ System.register(["./1"], function (exports_1, context_1) { } }; }); + + +//// [0.d.ts] +export declare const a = 1; +export declare const b = 2; +//// [1.d.ts] +export * as ns from './0'; +//// [2.d.ts] +export {}; diff --git a/tests/baselines/reference/exportAsNamespace1_umd.js b/tests/baselines/reference/exportAsNamespace1_umd.js index f4671fc7b82b4..7a9bf69965d98 100644 --- a/tests/baselines/reference/exportAsNamespace1_umd.js +++ b/tests/baselines/reference/exportAsNamespace1_umd.js @@ -63,3 +63,12 @@ foo.ns.b; foo.ns.a; foo.ns.b; }); + + +//// [0.d.ts] +export declare const a = 1; +export declare const b = 2; +//// [1.d.ts] +export * as ns from './0'; +//// [2.d.ts] +export {}; diff --git a/tests/baselines/reference/exportAsNamespace2.js b/tests/baselines/reference/exportAsNamespace2.js new file mode 100644 index 0000000000000..20c436764d8fd --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace2.js @@ -0,0 +1,58 @@ +//// [tests/cases/conformance/es2020/modules/exportAsNamespace2.ts] //// + +//// [0.ts] +export const a = 1; +export const b = 2; + +//// [1.ts] +export * as ns from './0'; +ns.a; +ns.b; + +//// [2.ts] +import * as foo from './1' + +foo.ns.a; +foo.ns.b; + +//// [0.js] +"use strict"; +exports.__esModule = true; +exports.a = 1; +exports.b = 2; +//// [1.js] +"use strict"; +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; + result["default"] = mod; + return result; +}; +exports.__esModule = true; +var ns = __importStar(require("./0")); +exports.ns = ns; +exports.ns.a; +exports.ns.b; +//// [2.js] +"use strict"; +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; + result["default"] = mod; + return result; +}; +exports.__esModule = true; +var foo = __importStar(require("./1")); +foo.ns.a; +foo.ns.b; + + +//// [0.d.ts] +export declare const a = 1; +export declare const b = 2; +//// [1.d.ts] +export * as ns from './0'; +//// [2.d.ts] +export {}; diff --git a/tests/baselines/reference/exportAsNamespace2.symbols b/tests/baselines/reference/exportAsNamespace2.symbols new file mode 100644 index 0000000000000..1ed5fa61afb25 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace2.symbols @@ -0,0 +1,39 @@ +=== tests/cases/conformance/es2020/modules/0.ts === +export const a = 1; +>a : Symbol(a, Decl(0.ts, 0, 12)) + +export const b = 2; +>b : Symbol(b, Decl(0.ts, 1, 12)) + +=== tests/cases/conformance/es2020/modules/1.ts === +export * as ns from './0'; +>ns : Symbol(ns, Decl(1.ts, 0, 11)) + +ns.a; +>ns.a : Symbol(ns.a, Decl(0.ts, 0, 12)) +>ns : Symbol(ns, Decl(1.ts, 0, 11)) +>a : Symbol(ns.a, Decl(0.ts, 0, 12)) + +ns.b; +>ns.b : Symbol(ns.b, Decl(0.ts, 1, 12)) +>ns : Symbol(ns, Decl(1.ts, 0, 11)) +>b : Symbol(ns.b, Decl(0.ts, 1, 12)) + +=== tests/cases/conformance/es2020/modules/2.ts === +import * as foo from './1' +>foo : Symbol(foo, Decl(2.ts, 0, 6)) + +foo.ns.a; +>foo.ns.a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo : Symbol(foo, Decl(2.ts, 0, 6)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) + +foo.ns.b; +>foo.ns.b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo : Symbol(foo, Decl(2.ts, 0, 6)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) + diff --git a/tests/baselines/reference/exportAsNamespace2.types b/tests/baselines/reference/exportAsNamespace2.types new file mode 100644 index 0000000000000..6e3ebceb001cd --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace2.types @@ -0,0 +1,41 @@ +=== tests/cases/conformance/es2020/modules/0.ts === +export const a = 1; +>a : 1 +>1 : 1 + +export const b = 2; +>b : 2 +>2 : 2 + +=== tests/cases/conformance/es2020/modules/1.ts === +export * as ns from './0'; +>ns : typeof ns + +ns.a; +>ns.a : 1 +>ns : typeof ns +>a : 1 + +ns.b; +>ns.b : 2 +>ns : typeof ns +>b : 2 + +=== tests/cases/conformance/es2020/modules/2.ts === +import * as foo from './1' +>foo : typeof foo + +foo.ns.a; +>foo.ns.a : 1 +>foo.ns : typeof foo.ns +>foo : typeof foo +>ns : typeof foo.ns +>a : 1 + +foo.ns.b; +>foo.ns.b : 2 +>foo.ns : typeof foo.ns +>foo : typeof foo +>ns : typeof foo.ns +>b : 2 + diff --git a/tests/baselines/reference/exportAsNamespace2_amd.js b/tests/baselines/reference/exportAsNamespace2_amd.js new file mode 100644 index 0000000000000..56c592c1d593e --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace2_amd.js @@ -0,0 +1,56 @@ +//// [tests/cases/conformance/es2020/modules/exportAsNamespace2_amd.ts] //// + +//// [0.ts] +export const a = 1; +export const b = 2; + +//// [1.ts] +export * as ns from './0'; +ns.a; +ns.b; + +//// [2.ts] +import * as foo from './1' + +foo.ns.a; +foo.ns.b; + +//// [0.js] +define(["require", "exports"], function (require, exports) { + "use strict"; + exports.__esModule = true; + exports.a = 1; + exports.b = 2; +}); +//// [1.js] +define(["require", "exports", "./0"], function (require, exports, ns) { + "use strict"; + exports.__esModule = true; + exports.ns = ns; + exports.ns.a; + exports.ns.b; +}); +//// [2.js] +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; + result["default"] = mod; + return result; +}; +define(["require", "exports", "./1"], function (require, exports, foo) { + "use strict"; + exports.__esModule = true; + foo = __importStar(foo); + foo.ns.a; + foo.ns.b; +}); + + +//// [0.d.ts] +export declare const a = 1; +export declare const b = 2; +//// [1.d.ts] +export * as ns from './0'; +//// [2.d.ts] +export {}; diff --git a/tests/baselines/reference/exportAsNamespace2_amd.symbols b/tests/baselines/reference/exportAsNamespace2_amd.symbols new file mode 100644 index 0000000000000..1ed5fa61afb25 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace2_amd.symbols @@ -0,0 +1,39 @@ +=== tests/cases/conformance/es2020/modules/0.ts === +export const a = 1; +>a : Symbol(a, Decl(0.ts, 0, 12)) + +export const b = 2; +>b : Symbol(b, Decl(0.ts, 1, 12)) + +=== tests/cases/conformance/es2020/modules/1.ts === +export * as ns from './0'; +>ns : Symbol(ns, Decl(1.ts, 0, 11)) + +ns.a; +>ns.a : Symbol(ns.a, Decl(0.ts, 0, 12)) +>ns : Symbol(ns, Decl(1.ts, 0, 11)) +>a : Symbol(ns.a, Decl(0.ts, 0, 12)) + +ns.b; +>ns.b : Symbol(ns.b, Decl(0.ts, 1, 12)) +>ns : Symbol(ns, Decl(1.ts, 0, 11)) +>b : Symbol(ns.b, Decl(0.ts, 1, 12)) + +=== tests/cases/conformance/es2020/modules/2.ts === +import * as foo from './1' +>foo : Symbol(foo, Decl(2.ts, 0, 6)) + +foo.ns.a; +>foo.ns.a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo : Symbol(foo, Decl(2.ts, 0, 6)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) + +foo.ns.b; +>foo.ns.b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo : Symbol(foo, Decl(2.ts, 0, 6)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) + diff --git a/tests/baselines/reference/exportAsNamespace2_amd.types b/tests/baselines/reference/exportAsNamespace2_amd.types new file mode 100644 index 0000000000000..6e3ebceb001cd --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace2_amd.types @@ -0,0 +1,41 @@ +=== tests/cases/conformance/es2020/modules/0.ts === +export const a = 1; +>a : 1 +>1 : 1 + +export const b = 2; +>b : 2 +>2 : 2 + +=== tests/cases/conformance/es2020/modules/1.ts === +export * as ns from './0'; +>ns : typeof ns + +ns.a; +>ns.a : 1 +>ns : typeof ns +>a : 1 + +ns.b; +>ns.b : 2 +>ns : typeof ns +>b : 2 + +=== tests/cases/conformance/es2020/modules/2.ts === +import * as foo from './1' +>foo : typeof foo + +foo.ns.a; +>foo.ns.a : 1 +>foo.ns : typeof foo.ns +>foo : typeof foo +>ns : typeof foo.ns +>a : 1 + +foo.ns.b; +>foo.ns.b : 2 +>foo.ns : typeof foo.ns +>foo : typeof foo +>ns : typeof foo.ns +>b : 2 + diff --git a/tests/baselines/reference/exportAsNamespace2_esnext.js b/tests/baselines/reference/exportAsNamespace2_esnext.js new file mode 100644 index 0000000000000..e9c6bd1a20377 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace2_esnext.js @@ -0,0 +1,37 @@ +//// [tests/cases/conformance/es2020/modules/exportAsNamespace2_esnext.ts] //// + +//// [0.ts] +export const a = 1; +export const b = 2; + +//// [1.ts] +export * as ns from './0'; +ns.a; +ns.b; + +//// [2.ts] +import * as foo from './1' + +foo.ns.a; +foo.ns.b; + +//// [0.js] +export var a = 1; +export var b = 2; +//// [1.js] +export * as ns from './0'; +ns.a; +ns.b; +//// [2.js] +import * as foo from './1'; +foo.ns.a; +foo.ns.b; + + +//// [0.d.ts] +export declare const a = 1; +export declare const b = 2; +//// [1.d.ts] +export * as ns from './0'; +//// [2.d.ts] +export {}; diff --git a/tests/baselines/reference/exportAsNamespace2_esnext.symbols b/tests/baselines/reference/exportAsNamespace2_esnext.symbols new file mode 100644 index 0000000000000..1ed5fa61afb25 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace2_esnext.symbols @@ -0,0 +1,39 @@ +=== tests/cases/conformance/es2020/modules/0.ts === +export const a = 1; +>a : Symbol(a, Decl(0.ts, 0, 12)) + +export const b = 2; +>b : Symbol(b, Decl(0.ts, 1, 12)) + +=== tests/cases/conformance/es2020/modules/1.ts === +export * as ns from './0'; +>ns : Symbol(ns, Decl(1.ts, 0, 11)) + +ns.a; +>ns.a : Symbol(ns.a, Decl(0.ts, 0, 12)) +>ns : Symbol(ns, Decl(1.ts, 0, 11)) +>a : Symbol(ns.a, Decl(0.ts, 0, 12)) + +ns.b; +>ns.b : Symbol(ns.b, Decl(0.ts, 1, 12)) +>ns : Symbol(ns, Decl(1.ts, 0, 11)) +>b : Symbol(ns.b, Decl(0.ts, 1, 12)) + +=== tests/cases/conformance/es2020/modules/2.ts === +import * as foo from './1' +>foo : Symbol(foo, Decl(2.ts, 0, 6)) + +foo.ns.a; +>foo.ns.a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo : Symbol(foo, Decl(2.ts, 0, 6)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) + +foo.ns.b; +>foo.ns.b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo : Symbol(foo, Decl(2.ts, 0, 6)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) + diff --git a/tests/baselines/reference/exportAsNamespace2_esnext.types b/tests/baselines/reference/exportAsNamespace2_esnext.types new file mode 100644 index 0000000000000..6e3ebceb001cd --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace2_esnext.types @@ -0,0 +1,41 @@ +=== tests/cases/conformance/es2020/modules/0.ts === +export const a = 1; +>a : 1 +>1 : 1 + +export const b = 2; +>b : 2 +>2 : 2 + +=== tests/cases/conformance/es2020/modules/1.ts === +export * as ns from './0'; +>ns : typeof ns + +ns.a; +>ns.a : 1 +>ns : typeof ns +>a : 1 + +ns.b; +>ns.b : 2 +>ns : typeof ns +>b : 2 + +=== tests/cases/conformance/es2020/modules/2.ts === +import * as foo from './1' +>foo : typeof foo + +foo.ns.a; +>foo.ns.a : 1 +>foo.ns : typeof foo.ns +>foo : typeof foo +>ns : typeof foo.ns +>a : 1 + +foo.ns.b; +>foo.ns.b : 2 +>foo.ns : typeof foo.ns +>foo : typeof foo +>ns : typeof foo.ns +>b : 2 + diff --git a/tests/baselines/reference/exportAsNamespace2_system.js b/tests/baselines/reference/exportAsNamespace2_system.js new file mode 100644 index 0000000000000..1f54350eac0ba --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace2_system.js @@ -0,0 +1,73 @@ +//// [tests/cases/conformance/es2020/modules/exportAsNamespace2_system.ts] //// + +//// [0.ts] +export const a = 1; +export const b = 2; + +//// [1.ts] +export * as ns from './0'; +ns.a; +ns.b; + +//// [2.ts] +import * as foo from './1' + +foo.ns.a; +foo.ns.b; + +//// [0.js] +System.register([], function (exports_1, context_1) { + "use strict"; + var a, b; + var __moduleName = context_1 && context_1.id; + return { + setters: [], + execute: function () { + exports_1("a", a = 1); + exports_1("b", b = 2); + } + }; +}); +//// [1.js] +System.register(["./0"], function (exports_1, context_1) { + "use strict"; + var ns; + var __moduleName = context_1 && context_1.id; + return { + setters: [ + function (ns_1) { + exports_1("ns", ns = ns_1); + } + ], + execute: function () { + ns.a; + ns.b; + } + }; +}); +//// [2.js] +System.register(["./1"], function (exports_1, context_1) { + "use strict"; + var foo; + var __moduleName = context_1 && context_1.id; + return { + setters: [ + function (foo_1) { + foo = foo_1; + } + ], + execute: function () { + foo.ns.a; + foo.ns.b; + } + }; +}); + + +//// [0.d.ts] +export declare const a = 1; +export declare const b = 2; +//// [1.d.ts] +export * as ns from './0'; +//// [2.d.ts] +export {}; diff --git a/tests/baselines/reference/exportAsNamespace2_system.symbols b/tests/baselines/reference/exportAsNamespace2_system.symbols new file mode 100644 index 0000000000000..1ed5fa61afb25 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace2_system.symbols @@ -0,0 +1,39 @@ +=== tests/cases/conformance/es2020/modules/0.ts === +export const a = 1; +>a : Symbol(a, Decl(0.ts, 0, 12)) + +export const b = 2; +>b : Symbol(b, Decl(0.ts, 1, 12)) + +=== tests/cases/conformance/es2020/modules/1.ts === +export * as ns from './0'; +>ns : Symbol(ns, Decl(1.ts, 0, 11)) + +ns.a; +>ns.a : Symbol(ns.a, Decl(0.ts, 0, 12)) +>ns : Symbol(ns, Decl(1.ts, 0, 11)) +>a : Symbol(ns.a, Decl(0.ts, 0, 12)) + +ns.b; +>ns.b : Symbol(ns.b, Decl(0.ts, 1, 12)) +>ns : Symbol(ns, Decl(1.ts, 0, 11)) +>b : Symbol(ns.b, Decl(0.ts, 1, 12)) + +=== tests/cases/conformance/es2020/modules/2.ts === +import * as foo from './1' +>foo : Symbol(foo, Decl(2.ts, 0, 6)) + +foo.ns.a; +>foo.ns.a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo : Symbol(foo, Decl(2.ts, 0, 6)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) + +foo.ns.b; +>foo.ns.b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo : Symbol(foo, Decl(2.ts, 0, 6)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) + diff --git a/tests/baselines/reference/exportAsNamespace2_system.types b/tests/baselines/reference/exportAsNamespace2_system.types new file mode 100644 index 0000000000000..6e3ebceb001cd --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace2_system.types @@ -0,0 +1,41 @@ +=== tests/cases/conformance/es2020/modules/0.ts === +export const a = 1; +>a : 1 +>1 : 1 + +export const b = 2; +>b : 2 +>2 : 2 + +=== tests/cases/conformance/es2020/modules/1.ts === +export * as ns from './0'; +>ns : typeof ns + +ns.a; +>ns.a : 1 +>ns : typeof ns +>a : 1 + +ns.b; +>ns.b : 2 +>ns : typeof ns +>b : 2 + +=== tests/cases/conformance/es2020/modules/2.ts === +import * as foo from './1' +>foo : typeof foo + +foo.ns.a; +>foo.ns.a : 1 +>foo.ns : typeof foo.ns +>foo : typeof foo +>ns : typeof foo.ns +>a : 1 + +foo.ns.b; +>foo.ns.b : 2 +>foo.ns : typeof foo.ns +>foo : typeof foo +>ns : typeof foo.ns +>b : 2 + diff --git a/tests/baselines/reference/exportAsNamespace2_umd.js b/tests/baselines/reference/exportAsNamespace2_umd.js new file mode 100644 index 0000000000000..81f5b7b8851e0 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace2_umd.js @@ -0,0 +1,88 @@ +//// [tests/cases/conformance/es2020/modules/exportAsNamespace2_umd.ts] //// + +//// [0.ts] +export const a = 1; +export const b = 2; + +//// [1.ts] +export * as ns from './0'; +ns.a; +ns.b; + +//// [2.ts] +import * as foo from './1' + +foo.ns.a; +foo.ns.b; + +//// [0.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"], factory); + } +})(function (require, exports) { + "use strict"; + exports.__esModule = true; + exports.a = 1; + exports.b = 2; +}); +//// [1.js] +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; + result["default"] = mod; + return result; +}; +(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", "./0"], factory); + } +})(function (require, exports) { + "use strict"; + exports.__esModule = true; + var ns = __importStar(require("./0")); + exports.ns = ns; + exports.ns.a; + exports.ns.b; +}); +//// [2.js] +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; + result["default"] = mod; + return result; +}; +(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", "./1"], factory); + } +})(function (require, exports) { + "use strict"; + exports.__esModule = true; + var foo = __importStar(require("./1")); + foo.ns.a; + foo.ns.b; +}); + + +//// [0.d.ts] +export declare const a = 1; +export declare const b = 2; +//// [1.d.ts] +export * as ns from './0'; +//// [2.d.ts] +export {}; diff --git a/tests/baselines/reference/exportAsNamespace2_umd.symbols b/tests/baselines/reference/exportAsNamespace2_umd.symbols new file mode 100644 index 0000000000000..1ed5fa61afb25 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace2_umd.symbols @@ -0,0 +1,39 @@ +=== tests/cases/conformance/es2020/modules/0.ts === +export const a = 1; +>a : Symbol(a, Decl(0.ts, 0, 12)) + +export const b = 2; +>b : Symbol(b, Decl(0.ts, 1, 12)) + +=== tests/cases/conformance/es2020/modules/1.ts === +export * as ns from './0'; +>ns : Symbol(ns, Decl(1.ts, 0, 11)) + +ns.a; +>ns.a : Symbol(ns.a, Decl(0.ts, 0, 12)) +>ns : Symbol(ns, Decl(1.ts, 0, 11)) +>a : Symbol(ns.a, Decl(0.ts, 0, 12)) + +ns.b; +>ns.b : Symbol(ns.b, Decl(0.ts, 1, 12)) +>ns : Symbol(ns, Decl(1.ts, 0, 11)) +>b : Symbol(ns.b, Decl(0.ts, 1, 12)) + +=== tests/cases/conformance/es2020/modules/2.ts === +import * as foo from './1' +>foo : Symbol(foo, Decl(2.ts, 0, 6)) + +foo.ns.a; +>foo.ns.a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo : Symbol(foo, Decl(2.ts, 0, 6)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) + +foo.ns.b; +>foo.ns.b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo : Symbol(foo, Decl(2.ts, 0, 6)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) + diff --git a/tests/baselines/reference/exportAsNamespace2_umd.types b/tests/baselines/reference/exportAsNamespace2_umd.types new file mode 100644 index 0000000000000..6e3ebceb001cd --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace2_umd.types @@ -0,0 +1,41 @@ +=== tests/cases/conformance/es2020/modules/0.ts === +export const a = 1; +>a : 1 +>1 : 1 + +export const b = 2; +>b : 2 +>2 : 2 + +=== tests/cases/conformance/es2020/modules/1.ts === +export * as ns from './0'; +>ns : typeof ns + +ns.a; +>ns.a : 1 +>ns : typeof ns +>a : 1 + +ns.b; +>ns.b : 2 +>ns : typeof ns +>b : 2 + +=== tests/cases/conformance/es2020/modules/2.ts === +import * as foo from './1' +>foo : typeof foo + +foo.ns.a; +>foo.ns.a : 1 +>foo.ns : typeof foo.ns +>foo : typeof foo +>ns : typeof foo.ns +>a : 1 + +foo.ns.b; +>foo.ns.b : 2 +>foo.ns : typeof foo.ns +>foo : typeof foo +>ns : typeof foo.ns +>b : 2 + From 33ae59276b3ea14cc9b3a8aa4bbc18cb36229a82 Mon Sep 17 00:00:00 2001 From: kingwl Date: Thu, 7 Nov 2019 15:02:41 +0800 Subject: [PATCH 12/29] make lint happy --- src/compiler/transformers/module/module.ts | 2 +- src/compiler/transformers/module/system.ts | 5 +++-- src/services/importTracker.ts | 4 +++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/compiler/transformers/module/module.ts b/src/compiler/transformers/module/module.ts index 9f49e762f8052..80c6ef391253d 100644 --- a/src/compiler/transformers/module/module.ts +++ b/src/compiler/transformers/module/module.ts @@ -1034,7 +1034,7 @@ namespace ts { ) ]) ) - ); + ); } statements.push( diff --git a/src/compiler/transformers/module/system.ts b/src/compiler/transformers/module/system.ts index 6282cf4818bbd..b92553c4f9076 100644 --- a/src/compiler/transformers/module/system.ts +++ b/src/compiler/transformers/module/system.ts @@ -364,7 +364,7 @@ namespace ts { createTrue() ) ); - } + } } const exportedNamesStorageRef = createUniqueName("exportedNames"); @@ -530,7 +530,8 @@ namespace ts { ) ) ); - } else { + } + else { statements.push( createExpressionStatement( createCall( diff --git a/src/services/importTracker.ts b/src/services/importTracker.ts index 165470e02d93e..a8401245c5ea5 100644 --- a/src/services/importTracker.ts +++ b/src/services/importTracker.ts @@ -237,7 +237,9 @@ namespace ts.FindAllReferences { } if (decl.kind === SyntaxKind.ExportDeclaration) { - decl.exportClause && isNamedExports(decl.exportClause) && searchForNamedImport(decl.exportClause); + if (decl.exportClause && isNamedExports(decl.exportClause)) { + searchForNamedImport(decl.exportClause); + } return; } From fb4ae008ec5b98373ff62de28faf41a8563cf047 Mon Sep 17 00:00:00 2001 From: kingwl Date: Thu, 12 Dec 2019 00:01:46 +0800 Subject: [PATCH 13/29] fix missing utils --- src/compiler/utilitiesPublic.ts | 1 + src/compiler/visitor.ts | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/src/compiler/utilitiesPublic.ts b/src/compiler/utilitiesPublic.ts index 209033156d2bd..0a360cd05a748 100644 --- a/src/compiler/utilitiesPublic.ts +++ b/src/compiler/utilitiesPublic.ts @@ -2231,6 +2231,7 @@ namespace ts { || kind === SyntaxKind.ModuleDeclaration || kind === SyntaxKind.NamespaceExportDeclaration || kind === SyntaxKind.NamespaceImport + || kind === SyntaxKind.NamespaceExport || kind === SyntaxKind.Parameter || kind === SyntaxKind.PropertyAssignment || kind === SyntaxKind.PropertyDeclaration diff --git a/src/compiler/visitor.ts b/src/compiler/visitor.ts index cbbd3c1924131..54ea4ea060a3f 100644 --- a/src/compiler/visitor.ts +++ b/src/compiler/visitor.ts @@ -386,6 +386,10 @@ namespace ts { result = reduceNode((node).name, cbNode, result); break; + case SyntaxKind.NamespaceExport: + result = reduceNode((node).name, cbNode, result); + break; + case SyntaxKind.NamedImports: case SyntaxKind.NamedExports: result = reduceNodes((node).elements, cbNodes, result); From c0d870557fe6168e7f804f6b86b0665f26937594 Mon Sep 17 00:00:00 2001 From: kingwl Date: Thu, 12 Dec 2019 01:37:49 +0800 Subject: [PATCH 14/29] update api --- tests/baselines/reference/api/tsserverlibrary.d.ts | 4 ++-- tests/baselines/reference/api/typescript.d.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index 20bc0fff56118..1a135cbd9e176 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -4101,8 +4101,6 @@ declare namespace ts { function updateCaseBlock(node: CaseBlock, clauses: readonly CaseOrDefaultClause[]): CaseBlock; function createNamespaceExportDeclaration(name: string | Identifier): NamespaceExportDeclaration; function updateNamespaceExportDeclaration(node: NamespaceExportDeclaration, name: Identifier): NamespaceExportDeclaration; - function createNamespaceExport(name: string | Identifier): NamespaceExport; - function updateNamespaceExport(node: NamespaceExport, name: Identifier): NamespaceExport; function createImportEqualsDeclaration(decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, name: string | Identifier, moduleReference: ModuleReference): ImportEqualsDeclaration; function updateImportEqualsDeclaration(node: ImportEqualsDeclaration, decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, name: Identifier, moduleReference: ModuleReference): ImportEqualsDeclaration; function createImportDeclaration(decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, importClause: ImportClause | undefined, moduleSpecifier: Expression): ImportDeclaration; @@ -4110,7 +4108,9 @@ declare namespace ts { function createImportClause(name: Identifier | undefined, namedBindings: NamedImportBindings | undefined): ImportClause; function updateImportClause(node: ImportClause, name: Identifier | undefined, namedBindings: NamedImportBindings | undefined): ImportClause; function createNamespaceImport(name: Identifier): NamespaceImport; + function createNamespaceExport(name: Identifier): NamespaceExport; function updateNamespaceImport(node: NamespaceImport, name: Identifier): NamespaceImport; + function updateNamespaceExport(node: NamespaceExport, name: Identifier): NamespaceExport; function createNamedImports(elements: readonly ImportSpecifier[]): NamedImports; function updateNamedImports(node: NamedImports, elements: readonly ImportSpecifier[]): NamedImports; function createImportSpecifier(propertyName: Identifier | undefined, name: Identifier): ImportSpecifier; diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index edb83d13bea53..9f85792909448 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -4101,8 +4101,6 @@ declare namespace ts { function updateCaseBlock(node: CaseBlock, clauses: readonly CaseOrDefaultClause[]): CaseBlock; function createNamespaceExportDeclaration(name: string | Identifier): NamespaceExportDeclaration; function updateNamespaceExportDeclaration(node: NamespaceExportDeclaration, name: Identifier): NamespaceExportDeclaration; - function createNamespaceExport(name: string | Identifier): NamespaceExport; - function updateNamespaceExport(node: NamespaceExport, name: Identifier): NamespaceExport; function createImportEqualsDeclaration(decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, name: string | Identifier, moduleReference: ModuleReference): ImportEqualsDeclaration; function updateImportEqualsDeclaration(node: ImportEqualsDeclaration, decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, name: Identifier, moduleReference: ModuleReference): ImportEqualsDeclaration; function createImportDeclaration(decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, importClause: ImportClause | undefined, moduleSpecifier: Expression): ImportDeclaration; @@ -4110,7 +4108,9 @@ declare namespace ts { function createImportClause(name: Identifier | undefined, namedBindings: NamedImportBindings | undefined): ImportClause; function updateImportClause(node: ImportClause, name: Identifier | undefined, namedBindings: NamedImportBindings | undefined): ImportClause; function createNamespaceImport(name: Identifier): NamespaceImport; + function createNamespaceExport(name: Identifier): NamespaceExport; function updateNamespaceImport(node: NamespaceImport, name: Identifier): NamespaceImport; + function updateNamespaceExport(node: NamespaceExport, name: Identifier): NamespaceExport; function createNamedImports(elements: readonly ImportSpecifier[]): NamedImports; function updateNamedImports(node: NamedImports, elements: readonly ImportSpecifier[]): NamedImports; function createImportSpecifier(propertyName: Identifier | undefined, name: Identifier): ImportSpecifier; From 584cd5b72ba72567f4db2d78c0f1115e897cf21f Mon Sep 17 00:00:00 2001 From: kingwl Date: Thu, 12 Dec 2019 12:54:28 +0800 Subject: [PATCH 15/29] make lint happy --- src/testRunner/parallel/host.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/testRunner/parallel/host.ts b/src/testRunner/parallel/host.ts index d25357ebea76f..bb4b31b9f058d 100644 --- a/src/testRunner/parallel/host.ts +++ b/src/testRunner/parallel/host.ts @@ -147,7 +147,7 @@ namespace Harness.Parallel.Host { } cursor.hide(); - readline.moveCursor(process.stdout, -process.stdout.columns!, -this._lineCount); + readline.moveCursor(process.stdout, -process.stdout.columns, -this._lineCount); let lineCount = 0; const numProgressBars = this._progressBars.length; for (let i = 0; i < numProgressBars; i++) { @@ -156,7 +156,7 @@ namespace Harness.Parallel.Host { process.stdout.write(this._progressBars[i].text + os.EOL); } else { - readline.moveCursor(process.stdout, -process.stdout.columns!, +1); + readline.moveCursor(process.stdout, -process.stdout.columns, +1); } lineCount++; From 2667ceefe67f81eae369b7d3a3488f6eb848f89a Mon Sep 17 00:00:00 2001 From: kingwl Date: Thu, 12 Dec 2019 13:35:06 +0800 Subject: [PATCH 16/29] add missing semi --- src/compiler/factoryPublic.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/factoryPublic.ts b/src/compiler/factoryPublic.ts index 7ec373ab54d14..a5a99d179db7a 100644 --- a/src/compiler/factoryPublic.ts +++ b/src/compiler/factoryPublic.ts @@ -2293,7 +2293,7 @@ namespace ts { export function updateNamespaceExport(node: NamespaceExport, name: Identifier) { return node.name !== name ? updateNode(createNamespaceExport(name), node) - :node + : node; } export function createNamedImports(elements: readonly ImportSpecifier[]): NamedImports { From 7582e25eefbb757bca55ca76ca3c0aa308f38e63 Mon Sep 17 00:00:00 2001 From: kingwl Date: Fri, 20 Dec 2019 15:11:45 +0800 Subject: [PATCH 17/29] fix minor issue --- src/compiler/binder.ts | 2 +- src/compiler/checker.ts | 2 -- src/compiler/utilities.ts | 1 + src/compiler/utilitiesPublic.ts | 4 ++++ src/compiler/visitorPublic.ts | 2 +- src/services/organizeImports.ts | 2 +- 6 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index d8fea05a34308..0b19d7806ff07 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -56,7 +56,7 @@ namespace ts { break; // 4. Export alias declarations pointing at only uninstantiated modules or things uninstantiated modules contain case SyntaxKind.ExportDeclaration: - const exportDeclaration = (node as ExportDeclaration); + const exportDeclaration = node as ExportDeclaration; if (!exportDeclaration.moduleSpecifier && exportDeclaration.exportClause && exportDeclaration.exportClause.kind === SyntaxKind.NamedExports) { let state = ModuleInstanceState.NonInstantiated; for (const specifier of exportDeclaration.exportClause.elements) { diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 58398767196d3..add0b56a0e966 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -6638,7 +6638,6 @@ namespace ts { case SyntaxKind.ImportSpecifier: case SyntaxKind.NamedImports: case SyntaxKind.NamespaceImport: - case SyntaxKind.NamespaceExport: case SyntaxKind.ImportClause: return false; default: @@ -36351,7 +36350,6 @@ namespace ts { case SyntaxKind.ImportClause: // For default import case SyntaxKind.ImportEqualsDeclaration: case SyntaxKind.NamespaceImport: - case SyntaxKind.NamespaceExport: case SyntaxKind.ImportSpecifier: // For rename import `x as y` return true; case SyntaxKind.Identifier: diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 90d0aa36ba826..8cc46bd8df4ac 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -2681,6 +2681,7 @@ namespace ts { // import * as from ... // import { x as } from ... // export { x as } from ... + // export * as ns from ... // export = // export default // module.exports = diff --git a/src/compiler/utilitiesPublic.ts b/src/compiler/utilitiesPublic.ts index 7514da2b981ce..b15356e740d50 100644 --- a/src/compiler/utilitiesPublic.ts +++ b/src/compiler/utilitiesPublic.ts @@ -1365,6 +1365,10 @@ namespace ts { return node.kind === SyntaxKind.NamespaceExport; } + export function isNamedExportBindings(node: Node): node is NamedExportBindings { + return node.kind === SyntaxKind.NamespaceExport || node.kind === SyntaxKind.NamedExports; + } + export function isNamedImports(node: Node): node is NamedImports { return node.kind === SyntaxKind.NamedImports; } diff --git a/src/compiler/visitorPublic.ts b/src/compiler/visitorPublic.ts index 6274be4b31e4e..c48b27bdce01c 100644 --- a/src/compiler/visitorPublic.ts +++ b/src/compiler/visitorPublic.ts @@ -821,7 +821,7 @@ namespace ts { return updateExportDeclaration(node, nodesVisitor((node).decorators, visitor, isDecorator), nodesVisitor((node).modifiers, visitor, isModifier), - visitNode((node).exportClause, visitor, isNamedExports), + visitNode((node).exportClause, visitor, isNamedExportBindings), visitNode((node).moduleSpecifier, visitor, isExpression)); case SyntaxKind.NamedExports: diff --git a/src/services/organizeImports.ts b/src/services/organizeImports.ts index f3e89219febd6..232f2c1ba9509 100644 --- a/src/services/organizeImports.ts +++ b/src/services/organizeImports.ts @@ -307,7 +307,7 @@ namespace ts.OrganizeImports { } const newExportSpecifiers: ExportSpecifier[] = []; - newExportSpecifiers.push(...flatMap(namedExports, i => i.exportClause && isNamedExports(i.exportClause) ? i.exportClause.elements : [])); + newExportSpecifiers.push(...flatMap(namedExports, i => i.exportClause && isNamedExports(i.exportClause) ? i.exportClause.elements : emptyArray)); const sortedExportSpecifiers = sortSpecifiers(newExportSpecifiers); From ee4b1f08fe9c434642bef9b958fc239262e73e02 Mon Sep 17 00:00:00 2001 From: kingwl Date: Sat, 21 Dec 2019 00:23:33 +0800 Subject: [PATCH 18/29] fix locally bound --- src/compiler/checker.ts | 2 +- .../reference/exportAsNamespace1.errors.txt | 22 +++++++++++++++++++ .../baselines/reference/exportAsNamespace1.js | 4 ++-- .../reference/exportAsNamespace1.symbols | 7 ------ .../reference/exportAsNamespace1.types | 12 +++++----- .../exportAsNamespace1_amd.errors.txt | 22 +++++++++++++++++++ .../reference/exportAsNamespace1_amd.js | 4 ++-- .../reference/exportAsNamespace1_amd.symbols | 7 ------ .../reference/exportAsNamespace1_amd.types | 12 +++++----- .../exportAsNamespace1_esnext.errors.txt | 22 +++++++++++++++++++ .../exportAsNamespace1_esnext.symbols | 7 ------ .../reference/exportAsNamespace1_esnext.types | 12 +++++----- .../exportAsNamespace1_system.errors.txt | 22 +++++++++++++++++++ .../exportAsNamespace1_system.symbols | 7 ------ .../reference/exportAsNamespace1_system.types | 12 +++++----- .../exportAsNamespace1_umd.errors.txt | 22 +++++++++++++++++++ .../reference/exportAsNamespace1_umd.js | 4 ++-- .../reference/exportAsNamespace1_umd.symbols | 7 ------ .../reference/exportAsNamespace1_umd.types | 12 +++++----- .../reference/exportAsNamespace2.errors.txt | 22 +++++++++++++++++++ .../baselines/reference/exportAsNamespace2.js | 4 ++-- .../reference/exportAsNamespace2.symbols | 7 ------ .../reference/exportAsNamespace2.types | 12 +++++----- .../exportAsNamespace2_amd.errors.txt | 22 +++++++++++++++++++ .../reference/exportAsNamespace2_amd.js | 4 ++-- .../reference/exportAsNamespace2_amd.symbols | 7 ------ .../reference/exportAsNamespace2_amd.types | 12 +++++----- .../exportAsNamespace2_esnext.errors.txt | 22 +++++++++++++++++++ .../exportAsNamespace2_esnext.symbols | 7 ------ .../reference/exportAsNamespace2_esnext.types | 12 +++++----- .../exportAsNamespace2_system.errors.txt | 22 +++++++++++++++++++ .../exportAsNamespace2_system.symbols | 7 ------ .../reference/exportAsNamespace2_system.types | 12 +++++----- .../exportAsNamespace2_umd.errors.txt | 22 +++++++++++++++++++ .../reference/exportAsNamespace2_umd.js | 4 ++-- .../reference/exportAsNamespace2_umd.symbols | 7 ------ .../reference/exportAsNamespace2_umd.types | 12 +++++----- 37 files changed, 293 insertions(+), 143 deletions(-) create mode 100644 tests/baselines/reference/exportAsNamespace1.errors.txt create mode 100644 tests/baselines/reference/exportAsNamespace1_amd.errors.txt create mode 100644 tests/baselines/reference/exportAsNamespace1_esnext.errors.txt create mode 100644 tests/baselines/reference/exportAsNamespace1_system.errors.txt create mode 100644 tests/baselines/reference/exportAsNamespace1_umd.errors.txt create mode 100644 tests/baselines/reference/exportAsNamespace2.errors.txt create mode 100644 tests/baselines/reference/exportAsNamespace2_amd.errors.txt create mode 100644 tests/baselines/reference/exportAsNamespace2_esnext.errors.txt create mode 100644 tests/baselines/reference/exportAsNamespace2_system.errors.txt create mode 100644 tests/baselines/reference/exportAsNamespace2_umd.errors.txt diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index add0b56a0e966..1848717e14249 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -1547,7 +1547,7 @@ namespace ts { const moduleExport = moduleExports.get(name); if (moduleExport && moduleExport.flags === SymbolFlags.Alias && - getDeclarationOfKind(moduleExport, SyntaxKind.ExportSpecifier)) { + (getDeclarationOfKind(moduleExport, SyntaxKind.ExportSpecifier) || getDeclarationOfKind(moduleExport, SyntaxKind.NamespaceExport))) { break; } } diff --git a/tests/baselines/reference/exportAsNamespace1.errors.txt b/tests/baselines/reference/exportAsNamespace1.errors.txt new file mode 100644 index 0000000000000..90b3756336ae0 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace1.errors.txt @@ -0,0 +1,22 @@ +tests/cases/conformance/es2020/modules/1.ts(2,1): error TS2304: Cannot find name 'ns'. +tests/cases/conformance/es2020/modules/1.ts(3,1): error TS2304: Cannot find name 'ns'. + + +==== tests/cases/conformance/es2020/modules/0.ts (0 errors) ==== + export const a = 1; + export const b = 2; + +==== tests/cases/conformance/es2020/modules/1.ts (2 errors) ==== + export * as ns from './0'; + ns.a; + ~~ +!!! error TS2304: Cannot find name 'ns'. + ns.b; + ~~ +!!! error TS2304: Cannot find name 'ns'. + +==== tests/cases/conformance/es2020/modules/2.ts (0 errors) ==== + import * as foo from './1' + + foo.ns.a; + foo.ns.b; \ No newline at end of file diff --git a/tests/baselines/reference/exportAsNamespace1.js b/tests/baselines/reference/exportAsNamespace1.js index 45221d0c074e2..c876785b96229 100644 --- a/tests/baselines/reference/exportAsNamespace1.js +++ b/tests/baselines/reference/exportAsNamespace1.js @@ -25,8 +25,8 @@ exports.b = 2; exports.__esModule = true; var ns = require("./0"); exports.ns = ns; -exports.ns.a; -exports.ns.b; +ns.a; +ns.b; //// [2.js] "use strict"; exports.__esModule = true; diff --git a/tests/baselines/reference/exportAsNamespace1.symbols b/tests/baselines/reference/exportAsNamespace1.symbols index 1ed5fa61afb25..3c6b7529361ba 100644 --- a/tests/baselines/reference/exportAsNamespace1.symbols +++ b/tests/baselines/reference/exportAsNamespace1.symbols @@ -10,14 +10,7 @@ export * as ns from './0'; >ns : Symbol(ns, Decl(1.ts, 0, 11)) ns.a; ->ns.a : Symbol(ns.a, Decl(0.ts, 0, 12)) ->ns : Symbol(ns, Decl(1.ts, 0, 11)) ->a : Symbol(ns.a, Decl(0.ts, 0, 12)) - ns.b; ->ns.b : Symbol(ns.b, Decl(0.ts, 1, 12)) ->ns : Symbol(ns, Decl(1.ts, 0, 11)) ->b : Symbol(ns.b, Decl(0.ts, 1, 12)) === tests/cases/conformance/es2020/modules/2.ts === import * as foo from './1' diff --git a/tests/baselines/reference/exportAsNamespace1.types b/tests/baselines/reference/exportAsNamespace1.types index 6e3ebceb001cd..43e33efa82b30 100644 --- a/tests/baselines/reference/exportAsNamespace1.types +++ b/tests/baselines/reference/exportAsNamespace1.types @@ -12,14 +12,14 @@ export * as ns from './0'; >ns : typeof ns ns.a; ->ns.a : 1 ->ns : typeof ns ->a : 1 +>ns.a : any +>ns : any +>a : any ns.b; ->ns.b : 2 ->ns : typeof ns ->b : 2 +>ns.b : any +>ns : any +>b : any === tests/cases/conformance/es2020/modules/2.ts === import * as foo from './1' diff --git a/tests/baselines/reference/exportAsNamespace1_amd.errors.txt b/tests/baselines/reference/exportAsNamespace1_amd.errors.txt new file mode 100644 index 0000000000000..90b3756336ae0 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace1_amd.errors.txt @@ -0,0 +1,22 @@ +tests/cases/conformance/es2020/modules/1.ts(2,1): error TS2304: Cannot find name 'ns'. +tests/cases/conformance/es2020/modules/1.ts(3,1): error TS2304: Cannot find name 'ns'. + + +==== tests/cases/conformance/es2020/modules/0.ts (0 errors) ==== + export const a = 1; + export const b = 2; + +==== tests/cases/conformance/es2020/modules/1.ts (2 errors) ==== + export * as ns from './0'; + ns.a; + ~~ +!!! error TS2304: Cannot find name 'ns'. + ns.b; + ~~ +!!! error TS2304: Cannot find name 'ns'. + +==== tests/cases/conformance/es2020/modules/2.ts (0 errors) ==== + import * as foo from './1' + + foo.ns.a; + foo.ns.b; \ No newline at end of file diff --git a/tests/baselines/reference/exportAsNamespace1_amd.js b/tests/baselines/reference/exportAsNamespace1_amd.js index cb48151c6a172..240bf93cdc9dc 100644 --- a/tests/baselines/reference/exportAsNamespace1_amd.js +++ b/tests/baselines/reference/exportAsNamespace1_amd.js @@ -27,8 +27,8 @@ define(["require", "exports", "./0"], function (require, exports, ns) { "use strict"; exports.__esModule = true; exports.ns = ns; - exports.ns.a; - exports.ns.b; + ns.a; + ns.b; }); //// [2.js] define(["require", "exports", "./1"], function (require, exports, foo) { diff --git a/tests/baselines/reference/exportAsNamespace1_amd.symbols b/tests/baselines/reference/exportAsNamespace1_amd.symbols index 1ed5fa61afb25..3c6b7529361ba 100644 --- a/tests/baselines/reference/exportAsNamespace1_amd.symbols +++ b/tests/baselines/reference/exportAsNamespace1_amd.symbols @@ -10,14 +10,7 @@ export * as ns from './0'; >ns : Symbol(ns, Decl(1.ts, 0, 11)) ns.a; ->ns.a : Symbol(ns.a, Decl(0.ts, 0, 12)) ->ns : Symbol(ns, Decl(1.ts, 0, 11)) ->a : Symbol(ns.a, Decl(0.ts, 0, 12)) - ns.b; ->ns.b : Symbol(ns.b, Decl(0.ts, 1, 12)) ->ns : Symbol(ns, Decl(1.ts, 0, 11)) ->b : Symbol(ns.b, Decl(0.ts, 1, 12)) === tests/cases/conformance/es2020/modules/2.ts === import * as foo from './1' diff --git a/tests/baselines/reference/exportAsNamespace1_amd.types b/tests/baselines/reference/exportAsNamespace1_amd.types index 6e3ebceb001cd..43e33efa82b30 100644 --- a/tests/baselines/reference/exportAsNamespace1_amd.types +++ b/tests/baselines/reference/exportAsNamespace1_amd.types @@ -12,14 +12,14 @@ export * as ns from './0'; >ns : typeof ns ns.a; ->ns.a : 1 ->ns : typeof ns ->a : 1 +>ns.a : any +>ns : any +>a : any ns.b; ->ns.b : 2 ->ns : typeof ns ->b : 2 +>ns.b : any +>ns : any +>b : any === tests/cases/conformance/es2020/modules/2.ts === import * as foo from './1' diff --git a/tests/baselines/reference/exportAsNamespace1_esnext.errors.txt b/tests/baselines/reference/exportAsNamespace1_esnext.errors.txt new file mode 100644 index 0000000000000..90b3756336ae0 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace1_esnext.errors.txt @@ -0,0 +1,22 @@ +tests/cases/conformance/es2020/modules/1.ts(2,1): error TS2304: Cannot find name 'ns'. +tests/cases/conformance/es2020/modules/1.ts(3,1): error TS2304: Cannot find name 'ns'. + + +==== tests/cases/conformance/es2020/modules/0.ts (0 errors) ==== + export const a = 1; + export const b = 2; + +==== tests/cases/conformance/es2020/modules/1.ts (2 errors) ==== + export * as ns from './0'; + ns.a; + ~~ +!!! error TS2304: Cannot find name 'ns'. + ns.b; + ~~ +!!! error TS2304: Cannot find name 'ns'. + +==== tests/cases/conformance/es2020/modules/2.ts (0 errors) ==== + import * as foo from './1' + + foo.ns.a; + foo.ns.b; \ No newline at end of file diff --git a/tests/baselines/reference/exportAsNamespace1_esnext.symbols b/tests/baselines/reference/exportAsNamespace1_esnext.symbols index 1ed5fa61afb25..3c6b7529361ba 100644 --- a/tests/baselines/reference/exportAsNamespace1_esnext.symbols +++ b/tests/baselines/reference/exportAsNamespace1_esnext.symbols @@ -10,14 +10,7 @@ export * as ns from './0'; >ns : Symbol(ns, Decl(1.ts, 0, 11)) ns.a; ->ns.a : Symbol(ns.a, Decl(0.ts, 0, 12)) ->ns : Symbol(ns, Decl(1.ts, 0, 11)) ->a : Symbol(ns.a, Decl(0.ts, 0, 12)) - ns.b; ->ns.b : Symbol(ns.b, Decl(0.ts, 1, 12)) ->ns : Symbol(ns, Decl(1.ts, 0, 11)) ->b : Symbol(ns.b, Decl(0.ts, 1, 12)) === tests/cases/conformance/es2020/modules/2.ts === import * as foo from './1' diff --git a/tests/baselines/reference/exportAsNamespace1_esnext.types b/tests/baselines/reference/exportAsNamespace1_esnext.types index 6e3ebceb001cd..43e33efa82b30 100644 --- a/tests/baselines/reference/exportAsNamespace1_esnext.types +++ b/tests/baselines/reference/exportAsNamespace1_esnext.types @@ -12,14 +12,14 @@ export * as ns from './0'; >ns : typeof ns ns.a; ->ns.a : 1 ->ns : typeof ns ->a : 1 +>ns.a : any +>ns : any +>a : any ns.b; ->ns.b : 2 ->ns : typeof ns ->b : 2 +>ns.b : any +>ns : any +>b : any === tests/cases/conformance/es2020/modules/2.ts === import * as foo from './1' diff --git a/tests/baselines/reference/exportAsNamespace1_system.errors.txt b/tests/baselines/reference/exportAsNamespace1_system.errors.txt new file mode 100644 index 0000000000000..90b3756336ae0 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace1_system.errors.txt @@ -0,0 +1,22 @@ +tests/cases/conformance/es2020/modules/1.ts(2,1): error TS2304: Cannot find name 'ns'. +tests/cases/conformance/es2020/modules/1.ts(3,1): error TS2304: Cannot find name 'ns'. + + +==== tests/cases/conformance/es2020/modules/0.ts (0 errors) ==== + export const a = 1; + export const b = 2; + +==== tests/cases/conformance/es2020/modules/1.ts (2 errors) ==== + export * as ns from './0'; + ns.a; + ~~ +!!! error TS2304: Cannot find name 'ns'. + ns.b; + ~~ +!!! error TS2304: Cannot find name 'ns'. + +==== tests/cases/conformance/es2020/modules/2.ts (0 errors) ==== + import * as foo from './1' + + foo.ns.a; + foo.ns.b; \ No newline at end of file diff --git a/tests/baselines/reference/exportAsNamespace1_system.symbols b/tests/baselines/reference/exportAsNamespace1_system.symbols index 1ed5fa61afb25..3c6b7529361ba 100644 --- a/tests/baselines/reference/exportAsNamespace1_system.symbols +++ b/tests/baselines/reference/exportAsNamespace1_system.symbols @@ -10,14 +10,7 @@ export * as ns from './0'; >ns : Symbol(ns, Decl(1.ts, 0, 11)) ns.a; ->ns.a : Symbol(ns.a, Decl(0.ts, 0, 12)) ->ns : Symbol(ns, Decl(1.ts, 0, 11)) ->a : Symbol(ns.a, Decl(0.ts, 0, 12)) - ns.b; ->ns.b : Symbol(ns.b, Decl(0.ts, 1, 12)) ->ns : Symbol(ns, Decl(1.ts, 0, 11)) ->b : Symbol(ns.b, Decl(0.ts, 1, 12)) === tests/cases/conformance/es2020/modules/2.ts === import * as foo from './1' diff --git a/tests/baselines/reference/exportAsNamespace1_system.types b/tests/baselines/reference/exportAsNamespace1_system.types index 6e3ebceb001cd..43e33efa82b30 100644 --- a/tests/baselines/reference/exportAsNamespace1_system.types +++ b/tests/baselines/reference/exportAsNamespace1_system.types @@ -12,14 +12,14 @@ export * as ns from './0'; >ns : typeof ns ns.a; ->ns.a : 1 ->ns : typeof ns ->a : 1 +>ns.a : any +>ns : any +>a : any ns.b; ->ns.b : 2 ->ns : typeof ns ->b : 2 +>ns.b : any +>ns : any +>b : any === tests/cases/conformance/es2020/modules/2.ts === import * as foo from './1' diff --git a/tests/baselines/reference/exportAsNamespace1_umd.errors.txt b/tests/baselines/reference/exportAsNamespace1_umd.errors.txt new file mode 100644 index 0000000000000..90b3756336ae0 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace1_umd.errors.txt @@ -0,0 +1,22 @@ +tests/cases/conformance/es2020/modules/1.ts(2,1): error TS2304: Cannot find name 'ns'. +tests/cases/conformance/es2020/modules/1.ts(3,1): error TS2304: Cannot find name 'ns'. + + +==== tests/cases/conformance/es2020/modules/0.ts (0 errors) ==== + export const a = 1; + export const b = 2; + +==== tests/cases/conformance/es2020/modules/1.ts (2 errors) ==== + export * as ns from './0'; + ns.a; + ~~ +!!! error TS2304: Cannot find name 'ns'. + ns.b; + ~~ +!!! error TS2304: Cannot find name 'ns'. + +==== tests/cases/conformance/es2020/modules/2.ts (0 errors) ==== + import * as foo from './1' + + foo.ns.a; + foo.ns.b; \ No newline at end of file diff --git a/tests/baselines/reference/exportAsNamespace1_umd.js b/tests/baselines/reference/exportAsNamespace1_umd.js index 7a9bf69965d98..0c19caafa18bd 100644 --- a/tests/baselines/reference/exportAsNamespace1_umd.js +++ b/tests/baselines/reference/exportAsNamespace1_umd.js @@ -44,8 +44,8 @@ foo.ns.b; exports.__esModule = true; var ns = require("./0"); exports.ns = ns; - exports.ns.a; - exports.ns.b; + ns.a; + ns.b; }); //// [2.js] (function (factory) { diff --git a/tests/baselines/reference/exportAsNamespace1_umd.symbols b/tests/baselines/reference/exportAsNamespace1_umd.symbols index 1ed5fa61afb25..3c6b7529361ba 100644 --- a/tests/baselines/reference/exportAsNamespace1_umd.symbols +++ b/tests/baselines/reference/exportAsNamespace1_umd.symbols @@ -10,14 +10,7 @@ export * as ns from './0'; >ns : Symbol(ns, Decl(1.ts, 0, 11)) ns.a; ->ns.a : Symbol(ns.a, Decl(0.ts, 0, 12)) ->ns : Symbol(ns, Decl(1.ts, 0, 11)) ->a : Symbol(ns.a, Decl(0.ts, 0, 12)) - ns.b; ->ns.b : Symbol(ns.b, Decl(0.ts, 1, 12)) ->ns : Symbol(ns, Decl(1.ts, 0, 11)) ->b : Symbol(ns.b, Decl(0.ts, 1, 12)) === tests/cases/conformance/es2020/modules/2.ts === import * as foo from './1' diff --git a/tests/baselines/reference/exportAsNamespace1_umd.types b/tests/baselines/reference/exportAsNamespace1_umd.types index 6e3ebceb001cd..43e33efa82b30 100644 --- a/tests/baselines/reference/exportAsNamespace1_umd.types +++ b/tests/baselines/reference/exportAsNamespace1_umd.types @@ -12,14 +12,14 @@ export * as ns from './0'; >ns : typeof ns ns.a; ->ns.a : 1 ->ns : typeof ns ->a : 1 +>ns.a : any +>ns : any +>a : any ns.b; ->ns.b : 2 ->ns : typeof ns ->b : 2 +>ns.b : any +>ns : any +>b : any === tests/cases/conformance/es2020/modules/2.ts === import * as foo from './1' diff --git a/tests/baselines/reference/exportAsNamespace2.errors.txt b/tests/baselines/reference/exportAsNamespace2.errors.txt new file mode 100644 index 0000000000000..90b3756336ae0 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace2.errors.txt @@ -0,0 +1,22 @@ +tests/cases/conformance/es2020/modules/1.ts(2,1): error TS2304: Cannot find name 'ns'. +tests/cases/conformance/es2020/modules/1.ts(3,1): error TS2304: Cannot find name 'ns'. + + +==== tests/cases/conformance/es2020/modules/0.ts (0 errors) ==== + export const a = 1; + export const b = 2; + +==== tests/cases/conformance/es2020/modules/1.ts (2 errors) ==== + export * as ns from './0'; + ns.a; + ~~ +!!! error TS2304: Cannot find name 'ns'. + ns.b; + ~~ +!!! error TS2304: Cannot find name 'ns'. + +==== tests/cases/conformance/es2020/modules/2.ts (0 errors) ==== + import * as foo from './1' + + foo.ns.a; + foo.ns.b; \ No newline at end of file diff --git a/tests/baselines/reference/exportAsNamespace2.js b/tests/baselines/reference/exportAsNamespace2.js index 20c436764d8fd..97f1778e5a2db 100644 --- a/tests/baselines/reference/exportAsNamespace2.js +++ b/tests/baselines/reference/exportAsNamespace2.js @@ -32,8 +32,8 @@ var __importStar = (this && this.__importStar) || function (mod) { exports.__esModule = true; var ns = __importStar(require("./0")); exports.ns = ns; -exports.ns.a; -exports.ns.b; +ns.a; +ns.b; //// [2.js] "use strict"; var __importStar = (this && this.__importStar) || function (mod) { diff --git a/tests/baselines/reference/exportAsNamespace2.symbols b/tests/baselines/reference/exportAsNamespace2.symbols index 1ed5fa61afb25..3c6b7529361ba 100644 --- a/tests/baselines/reference/exportAsNamespace2.symbols +++ b/tests/baselines/reference/exportAsNamespace2.symbols @@ -10,14 +10,7 @@ export * as ns from './0'; >ns : Symbol(ns, Decl(1.ts, 0, 11)) ns.a; ->ns.a : Symbol(ns.a, Decl(0.ts, 0, 12)) ->ns : Symbol(ns, Decl(1.ts, 0, 11)) ->a : Symbol(ns.a, Decl(0.ts, 0, 12)) - ns.b; ->ns.b : Symbol(ns.b, Decl(0.ts, 1, 12)) ->ns : Symbol(ns, Decl(1.ts, 0, 11)) ->b : Symbol(ns.b, Decl(0.ts, 1, 12)) === tests/cases/conformance/es2020/modules/2.ts === import * as foo from './1' diff --git a/tests/baselines/reference/exportAsNamespace2.types b/tests/baselines/reference/exportAsNamespace2.types index 6e3ebceb001cd..43e33efa82b30 100644 --- a/tests/baselines/reference/exportAsNamespace2.types +++ b/tests/baselines/reference/exportAsNamespace2.types @@ -12,14 +12,14 @@ export * as ns from './0'; >ns : typeof ns ns.a; ->ns.a : 1 ->ns : typeof ns ->a : 1 +>ns.a : any +>ns : any +>a : any ns.b; ->ns.b : 2 ->ns : typeof ns ->b : 2 +>ns.b : any +>ns : any +>b : any === tests/cases/conformance/es2020/modules/2.ts === import * as foo from './1' diff --git a/tests/baselines/reference/exportAsNamespace2_amd.errors.txt b/tests/baselines/reference/exportAsNamespace2_amd.errors.txt new file mode 100644 index 0000000000000..90b3756336ae0 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace2_amd.errors.txt @@ -0,0 +1,22 @@ +tests/cases/conformance/es2020/modules/1.ts(2,1): error TS2304: Cannot find name 'ns'. +tests/cases/conformance/es2020/modules/1.ts(3,1): error TS2304: Cannot find name 'ns'. + + +==== tests/cases/conformance/es2020/modules/0.ts (0 errors) ==== + export const a = 1; + export const b = 2; + +==== tests/cases/conformance/es2020/modules/1.ts (2 errors) ==== + export * as ns from './0'; + ns.a; + ~~ +!!! error TS2304: Cannot find name 'ns'. + ns.b; + ~~ +!!! error TS2304: Cannot find name 'ns'. + +==== tests/cases/conformance/es2020/modules/2.ts (0 errors) ==== + import * as foo from './1' + + foo.ns.a; + foo.ns.b; \ No newline at end of file diff --git a/tests/baselines/reference/exportAsNamespace2_amd.js b/tests/baselines/reference/exportAsNamespace2_amd.js index 56c592c1d593e..9bb659b380087 100644 --- a/tests/baselines/reference/exportAsNamespace2_amd.js +++ b/tests/baselines/reference/exportAsNamespace2_amd.js @@ -27,8 +27,8 @@ define(["require", "exports", "./0"], function (require, exports, ns) { "use strict"; exports.__esModule = true; exports.ns = ns; - exports.ns.a; - exports.ns.b; + ns.a; + ns.b; }); //// [2.js] var __importStar = (this && this.__importStar) || function (mod) { diff --git a/tests/baselines/reference/exportAsNamespace2_amd.symbols b/tests/baselines/reference/exportAsNamespace2_amd.symbols index 1ed5fa61afb25..3c6b7529361ba 100644 --- a/tests/baselines/reference/exportAsNamespace2_amd.symbols +++ b/tests/baselines/reference/exportAsNamespace2_amd.symbols @@ -10,14 +10,7 @@ export * as ns from './0'; >ns : Symbol(ns, Decl(1.ts, 0, 11)) ns.a; ->ns.a : Symbol(ns.a, Decl(0.ts, 0, 12)) ->ns : Symbol(ns, Decl(1.ts, 0, 11)) ->a : Symbol(ns.a, Decl(0.ts, 0, 12)) - ns.b; ->ns.b : Symbol(ns.b, Decl(0.ts, 1, 12)) ->ns : Symbol(ns, Decl(1.ts, 0, 11)) ->b : Symbol(ns.b, Decl(0.ts, 1, 12)) === tests/cases/conformance/es2020/modules/2.ts === import * as foo from './1' diff --git a/tests/baselines/reference/exportAsNamespace2_amd.types b/tests/baselines/reference/exportAsNamespace2_amd.types index 6e3ebceb001cd..43e33efa82b30 100644 --- a/tests/baselines/reference/exportAsNamespace2_amd.types +++ b/tests/baselines/reference/exportAsNamespace2_amd.types @@ -12,14 +12,14 @@ export * as ns from './0'; >ns : typeof ns ns.a; ->ns.a : 1 ->ns : typeof ns ->a : 1 +>ns.a : any +>ns : any +>a : any ns.b; ->ns.b : 2 ->ns : typeof ns ->b : 2 +>ns.b : any +>ns : any +>b : any === tests/cases/conformance/es2020/modules/2.ts === import * as foo from './1' diff --git a/tests/baselines/reference/exportAsNamespace2_esnext.errors.txt b/tests/baselines/reference/exportAsNamespace2_esnext.errors.txt new file mode 100644 index 0000000000000..90b3756336ae0 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace2_esnext.errors.txt @@ -0,0 +1,22 @@ +tests/cases/conformance/es2020/modules/1.ts(2,1): error TS2304: Cannot find name 'ns'. +tests/cases/conformance/es2020/modules/1.ts(3,1): error TS2304: Cannot find name 'ns'. + + +==== tests/cases/conformance/es2020/modules/0.ts (0 errors) ==== + export const a = 1; + export const b = 2; + +==== tests/cases/conformance/es2020/modules/1.ts (2 errors) ==== + export * as ns from './0'; + ns.a; + ~~ +!!! error TS2304: Cannot find name 'ns'. + ns.b; + ~~ +!!! error TS2304: Cannot find name 'ns'. + +==== tests/cases/conformance/es2020/modules/2.ts (0 errors) ==== + import * as foo from './1' + + foo.ns.a; + foo.ns.b; \ No newline at end of file diff --git a/tests/baselines/reference/exportAsNamespace2_esnext.symbols b/tests/baselines/reference/exportAsNamespace2_esnext.symbols index 1ed5fa61afb25..3c6b7529361ba 100644 --- a/tests/baselines/reference/exportAsNamespace2_esnext.symbols +++ b/tests/baselines/reference/exportAsNamespace2_esnext.symbols @@ -10,14 +10,7 @@ export * as ns from './0'; >ns : Symbol(ns, Decl(1.ts, 0, 11)) ns.a; ->ns.a : Symbol(ns.a, Decl(0.ts, 0, 12)) ->ns : Symbol(ns, Decl(1.ts, 0, 11)) ->a : Symbol(ns.a, Decl(0.ts, 0, 12)) - ns.b; ->ns.b : Symbol(ns.b, Decl(0.ts, 1, 12)) ->ns : Symbol(ns, Decl(1.ts, 0, 11)) ->b : Symbol(ns.b, Decl(0.ts, 1, 12)) === tests/cases/conformance/es2020/modules/2.ts === import * as foo from './1' diff --git a/tests/baselines/reference/exportAsNamespace2_esnext.types b/tests/baselines/reference/exportAsNamespace2_esnext.types index 6e3ebceb001cd..43e33efa82b30 100644 --- a/tests/baselines/reference/exportAsNamespace2_esnext.types +++ b/tests/baselines/reference/exportAsNamespace2_esnext.types @@ -12,14 +12,14 @@ export * as ns from './0'; >ns : typeof ns ns.a; ->ns.a : 1 ->ns : typeof ns ->a : 1 +>ns.a : any +>ns : any +>a : any ns.b; ->ns.b : 2 ->ns : typeof ns ->b : 2 +>ns.b : any +>ns : any +>b : any === tests/cases/conformance/es2020/modules/2.ts === import * as foo from './1' diff --git a/tests/baselines/reference/exportAsNamespace2_system.errors.txt b/tests/baselines/reference/exportAsNamespace2_system.errors.txt new file mode 100644 index 0000000000000..90b3756336ae0 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace2_system.errors.txt @@ -0,0 +1,22 @@ +tests/cases/conformance/es2020/modules/1.ts(2,1): error TS2304: Cannot find name 'ns'. +tests/cases/conformance/es2020/modules/1.ts(3,1): error TS2304: Cannot find name 'ns'. + + +==== tests/cases/conformance/es2020/modules/0.ts (0 errors) ==== + export const a = 1; + export const b = 2; + +==== tests/cases/conformance/es2020/modules/1.ts (2 errors) ==== + export * as ns from './0'; + ns.a; + ~~ +!!! error TS2304: Cannot find name 'ns'. + ns.b; + ~~ +!!! error TS2304: Cannot find name 'ns'. + +==== tests/cases/conformance/es2020/modules/2.ts (0 errors) ==== + import * as foo from './1' + + foo.ns.a; + foo.ns.b; \ No newline at end of file diff --git a/tests/baselines/reference/exportAsNamespace2_system.symbols b/tests/baselines/reference/exportAsNamespace2_system.symbols index 1ed5fa61afb25..3c6b7529361ba 100644 --- a/tests/baselines/reference/exportAsNamespace2_system.symbols +++ b/tests/baselines/reference/exportAsNamespace2_system.symbols @@ -10,14 +10,7 @@ export * as ns from './0'; >ns : Symbol(ns, Decl(1.ts, 0, 11)) ns.a; ->ns.a : Symbol(ns.a, Decl(0.ts, 0, 12)) ->ns : Symbol(ns, Decl(1.ts, 0, 11)) ->a : Symbol(ns.a, Decl(0.ts, 0, 12)) - ns.b; ->ns.b : Symbol(ns.b, Decl(0.ts, 1, 12)) ->ns : Symbol(ns, Decl(1.ts, 0, 11)) ->b : Symbol(ns.b, Decl(0.ts, 1, 12)) === tests/cases/conformance/es2020/modules/2.ts === import * as foo from './1' diff --git a/tests/baselines/reference/exportAsNamespace2_system.types b/tests/baselines/reference/exportAsNamespace2_system.types index 6e3ebceb001cd..43e33efa82b30 100644 --- a/tests/baselines/reference/exportAsNamespace2_system.types +++ b/tests/baselines/reference/exportAsNamespace2_system.types @@ -12,14 +12,14 @@ export * as ns from './0'; >ns : typeof ns ns.a; ->ns.a : 1 ->ns : typeof ns ->a : 1 +>ns.a : any +>ns : any +>a : any ns.b; ->ns.b : 2 ->ns : typeof ns ->b : 2 +>ns.b : any +>ns : any +>b : any === tests/cases/conformance/es2020/modules/2.ts === import * as foo from './1' diff --git a/tests/baselines/reference/exportAsNamespace2_umd.errors.txt b/tests/baselines/reference/exportAsNamespace2_umd.errors.txt new file mode 100644 index 0000000000000..90b3756336ae0 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace2_umd.errors.txt @@ -0,0 +1,22 @@ +tests/cases/conformance/es2020/modules/1.ts(2,1): error TS2304: Cannot find name 'ns'. +tests/cases/conformance/es2020/modules/1.ts(3,1): error TS2304: Cannot find name 'ns'. + + +==== tests/cases/conformance/es2020/modules/0.ts (0 errors) ==== + export const a = 1; + export const b = 2; + +==== tests/cases/conformance/es2020/modules/1.ts (2 errors) ==== + export * as ns from './0'; + ns.a; + ~~ +!!! error TS2304: Cannot find name 'ns'. + ns.b; + ~~ +!!! error TS2304: Cannot find name 'ns'. + +==== tests/cases/conformance/es2020/modules/2.ts (0 errors) ==== + import * as foo from './1' + + foo.ns.a; + foo.ns.b; \ No newline at end of file diff --git a/tests/baselines/reference/exportAsNamespace2_umd.js b/tests/baselines/reference/exportAsNamespace2_umd.js index 81f5b7b8851e0..f7ff19af22dbe 100644 --- a/tests/baselines/reference/exportAsNamespace2_umd.js +++ b/tests/baselines/reference/exportAsNamespace2_umd.js @@ -51,8 +51,8 @@ var __importStar = (this && this.__importStar) || function (mod) { exports.__esModule = true; var ns = __importStar(require("./0")); exports.ns = ns; - exports.ns.a; - exports.ns.b; + ns.a; + ns.b; }); //// [2.js] var __importStar = (this && this.__importStar) || function (mod) { diff --git a/tests/baselines/reference/exportAsNamespace2_umd.symbols b/tests/baselines/reference/exportAsNamespace2_umd.symbols index 1ed5fa61afb25..3c6b7529361ba 100644 --- a/tests/baselines/reference/exportAsNamespace2_umd.symbols +++ b/tests/baselines/reference/exportAsNamespace2_umd.symbols @@ -10,14 +10,7 @@ export * as ns from './0'; >ns : Symbol(ns, Decl(1.ts, 0, 11)) ns.a; ->ns.a : Symbol(ns.a, Decl(0.ts, 0, 12)) ->ns : Symbol(ns, Decl(1.ts, 0, 11)) ->a : Symbol(ns.a, Decl(0.ts, 0, 12)) - ns.b; ->ns.b : Symbol(ns.b, Decl(0.ts, 1, 12)) ->ns : Symbol(ns, Decl(1.ts, 0, 11)) ->b : Symbol(ns.b, Decl(0.ts, 1, 12)) === tests/cases/conformance/es2020/modules/2.ts === import * as foo from './1' diff --git a/tests/baselines/reference/exportAsNamespace2_umd.types b/tests/baselines/reference/exportAsNamespace2_umd.types index 6e3ebceb001cd..43e33efa82b30 100644 --- a/tests/baselines/reference/exportAsNamespace2_umd.types +++ b/tests/baselines/reference/exportAsNamespace2_umd.types @@ -12,14 +12,14 @@ export * as ns from './0'; >ns : typeof ns ns.a; ->ns.a : 1 ->ns : typeof ns ->a : 1 +>ns.a : any +>ns : any +>a : any ns.b; ->ns.b : 2 ->ns : typeof ns ->b : 2 +>ns.b : any +>ns : any +>b : any === tests/cases/conformance/es2020/modules/2.ts === import * as foo from './1' From a66b75b4a8e553f4aa607a873c5612f7ce7df14b Mon Sep 17 00:00:00 2001 From: kingwl Date: Sat, 21 Dec 2019 00:28:13 +0800 Subject: [PATCH 19/29] avoid useless check --- src/compiler/checker.ts | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 1848717e14249..b337a00accc02 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -32641,7 +32641,7 @@ namespace ts { } } - function checkImportOrExportBinding(node: ImportEqualsDeclaration | ImportClause | NamespaceImport | NamespaceExport | ImportSpecifier) { + function checkImportBinding(node: ImportEqualsDeclaration | ImportClause | NamespaceImport | ImportSpecifier) { checkCollisionWithRequireExportsInGeneratedCode(node, node.name!); checkCollisionWithGlobalPromiseInGeneratedCode(node, node.name!); checkAliasSymbol(node); @@ -32659,16 +32659,16 @@ namespace ts { const importClause = node.importClause; if (importClause) { if (importClause.name) { - checkImportOrExportBinding(importClause); + checkImportBinding(importClause); } if (importClause.namedBindings) { if (importClause.namedBindings.kind === SyntaxKind.NamespaceImport) { - checkImportOrExportBinding(importClause.namedBindings); + checkImportBinding(importClause.namedBindings); } else { const moduleExisted = resolveExternalModuleName(node, node.moduleSpecifier); if (moduleExisted) { - forEach(importClause.namedBindings.elements, checkImportOrExportBinding); + forEach(importClause.namedBindings.elements, checkImportBinding); } } } @@ -32684,7 +32684,7 @@ namespace ts { checkGrammarDecoratorsAndModifiers(node); if (isInternalModuleImportEqualsDeclaration(node) || checkExternalImportOrExportDeclaration(node)) { - checkImportOrExportBinding(node); + checkImportBinding(node); if (hasModifier(node, ModifierFlags.Export)) { markExportAsReferenced(node); } @@ -32726,8 +32726,12 @@ namespace ts { if (node.exportClause) { // export { x, y } // export { x, y } from "foo" - // export * as ns from "foo" - isNamedExports(node.exportClause) ? forEach(node.exportClause.elements, checkExportSpecifier) : checkImportOrExportBinding(node.exportClause); + if (isNamedExports(node.exportClause)) { + forEach(node.exportClause.elements, checkExportSpecifier); + } + else if(!isNamespaceExport(node.exportClause)) { + checkImportBinding(node.exportClause); + } const inAmbientExternalModule = node.parent.kind === SyntaxKind.ModuleBlock && isAmbientModule(node.parent.parent); const inAmbientNamespaceDeclaration = !inAmbientExternalModule && node.parent.kind === SyntaxKind.ModuleBlock && From d7355b5f9e8cf566dd50dd9b1dd53c5b5e87bb44 Mon Sep 17 00:00:00 2001 From: kingwl Date: Sat, 21 Dec 2019 01:25:15 +0800 Subject: [PATCH 20/29] update public api --- tests/baselines/reference/api/tsserverlibrary.d.ts | 1 + tests/baselines/reference/api/typescript.d.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index 5bfba0a6532a3..d945f7c0c725f 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -3639,6 +3639,7 @@ declare namespace ts { function isImportClause(node: Node): node is ImportClause; function isNamespaceImport(node: Node): node is NamespaceImport; function isNamespaceExport(node: Node): node is NamespaceExport; + function isNamedExportBindings(node: Node): node is NamedExportBindings; function isNamedImports(node: Node): node is NamedImports; function isImportSpecifier(node: Node): node is ImportSpecifier; function isExportAssignment(node: Node): node is ExportAssignment; diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index 6461b183fc908..1821a2a756364 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -3639,6 +3639,7 @@ declare namespace ts { function isImportClause(node: Node): node is ImportClause; function isNamespaceImport(node: Node): node is NamespaceImport; function isNamespaceExport(node: Node): node is NamespaceExport; + function isNamedExportBindings(node: Node): node is NamedExportBindings; function isNamedImports(node: Node): node is NamedImports; function isImportSpecifier(node: Node): node is ImportSpecifier; function isExportAssignment(node: Node): node is ExportAssignment; From dc204007bb368bfa93793071bbee431a45ac501a Mon Sep 17 00:00:00 2001 From: kingwl Date: Sat, 21 Dec 2019 01:30:57 +0800 Subject: [PATCH 21/29] add more case --- .../reference/exportAsNamespace3.errors.txt | 27 ++++++++ .../baselines/reference/exportAsNamespace3.js | 64 +++++++++++++++++++ .../reference/exportAsNamespace3.symbols | 54 ++++++++++++++++ .../reference/exportAsNamespace3.types | 59 +++++++++++++++++ .../es2020/modules/exportAsNamespace3.ts | 19 ++++++ 5 files changed, 223 insertions(+) create mode 100644 tests/baselines/reference/exportAsNamespace3.errors.txt create mode 100644 tests/baselines/reference/exportAsNamespace3.js create mode 100644 tests/baselines/reference/exportAsNamespace3.symbols create mode 100644 tests/baselines/reference/exportAsNamespace3.types create mode 100644 tests/cases/conformance/es2020/modules/exportAsNamespace3.ts diff --git a/tests/baselines/reference/exportAsNamespace3.errors.txt b/tests/baselines/reference/exportAsNamespace3.errors.txt new file mode 100644 index 0000000000000..eb0dcccdc79ed --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace3.errors.txt @@ -0,0 +1,27 @@ +tests/cases/conformance/es2020/modules/1.ts(2,1): error TS2448: Block-scoped variable 'ns' used before its declaration. +tests/cases/conformance/es2020/modules/1.ts(3,1): error TS2448: Block-scoped variable 'ns' used before its declaration. + + +==== tests/cases/conformance/es2020/modules/0.ts (0 errors) ==== + export const a = 1; + export const b = 2; + +==== tests/cases/conformance/es2020/modules/1.ts (2 errors) ==== + export * as ns from './0'; + ns.a; + ~~ +!!! error TS2448: Block-scoped variable 'ns' used before its declaration. +!!! related TS2728 tests/cases/conformance/es2020/modules/1.ts:4:5: 'ns' is declared here. + ns.b; + ~~ +!!! error TS2448: Block-scoped variable 'ns' used before its declaration. +!!! related TS2728 tests/cases/conformance/es2020/modules/1.ts:4:5: 'ns' is declared here. + let ns = {a: 1, b: 2} + ns.a; + ns.b; + +==== tests/cases/conformance/es2020/modules/2.ts (0 errors) ==== + import * as foo from './1' + + foo.ns.a; + foo.ns.b; \ No newline at end of file diff --git a/tests/baselines/reference/exportAsNamespace3.js b/tests/baselines/reference/exportAsNamespace3.js new file mode 100644 index 0000000000000..0b9ed7b56e9f4 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace3.js @@ -0,0 +1,64 @@ +//// [tests/cases/conformance/es2020/modules/exportAsNamespace3.ts] //// + +//// [0.ts] +export const a = 1; +export const b = 2; + +//// [1.ts] +export * as ns from './0'; +ns.a; +ns.b; +let ns = {a: 1, b: 2} +ns.a; +ns.b; + +//// [2.ts] +import * as foo from './1' + +foo.ns.a; +foo.ns.b; + +//// [0.js] +"use strict"; +exports.__esModule = true; +exports.a = 1; +exports.b = 2; +//// [1.js] +"use strict"; +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; + result["default"] = mod; + return result; +}; +exports.__esModule = true; +var ns = __importStar(require("./0")); +exports.ns = ns; +ns.a; +ns.b; +var ns = { a: 1, b: 2 }; +ns.a; +ns.b; +//// [2.js] +"use strict"; +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; + result["default"] = mod; + return result; +}; +exports.__esModule = true; +var foo = __importStar(require("./1")); +foo.ns.a; +foo.ns.b; + + +//// [0.d.ts] +export declare const a = 1; +export declare const b = 2; +//// [1.d.ts] +export * as ns from './0'; +//// [2.d.ts] +export {}; diff --git a/tests/baselines/reference/exportAsNamespace3.symbols b/tests/baselines/reference/exportAsNamespace3.symbols new file mode 100644 index 0000000000000..0414e93a36357 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace3.symbols @@ -0,0 +1,54 @@ +=== tests/cases/conformance/es2020/modules/0.ts === +export const a = 1; +>a : Symbol(a, Decl(0.ts, 0, 12)) + +export const b = 2; +>b : Symbol(b, Decl(0.ts, 1, 12)) + +=== tests/cases/conformance/es2020/modules/1.ts === +export * as ns from './0'; +>ns : Symbol(ns, Decl(1.ts, 0, 11)) + +ns.a; +>ns.a : Symbol(a, Decl(1.ts, 3, 10)) +>ns : Symbol(ns, Decl(1.ts, 3, 3)) +>a : Symbol(a, Decl(1.ts, 3, 10)) + +ns.b; +>ns.b : Symbol(b, Decl(1.ts, 3, 15)) +>ns : Symbol(ns, Decl(1.ts, 3, 3)) +>b : Symbol(b, Decl(1.ts, 3, 15)) + +let ns = {a: 1, b: 2} +>ns : Symbol(ns, Decl(1.ts, 3, 3)) +>a : Symbol(a, Decl(1.ts, 3, 10)) +>b : Symbol(b, Decl(1.ts, 3, 15)) + +ns.a; +>ns.a : Symbol(a, Decl(1.ts, 3, 10)) +>ns : Symbol(ns, Decl(1.ts, 3, 3)) +>a : Symbol(a, Decl(1.ts, 3, 10)) + +ns.b; +>ns.b : Symbol(b, Decl(1.ts, 3, 15)) +>ns : Symbol(ns, Decl(1.ts, 3, 3)) +>b : Symbol(b, Decl(1.ts, 3, 15)) + +=== tests/cases/conformance/es2020/modules/2.ts === +import * as foo from './1' +>foo : Symbol(foo, Decl(2.ts, 0, 6)) + +foo.ns.a; +>foo.ns.a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo : Symbol(foo, Decl(2.ts, 0, 6)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) + +foo.ns.b; +>foo.ns.b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo : Symbol(foo, Decl(2.ts, 0, 6)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) + diff --git a/tests/baselines/reference/exportAsNamespace3.types b/tests/baselines/reference/exportAsNamespace3.types new file mode 100644 index 0000000000000..b6a314299970c --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace3.types @@ -0,0 +1,59 @@ +=== tests/cases/conformance/es2020/modules/0.ts === +export const a = 1; +>a : 1 +>1 : 1 + +export const b = 2; +>b : 2 +>2 : 2 + +=== tests/cases/conformance/es2020/modules/1.ts === +export * as ns from './0'; +>ns : typeof import("tests/cases/conformance/es2020/modules/0") + +ns.a; +>ns.a : number +>ns : { a: number; b: number; } +>a : number + +ns.b; +>ns.b : number +>ns : { a: number; b: number; } +>b : number + +let ns = {a: 1, b: 2} +>ns : { a: number; b: number; } +>{a: 1, b: 2} : { a: number; b: number; } +>a : number +>1 : 1 +>b : number +>2 : 2 + +ns.a; +>ns.a : number +>ns : { a: number; b: number; } +>a : number + +ns.b; +>ns.b : number +>ns : { a: number; b: number; } +>b : number + +=== tests/cases/conformance/es2020/modules/2.ts === +import * as foo from './1' +>foo : typeof foo + +foo.ns.a; +>foo.ns.a : 1 +>foo.ns : typeof foo.ns +>foo : typeof foo +>ns : typeof foo.ns +>a : 1 + +foo.ns.b; +>foo.ns.b : 2 +>foo.ns : typeof foo.ns +>foo : typeof foo +>ns : typeof foo.ns +>b : 2 + diff --git a/tests/cases/conformance/es2020/modules/exportAsNamespace3.ts b/tests/cases/conformance/es2020/modules/exportAsNamespace3.ts new file mode 100644 index 0000000000000..a046438eb92c6 --- /dev/null +++ b/tests/cases/conformance/es2020/modules/exportAsNamespace3.ts @@ -0,0 +1,19 @@ +// @filename: 0.ts +// @declaration: true +// @esModuleInterop: true +export const a = 1; +export const b = 2; + +// @filename: 1.ts +export * as ns from './0'; +ns.a; +ns.b; +let ns = {a: 1, b: 2} +ns.a; +ns.b; + +// @filename: 2.ts +import * as foo from './1' + +foo.ns.a; +foo.ns.b; \ No newline at end of file From a595ad1711188a18271d04b455f7af57b058abd0 Mon Sep 17 00:00:00 2001 From: kingwl Date: Sat, 21 Dec 2019 03:06:13 +0800 Subject: [PATCH 22/29] fix some case --- src/compiler/transformers/module/module.ts | 22 +++++-------------- src/compiler/transformers/module/system.ts | 6 ++--- .../baselines/reference/exportAsNamespace1.js | 3 +-- .../reference/exportAsNamespace1_system.js | 3 +-- .../reference/exportAsNamespace1_umd.js | 3 +-- .../baselines/reference/exportAsNamespace2.js | 3 +-- .../reference/exportAsNamespace2_system.js | 3 +-- .../reference/exportAsNamespace2_umd.js | 3 +-- .../baselines/reference/exportAsNamespace3.js | 3 +-- 9 files changed, 15 insertions(+), 34 deletions(-) diff --git a/src/compiler/transformers/module/module.ts b/src/compiler/transformers/module/module.ts index 80c6ef391253d..0e90ad2eb2bb4 100644 --- a/src/compiler/transformers/module/module.ts +++ b/src/compiler/transformers/module/module.ts @@ -1022,26 +1022,16 @@ namespace ts { else if (node.exportClause) { const statements: Statement[] = []; // export * as ns from "mod"; - if (moduleKind !== ModuleKind.AMD) { - statements.push( - createVariableStatement( - /*modifiers*/ undefined, - createVariableDeclarationList([ - createVariableDeclaration( - getSynthesizedClone(node.exportClause.name), - /*type*/ undefined, - getHelperExpressionForExport(node, createRequireCall(node)) - ) - ]) - ) - ); - } - statements.push( setOriginalNode( setTextRange( createExpressionStatement( - createExportExpression(getSynthesizedClone(node.exportClause.name), createIdentifier(idText(node.exportClause.name))) + createExportExpression( + getSynthesizedClone(node.exportClause.name), + moduleKind !== ModuleKind.AMD ? + getHelperExpressionForExport(node, createRequireCall(node)) : + createIdentifier(idText(node.exportClause.name)) + ) ), node ), diff --git a/src/compiler/transformers/module/system.ts b/src/compiler/transformers/module/system.ts index b92553c4f9076..7c4755924510c 100644 --- a/src/compiler/transformers/module/system.ts +++ b/src/compiler/transformers/module/system.ts @@ -539,7 +539,7 @@ namespace ts { /*typeArguments*/ undefined, [ createLiteral(idText(entry.exportClause.name)), - createAssignment(importVariableName, parameterName) + parameterName ] ) ) @@ -634,9 +634,7 @@ namespace ts { } function visitExportDeclaration(node: ExportDeclaration): VisitResult { - if (node.exportClause && isNamespaceExport(node.exportClause)) { - hoistVariableDeclaration(getLocalNameForExternalImport(node, currentSourceFile)!); // TODO: GH#18217 - } + Debug.assertDefined(node); return undefined; } diff --git a/tests/baselines/reference/exportAsNamespace1.js b/tests/baselines/reference/exportAsNamespace1.js index c876785b96229..04171c4d75f05 100644 --- a/tests/baselines/reference/exportAsNamespace1.js +++ b/tests/baselines/reference/exportAsNamespace1.js @@ -23,8 +23,7 @@ exports.b = 2; //// [1.js] "use strict"; exports.__esModule = true; -var ns = require("./0"); -exports.ns = ns; +exports.ns = require("./0"); ns.a; ns.b; //// [2.js] diff --git a/tests/baselines/reference/exportAsNamespace1_system.js b/tests/baselines/reference/exportAsNamespace1_system.js index a0359af5721e2..f326d4ad7fc20 100644 --- a/tests/baselines/reference/exportAsNamespace1_system.js +++ b/tests/baselines/reference/exportAsNamespace1_system.js @@ -31,12 +31,11 @@ System.register([], function (exports_1, context_1) { //// [1.js] System.register(["./0"], function (exports_1, context_1) { "use strict"; - var ns; var __moduleName = context_1 && context_1.id; return { setters: [ function (ns_1) { - exports_1("ns", ns = ns_1); + exports_1("ns", ns_1); } ], execute: function () { diff --git a/tests/baselines/reference/exportAsNamespace1_umd.js b/tests/baselines/reference/exportAsNamespace1_umd.js index 0c19caafa18bd..35d797c66b79a 100644 --- a/tests/baselines/reference/exportAsNamespace1_umd.js +++ b/tests/baselines/reference/exportAsNamespace1_umd.js @@ -42,8 +42,7 @@ foo.ns.b; })(function (require, exports) { "use strict"; exports.__esModule = true; - var ns = require("./0"); - exports.ns = ns; + exports.ns = require("./0"); ns.a; ns.b; }); diff --git a/tests/baselines/reference/exportAsNamespace2.js b/tests/baselines/reference/exportAsNamespace2.js index 97f1778e5a2db..80341d5a5b396 100644 --- a/tests/baselines/reference/exportAsNamespace2.js +++ b/tests/baselines/reference/exportAsNamespace2.js @@ -30,8 +30,7 @@ var __importStar = (this && this.__importStar) || function (mod) { return result; }; exports.__esModule = true; -var ns = __importStar(require("./0")); -exports.ns = ns; +exports.ns = __importStar(require("./0")); ns.a; ns.b; //// [2.js] diff --git a/tests/baselines/reference/exportAsNamespace2_system.js b/tests/baselines/reference/exportAsNamespace2_system.js index 1f54350eac0ba..8a4582bd4ce8b 100644 --- a/tests/baselines/reference/exportAsNamespace2_system.js +++ b/tests/baselines/reference/exportAsNamespace2_system.js @@ -31,12 +31,11 @@ System.register([], function (exports_1, context_1) { //// [1.js] System.register(["./0"], function (exports_1, context_1) { "use strict"; - var ns; var __moduleName = context_1 && context_1.id; return { setters: [ function (ns_1) { - exports_1("ns", ns = ns_1); + exports_1("ns", ns_1); } ], execute: function () { diff --git a/tests/baselines/reference/exportAsNamespace2_umd.js b/tests/baselines/reference/exportAsNamespace2_umd.js index f7ff19af22dbe..e01ba1ae3771e 100644 --- a/tests/baselines/reference/exportAsNamespace2_umd.js +++ b/tests/baselines/reference/exportAsNamespace2_umd.js @@ -49,8 +49,7 @@ var __importStar = (this && this.__importStar) || function (mod) { })(function (require, exports) { "use strict"; exports.__esModule = true; - var ns = __importStar(require("./0")); - exports.ns = ns; + exports.ns = __importStar(require("./0")); ns.a; ns.b; }); diff --git a/tests/baselines/reference/exportAsNamespace3.js b/tests/baselines/reference/exportAsNamespace3.js index 0b9ed7b56e9f4..b05708a69df8d 100644 --- a/tests/baselines/reference/exportAsNamespace3.js +++ b/tests/baselines/reference/exportAsNamespace3.js @@ -33,8 +33,7 @@ var __importStar = (this && this.__importStar) || function (mod) { return result; }; exports.__esModule = true; -var ns = __importStar(require("./0")); -exports.ns = ns; +exports.ns = __importStar(require("./0")); ns.a; ns.b; var ns = { a: 1, b: 2 }; From d5e927a3d80a8c7c2986aa5adb8699c10840a0de Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Fri, 20 Dec 2019 14:07:05 -0800 Subject: [PATCH 23/29] Use multi-module selection in test runner to cut down on duplication. --- .../es2020/modules/exportAsNamespace1.ts | 1 + .../es2020/modules/exportAsNamespace1_amd.ts | 16 ---------------- .../es2020/modules/exportAsNamespace1_esnext.ts | 16 ---------------- .../es2020/modules/exportAsNamespace1_system.ts | 16 ---------------- .../es2020/modules/exportAsNamespace1_umd.ts | 16 ---------------- .../es2020/modules/exportAsNamespace2.ts | 1 + .../es2020/modules/exportAsNamespace3.ts | 1 + 7 files changed, 3 insertions(+), 64 deletions(-) delete mode 100644 tests/cases/conformance/es2020/modules/exportAsNamespace1_amd.ts delete mode 100644 tests/cases/conformance/es2020/modules/exportAsNamespace1_esnext.ts delete mode 100644 tests/cases/conformance/es2020/modules/exportAsNamespace1_system.ts delete mode 100644 tests/cases/conformance/es2020/modules/exportAsNamespace1_umd.ts diff --git a/tests/cases/conformance/es2020/modules/exportAsNamespace1.ts b/tests/cases/conformance/es2020/modules/exportAsNamespace1.ts index d878d8b23a25c..6e6b5959e9709 100644 --- a/tests/cases/conformance/es2020/modules/exportAsNamespace1.ts +++ b/tests/cases/conformance/es2020/modules/exportAsNamespace1.ts @@ -1,3 +1,4 @@ +// @module: esnext, es2015, commonjs, amd, system, umd // @filename: 0.ts // @declaration: true export const a = 1; diff --git a/tests/cases/conformance/es2020/modules/exportAsNamespace1_amd.ts b/tests/cases/conformance/es2020/modules/exportAsNamespace1_amd.ts deleted file mode 100644 index 9f3ae86d3146f..0000000000000 --- a/tests/cases/conformance/es2020/modules/exportAsNamespace1_amd.ts +++ /dev/null @@ -1,16 +0,0 @@ -// @module: amd -// @declaration: true -// @filename: 0.ts -export const a = 1; -export const b = 2; - -// @filename: 1.ts -export * as ns from './0'; -ns.a; -ns.b; - -// @filename: 2.ts -import * as foo from './1' - -foo.ns.a; -foo.ns.b; \ No newline at end of file diff --git a/tests/cases/conformance/es2020/modules/exportAsNamespace1_esnext.ts b/tests/cases/conformance/es2020/modules/exportAsNamespace1_esnext.ts deleted file mode 100644 index 89a81da3b3781..0000000000000 --- a/tests/cases/conformance/es2020/modules/exportAsNamespace1_esnext.ts +++ /dev/null @@ -1,16 +0,0 @@ -// @module: esnext -// @declaration: true -// @filename: 0.ts -export const a = 1; -export const b = 2; - -// @filename: 1.ts -export * as ns from './0'; -ns.a; -ns.b; - -// @filename: 2.ts -import * as foo from './1' - -foo.ns.a; -foo.ns.b; \ No newline at end of file diff --git a/tests/cases/conformance/es2020/modules/exportAsNamespace1_system.ts b/tests/cases/conformance/es2020/modules/exportAsNamespace1_system.ts deleted file mode 100644 index 3b2be142e2431..0000000000000 --- a/tests/cases/conformance/es2020/modules/exportAsNamespace1_system.ts +++ /dev/null @@ -1,16 +0,0 @@ -// @module: system -// @declaration: true -// @filename: 0.ts -export const a = 1; -export const b = 2; - -// @filename: 1.ts -export * as ns from './0'; -ns.a; -ns.b; - -// @filename: 2.ts -import * as foo from './1' - -foo.ns.a; -foo.ns.b; \ No newline at end of file diff --git a/tests/cases/conformance/es2020/modules/exportAsNamespace1_umd.ts b/tests/cases/conformance/es2020/modules/exportAsNamespace1_umd.ts deleted file mode 100644 index 61f8556872d75..0000000000000 --- a/tests/cases/conformance/es2020/modules/exportAsNamespace1_umd.ts +++ /dev/null @@ -1,16 +0,0 @@ -// @module: umd -// @declaration: true -// @filename: 0.ts -export const a = 1; -export const b = 2; - -// @filename: 1.ts -export * as ns from './0'; -ns.a; -ns.b; - -// @filename: 2.ts -import * as foo from './1' - -foo.ns.a; -foo.ns.b; \ No newline at end of file diff --git a/tests/cases/conformance/es2020/modules/exportAsNamespace2.ts b/tests/cases/conformance/es2020/modules/exportAsNamespace2.ts index a39a88181b413..f5ca1df13b278 100644 --- a/tests/cases/conformance/es2020/modules/exportAsNamespace2.ts +++ b/tests/cases/conformance/es2020/modules/exportAsNamespace2.ts @@ -1,3 +1,4 @@ +// @module: esnext, es2015, commonjs, amd, system, umd // @filename: 0.ts // @declaration: true // @esModuleInterop: true diff --git a/tests/cases/conformance/es2020/modules/exportAsNamespace3.ts b/tests/cases/conformance/es2020/modules/exportAsNamespace3.ts index a046438eb92c6..f652a0ca6c695 100644 --- a/tests/cases/conformance/es2020/modules/exportAsNamespace3.ts +++ b/tests/cases/conformance/es2020/modules/exportAsNamespace3.ts @@ -1,3 +1,4 @@ +// @module: esnext, es2015, commonjs, amd, system, umd // @filename: 0.ts // @declaration: true // @esModuleInterop: true From aa969ac8455c8b7379ae5daf5cbae2deaf52af46 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Fri, 20 Dec 2019 14:16:05 -0800 Subject: [PATCH 24/29] Accepted baselines. --- ...exportAsNamespace1(module=amd).errors.txt} | 0 .../exportAsNamespace1(module=amd).js | 48 ++++++++++ ...=> exportAsNamespace1(module=amd).symbols} | 0 ...s => exportAsNamespace1(module=amd).types} | 0 ...tAsNamespace1(module=commonjs).errors.txt} | 0 ...=> exportAsNamespace1(module=commonjs).js} | 0 ...portAsNamespace1(module=commonjs).symbols} | 0 ...exportAsNamespace1(module=commonjs).types} | 0 ...portAsNamespace1(module=es2015).errors.txt | 22 +++++ .../exportAsNamespace1(module=es2015).js | 37 ++++++++ .../exportAsNamespace1(module=es2015).symbols | 32 +++++++ .../exportAsNamespace1(module=es2015).types | 41 ++++++++ ...portAsNamespace1(module=esnext).errors.txt | 22 +++++ .../exportAsNamespace1(module=esnext).js | 37 ++++++++ .../exportAsNamespace1(module=esnext).symbols | 32 +++++++ .../exportAsNamespace1(module=esnext).types | 41 ++++++++ ...portAsNamespace1(module=system).errors.txt | 22 +++++ .../exportAsNamespace1(module=system).js | 72 ++++++++++++++ .../exportAsNamespace1(module=system).symbols | 32 +++++++ .../exportAsNamespace1(module=system).types | 41 ++++++++ .../exportAsNamespace1(module=umd).errors.txt | 22 +++++ .../exportAsNamespace1(module=umd).js | 73 +++++++++++++++ .../exportAsNamespace1(module=umd).symbols | 32 +++++++ .../exportAsNamespace1(module=umd).types | 41 ++++++++ .../exportAsNamespace2(module=amd).errors.txt | 22 +++++ .../exportAsNamespace2(module=amd).js | 56 +++++++++++ .../exportAsNamespace2(module=amd).symbols | 32 +++++++ .../exportAsNamespace2(module=amd).types | 41 ++++++++ ...rtAsNamespace2(module=commonjs).errors.txt | 22 +++++ ...=> exportAsNamespace2(module=commonjs).js} | 0 ...xportAsNamespace2(module=commonjs).symbols | 32 +++++++ .../exportAsNamespace2(module=commonjs).types | 41 ++++++++ ...portAsNamespace2(module=es2015).errors.txt | 22 +++++ .../exportAsNamespace2(module=es2015).js | 37 ++++++++ .../exportAsNamespace2(module=es2015).symbols | 32 +++++++ .../exportAsNamespace2(module=es2015).types | 41 ++++++++ ...portAsNamespace2(module=esnext).errors.txt | 22 +++++ .../exportAsNamespace2(module=esnext).js | 37 ++++++++ .../exportAsNamespace2(module=esnext).symbols | 32 +++++++ .../exportAsNamespace2(module=esnext).types | 41 ++++++++ ...portAsNamespace2(module=system).errors.txt | 22 +++++ .../exportAsNamespace2(module=system).js | 72 ++++++++++++++ .../exportAsNamespace2(module=system).symbols | 32 +++++++ .../exportAsNamespace2(module=system).types | 41 ++++++++ .../exportAsNamespace2(module=umd).errors.txt | 22 +++++ .../exportAsNamespace2(module=umd).js | 87 +++++++++++++++++ .../exportAsNamespace2(module=umd).symbols | 32 +++++++ .../exportAsNamespace2(module=umd).types | 41 ++++++++ ...exportAsNamespace3(module=amd).errors.txt} | 0 .../exportAsNamespace3(module=amd).js | 62 +++++++++++++ ...=> exportAsNamespace3(module=amd).symbols} | 0 ...s => exportAsNamespace3(module=amd).types} | 0 ...rtAsNamespace3(module=commonjs).errors.txt | 27 ++++++ ...=> exportAsNamespace3(module=commonjs).js} | 0 ...xportAsNamespace3(module=commonjs).symbols | 54 +++++++++++ .../exportAsNamespace3(module=commonjs).types | 59 ++++++++++++ ...portAsNamespace3(module=es2015).errors.txt | 27 ++++++ .../exportAsNamespace3(module=es2015).js | 43 +++++++++ .../exportAsNamespace3(module=es2015).symbols | 54 +++++++++++ .../exportAsNamespace3(module=es2015).types | 59 ++++++++++++ ...portAsNamespace3(module=esnext).errors.txt | 27 ++++++ .../exportAsNamespace3(module=esnext).js | 43 +++++++++ .../exportAsNamespace3(module=esnext).symbols | 54 +++++++++++ .../exportAsNamespace3(module=esnext).types | 59 ++++++++++++ ...portAsNamespace3(module=system).errors.txt | 27 ++++++ .../exportAsNamespace3(module=system).js | 79 ++++++++++++++++ .../exportAsNamespace3(module=system).symbols | 54 +++++++++++ .../exportAsNamespace3(module=system).types | 59 ++++++++++++ .../exportAsNamespace3(module=umd).errors.txt | 27 ++++++ .../exportAsNamespace3(module=umd).js | 93 +++++++++++++++++++ .../exportAsNamespace3(module=umd).symbols | 54 +++++++++++ .../exportAsNamespace3(module=umd).types | 59 ++++++++++++ 72 files changed, 2526 insertions(+) rename tests/baselines/reference/{exportAsNamespace1.errors.txt => exportAsNamespace1(module=amd).errors.txt} (100%) create mode 100644 tests/baselines/reference/exportAsNamespace1(module=amd).js rename tests/baselines/reference/{exportAsNamespace1.symbols => exportAsNamespace1(module=amd).symbols} (100%) rename tests/baselines/reference/{exportAsNamespace1.types => exportAsNamespace1(module=amd).types} (100%) rename tests/baselines/reference/{exportAsNamespace2.errors.txt => exportAsNamespace1(module=commonjs).errors.txt} (100%) rename tests/baselines/reference/{exportAsNamespace1.js => exportAsNamespace1(module=commonjs).js} (100%) rename tests/baselines/reference/{exportAsNamespace2.symbols => exportAsNamespace1(module=commonjs).symbols} (100%) rename tests/baselines/reference/{exportAsNamespace2.types => exportAsNamespace1(module=commonjs).types} (100%) create mode 100644 tests/baselines/reference/exportAsNamespace1(module=es2015).errors.txt create mode 100644 tests/baselines/reference/exportAsNamespace1(module=es2015).js create mode 100644 tests/baselines/reference/exportAsNamespace1(module=es2015).symbols create mode 100644 tests/baselines/reference/exportAsNamespace1(module=es2015).types create mode 100644 tests/baselines/reference/exportAsNamespace1(module=esnext).errors.txt create mode 100644 tests/baselines/reference/exportAsNamespace1(module=esnext).js create mode 100644 tests/baselines/reference/exportAsNamespace1(module=esnext).symbols create mode 100644 tests/baselines/reference/exportAsNamespace1(module=esnext).types create mode 100644 tests/baselines/reference/exportAsNamespace1(module=system).errors.txt create mode 100644 tests/baselines/reference/exportAsNamespace1(module=system).js create mode 100644 tests/baselines/reference/exportAsNamespace1(module=system).symbols create mode 100644 tests/baselines/reference/exportAsNamespace1(module=system).types create mode 100644 tests/baselines/reference/exportAsNamespace1(module=umd).errors.txt create mode 100644 tests/baselines/reference/exportAsNamespace1(module=umd).js create mode 100644 tests/baselines/reference/exportAsNamespace1(module=umd).symbols create mode 100644 tests/baselines/reference/exportAsNamespace1(module=umd).types create mode 100644 tests/baselines/reference/exportAsNamespace2(module=amd).errors.txt create mode 100644 tests/baselines/reference/exportAsNamespace2(module=amd).js create mode 100644 tests/baselines/reference/exportAsNamespace2(module=amd).symbols create mode 100644 tests/baselines/reference/exportAsNamespace2(module=amd).types create mode 100644 tests/baselines/reference/exportAsNamespace2(module=commonjs).errors.txt rename tests/baselines/reference/{exportAsNamespace2.js => exportAsNamespace2(module=commonjs).js} (100%) create mode 100644 tests/baselines/reference/exportAsNamespace2(module=commonjs).symbols create mode 100644 tests/baselines/reference/exportAsNamespace2(module=commonjs).types create mode 100644 tests/baselines/reference/exportAsNamespace2(module=es2015).errors.txt create mode 100644 tests/baselines/reference/exportAsNamespace2(module=es2015).js create mode 100644 tests/baselines/reference/exportAsNamespace2(module=es2015).symbols create mode 100644 tests/baselines/reference/exportAsNamespace2(module=es2015).types create mode 100644 tests/baselines/reference/exportAsNamespace2(module=esnext).errors.txt create mode 100644 tests/baselines/reference/exportAsNamespace2(module=esnext).js create mode 100644 tests/baselines/reference/exportAsNamespace2(module=esnext).symbols create mode 100644 tests/baselines/reference/exportAsNamespace2(module=esnext).types create mode 100644 tests/baselines/reference/exportAsNamespace2(module=system).errors.txt create mode 100644 tests/baselines/reference/exportAsNamespace2(module=system).js create mode 100644 tests/baselines/reference/exportAsNamespace2(module=system).symbols create mode 100644 tests/baselines/reference/exportAsNamespace2(module=system).types create mode 100644 tests/baselines/reference/exportAsNamespace2(module=umd).errors.txt create mode 100644 tests/baselines/reference/exportAsNamespace2(module=umd).js create mode 100644 tests/baselines/reference/exportAsNamespace2(module=umd).symbols create mode 100644 tests/baselines/reference/exportAsNamespace2(module=umd).types rename tests/baselines/reference/{exportAsNamespace3.errors.txt => exportAsNamespace3(module=amd).errors.txt} (100%) create mode 100644 tests/baselines/reference/exportAsNamespace3(module=amd).js rename tests/baselines/reference/{exportAsNamespace3.symbols => exportAsNamespace3(module=amd).symbols} (100%) rename tests/baselines/reference/{exportAsNamespace3.types => exportAsNamespace3(module=amd).types} (100%) create mode 100644 tests/baselines/reference/exportAsNamespace3(module=commonjs).errors.txt rename tests/baselines/reference/{exportAsNamespace3.js => exportAsNamespace3(module=commonjs).js} (100%) create mode 100644 tests/baselines/reference/exportAsNamespace3(module=commonjs).symbols create mode 100644 tests/baselines/reference/exportAsNamespace3(module=commonjs).types create mode 100644 tests/baselines/reference/exportAsNamespace3(module=es2015).errors.txt create mode 100644 tests/baselines/reference/exportAsNamespace3(module=es2015).js create mode 100644 tests/baselines/reference/exportAsNamespace3(module=es2015).symbols create mode 100644 tests/baselines/reference/exportAsNamespace3(module=es2015).types create mode 100644 tests/baselines/reference/exportAsNamespace3(module=esnext).errors.txt create mode 100644 tests/baselines/reference/exportAsNamespace3(module=esnext).js create mode 100644 tests/baselines/reference/exportAsNamespace3(module=esnext).symbols create mode 100644 tests/baselines/reference/exportAsNamespace3(module=esnext).types create mode 100644 tests/baselines/reference/exportAsNamespace3(module=system).errors.txt create mode 100644 tests/baselines/reference/exportAsNamespace3(module=system).js create mode 100644 tests/baselines/reference/exportAsNamespace3(module=system).symbols create mode 100644 tests/baselines/reference/exportAsNamespace3(module=system).types create mode 100644 tests/baselines/reference/exportAsNamespace3(module=umd).errors.txt create mode 100644 tests/baselines/reference/exportAsNamespace3(module=umd).js create mode 100644 tests/baselines/reference/exportAsNamespace3(module=umd).symbols create mode 100644 tests/baselines/reference/exportAsNamespace3(module=umd).types diff --git a/tests/baselines/reference/exportAsNamespace1.errors.txt b/tests/baselines/reference/exportAsNamespace1(module=amd).errors.txt similarity index 100% rename from tests/baselines/reference/exportAsNamespace1.errors.txt rename to tests/baselines/reference/exportAsNamespace1(module=amd).errors.txt diff --git a/tests/baselines/reference/exportAsNamespace1(module=amd).js b/tests/baselines/reference/exportAsNamespace1(module=amd).js new file mode 100644 index 0000000000000..ca45e03288c29 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace1(module=amd).js @@ -0,0 +1,48 @@ +//// [tests/cases/conformance/es2020/modules/exportAsNamespace1.ts] //// + +//// [0.ts] +export const a = 1; +export const b = 2; + +//// [1.ts] +export * as ns from './0'; +ns.a; +ns.b; + +//// [2.ts] +import * as foo from './1' + +foo.ns.a; +foo.ns.b; + +//// [0.js] +define(["require", "exports"], function (require, exports) { + "use strict"; + exports.__esModule = true; + exports.a = 1; + exports.b = 2; +}); +//// [1.js] +define(["require", "exports", "./0"], function (require, exports, ns) { + "use strict"; + exports.__esModule = true; + exports.ns = ns; + ns.a; + ns.b; +}); +//// [2.js] +define(["require", "exports", "./1"], function (require, exports, foo) { + "use strict"; + exports.__esModule = true; + foo.ns.a; + foo.ns.b; +}); + + +//// [0.d.ts] +export declare const a = 1; +export declare const b = 2; +//// [1.d.ts] +export * as ns from './0'; +//// [2.d.ts] +export {}; diff --git a/tests/baselines/reference/exportAsNamespace1.symbols b/tests/baselines/reference/exportAsNamespace1(module=amd).symbols similarity index 100% rename from tests/baselines/reference/exportAsNamespace1.symbols rename to tests/baselines/reference/exportAsNamespace1(module=amd).symbols diff --git a/tests/baselines/reference/exportAsNamespace1.types b/tests/baselines/reference/exportAsNamespace1(module=amd).types similarity index 100% rename from tests/baselines/reference/exportAsNamespace1.types rename to tests/baselines/reference/exportAsNamespace1(module=amd).types diff --git a/tests/baselines/reference/exportAsNamespace2.errors.txt b/tests/baselines/reference/exportAsNamespace1(module=commonjs).errors.txt similarity index 100% rename from tests/baselines/reference/exportAsNamespace2.errors.txt rename to tests/baselines/reference/exportAsNamespace1(module=commonjs).errors.txt diff --git a/tests/baselines/reference/exportAsNamespace1.js b/tests/baselines/reference/exportAsNamespace1(module=commonjs).js similarity index 100% rename from tests/baselines/reference/exportAsNamespace1.js rename to tests/baselines/reference/exportAsNamespace1(module=commonjs).js diff --git a/tests/baselines/reference/exportAsNamespace2.symbols b/tests/baselines/reference/exportAsNamespace1(module=commonjs).symbols similarity index 100% rename from tests/baselines/reference/exportAsNamespace2.symbols rename to tests/baselines/reference/exportAsNamespace1(module=commonjs).symbols diff --git a/tests/baselines/reference/exportAsNamespace2.types b/tests/baselines/reference/exportAsNamespace1(module=commonjs).types similarity index 100% rename from tests/baselines/reference/exportAsNamespace2.types rename to tests/baselines/reference/exportAsNamespace1(module=commonjs).types diff --git a/tests/baselines/reference/exportAsNamespace1(module=es2015).errors.txt b/tests/baselines/reference/exportAsNamespace1(module=es2015).errors.txt new file mode 100644 index 0000000000000..90b3756336ae0 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace1(module=es2015).errors.txt @@ -0,0 +1,22 @@ +tests/cases/conformance/es2020/modules/1.ts(2,1): error TS2304: Cannot find name 'ns'. +tests/cases/conformance/es2020/modules/1.ts(3,1): error TS2304: Cannot find name 'ns'. + + +==== tests/cases/conformance/es2020/modules/0.ts (0 errors) ==== + export const a = 1; + export const b = 2; + +==== tests/cases/conformance/es2020/modules/1.ts (2 errors) ==== + export * as ns from './0'; + ns.a; + ~~ +!!! error TS2304: Cannot find name 'ns'. + ns.b; + ~~ +!!! error TS2304: Cannot find name 'ns'. + +==== tests/cases/conformance/es2020/modules/2.ts (0 errors) ==== + import * as foo from './1' + + foo.ns.a; + foo.ns.b; \ No newline at end of file diff --git a/tests/baselines/reference/exportAsNamespace1(module=es2015).js b/tests/baselines/reference/exportAsNamespace1(module=es2015).js new file mode 100644 index 0000000000000..3deaebf27ef64 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace1(module=es2015).js @@ -0,0 +1,37 @@ +//// [tests/cases/conformance/es2020/modules/exportAsNamespace1.ts] //// + +//// [0.ts] +export const a = 1; +export const b = 2; + +//// [1.ts] +export * as ns from './0'; +ns.a; +ns.b; + +//// [2.ts] +import * as foo from './1' + +foo.ns.a; +foo.ns.b; + +//// [0.js] +export var a = 1; +export var b = 2; +//// [1.js] +export * as ns from './0'; +ns.a; +ns.b; +//// [2.js] +import * as foo from './1'; +foo.ns.a; +foo.ns.b; + + +//// [0.d.ts] +export declare const a = 1; +export declare const b = 2; +//// [1.d.ts] +export * as ns from './0'; +//// [2.d.ts] +export {}; diff --git a/tests/baselines/reference/exportAsNamespace1(module=es2015).symbols b/tests/baselines/reference/exportAsNamespace1(module=es2015).symbols new file mode 100644 index 0000000000000..3c6b7529361ba --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace1(module=es2015).symbols @@ -0,0 +1,32 @@ +=== tests/cases/conformance/es2020/modules/0.ts === +export const a = 1; +>a : Symbol(a, Decl(0.ts, 0, 12)) + +export const b = 2; +>b : Symbol(b, Decl(0.ts, 1, 12)) + +=== tests/cases/conformance/es2020/modules/1.ts === +export * as ns from './0'; +>ns : Symbol(ns, Decl(1.ts, 0, 11)) + +ns.a; +ns.b; + +=== tests/cases/conformance/es2020/modules/2.ts === +import * as foo from './1' +>foo : Symbol(foo, Decl(2.ts, 0, 6)) + +foo.ns.a; +>foo.ns.a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo : Symbol(foo, Decl(2.ts, 0, 6)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) + +foo.ns.b; +>foo.ns.b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo : Symbol(foo, Decl(2.ts, 0, 6)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) + diff --git a/tests/baselines/reference/exportAsNamespace1(module=es2015).types b/tests/baselines/reference/exportAsNamespace1(module=es2015).types new file mode 100644 index 0000000000000..43e33efa82b30 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace1(module=es2015).types @@ -0,0 +1,41 @@ +=== tests/cases/conformance/es2020/modules/0.ts === +export const a = 1; +>a : 1 +>1 : 1 + +export const b = 2; +>b : 2 +>2 : 2 + +=== tests/cases/conformance/es2020/modules/1.ts === +export * as ns from './0'; +>ns : typeof ns + +ns.a; +>ns.a : any +>ns : any +>a : any + +ns.b; +>ns.b : any +>ns : any +>b : any + +=== tests/cases/conformance/es2020/modules/2.ts === +import * as foo from './1' +>foo : typeof foo + +foo.ns.a; +>foo.ns.a : 1 +>foo.ns : typeof foo.ns +>foo : typeof foo +>ns : typeof foo.ns +>a : 1 + +foo.ns.b; +>foo.ns.b : 2 +>foo.ns : typeof foo.ns +>foo : typeof foo +>ns : typeof foo.ns +>b : 2 + diff --git a/tests/baselines/reference/exportAsNamespace1(module=esnext).errors.txt b/tests/baselines/reference/exportAsNamespace1(module=esnext).errors.txt new file mode 100644 index 0000000000000..90b3756336ae0 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace1(module=esnext).errors.txt @@ -0,0 +1,22 @@ +tests/cases/conformance/es2020/modules/1.ts(2,1): error TS2304: Cannot find name 'ns'. +tests/cases/conformance/es2020/modules/1.ts(3,1): error TS2304: Cannot find name 'ns'. + + +==== tests/cases/conformance/es2020/modules/0.ts (0 errors) ==== + export const a = 1; + export const b = 2; + +==== tests/cases/conformance/es2020/modules/1.ts (2 errors) ==== + export * as ns from './0'; + ns.a; + ~~ +!!! error TS2304: Cannot find name 'ns'. + ns.b; + ~~ +!!! error TS2304: Cannot find name 'ns'. + +==== tests/cases/conformance/es2020/modules/2.ts (0 errors) ==== + import * as foo from './1' + + foo.ns.a; + foo.ns.b; \ No newline at end of file diff --git a/tests/baselines/reference/exportAsNamespace1(module=esnext).js b/tests/baselines/reference/exportAsNamespace1(module=esnext).js new file mode 100644 index 0000000000000..3deaebf27ef64 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace1(module=esnext).js @@ -0,0 +1,37 @@ +//// [tests/cases/conformance/es2020/modules/exportAsNamespace1.ts] //// + +//// [0.ts] +export const a = 1; +export const b = 2; + +//// [1.ts] +export * as ns from './0'; +ns.a; +ns.b; + +//// [2.ts] +import * as foo from './1' + +foo.ns.a; +foo.ns.b; + +//// [0.js] +export var a = 1; +export var b = 2; +//// [1.js] +export * as ns from './0'; +ns.a; +ns.b; +//// [2.js] +import * as foo from './1'; +foo.ns.a; +foo.ns.b; + + +//// [0.d.ts] +export declare const a = 1; +export declare const b = 2; +//// [1.d.ts] +export * as ns from './0'; +//// [2.d.ts] +export {}; diff --git a/tests/baselines/reference/exportAsNamespace1(module=esnext).symbols b/tests/baselines/reference/exportAsNamespace1(module=esnext).symbols new file mode 100644 index 0000000000000..3c6b7529361ba --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace1(module=esnext).symbols @@ -0,0 +1,32 @@ +=== tests/cases/conformance/es2020/modules/0.ts === +export const a = 1; +>a : Symbol(a, Decl(0.ts, 0, 12)) + +export const b = 2; +>b : Symbol(b, Decl(0.ts, 1, 12)) + +=== tests/cases/conformance/es2020/modules/1.ts === +export * as ns from './0'; +>ns : Symbol(ns, Decl(1.ts, 0, 11)) + +ns.a; +ns.b; + +=== tests/cases/conformance/es2020/modules/2.ts === +import * as foo from './1' +>foo : Symbol(foo, Decl(2.ts, 0, 6)) + +foo.ns.a; +>foo.ns.a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo : Symbol(foo, Decl(2.ts, 0, 6)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) + +foo.ns.b; +>foo.ns.b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo : Symbol(foo, Decl(2.ts, 0, 6)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) + diff --git a/tests/baselines/reference/exportAsNamespace1(module=esnext).types b/tests/baselines/reference/exportAsNamespace1(module=esnext).types new file mode 100644 index 0000000000000..43e33efa82b30 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace1(module=esnext).types @@ -0,0 +1,41 @@ +=== tests/cases/conformance/es2020/modules/0.ts === +export const a = 1; +>a : 1 +>1 : 1 + +export const b = 2; +>b : 2 +>2 : 2 + +=== tests/cases/conformance/es2020/modules/1.ts === +export * as ns from './0'; +>ns : typeof ns + +ns.a; +>ns.a : any +>ns : any +>a : any + +ns.b; +>ns.b : any +>ns : any +>b : any + +=== tests/cases/conformance/es2020/modules/2.ts === +import * as foo from './1' +>foo : typeof foo + +foo.ns.a; +>foo.ns.a : 1 +>foo.ns : typeof foo.ns +>foo : typeof foo +>ns : typeof foo.ns +>a : 1 + +foo.ns.b; +>foo.ns.b : 2 +>foo.ns : typeof foo.ns +>foo : typeof foo +>ns : typeof foo.ns +>b : 2 + diff --git a/tests/baselines/reference/exportAsNamespace1(module=system).errors.txt b/tests/baselines/reference/exportAsNamespace1(module=system).errors.txt new file mode 100644 index 0000000000000..90b3756336ae0 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace1(module=system).errors.txt @@ -0,0 +1,22 @@ +tests/cases/conformance/es2020/modules/1.ts(2,1): error TS2304: Cannot find name 'ns'. +tests/cases/conformance/es2020/modules/1.ts(3,1): error TS2304: Cannot find name 'ns'. + + +==== tests/cases/conformance/es2020/modules/0.ts (0 errors) ==== + export const a = 1; + export const b = 2; + +==== tests/cases/conformance/es2020/modules/1.ts (2 errors) ==== + export * as ns from './0'; + ns.a; + ~~ +!!! error TS2304: Cannot find name 'ns'. + ns.b; + ~~ +!!! error TS2304: Cannot find name 'ns'. + +==== tests/cases/conformance/es2020/modules/2.ts (0 errors) ==== + import * as foo from './1' + + foo.ns.a; + foo.ns.b; \ No newline at end of file diff --git a/tests/baselines/reference/exportAsNamespace1(module=system).js b/tests/baselines/reference/exportAsNamespace1(module=system).js new file mode 100644 index 0000000000000..e40fec7232fe7 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace1(module=system).js @@ -0,0 +1,72 @@ +//// [tests/cases/conformance/es2020/modules/exportAsNamespace1.ts] //// + +//// [0.ts] +export const a = 1; +export const b = 2; + +//// [1.ts] +export * as ns from './0'; +ns.a; +ns.b; + +//// [2.ts] +import * as foo from './1' + +foo.ns.a; +foo.ns.b; + +//// [0.js] +System.register([], function (exports_1, context_1) { + "use strict"; + var a, b; + var __moduleName = context_1 && context_1.id; + return { + setters: [], + execute: function () { + exports_1("a", a = 1); + exports_1("b", b = 2); + } + }; +}); +//// [1.js] +System.register(["./0"], function (exports_1, context_1) { + "use strict"; + var __moduleName = context_1 && context_1.id; + return { + setters: [ + function (ns_1) { + exports_1("ns", ns_1); + } + ], + execute: function () { + ns.a; + ns.b; + } + }; +}); +//// [2.js] +System.register(["./1"], function (exports_1, context_1) { + "use strict"; + var foo; + var __moduleName = context_1 && context_1.id; + return { + setters: [ + function (foo_1) { + foo = foo_1; + } + ], + execute: function () { + foo.ns.a; + foo.ns.b; + } + }; +}); + + +//// [0.d.ts] +export declare const a = 1; +export declare const b = 2; +//// [1.d.ts] +export * as ns from './0'; +//// [2.d.ts] +export {}; diff --git a/tests/baselines/reference/exportAsNamespace1(module=system).symbols b/tests/baselines/reference/exportAsNamespace1(module=system).symbols new file mode 100644 index 0000000000000..3c6b7529361ba --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace1(module=system).symbols @@ -0,0 +1,32 @@ +=== tests/cases/conformance/es2020/modules/0.ts === +export const a = 1; +>a : Symbol(a, Decl(0.ts, 0, 12)) + +export const b = 2; +>b : Symbol(b, Decl(0.ts, 1, 12)) + +=== tests/cases/conformance/es2020/modules/1.ts === +export * as ns from './0'; +>ns : Symbol(ns, Decl(1.ts, 0, 11)) + +ns.a; +ns.b; + +=== tests/cases/conformance/es2020/modules/2.ts === +import * as foo from './1' +>foo : Symbol(foo, Decl(2.ts, 0, 6)) + +foo.ns.a; +>foo.ns.a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo : Symbol(foo, Decl(2.ts, 0, 6)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) + +foo.ns.b; +>foo.ns.b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo : Symbol(foo, Decl(2.ts, 0, 6)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) + diff --git a/tests/baselines/reference/exportAsNamespace1(module=system).types b/tests/baselines/reference/exportAsNamespace1(module=system).types new file mode 100644 index 0000000000000..43e33efa82b30 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace1(module=system).types @@ -0,0 +1,41 @@ +=== tests/cases/conformance/es2020/modules/0.ts === +export const a = 1; +>a : 1 +>1 : 1 + +export const b = 2; +>b : 2 +>2 : 2 + +=== tests/cases/conformance/es2020/modules/1.ts === +export * as ns from './0'; +>ns : typeof ns + +ns.a; +>ns.a : any +>ns : any +>a : any + +ns.b; +>ns.b : any +>ns : any +>b : any + +=== tests/cases/conformance/es2020/modules/2.ts === +import * as foo from './1' +>foo : typeof foo + +foo.ns.a; +>foo.ns.a : 1 +>foo.ns : typeof foo.ns +>foo : typeof foo +>ns : typeof foo.ns +>a : 1 + +foo.ns.b; +>foo.ns.b : 2 +>foo.ns : typeof foo.ns +>foo : typeof foo +>ns : typeof foo.ns +>b : 2 + diff --git a/tests/baselines/reference/exportAsNamespace1(module=umd).errors.txt b/tests/baselines/reference/exportAsNamespace1(module=umd).errors.txt new file mode 100644 index 0000000000000..90b3756336ae0 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace1(module=umd).errors.txt @@ -0,0 +1,22 @@ +tests/cases/conformance/es2020/modules/1.ts(2,1): error TS2304: Cannot find name 'ns'. +tests/cases/conformance/es2020/modules/1.ts(3,1): error TS2304: Cannot find name 'ns'. + + +==== tests/cases/conformance/es2020/modules/0.ts (0 errors) ==== + export const a = 1; + export const b = 2; + +==== tests/cases/conformance/es2020/modules/1.ts (2 errors) ==== + export * as ns from './0'; + ns.a; + ~~ +!!! error TS2304: Cannot find name 'ns'. + ns.b; + ~~ +!!! error TS2304: Cannot find name 'ns'. + +==== tests/cases/conformance/es2020/modules/2.ts (0 errors) ==== + import * as foo from './1' + + foo.ns.a; + foo.ns.b; \ No newline at end of file diff --git a/tests/baselines/reference/exportAsNamespace1(module=umd).js b/tests/baselines/reference/exportAsNamespace1(module=umd).js new file mode 100644 index 0000000000000..14ae069e61a88 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace1(module=umd).js @@ -0,0 +1,73 @@ +//// [tests/cases/conformance/es2020/modules/exportAsNamespace1.ts] //// + +//// [0.ts] +export const a = 1; +export const b = 2; + +//// [1.ts] +export * as ns from './0'; +ns.a; +ns.b; + +//// [2.ts] +import * as foo from './1' + +foo.ns.a; +foo.ns.b; + +//// [0.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"], factory); + } +})(function (require, exports) { + "use strict"; + exports.__esModule = true; + exports.a = 1; + exports.b = 2; +}); +//// [1.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", "./0"], factory); + } +})(function (require, exports) { + "use strict"; + exports.__esModule = true; + exports.ns = require("./0"); + ns.a; + ns.b; +}); +//// [2.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", "./1"], factory); + } +})(function (require, exports) { + "use strict"; + exports.__esModule = true; + var foo = require("./1"); + foo.ns.a; + foo.ns.b; +}); + + +//// [0.d.ts] +export declare const a = 1; +export declare const b = 2; +//// [1.d.ts] +export * as ns from './0'; +//// [2.d.ts] +export {}; diff --git a/tests/baselines/reference/exportAsNamespace1(module=umd).symbols b/tests/baselines/reference/exportAsNamespace1(module=umd).symbols new file mode 100644 index 0000000000000..3c6b7529361ba --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace1(module=umd).symbols @@ -0,0 +1,32 @@ +=== tests/cases/conformance/es2020/modules/0.ts === +export const a = 1; +>a : Symbol(a, Decl(0.ts, 0, 12)) + +export const b = 2; +>b : Symbol(b, Decl(0.ts, 1, 12)) + +=== tests/cases/conformance/es2020/modules/1.ts === +export * as ns from './0'; +>ns : Symbol(ns, Decl(1.ts, 0, 11)) + +ns.a; +ns.b; + +=== tests/cases/conformance/es2020/modules/2.ts === +import * as foo from './1' +>foo : Symbol(foo, Decl(2.ts, 0, 6)) + +foo.ns.a; +>foo.ns.a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo : Symbol(foo, Decl(2.ts, 0, 6)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) + +foo.ns.b; +>foo.ns.b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo : Symbol(foo, Decl(2.ts, 0, 6)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) + diff --git a/tests/baselines/reference/exportAsNamespace1(module=umd).types b/tests/baselines/reference/exportAsNamespace1(module=umd).types new file mode 100644 index 0000000000000..43e33efa82b30 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace1(module=umd).types @@ -0,0 +1,41 @@ +=== tests/cases/conformance/es2020/modules/0.ts === +export const a = 1; +>a : 1 +>1 : 1 + +export const b = 2; +>b : 2 +>2 : 2 + +=== tests/cases/conformance/es2020/modules/1.ts === +export * as ns from './0'; +>ns : typeof ns + +ns.a; +>ns.a : any +>ns : any +>a : any + +ns.b; +>ns.b : any +>ns : any +>b : any + +=== tests/cases/conformance/es2020/modules/2.ts === +import * as foo from './1' +>foo : typeof foo + +foo.ns.a; +>foo.ns.a : 1 +>foo.ns : typeof foo.ns +>foo : typeof foo +>ns : typeof foo.ns +>a : 1 + +foo.ns.b; +>foo.ns.b : 2 +>foo.ns : typeof foo.ns +>foo : typeof foo +>ns : typeof foo.ns +>b : 2 + diff --git a/tests/baselines/reference/exportAsNamespace2(module=amd).errors.txt b/tests/baselines/reference/exportAsNamespace2(module=amd).errors.txt new file mode 100644 index 0000000000000..90b3756336ae0 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace2(module=amd).errors.txt @@ -0,0 +1,22 @@ +tests/cases/conformance/es2020/modules/1.ts(2,1): error TS2304: Cannot find name 'ns'. +tests/cases/conformance/es2020/modules/1.ts(3,1): error TS2304: Cannot find name 'ns'. + + +==== tests/cases/conformance/es2020/modules/0.ts (0 errors) ==== + export const a = 1; + export const b = 2; + +==== tests/cases/conformance/es2020/modules/1.ts (2 errors) ==== + export * as ns from './0'; + ns.a; + ~~ +!!! error TS2304: Cannot find name 'ns'. + ns.b; + ~~ +!!! error TS2304: Cannot find name 'ns'. + +==== tests/cases/conformance/es2020/modules/2.ts (0 errors) ==== + import * as foo from './1' + + foo.ns.a; + foo.ns.b; \ No newline at end of file diff --git a/tests/baselines/reference/exportAsNamespace2(module=amd).js b/tests/baselines/reference/exportAsNamespace2(module=amd).js new file mode 100644 index 0000000000000..623de698072cd --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace2(module=amd).js @@ -0,0 +1,56 @@ +//// [tests/cases/conformance/es2020/modules/exportAsNamespace2.ts] //// + +//// [0.ts] +export const a = 1; +export const b = 2; + +//// [1.ts] +export * as ns from './0'; +ns.a; +ns.b; + +//// [2.ts] +import * as foo from './1' + +foo.ns.a; +foo.ns.b; + +//// [0.js] +define(["require", "exports"], function (require, exports) { + "use strict"; + exports.__esModule = true; + exports.a = 1; + exports.b = 2; +}); +//// [1.js] +define(["require", "exports", "./0"], function (require, exports, ns) { + "use strict"; + exports.__esModule = true; + exports.ns = ns; + ns.a; + ns.b; +}); +//// [2.js] +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; + result["default"] = mod; + return result; +}; +define(["require", "exports", "./1"], function (require, exports, foo) { + "use strict"; + exports.__esModule = true; + foo = __importStar(foo); + foo.ns.a; + foo.ns.b; +}); + + +//// [0.d.ts] +export declare const a = 1; +export declare const b = 2; +//// [1.d.ts] +export * as ns from './0'; +//// [2.d.ts] +export {}; diff --git a/tests/baselines/reference/exportAsNamespace2(module=amd).symbols b/tests/baselines/reference/exportAsNamespace2(module=amd).symbols new file mode 100644 index 0000000000000..3c6b7529361ba --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace2(module=amd).symbols @@ -0,0 +1,32 @@ +=== tests/cases/conformance/es2020/modules/0.ts === +export const a = 1; +>a : Symbol(a, Decl(0.ts, 0, 12)) + +export const b = 2; +>b : Symbol(b, Decl(0.ts, 1, 12)) + +=== tests/cases/conformance/es2020/modules/1.ts === +export * as ns from './0'; +>ns : Symbol(ns, Decl(1.ts, 0, 11)) + +ns.a; +ns.b; + +=== tests/cases/conformance/es2020/modules/2.ts === +import * as foo from './1' +>foo : Symbol(foo, Decl(2.ts, 0, 6)) + +foo.ns.a; +>foo.ns.a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo : Symbol(foo, Decl(2.ts, 0, 6)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) + +foo.ns.b; +>foo.ns.b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo : Symbol(foo, Decl(2.ts, 0, 6)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) + diff --git a/tests/baselines/reference/exportAsNamespace2(module=amd).types b/tests/baselines/reference/exportAsNamespace2(module=amd).types new file mode 100644 index 0000000000000..43e33efa82b30 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace2(module=amd).types @@ -0,0 +1,41 @@ +=== tests/cases/conformance/es2020/modules/0.ts === +export const a = 1; +>a : 1 +>1 : 1 + +export const b = 2; +>b : 2 +>2 : 2 + +=== tests/cases/conformance/es2020/modules/1.ts === +export * as ns from './0'; +>ns : typeof ns + +ns.a; +>ns.a : any +>ns : any +>a : any + +ns.b; +>ns.b : any +>ns : any +>b : any + +=== tests/cases/conformance/es2020/modules/2.ts === +import * as foo from './1' +>foo : typeof foo + +foo.ns.a; +>foo.ns.a : 1 +>foo.ns : typeof foo.ns +>foo : typeof foo +>ns : typeof foo.ns +>a : 1 + +foo.ns.b; +>foo.ns.b : 2 +>foo.ns : typeof foo.ns +>foo : typeof foo +>ns : typeof foo.ns +>b : 2 + diff --git a/tests/baselines/reference/exportAsNamespace2(module=commonjs).errors.txt b/tests/baselines/reference/exportAsNamespace2(module=commonjs).errors.txt new file mode 100644 index 0000000000000..90b3756336ae0 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace2(module=commonjs).errors.txt @@ -0,0 +1,22 @@ +tests/cases/conformance/es2020/modules/1.ts(2,1): error TS2304: Cannot find name 'ns'. +tests/cases/conformance/es2020/modules/1.ts(3,1): error TS2304: Cannot find name 'ns'. + + +==== tests/cases/conformance/es2020/modules/0.ts (0 errors) ==== + export const a = 1; + export const b = 2; + +==== tests/cases/conformance/es2020/modules/1.ts (2 errors) ==== + export * as ns from './0'; + ns.a; + ~~ +!!! error TS2304: Cannot find name 'ns'. + ns.b; + ~~ +!!! error TS2304: Cannot find name 'ns'. + +==== tests/cases/conformance/es2020/modules/2.ts (0 errors) ==== + import * as foo from './1' + + foo.ns.a; + foo.ns.b; \ No newline at end of file diff --git a/tests/baselines/reference/exportAsNamespace2.js b/tests/baselines/reference/exportAsNamespace2(module=commonjs).js similarity index 100% rename from tests/baselines/reference/exportAsNamespace2.js rename to tests/baselines/reference/exportAsNamespace2(module=commonjs).js diff --git a/tests/baselines/reference/exportAsNamespace2(module=commonjs).symbols b/tests/baselines/reference/exportAsNamespace2(module=commonjs).symbols new file mode 100644 index 0000000000000..3c6b7529361ba --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace2(module=commonjs).symbols @@ -0,0 +1,32 @@ +=== tests/cases/conformance/es2020/modules/0.ts === +export const a = 1; +>a : Symbol(a, Decl(0.ts, 0, 12)) + +export const b = 2; +>b : Symbol(b, Decl(0.ts, 1, 12)) + +=== tests/cases/conformance/es2020/modules/1.ts === +export * as ns from './0'; +>ns : Symbol(ns, Decl(1.ts, 0, 11)) + +ns.a; +ns.b; + +=== tests/cases/conformance/es2020/modules/2.ts === +import * as foo from './1' +>foo : Symbol(foo, Decl(2.ts, 0, 6)) + +foo.ns.a; +>foo.ns.a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo : Symbol(foo, Decl(2.ts, 0, 6)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) + +foo.ns.b; +>foo.ns.b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo : Symbol(foo, Decl(2.ts, 0, 6)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) + diff --git a/tests/baselines/reference/exportAsNamespace2(module=commonjs).types b/tests/baselines/reference/exportAsNamespace2(module=commonjs).types new file mode 100644 index 0000000000000..43e33efa82b30 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace2(module=commonjs).types @@ -0,0 +1,41 @@ +=== tests/cases/conformance/es2020/modules/0.ts === +export const a = 1; +>a : 1 +>1 : 1 + +export const b = 2; +>b : 2 +>2 : 2 + +=== tests/cases/conformance/es2020/modules/1.ts === +export * as ns from './0'; +>ns : typeof ns + +ns.a; +>ns.a : any +>ns : any +>a : any + +ns.b; +>ns.b : any +>ns : any +>b : any + +=== tests/cases/conformance/es2020/modules/2.ts === +import * as foo from './1' +>foo : typeof foo + +foo.ns.a; +>foo.ns.a : 1 +>foo.ns : typeof foo.ns +>foo : typeof foo +>ns : typeof foo.ns +>a : 1 + +foo.ns.b; +>foo.ns.b : 2 +>foo.ns : typeof foo.ns +>foo : typeof foo +>ns : typeof foo.ns +>b : 2 + diff --git a/tests/baselines/reference/exportAsNamespace2(module=es2015).errors.txt b/tests/baselines/reference/exportAsNamespace2(module=es2015).errors.txt new file mode 100644 index 0000000000000..90b3756336ae0 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace2(module=es2015).errors.txt @@ -0,0 +1,22 @@ +tests/cases/conformance/es2020/modules/1.ts(2,1): error TS2304: Cannot find name 'ns'. +tests/cases/conformance/es2020/modules/1.ts(3,1): error TS2304: Cannot find name 'ns'. + + +==== tests/cases/conformance/es2020/modules/0.ts (0 errors) ==== + export const a = 1; + export const b = 2; + +==== tests/cases/conformance/es2020/modules/1.ts (2 errors) ==== + export * as ns from './0'; + ns.a; + ~~ +!!! error TS2304: Cannot find name 'ns'. + ns.b; + ~~ +!!! error TS2304: Cannot find name 'ns'. + +==== tests/cases/conformance/es2020/modules/2.ts (0 errors) ==== + import * as foo from './1' + + foo.ns.a; + foo.ns.b; \ No newline at end of file diff --git a/tests/baselines/reference/exportAsNamespace2(module=es2015).js b/tests/baselines/reference/exportAsNamespace2(module=es2015).js new file mode 100644 index 0000000000000..5d2f1c65b3833 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace2(module=es2015).js @@ -0,0 +1,37 @@ +//// [tests/cases/conformance/es2020/modules/exportAsNamespace2.ts] //// + +//// [0.ts] +export const a = 1; +export const b = 2; + +//// [1.ts] +export * as ns from './0'; +ns.a; +ns.b; + +//// [2.ts] +import * as foo from './1' + +foo.ns.a; +foo.ns.b; + +//// [0.js] +export var a = 1; +export var b = 2; +//// [1.js] +export * as ns from './0'; +ns.a; +ns.b; +//// [2.js] +import * as foo from './1'; +foo.ns.a; +foo.ns.b; + + +//// [0.d.ts] +export declare const a = 1; +export declare const b = 2; +//// [1.d.ts] +export * as ns from './0'; +//// [2.d.ts] +export {}; diff --git a/tests/baselines/reference/exportAsNamespace2(module=es2015).symbols b/tests/baselines/reference/exportAsNamespace2(module=es2015).symbols new file mode 100644 index 0000000000000..3c6b7529361ba --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace2(module=es2015).symbols @@ -0,0 +1,32 @@ +=== tests/cases/conformance/es2020/modules/0.ts === +export const a = 1; +>a : Symbol(a, Decl(0.ts, 0, 12)) + +export const b = 2; +>b : Symbol(b, Decl(0.ts, 1, 12)) + +=== tests/cases/conformance/es2020/modules/1.ts === +export * as ns from './0'; +>ns : Symbol(ns, Decl(1.ts, 0, 11)) + +ns.a; +ns.b; + +=== tests/cases/conformance/es2020/modules/2.ts === +import * as foo from './1' +>foo : Symbol(foo, Decl(2.ts, 0, 6)) + +foo.ns.a; +>foo.ns.a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo : Symbol(foo, Decl(2.ts, 0, 6)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) + +foo.ns.b; +>foo.ns.b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo : Symbol(foo, Decl(2.ts, 0, 6)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) + diff --git a/tests/baselines/reference/exportAsNamespace2(module=es2015).types b/tests/baselines/reference/exportAsNamespace2(module=es2015).types new file mode 100644 index 0000000000000..43e33efa82b30 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace2(module=es2015).types @@ -0,0 +1,41 @@ +=== tests/cases/conformance/es2020/modules/0.ts === +export const a = 1; +>a : 1 +>1 : 1 + +export const b = 2; +>b : 2 +>2 : 2 + +=== tests/cases/conformance/es2020/modules/1.ts === +export * as ns from './0'; +>ns : typeof ns + +ns.a; +>ns.a : any +>ns : any +>a : any + +ns.b; +>ns.b : any +>ns : any +>b : any + +=== tests/cases/conformance/es2020/modules/2.ts === +import * as foo from './1' +>foo : typeof foo + +foo.ns.a; +>foo.ns.a : 1 +>foo.ns : typeof foo.ns +>foo : typeof foo +>ns : typeof foo.ns +>a : 1 + +foo.ns.b; +>foo.ns.b : 2 +>foo.ns : typeof foo.ns +>foo : typeof foo +>ns : typeof foo.ns +>b : 2 + diff --git a/tests/baselines/reference/exportAsNamespace2(module=esnext).errors.txt b/tests/baselines/reference/exportAsNamespace2(module=esnext).errors.txt new file mode 100644 index 0000000000000..90b3756336ae0 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace2(module=esnext).errors.txt @@ -0,0 +1,22 @@ +tests/cases/conformance/es2020/modules/1.ts(2,1): error TS2304: Cannot find name 'ns'. +tests/cases/conformance/es2020/modules/1.ts(3,1): error TS2304: Cannot find name 'ns'. + + +==== tests/cases/conformance/es2020/modules/0.ts (0 errors) ==== + export const a = 1; + export const b = 2; + +==== tests/cases/conformance/es2020/modules/1.ts (2 errors) ==== + export * as ns from './0'; + ns.a; + ~~ +!!! error TS2304: Cannot find name 'ns'. + ns.b; + ~~ +!!! error TS2304: Cannot find name 'ns'. + +==== tests/cases/conformance/es2020/modules/2.ts (0 errors) ==== + import * as foo from './1' + + foo.ns.a; + foo.ns.b; \ No newline at end of file diff --git a/tests/baselines/reference/exportAsNamespace2(module=esnext).js b/tests/baselines/reference/exportAsNamespace2(module=esnext).js new file mode 100644 index 0000000000000..5d2f1c65b3833 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace2(module=esnext).js @@ -0,0 +1,37 @@ +//// [tests/cases/conformance/es2020/modules/exportAsNamespace2.ts] //// + +//// [0.ts] +export const a = 1; +export const b = 2; + +//// [1.ts] +export * as ns from './0'; +ns.a; +ns.b; + +//// [2.ts] +import * as foo from './1' + +foo.ns.a; +foo.ns.b; + +//// [0.js] +export var a = 1; +export var b = 2; +//// [1.js] +export * as ns from './0'; +ns.a; +ns.b; +//// [2.js] +import * as foo from './1'; +foo.ns.a; +foo.ns.b; + + +//// [0.d.ts] +export declare const a = 1; +export declare const b = 2; +//// [1.d.ts] +export * as ns from './0'; +//// [2.d.ts] +export {}; diff --git a/tests/baselines/reference/exportAsNamespace2(module=esnext).symbols b/tests/baselines/reference/exportAsNamespace2(module=esnext).symbols new file mode 100644 index 0000000000000..3c6b7529361ba --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace2(module=esnext).symbols @@ -0,0 +1,32 @@ +=== tests/cases/conformance/es2020/modules/0.ts === +export const a = 1; +>a : Symbol(a, Decl(0.ts, 0, 12)) + +export const b = 2; +>b : Symbol(b, Decl(0.ts, 1, 12)) + +=== tests/cases/conformance/es2020/modules/1.ts === +export * as ns from './0'; +>ns : Symbol(ns, Decl(1.ts, 0, 11)) + +ns.a; +ns.b; + +=== tests/cases/conformance/es2020/modules/2.ts === +import * as foo from './1' +>foo : Symbol(foo, Decl(2.ts, 0, 6)) + +foo.ns.a; +>foo.ns.a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo : Symbol(foo, Decl(2.ts, 0, 6)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) + +foo.ns.b; +>foo.ns.b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo : Symbol(foo, Decl(2.ts, 0, 6)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) + diff --git a/tests/baselines/reference/exportAsNamespace2(module=esnext).types b/tests/baselines/reference/exportAsNamespace2(module=esnext).types new file mode 100644 index 0000000000000..43e33efa82b30 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace2(module=esnext).types @@ -0,0 +1,41 @@ +=== tests/cases/conformance/es2020/modules/0.ts === +export const a = 1; +>a : 1 +>1 : 1 + +export const b = 2; +>b : 2 +>2 : 2 + +=== tests/cases/conformance/es2020/modules/1.ts === +export * as ns from './0'; +>ns : typeof ns + +ns.a; +>ns.a : any +>ns : any +>a : any + +ns.b; +>ns.b : any +>ns : any +>b : any + +=== tests/cases/conformance/es2020/modules/2.ts === +import * as foo from './1' +>foo : typeof foo + +foo.ns.a; +>foo.ns.a : 1 +>foo.ns : typeof foo.ns +>foo : typeof foo +>ns : typeof foo.ns +>a : 1 + +foo.ns.b; +>foo.ns.b : 2 +>foo.ns : typeof foo.ns +>foo : typeof foo +>ns : typeof foo.ns +>b : 2 + diff --git a/tests/baselines/reference/exportAsNamespace2(module=system).errors.txt b/tests/baselines/reference/exportAsNamespace2(module=system).errors.txt new file mode 100644 index 0000000000000..90b3756336ae0 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace2(module=system).errors.txt @@ -0,0 +1,22 @@ +tests/cases/conformance/es2020/modules/1.ts(2,1): error TS2304: Cannot find name 'ns'. +tests/cases/conformance/es2020/modules/1.ts(3,1): error TS2304: Cannot find name 'ns'. + + +==== tests/cases/conformance/es2020/modules/0.ts (0 errors) ==== + export const a = 1; + export const b = 2; + +==== tests/cases/conformance/es2020/modules/1.ts (2 errors) ==== + export * as ns from './0'; + ns.a; + ~~ +!!! error TS2304: Cannot find name 'ns'. + ns.b; + ~~ +!!! error TS2304: Cannot find name 'ns'. + +==== tests/cases/conformance/es2020/modules/2.ts (0 errors) ==== + import * as foo from './1' + + foo.ns.a; + foo.ns.b; \ No newline at end of file diff --git a/tests/baselines/reference/exportAsNamespace2(module=system).js b/tests/baselines/reference/exportAsNamespace2(module=system).js new file mode 100644 index 0000000000000..a7f324958e4a9 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace2(module=system).js @@ -0,0 +1,72 @@ +//// [tests/cases/conformance/es2020/modules/exportAsNamespace2.ts] //// + +//// [0.ts] +export const a = 1; +export const b = 2; + +//// [1.ts] +export * as ns from './0'; +ns.a; +ns.b; + +//// [2.ts] +import * as foo from './1' + +foo.ns.a; +foo.ns.b; + +//// [0.js] +System.register([], function (exports_1, context_1) { + "use strict"; + var a, b; + var __moduleName = context_1 && context_1.id; + return { + setters: [], + execute: function () { + exports_1("a", a = 1); + exports_1("b", b = 2); + } + }; +}); +//// [1.js] +System.register(["./0"], function (exports_1, context_1) { + "use strict"; + var __moduleName = context_1 && context_1.id; + return { + setters: [ + function (ns_1) { + exports_1("ns", ns_1); + } + ], + execute: function () { + ns.a; + ns.b; + } + }; +}); +//// [2.js] +System.register(["./1"], function (exports_1, context_1) { + "use strict"; + var foo; + var __moduleName = context_1 && context_1.id; + return { + setters: [ + function (foo_1) { + foo = foo_1; + } + ], + execute: function () { + foo.ns.a; + foo.ns.b; + } + }; +}); + + +//// [0.d.ts] +export declare const a = 1; +export declare const b = 2; +//// [1.d.ts] +export * as ns from './0'; +//// [2.d.ts] +export {}; diff --git a/tests/baselines/reference/exportAsNamespace2(module=system).symbols b/tests/baselines/reference/exportAsNamespace2(module=system).symbols new file mode 100644 index 0000000000000..3c6b7529361ba --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace2(module=system).symbols @@ -0,0 +1,32 @@ +=== tests/cases/conformance/es2020/modules/0.ts === +export const a = 1; +>a : Symbol(a, Decl(0.ts, 0, 12)) + +export const b = 2; +>b : Symbol(b, Decl(0.ts, 1, 12)) + +=== tests/cases/conformance/es2020/modules/1.ts === +export * as ns from './0'; +>ns : Symbol(ns, Decl(1.ts, 0, 11)) + +ns.a; +ns.b; + +=== tests/cases/conformance/es2020/modules/2.ts === +import * as foo from './1' +>foo : Symbol(foo, Decl(2.ts, 0, 6)) + +foo.ns.a; +>foo.ns.a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo : Symbol(foo, Decl(2.ts, 0, 6)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) + +foo.ns.b; +>foo.ns.b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo : Symbol(foo, Decl(2.ts, 0, 6)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) + diff --git a/tests/baselines/reference/exportAsNamespace2(module=system).types b/tests/baselines/reference/exportAsNamespace2(module=system).types new file mode 100644 index 0000000000000..43e33efa82b30 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace2(module=system).types @@ -0,0 +1,41 @@ +=== tests/cases/conformance/es2020/modules/0.ts === +export const a = 1; +>a : 1 +>1 : 1 + +export const b = 2; +>b : 2 +>2 : 2 + +=== tests/cases/conformance/es2020/modules/1.ts === +export * as ns from './0'; +>ns : typeof ns + +ns.a; +>ns.a : any +>ns : any +>a : any + +ns.b; +>ns.b : any +>ns : any +>b : any + +=== tests/cases/conformance/es2020/modules/2.ts === +import * as foo from './1' +>foo : typeof foo + +foo.ns.a; +>foo.ns.a : 1 +>foo.ns : typeof foo.ns +>foo : typeof foo +>ns : typeof foo.ns +>a : 1 + +foo.ns.b; +>foo.ns.b : 2 +>foo.ns : typeof foo.ns +>foo : typeof foo +>ns : typeof foo.ns +>b : 2 + diff --git a/tests/baselines/reference/exportAsNamespace2(module=umd).errors.txt b/tests/baselines/reference/exportAsNamespace2(module=umd).errors.txt new file mode 100644 index 0000000000000..90b3756336ae0 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace2(module=umd).errors.txt @@ -0,0 +1,22 @@ +tests/cases/conformance/es2020/modules/1.ts(2,1): error TS2304: Cannot find name 'ns'. +tests/cases/conformance/es2020/modules/1.ts(3,1): error TS2304: Cannot find name 'ns'. + + +==== tests/cases/conformance/es2020/modules/0.ts (0 errors) ==== + export const a = 1; + export const b = 2; + +==== tests/cases/conformance/es2020/modules/1.ts (2 errors) ==== + export * as ns from './0'; + ns.a; + ~~ +!!! error TS2304: Cannot find name 'ns'. + ns.b; + ~~ +!!! error TS2304: Cannot find name 'ns'. + +==== tests/cases/conformance/es2020/modules/2.ts (0 errors) ==== + import * as foo from './1' + + foo.ns.a; + foo.ns.b; \ No newline at end of file diff --git a/tests/baselines/reference/exportAsNamespace2(module=umd).js b/tests/baselines/reference/exportAsNamespace2(module=umd).js new file mode 100644 index 0000000000000..dda2e48a8ab9a --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace2(module=umd).js @@ -0,0 +1,87 @@ +//// [tests/cases/conformance/es2020/modules/exportAsNamespace2.ts] //// + +//// [0.ts] +export const a = 1; +export const b = 2; + +//// [1.ts] +export * as ns from './0'; +ns.a; +ns.b; + +//// [2.ts] +import * as foo from './1' + +foo.ns.a; +foo.ns.b; + +//// [0.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"], factory); + } +})(function (require, exports) { + "use strict"; + exports.__esModule = true; + exports.a = 1; + exports.b = 2; +}); +//// [1.js] +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; + result["default"] = mod; + return result; +}; +(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", "./0"], factory); + } +})(function (require, exports) { + "use strict"; + exports.__esModule = true; + exports.ns = __importStar(require("./0")); + ns.a; + ns.b; +}); +//// [2.js] +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; + result["default"] = mod; + return result; +}; +(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", "./1"], factory); + } +})(function (require, exports) { + "use strict"; + exports.__esModule = true; + var foo = __importStar(require("./1")); + foo.ns.a; + foo.ns.b; +}); + + +//// [0.d.ts] +export declare const a = 1; +export declare const b = 2; +//// [1.d.ts] +export * as ns from './0'; +//// [2.d.ts] +export {}; diff --git a/tests/baselines/reference/exportAsNamespace2(module=umd).symbols b/tests/baselines/reference/exportAsNamespace2(module=umd).symbols new file mode 100644 index 0000000000000..3c6b7529361ba --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace2(module=umd).symbols @@ -0,0 +1,32 @@ +=== tests/cases/conformance/es2020/modules/0.ts === +export const a = 1; +>a : Symbol(a, Decl(0.ts, 0, 12)) + +export const b = 2; +>b : Symbol(b, Decl(0.ts, 1, 12)) + +=== tests/cases/conformance/es2020/modules/1.ts === +export * as ns from './0'; +>ns : Symbol(ns, Decl(1.ts, 0, 11)) + +ns.a; +ns.b; + +=== tests/cases/conformance/es2020/modules/2.ts === +import * as foo from './1' +>foo : Symbol(foo, Decl(2.ts, 0, 6)) + +foo.ns.a; +>foo.ns.a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo : Symbol(foo, Decl(2.ts, 0, 6)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) + +foo.ns.b; +>foo.ns.b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo : Symbol(foo, Decl(2.ts, 0, 6)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) + diff --git a/tests/baselines/reference/exportAsNamespace2(module=umd).types b/tests/baselines/reference/exportAsNamespace2(module=umd).types new file mode 100644 index 0000000000000..43e33efa82b30 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace2(module=umd).types @@ -0,0 +1,41 @@ +=== tests/cases/conformance/es2020/modules/0.ts === +export const a = 1; +>a : 1 +>1 : 1 + +export const b = 2; +>b : 2 +>2 : 2 + +=== tests/cases/conformance/es2020/modules/1.ts === +export * as ns from './0'; +>ns : typeof ns + +ns.a; +>ns.a : any +>ns : any +>a : any + +ns.b; +>ns.b : any +>ns : any +>b : any + +=== tests/cases/conformance/es2020/modules/2.ts === +import * as foo from './1' +>foo : typeof foo + +foo.ns.a; +>foo.ns.a : 1 +>foo.ns : typeof foo.ns +>foo : typeof foo +>ns : typeof foo.ns +>a : 1 + +foo.ns.b; +>foo.ns.b : 2 +>foo.ns : typeof foo.ns +>foo : typeof foo +>ns : typeof foo.ns +>b : 2 + diff --git a/tests/baselines/reference/exportAsNamespace3.errors.txt b/tests/baselines/reference/exportAsNamespace3(module=amd).errors.txt similarity index 100% rename from tests/baselines/reference/exportAsNamespace3.errors.txt rename to tests/baselines/reference/exportAsNamespace3(module=amd).errors.txt diff --git a/tests/baselines/reference/exportAsNamespace3(module=amd).js b/tests/baselines/reference/exportAsNamespace3(module=amd).js new file mode 100644 index 0000000000000..0935ee0c33b18 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace3(module=amd).js @@ -0,0 +1,62 @@ +//// [tests/cases/conformance/es2020/modules/exportAsNamespace3.ts] //// + +//// [0.ts] +export const a = 1; +export const b = 2; + +//// [1.ts] +export * as ns from './0'; +ns.a; +ns.b; +let ns = {a: 1, b: 2} +ns.a; +ns.b; + +//// [2.ts] +import * as foo from './1' + +foo.ns.a; +foo.ns.b; + +//// [0.js] +define(["require", "exports"], function (require, exports) { + "use strict"; + exports.__esModule = true; + exports.a = 1; + exports.b = 2; +}); +//// [1.js] +define(["require", "exports", "./0"], function (require, exports, ns) { + "use strict"; + exports.__esModule = true; + exports.ns = ns; + ns.a; + ns.b; + var ns = { a: 1, b: 2 }; + ns.a; + ns.b; +}); +//// [2.js] +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; + result["default"] = mod; + return result; +}; +define(["require", "exports", "./1"], function (require, exports, foo) { + "use strict"; + exports.__esModule = true; + foo = __importStar(foo); + foo.ns.a; + foo.ns.b; +}); + + +//// [0.d.ts] +export declare const a = 1; +export declare const b = 2; +//// [1.d.ts] +export * as ns from './0'; +//// [2.d.ts] +export {}; diff --git a/tests/baselines/reference/exportAsNamespace3.symbols b/tests/baselines/reference/exportAsNamespace3(module=amd).symbols similarity index 100% rename from tests/baselines/reference/exportAsNamespace3.symbols rename to tests/baselines/reference/exportAsNamespace3(module=amd).symbols diff --git a/tests/baselines/reference/exportAsNamespace3.types b/tests/baselines/reference/exportAsNamespace3(module=amd).types similarity index 100% rename from tests/baselines/reference/exportAsNamespace3.types rename to tests/baselines/reference/exportAsNamespace3(module=amd).types diff --git a/tests/baselines/reference/exportAsNamespace3(module=commonjs).errors.txt b/tests/baselines/reference/exportAsNamespace3(module=commonjs).errors.txt new file mode 100644 index 0000000000000..eb0dcccdc79ed --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace3(module=commonjs).errors.txt @@ -0,0 +1,27 @@ +tests/cases/conformance/es2020/modules/1.ts(2,1): error TS2448: Block-scoped variable 'ns' used before its declaration. +tests/cases/conformance/es2020/modules/1.ts(3,1): error TS2448: Block-scoped variable 'ns' used before its declaration. + + +==== tests/cases/conformance/es2020/modules/0.ts (0 errors) ==== + export const a = 1; + export const b = 2; + +==== tests/cases/conformance/es2020/modules/1.ts (2 errors) ==== + export * as ns from './0'; + ns.a; + ~~ +!!! error TS2448: Block-scoped variable 'ns' used before its declaration. +!!! related TS2728 tests/cases/conformance/es2020/modules/1.ts:4:5: 'ns' is declared here. + ns.b; + ~~ +!!! error TS2448: Block-scoped variable 'ns' used before its declaration. +!!! related TS2728 tests/cases/conformance/es2020/modules/1.ts:4:5: 'ns' is declared here. + let ns = {a: 1, b: 2} + ns.a; + ns.b; + +==== tests/cases/conformance/es2020/modules/2.ts (0 errors) ==== + import * as foo from './1' + + foo.ns.a; + foo.ns.b; \ No newline at end of file diff --git a/tests/baselines/reference/exportAsNamespace3.js b/tests/baselines/reference/exportAsNamespace3(module=commonjs).js similarity index 100% rename from tests/baselines/reference/exportAsNamespace3.js rename to tests/baselines/reference/exportAsNamespace3(module=commonjs).js diff --git a/tests/baselines/reference/exportAsNamespace3(module=commonjs).symbols b/tests/baselines/reference/exportAsNamespace3(module=commonjs).symbols new file mode 100644 index 0000000000000..0414e93a36357 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace3(module=commonjs).symbols @@ -0,0 +1,54 @@ +=== tests/cases/conformance/es2020/modules/0.ts === +export const a = 1; +>a : Symbol(a, Decl(0.ts, 0, 12)) + +export const b = 2; +>b : Symbol(b, Decl(0.ts, 1, 12)) + +=== tests/cases/conformance/es2020/modules/1.ts === +export * as ns from './0'; +>ns : Symbol(ns, Decl(1.ts, 0, 11)) + +ns.a; +>ns.a : Symbol(a, Decl(1.ts, 3, 10)) +>ns : Symbol(ns, Decl(1.ts, 3, 3)) +>a : Symbol(a, Decl(1.ts, 3, 10)) + +ns.b; +>ns.b : Symbol(b, Decl(1.ts, 3, 15)) +>ns : Symbol(ns, Decl(1.ts, 3, 3)) +>b : Symbol(b, Decl(1.ts, 3, 15)) + +let ns = {a: 1, b: 2} +>ns : Symbol(ns, Decl(1.ts, 3, 3)) +>a : Symbol(a, Decl(1.ts, 3, 10)) +>b : Symbol(b, Decl(1.ts, 3, 15)) + +ns.a; +>ns.a : Symbol(a, Decl(1.ts, 3, 10)) +>ns : Symbol(ns, Decl(1.ts, 3, 3)) +>a : Symbol(a, Decl(1.ts, 3, 10)) + +ns.b; +>ns.b : Symbol(b, Decl(1.ts, 3, 15)) +>ns : Symbol(ns, Decl(1.ts, 3, 3)) +>b : Symbol(b, Decl(1.ts, 3, 15)) + +=== tests/cases/conformance/es2020/modules/2.ts === +import * as foo from './1' +>foo : Symbol(foo, Decl(2.ts, 0, 6)) + +foo.ns.a; +>foo.ns.a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo : Symbol(foo, Decl(2.ts, 0, 6)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) + +foo.ns.b; +>foo.ns.b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo : Symbol(foo, Decl(2.ts, 0, 6)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) + diff --git a/tests/baselines/reference/exportAsNamespace3(module=commonjs).types b/tests/baselines/reference/exportAsNamespace3(module=commonjs).types new file mode 100644 index 0000000000000..b6a314299970c --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace3(module=commonjs).types @@ -0,0 +1,59 @@ +=== tests/cases/conformance/es2020/modules/0.ts === +export const a = 1; +>a : 1 +>1 : 1 + +export const b = 2; +>b : 2 +>2 : 2 + +=== tests/cases/conformance/es2020/modules/1.ts === +export * as ns from './0'; +>ns : typeof import("tests/cases/conformance/es2020/modules/0") + +ns.a; +>ns.a : number +>ns : { a: number; b: number; } +>a : number + +ns.b; +>ns.b : number +>ns : { a: number; b: number; } +>b : number + +let ns = {a: 1, b: 2} +>ns : { a: number; b: number; } +>{a: 1, b: 2} : { a: number; b: number; } +>a : number +>1 : 1 +>b : number +>2 : 2 + +ns.a; +>ns.a : number +>ns : { a: number; b: number; } +>a : number + +ns.b; +>ns.b : number +>ns : { a: number; b: number; } +>b : number + +=== tests/cases/conformance/es2020/modules/2.ts === +import * as foo from './1' +>foo : typeof foo + +foo.ns.a; +>foo.ns.a : 1 +>foo.ns : typeof foo.ns +>foo : typeof foo +>ns : typeof foo.ns +>a : 1 + +foo.ns.b; +>foo.ns.b : 2 +>foo.ns : typeof foo.ns +>foo : typeof foo +>ns : typeof foo.ns +>b : 2 + diff --git a/tests/baselines/reference/exportAsNamespace3(module=es2015).errors.txt b/tests/baselines/reference/exportAsNamespace3(module=es2015).errors.txt new file mode 100644 index 0000000000000..eb0dcccdc79ed --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace3(module=es2015).errors.txt @@ -0,0 +1,27 @@ +tests/cases/conformance/es2020/modules/1.ts(2,1): error TS2448: Block-scoped variable 'ns' used before its declaration. +tests/cases/conformance/es2020/modules/1.ts(3,1): error TS2448: Block-scoped variable 'ns' used before its declaration. + + +==== tests/cases/conformance/es2020/modules/0.ts (0 errors) ==== + export const a = 1; + export const b = 2; + +==== tests/cases/conformance/es2020/modules/1.ts (2 errors) ==== + export * as ns from './0'; + ns.a; + ~~ +!!! error TS2448: Block-scoped variable 'ns' used before its declaration. +!!! related TS2728 tests/cases/conformance/es2020/modules/1.ts:4:5: 'ns' is declared here. + ns.b; + ~~ +!!! error TS2448: Block-scoped variable 'ns' used before its declaration. +!!! related TS2728 tests/cases/conformance/es2020/modules/1.ts:4:5: 'ns' is declared here. + let ns = {a: 1, b: 2} + ns.a; + ns.b; + +==== tests/cases/conformance/es2020/modules/2.ts (0 errors) ==== + import * as foo from './1' + + foo.ns.a; + foo.ns.b; \ No newline at end of file diff --git a/tests/baselines/reference/exportAsNamespace3(module=es2015).js b/tests/baselines/reference/exportAsNamespace3(module=es2015).js new file mode 100644 index 0000000000000..af04da95e0d7e --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace3(module=es2015).js @@ -0,0 +1,43 @@ +//// [tests/cases/conformance/es2020/modules/exportAsNamespace3.ts] //// + +//// [0.ts] +export const a = 1; +export const b = 2; + +//// [1.ts] +export * as ns from './0'; +ns.a; +ns.b; +let ns = {a: 1, b: 2} +ns.a; +ns.b; + +//// [2.ts] +import * as foo from './1' + +foo.ns.a; +foo.ns.b; + +//// [0.js] +export var a = 1; +export var b = 2; +//// [1.js] +export * as ns from './0'; +ns.a; +ns.b; +var ns = { a: 1, b: 2 }; +ns.a; +ns.b; +//// [2.js] +import * as foo from './1'; +foo.ns.a; +foo.ns.b; + + +//// [0.d.ts] +export declare const a = 1; +export declare const b = 2; +//// [1.d.ts] +export * as ns from './0'; +//// [2.d.ts] +export {}; diff --git a/tests/baselines/reference/exportAsNamespace3(module=es2015).symbols b/tests/baselines/reference/exportAsNamespace3(module=es2015).symbols new file mode 100644 index 0000000000000..0414e93a36357 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace3(module=es2015).symbols @@ -0,0 +1,54 @@ +=== tests/cases/conformance/es2020/modules/0.ts === +export const a = 1; +>a : Symbol(a, Decl(0.ts, 0, 12)) + +export const b = 2; +>b : Symbol(b, Decl(0.ts, 1, 12)) + +=== tests/cases/conformance/es2020/modules/1.ts === +export * as ns from './0'; +>ns : Symbol(ns, Decl(1.ts, 0, 11)) + +ns.a; +>ns.a : Symbol(a, Decl(1.ts, 3, 10)) +>ns : Symbol(ns, Decl(1.ts, 3, 3)) +>a : Symbol(a, Decl(1.ts, 3, 10)) + +ns.b; +>ns.b : Symbol(b, Decl(1.ts, 3, 15)) +>ns : Symbol(ns, Decl(1.ts, 3, 3)) +>b : Symbol(b, Decl(1.ts, 3, 15)) + +let ns = {a: 1, b: 2} +>ns : Symbol(ns, Decl(1.ts, 3, 3)) +>a : Symbol(a, Decl(1.ts, 3, 10)) +>b : Symbol(b, Decl(1.ts, 3, 15)) + +ns.a; +>ns.a : Symbol(a, Decl(1.ts, 3, 10)) +>ns : Symbol(ns, Decl(1.ts, 3, 3)) +>a : Symbol(a, Decl(1.ts, 3, 10)) + +ns.b; +>ns.b : Symbol(b, Decl(1.ts, 3, 15)) +>ns : Symbol(ns, Decl(1.ts, 3, 3)) +>b : Symbol(b, Decl(1.ts, 3, 15)) + +=== tests/cases/conformance/es2020/modules/2.ts === +import * as foo from './1' +>foo : Symbol(foo, Decl(2.ts, 0, 6)) + +foo.ns.a; +>foo.ns.a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo : Symbol(foo, Decl(2.ts, 0, 6)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) + +foo.ns.b; +>foo.ns.b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo : Symbol(foo, Decl(2.ts, 0, 6)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) + diff --git a/tests/baselines/reference/exportAsNamespace3(module=es2015).types b/tests/baselines/reference/exportAsNamespace3(module=es2015).types new file mode 100644 index 0000000000000..b6a314299970c --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace3(module=es2015).types @@ -0,0 +1,59 @@ +=== tests/cases/conformance/es2020/modules/0.ts === +export const a = 1; +>a : 1 +>1 : 1 + +export const b = 2; +>b : 2 +>2 : 2 + +=== tests/cases/conformance/es2020/modules/1.ts === +export * as ns from './0'; +>ns : typeof import("tests/cases/conformance/es2020/modules/0") + +ns.a; +>ns.a : number +>ns : { a: number; b: number; } +>a : number + +ns.b; +>ns.b : number +>ns : { a: number; b: number; } +>b : number + +let ns = {a: 1, b: 2} +>ns : { a: number; b: number; } +>{a: 1, b: 2} : { a: number; b: number; } +>a : number +>1 : 1 +>b : number +>2 : 2 + +ns.a; +>ns.a : number +>ns : { a: number; b: number; } +>a : number + +ns.b; +>ns.b : number +>ns : { a: number; b: number; } +>b : number + +=== tests/cases/conformance/es2020/modules/2.ts === +import * as foo from './1' +>foo : typeof foo + +foo.ns.a; +>foo.ns.a : 1 +>foo.ns : typeof foo.ns +>foo : typeof foo +>ns : typeof foo.ns +>a : 1 + +foo.ns.b; +>foo.ns.b : 2 +>foo.ns : typeof foo.ns +>foo : typeof foo +>ns : typeof foo.ns +>b : 2 + diff --git a/tests/baselines/reference/exportAsNamespace3(module=esnext).errors.txt b/tests/baselines/reference/exportAsNamespace3(module=esnext).errors.txt new file mode 100644 index 0000000000000..eb0dcccdc79ed --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace3(module=esnext).errors.txt @@ -0,0 +1,27 @@ +tests/cases/conformance/es2020/modules/1.ts(2,1): error TS2448: Block-scoped variable 'ns' used before its declaration. +tests/cases/conformance/es2020/modules/1.ts(3,1): error TS2448: Block-scoped variable 'ns' used before its declaration. + + +==== tests/cases/conformance/es2020/modules/0.ts (0 errors) ==== + export const a = 1; + export const b = 2; + +==== tests/cases/conformance/es2020/modules/1.ts (2 errors) ==== + export * as ns from './0'; + ns.a; + ~~ +!!! error TS2448: Block-scoped variable 'ns' used before its declaration. +!!! related TS2728 tests/cases/conformance/es2020/modules/1.ts:4:5: 'ns' is declared here. + ns.b; + ~~ +!!! error TS2448: Block-scoped variable 'ns' used before its declaration. +!!! related TS2728 tests/cases/conformance/es2020/modules/1.ts:4:5: 'ns' is declared here. + let ns = {a: 1, b: 2} + ns.a; + ns.b; + +==== tests/cases/conformance/es2020/modules/2.ts (0 errors) ==== + import * as foo from './1' + + foo.ns.a; + foo.ns.b; \ No newline at end of file diff --git a/tests/baselines/reference/exportAsNamespace3(module=esnext).js b/tests/baselines/reference/exportAsNamespace3(module=esnext).js new file mode 100644 index 0000000000000..af04da95e0d7e --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace3(module=esnext).js @@ -0,0 +1,43 @@ +//// [tests/cases/conformance/es2020/modules/exportAsNamespace3.ts] //// + +//// [0.ts] +export const a = 1; +export const b = 2; + +//// [1.ts] +export * as ns from './0'; +ns.a; +ns.b; +let ns = {a: 1, b: 2} +ns.a; +ns.b; + +//// [2.ts] +import * as foo from './1' + +foo.ns.a; +foo.ns.b; + +//// [0.js] +export var a = 1; +export var b = 2; +//// [1.js] +export * as ns from './0'; +ns.a; +ns.b; +var ns = { a: 1, b: 2 }; +ns.a; +ns.b; +//// [2.js] +import * as foo from './1'; +foo.ns.a; +foo.ns.b; + + +//// [0.d.ts] +export declare const a = 1; +export declare const b = 2; +//// [1.d.ts] +export * as ns from './0'; +//// [2.d.ts] +export {}; diff --git a/tests/baselines/reference/exportAsNamespace3(module=esnext).symbols b/tests/baselines/reference/exportAsNamespace3(module=esnext).symbols new file mode 100644 index 0000000000000..0414e93a36357 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace3(module=esnext).symbols @@ -0,0 +1,54 @@ +=== tests/cases/conformance/es2020/modules/0.ts === +export const a = 1; +>a : Symbol(a, Decl(0.ts, 0, 12)) + +export const b = 2; +>b : Symbol(b, Decl(0.ts, 1, 12)) + +=== tests/cases/conformance/es2020/modules/1.ts === +export * as ns from './0'; +>ns : Symbol(ns, Decl(1.ts, 0, 11)) + +ns.a; +>ns.a : Symbol(a, Decl(1.ts, 3, 10)) +>ns : Symbol(ns, Decl(1.ts, 3, 3)) +>a : Symbol(a, Decl(1.ts, 3, 10)) + +ns.b; +>ns.b : Symbol(b, Decl(1.ts, 3, 15)) +>ns : Symbol(ns, Decl(1.ts, 3, 3)) +>b : Symbol(b, Decl(1.ts, 3, 15)) + +let ns = {a: 1, b: 2} +>ns : Symbol(ns, Decl(1.ts, 3, 3)) +>a : Symbol(a, Decl(1.ts, 3, 10)) +>b : Symbol(b, Decl(1.ts, 3, 15)) + +ns.a; +>ns.a : Symbol(a, Decl(1.ts, 3, 10)) +>ns : Symbol(ns, Decl(1.ts, 3, 3)) +>a : Symbol(a, Decl(1.ts, 3, 10)) + +ns.b; +>ns.b : Symbol(b, Decl(1.ts, 3, 15)) +>ns : Symbol(ns, Decl(1.ts, 3, 3)) +>b : Symbol(b, Decl(1.ts, 3, 15)) + +=== tests/cases/conformance/es2020/modules/2.ts === +import * as foo from './1' +>foo : Symbol(foo, Decl(2.ts, 0, 6)) + +foo.ns.a; +>foo.ns.a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo : Symbol(foo, Decl(2.ts, 0, 6)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) + +foo.ns.b; +>foo.ns.b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo : Symbol(foo, Decl(2.ts, 0, 6)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) + diff --git a/tests/baselines/reference/exportAsNamespace3(module=esnext).types b/tests/baselines/reference/exportAsNamespace3(module=esnext).types new file mode 100644 index 0000000000000..b6a314299970c --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace3(module=esnext).types @@ -0,0 +1,59 @@ +=== tests/cases/conformance/es2020/modules/0.ts === +export const a = 1; +>a : 1 +>1 : 1 + +export const b = 2; +>b : 2 +>2 : 2 + +=== tests/cases/conformance/es2020/modules/1.ts === +export * as ns from './0'; +>ns : typeof import("tests/cases/conformance/es2020/modules/0") + +ns.a; +>ns.a : number +>ns : { a: number; b: number; } +>a : number + +ns.b; +>ns.b : number +>ns : { a: number; b: number; } +>b : number + +let ns = {a: 1, b: 2} +>ns : { a: number; b: number; } +>{a: 1, b: 2} : { a: number; b: number; } +>a : number +>1 : 1 +>b : number +>2 : 2 + +ns.a; +>ns.a : number +>ns : { a: number; b: number; } +>a : number + +ns.b; +>ns.b : number +>ns : { a: number; b: number; } +>b : number + +=== tests/cases/conformance/es2020/modules/2.ts === +import * as foo from './1' +>foo : typeof foo + +foo.ns.a; +>foo.ns.a : 1 +>foo.ns : typeof foo.ns +>foo : typeof foo +>ns : typeof foo.ns +>a : 1 + +foo.ns.b; +>foo.ns.b : 2 +>foo.ns : typeof foo.ns +>foo : typeof foo +>ns : typeof foo.ns +>b : 2 + diff --git a/tests/baselines/reference/exportAsNamespace3(module=system).errors.txt b/tests/baselines/reference/exportAsNamespace3(module=system).errors.txt new file mode 100644 index 0000000000000..eb0dcccdc79ed --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace3(module=system).errors.txt @@ -0,0 +1,27 @@ +tests/cases/conformance/es2020/modules/1.ts(2,1): error TS2448: Block-scoped variable 'ns' used before its declaration. +tests/cases/conformance/es2020/modules/1.ts(3,1): error TS2448: Block-scoped variable 'ns' used before its declaration. + + +==== tests/cases/conformance/es2020/modules/0.ts (0 errors) ==== + export const a = 1; + export const b = 2; + +==== tests/cases/conformance/es2020/modules/1.ts (2 errors) ==== + export * as ns from './0'; + ns.a; + ~~ +!!! error TS2448: Block-scoped variable 'ns' used before its declaration. +!!! related TS2728 tests/cases/conformance/es2020/modules/1.ts:4:5: 'ns' is declared here. + ns.b; + ~~ +!!! error TS2448: Block-scoped variable 'ns' used before its declaration. +!!! related TS2728 tests/cases/conformance/es2020/modules/1.ts:4:5: 'ns' is declared here. + let ns = {a: 1, b: 2} + ns.a; + ns.b; + +==== tests/cases/conformance/es2020/modules/2.ts (0 errors) ==== + import * as foo from './1' + + foo.ns.a; + foo.ns.b; \ No newline at end of file diff --git a/tests/baselines/reference/exportAsNamespace3(module=system).js b/tests/baselines/reference/exportAsNamespace3(module=system).js new file mode 100644 index 0000000000000..2d153f8e6d246 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace3(module=system).js @@ -0,0 +1,79 @@ +//// [tests/cases/conformance/es2020/modules/exportAsNamespace3.ts] //// + +//// [0.ts] +export const a = 1; +export const b = 2; + +//// [1.ts] +export * as ns from './0'; +ns.a; +ns.b; +let ns = {a: 1, b: 2} +ns.a; +ns.b; + +//// [2.ts] +import * as foo from './1' + +foo.ns.a; +foo.ns.b; + +//// [0.js] +System.register([], function (exports_1, context_1) { + "use strict"; + var a, b; + var __moduleName = context_1 && context_1.id; + return { + setters: [], + execute: function () { + exports_1("a", a = 1); + exports_1("b", b = 2); + } + }; +}); +//// [1.js] +System.register(["./0"], function (exports_1, context_1) { + "use strict"; + var ns; + var __moduleName = context_1 && context_1.id; + return { + setters: [ + function (ns_1) { + exports_1("ns", ns_1); + } + ], + execute: function () { + ns.a; + ns.b; + ns = { a: 1, b: 2 }; + ns.a; + ns.b; + } + }; +}); +//// [2.js] +System.register(["./1"], function (exports_1, context_1) { + "use strict"; + var foo; + var __moduleName = context_1 && context_1.id; + return { + setters: [ + function (foo_1) { + foo = foo_1; + } + ], + execute: function () { + foo.ns.a; + foo.ns.b; + } + }; +}); + + +//// [0.d.ts] +export declare const a = 1; +export declare const b = 2; +//// [1.d.ts] +export * as ns from './0'; +//// [2.d.ts] +export {}; diff --git a/tests/baselines/reference/exportAsNamespace3(module=system).symbols b/tests/baselines/reference/exportAsNamespace3(module=system).symbols new file mode 100644 index 0000000000000..0414e93a36357 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace3(module=system).symbols @@ -0,0 +1,54 @@ +=== tests/cases/conformance/es2020/modules/0.ts === +export const a = 1; +>a : Symbol(a, Decl(0.ts, 0, 12)) + +export const b = 2; +>b : Symbol(b, Decl(0.ts, 1, 12)) + +=== tests/cases/conformance/es2020/modules/1.ts === +export * as ns from './0'; +>ns : Symbol(ns, Decl(1.ts, 0, 11)) + +ns.a; +>ns.a : Symbol(a, Decl(1.ts, 3, 10)) +>ns : Symbol(ns, Decl(1.ts, 3, 3)) +>a : Symbol(a, Decl(1.ts, 3, 10)) + +ns.b; +>ns.b : Symbol(b, Decl(1.ts, 3, 15)) +>ns : Symbol(ns, Decl(1.ts, 3, 3)) +>b : Symbol(b, Decl(1.ts, 3, 15)) + +let ns = {a: 1, b: 2} +>ns : Symbol(ns, Decl(1.ts, 3, 3)) +>a : Symbol(a, Decl(1.ts, 3, 10)) +>b : Symbol(b, Decl(1.ts, 3, 15)) + +ns.a; +>ns.a : Symbol(a, Decl(1.ts, 3, 10)) +>ns : Symbol(ns, Decl(1.ts, 3, 3)) +>a : Symbol(a, Decl(1.ts, 3, 10)) + +ns.b; +>ns.b : Symbol(b, Decl(1.ts, 3, 15)) +>ns : Symbol(ns, Decl(1.ts, 3, 3)) +>b : Symbol(b, Decl(1.ts, 3, 15)) + +=== tests/cases/conformance/es2020/modules/2.ts === +import * as foo from './1' +>foo : Symbol(foo, Decl(2.ts, 0, 6)) + +foo.ns.a; +>foo.ns.a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo : Symbol(foo, Decl(2.ts, 0, 6)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) + +foo.ns.b; +>foo.ns.b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo : Symbol(foo, Decl(2.ts, 0, 6)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) + diff --git a/tests/baselines/reference/exportAsNamespace3(module=system).types b/tests/baselines/reference/exportAsNamespace3(module=system).types new file mode 100644 index 0000000000000..b6a314299970c --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace3(module=system).types @@ -0,0 +1,59 @@ +=== tests/cases/conformance/es2020/modules/0.ts === +export const a = 1; +>a : 1 +>1 : 1 + +export const b = 2; +>b : 2 +>2 : 2 + +=== tests/cases/conformance/es2020/modules/1.ts === +export * as ns from './0'; +>ns : typeof import("tests/cases/conformance/es2020/modules/0") + +ns.a; +>ns.a : number +>ns : { a: number; b: number; } +>a : number + +ns.b; +>ns.b : number +>ns : { a: number; b: number; } +>b : number + +let ns = {a: 1, b: 2} +>ns : { a: number; b: number; } +>{a: 1, b: 2} : { a: number; b: number; } +>a : number +>1 : 1 +>b : number +>2 : 2 + +ns.a; +>ns.a : number +>ns : { a: number; b: number; } +>a : number + +ns.b; +>ns.b : number +>ns : { a: number; b: number; } +>b : number + +=== tests/cases/conformance/es2020/modules/2.ts === +import * as foo from './1' +>foo : typeof foo + +foo.ns.a; +>foo.ns.a : 1 +>foo.ns : typeof foo.ns +>foo : typeof foo +>ns : typeof foo.ns +>a : 1 + +foo.ns.b; +>foo.ns.b : 2 +>foo.ns : typeof foo.ns +>foo : typeof foo +>ns : typeof foo.ns +>b : 2 + diff --git a/tests/baselines/reference/exportAsNamespace3(module=umd).errors.txt b/tests/baselines/reference/exportAsNamespace3(module=umd).errors.txt new file mode 100644 index 0000000000000..eb0dcccdc79ed --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace3(module=umd).errors.txt @@ -0,0 +1,27 @@ +tests/cases/conformance/es2020/modules/1.ts(2,1): error TS2448: Block-scoped variable 'ns' used before its declaration. +tests/cases/conformance/es2020/modules/1.ts(3,1): error TS2448: Block-scoped variable 'ns' used before its declaration. + + +==== tests/cases/conformance/es2020/modules/0.ts (0 errors) ==== + export const a = 1; + export const b = 2; + +==== tests/cases/conformance/es2020/modules/1.ts (2 errors) ==== + export * as ns from './0'; + ns.a; + ~~ +!!! error TS2448: Block-scoped variable 'ns' used before its declaration. +!!! related TS2728 tests/cases/conformance/es2020/modules/1.ts:4:5: 'ns' is declared here. + ns.b; + ~~ +!!! error TS2448: Block-scoped variable 'ns' used before its declaration. +!!! related TS2728 tests/cases/conformance/es2020/modules/1.ts:4:5: 'ns' is declared here. + let ns = {a: 1, b: 2} + ns.a; + ns.b; + +==== tests/cases/conformance/es2020/modules/2.ts (0 errors) ==== + import * as foo from './1' + + foo.ns.a; + foo.ns.b; \ No newline at end of file diff --git a/tests/baselines/reference/exportAsNamespace3(module=umd).js b/tests/baselines/reference/exportAsNamespace3(module=umd).js new file mode 100644 index 0000000000000..11eed84883f3f --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace3(module=umd).js @@ -0,0 +1,93 @@ +//// [tests/cases/conformance/es2020/modules/exportAsNamespace3.ts] //// + +//// [0.ts] +export const a = 1; +export const b = 2; + +//// [1.ts] +export * as ns from './0'; +ns.a; +ns.b; +let ns = {a: 1, b: 2} +ns.a; +ns.b; + +//// [2.ts] +import * as foo from './1' + +foo.ns.a; +foo.ns.b; + +//// [0.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"], factory); + } +})(function (require, exports) { + "use strict"; + exports.__esModule = true; + exports.a = 1; + exports.b = 2; +}); +//// [1.js] +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; + result["default"] = mod; + return result; +}; +(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", "./0"], factory); + } +})(function (require, exports) { + "use strict"; + exports.__esModule = true; + exports.ns = __importStar(require("./0")); + ns.a; + ns.b; + var ns = { a: 1, b: 2 }; + ns.a; + ns.b; +}); +//// [2.js] +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; + result["default"] = mod; + return result; +}; +(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", "./1"], factory); + } +})(function (require, exports) { + "use strict"; + exports.__esModule = true; + var foo = __importStar(require("./1")); + foo.ns.a; + foo.ns.b; +}); + + +//// [0.d.ts] +export declare const a = 1; +export declare const b = 2; +//// [1.d.ts] +export * as ns from './0'; +//// [2.d.ts] +export {}; diff --git a/tests/baselines/reference/exportAsNamespace3(module=umd).symbols b/tests/baselines/reference/exportAsNamespace3(module=umd).symbols new file mode 100644 index 0000000000000..0414e93a36357 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace3(module=umd).symbols @@ -0,0 +1,54 @@ +=== tests/cases/conformance/es2020/modules/0.ts === +export const a = 1; +>a : Symbol(a, Decl(0.ts, 0, 12)) + +export const b = 2; +>b : Symbol(b, Decl(0.ts, 1, 12)) + +=== tests/cases/conformance/es2020/modules/1.ts === +export * as ns from './0'; +>ns : Symbol(ns, Decl(1.ts, 0, 11)) + +ns.a; +>ns.a : Symbol(a, Decl(1.ts, 3, 10)) +>ns : Symbol(ns, Decl(1.ts, 3, 3)) +>a : Symbol(a, Decl(1.ts, 3, 10)) + +ns.b; +>ns.b : Symbol(b, Decl(1.ts, 3, 15)) +>ns : Symbol(ns, Decl(1.ts, 3, 3)) +>b : Symbol(b, Decl(1.ts, 3, 15)) + +let ns = {a: 1, b: 2} +>ns : Symbol(ns, Decl(1.ts, 3, 3)) +>a : Symbol(a, Decl(1.ts, 3, 10)) +>b : Symbol(b, Decl(1.ts, 3, 15)) + +ns.a; +>ns.a : Symbol(a, Decl(1.ts, 3, 10)) +>ns : Symbol(ns, Decl(1.ts, 3, 3)) +>a : Symbol(a, Decl(1.ts, 3, 10)) + +ns.b; +>ns.b : Symbol(b, Decl(1.ts, 3, 15)) +>ns : Symbol(ns, Decl(1.ts, 3, 3)) +>b : Symbol(b, Decl(1.ts, 3, 15)) + +=== tests/cases/conformance/es2020/modules/2.ts === +import * as foo from './1' +>foo : Symbol(foo, Decl(2.ts, 0, 6)) + +foo.ns.a; +>foo.ns.a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo : Symbol(foo, Decl(2.ts, 0, 6)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) + +foo.ns.b; +>foo.ns.b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo : Symbol(foo, Decl(2.ts, 0, 6)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) + diff --git a/tests/baselines/reference/exportAsNamespace3(module=umd).types b/tests/baselines/reference/exportAsNamespace3(module=umd).types new file mode 100644 index 0000000000000..b6a314299970c --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace3(module=umd).types @@ -0,0 +1,59 @@ +=== tests/cases/conformance/es2020/modules/0.ts === +export const a = 1; +>a : 1 +>1 : 1 + +export const b = 2; +>b : 2 +>2 : 2 + +=== tests/cases/conformance/es2020/modules/1.ts === +export * as ns from './0'; +>ns : typeof import("tests/cases/conformance/es2020/modules/0") + +ns.a; +>ns.a : number +>ns : { a: number; b: number; } +>a : number + +ns.b; +>ns.b : number +>ns : { a: number; b: number; } +>b : number + +let ns = {a: 1, b: 2} +>ns : { a: number; b: number; } +>{a: 1, b: 2} : { a: number; b: number; } +>a : number +>1 : 1 +>b : number +>2 : 2 + +ns.a; +>ns.a : number +>ns : { a: number; b: number; } +>a : number + +ns.b; +>ns.b : number +>ns : { a: number; b: number; } +>b : number + +=== tests/cases/conformance/es2020/modules/2.ts === +import * as foo from './1' +>foo : typeof foo + +foo.ns.a; +>foo.ns.a : 1 +>foo.ns : typeof foo.ns +>foo : typeof foo +>ns : typeof foo.ns +>a : 1 + +foo.ns.b; +>foo.ns.b : 2 +>foo.ns : typeof foo.ns +>foo : typeof foo +>ns : typeof foo.ns +>b : 2 + From ef3be4a1c40c3fd99638f97214059aaf85a3cca5 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Fri, 20 Dec 2019 15:08:38 -0800 Subject: [PATCH 25/29] remove superfluous tests. --- .../es2020/modules/exportAsNamespace2_amd.ts | 17 ----------------- .../es2020/modules/exportAsNamespace2_esnext.ts | 17 ----------------- .../es2020/modules/exportAsNamespace2_system.ts | 17 ----------------- .../es2020/modules/exportAsNamespace2_umd.ts | 17 ----------------- 4 files changed, 68 deletions(-) delete mode 100644 tests/cases/conformance/es2020/modules/exportAsNamespace2_amd.ts delete mode 100644 tests/cases/conformance/es2020/modules/exportAsNamespace2_esnext.ts delete mode 100644 tests/cases/conformance/es2020/modules/exportAsNamespace2_system.ts delete mode 100644 tests/cases/conformance/es2020/modules/exportAsNamespace2_umd.ts diff --git a/tests/cases/conformance/es2020/modules/exportAsNamespace2_amd.ts b/tests/cases/conformance/es2020/modules/exportAsNamespace2_amd.ts deleted file mode 100644 index 7bf9dbd87b860..0000000000000 --- a/tests/cases/conformance/es2020/modules/exportAsNamespace2_amd.ts +++ /dev/null @@ -1,17 +0,0 @@ -// @module: amd -// @declaration: true -// @esModuleInterop: true -// @filename: 0.ts -export const a = 1; -export const b = 2; - -// @filename: 1.ts -export * as ns from './0'; -ns.a; -ns.b; - -// @filename: 2.ts -import * as foo from './1' - -foo.ns.a; -foo.ns.b; \ No newline at end of file diff --git a/tests/cases/conformance/es2020/modules/exportAsNamespace2_esnext.ts b/tests/cases/conformance/es2020/modules/exportAsNamespace2_esnext.ts deleted file mode 100644 index 9f8d4b7b63b41..0000000000000 --- a/tests/cases/conformance/es2020/modules/exportAsNamespace2_esnext.ts +++ /dev/null @@ -1,17 +0,0 @@ -// @module: esnext -// @declaration: true -// @esModuleInterop: true -// @filename: 0.ts -export const a = 1; -export const b = 2; - -// @filename: 1.ts -export * as ns from './0'; -ns.a; -ns.b; - -// @filename: 2.ts -import * as foo from './1' - -foo.ns.a; -foo.ns.b; \ No newline at end of file diff --git a/tests/cases/conformance/es2020/modules/exportAsNamespace2_system.ts b/tests/cases/conformance/es2020/modules/exportAsNamespace2_system.ts deleted file mode 100644 index c6788455b5668..0000000000000 --- a/tests/cases/conformance/es2020/modules/exportAsNamespace2_system.ts +++ /dev/null @@ -1,17 +0,0 @@ -// @module: system -// @declaration: true -// @esModuleInterop: true -// @filename: 0.ts -export const a = 1; -export const b = 2; - -// @filename: 1.ts -export * as ns from './0'; -ns.a; -ns.b; - -// @filename: 2.ts -import * as foo from './1' - -foo.ns.a; -foo.ns.b; \ No newline at end of file diff --git a/tests/cases/conformance/es2020/modules/exportAsNamespace2_umd.ts b/tests/cases/conformance/es2020/modules/exportAsNamespace2_umd.ts deleted file mode 100644 index 483fa891be5d5..0000000000000 --- a/tests/cases/conformance/es2020/modules/exportAsNamespace2_umd.ts +++ /dev/null @@ -1,17 +0,0 @@ -// @module: umd -// @declaration: true -// @esModuleInterop: true -// @filename: 0.ts -export const a = 1; -export const b = 2; - -// @filename: 1.ts -export * as ns from './0'; -ns.a; -ns.b; - -// @filename: 2.ts -import * as foo from './1' - -foo.ns.a; -foo.ns.b; \ No newline at end of file From a5e1d49ffc24ac01a3993f45e9c74a62f702fd8a Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Fri, 20 Dec 2019 15:19:55 -0800 Subject: [PATCH 26/29] Remove baseline. --- .../reference/exportAsNamespace2_esnext.js | 37 ------------------- 1 file changed, 37 deletions(-) delete mode 100644 tests/baselines/reference/exportAsNamespace2_esnext.js diff --git a/tests/baselines/reference/exportAsNamespace2_esnext.js b/tests/baselines/reference/exportAsNamespace2_esnext.js deleted file mode 100644 index e9c6bd1a20377..0000000000000 --- a/tests/baselines/reference/exportAsNamespace2_esnext.js +++ /dev/null @@ -1,37 +0,0 @@ -//// [tests/cases/conformance/es2020/modules/exportAsNamespace2_esnext.ts] //// - -//// [0.ts] -export const a = 1; -export const b = 2; - -//// [1.ts] -export * as ns from './0'; -ns.a; -ns.b; - -//// [2.ts] -import * as foo from './1' - -foo.ns.a; -foo.ns.b; - -//// [0.js] -export var a = 1; -export var b = 2; -//// [1.js] -export * as ns from './0'; -ns.a; -ns.b; -//// [2.js] -import * as foo from './1'; -foo.ns.a; -foo.ns.b; - - -//// [0.d.ts] -export declare const a = 1; -export declare const b = 2; -//// [1.d.ts] -export * as ns from './0'; -//// [2.d.ts] -export {}; From bbe5b334cd7a7d8ed73395afa1191c4c54c76cb1 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Fri, 20 Dec 2019 15:24:36 -0800 Subject: [PATCH 27/29] Downlevel `export * as ns` in es2015. --- src/compiler/transformers/module/es2015.ts | 38 ++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/src/compiler/transformers/module/es2015.ts b/src/compiler/transformers/module/es2015.ts index e1123d1248d9f..ff843b1e26236 100644 --- a/src/compiler/transformers/module/es2015.ts +++ b/src/compiler/transformers/module/es2015.ts @@ -44,6 +44,9 @@ namespace ts { return undefined; case SyntaxKind.ExportAssignment: return visitExportAssignment(node); + case SyntaxKind.ExportDeclaration: + const exportDecl = (node as ExportDeclaration); + return visitExportDeclaration(exportDecl); } return node; @@ -54,6 +57,41 @@ namespace ts { return node.isExportEquals ? undefined : node; } + function visitExportDeclaration(node: ExportDeclaration) { + // `export * as ns` only needs to be transformed in ES2015 + if (compilerOptions.module !== undefined && compilerOptions.module > ModuleKind.ES2015) { + return node; + } + + // Either ill-formed or don't need to be tranformed. + if (!node.exportClause || !isNamespaceExport(node.exportClause) || !node.moduleSpecifier) { + return node; + } + + const oldIdentifier = node.exportClause.name; + const synthName = getGeneratedNameForNode(oldIdentifier); + const importDecl = createImportDeclaration( + /*decorators*/ undefined, + /*modifiers*/ undefined, + createImportClause(/*name*/ undefined, + createNamespaceImport( + synthName + ) + ), + node.moduleSpecifier, + ); + setOriginalNode(importDecl, node.exportClause); + + const exportDecl = createExportDeclaration( + /*decorators*/ undefined, + /*modifiers*/ undefined, + createNamedExports([createExportSpecifier(synthName, oldIdentifier)]), + ); + setOriginalNode(exportDecl, node); + + return [importDecl, exportDecl]; + } + // // Emit Notification // From fcc6f92b4d271a546d01a2e28128285b2ae5826d Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Fri, 20 Dec 2019 15:24:59 -0800 Subject: [PATCH 28/29] Accepted baselines. --- tests/baselines/reference/exportAsNamespace1(module=es2015).js | 3 ++- tests/baselines/reference/exportAsNamespace2(module=es2015).js | 3 ++- tests/baselines/reference/exportAsNamespace3(module=es2015).js | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/baselines/reference/exportAsNamespace1(module=es2015).js b/tests/baselines/reference/exportAsNamespace1(module=es2015).js index 3deaebf27ef64..98017e97f3c42 100644 --- a/tests/baselines/reference/exportAsNamespace1(module=es2015).js +++ b/tests/baselines/reference/exportAsNamespace1(module=es2015).js @@ -19,7 +19,8 @@ foo.ns.b; export var a = 1; export var b = 2; //// [1.js] -export * as ns from './0'; +import * as ns_1 from './0'; +export { ns_1 as ns }; ns.a; ns.b; //// [2.js] diff --git a/tests/baselines/reference/exportAsNamespace2(module=es2015).js b/tests/baselines/reference/exportAsNamespace2(module=es2015).js index 5d2f1c65b3833..468d7968c5ccc 100644 --- a/tests/baselines/reference/exportAsNamespace2(module=es2015).js +++ b/tests/baselines/reference/exportAsNamespace2(module=es2015).js @@ -19,7 +19,8 @@ foo.ns.b; export var a = 1; export var b = 2; //// [1.js] -export * as ns from './0'; +import * as ns_1 from './0'; +export { ns_1 as ns }; ns.a; ns.b; //// [2.js] diff --git a/tests/baselines/reference/exportAsNamespace3(module=es2015).js b/tests/baselines/reference/exportAsNamespace3(module=es2015).js index af04da95e0d7e..46dd633b42b53 100644 --- a/tests/baselines/reference/exportAsNamespace3(module=es2015).js +++ b/tests/baselines/reference/exportAsNamespace3(module=es2015).js @@ -22,7 +22,8 @@ foo.ns.b; export var a = 1; export var b = 2; //// [1.js] -export * as ns from './0'; +import * as ns_1 from './0'; +export { ns_1 as ns }; ns.a; ns.b; var ns = { a: 1, b: 2 }; From ed4f9b5d94462566ba32898172d3338c6658c258 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Fri, 20 Dec 2019 15:27:33 -0800 Subject: [PATCH 29/29] Update names of things. --- src/compiler/transformer.ts | 2 +- .../transformers/module/{es2015.ts => esnextAnd2015.ts} | 2 +- src/compiler/tsconfig.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) rename src/compiler/transformers/module/{es2015.ts => esnextAnd2015.ts} (96%) diff --git a/src/compiler/transformer.ts b/src/compiler/transformer.ts index bd8f34ee128c6..f4932b8fa419c 100644 --- a/src/compiler/transformer.ts +++ b/src/compiler/transformer.ts @@ -4,7 +4,7 @@ namespace ts { switch (moduleKind) { case ModuleKind.ESNext: case ModuleKind.ES2015: - return transformES2015Module; + return transformECMAScriptModule; case ModuleKind.System: return transformSystemModule; default: diff --git a/src/compiler/transformers/module/es2015.ts b/src/compiler/transformers/module/esnextAnd2015.ts similarity index 96% rename from src/compiler/transformers/module/es2015.ts rename to src/compiler/transformers/module/esnextAnd2015.ts index ff843b1e26236..722c0ca770862 100644 --- a/src/compiler/transformers/module/es2015.ts +++ b/src/compiler/transformers/module/esnextAnd2015.ts @@ -1,6 +1,6 @@ /*@internal*/ namespace ts { - export function transformES2015Module(context: TransformationContext) { + export function transformECMAScriptModule(context: TransformationContext) { const compilerOptions = context.getCompilerOptions(); const previousOnEmitNode = context.onEmitNode; const previousOnSubstituteNode = context.onSubstituteNode; diff --git a/src/compiler/tsconfig.json b/src/compiler/tsconfig.json index ac072239eebb6..41048b59fdb22 100644 --- a/src/compiler/tsconfig.json +++ b/src/compiler/tsconfig.json @@ -51,7 +51,7 @@ "transformers/generators.ts", "transformers/module/module.ts", "transformers/module/system.ts", - "transformers/module/es2015.ts", + "transformers/module/esnextAnd2015.ts", "transformers/declarations/diagnostics.ts", "transformers/declarations.ts", "transformer.ts",