Skip to content

Commit

Permalink
Prevent ASI when simplifying a nested logical expression (#3734)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukastaegert committed Aug 16, 2020
1 parent 5c7b808 commit 9950a4d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/ast/nodes/LogicalExpression.ts
Expand Up @@ -184,7 +184,8 @@ export default class LogicalExpression extends NodeBase implements Deoptimizable
renderedParentType: renderedParentType || this.parent.type
});
} else {
super.render(code, options);
this.left.render(code, options, { preventASI });
this.right.render(code, options);
}
}

Expand Down
14 changes: 10 additions & 4 deletions test/function/samples/prevent-tree-shaking-asi/main.js
Expand Up @@ -28,13 +28,19 @@ function test3() {
}
assert.strictEqual(test3(), 'expected');

function test4() {
function test4(value) {
return true &&
value || false;
}
assert.strictEqual(test4('expected'), 'expected');

function test5() {
return 'removed',
/* kept */

'expected';
}
assert.strictEqual(test4(), 'expected');
assert.strictEqual(test5(), 'expected');

try {
throw true ?
Expand All @@ -45,8 +51,8 @@ try {
assert.strictEqual(err.message, 'expected');
}

function* test5() {
function* test6() {
yield false ||
'expected'
}
assert.strictEqual(test5().next().value, 'expected');
assert.strictEqual(test6().next().value, 'expected');

0 comments on commit 9950a4d

Please sign in to comment.