rename "reassigned" to "constant" to reflect purpose of the property better

This commit is contained in:
Sebastian McKenzie 2015-03-14 04:44:51 +11:00
parent 1f9f57a2a6
commit 080a844457
7 changed files with 15 additions and 13 deletions

View File

@ -209,7 +209,7 @@ class ClassTransformer {
}
// we have no constructor, we have a super, and the super doesn't appear to be falsy
if (!this.hasConstructor && this.hasSuper) { // todo: t.evaluateTruthy(superName, this.scope) !== false
if (!this.hasConstructor && this.hasSuper && this.path.get("superClass").evaluateTruthy() !== false) {
var helperName = "class-super-constructor-call";
if (this.isLoose) helperName += "-loose";
constructor.body.body.push(util.template(helperName, {

View File

@ -432,7 +432,7 @@ class DestructuringTransformer {
} else {
arrayRef = this.scope.generateUidBasedOnNode(arrayRef);
this.nodes.push(this.buildVariableDeclaration(arrayRef, toArray));
this.getBinding(arrayRef.name).assignTypeGeneric("Array");
//this.getBinding(arrayRef.name).assignTypeGeneric("Array");
}
//

View File

@ -144,7 +144,7 @@ class TailCallTransformer {
// check if the ownerId has been reassigned, if it has then it's not safe to
// perform optimisations
var ownerIdInfo = this.scope.getBinding(this.ownerId.name);
return ownerIdInfo && ownerIdInfo.reassigned;
return ownerIdInfo && !ownerIdInfo.constant;
}
run() {

View File

@ -3,7 +3,7 @@ import * as t from "../types";
export default class Binding {
constructor({ identifier, scope, path, kind }) {
this.identifier = identifier;
this.reassigned = false;
this.constant = true;
this.scope = scope;
this.path = path;
this.kind = kind;
@ -50,7 +50,7 @@ export default class Binding {
*/
reassign() {
this.reassigned = true;
this.constant = false;
if (this.typeAnnotationInferred) {
// destroy the inferred typeAnnotation

View File

@ -1,4 +1,4 @@
import * as t from "./index";
import * as t from "../../types";
/**
* Description

View File

@ -61,8 +61,10 @@ export default class TraversalPath {
return this.data[key] = val;
}
getData(key) {
return this.data[key];
getData(key, def) {
var val = this.data[key];
if (!val && def) val = this.data[key] = def;
return val;
}
setScope(file?) {
@ -270,7 +272,7 @@ export default class TraversalPath {
}
} else if (this.isIdentifier()) {
var binding = this.scope.getBinding(this.node.name);
if (!binding || binding.reassigned) return;
if (!binding || !binding.constant) return;
if (binding.path === this) {
return this;

View File

@ -44,11 +44,11 @@ var programReferenceVisitor = {
} else if (t.isLabeledStatement(node)) {
state.addGlobal(node);
} else if (t.isAssignmentExpression(node)) {
scope.registerBindingReassignment(this.get("left"), this.get("right"));
scope.registerConstantViolation(this.get("left"), this.get("right"));
} else if (t.isUpdateExpression(node)) {
// TODO
scope.registerConstantViolation(this.get("argument"), null);
} else if (t.isUnaryExpression(node) && node.operator === "delete") {
scope.registerBindingReassignment(this.get("left"), null);
scope.registerConstantViolation(this.get("left"), null);
}
}
};
@ -320,7 +320,7 @@ export default class Scope {
* Description
*/
registerBindingReassignment(left: TraversalPath, right: TraversalPath) {
registerConstantViolation(left: TraversalPath, right: TraversalPath) {
var ids = left.getBindingIdentifiers();
for (var name in ids) {
var binding = this.getBinding(name);