output.space();
} : noop);
});
- DEFPRINT(AST_DestructuredKeyVal, print_key_value);
+ DEFPRINT(AST_DestructuredKeyVal, function(output) {
+ var self = this;
+ var key = print_property_key(self, output);
+ var value = self.value;
+ if (key && value instanceof AST_SymbolDeclaration && key == get_symbol_name(value)) return;
+ output.colon();
+ value.print(output);
+ });
DEFPRINT(AST_DestructuredObject, function(output) {
var props = this.properties, len = props.length, rest = this.rest;
if (len || rest) output.with_block(function() {
output.print_string(key, quote);
} else {
output.print_name(key);
+ return key;
}
} else {
output.print_string(key, quote);
}
}
}
-
- function print_key_value(output) {
+ DEFPRINT(AST_ObjectKeyVal, function(output) {
var self = this;
print_property_key(self, output);
output.colon();
self.value.print(output);
- }
- DEFPRINT(AST_ObjectKeyVal, print_key_value);
+ });
DEFPRINT(AST_ObjectMethod, function(output) {
print_method(this, output);
});
}
DEFPRINT(AST_ObjectGetter, print_accessor("get"));
DEFPRINT(AST_ObjectSetter, print_accessor("set"));
- function print_symbol(self, output) {
- var def = self.definition();
- output.print_name(def && def.mangled_name || self.name);
+ function get_symbol_name(sym) {
+ var def = sym.definition();
+ return def && def.mangled_name || sym.name;
}
DEFPRINT(AST_Symbol, function(output) {
- print_symbol(this, output);
+ output.print_name(get_symbol_name(this));
});
DEFPRINT(AST_SymbolExport, function(output) {
var self = this;
- print_symbol(self, output);
- if (self.alias) {
+ var name = get_symbol_name(self);
+ output.print_name(name);
+ var alias = self.alias;
+ if (alias != name) {
output.space();
output.print("as");
output.space();
- output.print_name(self.alias);
+ output.print_name(alias);
}
});
DEFPRINT(AST_SymbolImport, function(output) {
var self = this;
- if (self.key) {
- output.print_name(self.key);
+ var name = get_symbol_name(self);
+ var key = self.key;
+ if (key && key != name) {
+ output.print_name(key);
output.space();
output.print("as");
output.space();
}
- print_symbol(self, output);
+ output.print_name(name);
});
DEFPRINT(AST_Hole, noop);
DEFPRINT(AST_Template, function(output) {
export {};
export { a, b as B, c as case, d as default };
}
- expect_exact: "export{};export{a as a,b as B,c as case,d as default};"
+ expect_exact: "export{};export{a,b as B,c as case,d as default};"
}
var_defs: {
export let b = 2, c = 3;
export var { d, e: [] } = f;
}
- expect_exact: "export const a=1;export let b=2,c=3;export var{d:d,e:[]}=f;"
+ expect_exact: "export const a=1;export let b=2,c=3;export var{d,e:[]}=f;"
}
defuns: {
export default function*(a, b) {};
export default async function f({ c }, ...[ d ]) {};
}
- expect_exact: "export default 42;export default async;export default(x,y)=>x*x;export default class{}export default function*(a,b){}export default async function f({c:c},...[d]){}"
+ expect_exact: "export default 42;export default async;export default(x,y)=>x*x;export default class{}export default function*(a,b){}export default async function f({c},...[d]){}"
}
defaults_parentheses_1: {
}
}
expect: {
- let f, { foo: o } = 42;
- function c(t, { [f]: a }) {
- t(a, c);
+ let e, { foo: a } = 42;
+ function f(t, { [e]: o }) {
+ t(o, f);
}
export default 42;
- export default async function e(t, ...{ [o]: a }) {
- (await t)(e, a);
+ export default async function n(t, ...{ [a]: o }) {
+ (await t)(n, o);
};
- export { f as bbb, o as ccc, c as fff };
+ export { e as bbb, a as ccc, f as fff };
}
}