From 07bf51805389650a953dfc289b748c8a5810c7fa Mon Sep 17 00:00:00 2001 From: katashin Date: Thu, 8 Sep 2016 16:06:45 +0900 Subject: [PATCH] allow to export constructor even if using es6 default export (#341) * allow to export constructor even if using es6 default export * add test for `export default Vue.extend` * test instance data of exported constructor --- lib/loader.js | 5 ++++- package.json | 1 + test/fixtures/extend.vue | 12 ++++++++++++ test/test.js | 15 +++++++++++++++ 4 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 test/fixtures/extend.vue diff --git a/lib/loader.js b/lib/loader.js index a098bf8ed..196d8307d 100644 --- a/lib/loader.js +++ b/lib/loader.js @@ -170,7 +170,10 @@ module.exports = function (content) { var exports = '__vue_options__ = __vue_exports__ = __vue_exports__ || {}\n' + // ES6 modules interop - 'if (typeof __vue_exports__.default === "object") {\n' + + 'if (\n' + + ' typeof __vue_exports__.default === "object" ||\n' + + ' typeof __vue_exports__.default === "function"\n' + + ') {\n' + (isProduction ? '' : checkNamedExports) + '__vue_options__ = __vue_exports__ = __vue_exports__.default\n' + '}\n' + diff --git a/package.json b/package.json index 3850f2194..e10a01810 100644 --- a/package.json +++ b/package.json @@ -71,6 +71,7 @@ "stylus": "^0.54.5", "stylus-loader": "^2.0.0", "sugarss": "^0.1.3", + "vue": "^2.0.0-rc.4", "webpack": "^1.12.2" } } diff --git a/test/fixtures/extend.vue b/test/fixtures/extend.vue new file mode 100644 index 000000000..ca11dfe65 --- /dev/null +++ b/test/fixtures/extend.vue @@ -0,0 +1,12 @@ + + + diff --git a/test/test.js b/test/test.js index 4d16cbe0e..abe47a253 100644 --- a/test/test.js +++ b/test/test.js @@ -333,4 +333,19 @@ describe('vue-loader', function () { done() }) }) + + it('allows to export extended constructor', function (done) { + test({ + entry: './test/fixtures/extend.vue' + }, function (window, Module) { + // extend.vue should export Vue constructor + var vnode = mockRender(Module.options, { + msg: 'success' + }) + expect(vnode.tag).to.equal('div') + expect(vnode.children[0]).to.equal('success') + expect(new Module().msg === 'success') + done() + }) + }) })