Comparing version 0.6.0 to 0.7.0
@@ -134,18 +134,5 @@ // Acorn: Loose parser | ||
function copyToken(token) { | ||
var copy = {start: token.start, end: token.end, type: token.type, value: token.value}; | ||
if (options.locations) { | ||
copy.startLoc = token.startLoc; | ||
copy.endLoc = token.endLoc; | ||
} | ||
return copy; | ||
} | ||
function lookAhead(n) { | ||
// Copy token objects, because fetchToken will overwrite the one | ||
// it returns, and in this case we still need it | ||
if (!ahead.length) | ||
token = copyToken(token); | ||
while (n > ahead.length) | ||
ahead.push(copyToken(readToken())); | ||
ahead.push(readToken()); | ||
return ahead[n-1]; | ||
@@ -710,3 +697,4 @@ } | ||
if (!name) { if (isDummy(parseExpression(true))) next(); eat(tt.comma); continue; } | ||
var prop = {key: name}, isGetSet = false, kind; | ||
var prop = startNode(), isGetSet = false, kind; | ||
prop.key = name; | ||
if (eat(tt.colon)) { | ||
@@ -727,3 +715,3 @@ prop.value = parseExpression(true); | ||
node.properties.push(prop); | ||
node.properties.push(finishNode(prop, "Property")); | ||
eat(tt.comma); | ||
@@ -730,0 +718,0 @@ } |
@@ -6,3 +6,3 @@ { | ||
"main": "acorn.js", | ||
"version": "0.6.0", | ||
"version": "0.7.0", | ||
"engines": {"node": ">=0.4.0"}, | ||
@@ -17,3 +17,5 @@ "maintainers": [{"name": "Marijn Haverbeke", | ||
"scripts": {"test": "node test/run.js"}, | ||
"bin": {"acorn": "./bin/acorn"} | ||
"bin": {"acorn": "./bin/acorn"}, | ||
"devDependencies": {"regenerate": "~0.6.2", | ||
"unicode-7.0.0": "~0.1.5"} | ||
} |
# Acorn | ||
[![Build Status](https://travis-ci.org/marijnh/acorn.svg?branch=master)](https://travis-ci.org/marijnh/acorn) | ||
A tiny, fast JavaScript parser, written completely in JavaScript. | ||
@@ -51,4 +53,3 @@ | ||
either 3, 5, or 6. This influences support for strict mode, the set | ||
of reserved words, and support for getters and setter. Default is 5. | ||
ES6 is only partially supported. | ||
of reserved words, and support for new syntax features. Default is 5. | ||
@@ -76,2 +77,5 @@ - **strictSemicolons**: If `true`, prevents the parser from doing | ||
- **onToken**: If a function is passed for this option, each found | ||
token will be passed in same format as `tokenize()` returns. | ||
- **onComment**: If a function is passed for this option, whenever a | ||
@@ -108,3 +112,3 @@ comment is encountered the function will be called with the | ||
- **sourceFile**: When the `locations` option is `true`, you can pass | ||
this option to add a `sourceFile` attribute in every node’s `loc` | ||
this option to add a `source` attribute in every node’s `loc` | ||
object. Note that the contents of this option are not examined or | ||
@@ -114,4 +118,4 @@ processed in any way; you are free to use whatever format you | ||
- **directSourceFile**: Like `sourceFile`, but the property will be | ||
added directly to the nodes, rather than to a `loc` object. | ||
- **directSourceFile**: Like `sourceFile`, but a `sourceFile` property | ||
will be added directly to the nodes, rather than the `loc` object. | ||
@@ -135,2 +139,41 @@ [range]: https://bugzilla.mozilla.org/show_bug.cgi?id=745678 | ||
#### Note on using with [Escodegen][escodegen] | ||
Escodegen supports generating comments from AST, attached in | ||
Esprima-specific format. In order to simulate same format in | ||
Acorn, consider following example (this may be simplified | ||
in future): | ||
```javascript | ||
var comments = [], tokens = []; | ||
var ast = acorn.parse('var x = 42; // answer', { | ||
// collect ranges for each node | ||
ranges: true, | ||
// collect comments in Esprima's format | ||
onComment: function (block, text, start, end) { | ||
comments.push({ | ||
type: block ? 'Block' : 'Line', | ||
value: text, | ||
range: [start, end] | ||
}); | ||
}, | ||
// collect token ranges | ||
onToken: function (token) { | ||
tokens.push({ | ||
range: [token.start, token.end] | ||
}); | ||
} | ||
}); | ||
// attach comments using collected information | ||
escodegen.attachComments(ast, comments, tokens); | ||
// generate code | ||
console.log(escodegen.generate(ast, {comment: true})); | ||
// > 'var x = 42; // answer' | ||
``` | ||
[escodegen]: https://github.com/Constellation/escodegen | ||
### acorn_loose.js ### | ||
@@ -208,3 +251,3 @@ | ||
- `--ecma3|--ecma5`: Sets the ECMAScript version to parse. Default is | ||
- `--ecma3|--ecma5|--ecma6`: Sets the ECMAScript version to parse. Default is | ||
version 5. | ||
@@ -211,0 +254,0 @@ |
var driver = require("./driver.js"); | ||
require("./tests.js"); | ||
require("./tests-harmony.js"); | ||
@@ -13,3 +14,10 @@ var testsRun = 0, failed = 0; | ||
console.log(testsRun + " tests run in " + (+new Date - t0) + "ms"); | ||
if (failed) console.log(failed + " failures."); | ||
else console.log("All passed."); | ||
if (failed) { | ||
console.log(failed + " failures."); | ||
process.stdout.write("", function() { | ||
process.exit(1); | ||
}); | ||
} else { | ||
console.log("All passed."); | ||
} |
@@ -200,6 +200,6 @@ // AST walker module for Mozilla Parser API compatible trees | ||
}; | ||
base.ReturnStatement = function(node, st, c) { | ||
base.ReturnStatement = base.YieldExpression = function(node, st, c) { | ||
if (node.argument) c(node.argument, st, "Expression"); | ||
}; | ||
base.ThrowStatement = function(node, st, c) { | ||
base.ThrowStatement = base.SpreadElement = function(node, st, c) { | ||
c(node.argument, st, "Expression"); | ||
@@ -223,3 +223,3 @@ }; | ||
}; | ||
base.ForInStatement = function(node, st, c) { | ||
base.ForInStatement = base.ForOfStatement = function(node, st, c) { | ||
c(node.left, st, "ForInit"); | ||
@@ -262,6 +262,6 @@ c(node.right, st, "Expression"); | ||
for (var i = 0; i < node.properties.length; ++i) | ||
c(node.properties[i].value, st, "Expression"); | ||
c(node.properties[i], st); | ||
}; | ||
base.FunctionExpression = base.FunctionDeclaration; | ||
base.SequenceExpression = function(node, st, c) { | ||
base.FunctionExpression = base.ArrowFunctionExpression = base.FunctionDeclaration; | ||
base.SequenceExpression = base.TemplateLiteral = function(node, st, c) { | ||
for (var i = 0; i < node.expressions.length; ++i) | ||
@@ -291,4 +291,23 @@ c(node.expressions[i], st, "Expression"); | ||
}; | ||
base.Identifier = base.Literal = ignore; | ||
base.Identifier = base.Literal = base.ExportDeclaration = base.ImportDeclaration = ignore; | ||
base.TaggedTemplateExpression = function(node, st, c) { | ||
c(node.tag, st, "Expression"); | ||
c(node.quasi, st); | ||
}; | ||
base.ClassDeclaration = base.ClassExpression = function(node, st, c) { | ||
if (node.superClass) c(node.superClass, st, "Expression"); | ||
for (var i = 0; i < node.body.body.length; i++) | ||
c(node.body.body[i], st); | ||
}; | ||
base.MethodDefinition = base.Property = function(node, st, c) { | ||
if (node.computed) c(node.key, st, "Expression"); | ||
c(node.value, st, "Expression"); | ||
}; | ||
base.ComprehensionExpression = function(node, st, c) { | ||
for (var i = 0; i < node.blocks.length; i++) | ||
c(node.blocks[i].right, st, "Expression"); | ||
c(node.body, st, "Expression"); | ||
}; | ||
// A custom walker that keeps track of the scope chain and the | ||
@@ -295,0 +314,0 @@ // variables defined in it. |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
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
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
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
3024299
28
87893
264
2
1
1