Skip to content

Commit

Permalink
Ignore unrecognized tags compiler option now includes @tags (#1335)
Browse files Browse the repository at this point in the history
* Ignore unrecognized tags compiler option now includes nested @tags
  • Loading branch information
DylanPiercey committed May 17, 2019
1 parent a2153d2 commit 263a378
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 18 deletions.
9 changes: 1 addition & 8 deletions src/compiler/CompileContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ class CompileContext extends EventEmitter {
writeVersionComment !== "undefined" ? writeVersionComment : true;
this.ignoreUnrecognizedTags =
this.options.ignoreUnrecognizedTags === true;
this.escapeAtTags = this.options.escapeAtTags === true;

this._vars = {};
this._uniqueVars = new UniqueVars();
Expand Down Expand Up @@ -493,18 +492,12 @@ class CompileContext extends EventEmitter {
}

var isAtTag = typeof tagName === "string" && tagName.startsWith("@");

if (isAtTag && this.escapeAtTags) {
tagName = tagName.replace(/^@/, "at_");
elDef.tagName = tagName;
}

var node;
var tagDef;

var taglibLookup = this.taglibLookup;

if ((isAtTag && !this.escapeAtTags) || tagName instanceof Node) {
if (isAtTag || tagName instanceof Node) {
// NOTE: The tag definition can't be determined now
// For @tags it will be determined by the parent
// For dynamic tags we cannot know at compile time
Expand Down
4 changes: 3 additions & 1 deletion src/compiler/Normalizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,11 @@ class Normalizer {
return;
}

var newNode = this.context.createNodeForEl({
var newNode = context.createNodeForEl({
tagName: elNode.rawTagNameExpression
? builder.parseExpression(elNode.rawTagNameExpression)
: context.ignoreUnrecognizedTags && !elNode.parentNode.tagDef
? elNode.tagName.replace(/^@/, "at_") // escapes @tags inside unrecognized tags
: elNode.tagName,
argument: elNode.argument,
params: elNode.params,
Expand Down
5 changes: 0 additions & 5 deletions src/compiler/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,6 @@ if (g.__MARKO_CONFIG) {
*/
ignoreUnrecognizedTags: false,

/**
* Whether <@tags> should error when are used outside a custom component.
*/
escapeAtTags: false,

/**
* Controls whether or not a key should be assigned to all HTML
* and custom tags at compile-time. The default is `true`
Expand Down
1 change: 0 additions & 1 deletion test/__util__/runRenderTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ module.exports = function runRenderTest(dir, snapshot, done, options) {
writeToDisk: main.writeToDisk !== false,
preserveWhitespace: main.preserveWhitespaceGlobal === true,
ignoreUnrecognizedTags: main.ignoreUnrecognizedTags === true,
escapeAtTags: main.escapeAtTags === true,
autoKeyEnabled: !isVDOM
};

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div class="child">
<${input.content}/>
</div>
2 changes: 1 addition & 1 deletion test/render/fixtures/escape-at-tag/expected.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<div><at_hello></at_hello></div>
<div class="child">Child Content</div><missing><at_content>Child Content</at_content></missing>
8 changes: 7 additions & 1 deletion test/render/fixtures/escape-at-tag/template.marko
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
<div><@hello></@hello></div>
<child>
<@content>Child Content</@content>
</child>

<missing>
<@content>Child Content</@content>
</missing>
1 change: 0 additions & 1 deletion test/render/fixtures/escape-at-tag/test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
exports.templateData = {};
exports.ignoreUnrecognizedTags = true;
exports.escapeAtTags = true;

0 comments on commit 263a378

Please sign in to comment.