All Projects → estools → esvalid

estools / esvalid

Licence: other
confirm that a SpiderMonkey format AST represents an ECMAScript program

Programming Languages

javascript
184084 projects - #8 most used programming language
Makefile
30231 projects

Labels

Projects that are alternatives of or similar to esvalid

Escodegen
ECMAScript code generator
Stars: ✭ 2,328 (+9600%)
Mutual labels:  ast, estree
Estree
The ESTree Spec
Stars: ✭ 3,867 (+16012.5%)
Mutual labels:  ast, estree
estree-to-babel
convert estree ast to babel
Stars: ✭ 23 (-4.17%)
Mutual labels:  ast, estree
Babylon
PSA: moved into babel/babel as @babel/parser -->
Stars: ✭ 1,692 (+6950%)
Mutual labels:  ast, estree
kataw
An 100% spec compliant ES2022 JavaScript toolchain
Stars: ✭ 303 (+1162.5%)
Mutual labels:  ast, estree
astravel
👟 Tiny and fast ESTree-compliant AST walker and modifier.
Stars: ✭ 38 (+58.33%)
Mutual labels:  ast, estree
eval-estree-expression
Safely evaluate JavaScript (estree) expressions, sync and async.
Stars: ✭ 22 (-8.33%)
Mutual labels:  ast, estree
kolasu
Kotlin Language Support – AST Library
Stars: ✭ 45 (+87.5%)
Mutual labels:  ast
vast
A simple tool for vlang, generate v source file to AST json file
Stars: ✭ 23 (-4.17%)
Mutual labels:  ast
bredon
A modern CSS value compiler in JavaScript
Stars: ✭ 39 (+62.5%)
Mutual labels:  ast
Headache
Programming Language that compiles to 8 Bit Brainfuck
Stars: ✭ 59 (+145.83%)
Mutual labels:  ast
rector-laravel
Rector upgrades rules for Laravel
Stars: ✭ 75 (+212.5%)
Mutual labels:  ast
parse-function
(!! moved to tunnckoCore/opensource multi-package repository !!) 🔱 Parse a function into an object using espree, acorn or babylon parsers. Extensible through Smart Plugins.
Stars: ✭ 37 (+54.17%)
Mutual labels:  ast
C90Compiler-EIE2
C90 to MIPS I Compiler done as a coursework for EE2-15
Stars: ✭ 15 (-37.5%)
Mutual labels:  ast
asty
Abstract Syntax Tree (AST) Data Structure
Stars: ✭ 28 (+16.67%)
Mutual labels:  ast
dedupimport
Deduplicate named/unnamed imports that have the same import path in Go files
Stars: ✭ 20 (-16.67%)
Mutual labels:  ast
ast ninja
The Elixir AST explorer
Stars: ✭ 59 (+145.83%)
Mutual labels:  ast
lpegrex
Parse programming languages syntax into an AST using PEGs with ease (LPeg Extension).
Stars: ✭ 32 (+33.33%)
Mutual labels:  ast
gogrep
Syntax-aware Go code search, based on the mvdan/gogrep
Stars: ✭ 25 (+4.17%)
Mutual labels:  ast
hxjsonast
Parse JSON into position-aware AST with Haxe!
Stars: ✭ 28 (+16.67%)
Mutual labels:  ast

esvalid

Install

npm install esvalid

Usage

esvalid.isValid(node) :: Spidermonkey AST Node → Boolean

Returns true if and only if the given AST node represents a valid ECMAScript program.

esvalid.isValidExpression(node) :: Spidermonkey AST Node → Boolean

Returns true if and only if the given AST node represents a valid ECMAScript expression.

esvalid.errors(node) :: Spidermonkey AST Node → [InvalidAstError]

Returns an array of InvalidAstError objects representing the errors in the given AST. An effort is made to continue collecting errors in the face of malformed ASTs. If an empty array is returned, it is implied that the given AST node is error free.

new esvalid.InvalidAstError(node, message) :: Node -> String -> InvalidAstError

Constructs a new InvalidAstError instance. node must be non-null.

Example
var esvalid = require("esvalid");
var esprima = require("esprima");

var program = esprima.parse(fs.readFileSync(require.resolve("esprima")));
esvalid.isValid(program); // true

esvalid.isValid({type: "Program", body: []}); // true
esvalid.isValid({type: "Program", body: null}); // false

esvalid.isValidExpression({type: "Program", body: []}); // false
esvalid.isValidExpression({type: "Literal", value: 0}); // true

esvalid.errors({type: "Program", body: []}); // []
var error = esvalid.errors({type: "Program", body: null})[0];
error instanceof esvalid.InvalidAstError; // true
error.node; // {type: "Program", body: null}
error.message; // "Program `body` member must be non-null"

Validity Tests

This is a list of all esvalid validity tests other than null tests and type checks.

  • BreakStatement must have an IterationStatement or SwitchStatement as an ancestor
  • labelled BreakStatement must have a matching LabeledStatement ancestor
  • CatchClause param member must not be eval or arguments in strict mode
  • ContinueStatement must have an IterationStatement as an ancestor
  • labelled ContinueStatement must have a matching LabeledStatement ancestor
  • FunctionDeclaration id member must not be eval or arguments in strict mode
  • FunctionExpression id member must not be eval or arguments in strict mode
  • FunctionDeclaration parameter names must be unique in strict mode
  • FunctionExpression parameter names must be unique in strict mode
  • Identifier name member must be a valid IdentifierName
  • Identifier name member must not be a ReservedWord
  • IfStatement with null alternate must not be the consequent of an IfStatement with a non-null alternate
  • LabeledStatement must not be nested within a LabeledStatement with the same label
  • numeric Literal nodes must not be NaN
  • numeric Literal nodes must be non-negative
  • numeric Literal nodes must be finite
  • static MemberExpression property member must have a valid IdentifierName name member
  • ObjectExpression getter property value member must have zero parameters
  • ObjectExpression setter property value member must have exactly one parameter
  • ObjectExpression must not have more than one data property with the same name in strict mode
  • ObjectExpression must not have data and getter properties with the same name
  • ObjectExpression must not have data and setter properties with the same name
  • ObjectExpression must not have data and getter properties with the same name
  • ObjectExpression must not have multiple getters with the same name
  • ObjectExpression must not have data and setter properties with the same name
  • ObjectExpression must not have multiple setters with the same name
  • ReturnStatement must be nested within a FunctionExpression or FunctionDeclaration node
  • SequenceExpression expressions member length must be >= 2
  • SwitchStatement cases member must contain no more than one SwitchCase with a null test member
  • TryStatement must have a non-null handler member or a non-null finalizer member
  • delete with unqualified identifier not allowed in strict mode
  • VariableDeclaration declarations member must be non-empty
  • WithStatement not allowed in strict mode
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].