-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
fix chained evaluation #1610
fix chained evaluation #1610
Conversation
`reduce_vars` enables substitution of variables but did not clone the value's `AST_Node`. This confuses `collapse_vars` and result in invalid AST and subsequent crash. fixes mishoo#1609
var a = "long piece of string"; | ||
(function() { | ||
var c; | ||
c = f(a); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks odd. collapse_vars
would not make this substitution of f(b)
-> f(a)
because function f
is undeclared and would be a side effect. There might be still another clone issue in reduce_vars
in var b
of value a
.
v2.7.5 by comparison produces:
$ uglifyjs chained_evaluation_2.js -c collapse_vars,reduce_vars -b
WARN: Replacing constant a [chained_evaluation_2.js:4,24]
!function() {
!function() {
var c, b = "long piece of string";
c = f(b), c.bar = b;
}();
}();
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@alexlamsl Did reduce_vars
eliminate var b
altogether and replace all its references with a
? If so, then it makes sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed - with this PR or 2.8.12:
$ bin/uglifyjs chained_evaluation_2.js -c collapse_vars=false,reduce_vars=true -b
WARN: Dropping unused variable b [chained_evaluation_2.js:4,20]
!function() {
var a = "long piece of string";
!function() {
var c;
c = f(a), c.bar = a;
}();
}();
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, you need both reduce_vars
and collapse_vars
to trigger this issue.
It's reduce_vars
fault, because it didn't clone the AST_Node
when performing the substitution, then collapse_vars
operated on the resulting invalid AST and gave us AST_Binary.right === null
.
Travis CI is erring out on installing node 4: |
See #1604 (comment) (Sorry I was away playing badminton.) |
reduce_vars
enables substitution of variables but did not clone the value'sAST_Node
.This confuses
collapse_vars
and result in invalid AST and subsequent crash.fixes #1609