This repository contains code samples from the talks:
- Parsing, Compiling, and
Static Metaprogramming at JSConfEU 2013 by Patrick Dubroy.
- You can find slides for the talk on Speaker Deck
- Master the Art of the AST and Take Control of Your JS by Yonatan Mevorach.
- Talk on the same topic at Javascript Israel by Yonatan Mevorach
- See also the video Master the Art of the AST and Take Control of Your JS.
- Here is another version of the talk at Javascript Israel
- Here are the slides
- Babel plugin Remove debugger transform. This plugin removes all
debugger;
statements - babel-plugin-transform-remove-debugger at GitHub
- codeshift at GitHub
- Write Code to Rewrite Your Code: jscodeshift
- jscodeshift example
- jscodeshift cpojer/js-codemod no-vars.js
- AST Scout is a tool for analyzing and visualizing the relationship between the public API of a Class\Module and its implementations details (e.g. private methods, dependencies used).
- A web tool to explore the ASTs generated by various parsers. https://astexplorer.net/
- A curated list of awesome AST resources
checkstyle.coffee
andlogging.coffee
contain the original source code for the style checker and logging examples presented in the talk.checkstyle.js
andlogging.js
are the slightly simplified JS versions that were shown in the talk.syntax-highlight.js
is taken from the Esprima tutorial Chapter 3. Lexical Analysis (Tokenization)¶
altjs.coffee
is the code for the "AltJS language in 5 minutes" section
presented in the second half of the talk.
idgrep.coffee
(and idgrep.js
) is another example of using Esprima
to do static analysis on JavaScript code.
> esprima = require('esprima')
{ parse: [Function: parse],
parseModule: [Function: parseModule],
parseScript: [Function: parseScript],
tokenize: [Function: tokenize],
Syntax:
{ ... },
version: '4.0.1' }
> esprima.tokenize('answer = 42', { range: true })
[ { type: 'Identifier', value: 'answer', range: [ 0, 6 ] },
{ type: 'Punctuator', value: '=', range: [ 7, 8 ] },
{ type: 'Numeric', value: '42', range: [ 9, 11 ] } ]
> esprima.parseScript('const answer = 42', { tokens: true })
Script {
type: 'Program',
body:
[ VariableDeclaration {
type: 'VariableDeclaration',
declarations: [Array],
kind: 'const' } ],
sourceType: 'script',
tokens:
[ { type: 'Keyword', value: 'const' },
{ type: 'Identifier', value: 'answer' },
{ type: 'Punctuator', value: '=' },
{ type: 'Numeric', value: '42' } ] }
> inspect = require('util')
{ ... }
> console.log(util.inspect(esprima.parseScript('answer = 42'), {depth: null}))
Script {
type: 'Program',
body:
[ ExpressionStatement {
type: 'ExpressionStatement',
expression:
AssignmentExpression {
type: 'AssignmentExpression',
operator: '=',
left: Identifier { type: 'Identifier', name: 'answer' },
right: Literal { type: 'Literal', value: 42, raw: '42' } } } ],
sourceType: 'script' }
undefined
>