You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1 line
98 KiB
1 line
98 KiB
|
3 years ago
|
{"version":3,"file":"acorn-loose.js","sources":["../src/state.js","../src/tokenize.js","../src/parseutil.js","../src/statement.js","../src/expression.js","../src/index.js"],"sourcesContent":["import {Parser, SourceLocation, tokTypes as tt, Node, lineBreak, isNewLine} from \"acorn\"\n\nfunction noop() {}\n\nexport class LooseParser {\n constructor(input, options = {}) {\n this.toks = this.constructor.BaseParser.tokenizer(input, options)\n this.options = this.toks.options\n this.input = this.toks.input\n this.tok = this.last = {type: tt.eof, start: 0, end: 0}\n this.tok.validateRegExpFlags = noop\n this.tok.validateRegExpPattern = noop\n if (this.options.locations) {\n let here = this.toks.curPosition()\n this.tok.loc = new SourceLocation(this.toks, here, here)\n }\n this.ahead = [] // Tokens ahead\n this.context = [] // Indentation contexted\n this.curIndent = 0\n this.curLineStart = 0\n this.nextLineStart = this.lineEnd(this.curLineStart) + 1\n this.inAsync = false\n this.inFunction = false\n }\n\n startNode() {\n return new Node(this.toks, this.tok.start, this.options.locations ? this.tok.loc.start : null)\n }\n\n storeCurrentPos() {\n return this.options.locations ? [this.tok.start, this.tok.loc.start] : this.tok.start\n }\n\n startNodeAt(pos) {\n if (this.options.locations) {\n return new Node(this.toks, pos[0], pos[1])\n } else {\n return new Node(this.toks, pos)\n }\n }\n\n finishNode(node, type) {\n node.type = type\n node.end = this.last.end\n if (this.options.locations)\n node.loc.end = this.last.loc.end\n if (this.options.ranges)\n node.range[1] = this.last.end\n return node\n }\n\n dummyNode(type) {\n let dummy = this.startNode()\n dummy.type = type\n dummy.end = dummy.start\n if (this.options.locations)\n dummy.loc.end = dummy.loc.start\n if (this.options.ranges)\n dummy.range[1] = dummy.start\n this.last = {type: tt.name, start: dummy.start, end: dummy.start, loc: dummy.loc}\n return dummy\n }\n\n dummyIdent() {\n let dummy = this.dummyNode(\"Identifier\")\n dummy.name = \"✖\"\n return dummy\n }\n\n dummyString() {\n let dummy = this.dummyNode(\"Literal\")\n dummy.value = dummy.raw = \"✖\"\n return dummy\n }\n\n eat(type) {\n if (this.tok.type === type) {\n this.next()\n return true\n } else {\n return false\n }\n }\n\n isContextual(name) {\n return this.tok.type === tt.name && this.tok.value === name\n }\n\n eatContextual(name) {\n return this.tok.value === name && this.eat(tt.name)\n }\n\n canInsertSemicolon() {\n return this.tok.type === tt.eof || this.tok.type === tt.braceR ||\n lineBreak.test(this.input.slice(this.last.end, this.tok.start))\n }\n\n semicolon() {\n return this.eat(tt.semi)\n }\n\n expect(type) {\n if (this.eat(type)) return true\n for (let i = 1; i <= 2; i++) {\n if (this.lookAhead(i).type === type) {\n for (let j = 0; j < i; j++) this.next()\n return true\n }\n }\n }\n\n pushCx() {\n this.context.push(this.curIndent)\n }\n\n popCx() {\n this.curIndent = this.context.pop()\n }\n\n lineEnd(pos) {\n while (pos < this.input.length && !isNewLine(this.input.charCodeAt(pos))) ++pos\n return pos\n }\n\n indentationAfter(pos) {\n for (let count = 0;; ++pos) {\n let ch = this.input.charCodeAt(pos)\n if (ch === 32) ++count\n else if (ch === 9) count += this.options.tabSize\n else return count\n }\n }\n\n closes(closeTok, indent, line, blockHeuristic) {\n if (this.tok.type === closeTok || this.tok.type === tt.eof) return true\n return line !== this.curLineStart && this.curIndent < indent && this.tokenStartsLine() &&\n (!blockHeuristic || this.nextLineStart >= this.input.length ||\n this.indentationAfter(this.nextLineStart) < indent)\n }\n\n tokenStartsLine() {\n for (let p = this.tok.start - 1; p >= this.curLineStart; --p) {\n let ch = this.input.charCodeAt(p)\n if
|