ECMAScript code generator that transforms Mozilla's Parser API ASTs back into executable JavaScript code
95
A utility that transforms JavaScript Abstract Syntax Trees (ASTs) into properly parenthesized JavaScript code based on operator precedence rules.
1 + 2 * 3, generates the code 1 + 2 * 3 without unnecessary parentheses @test(1 + 2) * 3, generates the code (1 + 2) * 3 with required parentheses @testa + b * c vs (a + b) * c) @test2 ** 3 ** 4 vs (2 ** 3) ** 4) @test1 + 2, generates code with explicit parentheses like (1 + 2) for clarity @test1 + 2 without optional parentheses @test(a ?? b) && c or a ?? (b && c)) @test@generates
/**
* Generates JavaScript code from an AST with proper parenthesization.
*
* @param {Object} ast - The Abstract Syntax Tree node (Mozilla Parser API format)
* @param {Object} options - Generation options
* @param {boolean} [options.parentheses] - If true, includes optional parentheses for clarity; if false, uses minimal parentheses
* @returns {string} The generated JavaScript code
*/
function generateWithParentheses(ast, options) {
// IMPLEMENTATION HERE
}
module.exports = {
generateWithParentheses
};Provides code generation from AST with operator precedence handling.
Install with Tessl CLI
npx tessl i tessl/npm-escodegendocs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10