UNPKG

eggtended-js

Version:

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

1,622 lines (1,621 loc) 254 kB
{ "type": "File", "start": 0, "end": 1061, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 49, "column": 0 } }, "program": { "type": "Program", "start": 0, "end": 1061, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 49, "column": 0 } }, "sourceType": "module", "body": [ { "type": "ImportDeclaration", "start": 0, "end": 48, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 48 } }, "specifiers": [ { "type": "ImportSpecifier", "start": 9, "end": 21, "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 21 } }, "imported": { "type": "Identifier", "start": 9, "end": 21, "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 21 }, "identifierName": "SpecialForms" }, "name": "SpecialForms" }, "local": { "type": "Identifier", "start": 9, "end": 21, "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 21 }, "identifierName": "SpecialForms" }, "name": "SpecialForms" } } ], "source": { "type": "StringLiteral", "start": 29, "end": 47, "loc": { "start": { "line": 1, "column": 29 }, "end": { "line": 1, "column": 47 } }, "extra": { "rawValue": "./environment.js", "raw": "\"./environment.js\"" }, "value": "./environment.js" } }, { "type": "ImportDeclaration", "start": 50, "end": 83, "loc": { "start": { "line": 3, "column": 0 }, "end": { "line": 3, "column": 33 } }, "specifiers": [ { "type": "ImportSpecifier", "start": 59, "end": 64, "loc": { "start": { "line": 3, "column": 9 }, "end": { "line": 3, "column": 14 } }, "imported": { "type": "Identifier", "start": 59, "end": 64, "loc": { "start": { "line": 3, "column": 9 }, "end": { "line": 3, "column": 14 }, "identifierName": "Value" }, "name": "Value" }, "local": { "type": "Identifier", "start": 59, "end": 64, "loc": { "start": { "line": 3, "column": 9 }, "end": { "line": 3, "column": 14 }, "identifierName": "Value" }, "name": "Value" } } ], "source": { "type": "StringLiteral", "start": 72, "end": 82, "loc": { "start": { "line": 3, "column": 22 }, "end": { "line": 3, "column": 32 } }, "extra": { "rawValue": "./ast.js", "raw": "\"./ast.js\"" }, "value": "./ast.js" } }, { "type": "ExpressionStatement", "start": 85, "end": 244, "loc": { "start": { "line": 5, "column": 0 }, "end": { "line": 11, "column": 2 } }, "expression": { "type": "AssignmentExpression", "start": 85, "end": 243, "loc": { "start": { "line": 5, "column": 0 }, "end": { "line": 11, "column": 1 } }, "operator": "=", "left": { "type": "MemberExpression", "start": 85, "end": 103, "loc": { "start": { "line": 5, "column": 0 }, "end": { "line": 5, "column": 18 } }, "object": { "type": "Identifier", "start": 85, "end": 97, "loc": { "start": { "line": 5, "column": 0 }, "end": { "line": 5, "column": 12 }, "identifierName": "SpecialForms" }, "name": "SpecialForms" }, "property": { "type": "StringLiteral", "start": 98, "end": 102, "loc": { "start": { "line": 5, "column": 13 }, "end": { "line": 5, "column": 17 } }, "extra": { "rawValue": "++", "raw": "\"++\"" }, "value": "++" }, "computed": true }, "right": { "type": "ArrowFunctionExpression", "start": 106, "end": 243, "loc": { "start": { "line": 5, "column": 21 }, "end": { "line": 11, "column": 1 } }, "id": null, "generator": false, "expression": false, "async": false, "params": [ { "type": "Identifier", "start": 107, "end": 111, "loc": { "start": { "line": 5, "column": 22 }, "end": { "line": 5, "column": 26 }, "identifierName": "args" }, "name": "args" }, { "type": "Identifier", "start": 113, "end": 116, "loc": { "start": { "line": 5, "column": 28 }, "end": { "line": 5, "column": 31 }, "identifierName": "env" }, "name": "env" } ], "body": { "type": "BlockStatement", "start": 121, "end": 243, "loc": { "start": { "line": 5, "column": 36 }, "end": { "line": 11, "column": 1 } }, "body": [ { "type": "IfStatement", "start": 125, "end": 197, "loc": { "start": { "line": 6, "column": 2 }, "end": { "line": 8, "column": 3 } }, "test": { "type": "BinaryExpression", "start": 129, "end": 146, "loc": { "start": { "line": 6, "column": 6 }, "end": { "line": 6, "column": 23 } }, "left": { "type": "MemberExpression", "start": 129, "end": 140, "loc": { "start": { "line": 6, "column": 6 }, "end": { "line": 6, "column": 17 } }, "object": { "type": "Identifier", "start": 129, "end": 133, "loc": { "start": { "line": 6, "column": 6 }, "end": { "line": 6, "column": 10 }, "identifierName": "args" }, "name": "args" }, "property": { "type": "Identifier", "start": 134, "end": 140, "loc": { "start": { "line": 6, "column": 11 }, "end": { "line": 6, "column": 17 }, "identifierName": "length" }, "name": "length" }, "computed": false }, "operator": "!==", "right": { "type": "NumericLiteral", "start": 145, "end": 146, "loc": { "start": { "line": 6, "column": 22 }, "end": { "line": 6, "column": 23 } }, "extra": { "rawValue": 1, "raw": "1" }, "value": 1 } }, "consequent": { "type": "BlockStatement", "start": 148, "end": 197, "loc": { "start": { "line": 6, "column": 25 }, "end": { "line": 8, "column": 3 } }, "body": [ { "type": "ThrowStatement", "start": 154, "end": 193, "loc": { "start": { "line": 7, "column": 4 }, "end": { "line": 7, "column": 43 } }, "argument": { "type": "NewExpression", "start": 160, "end": 192, "loc": { "start": { "line": 7, "column": 10 }, "end": { "line": 7, "column": 42 } }, "callee": { "type": "Identifier", "start": 164, "end": 175, "loc": { "start": { "line": 7, "column": 14 }, "end": { "line": 7, "column": 25 }, "identifierName": "SyntaxError" }, "name": "SyntaxError" }, "arguments": [ { "type": "StringLiteral", "start": 176, "end": 191, "loc": { "start": { "line": 7, "column": 26 }, "end": { "line": 7, "column": 41 } }, "extra": { "rawValue": "Bad use of ++", "raw": "\"Bad use of ++\"" }, "value": "Bad use of ++" } ] } } ], "directives": [] }, "alternate": null }, { "type": "ReturnStatement", "start": 201, "end": 241, "loc": { "start": { "line": 10, "column": 2 }, "end": { "line": 10, "column": 42 } }, "argument": { "type": "CallExpression", "start": 208, "end": 240, "loc": { "start": { "line": 10, "column": 9 }, "end": { "line": 10, "column": 41 } }, "callee": { "type": "Identifier", "start": 208, "end": 223, "loc": { "start": { "line": 10, "column": 9 }, "end": { "line": 10, "column": 24 }, "identifierName": "incrementHelper" }, "name": "incrementHelper" }, "arguments": [ { "type": "MemberExpression", "start": 224, "end": 231, "loc": { "start": { "line": 10, "column": 25 }, "end": { "line": 10, "column": 32 } }, "object": { "type": "Identifier", "start": 224, "end": 228, "loc": { "start": { "line": 10, "column": 25 }, "end": { "line": 10, "column": 29 }, "identifierName": "args" }, "name": "args" }, "property": { "type": "NumericLiteral", "start": 229, "end": 230, "loc": { "start": { "line": 10, "column": 30 }, "end": { "line": 10, "column": 31 } }, "extra": { "rawValue": 0, "raw": "0" }, "value": 0 }, "computed": true }, { "type": "Identifier", "start": 233, "end": 236, "loc": { "start": { "line": 10, "column": 34 }, "end": { "line": 10, "column": 37 }, "identifierName": "env" }, "name": "env" }, { "type": "NumericLiteral", "start": 238, "end": 239, "loc": { "start": { "line": 10, "column": 39 }, "end": { "line": 10, "column": 40 } }, "extra": { "rawValue": 1, "raw": "1" }, "value": 1 } ] } } ], "directives": [] } } } }, { "type": "ExpressionStatement", "start": 246, "end": 406, "loc": { "start": { "line": 13, "column": 0 }, "end": { "line": 19, "column": 2 } }, "expression": { "type": "AssignmentExpression", "start": 246, "end": 405, "loc": { "start": { "line": 13, "column": 0 }, "end": { "line": 19, "column": 1 } }, "operator": "=", "left": { "type": "MemberExpression", "start": 246, "end": 264, "loc": { "start": { "line": 13, "column": 0 }, "end": { "line": 13, "column": 18 } }, "object": { "type": "Identifier", "start": 246, "end": 258, "loc": { "start": { "line": 13, "column": 0 }, "end": { "line": 13, "column": 12 }, "identifierName": "SpecialForms" }, "name": "SpecialForms" }, "property": { "type": "StringLiteral", "start": 259, "end": 263, "loc": { "start": { "line": 13, "column": 13 }, "end": { "line": 13, "column": 17 } }, "extra": { "rawValue": "--", "raw": "\"--\"" }, "value": "--" }, "computed": true }, "right": { "type": "ArrowFunctionExpression", "start": 267, "end": 405, "loc": { "start": { "line": 13, "column": 21 }, "end": { "line": 19, "column": 1 } }, "id": null, "generator": false, "expression": false, "async": false, "params": [ { "type": "Identifier", "start": 268, "end": 272, "loc": { "start": { "line": 13, "column": 22 }, "end": { "line": 13, "column": 26 }, "identifierName": "args" }, "name": "args" }, { "type": "Identifier", "start": 274, "end": 277, "loc": { "start": { "line": 13, "column": 28 }, "end": { "line": 13, "column": 31 }, "identifierName": "env" }, "name": "env" } ], "body": { "type": "BlockStatement", "start": 282, "end": 405, "loc": { "start": { "line": 13, "column": 36 }, "end": { "line": 19, "column": 1 } }, "body": [ { "type": "IfStatement", "start": 286, "end": 358, "loc": { "start": { "line": 14, "column": 2 }, "end": { "line": 16, "column": 3 } }, "test": { "type": "BinaryExpression", "start": 290, "end": 307, "loc": { "start": { "line": 14, "column": 6 }, "end": { "line": 14, "column": 23 } }, "left": { "type": "MemberExpression", "start": 290, "end": 301, "loc": { "start": { "line": 14, "column": 6 }, "end": { "line": 14, "column": 17 } }, "object": { "type": "Identifier", "start": 290, "end": 294, "loc": { "start": { "line": 14, "column": 6 }, "end": { "line": 14, "column": 10 }, "identifierName": "args" }, "name": "args" }, "property": { "type": "Identifier", "start": 295, "end": 301, "loc": { "start": { "line": 14, "column": 11 }, "end": { "line": 14, "column": 17 }, "identifierName": "length" }, "name": "length" }, "computed": false }, "operator": "!==", "right": { "type": "NumericLiteral", "start": 306, "end": 307, "loc": { "start": { "line": 14, "column": 22 }, "end": { "line": 14, "column": 23 } }, "extra": { "rawValue": 1, "raw": "1" }, "value": 1 } }, "consequent": { "type": "BlockStatement", "start": 309, "end": 358, "loc": { "start": { "line": 14, "column": 25 }, "end": { "line": 16, "column": 3 } }, "body": [ { "type": "ThrowStatement", "start": 315, "end": 354, "loc": { "start": { "line": 15, "column": 4 }, "end": { "line": 15, "column": 43 } }, "argument": { "type": "NewExpression", "start": 321, "end": 353, "loc": { "start": { "line": 15, "column": 10 }, "end": { "line": 15, "column": 42 } }, "callee": { "type": "Identifier", "start": 325, "end": 336, "loc": { "start": { "line": 15, "column": 14 }, "end": { "line": 15, "column": 25 }, "identifierName": "SyntaxError" }, "name": "SyntaxError" }, "arguments": [ { "type": "StringLiteral", "start": 337, "end": 352, "loc": { "start": { "line": 15, "column": 26 }, "end": { "line": 15, "column": 41 } }, "extra": { "rawValue": "Bad use of --", "raw": "\"Bad use of --\"" }, "value": "Bad use of --" } ] } } ], "directives": [] }, "alternate": null }, { "type": "ReturnStatement", "start": 362, "end": 403, "loc": { "start": { "line": 18, "column": 2 }, "end": { "line": 18, "column": 43 } }, "argument": { "type": "CallExpression", "start": 369, "end": 402, "loc": { "start": { "line": 18, "column": 9 }, "end": { "line": 18, "column": 42 } }, "callee": { "type": "Identifier", "start": 369, "end": 384, "loc": { "start": { "line": 18, "column": 9 }, "end": { "line": 18, "column": 24 }, "identifierName": "incrementHelper" }, "name": "incrementHelper" }, "arguments": [ { "type": "MemberExpression", "start": 385, "end": 392, "loc": { "start": { "line": 18, "column": 25 }, "end": { "line": 18, "column": 32 } }, "object": { "type": "Identifier", "start": 385, "end": 389, "loc": { "start": { "line": 18, "column": 25 }, "end": { "line": 18, "column": 29 }, "identifierName": "args" }, "name": "args" }, "property": { "type": "NumericLiteral", "start": 390, "end": 391, "loc": { "start": { "line": 18, "column": 30 }, "end": { "line": 18, "column": 31 } }, "extra": { "rawValue": 0, "raw": "0" }, "value": 0 }, "computed": true }, { "type": "Identifier", "start": 394, "end": 397, "loc": { "start": { "line": 18, "column": 34 }, "end": { "line": 18, "column": 37 }, "identifierName": "env" }, "name": "env" }, { "type": "UnaryExpression", "start": 399, "end": 401, "loc": { "start": { "line": 18, "column": 39 }, "end": { "line": 18, "column": 41 } }, "operator": "-", "prefix": true, "argument": { "type": "NumericLiteral", "start": 400, "end": 401, "loc": { "start": { "line": 18, "column": 40 }, "end": { "line": 18, "column": 41 } }, "extra": { "rawValue": 1, "raw": "1" }, "value": 1 }, "extra": { "parenthesizedArgument": false } } ] } } ], "directives": [] } } } }, { "type": "ExpressionStatement", "start": 408, "end": 607, "loc": { "start": { "line": 21, "column": 0 }, "end": { "line": 29, "column": 2 } }, "expression": { "type": "AssignmentExpression", "start": 408, "end": 606, "loc": { "start": { "line": 21, "column": 0 }, "end": { "line": 29, "column": 1 } }, "operator": "=", "left": { "type": "MemberExpression", "start": 408, "end": 426, "loc": { "start": { "line": 21, "column": 0 }, "end": { "line": 21, "column": 18 } }, "object": { "type": "Identifier", "start": 408, "end": 420, "loc": { "start": { "line": 21, "column": 0 }, "end": { "line": 21, "column": 12 }, "identifierName": "SpecialForms" }, "name": "SpecialForms" }, "property": { "type": "StringLiteral", "start": 421, "end": 425, "loc": { "start": { "line": 21, "column": 13 }, "end": { "line": 21, "column": 17 } }, "extra": { "rawValue": "+=", "raw": "\"+=\"" }, "value": "+=" }, "computed": true }, "right": { "type": "ArrowFunctionExpression", "start": 429, "end": 606, "loc": { "start": { "line": 21, "column": 21 }, "end": { "line": 29, "column": 1 } }, "id": null, "generator": false, "expression": false, "async": false, "params": [ { "type": "Identifier", "start": 430, "end": 434, "loc": { "start": { "line": 21, "column": 22 }, "end": { "line": 21, "column": 26 }, "identifierName": "args" }, "name": "args" }, { "type": "Identifier", "start": 436, "end": 439, "loc": { "start": { "line": 21, "column": 28 }, "end": { "line": 21, "column": 31 }, "identifierName": "env" }, "name": "env" } ], "body": { "type": "BlockStatement", "start": 444, "end": 606, "loc": { "start": { "line": 21, "column": 36 }, "end": { "line": 29, "column": 1 } }, "body": [ { "type": "IfStatement", "start": 448, "end": 520, "loc": { "start": { "line": 22, "column": 2 }, "end": { "line": 24, "column": 3 } }, "test": { "type": "BinaryExpression", "start": 452, "end": 469, "loc": { "start": { "line": 22, "column": 6 }, "end": { "line": 22, "column": 23 } }, "left": { "type": "MemberExpression", "start": 452, "end": 463, "loc": { "start": { "line": 22, "column": 6 }, "end": { "line": 22, "column": 17 } }, "object": { "type": "Identifier", "start": 452, "end": 456, "loc": { "start": { "line": 22, "column": 6 }, "end": { "line": 22, "column": 10 }, "identifierName": "args" }, "name": "args" }, "property": { "type": "Identifier", "start": 457, "end": 463, "loc": { "start": { "line": 22, "column": 11 }, "end": { "line": 22, "column": 17 }, "identifierName": "length" }, "name": "length" }, "computed": false }, "operator": "!==", "right": { "type": "NumericLiteral", "start": 468, "end": 469, "loc": { "start": { "line": 22, "column": 22 }, "end": { "line": 22, "column": 23 } }, "extra": { "rawValue": 2, "raw": "2" }, "value": 2 } }, "consequent": { "type": "BlockStatement", "start": 471, "end": 520, "loc": { "start": { "line": 22, "column": 25 }, "end": { "line": 24, "column": 3 } }, "body": [ { "type": "ThrowStatement", "start": 477, "end": 516, "loc": { "start": { "line": 23, "column": 4 }, "end": { "line": 23, "column": 43 } }, "argument": { "type": "NewExpression", "start": 483, "end": 515, "loc": { "start": { "line": 23, "column": 10 }, "end": { "line": 23, "column": 42 } }, "callee": { "type": "Identifier", "start": 487, "end": 498, "loc": { "start": { "line": 23, "column": 14 }, "end": { "line": 23, "column": 25 }, "identifierName": "SyntaxError" }, "name": "SyntaxError" }, "arguments": [ { "type": "StringLiteral", "start": 499, "end": 514, "loc": { "start": { "line": 23, "column": 26 }, "end": { "line": 23, "column": 41 } }, "extra": { "rawValue": "Bad use of +=", "raw": "\"Bad use of +=\"" }, "value": "Bad use of +=" } ] } } ], "directives": [] }, "alternate": null }, { "type": "VariableDeclaration", "start": 524, "end": 558, "loc": { "start": { "line": 26, "column": 2 }, "end": { "line": 26, "column": 36 } }, "declarations": [ { "type": "VariableDeclarator", "start": 530, "end": 557, "loc": { "start": { "line": 26, "column": 8 }, "end": { "line": 26, "column": 35 } }, "id": { "type": "Identifier", "start": 530, "end": 533, "loc": { "start": { "line": 26, "column": 8 }, "end": { "line": 26, "column": 11 }, "identifierName": "inc" }, "name": "inc" }, "init": { "type": "CallExpression", "start": 536, "end": 557, "loc": { "start": { "line": 26, "column": 14 }, "end": { "line": 26, "column": 35 } }, "callee": { "type": "MemberExpression", "start": 536, "end": 552, "loc": { "start": { "line": 26, "column": 14 }, "end": { "line": 26, "column": 30 } }, "object": { "type": "MemberExpression", "start": 536, "end": 543, "loc": { "start": { "line": 26, "column": 14 }, "end": { "line": 26, "column": 21 } }, "object": {