Babel's modular runtime helpers that provide transpilation support for modern JavaScript features
94
Build a JavaScript code transformation utility that safely transforms code while preserving the original Abstract Syntax Tree (AST) for comparison purposes.
Create a module that exports a function transformWithComparison that:
var declarations to const declarationsoriginal: The original, unmodified AST (must remain unchanged even after transformation)transformed: The transformed JavaScript code as a stringwasModified: A boolean indicating whether any var-to-const transformations occurredThe original AST must remain completely unmodified after the transformation completes, preserving its initial state for comparison purposes.
@generates
/**
* Transforms JavaScript code while preserving the original AST.
*
* @param {string} sourceCode - The JavaScript source code to transform
* @returns {Object} An object with original AST, transformed code, and modification status
* @returns {Object} returns.original - The original, unmodified AST
* @returns {string} returns.transformed - The transformed JavaScript code
* @returns {boolean} returns.wasModified - Whether any transformations were applied
*/
function transformWithComparison(sourceCode) {
// Implementation
}
module.exports = { transformWithComparison };var x = 1;, the function returns an object where transformed is const x = 1;, wasModified is true, and original is an unmodified AST @testconst y = 2; (already using const), the function returns wasModified as false and transformed equals the input @testProvides JavaScript transformation and parsing capabilities with AST cloning support.
@satisfied-by
Install with Tessl CLI
npx tessl i tessl/npm-babel--runtimedocs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10