Mou*_*bar 2 javascript jscodeshift
我一直在编写一些转换来帮助我重构代码库。我所做的基本上是向某些对象表达式添加新属性。为什么要从jscodeshift/recast这些对象中删除尾随逗号?我怎样才能防止这种情况发生?
Recast 有一个尾随逗号选项:
// If you want to print trailing commas in object literals,
// array expressions, functions calls and function definitions pass true
// for this option.
trailingComma: false,
Run Code Online (Sandbox Code Playgroud)
您可以将重铸打印选项传递给 jscodeshift 的 totoSource方法,如下所述:
return x.toSource({trailingComma: true});
Run Code Online (Sandbox Code Playgroud)
现在下面评论中的问题已被合并,您也可以通过这种方式使用它以获得更细粒度:
trailingComma: {
objects: true,
arrays: true,
functions: false,
}
Run Code Online (Sandbox Code Playgroud)
为什么 jscodeshift/recast 会删除这些对象中的尾随逗号?
重铸无法删除不存在的东西。Recast 对代码的AST进行操作。AST 中不存在用于分隔属性的标点符号(例如逗号)。
| 归档时间: |
|
| 查看次数: |
912 次 |
| 最近记录: |