Comparing version 0.2.3 to 0.2.4
@@ -35,3 +35,3 @@ var esprima = require('esprima'); | ||
this.node.sort(function (prev, node) { | ||
if (node && node.expression.type === 'Literal' && node.expression.value === 'use strict') { | ||
if (node && node.expression && node.expression.type === 'Literal' && node.expression.value === 'use strict') { | ||
return 1; | ||
@@ -38,0 +38,0 @@ } |
@@ -10,4 +10,22 @@ var esprima = require('esprima'); | ||
var esprimaOptions = { | ||
comment: true, | ||
range: true, | ||
loc: false, | ||
tokens: true, | ||
raw: false | ||
}; | ||
var escodegenOptions = { | ||
comment: true, | ||
format: { | ||
indent: { | ||
adjustMultilineComment: true | ||
} | ||
} | ||
}; | ||
function Tree(source) { | ||
this.tree = esprima.parse(source); | ||
this.tree = esprima.parse(source.toString(),esprimaOptions); | ||
this.tree = escodegen.attachComments(this.tree, this.tree.comments, this.tree.tokens); | ||
this.body = new Body(this.tree.body); | ||
@@ -27,3 +45,3 @@ } | ||
}); | ||
return escodegen.generate(tree); | ||
return escodegen.generate(tree, escodegenOptions); | ||
}; | ||
@@ -30,0 +48,0 @@ |
{ | ||
"name": "ast-query", | ||
"version": "0.2.3", | ||
"version": "0.2.4", | ||
"description": "Declarative JavaScript AST modification façade", | ||
@@ -5,0 +5,0 @@ "main": "lib/tree.js", |
@@ -81,3 +81,3 @@ AST Query | ||
Find and return an [`AssignementExpression` node](#AssignementExpression-node). | ||
Find and return an [`AssignmentExpression` node](#assignmentexpression-node). | ||
@@ -117,5 +117,5 @@ You'd call `tree.assignment('module.exports')` to query the code below: | ||
A property pointing to an [`ArrayExpression` node] referencing the called function arguments. | ||
A property pointing to an [`ArrayExpression` node](#arrayexpression-node) referencing the called function arguments. | ||
AssignementExpression node | ||
AssignmentExpression node | ||
-------------------- | ||
@@ -125,3 +125,3 @@ | ||
Replace the assignement value with a new value or return the current value wrapped in an AST query interface. | ||
Replace the assignment value with a new value or return the current value wrapped in an AST query interface. | ||
@@ -128,0 +128,0 @@ Literal node |
@@ -13,2 +13,12 @@ var assert = require('assert'); | ||
describe('#toString() - with comments', function () { | ||
it('return the generated source code', function () { | ||
var tree = program('/* comment */var a = 1'); | ||
assert.equal(tree.toString().replace(/[\r\n\t\s]+/gm,''), '/*comment*/vara=1;'); | ||
tree = program('var a = {\n/* comment */a:1};'); | ||
assert.equal(tree.toString().replace(/[\r\n\t\s]+/gm,''), 'vara={/*comment*/a:1};'); | ||
}); | ||
}); | ||
describe('#body', function () { | ||
@@ -15,0 +25,0 @@ it('is a Body node instance', function () { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
30983
686