Skip to content

Commit

Permalink
[[FIX]] Allow regexp literal after 'instanceof'
Browse files Browse the repository at this point in the history
Fixes gh-2773
  • Loading branch information
nicolo-ribaudo authored and jugglinmike committed Jan 16, 2016
1 parent d089d7d commit caa30e6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/lex.js
Original file line number Diff line number Diff line change
Expand Up @@ -1627,7 +1627,8 @@ Lexer.prototype = {
}

if (type === "(identifier)") {
if (value === "return" || value === "case" || value === "typeof") {
if (value === "return" || value === "case" ||
value === "typeof" || value === "instanceof") {
this.prereg = true;
}

Expand Down
9 changes: 5 additions & 4 deletions tests/unit/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -492,10 +492,11 @@ exports.regexp = function (test) {
"var s = /(((/;",
"var t = /x/* 2;",
"var u = /x/;",
"var v = /dsdg;",
"var w = v + /s/;",
"var x = w - /s/;",
"var y = typeof /[a-z]/;" // GH-657
"var y = typeof /[a-z]/;", // GH-657
"var z = /a/ instanceof /a/.constructor;", // GH-2773
"var v = /dsdg;"
];

var run = TestRun(test)
Expand All @@ -514,8 +515,8 @@ exports.regexp = function (test) {
.addError(17, "Invalid regular expression.")
.addError(20, "Invalid regular expression.")
.addError(21, "Invalid regular expression.")
.addError(24, "Unclosed regular expression.")
.addError(24, "Unrecoverable syntax error. (88% scanned).");
.addError(28, "Unclosed regular expression.")
.addError(28, "Unrecoverable syntax error. (100% scanned).");

run.test(code, {es3: true});
run.test(code, {}); // es5
Expand Down

0 comments on commit caa30e6

Please sign in to comment.