eggtended-js
Version:
A extended version of the Egg programming language from the Eloquent Javascript book.
1,467 lines (1,466 loc) • 300 kB
JSON
{
"type": "File",
"start": 0,
"end": 1298,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 65,
"column": 0
}
},
"program": {
"type": "Program",
"start": 0,
"end": 1298,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 65,
"column": 0
}
},
"sourceType": "module",
"body": [
{
"type": "ImportDeclaration",
"start": 8,
"end": 40,
"loc": {
"start": {
"line": 2,
"column": 0
},
"end": {
"line": 2,
"column": 32
}
},
"specifiers": [
{
"type": "ImportDefaultSpecifier",
"start": 15,
"end": 20,
"loc": {
"start": {
"line": 2,
"column": 7
},
"end": {
"line": 2,
"column": 12
}
},
"local": {
"type": "Identifier",
"start": 15,
"end": 20,
"loc": {
"start": {
"line": 2,
"column": 7
},
"end": {
"line": 2,
"column": 12
},
"identifierName": "utils"
},
"name": "utils",
"leadingComments": null
},
"leadingComments": null
}
],
"source": {
"type": "StringLiteral",
"start": 26,
"end": 39,
"loc": {
"start": {
"line": 2,
"column": 18
},
"end": {
"line": 2,
"column": 31
}
},
"extra": {
"rawValue": "../utils.js",
"raw": "\"../utils.js\""
},
"value": "../utils.js"
},
"leadingComments": [
{
"type": "CommentLine",
"value": " SUB",
"start": 0,
"end": 7,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 7
}
}
}
]
},
{
"type": "ExpressionStatement",
"start": 42,
"end": 528,
"loc": {
"start": {
"line": 4,
"column": 0
},
"end": {
"line": 27,
"column": 2
}
},
"expression": {
"type": "AssignmentExpression",
"start": 42,
"end": 527,
"loc": {
"start": {
"line": 4,
"column": 0
},
"end": {
"line": 27,
"column": 1
}
},
"operator": "=",
"left": {
"type": "MemberExpression",
"start": 42,
"end": 62,
"loc": {
"start": {
"line": 4,
"column": 0
},
"end": {
"line": 4,
"column": 20
}
},
"object": {
"type": "MemberExpression",
"start": 42,
"end": 58,
"loc": {
"start": {
"line": 4,
"column": 0
},
"end": {
"line": 4,
"column": 16
}
},
"object": {
"type": "Identifier",
"start": 42,
"end": 48,
"loc": {
"start": {
"line": 4,
"column": 0
},
"end": {
"line": 4,
"column": 6
},
"identifierName": "Object"
},
"name": "Object"
},
"property": {
"type": "Identifier",
"start": 49,
"end": 58,
"loc": {
"start": {
"line": 4,
"column": 7
},
"end": {
"line": 4,
"column": 16
},
"identifierName": "prototype"
},
"name": "prototype"
},
"computed": false
},
"property": {
"type": "Identifier",
"start": 59,
"end": 62,
"loc": {
"start": {
"line": 4,
"column": 17
},
"end": {
"line": 4,
"column": 20
},
"identifierName": "sub"
},
"name": "sub"
},
"computed": false
},
"right": {
"type": "FunctionExpression",
"start": 65,
"end": 527,
"loc": {
"start": {
"line": 4,
"column": 23
},
"end": {
"line": 27,
"column": 1
}
},
"id": {
"type": "Identifier",
"start": 59,
"end": 62,
"loc": {
"start": {
"line": 4,
"column": 17
},
"end": {
"line": 4,
"column": 20
},
"identifierName": "sub"
},
"name": "sub"
},
"generator": false,
"expression": false,
"async": false,
"params": [
{
"type": "RestElement",
"start": 74,
"end": 84,
"loc": {
"start": {
"line": 4,
"column": 32
},
"end": {
"line": 4,
"column": 42
}
},
"argument": {
"type": "Identifier",
"start": 77,
"end": 84,
"loc": {
"start": {
"line": 4,
"column": 35
},
"end": {
"line": 4,
"column": 42
},
"identifierName": "indices"
},
"name": "indices"
}
}
],
"body": {
"type": "BlockStatement",
"start": 86,
"end": 527,
"loc": {
"start": {
"line": 4,
"column": 44
},
"end": {
"line": 27,
"column": 1
}
},
"body": [
{
"type": "ExpressionStatement",
"start": 90,
"end": 132,
"loc": {
"start": {
"line": 5,
"column": 2
},
"end": {
"line": 5,
"column": 44
}
},
"expression": {
"type": "CallExpression",
"start": 90,
"end": 131,
"loc": {
"start": {
"line": 5,
"column": 2
},
"end": {
"line": 5,
"column": 43
}
},
"callee": {
"type": "MemberExpression",
"start": 90,
"end": 109,
"loc": {
"start": {
"line": 5,
"column": 2
},
"end": {
"line": 5,
"column": 21
}
},
"object": {
"type": "Identifier",
"start": 90,
"end": 95,
"loc": {
"start": {
"line": 5,
"column": 2
},
"end": {
"line": 5,
"column": 7
},
"identifierName": "utils"
},
"name": "utils"
},
"property": {
"type": "Identifier",
"start": 96,
"end": 109,
"loc": {
"start": {
"line": 5,
"column": 8
},
"end": {
"line": 5,
"column": 21
},
"identifierName": "checkIterable"
},
"name": "checkIterable"
},
"computed": false
},
"arguments": [
{
"type": "ThisExpression",
"start": 110,
"end": 114,
"loc": {
"start": {
"line": 5,
"column": 22
},
"end": {
"line": 5,
"column": 26
}
}
},
{
"type": "MemberExpression",
"start": 116,
"end": 130,
"loc": {
"start": {
"line": 5,
"column": 28
},
"end": {
"line": 5,
"column": 42
}
},
"object": {
"type": "Identifier",
"start": 116,
"end": 123,
"loc": {
"start": {
"line": 5,
"column": 28
},
"end": {
"line": 5,
"column": 35
},
"identifierName": "indices"
},
"name": "indices"
},
"property": {
"type": "Identifier",
"start": 124,
"end": 130,
"loc": {
"start": {
"line": 5,
"column": 36
},
"end": {
"line": 5,
"column": 42
},
"identifierName": "length"
},
"name": "length"
},
"computed": false
}
]
},
"trailingComments": [
{
"type": "CommentLine",
"value": " Get index",
"start": 136,
"end": 148,
"loc": {
"start": {
"line": 7,
"column": 2
},
"end": {
"line": 7,
"column": 14
}
}
}
]
},
{
"type": "VariableDeclaration",
"start": 151,
"end": 174,
"loc": {
"start": {
"line": 8,
"column": 2
},
"end": {
"line": 8,
"column": 25
}
},
"declarations": [
{
"type": "VariableDeclarator",
"start": 155,
"end": 173,
"loc": {
"start": {
"line": 8,
"column": 6
},
"end": {
"line": 8,
"column": 24
}
},
"id": {
"type": "Identifier",
"start": 155,
"end": 160,
"loc": {
"start": {
"line": 8,
"column": 6
},
"end": {
"line": 8,
"column": 11
},
"identifierName": "index"
},
"name": "index",
"leadingComments": null
},
"init": {
"type": "MemberExpression",
"start": 163,
"end": 173,
"loc": {
"start": {
"line": 8,
"column": 14
},
"end": {
"line": 8,
"column": 24
}
},
"object": {
"type": "Identifier",
"start": 163,
"end": 170,
"loc": {
"start": {
"line": 8,
"column": 14
},
"end": {
"line": 8,
"column": 21
},
"identifierName": "indices"
},
"name": "indices"
},
"property": {
"type": "NumericLiteral",
"start": 171,
"end": 172,
"loc": {
"start": {
"line": 8,
"column": 22
},
"end": {
"line": 8,
"column": 23
}
},
"extra": {
"rawValue": 0,
"raw": "0"
},
"value": 0
},
"computed": true
},
"leadingComments": null
}
],
"kind": "let",
"leadingComments": [
{
"type": "CommentLine",
"value": " Get index",
"start": 136,
"end": 148,
"loc": {
"start": {
"line": 7,
"column": 2
},
"end": {
"line": 7,
"column": 14
}
}
}
]
},
{
"type": "IfStatement",
"start": 177,
"end": 267,
"loc": {
"start": {
"line": 9,
"column": 2
},
"end": {
"line": 11,
"column": 3
}
},
"test": {
"type": "BinaryExpression",
"start": 181,
"end": 202,
"loc": {
"start": {
"line": 9,
"column": 6
},
"end": {
"line": 9,
"column": 27
}
},
"left": {
"type": "ThisExpression",
"start": 181,
"end": 185,
"loc": {
"start": {
"line": 9,
"column": 6
},
"end": {
"line": 9,
"column": 10
}
}
},
"operator": "instanceof",
"right": {
"type": "Identifier",
"start": 197,
"end": 202,
"loc": {
"start": {
"line": 9,
"column": 22
},
"end": {
"line": 9,
"column": 27
},
"identifierName": "Array"
},
"name": "Array"
}
},
"consequent": {
"type": "BlockStatement",
"start": 204,
"end": 267,
"loc": {
"start": {
"line": 9,
"column": 29
},
"end": {
"line": 11,
"column": 3
}
},
"body": [
{
"type": "ExpressionStatement",
"start": 210,
"end": 263,
"loc": {
"start": {
"line": 10,
"column": 4
},
"end": {
"line": 10,
"column": 57
}
},
"expression": {
"type": "AssignmentExpression",
"start": 210,
"end": 262,
"loc": {
"start": {
"line": 10,
"column": 4
},
"end": {
"line": 10,
"column": 56
}
},
"operator": "=",
"left": {
"type": "Identifier",
"start": 210,
"end": 215,
"loc": {
"start": {
"line": 10,
"column": 4
},
"end": {
"line": 10,
"column": 9
},
"identifierName": "index"
},
"name": "index"
},
"right": {
"type": "CallExpression",
"start": 218,
"end": 262,
"loc": {
"start": {
"line": 10,
"column": 12
},
"end": {
"line": 10,
"column": 56
}
},
"callee": {
"type": "MemberExpression",
"start": 218,
"end": 237,
"loc": {
"start": {
"line": 10,
"column": 12
},
"end": {
"line": 10,
"column": 31
}
},
"object": {
"type": "Identifier",
"start": 218,
"end": 223,
"loc": {
"start": {
"line": 10,
"column": 12
},
"end": {
"line": 10,
"column": 17
},
"identifierName": "utils"
},
"name": "utils"
},
"property": {
"type": "Identifier",
"start": 224,
"end": 237,
"loc": {
"start": {
"line": 10,
"column": 18
},
"end": {
"line": 10,
"column": 31
},
"identifierName": "getValidIndex"
},
"name": "getValidIndex"
},
"computed": false
},
"arguments": [
{
"type": "MemberExpression",
"start": 238,
"end": 249,
"loc": {
"start": {
"line": 10,
"column": 32
},
"end": {
"line": 10,
"column": 43
}
},
"object": {
"type": "ThisExpression",
"start": 238,
"end": 242,
"loc": {
"start": {
"line": 10,
"column": 32
},
"end": {
"line": 10,
"column": 36
}
}
},
"property": {
"type": "Identifier",
"start": 243,
"end": 249,
"loc": {
"start": {
"line": 10,
"column": 37
},
"end": {
"line": 10,
"column": 43
},
"identifierName": "length"
},
"name": "length"
},
"computed": false
},
{
"type": "MemberExpression",
"start": 251,
"end": 261,
"loc": {
"start": {
"line": 10,
"column": 45
},
"end": {
"line": 10,
"column": 55
}
},
"object": {
"type": "Identifier",
"start": 251,
"end": 258,
"loc": {
"start": {
"line": 10,
"column": 45
},
"end": {
"line": 10,
"column": 52
},
"identifierName": "indices"
},
"name": "indices"
},
"property": {
"type": "NumericLiteral",
"start": 259,
"end": 260,
"loc": {
"start": {
"line": 10,
"column": 53
},
"end": {
"line": 10,
"column": 54
}
},
"extra": {
"rawValue": 0,
"raw": "0"
},
"value": 0
},
"computed": true
}
]
}
}
}
],
"directives": [],
"trailingComments": null
},
"alternate": null,
"trailingComments": [
{
"type": "CommentLine",
"value": " Get value",
"start": 271,
"end": 283,
"loc": {
"start": {
"line": 13,
"column": 2
},
"end": {
"line": 13,
"column": 14
}
}
}
]
},
{
"type": "VariableDeclaration",
"start": 286,
"end": 296,
"loc": {
"start": {
"line": 14,
"column": 2
},
"end": {
"line": 14,
"column": 12
}
},
"declarations": [
{
"type": "VariableDeclarator",
"start": 290,
"end": 295,
"loc": {
"start": {
"line": 14,
"column": 6
},
"end": {
"line": 14,
"column": 11
}
},
"id": {
"type": "Identifier",
"start": 290,
"end": 295,
"loc": {
"start": {
"line": 14,
"column": 6
},
"end": {
"line": 14,
"column": 11
},
"identifierName": "value"
},
"name": "value",
"leadingComments": null
},
"init": null,
"leadingComments": null
}
],
"kind": "let",
"leadingComments": [
{
"type": "CommentLine",
"value": " Get value",
"start": 271,
"end": 283,
"loc": {
"start": {
"line": 13,
"column": 2
},
"end": {
"line": 13,
"column": 14
}
}
}
]
},
{
"type": "IfStatement",
"start": 299,
"end": 394,
"loc": {
"start": {
"line": 15,
"column": 2
},
"end": {
"line": 19,
"column": 3
}
},
"test": {
"type": "BinaryExpression",
"start": 303,
"end": 322,
"loc": {
"start": {
"line": 15,
"column": 6
},
"end": {
"line": 15,
"column": 25
}
},
"left": {
"type": "ThisExpression",
"start": 303,
"end": 307,
"loc": {
"start": {
"line": 15,
"column": 6
},
"end": {
"line": 15,
"column": 10
}
}
},
"operator": "instanceof",
"right": {
"type": "Identifier",
"start": 319,
"end": 322,
"loc": {
"start": {
"line": 15,
"column": 22
},
"end": {
"line": 15,
"column": 25
},
"identifierName": "Map"
},
"name": "Map"
}
},
"consequent": {
"type": "BlockStatement",
"start": 324,
"end": 358,
"loc": {
"start": {
"line": 15,
"column": 27
},
"end": {
"line": 17,
"column": 3
}
},
"body": [
{
"type": "ExpressionStatement",
"start": 330,
"end": 354,
"loc": {
"start": {
"line": 16,
"column": 4
},
"end": {
"line": 16,
"column": 28
}
},
"expression": {
"type": "AssignmentExpression",
"start": 330,
"end": 353,
"loc": {
"start": {
"line": 16,
"column": 4
},
"end": {
"line": 16,
"column": 27
}
},
"operator": "=",
"left": {
"type": "Identifier",
"start": 330,
"end": 335,
"loc": {
"start": {
"line": 16,
"column": 4
},
"end": {
"line": 16,
"column": 9
},
"identifierName": "value"
},
"name": "value"
},
"right": {
"type": "CallExpression",
"start": 338,
"end": 353,
"loc": {
"start": {
"line": 16,
"column": 12
},
"end": {
"line": 16,
"column": 27
}
},
"callee": {
"type": "MemberExpression",
"start": 338,
"end": 346,
"loc": {
"start": {
"line": 16,
"column": 12
},
"end": {
"line": 16,
"column": 20
}
},
"object": {
"type": "ThisExpression",
"start": 338,
"end": 342,
"loc": {
"start": {
"line": 16,
"column": 12
},
"end": {
"line": 16,
"column": 16
}
}
},
"property": {
"type": "Identifier",
"start": 343,
"end": 346,
"loc": {
"start": {
"line": 16,
"column": 17
},
"end": {
"line": 16,
"column": 20
},
"identifierName": "get"
},
"name": "get"
},
"computed": false
},
"arguments": [
{
"type": "Identifier",
"start": 347,
"end": 352,
"loc": {
"start": {
"line": 16,
"column": 21
},
"end": {
"line": 16,
"column": 26
},
"identifierName": "index"
},
"name": "index"
}
]
}
}
}
],
"directives": []
},
"alternate": {
"type": "BlockStatement",
"start": 364,
"end": 394,
"loc": {
"start": {
"line": 17,
"column": 9
},
"end": {
"line": 19,
"column": 3
}
},
"body": [
{
"type": "ExpressionStatement",
"start": 370,
"end": 390,
"loc": {
"start": {
"line": 18,
"column": 4
},
"end": {
"line": 18,
"column": 24
}
},
"expression": {
"type": "AssignmentExpression",
"start": 370,
"end": 389,
"loc": {
"start": {
"line": 18,
"column": 4
},
"end": {
"line": 18,
"column": 23
}
},
"operator": "=",
"left": {
"type": "Identifier",
"start": 370,
"end": 375,
"loc": {
"start": {
"line": 18,
"column": 4
},
"end": {
"line": 18,
"column": 9
},
"identifierName": "value"
},
"name": "value"
},
"right": {
"type": "MemberExpression",
"start": 378,
"end": 389,
"loc": {
"start": {
"line": 18,
"column": 12
},
"end": {
"line": 18,
"column": 23
}
},
"object": {
"type": "ThisExpression",
"start": 378,
"end": 382,
"loc": {
"start": {
"line": 18,
"column": 12
},
"end": {
"line": 18,
"column": 16
}
}
},
"property": {
"type": "Identifier",
"start": 383,
"end": 388,
"loc": {
"start": {
"line": 18,
"column": 17
},
"end": {
"line": 18,
"column": 22
},
"identifierName": "index"
},
"name": "index"
},
"computed": true
}
}
}
],
"directives": [],
"trailingComments": null
},
"trailingComments": [
{
"type": "CommentLine",
"value": " Return value or keep recursion",
"start": 398,
"end": 431,
"loc": {
"start": {
"line": 21,
"column": 2
},
"end": {
"line": 21,
"column": 35
}
}
}
]
},
{
"type": "IfStatement",
"start": 434,
"end": 483,
"loc": {
"start": {
"line": 22,
"column": 2
},
"end": {
"line": 24,
"column": 3
}
},
"test": {
"type": "BinaryExpression",
"start": 438,
"end": 458,
"loc": {
"start": {
"line": 22,
"column": 6
},
"end": {
"line": 22,
"column": 26
}
},
"left": {
"type": "MemberExpression",
"start": 438,
"end": 452,
"loc": {
"start": {
"line": 22,
"column": 6
},
"end": {
"line": 22,
"column": 20
}
},
"object": {
"type": "Identifier",
"start": 438,
"end": 445,
"loc": {
"start": {
"line": 22,
"column": 6
},
"end": {
"line": 22,
"column": 13
},
"identifierName": "indices"
},
"name": "indices",
"leadingComments": null
},
"property": {
"type": "Identifier",
"start": 446,
"end": 452,
"loc": {
"start": {
"line": 22,
"column": 14
},
"end": {
"line": 22,
"column": 20
},
"identifierName": "length"
},
"name": "length"
},
"computed": false,
"leadingComments": null
},
"operator": "===",
"right": {
"type": "NumericLiteral",
"start": 457,
"end": 458,
"loc": {
"start": {
"line": 22,
"column": 25
},
"end": {
"line": 22,
"column": 26
}
},
"extra": {
"rawValue": 1,
"raw": "1"
},
"value": 1
},
"leadingComments": null
},
"consequent": {
"type": "BlockStatement",
"start": 460,
"end": 483,
"loc": {
"start": {
"line": 22,
"column": 28
},
"end": {
"line": 24,
"column": 3
}
},
"body": [
{
"type": "ReturnStatement",
"start": 466,
"end": 479,
"loc": {
"start": {
"line": 23,
"column": 4
},
"end": {
"line": 23,
"column": 17
}
},