Skip to content

Commit a21514f

Browse files
author
Alan Wang
authored
fix: render funciton expression can't be transformed (vuejs#30)
1 parent d02aa1e commit a21514f

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

transformations/__tests__/remove-contextual-h-from-render.spec.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ defineInlineTest(
99
'remove h from arrow functions'
1010
)
1111

12+
defineInlineTest(
13+
transform,
14+
{},
15+
`export default { render: function(h) { return h("div", ["hello"]) } };`,
16+
`import { h } from "vue";\nexport default { render: function() { return h("div", ["hello"]) } };`,
17+
'remove h from arrow functions'
18+
)
19+
1220
defineInlineTest(
1321
transform,
1422
{},

transformations/remove-contextual-h-from-render.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,12 @@ import { transformAST as addImport } from './add-import'
77

88
export const transformAST: ASTTransformation = context => {
99
const { root, j } = context
10-
const renderFns = root.find(j.ObjectProperty, {
11-
key: {
12-
name: 'render'
13-
},
14-
value: {
15-
type: 'ArrowFunctionExpression'
16-
}
10+
const renderFns = root.find(j.ObjectProperty, n => {
11+
return (
12+
n.key.name === 'render' &&
13+
(n.value.type === 'ArrowFunctionExpression' ||
14+
n.value.type === 'FunctionExpression')
15+
)
1716
})
1817

1918
const renderMethods = root.find(j.ObjectMethod, {

0 commit comments

Comments
 (0)