Skip to content
This repository was archived by the owner on Jan 19, 2019. It is now read-only.

Fix: Add start and end propert to tokens (fixes #172) #176

Merged
merged 1 commit into from
Feb 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/ast-converter.js
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,8 @@ function convertToken(token, ast) {
newToken = {
type: getTokenType(token),
value: value,
start: start,
end: token.end,
range: [start, token.end],
loc: getLoc(token, ast)
};
Expand Down
14 changes: 3 additions & 11 deletions tests/lib/attach-comments.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ var assert = require("chai").assert,
leche = require("leche"),
path = require("path"),
parser = require("../../parser"),
shelljs = require("shelljs");
shelljs = require("shelljs"),
tester = require("./tester");

//------------------------------------------------------------------------------
// Setup
Expand All @@ -48,15 +49,6 @@ var testFiles = shelljs.find(FIXTURES_DIR).filter(function(filename) {
return filename.substring(FIXTURES_DIR.length - 1, filename.length - 7); // strip off ".src.js"
});

/**
* Returns a raw copy of the given AST
* @param {object} ast the AST object
* @returns {object} copy of the AST object
*/
function getRaw(ast) {
return JSON.parse(JSON.stringify(ast));
}

//------------------------------------------------------------------------------
// Tests
//------------------------------------------------------------------------------
Expand Down Expand Up @@ -84,7 +76,7 @@ describe("attachComment: true", function() {

try {
result = parser.parse(code, config);
result = getRaw(result);
result = tester.getRaw(result);
} catch (ex) {

// format of error isn't exactly the same, just check if it's expected
Expand Down
14 changes: 3 additions & 11 deletions tests/lib/basics.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ var assert = require("chai").assert,
leche = require("leche"),
path = require("path"),
parser = require("../../parser"),
shelljs = require("shelljs");
shelljs = require("shelljs"),
tester = require("./tester");

//------------------------------------------------------------------------------
// Setup
Expand All @@ -29,15 +30,6 @@ var testFiles = shelljs.find(FIXTURES_DIR).filter(function(filename) {
return filename.substring(FIXTURES_DIR.length - 1, filename.length - 7); // strip off ".src.js"
});

/**
* Returns a raw copy of the given AST
* @param {object} ast the AST object
* @returns {object} copy of the AST object
*/
function getRaw(ast) {
return JSON.parse(JSON.stringify(ast));
}

//------------------------------------------------------------------------------
// Tests
//------------------------------------------------------------------------------
Expand Down Expand Up @@ -66,7 +58,7 @@ describe("basics", function() {

try {
result = parser.parse(code, config);
result = getRaw(result);
result = tester.getRaw(result);
} catch (ex) {

// format of error isn't exactly the same, just check if it's expected
Expand Down
14 changes: 3 additions & 11 deletions tests/lib/ecma-features.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ var assert = require("chai").assert,
leche = require("leche"),
path = require("path"),
parser = require("../../parser"),
shelljs = require("shelljs");
shelljs = require("shelljs"),
tester = require("./tester");

//------------------------------------------------------------------------------
// Setup
Expand Down Expand Up @@ -58,15 +59,6 @@ var testFiles = shelljs.find(FIXTURES_DIR).filter(function(filename) {
// console.dir(moduleTestFiles);
// return;

/**
* Returns a raw copy of the given AST
* @param {object} ast the AST object
* @returns {object} copy of the AST object
*/
function getRaw(ast) {
return JSON.parse(JSON.stringify(ast));
}

//------------------------------------------------------------------------------
// Tests
//------------------------------------------------------------------------------
Expand Down Expand Up @@ -97,7 +89,7 @@ describe("ecmaFeatures", function() {

try {
result = parser.parse(code, config);
result = getRaw(result);
result = tester.getRaw(result);
} catch (ex) {

// format of error isn't exactly the same, just check if it's expected
Expand Down
18 changes: 3 additions & 15 deletions tests/lib/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,8 @@
//------------------------------------------------------------------------------

var assert = require("chai").assert,
parser = require("../../parser");

//------------------------------------------------------------------------------
// Helpers
//------------------------------------------------------------------------------

/**
* Returns a raw copy of the given AST
* @param {object} ast the AST object
* @returns {object} copy of the AST object
*/
function getRaw(ast) {
return JSON.parse(JSON.stringify(ast));
}
parser = require("../../parser"),
tester = require("./tester");

//------------------------------------------------------------------------------
// Tests
Expand Down Expand Up @@ -68,7 +56,7 @@ describe("parse()", function() {
loc: true
});

assert.deepEqual(getRaw(ast), require("../fixtures/parse/all-pieces.json"));
assert.deepEqual(tester.getRaw(ast), require("../fixtures/parse/all-pieces.json"));
});

});
Expand Down
31 changes: 31 additions & 0 deletions tests/lib/tester.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* @fileoverview Tools for running test cases
* @author Nicholas C. Zakas
* @copyright jQuery Foundation and other contributors, https://jquery.org/
* MIT License
*/

"use strict";

//------------------------------------------------------------------------------
// Private
//--------------------------------------------------------------------------------

/**
* Returns a raw copy of the given AST
* @param {object} ast the AST object
* @returns {object} copy of the AST object
*/
function getRaw(ast) {
return JSON.parse(JSON.stringify(ast, function(key, value) {
if ((key === "start" || key === "end") && typeof value === "number") {
return undefined; // eslint-disable-line no-undefined
}

return value;
}));
}

module.exports = {
getRaw: getRaw
};
14 changes: 3 additions & 11 deletions tests/lib/typescript.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ var assert = require("chai").assert,
leche = require("leche"),
path = require("path"),
parser = require("../../parser"),
shelljs = require("shelljs");
shelljs = require("shelljs"),
tester = require("./tester");

//------------------------------------------------------------------------------
// Setup
Expand All @@ -29,15 +30,6 @@ var testFiles = shelljs.find(FIXTURES_DIR).filter(function(filename) {
return filename.substring(FIXTURES_DIR.length - 1, filename.length - 7); // strip off ".src.ts"
});

/**
* Returns a raw copy of the given AST
* @param {object} ast the AST object
* @returns {object} copy of the AST object
*/
function getRaw(ast) {
return JSON.parse(JSON.stringify(ast));
}

//------------------------------------------------------------------------------
// Tests
//------------------------------------------------------------------------------
Expand Down Expand Up @@ -66,7 +58,7 @@ describe("typescript", function() {

try {
result = parser.parse(code, config);
result = getRaw(result);
result = tester.getRaw(result);
} catch (ex) {

// format of error isn't exactly the same, just check if it's expected
Expand Down