Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/compiler/binder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2691,7 +2691,8 @@ namespace ts {
const flags = exportAssignmentIsAlias(node)
? SymbolFlags.Alias // An export= with an EntityNameExpression or a ClassExpression exports all meanings of that identifier or class
: SymbolFlags.Property | SymbolFlags.ExportValue | SymbolFlags.ValueModule;
declareSymbol(file.symbol.exports!, file.symbol, node, flags | SymbolFlags.Assignment, SymbolFlags.None);
const symbol = declareSymbol(file.symbol.exports!, file.symbol, node, flags | SymbolFlags.Assignment, SymbolFlags.None);
setValueDeclaration(symbol, node);
}

function bindThisPropertyAssignment(node: BindablePropertyAssignmentExpression | PropertyAccessExpression | LiteralLikeElementAccessExpression) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/b.js(1,8): error TS1259: Module '"/a"' can only be default-imported using the 'esModuleInterop' flag


==== /a.js (0 errors) ====
// https://github.com/microsoft/TypeScript/issues/34481


const alias = {};
module.exports = alias;

==== /b.js (1 errors) ====
import a from "./a";
~
!!! error TS1259: Module '"/a"' can only be default-imported using the 'esModuleInterop' flag
!!! related TS2594 /a.js:5:1: This module is declared with using 'export =', and can only be used with a default import when using the 'esModuleInterop' flag.

17 changes: 17 additions & 0 deletions tests/baselines/reference/javascriptImportDefaultBadExport.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
=== /a.js ===
// https://github.com/microsoft/TypeScript/issues/34481


const alias = {};
>alias : Symbol(alias, Decl(a.js, 3, 5))

module.exports = alias;
>module.exports : Symbol("/a", Decl(a.js, 0, 0))
>module : Symbol(export=, Decl(a.js, 3, 17))
>exports : Symbol(export=, Decl(a.js, 3, 17))
>alias : Symbol(alias, Decl(a.js, 3, 5))

=== /b.js ===
import a from "./a";
>a : Symbol(a, Decl(b.js, 0, 6))

19 changes: 19 additions & 0 deletions tests/baselines/reference/javascriptImportDefaultBadExport.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
=== /a.js ===
// https://github.com/microsoft/TypeScript/issues/34481


const alias = {};
>alias : {}
>{} : {}

module.exports = alias;
>module.exports = alias : {}
>module.exports : {}
>module : { "/a": {}; }
>exports : {}
>alias : {}

=== /b.js ===
import a from "./a";
>a : any

12 changes: 12 additions & 0 deletions tests/cases/compiler/javascriptImportDefaultBadExport.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// https://github.com/microsoft/TypeScript/issues/34481

// @allowJs: true
// @checkJs: true
// @noEmit: true

// @Filename: /a.js
const alias = {};
module.exports = alias;

// @Filename: /b.js
import a from "./a";