CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-babel-plugin-transform-eval

Babel plugin that transforms eval() calls containing string literals by parsing and compiling the string content at transform time

Overall
score

98%

Overview
Eval results
Files

task.mdevals/scenario-10/

Node.js Built-in Polyfill Mapper

A Babel plugin that automatically maps Node.js built-in module imports to browser-compatible polyfills.

Context

When writing code that needs to run in both Node.js and browser environments, developers often need to use polyfills for Node.js built-in modules. This plugin automates the process by transforming import statements for Node.js built-ins to use appropriate polyfill packages.

Capabilities

Transforms Node.js built-in imports to polyfills

  • Transforms import fs from 'fs' to import fs from 'browserify-fs' @test
  • Transforms import { readFile } from 'fs' to import { readFile } from 'browserify-fs' @test
  • Transforms import path from 'path' to import path from 'path-browserify' @test
  • Transforms import crypto from 'crypto' to import crypto from 'crypto-browserify' @test

Handles prefixed Node.js imports

  • Transforms import fs from 'node:fs' to import fs from 'browserify-fs' (strips the node: prefix) @test
  • Transforms import path from 'node:path' to import path from 'path-browserify' @test

Leaves non-Node.js imports unchanged

  • Does not transform import React from 'react' @test
  • Does not transform import { util } from './my-utils' @test

Implementation

@generates

API

/**
 * Creates a Babel plugin that transforms Node.js built-in imports to polyfills
 * @param {Object} babel - The Babel instance
 * @param {Object} babel.types - Babel types helper (commonly aliased as 't')
 * @returns {Object} Babel plugin object with visitor pattern
 */
export default function (babel) {
  const { types: t } = babel;

  return {
    visitor: {
      ImportDeclaration(path) {
        // Plugin implementation
      }
    }
  };
}

Dependencies { .dependencies }

@babel/core { .dependency }

Provides the core Babel transformation API and plugin infrastructure.

@satisfied-by

Install with Tessl CLI

npx tessl i tessl/npm-babel-plugin-transform-eval

tile.json