Comparing version 2.7.3 to 3.0.0
@@ -28,7 +28,11 @@ #!/usr/bin/env node | ||
var fs, esprima, fname, content, options, syntax; | ||
var fs, esprima, fname, forceFile, content, options, syntax; | ||
if (typeof require === 'function') { | ||
fs = require('fs'); | ||
esprima = require('esprima'); | ||
try { | ||
esprima = require('esprima'); | ||
} catch (e) { | ||
esprima = require('../'); | ||
} | ||
} else if (typeof load === 'function') { | ||
@@ -53,3 +57,3 @@ try { | ||
console.log('Usage:'); | ||
console.log(' esparse [options] file.js'); | ||
console.log(' esparse [options] [file.js]'); | ||
console.log(); | ||
@@ -69,6 +73,2 @@ console.log('Available options:'); | ||
if (process.argv.length <= 2) { | ||
showUsage(); | ||
} | ||
options = {}; | ||
@@ -78,3 +78,10 @@ | ||
if (entry === '-h' || entry === '--help') { | ||
if (forceFile || entry === '-' || entry.slice(0, 1) !== '-') { | ||
if (typeof fname === 'string') { | ||
console.log('Error: more than one input file.'); | ||
process.exit(1); | ||
} else { | ||
fname = entry; | ||
} | ||
} else if (entry === '-h' || entry === '--help') { | ||
showUsage(); | ||
@@ -97,18 +104,10 @@ } else if (entry === '-v' || entry === '--version') { | ||
options.tolerant = true; | ||
} else if (entry.slice(0, 2) === '--') { | ||
} else if (entry === '--') { | ||
forceFile = true; | ||
} else { | ||
console.log('Error: unknown option ' + entry + '.'); | ||
process.exit(1); | ||
} else if (typeof fname === 'string') { | ||
console.log('Error: more than one input file.'); | ||
process.exit(1); | ||
} else { | ||
fname = entry; | ||
} | ||
}); | ||
if (typeof fname !== 'string') { | ||
console.log('Error: no input file.'); | ||
process.exit(1); | ||
} | ||
// Special handling for regular expression literal since we need to | ||
@@ -124,6 +123,20 @@ // convert it to a string literal, otherwise it will be decoded | ||
try { | ||
content = fs.readFileSync(fname, 'utf-8'); | ||
function run(content) { | ||
syntax = esprima.parse(content, options); | ||
console.log(JSON.stringify(syntax, adjustRegexLiteral, 4)); | ||
} | ||
try { | ||
if (fname && (fname !== '-' || forceFile)) { | ||
run(fs.readFileSync(fname, 'utf-8')); | ||
} else { | ||
var content = ''; | ||
process.stdin.resume(); | ||
process.stdin.on('data', function(chunk) { | ||
content += chunk; | ||
}); | ||
process.stdin.on('end', function() { | ||
run(content); | ||
}); | ||
} | ||
} catch (e) { | ||
@@ -130,0 +143,0 @@ console.log('Error: ' + e.message); |
@@ -29,3 +29,3 @@ #!/usr/bin/env node | ||
var fs, system, esprima, options, fnames, count; | ||
var fs, system, esprima, options, fnames, forceFile, count; | ||
@@ -40,3 +40,7 @@ if (typeof esprima === 'undefined') { | ||
fs = require('fs'); | ||
esprima = require('esprima'); | ||
try { | ||
esprima = require('esprima'); | ||
} catch (e) { | ||
esprima = require('../'); | ||
} | ||
} else if (typeof load === 'function') { | ||
@@ -56,3 +60,6 @@ try { | ||
argv: [].slice.call(system.args), | ||
exit: phantom.exit | ||
exit: phantom.exit, | ||
on: function (evt, callback) { | ||
callback(); | ||
} | ||
}; | ||
@@ -66,3 +73,9 @@ process.argv.unshift('phantomjs'); | ||
fs = { readFileSync: readFile }; | ||
process = { argv: arguments, exit: quit }; | ||
process = { | ||
argv: arguments, | ||
exit: quit, | ||
on: function (evt, callback) { | ||
callback(); | ||
} | ||
}; | ||
process.argv.unshift('esvalidate.js'); | ||
@@ -74,3 +87,3 @@ process.argv.unshift('rhino'); | ||
console.log('Usage:'); | ||
console.log(' esvalidate [options] file.js'); | ||
console.log(' esvalidate [options] [file.js...]'); | ||
console.log(); | ||
@@ -85,6 +98,2 @@ console.log('Available options:'); | ||
if (process.argv.length <= 2) { | ||
showUsage(); | ||
} | ||
options = { | ||
@@ -98,3 +107,5 @@ format: 'plain' | ||
if (entry === '-h' || entry === '--help') { | ||
if (forceFile || entry === '-' || entry.slice(0, 1) !== '-') { | ||
fnames.push(entry); | ||
} else if (entry === '-h' || entry === '--help') { | ||
showUsage(); | ||
@@ -111,7 +122,7 @@ } else if (entry === '-v' || entry === '--version') { | ||
} | ||
} else if (entry.slice(0, 2) === '--') { | ||
} else if (entry === '--') { | ||
forceFile = true; | ||
} else { | ||
console.log('Error: unknown option ' + entry + '.'); | ||
process.exit(1); | ||
} else { | ||
fnames.push(entry); | ||
} | ||
@@ -121,4 +132,3 @@ }); | ||
if (fnames.length === 0) { | ||
console.log('Error: no input file.'); | ||
process.exit(1); | ||
fnames.push(''); | ||
} | ||
@@ -132,6 +142,9 @@ | ||
count = 0; | ||
fnames.forEach(function (fname) { | ||
var content, timestamp, syntax, name; | ||
function run(fname, content) { | ||
var timestamp, syntax, name; | ||
try { | ||
content = fs.readFileSync(fname, 'utf-8'); | ||
if (typeof content !== 'string') { | ||
throw content; | ||
} | ||
@@ -197,14 +210,38 @@ if (content[0] === '#' && content[1] === '!') { | ||
} | ||
} | ||
fnames.forEach(function (fname) { | ||
var content = ''; | ||
try { | ||
if (fname && (fname !== '-' || forceFile)) { | ||
content = fs.readFileSync(fname, 'utf-8'); | ||
} else { | ||
fname = ''; | ||
process.stdin.resume(); | ||
process.stdin.on('data', function(chunk) { | ||
content += chunk; | ||
}); | ||
process.stdin.on('end', function() { | ||
run(fname, content); | ||
}); | ||
return; | ||
} | ||
} catch (e) { | ||
content = e; | ||
} | ||
run(fname, content); | ||
}); | ||
if (options.format === 'junit') { | ||
console.log('</testsuites>'); | ||
} | ||
process.on('exit', function () { | ||
if (options.format === 'junit') { | ||
console.log('</testsuites>'); | ||
} | ||
if (count > 0) { | ||
process.exit(1); | ||
} | ||
if (count > 0) { | ||
process.exit(1); | ||
} | ||
if (count === 0 && typeof phantom === 'object') { | ||
process.exit(0); | ||
} | ||
if (count === 0 && typeof phantom === 'object') { | ||
process.exit(0); | ||
} | ||
}); |
@@ -5,3 +5,3 @@ { | ||
"homepage": "http://esprima.org", | ||
"main": "esprima.js", | ||
"main": "dist/esprima.js", | ||
"bin": { | ||
@@ -11,7 +11,6 @@ "esparse": "./bin/esparse.js", | ||
}, | ||
"version": "2.7.3", | ||
"version": "3.0.0", | ||
"files": [ | ||
"bin", | ||
"unit-tests.js", | ||
"esprima.js" | ||
"dist/esprima.js" | ||
], | ||
@@ -43,22 +42,25 @@ "engines": { | ||
"escomplex-js": "1.2.0", | ||
"eslint": "~1.7.2", | ||
"everything.js": "~1.0.3", | ||
"glob": "^5.0.15", | ||
"glob": "~7.0.0", | ||
"istanbul": "~0.4.0", | ||
"jscs": "~2.3.5", | ||
"jscs": "~3.0.3", | ||
"json-diff": "~0.3.1", | ||
"karma": "^0.13.11", | ||
"karma-chrome-launcher": "^0.2.1", | ||
"karma-detect-browsers": "^2.0.2", | ||
"karma-firefox-launcher": "^0.1.6", | ||
"karma-ie-launcher": "^0.2.0", | ||
"karma-mocha": "^0.2.0", | ||
"karma-safari-launcher": "^0.1.1", | ||
"karma-sauce-launcher": "^0.2.14", | ||
"lodash": "^3.10.0", | ||
"mocha": "^2.3.3", | ||
"karma": "~1.2.0", | ||
"karma-chrome-launcher": "~2.0.0", | ||
"karma-detect-browsers": "~2.1.0", | ||
"karma-firefox-launcher": "~1.0.0", | ||
"karma-ie-launcher": "~1.0.0", | ||
"karma-mocha": "~1.1.1", | ||
"karma-safari-launcher": "~1.0.0", | ||
"karma-sauce-launcher": "~1.0.0", | ||
"lodash": "~3.10.1", | ||
"mocha": "~3.0.2", | ||
"node-tick-processor": "~0.0.2", | ||
"regenerate": "~1.2.1", | ||
"regenerate": "~1.3.1", | ||
"temp": "~0.8.3", | ||
"unicode-7.0.0": "~0.1.5" | ||
"tslint": "~3.15.1", | ||
"typescript": "~1.8.10", | ||
"typescript-formatter": "~1.2.0", | ||
"unicode-8.0.0": "~0.7.0", | ||
"webpack": "~1.13.2" | ||
}, | ||
@@ -68,2 +70,3 @@ "keywords": [ | ||
"ecmascript", | ||
"esprima", | ||
"javascript", | ||
@@ -75,12 +78,15 @@ "parser", | ||
"check-version": "node test/check-version.js", | ||
"jscs": "jscs -p crockford esprima.js && jscs -p crockford test/*.js", | ||
"eslint": "node node_modules/eslint/bin/eslint.js -c .lintrc esprima.js", | ||
"tslint": "tslint src/*.ts", | ||
"code-style": "tsfmt --verify src/*.ts && jscs -p crockford test/*.js", | ||
"format-code": "tsfmt -r src/*.ts", | ||
"complexity": "node test/check-complexity.js", | ||
"static-analysis": "npm run check-version && npm run jscs && npm run eslint && npm run complexity", | ||
"static-analysis": "npm run check-version && npm run tslint && npm run code-style && npm run complexity", | ||
"hostile-env-tests": "node test/hostile-environment-tests.js", | ||
"unit-tests": "node test/unit-tests.js", | ||
"api-tests": "mocha -R dot test/api-tests.js", | ||
"grammar-tests": "node test/grammar-tests.js", | ||
"regression-tests": "node test/regression-tests.js", | ||
"all-tests": "npm run generate-fixtures && npm run unit-tests && npm run grammar-tests && npm run regression-tests", | ||
"all-tests": "npm run generate-fixtures && npm run unit-tests && npm run api-tests && npm run grammar-tests && npm run regression-tests && npm run hostile-env-tests", | ||
"generate-fixtures": "node tools/generate-fixtures.js", | ||
"browser-tests": "npm run generate-fixtures && cd test && karma start --single-run", | ||
"browser-tests": "npm run compile && npm run generate-fixtures && cd test && karma start --single-run", | ||
"saucelabs-evergreen": "cd test && karma start saucelabs-evergreen.conf.js", | ||
@@ -92,6 +98,9 @@ "saucelabs-safari": "cd test && karma start saucelabs-safari.conf.js", | ||
"dynamic-analysis": "npm run analyze-coverage && npm run check-coverage", | ||
"test": "npm run all-tests && npm run static-analysis && npm run dynamic-analysis", | ||
"compile": "tsc -p src/ && webpack && node tools/fixupbundle.js", | ||
"test": "npm run compile && npm run all-tests && npm run static-analysis && npm run dynamic-analysis", | ||
"prepublish": "npm run compile", | ||
"profile": "node --prof test/profile.js && mv isolate*.log v8.log && node-tick-processor", | ||
"benchmark": "node test/benchmarks.js", | ||
"benchmark-quick": "node test/benchmarks.js quick", | ||
"benchmark-parser": "node -expose_gc test/benchmark-parser.js", | ||
"benchmark-tokenizer": "node --expose_gc test/benchmark-tokenizer.js", | ||
"benchmark": "npm run benchmark-parser && npm run benchmark-tokenizer", | ||
"codecov" : "istanbul report cobertura && codecov < ./coverage/cobertura-coverage.xml", | ||
@@ -101,6 +110,7 @@ "downstream": "node test/downstream.js", | ||
"circleci": "npm test && npm run codecov && npm run downstream", | ||
"appveyor": "npm run all-tests && npm run browser-tests && npm run dynamic-analysis", | ||
"appveyor": "npm run compile && npm run all-tests && npm run browser-tests", | ||
"droneio": "npm test && npm run saucelabs-evergreen && npm run saucelabs-ie && npm run saucelabs-safari", | ||
"generate-regex": "node tools/generate-identifier-regex.js" | ||
"generate-regex": "node tools/generate-identifier-regex.js", | ||
"generate-xhtml-entities": "node tools/generate-xhtml-entities.js" | ||
} | ||
} |
@@ -15,14 +15,35 @@ [![NPM version](https://img.shields.io/npm/v/esprima.svg)](https://www.npmjs.com/package/esprima) | ||
- Full support for ECMAScript 6 ([ECMA-262](http://www.ecma-international.org/publications/standards/Ecma-262.htm)) | ||
- Sensible [syntax tree format](https://github.com/estree/estree/blob/master/spec.md) as standardized by [ESTree project](https://github.com/estree/estree) | ||
- Full support for ECMAScript 2016 ([ECMA-262 7th Edition](http://www.ecma-international.org/publications/standards/Ecma-262.htm)) | ||
- Sensible [syntax tree format](https://github.com/estree/estree/blob/master/es5.md) as standardized by [ESTree project](https://github.com/estree/estree) | ||
- Experimental support for [JSX](https://facebook.github.io/jsx/), a syntax extension for [React](https://facebook.github.io/react/) | ||
- Optional tracking of syntax node location (index-based and line-column) | ||
- [Heavily tested](http://esprima.org/test/ci.html) (~1250 [unit tests](https://github.com/jquery/esprima/tree/master/test/fixtures) with [full code coverage](https://codecov.io/github/jquery/esprima)) | ||
- [Heavily tested](http://esprima.org/test/ci.html) (~1300 [unit tests](https://github.com/jquery/esprima/tree/master/test/fixtures) with [full code coverage](https://codecov.io/github/jquery/esprima)) | ||
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). | ||
### API | ||
Esprima runs on many popular web browsers, as well as other ECMAScript platforms such as | ||
[Rhino](http://www.mozilla.org/rhino), [Nashorn](http://openjdk.java.net/projects/nashorn/), and [Node.js](https://npmjs.org/package/esprima). | ||
Esprima can be used to perform [lexical analysis](https://en.wikipedia.org/wiki/Lexical_analysis) (tokenization) or [syntactic analysis](https://en.wikipedia.org/wiki/Parsing) (parsing) of a JavaScript programs. | ||
For more information, check the web site [esprima.org](http://esprima.org). | ||
A simple example: | ||
```javascript | ||
var esprima = require('esprima'); | ||
var code = 'const answer = 42'; | ||
var tokens = esprima.tokenize(code); | ||
var ast = esprima.parse(code); | ||
``` | ||
which gives a list of [tokens](https://en.wikipedia.org/wiki/Lexical_analysis#Token): | ||
```javascript | ||
[ { type: 'Keyword', value: 'const' }, | ||
{ type: 'Identifier', value: 'answer' }, | ||
{ type: 'Punctuator', value: '=' }, | ||
{ type: 'Numeric', value: '42' } ] | ||
``` | ||
and an [abstract syntax tree](https://en.wikipedia.org/wiki/Abstract_syntax_tree): | ||
```javascript | ||
{ type: 'Program', | ||
body: | ||
[ { type: 'VariableDeclaration', | ||
declarations: [Object], | ||
kind: 'const' } ], | ||
sourceType: 'script' } | ||
``` |
Sorry, the diff of this file is not supported yet
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
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
291188
6678
49
25
1