Lazy attributes for dynamic tags (#1365)

This commit is contained in:
Dylan Piercey 2019-06-25 15:01:52 -07:00 committed by GitHub
parent 25b4220c8b
commit 881f1b8da7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
60 changed files with 253 additions and 288 deletions

View File

@ -490,11 +490,10 @@ class Builder {
}
renderBodyFunction(body, params) {
let name = "renderBody";
if (!params) {
params = [new Identifier({ name: "out" })];
}
return new FunctionDeclaration({ name, params, body });
return new FunctionDeclaration({ name: null, params, body });
}
require(path) {

View File

@ -15,6 +15,7 @@ var extend = require("raptor-util/extend");
var Walker = require("./Walker");
var EventEmitter = require("events").EventEmitter;
var utilFingerprint = require("./util/finger-print");
var safeVarName = require("./util/safeVarName");
var htmlElements = require("./util/html-elements");
var markoModules = require("./modules");
@ -278,6 +279,19 @@ class CompileContext extends EventEmitter {
return this.data[name];
}
nextUniqueId(name) {
name = name || "";
var lookup = `_${name}UniqueIdCounter`;
var componentNextElId = this.data[lookup];
if (componentNextElId == null) {
this.data[lookup] = 0;
}
var id = this.data[lookup]++;
return name ? `$${safeVarName(name)}$${id}` : `${id}`;
}
deprecate(message, node) {
var currentNode = node || this._currentNode;
var location = currentNode && currentNode.pos;

View File

@ -2,7 +2,6 @@
const HtmlElement = require("./HtmlElement");
const removeDashes = require("../util/removeDashes");
const safeVarName = require("../util/safeVarName");
const ok = require("assert").ok;
const merge = require("../util/mergeProps");
const complain = require("complain");
@ -130,29 +129,6 @@ function checkIfNestedTagCanBeAddedDirectlyToInput(nestedTag, parentCustomTag) {
return true;
}
function getNextNestedTagVarName(tagDef, context) {
let key = "customTag" + tagDef.name;
let nestedTagVarInfo =
context.data[key] ||
(context.data[key] = {
next: 0
});
return safeVarName(tagDef.name) + nestedTagVarInfo.next++;
}
function getNextRenderBodyVar(context) {
let key = "CustomTag_renderBodyVar";
let nextVarInfo =
context.data[key] ||
(context.data[key] = {
next: 0
});
return "renderBodyConditional" + nextVarInfo.next++;
}
function processDirectlyNestedTags(node, codegen) {
node.forEachChild(child => {
if (child.type === "CustomTag") {
@ -549,10 +525,9 @@ class CustomTag extends HtmlElement {
if (!this._nestedTagVar) {
let tagDef = this.tagDef;
let builder = context.builder;
let nextNestedTagVarName = getNextNestedTagVarName(tagDef, context);
this._nestedTagVar = builder.identifier(nextNestedTagVarName);
this._nestedTagVar = builder.identifier(
context.nextUniqueId(`nestedTag${tagDef.name}`)
);
}
return this._nestedTagVar;
@ -562,7 +537,13 @@ class CustomTag extends HtmlElement {
return codegen.builder.functionCall(tagVar, tagArgs);
}
generateRenderNode(codegen, tagDef, inputProps, parentCustomTag) {
generateRenderNode(
codegen,
tagDef,
inputProps,
parentCustomTag,
renderBody
) {
let context = codegen.context;
let builder = context.builder;
let renderTagNode;
@ -635,7 +616,15 @@ class CustomTag extends HtmlElement {
tagArgs = [
builder.identifierOut(),
this.tagNameExpression,
inputProps,
inputProps.type === "ObjectExpression" &&
!inputProps.properties.length
? builder.literalNull()
: builder.functionDeclaration(
null,
null,
builder.returnStatement(inputProps)
),
renderBody || builder.literalNull(),
argumentNode,
properties
? builder.objectExpression(
@ -683,7 +672,6 @@ class CustomTag extends HtmlElement {
if (hasBody) {
if (tagDef.bodyFunction) {
let bodyFunction = tagDef.bodyFunction;
let bodyFunctionName = bodyFunction.name;
let bodyFunctionParams = bodyFunction.params.map(function(
param
) {
@ -691,7 +679,7 @@ class CustomTag extends HtmlElement {
});
return builder.functionDeclaration(
bodyFunctionName,
null,
bodyFunctionParams,
body
);
@ -728,6 +716,7 @@ class CustomTag extends HtmlElement {
}
let parentCustomTag;
let isDynamicTag = tagDef.isDynamicTag;
context.pushData(CUSTOM_TAG_KEY, this);
processDirectlyNestedTags(this, codegen);
@ -808,59 +797,22 @@ class CustomTag extends HtmlElement {
}
}
let bodyOnlyIf = this.bodyOnlyIf;
// let parentTagVar;
let renderBody = this.generateRenderBodyCode(codegen, body);
let renderBodyFunctionVarIdentifier;
let renderBodyFunctionVar;
if (renderBody && bodyOnlyIf) {
// Move the renderBody function into a local variable
renderBodyFunctionVarIdentifier = builder.identifier(
getNextRenderBodyVar(context)
);
renderBodyFunctionVar = builder.var(
renderBodyFunctionVarIdentifier,
renderBody
);
renderBody = renderBodyFunctionVarIdentifier;
}
let additionalAttrs;
if (renderBody) {
if (tagDef.bodyFunction) {
let bodyFunctionName = tagDef.bodyFunction.name;
additionalAttrs = { [bodyFunctionName]: renderBody };
} else {
additionalAttrs = { renderBody };
}
}
let additionalAttrs = renderBody &&
!isDynamicTag && {
[(tagDef.bodyFunction && tagDef.bodyFunction.name) ||
"renderBody"]: renderBody
};
let inputProps = this.buildInputProps(codegen, additionalAttrs);
let renderTagNode = this.generateRenderNode(
codegen,
tagDef,
inputProps,
parentCustomTag
parentCustomTag,
renderBody
);
if (bodyOnlyIf && renderBodyFunctionVar) {
let ifStatement = builder.ifStatement(
bodyOnlyIf,
[
builder.functionCall(renderBodyFunctionVarIdentifier, [
builder.identifierOut()
])
],
builder.elseStatement([renderTagNode])
);
return [renderBodyFunctionVar, ifStatement];
} else {
return renderTagNode;
}
return renderTagNode;
}
}

View File

@ -37,7 +37,6 @@ module.exports = function generateCode(node, codegen) {
var argument = node.argument;
var hasBody = body && body.length;
var openTagOnly = node.openTagOnly;
var bodyOnlyIf = node.bodyOnlyIf;
var selfClosed = node.selfClosed === true;
var isCustomElement = node.customElement;
@ -45,7 +44,7 @@ module.exports = function generateCode(node, codegen) {
body = codegen.generateCode(body);
}
if (hasBody || bodyOnlyIf) {
if (hasBody) {
openTagOnly = false;
selfClosed = false;
} else if (selfClosed) {
@ -86,21 +85,9 @@ module.exports = function generateCode(node, codegen) {
);
}
if (bodyOnlyIf) {
var startIf = builder.ifStatement(builder.negate(bodyOnlyIf), [
startTag
]);
var endIf = builder.ifStatement(builder.negate(bodyOnlyIf), [
endTag,
propertiesScript
]);
return [startIf, body, endIf];
if (openTagOnly) {
return [codegen.generateCode(startTag), propertiesScript];
} else {
if (openTagOnly) {
return [codegen.generateCode(startTag), propertiesScript];
} else {
return [startTag, body, endTag, propertiesScript];
}
return [startTag, body, endTag, propertiesScript];
}
};

View File

@ -50,7 +50,6 @@ class HtmlElement extends Node {
this.openTagOnly = def.openTagOnly;
this.selfClosed = def.selfClosed;
this.bodyOnlyIf = undefined;
this.runtimeFlags = 0; // Runtime flags are used to flag VDOM nodes with important information (flags are OR'd together)
this.key = undefined;
@ -178,15 +177,10 @@ class HtmlElement extends Node {
attributes: this._attributes,
tagString: this.tagString,
argument: this.argument,
body: this.body,
bodyOnlyIf: this.bodyOnlyIf
body: this.body
};
}
setBodyOnlyIf(condition) {
this.bodyOnlyIf = condition;
}
walk(walker) {
this.setTagName(walker.walk(this.tagNameExpression));
this._attributes.walk(walker);

View File

@ -48,8 +48,6 @@ module.exports = function(node, codegen, vdomUtil) {
);
}
var builder = codegen.builder;
var isKeyStatic = vdomUtil.isStaticValue(key);
var isAttrsStatic = checkAttributesStatic(attributes);
var isPropsStatic = checkPropertiesStatic(properties, vdomUtil);
@ -81,11 +79,6 @@ module.exports = function(node, codegen, vdomUtil) {
}
}
var bodyOnlyIf = node.bodyOnlyIf;
if (bodyOnlyIf) {
isHtmlOnly = false;
}
var htmlElVDOM = new HtmlElementVDOM({
key,
tagName,
@ -100,19 +93,7 @@ module.exports = function(node, codegen, vdomUtil) {
isAutoKeyed
});
if (bodyOnlyIf) {
htmlElVDOM.body = null;
var startIf = builder.ifStatement(builder.negate(bodyOnlyIf), [
htmlElVDOM
]);
var endIf = builder.ifStatement(builder.negate(bodyOnlyIf), [
new EndElementVDOM()
]);
return [startIf, body, endIf];
} else if (isHtmlOnly) {
if (isHtmlOnly) {
return htmlElVDOM;
} else {
htmlElVDOM.body = null;

View File

@ -81,7 +81,7 @@ module.exports = function assignComponentId(isRepeated) {
} else {
// Case 3 - We need to add a unique auto key
let parentForKey = getParentForKeyVar(el, this);
let uniqueKey = this.nextUniqueId();
let uniqueKey = context.nextUniqueId();
el.isAutoKeyed = true;
@ -122,9 +122,7 @@ module.exports = function assignComponentId(isRepeated) {
return this.idVarNode;
}
const idVar = builder.identifier(
transformHelper.nextUniqueId("key")
);
const idVar = builder.identifier(context.nextUniqueId("key"));
this.idVarNode = builder.vars([
{
@ -168,7 +166,7 @@ const getParentForKeyVar = (el, transformHelper) => {
if (parentFor.keyVar) return parentFor.keyVar;
const keyScopeIdentifier = builder.identifier(
transformHelper.nextUniqueId("keyScope")
context.nextUniqueId("keyScope")
);
const vars = builder.vars([]);
@ -178,7 +176,7 @@ const getParentForKeyVar = (el, transformHelper) => {
if (firstElement) {
const keyValueIdentifier = builder.identifier(
transformHelper.nextUniqueId("keyValue")
context.nextUniqueId("keyValue")
);
if (firstElement.key) {
@ -232,7 +230,7 @@ const getParentForKeyVar = (el, transformHelper) => {
const createIndexKey = (forNode, transformHelper) => {
const context = transformHelper.context;
const builder = context.builder;
const identifier = builder.identifier(transformHelper.nextUniqueId("for"));
const identifier = builder.identifier(context.nextUniqueId("for"));
const initialize = builder.var(identifier, builder.literal(0));
const parentForKey = getParentForKeyVar(forNode, transformHelper);

View File

@ -54,19 +54,6 @@ class TransformHelper {
);
}
nextUniqueId(name) {
name = name || "";
var lookup = `_${name}UniqueIdCounter`;
var componentNextElId = this.context.data[lookup];
if (componentNextElId == null) {
this.context.data[lookup] = 0;
}
var id = this.context.data[lookup]++;
return name ? `$${name}$${id}` : `${id}`;
}
serializeKey() {
var el = this.el;
var key = el.key;

View File

@ -134,7 +134,8 @@ var helpers = {
d: function dynamicTag(
out,
tag,
attrs,
getAttrs,
renderBody,
args,
props,
componentDef,
@ -142,6 +143,7 @@ var helpers = {
customEvents
) {
if (tag) {
var attrs = getAttrs && getAttrs();
var component = componentDef && componentDef.___component;
if (typeof tag === "string") {
if (customEvents) {
@ -159,17 +161,10 @@ var helpers = {
});
}
if (attrs.renderBody) {
var renderBody = attrs.renderBody;
var otherAttrs = {};
for (var attrKey in attrs) {
if (attrKey !== "renderBody") {
otherAttrs[attrKey] = attrs[attrKey];
}
}
if (renderBody) {
out.___beginElementDynamic(
tag,
otherAttrs,
attrs,
key,
component,
0,
@ -190,13 +185,14 @@ var helpers = {
);
}
} else {
var defaultAttrs = renderBody ? { renderBody: renderBody } : {};
if (attrs == null) {
attrs = {};
attrs = defaultAttrs;
} else if (typeof attrs === "object") {
attrs = Object.keys(attrs).reduce(function(r, key) {
r[removeDashes(key)] = attrs[key];
return r;
}, {});
}, defaultAttrs);
}
if (tag._ || tag.renderer || tag.render) {
@ -256,7 +252,7 @@ var helpers = {
}
}
}
} else if (attrs.renderBody) {
} else if (renderBody) {
var compFlags = componentDef ? componentDef.___flags : 0;
out.___beginFragment(
key,
@ -265,7 +261,7 @@ var helpers = {
? compFlags & FLAG_WILL_RERENDER_IN_BROWSER
: render === w10NOOP
);
attrs.renderBody(out);
renderBody(out);
out.___endFragment();
}
},

View File

@ -1,13 +0,0 @@
if (true) {
if (!(!data.url)) {
out.w("<a" +
marko_attr("href", data.url) +
">");
}
out.w("Hello World");
if (!(!data.url)) {
out.w("</a>");
}
}

View File

@ -1,15 +0,0 @@
"use strict";
module.exports = function(builder) {
var anchor = builder.htmlElement(
"a",
{
href: "data.url"
},
[builder.text(builder.literal("Hello World"))]
);
anchor.setBodyOnlyIf("!data.url");
return builder.ifStatement(builder.literal(true), [anchor]);
};

View File

@ -1,3 +1,3 @@
function renderBody(out) {
function(out) {
out.w("Hello World!");
}

View File

@ -14,7 +14,7 @@ function render(input, out, __component, component, state) {
var data = input;
test_addNestedVariable_tag({
renderBody: function renderBody(out, foo) {
renderBody: function(out, foo) {
out.w("Hello " +
marko_escapeXml(foo) +
"!");

View File

@ -16,12 +16,12 @@ function render(input, out, __component, component, state) {
_provider: data.userInfo,
_name: "data.userInfo",
then: {
renderBody: function renderBody(out, userInfo) {
renderBody: function(out, userInfo) {
out.w("Success!");
}
},
catch: {
renderBody: function renderBody(out) {
renderBody: function(out) {
out.w("something went wrong!");
}
}

View File

@ -17,14 +17,14 @@ function render(input, out, __component, component, state) {
_provider: data.userInfo,
_name: "data.userInfo",
then: {
renderBody: function renderBody(out, userInfo) {
renderBody: function(out, userInfo) {
out.w("Hello " +
marko_escapeXml(testData.name) +
"!");
}
},
placeholder: {
renderBody: function renderBody(out) {
renderBody: function(out) {
out.w("Loading name...");
}
}

View File

@ -18,12 +18,12 @@ function render(input, out, __component, component, state) {
_provider: data.userInfo,
_name: "data.userInfo",
then: {
renderBody: function renderBody(out, userInfo) {
renderBody: function(out, userInfo) {
out.w("4");
}
},
catch: {
renderBody: function renderBody(out, err) {
renderBody: function(out, err) {
if (err.name === "TimeoutError") {
out.w("Timeout has occurred!");
}

View File

@ -19,17 +19,17 @@ function render(input, out, __component, component, state) {
var data = input;
hello_tag(marko_mergeNestedTagsHelper({
renderBody: function renderBody(out, hello0) {
renderBody: function(out, $nestedTaghello$0) {
var $for$0 = 0;
marko_forEach(input.colors, function(color) {
var $keyScope$0 = "[" + (($for$0++) + "]");
hello_foo_nested_tag({
renderBody: function renderBody(out) {
renderBody: function(out) {
out.w("Foo!");
}
}, hello0);
}, $nestedTaghello$0);
});
}
}), out, __component, "0");

View File

@ -13,7 +13,7 @@ var marko_template = module.exports = require("marko/src/html").t(__filename),
function render(input, out, __component, component, state) {
var data = input;
marko_dynamicTag(out, Target, {}, null, null, __component, "0");
marko_dynamicTag(out, Target, null, null, null, null, __component, "0");
}
marko_template._ = marko_renderer(render, {

View File

@ -16,9 +16,11 @@ function render(input, out, __component, component, state) {
__component = widget,
component = __component._c;
marko_dynamicTag(out, input, {
x: 1
}, null, null, __component, "hi");
marko_dynamicTag(out, input, function() {
return {
x: 1
};
}, null, null, null, __component, "hi");
}
marko_template._ = marko_renderer(render, {

View File

@ -30,9 +30,11 @@ function render(input, out, __component, component, state) {
out.w("<li>");
marko_dynamicTag(out, macro_renderTree, {
node: child
}, null, null, __component, "2" + $keyScope$0);
marko_dynamicTag(out, macro_renderTree, function() {
return {
node: child
};
}, null, null, null, __component, "2" + $keyScope$0);
out.w("</li>");
});
@ -41,9 +43,11 @@ function render(input, out, __component, component, state) {
}
}
marko_dynamicTag(out, macro_renderTree, {
node: input.node
}, null, null, __component, "3");
marko_dynamicTag(out, macro_renderTree, function() {
return {
node: input.node
};
}, null, null, null, __component, "3");
}
marko_template._ = marko_renderer(render, {

View File

@ -16,7 +16,7 @@ function render(input, out, __component, component, state) {
test_tag({
nested: true && {
renderBody: function renderBody(out) {
renderBody: function(out) {
out.w("Hello");
}
}
@ -24,7 +24,7 @@ function render(input, out, __component, component, state) {
test_tag({
nested: true && {
renderBody: function renderBody(out) {
renderBody: function(out) {
out.w("Hello");
}
}

View File

@ -16,7 +16,7 @@ function render(input, out, __component, component, state) {
test_message_tag({
body: someCondition && {
renderBody: function renderBody(out) {
renderBody: function(out) {
out.w("My body");
}
}

View File

@ -16,13 +16,13 @@ function render(input, out, __component, component, state) {
header: input.header,
body: {
className: "my-body",
renderBody: function renderBody(out) {
renderBody: function(out) {
out.w("Body content");
}
},
footer: {
className: "my-footer",
renderBody: function renderBody(out) {
renderBody: function(out) {
out.w("Footer content");
}
}

View File

@ -12,44 +12,50 @@ var marko_template = module.exports = require("marko/src/html").t(__filename),
function render(input, out, __component, component, state) {
var data = input;
marko_dynamicTag(out, input, {}, null, null, __component, "0");
marko_dynamicTag(out, input, null, null, null, null, __component, "0");
marko_dynamicTag(out, input.renderThing, {}, null, null, __component, "1");
marko_dynamicTag(out, input.renderThing, null, null, null, null, __component, "1");
marko_dynamicTag(out, input, attrs, null, null, __component, "2");
marko_dynamicTag(out, input, function() {
return attrs;
}, null, null, null, __component, "2");
marko_dynamicTag(out, renderBody, {}, null, null, __component, "3");
marko_dynamicTag(out, renderBody, null, null, null, null, __component, "3");
marko_dynamicTag(out, input.template, {
x: 1
}, null, null, __component, "4");
marko_dynamicTag(out, input.template, function() {
return {
x: 1
};
}, null, null, null, __component, "4");
marko_dynamicTag(out, input.template, {
y: function() {}
}, null, null, __component, "5");
marko_dynamicTag(out, input.template, function() {
return {
y: function() {}
};
}, null, null, null, __component, "5");
marko_dynamicTag(out, {
render: input.barRenderer
}, {}, null, null, __component, "6");
}, null, null, null, null, __component, "6");
marko_dynamicTag(out, function(out) {
input.barRenderer({}, true, out);
}, {}, null, null, __component, "7");
}, null, null, null, null, __component, "7");
if (x) {
marko_dynamicTag(out, renderA, {}, null, null, __component, "8");
marko_dynamicTag(out, renderA, null, null, null, null, __component, "8");
} else if (y) {
marko_dynamicTag(out, renderB, {}, null, null, __component, "9");
marko_dynamicTag(out, renderB, null, null, null, null, __component, "9");
} else {
marko_dynamicTag(out, renderC, {}, null, null, __component, "10");
marko_dynamicTag(out, renderC, null, null, null, null, __component, "10");
}
if (x) {
marko_dynamicTag(out, render, {}, null, null, __component, "11");
marko_dynamicTag(out, render, null, null, null, null, __component, "11");
}
if (!x) {
marko_dynamicTag(out, render, {}, null, null, __component, "12");
marko_dynamicTag(out, render, null, null, null, null, __component, "12");
}
var $for$0 = 0;
@ -57,17 +63,17 @@ function render(input, out, __component, component, state) {
marko_forRange(0, 9, null, function(i) {
var $keyScope$0 = "[" + (($for$0++) + "]");
marko_dynamicTag(out, input.items[i], {}, null, null, __component, "13" + $keyScope$0);
marko_dynamicTag(out, input.items[i], null, null, null, null, __component, "13" + $keyScope$0);
});
let i = 10;
while (i--) {
marko_dynamicTag(out, input, {}, null, null, __component, "14");
marko_dynamicTag(out, input, null, null, null, null, __component, "14");
}
if (z) {
marko_dynamicTag(out, renderD, {}, null, null, __component, "15");
marko_dynamicTag(out, renderD, null, null, null, null, __component, "15");
}
// if.test

View File

@ -19,17 +19,17 @@ function render(input, out, __component, component, state) {
var data = input;
hello_tag(marko_mergeNestedTagsHelper({
renderBody: function renderBody(out, hello0) {
renderBody: function(out, $nestedTaghello$0) {
var $for$0 = 0;
marko_forEach(input.colors, function(color) {
var $keyScope$0 = "[" + (($for$0++) + "]");
hello_foo_nested_tag({
renderBody: function renderBody(out) {
renderBody: function(out) {
out.w("Foo!");
}
}, hello0);
}, $nestedTaghello$0);
});
}
}), out, __component, "0");

View File

@ -16,7 +16,7 @@ function render(input, out, __component, component, state) {
hello_tag({
foo: {
renderBody: function renderBody(out) {
renderBody: function(out) {
out.w("Foo!");
}
}

View File

@ -16,12 +16,12 @@ function render(input, out, __component, component, state) {
_provider: data.userInfo,
_name: "data.userInfo",
then: {
renderBody: function renderBody(out, userInfo) {
renderBody: function(out, userInfo) {
out.w("Success!");
}
},
catch: {
renderBody: function renderBody(out) {
renderBody: function(out) {
out.w("something went wrong!");
}
}

View File

@ -17,14 +17,14 @@ function render(input, out, __component, component, state) {
_provider: data.userInfo,
_name: "data.userInfo",
then: {
renderBody: function renderBody(out, userInfo) {
renderBody: function(out, userInfo) {
out.w("Hello " +
marko_escapeXml(testData.name) +
"!");
}
},
placeholder: {
renderBody: function renderBody(out) {
renderBody: function(out) {
out.w("Loading name...");
}
}

View File

@ -18,12 +18,12 @@ function render(input, out, __component, component, state) {
_provider: data.userInfo,
_name: "data.userInfo",
then: {
renderBody: function renderBody(out, userInfo) {
renderBody: function(out, userInfo) {
out.w("4");
}
},
catch: {
renderBody: function renderBody(out, err) {
renderBody: function(out, err) {
if (err.name === "TimeoutError") {
out.w("Timeout has occurred!");
}

View File

@ -14,7 +14,7 @@ function render(input, out, __component, component, state) {
test_body_function_tag({
name: "World",
myBody: function myBody(foo, bar) {
myBody: function(foo, bar) {
out.w("This is the body content");
}
}, out, __component, "0");

View File

@ -16,7 +16,7 @@ function render(input, out, __component, component, state) {
name: "World",
foo: input.foo,
bar: input.bar,
renderBody: function renderBody(out) {
renderBody: function(out) {
out.w("This is the body content");
}
}, out, __component, "0");

View File

@ -0,0 +1,33 @@
"use strict";
var marko_template = module.exports = require("marko/src/html").t(__filename),
marko_componentType = "/marko-test$1.0.0/compiler/fixtures-html/dynamic-tag-render-body/template.marko",
components_helpers = require("marko/src/runtime/components/helpers"),
marko_renderer = components_helpers.r,
marko_defineComponent = components_helpers.c,
marko_loadTemplate = require("marko/src/runtime/helper-loadTemplate"),
Target = marko_loadTemplate(require.resolve("./target.marko")),
marko_helpers = require("marko/src/runtime/html/helpers"),
marko_dynamicTag = marko_helpers.d;
function render(input, out, __component, component, state) {
var data = input;
marko_dynamicTag(out, Target, null, function(out) {
out.w("Hello");
}, null, null, __component, "0");
}
marko_template._ = marko_renderer(render, {
___implicit: true,
___type: marko_componentType
});
marko_template.Component = marko_defineComponent({}, marko_template._);
marko_template.meta = {
id: "/marko-test$1.0.0/compiler/fixtures-html/dynamic-tag-render-body/template.marko",
tags: [
"./target.marko"
]
};

View File

@ -0,0 +1,5 @@
import Target from './target.marko';
<${Target}>
Hello
</>

View File

@ -13,7 +13,7 @@ var marko_template = module.exports = require("marko/src/html").t(__filename),
function render(input, out, __component, component, state) {
var data = input;
marko_dynamicTag(out, Target, {}, null, null, __component, "0");
marko_dynamicTag(out, Target, null, null, null, null, __component, "0");
}
marko_template._ = marko_renderer(render, {

View File

@ -13,7 +13,7 @@ var marko_template = module.exports = require("marko/src/html").t(__filename),
function render(input, out, __component, component, state) {
var data = input;
marko_dynamicTag(out, other, {}, null, null, __component, "0");
marko_dynamicTag(out, other, null, null, null, null, __component, "0");
}
marko_template._ = marko_renderer(render, {

View File

@ -30,9 +30,11 @@ function render(input, out, __component, component, state) {
out.w("<li>");
marko_dynamicTag(out, macro_renderTree, {
node: child
}, null, null, __component, "2" + $keyScope$0);
marko_dynamicTag(out, macro_renderTree, function() {
return {
node: child
};
}, null, null, null, __component, "2" + $keyScope$0);
out.w("</li>");
});
@ -41,9 +43,11 @@ function render(input, out, __component, component, state) {
}
}
marko_dynamicTag(out, macro_renderTree, {
node: input.node
}, null, null, __component, "3");
marko_dynamicTag(out, macro_renderTree, function() {
return {
node: input.node
};
}, null, null, null, __component, "3");
}
marko_template._ = marko_renderer(render, {

View File

@ -16,7 +16,7 @@ function render(input, out, __component, component, state) {
test_tag({
nested: true && {
renderBody: function renderBody(out) {
renderBody: function(out) {
out.w("Hello");
}
}
@ -24,7 +24,7 @@ function render(input, out, __component, component, state) {
test_tag({
nested: true && {
renderBody: function renderBody(out) {
renderBody: function(out) {
out.w("Hello");
}
}

View File

@ -16,13 +16,13 @@ function render(input, out, __component, component, state) {
header: input.header,
body: {
className: "my-body",
renderBody: function renderBody(out) {
renderBody: function(out) {
out.w("Body content");
}
},
footer: {
className: "my-footer",
renderBody: function renderBody(out) {
renderBody: function(out) {
out.w("Footer content");
}
}

View File

@ -11,7 +11,7 @@ var marko_template = module.exports = require("marko/src/html").t(__filename),
function render(input, out, __component, component, state) {
var data = input;
marko_dynamicTag(out, input.renderBody, {}, [
marko_dynamicTag(out, input.renderBody, null, null, [
...input.items
], null, __component, "0");
}

View File

@ -15,9 +15,11 @@ var marko_template = module.exports = require("marko/src/vdom").t(),
function render(input, out, __component, component, state) {
var data = input;
marko_dynamicTag(out, IncludeTarget, {
foo: "bar"
}, null, null, __component, "0");
marko_dynamicTag(out, IncludeTarget, function() {
return {
foo: "bar"
};
}, null, null, null, __component, "0");
}
marko_template._ = marko_renderer(render, {

View File

@ -14,7 +14,7 @@ var marko_template = module.exports = require("marko/src/vdom").t(),
function render(input, out, __component, component, state) {
var data = input;
marko_dynamicTag(out, foo ? "foo" : "bar", {}, null, null, __component, "0");
marko_dynamicTag(out, foo ? "foo" : "bar", null, null, null, null, __component, "0");
}
marko_template._ = marko_renderer(render, {

View File

@ -15,9 +15,11 @@ var marko_template = module.exports = require("marko/src/vdom").t(),
function render(input, out, __component, component, state) {
var data = input;
marko_dynamicTag(out, IncludeTarget, {
foo: "bar"
}, null, null, __component, "0");
marko_dynamicTag(out, IncludeTarget, function() {
return {
foo: "bar"
};
}, null, null, null, __component, "0");
}
marko_template._ = marko_renderer(render, {

View File

@ -41,7 +41,9 @@ function render(input, out, __component, component, state) {
out.be("li", null, "2" + $keyScope$1, component);
marko_dynamicTag(out, macro_renderTree, child, null, null, __component, "3" + $keyScope$1);
marko_dynamicTag(out, macro_renderTree, function() {
return child;
}, null, null, null, __component, "3" + $keyScope$1);
out.ee();
});
@ -50,7 +52,9 @@ function render(input, out, __component, component, state) {
}
}
marko_dynamicTag(out, macro_renderTree, input.nodes[i], null, null, __component, "4" + $keyScope$0);
marko_dynamicTag(out, macro_renderTree, function() {
return input.nodes[i];
}, null, null, null, __component, "4" + $keyScope$0);
});
}

View File

@ -22,10 +22,12 @@ function render(input, out, __component, component, state) {
out.be("svg", marko_attrs0, "0", component);
marko_dynamicTag(out, isCircle ? "circle" : "square", {
width: 200,
height: 200
}, null, null, __component, "1");
marko_dynamicTag(out, isCircle ? "circle" : "square", function() {
return {
width: 200,
height: 200
};
}, null, null, null, __component, "1");
out.ee();
}

View File

@ -39,14 +39,14 @@ function render(input, out, __component, component, state) {
_preserve_tag({
bodyOnly: true,
key: $key$0,
renderBody: function renderBody(out) {
renderBody: function(out) {
out.w(marko_escapeXml(Date.now()));
}
}, out);
out.w("</p></div><span>B</span>");
marko_dynamicTag(out, Foo, {}, null, null, __component, "4");
marko_dynamicTag(out, Foo, null, null, null, null, __component, "4");
}
marko_template._ = marko_renderer(render, {

View File

@ -18,7 +18,7 @@ function render(input, out, __component, widget, component) {
"><h1>Header</h1><div>");
if ((typeof input.renderBody) === "function") {
marko_dynamicTag(out, input, {}, null, null, __component, "2");
marko_dynamicTag(out, input, null, null, null, null, __component, "2");
} else {
out.w(marko_escapeXml(input.renderBody));
}

View File

@ -18,7 +18,7 @@ function render(input, out, __component, component, state) {
if ((typeof data.renderBody) === "string") {
out.w(marko_escapeXml(data.renderBody));
} else {
marko_dynamicTag(out, data.renderBody, {}, null, null, __component, "3");
marko_dynamicTag(out, data.renderBody, null, null, null, null, __component, "3");
}
out.w("</div></div>");

View File

@ -18,9 +18,11 @@ function render(input, out, __component, component, state) {
if ((typeof data.renderBody) === "string") {
out.w(marko_escapeXml(data.renderBody));
} else {
marko_dynamicTag(out, data.renderBody, {
test: 1
}, null, null, __component, "1");
marko_dynamicTag(out, data.renderBody, function() {
return {
test: 1
};
}, null, null, null, __component, "1");
}
out.w("\n</div>");

View File

@ -18,7 +18,7 @@ function render(input, out, __component, component, state) {
if ((typeof data.renderBody) === "string") {
out.w(marko_escapeXml(data.renderBody));
} else {
marko_dynamicTag(out, data.renderBody, {}, null, null, __component, "1");
marko_dynamicTag(out, data.renderBody, null, null, null, null, __component, "1");
}
out.w("\n</div>");

View File

@ -33,9 +33,11 @@ function render(input, out, __component, component, state) {
], function(color) {
var $keyScope$0 = "[" + (($for$0++) + "]");
marko_dynamicTag(out, macro_renderButton, {
color: color
}, null, null, __component, "2" + $keyScope$0);
marko_dynamicTag(out, macro_renderButton, function() {
return {
color: color
};
}, null, null, null, __component, "2" + $keyScope$0);
});
out.w("</div>");

View File

@ -18,7 +18,7 @@ function render(input, out, __component, component, state) {
out.w("<div><span>A</span>");
another_component_tag({
renderBody: function renderBody(out) {
renderBody: function(out) {
out.w("<div><span>This is <b>static</b></span></div>");
}
}, out, __component, "1");

View File

@ -39,14 +39,14 @@ function render(input, out, __component, component, state) {
_preserve_tag({
bodyOnly: true,
key: $key$0,
renderBody: function renderBody(out) {
renderBody: function(out) {
out.w(marko_escapeXml(Date.now()));
}
}, out);
out.w("</p></div><span>B</span>");
marko_dynamicTag(out, Foo, {}, null, null, __component, "4");
marko_dynamicTag(out, Foo, null, null, null, null, __component, "4");
}
marko_template._ = marko_renderer(render, {

View File

@ -33,9 +33,11 @@ function render(input, out, __component, component, state) {
], function(color) {
var $keyScope$0 = "[" + (($for$0++) + "]");
marko_dynamicTag(out, macro_renderButton, {
color: color
}, null, null, __component, "2" + $keyScope$0);
marko_dynamicTag(out, macro_renderButton, function() {
return {
color: color
};
}, null, null, null, __component, "2" + $keyScope$0);
});
out.w("</div>");

View File

@ -0,0 +1 @@
My nested content<a data-index=0></a><a data-index=1></a><div>2</div>

View File

@ -0,0 +1,8 @@
$ var i = 0;
$ var tag = null;
<${tag} data-index=i++/>
<${tag} data-index=i++>My nested content</>
<${!tag && "a"} data-index=i++/>
<${!tag && "a"} data-index=i++/>
<div>${i}</div>

View File

@ -0,0 +1 @@
exports.templateData = {};

View File

@ -0,0 +1,5 @@
"My nested content"
<A data-index="0">
<A data-index="1">
<DIV>
"2"

View File

@ -28,7 +28,7 @@ function render(input, out, __component, component, state) {
test_hello_tag({
name: "World",
renderBody: function renderBody(out) {
renderBody: function(out) {
out.n(marko_node0, component);
}
}, out);

View File

@ -17,7 +17,7 @@ function render(input, out, __component, component, state) {
test_hello_tag({
name: "World",
renderBody: function renderBody(out) {
renderBody: function(out) {
out.t("Body content");
}
}, out);