Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent ASI when simplifying a nested logical expression #3734

Merged
merged 1 commit into from
Aug 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/ast/nodes/LogicalExpression.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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');