Skip to content

Commit 852481c

Browse files
committed
fix: Support props with underscore, close #55
1 parent ef44334 commit 852481c

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

Diff for: packages/babel-plugin-transform-vue-jsx/src/index.js

+10-8
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ const parseAttributeJSXAttribute = (t, path, attributes, tagName, elementType) =
163163
}
164164

165165
;[name, ...modifiers] = name.split('_')
166-
;[name, argument] = name.split(':')
166+
;[name, argument] = name.split(':')
167167

168168
prefix = prefixes.find(el => name.startsWith(el)) || 'attrs'
169169
name = name.replace(new RegExp(`^${prefix}\-?`), '')
@@ -196,6 +196,8 @@ const parseAttributeJSXAttribute = (t, path, attributes, tagName, elementType) =
196196
if (isDirective(name)) {
197197
name = kebabcase(name.substr(1))
198198
prefix = 'directives'
199+
} else {
200+
name = [name, ...modifiers].join('_')
199201
}
200202
if (name.match(xlinkRE)) {
201203
name = name.replace(xlinkRE, (_, firstCharacter) => {
@@ -299,15 +301,15 @@ const transformDirectives = (t, directives) =>
299301
: []),
300302
...(directive.value._modifiers && directive.value._modifiers.length > 0
301303
? [
302-
t.objectProperty(
303-
t.identifier('modifiers'),
304-
t.objectExpression(
305-
directive.value._modifiers.map(modifier =>
306-
t.objectProperty(t.stringLiteral(modifier), t.booleanLiteral(true)),
307-
),
304+
t.objectProperty(
305+
t.identifier('modifiers'),
306+
t.objectExpression(
307+
directive.value._modifiers.map(modifier =>
308+
t.objectProperty(t.stringLiteral(modifier), t.booleanLiteral(true)),
308309
),
309310
),
310-
]
311+
),
312+
]
311313
: []),
312314
]),
313315
),

Diff for: packages/babel-plugin-transform-vue-jsx/test/snapshot.js

+10
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,16 @@ h("MyComponent", _mergeJSXProps([{
329329
name: 'JSX comments',
330330
from: `<div><p>jsx</p>{/* <p>comment</p> */}</div>`,
331331
to: `h("div", [h("p", ["jsx"])]);`
332+
},
333+
{
334+
name: 'Underscore Props',
335+
from: `const MyComp = {}; render(h => <MyComponent attrs-my_prop="test">test</MyComponent>)`,
336+
to: `const MyComp = {};
337+
render(h => h("MyComponent", {
338+
"attrs": {
339+
"my_prop": "test"
340+
}
341+
}, ["test"]));`,
332342
}
333343
]
334344

0 commit comments

Comments
 (0)