From 6a5b7a542418c6f1ef74283e05be73625a05715c Mon Sep 17 00:00:00 2001 From: m1ga Date: Wed, 2 Apr 2025 11:04:45 +0200 Subject: [PATCH 1/2] feat: pre UI code --- Alloy/commands/compile/ast/controller.js | 16 ++++++++++++++-- Alloy/commands/compile/compilerUtils.js | 1 + 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/Alloy/commands/compile/ast/controller.js b/Alloy/commands/compile/ast/controller.js index 82af33902..4f1d55bb1 100644 --- a/Alloy/commands/compile/ast/controller.js +++ b/Alloy/commands/compile/ast/controller.js @@ -14,6 +14,7 @@ exports.processController = function(code, file) { var baseController = '', moduleCodes = '', newCode = '', + preCode = '', exportSpecifiers = []; try { @@ -38,10 +39,20 @@ exports.processController = function(code, file) { }).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) { @@ -91,6 +102,7 @@ exports.processController = function(code, file) { return { es6mods: moduleCodes, base: baseController, - code: newCode + code: newCode, + pre: preCode.trim() }; }; diff --git a/Alloy/commands/compile/compilerUtils.js b/Alloy/commands/compile/compilerUtils.js index 922d1fdf1..3039a1720 100755 --- a/Alloy/commands/compile/compilerUtils.js +++ b/Alloy/commands/compile/compilerUtils.js @@ -957,6 +957,7 @@ exports.loadController = function(file) { code.controller = controller.code; code.parentControllerName = controller.base; code.es6mods = controller.es6mods; + code.pre = controller.pre; return code; }; From cbe14a0fcf6d7c9f40a3e386a88b669bdff8c4cf Mon Sep 17 00:00:00 2001 From: m1ga Date: Wed, 2 Apr 2025 11:07:54 +0200 Subject: [PATCH 2/2] lint --- Alloy/commands/compile/ast/controller.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Alloy/commands/compile/ast/controller.js b/Alloy/commands/compile/ast/controller.js index 4f1d55bb1..46afe30a8 100644 --- a/Alloy/commands/compile/ast/controller.js +++ b/Alloy/commands/compile/ast/controller.js @@ -47,12 +47,12 @@ exports.processController = function(code, file) { // 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(); - } - } + if (node.id.name == '__pre') { + // put function code into preCode + preCode += generate(node.body, GENCODE_OPTIONS).code; + path.remove(); + } + } }, ImportDeclaration: function(path) {