A blazingly fast, single-file, zero dependency JavaScript expression parser.
- Fast. Hand-coded lexer and top-down operator precedence parser. Twice as fast as
esprima. - Small. Less than 10KB minified and gzipped.
- Compatible. Parses all valid JavaScript expressions. Produces an
esprimastyle AST.
Usage:
import{parse}from'@anpete/fastexpr';constexpr=(s)=>`hello from ${s}!`;constast=parse(expr.toString());console.log(ast);which produces:
{type: "ArrowFunctionExpression",params: [{type: "IdentifierExpression",name: "s"}],body: {type: "TemplateLiteralExpression",quasis: [{type: "TemplateExpression",value: {cooked: "hello from "},tail: false},{type: "TemplateExpression",value: {cooked: "!"},tail: true}],expressions: [{type: "IdentifierExpression",name: "s"}]}}