From 74308d53f65d897d89a788fdaa05db1ef15c25d9 Mon Sep 17 00:00:00 2001 From: Mathias Bynens Date: Thu, 23 Jun 2016 12:11:22 +0200 Subject: [PATCH] Match updated spec for `/\W/iu` Per ES6, `/\W/iu` matched U+017F, U+212A, and, surprisingly, `K` and `S`. This is no longer the case now that https://github.com/tc39/ecma262/pull/525 is merged. Ref. https://github.com/mathiasbynens/regexpu-core/issues/8. Ref. https://github.com/mathiasbynens/regexpu-fixtures/commit/81eeb147b4a1ef9eb90d2f6b75ae0dd4d4c0e028. --- data/character-class-escape-sets.js | 6 ++++-- scripts/character-class-escape-sets.js | 15 +++++++-------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/data/character-class-escape-sets.js b/data/character-class-escape-sets.js index f364f75..d5bca33 100644 --- a/data/character-class-escape-sets.js +++ b/data/character-class-escape-sets.js @@ -95,9 +95,11 @@ exports.UNICODE_IGNORE_CASE = new Map([ .addRange(0x30, 0x39) .addRange(0x41, 0x5A) .addRange(0x61, 0x7A)], - ['W', regenerate(0x4B, 0x53, 0x60) + ['W', regenerate(0x60) .addRange(0x0, 0x2F) .addRange(0x3A, 0x40) .addRange(0x5B, 0x5E) - .addRange(0x7B, 0x10FFFF)] + .addRange(0x7B, 0x17E) + .addRange(0x180, 0x2129) + .addRange(0x212B, 0x10FFFF)] ]); diff --git a/scripts/character-class-escape-sets.js b/scripts/character-class-escape-sets.js index 63f4a42..eba9529 100644 --- a/scripts/character-class-escape-sets.js +++ b/scripts/character-class-escape-sets.js @@ -26,15 +26,14 @@ function addCharacterClassEscape(lower, set) { ESCAPE_CHARS[lower] = ESCAPE_CHARS_UNICODE[lower] = set; const upper = lower.toUpperCase(); ESCAPE_CHARS[upper] = BMP_SET.clone().remove(set); - const uExcludeSet = UNICODE_SET.clone().remove(set); - ESCAPE_CHARS_UNICODE[upper] = uExcludeSet; + ESCAPE_CHARS_UNICODE[upper] = UNICODE_SET.clone().remove(set); // Check if one or more symbols in this set fold to another one. If so, // a copy of the set including the mapped symbols is created for use with // regular expressions that have both the `u` and `i` flags set. const codePoints = set.toArray(); const iuSet = regenerate(); let containsFoldingSymbols = false; - codePoints.forEach(function(codePoint) { + for (const codePoint of codePoints) { let folded = caseFold(codePoint); if (folded) { containsFoldingSymbols = true; @@ -44,13 +43,13 @@ function addCharacterClassEscape(lower, set) { iuSet.add(folded); } } - }); - ESCAPE_CHARS_UNICODE_IGNORE_CASE[lower] = containsFoldingSymbols ? + } + const iuLowerSet = containsFoldingSymbols ? iuSet.clone().add(set) : set; - ESCAPE_CHARS_UNICODE_IGNORE_CASE[upper] = containsFoldingSymbols ? - iuSet.clone().add(uExcludeSet) : - uExcludeSet; + const iuUpperSet = UNICODE_SET.clone().remove(iuLowerSet); + ESCAPE_CHARS_UNICODE_IGNORE_CASE[lower] = iuLowerSet; + ESCAPE_CHARS_UNICODE_IGNORE_CASE[upper] = iuUpperSet; } // Prepare a Regenerate set for every existing character class escape.