Explorar el Código

Add warning for x-for key not being an integer or string

Caleb Porzio hace 4 años
padre
commit
0710e33a59
Se han modificado 1 ficheros con 5 adiciones y 0 borrados
  1. 5 0
      packages/alpinejs/src/directives/x-for.js

+ 5 - 0
packages/alpinejs/src/directives/x-for.js

@@ -5,6 +5,7 @@ import { reactive } from '../reactivity'
 import { initTree } from '../lifecycle'
 import { mutateDom } from '../mutation'
 import { flushJobs } from '../scheduler'
+import { warn } from '../utils/warn'
 
 directive('for', (el, { expression }, { effect, cleanup }) => {
     let iteratorNames = parseForExpression(expression)
@@ -177,6 +178,10 @@ function loop(el, iteratorNames, evaluateItems, evaluateKey) {
                 initTree(clone)
             })
 
+            if (typeof key === 'object') {
+                warn('x-for key cannot be an object, it must be a string or an integer', templateEl)
+            }
+
             lookup[key] = clone
         }