JavaScript ES5 to ES6/ES7 transpiler that performs the opposite function of Babel
—
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
Lebab provides a comprehensive command-line interface for transforming JavaScript files in batch operations.
# Global installation for CLI usage
npm install -g lebab
# Local installation for project-specific usage
npm install lebabTransform 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-returnTransform 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,commonjsSpecify 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# 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# 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 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# 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-spreadThe 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 transformationCommon warning messages and their meanings:
Unable to transform var (let) - Variable cannot be safely converted to let/constVariable used before declaration (let) - Temporal dead zone issuesCannot convert to arrow function (arrow) - Function uses this or argumentsPotential prototype conflict (class) - Class conversion may affect prototype chain# 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)# 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