UNPKG

1.53 kBJavaScriptView Raw
1/* @flow */
2
3"use strict";
4
5var _classCallCheck = require("babel-runtime/helpers/class-call-check")["default"];
6
7var _interopRequireDefault = require("babel-runtime/helpers/interop-require-default")["default"];
8
9var _index = require("./index");
10
11var _index2 = _interopRequireDefault(_index);
12
13var _utilLocation = require("../util/location");
14
15// Start an AST node, attaching a start offset.
16
17var pp = _index2["default"].prototype;
18
19var Node = (function () {
20 function Node(pos /*:: ?: number*/, loc /*:: ?: SourceLocation*/) {
21 _classCallCheck(this, Node);
22
23 this.type = "";
24 this.start = pos;
25 this.end = 0;
26 this.loc = new _utilLocation.SourceLocation(loc);
27 }
28
29 Node.prototype.__clone = function __clone() /*: Node*/ {
30 var node2 = new Node();
31 for (var key in this) {
32 node2[key] = this[key];
33 }return node2;
34 };
35
36 return Node;
37})();
38
39pp.startNode = function () {
40 return new Node(this.state.start, this.state.startLoc);
41};
42
43pp.startNodeAt = function (pos, loc) {
44 return new Node(pos, loc);
45};
46
47function finishNodeAt(node, type, pos, loc) {
48 node.type = type;
49 node.end = pos;
50 node.loc.end = loc;
51 this.processComment(node);
52 return node;
53}
54
55// Finish an AST node, adding `type` and `end` properties.
56
57pp.finishNode = function (node, type) {
58 return finishNodeAt.call(this, node, type, this.state.lastTokEnd, this.state.lastTokEndLoc);
59};
60
61// Finish node at given position
62
63pp.finishNodeAt = function (node, type, pos, loc) {
64 return finishNodeAt.call(this, node, type, pos, loc);
65};
\No newline at end of file