Skip to content

Regression in babel-template with uppercase variables not meant to be replaced #7035

@danez

Description

@danez

Choose one: is this a bug report or feature request?

bug

Input Code

const unsafeWrapTemplate = template(`
  if (process.env.NODE_ENV !== "production") {
    NODE;
  }
`);

unsafeWrapTemplate({
  NODE: path.node,
}),

Expected Behavior

returns the template with NODE replaced

Current Behavior

Error: No substitution given for "NODE_ENV"
    at /Users/danieltschinder/Documents/Github/react-fast-highlight/node_modules/@babel/template/lib/populate.js:16:15
    at Array.forEach (<anonymous>)
    at populatePlaceholders (/Users/danieltschinder/Documents/Github/react-fast-highlight/node_modules/@babel/template/lib/populate.js:14:27)
    at /Users/danieltschinder/Documents/Github/react-fast-highlight/node_modules/@babel/template/lib/string.js:20:51
    at /Users/danieltschinder/Documents/Github/react-fast-highlight/node_modules/@babel/template/lib/builder.js:83:14
    at remove (/Users/danieltschinder/Documents/Github/react-fast-highlight/node_modules/babel-plugin-transform-react-remove-prop-types/lib/remove.js:88:28)

Possible Solution

We either need a way to whitelist ´NODE_ENV` or allow replacements to be not replaced?

Context

Found in babel-plugin-transform-react-remove-prop-types

Regressed in #6492

Your Environment

software version(s)
Babel beta 35
node 8.9.3
npm 5.5
Operating System mac

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions