Skip to content
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

Merged
merged 7 commits into from
Mar 29, 2018
Merged

Issue 6867 #6889

merged 7 commits into from
Mar 29, 2018

Conversation

Janpot
Copy link
Member

@Janpot Janpot commented Mar 28, 2018

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

Explain the motivation for making this change. What existing problem does the pull request solve?

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

export default (class A {

});

suffers from the same problem, and some other code probably too.

@jsf-clabot
Copy link

jsf-clabot commented Mar 28, 2018

CLA assistant check
All committers have signed the CLA.

lib/Parser.js Outdated
if (
statement.declaration.id &&
statement.declaration.type !== "FunctionExpression"
) {
Copy link
Member

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.

Copy link
Member

@ooflorent ooflorent Mar 28, 2018

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;
})
Copy link
Member

@Jessidhia Jessidhia Mar 28, 2018

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() {})

Copy link
Member

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 🤔

Copy link
Member

@ooflorent ooflorent Mar 28, 2018

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.

Copy link
Member

@sokra sokra left a 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

@Janpot
Copy link
Member Author

Janpot commented Mar 28, 2018

@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?

@ooflorent
Copy link
Member

@Janpot yes it is. You could test both node types.

@webpack-bot
Copy link
Contributor

@Janpot Thanks for your update.

I labeled the Pull Request so reviewers will review it again.

@sokra Please review the new changes.

I think it's messing up coverage results
@Jessidhia
Copy link
Member

Nah, it's definitely a separate issue. Webpack doesn't actually detect when an export is mutable (mutated) or immutable, it just guesses that function and const are immutable and everything else is mutable.

@Janpot
Copy link
Member Author

Janpot commented Mar 28, 2018

Could it be that the coverage went down, just because the amount of lines increased more than the amount of statements?

@ooflorent ooflorent closed this Mar 28, 2018
@ooflorent ooflorent reopened this Mar 28, 2018
@webpack-bot
Copy link
Contributor

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() {
Copy link
Member

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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Member

@Jessidhia Jessidhia left a 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() {
Copy link
Member

@Jessidhia Jessidhia Mar 29, 2018

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

@sokra sokra merged commit 1e7cc39 into webpack:master Mar 29, 2018
@sokra
Copy link
Member

sokra commented Mar 29, 2018

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants