diff --git a/acorn/src/regexp.js b/acorn/src/regexp.js index 37cc75b6f..be6975be9 100644 --- a/acorn/src/regexp.js +++ b/acorn/src/regexp.js @@ -1,7 +1,7 @@ import {isIdentifierStart, isIdentifierChar} from "./identifier.js" import {Parser} from "./state.js" import UNICODE_PROPERTY_VALUES from "./unicode-property-data.js" -import {hasOwn} from "./util.js" +import {hasOwn, codePointToString} from "./util.js" const pp = Parser.prototype @@ -89,12 +89,6 @@ export class RegExpValidationState { } } -function codePointToString(ch) { - if (ch <= 0xFFFF) return String.fromCharCode(ch) - ch -= 0x10000 - return String.fromCharCode((ch >> 10) + 0xD800, (ch & 0x03FF) + 0xDC00) -} - /** * Validate the flags part of a given RegExpLiteral. * diff --git a/acorn/src/tokenize.js b/acorn/src/tokenize.js index ffac4f749..fa9ddaab8 100644 --- a/acorn/src/tokenize.js +++ b/acorn/src/tokenize.js @@ -4,6 +4,7 @@ import {Parser} from "./state.js" import {SourceLocation} from "./locutil.js" import {RegExpValidationState} from "./regexp.js" import {lineBreak, nextLineBreak, isNewLine, nonASCIIwhitespace} from "./whitespace.js" +import {codePointToString} from "./util" // Object type used to represent tokens. Note that normally, tokens // simply exist as properties on the parser object. This is only @@ -562,13 +563,6 @@ pp.readCodePoint = function() { return code } -function codePointToString(code) { - // UTF-16 Decoding - if (code <= 0xFFFF) return String.fromCharCode(code) - code -= 0x10000 - return String.fromCharCode((code >> 10) + 0xD800, (code & 1023) + 0xDC00) -} - pp.readString = function(quote) { let out = "", chunkStart = ++this.pos for (;;) { diff --git a/acorn/src/util.js b/acorn/src/util.js index 8262cc6bb..ac5d9505a 100644 --- a/acorn/src/util.js +++ b/acorn/src/util.js @@ -12,4 +12,11 @@ export function wordsRegexp(words) { return new RegExp("^(?:" + words.replace(/ /g, "|") + ")$") } +export function codePointToString(code) { + // UTF-16 Decoding + if (code <= 0xFFFF) return String.fromCharCode(code) + code -= 0x10000 + return String.fromCharCode((code >> 10) + 0xD800, (code & 1023) + 0xDC00) +} + export const loneSurrogate = /[\uD800-\uDFFF]/u