-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
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
Bugfix/disable module in harmony #3755
Conversation
ffbef21
to
f56e5d5
Compare
04938c8
to
e8d1271
Compare
allow dependencies to report errors too
e8d1271
to
828d5e3
Compare
Looks good. Still working on this? |
this.message += err.message; | ||
this.origin = this.module = module; | ||
this.error = err; | ||
} |
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.
class ModuleDependencyError extends Error {
constructor(module, err, loc) {
super(`${formatLocation(loc)} ${err.message}`);
this.name = "ModuleDependencyError";
this.details = err.stack.split("\n").slice(1).join("\n"); // err.stack.replace(/^./g, "")?
this.origin = this.module = module;
this.error = err;
}
}
Calling Error.captureStackTrace
is not necessary on native subclasses. The message can also just be given as the super
argument instead of assigning to this.message
. However, not calling Error.captureStackTrace
does leave the constructor itself as the top of the stack trace.
@@ -2,12 +2,14 @@ | |||
MIT License http://www.opensource.org/licenses/mit-license.php | |||
Author Tobias Koppers @sokra | |||
*/ | |||
var formatLocation = require("./formatLocation"); |
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.
const
var dep = new CommonJsInHarmonyDependency(this.state.module, "exports"); | ||
dep.loc = expr.loc; | ||
this.state.current.addDependency(dep); | ||
}); |
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.
All of these should only match if the user doesn't shadow them with their own binding, otherwise this would prevent using e.g. module
as an identifier (as often happens in webpack's own code).
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 Parser should automatically handle this. But I'll add a test case validating it.
var dep = new CommonJsInHarmonyDependency(this.state.module, "module"); | ||
dep.loc = expr.loc; | ||
this.state.current.addDependency(dep); | ||
}); |
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.
Any escape hatch (or alternative) for module.hot
? Or it is not a problem as a more specific expression module.hot
plugin would run before?
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.
expression module.hot
will run before expression module
. As expression module.hot
returns false it stops traversion.
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 is already tested by the HMR testcases for harmony modules.
Error.captureStackTrace(this, CommonJsInHarmonyWarning); | ||
this.name = "CommonJsInHarmonyWarning"; | ||
this.message = name + " is not allowed in EcmaScript module: This module was detected as EcmaScript module (import or export syntax was used). In such a module using '" + name + "' is not allowed."; | ||
} |
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.
class CommonJsInHarmonyWarning extends Error {
constructor (name) {
super(`${name} is not allowed in EcmaScript module: This module was detected as EcmaScript module (import or export syntax was used). In such a module using '${name}' is not allowed.`)
this.name = "CommonJsInHarmonyWarning"
}
}
xc as xc, | ||
xd as xd | ||
} |
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.
export { xa, xb, xc as xc, xd as xd } from "./module"
?
or is this specifically checking export
of import
ed symbol?
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 is an old test and I didn't want to change it more than necessary.
Looks good. |
Sorry I missed this. @sokra do you want a separate issue for that? |
uh you already merged it... I'll create a new PR... |
What kind of change does this PR introduce?
bugfix
Did you add tests for your changes?
yes
If relevant, link to documentation update:
N/A
Summary
emit errors if using AMD or CommonJS syntax in harmony modules
and some refactorings needed for this
Does this PR introduce a breaking change?
yes