Skip to content

Commit

Permalink
Add property reflection for Polymer computed property and complex obs…
Browse files Browse the repository at this point in the history
…erver strings

Closes #3184.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=232359838
  • Loading branch information
ChadKillingsworth authored and blickly committed Feb 6, 2019
1 parent ac40861 commit 4cd6295
Show file tree
Hide file tree
Showing 8 changed files with 837 additions and 13 deletions.
14 changes: 12 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,9 @@ final class CheckSideEffects extends AbstractPostOrderCallback

private final boolean protectSideEffectFreeCode;

/** Whether the synthetic extern for JSCOMPILER_PRESERVE has been injected */
private boolean preserveFunctionInjected = false;

CheckSideEffects(AbstractCompiler compiler, boolean report,
boolean protectSideEffectFreeCode) {
this.compiler = compiler;
Expand Down Expand Up @@ -170,7 +173,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 +188,8 @@ private void protectSideEffects() {
}
}

private void addExtern() {
/** Injects JSCOMPILER_PRESEVE into the synthetic externs */
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 +251,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

0 comments on commit 4cd6295

Please sign in to comment.