Skip to content

Commit

Permalink
Remove forEachReturnExpression and someReturnExpression logic!
Browse files Browse the repository at this point in the history
  • Loading branch information
lukastaegert committed Jun 14, 2018
1 parent e329e36 commit b114c9d
Show file tree
Hide file tree
Showing 20 changed files with 35 additions and 818 deletions.
20 changes: 0 additions & 20 deletions src/ast/nodes/ArrayExpression.ts
Expand Up @@ -5,11 +5,9 @@ import {
getMemberReturnExpressionWhenCalled,
hasMemberEffectWhenCalled,
ObjectPath,
someMemberReturnExpressionWhenCalled,
UNKNOWN_EXPRESSION
} from '../values';
import * as NodeType from './NodeType';
import { SomeReturnExpressionCallback } from './shared/Expression';
import { ExpressionNode, NodeBase } from './shared/Node';
import SpreadElement from './SpreadElement';

Expand All @@ -36,22 +34,4 @@ export default class ArrayExpression extends NodeBase {
}
return true;
}

someReturnExpressionWhenCalledAtPath(
path: ObjectPath,
callOptions: CallOptions,
predicateFunction: SomeReturnExpressionCallback,
options: ExecutionPathOptions
): boolean {
if (path.length === 1) {
return someMemberReturnExpressionWhenCalled(
arrayMembers,
path[0],
callOptions,
predicateFunction,
options
);
}
return true;
}
}
21 changes: 0 additions & 21 deletions src/ast/nodes/ArrowFunctionExpression.ts
Expand Up @@ -5,7 +5,6 @@ import Scope from '../scopes/Scope';
import { ObjectPath, UNKNOWN_EXPRESSION } from '../values';
import BlockStatement from './BlockStatement';
import * as NodeType from './NodeType';
import { ForEachReturnExpressionCallback, SomeReturnExpressionCallback } from './shared/Expression';
import { ExpressionNode, GenericEsTreeNode, NodeBase } from './shared/Node';
import { PatternNode } from './shared/Pattern';

Expand All @@ -21,14 +20,6 @@ export default class ArrowFunctionExpression extends NodeBase {
this.scope = new ReturnValueScope(parentScope);
}

forEachReturnExpressionWhenCalledAtPath(
path: ObjectPath,
callOptions: CallOptions,
callback: ForEachReturnExpressionCallback
) {
path.length === 0 && this.scope.forEachReturnExpressionWhenCalled(callOptions, callback);
}

getReturnExpressionWhenCalledAtPath(path: ObjectPath) {
return path.length === 0 ? this.scope.getReturnExpression() : UNKNOWN_EXPRESSION;
}
Expand Down Expand Up @@ -81,18 +72,6 @@ export default class ArrowFunctionExpression extends NodeBase {
}
super.parseNode(esTreeNode);
}

someReturnExpressionWhenCalledAtPath(
path: ObjectPath,
callOptions: CallOptions,
predicateFunction: SomeReturnExpressionCallback,
options: ExecutionPathOptions
): boolean {
return (
path.length > 0 ||
this.scope.someReturnExpressionWhenCalled(callOptions, predicateFunction, options)
);
}
}

ArrowFunctionExpression.prototype.preventChildBlockScope = true;
41 changes: 1 addition & 40 deletions src/ast/nodes/CallExpression.ts
@@ -1,18 +1,13 @@
import CallOptions from '../CallOptions';
import { ExecutionPathOptions } from '../ExecutionPathOptions';
import { EntityPathTracker } from '../utils/EntityPathTracker';
import {
EMPTY_IMMUTABLE_TRACKER,
ImmutableEntityPathTracker
} from '../utils/ImmutableEntityPathTracker';
import { EMPTY_PATH, ObjectPath, UNKNOWN_EXPRESSION, UNKNOWN_PATH } from '../values';
import Identifier from './Identifier';
import * as NodeType from './NodeType';
import {
ExpressionEntity,
ForEachReturnExpressionCallback,
SomeReturnExpressionCallback
} from './shared/Expression';
import { ExpressionEntity } from './shared/Expression';
import { ExpressionNode, NodeBase } from './shared/Node';
import SpreadElement from './SpreadElement';

Expand Down Expand Up @@ -62,26 +57,6 @@ export default class CallExpression extends NodeBase {
}
}

forEachReturnExpressionWhenCalledAtPath(
path: ObjectPath,
callOptions: CallOptions,
callback: ForEachReturnExpressionCallback,
recursionTracker: EntityPathTracker
) {
if (this.returnExpression === null) {
this.returnExpression = this.callee.getReturnExpressionWhenCalledAtPath(
EMPTY_PATH,
EMPTY_IMMUTABLE_TRACKER
);
}
this.returnExpression.forEachReturnExpressionWhenCalledAtPath(
path,
callOptions,
callback,
recursionTracker
);
}

