[Pkg-javascript-commits] [node-acorn-jsx] 108/484: .parse_dammit() now recognizes the locations option, and will add a loc object to the ast nodes as .parse() does
Bastien Roucariès
rouca at moszumanska.debian.org
Sat Aug 19 14:20:11 UTC 2017
This is an automated email from the git hooks/post-receive script.
rouca pushed a commit to branch master
in repository node-acorn-jsx.
commit 559518acc877d9617f35bb2c9fde19c8d1cf9a1f
Author: Paul Harper <benekastah at gmail.com>
Date: Fri Mar 15 23:02:44 2013 -0600
.parse_dammit() now recognizes the locations option, and will add a loc object to the ast nodes as .parse() does
---
acorn_loose.js | 20 ++++++++++++++++++--
1 file changed, 18 insertions(+), 2 deletions(-)
diff --git a/acorn_loose.js b/acorn_loose.js
index 16742f8..4c97323 100644
--- a/acorn_loose.js
+++ b/acorn_loose.js
@@ -42,6 +42,7 @@
options = opts;
if (!opts.tabSize) opts.tabSize = 4;
fetchToken = acorn.tokenize(inpt, opts);
+ sourceFile = options.sourceFile || null;
context = [];
nextLineStart = 0;
ahead.length = 0;
@@ -50,14 +51,18 @@
};
var lastEnd, token = {start: 0, end: 0}, ahead = [];
- var curLineStart, nextLineStart, curIndent;
+ var curLineStart, nextLineStart, curIndent, lastEndLoc, sourceFile;
function next() {
lastEnd = token.end;
+ if (options.locations)
+ lastEndLoc = token.endLoc;
+
if (ahead.length)
token = ahead.shift();
else
token = readToken();
+
if (token.start >= nextLineStart) {
while (token.start >= nextLineStart) {
curLineStart = nextLineStart;
@@ -181,8 +186,17 @@
this.end = null;
}
+ function node_loc_t() {
+ this.start = token.startLoc;
+ this.end = null;
+ if (sourceFile !== null) this.source = sourceFile;
+ }
+
function startNode() {
- return new node_t(token.start);
+ var node = new node_t(token.start);
+ if (options.locations)
+ node.loc = new node_loc_t();
+ return node
}
function startNodeFrom(other) {
return new node_t(other.start);
@@ -190,6 +204,8 @@
function finishNode(node, type) {
node.type = type;
node.end = lastEnd;
+ if (options.locations)
+ node.loc.end = lastEndLoc;
return node;
}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-acorn-jsx.git
More information about the Pkg-javascript-commits
mailing list