From 2636f20d94db3c724cf9dcadb941dcc64459b30a Mon Sep 17 00:00:00 2001 From: mbruce Date: Wed, 1 May 2019 13:49:33 -0700 Subject: [PATCH] fix unicode in identifiers --- .../shift/es2017/parser/PatternAcceptor.java | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/shapesecurity/shift/es2017/parser/PatternAcceptor.java b/src/main/java/com/shapesecurity/shift/es2017/parser/PatternAcceptor.java index 76a2862e..bc087539 100644 --- a/src/main/java/com/shapesecurity/shift/es2017/parser/PatternAcceptor.java +++ b/src/main/java/com/shapesecurity/shift/es2017/parser/PatternAcceptor.java @@ -248,20 +248,16 @@ private Maybe eatUnicodeOrCharacter() { return Maybe.empty(); } return this.backtrackOnFailureMaybe(state -> { - int characterValue; if (state.match("\\u")) { state.skipCodePoint(); Maybe maybeCharacterValue = acceptUnicodeEscape(state); - if (!maybeCharacterValue.isJust()) { - return Maybe.empty(); - } - characterValue = maybeCharacterValue.fromJust(); - } else { - characterValue = pattern.codePointAt(state.index); - state.index += Character.toChars(characterValue).length; + return maybeCharacterValue.map(value -> new String(Character.toChars(value))); + } + Maybe character = state.nextCodePoint(); + if (character.isJust()) { + state.skipCodePoint(); } - String character = new String(Character.toChars(characterValue)); - return Maybe.of(character); + return character; }); } @@ -663,7 +659,7 @@ private Maybe acceptUnicodeEscape(State superState) { } int value = Integer.parseInt(hex, 16); - if (value >= 0xD800 && value <= 0xDBFF) { + if (this.unicode && value >= 0xD800 && value <= 0xDBFF) { Maybe surrogatePairValue = state.backtrackOnFailureMaybe(subState -> { if (!subState.eat("\\u")) { return Maybe.empty();