Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make unicode-property-data ecmaVersion-aware #798

Merged
merged 1 commit into from
Feb 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions acorn/src/regexp.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import {isIdentifierStart, isIdentifierChar} from "./identifier.js"
import {Parser} from "./state.js"
import UNICODE_PROPERTY_VALUES from "./unicode-property-data.js"
import {has} from "./util.js"

const pp = Parser.prototype

export class RegExpValidationState {
constructor(parser) {
this.parser = parser
this.validFlags = `gim${parser.options.ecmaVersion >= 6 ? "uy" : ""}${parser.options.ecmaVersion >= 9 ? "s" : ""}`
this.unicodeProperties = UNICODE_PROPERTY_VALUES[parser.options.ecmaVersion >= 10 ? 10 : parser.options.ecmaVersion]
this.source = ""
this.flags = ""
this.start = 0
Expand Down Expand Up @@ -784,14 +786,14 @@ pp.regexp_eatUnicodePropertyValueExpression = function(state) {
return false
}
pp.regexp_validateUnicodePropertyNameAndValue = function(state, name, value) {
if (!UNICODE_PROPERTY_VALUES.hasOwnProperty(name) || UNICODE_PROPERTY_VALUES[name].indexOf(value) === -1) {
if (!has(state.unicodeProperties.nonBinary, name))
state.raise("Invalid property name")
}
if (!state.unicodeProperties.nonBinary[name].test(value))
state.raise("Invalid property value")
}
pp.regexp_validateUnicodePropertyNameOrValue = function(state, nameOrValue) {
if (UNICODE_PROPERTY_VALUES.$LONE.indexOf(nameOrValue) === -1) {
if (!state.unicodeProperties.binary.test(nameOrValue))
state.raise("Invalid property name")
}
}

// UnicodePropertyName ::
Expand Down
13 changes: 5 additions & 8 deletions acorn/src/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,24 @@ import {reservedWords, keywords} from "./identifier"
import {types as tt} from "./tokentype"
import {lineBreak} from "./whitespace"
import {getOptions} from "./options"
import {wordsRegexp} from "./util"
import {SCOPE_TOP, SCOPE_FUNCTION, SCOPE_ASYNC, SCOPE_GENERATOR, SCOPE_SUPER, SCOPE_DIRECT_SUPER} from "./scopeflags"

function keywordRegexp(words) {
return new RegExp("^(?:" + words.replace(/ /g, "|") + ")$")
}

export class Parser {
constructor(options, input, startPos) {
this.options = options = getOptions(options)
this.sourceFile = options.sourceFile
this.keywords = keywordRegexp(keywords[options.ecmaVersion >= 6 ? 6 : 5])
this.keywords = wordsRegexp(keywords[options.ecmaVersion >= 6 ? 6 : 5])
let reserved = ""
if (!options.allowReserved) {
for (let v = options.ecmaVersion;; v--)
if (reserved = reservedWords[v]) break
if (options.sourceType === "module") reserved += " await"
}
this.reservedWords = keywordRegexp(reserved)
this.reservedWords = wordsRegexp(reserved)
let reservedStrict = (reserved ? reserved + " " : "") + reservedWords.strict
this.reservedWordsStrict = keywordRegexp(reservedStrict)
this.reservedWordsStrictBind = keywordRegexp(reservedStrict + " " + reservedWords.strictBind)
this.reservedWordsStrict = wordsRegexp(reservedStrict)
this.reservedWordsStrictBind = wordsRegexp(reservedStrict + " " + reservedWords.strictBind)
this.input = String(input)

// Used to signal to callers of `readWord1` whether the word
Expand Down
Loading