From 8ec87e02a1113905eb6027f26f19772289396a4b Mon Sep 17 00:00:00 2001 From: Robert Jackson Date: Tue, 1 Dec 2015 17:19:56 -0500 Subject: [PATCH] Provide moduleName for transpiled templates. This is used internally within Ember to allow local lookups in the future, it also mirrors ember-cli-htmlbars transpilation a bit better. --- app/services/ember-cli.js | 4 +++- tests/unit/services/ember-cli-test.js | 7 +++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/app/services/ember-cli.js b/app/services/ember-cli.js index 42dbaf19..4baa8ade 100644 --- a/app/services/ember-cli.js +++ b/app/services/ember-cli.js @@ -338,8 +338,10 @@ export default Ember.Service.extend({ // let templateCode = Ember.HTMLBars.precompile(code || ''); // Compiles all templates at runtime. + let moduleName = this.nameWithModule(filePath); + const mungedCode = (code || '').replace(/\\/g, "\\\\"); // Prevent backslashes from being escaped - return this.compileJs('export default Ember.HTMLBars.compile(`' + mungedCode + '`);', filePath); + return this.compileJs('export default Ember.HTMLBars.compile(`' + mungedCode + '`, { moduleName: `' + moduleName + '`});', filePath); }, compileCss(code, moduleName) { diff --git a/tests/unit/services/ember-cli-test.js b/tests/unit/services/ember-cli-test.js index 16b5c613..894489e6 100644 --- a/tests/unit/services/ember-cli-test.js +++ b/tests/unit/services/ember-cli-test.js @@ -149,3 +149,10 @@ test("buildProperties() works as expected with replacements", function (assert) assert.ok(props.content.indexOf('myHelper(params') !== -1, 'Replacements worked'); assert.ok(props.content.indexOf('helper(myHelper)') !== -1, 'Replacements worked if multiple'); }); + +test('compileHbs includes moduleName', function(assert) { + var service = this.subject(); + var result = service.compileHbs('foo', 'somePath/here.hbs'); + + assert.ok(result.indexOf('moduleName: "demo-app/somePath/here"') > -1, 'moduleName included'); +});