-
Notifications
You must be signed in to change notification settings - Fork 94
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
Lose "()" after parse and cause Syntax error in js #114
Comments
The package >>> content = '''function _fAddItem(_aoContainer, _aoItem, _anIndex)
... {
... ({}).toString.call([]) != "[object Array]" && (_aoItem = [_aoItem]);
... return _aoContainer.slice(0, _anIndex).concat(_aoItem).concat(_aoContainer.slice(_anIndex, _aoContainer.length));
... };'''
>>> from calmjs.parse import es5
>>> tree = es5(content)
>>> print(tree)
function _fAddItem(_aoContainer, _aoItem, _anIndex) {
({}).toString.call([]) != "[object Array]" && (_aoItem = [_aoItem]);
return _aoContainer.slice(0, _anIndex).concat(_aoItem).concat(_aoContainer.slice(_anIndex, _aoContainer.length));
}
; |
Thank you very much, I tried this method, it works very well. |
The from calmjs.parse import es5
from calmjs.parse import asttypes as ast
from calmjs.parse.walkers import Walker
tree = es5(source)
walker = Walker()
for node in walker.filter(tree, lambda node: isinstance(node, ast.Default)):
print(node) # just print them out as a demo Otherwise the "visitor" pattern that |
here is a content:
function _fAddItem(_aoContainer, _aoItem, _anIndex)
{
({}).toString.call([]) != "[object Array]" && (_aoItem = [_aoItem]);
return _aoContainer.slice(0, _anIndex).concat(_aoItem).concat(_aoContainer.slice(_anIndex, _aoContainer.length));
};
function _fAddItem(_aoContainer, _aoItem, _anIndex) {
{
}.toString.call([]) != "[object Array]" && (_aoItem = [_aoItem]);
return _aoContainer.slice(0, _anIndex).concat(_aoItem).concat(_aoContainer.slice(_anIndex, _aoContainer.length));
}
;
I found that the "()" in the "({}}"" in line 3 of the content is gone and casued Syntax error in js
i wonder which part of code what reason caused this.
I have not learned lexer, parser or something,i want to know whether i have the ability to learn and fix it by myself or not ,and if it will takes me too much time.
I will be appreciate if someone can help
The text was updated successfully, but these errors were encountered: