From ad69446c0a95d58804f12d63785b160ac93d2760 Mon Sep 17 00:00:00 2001 From: Mike Rennie Date: Thu, 9 Oct 2014 13:12:02 -0500 Subject: [PATCH] Make parse_dammit honour the 'ranges' option Closes #140 --- acorn_loose.js | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/acorn_loose.js b/acorn_loose.js index 634479280c..d94fb46c64 100644 --- a/acorn_loose.js +++ b/acorn_loose.js @@ -209,6 +209,8 @@ node.loc = new SourceLocation(); if (options.directSourceFile) node.sourceFile = options.directSourceFile; + if (options.ranges) + node.range = [token.start, 0]; return node; } @@ -226,6 +228,8 @@ } if (options.directSourceFile) node.sourceFile = options.directSourceFile; + if (options.ranges) + node.range = [pos[0], 0]; return node; } @@ -234,24 +238,15 @@ node.end = lastEnd; if (options.locations) node.loc.end = lastEndLoc; + if (options.ranges) + node.range[1] = lastEnd; return node; } - function getDummyLoc() { - if (options.locations) { - var loc = new SourceLocation(); - loc.end = loc.start; - return loc; - } - }; - function dummyIdent() { - var dummy = new Node(token.start); - dummy.type = "Identifier"; - dummy.end = token.start; + var dummy = startNode(); dummy.name = "✖"; - dummy.loc = getDummyLoc(); - return dummy; + return finishNode(dummy, "Identifier"); } function isDummy(node) { return node.name == "✖"; }