Fix handling of "use asm" when no command line flags are passed to uglifyjs. SCOPE_IS_NEEDED is unconditionally true now. Refactored floating point literal parsing to be more in keeping with the AST class design.

This commit is contained in:
kzc
2015-10-07 13:10:53 -04:00
parent 99945fcd04
commit 4d2f7d83af
4 changed files with 14 additions and 10 deletions

View File

@@ -401,7 +401,7 @@ async.eachLimit(files, 1, function (file, cb) {
writeNameCache("props", cache); writeNameCache("props", cache);
})(); })();
var SCOPE_IS_NEEDED = COMPRESS || MANGLE || BEAUTIFY || ARGS.lint; var SCOPE_IS_NEEDED = true;
var TL_CACHE = readNameCache("vars"); var TL_CACHE = readNameCache("vars");
if (SCOPE_IS_NEEDED) { if (SCOPE_IS_NEEDED) {

View File

@@ -864,10 +864,11 @@ var AST_String = DEFNODE("String", "value quote", {
} }
}, AST_Constant); }, AST_Constant);
var AST_Number = DEFNODE("Number", "value", { var AST_Number = DEFNODE("Number", "value literal", {
$documentation: "A number literal", $documentation: "A number literal",
$propdoc: { $propdoc: {
value: "[number] the numeric value" value: "[number] the numeric value",
literal: "[string] numeric value as string (optional)"
} }
}, AST_Constant); }, AST_Constant);

View File

@@ -1158,8 +1158,10 @@ function OutputStream(options) {
output.print_string(self.getValue(), self.quote); output.print_string(self.getValue(), self.quote);
}); });
DEFPRINT(AST_Number, function(self, output){ DEFPRINT(AST_Number, function(self, output){
if (self.value_string !== undefined && self.scope && self.scope.has_directive('use asm')) { if (self.literal !== undefined
output.print(self.value_string); && +self.literal === self.value /* paranoid check */
&& self.scope && self.scope.has_directive('use asm')) {
output.print(self.literal);
} else { } else {
output.print(make_num(self.getValue())); output.print(make_num(self.getValue()));
} }

View File

@@ -335,7 +335,11 @@ function tokenizer($TEXT, filename, html5_comments, shebang) {
if (prefix) num = prefix + num; if (prefix) num = prefix + num;
var valid = parse_js_number(num); var valid = parse_js_number(num);
if (!isNaN(valid)) { if (!isNaN(valid)) {
return token("num", valid); var tok = token("num", valid);
if (num.indexOf('.') >= 0) {
tok.literal = num;
}
return tok;
} else { } else {
parse_error("Invalid syntax: " + num); parse_error("Invalid syntax: " + num);
} }
@@ -1148,10 +1152,7 @@ function parse($TEXT, options) {
ret = _make_symbol(AST_SymbolRef); ret = _make_symbol(AST_SymbolRef);
break; break;
case "num": case "num":
ret = new AST_Number({ start: tok, end: tok, value: tok.value }); ret = new AST_Number({ start: tok, end: tok, value: tok.value, literal: tok.literal });
var value_string = $TEXT.substring(tok.pos, tok.endpos);
if (value_string.indexOf('.') >= 0)
ret.value_string = value_string;
break; break;
case "string": case "string":
ret = new AST_String({ ret = new AST_String({