Skip to content

Commit

Permalink
Improve coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
lukastaegert committed Jul 24, 2021
1 parent 16127ed commit 6ca5536
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 28 deletions.
14 changes: 7 additions & 7 deletions src/ast/nodes/MemberExpression.ts
Expand Up @@ -127,7 +127,7 @@ export default class MemberExpression extends NodeBase implements DeoptimizableE
if (this.variable) {
this.variable.deoptimizePath(path);
} else if (!this.replacement) {
if (path.length <= MAX_PATH_DEPTH) {
if (path.length < MAX_PATH_DEPTH) {
this.object.deoptimizePath([this.getPropertyKey(), ...path]);
}
}
Expand All @@ -142,7 +142,7 @@ export default class MemberExpression extends NodeBase implements DeoptimizableE
if (this.variable) {
this.variable.deoptimizeThisOnEventAtPath(event, path, thisParameter, recursionTracker);
} else if (!this.replacement) {
if (path.length <= MAX_PATH_DEPTH) {
if (path.length < MAX_PATH_DEPTH) {
this.object.deoptimizeThisOnEventAtPath(
event,
[this.getPropertyKey(), ...path],
Expand All @@ -167,7 +167,7 @@ export default class MemberExpression extends NodeBase implements DeoptimizableE
return UnknownValue;
}
this.expressionsToBeDeoptimized.push(origin);
if (path.length <= MAX_PATH_DEPTH) {
if (path.length < MAX_PATH_DEPTH) {
return this.object.getLiteralValueAtPath(
[this.getPropertyKey(), ...path],
recursionTracker,
Expand Down Expand Up @@ -195,7 +195,7 @@ export default class MemberExpression extends NodeBase implements DeoptimizableE
return UNKNOWN_EXPRESSION;
}
this.expressionsToBeDeoptimized.push(origin);
if (path.length <= MAX_PATH_DEPTH) {
if (path.length < MAX_PATH_DEPTH) {
return this.object.getReturnExpressionWhenCalledAtPath(
[this.getPropertyKey(), ...path],
callOptions,
Expand Down Expand Up @@ -232,7 +232,7 @@ export default class MemberExpression extends NodeBase implements DeoptimizableE
if (this.replacement) {
return true;
}
if (path.length <= MAX_PATH_DEPTH) {
if (path.length < MAX_PATH_DEPTH) {
return this.object.hasEffectsWhenAccessedAtPath([this.getPropertyKey(), ...path], context);
}
return true;
Expand All @@ -245,7 +245,7 @@ export default class MemberExpression extends NodeBase implements DeoptimizableE
if (this.replacement) {
return true;
}
if (path.length <= MAX_PATH_DEPTH) {
if (path.length < MAX_PATH_DEPTH) {
return this.object.hasEffectsWhenAssignedAtPath([this.getPropertyKey(), ...path], context);
}
return true;
Expand All @@ -262,7 +262,7 @@ export default class MemberExpression extends NodeBase implements DeoptimizableE
if (this.replacement) {
return true;
}
if (path.length <= MAX_PATH_DEPTH) {
if (path.length < MAX_PATH_DEPTH) {
return this.object.hasEffectsWhenCalledAtPath(
[this.getPropertyKey(), ...path],
callOptions,
Expand Down
3 changes: 3 additions & 0 deletions test/form/samples/deep-properties-access/_config.js
@@ -0,0 +1,3 @@
module.exports = {
description: 'handles deeply nested property accesses'
};
2 changes: 2 additions & 0 deletions test/form/samples/deep-properties-access/_expected.js
@@ -0,0 +1,2 @@
var obj = { obj: {obj: {obj: {obj: {obj: {obj: {obj: {obj: {obj: {obj: {}}}}}}}}}}};
console.log(obj.obj.obj.obj.obj.obj.obj.obj.obj.foo);
2 changes: 2 additions & 0 deletions test/form/samples/deep-properties-access/main.js
@@ -0,0 +1,2 @@
var obj = { obj: {obj: {obj: {obj: {obj: {obj: {obj: {obj: {obj: {obj: {}}}}}}}}}}};
console.log(obj.obj.obj.obj.obj.obj.obj.obj.obj.foo);
6 changes: 6 additions & 0 deletions test/form/samples/deep-properties/_config.js
@@ -0,0 +1,6 @@
module.exports = {
description: 'handles deeply nested properties',
options: {
treeshake: { propertyReadSideEffects: false }
}
};
11 changes: 11 additions & 0 deletions test/form/samples/deep-properties/_expected.js
@@ -0,0 +1,11 @@
var obj1 = obj1;
console.log(obj1.foo());

var obj2 = { obj: {obj: {obj: {obj: {obj: {obj: {obj: {obj: {obj: {obj: {}}}}}}}}}}};
obj2.obj.obj.obj.obj.obj.obj.obj.foo();

var obj3 = { obj: {obj: {obj: {obj: {obj: {obj: {obj: {obj: {obj: {obj: {}}}}}}}}}}};
if (obj3.obj.obj.obj.obj.obj.obj.obj.obj.foo) console.log('nested');

var obj4 = { obj: {obj: {obj: {obj: {obj: {obj: {obj: {obj: {obj: {obj: {}}}}}}}}}}};
obj4.obj.obj.obj.obj.obj.obj.obj.foo = 'nested';
11 changes: 11 additions & 0 deletions test/form/samples/deep-properties/main.js
@@ -0,0 +1,11 @@
var obj1 = obj1;
console.log(obj1.foo());

var obj2 = { obj: {obj: {obj: {obj: {obj: {obj: {obj: {obj: {obj: {obj: {}}}}}}}}}}};
obj2.obj.obj.obj.obj.obj.obj.obj.foo();

var obj3 = { obj: {obj: {obj: {obj: {obj: {obj: {obj: {obj: {obj: {obj: {}}}}}}}}}}};
if (obj3.obj.obj.obj.obj.obj.obj.obj.obj.foo) console.log('nested');

var obj4 = { obj: {obj: {obj: {obj: {obj: {obj: {obj: {obj: {obj: {obj: {}}}}}}}}}}};
obj4.obj.obj.obj.obj.obj.obj.obj.foo = 'nested';
3 changes: 0 additions & 3 deletions test/form/samples/recursive-property-call/_config.js

This file was deleted.

9 changes: 0 additions & 9 deletions test/form/samples/recursive-property-call/_expected.js

This file was deleted.

9 changes: 0 additions & 9 deletions test/form/samples/recursive-property-call/main.js

This file was deleted.

0 comments on commit 6ca5536

Please sign in to comment.