From 640a5a05cecd5abc8f7bd1f7e30a939d6c4803cc Mon Sep 17 00:00:00 2001 From: Patrick Steele-Idem Date: Mon, 18 Apr 2016 11:32:33 -0600 Subject: [PATCH] Fixes #262 - node-require module removes .marko extension from filenames in compiled code --- compiler/CompileContext.js | 8 +++++++- .../autotest/custom-tag-template/expected.js | 16 ++++++++++++++++ .../autotest/custom-tag-template/hello.marko | 1 + .../autotest/custom-tag-template/marko.json | 5 +++++ .../autotest/custom-tag-template/template.marko | 1 + 5 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 test/fixtures/compiler/autotest/custom-tag-template/expected.js create mode 100644 test/fixtures/compiler/autotest/custom-tag-template/hello.marko create mode 100644 test/fixtures/compiler/autotest/custom-tag-template/marko.json create mode 100644 test/fixtures/compiler/autotest/custom-tag-template/template.marko diff --git a/compiler/CompileContext.js b/compiler/CompileContext.js index 7f24d1179..336e2ccd4 100644 --- a/compiler/CompileContext.js +++ b/compiler/CompileContext.js @@ -14,6 +14,12 @@ var macros = require('./util/macros'); var extend = require('raptor-util/extend'); var Walker = require('./Walker'); +const deresolveOptions = { + shouldRemoveExt(ext) { + return ext === '.js' || ext === '.json' || ext === '.es6'; + } +}; + function getTaglibPath(taglibPath) { if (typeof window === 'undefined') { return path.relative(process.cwd(), taglibPath); @@ -115,7 +121,7 @@ class CompileContext { } getRequirePath(targetFilename) { - return deresolve(targetFilename, this.dirname); + return deresolve(targetFilename, this.dirname, deresolveOptions); } importModule(varName, path) { diff --git a/test/fixtures/compiler/autotest/custom-tag-template/expected.js b/test/fixtures/compiler/autotest/custom-tag-template/expected.js new file mode 100644 index 000000000..decaa1b6a --- /dev/null +++ b/test/fixtures/compiler/autotest/custom-tag-template/expected.js @@ -0,0 +1,16 @@ +function create(__helpers) { + var str = __helpers.s, + empty = __helpers.e, + notEmpty = __helpers.ne, + escapeXml = __helpers.x, + loadTemplate = __helpers.l, + __hello = loadTemplate(require.resolve("./hello.marko")); + + return function render(data, out) { + __hello.render({ + name: "Frank" + }, out); + }; +} + +(module.exports = require("marko").c(__filename)).c(create); diff --git a/test/fixtures/compiler/autotest/custom-tag-template/hello.marko b/test/fixtures/compiler/autotest/custom-tag-template/hello.marko new file mode 100644 index 000000000..eabd502aa --- /dev/null +++ b/test/fixtures/compiler/autotest/custom-tag-template/hello.marko @@ -0,0 +1 @@ +- Hello ${data.name}! \ No newline at end of file diff --git a/test/fixtures/compiler/autotest/custom-tag-template/marko.json b/test/fixtures/compiler/autotest/custom-tag-template/marko.json new file mode 100644 index 000000000..37f4d2cb2 --- /dev/null +++ b/test/fixtures/compiler/autotest/custom-tag-template/marko.json @@ -0,0 +1,5 @@ +{ + "": { + "template": "./hello.marko" + } +} \ No newline at end of file diff --git a/test/fixtures/compiler/autotest/custom-tag-template/template.marko b/test/fixtures/compiler/autotest/custom-tag-template/template.marko new file mode 100644 index 000000000..f6628c016 --- /dev/null +++ b/test/fixtures/compiler/autotest/custom-tag-template/template.marko @@ -0,0 +1 @@ + \ No newline at end of file