Skip to content

Commit 9fc4e55

Browse files
committed
init
0 parents  commit 9fc4e55

20 files changed

+11753
-0
lines changed

.gitignore

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
8+
# Runtime data
9+
pids
10+
*.pid
11+
*.seed
12+
*.pid.lock
13+
14+
# Directory for instrumented libs generated by jscoverage/JSCover
15+
lib-cov
16+
17+
# Coverage directory used by tools like istanbul
18+
coverage
19+
20+
# nyc test coverage
21+
.nyc_output
22+
23+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
24+
.grunt
25+
26+
# Bower dependency directory (https://bower.io/)
27+
bower_components
28+
29+
# node-waf configuration
30+
.lock-wscript
31+
32+
# Compiled binary addons (https://nodejs.org/api/addons.html)
33+
build/Release
34+
35+
# Dependency directories
36+
node_modules/
37+
jspm_packages/
38+
39+
# TypeScript v1 declaration files
40+
typings/
41+
42+
# Optional npm cache directory
43+
.npm
44+
45+
# Optional eslint cache
46+
.eslintcache
47+
48+
# Optional REPL history
49+
.node_repl_history
50+
51+
# Output of 'npm pack'
52+
*.tgz
53+
54+
# Yarn Integrity file
55+
.yarn-integrity
56+
57+
# dotenv environment variables file
58+
.env
59+
60+
# next.js build output
61+
.next
62+
63+
# vuepress build output
64+
.vuepress/dist

.vscode/settings.json

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"editor.formatOnSave": true,
3+
"prettier.eslintIntegration": false,
4+
"prettier.arrowParens": "avoid",
5+
"prettier.bracketSpacing": true,
6+
"prettier.ignorePath": ".prettierignore",
7+
"prettier.printWidth": 120,
8+
"prettier.semi": false,
9+
"prettier.singleQuote": true,
10+
"prettier.tabWidth": 2,
11+
"prettier.trailingComma": "all"
12+
}

lerna.json

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"lerna": "2.9.1",
3+
"packages": ["packages/*"],
4+
"version": "0.1.0",
5+
"npmClient": "yarn"
6+
}

