acorn
Version:
ECMAScript parser
2,369 lines (2,310 loc) • 326 kB
JavaScript
/*
Copyright (C) 2012 Ariya Hidayat <ariya.hidayat@gmail.com>
Copyright (C) 2012 Joost-Wim Boekesteijn <joost-wim@boekesteijn.nl>
Copyright (C) 2012 Yusuke Suzuki <utatane.tea@gmail.com>
Copyright (C) 2012 Arpad Borsos <arpad.borsos@googlemail.com>
Copyright (C) 2011 Ariya Hidayat <ariya.hidayat@gmail.com>
Copyright (C) 2011 Yusuke Suzuki <utatane.tea@gmail.com>
Copyright (C) 2011 Arpad Borsos <arpad.borsos@googlemail.com>
Copyright (C) 2014 Ingvar Stepanyan <me@rreverser.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
if (typeof exports != "undefined") {
var test = require("./driver.js").test;
var testFail = require("./driver.js").testFail;
var testAssert = require("./driver.js").testAssert;
}
/*
Tests below were automatically converted from https://github.com/ariya/esprima/blob/2bb17ef9a45c88e82d72c2c61b7b7af93caef028/test/harmonytest.js.
Manually fixed locations for:
- parenthesized expressions (include brackets into expression's location)
- expression statements (excluded spaces after statement's semicolon)
- arrow and method functions (included arguments into function's location)
- template elements (excluded '`', '${' and '}' from element's location)
*/
// ES6 Unicode Code Point Escape Sequence
test("\"\\u{714E}\\u{8336}\"", {
type: "Program",
body: [{
type: "ExpressionStatement",
expression: {
type: "Literal",
value: "煎茶",
raw: "\"\\u{714E}\\u{8336}\"",
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 18}
}
},
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 18}
}
}],
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 18}
}
}, {
ecmaVersion: 6,
ranges: true,
locations: true
});
test("\"\\u{20BB7}\\u{91CE}\\u{5BB6}\"", {
type: "Program",
body: [{
type: "ExpressionStatement",
expression: {
type: "Literal",
value: "𠮷野家",
raw: "\"\\u{20BB7}\\u{91CE}\\u{5BB6}\"",
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 27}
}
},
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 27}
}
}],
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 27}
}
}, {
ecmaVersion: 6,
ranges: true,
locations: true
});
// ES6: Numeric Literal
test("00", {
type: "Program",
body: [{
type: "ExpressionStatement",
expression: {
type: "Literal",
value: 0,
raw: "00",
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 2}
}
},
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 2}
}
}],
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 2}
}
}, {
ecmaVersion: 6,
ranges: true,
locations: true
});
test("0o0", {
type: "Program",
body: [{
type: "ExpressionStatement",
expression: {
type: "Literal",
value: 0,
raw: "0o0",
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 3}
}
},
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 3}
}
}],
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 3}
}
}, {
ecmaVersion: 6,
ranges: true,
locations: true
});
test("function test() {'use strict'; 0o0; }", {
type: "Program",
body: [{
type: "FunctionDeclaration",
id: {
type: "Identifier",
name: "test",
loc: {
start: {line: 1, column: 9},
end: {line: 1, column: 13}
}
},
params: [],
defaults: [],
body: {
type: "BlockStatement",
body: [
{
type: "ExpressionStatement",
expression: {
type: "Literal",
value: "use strict",
raw: "'use strict'",
loc: {
start: {line: 1, column: 17},
end: {line: 1, column: 29}
}
},
loc: {
start: {line: 1, column: 17},
end: {line: 1, column: 30}
}
},
{
type: "ExpressionStatement",
expression: {
type: "Literal",
value: 0,
raw: "0o0",
loc: {
start: {line: 1, column: 31},
end: {line: 1, column: 34}
}
},
loc: {
start: {line: 1, column: 31},
end: {line: 1, column: 35}
}
}
],
loc: {
start: {line: 1, column: 16},
end: {line: 1, column: 37}
}
},
rest: null,
generator: false,
expression: false,
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 37}
}
}],
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 37}
}
}, {
ecmaVersion: 6,
ranges: true,
locations: true
});
test("0o2", {
type: "Program",
body: [{
type: "ExpressionStatement",
expression: {
type: "Literal",
value: 2,
raw: "0o2",
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 3}
}
},
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 3}
}
}],
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 3}
}
}, {
ecmaVersion: 6,
ranges: true,
locations: true
});
test("0o12", {
type: "Program",
body: [{
type: "ExpressionStatement",
expression: {
type: "Literal",
value: 10,
raw: "0o12",
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 4}
}
},
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 4}
}
}],
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 4}
}
}, {
ecmaVersion: 6,
ranges: true,
locations: true
});
test("0O0", {
type: "Program",
body: [{
type: "ExpressionStatement",
expression: {
type: "Literal",
value: 0,
raw: "0O0",
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 3}
}
},
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 3}
}
}],
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 3}
}
}, {
ecmaVersion: 6,
ranges: true,
locations: true
});
test("function test() {'use strict'; 0O0; }", {
type: "Program",
body: [{
type: "FunctionDeclaration",
id: {
type: "Identifier",
name: "test",
loc: {
start: {line: 1, column: 9},
end: {line: 1, column: 13}
}
},
params: [],
defaults: [],
body: {
type: "BlockStatement",
body: [
{
type: "ExpressionStatement",
expression: {
type: "Literal",
value: "use strict",
raw: "'use strict'",
loc: {
start: {line: 1, column: 17},
end: {line: 1, column: 29}
}
},
loc: {
start: {line: 1, column: 17},
end: {line: 1, column: 30}
}
},
{
type: "ExpressionStatement",
expression: {
type: "Literal",
value: 0,
raw: "0O0",
loc: {
start: {line: 1, column: 31},
end: {line: 1, column: 34}
}
},
loc: {
start: {line: 1, column: 31},
end: {line: 1, column: 35}
}
}
],
loc: {
start: {line: 1, column: 16},
end: {line: 1, column: 37}
}
},
rest: null,
generator: false,
expression: false,
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 37}
}
}],
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 37}
}
}, {
ecmaVersion: 6,
ranges: true,
locations: true
});
test("0O2", {
type: "Program",
body: [{
type: "ExpressionStatement",
expression: {
type: "Literal",
value: 2,
raw: "0O2",
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 3}
}
},
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 3}
}
}],
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 3}
}
}, {
ecmaVersion: 6,
ranges: true,
locations: true
});
test("0O12", {
type: "Program",
body: [{
type: "ExpressionStatement",
expression: {
type: "Literal",
value: 10,
raw: "0O12",
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 4}
}
},
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 4}
}
}],
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 4}
}
}, {
ecmaVersion: 6,
ranges: true,
locations: true
});
test("0b0", {
type: "Program",
body: [{
type: "ExpressionStatement",
expression: {
type: "Literal",
value: 0,
raw: "0b0",
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 3}
}
},
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 3}
}
}],
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 3}
}
}, {
ecmaVersion: 6,
ranges: true,
locations: true
});
test("0b1", {
type: "Program",
body: [{
type: "ExpressionStatement",
expression: {
type: "Literal",
value: 1,
raw: "0b1",
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 3}
}
},
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 3}
}
}],
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 3}
}
}, {
ecmaVersion: 6,
ranges: true,
locations: true
});
test("0b10", {
type: "Program",
body: [{
type: "ExpressionStatement",
expression: {
type: "Literal",
value: 2,
raw: "0b10",
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 4}
}
},
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 4}
}
}],
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 4}
}
}, {
ecmaVersion: 6,
ranges: true,
locations: true
});
test("0B0", {
type: "Program",
body: [{
type: "ExpressionStatement",
expression: {
type: "Literal",
value: 0,
raw: "0B0",
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 3}
}
},
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 3}
}
}],
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 3}
}
}, {
ecmaVersion: 6,
ranges: true,
locations: true
});
test("0B1", {
type: "Program",
body: [{
type: "ExpressionStatement",
expression: {
type: "Literal",
value: 1,
raw: "0B1",
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 3}
}
},
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 3}
}
}],
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 3}
}
}, {
ecmaVersion: 6,
ranges: true,
locations: true
});
test("0B10", {
type: "Program",
body: [{
type: "ExpressionStatement",
expression: {
type: "Literal",
value: 2,
raw: "0B10",
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 4}
}
},
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 4}
}
}],
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 4}
}
}, {
ecmaVersion: 6,
ranges: true,
locations: true
});
// ES6 Template Strings
test("`42`", {
type: "Program",
body: [{
type: "ExpressionStatement",
expression: {
type: "TemplateLiteral",
quasis: [{
type: "TemplateElement",
value: {raw: "42", cooked: "42"},
tail: true,
loc: {
start: {line: 1, column: 0},
end: {line: 1, column:4}
}
}],
expressions: [],
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 4}
}
},
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 4}
}
}],
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 4}
}
}, {
ecmaVersion: 6,
ranges: true,
locations: true
});
test("raw`42`", {
type: "Program",
body: [{
type: "ExpressionStatement",
expression: {
type: "TaggedTemplateExpression",
tag: {
type: "Identifier",
name: "raw",
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 3}
}
},
quasi: {
type: "TemplateLiteral",
quasis: [{
type: "TemplateElement",
value: {raw: "42", cooked: "42"},
tail: true,
loc: {
start: {line: 1, column: 3},
end: {line: 1, column: 7}
}
}],
expressions: [],
loc: {
start: {line: 1, column: 3},
end: {line: 1, column: 7}
}
},
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 7}
}
},
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 7}
}
}],
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 7}
}
}, {
ecmaVersion: 6,
ranges: true,
locations: true
});
test("raw`hello ${name}`", {
type: "Program",
body: [{
type: "ExpressionStatement",
expression: {
type: "TaggedTemplateExpression",
tag: {
type: "Identifier",
name: "raw",
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 3}
}
},
quasi: {
type: "TemplateLiteral",
quasis: [
{
type: "TemplateElement",
value: {raw: "hello ", cooked: "hello "},
tail: false,
loc: {
start: {line: 1, column: 3},
end: {line: 1, column: 12}
}
},
{
type: "TemplateElement",
value: {raw: "", cooked: ""},
tail: true,
loc: {
start: {line: 1, column: 16},
end: {line: 1, column: 18}
}
}
],
expressions: [{
type: "Identifier",
name: "name",
loc: {
start: {line: 1, column: 12},
end: {line: 1, column: 16}
}
}],
loc: {
start: {line: 1, column: 3},
end: {line: 1, column: 18}
}
},
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 18}
}
},
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 18}
}
}],
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 18}
}
}, {
ecmaVersion: 6,
ranges: true,
locations: true
});
test("`$`", {
type: "Program",
body: [{
type: "ExpressionStatement",
expression: {
type: "TemplateLiteral",
quasis: [{
type: "TemplateElement",
value: {raw: "$", cooked: "$"},
tail: true,
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 3}
}
}],
expressions: [],
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 3}
}
},
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 3}
}
}],
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 3}
}
}, {
ecmaVersion: 6,
ranges: true,
locations: true
});
test("`\\n\\r\\b\\v\\t\\f\\\n\\\r\n`", {
type: "Program",
body: [{
type: "ExpressionStatement",
expression: {
type: "TemplateLiteral",
quasis: [{
type: "TemplateElement",
value: {raw: "\\n\\r\\b\\v\\t\\f\\\n\\\r\n", cooked: "\n\r\b\u000b\t\f"},
tail: true,
loc: {
start: {line: 1, column: 0},
end: {line: 3, column: 1}
}
}],
expressions: [],
loc: {
start: {line: 1, column: 0},
end: {line: 3, column: 1}
}
},
loc: {
start: {line: 1, column: 0},
end: {line: 3, column: 1}
}
}],
loc: {
start: {line: 1, column: 0},
end: {line: 3, column: 1}
}
}, {
ecmaVersion: 6,
ranges: true,
locations: true
});
test("`\n\r\n`", {
type: "Program",
body: [{
type: "ExpressionStatement",
expression: {
type: "TemplateLiteral",
quasis: [{
type: "TemplateElement",
value: {raw: "\n\r\n", cooked: "\n\n"},
tail: true,
loc: {
start: {line: 1, column: 0},
end: {line: 3, column: 1}
}
}],
expressions: [],
loc: {
start: {line: 1, column: 0},
end: {line: 3, column: 1}
}
},
loc: {
start: {line: 1, column: 0},
end: {line: 3, column: 1}
}
}],
loc: {
start: {line: 1, column: 0},
end: {line: 3, column: 1}
}
}, {
ecmaVersion: 6,
ranges: true,
locations: true
});
test("`\\u{000042}\\u0042\\x42u0\\102\\A`", {
type: "Program",
body: [{
type: "ExpressionStatement",
expression: {
type: "TemplateLiteral",
quasis: [{
type: "TemplateElement",
value: {raw: "\\u{000042}\\u0042\\x42u0\\102\\A", cooked: "BBBu0BA"},
tail: true,
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 30}
}
}],
expressions: [],
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 30}
}
},
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 30}
}
}],
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 30}
}
}, {
ecmaVersion: 6,
ranges: true,
locations: true
});
test("new raw`42`", {
type: "Program",
body: [{
type: "ExpressionStatement",
expression: {
type: "NewExpression",
callee: {
type: "TaggedTemplateExpression",
tag: {
type: "Identifier",
name: "raw",
loc: {
start: {line: 1, column: 4},
end: {line: 1, column: 7}
}
},
quasi: {
type: "TemplateLiteral",
quasis: [{
type: "TemplateElement",
value: {raw: "42", cooked: "42"},
tail: true,
loc: {
start: {line: 1, column: 7},
end: {line: 1, column: 11}
}
}],
expressions: [],
loc: {
start: {line: 1, column: 7},
end: {line: 1, column: 11}
}
},
loc: {
start: {line: 1, column: 4},
end: {line: 1, column: 11}
}
},
arguments: [],
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 11}
}
},
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 11}
}
}],
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 11}
}
}, {
ecmaVersion: 6,
ranges: true,
locations: true
});
test("`outer${{x: {y: 10}}}bar${`nested${function(){return 1;}}endnest`}end`",{
type: "Program",
body: [
{
type: "ExpressionStatement",
expression: {
type: "TemplateLiteral",
expressions: [
{
type: "ObjectExpression",
properties: [
{
type: "Property",
method: false,
shorthand: false,
computed: false,
key: {
type: "Identifier",
name: "x"
},
value: {
type: "ObjectExpression",
properties: [
{
type: "Property",
method: false,
shorthand: false,
computed: false,
key: {
type: "Identifier",
name: "y"
},
value: {
type: "Literal",
value: 10,
raw: "10"
},
kind: "init"
}
]
},
kind: "init"
}
]
},
{
type: "TemplateLiteral",
expressions: [
{
type: "FunctionExpression",
id: null,
params: [],
defaults: [],
rest: null,
generator: false,
body: {
type: "BlockStatement",
body: [
{
type: "ReturnStatement",
argument: {
type: "Literal",
value: 1,
raw: "1"
}
}
]
},
expression: false
}
],
quasis: [
{
type: "TemplateElement",
value: {
cooked: "nested",
raw: "nested"
},
tail: false
},
{
type: "TemplateElement",
value: {
cooked: "endnest",
raw: "endnest"
},
tail: true
}
]
}
],
quasis: [
{
type: "TemplateElement",
value: {
cooked: "outer",
raw: "outer"
},
tail: false
},
{
type: "TemplateElement",
value: {
cooked: "bar",
raw: "bar"
},
tail: false
},
{
type: "TemplateElement",
value: {
cooked: "end",
raw: "end"
},
tail: true
}
]
}
}
]
}, {
ecmaVersion: 6
});
// ES6: Switch Case Declaration
test("switch (answer) { case 42: let t = 42; break; }", {
type: "Program",
body: [{
type: "SwitchStatement",
discriminant: {
type: "Identifier",
name: "answer",
loc: {
start: {line: 1, column: 8},
end: {line: 1, column: 14}
}
},
cases: [{
type: "SwitchCase",
test: {
type: "Literal",
value: 42,
raw: "42",
loc: {
start: {line: 1, column: 23},
end: {line: 1, column: 25}
}
},
consequent: [
{
type: "VariableDeclaration",
declarations: [{
type: "VariableDeclarator",
id: {
type: "Identifier",
name: "t",
loc: {
start: {line: 1, column: 31},
end: {line: 1, column: 32}
}
},
init: {
type: "Literal",
value: 42,
raw: "42",
loc: {
start: {line: 1, column: 35},
end: {line: 1, column: 37}
}
},
loc: {
start: {line: 1, column: 31},
end: {line: 1, column: 37}
}
}],
kind: "let",
loc: {
start: {line: 1, column: 27},
end: {line: 1, column: 38}
}
},
{
type: "BreakStatement",
label: null,
loc: {
start: {line: 1, column: 39},
end: {line: 1, column: 45}
}
}
],
loc: {
start: {line: 1, column: 18},
end: {line: 1, column: 45}
}
}],
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 47}
}
}],
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 47}
}
}, {
ecmaVersion: 6,
ranges: true,
locations: true
});
// ES6: Arrow Function
test("() => \"test\"", {
type: "Program",
body: [{
type: "ExpressionStatement",
expression: {
type: "ArrowFunctionExpression",
id: null,
params: [],
defaults: [],
body: {
type: "Literal",
value: "test",
raw: "\"test\"",
loc: {
start: {line: 1, column: 6},
end: {line: 1, column: 12}
}
},
rest: null,
generator: false,
expression: true,
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 12}
}
},
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 12}
}
}],
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 12}
}
}, {
ecmaVersion: 6,
ranges: true,
locations: true
});
test("e => \"test\"", {
type: "Program",
body: [{
type: "ExpressionStatement",
expression: {
type: "ArrowFunctionExpression",
id: null,
params: [{
type: "Identifier",
name: "e",
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 1}
}
}],
defaults: [],
body: {
type: "Literal",
value: "test",
raw: "\"test\"",
loc: {
start: {line: 1, column: 5},
end: {line: 1, column: 11}
}
},
rest: null,
generator: false,
expression: true,
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 11}
}
},
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 11}
}
}],
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 11}
}
}, {
ecmaVersion: 6,
ranges: true,
locations: true
});
test("(e) => \"test\"", {
type: "Program",
body: [{
type: "ExpressionStatement",
expression: {
type: "ArrowFunctionExpression",
id: null,
params: [{
type: "Identifier",
name: "e",
loc: {
start: {line: 1, column: 1},
end: {line: 1, column: 2}
}
}],
defaults: [],
body: {
type: "Literal",
value: "test",
raw: "\"test\"",
loc: {
start: {line: 1, column: 7},
end: {line: 1, column: 13}
}
},
rest: null,
generator: false,
expression: true,
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 13}
}
},
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 13}
}
}],
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 13}
}
}, {
ecmaVersion: 6,
ranges: true,
locations: true
});
test("(a, b) => \"test\"", {
type: "Program",
body: [{
type: "ExpressionStatement",
expression: {
type: "ArrowFunctionExpression",
id: null,
params: [
{
type: "Identifier",
name: "a",
loc: {
start: {line: 1, column: 1},
end: {line: 1, column: 2}
}
},
{
type: "Identifier",
name: "b",
loc: {
start: {line: 1, column: 4},
end: {line: 1, column: 5}
}
}
],
defaults: [],
body: {
type: "Literal",
value: "test",
raw: "\"test\"",
loc: {
start: {line: 1, column: 10},
end: {line: 1, column: 16}
}
},
rest: null,
generator: false,
expression: true,
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 16}
}
},
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 16}
}
}],
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 16}
}
}, {
ecmaVersion: 6,
ranges: true,
locations: true
});
test("e => { 42; }", {
type: "Program",
body: [{
type: "ExpressionStatement",
expression: {
type: "ArrowFunctionExpression",
id: null,
params: [{
type: "Identifier",
name: "e",
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 1}
}
}],
defaults: [],
body: {
type: "BlockStatement",
body: [{
type: "ExpressionStatement",
expression: {
type: "Literal",
value: 42,
raw: "42",
loc: {
start: {line: 1, column: 7},
end: {line: 1, column: 9}
}
},
loc: {
start: {line: 1, column: 7},
end: {line: 1, column: 10}
}
}],
loc: {
start: {line: 1, column: 5},
end: {line: 1, column: 12}
}
},
rest: null,
generator: false,
expression: false,
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 12}
}
},
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 12}
}
}],
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 12}
}
}, {
ecmaVersion: 6,
ranges: true,
locations: true
});
test("e => ({ property: 42 })", {
type: "Program",
body: [{
type: "ExpressionStatement",
expression: {
type: "ArrowFunctionExpression",
id: null,
params: [{
type: "Identifier",
name: "e",
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 1}
}
}],
defaults: [],
body: {
type: "ObjectExpression",
properties: [{
type: "Property",
key: {
type: "Identifier",
name: "property",
loc: {
start: {line: 1, column: 8},
end: {line: 1, column: 16}
}
},
value: {
type: "Literal",
value: 42,
raw: "42",
loc: {
start: {line: 1, column: 18},
end: {line: 1, column: 20}
}
},
kind: "init",
method: false,
shorthand: false,
computed: false,
loc: {
start: {line: 1, column: 8},
end: {line: 1, column: 20}
}
}],
loc: {
start: {line: 1, column: 6},
end: {line: 1, column: 22}
}
},
rest: null,
generator: false,
expression: true,
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 23}
}
},
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 23}
}
}],
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 23}
}
}, {
ecmaVersion: 6,
ranges: true,
locations: true
});
test("e => { label: 42 }", {
type: "Program",
body: [{
type: "ExpressionStatement",
expression: {
type: "ArrowFunctionExpression",
id: null,
params: [{
type: "Identifier",
name: "e",
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 1}
}
}],
defaults: [],
body: {
type: "BlockStatement",
body: [{
type: "LabeledStatement",
label: {
type: "Identifier",
name: "label",
loc: {
start: {line: 1, column: 7},
end: {line: 1, column: 12}
}
},
body: {
type: "ExpressionStatement",
expression: {
type: "Literal",
value: 42,
raw: "42",
loc: {
start: {line: 1, column: 14},
end: {line: 1, column: 16}
}
},
loc: {
start: {line: 1, column: 14},
end: {line: 1, column: 16}
}
},
loc: {
start: {line: 1, column: 7},
end: {line: 1, column: 16}
}
}],
loc: {
start: {line: 1, column: 5},
end: {line: 1, column: 18}
}
},
rest: null,
generator: false,
expression: false,
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 18}
}
},
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 18}
}
}],
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 18}
}
}, {
ecmaVersion: 6,
ranges: true,
locations: true
});
test("(a, b) => { 42; }", {
type: "Program",
body: [{
type: "ExpressionStatement",
expression: {
type: "ArrowFunctionExpression",
id: null,
params: [
{
type: "Identifier",
name: "a",
loc: {
start: {line: 1, column: 1},
end: {line: 1, column: 2}
}
},
{
type: "Identifier",
name: "b",
loc: {
start: {line: 1, column: 4},
end: {line: 1, column: 5}
}
}
],
defaults: [],
body: {
type: "BlockStatement",
body: [{
type: "ExpressionStatement",
expression: {
type: "Literal",
value: 42,
raw: "42",
loc: {
start: {line: 1, column: 12},
end: {line: 1, column: 14}
}
},
loc: {
start: {line: 1, column: 12},
end: {line: 1, column: 15}
}
}],
loc: {
start: {line: 1, column: 10},
end: {line: 1, column: 17}
}
},
rest: null,
generator: false,
expression: false,
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 17}
}
},
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 17}
}
}],
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 17}
}
}, {
ecmaVersion: 6,
ranges: true,
locations: true
});
test("([a, , b]) => 42", {
type: "Program",
body: [{
type: "ExpressionStatement",
expression: {
type: "ArrowFunctionExpression",
id: null,
params: [{
type: "ArrayPattern",
elements: [
{
type: "Identifier",
name: "a",
loc: {
start: {line: 1, column: 2},
end: {line: 1, column: 3}
}
},
null,
{
type: "Identifier",
name: "b",
loc: {
start: {line: 1, column: 7},
end: {line: 1, column: 8}
}
}
],
loc: {
start: {line: 1, column: 1},
end: {line: 1, column: 9}
}
}],
defaults: [],
body: {
type: "Literal",
value: 42,
raw: "42",
loc: {
start: {line: 1, column: 14},
end: {line: 1, column: 16}
}
},
rest: null,
generator: false,
expression: true,
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 16}
}
},
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 16}
}
}],
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 16}
}
}, {
ecmaVersion: 6,
ranges: true,
locations: true
});
test("([a.a]) => 42", {
type: "Program",
body: [{
type: "ExpressionStatement",
expression: {
type: "ArrowFunctionExpression",
id: null,
params: [{
type: "ArrayPattern",
elements: [{
type: "MemberExpression",
computed: false,
object: {
type: "Identifier",
name: "a",
loc: {
start: {line: 1, column: 2},
end: {line: 1, column: 3}
}
},
property: {
type: "Identifier",
name: "a",
loc: {
start: {line: 1, column: 4},
end: {line: 1, column: 5}
}
},
loc: {
start: {line: 1, column: 2},
end: {line: 1, column: 5}
}
}],
loc: {
start: {line: 1, column: 1},
end: {line: 1, column: 6}
}
}],
defaults: [],
body: {
type: "Literal",
value: 42,
raw: "42",
loc: {
start: {line: 1, column: 11},
end: {line: 1, column: 13}
}
},
rest: null,
generator: false,
expression: true,
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 13}
}
},
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 13}
}
}],
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 13}
}
}, {
ecmaVersion: 6,
ranges: true,
locations: true
});
test("(x=1) => x * x", {
type: "Program",
body: [{
type: "ExpressionStatement",
expression: {
type: "ArrowFunctionExpression",
id: null,
params: [{
type: "Identifier",
name: "x",
loc: {
start: {line: 1, column: 1},
end: {line: 1, column: 2}
}
}],
defaults: [{
type: "Literal",
value: 1,
raw: "1",
loc: {
start: {line: 1, column: 3},
end: {line: 1, column: 4}
}
}],
body: {
type: "BinaryExpression",
operator: "*",
left: {
type: "Identifier",
name: "x",
loc: {
start: {line: 1, column: 9},
end: {line: 1, column: 10}
}
},
right: {
type: "Identifier",
name: "x",
loc: {
start: {line: 1, column: 13},
end: {line: 1, column: 14}
}
},
loc: {
start: {line: 1, column: 9},
end: {line: 1, column: 14}
}
},
rest: null,
generator: false,
expression: true,
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 14}
}
},
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 14}
}
}],
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 14}
}
}, {
ecmaVersion: 6,
ranges: true,
locations: true
});
test("eval => 42", {
type: "Program",
body: [{
type: "ExpressionStatement",
expression: {
type: "ArrowFunctionExpression",
id: null,
params: [{
type: "Identifier",
name: "eval",
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 4}
}
}],
defaults: [],
body: {
type: "Literal",
value: 42,
raw: "42",
loc: {
start: {line: 1, column: 8},
end: {line: 1, column: 10}
}
},
rest: null,
generator: false,
expression: true,
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 10}
}
},
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 10}
}
}],
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 10}
}
}, {
ecmaVersion: 6,
ranges: true,
locations: true
});
test("arguments => 42", {
type: "Program",
body: [{
type: "ExpressionStatement",
expression: {
type: "ArrowFunctionExpression",
id: null,
params: [{
type: "Identifier",
name: "arguments",
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 9}
}
}],
defaults: [],
body: {
type: "Literal",
value: 42,
raw: "42",
loc: {
start: {line: 1, column: 13},
end: {line: 1, column: 15}
}
},
rest: null,
generator: false,
expression: true,
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 15}
}
},
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 15}
}
}],
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 15}
}
}, {
ecmaVersion: 6,
ranges: true,
locations: true
});
test("(a) => 00", {
type: "Program",
body: [{
type: "ExpressionStatement",
expression: {
type: "ArrowFunctionExpression",
id: null,
params: [{
type: "Identifier",
name: "a",
loc: {
start: {line: 1, column: 1},
end: {line: 1, column: 2}
}
}],
defaults: [],
body: {
type: "Literal",
value: 0,
raw: "00",
loc: {
start: {line: 1, column: 7},
end: {line: 1, column: 9}
}
},
rest: null,
generator: false,
expression: true,
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 9}
}
},
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 9}
}
}],
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 9}
}
}, {
ecmaVersion: 6,
ranges: true,
locations: true
});
test("(eval, a) => 42", {
type: "Program",
body: [{
type: "ExpressionStatement",
expression: {
type: "ArrowFunctionExpression",
id: null,
params: [
{
type: "Identifier",
name: "eval",
loc: {
start: {line: 1, column: 1},
end: {line: 1, column: 5}
}
},
{
type: "Identifier",
name: "a",
loc: {
start: {line: 1, column: 7},
end: {line: 1, column: 8}
}
}
],
defaults: [],
body: {
type: "Literal",
value: 42,
raw: "42",
loc: {
start: {line: 1, column: 13},
end: {line: 1, column: 15}
}
},
rest: null,
generator: false,
expression: true,
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 15}
}
},
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 15}
}
}],
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 15}
}
}, {
ecmaVersion: 6,
ranges: true,
locations: true
});
test("(eval = 10) => 42", {
type: "Program",
body: [{
type: "ExpressionStatement",
expression: {
type: "ArrowFunctionExpression",
id: null,
params: [{
type: "Identifier",
name: "eval",
loc: {
start: {line: 1, column: 1},
end: {line: 1, column: 5}
}
}],
defaults: [{
type: "Literal",
value: 10,
raw: "10",
loc: {
start: {line: 1, column: 8},
end: {line: 1, column: 10}
}
}],
body: {
type: "Literal",
value: 42,
raw: "42",
loc: {
start: {line: 1, column: 15},
end: {line: 1, column: 17}
}
},
rest: null,
generator: false,
expression: true,
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 17}
}
},
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 17}
}
}],
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 17}
}
}, {
ecmaVersion: 6,
ranges: true,
locations: true
});
test("(eval, a = 10) => 42", {
type: "Program",
body: [{
type: "ExpressionStatement",
expression: {
type: "ArrowFunctionExpression",
id: null,
params: [
{
type: "Identifier",
name: "eval",
loc: {
start: {line: 1, column: 1},
end: {line: 1, column: 5}
}
},
{
type: "Identifier",
name: "a",
loc: {
start: {line: 1, column: 7},
end: {line: 1, column: 8}
}
}
],
defaults: [
null,
{
type: "Literal",
value: 10,
raw: "10",
loc: {
start: {line: 1, column: 11},
end: {line: 1, column: 13}
}
}
],
body: {
type: "Literal",
value: 42,
raw: "42",
loc: {
start: {line: 1, column: 18},
end: {line: 1, column: 20}
}
},
rest: null,
generator: false,
expression: true,
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 20}
}
},
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 20}
}
}],
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 20}
}
}, {
ecmaVersion: 6,
ranges: true,
locations: true
});
test("(x => x)", {
type: "Program",
body: [{
type: "ExpressionStatement",
expression: {
type: "ArrowFunctionExpression",
id: null,
params: [{
type: "Identifier",
name: "x",
loc: {
start: {line: 1, column: 1},
end: {line: 1, column: 2}
}
}],
defaults: [],
body: {
type: "Identifier",
name: "x",
loc: {
start: {line: 1, column: 6},
end: {line: 1, column: 7}
}
},
rest: null,
generator: false,
expression: true,
loc: {
start: {line: 1, column: 1},
end: {line: 1, column: 7}
}
},
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 8}
}
}],
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 8}
}
}, {
ecmaVersion: 6,
ranges: true,
locations: true
});
test("x => y => 42", {
type: "Program",
body: [{
type: "ExpressionStatement",
expression: {
type: "ArrowFunctionExpression",
id: null,
params: [{
type: "Identifier",
name: "x",
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 1}
}
}],
defaults: [],
body: {
type: "ArrowFunctionExpression",
id: null,
params: [{
type: "Identifier",
name: "y",
loc: {
start: {line: 1, column: 5},
end: {line: 1, column: 6}
}
}],
defaults: [],
body: {
type: "Literal",
value: 42,
raw: "42",
loc: {
start: {line: 1, column: 10},
end: {line: 1, column: 12}
}
},
rest: null,
generator: false,
expression: true,
loc: {
start: {line: 1, column: 5},
end: {line: 1, column: 12}
}
},
rest: null,
generator: false,
expression: true,
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 12}
}
},
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 12}
}
}],
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 12}
}
}, {
ecmaVersion: 6,
ranges: true,
locations: true
});
test("(x) => ((y, z) => (x, y, z))", {
type: "Program",
body: [{
type: "ExpressionStatement",
expression: {
type: "ArrowFunctionExpression",
id: null,
params: [{
type: "Identifier",
name: "x",
loc: {
start: {line: 1, column: 1},
end: {line: 1, column: 2}
}
}],
defaults: [],
body: {
type: "ArrowFunctionExpression",
id: null,
params: [
{
type: "Identifier",
name: "y",
loc: {
start: {line: 1, column: 9},
end: {line: 1, column: 10}
}
},
{
type: "Identifier",
name: "z",
loc: {
start: {line: 1, column: 12},
end: {line: 1, column: 13}
}
}
],
defaults: [],
body: {
type: "SequenceExpression",
expressions: [
{
type: "Identifier",
name: "x",
loc: {
start: {line: 1, column: 19},
end: {line: 1, column: 20}