ast.js中,获取函数名的方式有错 #4

Closed
chx007 opened this Issue May 22, 2013 · 2 comments

Comments

Projects
None yet
2 participants
@chx007

chx007 commented May 22, 2013

ast.js代码中多处出现以下类似代码,用于判断代码结点是否为对函数名为require的调用,然后再获取其参数,比如模块 id

if(node instanceof UglifyJS.AST_Call && node.start.value === 'require')

此种方式对如下代码也能判断通过

require('module-a')('abc')

但是,此时 node.args[0] 其实是 'abc',而不是 'module-a',也就是说通过上述方式解析require 对应的模块 id 参数值,很有可能是错的

正确的方式应该是

if(node instanceof UglifyJS.AST_Call && node.expression.name === 'require') {
  var id = node.args[0].value
}
@lepture

This comment has been minimized.

Show comment
Hide comment

lepture added a commit that referenced this issue May 22, 2013

@lepture

This comment has been minimized.

Show comment
Hide comment
@lepture

lepture May 22, 2013

Member

Thanks for your feedback.

You can send a pull request the next time.

Member

lepture commented May 22, 2013

Thanks for your feedback.

You can send a pull request the next time.

@lepture lepture closed this May 22, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment