question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Replace well-defined variable with undefined in for statement

See original GitHub issue

Context

I use Vue.js, and when I replace process.env.NODE_ENV with 'production', and minify my bundle with babel-preset-minify the resulting code is broken in this function actuallySetSelected, and more precisely the i < l expression in the for statement is replaced with i < undefined.

Steps to reproduce

I use:

  • @babel/core v7.0.0-beta.51;
  • babel-preset-minify v0.4.3.

With this config for babel-preset-minify:

{
  evaluate: true,
  simplify: true,
  mergeVars: true,

  removeUndefined: false,
  deadcode: false,
  booleans: false,
  builtIns: false,
  consecutiveAdds: false,
  flipComparisons: false,
  guards: false,
  infinity: false,
  mangle: false,
  memberExpressions: false,
  numericLiterals: false,
  propertyLiterals: false,
  regexpConstructors: false,
  replace: false,
  simplifyComparisons: false,
  typeConstructors: false,
  undefinedToVoid: false
}

I’ve simplified the test case:

Input

function test () {
  if (false) return
  var i
  for (var l=1; i < l; i++) {}
}

Expected output

function test(){if(true)for(var i,l=1;i<l;i++);}

Actual output

function test(){if(true)for(var i,l=1;i<undefined;i++);}

It seems I’ve managed to reduce it to an interaction between those three plugins:

You can pull this repo to test it for yourself.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:6
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
kevinv11ncommented, Oct 25, 2018

@trevor-bliss and I just ran into the same issue.

1reaction
tex0lcommented, Oct 4, 2018

I noticed version 0.5.0 just got out, I updated the test case here: https://github.com/tex0l/bug-report-babel

@boopathi : the bug still exists in the latest version.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Is modifying a variable in its declaration statement well-defined?
I'd be concerned that the standard may permit i=0 to run, then i to be initialized to an unspecified state, then i initialized...
Read more >
1.6 — Uninitialized variables and undefined behavior
Undefined behavior (often abbreviated UB) is the result of executing code whose behavior is not well defined by the C++ language.
Read more >
undefined - JavaScript - MDN Web Docs - Mozilla
A variable that has not been assigned a value is of type undefined . A method or statement also returns undefined if the...
Read more >
Managing Variables - UiPath Documentation Portal
If you remove or upgrade a package that may lead to a variable or argument being undefined, an Unknown Type is added in...
Read more >
Undefined behavior in C and C++ programs - Project Nayuki
These strategies failed in a spectacular way: Just by moving a print statement up or down one line, I could change the program's...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found