Skip to content

Commit

Permalink
Allow PascalCase tag to be used for non-pascal-case tag
Browse files Browse the repository at this point in the history
  • Loading branch information
patrick-steele-idem committed Nov 7, 2017
1 parent d3e0fff commit 71c10bf
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/compiler/CompileContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,7 @@ class CompileContext extends EventEmitter {
} else {
if (typeof tagName === 'string') {
tagDef = taglibLookup.getTag(tagName);

if (!tagDef && !this.isMacro(tagName) && tagName.indexOf(':') === -1) {
var customElement = htmlElements.getRegisteredElement(tagName, this.dirname);
if (customElement) {
Expand Down Expand Up @@ -553,7 +554,7 @@ class CompileContext extends EventEmitter {
// Attribute will be name for placeholder attributes. For example: <div ${data.myAttrs}>
return;
}
let attrDef = taglibLookup.getAttribute(tagName, attrName);
let attrDef = taglibLookup.getAttribute(tagDef ? tagDef.name : tagName, attrName);
if (!attrDef) {
if (tagDef) {
if (node.removeAttribute) {
Expand Down
1 change: 0 additions & 1 deletion src/compiler/Walker.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';
var isArray = Array.isArray;
var Container = require('./ast/Container');

function noop() {}

Expand Down
3 changes: 2 additions & 1 deletion src/compiler/ast/ArrayContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,17 @@ class ArrayContainer extends Container {
for (var i=0; i<len; i++) {
var curChild = array[i];
if (curChild === oldChild) {
oldChild.detach();
if (Array.isArray(newChild)) {
let newChildren = newChild;
array.splice.apply(array, [i, 1].concat(newChildren));
newChildren.forEach((newChild) => {
newChild.container = this;
});
oldChild.detach();
} else {
array[i] = newChild;
newChild.container = this;
oldChild.detach();
}
return true;
}
Expand Down
1 change: 0 additions & 1 deletion src/compiler/taglib-loader/scanTagsDir.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ module.exports = function scanTagsDir(tagsConfigPath, tagsConfigDirname, dir, ta
tagName = childFilename.slice(0, 0 - ext.length);
tagDirname = dir;
tagDef = createDefaultTagDef();
debugger;
tagDef.template = tagFilePath = nodePath.join(dir, childFilename);
} else {
tagName = prefix + childFilename;
Expand Down
22 changes: 20 additions & 2 deletions src/compiler/taglib-lookup/TaglibLookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,18 @@ function TAG_COMPARATOR(a, b) {
return a.localeCompare(b);
}

function toLowerCase(tagName) {
return tagName.replace(/(^[A-Z])|([a-z][A-Z])/g, function(match, startMatch, nonStartMatch) {
if (startMatch) {
return startMatch.toLowerCase();
} else if (nonStartMatch) {
return nonStartMatch[0] + '-' + nonStartMatch[1];
} else {
return match;
}
});
}

function merge(target, source) {
for (var k in source) {
if (source.hasOwnProperty(k)) {
Expand Down Expand Up @@ -239,7 +251,13 @@ class TaglibLookup {
}

var tagName = element.tagName;
return tags[tagName];

let tagDef = tags[tagName];
if (!tagDef && /[A-Z]/.test(tagName.charAt(0))) {
tagDef = tags[toLowerCase(tagName)];
}

return tagDef;
}

getAttribute(element, attr) {
Expand Down Expand Up @@ -420,4 +438,4 @@ class TaglibLookup {
}
}

module.exports = TaglibLookup;
module.exports = TaglibLookup;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div>Hello ${input.name}</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div>Hello Frank</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<Hello name="Frank"/>

0 comments on commit 71c10bf

Please sign in to comment.