Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions Alloy/commands/compile/ast/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ exports.processController = function(code, file, isProduction = false) {
var baseController = '',
moduleCodes = '',
newCode = '',
preCode = '',
exportSpecifiers = [];

if (isProduction) {
Expand Down Expand Up @@ -42,10 +43,20 @@ exports.processController = function(code, file, isProduction = false) {
}).setContext();
traverse(ast, {
enter: function(path) {
if (types.isAssignmentExpression(path.node) && isBaseControllerExportExpression(path.node.left)) {
var node = path.node;
if (types.isAssignmentExpression(node) && isBaseControllerExportExpression(node.left)) {
// what's equivalent of print_to_string()? I replaced with simple value property assuming it's a string literal
baseController = '\'' + path.node.right.value + '\'';
}

// find function named __pre
if (node.type === 'FunctionDeclaration') {
if (node.id.name == '__pre') {
// put function code into preCode
preCode += generate(node.body, GENCODE_OPTIONS).code;
path.remove();
}
}
},

ImportDeclaration: function(path) {
Expand Down Expand Up @@ -95,6 +106,7 @@ exports.processController = function(code, file, isProduction = false) {
return {
es6mods: moduleCodes,
base: baseController,
code: newCode
code: newCode,
pre: preCode.trim()
};
};
1 change: 1 addition & 0 deletions Alloy/commands/compile/compilerUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -958,6 +958,7 @@ exports.loadController = function(file) {
code.controller = controller.code;
code.parentControllerName = controller.base;
code.es6mods = controller.es6mods;
code.pre = controller.pre;

return code;
};
Expand Down