スライドをクリックでスタート、矢印キーでスライド移動、Escで一覧モードへ戻る


new C(1 + a);
このコードには、以下のような要素(node)が存在する
NewExpression - new演算子BinaryExpression の +1 というvalueをもつ LiteralC と a という変数は Identifier
new C (1 + a ) ;

assert() 等のASTを変換;があるとかそういう情報はASTには(そのままだと)ない
JavaScript ASTを使ったツールを書いてみよう
var assert = require("power-assert");
describe('Array', function () {
describe('#indexOf()', function () {
it('should return -1 when the value is not present', function () {
assert.equal([1, 2, 3].indexOf(5), -1);
assert.equal([1, 2, 3].indexOf(0), -1);
});
it('should return -1 when the value is not present', function () {
assert.equal([1, 2, 3].indexOf(5), -1);
assert.equal([1, 2, 3].indexOf(0), -1);
})
});
});
describe('IsNaN', function () {
context("when value is NaN", function () {
it('should return true', function () {
assert(isNaN(NaN));
});
});
});
テストコードから以下のようなテキストを出力
Array
#indexOf()
should return -1 when the value is not present
[1, 2, 3].indexOf(5) equal -1
[1, 2, 3].indexOf(0) equal -1
IsNaN
when value is NaN
should return true
assert isNaN(NaN)
"describe", "context", "it" の CallExpression ならindentレベルを+1["describe", "context", "it"] なら printassert ならprint"describe", "context", "it" の CallExpression ならindentレベルを-1requireをインライン化してつなげる"use strict"を取り除くNode.jsのrequireをインライン化、無駄なuse strictを取り除くモジュールを書いた | Web scratch
❝ある人々は問題に直面すると、「そうか、正規表現を使うんだ」と考える。こうして彼らは2つの問題を抱えることになる。❞ — Jamie Zawinski
最新の正規表現でやってぶっ壊れた事例(fixed)