From abbeb266b521be5530eca26c466161f76678969d Mon Sep 17 00:00:00 2001 From: kzc Date: Tue, 10 Jan 2017 14:19:32 -0500 Subject: [PATCH] [ES6] output parens for yield when parented by AST_Dot or AST_Sub (#1419) --- lib/output.js | 6 ++++++ test/compress/yield.js | 28 +++++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/lib/output.js b/lib/output.js index c0b5d7df..79165618 100644 --- a/lib/output.js +++ b/lib/output.js @@ -686,6 +686,12 @@ function OutputStream(options) { // -(yield 4) if (p instanceof AST_Unary) return true; + // (yield x).foo + if (p instanceof AST_Dot && p.expression === this) + return true; + // (yield x)['foo'] + if (p instanceof AST_Sub && p.expression === this) + return true; }); PARENS(AST_PropAccess, function(output){ diff --git a/test/compress/yield.js b/test/compress/yield.js index 4f28b647..d1e7ece3 100644 --- a/test/compress/yield.js +++ b/test/compress/yield.js @@ -163,4 +163,30 @@ empty_generator_as_parameter_without_side_effects: { evaluate(GeneratorPrototype); } expect_exact: "var GeneratorPrototype=Object.getPrototypeOf(Object.getPrototypeOf(function*(){}()));evaluate(GeneratorPrototype);" -} \ No newline at end of file +} + +yield_dot: { + options = { + } + input: { + function* foo(){ + yield x.foo; + (yield x).foo; + yield (yield obj.foo()).bar(); + } + } + expect_exact: "function*foo(){yield x.foo;(yield x).foo;yield(yield obj.foo()).bar()}" +} + +yield_sub: { + options = { + } + input: { + function* foo(){ + yield x['foo']; + (yield x)['foo']; + yield (yield obj.foo())['bar'](); + } + } + expect_exact: 'function*foo(){yield x["foo"];(yield x)["foo"];yield(yield obj.foo())["bar"]()}' +}