1. babel-plugin-minify-constant-folding
Tries to evaluate expressions and inline the result.
babel-plugin-minify-constant-folding
Package: babel-plugin-minify-constant-folding
Created by: babel
Last modified: Fri, 21 Jul 2023 15:40:21 GMT
Version: 0.5.0
License: MIT
Downloads: 1,770,831
Repository: https://github.com/babel/minify/tree/master/packages/babel-plugin-minify-constant-folding

Install

npm install babel-plugin-minify-constant-folding
yarn add babel-plugin-minify-constant-folding

babel-plugin-minify-constant-folding

Tries to evaluate expressions and inline the result.

Example

In

 "a" + "b"
2 * 3;
4 | 3;
"b" + a + "c" + "d" + g + z + "f" + "h" + "i"

[a, b, c].concat([d, e], f, g, [h]);
["a", "b", "c"].join();
["a", "b", "c"].join('@');
[1, 2, 3].length;
[1, 2, 3][1];
[1, 2, 3].shift();
[1, 2, 3].slice(0, 2);
[a, b, c].pop();
[a, b, c].reverse();
"a,b,c".split(",");
"abc"[0];
"abc".charAt();
"abc".charAt(1);
"abc".length;

Out

 "ab";
6;
7;
"b" + a + "cd" + g + z + "fhi";

[a, b, c, d, e, f, g, h];
"a,b,c";
"a@b@c";
3;
2;
2;
[1, 2];
c;
[c, b, a];
["a", "b", "c"];
"a";
"a";
"a";
"b";
3;

Installation

 npm install babel-plugin-minify-constant-folding --save-dev

Usage

Via .babelrc (Recommended)

.babelrc

 {
  "plugins": ["minify-constant-folding"]
}

Via CLI

 babel --plugins minify-constant-folding script.js

Via Node API

 require("@babel/core").transform("code", {
  plugins: ["minify-constant-folding"]
});

Options

  • tdz - Account for TDZ (Temporal Dead Zone)

RELATED POST

10 Must-Know Windows Shortcuts That Will Save You Time

10 Must-Know Windows Shortcuts That Will Save You Time

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Navigating AWS Networking: Essential Hacks for Smooth Operation

Navigating AWS Networking: Essential Hacks for Smooth Operation

Achieving Stunning Visuals with Unity's Global Illumination

Achieving Stunning Visuals with Unity's Global Illumination

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code