Skip to content

Instantly share code, notes, and snippets.

@m2ym
Created September 12, 2013 07:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save m2ym/6534131 to your computer and use it in GitHub Desktop.
Save m2ym/6534131 to your computer and use it in GitHub Desktop.
for (...) { var a = ...; f(function() { return a; }); } みたいな危険なキャプチャを検出するルール
dangerous_capture(Ident) :-
for_body(ForBody),
stmt_child(ForBody, stmt, VarStmt),
statement(VarStmt, var, Var, _, _),
var(Var, Decls),
var_decls(Decls, D),
var_decl(D, VarName, _, _, _),
stmt_desc(ForBody, expr, FuncExpr),
expression(FuncExpr, function, Func, _, _),
function(Func, _, _, FuncBody),
statements(FuncBody, FuncStmt),
stmt_desc(FuncStmt, expr, IdentExpr),
expression(IdentExpr, ident, Ident, _, _),
ident(Ident, VarName).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment