Skip to content

Make .insert{Before,After} work by default when the parent is an eport declaration#7040

Merged
nicolo-ribaudo merged 4 commits intobabel:masterfrom
nicolo-ribaudo:export-insert-before-after
Dec 18, 2017
Merged

Make .insert{Before,After} work by default when the parent is an eport declaration#7040
nicolo-ribaudo merged 4 commits intobabel:masterfrom
nicolo-ribaudo:export-insert-before-after

Conversation

@nicolo-ribaudo
Copy link
Copy Markdown
Member

Q                       A
Fixed Issues?
Patch: Bug Fix?
Major: Breaking Change?
Minor: New Feature? Yes
Tests Added + Pass? Yes
Documentation PR
Any Dependency Changes?
License MIT

This PR makes declarationPath.insertBefore() and declarationPath.insertAfter() work by default even if declarationPath.parentPath.isExportDeclaration().
Babel already handles it in a similar way when path.parentPath.isLabelledStatement(): https://astexplorer.net/#/gist/192e79a63708ad6195496dffe34b6fd7/35538c7478fe1340c9e8bdb2e6c40f24f5adc40b
As you can see by the diff, we already had to handle insertion before/after exported declarations in different places. Less special cases to think about -> less probability of forgetting about them.

This PR doesn't introduce breaking changes, because it only makes cases that previously threw do what it is actually expected.

It makes the output of insertAfter a bit nicer:

  In:
    export default 2;

  Out (Before):
    var _temp;
    export default (_temp = 2, x, _temp)

  Out (Now):
    export default 2;
    x
@nicolo-ribaudo nicolo-ribaudo added the PR: Internal 🏠 A type of pull request used for our changelog categories label Dec 17, 2017
@babel-bot
Copy link
Copy Markdown
Collaborator

babel-bot commented Dec 17, 2017

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/6215/

Copy link
Copy Markdown
Member

@existentialism existentialism left a comment

Choose a reason for hiding this comment

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

👍

@nicolo-ribaudo nicolo-ribaudo merged commit 68476b6 into babel:master Dec 18, 2017
@nicolo-ribaudo nicolo-ribaudo deleted the export-insert-before-after branch December 18, 2017 23:05
nicolo-ribaudo added a commit to nicolo-ribaudo/babel that referenced this pull request Dec 27, 2017
nicolo-ribaudo added a commit that referenced this pull request Dec 28, 2017
@lock lock bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Oct 5, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 5, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

outdated A closed issue/PR that is archived due to age. Recommended to make a new issue PR: Internal 🏠 A type of pull request used for our changelog categories

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants