UNPKG

eggtended-js

Version:

A extended version of the Egg programming language from the Eloquent Javascript book.

1,505 lines (1,504 loc) 247 kB
{ "type": "File", "start": 0, "end": 790, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 37, "column": 0 } }, "program": { "type": "Program", "start": 0, "end": 790, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 37, "column": 0 } }, "sourceType": "module", "body": [ { "type": "ImportDeclaration", "start": 0, "end": 27, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 27 } }, "specifiers": [ { "type": "ImportDefaultSpecifier", "start": 7, "end": 14, "loc": { "start": { "line": 1, "column": 7 }, "end": { "line": 1, "column": 14 } }, "local": { "type": "Identifier", "start": 7, "end": 14, "loc": { "start": { "line": 1, "column": 7 }, "end": { "line": 1, "column": 14 }, "identifierName": "inspect" }, "name": "inspect" } } ], "source": { "type": "StringLiteral", "start": 20, "end": 26, "loc": { "start": { "line": 1, "column": 20 }, "end": { "line": 1, "column": 26 } }, "extra": { "rawValue": "util", "raw": "\"util\"" }, "value": "util" } }, { "type": "ExpressionStatement", "start": 28, "end": 44, "loc": { "start": { "line": 1, "column": 28 }, "end": { "line": 1, "column": 44 } }, "expression": { "type": "MemberExpression", "start": 28, "end": 43, "loc": { "start": { "line": 1, "column": 28 }, "end": { "line": 1, "column": 43 } }, "object": { "type": "Identifier", "start": 28, "end": 35, "loc": { "start": { "line": 1, "column": 28 }, "end": { "line": 1, "column": 35 }, "identifierName": "inspect" }, "name": "inspect" }, "property": { "type": "Identifier", "start": 36, "end": 43, "loc": { "start": { "line": 1, "column": 36 }, "end": { "line": 1, "column": 43 }, "identifierName": "inspect" }, "name": "inspect" }, "computed": false } }, { "type": "Identifier", "start": 46, "end": 93, "loc": { "start": { "line": 3, "column": 0 }, "end": { "line": 3, "column": 47 } }, "declarations": [ { "type": "VariableDeclarator", "start": 52, "end": 92, "loc": { "start": { "line": 3, "column": 6 }, "end": { "line": 3, "column": 46 } }, "id": { "type": "Identifier", "start": 52, "end": 55, "loc": { "start": { "line": 3, "column": 6 }, "end": { "line": 3, "column": 9 }, "identifierName": "ins" }, "name": "ins" }, "init": { "type": "ArrowFunctionExpression", "start": 58, "end": 92, "loc": { "start": { "line": 3, "column": 12 }, "end": { "line": 3, "column": 46 } }, "id": null, "generator": false, "expression": true, "async": false, "params": [ { "type": "Identifier", "start": 58, "end": 59, "loc": { "start": { "line": 3, "column": 12 }, "end": { "line": 3, "column": 13 }, "identifierName": "x" }, "name": "x" } ], "body": { "type": "CallExpression", "start": 63, "end": 92, "loc": { "start": { "line": 3, "column": 17 }, "end": { "line": 3, "column": 46 } }, "callee": { "type": "Identifier", "start": 63, "end": 70, "loc": { "start": { "line": 3, "column": 17 }, "end": { "line": 3, "column": 24 }, "identifierName": "inspect" }, "name": "inspect" }, "arguments": [ { "type": "Identifier", "start": 71, "end": 72, "loc": { "start": { "line": 3, "column": 25 }, "end": { "line": 3, "column": 26 }, "identifierName": "x" }, "name": "x" }, { "type": "ObjectExpression", "start": 74, "end": 91, "loc": { "start": { "line": 3, "column": 28 }, "end": { "line": 3, "column": 45 } }, "properties": [ { "type": "ObjectProperty", "start": 76, "end": 89, "loc": { "start": { "line": 3, "column": 30 }, "end": { "line": 3, "column": 43 } }, "method": false, "shorthand": false, "computed": false, "key": { "type": "Identifier", "start": 76, "end": 81, "loc": { "start": { "line": 3, "column": 30 }, "end": { "line": 3, "column": 35 }, "identifierName": "depth" }, "name": "depth" }, "value": { "type": "StringLiteral", "start": 83, "end": 89, "loc": { "start": { "line": 3, "column": 37 }, "end": { "line": 3, "column": 43 } }, "extra": { "rawValue": "null", "raw": "\"null\"" }, "value": "null" } } ] } ] } } } ], "kind": "const", "name": "_", "leadingComments": [], "trailingComments": [] }, { "type": "Identifier", "start": 95, "end": 219, "loc": { "start": { "line": 5, "column": 0 }, "end": { "line": 9, "column": 2 } }, "declarations": [ { "type": "VariableDeclarator", "start": 101, "end": 218, "loc": { "start": { "line": 5, "column": 6 }, "end": { "line": 9, "column": 1 } }, "id": { "type": "Identifier", "start": 101, "end": 106, "loc": { "start": { "line": 5, "column": 6 }, "end": { "line": 5, "column": 11 }, "identifierName": "chunk" }, "name": "chunk" }, "init": { "type": "FunctionExpression", "start": 109, "end": 218, "loc": { "start": { "line": 5, "column": 14 }, "end": { "line": 9, "column": 1 } }, "id": null, "generator": true, "expression": false, "async": false, "params": [ { "type": "Identifier", "start": 119, "end": 122, "loc": { "start": { "line": 5, "column": 24 }, "end": { "line": 5, "column": 27 }, "identifierName": "arr" }, "name": "arr" }, { "type": "Identifier", "start": 124, "end": 128, "loc": { "start": { "line": 5, "column": 29 }, "end": { "line": 5, "column": 33 }, "identifierName": "step" }, "name": "step" } ], "body": { "type": "BlockStatement", "start": 130, "end": 218, "loc": { "start": { "line": 5, "column": 35 }, "end": { "line": 9, "column": 1 } }, "body": [ { "type": "ForStatement", "start": 134, "end": 216, "loc": { "start": { "line": 6, "column": 2 }, "end": { "line": 8, "column": 3 } }, "init": { "type": "VariableDeclaration", "start": 139, "end": 148, "loc": { "start": { "line": 6, "column": 7 }, "end": { "line": 6, "column": 16 } }, "declarations": [ { "type": "VariableDeclarator", "start": 143, "end": 148, "loc": { "start": { "line": 6, "column": 11 }, "end": { "line": 6, "column": 16 } }, "id": { "type": "Identifier", "start": 143, "end": 144, "loc": { "start": { "line": 6, "column": 11 }, "end": { "line": 6, "column": 12 }, "identifierName": "i" }, "name": "i" }, "init": { "type": "NumericLiteral", "start": 147, "end": 148, "loc": { "start": { "line": 6, "column": 15 }, "end": { "line": 6, "column": 16 } }, "extra": { "rawValue": 0, "raw": "0" }, "value": 0 } } ], "kind": "let" }, "test": { "type": "BinaryExpression", "start": 150, "end": 164, "loc": { "start": { "line": 6, "column": 18 }, "end": { "line": 6, "column": 32 } }, "left": { "type": "Identifier", "start": 150, "end": 151, "loc": { "start": { "line": 6, "column": 18 }, "end": { "line": 6, "column": 19 }, "identifierName": "i" }, "name": "i" }, "operator": "<", "right": { "type": "MemberExpression", "start": 154, "end": 164, "loc": { "start": { "line": 6, "column": 22 }, "end": { "line": 6, "column": 32 } }, "object": { "type": "Identifier", "start": 154, "end": 157, "loc": { "start": { "line": 6, "column": 22 }, "end": { "line": 6, "column": 25 }, "identifierName": "arr" }, "name": "arr" }, "property": { "type": "Identifier", "start": 158, "end": 164, "loc": { "start": { "line": 6, "column": 26 }, "end": { "line": 6, "column": 32 }, "identifierName": "length" }, "name": "length" }, "computed": false } }, "update": { "type": "AssignmentExpression", "start": 166, "end": 175, "loc": { "start": { "line": 6, "column": 34 }, "end": { "line": 6, "column": 43 } }, "operator": "+=", "left": { "type": "Identifier", "start": 166, "end": 167, "loc": { "start": { "line": 6, "column": 34 }, "end": { "line": 6, "column": 35 }, "identifierName": "i" }, "name": "i" }, "right": { "type": "Identifier", "start": 171, "end": 175, "loc": { "start": { "line": 6, "column": 39 }, "end": { "line": 6, "column": 43 }, "identifierName": "step" }, "name": "step" } }, "body": { "type": "BlockStatement", "start": 177, "end": 216, "loc": { "start": { "line": 6, "column": 45 }, "end": { "line": 8, "column": 3 } }, "body": [ { "type": "ExpressionStatement", "start": 183, "end": 212, "loc": { "start": { "line": 7, "column": 4 }, "end": { "line": 7, "column": 33 } }, "expression": { "type": "YieldExpression", "start": 183, "end": 211, "loc": { "start": { "line": 7, "column": 4 }, "end": { "line": 7, "column": 32 } }, "delegate": false, "argument": { "type": "CallExpression", "start": 189, "end": 211, "loc": { "start": { "line": 7, "column": 10 }, "end": { "line": 7, "column": 32 } }, "callee": { "type": "MemberExpression", "start": 189, "end": 198, "loc": { "start": { "line": 7, "column": 10 }, "end": { "line": 7, "column": 19 } }, "object": { "type": "Identifier", "start": 189, "end": 192, "loc": { "start": { "line": 7, "column": 10 }, "end": { "line": 7, "column": 13 }, "identifierName": "arr" }, "name": "arr" }, "property": { "type": "Identifier", "start": 193, "end": 198, "loc": { "start": { "line": 7, "column": 14 }, "end": { "line": 7, "column": 19 }, "identifierName": "slice" }, "name": "slice" }, "computed": false }, "arguments": [ { "type": "Identifier", "start": 199, "end": 200, "loc": { "start": { "line": 7, "column": 20 }, "end": { "line": 7, "column": 21 }, "identifierName": "i" }, "name": "i" }, { "type": "BinaryExpression", "start": 202, "end": 210, "loc": { "start": { "line": 7, "column": 23 }, "end": { "line": 7, "column": 31 } }, "left": { "type": "Identifier", "start": 202, "end": 203, "loc": { "start": { "line": 7, "column": 23 }, "end": { "line": 7, "column": 24 }, "identifierName": "i" }, "name": "i" }, "operator": "+", "right": { "type": "Identifier", "start": 206, "end": 210, "loc": { "start": { "line": 7, "column": 27 }, "end": { "line": 7, "column": 31 }, "identifierName": "step" }, "name": "step" } } ] } } } ], "directives": [] } } ], "directives": [] } } } ], "kind": "const", "name": "_", "leadingComments": [], "trailingComments": [] }, { "type": "Identifier", "start": 221, "end": 501, "loc": { "start": { "line": 11, "column": 0 }, "end": { "line": 19, "column": 2 } }, "declarations": [ { "type": "VariableDeclarator", "start": 227, "end": 500, "loc": { "start": { "line": 11, "column": 6 }, "end": { "line": 19, "column": 1 } }, "id": { "type": "Identifier", "start": 227, "end": 240, "loc": { "start": { "line": 11, "column": 6 }, "end": { "line": 11, "column": 19 }, "identifierName": "checkIterable" }, "name": "checkIterable" }, "init": { "type": "ArrowFunctionExpression", "start": 243, "end": 500, "loc": { "start": { "line": 11, "column": 22 }, "end": { "line": 19, "column": 1 } }, "id": null, "generator": false, "expression": false, "async": false, "params": [ { "type": "Identifier", "start": 244, "end": 250, "loc": { "start": { "line": 11, "column": 23 }, "end": { "line": 11, "column": 29 }, "identifierName": "object" }, "name": "object" }, { "type": "Identifier", "start": 252, "end": 258, "loc": { "start": { "line": 11, "column": 31 }, "end": { "line": 11, "column": 37 }, "identifierName": "length" }, "name": "length" } ], "body": { "type": "BlockStatement", "start": 263, "end": 500, "loc": { "start": { "line": 11, "column": 42 }, "end": { "line": 19, "column": 1 } }, "body": [ { "type": "IfStatement", "start": 267, "end": 361, "loc": { "start": { "line": 12, "column": 2 }, "end": { "line": 14, "column": 3 } }, "test": { "type": "BinaryExpression", "start": 271, "end": 283, "loc": { "start": { "line": 12, "column": 6 }, "end": { "line": 12, "column": 18 } }, "left": { "type": "Identifier", "start": 271, "end": 277, "loc": { "start": { "line": 12, "column": 6 }, "end": { "line": 12, "column": 12 }, "identifierName": "length" }, "name": "length" }, "operator": "===", "right": { "type": "NumericLiteral", "start": 282, "end": 283, "loc": { "start": { "line": 12, "column": 17 }, "end": { "line": 12, "column": 18 } }, "extra": { "rawValue": 0, "raw": "0" }, "value": 0 } }, "consequent": { "type": "BlockStatement", "start": 285, "end": 361, "loc": { "start": { "line": 12, "column": 20 }, "end": { "line": 14, "column": 3 } }, "body": [ { "type": "ThrowStatement", "start": 291, "end": 357, "loc": { "start": { "line": 13, "column": 4 }, "end": { "line": 13, "column": 70 } }, "argument": { "type": "NewExpression", "start": 297, "end": 356, "loc": { "start": { "line": 13, "column": 10 }, "end": { "line": 13, "column": 69 } }, "callee": { "type": "Identifier", "start": 301, "end": 312, "loc": { "start": { "line": 13, "column": 14 }, "end": { "line": 13, "column": 25 }, "identifierName": "SyntaxError" }, "name": "SyntaxError" }, "arguments": [ { "type": "StringLiteral", "start": 313, "end": 355, "loc": { "start": { "line": 13, "column": 26 }, "end": { "line": 13, "column": 68 } }, "extra": { "rawValue": "At least one index must be passed to sub", "raw": "\"At least one index must be passed to sub\"" }, "value": "At least one index must be passed to sub" } ] } } ], "directives": [] }, "alternate": null }, { "type": "IfStatement", "start": 365, "end": 498, "loc": { "start": { "line": 16, "column": 2 }, "end": { "line": 18, "column": 3 } }, "test": { "type": "LogicalExpression", "start": 369, "end": 421, "loc": { "start": { "line": 16, "column": 6 }, "end": { "line": 16, "column": 58 } }, "left": { "type": "BinaryExpression", "start": 369, "end": 393, "loc": { "start": { "line": 16, "column": 6 }, "end": { "line": 16, "column": 30 } }, "left": { "type": "Identifier", "start": 369, "end": 375, "loc": { "start": { "line": 16, "column": 6 }, "end": { "line": 16, "column": 12 }, "identifierName": "object" }, "name": "object" }, "operator": "instanceof", "right": { "type": "Identifier", "start": 387, "end": 393, "loc": { "start": { "line": 16, "column": 24 }, "end": { "line": 16, "column": 30 }, "identifierName": "Number" }, "name": "Number" } }, "operator": "||", "right": { "type": "BinaryExpression", "start": 397, "end": 421, "loc": { "start": { "line": 16, "column": 34 }, "end": { "line": 16, "column": 58 } }, "left": { "type": "Identifier", "start": 397, "end": 403, "loc": { "start": { "line": 16, "column": 34 }, "end": { "line": 16, "column": 40 }, "identifierName": "object" }, "name": "object" }, "operator": "instanceof", "right": { "type": "Identifier", "start": 415, "end": 421, "loc": { "start": { "line": 16, "column": 52 }, "end": { "line": 16, "column": 58 }, "identifierName": "String" }, "name": "String" } } }, "consequent": { "type": "BlockStatement", "start": 423, "end": 498, "loc": { "start": { "line": 16, "column": 60 }, "end": { "line": 18, "column": 3 } }, "body": [ { "type": "ThrowStatement", "start": 429, "end": 494, "loc": { "start": { "line": 17, "column": 4 }, "end": { "line": 17, "column": 69 } }, "argument": { "type": "NewExpression", "start": 435, "end": 493, "loc": { "start": { "line": 17, "column": 10 }, "end": { "line": 17, "column": 68 } }, "callee": { "type": "Identifier", "start": 439, "end": 448, "loc": { "start": { "line": 17, "column": 14 }, "end": { "line": 17, "column": 23 }, "identifierName": "TypeError" }, "name": "TypeError" }, "arguments": [ { "type": "TemplateLiteral", "start": 449, "end": 492, "loc": { "start": { "line": 17, "column": 24 }, "end": { "line": 17, "column": 67 } }, "expressions": [ { "type": "Identifier", "start": 464, "end": 470, "loc": { "start": { "line": 17, "column": 39 }, "end": { "line": 17, "column": 45 }, "identifierName": "object" }, "name": "object" } ], "quasis": [ { "type": "TemplateElement", "start": 450, "end": 462, "loc": { "start": { "line": 17, "column": 25 }, "end": { "line": 17, "column": 37 } }, "value": { "raw": "The object '", "cooked": "The object '" }, "tail": false }, { "type": "TemplateElement", "start": 471, "end": 491, "loc": { "start": { "line": 17, "column": 46 }, "end": { "line": 17, "column": 66 } }, "value": { "raw": "'' is not indexable!", "cooked": "'' is not indexable!" }, "tail": true } ] } ] } } ], "directives": [] }, "alternate": null } ], "directives": [] } } } ], "kind": "const", "name": "_", "leadingComments": [], "trailingComments": [] }, { "type": "Identifier", "start": 503, "end": 729, "loc": { "start": { "line": 21, "column": 0 }, "end": { "line": 31, "column": 2 } }, "declarations": [ { "type": "VariableDeclarator", "start": 509, "end": 728, "loc": { "start": { "line": 21, "column": 6 }, "end": { "line": 31, "column": 1 } }, "id": { "type": "Identifier", "start": 509, "end": 522, "loc": { "start": { "line": 21, "column": 6 }, "end": { "line": 21, "column": 19 },