Comparing version 1.0.4 to 1.1.0
@@ -110,6 +110,16 @@ #!/usr/bin/env node | ||
// Special handling for regular expression literal since we need to | ||
// convert it to a string literal, otherwise it will be decoded | ||
// as object "{}" and the regular expression would be lost. | ||
function adjustRegexLiteral(key, value) { | ||
if (key === 'value' && value instanceof RegExp) { | ||
value = value.toString(); | ||
} | ||
return value; | ||
} | ||
try { | ||
content = fs.readFileSync(fname, 'utf-8'); | ||
syntax = esprima.parse(content, options); | ||
console.log(JSON.stringify(syntax, null, 4)); | ||
console.log(JSON.stringify(syntax, adjustRegexLiteral, 4)); | ||
} catch (e) { | ||
@@ -116,0 +126,0 @@ console.log('Error: ' + e.message); |
@@ -27,16 +27,34 @@ #!/usr/bin/env node | ||
/*jslint sloppy:true plusplus:true node:true rhino:true */ | ||
/*global phantom:true */ | ||
var fs, esprima, options, fnames, count; | ||
var fs, system, esprima, options, fnames, count; | ||
if (typeof require === 'function') { | ||
fs = require('fs'); | ||
esprima = require('esprima'); | ||
} else if (typeof load === 'function') { | ||
try { | ||
load('esprima.js'); | ||
} catch (e) { | ||
load('../esprima.js'); | ||
if (typeof esprima === 'undefined') { | ||
// PhantomJS can only require() relative files | ||
if (typeof phantom === 'object') { | ||
fs = require('fs'); | ||
system = require('system'); | ||
esprima = require('./esprima'); | ||
} else if (typeof require === 'function') { | ||
fs = require('fs'); | ||
esprima = require('esprima'); | ||
} else if (typeof load === 'function') { | ||
try { | ||
load('esprima.js'); | ||
} catch (e) { | ||
load('../esprima.js'); | ||
} | ||
} | ||
} | ||
// Shims to Node.js objects when running under PhantomJS 1.7+. | ||
if (typeof phantom === 'object') { | ||
fs.readFileSync = fs.read; | ||
process = { | ||
argv: [].slice.call(system.args), | ||
exit: phantom.exit | ||
}; | ||
process.argv.unshift('phantomjs'); | ||
} | ||
// Shims to Node.js objects when running under Rhino. | ||
@@ -179,1 +197,5 @@ if (typeof console === 'undefined' && typeof process === 'undefined') { | ||
} | ||
if (count === 0 && typeof phantom === 'object') { | ||
process.exit(0); | ||
} |
@@ -10,2 +10,3 @@ { | ||
}, | ||
"version": "1.1.0", | ||
"files": [ | ||
@@ -20,6 +21,9 @@ "bin", | ||
], | ||
"version": "1.0.4", | ||
"engines": { | ||
"node": ">=0.4.0" | ||
}, | ||
"author": { | ||
"name": "Ariya Hidayat", | ||
"email": "ariya.hidayat@gmail.com" | ||
}, | ||
"maintainers": [{ | ||
@@ -34,2 +38,5 @@ "name": "Ariya Hidayat", | ||
}, | ||
"bugs": { | ||
"url": "http://issues.esprima.org" | ||
}, | ||
"licenses": [{ | ||
@@ -39,2 +46,13 @@ "type": "BSD", | ||
}], | ||
"devDependencies": { | ||
"jslint": "~0.1.9", | ||
"eslint": "~0.4.3", | ||
"jscs": "~1.2.4", | ||
"istanbul": "~0.1.27", | ||
"complexity-report": "~0.6.1", | ||
"regenerate": "~0.5.4", | ||
"unicode-6.3.0": "~0.1.0", | ||
"json-diff": "~0.3.1", | ||
"optimist": "~0.6.0" | ||
}, | ||
"keywords": [ | ||
@@ -48,3 +66,20 @@ "ast", | ||
"scripts": { | ||
"test": "node test/run.js", | ||
"generate-regex": "node tools/generate-identifier-regex.js", | ||
"test": "npm run-script lint && node test/run.js && npm run-script coverage && npm run-script complexity", | ||
"lint": "npm run-script check-version && npm run-script eslint && npm run-script jscs && npm run-script jslint", | ||
"check-version": "node tools/check-version.js", | ||
"eslint": "node node_modules/eslint/bin/eslint.js esprima.js", | ||
"jscs": "node node_modules/.bin/jscs esprima.js", | ||
"jslint": "node node_modules/jslint/bin/jslint.js esprima.js", | ||
"coverage": "npm run-script analyze-coverage && npm run-script check-coverage", | ||
"analyze-coverage": "node node_modules/istanbul/lib/cli.js cover test/runner.js", | ||
"check-coverage": "node node_modules/istanbul/lib/cli.js check-coverage --statement -8 --branch -19 --function 100", | ||
"complexity": "npm run-script analyze-complexity && npm run-script check-complexity", | ||
"analyze-complexity": "node tools/list-complexity.js", | ||
"check-complexity": "node node_modules/complexity-report/src/cli.js --maxcc 17 --silent -l -w esprima.js", | ||
"benchmark": "node test/benchmarks.js", | ||
@@ -51,0 +86,0 @@ "benchmark-quick": "node test/benchmarks.js quick" |
@@ -1,2 +0,2 @@ | ||
**Esprima** ([esprima.org](http://esprima.org)) is a high performance, | ||
**Esprima** ([esprima.org](http://esprima.org), BSD license) is a high performance, | ||
standard-compliant [ECMAScript](http://www.ecma-international.org/publications/standards/Ecma-262.htm) | ||
@@ -8,67 +8,18 @@ parser written in ECMAScript (also popularly known as | ||
Esprima runs on web browsers (IE 6+, Firefox 1+, Safari 3+, Chrome 1+, Konqueror 4.6+, Opera 8+) as well as | ||
[Node.js](http://nodejs.org). | ||
### Features | ||
- Full support for [ECMAScript 5.1](http://www.ecma-international.org/publications/standards/Ecma-262.htm)(ECMA-262) | ||
- Full support for ECMAScript 5.1 ([ECMA-262](http://www.ecma-international.org/publications/standards/Ecma-262.htm)) | ||
- Sensible [syntax tree format](http://esprima.org/doc/index.html#ast) compatible with Mozilla | ||
[Parser AST](https://developer.mozilla.org/en/SpiderMonkey/Parser_API) | ||
- Heavily tested (> 550 [unit tests](http://esprima.org/test/) with solid 100% statement coverage) | ||
- Optional tracking of syntax node location (index-based and line-column) | ||
- Heavily tested (> 600 [unit tests](http://esprima.org/test/) with solid statement and branch coverage) | ||
- Experimental support for ES6/Harmony (module, class, destructuring, ...) | ||
Esprima is blazing fast (see the [benchmark suite](http://esprima.org/test/benchmarks.html)). | ||
It is up to 3x faster than UglifyJS v1 and it is still [competitive](http://esprima.org/test/compare.html) | ||
with the new generation of fast parsers. | ||
Esprima serves as a **building block** for some JavaScript | ||
language tools, from [code instrumentation](http://esprima.org/demo/functiontrace.html) | ||
to [editor autocompletion](http://esprima.org/demo/autocomplete.html). | ||
### Applications | ||
Esprima runs on many popular web browsers, as well as other ECMAScript platforms such as | ||
[Rhino](http://www.mozilla.org/rhino) and [Node.js](https://npmjs.org/package/esprima). | ||
Esprima serves as the basis for many popular JavaScript development tools: | ||
- Code coverage analysis: [node-cover](https://github.com/itay/node-cover), [Istanbul](https://github.com/yahoo/Istanbul) | ||
- Documentation tool: [JFDoc](https://github.com/thejohnfreeman/jfdoc), [JSDuck](https://github.com/senchalabs/jsduck) | ||
- Language extension: [LLJS](http://mbebenita.github.com/LLJS/) (low-level JS), | ||
[Sweet.js](http://sweetjs.org/) (macro) | ||
- ES6/Harmony transpiler: [Six](https://github.com/matthewrobb/six), [Harmonizr](https://github.com/jdiamond/harmonizr) | ||
- Eclipse Orion smart editing ([outline view](https://github.com/aclement/esprima-outline), [content assist](http://contraptionsforprogramming.blogspot.com/2012/02/better-javascript-content-assist-in.html)) | ||
- Source code modification: [Esmorph](https://github.com/ariya/esmorph), [Code Painter](https://github.com/fawek/codepainter), | ||
- Source transformation: [node-falafel](https://github.com/substack/node-falafel), [Esmangle](https://github.com/Constellation/esmangle), [escodegen](https://github.com/Constellation/escodegen) | ||
### Questions? | ||
- [Documentation](http://esprima.org/doc) | ||
- [Issue tracker](http://issues.esprima.org): [known problems](http://code.google.com/p/esprima/issues/list?q=Defect) | ||
and [future plans](http://code.google.com/p/esprima/issues/list?q=Enhancement) | ||
- [Mailing list](http://groups.google.com/group/esprima) | ||
- [Contribution guide](http://esprima.org/doc/index.html#contribution) | ||
Follow [@Esprima](http://twitter.com/Esprima) on Twitter to get the | ||
development updates. | ||
Feedback and contribution are welcomed! | ||
### License | ||
Copyright (C) 2012, 2011 [Ariya Hidayat](http://ariya.ofilabs.com/about) | ||
and other contributors. | ||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are met: | ||
* Redistributions of source code must retain the above copyright | ||
notice, this list of conditions and the following disclaimer. | ||
* Redistributions in binary form must reproduce the above copyright | ||
notice, this list of conditions and the following disclaimer in the | ||
documentation and/or other materials provided with the distribution. | ||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY | ||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
For more information, check the web site [esprima.org](http://esprima.org). |
@@ -186,9 +186,11 @@ /* | ||
if (failures > 0) { | ||
document.getElementById('status').className = 'alert-box alert'; | ||
setText(document.getElementById('status'), total + ' tests. ' + | ||
'Failures: ' + failures + '. ' + tick + ' ms'); | ||
} else { | ||
document.getElementById('status').className = 'alert-box success'; | ||
setText(document.getElementById('status'), total + ' tests. ' + | ||
'No failure. ' + tick + ' ms'); | ||
} | ||
}, 513); | ||
}, 11); | ||
}; | ||
@@ -195,0 +197,0 @@ } else { |
@@ -39,3 +39,4 @@ /* | ||
'runner', | ||
'compat' | ||
'compat', | ||
'parselibs' | ||
]; | ||
@@ -42,0 +43,0 @@ |
@@ -74,2 +74,17 @@ /* | ||
function hasAttachedComment(syntax) { | ||
var key; | ||
for (key in syntax) { | ||
if (key === 'leadingComments' || key === 'trailingComments') { | ||
return true; | ||
} | ||
if (typeof syntax[key] === 'object' && syntax[key] !== null) { | ||
if (hasAttachedComment(syntax[key])) { | ||
return true; | ||
} | ||
} | ||
} | ||
return false; | ||
} | ||
function testParse(esprima, code, syntax) { | ||
@@ -88,5 +103,10 @@ 'use strict'; | ||
raw: true, | ||
tolerant: (typeof syntax.errors !== 'undefined') | ||
tolerant: (typeof syntax.errors !== 'undefined'), | ||
source: null | ||
}; | ||
if (options.comment) { | ||
options.attachComment = hasAttachedComment(syntax); | ||
} | ||
if (typeof syntax.tokens !== 'undefined') { | ||
@@ -106,4 +126,13 @@ if (syntax.tokens.length > 0) { | ||
if (options.loc) { | ||
options.source = syntax.loc.source; | ||
} | ||
expected = JSON.stringify(syntax, null, 4); | ||
try { | ||
// Some variations of the options. | ||
tree = esprima.parse(code, { tolerant: options.tolerant }); | ||
tree = esprima.parse(code, { tolerant: options.tolerant, range: true }); | ||
tree = esprima.parse(code, { tolerant: options.tolerant, loc: true }); | ||
tree = esprima.parse(code, options); | ||
@@ -165,5 +194,29 @@ tree = (options.comment || options.tokens || options.tolerant) ? tree : tree.body[0]; | ||
function testTokenize(esprima, code, tokens) { | ||
'use strict'; | ||
var options, expected, actual, tree; | ||
options = { | ||
comment: true, | ||
tolerant: true, | ||
loc: true, | ||
range: true | ||
}; | ||
expected = JSON.stringify(tokens, null, 4); | ||
try { | ||
tree = esprima.tokenize(code, options); | ||
actual = JSON.stringify(tree, null, 4); | ||
} catch (e) { | ||
throw new NotMatchingError(expected, e.toString()); | ||
} | ||
if (expected !== actual) { | ||
throw new NotMatchingError(expected, actual); | ||
} | ||
} | ||
function testError(esprima, code, exception) { | ||
'use strict'; | ||
var i, options, expected, actual, handleInvalidRegexFlag; | ||
var i, options, expected, actual, err, handleInvalidRegexFlag, tokenize; | ||
@@ -188,2 +241,8 @@ // Different parsing options should give the same error. | ||
exception.description = exception.message.replace(/Error: Line [0-9]+: /, ''); | ||
if (exception.tokenize) { | ||
tokenize = true; | ||
exception.tokenize = undefined; | ||
} | ||
expected = JSON.stringify(exception); | ||
@@ -194,5 +253,11 @@ | ||
try { | ||
esprima.parse(code, options[i]); | ||
if (tokenize) { | ||
esprima.tokenize(code, options[i]) | ||
} else { | ||
esprima.parse(code, options[i]); | ||
} | ||
} catch (e) { | ||
actual = JSON.stringify(errorToObject(e)); | ||
err = errorToObject(e); | ||
err.description = e.description; | ||
actual = JSON.stringify(err); | ||
} | ||
@@ -241,2 +306,4 @@ | ||
testAPI(esprima, code, result); | ||
} else if (result instanceof Array) { | ||
testTokenize(esprima, code, result); | ||
} else { | ||
@@ -344,7 +411,9 @@ testParse(esprima, code, result); | ||
if (failures > 0) { | ||
document.getElementById('status').className = 'alert-box alert'; | ||
setText(document.getElementById('status'), total + ' tests. ' + | ||
'Failures: ' + failures + '. ' + tick + ' ms'); | ||
'Failures: ' + failures + '. ' + tick + ' ms.'); | ||
} else { | ||
document.getElementById('status').className = 'alert-box success'; | ||
setText(document.getElementById('status'), total + ' tests. ' + | ||
'No failure. ' + tick + ' ms'); | ||
'No failure. ' + tick + ' ms.'); | ||
} | ||
@@ -359,2 +428,3 @@ }; | ||
fs = require('fs'), | ||
diff = require('json-diff').diffString, | ||
total = 0, | ||
@@ -387,5 +457,15 @@ failures = [], | ||
failures.forEach(function (failure) { | ||
console.error(failure.source + ': Expected\n ' + | ||
failure.expected.split('\n').join('\n ') + | ||
'\nto match\n ' + failure.actual); | ||
try { | ||
var expectedObject = JSON.parse(failure.expected); | ||
var actualObject = JSON.parse(failure.actual); | ||
console.error(failure.source + ': Expected\n ' + | ||
failure.expected.split('\n').join('\n ') + | ||
'\nto match\n ' + failure.actual + '\nDiff:\n' + | ||
diff(expectedObject, actualObject)); | ||
} catch (ex) { | ||
console.error(failure.source + ': Expected\n ' + | ||
failure.expected.split('\n').join('\n ') + | ||
'\nto match\n ' + failure.actual); | ||
} | ||
}); | ||
@@ -392,0 +472,0 @@ } else { |
Sorry, the diff of this file is too big to display
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
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No contributors or author data
MaintenancePackage does not specify a list of contributors or an author in package.json.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
1009826
28095
2
1
9
25
5