pax_global_header00006660000000000000000000000064130556502170014516gustar00rootroot0000000000000052 comment=6d3fe5b4c4169837a703b0cf4887f45234a645b1 node-syntax-error-1.3.0/000077500000000000000000000000001305565021700151175ustar00rootroot00000000000000node-syntax-error-1.3.0/.travis.yml000066400000000000000000000001641305565021700172310ustar00rootroot00000000000000language: node_js node_js: - "0.8" - "0.10" - "0.12" - "iojs" before_install: - npm install -g npm@~1.4.6 node-syntax-error-1.3.0/LICENSE000066400000000000000000000020611305565021700161230ustar00rootroot00000000000000This 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. node-syntax-error-1.3.0/example/000077500000000000000000000000001305565021700165525ustar00rootroot00000000000000node-syntax-error-1.3.0/example/check.js000066400000000000000000000004351305565021700201670ustar00rootroot00000000000000var 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('-')); } node-syntax-error-1.3.0/example/src.js000066400000000000000000000003471305565021700177030ustar00rootroot00000000000000module.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; }; node-syntax-error-1.3.0/index.js000066400000000000000000000026351305565021700165720ustar00rootroot00000000000000var aparse = require('acorn').parse; function parse (src, opts) { if (!opts) opts = {} return aparse(src, { ecmaVersion: opts.ecmaVersion || 8, allowHashBang: true }); } module.exports = function (src, file,opts) { if (typeof src !== 'string') src = String(src); try { eval('throw "STOP"; (function () { ' + src + '})()'); 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; }; node-syntax-error-1.3.0/package.json000066400000000000000000000013351305565021700174070ustar00rootroot00000000000000{ "name": "syntax-error", "version": "1.3.0", "description": "detect and report syntax errors in source code strings", "main": "index.js", "dependencies": { "acorn": "^4.0.3" }, "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" } } node-syntax-error-1.3.0/readme.markdown000066400000000000000000000040441305565021700201220ustar00rootroot00000000000000# 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`. Optionally set: * `opts.ecmaVersion` - default: 8 ## 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 node-syntax-error-1.3.0/test/000077500000000000000000000000001305565021700160765ustar00rootroot00000000000000node-syntax-error-1.3.0/test/check.js000066400000000000000000000006221305565021700175110ustar00rootroot00000000000000var 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(); }); node-syntax-error-1.3.0/test/html.js000066400000000000000000000005421305565021700174010ustar00rootroot00000000000000var 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(); }); node-syntax-error-1.3.0/test/ok.js000066400000000000000000000003761305565021700170530ustar00rootroot00000000000000var 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(); }); node-syntax-error-1.3.0/test/run.js000066400000000000000000000004201305565021700172340ustar00rootroot00000000000000var 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); }); node-syntax-error-1.3.0/test/run2.js000066400000000000000000000004251305565021700173230ustar00rootroot00000000000000var 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); }); node-syntax-error-1.3.0/test/shebang.js000066400000000000000000000004101305565021700200360ustar00rootroot00000000000000var 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(); }); node-syntax-error-1.3.0/test/sources/000077500000000000000000000000001305565021700175615ustar00rootroot00000000000000node-syntax-error-1.3.0/test/sources/check.js000066400000000000000000000003471305565021700212000ustar00rootroot00000000000000module.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; }; node-syntax-error-1.3.0/test/sources/ok.js000066400000000000000000000000211305565021700205210ustar00rootroot00000000000000function f () {} node-syntax-error-1.3.0/test/sources/run.js000066400000000000000000000000211305565021700207140ustar00rootroot00000000000000process.exit(1); node-syntax-error-1.3.0/test/sources/run2.js000066400000000000000000000000461305565021700210050ustar00rootroot00000000000000})(); process.exit(1); (function () { node-syntax-error-1.3.0/test/sources/shebang.js000066400000000000000000000000501305565021700215210ustar00rootroot00000000000000#!/usr/bin/env node console.log('foo'); node-syntax-error-1.3.0/test/sources/yield.js000066400000000000000000000002441305565021700212250ustar00rootroot00000000000000function *foo () { yield 5 } (function *() { console.log(foo().next().value) })().next(); (function *() { })(); (function * () { yield yield 3 })(); node-syntax-error-1.3.0/test/yield.js000066400000000000000000000004041305565021700175400ustar00rootroot00000000000000var 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(); });