Skip to content

Commit cbc2c5d

Browse files
committed
Fix PolymerPass crash (#1950)
1 parent 678b655 commit cbc2c5d

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

src/com/google/javascript/jscomp/PolymerPassErrors.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ final class PolymerPassErrors {
5858
"JSC_POLYMER_UNANNOTATED_BEHAVIOR",
5959
"Behavior declarations must be annotated with @polymerBehavior.");
6060

61+
static final DiagnosticType POLYMER_PROPERTIES_INVALID =
62+
DiagnosticType.error(
63+
"JSC_POLYMER_PROPERTIES_INVALID",
64+
"The Polymer element 'properties' must be an object literal.");
65+
6166
static final DiagnosticType POLYMER_CLASS_PROPERTIES_INVALID =
6267
DiagnosticType.error(
6368
"JSC_POLYMER_CLASS_PROPERTIES_INVALID",

src/com/google/javascript/jscomp/PolymerPassStaticUtils.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import static com.google.common.base.Preconditions.checkNotNull;
1919
import static com.google.common.base.Preconditions.checkState;
2020
import static com.google.javascript.jscomp.PolymerPassErrors.POLYMER_MISPLACED_PROPERTY_JSDOC;
21+
import static com.google.javascript.jscomp.PolymerPassErrors.POLYMER_PROPERTIES_INVALID;
2122

2223
import com.google.common.annotations.VisibleForTesting;
2324
import com.google.common.base.Ascii;
@@ -265,6 +266,10 @@ static ImmutableList<MemberDefinition> extractProperties(
265266
Node properties = descriptor;
266267
if (defType == PolymerClassDefinition.DefinitionType.ObjectLiteral) {
267268
properties = NodeUtil.getFirstPropMatchingKey(descriptor, "properties");
269+
if (properties != null && !properties.isObjectLit()) {
270+
compiler.report(JSError.make(properties, POLYMER_PROPERTIES_INVALID));
271+
return ImmutableList.of();
272+
}
268273
}
269274
if (properties == null) {
270275
return ImmutableList.of();

test/com/google/javascript/jscomp/PolymerPassTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,22 @@ public void setUp() throws Exception {
183183
setGenericNameReplacements(ImmutableMap.of("Interface$UID", "Interface$"));
184184
}
185185

186+
/** Regression test for https://github.com/google/closure-compiler/issues/1950 */
187+
@Test
188+
public void testPropertiesNotObjLit() {
189+
testError(
190+
srcs(
191+
"""
192+
Polymer({
193+
is: 'x-y',
194+
properties: (function() {
195+
return {};
196+
})(),
197+
})
198+
"""),
199+
error(PolymerPassErrors.POLYMER_PROPERTIES_INVALID));
200+
}
201+
186202
@Test
187203
public void testPolymerRewriterGeneratesDeclarationOutsideLoadModule() {
188204
test(

0 commit comments

Comments
 (0)