FormidableLabs / babel-plugin-transform-define

Compile time code replacement for babel similar to Webpack's DefinePlugin
MIT License
245 stars 31 forks source link

should not transform identifiers with binding #81

Closed inottn closed 1 year ago

inottn commented 1 year ago

Here is a babel config:

module.exports = {
  plugins: [["transform-define", { TEST: "replaced" }]],
};

Transform the code below:

console.log(TEST); // should be transformed
function fn() {
  let TEST = "test"; // should not be transformed
  console.log(TEST); // should not be transformed
}

Currently, will be transformed into:

console.log("replaced");
function fn() {
  let "replaced" = "test"; // an error will be thrown here
  console.log("replaced");
}

Similar to #69 , an error will be thrown.