Skip to content

Commit 8203489

Browse files
committed
refactor: move wrapFunctional util to index
1 parent c39a593 commit 8203489

File tree

3 files changed

+31
-33
lines changed

3 files changed

+31
-33
lines changed

src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,6 @@ const componentsModule: Module<Options> = function () {
159159
const templates = [
160160
'components/index.js',
161161
'components/plugin.js',
162-
'components/utils.js',
163162
'components/readme_md',
164163
'vetur/tags.json'
165164
]

templates/components/index.js

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { wrapFunctional } from './utils'
2-
31
<%= options.getComponents().map(c => {
42
const magicComments = [
53
`webpackChunkName: "${c.chunkName}"`,
@@ -15,3 +13,34 @@ import { wrapFunctional } from './utils'
1513
return `export { ${exp} } from '../${relativeToBuild(c.filePath)}'`
1614
}
1715
}).join('\n') %>
16+
17+
// nuxt/nuxt.js#8607
18+
function wrapFunctional(options) {
19+
if (!options || !options.functional) {
20+
return options
21+
}
22+
23+
const propKeys = Array.isArray(options.props) ? options.props : Object.keys(options.props || {})
24+
25+
return {
26+
render(h) {
27+
const attrs = {}
28+
const props = {}
29+
30+
for (const key in this.$attrs) {
31+
if (propKeys.includes(key)) {
32+
props[key] = this.$attrs[key]
33+
} else {
34+
attrs[key] = this.$attrs[key]
35+
}
36+
}
37+
38+
return h(options, {
39+
on: this.$listeners,
40+
attrs,
41+
props,
42+
scopedSlots: this.$scopedSlots,
43+
}, this.$slots.default)
44+
}
45+
}
46+
}

templates/components/utils.js

Lines changed: 0 additions & 30 deletions
This file was deleted.

0 commit comments

Comments
 (0)