Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

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

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

chx007 opened this issue May 22, 2013 · 2 comments

Comments

@chx007
Copy link

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
Copy link
Contributor

lepture commented May 22, 2013

lepture added a commit that referenced this issue May 22, 2013
@lepture
Copy link
Contributor

lepture commented May 22, 2013

Thanks for your feedback.

You can send a pull request the next time.

@lepture lepture closed this as completed May 22, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants