UNPKG

3.74 kBJavaScriptView Raw
1(function() {
2 var self = this;
3 module.exports = function(terms) {
4 var self = this;
5 var moduleTerm, module;
6 moduleTerm = terms.term({
7 constructor: function(statements, gen1_options) {
8 var self = this;
9 var global, returnLastStatement, bodyStatements;
10 global = gen1_options !== void 0 && Object.prototype.hasOwnProperty.call(gen1_options, "global") && gen1_options.global !== void 0 ? gen1_options.global : false;
11 returnLastStatement = gen1_options !== void 0 && Object.prototype.hasOwnProperty.call(gen1_options, "returnLastStatement") && gen1_options.returnLastStatement !== void 0 ? gen1_options.returnLastStatement : false;
12 bodyStatements = gen1_options !== void 0 && Object.prototype.hasOwnProperty.call(gen1_options, "bodyStatements") && gen1_options.bodyStatements !== void 0 ? gen1_options.bodyStatements : void 0;
13 self.statements = statements;
14 self.isModule = true;
15 self.global = global;
16 return self.bodyStatements = bodyStatements || statements;
17 },
18 generateModule: function() {
19 var self = this;
20 var scope;
21 scope = new terms.SymbolScope(void 0);
22 return self.code(self.statements.generateStatements(scope, {
23 global: self.global,
24 inClosure: true
25 }));
26 }
27 });
28 return module = function(statements, gen2_options) {
29 var inScope, global, returnLastStatement, bodyStatements;
30 inScope = gen2_options !== void 0 && Object.prototype.hasOwnProperty.call(gen2_options, "inScope") && gen2_options.inScope !== void 0 ? gen2_options.inScope : true;
31 global = gen2_options !== void 0 && Object.prototype.hasOwnProperty.call(gen2_options, "global") && gen2_options.global !== void 0 ? gen2_options.global : false;
32 returnLastStatement = gen2_options !== void 0 && Object.prototype.hasOwnProperty.call(gen2_options, "returnLastStatement") && gen2_options.returnLastStatement !== void 0 ? gen2_options.returnLastStatement : false;
33 bodyStatements = gen2_options !== void 0 && Object.prototype.hasOwnProperty.call(gen2_options, "bodyStatements") && gen2_options.bodyStatements !== void 0 ? gen2_options.bodyStatements : bodyStatements;
34 var scope, args, methodCall, call;
35 if (returnLastStatement) {
36 statements.rewriteLastStatementToReturn({
37 async: false
38 });
39 }
40 if (inScope) {
41 scope = terms.closure([], statements, {
42 returnLastStatement: returnLastStatement,
43 redefinesSelf: true,
44 definesModuleConstants: true
45 });
46 args = [ terms.variable([ "this" ]) ];
47 methodCall = terms.methodCall(terms.subExpression(scope), [ "call" ], args);
48 call = function() {
49 if (statements.isAsync) {
50 return methodCall;
51 } else {
52 return methodCall;
53 }
54 }();
55 return moduleTerm(terms.statements([ call ]), {
56 bodyStatements: statements,
57 global: global
58 });
59 } else {
60 return moduleTerm(statements, {
61 global: global,
62 returnLastStatement: returnLastStatement,
63 bodyStatements: bodyStatements
64 });
65 }
66 };
67 };
68}).call(this);
\No newline at end of file