2017-09-29 1 views
0

JsCodeShiftに新しい変数を作成するためのテンプレート関数を書きたいと思います。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 

乾杯イェンス

答えて

0

エラーを取得:

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

https://www.toptal.com/javascrip t/write-code-to-rewrite-your-code が最も役に立つ記事でした –

関連する問題