Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions e2e/__projects__/basic/components/ClassComponent.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

<template>
<div>{{ msg }}</div>
</template>

<script lang="ts">
import { Vue, Options } from 'vue-class-component'

@Options({
props: ['msg']
})
export default class ClassComponent extends Vue {}
</script>
3 changes: 2 additions & 1 deletion e2e/__projects__/basic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"babel-helper-vue-jsx-merge-props": "^2.0.3",
"babel-plugin-syntax-jsx": "^6.18.0",
"babel-plugin-transform-vue-jsx": "^3.7.0",
"jest": "^24.0.0"
"jest": "^24.0.0",
"vue-class-component": "^8.0.0-beta.4"
},
"jest": {
"moduleFileExtensions": [
Expand Down
6 changes: 6 additions & 0 deletions e2e/__projects__/basic/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import BasicSrc from './components/BasicSrc.vue'
import Pug from './components/Pug.vue'
import Coffee from './components/Coffee.vue'
import Basic from './components/Basic.vue'
import ClassComponent from './components/ClassComponent.vue'
import TypeScript from './components/TypeScript.vue'
import jestVue from '../../../'
import RenderFunction from './components/RenderFunction.vue'
Expand Down Expand Up @@ -116,6 +117,11 @@ test('supports relative paths when extending templates from .pug files', () => {
expect(document.querySelector('.pug-relative-base')).toBeTruthy()
})

test('supports class component .vue files', () => {
mount(ClassComponent, { msg: 'Hello' })
expect(document.querySelector('div').textContent).toBe('Hello')
})

// TODO: How do functional components work in Vue 3?
xtest('processes functional components', () => {
// const clickSpy = jest.fn()
Expand Down
5 changes: 5 additions & 0 deletions e2e/__projects__/basic/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4157,6 +4157,11 @@ verror@1.10.0:
core-util-is "1.0.2"
extsprintf "^1.2.0"

vue-class-component@^8.0.0-beta.4:
version "8.0.0-beta.4"
resolved "https://registry.yarnpkg.com/vue-class-component/-/vue-class-component-8.0.0-beta.4.tgz#bff95cdd44eb450a4a4e54b69da22099613d8071"
integrity sha512-+QXBhVH/Mz8dEC+IU7e8XXM54Tn0Aj9/saybeuK8XmhQiJlcijCB8kB7CYpBEMpHWaA+DoLr6LvHMbclYRCwZQ==

vue@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/vue/-/vue-3.0.0.tgz#cfb5df5c34efce319b113a1667d12b74dcfd9c90"
Expand Down
8 changes: 8 additions & 0 deletions lib/generate-code.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,18 @@ module.exports = function generateCode(

var tempOutput = node.toString()

if (
tempOutput.match(/\}\(.*.?Vue\);/) &&
tempOutput.includes('vue-class-component')
) {
node.add(';exports.default = {...exports.default.__vccBase};')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we will now end up with 2x node.add(';exports.default = {...exports.default};') (added here and line 43).

Can you 1) check if that is the case and 2) make sure we only add it once? If we aren't careful, this can become really complex really fast!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

node now ends with

';exports.default = {...exports.default.__vccBase};',
';exports.default = {...exports.default, render};' 

or

';exports.default = {...exports.default.__vccBase};',
';exports.default = {...exports.default};' 

I think this is the desired behavoir because otherwise the code will be more complex.

Example:

if (
  tempOutput.match(/\}\(.*.?Vue\);/) &&
  tempOutput.includes('vue-class-component')
) {
if (tempOutput.includes('exports.render = render;')) {
    node.add(';exports.default = {...exports.default.__vccBase, render};')
  } else {
    node.add(';exports.default = {...exports.default.__vccBase};')
  }
} else {
  if (tempOutput.includes('exports.render = render;')) {
    node.add(';exports.default = {...exports.default, render};')
  } else {
    node.add(';exports.default = {...exports.default};')
  }
}

this will have an output of

';exports.default = {...exports.default.__vccBase, render};'

or

';exports.default = {...exports.default.__vccBase};'

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, true, that is very complex. Fair enough.

I wonder if we should create a isClassComponent function 🤔

Anyway, this will do for now, I will test it out a bit and if it's all good do a release. thanks!

}

if (tempOutput.includes('exports.render = render;')) {
node.add(';exports.default = {...exports.default, render};')
} else {
node.add(';exports.default = {...exports.default};')
}

return node.toStringWithSourceMap({ file: filename })
}
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8589,6 +8589,11 @@ yargs@~3.10.0:
decamelize "^1.0.0"
window-size "0.1.0"

yarn@^1.22.10:
version "1.22.10"
resolved "https://registry.yarnpkg.com/yarn/-/yarn-1.22.10.tgz#c99daa06257c80f8fa2c3f1490724e394c26b18c"
integrity sha512-IanQGI9RRPAN87VGTF7zs2uxkSyQSrSPsju0COgbsKQOOXr5LtcVPeyXWgwVa0ywG3d8dg6kSYKGBuYK021qeA==

yup@^0.27.0:
version "0.27.0"
resolved "https://registry.yarnpkg.com/yup/-/yup-0.27.0.tgz#f8cb198c8e7dd2124beddc2457571329096b06e7"
Expand Down