-
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
Consider the commonjs module indicator as a module indicator #18490
Changes from 1 commit
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 |
---|---|---|
|
@@ -4,6 +4,9 @@ function foo(name) { | |
} | ||
|
||
//// [a_out.js] | ||
function foo(name) { | ||
var s = require("t/" + name); | ||
} | ||
define("a", ["require", "exports"], function (require, exports) { | ||
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. hmm.. this does not look good. we should not mess up the module output if we can. 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. not sure what to do though.. @rbuckton thoughts? 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. This file has an explicit |
||
"use strict"; | ||
function foo(name) { | ||
var s = require("t/" + name); | ||
} | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
//// [index.js] | ||
class Foo {} | ||
|
||
class Bar extends Foo {} | ||
|
||
module.exports = Bar; | ||
|
||
|
||
//// [index.js] | ||
var tslib_1 = require("tslib"); | ||
var Foo = /** @class */ (function () { | ||
function Foo() { | ||
} | ||
return Foo; | ||
}()); | ||
var Bar = /** @class */ (function (_super) { | ||
tslib_1.__extends(Bar, _super); | ||
function Bar() { | ||
return _super !== null && _super.apply(this, arguments) || this; | ||
} | ||
return Bar; | ||
}(Foo)); | ||
module.exports = Bar; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
=== tests/cases/compiler/index.js === | ||
class Foo {} | ||
>Foo : Symbol(Foo, Decl(index.js, 0, 0)) | ||
|
||
class Bar extends Foo {} | ||
>Bar : Symbol(Bar, Decl(index.js, 0, 12)) | ||
>Foo : Symbol(Foo, Decl(index.js, 0, 0)) | ||
|
||
module.exports = Bar; | ||
>module : Symbol(export=, Decl(index.js, 2, 24)) | ||
>exports : Symbol(export=, Decl(index.js, 2, 24)) | ||
>Bar : Symbol(Bar, Decl(index.js, 0, 12)) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
=== tests/cases/compiler/index.js === | ||
class Foo {} | ||
>Foo : Foo | ||
|
||
class Bar extends Foo {} | ||
>Bar : Bar | ||
>Foo : Foo | ||
|
||
module.exports = Bar; | ||
>module.exports = Bar : typeof Bar | ||
>module.exports : any | ||
>module : any | ||
>exports : any | ||
>Bar : typeof Bar | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// @allowJS: true | ||
// @outDir: ./out | ||
// @module: commonjs | ||
// @noEmitHelpers: true | ||
// @importHelpers: true | ||
// @filename: index.js | ||
class Foo {} | ||
|
||
class Bar extends Foo {} | ||
|
||
module.exports = Bar; |
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.
this seems like the best compromise here:
(!!node.commonJsModuleIndicator && getEmitModuleKind(compilerOptions) === ModuleKind.CommonJS)
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.
so what u think?
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.
It seems reasonable. Though anyone with mixed-mode compilations targeting commonjs where they use
require
in some global files is going to get sad when their global files start getting transpiled as modules. Though why we even support mixed mode compilations in the first place...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.
the other option is to do nothing and leave the current behavior.. which is broken on import helpers + js files (which could be a smaller group affected than by the proposed change)...
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.
mmmmmmm I think once limited to commonjs it's likely fine. The only difference other than helpers, which is what this aims to change, for module vs non-module would be that top level declarations are local to the file instead of global. And given that the commonjs module flag is only set in JS files, it's not like there'll be any potential interface or namespace merging going on; so it'd just be weather people expected the
var x
they declared in one file with arequire
to be visible in another file with arequire
..... except that's governed byisExternalModule
and notisEffectiveExternalModule
(since the latter only affects emit), so I'm pretty sure once limited to commonjs there's no obserable changes?