Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add property reflection for Polymer computed properties and observers #3184

Closed
12 changes: 10 additions & 2 deletions src/com/google/javascript/jscomp/CheckSideEffects.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ final class CheckSideEffects extends AbstractPostOrderCallback

private final boolean protectSideEffectFreeCode;

private boolean preserveFunctionInjected = false;

CheckSideEffects(AbstractCompiler compiler, boolean report,
boolean protectSideEffectFreeCode) {
this.compiler = compiler;
Expand Down Expand Up @@ -170,7 +172,9 @@ public void visit(NodeTraversal t, Node n, Node parent) {
*/
private void protectSideEffects() {
if (!problemNodes.isEmpty()) {
addExtern();
if (!preserveFunctionInjected) {
addExtern(compiler);
}
for (Node n : problemNodes) {
Node name = IR.name(PROTECTOR_FN).srcref(n);
name.putBooleanProp(Node.IS_CONSTANT_NAME, true);
Expand All @@ -183,7 +187,7 @@ private void protectSideEffects() {
}
}

private void addExtern() {
static void addExtern(AbstractCompiler compiler) {
Node name = IR.name(PROTECTOR_FN);
name.putBooleanProp(Node.IS_CONSTANT_NAME, true);
Node var = IR.var(name);
Expand Down Expand Up @@ -245,6 +249,10 @@ public void visit(NodeTraversal t, Node n, Node parent) {
noSideEffectExterns.add(name);
}
}

if (n.isName() && PROTECTOR_FN.equals(n.getString())) {
preserveFunctionInjected = true;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,9 @@ public boolean isPropertyTestFunction(Node call) {

@Override
public boolean isPropertyRenameFunction(String name) {
return super.isPropertyRenameFunction(name) || "goog.reflect.objectProperty".equals(name);
return super.isPropertyRenameFunction(name)
|| "goog.reflect.objectProperty".equals(name)
|| "$jscomp.reflectProperty".equals(name);
}

@Override
Expand Down
Loading