spider-src 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +2 -0
- data/Gemfile +7 -0
- data/LICENSE.txt +74 -0
- data/README.md +37 -0
- data/Rakefile +25 -0
- data/lib/spider-src/support/spider/.eslintrc +17 -0
- data/lib/spider-src/support/spider/.npmignore +9 -0
- data/lib/spider-src/support/spider/.travis.yml +7 -0
- data/lib/spider-src/support/spider/.yo-rc.json +3 -0
- data/lib/spider-src/support/spider/CHANGELOG.md +64 -0
- data/lib/spider-src/support/spider/Gruntfile.js +97 -0
- data/lib/spider-src/support/spider/Gruntfile.spider +93 -0
- data/lib/spider-src/support/spider/LICENSE +201 -0
- data/lib/spider-src/support/spider/README.md +50 -0
- data/lib/spider-src/support/spider/cli.js +119 -0
- data/lib/spider-src/support/spider/lib/ast/CaseClause.js +179 -0
- data/lib/spider-src/support/spider/lib/ast/CatchClause.js +26 -0
- data/lib/spider-src/support/spider/lib/ast/ExportBatchSpecifier.js +19 -0
- data/lib/spider-src/support/spider/lib/ast/ExportSpecifier.js +33 -0
- data/lib/spider-src/support/spider/lib/ast/ImportDefaultSpecifier.js +23 -0
- data/lib/spider-src/support/spider/lib/ast/ImportNamespaceSpecifier.js +23 -0
- data/lib/spider-src/support/spider/lib/ast/ImportSpecifier.js +40 -0
- data/lib/spider-src/support/spider/lib/ast/Node.js +93 -0
- data/lib/spider-src/support/spider/lib/ast/Parameter.js +229 -0
- data/lib/spider-src/support/spider/lib/ast/Program.js +58 -0
- data/lib/spider-src/support/spider/lib/ast/Property.js +32 -0
- data/lib/spider-src/support/spider/lib/ast/Range.js +257 -0
- data/lib/spider-src/support/spider/lib/ast/VariableDeclarator.js +29 -0
- data/lib/spider-src/support/spider/lib/ast/expressions/ArrayExpression.js +41 -0
- data/lib/spider-src/support/spider/lib/ast/expressions/ArrayPattern.js +45 -0
- data/lib/spider-src/support/spider/lib/ast/expressions/AssignmentExpression.js +29 -0
- data/lib/spider-src/support/spider/lib/ast/expressions/BinaryExpression.js +104 -0
- data/lib/spider-src/support/spider/lib/ast/expressions/CallExpression.js +139 -0
- data/lib/spider-src/support/spider/lib/ast/expressions/ConditionalExpression.js +31 -0
- data/lib/spider-src/support/spider/lib/ast/expressions/CurryCallExpression.js +102 -0
- data/lib/spider-src/support/spider/lib/ast/expressions/ExistentialExpression.js +83 -0
- data/lib/spider-src/support/spider/lib/ast/expressions/ForInExpression.js +116 -0
- data/lib/spider-src/support/spider/lib/ast/expressions/FunctionExpression.js +157 -0
- data/lib/spider-src/support/spider/lib/ast/expressions/InExpression.js +99 -0
- data/lib/spider-src/support/spider/lib/ast/expressions/LogicalExpression.js +50 -0
- data/lib/spider-src/support/spider/lib/ast/expressions/MemberExpression.js +43 -0
- data/lib/spider-src/support/spider/lib/ast/expressions/NewExpression.js +46 -0
- data/lib/spider-src/support/spider/lib/ast/expressions/NullCheckCallExpression.js +132 -0
- data/lib/spider-src/support/spider/lib/ast/expressions/NullCoalescingExpression.js +114 -0
- data/lib/spider-src/support/spider/lib/ast/expressions/NullPropagatingExpression.js +161 -0
- data/lib/spider-src/support/spider/lib/ast/expressions/ObjectExpression.js +39 -0
- data/lib/spider-src/support/spider/lib/ast/expressions/ObjectPattern.js +49 -0
- data/lib/spider-src/support/spider/lib/ast/expressions/RangeMemberExpression.js +157 -0
- data/lib/spider-src/support/spider/lib/ast/expressions/SplatExpression.js +48 -0
- data/lib/spider-src/support/spider/lib/ast/expressions/SuperExpression.js +170 -0
- data/lib/spider-src/support/spider/lib/ast/expressions/ThisExpression.js +22 -0
- data/lib/spider-src/support/spider/lib/ast/expressions/UnaryExpression.js +147 -0
- data/lib/spider-src/support/spider/lib/ast/expressions/UpdateExpression.js +26 -0
- data/lib/spider-src/support/spider/lib/ast/literals/BooleanLiteral.js +24 -0
- data/lib/spider-src/support/spider/lib/ast/literals/Identifier.js +60 -0
- data/lib/spider-src/support/spider/lib/ast/literals/NullLiteral.js +24 -0
- data/lib/spider-src/support/spider/lib/ast/literals/NumberLiteral.js +24 -0
- data/lib/spider-src/support/spider/lib/ast/literals/RegularExpressionLiteral.js +25 -0
- data/lib/spider-src/support/spider/lib/ast/literals/StringLiteral.js +90 -0
- data/lib/spider-src/support/spider/lib/ast/literals/UndefinedLiteral.js +30 -0
- data/lib/spider-src/support/spider/lib/ast/statements/BlockStatement.js +47 -0
- data/lib/spider-src/support/spider/lib/ast/statements/BreakStatement.js +19 -0
- data/lib/spider-src/support/spider/lib/ast/statements/ContinueStatement.js +19 -0
- data/lib/spider-src/support/spider/lib/ast/statements/DebuggerStatement.js +19 -0
- data/lib/spider-src/support/spider/lib/ast/statements/DoWhileStatement.js +25 -0
- data/lib/spider-src/support/spider/lib/ast/statements/ExportDeclarationStatement.js +51 -0
- data/lib/spider-src/support/spider/lib/ast/statements/ExpressionStatement.js +22 -0
- data/lib/spider-src/support/spider/lib/ast/statements/FallthroughStatement.js +74 -0
- data/lib/spider-src/support/spider/lib/ast/statements/ForInStatement.js +79 -0
- data/lib/spider-src/support/spider/lib/ast/statements/ForOfStatement.js +98 -0
- data/lib/spider-src/support/spider/lib/ast/statements/ForStatement.js +43 -0
- data/lib/spider-src/support/spider/lib/ast/statements/FunctionDeclarationStatement.js +104 -0
- data/lib/spider-src/support/spider/lib/ast/statements/GoStatement.js +41 -0
- data/lib/spider-src/support/spider/lib/ast/statements/IfStatement.js +32 -0
- data/lib/spider-src/support/spider/lib/ast/statements/ImportDeclarationStatement.js +40 -0
- data/lib/spider-src/support/spider/lib/ast/statements/PushStatement.js +37 -0
- data/lib/spider-src/support/spider/lib/ast/statements/ReturnStatement.js +26 -0
- data/lib/spider-src/support/spider/lib/ast/statements/SwitchStatement.js +159 -0
- data/lib/spider-src/support/spider/lib/ast/statements/ThrowStatement.js +22 -0
- data/lib/spider-src/support/spider/lib/ast/statements/TryStatement.js +36 -0
- data/lib/spider-src/support/spider/lib/ast/statements/UntilStatement.js +31 -0
- data/lib/spider-src/support/spider/lib/ast/statements/UseStatement.js +49 -0
- data/lib/spider-src/support/spider/lib/ast/statements/VariableDeclarationStatement.js +36 -0
- data/lib/spider-src/support/spider/lib/ast/statements/WhileStatement.js +25 -0
- data/lib/spider-src/support/spider/lib/ast.js +16 -0
- data/lib/spider-src/support/spider/lib/parser.js +14878 -0
- data/lib/spider-src/support/spider/lib/spider.js +217 -0
- data/lib/spider-src/support/spider/package.json +61 -0
- data/lib/spider-src/support/spider/spider-script.js +6 -0
- data/lib/spider-src/support/spider/src/ast/CaseClause.spider +179 -0
- data/lib/spider-src/support/spider/src/ast/CatchClause.spider +30 -0
- data/lib/spider-src/support/spider/src/ast/ExportBatchSpecifier.spider +19 -0
- data/lib/spider-src/support/spider/src/ast/ExportSpecifier.spider +37 -0
- data/lib/spider-src/support/spider/src/ast/ImportDefaultSpecifier.spider +25 -0
- data/lib/spider-src/support/spider/src/ast/ImportNamespaceSpecifier.spider +25 -0
- data/lib/spider-src/support/spider/src/ast/ImportSpecifier.spider +44 -0
- data/lib/spider-src/support/spider/src/ast/Node.spider +104 -0
- data/lib/spider-src/support/spider/src/ast/Parameter.spider +233 -0
- data/lib/spider-src/support/spider/src/ast/Program.spider +109 -0
- data/lib/spider-src/support/spider/src/ast/Property.spider +36 -0
- data/lib/spider-src/support/spider/src/ast/Range.spider +291 -0
- data/lib/spider-src/support/spider/src/ast/VariableDeclarator.spider +33 -0
- data/lib/spider-src/support/spider/src/ast/expressions/ArrayExpression.spider +32 -0
- data/lib/spider-src/support/spider/src/ast/expressions/ArrayPattern.spider +37 -0
- data/lib/spider-src/support/spider/src/ast/expressions/AssignmentExpression.spider +34 -0
- data/lib/spider-src/support/spider/src/ast/expressions/BinaryExpression.spider +125 -0
- data/lib/spider-src/support/spider/src/ast/expressions/CallExpression.spider +149 -0
- data/lib/spider-src/support/spider/src/ast/expressions/ConditionalExpression.spider +34 -0
- data/lib/spider-src/support/spider/src/ast/expressions/CurryCallExpression.spider +109 -0
- data/lib/spider-src/support/spider/src/ast/expressions/ExistentialExpression.spider +102 -0
- data/lib/spider-src/support/spider/src/ast/expressions/ForInExpression.spider +140 -0
- data/lib/spider-src/support/spider/src/ast/expressions/FunctionExpression.spider +183 -0
- data/lib/spider-src/support/spider/src/ast/expressions/InExpression.spider +114 -0
- data/lib/spider-src/support/spider/src/ast/expressions/LogicalExpression.spider +62 -0
- data/lib/spider-src/support/spider/src/ast/expressions/MemberExpression.spider +57 -0
- data/lib/spider-src/support/spider/src/ast/expressions/NewExpression.spider +40 -0
- data/lib/spider-src/support/spider/src/ast/expressions/NullCheckCallExpression.spider +151 -0
- data/lib/spider-src/support/spider/src/ast/expressions/NullCoalescingExpression.spider +151 -0
- data/lib/spider-src/support/spider/src/ast/expressions/NullPropagatingExpression.spider +190 -0
- data/lib/spider-src/support/spider/src/ast/expressions/ObjectExpression.spider +30 -0
- data/lib/spider-src/support/spider/src/ast/expressions/ObjectPattern.spider +42 -0
- data/lib/spider-src/support/spider/src/ast/expressions/RangeMemberExpression.spider +179 -0
- data/lib/spider-src/support/spider/src/ast/expressions/SplatExpression.spider +49 -0
- data/lib/spider-src/support/spider/src/ast/expressions/SuperExpression.spider +235 -0
- data/lib/spider-src/support/spider/src/ast/expressions/ThisExpression.spider +21 -0
- data/lib/spider-src/support/spider/src/ast/expressions/UnaryExpression.spider +158 -0
- data/lib/spider-src/support/spider/src/ast/expressions/UpdateExpression.spider +28 -0
- data/lib/spider-src/support/spider/src/ast/literals/BooleanLiteral.spider +23 -0
- data/lib/spider-src/support/spider/src/ast/literals/Identifier.spider +68 -0
- data/lib/spider-src/support/spider/src/ast/literals/NullLiteral.spider +23 -0
- data/lib/spider-src/support/spider/src/ast/literals/NumberLiteral.spider +23 -0
- data/lib/spider-src/support/spider/src/ast/literals/RegularExpressionLiteral.spider +24 -0
- data/lib/spider-src/support/spider/src/ast/literals/StringLiteral.spider +91 -0
- data/lib/spider-src/support/spider/src/ast/literals/UndefinedLiteral.spider +30 -0
- data/lib/spider-src/support/spider/src/ast/statements/BlockStatement.spider +45 -0
- data/lib/spider-src/support/spider/src/ast/statements/BreakStatement.spider +19 -0
- data/lib/spider-src/support/spider/src/ast/statements/ContinueStatement.spider +19 -0
- data/lib/spider-src/support/spider/src/ast/statements/DebuggerStatement.spider +19 -0
- data/lib/spider-src/support/spider/src/ast/statements/DoWhileStatement.spider +28 -0
- data/lib/spider-src/support/spider/src/ast/statements/ExportDeclarationStatement.spider +46 -0
- data/lib/spider-src/support/spider/src/ast/statements/ExpressionStatement.spider +22 -0
- data/lib/spider-src/support/spider/src/ast/statements/FallthroughStatement.spider +85 -0
- data/lib/spider-src/support/spider/src/ast/statements/ForInStatement.spider +92 -0
- data/lib/spider-src/support/spider/src/ast/statements/ForOfStatement.spider +117 -0
- data/lib/spider-src/support/spider/src/ast/statements/ForStatement.spider +51 -0
- data/lib/spider-src/support/spider/src/ast/statements/FunctionDeclarationStatement.spider +115 -0
- data/lib/spider-src/support/spider/src/ast/statements/GoStatement.spider +44 -0
- data/lib/spider-src/support/spider/src/ast/statements/IfStatement.spider +38 -0
- data/lib/spider-src/support/spider/src/ast/statements/ImportDeclarationStatement.spider +33 -0
- data/lib/spider-src/support/spider/src/ast/statements/PushStatement.spider +40 -0
- data/lib/spider-src/support/spider/src/ast/statements/ReturnStatement.spider +28 -0
- data/lib/spider-src/support/spider/src/ast/statements/SwitchStatement.spider +161 -0
- data/lib/spider-src/support/spider/src/ast/statements/ThrowStatement.spider +23 -0
- data/lib/spider-src/support/spider/src/ast/statements/TryStatement.spider +42 -0
- data/lib/spider-src/support/spider/src/ast/statements/UntilStatement.spider +36 -0
- data/lib/spider-src/support/spider/src/ast/statements/UseStatement.spider +62 -0
- data/lib/spider-src/support/spider/src/ast/statements/VariableDeclarationStatement.spider +34 -0
- data/lib/spider-src/support/spider/src/ast/statements/WhileStatement.spider +28 -0
- data/lib/spider-src/support/spider/src/ast.spider +80 -0
- data/lib/spider-src/support/spider/src/spider.pegjs +1434 -0
- data/lib/spider-src/support/spider/src/spider.spider +276 -0
- data/lib/spider-src/support/spider/test/spider_test.js +1787 -0
- data/lib/spider-src/version.rb +5 -0
- data/lib/spider-src.rb +37 -0
- data/spider-src.gemspec +24 -0
- data/test/test_spider_src.rb +33 -0
- metadata +225 -0
@@ -0,0 +1,117 @@
|
|
1
|
+
use :node;
|
2
|
+
|
3
|
+
var Node = module.require('../Node').Node,
|
4
|
+
ForInStatement = module.require('./ForInStatement').ForInStatement;
|
5
|
+
|
6
|
+
fn ForOfStatement(key, value, object, body)
|
7
|
+
extends Node {
|
8
|
+
|
9
|
+
this.type = 'ForOfStatement';
|
10
|
+
|
11
|
+
this.key = key;
|
12
|
+
this.key.parent = this;
|
13
|
+
|
14
|
+
this.value = value;
|
15
|
+
if this.value? {
|
16
|
+
this.value.parent = this;
|
17
|
+
}
|
18
|
+
|
19
|
+
this.object = object;
|
20
|
+
this.object.parent = this;
|
21
|
+
|
22
|
+
this.body = body;
|
23
|
+
this.body.parent = this;
|
24
|
+
}
|
25
|
+
|
26
|
+
ForOfStatement.prototype.codegen = () -> {
|
27
|
+
if !super.codegen() {
|
28
|
+
return;
|
29
|
+
}
|
30
|
+
|
31
|
+
this.object = this.object.codegen();
|
32
|
+
|
33
|
+
if this.value? {
|
34
|
+
this.value = this.value.codegen(false);
|
35
|
+
this.body.defineIdentifier(this.value);
|
36
|
+
|
37
|
+
if this.object.hasCallExpression() {
|
38
|
+
var id = {
|
39
|
+
"type": "Identifier",
|
40
|
+
"name": exports.ForOfStatement.getNextVariableName()
|
41
|
+
};
|
42
|
+
|
43
|
+
var context = this.getContext();
|
44
|
+
context.node.body.splice(context.position, 0, {
|
45
|
+
"type": "VariableDeclaration",
|
46
|
+
"declarations": [{
|
47
|
+
"type": "VariableDeclarator",
|
48
|
+
"id": id,
|
49
|
+
"init": this.object
|
50
|
+
}],
|
51
|
+
"kind": "let",
|
52
|
+
"codeGenerated": true
|
53
|
+
});
|
54
|
+
|
55
|
+
this.object = id;
|
56
|
+
}
|
57
|
+
|
58
|
+
this.body.body = [{
|
59
|
+
"type": "VariableDeclaration",
|
60
|
+
"codeGenerated": true,
|
61
|
+
"declarations": [{
|
62
|
+
"type": "VariableDeclarator",
|
63
|
+
"id": this.value,
|
64
|
+
"init": {
|
65
|
+
"type": "MemberExpression",
|
66
|
+
"computed": "true",
|
67
|
+
"object": this.object,
|
68
|
+
"property": this.key
|
69
|
+
}
|
70
|
+
}],
|
71
|
+
"kind": "let",
|
72
|
+
}].concat(this.body.body);
|
73
|
+
}
|
74
|
+
|
75
|
+
var forInLoop = (new ForInStatement(this.key,
|
76
|
+
null,
|
77
|
+
{
|
78
|
+
"type": "CallExpression",
|
79
|
+
"codeGenerated": true,
|
80
|
+
"callee": {
|
81
|
+
"type": "MemberExpression",
|
82
|
+
"computed": false,
|
83
|
+
"object": {
|
84
|
+
"type": "Identifier",
|
85
|
+
"name": "Object"
|
86
|
+
},
|
87
|
+
"property": {
|
88
|
+
"type": "Identifier",
|
89
|
+
"name": "keys"
|
90
|
+
}
|
91
|
+
},
|
92
|
+
"arguments": [this.object]
|
93
|
+
},
|
94
|
+
this.body
|
95
|
+
)).codegen();
|
96
|
+
|
97
|
+
this.type = forInLoop.type;
|
98
|
+
this.right = forInLoop.right;
|
99
|
+
this.left = forInLoop.left;
|
100
|
+
this.each = forInLoop.each;
|
101
|
+
|
102
|
+
return this;
|
103
|
+
};
|
104
|
+
|
105
|
+
ForOfStatement.getNextVariableName = () -> {
|
106
|
+
if (!this.forOfIndex) {
|
107
|
+
this.forOfIndex = 0;
|
108
|
+
}
|
109
|
+
|
110
|
+
return "forOf" + this.forOfIndex++;
|
111
|
+
};
|
112
|
+
|
113
|
+
ForOfStatement.resetVariableNames = () -> {
|
114
|
+
this.forOfIndex = 0;
|
115
|
+
};
|
116
|
+
|
117
|
+
exports.ForOfStatement = ForOfStatement;
|
@@ -0,0 +1,51 @@
|
|
1
|
+
use :node;
|
2
|
+
|
3
|
+
var Node = module.require('../Node').Node;
|
4
|
+
|
5
|
+
fn ForStatement(init, test, update, body)
|
6
|
+
extends Node {
|
7
|
+
|
8
|
+
this.type = 'ForStatement';
|
9
|
+
|
10
|
+
this.init = init;
|
11
|
+
if this.init? {
|
12
|
+
this.init.parent = this;
|
13
|
+
}
|
14
|
+
|
15
|
+
this.test = test;
|
16
|
+
if this.test? {
|
17
|
+
this.test.parent = this;
|
18
|
+
}
|
19
|
+
|
20
|
+
this.update = update;
|
21
|
+
if this.update? {
|
22
|
+
this.update.parent = this;
|
23
|
+
}
|
24
|
+
|
25
|
+
this.body = body;
|
26
|
+
this.body.parent = this;
|
27
|
+
}
|
28
|
+
|
29
|
+
ForStatement.prototype.codegen = () -> {
|
30
|
+
if !super.codegen() {
|
31
|
+
return;
|
32
|
+
}
|
33
|
+
|
34
|
+
if this.init? {
|
35
|
+
this.init = this.init.codegen();
|
36
|
+
}
|
37
|
+
|
38
|
+
if this.test? {
|
39
|
+
this.test = this.test.codegen();
|
40
|
+
}
|
41
|
+
|
42
|
+
if this.update? {
|
43
|
+
this.update = this.update.codegen();
|
44
|
+
}
|
45
|
+
|
46
|
+
this.body = this.body.blockWrap().codegen();
|
47
|
+
|
48
|
+
return this;
|
49
|
+
};
|
50
|
+
|
51
|
+
exports.ForStatement = ForStatement;
|
@@ -0,0 +1,115 @@
|
|
1
|
+
use :node;
|
2
|
+
|
3
|
+
var Node = module.require('../Node').Node,
|
4
|
+
Parameter = module.require('../Parameter').Parameter,
|
5
|
+
CallExpression = module.require('../expressions/CallExpression').CallExpression;
|
6
|
+
|
7
|
+
fn FunctionDeclarationStatement(id, params, body, inheritsFrom)
|
8
|
+
extends Node {
|
9
|
+
|
10
|
+
this.type = 'FunctionDeclaration';
|
11
|
+
this.defaults = [];
|
12
|
+
this.rest = null;
|
13
|
+
this.generator = false;
|
14
|
+
this.expression = false;
|
15
|
+
|
16
|
+
this.id = id;
|
17
|
+
this.id.parent = this;
|
18
|
+
|
19
|
+
this.body = body;
|
20
|
+
this.body.parent = this;
|
21
|
+
|
22
|
+
this.params = params;
|
23
|
+
|
24
|
+
for param in params {
|
25
|
+
param.parent = this;
|
26
|
+
}
|
27
|
+
|
28
|
+
this.inheritsFrom = inheritsFrom;
|
29
|
+
|
30
|
+
if this.inheritsFrom? {
|
31
|
+
this.inheritsFrom.parent = this;
|
32
|
+
}
|
33
|
+
}
|
34
|
+
|
35
|
+
FunctionDeclarationStatement.prototype.codegen = () -> {
|
36
|
+
if !super.codegen() {
|
37
|
+
return;
|
38
|
+
}
|
39
|
+
|
40
|
+
this.id = this.id.codegen();
|
41
|
+
Parameter.generateFunctionBody(this, this.params, this.body, this.defaults);
|
42
|
+
|
43
|
+
this.body = this.body.codegen();
|
44
|
+
|
45
|
+
if this.inheritsFrom? {
|
46
|
+
if this.inheritsFrom.type != 'CallExpression' {
|
47
|
+
this.inheritsFrom = new CallExpression(this.inheritsFrom, []);
|
48
|
+
this.inheritsFrom.parent = this;
|
49
|
+
}
|
50
|
+
|
51
|
+
this.inheritsFrom = this.inheritsFrom.codegen();
|
52
|
+
|
53
|
+
this.body.body.splice(0, 0, {
|
54
|
+
"type": "ExpressionStatement",
|
55
|
+
"expression": {
|
56
|
+
"type": "CallExpression",
|
57
|
+
"callee": {
|
58
|
+
"type": "MemberExpression",
|
59
|
+
"computed": false,
|
60
|
+
"object": this.inheritsFrom.callee,
|
61
|
+
"property": {
|
62
|
+
"type": "Identifier",
|
63
|
+
"name": "call"
|
64
|
+
}
|
65
|
+
},
|
66
|
+
"arguments": [
|
67
|
+
{ "type": "ThisExpression" }
|
68
|
+
].concat(this.inheritsFrom.arguments)
|
69
|
+
}
|
70
|
+
});
|
71
|
+
|
72
|
+
var context = this.getContext();
|
73
|
+
context.node.body.splice(context.position + 1, 0, {
|
74
|
+
"type": "ExpressionStatement",
|
75
|
+
"codeGenerated": "true",
|
76
|
+
"expression": {
|
77
|
+
"type": "AssignmentExpression",
|
78
|
+
"operator": "=",
|
79
|
+
"left": {
|
80
|
+
"type": "MemberExpression",
|
81
|
+
"computed": false,
|
82
|
+
"object": this.id,
|
83
|
+
"property": {
|
84
|
+
"type": "Identifier",
|
85
|
+
"name": "prototype"
|
86
|
+
}
|
87
|
+
},
|
88
|
+
"right": {
|
89
|
+
"type": "CallExpression",
|
90
|
+
"callee": {
|
91
|
+
"type": "MemberExpression",
|
92
|
+
"computed": false,
|
93
|
+
"object": {
|
94
|
+
"type": "Identifier",
|
95
|
+
"name": "Object"
|
96
|
+
},
|
97
|
+
"property": {
|
98
|
+
"type": "Identifier",
|
99
|
+
"name": "create"
|
100
|
+
}
|
101
|
+
},
|
102
|
+
"arguments": [
|
103
|
+
this.inheritsFrom.callee
|
104
|
+
]
|
105
|
+
}
|
106
|
+
}
|
107
|
+
});
|
108
|
+
}
|
109
|
+
|
110
|
+
return this;
|
111
|
+
};
|
112
|
+
|
113
|
+
FunctionDeclarationStatement.prototype.hasCallExpression = () -> true;
|
114
|
+
|
115
|
+
exports.FunctionDeclarationStatement = FunctionDeclarationStatement;
|
@@ -0,0 +1,44 @@
|
|
1
|
+
use :node;
|
2
|
+
|
3
|
+
var Node = module.require('../Node').Node;
|
4
|
+
|
5
|
+
fn GoStatement(body)
|
6
|
+
extends Node {
|
7
|
+
|
8
|
+
this.type = 'GoStatement';
|
9
|
+
|
10
|
+
this.body = body;
|
11
|
+
this.body.parent = this;
|
12
|
+
}
|
13
|
+
|
14
|
+
GoStatement.prototype.codegen = () -> {
|
15
|
+
if !super.codegen() {
|
16
|
+
return;
|
17
|
+
}
|
18
|
+
|
19
|
+
this.body = this.body.codegen();
|
20
|
+
|
21
|
+
this.type = "ExpressionStatement";
|
22
|
+
this.expression = {
|
23
|
+
"type": "CallExpression",
|
24
|
+
"callee": {
|
25
|
+
"type": "UnaryExpression",
|
26
|
+
"operator": "async",
|
27
|
+
"argument": {
|
28
|
+
"type": "FunctionExpression",
|
29
|
+
"id": null,
|
30
|
+
"params": [],
|
31
|
+
"defaults": [],
|
32
|
+
"body": this.body,
|
33
|
+
"rest": null,
|
34
|
+
"generator": false,
|
35
|
+
"expression": false
|
36
|
+
}
|
37
|
+
},
|
38
|
+
"arguments": []
|
39
|
+
};
|
40
|
+
|
41
|
+
return this;
|
42
|
+
};
|
43
|
+
|
44
|
+
exports.GoStatement = GoStatement;
|
@@ -0,0 +1,38 @@
|
|
1
|
+
use :node;
|
2
|
+
|
3
|
+
var Node = module.require('../Node').Node;
|
4
|
+
|
5
|
+
fn IfStatement(test, consequent, alternate)
|
6
|
+
extends Node {
|
7
|
+
|
8
|
+
this.type = 'IfStatement';
|
9
|
+
|
10
|
+
this.test = test;
|
11
|
+
this.test.parent = this;
|
12
|
+
|
13
|
+
this.consequent = consequent;
|
14
|
+
this.consequent.parent = this;
|
15
|
+
|
16
|
+
this.alternate = alternate;
|
17
|
+
|
18
|
+
if this.alternate? {
|
19
|
+
this.alternate.parent = this;
|
20
|
+
}
|
21
|
+
}
|
22
|
+
|
23
|
+
IfStatement.prototype.codegen = () -> {
|
24
|
+
if !super.codegen() {
|
25
|
+
return;
|
26
|
+
}
|
27
|
+
|
28
|
+
this.test = this.test.codegen();
|
29
|
+
this.consequent = this.consequent.blockWrap().codegen();
|
30
|
+
|
31
|
+
if this.alternate? {
|
32
|
+
this.alternate = this.alternate.blockWrap().codegen();
|
33
|
+
}
|
34
|
+
|
35
|
+
return this;
|
36
|
+
};
|
37
|
+
|
38
|
+
exports.IfStatement = IfStatement;
|
@@ -0,0 +1,33 @@
|
|
1
|
+
use :node;
|
2
|
+
|
3
|
+
var Node = module.require('../Node').Node;
|
4
|
+
|
5
|
+
fn ImportDeclarationStatement(specifiers, source, kind)
|
6
|
+
extends Node {
|
7
|
+
|
8
|
+
this.type = "ImportDeclaration";
|
9
|
+
this.kind = kind;
|
10
|
+
|
11
|
+
this.specifiers = specifiers;
|
12
|
+
for specifier in this.specifiers {
|
13
|
+
specifier.parent = this;
|
14
|
+
}
|
15
|
+
|
16
|
+
this.source = source;
|
17
|
+
this.source.parent = this;
|
18
|
+
}
|
19
|
+
|
20
|
+
ImportDeclarationStatement.prototype.codegen = () -> {
|
21
|
+
if !super.codegen() {
|
22
|
+
return;
|
23
|
+
}
|
24
|
+
|
25
|
+
for specifier, i in this.specifiers {
|
26
|
+
this.specifiers[i] = specifier.codegen();
|
27
|
+
}
|
28
|
+
|
29
|
+
this.source = this.source.codegen();
|
30
|
+
return this;
|
31
|
+
};
|
32
|
+
|
33
|
+
exports.ImportDeclarationStatement = ImportDeclarationStatement;
|
@@ -0,0 +1,40 @@
|
|
1
|
+
use :node;
|
2
|
+
|
3
|
+
var Node = module.require('../Node').Node;
|
4
|
+
|
5
|
+
fn PushStatement(left, right)
|
6
|
+
extends Node {
|
7
|
+
|
8
|
+
this.type = 'PushStatement';
|
9
|
+
|
10
|
+
this.left = left;
|
11
|
+
this.left.parent = this;
|
12
|
+
|
13
|
+
this.right = right;
|
14
|
+
this.right.parent = this;
|
15
|
+
}
|
16
|
+
|
17
|
+
PushStatement.prototype.codegen = () -> {
|
18
|
+
if !super.codegen() {
|
19
|
+
return;
|
20
|
+
}
|
21
|
+
|
22
|
+
this.type = "ExpressionStatement";
|
23
|
+
this.expression = {
|
24
|
+
"type": "CallExpression",
|
25
|
+
"callee": {
|
26
|
+
"type": "MemberExpression",
|
27
|
+
"object": this.left.codegen(),
|
28
|
+
"property": {
|
29
|
+
"type": "Identifier",
|
30
|
+
"name": "push"
|
31
|
+
},
|
32
|
+
"computed": false
|
33
|
+
},
|
34
|
+
"arguments": [this.right.codegen()]
|
35
|
+
};
|
36
|
+
|
37
|
+
return this;
|
38
|
+
};
|
39
|
+
|
40
|
+
exports.PushStatement = PushStatement;
|
@@ -0,0 +1,28 @@
|
|
1
|
+
use :node;
|
2
|
+
|
3
|
+
var Node = module.require('../Node').Node;
|
4
|
+
|
5
|
+
fn ReturnStatement(argument)
|
6
|
+
extends Node {
|
7
|
+
|
8
|
+
this.type = 'ReturnStatement';
|
9
|
+
this.argument = argument;
|
10
|
+
|
11
|
+
if this.argument? {
|
12
|
+
this.argument.parent = this;
|
13
|
+
}
|
14
|
+
}
|
15
|
+
|
16
|
+
ReturnStatement.prototype.codegen = () -> {
|
17
|
+
if !super.codegen() {
|
18
|
+
return;
|
19
|
+
}
|
20
|
+
|
21
|
+
if this.argument? {
|
22
|
+
this.argument = this.argument.codegen();
|
23
|
+
}
|
24
|
+
|
25
|
+
return this;
|
26
|
+
};
|
27
|
+
|
28
|
+
exports.ReturnStatement = ReturnStatement;
|
@@ -0,0 +1,161 @@
|
|
1
|
+
use :node;
|
2
|
+
|
3
|
+
var Node = module.require('../Node').Node;
|
4
|
+
|
5
|
+
fn SwitchStatement(discriminant, cases)
|
6
|
+
extends Node {
|
7
|
+
|
8
|
+
this.type = 'SwitchStatement';
|
9
|
+
|
10
|
+
this.discriminant = discriminant;
|
11
|
+
this.discriminant.parent = this;
|
12
|
+
|
13
|
+
this.cases = cases;
|
14
|
+
|
15
|
+
for caseClause in this.cases {
|
16
|
+
caseClause.parent = this;
|
17
|
+
}
|
18
|
+
}
|
19
|
+
|
20
|
+
SwitchStatement.prototype.codegen = () -> {
|
21
|
+
if !super.codegen() {
|
22
|
+
return;
|
23
|
+
}
|
24
|
+
|
25
|
+
var context = this.getContext();
|
26
|
+
var firstCase, currentCase, defaultCase;
|
27
|
+
var fallthroughPosition = 1;
|
28
|
+
|
29
|
+
this.discriminant = this.discriminant.codegen();
|
30
|
+
|
31
|
+
if this.discriminant.hasCallExpression() {
|
32
|
+
var id = {
|
33
|
+
"type": "Identifier",
|
34
|
+
"name": SwitchStatement.getNextVariableName()
|
35
|
+
};
|
36
|
+
|
37
|
+
context.node.body.splice(context.position, 0, {
|
38
|
+
"type": "VariableDeclaration",
|
39
|
+
"codeGenerated": true,
|
40
|
+
"declarations": [{
|
41
|
+
"type": "VariableDeclarator",
|
42
|
+
"id": id,
|
43
|
+
"init": this.discriminant
|
44
|
+
}],
|
45
|
+
"kind": "let"
|
46
|
+
});
|
47
|
+
|
48
|
+
this.discriminant = id;
|
49
|
+
}
|
50
|
+
|
51
|
+
var hasFallthrough = false;
|
52
|
+
|
53
|
+
for caseClause in this.cases {
|
54
|
+
if (!caseClause.tests) {
|
55
|
+
defaultCase = caseClause;
|
56
|
+
break;
|
57
|
+
}
|
58
|
+
|
59
|
+
if !firstCase? {
|
60
|
+
firstCase = caseClause.codegen();
|
61
|
+
currentCase = firstCase;
|
62
|
+
} else {
|
63
|
+
if currentCase.fallthrough {
|
64
|
+
hasFallthrough = true;
|
65
|
+
currentCase = caseClause.codegen(this.branchFallthrough);
|
66
|
+
context.node.body.splice(context.position + fallthroughPosition++, 0, currentCase);
|
67
|
+
} else {
|
68
|
+
currentCase.alternate = caseClause.codegen(this.fallthroughId?);
|
69
|
+
currentCase = currentCase.alternate;
|
70
|
+
}
|
71
|
+
}
|
72
|
+
}
|
73
|
+
|
74
|
+
if hasFallthrough {
|
75
|
+
for caseClause in this.cases {
|
76
|
+
if !caseClause.fallthrough and caseClause != defaultCase {
|
77
|
+
caseClause.body.body = [{
|
78
|
+
"type": "ExpressionStatement",
|
79
|
+
"codeGenerated": true,
|
80
|
+
"expression": {
|
81
|
+
"type": "AssignmentExpression",
|
82
|
+
"operator": "=",
|
83
|
+
"left": this.fallthroughId,
|
84
|
+
"right": {
|
85
|
+
"type": "Literal",
|
86
|
+
"value": 2
|
87
|
+
}
|
88
|
+
}
|
89
|
+
}].concat(caseClause.body.body);
|
90
|
+
}
|
91
|
+
}
|
92
|
+
}
|
93
|
+
|
94
|
+
if defaultCase? {
|
95
|
+
if !firstCase? {
|
96
|
+
Node.getErrorManager().error({
|
97
|
+
type: "SingleDefaultClause",
|
98
|
+
message: "default clause without other case clauses is disallowed.",
|
99
|
+
loc: defaultCase.loc
|
100
|
+
});
|
101
|
+
} else {
|
102
|
+
if currentCase.fallthrough {
|
103
|
+
defaultCase = defaultCase.codegen(this.fallthroughId?);
|
104
|
+
defaultCase.codeGenerated = true;
|
105
|
+
if this.fallthroughId? {
|
106
|
+
context.node.body.splice(context.position + fallthroughPosition++, 0, defaultCase);
|
107
|
+
} else {
|
108
|
+
for statement in defaultCase.body {
|
109
|
+
context.node.body.splice(context.position + fallthroughPosition++, 0, statement);
|
110
|
+
}
|
111
|
+
}
|
112
|
+
} else {
|
113
|
+
currentCase.alternate = defaultCase.codegen(this.fallthroughId?);
|
114
|
+
}
|
115
|
+
}
|
116
|
+
}
|
117
|
+
|
118
|
+
if this.fallthroughId? {
|
119
|
+
context.node.body.splice(context.position, 0, {
|
120
|
+
"type": "VariableDeclaration",
|
121
|
+
"codeGenerated": true,
|
122
|
+
"declarations": [
|
123
|
+
{
|
124
|
+
"type": "VariableDeclarator",
|
125
|
+
"id": this.fallthroughId,
|
126
|
+
"init": {
|
127
|
+
"type": "Literal",
|
128
|
+
"value": 0
|
129
|
+
}
|
130
|
+
}
|
131
|
+
],
|
132
|
+
"kind": "let"
|
133
|
+
});
|
134
|
+
}
|
135
|
+
|
136
|
+
if !firstCase? {
|
137
|
+
this.type = "ExpressionStatement";
|
138
|
+
this.expression = this.discriminant;
|
139
|
+
} else {
|
140
|
+
this.type = firstCase.type;
|
141
|
+
this.test = firstCase.test;
|
142
|
+
this.consequent = firstCase.consequent;
|
143
|
+
this.alternate = firstCase.alternate;
|
144
|
+
}
|
145
|
+
|
146
|
+
return this;
|
147
|
+
};
|
148
|
+
|
149
|
+
SwitchStatement.getNextVariableName = () -> {
|
150
|
+
if !this.switchStatementIndex? {
|
151
|
+
this.switchStatementIndex = 0;
|
152
|
+
}
|
153
|
+
|
154
|
+
return "switchStatement" + this.switchStatementIndex++;
|
155
|
+
};
|
156
|
+
|
157
|
+
SwitchStatement.resetVariableNames = () -> {
|
158
|
+
this.switchStatementIndex = 0;
|
159
|
+
};
|
160
|
+
|
161
|
+
exports.SwitchStatement = SwitchStatement;
|
@@ -0,0 +1,23 @@
|
|
1
|
+
use :node;
|
2
|
+
|
3
|
+
var Node = module.require('../Node').Node;
|
4
|
+
|
5
|
+
fn ThrowStatement(argument)
|
6
|
+
extends Node {
|
7
|
+
|
8
|
+
this.type = 'ThrowStatement';
|
9
|
+
|
10
|
+
this.argument = argument;
|
11
|
+
this.argument.parent = this;
|
12
|
+
}
|
13
|
+
|
14
|
+
ThrowStatement.prototype.codegen = () -> {
|
15
|
+
if !super.codegen() {
|
16
|
+
return;
|
17
|
+
}
|
18
|
+
|
19
|
+
this.argument = this.argument.codegen();
|
20
|
+
return this;
|
21
|
+
};
|
22
|
+
|
23
|
+
exports.ThrowStatement = ThrowStatement;
|
@@ -0,0 +1,42 @@
|
|
1
|
+
use :node;
|
2
|
+
|
3
|
+
var Node = module.require('../Node').Node;
|
4
|
+
|
5
|
+
fn TryStatement(block, handler, finalizer)
|
6
|
+
extends Node {
|
7
|
+
|
8
|
+
this.type = 'TryStatement';
|
9
|
+
|
10
|
+
this.block = block;
|
11
|
+
this.block.parent = this;
|
12
|
+
|
13
|
+
this.handler = handler;
|
14
|
+
if this.handler? {
|
15
|
+
this.handler.parent = this;
|
16
|
+
}
|
17
|
+
|
18
|
+
this.finalizer = finalizer;
|
19
|
+
if this.finalizer? {
|
20
|
+
this.finalizer.parent = this;
|
21
|
+
}
|
22
|
+
}
|
23
|
+
|
24
|
+
TryStatement.prototype.codegen = () -> {
|
25
|
+
if !super.codegen() {
|
26
|
+
return;
|
27
|
+
}
|
28
|
+
|
29
|
+
this.block = this.block.codegen();
|
30
|
+
|
31
|
+
if this.handler? {
|
32
|
+
this.handler = this.handler.codegen();
|
33
|
+
}
|
34
|
+
|
35
|
+
if this.finalizer? {
|
36
|
+
this.finalizer = this.finalizer.codegen();
|
37
|
+
}
|
38
|
+
|
39
|
+
return this;
|
40
|
+
};
|
41
|
+
|
42
|
+
exports.TryStatement = TryStatement;
|