Skip to content

Commit

Permalink
Improve coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
lukastaegert committed Aug 28, 2020
1 parent e7e4b62 commit aa8e252
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 22 deletions.
14 changes: 10 additions & 4 deletions src/ast/nodes/IfStatement.ts
Expand Up @@ -70,12 +70,18 @@ export default class IfStatement extends StatementBase implements DeoptimizableE

parseNode(esTreeNode: GenericEsTreeNode) {
this.consequentScope = new TrackingScope(this.scope);
this.consequent = new (this.context.nodeConstructors[esTreeNode.consequent.type] ||
this.context.nodeConstructors.UnknownNode)(esTreeNode.consequent, this, this.consequentScope);
this.consequent = new this.context.nodeConstructors[esTreeNode.consequent.type](
esTreeNode.consequent,
this,
this.consequentScope
);
if (esTreeNode.alternate) {
this.alternateScope = new TrackingScope(this.scope);
this.alternate = new (this.context.nodeConstructors[esTreeNode.alternate.type] ||
this.context.nodeConstructors.UnknownNode)(esTreeNode.alternate, this, this.alternateScope);
this.alternate = new this.context.nodeConstructors[esTreeNode.alternate.type](
esTreeNode.alternate,
this,
this.alternateScope
);
}
super.parseNode(esTreeNode);
}
Expand Down
12 changes: 0 additions & 12 deletions src/ast/nodes/VariableDeclarator.ts
@@ -1,5 +1,3 @@
import MagicString from 'magic-string';
import { RenderOptions } from '../../utils/renderHelpers';
import { ObjectPath } from '../utils/PathTracker';
import { UNDEFINED_EXPRESSION } from '../values';
import * as NodeType from './NodeType';
Expand All @@ -18,14 +16,4 @@ export default class VariableDeclarator extends NodeBase {
deoptimizePath(path: ObjectPath) {
this.id.deoptimizePath(path);
}

render(code: MagicString, options: RenderOptions) {
// This can happen for hoisted variables in dead branches
if (this.init !== null && !this.init.included) {
code.remove(this.id.end, this.end);
this.id.render(code, options);
} else {
super.render(code, options);
}
}
}
2 changes: 1 addition & 1 deletion src/ast/scopes/BlockScope.ts
Expand Up @@ -9,7 +9,7 @@ export default class BlockScope extends ChildScope {
addDeclaration(
identifier: Identifier,
context: AstContext,
init: ExpressionEntity | null = null,
init: ExpressionEntity | null,
isHoisted: boolean
): LocalVariable {
if (isHoisted) {
Expand Down
2 changes: 1 addition & 1 deletion src/ast/scopes/Scope.ts
Expand Up @@ -13,7 +13,7 @@ export default class Scope {
addDeclaration(
identifier: Identifier,
context: AstContext,
init: ExpressionEntity | null = null,
init: ExpressionEntity | null,
_isHoisted: boolean
) {
const name = identifier.name;
Expand Down
6 changes: 2 additions & 4 deletions src/ast/scopes/TrackingScope.ts
Expand Up @@ -10,12 +10,10 @@ export default class TrackingScope extends BlockScope {
addDeclaration(
identifier: Identifier,
context: AstContext,
init: ExpressionEntity | null = null,
init: ExpressionEntity | null,
isHoisted: boolean
): LocalVariable {
if (isHoisted) {
this.hoistedDeclarations.push(identifier);
}
this.hoistedDeclarations.push(identifier);
return this.parent.addDeclaration(identifier, context, init, isHoisted);
}
}

0 comments on commit aa8e252

Please sign in to comment.