CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-lebab

JavaScript ES5 to ES6/ES7 transpiler that performs the opposite function of Babel

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

cli-usage.mddocs/

CLI Usage

Lebab provides a comprehensive command-line interface for transforming JavaScript files in batch operations.

Installation

# Global installation for CLI usage
npm install -g lebab

# Local installation for project-specific usage
npm install lebab

Capabilities

Basic File Transformation

Transform a single file with specified transforms.

# Basic syntax
lebab <input-file> -o <output-file> --transform <transforms>

# Examples
lebab es5.js -o es6.js --transform let
lebab old-code.js -o modern-code.js --transform let,arrow,arrow-return

In-Place Directory Transformation

Transform all files in a directory or matching a pattern.

# Transform all .js files in directory
lebab --replace src/js/ --transform arrow

# Transform with specific glob patterns  
lebab --replace 'src/js/**/*.jsx' --transform arrow
lebab --replace 'lib/**/*.js' --transform let,arrow

# Transform multiple file types
lebab --replace 'src/**/*.{js,jsx}' --transform class,commonjs

Transform Options

Specify which transformations to apply.

# Single transform
--transform let
-t let

# Multiple transforms (comma-separated)
--transform let,arrow,arrow-return
-t class,template,obj-shorthand

# All safe transforms
--transform arrow,arrow-return,for-of,for-each,arg-rest,arg-spread,obj-method,obj-shorthand,no-strict,exponent,multi-var

# Common unsafe transforms  
--transform let,class,commonjs,template,default-param

Command Options

# Show help
lebab --help
lebab -h

# Show version
lebab --version  
lebab -v

# Input/output options
--out-file <file>    # Specify output file
-o <file>            # Alias for --out-file

--replace <pattern>  # In-place transformation with glob pattern
-r <pattern>         # Alias for --replace

--transform <list>   # Comma-separated transform names
-t <list>           # Alias for --transform

Usage Examples

Modernizing Legacy Code

# Start with safe transforms
lebab --replace 'src/**/*.js' --transform arrow,arrow-return,obj-method,obj-shorthand

# Add variable declarations
lebab --replace 'src/**/*.js' --transform let

# Convert to classes (review output carefully)
lebab --replace 'src/**/*.js' --transform class

# Convert to ES6 modules (review imports/exports)  
lebab --replace 'src/**/*.js' --transform commonjs

Step-by-Step Modernization

# Step 1: Safe syntax improvements
lebab old-app.js -o step1.js --transform arrow,obj-method,obj-shorthand

# Step 2: Variable declarations  
lebab step1.js -o step2.js --transform let

# Step 3: Template literals
lebab step2.js -o step3.js --transform template

# Step 4: Modern features
lebab step3.js -o modern-app.js --transform default-param,arg-spread,includes

Processing Specific Frameworks

# React components
lebab --replace 'src/components/**/*.jsx' --transform let,arrow,class,obj-method

# Node.js modules  
lebab --replace 'lib/**/*.js' --transform let,arrow,commonjs,template

# Express.js applications
lebab --replace 'routes/**/*.js' --transform let,arrow,default-param,arg-spread

Output and Warnings

The CLI provides detailed feedback about the transformation process:

# Example output with warnings
$ lebab problematic.js -o result.js --transform let

problematic.js:
5:  warning  Unable to transform var  (let)
12: warning  Variable used before declaration  (let)

# Successful transformation
$ lebab simple.js -o result.js --transform arrow

# No output indicates successful transformation

Warning Types

Common warning messages and their meanings:

  • Unable to transform var (let) - Variable cannot be safely converted to let/const
  • Variable used before declaration (let) - Temporal dead zone issues
  • Cannot convert to arrow function (arrow) - Function uses this or arguments
  • Potential prototype conflict (class) - Class conversion may affect prototype chain

Best Practices

Recommended Workflow

  1. Start with safe transforms - Apply low-risk transforms first
  2. One transform at a time - Apply transforms individually to review changes
  3. Test thoroughly - Run tests after each transformation
  4. Review diffs - Manually inspect all changes, especially for unsafe transforms
  5. Version control - Commit between transformation steps

Transform Order Recommendations

# Recommended order for comprehensive modernization
lebab --replace 'src/**/*.js' --transform multi-var    # 1. Split declarations
lebab --replace 'src/**/*.js' --transform obj-shorthand # 2. Object syntax
lebab --replace 'src/**/*.js' --transform obj-method   # 3. Method syntax  
lebab --replace 'src/**/*.js' --transform let          # 4. Variable declarations
lebab --replace 'src/**/*.js' --transform arrow        # 5. Arrow functions
lebab --replace 'src/**/*.js' --transform arrow-return # 6. Concise arrows
lebab --replace 'src/**/*.js' --transform class        # 7. ES6 classes
lebab --replace 'src/**/*.js' --transform template     # 8. Template literals
lebab --replace 'src/**/*.js' --transform commonjs     # 9. ES6 modules (last)

Error Prevention

# Always backup before in-place transforms
cp -r src src-backup
lebab --replace 'src/**/*.js' --transform let

# Use version control
git add -A
git commit -m "Before lebab transformation"
lebab --replace 'src/**/*.js' --transform arrow
git diff  # Review changes

docs

cli-usage.md

index.md

safe-transforms.md

unsafe-transforms.md

tile.json