pax_global_header00006660000000000000000000000064132372771660014530gustar00rootroot0000000000000052 comment=d3f21ced797a7c96b23deac1e836f2d4403d7dce syntax-error-1.4.0/000077500000000000000000000000001323727716600142075ustar00rootroot00000000000000syntax-error-1.4.0/.travis.yml000066400000000000000000000002161323727716600163170ustar00rootroot00000000000000language: node_js node_js: - stable - 8 - 6 - 4 - "iojs" - "0.12" - "0.10" - "0.8" before_install: - nvm install-latest-npm syntax-error-1.4.0/LICENSE000066400000000000000000000020611323727716600152130ustar00rootroot00000000000000This software is released under the MIT license: Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. syntax-error-1.4.0/example/000077500000000000000000000000001323727716600156425ustar00rootroot00000000000000syntax-error-1.4.0/example/check.js000066400000000000000000000004351323727716600172570ustar00rootroot00000000000000var fs = require('fs'); var check = require('../'); var file = __dirname + '/src.js'; var src = fs.readFileSync(file); var err = check(src, file); if (err) { console.error('ERROR DETECTED' + Array(62).join('!')); console.error(err); console.error(Array(76).join('-')); } syntax-error-1.4.0/example/src.js000066400000000000000000000003471323727716600167730ustar00rootroot00000000000000module.exports = function (xs, fn) { var res = []; for (var i = 0; i < xs.length; i++) { var x = fn(xs[i], i); if (Array.isArray(x) res.push.apply(res, x); else res.push(x); } return res; }; syntax-error-1.4.0/index.js000066400000000000000000000025311323727716600156550ustar00rootroot00000000000000var aparse = require('acorn-node').parse; function parse (src, opts) { if (!opts) opts = {} return aparse(src, opts); } module.exports = function (src, file,opts) { if (typeof src !== 'string') src = String(src); try { eval('throw "STOP"; (function () { ' + src + '\n})()'); return; } catch (err) { if (err === 'STOP') return undefined; if (err.constructor.name !== 'SyntaxError') return err; return errorInfo(src, file, opts); } }; function errorInfo (src, file, opts) { try { parse(src,opts) } catch (err) { return new ParseError(err, src, file); } return undefined; } function ParseError (err, src, file) { SyntaxError.call(this); this.message = err.message.replace(/\s+\(\d+:\d+\)$/, ''); this.line = err.loc.line; this.column = err.loc.column + 1; this.annotated = '\n' + (file || '(anonymous file)') + ':' + this.line + '\n' + src.split('\n')[this.line - 1] + '\n' + Array(this.column).join(' ') + '^' + '\n' + 'ParseError: ' + this.message ; } ParseError.prototype = Object.create(SyntaxError.prototype); ParseError.prototype.toString = function () { return this.annotated; }; ParseError.prototype.inspect = function () { return this.annotated; }; syntax-error-1.4.0/package.json000066400000000000000000000013421323727716600164750ustar00rootroot00000000000000{ "name": "syntax-error", "version": "1.4.0", "description": "detect and report syntax errors in source code strings", "main": "index.js", "dependencies": { "acorn-node": "^1.2.0" }, "devDependencies": { "tap": "^1.1.0" }, "scripts": { "test": "tap test/*.js" }, "repository": { "type": "git", "url": "git://github.com/substack/node-syntax-error.git" }, "homepage": "https://github.com/substack/node-syntax-error", "keywords": [ "syntax", "error", "esprima", "stack", "line", "column" ], "author": { "name": "James Halliday", "email": "mail@substack.net", "url": "http://substack.net" }, "license": "MIT", "engine": { "node": ">=0.6" } } syntax-error-1.4.0/readme.markdown000066400000000000000000000042241323727716600172120ustar00rootroot00000000000000# syntax-error Detect and report syntax errors in source code strings. [![build status](https://secure.travis-ci.org/substack/node-syntax-error.png)](http://travis-ci.org/substack/node-syntax-error) When you type `node src.js` you get a friendly error report about exactly where the syntax error is. This module lets you check for syntax errors and report them in a similarly friendly format that wrapping a try/catch around `Function()` or `vm.runInNewContext()` doesn't get you. # example ``` js var fs = require('fs'); var check = require('syntax-error'); var file = __dirname + '/src.js'; var src = fs.readFileSync(file); var err = check(src, file); if (err) { console.error('ERROR DETECTED' + Array(62).join('!')); console.error(err); console.error(Array(76).join('-')); } ``` --- ``` $ node check.js ERROR DETECTED!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! /home/substack/projects/node-syntax-error/example/src.js:5 if (Array.isArray(x) res.push.apply(res, x); ^ ParseError: Unexpected identifier --------------------------------------------------------------------------- ``` # methods ``` js var check = require('syntax-error') ``` ## var err = check(src, file, opts={}) Check the source code string `src` for syntax errors. Optionally you can specify a filename `file` that will show up in the output. If `src` has a syntax error, return an error object `err` that can be printed or stringified. If there are no syntax errors in `src`, return `undefined`. Options will be passed through to [acorn-node](https://github.com/browserify/acorn-node). acorn-node defaults to options that match the most recent Node versions. ## err.toString() Return the long string description with a source snippet and a `^` under pointing exactly where the error was detected. # attributes ## err.message short string description of the error type ## err.line line number of the error in the original source (indexing starts at 1) ## err.column column number of the error in the original source (indexing starts at 1) # install With [npm](http://npmjs.org) do: ``` npm install syntax-error ``` # license MIT syntax-error-1.4.0/test/000077500000000000000000000000001323727716600151665ustar00rootroot00000000000000syntax-error-1.4.0/test/check.js000066400000000000000000000006221323727716600166010ustar00rootroot00000000000000var test = require('tap').test; var fs = require('fs'); var check = require('../'); var file = __dirname + '/sources/check.js'; var src = fs.readFileSync(file); test('check', function (t) { var err = check(src, file); t.ok(err); t.equal(err.line, 5); t.equal(err.column, 30); t.equal(err.message, 'Unexpected token'); t.ok(String(err).indexOf(file + ':5')); t.end(); }); syntax-error-1.4.0/test/esm.js000066400000000000000000000011431323727716600163070ustar00rootroot00000000000000var test = require('tap').test; var fs = require('fs'); var check = require('../'); var file = __dirname + '/sources/esm.js'; var src = fs.readFileSync(file); test('esm with sourceType script', function (t) { var err = check(src, file); t.ok(err); t.equal(err.line, 1); t.equal(err.column, 1); t.equal(err.message, "'import' and 'export' may appear only with 'sourceType: module'"); t.ok(String(err).indexOf(file + ':1')); t.end(); }); test('esm with sourceType module', function (t) { var err = check(src, file, { sourceType: 'module' }); t.notOk(err); t.end(); }); syntax-error-1.4.0/test/html.js000066400000000000000000000005421323727716600164710ustar00rootroot00000000000000var test = require('tap').test; var fs = require('fs'); var check = require('../'); var src = ''; test('html', function (t) { var err = check(src, 'foo.js'); t.ok(err); t.equal(err.line, 1); t.equal(err.column, 1); t.equal(err.message, 'Unexpected token'); t.ok(/foo.js:1/.test(err), 'foo.js:1'); t.end(); }); syntax-error-1.4.0/test/ok.js000066400000000000000000000003761323727716600161430ustar00rootroot00000000000000var test = require('tap').test; var fs = require('fs'); var check = require('../'); var file = __dirname + '/sources/ok.js'; var src = fs.readFileSync(file); test('ok', function (t) { var err = check(src, file); t.notOk(err); t.end(); }); syntax-error-1.4.0/test/run.js000066400000000000000000000004201323727716600163240ustar00rootroot00000000000000var test = require('tap').test; var check = require('../'); var fs = require('fs'); var file = __dirname + '/sources/run.js'; var src = fs.readFileSync(file); test('do not run sources', function (t) { t.plan(1); var err = check(src, file); t.notOk(err); }); syntax-error-1.4.0/test/run2.js000066400000000000000000000004251323727716600164130ustar00rootroot00000000000000var test = require('tap').test; var check = require('../'); var fs = require('fs'); var file = __dirname + '/sources/run2.js'; var src = fs.readFileSync(file); test('do not run sources (2)', function (t) { t.plan(1); var err = check(src, file); t.notOk(err); }); syntax-error-1.4.0/test/shebang.js000066400000000000000000000004101323727716600171260ustar00rootroot00000000000000var test = require('tap').test; var fs = require('fs'); var check = require('../'); var file = __dirname + '/sources/shebang.js'; var src = fs.readFileSync(file); test('shebang', function (t) { var err = check(src, file); t.notOk(err); t.end(); }); syntax-error-1.4.0/test/sources/000077500000000000000000000000001323727716600166515ustar00rootroot00000000000000syntax-error-1.4.0/test/sources/check.js000066400000000000000000000003471323727716600202700ustar00rootroot00000000000000module.exports = function (xs, fn) { var res = []; for (var i = 0; i < xs.length; i++) { var x = fn(xs[i], i); if (Array.isArray(x) res.push.apply(res, x); else res.push(x); } return res; }; syntax-error-1.4.0/test/sources/esm.js000066400000000000000000000000451323727716600177720ustar00rootroot00000000000000import x from 'y'; export default z; syntax-error-1.4.0/test/sources/ok.js000066400000000000000000000000211323727716600176110ustar00rootroot00000000000000function f () {} syntax-error-1.4.0/test/sources/run.js000066400000000000000000000000211323727716600200040ustar00rootroot00000000000000process.exit(1); syntax-error-1.4.0/test/sources/run2.js000066400000000000000000000000461323727716600200750ustar00rootroot00000000000000})(); process.exit(1); (function () { syntax-error-1.4.0/test/sources/shebang.js000066400000000000000000000000501323727716600206110ustar00rootroot00000000000000#!/usr/bin/env node console.log('foo'); syntax-error-1.4.0/test/sources/spread.js000066400000000000000000000000441323727716600204630ustar00rootroot00000000000000var a = { ...b } ;({ d, ...e } = a) syntax-error-1.4.0/test/sources/yield.js000066400000000000000000000002441323727716600203150ustar00rootroot00000000000000function *foo () { yield 5 } (function *() { console.log(foo().next().value) })().next(); (function *() { })(); (function * () { yield yield 3 })(); syntax-error-1.4.0/test/spread.js000066400000000000000000000004061323727716600170020ustar00rootroot00000000000000var test = require('tap').test; var fs = require('fs'); var check = require('../'); var file = __dirname + '/sources/spread.js'; var src = fs.readFileSync(file); test('spread', function (t) { var err = check(src, file); t.notOk(err); t.end(); }); syntax-error-1.4.0/test/yield.js000066400000000000000000000004041323727716600166300ustar00rootroot00000000000000var test = require('tap').test; var fs = require('fs'); var check = require('../'); var file = __dirname + '/sources/yield.js'; var src = fs.readFileSync(file); test('yield', function (t) { var err = check(src, file); t.notOk(err); t.end(); });