簡體   English   中英

如何將ast節點轉換為表示其基礎javascript的字符串

[英]How to convert an ast-node to a string of the underlying javascript its representing

如何將節點轉換為javascript?

https://astexplorer.net/#/gist/cf11a829035dd865a3fbf6744aa4b146/50e921c2b4bea27c5d1b214acae3c5ef11a2f1af

// target file
function execute() { 
  var a = 'a'
}

// jscodeshift
export default(file, api) => {
  const j = api.jscodeshift
  const root = j(file.source)

  var node = root.find(j.VariableDeclaration)
  // i want to see what node looks like in javascript.

  return root.toSource()
}

大概有一個非空的搜索內容集合:

var node = root.find(j.VariableDeclaration).at(0).get();
// in js node looks like
return j(node).toSource();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM