diff options
author | Michaël Zasso <targos@protonmail.com> | 2017-12-22 16:53:42 +0100 |
---|---|---|
committer | Michaël Zasso <targos@protonmail.com> | 2018-01-11 09:48:05 +0100 |
commit | 3dc30632755713179f345f4af024bd904c6162d0 (patch) | |
tree | f28c4f6dd6dfc5992edf301449d1a371d229755b /tools/node_modules/eslint/node_modules/acorn-jsx/node_modules/acorn/src/loose/tokenize.js | |
parent | a2c7085dd4a8e60d1a47572aca8bb6fcb7a32f88 (diff) | |
download | android-node-v8-3dc30632755713179f345f4af024bd904c6162d0.tar.gz android-node-v8-3dc30632755713179f345f4af024bd904c6162d0.tar.bz2 android-node-v8-3dc30632755713179f345f4af024bd904c6162d0.zip |
tools: move eslint from tools to tools/node_modules
This is required because we need to add the babel-eslint dependency
and it has to be able to resolve "eslint".
babel-eslint is required to support future ES features such as async
iterators and import.meta.
Refs: https://github.com/nodejs/node/pull/17755
PR-URL: https://github.com/nodejs/node/pull/17820
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Diffstat (limited to 'tools/node_modules/eslint/node_modules/acorn-jsx/node_modules/acorn/src/loose/tokenize.js')
-rw-r--r-- | tools/node_modules/eslint/node_modules/acorn-jsx/node_modules/acorn/src/loose/tokenize.js | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/tools/node_modules/eslint/node_modules/acorn-jsx/node_modules/acorn/src/loose/tokenize.js b/tools/node_modules/eslint/node_modules/acorn-jsx/node_modules/acorn/src/loose/tokenize.js new file mode 100644 index 0000000000..ce5a49a3f4 --- /dev/null +++ b/tools/node_modules/eslint/node_modules/acorn-jsx/node_modules/acorn/src/loose/tokenize.js @@ -0,0 +1,108 @@ +import {tokTypes as tt, Token, isNewLine, SourceLocation, getLineInfo, lineBreakG} from "acorn" +import {LooseParser} from "./state" + +const lp = LooseParser.prototype + +function isSpace(ch) { + return (ch < 14 && ch > 8) || ch === 32 || ch === 160 || isNewLine(ch) +} + +lp.next = function() { + this.last = this.tok + if (this.ahead.length) + this.tok = this.ahead.shift() + else + this.tok = this.readToken() + + if (this.tok.start >= this.nextLineStart) { + while (this.tok.start >= this.nextLineStart) { + this.curLineStart = this.nextLineStart + this.nextLineStart = this.lineEnd(this.curLineStart) + 1 + } + this.curIndent = this.indentationAfter(this.curLineStart) + } +} + +lp.readToken = function() { + for (;;) { + try { + this.toks.next() + if (this.toks.type === tt.dot && + this.input.substr(this.toks.end, 1) === "." && + this.options.ecmaVersion >= 6) { + this.toks.end++ + this.toks.type = tt.ellipsis + } + return new Token(this.toks) + } catch(e) { + if (!(e instanceof SyntaxError)) throw e + + // Try to skip some text, based on the error message, and then continue + let msg = e.message, pos = e.raisedAt, replace = true + if (/unterminated/i.test(msg)) { + pos = this.lineEnd(e.pos + 1) + if (/string/.test(msg)) { + replace = {start: e.pos, end: pos, type: tt.string, value: this.input.slice(e.pos + 1, pos)} + } else if (/regular expr/i.test(msg)) { + let re = this.input.slice(e.pos, pos) + try { re = new RegExp(re) } catch(e) {} + replace = {start: e.pos, end: pos, type: tt.regexp, value: re} + } else if (/template/.test(msg)) { + replace = {start: e.pos, end: pos, + type: tt.template, + value: this.input.slice(e.pos, pos)} + } else { + replace = false + } + } else if (/invalid (unicode|regexp|number)|expecting unicode|octal literal|is reserved|directly after number|expected number in radix/i.test(msg)) { + while (pos < this.input.length && !isSpace(this.input.charCodeAt(pos))) ++pos + } else if (/character escape|expected hexadecimal/i.test(msg)) { + while (pos < this.input.length) { + let ch = this.input.charCodeAt(pos++) + if (ch === 34 || ch === 39 || isNewLine(ch)) break + } + } else if (/unexpected character/i.test(msg)) { + pos++ + replace = false + } else if (/regular expression/i.test(msg)) { + replace = true + } else { + throw e + } + this.resetTo(pos) + if (replace === true) replace = {start: pos, end: pos, type: tt.name, value: "✖"} + if (replace) { + if (this.options.locations) + replace.loc = new SourceLocation( + this.toks, + getLineInfo(this.input, replace.start), + getLineInfo(this.input, replace.end)) + return replace + } + } + } +} + +lp.resetTo = function(pos) { + this.toks.pos = pos + let ch = this.input.charAt(pos - 1) + this.toks.exprAllowed = !ch || /[\[\{\(,;:?\/*=+\-~!|&%^<>]/.test(ch) || + /[enwfd]/.test(ch) && + /\b(keywords|case|else|return|throw|new|in|(instance|type)of|delete|void)$/.test(this.input.slice(pos - 10, pos)) + + if (this.options.locations) { + this.toks.curLine = 1 + this.toks.lineStart = lineBreakG.lastIndex = 0 + let match + while ((match = lineBreakG.exec(this.input)) && match.index < pos) { + ++this.toks.curLine + this.toks.lineStart = match.index + match[0].length + } + } +} + +lp.lookAhead = function(n) { + while (n > this.ahead.length) + this.ahead.push(this.readToken()) + return this.ahead[n - 1] +} |