# buster-syntax

> [![Build status](https://secure.travis-ci.org/busterjs/buster-syntax.png?branch=master)](http://travis-ci.org/busterjs/buster-syntax)

Latest version **0.5.0** (published 2015-11-29) · BSD-3-Clause license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install buster-syntax
pnpm add buster-syntax
yarn add buster-syntax
bun add buster-syntax
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.5.0 |
| Published | 2015-11-29 |
| First published | 2012-02-16 |
| Weekly downloads | 0 |
| License | BSD-3-Clause |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >= 4 |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Christian Johansen |
| Maintainers | augustl, cjohansen, dominykas, dwittner |

## Links

- npm: https://www.npmjs.com/package/buster-syntax
- Repository: https://github.com/busterjs/buster-syntax
- Homepage: http://busterjs.org/docs/syntax
- Issues: https://github.com/busterjs/buster-syntax/issues
- npm.io page: https://npm.io/package/buster-syntax

## Dependencies (1)

- [uglify-js](https://npm.io/package/uglify-js.md) 2.x

## Recent versions

- 0.5.0 (latest) — 2015-11-29
- 0.4.3 — 2014-06-06
- 0.4.2 — 2012-07-09
- 0.4.0 — 2012-06-20
- 0.2.0 — 2012-04-17
- 0.1.1 — 2012-03-03
- 0.1.0 — 2012-02-16

## README

# buster-syntax

[![Build status](https://secure.travis-ci.org/busterjs/buster-syntax.png?branch=master)](http://travis-ci.org/busterjs/buster-syntax)

> Stop syntax errors before they hit the browser

`buster-syntax` is an API for syntax checking JavaScript in Node.JS. It also
provides a Buster.JS extension that syntax checks files on the server before
running them in the browser (over `ramp`).

Catching errors early with Buster.JS test runs has one primary goal: Avoid
browsers with poor error handling freezing if a test run contains lots of
errors. As a pleasant side-effect, you get consistent and detailed syntax
errors, regardless of target browser.

This extension ships with Buster.JS by default, so there's nothing to do to
enable it. If you want to do test runs in the browser without this extension,
you have to provide your own runner plumbing, see `buster docs
<http://github.com/busterjs/buster/>`_ for information on how.


## API Docs

To syntax check some JavaScript, require the module and call its `check`
method. It returns an object with details about the validity.


### `check(script[, file])`

Syntax check the code with the optional file name. The file name is used to
create nice error messages.

```javascript
var syntax = require("buster-syntax").syntax;

// Syntactically valid
syntax.check("var a = 42;"); // => { ok: true }

// Syntactically invalid
syntax.check("var a 42;"); // => {
  ok: false,
  errors:
    [ { file: null,
        type: 'Syntax error',
        message: 'Unexpected token: num (42)',
        line: 1,
        col: 7,
        content: 'var a 42;' } ] }


// Syntactically invalid, with file name
syntax.check("var a 42;", "life.js"); // => {
  ok: false,
  errors:
    [ { file: "life.js",
        type: 'Syntax error',
        message: 'Unexpected token: num (42)',
        line: 1,
        col: 7,
        content: 'var a 42;' } ] }
```        


### `configure(options)`

Configures the syntax checker and returns a specialized instance (i.e., it does
not change the module instance). Currently only one configuration property is
supported: `ignoreReferenceErrors`. References typically require more than one
file to be viewed as one unit. If you just want to syntax check one file that
contains references to external identifiers, you can choose to not fail on those
unknown references.

```javascript
var syntax = require("buster-syntax").syntax;

syntax.check("$('li').on('click', function() {})"); // => {
  ok: false,
  errors:
    [ { file: null,
        type: 'Syntax error',
        message: 'Unexpected token punc, expected punc',
        line: 1,
        col: 30,
        content: '$(\'li\').on(\'click\', function {})' } ] }

var checker = syntax.configure({ ignoreReferenceErrors: true });
checker.check("$('li').on('click', function() {})"); // => { ok: true }
```


## Changelog

**0.5.0** (2015-Nov-29)

* Updated all dependencies, incl. uglify to v2
* Removed `jsdom`
* Added supported engines (node 4+) flag in package.json

**0.4.3** (2014-Jun-06)

* JsDom updated to version ~0.10 for issue [#410 - Buster is modifying the global `Error` object (via old JSDOM)](https://github.com/busterjs/buster/issues/410)

---
_Source: https://npm.io/package/buster-syntax · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
