【问题标题】:JSCodeshift declare new variableJSCodeshift 声明新变量
【发布时间】:2017-09-29 12:06:49
【问题描述】:

我想写一个模板函数来在 JsCodeShift 中创建新的变量。

有人有想法吗?或者一些更好的文档?

我根据this尝试了下面的代码。

 const j = api.jscodeshift;
 let test = j.variableDeclaration('let',
    j.variableDeclarator(
      j.identifier('test'),
      null
    )
  );

但我得到了错误

Error: {id: [object Object], init: null, loc: null, type: VariableDeclarator, 
comments: null} does not match field "declarations": [VariableDeclarator | 
Identifier] of type VariableDeclaration

詹斯干杯

【问题讨论】:

    标签: javascript jscodeshift


    【解决方案1】:

    我找到原因了,我忘了把第二个参数放在括号里

    所以这行得通:

    const j = api.jscodeshift;
    let test = j.variableDeclaration('let',
       [j.variableDeclarator(
         j.identifier('test'),
         null
       )]
     );
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-04
    相关资源
    最近更新 更多