Skip to content

Commit 542250f

Browse files
committed
+ Support v-bind and v-on.
1 parent c3955a0 commit 542250f

File tree

5 files changed

+18
-18
lines changed

5 files changed

+18
-18
lines changed

lib/jsx.ts

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import type { VNode, VNodeData } from 'vue'
2-
import { camelCase } from 'change-case'
32
import {
43
checkKeyIsVueDirective,
54
checkIsHTMLElement,
@@ -25,7 +24,6 @@ import { dealWithDirective } from './modules/directive'
2524
import { ConfigType, TagType } from './type'
2625
import { getCurrentInstance } from './runtime'
2726

28-
const V_ON_REGEXP = /^v(O|-o)n:/
2927
const V_BIND_REGEXP = /^v(-b|B)ind:/
3028

3129
// Reference:
@@ -64,16 +62,6 @@ const jsx = function (
6462
continue
6563
}
6664

67-
// Transform v-on:xx or vOn:xx to onXx.
68-
if (V_ON_REGEXP.test(key)) {
69-
key = camelCase(key.replace(V_ON_REGEXP, 'on-'))
70-
}
71-
72-
// Transform v-bind:xx to xx.
73-
if (V_BIND_REGEXP.test(key)) {
74-
key = key.replace(V_BIND_REGEXP, '')
75-
}
76-
7765
const value = config[key]
7866

7967
if (checkKeyIsKey(key)) {
@@ -99,6 +87,7 @@ const jsx = function (
9987
continue
10088
}
10189

90+
// on.
10291
if (checkKeyIsOnObject(key)) {
10392
vNodeData.on = value
10493
continue
@@ -111,17 +100,20 @@ const jsx = function (
111100
continue
112101
}
113102

103+
// onInput, v-on:input, vOn:input
114104
if (checkKeyIsOnEvent(key)) {
115105
const _key = removeOn(key)
116-
vNodeData.on[_key] = value || noop
106+
vNodeData.on[_key] = value
117107
continue
118108
}
119109

110+
// slot.
120111
if (checkKeyIsSlot(key)) {
121112
vNodeData.slot = value
122113
continue
123114
}
124115

116+
// scopedSlots.
125117
if (checkKeyIsScopedSlots(key)) {
126118
vNodeData.scopedSlots = value
127119
continue
@@ -144,6 +136,11 @@ const jsx = function (
144136
continue
145137
}
146138

139+
// Transform v-bind:xx to xx.
140+
if (V_BIND_REGEXP.test(key)) {
141+
key = key.replace(V_BIND_REGEXP, '')
142+
}
143+
147144
if (isHTMLElement) {
148145
vNodeData.attrs[key] = value
149146
} else {
@@ -166,5 +163,3 @@ const jsx = function (
166163
export {
167164
jsx
168165
}
169-
170-
function noop () {}

lib/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const domProps = [
66
'src', 'checked'
77
]
88

9-
const ON_EVENT_REGEXP = /^on/
9+
const ON_EVENT_REGEXP = /^((v(-o|O)n:)|on)/
1010
const HTML_TAG_REGEXP = /^[\da-z]+$/
1111
const NATIVE_ON_REGEXP = /:native$/
1212

package-lock.json

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
"email": "[email protected]"
2424
},
2525
"license": "Apache-2.0",
26+
"repository": {
27+
"type": "git",
28+
"url": "https://github.com/LancerComet/vue2-jsx-runtime.git"
29+
},
2630
"peerDependencies": {
2731
"vue": "2"
2832
},

test/component.spec.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/* eslint-disable no-undef */
2+
13
import Vue from 'vue'
24
import { defineComponent } from '@vue/composition-api'
35
import { mount } from '@vue/test-utils'

0 commit comments

Comments
 (0)