Plugin Ordering (Part 2)
- Dominant language
- TypeScript
- Stars
- 44k
- Forks
- 6k
- Avg merge
- 5d 15h
- Merged PRs (30d)
- 23
Description
First discussion issue: https://github.com/babel/babel/issues/5623
Current PR: https://github.com/babel/babel/pull/5735
> James wrote a good article about the general problem: http://thejameskyle.com/babel-plugin-ordering.html
> Babel is single pass traversal so top level ordering isn't a thing (unless you use `passPerPreset` which is why we are going to remove that), however the individual node visitors have an ordering.
```js
const visitors = plugins.map(plugin => plugin.visitor);
const mergedVisitors = merge(visitors);
traverse(ast, mergedVisitors);
```
I believe most agree on:
- [x] introduce a before/after key to specify which plugin ordering
- [x] should error/warn if the same plugin/capability is specified twice
- [ ] edge case would be if you are using a plugin in a "preset" that you want to still use but want to modify it by using a plugin option - either error and not use the preset anymore or the user specified plugin should override the one used in the preset itself
- [x] should any of this be user-specified (mostly likely no: if it's possible to encode for plugin authors we don't need to expose that to users)
### Questions
- [ ] what exactly should be specified in the before/after:
- [ ] a specific plugin name (probably taken from npm package) `babel-plugin-transform-es2015-arrow-function` (I'm not in favor personally)
- [ ] the more generic "capability" of many plugins (ex: `"arrowFunction", "jsx", "flow", "asyncFunction"`)
- [ ] does minification/info gathering plugin require a different approach/multiple passes again? They don't depend on a specific node type to run before/after but rather always before/after "everything else"?
- [#5623](https://github.com/babel/babel/issues/5623) discusses allowing free form strings for before/after vs. specifically named passes.
- [ ] how does the native host environment fit into this? How can we encode their support via preset-env data. If a syntax is natively provided, then it provides the capability and another plugin can output that syntax without it being transformed.
Contributor guide
Assessment
This issue has not been assessed yet.