From 71c10bf74d03ef7bf21d96e424b21e080b8d6904 Mon Sep 17 00:00:00 2001 From: Patrick Steele-Idem Date: Fri, 3 Nov 2017 10:45:45 -0600 Subject: [PATCH] Allow PascalCase tag to be used for non-pascal-case tag --- src/compiler/CompileContext.js | 3 ++- src/compiler/Walker.js | 1 - src/compiler/ast/ArrayContainer.js | 3 ++- src/compiler/taglib-loader/scanTagsDir.js | 1 - src/compiler/taglib-lookup/TaglibLookup.js | 22 +++++++++++++++++-- .../components/hello/index.marko | 1 + .../pascal-case-caller/expected.html | 1 + .../pascal-case-caller/template.marko | 1 + 8 files changed, 27 insertions(+), 6 deletions(-) create mode 100644 test/autotests/render-deprecated/pascal-case-caller/components/hello/index.marko create mode 100644 test/autotests/render-deprecated/pascal-case-caller/expected.html create mode 100644 test/autotests/render-deprecated/pascal-case-caller/template.marko diff --git a/src/compiler/CompileContext.js b/src/compiler/CompileContext.js index 68cdd6c8b3..42d1fe74d5 100644 --- a/src/compiler/CompileContext.js +++ b/src/compiler/CompileContext.js @@ -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) { @@ -553,7 +554,7 @@ class CompileContext extends EventEmitter { // Attribute will be name for placeholder attributes. For example:
return; } - let attrDef = taglibLookup.getAttribute(tagName, attrName); + let attrDef = taglibLookup.getAttribute(tagDef ? tagDef.name : tagName, attrName); if (!attrDef) { if (tagDef) { if (node.removeAttribute) { diff --git a/src/compiler/Walker.js b/src/compiler/Walker.js index d5236b2173..c10c2b62e0 100644 --- a/src/compiler/Walker.js +++ b/src/compiler/Walker.js @@ -1,6 +1,5 @@ 'use strict'; var isArray = Array.isArray; -var Container = require('./ast/Container'); function noop() {} diff --git a/src/compiler/ast/ArrayContainer.js b/src/compiler/ast/ArrayContainer.js index 16735eb323..465b479ca9 100644 --- a/src/compiler/ast/ArrayContainer.js +++ b/src/compiler/ast/ArrayContainer.js @@ -28,16 +28,17 @@ class ArrayContainer extends Container { for (var i=0; i { newChild.container = this; }); + oldChild.detach(); } else { array[i] = newChild; newChild.container = this; + oldChild.detach(); } return true; } diff --git a/src/compiler/taglib-loader/scanTagsDir.js b/src/compiler/taglib-loader/scanTagsDir.js index ff3509d6e0..d97c5ad63c 100644 --- a/src/compiler/taglib-loader/scanTagsDir.js +++ b/src/compiler/taglib-loader/scanTagsDir.js @@ -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; diff --git a/src/compiler/taglib-lookup/TaglibLookup.js b/src/compiler/taglib-lookup/TaglibLookup.js index 1ac76b8f94..da80788678 100644 --- a/src/compiler/taglib-lookup/TaglibLookup.js +++ b/src/compiler/taglib-lookup/TaglibLookup.js @@ -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)) { @@ -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) { @@ -420,4 +438,4 @@ class TaglibLookup { } } -module.exports = TaglibLookup; \ No newline at end of file +module.exports = TaglibLookup; diff --git a/test/autotests/render-deprecated/pascal-case-caller/components/hello/index.marko b/test/autotests/render-deprecated/pascal-case-caller/components/hello/index.marko new file mode 100644 index 0000000000..df1dd69946 --- /dev/null +++ b/test/autotests/render-deprecated/pascal-case-caller/components/hello/index.marko @@ -0,0 +1 @@ +
Hello ${input.name}
diff --git a/test/autotests/render-deprecated/pascal-case-caller/expected.html b/test/autotests/render-deprecated/pascal-case-caller/expected.html new file mode 100644 index 0000000000..5a9edab733 --- /dev/null +++ b/test/autotests/render-deprecated/pascal-case-caller/expected.html @@ -0,0 +1 @@ +
Hello Frank
diff --git a/test/autotests/render-deprecated/pascal-case-caller/template.marko b/test/autotests/render-deprecated/pascal-case-caller/template.marko new file mode 100644 index 0000000000..8b6a040fe3 --- /dev/null +++ b/test/autotests/render-deprecated/pascal-case-caller/template.marko @@ -0,0 +1 @@ +