clean up webkit quirks (#3229)

This commit is contained in:
Alex Lam S.L
2018-08-08 16:15:45 +08:00
committed by GitHub
parent 2a5277b391
commit fc78423f1d
7 changed files with 148 additions and 126 deletions

View File

@@ -86,7 +86,7 @@ function Compressor(options, false_by_default) {
typeofs : !false_by_default, typeofs : !false_by_default,
unsafe : false, unsafe : false,
unsafe_comps : false, unsafe_comps : false,
unsafe_Function: false, unsafe_Function : false,
unsafe_math : false, unsafe_math : false,
unsafe_proto : false, unsafe_proto : false,
unsafe_regexp : false, unsafe_regexp : false,

View File

@@ -694,23 +694,15 @@ function OutputStream(options) {
// a function expression needs parens around it when it's provably // a function expression needs parens around it when it's provably
// the first token to appear in a statement. // the first token to appear in a statement.
PARENS(AST_Function, function(output) { PARENS(AST_Function, function(output) {
if (!output.has_parens() && first_in_statement(output)) { if (!output.has_parens() && first_in_statement(output)) return true;
return true;
}
if (output.option('webkit')) { if (output.option('webkit')) {
var p = output.parent(); var p = output.parent();
if (p instanceof AST_PropAccess && p.expression === this) { if (p instanceof AST_PropAccess && p.expression === this) return true;
return true;
} }
}
if (output.option('wrap_iife')) { if (output.option('wrap_iife')) {
var p = output.parent(); var p = output.parent();
return p instanceof AST_Call && p.expression === this; if (p instanceof AST_Call && p.expression === this) return true;
} }
return false;
}); });
// same goes for an object literal, because otherwise it would be // same goes for an object literal, because otherwise it would be
@@ -784,17 +776,17 @@ function OutputStream(options) {
}); });
PARENS(AST_Call, function(output) { PARENS(AST_Call, function(output) {
var p = output.parent(), p1; var p = output.parent();
if (p instanceof AST_New && p.expression === this) if (p instanceof AST_New && p.expression === this) return true;
return true;
// workaround for Safari bug.
// https://bugs.webkit.org/show_bug.cgi?id=123506 // https://bugs.webkit.org/show_bug.cgi?id=123506
if (output.option('webkit')) {
var g = output.parent(1);
return this.expression instanceof AST_Function return this.expression instanceof AST_Function
&& p instanceof AST_PropAccess && p instanceof AST_PropAccess
&& p.expression === this && p.expression === this
&& (p1 = output.parent(1)) instanceof AST_Assign && g instanceof AST_Assign
&& p1.left === p; && g.left === p;
}
}); });
PARENS(AST_New, function(output) { PARENS(AST_New, function(output) {

View File

@@ -320,14 +320,6 @@ function next_mangled_name(scope, options, def) {
var in_use = names_in_use(scope, options); var in_use = names_in_use(scope, options);
var holes = scope.cname_holes; var holes = scope.cname_holes;
var names = Object.create(null); var names = Object.create(null);
// #179, #326
// in Safari strict mode, something like (function x(x){...}) is a syntax error;
// a function expression's argument cannot shadow the function expression's name
if (scope instanceof AST_Function && scope.name && def.orig[0] instanceof AST_SymbolFunarg) {
var tricky_def = scope.name.definition();
// the function's mangled_name is null when keep_fnames is true
names[tricky_def.mangled_name || tricky_def.name] = true;
}
var scopes = [ scope ]; var scopes = [ scope ];
def.references.forEach(function(sym) { def.references.forEach(function(sym) {
var scope = sym.scope; var scope = sym.scope;

View File

@@ -236,32 +236,6 @@ issue_203: {
expect_stdout: "42" expect_stdout: "42"
} }
no_webkit: {
beautify = {
webkit: false,
}
input: {
console.log(function() {
1 + 1;
}.a = 1);
}
expect_exact: "console.log(function(){1+1}.a=1);"
expect_stdout: "1"
}
webkit: {
beautify = {
webkit: true,
}
input: {
console.log(function() {
1 + 1;
}.a = 1);
}
expect_exact: "console.log((function(){1+1}).a=1);"
expect_stdout: "1"
}
issue_2084: { issue_2084: {
options = { options = {
collapse_vars: true, collapse_vars: true,

60
test/compress/webkit.js Normal file
View File

@@ -0,0 +1,60 @@
lambda_call_dot_assign: {
beautify = {
webkit: false,
}
input: {
console.log(function() {
return {};
}().a = 1);
}
expect_exact: "console.log(function(){return{}}().a=1);"
expect_stdout: "1"
}
lambda_call_dot_assign_webkit: {
beautify = {
webkit: true,
}
input: {
console.log(function() {
return {};
}().a = 1);
}
expect_exact: "console.log((function(){return{}}()).a=1);"
expect_stdout: "1"
}
lambda_dot_assign: {
beautify = {
webkit: false,
}
input: {
console.log(function() {
1 + 1;
}.a = 1);
}
expect_exact: "console.log(function(){1+1}.a=1);"
expect_stdout: "1"
}
lambda_dot_assign_webkit: {
beautify = {
webkit: true,
}
input: {
console.log(function() {
1 + 1;
}.a = 1);
}
expect_exact: "console.log((function(){1+1}).a=1);"
expect_stdout: "1"
}
lambda_name_mangle: {
mangle = {}
input: {
console.log(typeof function foo(bar) {});
}
expect_exact: "console.log(typeof function o(n){});"
expect_stdout: "function"
}

View File

@@ -23,10 +23,9 @@ module.exports = function(url, callback) {
var options = parse(url); var options = parse(url);
options.rejectUnauthorized = false; options.rejectUnauthorized = false;
require(options.protocol.slice(0, -1)).get(options, function(res) { require(options.protocol.slice(0, -1)).get(options, function(res) {
if (res.statusCode !== 200) return callback(res); if (res.statusCode !== 200) return callback(res.statusCode);
res.pipe(fs.createWriteStream(local(url)).on("close", function() { res.pipe(fs.createWriteStream(local(url)));
callback(null, read(url)); callback(null, res);
}));
}); });
}).on("open", function() { }).on("open", function() {
callback(null, result); callback(null, result);

View File

@@ -25,7 +25,11 @@ if (typeof phantom == "undefined") {
request.resume(); request.resume();
var url = site + request.url; var url = site + request.url;
fetch(url, function(err, res) { fetch(url, function(err, res) {
if (err) throw err; if (err) {
if (typeof err != "number") throw err;
response.writeHead(err);
response.end();
} else {
response.writeHead(200, { response.writeHead(200, {
"Content-Type": { "Content-Type": {
css: "text/css", css: "text/css",
@@ -50,6 +54,7 @@ if (typeof phantom == "undefined") {
} else { } else {
res.pipe(response); res.pipe(response);
} }
}
}); });
}).listen(); }).listen();
server.on("listening", function() { server.on("listening", function() {