Improve binding patterns for arrow functions

This commit is contained in:
Anthony Van de Gejuchte
2016-09-07 01:00:07 +02:00
committed by Richard van Velzen
parent 947b8750e8
commit 32c2cc33bb
12 changed files with 243 additions and 54 deletions

View File

@@ -69,11 +69,16 @@ function OutputStream(options) {
preamble : null,
quote_style : 0,
keep_quoted_props: false,
shorthand : undefined,
ecma : 5,
}, true);
if (typeof options.ascii_identifiers === 'undefined')
options.ascii_identifiers = options.ascii_only;
if (options.shorthand === undefined)
options.shorthand = options.ecma > 5;
var indentation = 0;
var current_col = 0;
var current_line = 1;
@@ -728,9 +733,15 @@ function OutputStream(options) {
DEFPRINT(AST_Destructuring, function (self, output) {
output.print(self.is_array ? "[" : "{");
var first = true;
self.names.forEach(function (name) {
var len = self.names.length;
self.names.forEach(function (name, i) {
if (first) first = false; else { output.comma(); output.space(); }
name.print(output);
// If the final element is a hole, we need to make sure it
// doesn't look like a trailing comma, by inserting an actual
// trailing comma.
if (i === len - 1 && name instanceof AST_Hole)
output.comma();
})
output.print(self.is_array ? "]" : "}");
if (self.default) {
@@ -739,7 +750,7 @@ function OutputStream(options) {
output.space();
self.default.print(output)
}
})
});
DEFPRINT(AST_Debugger, function(self, output){
output.print("debugger");
@@ -1444,17 +1455,21 @@ function OutputStream(options) {
}
});
DEFPRINT(AST_ObjectKeyVal, function(self, output){
var print_as_shorthand = self.shorthand &&
self.value instanceof AST_Symbol &&
self.key == self.value.print_to_string();
if (print_as_shorthand) {
output.print_name(self.key);
return;
function get_name(self) {
var def = self.value.definition();
return def ? def.mangled_name || def.name : self.value.name;
}
if (output.option("shorthand") &&
self.value instanceof AST_Symbol &&
is_identifier_string(self.key) &&
get_name(self) === self.key
) {
self.print_property_name(self.key, self.quote, output);
} else {
self.print_property_name(self.key, self.quote, output);
output.colon();
self.value.print(output);
}
self.print_property_name(self.key, self.quote, output);
output.colon();
self.value.print(output);
if (self.default) {
output.space();
output.print('=');