Sha256: 703e37e9573cefc64d6e0c0608d2ab385e66470dbc90b3f875012b80908c60df

Contents?: true

Size: 1.98 KB

Versions: 14

Compression:

Stored size: 1.98 KB

Contents

# 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)

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`.

## 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

Version data entries

14 entries across 14 versions & 5 rubygems

Version Path
minimum_viable_product-0.0.11 test/dummy/node_modules/syntax-error/readme.markdown
brwy_rails-0.0.6 test/dummy/node_modules/syntax-error/readme.markdown
brwy_rails-0.0.5 test/dummy/node_modules/syntax-error/readme.markdown
brwy_rails-0.0.4 test/dummy/node_modules/syntax-error/readme.markdown
brwy_rails-0.0.3 test/dummy/node_modules/syntax-error/readme.markdown
brwy_rails-0.0.2 test/dummy/node_modules/syntax-error/readme.markdown
brwy_rails-0.0.1 test/dummy/node_modules/syntax-error/readme.markdown
snowball-0.1.22 node_modules/browserify/node_modules/syntax-error/readme.markdown
sprockets-browserify-0.3.0 node_modules/browserify/node_modules/syntax-error/readme.markdown
sprockets-browserify-0.2.0 node_modules/browserify/node_modules/syntax-error/readme.markdown
ruby-wisp-source-0.8.0 vendor/node_modules/browserify/node_modules/syntax-error/readme.markdown
ruby-wisp-source-0.7.0 vendor/node_modules/browserify/node_modules/syntax-error/readme.markdown
sprockets-browserify-0.1.2 node_modules/browserify/node_modules/syntax-error/readme.markdown
sprockets-browserify-0.1.0 node_modules/browserify/node_modules/syntax-error/readme.markdown