1 import {Parser} from "./state.js"
2 import {SourceLocation} from "./locutil.js"
5 constructor(parser, pos, loc) {
9 if (parser.options.locations)
10 this.loc = new SourceLocation(parser, loc)
11 if (parser.options.directSourceFile)
12 this.sourceFile = parser.options.directSourceFile
13 if (parser.options.ranges)
18 // Start an AST node, attaching a start offset.
20 const pp = Parser.prototype
22 pp.startNode = function() {
23 return new Node(this, this.start, this.startLoc)
26 pp.startNodeAt = function(pos, loc) {
27 return new Node(this, pos, loc)
30 // Finish an AST node, adding `type` and `end` properties.
32 function finishNodeAt(node, type, pos, loc) {
35 if (this.options.locations)
37 if (this.options.ranges)
42 pp.finishNode = function(node, type) {
43 return finishNodeAt.call(this, node, type, this.lastTokEnd, this.lastTokEndLoc)
46 // Finish node at given position
48 pp.finishNodeAt = function(node, type, pos, loc) {
49 return finishNodeAt.call(this, node, type, pos, loc)
52 pp.copyNode = function(node) {
53 let newNode = new Node(this, node.start, this.startLoc)
54 for (let prop in node) newNode[prop] = node[prop]