package.json

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"private": true,
3+
"license": "MIT",
4+
"scripts": {
5+
"postinstall": "lerna bootstrap",
6+
"test": "lerna run test"
7+
},
8+
"devDependencies": {
9+
"lerna": "^2.9.1"
10+
}
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/dist
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"name": "@vuejs/babel-helper-vue-jsx-merge-props",
3+
"version": "0.1.0",
4+
"description": "Babel helper for Vue JSX spread",
5+
"main": "dist/helper.js",
6+
"repository": "https://github.com/vuejs/jsx/tree/master/packages/babel-helper-vue-jsx-merge-props",
7+
"author": "Evan You",
8+
"license": "MIT",
9+
"private": false,
10+
"scripts": {
11+
"build:testing": "rollup -c rollup.config.testing.js",
12+
"build": "rollup -c",
13+
"pretest": "yarn build:testing",
14+
"test": "nyc --reporter=html --reporter=text ava -v test/test.js"
15+
},
16+
"devDependencies": {
17+
"@babel/core": "^7.0.0-beta.49",
18+
"@babel/preset-env": "^7.0.0-beta.49",
19+
"ava": "^0.25.0",
20+
"babel-preset-minify": "^0.4.3",
21+
"nyc": "^11.8.0",
22+
"rollup": "^0.59.4",
23+
"rollup-plugin-babel": "beta",
24+
"rollup-plugin-istanbul": "^2.0.1",
25+
"rollup-plugin-uglify": "^4.0.0",
26+
"rollup-plugin-uglify-es": "^0.0.1"
27+
},
28+
"nyc": {
29+
"exclude": ["dist", "test"]
30+
}
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { rollup } from 'rollup'
2+
import babel from 'rollup-plugin-babel'
3+
import uglify from 'rollup-plugin-uglify-es'
4+
5+
export default {
6+
input: 'src/index.js',
7+
plugins: [
8+
babel({
9+
presets: [
10+
[
11+
'@babel/preset-env',
12+
{
13+
targets: {
14+
browsers: [
15+
'ie 11', // es5
16+
],
17+
},
18+
modules: false,
19+
loose: true,
20+
},
21+
],
22+
],
23+
}),
24+
uglify(),
25+
],
26+
output: [
27+
{
28+
file: 'dist/helper.esm.js',
29+
format: 'es',
30+
},
31+
{
32+
file: 'dist/helper.js',
33+
format: 'cjs',
34+
},
35+
],
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import istanbul from 'rollup-plugin-istanbul'
2+
3+
export default {
4+
input: 'src/index.js',
5+
plugins: [istanbul()],
6+
output: [
7+
{
8+
file: 'dist/helper.testing.js',
9+
format: 'cjs',
10+
},
11+
],
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
const normalMerge = ['attrs', 'props', 'domProps']
2+
const toArrayMerge = ['class', 'style', 'directives']
3+
const functionalMerge = ['on', 'nativeOn']
4+
5+
const mergeJsxProps = objects =>
6+
objects.reduce((a, b) => {
7+
for (const key in b) {
8+
if (a[key]) {
9+
if (normalMerge.indexOf(key) !== -1) {
10+
a[key] = { ...a[key], ...b[key] }
11+
} else if (toArrayMerge.indexOf(key) !== -1) {
12+
const arrA = a[key] instanceof Array ? a[key] : [a[key]]
13+
const arrB = b[key] instanceof Array ? b[key] : [b[key]]
14+
a[key] = [...arrA, ...arrB]
15+
} else if (functionalMerge.indexOf(key) !== -1) {
16+
for (const event in b[key]) {
17+
if (a[key][event]) {
18+
const arrA = a[key][event] instanceof Array ? a[key][event] : [a[key][event]]
19+
const arrB = b[key][event] instanceof Array ? b[key][event] : [b[key][event]]
20+
a[key][event] = [...arrA, ...arrB]
21+
} else {
22+
a[key][event] = b[key][event]
23+
}
24+
}
25+
} else if (key === 'hook') {
26+
for (let hook in b[key]) {
27+
if (a[key][hook]) {
28+
a[key][hook] = mergeFn(a[key][hook], b[key][hook])
29+
} else {
30+
a[key][hook] = b[key][hook]
31+
}
32+
}
33+
} else {
34+
a[key] = b[key]
35+
}
36+
} else {
37+
a[key] = b[key]
38+
}
39+
}
40+
return a
41+
}, {})
42+
43+
const mergeFn = (fn1, fn2) =>
44+
function() {
45+
fn1 && fn1.apply(this, arguments)
46+
fn2 && fn2.apply(this, arguments)
47+
}
48+
49+
export default mergeJsxProps
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import test from 'ava'
2+
import helper from '../dist/helper.testing'
3+
4+
test('Complete merge scenario', t => {
5+
let counter = 0
6+
const merged = helper([
7+
{
8+
attrs: {
9+
a: 1,
10+
b: 3,
11+
},
12+
class: 'hello',
13+
on: {
14+
click: 'hey',
15+
},
16+
ref: 'beta',
17+
hook: {
18+
insert() {
19+
counter++
20+
},
21+
},
22+
},
23+
{
24+
attrs: {
25+
a: 2,
26+
},
27+
class: 'world',
28+
on: {
29+
click: 'you',
30+
hover: 'woohoo',
31+
},
32+
ref: 'delta',
33+
hook: {
34+
insert() {
35+
counter += 2
36+
},
37+
next: 'anotherHook',
38+
},
39+
},
40+
{
41+
class: ['alpha', 'beta'],
42+
on: {
43+
click: ['how', 'you', 'doin'],
44+
},
45+
},
46+
])
47+
t.deepEqual(merged, {
48+
attrs: {
49+
a: 2,
50+
b: 3,
51+
},
52+
class: ['hello', 'world', 'alpha', 'beta'],
53+
on: {
54+
click: ['hey', 'you', 'how', 'you', 'doin'],
55+
hover: 'woohoo',
56+
},
57+
ref: 'delta',
58+
hook: {
59+
insert: merged.hook.insert,
60+
next: 'anotherHook',
61+
},
62+
})
63+
t.is(counter, 0)
64+
merged.hook.insert()
65+
t.is(counter, 3)
66+
})

0 commit comments

Comments
 (0)