Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/custom component prefix on #102

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 16 additions & 1 deletion packages/babel-plugin-transform-vue-jsx/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,23 @@ const parseAttributeJSXAttribute = (t, path, attributes, tagName, elementType) =
;[name, argument] = name.split(':')

prefix = prefixes.find(el => name.startsWith(el)) || 'attrs'

// For custom components(which tag name is not html tag), event binding need to use `nativeOn` but not `on`
// `on` prefix should transform to `attrs`
if (!htmlTags.includes(tagName) && prefix === 'on') {
prefix = 'attrs'
}

name = name.replace(new RegExp(`^${prefix}\-?`), '')
name = name[0].toLowerCase() + name.substr(1)

// in jsx, event binding use Camel case, such as `onClick`, `onMouseDown`;
// in HTML Specification, event binding is all lower case, such as `onclick`, `onmousedown`
// so for `on` and `nativeOn` attribute in jsx, transform `name` to all lower case
Copy link
Member

Choose a reason for hiding this comment

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

But camel case is allowed in Vue.js, though not preferred https://vuejs.org/v2/guide/components-custom-events.html#Event-Names

if (prefix === 'on' || prefix === 'nativeOn') {
name = name.toLowerCase()
} else {
name = name[0].toLowerCase() + name.substr(1)
}

const valuePath = path.get('value')
let value
Expand Down