From c00cc93e764deb0642f91e44187efa0ef8f87ea1 Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Sat, 24 Jul 2021 07:38:51 +0200 Subject: [PATCH] Improve coverage --- src/ast/nodes/MemberExpression.ts | 14 +++++++------- .../form/samples/deep-properties-access/_config.js | 3 +++ .../samples/deep-properties-access/_expected.js | 2 ++ test/form/samples/deep-properties-access/main.js | 2 ++ test/form/samples/deep-properties/_config.js | 6 ++++++ test/form/samples/deep-properties/_expected.js | 11 +++++++++++ test/form/samples/deep-properties/main.js | 11 +++++++++++ .../samples/recursive-property-call/_config.js | 3 --- .../samples/recursive-property-call/_expected.js | 9 --------- test/form/samples/recursive-property-call/main.js | 9 --------- 10 files changed, 42 insertions(+), 28 deletions(-) create mode 100644 test/form/samples/deep-properties-access/_config.js create mode 100644 test/form/samples/deep-properties-access/_expected.js create mode 100644 test/form/samples/deep-properties-access/main.js create mode 100644 test/form/samples/deep-properties/_config.js create mode 100644 test/form/samples/deep-properties/_expected.js create mode 100644 test/form/samples/deep-properties/main.js delete mode 100644 test/form/samples/recursive-property-call/_config.js delete mode 100644 test/form/samples/recursive-property-call/_expected.js delete mode 100644 test/form/samples/recursive-property-call/main.js diff --git a/src/ast/nodes/MemberExpression.ts b/src/ast/nodes/MemberExpression.ts index e017082683c..f7a3ab0b61a 100644 --- a/src/ast/nodes/MemberExpression.ts +++ b/src/ast/nodes/MemberExpression.ts @@ -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]); } } @@ -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], @@ -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, @@ -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, @@ -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; @@ -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; @@ -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, diff --git a/test/form/samples/deep-properties-access/_config.js b/test/form/samples/deep-properties-access/_config.js new file mode 100644 index 00000000000..e71a93b8870 --- /dev/null +++ b/test/form/samples/deep-properties-access/_config.js @@ -0,0 +1,3 @@ +module.exports = { + description: 'handles deeply nested property accesses' +}; diff --git a/test/form/samples/deep-properties-access/_expected.js b/test/form/samples/deep-properties-access/_expected.js new file mode 100644 index 00000000000..c1d319eb87d --- /dev/null +++ b/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); diff --git a/test/form/samples/deep-properties-access/main.js b/test/form/samples/deep-properties-access/main.js new file mode 100644 index 00000000000..c1d319eb87d --- /dev/null +++ b/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); diff --git a/test/form/samples/deep-properties/_config.js b/test/form/samples/deep-properties/_config.js new file mode 100644 index 00000000000..e721c6711ce --- /dev/null +++ b/test/form/samples/deep-properties/_config.js @@ -0,0 +1,6 @@ +module.exports = { + description: 'handles deeply nested properties', + options: { + treeshake: { propertyReadSideEffects: false } + } +}; diff --git a/test/form/samples/deep-properties/_expected.js b/test/form/samples/deep-properties/_expected.js new file mode 100644 index 00000000000..ea78417e0f4 --- /dev/null +++ b/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'; diff --git a/test/form/samples/deep-properties/main.js b/test/form/samples/deep-properties/main.js new file mode 100644 index 00000000000..ea78417e0f4 --- /dev/null +++ b/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'; diff --git a/test/form/samples/recursive-property-call/_config.js b/test/form/samples/recursive-property-call/_config.js deleted file mode 100644 index 99bde22fce9..00000000000 --- a/test/form/samples/recursive-property-call/_config.js +++ /dev/null @@ -1,3 +0,0 @@ -module.exports = { - description: 'handles calls to properties of recursively defined variables' -}; diff --git a/test/form/samples/recursive-property-call/_expected.js b/test/form/samples/recursive-property-call/_expected.js deleted file mode 100644 index 37fff7100ad..00000000000 --- a/test/form/samples/recursive-property-call/_expected.js +++ /dev/null @@ -1,9 +0,0 @@ -var obj1 = obj1; -console.log(obj1.foo()); - -var obj2 = {foo: () => {}}; -var obj2 = {foo: log}; -obj2.foo(); - -var obj3 = {obj: obj3}; -obj3.obj.obj.obj.obj.obj.obj.obj.obj.obj.foo(); diff --git a/test/form/samples/recursive-property-call/main.js b/test/form/samples/recursive-property-call/main.js deleted file mode 100644 index 9337bc08b1d..00000000000 --- a/test/form/samples/recursive-property-call/main.js +++ /dev/null @@ -1,9 +0,0 @@ -var obj1 = obj1; -console.log(obj1.foo()); - -var obj2 = {foo: () => {}}; -var obj2 = {foo: log}; -obj2.foo(); - -var obj3 = {obj: obj3} -obj3.obj.obj.obj.obj.obj.obj.obj.obj.obj.foo()