JSPM

  • Created
  • Published
  • Downloads 12
  • Score
    100M100P100Q65746F
  • License MIT

Parsing JS code into ASTs and tools to query and transform these trees.

Package Exports

  • lively.ast
  • lively.ast/dist/lively.ast.js
  • lively.ast/dist/lively.ast_no-deps.js
  • lively.ast/lib/class-to-function-transform.js
  • lively.ast/lib/nodes.js
  • lively.ast/lib/parser.js
  • lively.ast/lib/stringify.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (lively.ast) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

lively.ast Build Status

Parsing JS code into ASTs and tools to query and transform these trees.

API

main interface

  • ast.printAst
  • ast.compareAst
  • ast.pathToNode
  • ast.stringify
  • ast.parse
  • ast.parseFunction
  • ast.fuzzyParse
  • ast.nodesAt
  • ast.withMozillaAstDo

Visitors

  • ast.MozillaAST.BaseVisitor
  • ast.MozillaAST.PrinterVisitor
  • ast.MozillaAST.ComparisonVisitor
  • ast.MozillaAST.ScopeVisitor

query ast nodes

  • ast.query.knownGlobals
  • ast.query.scopes
  • ast.query.nodesAtIndex
  • ast.query.scopesAtIndex
  • ast.query.scopeAtIndex
  • ast.query.scopesAtPos
  • ast.query.nodesInScopeOf
  • ast.query.topLevelDeclsAndRefs
  • ast.query.findGlobalVarRefs
  • ast.query.findNodesIncludingLines
  • ast.query.findReferencesAndDeclsInScope
  • ast.query.findDeclarationClosestToIndex

transform asts

  • ast.transform.replace
  • ast.transform.replaceTopLevelVarDeclAndUsageForCapturing
  • ast.transform.oneDeclaratorPerVarDecl
  • ast.transform.oneDeclaratorForVarsInDestructoring
  • ast.transform.returnLastStatement
  • ast.transform.wrapInFunction

comment parsing

  • ast.comments.extractComments

code categorizer, scan code for known constructs

  • ast.codeCategorizer.findDecls

Usage

node.js

var ast = require('lively.ast'),
    parsed = ast.parse("1 + 2");
ast.printAst(parsed);
// =>
// :Program
// \-.body[0]:ExpressionStatement
//   \-.body[0].expression:BinaryExpression
//     |-.body[0].expression.left:Literal
//     \-.body[0].expression.right:Literal
...

browser

HTML: <script src="dist/lively.ast.bundle.js"></script>

JS: like above

Development

build dist

npm run build

Testing

npm test

LICENSE

MIT