Skip to content

Commit

Permalink
remove redundant codePointToString
Browse files Browse the repository at this point in the history
  • Loading branch information
bvanjoi authored and marijnh committed Mar 27, 2022
1 parent 1ecd60b commit 4236464
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 14 deletions.
8 changes: 1 addition & 7 deletions acorn/src/regexp.js
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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.
*
Expand Down
8 changes: 1 addition & 7 deletions acorn/src/tokenize.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 (;;) {
Expand Down
7 changes: 7 additions & 0 deletions acorn/src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 4236464

Please sign in to comment.