File tree Expand file tree Collapse file tree 3 files changed +26
-0
lines changed
src/com/google/javascript/jscomp
test/com/google/javascript/jscomp Expand file tree Collapse file tree 3 files changed +26
-0
lines changed Original file line number Diff line number Diff 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" ,
Original file line number Diff line number Diff line change 1818import static com .google .common .base .Preconditions .checkNotNull ;
1919import static com .google .common .base .Preconditions .checkState ;
2020import static com .google .javascript .jscomp .PolymerPassErrors .POLYMER_MISPLACED_PROPERTY_JSDOC ;
21+ import static com .google .javascript .jscomp .PolymerPassErrors .POLYMER_PROPERTIES_INVALID ;
2122
2223import com .google .common .annotations .VisibleForTesting ;
2324import 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 ();
Original file line number Diff line number Diff 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 (
You can’t perform that action at this time.
0 commit comments