Skip to content

Commit

Permalink
Fixes #705 - Throw error when the root HTML element has a dynamic id …
Browse files Browse the repository at this point in the history
…attribute.
  • Loading branch information
austinkelleher committed May 31, 2017
1 parent fe60da9 commit f73c236
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/components/taglib/TransformHelper/handleRootNodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,16 @@ module.exports = function handleRootNodes() {
hasLegacyExplicitBind = true;
} else {
if (node.hasAttribute('id')) {
let id = node.getAttributeValue('id');

if (id && id.name) {
context.addError('Root HTML element should not have a dynamic `id` attribute');
return;
}

hasIdCount++;
nodeWithAssignedId = node;
assignedId = node.getAttributeValue('id');
assignedId = id;
}

if (tagName === 'style') {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
$ var id = 'abc123';

<div id=id/>
6 changes: 6 additions & 0 deletions test/autotests/render/error-variable-id-root-node/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
var expect = require('chai').expect;

exports.checkError = function(e) {
var message = e.toString();
expect(message).to.contain('Root HTML element should not have a dynamic `id` attribute');
};

0 comments on commit f73c236

Please sign in to comment.