Fixes #705 - Throw error when the root HTML element is a component and has a dynamic id attribute.

This commit is contained in:
Austin Kelleher 2017-06-12 14:05:35 -04:00
parent 7aac3aae38
commit 11580da273
6 changed files with 23 additions and 0 deletions

View File

@ -266,6 +266,13 @@ module.exports = function handleRootNodes() {
var nextKey = 0;
rootNodes.forEach((curNode, i) => {
let id = curNode.getAttributeValue('id');
if (id && id.type !== 'Literal') {
context.addError('Root HTML element should not have a dynamic `id` attribute. See: https://github.com/marko-js/marko/wiki/Error:-Dynamic-root-HTML-element-id-attribute');
return;
}
curNode.setFlag('hasComponentBind');
if (!curNode.hasAttribute('key') && !curNode.hasAttribute('ref')) {

View File

@ -0,0 +1,5 @@
class {}
$ var id = 'abc123';
<div id=id/>

View File

@ -0,0 +1,6 @@
var expect = require('chai').expect;
exports.checkError = function(e) {
var message = e.toString();
expect(message).to.contain('https://github.com/marko-js/marko/wiki/Error:-Dynamic-root-HTML-element-id-attribute');
};

View File

@ -0,0 +1 @@
<div id="abc123"></div>

View File

@ -0,0 +1,3 @@
$ var id = 'abc123';
<div id=id/>

View File

@ -0,0 +1 @@
exports.templateData = {};