From 68fd78e9eca2f6dbb60c4d08957a10bc0b20427a Mon Sep 17 00:00:00 2001 From: Toru Nagashima Date: Tue, 13 Feb 2018 22:18:37 +0900 Subject: [PATCH] small fix --- src/regexp.js | 37 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/src/regexp.js b/src/regexp.js index acc6a853d..5e8143451 100644 --- a/src/regexp.js +++ b/src/regexp.js @@ -2,8 +2,6 @@ import {isIdentifierStart, isIdentifierChar} from "./identifier.js" import {Parser} from "./state.js" import UNICODE_PROPERTY_VALUES from "./unicode-property-data.js" -/* eslint no-invalid-this: error */ - const BACKSPACE = 0x08 const CHARACTER_TABULATION = 0x09 const LINE_FEED = 0x0A @@ -200,14 +198,6 @@ pp.validateRegExpPattern = function(state) { } } -// --------------------------------------------------------------------------- -// Helpers -// --------------------------------------------------------------------------- - -// --------------------------------------------------------------------------- -// Productions -// --------------------------------------------------------------------------- - // https://www.ecma-international.org/ecma-262/8.0/#prod-Pattern pp.validateRegExp_pattern = function(state) { state.pos = 0 @@ -518,23 +508,30 @@ pp.validateRegExp_groupSpecifier = function(state) { // GroupName[U] :: // `<` RegExpIdentifierName[?U] `>` +// Note: this updates `state.lastStringValue` property with the eaten name. +pp.validateRegExp_eatGroupName = function(state) { + state.lastStringValue = "" + if (state.eat(LESS_THAN_SIGN)) { + if (this.validateRegExp_eatRegExpIdentifierName(state) && state.eat(GREATER_THAN_SIGN)) { + return true + } + state.raise("Invalid capture group name") + } + return false +} + // RegExpIdentifierName[U] :: // RegExpIdentifierStart[?U] // RegExpIdentifierName[?U] RegExpIdentifierPart[?U] // Note: this updates `state.lastStringValue` property with the eaten name. -pp.validateRegExp_eatGroupName = function(state) { +pp.validateRegExp_eatRegExpIdentifierName = function(state) { state.lastStringValue = "" - if (state.eat(LESS_THAN_SIGN)) { - if (this.validateRegExp_eatRegExpIdentifierStart(state)) { + if (this.validateRegExp_eatRegExpIdentifierStart(state)) { + state.lastStringValue += codePointToString(state.lastIntValue) + while (this.validateRegExp_eatRegExpIdentifierPart(state)) { state.lastStringValue += codePointToString(state.lastIntValue) - while (this.validateRegExp_eatRegExpIdentifierPart(state)) { - state.lastStringValue += codePointToString(state.lastIntValue) - } - if (state.eat(GREATER_THAN_SIGN)) { - return true - } } - state.raise("Invalid capture group name") + return true } return false }