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); + }); });