mirror of https://github.com/Wilfred/difftastic/
172 lines
3.3 KiB
Plaintext
172 lines
3.3 KiB
Plaintext
============================================
|
|
If statements
|
|
============================================
|
|
|
|
if (x)
|
|
log(y);
|
|
|
|
if (a.b) {
|
|
log(c);
|
|
log(d);
|
|
}
|
|
|
|
----
|
|
|
|
(program
|
|
(if_statement (identifier)
|
|
(expression_statement (function_call
|
|
(identifier) (arguments (identifier)))))
|
|
(if_statement (member_access (identifier) (identifier))
|
|
(statement_block
|
|
(expression_statement (function_call
|
|
(identifier) (arguments (identifier))))
|
|
(expression_statement (function_call
|
|
(identifier) (arguments (identifier)))))))
|
|
|
|
============================================
|
|
For statements
|
|
============================================
|
|
|
|
for (i = 0; i < 10; i++)
|
|
log(y);
|
|
|
|
for (;;) {
|
|
log(y);
|
|
}
|
|
|
|
---
|
|
|
|
(program
|
|
(for_statement
|
|
(var_assignment (identifier) (number))
|
|
(rel_op (identifier) (number))
|
|
(math_op (identifier))
|
|
(expression_statement (function_call (identifier) (arguments (identifier)))))
|
|
|
|
(for_statement
|
|
(statement_block
|
|
(expression_statement (function_call (identifier) (arguments (identifier)))))))
|
|
|
|
============================================
|
|
For-in statements
|
|
============================================
|
|
|
|
for (var item in items)
|
|
log(item);
|
|
|
|
for (item in items)
|
|
log(item);
|
|
|
|
---
|
|
|
|
(program
|
|
(for_in_statement (identifier) (identifier)
|
|
(expression_statement (function_call (identifier) (arguments (identifier)))))
|
|
(for_in_statement (identifier) (identifier)
|
|
(expression_statement (function_call (identifier) (arguments (identifier))))))
|
|
|
|
============================================
|
|
Return statements
|
|
============================================
|
|
|
|
return;
|
|
return 5;
|
|
|
|
---
|
|
|
|
(program
|
|
(return_statement)
|
|
(return_statement (number)))
|
|
|
|
============================================
|
|
Var declarations
|
|
============================================
|
|
|
|
var x = 1;
|
|
var x, y = {}, z;
|
|
|
|
---
|
|
|
|
(program
|
|
(var_declaration
|
|
(var_assignment (identifier) (number)))
|
|
(var_declaration
|
|
(identifier)
|
|
(var_assignment (identifier) (object))
|
|
(identifier)))
|
|
|
|
============================================
|
|
Comments
|
|
============================================
|
|
|
|
{
|
|
|
|
// This is a property
|
|
aProperty: 1,
|
|
|
|
|
|
/*
|
|
* This is a method
|
|
*/
|
|
aMethod: function() {}
|
|
};
|
|
|
|
---
|
|
|
|
(program
|
|
(expression_statement (object
|
|
(comment)
|
|
(pair (identifier) (number))
|
|
(comment)
|
|
(pair (identifier) (function (statement_block))))))
|
|
|
|
============================================
|
|
Automatic semicolon insertion
|
|
============================================
|
|
|
|
if (a) {
|
|
var b = c
|
|
d()
|
|
e()
|
|
return f
|
|
}
|
|
|
|
---
|
|
|
|
(program
|
|
(if_statement (identifier) (statement_block
|
|
(var_declaration (var_assignment (identifier) (identifier)))
|
|
(expression_statement (function_call (identifier)))
|
|
(expression_statement (function_call (identifier)))
|
|
(return_statement (identifier)))))
|
|
|
|
============================================
|
|
Switch statements
|
|
============================================
|
|
|
|
switch (x) {
|
|
case 1:
|
|
case 2:
|
|
something();
|
|
break;
|
|
case "three":
|
|
somethingElse();
|
|
break;
|
|
default:
|
|
return 4;
|
|
}
|
|
|
|
---
|
|
|
|
(program
|
|
(switch_statement (identifier)
|
|
(case (number))
|
|
(case (number)
|
|
(expression_statement (function_call (identifier)))
|
|
(break_statement))
|
|
(case (string)
|
|
(expression_statement (function_call (identifier)))
|
|
(break_statement))
|
|
(default
|
|
(return_statement (number)))))
|