react / wstein / node_modules / browserify / node_modules / syntax-error / node_modules / acorn / src / node.js
80551 viewsimport {Parser} from "./state"1import {SourceLocation} from "./location"23// Start an AST node, attaching a start offset.45const pp = Parser.prototype67export class Node {}89pp.startNode = function() {10let node = new Node11node.start = this.start12if (this.options.locations)13node.loc = new SourceLocation(this, this.startLoc)14if (this.options.directSourceFile)15node.sourceFile = this.options.directSourceFile16if (this.options.ranges)17node.range = [this.start, 0]18return node19}2021pp.startNodeAt = function(pos, loc) {22let node = new Node23if (Array.isArray(pos)){24if (this.options.locations && loc === undefined) {25// flatten pos26loc = pos[1]27pos = pos[0]28}29}30node.start = pos31if (this.options.locations)32node.loc = new SourceLocation(this, loc)33if (this.options.directSourceFile)34node.sourceFile = this.options.directSourceFile35if (this.options.ranges)36node.range = [pos, 0]37return node38}3940// Finish an AST node, adding `type` and `end` properties.4142pp.finishNode = function(node, type) {43node.type = type44node.end = this.lastTokEnd45if (this.options.locations)46node.loc.end = this.lastTokEndLoc47if (this.options.ranges)48node.range[1] = this.lastTokEnd49return node50}5152// Finish node at given position5354pp.finishNodeAt = function(node, type, pos, loc) {55node.type = type56if (Array.isArray(pos)){57if (this.options.locations && loc === undefined) {58// flatten pos59loc = pos[1]60pos = pos[0]61}62}63node.end = pos64if (this.options.locations)65node.loc.end = loc66if (this.options.ranges)67node.range[1] = pos68return node69}707172