From 605c701d5d447940480b6e74af367f1d8b6f4626 Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Tue, 7 Jun 2022 07:07:21 +0200 Subject: [PATCH] Improve coverage --- src/ast/nodes/AssignmentExpression.ts | 10 +--------- src/ast/nodes/AssignmentPattern.ts | 16 ++-------------- src/ast/nodes/ForInStatement.ts | 3 +-- src/ast/nodes/ObjectPattern.ts | 5 +++-- src/ast/nodes/SequenceExpression.ts | 5 +---- 5 files changed, 8 insertions(+), 31 deletions(-) diff --git a/src/ast/nodes/AssignmentExpression.ts b/src/ast/nodes/AssignmentExpression.ts index bafb062c1e2..a985ddc272a 100644 --- a/src/ast/nodes/AssignmentExpression.ts +++ b/src/ast/nodes/AssignmentExpression.ts @@ -17,7 +17,7 @@ import { type HasEffectsContext, type InclusionContext } from '../ExecutionContext'; -import { INTERACTION_ACCESSED, INTERACTION_ASSIGNED, NodeInteraction } from '../NodeInteractions'; +import { NodeInteraction } from '../NodeInteractions'; import { EMPTY_PATH, type ObjectPath, UNKNOWN_PATH } from '../utils/PathTracker'; import type Variable from '../variables/Variable'; import Identifier from './Identifier'; @@ -60,14 +60,6 @@ export default class AssignmentExpression extends NodeBase { interaction: NodeInteraction, context: HasEffectsContext ): boolean { - if (path.length === 0) { - if (interaction.type === INTERACTION_ACCESSED) { - return false; - } - if (interaction.type === INTERACTION_ASSIGNED) { - return true; - } - } return this.right.hasEffectsOnInteractionAtPath(path, interaction, context); } diff --git a/src/ast/nodes/AssignmentPattern.ts b/src/ast/nodes/AssignmentPattern.ts index fdfc06a4d3c..14ef36a46b0 100644 --- a/src/ast/nodes/AssignmentPattern.ts +++ b/src/ast/nodes/AssignmentPattern.ts @@ -2,14 +2,13 @@ import type MagicString from 'magic-string'; import { BLANK } from '../../utils/blank'; import type { NodeRenderOptions, RenderOptions } from '../../utils/renderHelpers'; import type { HasEffectsContext } from '../ExecutionContext'; -import { InclusionContext } from '../ExecutionContext'; import { NodeInteractionAssigned } from '../NodeInteractions'; import { EMPTY_PATH, type ObjectPath, UNKNOWN_PATH } from '../utils/PathTracker'; import type LocalVariable from '../variables/LocalVariable'; import type Variable from '../variables/Variable'; import type * as NodeType from './NodeType'; import type { ExpressionEntity } from './shared/Expression'; -import { type ExpressionNode, IncludeChildren, NodeBase } from './shared/Node'; +import { type ExpressionNode, NodeBase } from './shared/Node'; import type { PatternNode } from './shared/Pattern'; export default class AssignmentPattern extends NodeBase implements PatternNode { @@ -42,13 +41,6 @@ export default class AssignmentPattern extends NodeBase implements PatternNode { ); } - include(context: InclusionContext, includeChildrenRecursively: IncludeChildren): void { - if (!this.deoptimized) this.applyDeoptimizations(); - this.included = true; - this.left.include(context, includeChildrenRecursively); - this.right.include(context, includeChildrenRecursively); - } - markDeclarationReached(): void { this.left.markDeclarationReached(); } @@ -59,11 +51,7 @@ export default class AssignmentPattern extends NodeBase implements PatternNode { { isShorthandProperty }: NodeRenderOptions = BLANK ): void { this.left.render(code, options, { isShorthandProperty }); - if (this.right.included) { - this.right.render(code, options); - } else { - code.remove(this.left.end, this.end); - } + this.right.render(code, options); } protected applyDeoptimizations(): void { diff --git a/src/ast/nodes/ForInStatement.ts b/src/ast/nodes/ForInStatement.ts index ca66952cb89..8ca62b46738 100644 --- a/src/ast/nodes/ForInStatement.ts +++ b/src/ast/nodes/ForInStatement.ts @@ -29,8 +29,7 @@ export default class ForInStatement extends StatementBase { hasEffects(context: HasEffectsContext): boolean { const { deoptimized, left, right } = this; if (!deoptimized) this.applyDeoptimizations(); - if (left?.hasEffectsAsAssignmentTarget(context, false) || right?.hasEffects(context)) - return true; + if (left.hasEffectsAsAssignmentTarget(context, false) || right.hasEffects(context)) return true; const { brokenFlow, ignore: { breaks, continues } diff --git a/src/ast/nodes/ObjectPattern.ts b/src/ast/nodes/ObjectPattern.ts index 4e4a12a1216..42fa761eba4 100644 --- a/src/ast/nodes/ObjectPattern.ts +++ b/src/ast/nodes/ObjectPattern.ts @@ -47,11 +47,12 @@ export default class ObjectPattern extends NodeBase implements PatternNode { } hasEffectsOnInteractionAtPath( - path: ObjectPath, + // At the moment, this is only triggered for assignment left-hand sides, + // where the path is empty + _path: ObjectPath, interaction: NodeInteractionAssigned, context: HasEffectsContext ): boolean { - if (path.length > 0) return true; for (const property of this.properties) { if (property.hasEffectsOnInteractionAtPath(EMPTY_PATH, interaction, context)) return true; } diff --git a/src/ast/nodes/SequenceExpression.ts b/src/ast/nodes/SequenceExpression.ts index d7f5aba5d28..b2f5a1b48e4 100644 --- a/src/ast/nodes/SequenceExpression.ts +++ b/src/ast/nodes/SequenceExpression.ts @@ -10,7 +10,7 @@ import { treeshakeNode } from '../../utils/treeshakeNode'; import type { DeoptimizableEntity } from '../DeoptimizableEntity'; import type { HasEffectsContext, InclusionContext } from '../ExecutionContext'; import type { NodeInteractionWithThisArg } from '../NodeInteractions'; -import { INTERACTION_ACCESSED, NodeInteraction } from '../NodeInteractions'; +import { NodeInteraction } from '../NodeInteractions'; import type { ObjectPath, PathTracker } from '../utils/PathTracker'; import ExpressionStatement from './ExpressionStatement'; import type * as NodeType from './NodeType'; @@ -61,9 +61,6 @@ export default class SequenceExpression extends NodeBase { interaction: NodeInteraction, context: HasEffectsContext ): boolean { - if (path.length === 0 && interaction.type === INTERACTION_ACCESSED) { - return false; - } return this.expressions[this.expressions.length - 1].hasEffectsOnInteractionAtPath( path, interaction,