package
detect and report syntax errors in source code strings
npm install syntax-errorGitHub-flavored package documentation.
Across all versions.
Download trend unavailable.
Runtime metadata.
Tagged topics.
Detect and report syntax errors in source code strings.
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.
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
---------------------------------------------------------------------------var check = require('syntax-error')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. acorn-node defaults to options that match the most recent Node versions.
Return the long string description with a source snippet and a ^ under
pointing exactly where the error was detected.
short string description of the error type
line number of the error in the original source (indexing starts at 1)
column number of the error in the original source (indexing starts at 1)
With npm do:
npm install syntax-errorMIT
Estimated unpacked size across 5 packages.
668.3 kB
Includes dependencies.
gkatsev
me@gkatsev.com
maxogden
max@maxogden.com
thlorenz
thlorenz10@gmail.com
terinjokes
terinjokes@gmail.com
jmm
npm-public@jessemccarthy.net
mellowmelon
palmermebane@gmail.com
ashaffer88
darawk@gmail.com
balupton
b@lupton.cc
cwmma
calvin.metcalf@gmail.com
jprichardson
jprichardson@gmail.com
indutny
blackhole@livebox.sh
jryans
jryans@gmail.com
sethvincent
sethvincent@gmail.com
yoshuawuyts
javascript@yosh.is
ungoldman
ungoldman@gmail.com
ahdinosaur
michael.williams@enspiral.com
elnounch
contact@elnounch.net
parshap
parshap+npm@gmail.com
yerkopalma
yerko.palma@usach.cl
forbeslindesay
forbes@lindesay.co.uk
leichtgewicht
martin.heidegger@gmail.com
garann
garann@gmail.com
bret
bcomnes@gmail.com
anandthakker
vestibule@anandthakker.net
mattdesl
dave.des@gmail.com
hughsk
hughskennedy@gmail.com
fpereira1
pereira.filype@gmail.com
goto-bus-stop
renee@kooi.me
bpostlethwaite
post.ben.here@gmail.com
emilbayes
github@tixz.dk
stevemao
maochenyan@gmail.com
pkrumins
peteris.krumins@gmail.com
tehshrike
me@JoshDuff.com
defunctzombie
shtylman@gmail.com
lukechilds
lukechilds123@gmail.com
raynos
raynos2@gmail.com