buster-syntax

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

No longer maintained
Last updated 9 years ago by dominykas .
BSD-3-Clause · Repository · Bugs · Original npm · Tarball · package.json
$ npm install buster-syntax 
SYNC missed versions from official npm registry.

buster-syntax

Build status

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.

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.

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)

Current Tags

  • 0.5.0                                ...           latest (9 years ago)

7 Versions

  • 0.5.0 [deprecated]           ...           9 years ago
  • 0.4.3 [deprecated]           ...           10 years ago
  • 0.4.2 [deprecated]           ...           12 years ago
  • 0.4.0 [deprecated]           ...           12 years ago
  • 0.2.0 [deprecated]           ...           13 years ago
  • 0.1.1 [deprecated]           ...           13 years ago
  • 0.1.0 [deprecated]           ...           13 years ago
Downloads
Total 0
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (1)
Dev Dependencies (5)
Dependents (1)

© 2010 - cnpmjs.org x YWFE | Home | YWFE