From bf82d73f5e24cc41e9e014907f6fe0d1fcf6aab2 Mon Sep 17 00:00:00 2001 From: Chris Fritz Date: Tue, 23 Aug 2016 17:15:42 -0400 Subject: [PATCH 1/4] Automatically set name option unless already set Use the filename to set a component's name option, if one isn't provided. This allows more helpful debugging messages by default. --- lib/loader.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/loader.js b/lib/loader.js index 40424fbf9..8df780ca3 100644 --- a/lib/loader.js +++ b/lib/loader.js @@ -180,6 +180,10 @@ module.exports = function (content) { // constructor export interop 'if (typeof __vue_options__ === "function") {\n' + ' __vue_options__ = __vue_options__.options\n' + + '}\n' + + // add name based on filename if not already set + 'if (typeof __vue_options__ === "object" && !__vue_options__.name) {\n' + + ' __vue_options__.name = __vue_options__.name || "' + fileName.replace(/(\.vue|[^a-z0-9\-])/gi, '') + '"\n' + '}\n' // add require for template From fa46e5d51bbdea643569f8e854ccac2ec00c3193 Mon Sep 17 00:00:00 2001 From: Chris Fritz Date: Thu, 15 Sep 2016 00:52:47 -0400 Subject: [PATCH 2/4] remove unnecessary object check for __vue_options__ --- lib/loader.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/loader.js b/lib/loader.js index 8df780ca3..f57ff7b34 100644 --- a/lib/loader.js +++ b/lib/loader.js @@ -182,7 +182,7 @@ module.exports = function (content) { ' __vue_options__ = __vue_options__.options\n' + '}\n' + // add name based on filename if not already set - 'if (typeof __vue_options__ === "object" && !__vue_options__.name) {\n' + + 'if (!__vue_options__.name) {\n' + ' __vue_options__.name = __vue_options__.name || "' + fileName.replace(/(\.vue|[^a-z0-9\-])/gi, '') + '"\n' + '}\n' From 96ca8a63b76dd58e20b442ea2f921ea86758b29a Mon Sep 17 00:00:00 2001 From: Chris Fritz Date: Thu, 15 Sep 2016 01:13:13 -0400 Subject: [PATCH 3/4] add test for automatic name setting based on filenames --- test/fixtures/named.vue | 9 +++++++++ test/fixtures/unnamed-5tr@ng3_f1l3n@me$.vue | 3 +++ test/fixtures/unnamed.vue | 3 +++ test/test.js | 19 +++++++++++++++++++ 4 files changed, 34 insertions(+) create mode 100644 test/fixtures/named.vue create mode 100644 test/fixtures/unnamed-5tr@ng3_f1l3n@me$.vue create mode 100644 test/fixtures/unnamed.vue diff --git a/test/fixtures/named.vue b/test/fixtures/named.vue new file mode 100644 index 000000000..f2edcd883 --- /dev/null +++ b/test/fixtures/named.vue @@ -0,0 +1,9 @@ + + + diff --git a/test/fixtures/unnamed-5tr@ng3_f1l3n@me$.vue b/test/fixtures/unnamed-5tr@ng3_f1l3n@me$.vue new file mode 100644 index 000000000..92122e949 --- /dev/null +++ b/test/fixtures/unnamed-5tr@ng3_f1l3n@me$.vue @@ -0,0 +1,3 @@ + diff --git a/test/fixtures/unnamed.vue b/test/fixtures/unnamed.vue new file mode 100644 index 000000000..92122e949 --- /dev/null +++ b/test/fixtures/unnamed.vue @@ -0,0 +1,3 @@ + diff --git a/test/test.js b/test/test.js index 056599c18..61818d08f 100644 --- a/test/test.js +++ b/test/test.js @@ -108,6 +108,25 @@ describe('vue-loader', function () { }) }) + it('automatic name setting based on filename', function (done) { + test({ + entry: './test/fixtures/unnamed.vue' + }, function (window, module, rawModule) { + expect(module.name).to.equal('unnamed') + test({ + entry: './test/fixtures/named.vue' + }, function (window, module, rawModule) { + expect(module.name).to.equal('custom-name') + test({ + entry: './test/fixtures/unnamed-5tr@ng3_f1l3n@me$.vue' + }, function (window, module, rawModule) { + expect(module.name).to.equal('unnamed-5trng3f1l3nme') + done() + }) + }) + }) + }) + it('pre-processors', function (done) { test({ entry: './test/fixtures/pre.vue' From e5298d7284a84d34b0aa0c1599a6ee28e5feb4c7 Mon Sep 17 00:00:00 2001 From: Chris Fritz Date: Tue, 11 Oct 2016 12:20:03 -0400 Subject: [PATCH 4/4] remove redundant if statement from loader.js --- lib/loader.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/loader.js b/lib/loader.js index f57ff7b34..ee14c74c0 100644 --- a/lib/loader.js +++ b/lib/loader.js @@ -182,9 +182,7 @@ module.exports = function (content) { ' __vue_options__ = __vue_options__.options\n' + '}\n' + // add name based on filename if not already set - 'if (!__vue_options__.name) {\n' + - ' __vue_options__.name = __vue_options__.name || "' + fileName.replace(/(\.vue|[^a-z0-9\-])/gi, '') + '"\n' + - '}\n' + '__vue_options__.name = __vue_options__.name || "' + fileName.replace(/(\.vue|[^a-z0-9\-])/gi, '') + '"\n' // add require for template var template = parts.template