// Copyright 2017 the V8 project authors. All rights reserved. // This code is governed by the BSD license found in the LICENSE file. /*--- description: Named backreferences in Unicode RegExps esid: sec-atomescape info: | The production AtomEscape :: [+N] k GroupName evaluates as follows: 1. Search the enclosing RegExp for an instance of a GroupSpecifier for an RegExpIdentifierName which has a StringValue equal to the StringValue of the RegExpIdentifierName contained in GroupName. 2. Assert: A unique such GroupSpecifier is found. 3. Let parenIndex be the number of left capturing parentheses in the entire regular expression that occur to the left of the located GroupSpecifier. This is the total number of times the Atom::(GroupSpecifierDisjunction) production is expanded prior to that production's Term plus the total number of Atom :: (GroupSpecifierDisjunction) productions enclosing this Term. 4. Call BackreferenceMatcher(parenIndex) and return its Matcher result. features: [regexp-named-groups] includes: [compareArray.js] ---*/ // Named references. assert.compareArray(["bab", "b"], "bab".match(/(?.).\k/u)); assert.sameValue(null, "baa".match(/(?.).\k/u)); // Reference inside group. assert.compareArray(["bab", "b"], "bab".match(/(?\k\w)../u)); assert.sameValue("b", "bab".match(/(?\k\w)../u).groups.a); // Reference before group. assert.compareArray(["bab", "b"], "bab".match(/\k(?b)\w\k/u)); assert.sameValue("b", "bab".match(/\k(?b)\w\k/u).groups.a); assert.compareArray(["bab", "b", "a"], "bab".match(/(?b)\k(?a)\k/u)); let {a, b} = "bab".match(/(?b)\k(?a)\k/u).groups; assert.sameValue(a, "a"); assert.sameValue(b, "b"); assert.compareArray(["bab", "b"], "bab".match(/\k(?b)\w\k/)); assert.compareArray(["bab", "b", "a"], "bab".match(/(?b)\k(?a)\k/)); // Reference properties. assert.sameValue("a", /(?a)(?b)\k/u.exec("aba").groups.a); assert.sameValue("b", /(?a)(?b)\k/u.exec("aba").groups.b); assert.sameValue(undefined, /(?a)(?b)\k/u.exec("aba").groups.c); assert.sameValue(undefined, /(?a)(?b)\k|(?c)/u.exec("aba").groups.c); reportCompare(0, 0);