Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/com/google/javascript/jscomp/PolymerPassErrors.java
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 5 additions & 0 deletions src/com/google/javascript/jscomp/PolymerPassStaticUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -265,6 +266,10 @@ static ImmutableList<MemberDefinition> 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();
Expand Down
16 changes: 16 additions & 0 deletions test/com/google/javascript/jscomp/PolymerPassTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down