Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
mysticatea committed Feb 17, 2018
1 parent c44e09b commit 2b229f0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
5 changes: 3 additions & 2 deletions src/regexp.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,15 +289,16 @@ pp.validateRegExp_eatAssertion = function(state) {

// Lookahead / Lookbehind
if (state.eat(LEFT_PARENTHESIS) && state.eat(QUESTION_MARK)) {
let lookbehind = false
if (this.options.ecmaVersion >= 9) {
state.eat(LESS_THAN_SIGN)
lookbehind = state.eat(LESS_THAN_SIGN)
}
if (state.eat(EQUALS_SIGN) || state.eat(EXCLAMATION_MARK)) {
this.validateRegExp_disjunction(state)
if (!state.eat(RIGHT_PARENTHESIS)) {
state.raise("Unterminated group")
}
state.lastAssertionIsQuantifiable = true
state.lastAssertionIsQuantifiable = !lookbehind
return true
}
}
Expand Down
32 changes: 16 additions & 16 deletions test/tests-regexp-2018.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,23 +118,23 @@ testFail("/(?<!a)/u", "Invalid regular expression: /(?<!a)/: Invalid group (1:1)
test("/(?<!a)/", {}, { ecmaVersion: 2018 })
test("/(?<!a)/u", {}, { ecmaVersion: 2018 })

test("/(?<=a)?/", {}, { ecmaVersion: 2018 })
testFail("/(?<=a)?/u", "Invalid regular expression: /(?<=a)?/: Invalid quantifier (1:1)", { ecmaVersion: 2018 })
test("/(?<=a)+/", {}, { ecmaVersion: 2018 })
testFail("/(?<=a)+/u", "Invalid regular expression: /(?<=a)+/: Invalid quantifier (1:1)", { ecmaVersion: 2018 })
test("/(?<=a)*/", {}, { ecmaVersion: 2018 })
testFail("/(?<=a)*/u", "Invalid regular expression: /(?<=a)*/: Invalid quantifier (1:1)", { ecmaVersion: 2018 })
test("/(?<=a){1}/", {}, { ecmaVersion: 2018 })
testFail("/(?<=a){1}/u", "Invalid regular expression: /(?<=a){1}/: Invalid quantifier (1:1)", { ecmaVersion: 2018 })
testFail("/(?<=a)?/", "Invalid regular expression: /(?<=a)?/: Nothing to repeat (1:1)", { ecmaVersion: 2018 })
testFail("/(?<=a)?/u", "Invalid regular expression: /(?<=a)?/: Nothing to repeat (1:1)", { ecmaVersion: 2018 })
testFail("/(?<=a)+/", "Invalid regular expression: /(?<=a)+/: Nothing to repeat (1:1)", { ecmaVersion: 2018 })
testFail("/(?<=a)+/u", "Invalid regular expression: /(?<=a)+/: Nothing to repeat (1:1)", { ecmaVersion: 2018 })
testFail("/(?<=a)*/", "Invalid regular expression: /(?<=a)*/: Nothing to repeat (1:1)", { ecmaVersion: 2018 })
testFail("/(?<=a)*/u", "Invalid regular expression: /(?<=a)*/: Nothing to repeat (1:1)", { ecmaVersion: 2018 })
testFail("/(?<=a){1}/", "Invalid regular expression: /(?<=a){1}/: Nothing to repeat (1:1)", { ecmaVersion: 2018 })
testFail("/(?<=a){1}/u", "Invalid regular expression: /(?<=a){1}/: Nothing to repeat (1:1)", { ecmaVersion: 2018 })

test("/(?<!a)?/", {}, { ecmaVersion: 2018 })
testFail("/(?<!a)?/u", "Invalid regular expression: /(?<!a)?/: Invalid quantifier (1:1)", { ecmaVersion: 2018 })
test("/(?<!a)+/", {}, { ecmaVersion: 2018 })
testFail("/(?<!a)+/u", "Invalid regular expression: /(?<!a)+/: Invalid quantifier (1:1)", { ecmaVersion: 2018 })
test("/(?<!a)*/", {}, { ecmaVersion: 2018 })
testFail("/(?<!a)*/u", "Invalid regular expression: /(?<!a)*/: Invalid quantifier (1:1)", { ecmaVersion: 2018 })
test("/(?<!a){1}/", {}, { ecmaVersion: 2018 })
testFail("/(?<!a){1}/u", "Invalid regular expression: /(?<!a){1}/: Invalid quantifier (1:1)", { ecmaVersion: 2018 })
testFail("/(?<!a)?/", "Invalid regular expression: /(?<!a)?/: Nothing to repeat (1:1)", { ecmaVersion: 2018 })
testFail("/(?<!a)?/u", "Invalid regular expression: /(?<!a)?/: Nothing to repeat (1:1)", { ecmaVersion: 2018 })
testFail("/(?<!a)+/", "Invalid regular expression: /(?<!a)+/: Nothing to repeat (1:1)", { ecmaVersion: 2018 })
testFail("/(?<!a)+/u", "Invalid regular expression: /(?<!a)+/: Nothing to repeat (1:1)", { ecmaVersion: 2018 })
testFail("/(?<!a)*/", "Invalid regular expression: /(?<!a)*/: Nothing to repeat (1:1)", { ecmaVersion: 2018 })
testFail("/(?<!a)*/u", "Invalid regular expression: /(?<!a)*/: Nothing to repeat (1:1)", { ecmaVersion: 2018 })
testFail("/(?<!a){1}/", "Invalid regular expression: /(?<!a){1}/: Nothing to repeat (1:1)", { ecmaVersion: 2018 })
testFail("/(?<!a){1}/u", "Invalid regular expression: /(?<!a){1}/: Nothing to repeat (1:1)", { ecmaVersion: 2018 })

test("/(?<=(?<a>\\w){3})f/u", {}, { ecmaVersion: 2018 })
test("/((?<=\\w{3}))f/u", {}, { ecmaVersion: 2018 })
Expand Down

0 comments on commit 2b229f0

Please sign in to comment.