-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
improve module loading interoperability for babel #3586
Changes from 1 commit
54a4e9e
3aba5aa
e9d590f
75466e6
86d106a
a512e9e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2709,6 +2709,17 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { | |
} | ||
else { | ||
if (node.flags & NodeFlags.Default) { | ||
if (compilerOptions.module === ModuleKind.CommonJS || compilerOptions.module === ModuleKind.AMD || compilerOptions.module === ModuleKind.UMD) { | ||
write("Object.defineProperty(exports, \"__esModule\", {"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you want to emulate this automatically, putting the define property behind a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thanks! applied. |
||
writeLine(); | ||
increaseIndent(); | ||
// default value of configurable, enumerable, writable are `false`. | ||
write("value: true"); | ||
writeLine(); | ||
decreaseIndent(); | ||
write("};"); | ||
writeLine(); | ||
} | ||
if (languageVersion === ScriptTarget.ES3) { | ||
write("exports[\"default\"]"); | ||
} else { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
//// [es5-commonjs.ts] | ||
|
||
export default class A | ||
{ | ||
constructor () | ||
{ | ||
|
||
} | ||
|
||
public B() | ||
{ | ||
return 42; | ||
} | ||
} | ||
|
||
|
||
//// [es5-commonjs.js] | ||
var A = (function () { | ||
function A() { | ||
} | ||
A.prototype.B = function () { | ||
return 42; | ||
}; | ||
return A; | ||
})(); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}; | ||
exports.default = A; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
=== tests/cases/compiler/es5-commonjs.ts === | ||
|
||
export default class A | ||
>A : Symbol(A, Decl(es5-commonjs.ts, 0, 0)) | ||
{ | ||
constructor () | ||
{ | ||
|
||
} | ||
|
||
public B() | ||
>B : Symbol(B, Decl(es5-commonjs.ts, 6, 5)) | ||
{ | ||
return 42; | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
=== tests/cases/compiler/es5-commonjs.ts === | ||
|
||
export default class A | ||
>A : A | ||
{ | ||
constructor () | ||
{ | ||
|
||
} | ||
|
||
public B() | ||
>B : () => number | ||
{ | ||
return 42; | ||
>42 : number | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
//// [es5-system.ts] | ||
|
||
export default class A | ||
{ | ||
constructor () | ||
{ | ||
|
||
} | ||
|
||
public B() | ||
{ | ||
return 42; | ||
} | ||
} | ||
|
||
|
||
//// [es5-system.js] | ||
System.register([], function(exports_1) { | ||
var A; | ||
return { | ||
setters:[], | ||
execute: function() { | ||
A = (function () { | ||
function A() { | ||
} | ||
A.prototype.B = function () { | ||
return 42; | ||
}; | ||
return A; | ||
})(); | ||
exports_1("default", A); | ||
} | ||
} | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
=== tests/cases/compiler/es5-system.ts === | ||
|
||
export default class A | ||
>A : Symbol(A, Decl(es5-system.ts, 0, 0)) | ||
{ | ||
constructor () | ||
{ | ||
|
||
} | ||
|
||
public B() | ||
>B : Symbol(B, Decl(es5-system.ts, 6, 5)) | ||
{ | ||
return 42; | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
=== tests/cases/compiler/es5-system.ts === | ||
|
||
export default class A | ||
>A : A | ||
{ | ||
constructor () | ||
{ | ||
|
||
} | ||
|
||
public B() | ||
>B : () => number | ||
{ | ||
return 42; | ||
>42 : number | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// @target: ES5 | ||
// @sourcemap: false | ||
// @declaration: false | ||
// @module: commonjs | ||
|
||
export default class A | ||
{ | ||
constructor () | ||
{ | ||
|
||
} | ||
|
||
public B() | ||
{ | ||
return 42; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// @target: ES5 | ||
// @sourcemap: false | ||
// @declaration: false | ||
// @module: system | ||
|
||
export default class A | ||
{ | ||
constructor () | ||
{ | ||
|
||
} | ||
|
||
public B() | ||
{ | ||
return 42; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you also want to check that this module does not have any exported name called "__esModule" so as not to step on it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✅