Skip to content

Commit

Permalink
Handle deoptimizations while a node is being included. (#3327)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukastaegert committed Jan 8, 2020
1 parent 35e127c commit b3d610f
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 6 deletions.
4 changes: 2 additions & 2 deletions LICENSE.md
Expand Up @@ -249,7 +249,7 @@ Repository: Rich-Harris/locate-character
## magic-string
License: MIT
By: Rich Harris
Repository: git+https://github.com/rich-harris/magic-string.git
Repository: https://github.com/rich-harris/magic-string

> Copyright 2018 Rich Harris
>
Expand Down Expand Up @@ -427,7 +427,7 @@ Repository: https://github.com/tapjs/signal-exit.git
## sourcemap-codec
License: MIT
By: Rich Harris
Repository: git+https://github.com/Rich-Harris/sourcemap-codec.git
Repository: https://github.com/Rich-Harris/sourcemap-codec

> The MIT License
>
Expand Down
4 changes: 2 additions & 2 deletions src/ast/nodes/ConditionalExpression.ts
Expand Up @@ -143,8 +143,8 @@ export default class ConditionalExpression extends NodeBase implements Deoptimiz
this.included = true;
if (
includeChildrenRecursively ||
this.usedBranch === null ||
this.test.shouldBeIncluded(context)
this.test.shouldBeIncluded(context) ||
this.usedBranch === null
) {
this.test.include(context, includeChildrenRecursively);
this.consequent.include(context, includeChildrenRecursively);
Expand Down
4 changes: 2 additions & 2 deletions src/ast/nodes/LogicalExpression.ts
Expand Up @@ -143,8 +143,8 @@ export default class LogicalExpression extends NodeBase implements Deoptimizable
this.included = true;
if (
includeChildrenRecursively ||
this.usedBranch === null ||
this.unusedBranch!.shouldBeIncluded(context)
(this.usedBranch === this.right && this.left.shouldBeIncluded(context)) ||
this.usedBranch === null
) {
this.left.include(context, includeChildrenRecursively);
this.right.include(context, includeChildrenRecursively);
Expand Down
@@ -0,0 +1,3 @@
module.exports = {
description: 'handles deoptimizations of logical expression while they are inlcuded (#3324)'
};
@@ -0,0 +1,9 @@
let isReassigned = false;

const result = (foo(), reassign() ? first() : second());
console.log(result);

function reassign() {
isReassigned = true;
return isReassigned;
}
@@ -0,0 +1,9 @@
let isReassigned = false;

const result = (foo(), reassign() ? first() : second());
console.log(result);

function reassign() {
isReassigned = true;
return isReassigned;
}
@@ -0,0 +1,3 @@
module.exports = {
description: 'handles deoptimizations of logical expression while they are inlcuded (#3324)'
};
@@ -0,0 +1,15 @@
let isFirstReassigned = false;

const result1 = (foo(), isFirstReassigned );
console.log(result1);

let isSecondReassigned = false;

const result2 = (foo(), reassign2() || foo());
console.log(result1);

function reassign2() {
// this needs to be included
isSecondReassigned = true;
return isSecondReassigned;
}
@@ -0,0 +1,20 @@
let isFirstReassigned = false;

const result1 = (foo(), isFirstReassigned && reassign1());
console.log(result1);

function reassign1() {
// this should never be triggered
isFirstReassigned = true;
}

let isSecondReassigned = false;

const result2 = (foo(), reassign2() || foo());
console.log(result1);

function reassign2() {
// this needs to be included
isSecondReassigned = true;
return isSecondReassigned;
}

0 comments on commit b3d610f

Please sign in to comment.