diff --git a/src/com/google/javascript/jscomp/PolymerPassErrors.java b/src/com/google/javascript/jscomp/PolymerPassErrors.java index 6e946aa7ceb..f9c6973ee07 100644 --- a/src/com/google/javascript/jscomp/PolymerPassErrors.java +++ b/src/com/google/javascript/jscomp/PolymerPassErrors.java @@ -58,6 +58,11 @@ final class PolymerPassErrors { "JSC_POLYMER_UNANNOTATED_BEHAVIOR", "Behavior declarations must be annotated with @polymerBehavior."); + static final DiagnosticType POLYMER_PROPERTIES_INVALID = + DiagnosticType.error( + "JSC_POLYMER_PROPERTIES_INVALID", + "The Polymer element 'properties' must be an object literal."); + static final DiagnosticType POLYMER_CLASS_PROPERTIES_INVALID = DiagnosticType.error( "JSC_POLYMER_CLASS_PROPERTIES_INVALID", diff --git a/src/com/google/javascript/jscomp/PolymerPassStaticUtils.java b/src/com/google/javascript/jscomp/PolymerPassStaticUtils.java index 039b19c5177..f126f4998ad 100644 --- a/src/com/google/javascript/jscomp/PolymerPassStaticUtils.java +++ b/src/com/google/javascript/jscomp/PolymerPassStaticUtils.java @@ -18,6 +18,7 @@ import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkState; import static com.google.javascript.jscomp.PolymerPassErrors.POLYMER_MISPLACED_PROPERTY_JSDOC; +import static com.google.javascript.jscomp.PolymerPassErrors.POLYMER_PROPERTIES_INVALID; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Ascii; @@ -265,6 +266,10 @@ static ImmutableList extractProperties( Node properties = descriptor; if (defType == PolymerClassDefinition.DefinitionType.ObjectLiteral) { properties = NodeUtil.getFirstPropMatchingKey(descriptor, "properties"); + if (properties != null && !properties.isObjectLit()) { + compiler.report(JSError.make(properties, POLYMER_PROPERTIES_INVALID)); + return ImmutableList.of(); + } } if (properties == null) { return ImmutableList.of(); diff --git a/test/com/google/javascript/jscomp/PolymerPassTest.java b/test/com/google/javascript/jscomp/PolymerPassTest.java index 8b775d3cdc2..022dbf86d0d 100644 --- a/test/com/google/javascript/jscomp/PolymerPassTest.java +++ b/test/com/google/javascript/jscomp/PolymerPassTest.java @@ -183,6 +183,22 @@ public void setUp() throws Exception { setGenericNameReplacements(ImmutableMap.of("Interface$UID", "Interface$")); } +/** Regression test for https://github.com/google/closure-compiler/issues/1950 */ + @Test + public void testPropertiesNotObjLit() { + testError( + srcs( + """ + Polymer({ + is: 'x-y', + properties: (function() { + return {}; + })(), + }) + """), + error(PolymerPassErrors.POLYMER_PROPERTIES_INVALID)); + } + @Test public void testPolymerRewriterGeneratesDeclarationOutsideLoadModule() { test(