Gathering detailed insights and metrics for babel-plugin-transform-replace-expressions
Gathering detailed insights and metrics for babel-plugin-transform-replace-expressions
Gathering detailed insights and metrics for babel-plugin-transform-replace-expressions
Gathering detailed insights and metrics for babel-plugin-transform-replace-expressions
A Babel plugin for replacing expressions with other expressions
npm install babel-plugin-transform-replace-expressions
Typescript
Module System
JavaScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
24 Stars
35 Commits
1 Watchers
2 Branches
17 Contributors
Updated on Dec 09, 2023
Latest Version
0.2.0
Package Id
babel-plugin-transform-replace-expressions@0.2.0
Size
2.78 kB
Published on
Mar 11, 2019
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
1
1
Replace JavaScript expressions with other expressions.
$ yarn add --dev babel-plugin-transform-replace-expressions
Input file:
1const env = process.env.NODE_ENV; 2 3typeof Hello === "number";
.babelrc
:
1{ 2 "plugins": [ 3 [ 4 "babel-plugin-transform-replace-expressions", 5 { 6 "replace": { 7 "process.env.NODE_ENV": "\"production\"", 8 "typeof Hello": "42" 9 } 10 } 11 ] 12 ] 13}
Output:
1const env = "production"; 2 342 === "number";
A conflict happens when two replacements have the same Babel abstract syntax tree representation. For example expressions typeof A
and typeof (A)
are formatted differently but have the same AST representation as far as the plugin is concerned. In those situations the default is to raise an error, and can be overwritten by setting the option allowConflictingReplacements
to true
.
You can also always give the replacements as an array of key-value pairs. When allowConflictingReplacements
is set to true
the last conflicting replacement gets selected.
1{ 2 "plugins": [ 3 [ 4 "babel-plugin-transform-replace-expressions", 5 { 6 "replace": [ 7 ["typeof A", "B"], 8 ["typeof (A)", "C"] 9 ], 10 "allowConflictingReplacements": true 11 } 12 ] 13 ] 14}
Replacements are only applied to expressions. Therefore replacing DEBUG
with false
in const DEBUG = true
does nothing, but for if (DEBUG) {}
the result is if (false) {}
.
Only full expressions count. You can't replace env
in process.env.NODE_ENV
, you have to replace process.env
, which is a proper expression in Babel AST.
A replacement is only applied when the result is valid JavaScript. For example replacing a
with 2
in the following code:
1a = 1; 2b = a;
yields
1a = 1; 2b = 2;
This plugin is licensed under the MIT license. See LICENSE.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no SAST tool detected
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
security policy file not detected
Details
Reason
25 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More