chushihua
This commit is contained in:
+50
@@ -0,0 +1,50 @@
|
||||
var nestRE = /^(attrs|props|on|nativeOn|class|style|hook)$/
|
||||
|
||||
module.exports = function mergeJSXProps (objs) {
|
||||
return objs.reduce(function (a, b) {
|
||||
var aa, bb, key, nestedKey, temp
|
||||
for (key in b) {
|
||||
aa = a[key]
|
||||
bb = b[key]
|
||||
if (aa && nestRE.test(key)) {
|
||||
// normalize class
|
||||
if (key === 'class') {
|
||||
if (typeof aa === 'string') {
|
||||
temp = aa
|
||||
a[key] = aa = {}
|
||||
aa[temp] = true
|
||||
}
|
||||
if (typeof bb === 'string') {
|
||||
temp = bb
|
||||
b[key] = bb = {}
|
||||
bb[temp] = true
|
||||
}
|
||||
}
|
||||
if (key === 'on' || key === 'nativeOn' || key === 'hook') {
|
||||
// merge functions
|
||||
for (nestedKey in bb) {
|
||||
aa[nestedKey] = mergeFn(aa[nestedKey], bb[nestedKey])
|
||||
}
|
||||
} else if (Array.isArray(aa)) {
|
||||
a[key] = aa.concat(bb)
|
||||
} else if (Array.isArray(bb)) {
|
||||
a[key] = [aa].concat(bb)
|
||||
} else {
|
||||
for (nestedKey in bb) {
|
||||
aa[nestedKey] = bb[nestedKey]
|
||||
}
|
||||
}
|
||||
} else {
|
||||
a[key] = b[key]
|
||||
}
|
||||
}
|
||||
return a
|
||||
}, {})
|
||||
}
|
||||
|
||||
function mergeFn (a, b) {
|
||||
return function () {
|
||||
a && a.apply(this, arguments)
|
||||
b && b.apply(this, arguments)
|
||||
}
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"name": "babel-helper-vue-jsx-merge-props",
|
||||
"version": "2.0.3",
|
||||
"description": "babel helper for vue jsx spread.",
|
||||
"main": "index.js",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/vuejs/babel-helper-vue-jsx-merge-props.git"
|
||||
},
|
||||
"keywords": [
|
||||
"babel",
|
||||
"vue",
|
||||
"jsx"
|
||||
],
|
||||
"author": "Evan You",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/vuejs/babel-helper-vue-jsx-merge-props/issues"
|
||||
},
|
||||
"homepage": "https://github.com/vuejs/babel-helper-vue-jsx-merge-props#readme"
|
||||
}
|
||||
Reference in New Issue
Block a user