CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-babel-plugin-transform-es2015-computed-properties

Babel plugin that compiles ES2015 computed properties to ES5-compatible code

88

1.07x
Overview
Eval results
Files

task.mdevals/scenario-1/

Object Literal Temporary Variable Generator

Build a Babel plugin helper that generates unique temporary variable names for object literal transformations, avoiding conflicts with existing variables in the current scope.

Requirements

When transforming object literals with computed properties in Babel, you often need to create temporary variables to hold the object being constructed. This utility should generate these temporary variable names intelligently by:

  1. Taking a Babel AST node representing an object literal
  2. Taking a Babel Scope object representing the current scope
  3. Generating a unique identifier name (starting with "_obj") that doesn't conflict with any existing bindings in the scope
  4. If "_obj" is already used in the scope, automatically generating "_obj2", "_obj3", etc. until finding an available name
  5. Returning the generated unique identifier name as a string

Implementation

@generates

API

/**
 * Generates a unique temporary variable name for an object literal node
 * @param {Object} node - Babel AST node (ObjectExpression)
 * @param {Object} scope - Babel Scope object for checking existing bindings
 * @returns {string} A unique variable name (e.g., "_obj", "_obj2", "_obj3")
 */
function generateTempVarName(node, scope) {
  // Implementation here
}

module.exports = { generateTempVarName };

Test Cases

  • Given an object literal node and a scope with no "_obj" binding, returns "_obj" @test
  • Given an object literal node and a scope where "_obj" is already bound, returns "_obj2" @test
  • Given a scope with bindings for "_obj", "_obj2", and "_obj3", returns "_obj4" @test

Dependencies { .dependencies }

@babel/plugin-transform-computed-properties { .dependency }

Provides examples and patterns for scope-aware variable generation when transforming computed properties.

@satisfied-by

Install with Tessl CLI

npx tessl i tessl/npm-babel-plugin-transform-es2015-computed-properties

tile.json