mirror of
https://github.com/marko-js/marko.git
synced 2025-12-08 19:26:05 +00:00
Fixes #705 - Throw error when the root HTML element is a component and has a dynamic id attribute.
This commit is contained in:
parent
7aac3aae38
commit
11580da273
@ -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')) {
|
||||
|
||||
@ -0,0 +1,5 @@
|
||||
class {}
|
||||
|
||||
$ var id = 'abc123';
|
||||
|
||||
<div id=id/>
|
||||
@ -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');
|
||||
};
|
||||
@ -0,0 +1 @@
|
||||
<div id="abc123"></div>
|
||||
@ -0,0 +1,3 @@
|
||||
$ var id = 'abc123';
|
||||
|
||||
<div id=id/>
|
||||
1
test/autotests/render/variable-id-root-node/test.js
Normal file
1
test/autotests/render/variable-id-root-node/test.js
Normal file
@ -0,0 +1 @@
|
||||
exports.templateData = {};
|
||||
Loading…
x
Reference in New Issue
Block a user