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.

simplify produces an incorrect result

See original GitHub issue

Describe the bug

Incorrect optimization.

To Reproduce

Minimal code to reproduce the bug

function draw () {
	const {canvas, currentLayout: layout} = this;

	canvas.width = layout.canvas.width + 2 * CANVAS_PADDING;
	canvas.height = layout.canvas.height + 2 * CANVAS_PADDING;
}

Actual Output

If there is no Error thrown,

function draw() {
  const {
    canvas,
    currentLayout: layout
  } = this;

  canvas.width += 2 * CANVAS_PADDING, canvas.height += 2 * CANVAS_PADDING;
}

Expected Output

function draw() {
  const {
    canvas,
    currentLayout: layout
  } = this;

  canvas.width = layout.canvas.width + 2 * CANVAS_PADDING, canvas.height = layout.canvas.width + 2 * CANVAS_PADDING;
}

Configuration

How are you using babel-minify? babel --plugins minify-simplify test.js

babel-minify version: 0.4.3

babel version : 7.1.0

babel-minify-config: none babelrc: none

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
jsg2021commented, Oct 26, 2018

My build process is webpack. I am using this minifier as a preset in the babel-loader… so, not really. Anyways, this has accidentally hijacked the original issue and I have found to be unrelated. (Which is why I updated my comment from two days ago) I originally thought this was related to the original issue, but I believe is intended behavior (the no-space between return and the quote)

0reactions
j-f1commented, Oct 26, 2018

Can your build process substitute typeof define === "function" with true before you minify? This will also allow the minifier to remove unnecessary branches/conditionals.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Simplify quick-fix produces incorrect result when if condition ...
Simplify quick-fix produces incorrect result when if condition contains init statement. Subtask of 1. Subtask of 1 issue (1 unresolved).
Read more >
Why is this simplification wrong? - Mathematics Stack Exchange
It's true that z/z=1 (if z≠0), but you don't have z/z in your expression.
Read more >
Answer Explanations for the 2021-22 ACT Math Test - Piqosity
This would simplify the equation to 10 + 3(12 ÷(3⋅2)) ... volunteers who received an incorrect result from the Sam77 test are 25...
Read more >
Solving Radical Equations
FALSE ! TRUE! Now check both solutions by substituting them into the original equation. Since x = −6 produces a false statement, it...
Read more >
Common Mistakes
Cancelling incorrectly. When solving algebraic equations or simplifying rational expressions (polynomial fractions), students often try to "cancel" items to ...
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