Permalink
Browse files

[[FIX]] Allow RegExp literal as `yield` operand (#3011)

Extend the lexer to recognize RegExp literals which immediately follow
the `yield` operator.
  • Loading branch information...
jugglinmike authored and rwaldron committed Sep 22, 2016
1 parent a2b3881 commit b646aeae63f49a24e649a86dbc8d94c20d57f38c
Showing with 52 additions and 2 deletions.
  1. +1 −1 src/lex.js
  2. +51 −1 tests/unit/parser.js
@@ -1696,7 +1696,7 @@ Lexer.prototype = {
}

if (type === "(identifier)") {
if (value === "return" || value === "case" ||
if (value === "return" || value === "case" || value === "yield" ||
value === "typeof" || value === "instanceof") {
this.prereg = true;
}
@@ -6465,7 +6465,6 @@ exports["test 'yield' in invalid positions"] = function (test) {
testRun.test("function* g() { yield* ? null : null; }", { esversion: 6, expr: true });
testRun.test("function* g() { (yield ? 1 : 1); }", { esversion: 6, expr: true });
testRun.test("function* g() { (yield* ? 1 : 1); }", { esversion: 6, expr: true });
testRun.test("function* g() { yield / 1; }", { esversion: 6, expr: true });
TestRun(test)
.addError(1, "Unclosed regular expression.")
.addError(1, "Unrecoverable syntax error. (100% scanned).")
@@ -6647,6 +6646,57 @@ exports["test for line breaks with 'yield'"] = function (test) {
test.done();
};

// Regression test for gh-2956
exports.yieldRegExp = function (test) {
var code = [
"function* g() {",
" yield /./;",
" yield/./;",
" yield",
" /./;",
" yield /* comment */;",
" yield /* comment *//./;",
" yield 1 / 1;",
"}"
];

TestRun(test)
.addError(1, "'function*' is only available in ES6 (use 'esversion: 6').")
.addError(2, "'yield' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz).")
.addError(3, "'yield' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz).")
.addError(4, "'yield' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz).")
.addError(4, "Missing semicolon.")
.addError(5, "Expected an assignment or function call and instead saw an expression.")
.addError(6, "'yield' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz).")
.addError(7, "'yield' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz).")
.addError(8, "'yield' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz).")
.test(code);

TestRun(test)
.addError(4, "Missing semicolon.")
.addError(5, "Expected an assignment or function call and instead saw an expression.")
.test(code, { esversion: 6 });

code = [
"function* g() {",
" yield / 2;",
"}"
];

TestRun(test)
.addError(1, "'function*' is only available in ES6 (use 'esversion: 6').")
.addError(2, "Unclosed regular expression.")
.addError(2, "Unrecoverable syntax error. (66% scanned).")
.test(code);

TestRun(test)
.addError(2, "Unclosed regular expression.")
.addError(2, "Unrecoverable syntax error. (66% scanned).")
.test(code, { esversion: 6 });

test.done();
};

exports.unreachable = {
"regression for GH-1227": function (test) {
var src = fs.readFileSync(__dirname + "/fixtures/gh1227.js", "utf8");

0 comments on commit b646aea

Please sign in to comment.