CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-babel--plugin-transform-block-scoped-functions

Babel plugin to ensure function declarations at the block level are block scoped

89

1.04x
Overview
Eval results
Files

task.mdevals/scenario-7/

Function Declaration Context Analyzer

A Babel plugin that analyzes function declarations and identifies their parent context by traversing the AST structure.

Capabilities

Analyzes function declarations in different contexts

  • Given code { function foo() {} }, the plugin reports {name: "foo", context: "block"} @test
  • Given code function outer() { function inner() {} }, the plugin reports {name: "inner", context: "function-body"} for the inner function @test
  • Given code export function bar() {}, the plugin reports {name: "bar", context: "export"} @test

Detects function properties

  • Given code { async function fetchData() {} }, the plugin reports {name: "fetchData", context: "block", async: true} @test
  • Given code { function* generator() {} }, the plugin reports {name: "generator", context: "block", generator: true} @test

Implementation

@generates

API

/**
 * Creates a Babel plugin that analyzes function declarations and their parent context.
 *
 * The plugin collects analysis results that can be accessed via the plugin state.
 *
 * Each result object contains:
 * - name: string - the function name
 * - context: string - one of "block", "function-body", or "export"
 * - async: boolean - whether the function is async (default: false)
 * - generator: boolean - whether the function is a generator (default: false)
 *
 * @returns {Object} Babel plugin object with visitor methods
 */
export default function analyzerPlugin() {
  return {
    name: "function-declaration-context-analyzer",
    visitor: {
      // Visitor methods to implement
    }
  };
}

Dependencies { .dependencies }

@babel/core { .dependency }

Provides the Babel plugin system and AST types for code transformation and analysis.

Install with Tessl CLI

npx tessl i tessl/npm-babel--plugin-transform-block-scoped-functions

tile.json