-
-
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
Issue 6867 #6889
Issue 6867 #6889
Conversation
lib/Parser.js
Outdated
if ( | ||
statement.declaration.id && | ||
statement.declaration.type !== "FunctionExpression" | ||
) { |
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's possible that this was an attempt to workaround an old acorn bug where it'd incorrectly parse export default function () {}
as a function expression.
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.
In acorn 4, export default function() {
was parsed as a FunctionExpression
.
Since acorn 5 it is a FunctionDeclaration
with id=null
.
@@ -0,0 +1,3 @@ | |||
export default (function hello () { | |||
return 1; | |||
}) |
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.
I'd feel better if there were tests for each permutation.
// function _declaration_, id is null
// in native implementations the function is named "default"
export default function() {}
// function _expression_, id is null
// in native implementations the function is named "default"
export default (function() {})
// function _declaration_, id is "foo"
export default function foo() {
// this not working at runtime is currently a bug in webpack 😝
foo = function() {}
})
// function _expression_, id is "bar"
export default (function 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.
These same permutations also apply to class
declarations, but we probably don't need to test them here 🤔
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.
Acorn did the same for ClassDeclaration
and ClassExpression
. It may be worth testing 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.
see @Kovensky's review
@Kovensky @sokra export default (class A {
}); is breaking too, how do you feel about if (
statement.declaration.id &&
!statement.declaration.type.endsWith("Expression")
) ? is that too hacky? |
@Janpot yes it is. You could test both node types. |
I think it's messing up coverage results
Nah, it's definitely a separate issue. Webpack doesn't actually detect when an export is mutable (mutated) or immutable, it just guesses that |
Could it be that the coverage went down, just because the amount of lines increased more than the amount of statements? |
Thank you for your pull request! The most important CI builds succeeded, we’ll review the pull request soon. |
@@ -0,0 +1,57 @@ | |||
it("should compile default export unnamed function declaration", function() { |
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.
Could you move this test case from configCases
to cases
?
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.
done
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.
Other than the test messages looks OK
}); | ||
}); | ||
|
||
it("should compile default export named function expression", function() { |
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 declaration
/ class expression
; same for lines 30, 38 and 45
Thanks |
What kind of change does this PR introduce?
Bug fix for #6867
Did you add tests for your changes?
Yes, always
If relevant, link to documentation update:
Summary
Basically, I tried to compile a project with webpack 4, it didn't work.
#6867 contains more info on what's going on exactly.
Does this PR introduce a breaking change?
Only if you rely on it throwing errors when it shouldn't :)
Other information
Don't merge yet, I just realized
suffers from the same problem, and some other code probably too.