Skip to content

Commit

Permalink
Improve coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
lukastaegert committed Jun 7, 2022
1 parent e8247bd commit 605c701
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 31 deletions.
10 changes: 1 addition & 9 deletions src/ast/nodes/AssignmentExpression.ts
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
}

Expand Down
16 changes: 2 additions & 14 deletions src/ast/nodes/AssignmentPattern.ts
Expand Up @@ -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 {
Expand Down Expand Up @@ -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();
}
Expand All @@ -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 {
Expand Down
3 changes: 1 addition & 2 deletions src/ast/nodes/ForInStatement.ts
Expand Up @@ -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 }
Expand Down
5 changes: 3 additions & 2 deletions src/ast/nodes/ObjectPattern.ts
Expand Up @@ -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;
}
Expand Down
5 changes: 1 addition & 4 deletions src/ast/nodes/SequenceExpression.ts
Expand Up @@ -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';
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 605c701

Please sign in to comment.