Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | 2x 2x 2x 2x 2x 29x 29x 2x 29x 29x 29x 29x | const SEPARATION_STRING = '\n/* End of support code */\n\n' const recast = require("recast"); const Support = require("./support-lib.js"); const path = require('path'); /* INLINE SUPPORT CODE const functionTemplate = (name, fun) => `const ${name} = ${fun.toString()};\n`; function buildSupportCode(dependencies) { let code = ''; for (let name of dependencies) { code += functionTemplate(name, Support[name]); } code += SEPARATION_STRING; //console.error('code:', code) return code; } module.exports = function codeGen(ast) { let fullPath = path.join(__dirname, 'complex.js'); let preamble = `#!/usr/bin/env node const Complex = require("${fullPath}"); `; preamble += buildSupportCode(ast.dependencies); let output = preamble+recast.print(ast.ast).code; return output; } */ /** * Generates a template for code generation. * * @param {Array} dependencies - The list of dependencies. * @param {string} fullPath - The full path of the file. * @param {string} code - The code to be generated. * @returns {string} - The generated template. */ let template = (dependencies, fullPath, code) => { Iif (dependencies.length === 0) { return code; } return `#!/usr/bin/env node const { ${dependencies} } = require("${fullPath}"); ${SEPARATION_STRING} ${code} ` }; module.exports = function codeGen(ast) { let fullPath = path.join(__dirname, 'support-lib.js'); let dependencies = Array.from(ast.dependencies).join(", "); let output = template(dependencies, fullPath, recast.print(ast.ast).code); return output; } |