Babel plugin 体系的缺点
- Babel 的 syntax plugins 毫无意义。仅仅是开启 babylon parser 的选项,并没有真正可插拔的语法扩展能力
- Babel 的 plugins 可以声明直接依赖关系(inherits),但无法声明其他关系(排斥、顺序要求),并且暂时拒绝此提议(https://github.com/thejameskyle/babel-plugin-handbook/issues/17 )
- Babel 的一些官方 plugins 的职责切分有问题,导致一些微妙的 bug,如
- https://phabricator.babeljs.io/T2776#67632
- https://phabricator.babeljs.io/T6779 (transform-es2015-shorthand-properties 和 transform-es2015-function-name 如何转换包含 super 的 method ?实际上 transform-2015-object-super 应该被合并到 transform-es2015-shorthand-properties,或者从 transform-es2015-shorthand-properties 拆分单独的 transform-es2015-shorthand-methods)
很高兴能听到抨击 babel 的声音 越来越觉得连 npm 都不够用了,npm 之外还是得需要一套依赖管理模块……不知道是为啥有这想法
@luqin 这并不是抨击 babel,而是指出 babel 的不足。
@hax 明白你的意思,plugin的出发点倒是值得称赞,不过babel6带来了太多的问题。
表示直接把babel依赖定格在了 5.8.xx,刚由工具转型到平台,估计开始要混乱一阵子。
ps 好黑的label
Babel 的 plugins 可以声明直接依赖关系(inherits),但无法声明其他关系(排斥、顺序要求),并且暂时拒绝此提议(thejameskyle/babel-plugin-handbook#17 )
我看了这个 issue,我觉得 thejameskyle 说得挺有道理的。我的理解是,继承是实现层面的关系,而排斥、顺序是运行时的关系,并不是同一种关系,不好类比的。如果 plugin 间的顺序/排斥关系依赖 plugin 的显式声明,那么必然是不可靠的(因为 plugin 的集合是没有边界的,新增的 plugin 与现有的 plugin 是否会有排斥/顺序上的关系要求,是无法预测的)。而正因为不管从哪个独立 plugin 出发,这种声明都是不可靠的,所以不应该由 plugin 自己来维护管理这种关系。
@nighca 他讲的有一定道理,但是前提是plugins真的是不相关的,但事实上许多plugins是相关的(所有inherits的那些你可以仔细看看它们直接到底是什么关系),所以先验的作出plugins不应该相关这种预先假设是不成立的。他们的问题就是以一个先验的观念否定我给的use cases的合理性,属于本末倒置。我提这个issue实际是希望他们检讨plugins架构设计的合理性,但是他们并没有检讨。
给贺老提供一个论据:
loganfsmyth/babel-plugin-transform-decorators-legacy
// WRONG
"plugins": [
"transform-class-properties",
"transform-decorators-legacy"
]
// RIGHT
"plugins": [
"transform-decorators-legacy",
"transform-class-properties"
]
很明显这个是通过文档在管理这个关系。如果新加个 plugin,可能这个逻辑又不对了。
babel 的最新 roadmap 表示要重新考虑 order 问题。看来现在的维护者终于开窍了。
https://babeljs.io/blog/2016/12/07/the-state-of-babel#the-future
There is a lot of confusion around how plugins/presets interact regarding ordering. This results in bugs and issues with the config which require users to place plugins before/after others in a non-intuitive way. We’re currently discussing API changes that could reduce the confusion. However, since this is a fundamental change to the core of Babel, it might take a while to figure out the best approach.