Skip to content

Commit

Permalink
fix: Support props with underscore, close #55
Browse files Browse the repository at this point in the history
  • Loading branch information
nickmessing committed May 8, 2019
1 parent ef44334 commit 852481c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
18 changes: 10 additions & 8 deletions packages/babel-plugin-transform-vue-jsx/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ const parseAttributeJSXAttribute = (t, path, attributes, tagName, elementType) =
}

;[name, ...modifiers] = name.split('_')
;[name, argument] = name.split(':')
;[name, argument] = name.split(':')

prefix = prefixes.find(el => name.startsWith(el)) || 'attrs'
name = name.replace(new RegExp(`^${prefix}\-?`), '')
Expand Down Expand Up @@ -196,6 +196,8 @@ const parseAttributeJSXAttribute = (t, path, attributes, tagName, elementType) =
if (isDirective(name)) {
name = kebabcase(name.substr(1))
prefix = 'directives'
} else {
name = [name, ...modifiers].join('_')
}
if (name.match(xlinkRE)) {
name = name.replace(xlinkRE, (_, firstCharacter) => {
Expand Down Expand Up @@ -299,15 +301,15 @@ const transformDirectives = (t, directives) =>
: []),
...(directive.value._modifiers && directive.value._modifiers.length > 0
? [
t.objectProperty(
t.identifier('modifiers'),
t.objectExpression(
directive.value._modifiers.map(modifier =>
t.objectProperty(t.stringLiteral(modifier), t.booleanLiteral(true)),
),
t.objectProperty(
t.identifier('modifiers'),
t.objectExpression(
directive.value._modifiers.map(modifier =>
t.objectProperty(t.stringLiteral(modifier), t.booleanLiteral(true)),
),
),
]
),
]
: []),
]),
),
Expand Down
10 changes: 10 additions & 0 deletions packages/babel-plugin-transform-vue-jsx/test/snapshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,16 @@ h("MyComponent", _mergeJSXProps([{
name: 'JSX comments',
from: `<div><p>jsx</p>{/* <p>comment</p> */}</div>`,
to: `h("div", [h("p", ["jsx"])]);`
},
{
name: 'Underscore Props',
from: `const MyComp = {}; render(h => <MyComponent attrs-my_prop="test">test</MyComponent>)`,
to: `const MyComp = {};
render(h => h("MyComponent", {
"attrs": {
"my_prop": "test"
}
}, ["test"]));`,
}
]

Expand Down

0 comments on commit 852481c

Please sign in to comment.