diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 647384c5a30..dc40e686eeb 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -1323,8 +1323,14 @@ namespace ts { } } + // ES6 exports are also visible locally (except for 'default'), but commonjs exports are not (except typedefs) if (name !== InternalSymbolName.Default && (result = lookup(moduleExports, name, meaning & SymbolFlags.ModuleMember))) { - break loop; + if (isSourceFile(location) && location.commonJsModuleIndicator && !result.declarations.some(isJSDocTypeAlias)) { + result = undefined; + } + else { + break loop; + } } break; case SyntaxKind.EnumDeclaration: diff --git a/tests/baselines/reference/exportPropertyAssignmentNameResolution.errors.txt b/tests/baselines/reference/exportPropertyAssignmentNameResolution.errors.txt new file mode 100644 index 00000000000..c5f4427cc45 --- /dev/null +++ b/tests/baselines/reference/exportPropertyAssignmentNameResolution.errors.txt @@ -0,0 +1,9 @@ +tests/cases/conformance/salsa/bug24492.js(2,5): error TS2304: Cannot find name 'D'. + + +==== tests/cases/conformance/salsa/bug24492.js (1 errors) ==== + module.exports.D = class { } + new D() + ~ +!!! error TS2304: Cannot find name 'D'. + \ No newline at end of file diff --git a/tests/baselines/reference/exportPropertyAssignmentNameResolution.symbols b/tests/baselines/reference/exportPropertyAssignmentNameResolution.symbols new file mode 100644 index 00000000000..e7da3bfc2b4 --- /dev/null +++ b/tests/baselines/reference/exportPropertyAssignmentNameResolution.symbols @@ -0,0 +1,8 @@ +=== tests/cases/conformance/salsa/bug24492.js === +module.exports.D = class { } +>module.exports : Symbol(D, Decl(bug24492.js, 0, 0)) +>module : Symbol(module) +>D : Symbol(D, Decl(bug24492.js, 0, 0)) + +new D() + diff --git a/tests/baselines/reference/exportPropertyAssignmentNameResolution.types b/tests/baselines/reference/exportPropertyAssignmentNameResolution.types new file mode 100644 index 00000000000..24553ae18c5 --- /dev/null +++ b/tests/baselines/reference/exportPropertyAssignmentNameResolution.types @@ -0,0 +1,14 @@ +=== tests/cases/conformance/salsa/bug24492.js === +module.exports.D = class { } +>module.exports.D = class { } : typeof D +>module.exports.D : any +>module.exports : any +>module : any +>exports : any +>D : any +>class { } : typeof D + +new D() +>new D() : any +>D : any + diff --git a/tests/cases/conformance/salsa/exportPropertyAssignmentNameResolution.ts b/tests/cases/conformance/salsa/exportPropertyAssignmentNameResolution.ts new file mode 100644 index 00000000000..3d131a2d3fd --- /dev/null +++ b/tests/cases/conformance/salsa/exportPropertyAssignmentNameResolution.ts @@ -0,0 +1,6 @@ +// @noEmit: true +// @allowJs: true +// @checkJs: true +// @Filename: bug24492.js +module.exports.D = class { } +new D() diff --git a/tests/cases/fourslash/refactorConvertToEs6Module_export_named.ts b/tests/cases/fourslash/refactorConvertToEs6Module_export_named.ts index f8eba2b0213..e7ee2908580 100644 --- a/tests/cases/fourslash/refactorConvertToEs6Module_export_named.ts +++ b/tests/cases/fourslash/refactorConvertToEs6Module_export_named.ts @@ -21,9 +21,7 @@ verify.codeFix({ description: "Convert to ES6 module", newFileContent: `export function f() {} -const _C = class { -}; -export { _C as C }; +export class C {} export const x = 0; export function a1() {} export function a2() { return 0; } diff --git a/tests/cases/fourslash/refactorConvertToEs6Module_export_namedClassExpression.ts b/tests/cases/fourslash/refactorConvertToEs6Module_export_namedClassExpression.ts index 47b8a5e0b32..e1cb86e8d68 100644 --- a/tests/cases/fourslash/refactorConvertToEs6Module_export_namedClassExpression.ts +++ b/tests/cases/fourslash/refactorConvertToEs6Module_export_namedClassExpression.ts @@ -10,12 +10,6 @@ verify.codeFix({ description: "Convert to ES6 module", newFileContent: -`const _C = class E { - static instance = new E(); -}; -export { _C as C }; -const _D = class D { - static instance = new D(); -}; -export { _D as D };`, +`export const C = class E { static instance = new E(); } +export class D { static instance = new D(); }`, }); diff --git a/tests/cases/fourslash/refactorConvertToEs6Module_expressionToDeclaration.ts b/tests/cases/fourslash/refactorConvertToEs6Module_expressionToDeclaration.ts index b360334767f..c91c726dbfd 100644 --- a/tests/cases/fourslash/refactorConvertToEs6Module_expressionToDeclaration.ts +++ b/tests/cases/fourslash/refactorConvertToEs6Module_expressionToDeclaration.ts @@ -4,13 +4,17 @@ // @target: esnext // @Filename: /a.js +////var C = {}; +////console.log(C); ////exports.f = async function* f(p) { p; } ////exports.C = class C extends D { m() {} } verify.codeFix({ description: "Convert to ES6 module", newFileContent: -`export async function* f(p) { p; } +`var C = {}; +console.log(C); +export async function* f(p) { p; } const _C = class C extends D { m() { } };