use of com.google.javascript.jscomp.GlobalNamespace.Name in project closure-compiler by google.
the class CheckGlobalNames method process.
@Override
public void process(Node externs, Node root) {
if (namespace == null) {
namespace = new GlobalNamespace(compiler, externs, root);
}
// Find prototype properties that will affect our analysis.
checkState(namespace.hasExternsRoot());
findPrototypeProps("Object", objectPrototypeProps);
findPrototypeProps("Function", functionPrototypeProps);
objectPrototypeProps.addAll(convention.getIndirectlyDeclaredProperties());
for (Name name : namespace.getNameForest()) {
// which this check forbids.
if (name.inExterns) {
continue;
}
checkDescendantNames(name, name.globalSets + name.localSets > 0);
}
}
use of com.google.javascript.jscomp.GlobalNamespace.Name in project closure-compiler by google.
the class ProcessDefinesTest method testReassignAfterNonGlobalRef.
public void testReassignAfterNonGlobalRef() {
test(lines("/** @fileoverview @suppress {newCheckTypes} */", "/** @define {boolean} */ var DEF=true;", "var x=function(){var y=DEF};", "DEF=false"), lines("/** @fileoverview @suppress {newCheckTypes} */", "/** @define {boolean} */ var DEF = false;", "var x = function(){var y = DEF; };", "false"));
Name def = namespace.getNameIndex().get("DEF");
assertThat(def.getRefs()).hasSize(2);
assertEquals(1, def.globalSets);
assertNotNull(def.getDeclaration());
}
use of com.google.javascript.jscomp.GlobalNamespace.Name in project closure-compiler by google.
the class ProcessDefinesTest method testSimpleReassign2.
public void testSimpleReassign2() {
test(lines("/** @fileoverview @suppress {newCheckTypes} */", "/** @define {number|boolean} */ var DEF=false;", "DEF=true;", "DEF=3"), lines("/** @fileoverview @suppress {newCheckTypes} */", "/** @define {number|boolean} */ var DEF=3;", "true;3"));
Name def = namespace.getNameIndex().get("DEF");
assertThat(def.getRefs()).hasSize(1);
assertEquals(1, def.globalSets);
assertNotNull(def.getDeclaration());
}
use of com.google.javascript.jscomp.GlobalNamespace.Name in project closure-compiler by google.
the class ProcessDefinesTest method testNamespacedDefine1.
public void testNamespacedDefine1() {
test("var a = {}; /** @define {boolean} */ a.B = false; a.B = true;", "var a = {}; /** @define {boolean} */ a.B = true; true;");
Name aDotB = namespace.getNameIndex().get("a.B");
assertThat(aDotB.getRefs()).hasSize(1);
assertEquals(1, aDotB.globalSets);
assertNotNull(aDotB.getDeclaration());
}
use of com.google.javascript.jscomp.GlobalNamespace.Name in project closure-compiler by google.
the class AggressiveInlineAliases method referencesCollapsibleProperty.
/**
* Returns whether a ReferenceCollection for some aliasing variable references a property on the
* original aliased variable that may be collapsed in CollapseProperties.
*
* <p>See {@link GlobalNamespace.Name#canCollapse} for what can/cannot be collapsed.
*/
private boolean referencesCollapsibleProperty(ReferenceCollection aliasRefs, Name aliasedName, GlobalNamespace namespace) {
for (Reference ref : aliasRefs.references) {
if (ref.getParent() == null) {
continue;
}
if (ref.getParent().isGetProp()) {
Node propertyNode = ref.getNode().getNext();
// e.g. if the reference is "alias.b.someProp", this will be "b".
String propertyName = propertyNode.getString();
// e.g. if the aliased name is "originalName", this will be "originalName.b".
String originalPropertyName = aliasedName.getName() + "." + propertyName;
Name originalProperty = namespace.getOwnSlot(originalPropertyName);
// If the original property isn't in the namespace or can't be collapsed, keep going.
if (originalProperty == null || !originalProperty.canCollapse()) {
continue;
}
return true;
}
}
return false;
}
Aggregations