Created
April 14, 2015 20:01
-
-
Save lorenzoongithub/8aa87cec23747b1ebbfd to your computer and use it in GitHub Desktop.
a simple showcase for esprima
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Showcase for Esprima. | |
// http://esprima.org | |
// | |
// This work is based on the following work | |
// https://github.com/marijnh/acorn/blob/master/test/tests.js | |
// | |
load('http://esprima.org/esprima.js'); | |
// Utility function to check the similarity of the arguments. | |
function chk(a,b) { | |
if (a == b) return; | |
if (typeof a != 'object') throw ''; | |
if (typeof b != 'object') throw ''; | |
for (var i in b) { chk(a[i],b[i]); } | |
} | |
chk(esprima.parse("this\n"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "ThisExpression" | |
} | |
}] | |
}); | |
chk(esprima.parse("null\n"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "Literal", | |
value: null, | |
raw: "null" | |
} | |
}] | |
}); | |
chk(esprima.parse("\n 42\n\n"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "Literal", | |
value: 42, | |
raw: "42" | |
} | |
}] | |
}); | |
chk(esprima.parse("/foobar/"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "Literal", | |
value: {}, | |
raw: "/foobar/", | |
regex: { | |
pattern: "foobar", | |
flags: "" | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("/[a-z]/g"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "Literal", | |
value: {}, | |
raw: "/[a-z]/g", | |
regex: { | |
pattern: "[a-z]", | |
flags: "g" | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("(1 + 2 ) * 3"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "BinaryExpression", | |
operator: "*", | |
left: { | |
type: "BinaryExpression", | |
operator: "+", | |
left: { | |
type: "Literal", | |
value: 1, | |
raw: "1" | |
}, | |
right: { | |
type: "Literal", | |
value: 2, | |
raw: "2" | |
} | |
}, | |
right: { | |
type: "Literal", | |
value: 3, | |
raw: "3" | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("(1 + 2 ) * 3"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "BinaryExpression", | |
operator: "*", | |
left: { | |
type: "BinaryExpression", | |
operator: "+", | |
left: { | |
type: "Literal", | |
value: 1, | |
raw: "1" | |
}, | |
right: { | |
type: "Literal", | |
value: 2, | |
raw: "2" | |
} | |
}, | |
right: { | |
type: "Literal", | |
value: 3, | |
raw: "3" | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("(x) = 23"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "AssignmentExpression", | |
operator: "=", | |
left: { | |
type: "Identifier", | |
name: "x" | |
}, | |
right: { | |
type: "Literal", | |
value: 23, | |
raw: "23" | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("x = []"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "AssignmentExpression", | |
operator: "=", | |
left: { | |
type: "Identifier", | |
name: "x" | |
}, | |
right: { | |
type: "ArrayExpression", | |
elements: [] | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("x = [ ]"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "AssignmentExpression", | |
operator: "=", | |
left: { | |
type: "Identifier", | |
name: "x" | |
}, | |
right: { | |
type: "ArrayExpression", | |
elements: [] | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("x = [ 42 ]"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "AssignmentExpression", | |
operator: "=", | |
left: { | |
type: "Identifier", | |
name: "x" | |
}, | |
right: { | |
type: "ArrayExpression", | |
elements: [{ | |
type: "Literal", | |
value: 42, | |
raw: "42" | |
}] | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("x = [ 42, ]"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "AssignmentExpression", | |
operator: "=", | |
left: { | |
type: "Identifier", | |
name: "x" | |
}, | |
right: { | |
type: "ArrayExpression", | |
elements: [{ | |
type: "Literal", | |
value: 42, | |
raw: "42" | |
}] | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("x = [ ,, 42 ]"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "AssignmentExpression", | |
operator: "=", | |
left: { | |
type: "Identifier", | |
name: "x" | |
}, | |
right: { | |
type: "ArrayExpression", | |
elements: [null, null, { | |
type: "Literal", | |
value: 42, | |
raw: "42" | |
}] | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("x = [ 1, 2, 3, ]"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "AssignmentExpression", | |
operator: "=", | |
left: { | |
type: "Identifier", | |
name: "x" | |
}, | |
right: { | |
type: "ArrayExpression", | |
elements: [{ | |
type: "Literal", | |
value: 1, | |
raw: "1" | |
}, { | |
type: "Literal", | |
value: 2, | |
raw: "2" | |
}, { | |
type: "Literal", | |
value: 3, | |
raw: "3" | |
}] | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("x = [ 1, 2,, 3, ]"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "AssignmentExpression", | |
operator: "=", | |
left: { | |
type: "Identifier", | |
name: "x" | |
}, | |
right: { | |
type: "ArrayExpression", | |
elements: [{ | |
type: "Literal", | |
value: 1, | |
raw: "1" | |
}, { | |
type: "Literal", | |
value: 2, | |
raw: "2" | |
}, null, { | |
type: "Literal", | |
value: 3, | |
raw: "3" | |
}] | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("x = {}"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "AssignmentExpression", | |
operator: "=", | |
left: { | |
type: "Identifier", | |
name: "x" | |
}, | |
right: { | |
type: "ObjectExpression", | |
properties: [] | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("x = { }"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "AssignmentExpression", | |
operator: "=", | |
left: { | |
type: "Identifier", | |
name: "x" | |
}, | |
right: { | |
type: "ObjectExpression", | |
properties: [] | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("x = { answer: 42 }"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "AssignmentExpression", | |
operator: "=", | |
left: { | |
type: "Identifier", | |
name: "x" | |
}, | |
right: { | |
type: "ObjectExpression", | |
properties: [{ | |
type: "Property", | |
key: { | |
type: "Identifier", | |
name: "answer" | |
}, | |
computed: false, | |
value: { | |
type: "Literal", | |
value: 42, | |
raw: "42" | |
}, | |
kind: "init", | |
method: false, | |
shorthand: false | |
}] | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("x = { if: 42 }"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "AssignmentExpression", | |
operator: "=", | |
left: { | |
type: "Identifier", | |
name: "x" | |
}, | |
right: { | |
type: "ObjectExpression", | |
properties: [{ | |
type: "Property", | |
key: { | |
type: "Identifier", | |
name: "if" | |
}, | |
computed: false, | |
value: { | |
type: "Literal", | |
value: 42, | |
raw: "42" | |
}, | |
kind: "init", | |
method: false, | |
shorthand: false | |
}] | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("x = { true: 42 }"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "AssignmentExpression", | |
operator: "=", | |
left: { | |
type: "Identifier", | |
name: "x" | |
}, | |
right: { | |
type: "ObjectExpression", | |
properties: [{ | |
type: "Property", | |
key: { | |
type: "Identifier", | |
name: "true" | |
}, | |
computed: false, | |
value: { | |
type: "Literal", | |
value: 42, | |
raw: "42" | |
}, | |
kind: "init", | |
method: false, | |
shorthand: false | |
}] | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("x = { false: 42 }"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "AssignmentExpression", | |
operator: "=", | |
left: { | |
type: "Identifier", | |
name: "x" | |
}, | |
right: { | |
type: "ObjectExpression", | |
properties: [{ | |
type: "Property", | |
key: { | |
type: "Identifier", | |
name: "false" | |
}, | |
computed: false, | |
value: { | |
type: "Literal", | |
value: 42, | |
raw: "42" | |
}, | |
kind: "init", | |
method: false, | |
shorthand: false | |
}] | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("x = { null: 42 }"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "AssignmentExpression", | |
operator: "=", | |
left: { | |
type: "Identifier", | |
name: "x" | |
}, | |
right: { | |
type: "ObjectExpression", | |
properties: [{ | |
type: "Property", | |
key: { | |
type: "Identifier", | |
name: "null" | |
}, | |
computed: false, | |
value: { | |
type: "Literal", | |
value: 42, | |
raw: "42" | |
}, | |
kind: "init", | |
method: false, | |
shorthand: false | |
}] | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("x = { \"answer\": 42 }"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "AssignmentExpression", | |
operator: "=", | |
left: { | |
type: "Identifier", | |
name: "x" | |
}, | |
right: { | |
type: "ObjectExpression", | |
properties: [{ | |
type: "Property", | |
key: { | |
type: "Literal", | |
value: "answer", | |
raw: "\"answer\"" | |
}, | |
computed: false, | |
value: { | |
type: "Literal", | |
value: 42, | |
raw: "42" | |
}, | |
kind: "init", | |
method: false, | |
shorthand: false | |
}] | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("x = { x: 1, x: 2 }"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "AssignmentExpression", | |
operator: "=", | |
left: { | |
type: "Identifier", | |
name: "x" | |
}, | |
right: { | |
type: "ObjectExpression", | |
properties: [{ | |
type: "Property", | |
key: { | |
type: "Identifier", | |
name: "x" | |
}, | |
computed: false, | |
value: { | |
type: "Literal", | |
value: 1, | |
raw: "1" | |
}, | |
kind: "init", | |
method: false, | |
shorthand: false | |
}, { | |
type: "Property", | |
key: { | |
type: "Identifier", | |
name: "x" | |
}, | |
computed: false, | |
value: { | |
type: "Literal", | |
value: 2, | |
raw: "2" | |
}, | |
kind: "init", | |
method: false, | |
shorthand: false | |
}] | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("x = { get width() { return m_width } }"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "AssignmentExpression", | |
operator: "=", | |
left: { | |
type: "Identifier", | |
name: "x" | |
}, | |
right: { | |
type: "ObjectExpression", | |
properties: [{ | |
type: "Property", | |
key: { | |
type: "Identifier", | |
name: "width" | |
}, | |
computed: false, | |
value: { | |
type: "FunctionExpression", | |
id: null, | |
params: [], | |
defaults: [], | |
body: { | |
type: "BlockStatement", | |
body: [{ | |
type: "ReturnStatement", | |
argument: { | |
type: "Identifier", | |
name: "m_width" | |
} | |
}] | |
}, | |
generator: false, | |
expression: false | |
}, | |
kind: "get", | |
method: false, | |
shorthand: false | |
}] | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("x = { get undef() {} }"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "AssignmentExpression", | |
operator: "=", | |
left: { | |
type: "Identifier", | |
name: "x" | |
}, | |
right: { | |
type: "ObjectExpression", | |
properties: [{ | |
type: "Property", | |
key: { | |
type: "Identifier", | |
name: "undef" | |
}, | |
computed: false, | |
value: { | |
type: "FunctionExpression", | |
id: null, | |
params: [], | |
defaults: [], | |
body: { | |
type: "BlockStatement", | |
body: [] | |
}, | |
generator: false, | |
expression: false | |
}, | |
kind: "get", | |
method: false, | |
shorthand: false | |
}] | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("x = { get if() {} }"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "AssignmentExpression", | |
operator: "=", | |
left: { | |
type: "Identifier", | |
name: "x" | |
}, | |
right: { | |
type: "ObjectExpression", | |
properties: [{ | |
type: "Property", | |
key: { | |
type: "Identifier", | |
name: "if" | |
}, | |
computed: false, | |
value: { | |
type: "FunctionExpression", | |
id: null, | |
params: [], | |
defaults: [], | |
body: { | |
type: "BlockStatement", | |
body: [] | |
}, | |
generator: false, | |
expression: false | |
}, | |
kind: "get", | |
method: false, | |
shorthand: false | |
}] | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("x = { get true() {} }"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "AssignmentExpression", | |
operator: "=", | |
left: { | |
type: "Identifier", | |
name: "x" | |
}, | |
right: { | |
type: "ObjectExpression", | |
properties: [{ | |
type: "Property", | |
key: { | |
type: "Identifier", | |
name: "true" | |
}, | |
computed: false, | |
value: { | |
type: "FunctionExpression", | |
id: null, | |
params: [], | |
defaults: [], | |
body: { | |
type: "BlockStatement", | |
body: [] | |
}, | |
generator: false, | |
expression: false | |
}, | |
kind: "get", | |
method: false, | |
shorthand: false | |
}] | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("x = { get false() {} }"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "AssignmentExpression", | |
operator: "=", | |
left: { | |
type: "Identifier", | |
name: "x" | |
}, | |
right: { | |
type: "ObjectExpression", | |
properties: [{ | |
type: "Property", | |
key: { | |
type: "Identifier", | |
name: "false" | |
}, | |
computed: false, | |
value: { | |
type: "FunctionExpression", | |
id: null, | |
params: [], | |
defaults: [], | |
body: { | |
type: "BlockStatement", | |
body: [] | |
}, | |
generator: false, | |
expression: false | |
}, | |
kind: "get", | |
method: false, | |
shorthand: false | |
}] | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("x = { get null() {} }"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "AssignmentExpression", | |
operator: "=", | |
left: { | |
type: "Identifier", | |
name: "x" | |
}, | |
right: { | |
type: "ObjectExpression", | |
properties: [{ | |
type: "Property", | |
key: { | |
type: "Identifier", | |
name: "null" | |
}, | |
computed: false, | |
value: { | |
type: "FunctionExpression", | |
id: null, | |
params: [], | |
defaults: [], | |
body: { | |
type: "BlockStatement", | |
body: [] | |
}, | |
generator: false, | |
expression: false | |
}, | |
kind: "get", | |
method: false, | |
shorthand: false | |
}] | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("x = { get \"undef\"() {} }"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "AssignmentExpression", | |
operator: "=", | |
left: { | |
type: "Identifier", | |
name: "x" | |
}, | |
right: { | |
type: "ObjectExpression", | |
properties: [{ | |
type: "Property", | |
key: { | |
type: "Literal", | |
value: "undef", | |
raw: "\"undef\"" | |
}, | |
computed: false, | |
value: { | |
type: "FunctionExpression", | |
id: null, | |
params: [], | |
defaults: [], | |
body: { | |
type: "BlockStatement", | |
body: [] | |
}, | |
generator: false, | |
expression: false | |
}, | |
kind: "get", | |
method: false, | |
shorthand: false | |
}] | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("x = { get 10() {} }"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "AssignmentExpression", | |
operator: "=", | |
left: { | |
type: "Identifier", | |
name: "x" | |
}, | |
right: { | |
type: "ObjectExpression", | |
properties: [{ | |
type: "Property", | |
key: { | |
type: "Literal", | |
value: 10, | |
raw: "10" | |
}, | |
computed: false, | |
value: { | |
type: "FunctionExpression", | |
id: null, | |
params: [], | |
defaults: [], | |
body: { | |
type: "BlockStatement", | |
body: [] | |
}, | |
generator: false, | |
expression: false | |
}, | |
kind: "get", | |
method: false, | |
shorthand: false | |
}] | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("x = { set width(w) { m_width = w } }"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "AssignmentExpression", | |
operator: "=", | |
left: { | |
type: "Identifier", | |
name: "x" | |
}, | |
right: { | |
type: "ObjectExpression", | |
properties: [{ | |
type: "Property", | |
key: { | |
type: "Identifier", | |
name: "width" | |
}, | |
computed: false, | |
value: { | |
type: "FunctionExpression", | |
id: null, | |
params: [{ | |
type: "Identifier", | |
name: "w" | |
}], | |
defaults: [], | |
body: { | |
type: "BlockStatement", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "AssignmentExpression", | |
operator: "=", | |
left: { | |
type: "Identifier", | |
name: "m_width" | |
}, | |
right: { | |
type: "Identifier", | |
name: "w" | |
} | |
} | |
}] | |
}, | |
generator: false, | |
expression: false | |
}, | |
kind: "set", | |
method: false, | |
shorthand: false | |
}] | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("x = { set if(w) { m_if = w } }"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "AssignmentExpression", | |
operator: "=", | |
left: { | |
type: "Identifier", | |
name: "x" | |
}, | |
right: { | |
type: "ObjectExpression", | |
properties: [{ | |
type: "Property", | |
key: { | |
type: "Identifier", | |
name: "if" | |
}, | |
computed: false, | |
value: { | |
type: "FunctionExpression", | |
id: null, | |
params: [{ | |
type: "Identifier", | |
name: "w" | |
}], | |
defaults: [], | |
body: { | |
type: "BlockStatement", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "AssignmentExpression", | |
operator: "=", | |
left: { | |
type: "Identifier", | |
name: "m_if" | |
}, | |
right: { | |
type: "Identifier", | |
name: "w" | |
} | |
} | |
}] | |
}, | |
generator: false, | |
expression: false | |
}, | |
kind: "set", | |
method: false, | |
shorthand: false | |
}] | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("x = { set true(w) { m_true = w } }"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "AssignmentExpression", | |
operator: "=", | |
left: { | |
type: "Identifier", | |
name: "x" | |
}, | |
right: { | |
type: "ObjectExpression", | |
properties: [{ | |
type: "Property", | |
key: { | |
type: "Identifier", | |
name: "true" | |
}, | |
computed: false, | |
value: { | |
type: "FunctionExpression", | |
id: null, | |
params: [{ | |
type: "Identifier", | |
name: "w" | |
}], | |
defaults: [], | |
body: { | |
type: "BlockStatement", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "AssignmentExpression", | |
operator: "=", | |
left: { | |
type: "Identifier", | |
name: "m_true" | |
}, | |
right: { | |
type: "Identifier", | |
name: "w" | |
} | |
} | |
}] | |
}, | |
generator: false, | |
expression: false | |
}, | |
kind: "set", | |
method: false, | |
shorthand: false | |
}] | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("x = { set false(w) { m_false = w } }"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "AssignmentExpression", | |
operator: "=", | |
left: { | |
type: "Identifier", | |
name: "x" | |
}, | |
right: { | |
type: "ObjectExpression", | |
properties: [{ | |
type: "Property", | |
key: { | |
type: "Identifier", | |
name: "false" | |
}, | |
computed: false, | |
value: { | |
type: "FunctionExpression", | |
id: null, | |
params: [{ | |
type: "Identifier", | |
name: "w" | |
}], | |
defaults: [], | |
body: { | |
type: "BlockStatement", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "AssignmentExpression", | |
operator: "=", | |
left: { | |
type: "Identifier", | |
name: "m_false" | |
}, | |
right: { | |
type: "Identifier", | |
name: "w" | |
} | |
} | |
}] | |
}, | |
generator: false, | |
expression: false | |
}, | |
kind: "set", | |
method: false, | |
shorthand: false | |
}] | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("x = { set null(w) { m_null = w } }"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "AssignmentExpression", | |
operator: "=", | |
left: { | |
type: "Identifier", | |
name: "x" | |
}, | |
right: { | |
type: "ObjectExpression", | |
properties: [{ | |
type: "Property", | |
key: { | |
type: "Identifier", | |
name: "null" | |
}, | |
computed: false, | |
value: { | |
type: "FunctionExpression", | |
id: null, | |
params: [{ | |
type: "Identifier", | |
name: "w" | |
}], | |
defaults: [], | |
body: { | |
type: "BlockStatement", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "AssignmentExpression", | |
operator: "=", | |
left: { | |
type: "Identifier", | |
name: "m_null" | |
}, | |
right: { | |
type: "Identifier", | |
name: "w" | |
} | |
} | |
}] | |
}, | |
generator: false, | |
expression: false | |
}, | |
kind: "set", | |
method: false, | |
shorthand: false | |
}] | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("x = { set \"null\"(w) { m_null = w } }"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "AssignmentExpression", | |
operator: "=", | |
left: { | |
type: "Identifier", | |
name: "x" | |
}, | |
right: { | |
type: "ObjectExpression", | |
properties: [{ | |
type: "Property", | |
key: { | |
type: "Literal", | |
value: "null", | |
raw: "\"null\"" | |
}, | |
computed: false, | |
value: { | |
type: "FunctionExpression", | |
id: null, | |
params: [{ | |
type: "Identifier", | |
name: "w" | |
}], | |
defaults: [], | |
body: { | |
type: "BlockStatement", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "AssignmentExpression", | |
operator: "=", | |
left: { | |
type: "Identifier", | |
name: "m_null" | |
}, | |
right: { | |
type: "Identifier", | |
name: "w" | |
} | |
} | |
}] | |
}, | |
generator: false, | |
expression: false | |
}, | |
kind: "set", | |
method: false, | |
shorthand: false | |
}] | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("x = { set 10(w) { m_null = w } }"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "AssignmentExpression", | |
operator: "=", | |
left: { | |
type: "Identifier", | |
name: "x" | |
}, | |
right: { | |
type: "ObjectExpression", | |
properties: [{ | |
type: "Property", | |
key: { | |
type: "Literal", | |
value: 10, | |
raw: "10" | |
}, | |
computed: false, | |
value: { | |
type: "FunctionExpression", | |
id: null, | |
params: [{ | |
type: "Identifier", | |
name: "w" | |
}], | |
defaults: [], | |
body: { | |
type: "BlockStatement", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "AssignmentExpression", | |
operator: "=", | |
left: { | |
type: "Identifier", | |
name: "m_null" | |
}, | |
right: { | |
type: "Identifier", | |
name: "w" | |
} | |
} | |
}] | |
}, | |
generator: false, | |
expression: false | |
}, | |
kind: "set", | |
method: false, | |
shorthand: false | |
}] | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("x = { get: 42 }"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "AssignmentExpression", | |
operator: "=", | |
left: { | |
type: "Identifier", | |
name: "x" | |
}, | |
right: { | |
type: "ObjectExpression", | |
properties: [{ | |
type: "Property", | |
key: { | |
type: "Identifier", | |
name: "get" | |
}, | |
computed: false, | |
value: { | |
type: "Literal", | |
value: 42, | |
raw: "42" | |
}, | |
kind: "init", | |
method: false, | |
shorthand: false | |
}] | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("x = { set: 43 }"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "AssignmentExpression", | |
operator: "=", | |
left: { | |
type: "Identifier", | |
name: "x" | |
}, | |
right: { | |
type: "ObjectExpression", | |
properties: [{ | |
type: "Property", | |
key: { | |
type: "Identifier", | |
name: "set" | |
}, | |
computed: false, | |
value: { | |
type: "Literal", | |
value: 43, | |
raw: "43" | |
}, | |
kind: "init", | |
method: false, | |
shorthand: false | |
}] | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("/* block comment */ 42"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "Literal", | |
value: 42, | |
raw: "42" | |
} | |
}] | |
}); | |
chk(esprima.parse("42 /*The*/ /*Answer*/"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "Literal", | |
value: 42, | |
raw: "42" | |
} | |
}] | |
}); | |
chk(esprima.parse("42 /*the*/ /*answer*/"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "Literal", | |
value: 42, | |
raw: "42" | |
} | |
}] | |
}); | |
chk(esprima.parse("/* multiline\ncomment\nshould\nbe\nignored */ 42"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "Literal", | |
value: 42, | |
raw: "42" | |
} | |
}] | |
}); | |
chk(esprima.parse("/*a\r\nb*/ 42"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "Literal", | |
value: 42, | |
raw: "42" | |
} | |
}] | |
}); | |
chk(esprima.parse("/*a\rb*/ 42"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "Literal", | |
value: 42, | |
raw: "42" | |
} | |
}] | |
}); | |
chk(esprima.parse("/*a\nb*/ 42"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "Literal", | |
value: 42, | |
raw: "42" | |
} | |
}] | |
}); | |
chk(esprima.parse("/*a\nc*/ 42"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "Literal", | |
value: 42, | |
raw: "42" | |
} | |
}] | |
}); | |
chk(esprima.parse("// line comment\n42"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "Literal", | |
value: 42, | |
raw: "42" | |
} | |
}] | |
}); | |
chk(esprima.parse("42 // line comment"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "Literal", | |
value: 42, | |
raw: "42" | |
} | |
}] | |
}); | |
chk(esprima.parse("// Hello, world!\n42"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "Literal", | |
value: 42, | |
raw: "42" | |
} | |
}] | |
}); | |
chk(esprima.parse("// Hello, world!\n"), { | |
type: "Program", | |
body: [] | |
}); | |
chk(esprima.parse("// Hallo, world!\n"), { | |
type: "Program", | |
body: [] | |
}); | |
chk(esprima.parse("//\n42"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "Literal", | |
value: 42, | |
raw: "42" | |
} | |
}] | |
}); | |
chk(esprima.parse("//"), { | |
type: "Program", | |
body: [] | |
}); | |
chk(esprima.parse("// "), { | |
type: "Program", | |
body: [] | |
}); | |
chk(esprima.parse("/**/42"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "Literal", | |
value: 42, | |
raw: "42" | |
} | |
}] | |
}); | |
chk(esprima.parse("// Hello, world!\n\n// Another hello\n42"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "Literal", | |
value: 42, | |
raw: "42" | |
} | |
}] | |
}); | |
chk(esprima.parse("if (x) { // Some comment\ndoThat(); }"), { | |
type: "Program", | |
body: [{ | |
type: "IfStatement", | |
test: { | |
type: "Identifier", | |
name: "x" | |
}, | |
consequent: { | |
type: "BlockStatement", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "CallExpression", | |
callee: { | |
type: "Identifier", | |
name: "doThat" | |
}, | |
arguments: [] | |
} | |
}] | |
}, | |
alternate: null | |
}] | |
}); | |
chk(esprima.parse("switch (answer) { case 42: /* perfect */ bingo() }"), { | |
type: "Program", | |
body: [{ | |
type: "SwitchStatement", | |
discriminant: { | |
type: "Identifier", | |
name: "answer" | |
}, | |
cases: [{ | |
type: "SwitchCase", | |
test: { | |
type: "Literal", | |
value: 42, | |
raw: "42" | |
}, | |
consequent: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "CallExpression", | |
callee: { | |
type: "Identifier", | |
name: "bingo" | |
}, | |
arguments: [] | |
} | |
}] | |
}] | |
}] | |
}); | |
chk(esprima.parse("0"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "Literal", | |
value: 0, | |
raw: "0" | |
} | |
}] | |
}); | |
chk(esprima.parse("3"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "Literal", | |
value: 3, | |
raw: "3" | |
} | |
}] | |
}); | |
chk(esprima.parse("5"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "Literal", | |
value: 5, | |
raw: "5" | |
} | |
}] | |
}); | |
chk(esprima.parse("42"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "Literal", | |
value: 42, | |
raw: "42" | |
} | |
}] | |
}); | |
chk(esprima.parse(".14"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "Literal", | |
value: 0.14, | |
raw: ".14" | |
} | |
}] | |
}); | |
chk(esprima.parse("3.14159"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "Literal", | |
value: 3.14159, | |
raw: "3.14159" | |
} | |
}] | |
}); | |
chk(esprima.parse("6.02214179e+23"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "Literal", | |
value: 6.02214179e+23, | |
raw: "6.02214179e+23" | |
} | |
}] | |
}); | |
chk(esprima.parse("1.492417830e-10"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "Literal", | |
value: 1.49241783e-10, | |
raw: "1.492417830e-10" | |
} | |
}] | |
}); | |
chk(esprima.parse("0x0"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "Literal", | |
value: 0, | |
raw: "0x0" | |
} | |
}] | |
}); | |
chk(esprima.parse("0e+100"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "Literal", | |
value: 0, | |
raw: "0e+100" | |
} | |
}] | |
}); | |
chk(esprima.parse("0xabc"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "Literal", | |
value: 2748, | |
raw: "0xabc" | |
} | |
}] | |
}); | |
chk(esprima.parse("0xdef"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "Literal", | |
value: 3567, | |
raw: "0xdef" | |
} | |
}] | |
}); | |
chk(esprima.parse("0X1A"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "Literal", | |
value: 26, | |
raw: "0X1A" | |
} | |
}] | |
}); | |
chk(esprima.parse("0x10"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "Literal", | |
value: 16, | |
raw: "0x10" | |
} | |
}] | |
}); | |
chk(esprima.parse("0x100"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "Literal", | |
value: 256, | |
raw: "0x100" | |
} | |
}] | |
}); | |
chk(esprima.parse("0X04"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "Literal", | |
value: 4, | |
raw: "0X04" | |
} | |
}] | |
}); | |
chk(esprima.parse("02"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "Literal", | |
value: 2, | |
raw: "02" | |
} | |
}] | |
}); | |
chk(esprima.parse("012"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "Literal", | |
value: 10, | |
raw: "012" | |
} | |
}] | |
}); | |
chk(esprima.parse("0012"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "Literal", | |
value: 10, | |
raw: "0012" | |
} | |
}] | |
}); | |
chk(esprima.parse("\"Hello\""), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "Literal", | |
value: "Hello", | |
raw: "\"Hello\"" | |
} | |
}] | |
}); | |
chk(esprima.parse("\"\\n\\r\\t\\v\\b\\f\\\\\\'\\\"\\0\""), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "Literal", | |
value: "\n\r\t\u000b\b\f\\'\"\u0000", | |
raw: "\"\\n\\r\\t\\v\\b\\f\\\\\\'\\\"\\0\"" | |
} | |
}] | |
}); | |
chk(esprima.parse("\"\\u0061\""), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "Literal", | |
value: "a", | |
raw: "\"\\u0061\"" | |
} | |
}] | |
}); | |
chk(esprima.parse("\"\\x61\""), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "Literal", | |
value: "a", | |
raw: "\"\\x61\"" | |
} | |
}] | |
}); | |
chk(esprima.parse("\"Hello\\nworld\""), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "Literal", | |
value: "Hello\nworld", | |
raw: "\"Hello\\nworld\"" | |
} | |
}] | |
}); | |
chk(esprima.parse("\"Hello\\\nworld\""), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "Literal", | |
value: "Helloworld", | |
raw: "\"Hello\\\nworld\"" | |
} | |
}] | |
}); | |
chk(esprima.parse("\"Hello\\02World\""), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "Literal", | |
value: "Hello\u0002World", | |
raw: "\"Hello\\02World\"" | |
} | |
}] | |
}); | |
chk(esprima.parse("\"Hello\\012World\""), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "Literal", | |
value: "Hello\nWorld", | |
raw: "\"Hello\\012World\"" | |
} | |
}] | |
}); | |
chk(esprima.parse("\"Hello\\122World\""), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "Literal", | |
value: "HelloRWorld", | |
raw: "\"Hello\\122World\"" | |
} | |
}] | |
}); | |
chk(esprima.parse("\"Hello\\0122World\""), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "Literal", | |
value: "Hello\n2World", | |
raw: "\"Hello\\0122World\"" | |
} | |
}] | |
}); | |
chk(esprima.parse("\"Hello\\312World\""), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "Literal", | |
value: "HelloÊWorld", | |
raw: "\"Hello\\312World\"" | |
} | |
}] | |
}); | |
chk(esprima.parse("\"Hello\\412World\""), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "Literal", | |
value: "Hello!2World", | |
raw: "\"Hello\\412World\"" | |
} | |
}] | |
}); | |
chk(esprima.parse("\"Hello\\812World\""), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "Literal", | |
value: "Hello812World", | |
raw: "\"Hello\\812World\"" | |
} | |
}] | |
}); | |
chk(esprima.parse("\"Hello\\712World\""), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "Literal", | |
value: "Hello92World", | |
raw: "\"Hello\\712World\"" | |
} | |
}] | |
}); | |
chk(esprima.parse("\"Hello\\0World\""), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "Literal", | |
value: "Hello\u0000World", | |
raw: "\"Hello\\0World\"" | |
} | |
}] | |
}); | |
chk(esprima.parse("\"Hello\\\r\nworld\""), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "Literal", | |
value: "Helloworld", | |
raw: "\"Hello\\\r\nworld\"" | |
} | |
}] | |
}); | |
chk(esprima.parse("\"Hello\\1World\""), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "Literal", | |
value: "Hello\u0001World", | |
raw: "\"Hello\\1World\"" | |
} | |
}] | |
}); | |
chk(esprima.parse("var x = /[a-z]/i"), { | |
type: "Program", | |
body: [{ | |
type: "VariableDeclaration", | |
declarations: [{ | |
type: "VariableDeclarator", | |
id: { | |
type: "Identifier", | |
name: "x" | |
}, | |
init: { | |
type: "Literal", | |
value: {}, | |
raw: "/[a-z]/i", | |
regex: { | |
pattern: "[a-z]", | |
flags: "i" | |
} | |
} | |
}], | |
kind: "var" | |
}] | |
}); | |
chk(esprima.parse("var x = /[x-z]/i"), { | |
type: "Program", | |
body: [{ | |
type: "VariableDeclaration", | |
declarations: [{ | |
type: "VariableDeclarator", | |
id: { | |
type: "Identifier", | |
name: "x" | |
}, | |
init: { | |
type: "Literal", | |
value: {}, | |
raw: "/[x-z]/i", | |
regex: { | |
pattern: "[x-z]", | |
flags: "i" | |
} | |
} | |
}], | |
kind: "var" | |
}] | |
}); | |
chk(esprima.parse("var x = /[a-c]/i"), { | |
type: "Program", | |
body: [{ | |
type: "VariableDeclaration", | |
declarations: [{ | |
type: "VariableDeclarator", | |
id: { | |
type: "Identifier", | |
name: "x" | |
}, | |
init: { | |
type: "Literal", | |
value: {}, | |
raw: "/[a-c]/i", | |
regex: { | |
pattern: "[a-c]", | |
flags: "i" | |
} | |
} | |
}], | |
kind: "var" | |
}] | |
}); | |
chk(esprima.parse("var x = /[P QR]/i"), { | |
type: "Program", | |
body: [{ | |
type: "VariableDeclaration", | |
declarations: [{ | |
type: "VariableDeclarator", | |
id: { | |
type: "Identifier", | |
name: "x" | |
}, | |
init: { | |
type: "Literal", | |
value: {}, | |
raw: "/[P QR]/i", | |
regex: { | |
pattern: "[P QR]", | |
flags: "i" | |
} | |
} | |
}], | |
kind: "var" | |
}] | |
}); | |
chk(esprima.parse("var x = /foo\\/bar/"), { | |
type: "Program", | |
body: [{ | |
type: "VariableDeclaration", | |
declarations: [{ | |
type: "VariableDeclarator", | |
id: { | |
type: "Identifier", | |
name: "x" | |
}, | |
init: { | |
type: "Literal", | |
value: {}, | |
raw: "/foo\\/bar/", | |
regex: { | |
pattern: "foo\\/bar", | |
flags: "" | |
} | |
} | |
}], | |
kind: "var" | |
}] | |
}); | |
chk(esprima.parse("var x = /=([^=\\s])+/g"), { | |
type: "Program", | |
body: [{ | |
type: "VariableDeclaration", | |
declarations: [{ | |
type: "VariableDeclarator", | |
id: { | |
type: "Identifier", | |
name: "x" | |
}, | |
init: { | |
type: "Literal", | |
value: {}, | |
raw: "/=([^=\\s])+/g", | |
regex: { | |
pattern: "=([^=\\s])+", | |
flags: "g" | |
} | |
} | |
}], | |
kind: "var" | |
}] | |
}); | |
chk(esprima.parse("new Button"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "NewExpression", | |
callee: { | |
type: "Identifier", | |
name: "Button" | |
}, | |
arguments: [] | |
} | |
}] | |
}); | |
chk(esprima.parse("new Button()"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "NewExpression", | |
callee: { | |
type: "Identifier", | |
name: "Button" | |
}, | |
arguments: [] | |
} | |
}] | |
}); | |
chk(esprima.parse("new new foo"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "NewExpression", | |
callee: { | |
type: "NewExpression", | |
callee: { | |
type: "Identifier", | |
name: "foo" | |
}, | |
arguments: [] | |
}, | |
arguments: [] | |
} | |
}] | |
}); | |
chk(esprima.parse("new new foo()"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "NewExpression", | |
callee: { | |
type: "NewExpression", | |
callee: { | |
type: "Identifier", | |
name: "foo" | |
}, | |
arguments: [] | |
}, | |
arguments: [] | |
} | |
}] | |
}); | |
chk(esprima.parse("new foo().bar()"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "CallExpression", | |
callee: { | |
type: "MemberExpression", | |
computed: false, | |
object: { | |
type: "NewExpression", | |
callee: { | |
type: "Identifier", | |
name: "foo" | |
}, | |
arguments: [] | |
}, | |
property: { | |
type: "Identifier", | |
name: "bar" | |
} | |
}, | |
arguments: [] | |
} | |
}] | |
}); | |
chk(esprima.parse("new foo[bar]"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "NewExpression", | |
callee: { | |
type: "MemberExpression", | |
computed: true, | |
object: { | |
type: "Identifier", | |
name: "foo" | |
}, | |
property: { | |
type: "Identifier", | |
name: "bar" | |
} | |
}, | |
arguments: [] | |
} | |
}] | |
}); | |
chk(esprima.parse("new foo.bar()"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "NewExpression", | |
callee: { | |
type: "MemberExpression", | |
computed: false, | |
object: { | |
type: "Identifier", | |
name: "foo" | |
}, | |
property: { | |
type: "Identifier", | |
name: "bar" | |
} | |
}, | |
arguments: [] | |
} | |
}] | |
}); | |
chk(esprima.parse("( new foo).bar()"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "CallExpression", | |
callee: { | |
type: "MemberExpression", | |
computed: false, | |
object: { | |
type: "NewExpression", | |
callee: { | |
type: "Identifier", | |
name: "foo" | |
}, | |
arguments: [] | |
}, | |
property: { | |
type: "Identifier", | |
name: "bar" | |
} | |
}, | |
arguments: [] | |
} | |
}] | |
}); | |
chk(esprima.parse("foo(bar, baz)"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "CallExpression", | |
callee: { | |
type: "Identifier", | |
name: "foo" | |
}, | |
arguments: [{ | |
type: "Identifier", | |
name: "bar" | |
}, { | |
type: "Identifier", | |
name: "baz" | |
}] | |
} | |
}] | |
}); | |
chk(esprima.parse("( foo )()"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "CallExpression", | |
callee: { | |
type: "Identifier", | |
name: "foo" | |
}, | |
arguments: [] | |
} | |
}] | |
}); | |
chk(esprima.parse("universe.milkyway"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "MemberExpression", | |
computed: false, | |
object: { | |
type: "Identifier", | |
name: "universe" | |
}, | |
property: { | |
type: "Identifier", | |
name: "milkyway" | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("universe.milkyway.solarsystem"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "MemberExpression", | |
computed: false, | |
object: { | |
type: "MemberExpression", | |
computed: false, | |
object: { | |
type: "Identifier", | |
name: "universe" | |
}, | |
property: { | |
type: "Identifier", | |
name: "milkyway" | |
} | |
}, | |
property: { | |
type: "Identifier", | |
name: "solarsystem" | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("universe.milkyway.solarsystem.Earth"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "MemberExpression", | |
computed: false, | |
object: { | |
type: "MemberExpression", | |
computed: false, | |
object: { | |
type: "MemberExpression", | |
computed: false, | |
object: { | |
type: "Identifier", | |
name: "universe" | |
}, | |
property: { | |
type: "Identifier", | |
name: "milkyway" | |
} | |
}, | |
property: { | |
type: "Identifier", | |
name: "solarsystem" | |
} | |
}, | |
property: { | |
type: "Identifier", | |
name: "Earth" | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("universe[galaxyName, otherUselessName]"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "MemberExpression", | |
computed: true, | |
object: { | |
type: "Identifier", | |
name: "universe" | |
}, | |
property: { | |
type: "SequenceExpression", | |
expressions: [{ | |
type: "Identifier", | |
name: "galaxyName" | |
}, { | |
type: "Identifier", | |
name: "otherUselessName" | |
}] | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("universe[galaxyName]"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "MemberExpression", | |
computed: true, | |
object: { | |
type: "Identifier", | |
name: "universe" | |
}, | |
property: { | |
type: "Identifier", | |
name: "galaxyName" | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("universe[42].galaxies"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "MemberExpression", | |
computed: false, | |
object: { | |
type: "MemberExpression", | |
computed: true, | |
object: { | |
type: "Identifier", | |
name: "universe" | |
}, | |
property: { | |
type: "Literal", | |
value: 42, | |
raw: "42" | |
} | |
}, | |
property: { | |
type: "Identifier", | |
name: "galaxies" | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("universe(42).galaxies"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "MemberExpression", | |
computed: false, | |
object: { | |
type: "CallExpression", | |
callee: { | |
type: "Identifier", | |
name: "universe" | |
}, | |
arguments: [{ | |
type: "Literal", | |
value: 42, | |
raw: "42" | |
}] | |
}, | |
property: { | |
type: "Identifier", | |
name: "galaxies" | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("universe(42).galaxies(14, 3, 77).milkyway"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "MemberExpression", | |
computed: false, | |
object: { | |
type: "CallExpression", | |
callee: { | |
type: "MemberExpression", | |
computed: false, | |
object: { | |
type: "CallExpression", | |
callee: { | |
type: "Identifier", | |
name: "universe" | |
}, | |
arguments: [{ | |
type: "Literal", | |
value: 42, | |
raw: "42" | |
}] | |
}, | |
property: { | |
type: "Identifier", | |
name: "galaxies" | |
} | |
}, | |
arguments: [{ | |
type: "Literal", | |
value: 14, | |
raw: "14" | |
}, { | |
type: "Literal", | |
value: 3, | |
raw: "3" | |
}, { | |
type: "Literal", | |
value: 77, | |
raw: "77" | |
}] | |
}, | |
property: { | |
type: "Identifier", | |
name: "milkyway" | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("earth.asia.Indonesia.prepareForElection(2014)"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "CallExpression", | |
callee: { | |
type: "MemberExpression", | |
computed: false, | |
object: { | |
type: "MemberExpression", | |
computed: false, | |
object: { | |
type: "MemberExpression", | |
computed: false, | |
object: { | |
type: "Identifier", | |
name: "earth" | |
}, | |
property: { | |
type: "Identifier", | |
name: "asia" | |
} | |
}, | |
property: { | |
type: "Identifier", | |
name: "Indonesia" | |
} | |
}, | |
property: { | |
type: "Identifier", | |
name: "prepareForElection" | |
} | |
}, | |
arguments: [{ | |
type: "Literal", | |
value: 2014, | |
raw: "2014" | |
}] | |
} | |
}] | |
}); | |
chk(esprima.parse("universe.if"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "MemberExpression", | |
computed: false, | |
object: { | |
type: "Identifier", | |
name: "universe" | |
}, | |
property: { | |
type: "Identifier", | |
name: "if" | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("universe.true"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "MemberExpression", | |
computed: false, | |
object: { | |
type: "Identifier", | |
name: "universe" | |
}, | |
property: { | |
type: "Identifier", | |
name: "true" | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("universe.false"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "MemberExpression", | |
computed: false, | |
object: { | |
type: "Identifier", | |
name: "universe" | |
}, | |
property: { | |
type: "Identifier", | |
name: "false" | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("universe.null"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "MemberExpression", | |
computed: false, | |
object: { | |
type: "Identifier", | |
name: "universe" | |
}, | |
property: { | |
type: "Identifier", | |
name: "null" | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("x++"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "UpdateExpression", | |
operator: "++", | |
argument: { | |
type: "Identifier", | |
name: "x" | |
}, | |
prefix: false | |
} | |
}] | |
}); | |
chk(esprima.parse("x--"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "UpdateExpression", | |
operator: "--", | |
argument: { | |
type: "Identifier", | |
name: "x" | |
}, | |
prefix: false | |
} | |
}] | |
}); | |
chk(esprima.parse("eval++"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "UpdateExpression", | |
operator: "++", | |
argument: { | |
type: "Identifier", | |
name: "eval" | |
}, | |
prefix: false | |
} | |
}] | |
}); | |
chk(esprima.parse("eval--"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "UpdateExpression", | |
operator: "--", | |
argument: { | |
type: "Identifier", | |
name: "eval" | |
}, | |
prefix: false | |
} | |
}] | |
}); | |
chk(esprima.parse("arguments++"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "UpdateExpression", | |
operator: "++", | |
argument: { | |
type: "Identifier", | |
name: "arguments" | |
}, | |
prefix: false | |
} | |
}] | |
}); | |
chk(esprima.parse("arguments--"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "UpdateExpression", | |
operator: "--", | |
argument: { | |
type: "Identifier", | |
name: "arguments" | |
}, | |
prefix: false | |
} | |
}] | |
}); | |
chk(esprima.parse("++x"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "UpdateExpression", | |
operator: "++", | |
argument: { | |
type: "Identifier", | |
name: "x" | |
}, | |
prefix: true | |
} | |
}] | |
}); | |
chk(esprima.parse("--x"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "UpdateExpression", | |
operator: "--", | |
argument: { | |
type: "Identifier", | |
name: "x" | |
}, | |
prefix: true | |
} | |
}] | |
}); | |
chk(esprima.parse("++eval"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "UpdateExpression", | |
operator: "++", | |
argument: { | |
type: "Identifier", | |
name: "eval" | |
}, | |
prefix: true | |
} | |
}] | |
}); | |
chk(esprima.parse("--eval"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "UpdateExpression", | |
operator: "--", | |
argument: { | |
type: "Identifier", | |
name: "eval" | |
}, | |
prefix: true | |
} | |
}] | |
}); | |
chk(esprima.parse("++arguments"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "UpdateExpression", | |
operator: "++", | |
argument: { | |
type: "Identifier", | |
name: "arguments" | |
}, | |
prefix: true | |
} | |
}] | |
}); | |
chk(esprima.parse("--arguments"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "UpdateExpression", | |
operator: "--", | |
argument: { | |
type: "Identifier", | |
name: "arguments" | |
}, | |
prefix: true | |
} | |
}] | |
}); | |
chk(esprima.parse("+x"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "UnaryExpression", | |
operator: "+", | |
argument: { | |
type: "Identifier", | |
name: "x" | |
}, | |
prefix: true | |
} | |
}] | |
}); | |
chk(esprima.parse("-x"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "UnaryExpression", | |
operator: "-", | |
argument: { | |
type: "Identifier", | |
name: "x" | |
}, | |
prefix: true | |
} | |
}] | |
}); | |
chk(esprima.parse("~x"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "UnaryExpression", | |
operator: "~", | |
argument: { | |
type: "Identifier", | |
name: "x" | |
}, | |
prefix: true | |
} | |
}] | |
}); | |
chk(esprima.parse("!x"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "UnaryExpression", | |
operator: "!", | |
argument: { | |
type: "Identifier", | |
name: "x" | |
}, | |
prefix: true | |
} | |
}] | |
}); | |
chk(esprima.parse("void x"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "UnaryExpression", | |
operator: "void", | |
argument: { | |
type: "Identifier", | |
name: "x" | |
}, | |
prefix: true | |
} | |
}] | |
}); | |
chk(esprima.parse("delete x"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "UnaryExpression", | |
operator: "delete", | |
argument: { | |
type: "Identifier", | |
name: "x" | |
}, | |
prefix: true | |
} | |
}] | |
}); | |
chk(esprima.parse("typeof x"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "UnaryExpression", | |
operator: "typeof", | |
argument: { | |
type: "Identifier", | |
name: "x" | |
}, | |
prefix: true | |
} | |
}] | |
}); | |
chk(esprima.parse("x * y"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "BinaryExpression", | |
operator: "*", | |
left: { | |
type: "Identifier", | |
name: "x" | |
}, | |
right: { | |
type: "Identifier", | |
name: "y" | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("x / y"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "BinaryExpression", | |
operator: "/", | |
left: { | |
type: "Identifier", | |
name: "x" | |
}, | |
right: { | |
type: "Identifier", | |
name: "y" | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("x % y"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "BinaryExpression", | |
operator: "%", | |
left: { | |
type: "Identifier", | |
name: "x" | |
}, | |
right: { | |
type: "Identifier", | |
name: "y" | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("x + y"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "BinaryExpression", | |
operator: "+", | |
left: { | |
type: "Identifier", | |
name: "x" | |
}, | |
right: { | |
type: "Identifier", | |
name: "y" | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("x - y"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "BinaryExpression", | |
operator: "-", | |
left: { | |
type: "Identifier", | |
name: "x" | |
}, | |
right: { | |
type: "Identifier", | |
name: "y" | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("x << y"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "BinaryExpression", | |
operator: "<<", | |
left: { | |
type: "Identifier", | |
name: "x" | |
}, | |
right: { | |
type: "Identifier", | |
name: "y" | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("x >> y"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "BinaryExpression", | |
operator: ">>", | |
left: { | |
type: "Identifier", | |
name: "x" | |
}, | |
right: { | |
type: "Identifier", | |
name: "y" | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("x >>> y"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "BinaryExpression", | |
operator: ">>>", | |
left: { | |
type: "Identifier", | |
name: "x" | |
}, | |
right: { | |
type: "Identifier", | |
name: "y" | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("x < y"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "BinaryExpression", | |
operator: "<", | |
left: { | |
type: "Identifier", | |
name: "x" | |
}, | |
right: { | |
type: "Identifier", | |
name: "y" | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("x > y"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "BinaryExpression", | |
operator: ">", | |
left: { | |
type: "Identifier", | |
name: "x" | |
}, | |
right: { | |
type: "Identifier", | |
name: "y" | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("x <= y"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "BinaryExpression", | |
operator: "<=", | |
left: { | |
type: "Identifier", | |
name: "x" | |
}, | |
right: { | |
type: "Identifier", | |
name: "y" | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("x >= y"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "BinaryExpression", | |
operator: ">=", | |
left: { | |
type: "Identifier", | |
name: "x" | |
}, | |
right: { | |
type: "Identifier", | |
name: "y" | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("x in y"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "BinaryExpression", | |
operator: "in", | |
left: { | |
type: "Identifier", | |
name: "x" | |
}, | |
right: { | |
type: "Identifier", | |
name: "y" | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("x instanceof y"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "BinaryExpression", | |
operator: "instanceof", | |
left: { | |
type: "Identifier", | |
name: "x" | |
}, | |
right: { | |
type: "Identifier", | |
name: "y" | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("x < y < z"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "BinaryExpression", | |
operator: "<", | |
left: { | |
type: "BinaryExpression", | |
operator: "<", | |
left: { | |
type: "Identifier", | |
name: "x" | |
}, | |
right: { | |
type: "Identifier", | |
name: "y" | |
} | |
}, | |
right: { | |
type: "Identifier", | |
name: "z" | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("x == y"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "BinaryExpression", | |
operator: "==", | |
left: { | |
type: "Identifier", | |
name: "x" | |
}, | |
right: { | |
type: "Identifier", | |
name: "y" | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("x != y"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "BinaryExpression", | |
operator: "!=", | |
left: { | |
type: "Identifier", | |
name: "x" | |
}, | |
right: { | |
type: "Identifier", | |
name: "y" | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("x === y"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "BinaryExpression", | |
operator: "===", | |
left: { | |
type: "Identifier", | |
name: "x" | |
}, | |
right: { | |
type: "Identifier", | |
name: "y" | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("x !== y"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "BinaryExpression", | |
operator: "!==", | |
left: { | |
type: "Identifier", | |
name: "x" | |
}, | |
right: { | |
type: "Identifier", | |
name: "y" | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("x & y"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "BinaryExpression", | |
operator: "&", | |
left: { | |
type: "Identifier", | |
name: "x" | |
}, | |
right: { | |
type: "Identifier", | |
name: "y" | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("x ^ y"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "BinaryExpression", | |
operator: "^", | |
left: { | |
type: "Identifier", | |
name: "x" | |
}, | |
right: { | |
type: "Identifier", | |
name: "y" | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("x | y"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "BinaryExpression", | |
operator: "|", | |
left: { | |
type: "Identifier", | |
name: "x" | |
}, | |
right: { | |
type: "Identifier", | |
name: "y" | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("x + y + z"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "BinaryExpression", | |
operator: "+", | |
left: { | |
type: "BinaryExpression", | |
operator: "+", | |
left: { | |
type: "Identifier", | |
name: "x" | |
}, | |
right: { | |
type: "Identifier", | |
name: "y" | |
} | |
}, | |
right: { | |
type: "Identifier", | |
name: "z" | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("x - y + z"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "BinaryExpression", | |
operator: "+", | |
left: { | |
type: "BinaryExpression", | |
operator: "-", | |
left: { | |
type: "Identifier", | |
name: "x" | |
}, | |
right: { | |
type: "Identifier", | |
name: "y" | |
} | |
}, | |
right: { | |
type: "Identifier", | |
name: "z" | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("x + y - z"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "BinaryExpression", | |
operator: "-", | |
left: { | |
type: "BinaryExpression", | |
operator: "+", | |
left: { | |
type: "Identifier", | |
name: "x" | |
}, | |
right: { | |
type: "Identifier", | |
name: "y" | |
} | |
}, | |
right: { | |
type: "Identifier", | |
name: "z" | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("x - y - z"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "BinaryExpression", | |
operator: "-", | |
left: { | |
type: "BinaryExpression", | |
operator: "-", | |
left: { | |
type: "Identifier", | |
name: "x" | |
}, | |
right: { | |
type: "Identifier", | |
name: "y" | |
} | |
}, | |
right: { | |
type: "Identifier", | |
name: "z" | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("x + y * z"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "BinaryExpression", | |
operator: "+", | |
left: { | |
type: "Identifier", | |
name: "x" | |
}, | |
right: { | |
type: "BinaryExpression", | |
operator: "*", | |
left: { | |
type: "Identifier", | |
name: "y" | |
}, | |
right: { | |
type: "Identifier", | |
name: "z" | |
} | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("x + y / z"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "BinaryExpression", | |
operator: "+", | |
left: { | |
type: "Identifier", | |
name: "x" | |
}, | |
right: { | |
type: "BinaryExpression", | |
operator: "/", | |
left: { | |
type: "Identifier", | |
name: "y" | |
}, | |
right: { | |
type: "Identifier", | |
name: "z" | |
} | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("x - y % z"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "BinaryExpression", | |
operator: "-", | |
left: { | |
type: "Identifier", | |
name: "x" | |
}, | |
right: { | |
type: "BinaryExpression", | |
operator: "%", | |
left: { | |
type: "Identifier", | |
name: "y" | |
}, | |
right: { | |
type: "Identifier", | |
name: "z" | |
} | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("x * y * z"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "BinaryExpression", | |
operator: "*", | |
left: { | |
type: "BinaryExpression", | |
operator: "*", | |
left: { | |
type: "Identifier", | |
name: "x" | |
}, | |
right: { | |
type: "Identifier", | |
name: "y" | |
} | |
}, | |
right: { | |
type: "Identifier", | |
name: "z" | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("x * y / z"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "BinaryExpression", | |
operator: "/", | |
left: { | |
type: "BinaryExpression", | |
operator: "*", | |
left: { | |
type: "Identifier", | |
name: "x" | |
}, | |
right: { | |
type: "Identifier", | |
name: "y" | |
} | |
}, | |
right: { | |
type: "Identifier", | |
name: "z" | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("x * y % z"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "BinaryExpression", | |
operator: "%", | |
left: { | |
type: "BinaryExpression", | |
operator: "*", | |
left: { | |
type: "Identifier", | |
name: "x" | |
}, | |
right: { | |
type: "Identifier", | |
name: "y" | |
} | |
}, | |
right: { | |
type: "Identifier", | |
name: "z" | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("x % y * z"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "BinaryExpression", | |
operator: "*", | |
left: { | |
type: "BinaryExpression", | |
operator: "%", | |
left: { | |
type: "Identifier", | |
name: "x" | |
}, | |
right: { | |
type: "Identifier", | |
name: "y" | |
} | |
}, | |
right: { | |
type: "Identifier", | |
name: "z" | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("x << y << z"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "BinaryExpression", | |
operator: "<<", | |
left: { | |
type: "BinaryExpression", | |
operator: "<<", | |
left: { | |
type: "Identifier", | |
name: "x" | |
}, | |
right: { | |
type: "Identifier", | |
name: "y" | |
} | |
}, | |
right: { | |
type: "Identifier", | |
name: "z" | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("x | y | z"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "BinaryExpression", | |
operator: "|", | |
left: { | |
type: "BinaryExpression", | |
operator: "|", | |
left: { | |
type: "Identifier", | |
name: "x" | |
}, | |
right: { | |
type: "Identifier", | |
name: "y" | |
} | |
}, | |
right: { | |
type: "Identifier", | |
name: "z" | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("x & y & z"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "BinaryExpression", | |
operator: "&", | |
left: { | |
type: "BinaryExpression", | |
operator: "&", | |
left: { | |
type: "Identifier", | |
name: "x" | |
}, | |
right: { | |
type: "Identifier", | |
name: "y" | |
} | |
}, | |
right: { | |
type: "Identifier", | |
name: "z" | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("x ^ y ^ z"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "BinaryExpression", | |
operator: "^", | |
left: { | |
type: "BinaryExpression", | |
operator: "^", | |
left: { | |
type: "Identifier", | |
name: "x" | |
}, | |
right: { | |
type: "Identifier", | |
name: "y" | |
} | |
}, | |
right: { | |
type: "Identifier", | |
name: "z" | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("x & y | z"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "BinaryExpression", | |
operator: "|", | |
left: { | |
type: "BinaryExpression", | |
operator: "&", | |
left: { | |
type: "Identifier", | |
name: "x" | |
}, | |
right: { | |
type: "Identifier", | |
name: "y" | |
} | |
}, | |
right: { | |
type: "Identifier", | |
name: "z" | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("x | y ^ z"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "BinaryExpression", | |
operator: "|", | |
left: { | |
type: "Identifier", | |
name: "x" | |
}, | |
right: { | |
type: "BinaryExpression", | |
operator: "^", | |
left: { | |
type: "Identifier", | |
name: "y" | |
}, | |
right: { | |
type: "Identifier", | |
name: "z" | |
} | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("x | y & z"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "BinaryExpression", | |
operator: "|", | |
left: { | |
type: "Identifier", | |
name: "x" | |
}, | |
right: { | |
type: "BinaryExpression", | |
operator: "&", | |
left: { | |
type: "Identifier", | |
name: "y" | |
}, | |
right: { | |
type: "Identifier", | |
name: "z" | |
} | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("x || y"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "LogicalExpression", | |
operator: "||", | |
left: { | |
type: "Identifier", | |
name: "x" | |
}, | |
right: { | |
type: "Identifier", | |
name: "y" | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("x && y"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "LogicalExpression", | |
operator: "&&", | |
left: { | |
type: "Identifier", | |
name: "x" | |
}, | |
right: { | |
type: "Identifier", | |
name: "y" | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("x || y || z"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "LogicalExpression", | |
operator: "||", | |
left: { | |
type: "LogicalExpression", | |
operator: "||", | |
left: { | |
type: "Identifier", | |
name: "x" | |
}, | |
right: { | |
type: "Identifier", | |
name: "y" | |
} | |
}, | |
right: { | |
type: "Identifier", | |
name: "z" | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("x && y && z"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "LogicalExpression", | |
operator: "&&", | |
left: { | |
type: "LogicalExpression", | |
operator: "&&", | |
left: { | |
type: "Identifier", | |
name: "x" | |
}, | |
right: { | |
type: "Identifier", | |
name: "y" | |
} | |
}, | |
right: { | |
type: "Identifier", | |
name: "z" | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("x || y && z"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "LogicalExpression", | |
operator: "||", | |
left: { | |
type: "Identifier", | |
name: "x" | |
}, | |
right: { | |
type: "LogicalExpression", | |
operator: "&&", | |
left: { | |
type: "Identifier", | |
name: "y" | |
}, | |
right: { | |
type: "Identifier", | |
name: "z" | |
} | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("x || y ^ z"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "LogicalExpression", | |
operator: "||", | |
left: { | |
type: "Identifier", | |
name: "x" | |
}, | |
right: { | |
type: "BinaryExpression", | |
operator: "^", | |
left: { | |
type: "Identifier", | |
name: "y" | |
}, | |
right: { | |
type: "Identifier", | |
name: "z" | |
} | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("y ? 1 : 2"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "ConditionalExpression", | |
test: { | |
type: "Identifier", | |
name: "y" | |
}, | |
consequent: { | |
type: "Literal", | |
value: 1, | |
raw: "1" | |
}, | |
alternate: { | |
type: "Literal", | |
value: 2, | |
raw: "2" | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("x && y ? 1 : 2"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "ConditionalExpression", | |
test: { | |
type: "LogicalExpression", | |
operator: "&&", | |
left: { | |
type: "Identifier", | |
name: "x" | |
}, | |
right: { | |
type: "Identifier", | |
name: "y" | |
} | |
}, | |
consequent: { | |
type: "Literal", | |
value: 1, | |
raw: "1" | |
}, | |
alternate: { | |
type: "Literal", | |
value: 2, | |
raw: "2" | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("x = 42"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "AssignmentExpression", | |
operator: "=", | |
left: { | |
type: "Identifier", | |
name: "x" | |
}, | |
right: { | |
type: "Literal", | |
value: 42, | |
raw: "42" | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("eval = 42"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "AssignmentExpression", | |
operator: "=", | |
left: { | |
type: "Identifier", | |
name: "eval" | |
}, | |
right: { | |
type: "Literal", | |
value: 42, | |
raw: "42" | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("arguments = 42"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "AssignmentExpression", | |
operator: "=", | |
left: { | |
type: "Identifier", | |
name: "arguments" | |
}, | |
right: { | |
type: "Literal", | |
value: 42, | |
raw: "42" | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("x *= 42"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "AssignmentExpression", | |
operator: "*=", | |
left: { | |
type: "Identifier", | |
name: "x" | |
}, | |
right: { | |
type: "Literal", | |
value: 42, | |
raw: "42" | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("x /= 42"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "AssignmentExpression", | |
operator: "/=", | |
left: { | |
type: "Identifier", | |
name: "x" | |
}, | |
right: { | |
type: "Literal", | |
value: 42, | |
raw: "42" | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("x %= 42"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "AssignmentExpression", | |
operator: "%=", | |
left: { | |
type: "Identifier", | |
name: "x" | |
}, | |
right: { | |
type: "Literal", | |
value: 42, | |
raw: "42" | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("x += 42"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "AssignmentExpression", | |
operator: "+=", | |
left: { | |
type: "Identifier", | |
name: "x" | |
}, | |
right: { | |
type: "Literal", | |
value: 42, | |
raw: "42" | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("x -= 42"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "AssignmentExpression", | |
operator: "-=", | |
left: { | |
type: "Identifier", | |
name: "x" | |
}, | |
right: { | |
type: "Literal", | |
value: 42, | |
raw: "42" | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("x <<= 42"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "AssignmentExpression", | |
operator: "<<=", | |
left: { | |
type: "Identifier", | |
name: "x" | |
}, | |
right: { | |
type: "Literal", | |
value: 42, | |
raw: "42" | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("x >>= 42"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "AssignmentExpression", | |
operator: ">>=", | |
left: { | |
type: "Identifier", | |
name: "x" | |
}, | |
right: { | |
type: "Literal", | |
value: 42, | |
raw: "42" | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("x >>>= 42"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "AssignmentExpression", | |
operator: ">>>=", | |
left: { | |
type: "Identifier", | |
name: "x" | |
}, | |
right: { | |
type: "Literal", | |
value: 42, | |
raw: "42" | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("x &= 42"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "AssignmentExpression", | |
operator: "&=", | |
left: { | |
type: "Identifier", | |
name: "x" | |
}, | |
right: { | |
type: "Literal", | |
value: 42, | |
raw: "42" | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("x ^= 42"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "AssignmentExpression", | |
operator: "^=", | |
left: { | |
type: "Identifier", | |
name: "x" | |
}, | |
right: { | |
type: "Literal", | |
value: 42, | |
raw: "42" | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("x |= 42"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "AssignmentExpression", | |
operator: "|=", | |
left: { | |
type: "Identifier", | |
name: "x" | |
}, | |
right: { | |
type: "Literal", | |
value: 42, | |
raw: "42" | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("{ foo }"), { | |
type: "Program", | |
body: [{ | |
type: "BlockStatement", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "Identifier", | |
name: "foo" | |
} | |
}] | |
}] | |
}); | |
chk(esprima.parse("{ doThis(); doThat(); }"), { | |
type: "Program", | |
body: [{ | |
type: "BlockStatement", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "CallExpression", | |
callee: { | |
type: "Identifier", | |
name: "doThis" | |
}, | |
arguments: [] | |
} | |
}, { | |
type: "ExpressionStatement", | |
expression: { | |
type: "CallExpression", | |
callee: { | |
type: "Identifier", | |
name: "doThat" | |
}, | |
arguments: [] | |
} | |
}] | |
}] | |
}); | |
chk(esprima.parse("{}"), { | |
type: "Program", | |
body: [{ | |
type: "BlockStatement", | |
body: [] | |
}] | |
}); | |
chk(esprima.parse("var x"), { | |
type: "Program", | |
body: [{ | |
type: "VariableDeclaration", | |
declarations: [{ | |
type: "VariableDeclarator", | |
id: { | |
type: "Identifier", | |
name: "x" | |
}, | |
init: null | |
}], | |
kind: "var" | |
}] | |
}); | |
chk(esprima.parse("var x, y;"), { | |
type: "Program", | |
body: [{ | |
type: "VariableDeclaration", | |
declarations: [{ | |
type: "VariableDeclarator", | |
id: { | |
type: "Identifier", | |
name: "x" | |
}, | |
init: null | |
}, { | |
type: "VariableDeclarator", | |
id: { | |
type: "Identifier", | |
name: "y" | |
}, | |
init: null | |
}], | |
kind: "var" | |
}] | |
}); | |
chk(esprima.parse("var x = 42"), { | |
type: "Program", | |
body: [{ | |
type: "VariableDeclaration", | |
declarations: [{ | |
type: "VariableDeclarator", | |
id: { | |
type: "Identifier", | |
name: "x" | |
}, | |
init: { | |
type: "Literal", | |
value: 42, | |
raw: "42" | |
} | |
}], | |
kind: "var" | |
}] | |
}); | |
chk(esprima.parse("var eval = 42, arguments = 42"), { | |
type: "Program", | |
body: [{ | |
type: "VariableDeclaration", | |
declarations: [{ | |
type: "VariableDeclarator", | |
id: { | |
type: "Identifier", | |
name: "eval" | |
}, | |
init: { | |
type: "Literal", | |
value: 42, | |
raw: "42" | |
} | |
}, { | |
type: "VariableDeclarator", | |
id: { | |
type: "Identifier", | |
name: "arguments" | |
}, | |
init: { | |
type: "Literal", | |
value: 42, | |
raw: "42" | |
} | |
}], | |
kind: "var" | |
}] | |
}); | |
chk(esprima.parse("var x = 14, y = 3, z = 1977"), { | |
type: "Program", | |
body: [{ | |
type: "VariableDeclaration", | |
declarations: [{ | |
type: "VariableDeclarator", | |
id: { | |
type: "Identifier", | |
name: "x" | |
}, | |
init: { | |
type: "Literal", | |
value: 14, | |
raw: "14" | |
} | |
}, { | |
type: "VariableDeclarator", | |
id: { | |
type: "Identifier", | |
name: "y" | |
}, | |
init: { | |
type: "Literal", | |
value: 3, | |
raw: "3" | |
} | |
}, { | |
type: "VariableDeclarator", | |
id: { | |
type: "Identifier", | |
name: "z" | |
}, | |
init: { | |
type: "Literal", | |
value: 1977, | |
raw: "1977" | |
} | |
}], | |
kind: "var" | |
}] | |
}); | |
chk(esprima.parse("var implements, interface, package"), { | |
type: "Program", | |
body: [{ | |
type: "VariableDeclaration", | |
declarations: [{ | |
type: "VariableDeclarator", | |
id: { | |
type: "Identifier", | |
name: "implements" | |
}, | |
init: null | |
}, { | |
type: "VariableDeclarator", | |
id: { | |
type: "Identifier", | |
name: "interface" | |
}, | |
init: null | |
}, { | |
type: "VariableDeclarator", | |
id: { | |
type: "Identifier", | |
name: "package" | |
}, | |
init: null | |
}], | |
kind: "var" | |
}] | |
}); | |
chk(esprima.parse("var private, protected, public, static"), { | |
type: "Program", | |
body: [{ | |
type: "VariableDeclaration", | |
declarations: [{ | |
type: "VariableDeclarator", | |
id: { | |
type: "Identifier", | |
name: "private" | |
}, | |
init: null | |
}, { | |
type: "VariableDeclarator", | |
id: { | |
type: "Identifier", | |
name: "protected" | |
}, | |
init: null | |
}, { | |
type: "VariableDeclarator", | |
id: { | |
type: "Identifier", | |
name: "public" | |
}, | |
init: null | |
}, { | |
type: "VariableDeclarator", | |
id: { | |
type: "Identifier", | |
name: "static" | |
}, | |
init: null | |
}], | |
kind: "var" | |
}] | |
}); | |
chk(esprima.parse(";"), { | |
type: "Program", | |
body: [{ | |
type: "EmptyStatement" | |
}] | |
}); | |
chk(esprima.parse("x"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "Identifier", | |
name: "x" | |
} | |
}] | |
}); | |
chk(esprima.parse("x, y"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "SequenceExpression", | |
expressions: [{ | |
type: "Identifier", | |
name: "x" | |
}, { | |
type: "Identifier", | |
name: "y" | |
}] | |
} | |
}] | |
}); | |
chk(esprima.parse("\\u0061"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "Identifier", | |
name: "a" | |
} | |
}] | |
}); | |
chk(esprima.parse("a\\u0061"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "Identifier", | |
name: "aa" | |
} | |
}] | |
}); | |
chk(esprima.parse("if (morning) goodMorning()"), { | |
type: "Program", | |
body: [{ | |
type: "IfStatement", | |
test: { | |
type: "Identifier", | |
name: "morning" | |
}, | |
consequent: { | |
type: "ExpressionStatement", | |
expression: { | |
type: "CallExpression", | |
callee: { | |
type: "Identifier", | |
name: "goodMorning" | |
}, | |
arguments: [] | |
} | |
}, | |
alternate: null | |
}] | |
}); | |
chk(esprima.parse("if (morning) (function(){})"), { | |
type: "Program", | |
body: [{ | |
type: "IfStatement", | |
test: { | |
type: "Identifier", | |
name: "morning" | |
}, | |
consequent: { | |
type: "ExpressionStatement", | |
expression: { | |
type: "FunctionExpression", | |
id: null, | |
params: [], | |
defaults: [], | |
body: { | |
type: "BlockStatement", | |
body: [] | |
}, | |
generator: false, | |
expression: false | |
} | |
}, | |
alternate: null | |
}] | |
}); | |
chk(esprima.parse("if (morning) var x = 0;"), { | |
type: "Program", | |
body: [{ | |
type: "IfStatement", | |
test: { | |
type: "Identifier", | |
name: "morning" | |
}, | |
consequent: { | |
type: "VariableDeclaration", | |
declarations: [{ | |
type: "VariableDeclarator", | |
id: { | |
type: "Identifier", | |
name: "x" | |
}, | |
init: { | |
type: "Literal", | |
value: 0, | |
raw: "0" | |
} | |
}], | |
kind: "var" | |
}, | |
alternate: null | |
}] | |
}); | |
chk(esprima.parse("if (morning) function a(){}"), { | |
type: "Program", | |
body: [{ | |
type: "IfStatement", | |
test: { | |
type: "Identifier", | |
name: "morning" | |
}, | |
consequent: { | |
type: "FunctionDeclaration", | |
id: { | |
type: "Identifier", | |
name: "a" | |
}, | |
params: [], | |
defaults: [], | |
body: { | |
type: "BlockStatement", | |
body: [] | |
}, | |
generator: false, | |
expression: false | |
}, | |
alternate: null | |
}] | |
}); | |
chk(esprima.parse("if (morning) goodMorning(); else goodDay()"), { | |
type: "Program", | |
body: [{ | |
type: "IfStatement", | |
test: { | |
type: "Identifier", | |
name: "morning" | |
}, | |
consequent: { | |
type: "ExpressionStatement", | |
expression: { | |
type: "CallExpression", | |
callee: { | |
type: "Identifier", | |
name: "goodMorning" | |
}, | |
arguments: [] | |
} | |
}, | |
alternate: { | |
type: "ExpressionStatement", | |
expression: { | |
type: "CallExpression", | |
callee: { | |
type: "Identifier", | |
name: "goodDay" | |
}, | |
arguments: [] | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("do keep(); while (true)"), { | |
type: "Program", | |
body: [{ | |
type: "DoWhileStatement", | |
body: { | |
type: "ExpressionStatement", | |
expression: { | |
type: "CallExpression", | |
callee: { | |
type: "Identifier", | |
name: "keep" | |
}, | |
arguments: [] | |
} | |
}, | |
test: { | |
type: "Literal", | |
value: true, | |
raw: "true" | |
} | |
}] | |
}); | |
chk(esprima.parse("do keep(); while (true);"), { | |
type: "Program", | |
body: [{ | |
type: "DoWhileStatement", | |
body: { | |
type: "ExpressionStatement", | |
expression: { | |
type: "CallExpression", | |
callee: { | |
type: "Identifier", | |
name: "keep" | |
}, | |
arguments: [] | |
} | |
}, | |
test: { | |
type: "Literal", | |
value: true, | |
raw: "true" | |
} | |
}] | |
}); | |
chk(esprima.parse("do { x++; y--; } while (x < 10)"), { | |
type: "Program", | |
body: [{ | |
type: "DoWhileStatement", | |
body: { | |
type: "BlockStatement", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "UpdateExpression", | |
operator: "++", | |
argument: { | |
type: "Identifier", | |
name: "x" | |
}, | |
prefix: false | |
} | |
}, { | |
type: "ExpressionStatement", | |
expression: { | |
type: "UpdateExpression", | |
operator: "--", | |
argument: { | |
type: "Identifier", | |
name: "y" | |
}, | |
prefix: false | |
} | |
}] | |
}, | |
test: { | |
type: "BinaryExpression", | |
operator: "<", | |
left: { | |
type: "Identifier", | |
name: "x" | |
}, | |
right: { | |
type: "Literal", | |
value: 10, | |
raw: "10" | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("{ do { } while (false);false }"), { | |
type: "Program", | |
body: [{ | |
type: "BlockStatement", | |
body: [{ | |
type: "DoWhileStatement", | |
body: { | |
type: "BlockStatement", | |
body: [] | |
}, | |
test: { | |
type: "Literal", | |
value: false, | |
raw: "false" | |
} | |
}, { | |
type: "ExpressionStatement", | |
expression: { | |
type: "Literal", | |
value: false, | |
raw: "false" | |
} | |
}] | |
}] | |
}); | |
chk(esprima.parse("while (true) doSomething()"), { | |
type: "Program", | |
body: [{ | |
type: "WhileStatement", | |
test: { | |
type: "Literal", | |
value: true, | |
raw: "true" | |
}, | |
body: { | |
type: "ExpressionStatement", | |
expression: { | |
type: "CallExpression", | |
callee: { | |
type: "Identifier", | |
name: "doSomething" | |
}, | |
arguments: [] | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("while (x < 10) { x++; y--; }"), { | |
type: "Program", | |
body: [{ | |
type: "WhileStatement", | |
test: { | |
type: "BinaryExpression", | |
operator: "<", | |
left: { | |
type: "Identifier", | |
name: "x" | |
}, | |
right: { | |
type: "Literal", | |
value: 10, | |
raw: "10" | |
} | |
}, | |
body: { | |
type: "BlockStatement", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "UpdateExpression", | |
operator: "++", | |
argument: { | |
type: "Identifier", | |
name: "x" | |
}, | |
prefix: false | |
} | |
}, { | |
type: "ExpressionStatement", | |
expression: { | |
type: "UpdateExpression", | |
operator: "--", | |
argument: { | |
type: "Identifier", | |
name: "y" | |
}, | |
prefix: false | |
} | |
}] | |
} | |
}] | |
}); | |
chk(esprima.parse("for(;;);"), { | |
type: "Program", | |
body: [{ | |
type: "ForStatement", | |
init: null, | |
test: null, | |
update: null, | |
body: { | |
type: "EmptyStatement" | |
} | |
}] | |
}); | |
chk(esprima.parse("for(;;){}"), { | |
type: "Program", | |
body: [{ | |
type: "ForStatement", | |
init: null, | |
test: null, | |
update: null, | |
body: { | |
type: "BlockStatement", | |
body: [] | |
} | |
}] | |
}); | |
chk(esprima.parse("for(x = 0;;);"), { | |
type: "Program", | |
body: [{ | |
type: "ForStatement", | |
init: { | |
type: "AssignmentExpression", | |
operator: "=", | |
left: { | |
type: "Identifier", | |
name: "x" | |
}, | |
right: { | |
type: "Literal", | |
value: 0, | |
raw: "0" | |
} | |
}, | |
test: null, | |
update: null, | |
body: { | |
type: "EmptyStatement" | |
} | |
}] | |
}); | |
chk(esprima.parse("for(var x = 0;;);"), { | |
type: "Program", | |
body: [{ | |
type: "ForStatement", | |
init: { | |
type: "VariableDeclaration", | |
declarations: [{ | |
type: "VariableDeclarator", | |
id: { | |
type: "Identifier", | |
name: "x" | |
}, | |
init: { | |
type: "Literal", | |
value: 0, | |
raw: "0" | |
} | |
}], | |
kind: "var" | |
}, | |
test: null, | |
update: null, | |
body: { | |
type: "EmptyStatement" | |
} | |
}] | |
}); | |
chk(esprima.parse("for(var x = 0, y = 1;;);"), { | |
type: "Program", | |
body: [{ | |
type: "ForStatement", | |
init: { | |
type: "VariableDeclaration", | |
declarations: [{ | |
type: "VariableDeclarator", | |
id: { | |
type: "Identifier", | |
name: "x" | |
}, | |
init: { | |
type: "Literal", | |
value: 0, | |
raw: "0" | |
} | |
}, { | |
type: "VariableDeclarator", | |
id: { | |
type: "Identifier", | |
name: "y" | |
}, | |
init: { | |
type: "Literal", | |
value: 1, | |
raw: "1" | |
} | |
}], | |
kind: "var" | |
}, | |
test: null, | |
update: null, | |
body: { | |
type: "EmptyStatement" | |
} | |
}] | |
}); | |
chk(esprima.parse("for(x = 0; x < 42;);"), { | |
type: "Program", | |
body: [{ | |
type: "ForStatement", | |
init: { | |
type: "AssignmentExpression", | |
operator: "=", | |
left: { | |
type: "Identifier", | |
name: "x" | |
}, | |
right: { | |
type: "Literal", | |
value: 0, | |
raw: "0" | |
} | |
}, | |
test: { | |
type: "BinaryExpression", | |
operator: "<", | |
left: { | |
type: "Identifier", | |
name: "x" | |
}, | |
right: { | |
type: "Literal", | |
value: 42, | |
raw: "42" | |
} | |
}, | |
update: null, | |
body: { | |
type: "EmptyStatement" | |
} | |
}] | |
}); | |
chk(esprima.parse("for(x = 0; x < 42; x++);"), { | |
type: "Program", | |
body: [{ | |
type: "ForStatement", | |
init: { | |
type: "AssignmentExpression", | |
operator: "=", | |
left: { | |
type: "Identifier", | |
name: "x" | |
}, | |
right: { | |
type: "Literal", | |
value: 0, | |
raw: "0" | |
} | |
}, | |
test: { | |
type: "BinaryExpression", | |
operator: "<", | |
left: { | |
type: "Identifier", | |
name: "x" | |
}, | |
right: { | |
type: "Literal", | |
value: 42, | |
raw: "42" | |
} | |
}, | |
update: { | |
type: "UpdateExpression", | |
operator: "++", | |
argument: { | |
type: "Identifier", | |
name: "x" | |
}, | |
prefix: false | |
}, | |
body: { | |
type: "EmptyStatement" | |
} | |
}] | |
}); | |
chk(esprima.parse("for(x = 0; x < 42; x++) process(x);"), { | |
type: "Program", | |
body: [{ | |
type: "ForStatement", | |
init: { | |
type: "AssignmentExpression", | |
operator: "=", | |
left: { | |
type: "Identifier", | |
name: "x" | |
}, | |
right: { | |
type: "Literal", | |
value: 0, | |
raw: "0" | |
} | |
}, | |
test: { | |
type: "BinaryExpression", | |
operator: "<", | |
left: { | |
type: "Identifier", | |
name: "x" | |
}, | |
right: { | |
type: "Literal", | |
value: 42, | |
raw: "42" | |
} | |
}, | |
update: { | |
type: "UpdateExpression", | |
operator: "++", | |
argument: { | |
type: "Identifier", | |
name: "x" | |
}, | |
prefix: false | |
}, | |
body: { | |
type: "ExpressionStatement", | |
expression: { | |
type: "CallExpression", | |
callee: { | |
type: "Identifier", | |
name: "process" | |
}, | |
arguments: [{ | |
type: "Identifier", | |
name: "x" | |
}] | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("for(x in list) process(x);"), { | |
type: "Program", | |
body: [{ | |
type: "ForInStatement", | |
left: { | |
type: "Identifier", | |
name: "x" | |
}, | |
right: { | |
type: "Identifier", | |
name: "list" | |
}, | |
body: { | |
type: "ExpressionStatement", | |
expression: { | |
type: "CallExpression", | |
callee: { | |
type: "Identifier", | |
name: "process" | |
}, | |
arguments: [{ | |
type: "Identifier", | |
name: "x" | |
}] | |
} | |
}, | |
each: false | |
}] | |
}); | |
chk(esprima.parse("for (var x in list) process(x);"), { | |
type: "Program", | |
body: [{ | |
type: "ForInStatement", | |
left: { | |
type: "VariableDeclaration", | |
declarations: [{ | |
type: "VariableDeclarator", | |
id: { | |
type: "Identifier", | |
name: "x" | |
}, | |
init: null | |
}], | |
kind: "var" | |
}, | |
right: { | |
type: "Identifier", | |
name: "list" | |
}, | |
body: { | |
type: "ExpressionStatement", | |
expression: { | |
type: "CallExpression", | |
callee: { | |
type: "Identifier", | |
name: "process" | |
}, | |
arguments: [{ | |
type: "Identifier", | |
name: "x" | |
}] | |
} | |
}, | |
each: false | |
}] | |
}); | |
chk(esprima.parse("for (var x = 42 in list) process(x);"), { | |
type: "Program", | |
body: [{ | |
type: "ForInStatement", | |
left: { | |
type: "VariableDeclaration", | |
declarations: [{ | |
type: "VariableDeclarator", | |
id: { | |
type: "Identifier", | |
name: "x" | |
}, | |
init: { | |
type: "Literal", | |
value: 42, | |
raw: "42" | |
} | |
}], | |
kind: "var" | |
}, | |
right: { | |
type: "Identifier", | |
name: "list" | |
}, | |
body: { | |
type: "ExpressionStatement", | |
expression: { | |
type: "CallExpression", | |
callee: { | |
type: "Identifier", | |
name: "process" | |
}, | |
arguments: [{ | |
type: "Identifier", | |
name: "x" | |
}] | |
} | |
}, | |
each: false | |
}] | |
}); | |
chk(esprima.parse("for (var i = function() { return 10 in [] } in list) process(x);"), { | |
type: "Program", | |
body: [{ | |
type: "ForInStatement", | |
left: { | |
type: "VariableDeclaration", | |
declarations: [{ | |
type: "VariableDeclarator", | |
id: { | |
type: "Identifier", | |
name: "i" | |
}, | |
init: { | |
type: "FunctionExpression", | |
id: null, | |
params: [], | |
defaults: [], | |
body: { | |
type: "BlockStatement", | |
body: [{ | |
type: "ReturnStatement", | |
argument: { | |
type: "BinaryExpression", | |
operator: "in", | |
left: { | |
type: "Literal", | |
value: 10, | |
raw: "10" | |
}, | |
right: { | |
type: "ArrayExpression", | |
elements: [] | |
} | |
} | |
}] | |
}, | |
generator: false, | |
expression: false | |
} | |
}], | |
kind: "var" | |
}, | |
right: { | |
type: "Identifier", | |
name: "list" | |
}, | |
body: { | |
type: "ExpressionStatement", | |
expression: { | |
type: "CallExpression", | |
callee: { | |
type: "Identifier", | |
name: "process" | |
}, | |
arguments: [{ | |
type: "Identifier", | |
name: "x" | |
}] | |
} | |
}, | |
each: false | |
}] | |
}); | |
chk(esprima.parse("while (true) { continue; }"), { | |
type: "Program", | |
body: [{ | |
type: "WhileStatement", | |
test: { | |
type: "Literal", | |
value: true, | |
raw: "true" | |
}, | |
body: { | |
type: "BlockStatement", | |
body: [{ | |
type: "ContinueStatement", | |
label: null | |
}] | |
} | |
}] | |
}); | |
chk(esprima.parse("while (true) { continue }"), { | |
type: "Program", | |
body: [{ | |
type: "WhileStatement", | |
test: { | |
type: "Literal", | |
value: true, | |
raw: "true" | |
}, | |
body: { | |
type: "BlockStatement", | |
body: [{ | |
type: "ContinueStatement", | |
label: null | |
}] | |
} | |
}] | |
}); | |
chk(esprima.parse("done: while (true) { continue done }"), { | |
type: "Program", | |
body: [{ | |
type: "LabeledStatement", | |
label: { | |
type: "Identifier", | |
name: "done" | |
}, | |
body: { | |
type: "WhileStatement", | |
test: { | |
type: "Literal", | |
value: true, | |
raw: "true" | |
}, | |
body: { | |
type: "BlockStatement", | |
body: [{ | |
type: "ContinueStatement", | |
label: { | |
type: "Identifier", | |
name: "done" | |
} | |
}] | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("done: while (true) { continue done; }"), { | |
type: "Program", | |
body: [{ | |
type: "LabeledStatement", | |
label: { | |
type: "Identifier", | |
name: "done" | |
}, | |
body: { | |
type: "WhileStatement", | |
test: { | |
type: "Literal", | |
value: true, | |
raw: "true" | |
}, | |
body: { | |
type: "BlockStatement", | |
body: [{ | |
type: "ContinueStatement", | |
label: { | |
type: "Identifier", | |
name: "done" | |
} | |
}] | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("while (true) { break }"), { | |
type: "Program", | |
body: [{ | |
type: "WhileStatement", | |
test: { | |
type: "Literal", | |
value: true, | |
raw: "true" | |
}, | |
body: { | |
type: "BlockStatement", | |
body: [{ | |
type: "BreakStatement", | |
label: null | |
}] | |
} | |
}] | |
}); | |
chk(esprima.parse("done: while (true) { break done }"), { | |
type: "Program", | |
body: [{ | |
type: "LabeledStatement", | |
label: { | |
type: "Identifier", | |
name: "done" | |
}, | |
body: { | |
type: "WhileStatement", | |
test: { | |
type: "Literal", | |
value: true, | |
raw: "true" | |
}, | |
body: { | |
type: "BlockStatement", | |
body: [{ | |
type: "BreakStatement", | |
label: { | |
type: "Identifier", | |
name: "done" | |
} | |
}] | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("done: while (true) { break done; }"), { | |
type: "Program", | |
body: [{ | |
type: "LabeledStatement", | |
label: { | |
type: "Identifier", | |
name: "done" | |
}, | |
body: { | |
type: "WhileStatement", | |
test: { | |
type: "Literal", | |
value: true, | |
raw: "true" | |
}, | |
body: { | |
type: "BlockStatement", | |
body: [{ | |
type: "BreakStatement", | |
label: { | |
type: "Identifier", | |
name: "done" | |
} | |
}] | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("(function(){ return })"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "FunctionExpression", | |
id: null, | |
params: [], | |
defaults: [], | |
body: { | |
type: "BlockStatement", | |
body: [{ | |
type: "ReturnStatement", | |
argument: null | |
}] | |
}, | |
generator: false, | |
expression: false | |
} | |
}] | |
}); | |
chk(esprima.parse("(function(){ return; })"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "FunctionExpression", | |
id: null, | |
params: [], | |
defaults: [], | |
body: { | |
type: "BlockStatement", | |
body: [{ | |
type: "ReturnStatement", | |
argument: null | |
}] | |
}, | |
generator: false, | |
expression: false | |
} | |
}] | |
}); | |
chk(esprima.parse("(function(){ return x; })"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "FunctionExpression", | |
id: null, | |
params: [], | |
defaults: [], | |
body: { | |
type: "BlockStatement", | |
body: [{ | |
type: "ReturnStatement", | |
argument: { | |
type: "Identifier", | |
name: "x" | |
} | |
}] | |
}, | |
generator: false, | |
expression: false | |
} | |
}] | |
}); | |
chk(esprima.parse("(function(){ return x * y })"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "FunctionExpression", | |
id: null, | |
params: [], | |
defaults: [], | |
body: { | |
type: "BlockStatement", | |
body: [{ | |
type: "ReturnStatement", | |
argument: { | |
type: "BinaryExpression", | |
operator: "*", | |
left: { | |
type: "Identifier", | |
name: "x" | |
}, | |
right: { | |
type: "Identifier", | |
name: "y" | |
} | |
} | |
}] | |
}, | |
generator: false, | |
expression: false | |
} | |
}] | |
}); | |
chk(esprima.parse("with (x) foo = bar"), { | |
type: "Program", | |
body: [{ | |
type: "WithStatement", | |
object: { | |
type: "Identifier", | |
name: "x" | |
}, | |
body: { | |
type: "ExpressionStatement", | |
expression: { | |
type: "AssignmentExpression", | |
operator: "=", | |
left: { | |
type: "Identifier", | |
name: "foo" | |
}, | |
right: { | |
type: "Identifier", | |
name: "bar" | |
} | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("with (x) foo = bar;"), { | |
type: "Program", | |
body: [{ | |
type: "WithStatement", | |
object: { | |
type: "Identifier", | |
name: "x" | |
}, | |
body: { | |
type: "ExpressionStatement", | |
expression: { | |
type: "AssignmentExpression", | |
operator: "=", | |
left: { | |
type: "Identifier", | |
name: "foo" | |
}, | |
right: { | |
type: "Identifier", | |
name: "bar" | |
} | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("with (x) { foo = bar }"), { | |
type: "Program", | |
body: [{ | |
type: "WithStatement", | |
object: { | |
type: "Identifier", | |
name: "x" | |
}, | |
body: { | |
type: "BlockStatement", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "AssignmentExpression", | |
operator: "=", | |
left: { | |
type: "Identifier", | |
name: "foo" | |
}, | |
right: { | |
type: "Identifier", | |
name: "bar" | |
} | |
} | |
}] | |
} | |
}] | |
}); | |
chk(esprima.parse("switch (x) {}"), { | |
type: "Program", | |
body: [{ | |
type: "SwitchStatement", | |
discriminant: { | |
type: "Identifier", | |
name: "x" | |
}, | |
cases: [] | |
}] | |
}); | |
chk(esprima.parse("switch (answer) { case 42: hi(); break; }"), { | |
type: "Program", | |
body: [{ | |
type: "SwitchStatement", | |
discriminant: { | |
type: "Identifier", | |
name: "answer" | |
}, | |
cases: [{ | |
type: "SwitchCase", | |
test: { | |
type: "Literal", | |
value: 42, | |
raw: "42" | |
}, | |
consequent: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "CallExpression", | |
callee: { | |
type: "Identifier", | |
name: "hi" | |
}, | |
arguments: [] | |
} | |
}, { | |
type: "BreakStatement", | |
label: null | |
}] | |
}] | |
}] | |
}); | |
chk(esprima.parse("switch (answer) { case 42: hi(); break; default: break }"), { | |
type: "Program", | |
body: [{ | |
type: "SwitchStatement", | |
discriminant: { | |
type: "Identifier", | |
name: "answer" | |
}, | |
cases: [{ | |
type: "SwitchCase", | |
test: { | |
type: "Literal", | |
value: 42, | |
raw: "42" | |
}, | |
consequent: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "CallExpression", | |
callee: { | |
type: "Identifier", | |
name: "hi" | |
}, | |
arguments: [] | |
} | |
}, { | |
type: "BreakStatement", | |
label: null | |
}] | |
}, { | |
type: "SwitchCase", | |
test: null, | |
consequent: [{ | |
type: "BreakStatement", | |
label: null | |
}] | |
}] | |
}] | |
}); | |
chk(esprima.parse("start: for (;;) break start"), { | |
type: "Program", | |
body: [{ | |
type: "LabeledStatement", | |
label: { | |
type: "Identifier", | |
name: "start" | |
}, | |
body: { | |
type: "ForStatement", | |
init: null, | |
test: null, | |
update: null, | |
body: { | |
type: "BreakStatement", | |
label: { | |
type: "Identifier", | |
name: "start" | |
} | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("start: while (true) break start"), { | |
type: "Program", | |
body: [{ | |
type: "LabeledStatement", | |
label: { | |
type: "Identifier", | |
name: "start" | |
}, | |
body: { | |
type: "WhileStatement", | |
test: { | |
type: "Literal", | |
value: true, | |
raw: "true" | |
}, | |
body: { | |
type: "BreakStatement", | |
label: { | |
type: "Identifier", | |
name: "start" | |
} | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("throw x;"), { | |
type: "Program", | |
body: [{ | |
type: "ThrowStatement", | |
argument: { | |
type: "Identifier", | |
name: "x" | |
} | |
}] | |
}); | |
chk(esprima.parse("throw x * y"), { | |
type: "Program", | |
body: [{ | |
type: "ThrowStatement", | |
argument: { | |
type: "BinaryExpression", | |
operator: "*", | |
left: { | |
type: "Identifier", | |
name: "x" | |
}, | |
right: { | |
type: "Identifier", | |
name: "y" | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("throw { message: \"Error\" }"), { | |
type: "Program", | |
body: [{ | |
type: "ThrowStatement", | |
argument: { | |
type: "ObjectExpression", | |
properties: [{ | |
type: "Property", | |
key: { | |
type: "Identifier", | |
name: "message" | |
}, | |
computed: false, | |
value: { | |
type: "Literal", | |
value: "Error", | |
raw: "\"Error\"" | |
}, | |
kind: "init", | |
method: false, | |
shorthand: false | |
}] | |
} | |
}] | |
}); | |
chk(esprima.parse("try { } catch (e) { }"), { | |
type: "Program", | |
body: [{ | |
type: "TryStatement", | |
block: { | |
type: "BlockStatement", | |
body: [] | |
}, | |
guardedHandlers: [], | |
handlers: [{ | |
type: "CatchClause", | |
param: { | |
type: "Identifier", | |
name: "e" | |
}, | |
body: { | |
type: "BlockStatement", | |
body: [] | |
} | |
}], | |
handler: { | |
type: "CatchClause", | |
param: { | |
type: "Identifier", | |
name: "e" | |
}, | |
body: { | |
type: "BlockStatement", | |
body: [] | |
} | |
}, | |
finalizer: null | |
}] | |
}); | |
chk(esprima.parse("try { } catch (eval) { }"), { | |
type: "Program", | |
body: [{ | |
type: "TryStatement", | |
block: { | |
type: "BlockStatement", | |
body: [] | |
}, | |
guardedHandlers: [], | |
handlers: [{ | |
type: "CatchClause", | |
param: { | |
type: "Identifier", | |
name: "eval" | |
}, | |
body: { | |
type: "BlockStatement", | |
body: [] | |
} | |
}], | |
handler: { | |
type: "CatchClause", | |
param: { | |
type: "Identifier", | |
name: "eval" | |
}, | |
body: { | |
type: "BlockStatement", | |
body: [] | |
} | |
}, | |
finalizer: null | |
}] | |
}); | |
chk(esprima.parse("try { } catch (arguments) { }"), { | |
type: "Program", | |
body: [{ | |
type: "TryStatement", | |
block: { | |
type: "BlockStatement", | |
body: [] | |
}, | |
guardedHandlers: [], | |
handlers: [{ | |
type: "CatchClause", | |
param: { | |
type: "Identifier", | |
name: "arguments" | |
}, | |
body: { | |
type: "BlockStatement", | |
body: [] | |
} | |
}], | |
handler: { | |
type: "CatchClause", | |
param: { | |
type: "Identifier", | |
name: "arguments" | |
}, | |
body: { | |
type: "BlockStatement", | |
body: [] | |
} | |
}, | |
finalizer: null | |
}] | |
}); | |
chk(esprima.parse("try { } catch (e) { say(e) }"), { | |
type: "Program", | |
body: [{ | |
type: "TryStatement", | |
block: { | |
type: "BlockStatement", | |
body: [] | |
}, | |
guardedHandlers: [], | |
handlers: [{ | |
type: "CatchClause", | |
param: { | |
type: "Identifier", | |
name: "e" | |
}, | |
body: { | |
type: "BlockStatement", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "CallExpression", | |
callee: { | |
type: "Identifier", | |
name: "say" | |
}, | |
arguments: [{ | |
type: "Identifier", | |
name: "e" | |
}] | |
} | |
}] | |
} | |
}], | |
handler: { | |
type: "CatchClause", | |
param: { | |
type: "Identifier", | |
name: "e" | |
}, | |
body: { | |
type: "BlockStatement", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "CallExpression", | |
callee: { | |
type: "Identifier", | |
name: "say" | |
}, | |
arguments: [{ | |
type: "Identifier", | |
name: "e" | |
}] | |
} | |
}] | |
} | |
}, | |
finalizer: null | |
}] | |
}); | |
chk(esprima.parse("try { } finally { cleanup(stuff) }"), { | |
type: "Program", | |
body: [{ | |
type: "TryStatement", | |
block: { | |
type: "BlockStatement", | |
body: [] | |
}, | |
guardedHandlers: [], | |
handlers: [], | |
handler: null, | |
finalizer: { | |
type: "BlockStatement", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "CallExpression", | |
callee: { | |
type: "Identifier", | |
name: "cleanup" | |
}, | |
arguments: [{ | |
type: "Identifier", | |
name: "stuff" | |
}] | |
} | |
}] | |
} | |
}] | |
}); | |
chk(esprima.parse("try { doThat(); } catch (e) { say(e) }"), { | |
type: "Program", | |
body: [{ | |
type: "TryStatement", | |
block: { | |
type: "BlockStatement", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "CallExpression", | |
callee: { | |
type: "Identifier", | |
name: "doThat" | |
}, | |
arguments: [] | |
} | |
}] | |
}, | |
guardedHandlers: [], | |
handlers: [{ | |
type: "CatchClause", | |
param: { | |
type: "Identifier", | |
name: "e" | |
}, | |
body: { | |
type: "BlockStatement", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "CallExpression", | |
callee: { | |
type: "Identifier", | |
name: "say" | |
}, | |
arguments: [{ | |
type: "Identifier", | |
name: "e" | |
}] | |
} | |
}] | |
} | |
}], | |
handler: { | |
type: "CatchClause", | |
param: { | |
type: "Identifier", | |
name: "e" | |
}, | |
body: { | |
type: "BlockStatement", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "CallExpression", | |
callee: { | |
type: "Identifier", | |
name: "say" | |
}, | |
arguments: [{ | |
type: "Identifier", | |
name: "e" | |
}] | |
} | |
}] | |
} | |
}, | |
finalizer: null | |
}] | |
}); | |
chk(esprima.parse("try { doThat(); } catch (e) { say(e) } finally { cleanup(stuff) }"), { | |
type: "Program", | |
body: [{ | |
type: "TryStatement", | |
block: { | |
type: "BlockStatement", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "CallExpression", | |
callee: { | |
type: "Identifier", | |
name: "doThat" | |
}, | |
arguments: [] | |
} | |
}] | |
}, | |
guardedHandlers: [], | |
handlers: [{ | |
type: "CatchClause", | |
param: { | |
type: "Identifier", | |
name: "e" | |
}, | |
body: { | |
type: "BlockStatement", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "CallExpression", | |
callee: { | |
type: "Identifier", | |
name: "say" | |
}, | |
arguments: [{ | |
type: "Identifier", | |
name: "e" | |
}] | |
} | |
}] | |
} | |
}], | |
handler: { | |
type: "CatchClause", | |
param: { | |
type: "Identifier", | |
name: "e" | |
}, | |
body: { | |
type: "BlockStatement", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "CallExpression", | |
callee: { | |
type: "Identifier", | |
name: "say" | |
}, | |
arguments: [{ | |
type: "Identifier", | |
name: "e" | |
}] | |
} | |
}] | |
} | |
}, | |
finalizer: { | |
type: "BlockStatement", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "CallExpression", | |
callee: { | |
type: "Identifier", | |
name: "cleanup" | |
}, | |
arguments: [{ | |
type: "Identifier", | |
name: "stuff" | |
}] | |
} | |
}] | |
} | |
}] | |
}); | |
chk(esprima.parse("debugger;"), { | |
type: "Program", | |
body: [{ | |
type: "DebuggerStatement" | |
}] | |
}); | |
chk(esprima.parse("function hello() { sayHi(); }"), { | |
type: "Program", | |
body: [{ | |
type: "FunctionDeclaration", | |
id: { | |
type: "Identifier", | |
name: "hello" | |
}, | |
params: [], | |
defaults: [], | |
body: { | |
type: "BlockStatement", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "CallExpression", | |
callee: { | |
type: "Identifier", | |
name: "sayHi" | |
}, | |
arguments: [] | |
} | |
}] | |
}, | |
generator: false, | |
expression: false | |
}] | |
}); | |
chk(esprima.parse("function eval() { }"), { | |
type: "Program", | |
body: [{ | |
type: "FunctionDeclaration", | |
id: { | |
type: "Identifier", | |
name: "eval" | |
}, | |
params: [], | |
defaults: [], | |
body: { | |
type: "BlockStatement", | |
body: [] | |
}, | |
generator: false, | |
expression: false | |
}] | |
}); | |
chk(esprima.parse("function arguments() { }"), { | |
type: "Program", | |
body: [{ | |
type: "FunctionDeclaration", | |
id: { | |
type: "Identifier", | |
name: "arguments" | |
}, | |
params: [], | |
defaults: [], | |
body: { | |
type: "BlockStatement", | |
body: [] | |
}, | |
generator: false, | |
expression: false | |
}] | |
}); | |
chk(esprima.parse("function test(t, t) { }"), { | |
type: "Program", | |
body: [{ | |
type: "FunctionDeclaration", | |
id: { | |
type: "Identifier", | |
name: "test" | |
}, | |
params: [{ | |
type: "Identifier", | |
name: "t" | |
}, { | |
type: "Identifier", | |
name: "t" | |
}], | |
defaults: [], | |
body: { | |
type: "BlockStatement", | |
body: [] | |
}, | |
generator: false, | |
expression: false | |
}] | |
}); | |
chk(esprima.parse("(function test(t, t) { })"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "FunctionExpression", | |
id: { | |
type: "Identifier", | |
name: "test" | |
}, | |
params: [{ | |
type: "Identifier", | |
name: "t" | |
}, { | |
type: "Identifier", | |
name: "t" | |
}], | |
defaults: [], | |
body: { | |
type: "BlockStatement", | |
body: [] | |
}, | |
generator: false, | |
expression: false | |
} | |
}] | |
}); | |
chk(esprima.parse("function eval() { function inner() { \"use strict\" } }"), { | |
type: "Program", | |
body: [{ | |
type: "FunctionDeclaration", | |
id: { | |
type: "Identifier", | |
name: "eval" | |
}, | |
params: [], | |
defaults: [], | |
body: { | |
type: "BlockStatement", | |
body: [{ | |
type: "FunctionDeclaration", | |
id: { | |
type: "Identifier", | |
name: "inner" | |
}, | |
params: [], | |
defaults: [], | |
body: { | |
type: "BlockStatement", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "Literal", | |
value: "use strict", | |
raw: "\"use strict\"" | |
} | |
}] | |
}, | |
generator: false, | |
expression: false | |
}] | |
}, | |
generator: false, | |
expression: false | |
}] | |
}); | |
chk(esprima.parse("function hello(a) { sayHi(); }"), { | |
type: "Program", | |
body: [{ | |
type: "FunctionDeclaration", | |
id: { | |
type: "Identifier", | |
name: "hello" | |
}, | |
params: [{ | |
type: "Identifier", | |
name: "a" | |
}], | |
defaults: [], | |
body: { | |
type: "BlockStatement", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "CallExpression", | |
callee: { | |
type: "Identifier", | |
name: "sayHi" | |
}, | |
arguments: [] | |
} | |
}] | |
}, | |
generator: false, | |
expression: false | |
}] | |
}); | |
chk(esprima.parse("function hello(a, b) { sayHi(); }"), { | |
type: "Program", | |
body: [{ | |
type: "FunctionDeclaration", | |
id: { | |
type: "Identifier", | |
name: "hello" | |
}, | |
params: [{ | |
type: "Identifier", | |
name: "a" | |
}, { | |
type: "Identifier", | |
name: "b" | |
}], | |
defaults: [], | |
body: { | |
type: "BlockStatement", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "CallExpression", | |
callee: { | |
type: "Identifier", | |
name: "sayHi" | |
}, | |
arguments: [] | |
} | |
}] | |
}, | |
generator: false, | |
expression: false | |
}] | |
}); | |
chk(esprima.parse("function hello(...rest) { }"), { | |
type: "Program", | |
body: [{ | |
type: "FunctionDeclaration", | |
id: { | |
type: "Identifier", | |
name: "hello" | |
}, | |
params: [{ | |
type: "RestElement", | |
argument: { | |
type: "Identifier", | |
name: "rest" | |
} | |
}], | |
defaults: [], | |
body: { | |
type: "BlockStatement", | |
body: [] | |
}, | |
generator: false, | |
expression: false | |
}] | |
}); | |
chk(esprima.parse("function hello(a, ...rest) { }"), { | |
type: "Program", | |
body: [{ | |
type: "FunctionDeclaration", | |
id: { | |
type: "Identifier", | |
name: "hello" | |
}, | |
params: [{ | |
type: "Identifier", | |
name: "a" | |
}, { | |
type: "RestElement", | |
argument: { | |
type: "Identifier", | |
name: "rest" | |
} | |
}], | |
defaults: [], | |
body: { | |
type: "BlockStatement", | |
body: [] | |
}, | |
generator: false, | |
expression: false | |
}] | |
}); | |
chk(esprima.parse("var hi = function() { sayHi() };"), { | |
type: "Program", | |
body: [{ | |
type: "VariableDeclaration", | |
declarations: [{ | |
type: "VariableDeclarator", | |
id: { | |
type: "Identifier", | |
name: "hi" | |
}, | |
init: { | |
type: "FunctionExpression", | |
id: null, | |
params: [], | |
defaults: [], | |
body: { | |
type: "BlockStatement", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "CallExpression", | |
callee: { | |
type: "Identifier", | |
name: "sayHi" | |
}, | |
arguments: [] | |
} | |
}] | |
}, | |
generator: false, | |
expression: false | |
} | |
}], | |
kind: "var" | |
}] | |
}); | |
chk(esprima.parse("var hi = function (...r) { sayHi() };"), { | |
type: "Program", | |
body: [{ | |
type: "VariableDeclaration", | |
declarations: [{ | |
type: "VariableDeclarator", | |
id: { | |
type: "Identifier", | |
name: "hi" | |
}, | |
init: { | |
type: "FunctionExpression", | |
id: null, | |
params: [{ | |
type: "RestElement", | |
argument: { | |
type: "Identifier", | |
name: "r" | |
} | |
}], | |
defaults: [], | |
body: { | |
type: "BlockStatement", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "CallExpression", | |
callee: { | |
type: "Identifier", | |
name: "sayHi" | |
}, | |
arguments: [] | |
} | |
}] | |
}, | |
generator: false, | |
expression: false | |
} | |
}], | |
kind: "var" | |
}] | |
}); | |
chk(esprima.parse("var hi = function eval() { };"), { | |
type: "Program", | |
body: [{ | |
type: "VariableDeclaration", | |
declarations: [{ | |
type: "VariableDeclarator", | |
id: { | |
type: "Identifier", | |
name: "hi" | |
}, | |
init: { | |
type: "FunctionExpression", | |
id: { | |
type: "Identifier", | |
name: "eval" | |
}, | |
params: [], | |
defaults: [], | |
body: { | |
type: "BlockStatement", | |
body: [] | |
}, | |
generator: false, | |
expression: false | |
} | |
}], | |
kind: "var" | |
}] | |
}); | |
chk(esprima.parse("var hi = function arguments() { };"), { | |
type: "Program", | |
body: [{ | |
type: "VariableDeclaration", | |
declarations: [{ | |
type: "VariableDeclarator", | |
id: { | |
type: "Identifier", | |
name: "hi" | |
}, | |
init: { | |
type: "FunctionExpression", | |
id: { | |
type: "Identifier", | |
name: "arguments" | |
}, | |
params: [], | |
defaults: [], | |
body: { | |
type: "BlockStatement", | |
body: [] | |
}, | |
generator: false, | |
expression: false | |
} | |
}], | |
kind: "var" | |
}] | |
}); | |
chk(esprima.parse("var hello = function hi() { sayHi() };"), { | |
type: "Program", | |
body: [{ | |
type: "VariableDeclaration", | |
declarations: [{ | |
type: "VariableDeclarator", | |
id: { | |
type: "Identifier", | |
name: "hello" | |
}, | |
init: { | |
type: "FunctionExpression", | |
id: { | |
type: "Identifier", | |
name: "hi" | |
}, | |
params: [], | |
defaults: [], | |
body: { | |
type: "BlockStatement", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "CallExpression", | |
callee: { | |
type: "Identifier", | |
name: "sayHi" | |
}, | |
arguments: [] | |
} | |
}] | |
}, | |
generator: false, | |
expression: false | |
} | |
}], | |
kind: "var" | |
}] | |
}); | |
chk(esprima.parse("(function(){})"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "FunctionExpression", | |
id: null, | |
params: [], | |
defaults: [], | |
body: { | |
type: "BlockStatement", | |
body: [] | |
}, | |
generator: false, | |
expression: false | |
} | |
}] | |
}); | |
chk(esprima.parse("{ x\n++y }"), { | |
type: "Program", | |
body: [{ | |
type: "BlockStatement", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "Identifier", | |
name: "x" | |
} | |
}, { | |
type: "ExpressionStatement", | |
expression: { | |
type: "UpdateExpression", | |
operator: "++", | |
argument: { | |
type: "Identifier", | |
name: "y" | |
}, | |
prefix: true | |
} | |
}] | |
}] | |
}); | |
chk(esprima.parse("{ x\n--y }"), { | |
type: "Program", | |
body: [{ | |
type: "BlockStatement", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "Identifier", | |
name: "x" | |
} | |
}, { | |
type: "ExpressionStatement", | |
expression: { | |
type: "UpdateExpression", | |
operator: "--", | |
argument: { | |
type: "Identifier", | |
name: "y" | |
}, | |
prefix: true | |
} | |
}] | |
}] | |
}); | |
chk(esprima.parse("var x /* comment */;"), { | |
type: "Program", | |
body: [{ | |
type: "VariableDeclaration", | |
declarations: [{ | |
type: "VariableDeclarator", | |
id: { | |
type: "Identifier", | |
name: "x" | |
}, | |
init: null | |
}], | |
kind: "var" | |
}] | |
}); | |
chk(esprima.parse("{ var x = 14, y = 3\nz; }"), { | |
type: "Program", | |
body: [{ | |
type: "BlockStatement", | |
body: [{ | |
type: "VariableDeclaration", | |
declarations: [{ | |
type: "VariableDeclarator", | |
id: { | |
type: "Identifier", | |
name: "x" | |
}, | |
init: { | |
type: "Literal", | |
value: 14, | |
raw: "14" | |
} | |
}, { | |
type: "VariableDeclarator", | |
id: { | |
type: "Identifier", | |
name: "y" | |
}, | |
init: { | |
type: "Literal", | |
value: 3, | |
raw: "3" | |
} | |
}], | |
kind: "var" | |
}, { | |
type: "ExpressionStatement", | |
expression: { | |
type: "Identifier", | |
name: "z" | |
} | |
}] | |
}] | |
}); | |
chk(esprima.parse("while (true) { continue\nthere; }"), { | |
type: "Program", | |
body: [{ | |
type: "WhileStatement", | |
test: { | |
type: "Literal", | |
value: true, | |
raw: "true" | |
}, | |
body: { | |
type: "BlockStatement", | |
body: [{ | |
type: "ContinueStatement", | |
label: null | |
}, { | |
type: "ExpressionStatement", | |
expression: { | |
type: "Identifier", | |
name: "there" | |
} | |
}] | |
} | |
}] | |
}); | |
chk(esprima.parse("while (true) { continue // Comment\nthere; }"), { | |
type: "Program", | |
body: [{ | |
type: "WhileStatement", | |
test: { | |
type: "Literal", | |
value: true, | |
raw: "true" | |
}, | |
body: { | |
type: "BlockStatement", | |
body: [{ | |
type: "ContinueStatement", | |
label: null | |
}, { | |
type: "ExpressionStatement", | |
expression: { | |
type: "Identifier", | |
name: "there" | |
} | |
}] | |
} | |
}] | |
}); | |
chk(esprima.parse("while (true) { continue /* Multiline\nComment */there; }"), { | |
type: "Program", | |
body: [{ | |
type: "WhileStatement", | |
test: { | |
type: "Literal", | |
value: true, | |
raw: "true" | |
}, | |
body: { | |
type: "BlockStatement", | |
body: [{ | |
type: "ContinueStatement", | |
label: null | |
}, { | |
type: "ExpressionStatement", | |
expression: { | |
type: "Identifier", | |
name: "there" | |
} | |
}] | |
} | |
}] | |
}); | |
chk(esprima.parse("while (true) { break\nthere; }"), { | |
type: "Program", | |
body: [{ | |
type: "WhileStatement", | |
test: { | |
type: "Literal", | |
value: true, | |
raw: "true" | |
}, | |
body: { | |
type: "BlockStatement", | |
body: [{ | |
type: "BreakStatement", | |
label: null | |
}, { | |
type: "ExpressionStatement", | |
expression: { | |
type: "Identifier", | |
name: "there" | |
} | |
}] | |
} | |
}] | |
}); | |
chk(esprima.parse("while (true) { break // Comment\nthere; }"), { | |
type: "Program", | |
body: [{ | |
type: "WhileStatement", | |
test: { | |
type: "Literal", | |
value: true, | |
raw: "true" | |
}, | |
body: { | |
type: "BlockStatement", | |
body: [{ | |
type: "BreakStatement", | |
label: null | |
}, { | |
type: "ExpressionStatement", | |
expression: { | |
type: "Identifier", | |
name: "there" | |
} | |
}] | |
} | |
}] | |
}); | |
chk(esprima.parse("while (true) { break /* Multiline\nComment */there; }"), { | |
type: "Program", | |
body: [{ | |
type: "WhileStatement", | |
test: { | |
type: "Literal", | |
value: true, | |
raw: "true" | |
}, | |
body: { | |
type: "BlockStatement", | |
body: [{ | |
type: "BreakStatement", | |
label: null | |
}, { | |
type: "ExpressionStatement", | |
expression: { | |
type: "Identifier", | |
name: "there" | |
} | |
}] | |
} | |
}] | |
}); | |
chk(esprima.parse("(function(){ return\nx; })"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "FunctionExpression", | |
id: null, | |
params: [], | |
defaults: [], | |
body: { | |
type: "BlockStatement", | |
body: [{ | |
type: "ReturnStatement", | |
argument: null | |
}, { | |
type: "ExpressionStatement", | |
expression: { | |
type: "Identifier", | |
name: "x" | |
} | |
}] | |
}, | |
generator: false, | |
expression: false | |
} | |
}] | |
}); | |
chk(esprima.parse("(function(){ return // Comment\nx; })"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "FunctionExpression", | |
id: null, | |
params: [], | |
defaults: [], | |
body: { | |
type: "BlockStatement", | |
body: [{ | |
type: "ReturnStatement", | |
argument: null | |
}, { | |
type: "ExpressionStatement", | |
expression: { | |
type: "Identifier", | |
name: "x" | |
} | |
}] | |
}, | |
generator: false, | |
expression: false | |
} | |
}] | |
}); | |
chk(esprima.parse("(function(){ return/* Multiline\nComment */x; })"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "FunctionExpression", | |
id: null, | |
params: [], | |
defaults: [], | |
body: { | |
type: "BlockStatement", | |
body: [{ | |
type: "ReturnStatement", | |
argument: null | |
}, { | |
type: "ExpressionStatement", | |
expression: { | |
type: "Identifier", | |
name: "x" | |
} | |
}] | |
}, | |
generator: false, | |
expression: false | |
} | |
}] | |
}); | |
chk(esprima.parse("{ throw error\nerror; }"), { | |
type: "Program", | |
body: [{ | |
type: "BlockStatement", | |
body: [{ | |
type: "ThrowStatement", | |
argument: { | |
type: "Identifier", | |
name: "error" | |
} | |
}, { | |
type: "ExpressionStatement", | |
expression: { | |
type: "Identifier", | |
name: "error" | |
} | |
}] | |
}] | |
}); | |
chk(esprima.parse("{ throw error// Comment\nerror; }"), { | |
type: "Program", | |
body: [{ | |
type: "BlockStatement", | |
body: [{ | |
type: "ThrowStatement", | |
argument: { | |
type: "Identifier", | |
name: "error" | |
} | |
}, { | |
type: "ExpressionStatement", | |
expression: { | |
type: "Identifier", | |
name: "error" | |
} | |
}] | |
}] | |
}); | |
chk(esprima.parse("{ throw error/* Multiline\nComment */error; }"), { | |
type: "Program", | |
body: [{ | |
type: "BlockStatement", | |
body: [{ | |
type: "ThrowStatement", | |
argument: { | |
type: "Identifier", | |
name: "error" | |
} | |
}, { | |
type: "ExpressionStatement", | |
expression: { | |
type: "Identifier", | |
name: "error" | |
} | |
}] | |
}] | |
}); | |
chk(esprima.parse(""), { | |
type: "Program", | |
body: [] | |
}); | |
chk(esprima.parse("foo: if (true) break foo;"), { | |
type: "Program", | |
body: [{ | |
type: "LabeledStatement", | |
label: { | |
type: "Identifier", | |
name: "foo" | |
}, | |
body: { | |
type: "IfStatement", | |
test: { | |
type: "Literal", | |
value: true, | |
raw: "true" | |
}, | |
consequent: { | |
type: "BreakStatement", | |
label: { | |
type: "Identifier", | |
name: "foo" | |
} | |
}, | |
alternate: null | |
} | |
}] | |
}); | |
chk(esprima.parse("(function () {\n 'use strict';\n '\u0000';\n}())"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "CallExpression", | |
callee: { | |
type: "FunctionExpression", | |
id: null, | |
params: [], | |
defaults: [], | |
body: { | |
type: "BlockStatement", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "Literal", | |
value: "use strict", | |
raw: "'use strict'" | |
} | |
}, { | |
type: "ExpressionStatement", | |
expression: { | |
type: "Literal", | |
value: "\u0000", | |
raw: "'\u0000'" | |
} | |
}] | |
}, | |
generator: false, | |
expression: false | |
}, | |
arguments: [] | |
} | |
}] | |
}); | |
chk(esprima.parse("123..toString(10)"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "CallExpression", | |
callee: { | |
type: "MemberExpression", | |
computed: false, | |
object: { | |
type: "Literal", | |
value: 123, | |
raw: "123." | |
}, | |
property: { | |
type: "Identifier", | |
name: "toString" | |
} | |
}, | |
arguments: [{ | |
type: "Literal", | |
value: 10, | |
raw: "10" | |
}] | |
} | |
}] | |
}); | |
chk(esprima.parse("123.+2"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "BinaryExpression", | |
operator: "+", | |
left: { | |
type: "Literal", | |
value: 123, | |
raw: "123." | |
}, | |
right: { | |
type: "Literal", | |
value: 2, | |
raw: "2" | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("a\u2028b"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "Identifier", | |
name: "a" | |
} | |
}, { | |
type: "ExpressionStatement", | |
expression: { | |
type: "Identifier", | |
name: "b" | |
} | |
}] | |
}); | |
chk(esprima.parse("'a\\u0026b'"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "Literal", | |
value: "a&b", | |
raw: "'a\\u0026b'" | |
} | |
}] | |
}); | |
chk(esprima.parse("foo: 10; foo: 20;"), { | |
type: "Program", | |
body: [{ | |
type: "LabeledStatement", | |
label: { | |
type: "Identifier", | |
name: "foo" | |
}, | |
body: { | |
type: "ExpressionStatement", | |
expression: { | |
type: "Literal", | |
value: 10, | |
raw: "10" | |
} | |
} | |
}, { | |
type: "LabeledStatement", | |
label: { | |
type: "Identifier", | |
name: "foo" | |
}, | |
body: { | |
type: "ExpressionStatement", | |
expression: { | |
type: "Literal", | |
value: 20, | |
raw: "20" | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("if(1)/ foo/"), { | |
type: "Program", | |
body: [{ | |
type: "IfStatement", | |
test: { | |
type: "Literal", | |
value: 1, | |
raw: "1" | |
}, | |
consequent: { | |
type: "ExpressionStatement", | |
expression: { | |
type: "Literal", | |
value: {}, | |
raw: "/ foo/", | |
regex: { | |
pattern: " foo", | |
flags: "" | |
} | |
} | |
}, | |
alternate: null | |
}] | |
}); | |
chk(esprima.parse("var a = 1;"), { | |
type: "Program", | |
body: [{ | |
type: "VariableDeclaration", | |
declarations: [{ | |
type: "VariableDeclarator", | |
id: { | |
type: "Identifier", | |
name: "a" | |
}, | |
init: { | |
type: "Literal", | |
value: 1, | |
raw: "1" | |
} | |
}], | |
kind: "var" | |
}] | |
}); | |
chk(esprima.parse("a.in / b"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "BinaryExpression", | |
operator: "/", | |
left: { | |
type: "MemberExpression", | |
computed: false, | |
object: { | |
type: "Identifier", | |
name: "a" | |
}, | |
property: { | |
type: "Identifier", | |
name: "in" | |
} | |
}, | |
right: { | |
type: "Identifier", | |
name: "b" | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("function x() { return {} / 2}"), { | |
type: "Program", | |
body: [{ | |
type: "FunctionDeclaration", | |
id: { | |
type: "Identifier", | |
name: "x" | |
}, | |
params: [], | |
defaults: [], | |
body: { | |
type: "BlockStatement", | |
body: [{ | |
type: "ReturnStatement", | |
argument: { | |
type: "BinaryExpression", | |
operator: "/", | |
left: { | |
type: "ObjectExpression", | |
properties: [] | |
}, | |
right: { | |
type: "Literal", | |
value: 2, | |
raw: "2" | |
} | |
} | |
}] | |
}, | |
generator: false, | |
expression: false | |
}] | |
}); | |
chk(esprima.parse("function x() { return\n{}\n/foo/ }"), { | |
type: "Program", | |
body: [{ | |
type: "FunctionDeclaration", | |
id: { | |
type: "Identifier", | |
name: "x" | |
}, | |
params: [], | |
defaults: [], | |
body: { | |
type: "BlockStatement", | |
body: [{ | |
type: "ReturnStatement", | |
argument: null | |
}, { | |
type: "BlockStatement", | |
body: [] | |
}, { | |
type: "ExpressionStatement", | |
expression: { | |
type: "Literal", | |
value: {}, | |
raw: "/foo/", | |
regex: { | |
pattern: "foo", | |
flags: "" | |
} | |
} | |
}] | |
}, | |
generator: false, | |
expression: false | |
}] | |
}); | |
chk(esprima.parse("+{} / 2"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "BinaryExpression", | |
operator: "/", | |
left: { | |
type: "UnaryExpression", | |
operator: "+", | |
argument: { | |
type: "ObjectExpression", | |
properties: [] | |
}, | |
prefix: true | |
}, | |
right: { | |
type: "Literal", | |
value: 2, | |
raw: "2" | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("{}\n/foo/"), { | |
type: "Program", | |
body: [{ | |
type: "BlockStatement", | |
body: [] | |
}, { | |
type: "ExpressionStatement", | |
expression: { | |
type: "Literal", | |
value: {}, | |
raw: "/foo/", | |
regex: { | |
pattern: "foo", | |
flags: "" | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("x++\n{}\n/foo/"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "UpdateExpression", | |
operator: "++", | |
argument: { | |
type: "Identifier", | |
name: "x" | |
}, | |
prefix: false | |
} | |
}, { | |
type: "BlockStatement", | |
body: [] | |
}, { | |
type: "ExpressionStatement", | |
expression: { | |
type: "Literal", | |
value: {}, | |
raw: "/foo/", | |
regex: { | |
pattern: "foo", | |
flags: "" | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("{{}\n/foo/}"), { | |
type: "Program", | |
body: [{ | |
type: "BlockStatement", | |
body: [{ | |
type: "BlockStatement", | |
body: [] | |
}, { | |
type: "ExpressionStatement", | |
expression: { | |
type: "Literal", | |
value: {}, | |
raw: "/foo/", | |
regex: { | |
pattern: "foo", | |
flags: "" | |
} | |
} | |
}] | |
}] | |
}); | |
chk(esprima.parse("while (1) /foo/"), { | |
type: "Program", | |
body: [{ | |
type: "WhileStatement", | |
test: { | |
type: "Literal", | |
value: 1, | |
raw: "1" | |
}, | |
body: { | |
type: "ExpressionStatement", | |
expression: { | |
type: "Literal", | |
value: {}, | |
raw: "/foo/", | |
regex: { | |
pattern: "foo", | |
flags: "" | |
} | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("(1) / 2"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "BinaryExpression", | |
operator: "/", | |
left: { | |
type: "Literal", | |
value: 1, | |
raw: "1" | |
}, | |
right: { | |
type: "Literal", | |
value: 2, | |
raw: "2" | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("({a: [1]}+[]) / 2"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "BinaryExpression", | |
operator: "/", | |
left: { | |
type: "BinaryExpression", | |
operator: "+", | |
left: { | |
type: "ObjectExpression", | |
properties: [{ | |
type: "Property", | |
key: { | |
type: "Identifier", | |
name: "a" | |
}, | |
computed: false, | |
value: { | |
type: "ArrayExpression", | |
elements: [{ | |
type: "Literal", | |
value: 1, | |
raw: "1" | |
}] | |
}, | |
kind: "init", | |
method: false, | |
shorthand: false | |
}] | |
}, | |
right: { | |
type: "ArrayExpression", | |
elements: [] | |
} | |
}, | |
right: { | |
type: "Literal", | |
value: 2, | |
raw: "2" | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("{[1]}\n/foo/"), { | |
type: "Program", | |
body: [{ | |
type: "BlockStatement", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "ArrayExpression", | |
elements: [{ | |
type: "Literal", | |
value: 1, | |
raw: "1" | |
}] | |
} | |
}] | |
}, { | |
type: "ExpressionStatement", | |
expression: { | |
type: "Literal", | |
value: {}, | |
raw: "/foo/", | |
regex: { | |
pattern: "foo", | |
flags: "" | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("switch(a) { case 1: {}\n/foo/ }"), { | |
type: "Program", | |
body: [{ | |
type: "SwitchStatement", | |
discriminant: { | |
type: "Identifier", | |
name: "a" | |
}, | |
cases: [{ | |
type: "SwitchCase", | |
test: { | |
type: "Literal", | |
value: 1, | |
raw: "1" | |
}, | |
consequent: [{ | |
type: "BlockStatement", | |
body: [] | |
}, { | |
type: "ExpressionStatement", | |
expression: { | |
type: "Literal", | |
value: {}, | |
raw: "/foo/", | |
regex: { | |
pattern: "foo", | |
flags: "" | |
} | |
} | |
}] | |
}] | |
}] | |
}); | |
chk(esprima.parse("({1: {} / 2})"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "ObjectExpression", | |
properties: [{ | |
type: "Property", | |
key: { | |
type: "Literal", | |
value: 1, | |
raw: "1" | |
}, | |
computed: false, | |
value: { | |
type: "BinaryExpression", | |
operator: "/", | |
left: { | |
type: "ObjectExpression", | |
properties: [] | |
}, | |
right: { | |
type: "Literal", | |
value: 2, | |
raw: "2" | |
} | |
}, | |
kind: "init", | |
method: false, | |
shorthand: false | |
}] | |
} | |
}] | |
}); | |
chk(esprima.parse("+x++ / 2"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "BinaryExpression", | |
operator: "/", | |
left: { | |
type: "UnaryExpression", | |
operator: "+", | |
argument: { | |
type: "UpdateExpression", | |
operator: "++", | |
argument: { | |
type: "Identifier", | |
name: "x" | |
}, | |
prefix: false | |
}, | |
prefix: true | |
}, | |
right: { | |
type: "Literal", | |
value: 2, | |
raw: "2" | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("foo.in\n{}\n/foo/"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "MemberExpression", | |
computed: false, | |
object: { | |
type: "Identifier", | |
name: "foo" | |
}, | |
property: { | |
type: "Identifier", | |
name: "in" | |
} | |
} | |
}, { | |
type: "BlockStatement", | |
body: [] | |
}, { | |
type: "ExpressionStatement", | |
expression: { | |
type: "Literal", | |
value: {}, | |
raw: "/foo/", | |
regex: { | |
pattern: "foo", | |
flags: "" | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("{}/=/"), { | |
type: "Program", | |
body: [{ | |
type: "BlockStatement", | |
body: [] | |
}, { | |
type: "ExpressionStatement", | |
expression: { | |
type: "Literal", | |
value: {}, | |
raw: "/=/", | |
regex: { | |
pattern: "=", | |
flags: "" | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("foo <!--bar\n+baz"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "BinaryExpression", | |
operator: "+", | |
left: { | |
type: "Identifier", | |
name: "foo" | |
}, | |
right: { | |
type: "Identifier", | |
name: "baz" | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("x = y-->10;\n --> nothing"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "AssignmentExpression", | |
operator: "=", | |
left: { | |
type: "Identifier", | |
name: "x" | |
}, | |
right: { | |
type: "BinaryExpression", | |
operator: ">", | |
left: { | |
type: "UpdateExpression", | |
operator: "--", | |
argument: { | |
type: "Identifier", | |
name: "y" | |
}, | |
prefix: false | |
}, | |
right: { | |
type: "Literal", | |
value: 10, | |
raw: "10" | |
} | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("'use strict';\nobject.static();"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "Literal", | |
value: "use strict", | |
raw: "'use strict'" | |
} | |
}, { | |
type: "ExpressionStatement", | |
expression: { | |
type: "CallExpression", | |
callee: { | |
type: "MemberExpression", | |
computed: false, | |
object: { | |
type: "Identifier", | |
name: "object" | |
}, | |
property: { | |
type: "Identifier", | |
name: "static" | |
} | |
}, | |
arguments: [] | |
} | |
}] | |
}); | |
chk(esprima.parse("let x"), { | |
type: "Program", | |
body: [{ | |
type: "VariableDeclaration", | |
declarations: [{ | |
type: "VariableDeclarator", | |
id: { | |
type: "Identifier", | |
name: "x" | |
}, | |
init: null | |
}], | |
kind: "let" | |
}] | |
}); | |
chk(esprima.parse("let x, y;"), { | |
type: "Program", | |
body: [{ | |
type: "VariableDeclaration", | |
declarations: [{ | |
type: "VariableDeclarator", | |
id: { | |
type: "Identifier", | |
name: "x" | |
}, | |
init: null | |
}, { | |
type: "VariableDeclarator", | |
id: { | |
type: "Identifier", | |
name: "y" | |
}, | |
init: null | |
}], | |
kind: "let" | |
}] | |
}); | |
chk(esprima.parse("let x = 42"), { | |
type: "Program", | |
body: [{ | |
type: "VariableDeclaration", | |
declarations: [{ | |
type: "VariableDeclarator", | |
id: { | |
type: "Identifier", | |
name: "x" | |
}, | |
init: { | |
type: "Literal", | |
value: 42, | |
raw: "42" | |
} | |
}], | |
kind: "let" | |
}] | |
}); | |
chk(esprima.parse("let eval = 42, arguments = 42"), { | |
type: "Program", | |
body: [{ | |
type: "VariableDeclaration", | |
declarations: [{ | |
type: "VariableDeclarator", | |
id: { | |
type: "Identifier", | |
name: "eval" | |
}, | |
init: { | |
type: "Literal", | |
value: 42, | |
raw: "42" | |
} | |
}, { | |
type: "VariableDeclarator", | |
id: { | |
type: "Identifier", | |
name: "arguments" | |
}, | |
init: { | |
type: "Literal", | |
value: 42, | |
raw: "42" | |
} | |
}], | |
kind: "let" | |
}] | |
}); | |
chk(esprima.parse("let x = 14, y = 3, z = 1977"), { | |
type: "Program", | |
body: [{ | |
type: "VariableDeclaration", | |
declarations: [{ | |
type: "VariableDeclarator", | |
id: { | |
type: "Identifier", | |
name: "x" | |
}, | |
init: { | |
type: "Literal", | |
value: 14, | |
raw: "14" | |
} | |
}, { | |
type: "VariableDeclarator", | |
id: { | |
type: "Identifier", | |
name: "y" | |
}, | |
init: { | |
type: "Literal", | |
value: 3, | |
raw: "3" | |
} | |
}, { | |
type: "VariableDeclarator", | |
id: { | |
type: "Identifier", | |
name: "z" | |
}, | |
init: { | |
type: "Literal", | |
value: 1977, | |
raw: "1977" | |
} | |
}], | |
kind: "let" | |
}] | |
}); | |
chk(esprima.parse("for(let x = 0;;);"), { | |
type: "Program", | |
body: [{ | |
type: "ForStatement", | |
init: { | |
type: "VariableDeclaration", | |
declarations: [{ | |
type: "VariableDeclarator", | |
id: { | |
type: "Identifier", | |
name: "x" | |
}, | |
init: { | |
type: "Literal", | |
value: 0, | |
raw: "0" | |
} | |
}], | |
kind: "let" | |
}, | |
test: null, | |
update: null, | |
body: { | |
type: "EmptyStatement" | |
} | |
}] | |
}); | |
chk(esprima.parse("for(let x = 0, y = 1;;);"), { | |
type: "Program", | |
body: [{ | |
type: "ForStatement", | |
init: { | |
type: "VariableDeclaration", | |
declarations: [{ | |
type: "VariableDeclarator", | |
id: { | |
type: "Identifier", | |
name: "x" | |
}, | |
init: { | |
type: "Literal", | |
value: 0, | |
raw: "0" | |
} | |
}, { | |
type: "VariableDeclarator", | |
id: { | |
type: "Identifier", | |
name: "y" | |
}, | |
init: { | |
type: "Literal", | |
value: 1, | |
raw: "1" | |
} | |
}], | |
kind: "let" | |
}, | |
test: null, | |
update: null, | |
body: { | |
type: "EmptyStatement" | |
} | |
}] | |
}); | |
chk(esprima.parse("for (let x in list) process(x);"), { | |
type: "Program", | |
body: [{ | |
type: "ForInStatement", | |
left: { | |
type: "VariableDeclaration", | |
declarations: [{ | |
type: "VariableDeclarator", | |
id: { | |
type: "Identifier", | |
name: "x" | |
}, | |
init: null | |
}], | |
kind: "let" | |
}, | |
right: { | |
type: "Identifier", | |
name: "list" | |
}, | |
body: { | |
type: "ExpressionStatement", | |
expression: { | |
type: "CallExpression", | |
callee: { | |
type: "Identifier", | |
name: "process" | |
}, | |
arguments: [{ | |
type: "Identifier", | |
name: "x" | |
}] | |
} | |
}, | |
each: false | |
}] | |
}); | |
chk(esprima.parse("const x = 42"), { | |
type: "Program", | |
body: [{ | |
type: "VariableDeclaration", | |
declarations: [{ | |
type: "VariableDeclarator", | |
id: { | |
type: "Identifier", | |
name: "x" | |
}, | |
init: { | |
type: "Literal", | |
value: 42, | |
raw: "42" | |
} | |
}], | |
kind: "const" | |
}] | |
}); | |
chk(esprima.parse("const eval = 42, arguments = 42"), { | |
type: "Program", | |
body: [{ | |
type: "VariableDeclaration", | |
declarations: [{ | |
type: "VariableDeclarator", | |
id: { | |
type: "Identifier", | |
name: "eval" | |
}, | |
init: { | |
type: "Literal", | |
value: 42, | |
raw: "42" | |
} | |
}, { | |
type: "VariableDeclarator", | |
id: { | |
type: "Identifier", | |
name: "arguments" | |
}, | |
init: { | |
type: "Literal", | |
value: 42, | |
raw: "42" | |
} | |
}], | |
kind: "const" | |
}] | |
}); | |
chk(esprima.parse("const x = 14, y = 3, z = 1977"), { | |
type: "Program", | |
body: [{ | |
type: "VariableDeclaration", | |
declarations: [{ | |
type: "VariableDeclarator", | |
id: { | |
type: "Identifier", | |
name: "x" | |
}, | |
init: { | |
type: "Literal", | |
value: 14, | |
raw: "14" | |
} | |
}, { | |
type: "VariableDeclarator", | |
id: { | |
type: "Identifier", | |
name: "y" | |
}, | |
init: { | |
type: "Literal", | |
value: 3, | |
raw: "3" | |
} | |
}, { | |
type: "VariableDeclarator", | |
id: { | |
type: "Identifier", | |
name: "z" | |
}, | |
init: { | |
type: "Literal", | |
value: 1977, | |
raw: "1977" | |
} | |
}], | |
kind: "const" | |
}] | |
}); | |
chk(esprima.parse("for(const x = 0;;);"), { | |
type: "Program", | |
body: [{ | |
type: "ForStatement", | |
init: { | |
type: "VariableDeclaration", | |
declarations: [{ | |
type: "VariableDeclarator", | |
id: { | |
type: "Identifier", | |
name: "x" | |
}, | |
init: { | |
type: "Literal", | |
value: 0, | |
raw: "0" | |
} | |
}], | |
kind: "const" | |
}, | |
test: null, | |
update: null, | |
body: { | |
type: "EmptyStatement" | |
} | |
}] | |
}); | |
chk(esprima.parse("<!--\n;"), { | |
type: "Program", | |
body: [{ | |
type: "EmptyStatement" | |
}] | |
}); | |
chk(esprima.parse("\nfunction plop() {\n'use strict';\n/* Comment */\n}"), { | |
type: "Program", | |
body: [{ | |
type: "FunctionDeclaration", | |
id: { | |
type: "Identifier", | |
name: "plop" | |
}, | |
params: [], | |
defaults: [], | |
body: { | |
type: "BlockStatement", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "Literal", | |
value: "use strict", | |
raw: "'use strict'" | |
} | |
}] | |
}, | |
generator: false, | |
expression: false | |
}] | |
}); | |
chk(esprima.parse("// line comment"), { | |
type: "Program", | |
body: [] | |
}); | |
chk(esprima.parse("<!-- HTML comment"), { | |
type: "Program", | |
body: [] | |
}); | |
chk(esprima.parse(";\n--> HTML comment"), { | |
type: "Program", | |
body: [{ | |
type: "EmptyStatement" | |
}] | |
}); | |
chk(esprima.parse("function f(f) { 'use strict'; }"), { | |
type: "Program", | |
body: [{ | |
type: "FunctionDeclaration", | |
id: { | |
type: "Identifier", | |
name: "f" | |
}, | |
params: [{ | |
type: "Identifier", | |
name: "f" | |
}], | |
defaults: [], | |
body: { | |
type: "BlockStatement", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "Literal", | |
value: "use strict", | |
raw: "'use strict'" | |
} | |
}] | |
}, | |
generator: false, | |
expression: false | |
}] | |
}); | |
chk(esprima.parse("(function () {} / 1)"), { | |
type: "Program", | |
body: [{ | |
type: "ExpressionStatement", | |
expression: { | |
type: "BinaryExpression", | |
operator: "/", | |
left: { | |
type: "FunctionExpression", | |
id: null, | |
params: [], | |
defaults: [], | |
body: { | |
type: "BlockStatement", | |
body: [] | |
}, | |
generator: false, | |
expression: false | |
}, | |
right: { | |
type: "Literal", | |
value: 1, | |
raw: "1" | |
} | |
} | |
}] | |
}); | |
chk(esprima.parse("function f() {} / 1 /"), { | |
type: "Program", | |
body: [{ | |
type: "FunctionDeclaration", | |
id: { | |
type: "Identifier", | |
name: "f" | |
}, | |
params: [], | |
defaults: [], | |
body: { | |
type: "BlockStatement", | |
body: [] | |
}, | |
generator: false, | |
expression: false | |
}, { | |
type: "ExpressionStatement", | |
expression: { | |
type: "Literal", | |
value: {}, | |
raw: "/ 1 /", | |
regex: { | |
pattern: " 1 ", | |
flags: "" | |
} | |
} | |
}] | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment