Skip to content

Commit

Permalink
Add tests and slightly adapt logic
Browse files Browse the repository at this point in the history
  • Loading branch information
lukastaegert committed Jan 4, 2020
1 parent 0725fbe commit f6ea740
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 15 deletions.
25 changes: 10 additions & 15 deletions src/ast/nodes/AssignmentExpression.ts
Expand Up @@ -29,7 +29,7 @@ export default class AssignmentExpression extends NodeBase {
private deoptimized = false;

hasEffects(context: HasEffectsContext): boolean {
this.deoptimize();
if (!this.deoptimized) this.applyDeoptimizations();
return (
this.right.hasEffects(context) ||
this.left.hasEffects(context) ||
Expand All @@ -41,9 +41,11 @@ export default class AssignmentExpression extends NodeBase {
return path.length > 0 && this.right.hasEffectsWhenAccessedAtPath(path, context);
}

include(context: InclusionContext, includeChildrenRecursively: IncludeChildren) {
this.deoptimize();
return super.include(context, includeChildrenRecursively);
include(context: InclusionContext, includeChildrenRecursively: IncludeChildren): void {
if (!this.deoptimized) this.applyDeoptimizations();
this.included = true;
this.left.include(context, includeChildrenRecursively);
this.right.include(context, includeChildrenRecursively);
}

render(code: MagicString, options: RenderOptions) {
Expand Down Expand Up @@ -80,16 +82,9 @@ export default class AssignmentExpression extends NodeBase {
}
}

shouldBeIncluded(context: InclusionContext): boolean {
this.deoptimize();
return super.shouldBeIncluded(context);
}

private deoptimize() {
if (!this.deoptimized) {
this.deoptimized = true;
this.left.deoptimizePath(EMPTY_PATH);
this.right.deoptimizePath(UNKNOWN_PATH);
}
private applyDeoptimizations() {
this.deoptimized = true;
this.left.deoptimizePath(EMPTY_PATH);
this.right.deoptimizePath(UNKNOWN_PATH);
}
}
@@ -0,0 +1,3 @@
module.exports = {
description: 'makes sure the assignee is deoptimized'
};
@@ -0,0 +1,5 @@
const flags = { updated: false };
let toBeUpdated = {};
toBeUpdated = flags;
toBeUpdated.updated = true;
if (!flags.updated) throw new Error('Update was not tracked');
@@ -0,0 +1,3 @@
module.exports = {
description: 'makes sure the assignment target is deoptimized'
};
@@ -0,0 +1,3 @@
let updated = false;
updated = true;
if (!updated) throw new Error('Update was not tracked');
@@ -0,0 +1,3 @@
module.exports = {
description: 'tracks assigments nested in expressions that are included for other reasons'
};
@@ -0,0 +1,3 @@
let updated = false;
assert.ok(!updated) || (updated = true);
if (!updated) throw new Error('Update was not tracked');
@@ -0,0 +1,3 @@
module.exports = {
description: 'tracks assigments included via try-catch-deoptimization'
};
@@ -0,0 +1,6 @@
let updated = false;
try {
updated = true;
} catch (err) {}

if (!updated) throw new Error('Update was not tracked');

0 comments on commit f6ea740

Please sign in to comment.