babel/src/parser/node.js
Sebastian McKenzie b909a81ab7 6.0.0
I'm extremely stupid and didn't commit as I go. To anyone reading this
I'm extremely sorry. A lot of these changes are very broad and I plan on
releasing Babel 6.0.0 today live on stage at Ember Camp London so I'm
afraid I couldn't wait. If you're ever in London I'll buy you a beer
(or assorted beverage!) to make up for it, also I'll kiss your feet and
give you a back massage, maybe.
2015-10-29 17:51:24 +00:00

57 lines
1.2 KiB
JavaScript

/* @flow */
import Parser from "./index";
import { SourceLocation } from "../util/location";
// Start an AST node, attaching a start offset.
const pp = Parser.prototype;
class Node {
constructor(pos?: number, loc?: SourceLocation) {
this.type = "";
this.start = pos;
this.end = 0;
this.loc = new SourceLocation(loc);
}
type: string;
start: ?number;
end: number;
loc: SourceLocation;
__clone(): Node {
let node2 = new Node;
for (let key in this) node2[key] = this[key];
return node2;
}
}
pp.startNode = function () {
return new Node(this.state.start, this.state.startLoc);
};
pp.startNodeAt = function (pos, loc) {
return new Node(pos, loc);
};
function finishNodeAt(node, type, pos, loc) {
node.type = type;
node.end = pos;
node.loc.end = loc;
this.processComment(node);
return node;
}
// Finish an AST node, adding `type` and `end` properties.
pp.finishNode = function (node, type) {
return finishNodeAt.call(this, node, type, this.state.lastTokEnd, this.state.lastTokEndLoc);
};
// Finish node at given position
pp.finishNodeAt = function (node, type, pos, loc) {
return finishNodeAt.call(this, node, type, pos, loc);
};