Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
* Rename StructuredAssignmentTracker -> ObjectShapeTracker
* Rename ReplaceableInitVariable -> ReplaceableInitializationVariable
  and simplify it as most of its logic (including the awkwardly named
  ReplaceableInitStructuredAssignmentTracker) are no longer needed now
  we assume all parameters to have unknown initial values
  • Loading branch information
lukastaegert committed Nov 8, 2017
1 parent ba7f8b2 commit 00a5b9c
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 93 deletions.
2 changes: 1 addition & 1 deletion src/ast/nodes/MemberExpression.js
@@ -1,6 +1,6 @@
import relativeId from '../../utils/relativeId.js';
import Node from '../Node.js';
import { UNKNOWN_KEY } from '../variables/StructuredAssignmentTracker';
import { UNKNOWN_KEY } from '../variables/VariableShapeTracker';

const validProp = /^[a-zA-Z_$][a-zA-Z_$0-9]*$/;

Expand Down
2 changes: 1 addition & 1 deletion src/ast/nodes/ObjectExpression.js
@@ -1,5 +1,5 @@
import Node from '../Node.js';
import { UNKNOWN_KEY } from '../variables/StructuredAssignmentTracker';
import { UNKNOWN_KEY } from '../variables/VariableShapeTracker';

const PROPERTY_KINDS_READ = [ 'init', 'get' ];
const PROPERTY_KINDS_WRITE = [ 'init', 'set' ];
Expand Down
4 changes: 2 additions & 2 deletions src/ast/variables/LocalVariable.js
@@ -1,5 +1,5 @@
import Variable from './Variable';
import StructuredAssignmentTracker from './StructuredAssignmentTracker';
import VariableShapeTracker from './VariableShapeTracker';

// To avoid infinite recursions
const MAX_PATH_LENGTH = 6;
Expand All @@ -10,7 +10,7 @@ export default class LocalVariable extends Variable {
this.isReassigned = false;
this.exportName = null;
this.declarations = new Set( declarator ? [ declarator ] : null );
this.boundExpressions = new StructuredAssignmentTracker();
this.boundExpressions = new VariableShapeTracker();
init && this.boundExpressions.addAtPath( [], init );
}

Expand Down
6 changes: 3 additions & 3 deletions src/ast/variables/ParameterVariable.js
@@ -1,8 +1,8 @@
import ReplaceableInitVariable from './ReplaceableInitVariable';
import ReplaceableInitializationVariable from './ReplaceableInitializationVariable';

export default class ParameterVariable extends ReplaceableInitVariable {
export default class ParameterVariable extends ReplaceableInitializationVariable {
constructor ( identifier ) {
super( identifier.name, identifier );
super( identifier.name, identifier, null );
}

getName () {
Expand Down
40 changes: 0 additions & 40 deletions src/ast/variables/ReplaceableInitStructuredAssignmentTracker.js

This file was deleted.

42 changes: 0 additions & 42 deletions src/ast/variables/ReplaceableInitVariable.js

This file was deleted.

36 changes: 36 additions & 0 deletions src/ast/variables/ReplaceableInitializationVariable.js
@@ -0,0 +1,36 @@
import LocalVariable from './LocalVariable';
import { UNKNOWN_ASSIGNMENT } from '../values';

export default class ReplaceableInitializationVariable extends LocalVariable {
constructor ( name, declarator ) {
super( name, declarator, null );
}

getName () {
return this.name;
}

hasEffectsWhenAccessedAtPath ( path, options ) {
return this._getInit( options ).hasEffectsWhenAccessedAtPath( path, options )
|| super.hasEffectsWhenAccessedAtPath( path, options );
}

hasEffectsWhenAssignedAtPath ( path, options ) {
return this._getInit( options ).hasEffectsWhenAssignedAtPath( path, options )
|| super.hasEffectsWhenAssignedAtPath( path, options );
}

hasEffectsWhenCalledAtPath ( path, callOptions, options ) {
return this._getInit( options ).hasEffectsWhenCalledAtPath( path, callOptions, options )
|| super.hasEffectsWhenCalledAtPath( path, callOptions, options );
}

someReturnExpressionWhenCalledAtPath ( path, callOptions, predicateFunction, options ) {
return this._getInit( options ).someReturnExpressionWhenCalledAtPath( path, callOptions, predicateFunction, options )
|| super.someReturnExpressionWhenCalledAtPath( path, callOptions, predicateFunction, options );
}

_getInit ( options ) {
return options.getReplacedVariableInit( this ) || UNKNOWN_ASSIGNMENT;
}
}
4 changes: 2 additions & 2 deletions src/ast/variables/ThisVariable.js
@@ -1,6 +1,6 @@
import ReplaceableInitVariable from './ReplaceableInitVariable';
import ReplaceableInitializationVariable from './ReplaceableInitializationVariable';

export default class ThisVariable extends ReplaceableInitVariable {
export default class ThisVariable extends ReplaceableInitializationVariable {
constructor () {
super( 'this', null );
}
Expand Down
Expand Up @@ -5,7 +5,7 @@ export const UNKNOWN_KEY = { type: 'UNKNOWN_KEY' };

const UNKNOWN_ASSIGNMENTS = new Map( [ [ SET_KEY, new Set( [ UNKNOWN_ASSIGNMENT ] ) ] ] );

export default class StructuredAssignmentTracker {
export default class VariableShapeTracker {
constructor () {
this._assignments = new Map( [ [ SET_KEY, new Set() ] ] );
}
Expand All @@ -21,7 +21,7 @@ export default class StructuredAssignmentTracker {
} else {
const [ nextPath, ...remainingPath ] = path;
if ( !this._assignments.has( nextPath ) ) {
this._assignments.set( nextPath, new StructuredAssignmentTracker() );
this._assignments.set( nextPath, new VariableShapeTracker() );
}
this._assignments.get( nextPath ).addAtPath( remainingPath, assignment );
}
Expand Down

0 comments on commit 00a5b9c

Please sign in to comment.