getReturnExpressionWhenCalledAtPath(
path: ObjectPath,
recursionTracker: ImmutableEntityPathTracker
Expand Down Expand Up @@ -171,18 +146,4 @@ export default class CallExpression extends NodeBase {
this.returnExpression.reassignPath(path);
}
}

someReturnExpressionWhenCalledAtPath(
path: ObjectPath,
callOptions: CallOptions,
predicateFunction: SomeReturnExpressionCallback,
options: ExecutionPathOptions
): boolean {
return this.returnExpression.someReturnExpressionWhenCalledAtPath(
path,
callOptions,
predicateFunction,
options
);
}
}
80 changes: 4 additions & 76 deletions src/ast/nodes/ConditionalExpression.ts
Expand Up @@ -3,7 +3,6 @@ import { BLANK } from '../../utils/blank';
import { NodeRenderOptions, RenderOptions } from '../../utils/renderHelpers';
import CallOptions from '../CallOptions';
import { ExecutionPathOptions } from '../ExecutionPathOptions';
import { EntityPathTracker } from '../utils/EntityPathTracker';
import {
EMPTY_IMMUTABLE_TRACKER,
ImmutableEntityPathTracker
Expand All @@ -17,11 +16,7 @@ import {
} from '../values';
import CallExpression from './CallExpression';
import * as NodeType from './NodeType';
import {
ExpressionEntity,
ForEachReturnExpressionCallback,
SomeReturnExpressionCallback
} from './shared/Expression';
import { ExpressionEntity } from './shared/Expression';
import { ExpressionNode, NodeBase } from './shared/Node';

export default class ConditionalExpression extends NodeBase {
Expand All @@ -32,33 +27,6 @@ export default class ConditionalExpression extends NodeBase {

private hasUnknownTestValue: boolean;

forEachReturnExpressionWhenCalledAtPath(
path: ObjectPath,
callOptions: CallOptions,
callback: ForEachReturnExpressionCallback,
recursionTracker: EntityPathTracker
) {
const testValue = this.hasUnknownTestValue
? UNKNOWN_VALUE
: this.getTestValue(EMPTY_IMMUTABLE_TRACKER);
if (testValue === UNKNOWN_VALUE || testValue) {
this.consequent.forEachReturnExpressionWhenCalledAtPath(
path,
callOptions,
callback,
recursionTracker
);
}
if (testValue === UNKNOWN_VALUE || !testValue) {
this.alternate.forEachReturnExpressionWhenCalledAtPath(
path,
callOptions,
callback,
recursionTracker
);
}
}

getLiteralValueAtPath(
path: ObjectPath,
recursionTracker: ImmutableEntityPathTracker
Expand All @@ -74,15 +42,15 @@ export default class ConditionalExpression extends NodeBase {

getReturnExpressionWhenCalledAtPath(
path: ObjectPath,
calledPathTracker: ImmutableEntityPathTracker
recursionTracker: ImmutableEntityPathTracker
): ExpressionEntity {
const testValue = this.hasUnknownTestValue
? UNKNOWN_VALUE
: this.getTestValue(EMPTY_IMMUTABLE_TRACKER);
if (testValue === UNKNOWN_VALUE) return UNKNOWN_EXPRESSION;
return testValue
? this.consequent.getReturnExpressionWhenCalledAtPath(path, calledPathTracker)
: this.alternate.getReturnExpressionWhenCalledAtPath(path, calledPathTracker);
? this.consequent.getReturnExpressionWhenCalledAtPath(path, recursionTracker)
: this.alternate.getReturnExpressionWhenCalledAtPath(path, recursionTracker);
}

hasEffects(options: ExecutionPathOptions): boolean {
Expand Down Expand Up @@ -202,46 +170,6 @@ export default class ConditionalExpression extends NodeBase {
}
}

someReturnExpressionWhenCalledAtPath(
path: ObjectPath,
callOptions: CallOptions,
predicateFunction: SomeReturnExpressionCallback,
options: ExecutionPathOptions
): boolean {
const testValue = this.hasUnknownTestValue
? UNKNOWN_VALUE
: this.getTestValue(EMPTY_IMMUTABLE_TRACKER);
if (testValue === UNKNOWN_VALUE) {
return (
this.consequent.someReturnExpressionWhenCalledAtPath(
path,
callOptions,
predicateFunction,
options
) ||
this.alternate.someReturnExpressionWhenCalledAtPath(
path,
callOptions,
predicateFunction,
options
)
);
}
return testValue
? this.consequent.someReturnExpressionWhenCalledAtPath(
path,
callOptions,
predicateFunction,
options
)
: this.alternate.someReturnExpressionWhenCalledAtPath(
path,
callOptions,
predicateFunction,
options
);
}

private getTestValue(recursionTracker: ImmutableEntityPathTracker) {
if (this.hasUnknownTestValue) return UNKNOWN_VALUE;
const value = this.test.getLiteralValueAtPath(EMPTY_PATH, recursionTracker);
Expand Down
45 changes: 3 additions & 42 deletions src/ast/nodes/Identifier.ts
Expand Up @@ -5,18 +5,13 @@ import { NodeRenderOptions, RenderOptions } from '../../utils/renderHelpers';
import CallOptions from '../CallOptions';
import { ExecutionPathOptions } from '../ExecutionPathOptions';
import FunctionScope from '../scopes/FunctionScope';
import { EntityPathTracker } from '../utils/EntityPathTracker';
import { ImmutableEntityPathTracker } from '../utils/ImmutableEntityPathTracker';
import { LiteralValueOrUnknown, ObjectPath, UNKNOWN_EXPRESSION, UNKNOWN_VALUE } from '../values';
import Variable from '../variables/Variable';
import AssignmentExpression from './AssignmentExpression';
import * as NodeType from './NodeType';
import Property from './Property';
import {
ExpressionEntity,
ForEachReturnExpressionCallback,
SomeReturnExpressionCallback
} from './shared/Expression';
import { ExpressionEntity } from './shared/Expression';
import { Node, NodeBase } from './shared/Node';
import UpdateExpression from './UpdateExpression';

Expand Down Expand Up @@ -72,23 +67,6 @@ export default class Identifier extends NodeBase {
}
}

forEachReturnExpressionWhenCalledAtPath(
path: ObjectPath,
callOptions: CallOptions,
callback: ForEachReturnExpressionCallback,
recursionTracker: EntityPathTracker
) {
if (!this.bound) this.bind();
if (this.variable !== null) {
this.variable.forEachReturnExpressionWhenCalledAtPath(
path,
callOptions,
callback,
recursionTracker
);
}
}

getLiteralValueAtPath(
path: ObjectPath,
recursionTracker: ImmutableEntityPathTracker
Expand All @@ -101,10 +79,10 @@ export default class Identifier extends NodeBase {

getReturnExpressionWhenCalledAtPath(
path: ObjectPath,
calledPathTracker: ImmutableEntityPathTracker
recursionTracker: ImmutableEntityPathTracker
) {
if (this.variable !== null) {
return this.variable.getReturnExpressionWhenCalledAtPath(path, calledPathTracker);
return this.variable.getReturnExpressionWhenCalledAtPath(path, recursionTracker);
}
return UNKNOWN_EXPRESSION;
}
Expand Down Expand Up @@ -189,23 +167,6 @@ export default class Identifier extends NodeBase {
}
}

someReturnExpressionWhenCalledAtPath(
path: ObjectPath,
callOptions: CallOptions,
predicateFunction: SomeReturnExpressionCallback,
options: ExecutionPathOptions
) {
if (this.variable) {
return this.variable.someReturnExpressionWhenCalledAtPath(
path,
callOptions,
predicateFunction,
options
);
}
return predicateFunction(options, UNKNOWN_EXPRESSION);
}

private disallowImportReassignment() {
this.context.error(
{
Expand Down
20 changes: 0 additions & 20 deletions src/ast/nodes/Literal.ts
Expand Up @@ -9,12 +9,10 @@ import {
LiteralValueOrUnknown,
MemberDescription,
ObjectPath,
someMemberReturnExpressionWhenCalled,
UNKNOWN_EXPRESSION,
UNKNOWN_VALUE
} from '../values';
import * as NodeType from './NodeType';
import { SomeReturnExpressionCallback } from './shared/Expression';
import { Node, NodeBase } from './shared/Node';

export type LiteralValue = string | boolean | null | number | RegExp;
Expand Down Expand Up @@ -74,22 +72,4 @@ export default class Literal<T = LiteralValue> extends NodeBase {
(<[number, number][]>code.indentExclusionRanges).push([this.start + 1, this.end - 1]);
}
}

someReturnExpressionWhenCalledAtPath(
path: ObjectPath,
callOptions: CallOptions,
predicateFunction: SomeReturnExpressionCallback,
options: ExecutionPathOptions
): boolean {
if (path.length === 1) {
return someMemberReturnExpressionWhenCalled(
this.members,
path[0],
callOptions,
predicateFunction,
options
);
}
return true;
}
}

0 comments on commit b114c9d

Please sign in to comment.