From f9c57dfee0a768b483db74486919f254ed84a8b0 Mon Sep 17 00:00:00 2001 From: Thomas Sauer Date: Sat, 21 Oct 2017 08:22:39 +0200 Subject: [PATCH] Allow 'yield' as method name (#2382) fixes #2381 --- lib/parse.js | 2 +- test/mocha/yield.js | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/parse.js b/lib/parse.js index 619034c6..35615752 100644 --- a/lib/parse.js +++ b/lib/parse.js @@ -2565,7 +2565,7 @@ function parse($TEXT, options) { unexpected(tmp); } case "name": - if (tmp.value == "yield" && !is_token(peek(), "punc", ":") + if (tmp.value == "yield" && !is_token(peek(), "punc", ":") && !is_token(peek(), "punc", "(") && S.input.has_directive("use strict") && !is_in_generator()) { token_error(tmp, "Unexpected yield identifier inside strict mode"); } diff --git a/test/mocha/yield.js b/test/mocha/yield.js index 22b5bb07..26a66ec1 100644 --- a/test/mocha/yield.js +++ b/test/mocha/yield.js @@ -102,4 +102,15 @@ describe("Yield", function() { assert.throws(test(tests[i]), fail, tests[i]); } }); + + it("Should allow yield to be used as class/object property name", function() { + var input = [ + '"use strict";', + "({yield:42});", + "({yield(){}});", + "(class{yield(){}});", + "class C{yield(){}}", + ].join(""); + assert.strictEqual(UglifyJS.minify(input, { compress: false }).code, input); + }); });