pugjs/is-expression-babylon

Name: is-expression-babylon

Owner: Pug

Description: Check if a string is a valid JavaScript expression using Babylon

Created: 2016-10-12 02:26:09.0

Updated: 2017-01-23 02:09:52.0

Pushed: 2017-01-23 02:12:31.0

Homepage: null

Size: 8

Language: JavaScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

!!!DEPRECATED!!!

This module has stopped working since babylon@6.13.1. Please use Babylon's babylon.parseExpression() instead.


is-expression-babylon

Validates a string as a JavaScript expression using Babylon

An alternative version of this module using Acorn instead of Babylon is available at is-expression. While this module aims to support all ECMAScript features, even spec proposals in Stage 0, is-expression is more conservative on the features it implements. Pick your poison.

Build Status Dependency Status npm version

Installation
npm install is-expression-babylon
Usage
t isExpression = require('is-expression-babylon');
isExpression(src[, options])

Validates a string as a JavaScript expression.

src contains the source.

options can contain any Babylon options, or any of the following:

See the examples below for usage.

isExpression.getExpression(src[, options])

Get the Babylon Expression AST node of a string.

src contains the source.

options can contain any Babylon options, or any of the following:

If the string is not an expression, an error is thrown.

Examples
t isExpression = require('is-expression-babylon');

pression('myVar');
 true
pression('var');
 false
pression('["an", "array", "\'s"].indexOf("index")');
 true

pression('var', {throw: true});
yntaxError: Unexpected token (1:0)
   at Parser.pp.raise (acorn/dist/acorn.js:940:13)
   at ...

pression('public');
 true
pression('public', {strict: true});
 false

pression('abc // my comment');
 false
pression('abc // my comment', {lineComment: true});
 true

t expression = isExpression.getExpression('abc');
 Node { type: 'Identifier', ... }
License

MIT


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.