Skip to content

Commit

Permalink
allow to export constructor even if using es6 default export (#341)
Browse files Browse the repository at this point in the history
* allow to export constructor even if using es6 default export

* add test for `export default Vue.extend`

* test instance data of exported constructor
  • Loading branch information
ktsn authored and yyx990803 committed Sep 8, 2016
1 parent 7828b41 commit 07bf518
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' +
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
12 changes: 12 additions & 0 deletions test/fixtures/extend.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<template>
<div>{{ msg }}</div>
</template>

<script>
import Vue from 'vue'
export default Vue.extend({
data () {
return { msg: 'success' }
}
})
</script>
15 changes: 15 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})
})
})

0 comments on commit 07bf518

Please sign in to comment.