From 35e33aeb7538ee8e5c6b6fb95d0f804151c4fa35 Mon Sep 17 00:00:00 2001 From: Patrick Steele-Idem Date: Mon, 18 Jan 2016 14:38:30 -0700 Subject: [PATCH] Fixes #208 - Marko v3: Re-introduce support for "import-var" in taglib --- compiler/ast/CustomTag.js | 7 +++++++ compiler/taglib-loader/loader-tag.js | 3 ++- .../custom-tag-import-var/expected.js | 20 +++++++++++++++++++ .../custom-tag-import-var/template.marko | 3 +++ .../test-import-var/marko-tag.json | 7 +++++++ .../scanned-tags/test-import-var/renderer.js | 3 +++ 6 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 test/fixtures/compiler/autotest/custom-tag-import-var/expected.js create mode 100644 test/fixtures/compiler/autotest/custom-tag-import-var/template.marko create mode 100644 test/fixtures/taglib/scanned-tags/test-import-var/marko-tag.json create mode 100644 test/fixtures/taglib/scanned-tags/test-import-var/renderer.js diff --git a/compiler/ast/CustomTag.js b/compiler/ast/CustomTag.js index f77c47dd2..124c135ae 100644 --- a/compiler/ast/CustomTag.js +++ b/compiler/ast/CustomTag.js @@ -67,6 +67,13 @@ function buildInputProps(node, context) { } }); + tagDef.forEachImportedVariable(function(importedVariable) { + let propName = importedVariable.targetProperty; + let propExpression = importedVariable.expression; + + inputProps[propName] = propExpression; + }); + if (node.body && node.body.length) { if (tagDef.bodyFunction) { diff --git a/compiler/taglib-loader/loader-tag.js b/compiler/taglib-loader/loader-tag.js index 2b42a6800..73288d0f8 100644 --- a/compiler/taglib-loader/loader-tag.js +++ b/compiler/taglib-loader/loader-tag.js @@ -29,6 +29,7 @@ var Taglib = require('./Taglib'); var propertyHandlers = require('property-handlers'); var forEachEntry = require('raptor-util').forEachEntry; var loader = require('./loader'); +var markoCompiler = require('../'); function exists(path) { try { @@ -368,7 +369,7 @@ TagHandlers.prototype = { throw new Error('Invalid "import-var": ' + require('util').inspect(varValue)); } - importedVar.expression = expression; + importedVar.expression = markoCompiler.defaultBuilder.parseExpression(expression); tag.addImportedVariable(importedVar); }); }, diff --git a/test/fixtures/compiler/autotest/custom-tag-import-var/expected.js b/test/fixtures/compiler/autotest/custom-tag-import-var/expected.js new file mode 100644 index 000000000..1d8b53d2e --- /dev/null +++ b/test/fixtures/compiler/autotest/custom-tag-import-var/expected.js @@ -0,0 +1,20 @@ +function create(__helpers) { + var str = __helpers.s, + empty = __helpers.e, + notEmpty = __helpers.ne, + escapeXml = __helpers.x, + __renderer = __helpers.r, + __tag = __helpers.t, + test_body_function_renderer = __renderer(require("../../../taglib/scanned-tags/test-body-function/renderer")); + + return function render(data, out) { + __tag(out, test_body_function_renderer, { + "name": "World", + "myBody": function myBody(foo, bar) { + out.w("This is the body content"); + } + }); + }; +} + +(module.exports = require("marko").c(__filename)).c(create); diff --git a/test/fixtures/compiler/autotest/custom-tag-import-var/template.marko b/test/fixtures/compiler/autotest/custom-tag-import-var/template.marko new file mode 100644 index 000000000..1f2eaed07 --- /dev/null +++ b/test/fixtures/compiler/autotest/custom-tag-import-var/template.marko @@ -0,0 +1,3 @@ + + This is the body content + \ No newline at end of file diff --git a/test/fixtures/taglib/scanned-tags/test-import-var/marko-tag.json b/test/fixtures/taglib/scanned-tags/test-import-var/marko-tag.json new file mode 100644 index 000000000..2c96a3525 --- /dev/null +++ b/test/fixtures/taglib/scanned-tags/test-import-var/marko-tag.json @@ -0,0 +1,7 @@ +{ + "renderer": "./renderer", + "import-var": { + "foo": "data.foo", + "bar": "data.bar" + } +} \ No newline at end of file diff --git a/test/fixtures/taglib/scanned-tags/test-import-var/renderer.js b/test/fixtures/taglib/scanned-tags/test-import-var/renderer.js new file mode 100644 index 000000000..2d87648d8 --- /dev/null +++ b/test/fixtures/taglib/scanned-tags/test-import-var/renderer.js @@ -0,0 +1,3 @@ +module.exports = function(input, out) { + +}; \ No newline at end of file