Skip to content

Commit ecc6ed6

Browse files
antfuluwanquanhaoqunjiang
authored
feat: add @vue/composition-api support (vuejs#142)
Co-authored-by: luwanquan <[email protected]> Co-authored-by: Haoqun Jiang <[email protected]>
1 parent bcf52c1 commit ecc6ed6

File tree

21 files changed

+10514
-162
lines changed

21 files changed

+10514
-162
lines changed

packages/babel-plugin-transform-vue-jsx/yarn.lock

-5
Original file line numberDiff line numberDiff line change
@@ -769,11 +769,6 @@
769769
resolved "https://registry.yarnpkg.com/@types/node/-/node-10.12.12.tgz#e15a9d034d9210f00320ef718a50c4a799417c47"
770770
integrity sha512-Pr+6JRiKkfsFvmU/LK68oBRCQeEg36TyAbPhc2xpez24OOZZCuoIhWGTd39VZy6nGafSbxzGouFPTFD/rR1A0A==
771771

772-
"@vue/babel-helper-vue-jsx-merge-props@^1.0.0":
773-
version "1.0.0"
774-
resolved "https://registry.yarnpkg.com/@vue/babel-helper-vue-jsx-merge-props/-/babel-helper-vue-jsx-merge-props-1.0.0.tgz#048fe579958da408fb7a8b2a3ec050b50a661040"
775-
integrity sha512-6tyf5Cqm4m6v7buITuwS+jHzPlIPxbFzEhXR5JGZpbrvOcp1hiQKckd305/3C7C36wFekNTQSxAtgeM0j0yoUw==
776-
777772
"@vue/test-utils@^1.0.0-beta.26":
778773
version "1.0.0-beta.26"
779774
resolved "https://registry.yarnpkg.com/@vue/test-utils/-/test-utils-1.0.0-beta.26.tgz#1ae7e1dc2bef4f49f9dbfdfecad342d17d6c5c88"

packages/babel-preset-jsx/src/index.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
import babelPluginTransformVueJsx from '@vue/babel-plugin-transform-vue-jsx'
22
import babelSugarFunctionalVue from '@vue/babel-sugar-functional-vue'
33
import babelSugarInjectH from '@vue/babel-sugar-inject-h'
4+
import babelSugarCompositionApiInjectH from '@vue/babel-sugar-composition-api-inject-h'
5+
import babelSugarCompositionApiRenderInstance from '@vue/babel-sugar-composition-api-render-instance'
46
import babelSugarVModel from '@vue/babel-sugar-v-model'
57
import babelSugarVOn from '@vue/babel-sugar-v-on'
68

7-
export default (_, { functional = true, injectH = true, vModel = true, vOn = true } = {}) => {
9+
export default (_, { functional = true, injectH = true, vModel = true, vOn = true, compositionAPI = false } = {}) => {
810
return {
911
plugins: [
1012
functional && babelSugarFunctionalVue,
11-
injectH && babelSugarInjectH,
13+
injectH && (compositionAPI ? babelSugarCompositionApiInjectH : babelSugarInjectH),
1214
vModel && babelSugarVModel,
1315
vOn && babelSugarVOn,
16+
compositionAPI && babelSugarCompositionApiRenderInstance,
1417
babelPluginTransformVueJsx,
1518
].filter(Boolean),
1619
}

packages/babel-preset-jsx/yarn.lock

+1-101
Original file line numberDiff line numberDiff line change
@@ -56,18 +56,6 @@
5656
dependencies:
5757
"@babel/types" "^7.0.0"
5858

59-
"@babel/helper-module-imports@^7.0.0":
60-
version "7.8.3"
61-
resolved "https://registry.yarnpkg.com/@babel/helper-module-imports/-/helper-module-imports-7.8.3.tgz#7fe39589b39c016331b6b8c3f441e8f0b1419498"
62-
integrity sha512-R0Bx3jippsbAEtzkpZ/6FIiuzOURPcMjHp+Z6xPe6DtApDJx+w7UYyOLanZqO8+wKR9G10s/FmHXvxaMd9s6Kg==
63-
dependencies:
64-
"@babel/types" "^7.8.3"
65-
66-
"@babel/helper-plugin-utils@^7.8.3":
67-
version "7.8.3"
68-
resolved "https://registry.yarnpkg.com/@babel/helper-plugin-utils/-/helper-plugin-utils-7.8.3.tgz#9ea293be19babc0f52ff8ca88b34c3611b208670"
69-
integrity sha512-j+fq49Xds2smCUNYmEHF9kGNkhbet6yVIBp4e6oeQpH1RUs/Ir06xUKzDjDkGcaaokPiTNs2JBWHjaE4csUkZQ==
70-
7159
"@babel/helper-split-export-declaration@^7.0.0":
7260
version "7.0.0"
7361
resolved "https://registry.yarnpkg.com/@babel/helper-split-export-declaration/-/helper-split-export-declaration-7.0.0.tgz#3aae285c0311c2ab095d997b8c9a94cad547d813"
@@ -98,13 +86,6 @@
9886
resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.2.0.tgz#02d01dbc330b6cbf36b76ac93c50752c69027065"
9987
integrity sha512-M74+GvK4hn1eejD9lZ7967qAwvqTZayQa3g10ag4s9uewgR7TKjeaT0YMyoq+gVfKYABiWZ4MQD701/t5e1Jhg==
10088

101-
"@babel/plugin-syntax-jsx@^7.2.0":
102-
version "7.8.3"
103-
resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-jsx/-/plugin-syntax-jsx-7.8.3.tgz#521b06c83c40480f1e58b4fd33b92eceb1d6ea94"
104-
integrity sha512-WxdW9xyLgBdefoo0Ynn3MRSkhe5tFVxxKNVdnZSh318WrG2e2jH+E9wd/++JsqcLJZPfz87njQJ8j2Upjm0M0A==
105-
dependencies:
106-
"@babel/helper-plugin-utils" "^7.8.3"
107-
10889
"@babel/template@^7.1.0", "@babel/template@^7.1.2":
10990
version "7.1.2"
11091
resolved "https://registry.yarnpkg.com/@babel/template/-/template-7.1.2.tgz#090484a574fef5a2d2d7726a674eceda5c5b5644"
@@ -138,15 +119,6 @@
138119
lodash "^4.17.10"
139120
to-fast-properties "^2.0.0"
140121

141-
"@babel/types@^7.8.3":
142-
version "7.8.7"
143-
resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.8.7.tgz#1fc9729e1acbb2337d5b6977a63979b4819f5d1d"
144-
integrity sha512-k2TreEHxFA4CjGkL+GYjRyx35W0Mr7DP5+9q6WMkyKXB+904bYmG40syjMFV0oLlhhFCwWl0vA0DyzTDkwAiJw==
145-
dependencies:
146-
esutils "^2.0.2"
147-
lodash "^4.17.13"
148-
to-fast-properties "^2.0.0"
149-
150122
"@comandeer/babel-plugin-banner@^4.0.0":
151123
version "4.1.0"
152124
resolved "https://registry.yarnpkg.com/@comandeer/babel-plugin-banner/-/babel-plugin-banner-4.1.0.tgz#5f9f22f3ba5a4e87d0c972c402f039c6eeffc079"
@@ -162,58 +134,6 @@
162134
resolved "https://registry.yarnpkg.com/@types/node/-/node-10.12.12.tgz#e15a9d034d9210f00320ef718a50c4a799417c47"
163135
integrity sha512-Pr+6JRiKkfsFvmU/LK68oBRCQeEg36TyAbPhc2xpez24OOZZCuoIhWGTd39VZy6nGafSbxzGouFPTFD/rR1A0A==
164136

165-
"@vue/babel-helper-vue-jsx-merge-props@^1.0.0":
166-
version "1.0.0"
167-
resolved "https://registry.yarnpkg.com/@vue/babel-helper-vue-jsx-merge-props/-/babel-helper-vue-jsx-merge-props-1.0.0.tgz#048fe579958da408fb7a8b2a3ec050b50a661040"
168-
integrity sha512-6tyf5Cqm4m6v7buITuwS+jHzPlIPxbFzEhXR5JGZpbrvOcp1hiQKckd305/3C7C36wFekNTQSxAtgeM0j0yoUw==
169-
170-
"@vue/babel-plugin-transform-vue-jsx@^1.1.2":
171-
version "1.1.2"
172-
resolved "https://registry.yarnpkg.com/@vue/babel-plugin-transform-vue-jsx/-/babel-plugin-transform-vue-jsx-1.1.2.tgz#c0a3e6efc022e75e4247b448a8fc6b86f03e91c0"
173-
integrity sha512-YfdaoSMvD1nj7+DsrwfTvTnhDXI7bsuh+Y5qWwvQXlD24uLgnsoww3qbiZvWf/EoviZMrvqkqN4CBw0W3BWUTQ==
174-
dependencies:
175-
"@babel/helper-module-imports" "^7.0.0"
176-
"@babel/plugin-syntax-jsx" "^7.2.0"
177-
"@vue/babel-helper-vue-jsx-merge-props" "^1.0.0"
178-
html-tags "^2.0.0"
179-
lodash.kebabcase "^4.1.1"
180-
svg-tags "^1.0.0"
181-
182-
"@vue/babel-sugar-functional-vue@^1.1.2":
183-
version "1.1.2"
184-
resolved "https://registry.yarnpkg.com/@vue/babel-sugar-functional-vue/-/babel-sugar-functional-vue-1.1.2.tgz#f7e24fba09e6f1ee70104560a8808057555f1a9a"
185-
integrity sha512-YhmdJQSVEFF5ETJXzrMpj0nkCXEa39TvVxJTuVjzvP2rgKhdMmQzlJuMv/HpadhZaRVMCCF3AEjjJcK5q/cYzQ==
186-
dependencies:
187-
"@babel/plugin-syntax-jsx" "^7.2.0"
188-
189-
"@vue/babel-sugar-inject-h@^1.1.2":
190-
version "1.1.2"
191-
resolved "https://registry.yarnpkg.com/@vue/babel-sugar-inject-h/-/babel-sugar-inject-h-1.1.2.tgz#8a5276b6d8e2ed16ffc8078aad94236274e6edf0"
192-
integrity sha512-VRSENdTvD5htpnVp7i7DNuChR5rVMcORdXjvv5HVvpdKHzDZAYiLSD+GhnhxLm3/dMuk8pSzV+k28ECkiN5m8w==
193-
dependencies:
194-
"@babel/plugin-syntax-jsx" "^7.2.0"
195-
196-
"@vue/babel-sugar-v-model@^1.1.2":
197-
version "1.1.2"
198-
resolved "https://registry.yarnpkg.com/@vue/babel-sugar-v-model/-/babel-sugar-v-model-1.1.2.tgz#1ff6fd1b800223fc9cb1e84dceb5e52d737a8192"
199-
integrity sha512-vLXPvNq8vDtt0u9LqFdpGM9W9IWDmCmCyJXuozlq4F4UYVleXJ2Fa+3JsnTZNJcG+pLjjfnEGHci2339Kj5sGg==
200-
dependencies:
201-
"@babel/plugin-syntax-jsx" "^7.2.0"
202-
"@vue/babel-helper-vue-jsx-merge-props" "^1.0.0"
203-
"@vue/babel-plugin-transform-vue-jsx" "^1.1.2"
204-
camelcase "^5.0.0"
205-
html-tags "^2.0.0"
206-
svg-tags "^1.0.0"
207-
208-
"@vue/babel-sugar-v-on@^1.1.2":
209-
version "1.1.2"
210-
resolved "https://registry.yarnpkg.com/@vue/babel-sugar-v-on/-/babel-sugar-v-on-1.1.2.tgz#b2ef99b8f2fab09fbead25aad70ef42e1cf5b13b"
211-
integrity sha512-T8ZCwC8Jp2uRtcZ88YwZtZXe7eQrJcfRq0uTFy6ShbwYJyz5qWskRFoVsdTi9o0WEhmQXxhQUewodOSCUPVmsQ==
212-
dependencies:
213-
"@babel/plugin-syntax-jsx" "^7.2.0"
214-
"@vue/babel-plugin-transform-vue-jsx" "^1.1.2"
215-
camelcase "^5.0.0"
216-
217137
ansi-styles@^3.2.1:
218138
version "3.2.1"
219139
resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-3.2.1.tgz#41fbb20243e50b12be0f04b8dedbf07520ce841d"
@@ -418,11 +338,6 @@ babel-preset-minify@^0.5.0:
418338
babel-plugin-transform-undefined-to-void "^6.9.4"
419339
lodash.isplainobject "^4.0.6"
420340

421-
camelcase@^5.0.0:
422-
version "5.3.1"
423-
resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-5.3.1.tgz#e3c9b31569e106811df242f715725a1f4c494320"
424-
integrity sha512-L28STB170nwWS63UjtlEOE3dldQApaJXZkOI1uMFfzf3rRuPegHaHesyee+YxQ+W6SvRDQV6UrdOdRiR153wJg==
425-
426341
chalk@^2.0.0:
427342
version "2.4.1"
428343
resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.4.1.tgz#18c49ab16a037b6eb0152cc83e3471338215b66e"
@@ -478,11 +393,6 @@ has-flag@^3.0.0:
478393
resolved "https://registry.yarnpkg.com/has-flag/-/has-flag-3.0.0.tgz#b5d454dc2199ae225699f3467e5a07f3b955bafd"
479394
integrity sha1-tdRU3CGZriJWmfNGfloH87lVuv0=
480395

481-
html-tags@^2.0.0:
482-
version "2.0.0"
483-
resolved "https://registry.yarnpkg.com/html-tags/-/html-tags-2.0.0.tgz#10b30a386085f43cede353cc8fa7cb0deeea668b"
484-
integrity sha1-ELMKOGCF9Dzt41PMj6fLDe7qZos=
485-
486396
js-tokens@^4.0.0:
487397
version "4.0.0"
488398
resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499"
@@ -505,17 +415,12 @@ lodash.isplainobject@^4.0.6:
505415
resolved "https://registry.yarnpkg.com/lodash.isplainobject/-/lodash.isplainobject-4.0.6.tgz#7c526a52d89b45c45cc690b88163be0497f550cb"
506416
integrity sha1-fFJqUtibRcRcxpC4gWO+BJf1UMs=
507417

508-
lodash.kebabcase@^4.1.1:
509-
version "4.1.1"
510-
resolved "https://registry.yarnpkg.com/lodash.kebabcase/-/lodash.kebabcase-4.1.1.tgz#8489b1cb0d29ff88195cceca448ff6d6cc295c36"
511-
integrity sha1-hImxyw0p/4gZXM7KRI/21swpXDY=
512-
513418
lodash.some@^4.6.0:
514419
version "4.6.0"
515420
resolved "https://registry.yarnpkg.com/lodash.some/-/lodash.some-4.6.0.tgz#1bb9f314ef6b8baded13b549169b2a945eb68e4d"
516421
integrity sha1-G7nzFO9ri63tE7VJFpsqlF62jk0=
517422

518-
lodash@^4.17.10, lodash@^4.17.13:
423+
lodash@^4.17.10:
519424
version "4.17.15"
520425
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.15.tgz#b447f6670a0455bbfeedd11392eff330ea097548"
521426
integrity sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==
@@ -587,11 +492,6 @@ supports-color@^5.3.0:
587492
dependencies:
588493
has-flag "^3.0.0"
589494

590-
svg-tags@^1.0.0:
591-
version "1.0.0"
592-
resolved "https://registry.yarnpkg.com/svg-tags/-/svg-tags-1.0.0.tgz#58f71cee3bd519b59d4b2a843b6c7de64ac04764"
593-
integrity sha1-WPcc7jvVGbWdSyqEO2x95krAR2Q=
594-
595495
to-fast-properties@^2.0.0:
596496
version "2.0.0"
597497
resolved "https://registry.yarnpkg.com/to-fast-properties/-/to-fast-properties-2.0.0.tgz#dc5e698cbd079265bc73e0377681a4e4e83f616e"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/dist
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
## @vue/babel-sugar-composition-api-inject-h
2+
3+
> Ported from [luwanquan/babel-preset-vca-jsx](https://github.com/luwanquan/babel-preset-vca-jsx) by [@luwanquan](https://github.com/luwanquan)
4+
5+
Syntactic sugar for automatic `h` inject in JSX with @vue/composition-api.
6+
7+
### Babel Compatibility Notes
8+
9+
- This repo is only compatible with Babel 7.x
10+
11+
### Usage
12+
13+
Install the dependencies:
14+
15+
```sh
16+
# for yarn:
17+
yarn add @vue/babel-sugar-composition-api-inject-h
18+
# for npm:
19+
npm install @vue/babel-sugar-composition-api-inject-h --save
20+
```
21+
22+
In your `.babelrc`:
23+
24+
```json
25+
{
26+
"plugins": ["@vue/babel-sugar-composition-api-inject-h"]
27+
}
28+
```
29+
30+
However it is recommended to use the [configurable preset](../babel-preset-jsx/README.md) instead.
31+
32+
### Details
33+
34+
This plugin automatically injects `h` in every method that has JSX. By using this plugin you don't have to always import `h` from `@vue/composition-api`.
35+
36+
```js
37+
// Without @vue/babel-sugar-inject-h
38+
import { h } from '@vue/composition-api'
39+
40+
export default {
41+
setup() {
42+
return () => <button />
43+
},
44+
}
45+
```
46+
47+
```js
48+
// With @vue/babel-sugar-inject-h
49+
export default {
50+
setup() {
51+
return () => <button />
52+
},
53+
}
54+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"name": "@vue/babel-sugar-composition-api-inject-h",
3+
"version": "1.1.2",
4+
"description": "Babel syntactic sugar for h automatic injection for Vue JSX with @vue/composition-api",
5+
"main": "dist/plugin.js",
6+
"repository": "https://github.com/vuejs/jsx/tree/master/packages/babel-sugar-composition-api-inject-h",
7+
"author": "luwanquan <[email protected]>",
8+
"license": "MIT",
9+
"private": false,
10+
"files": [],
11+
"scripts": {
12+
"prepublish": "yarn build",
13+
"build": "rollup -c",
14+
"build:test": "rollup -c rollup.config.testing.js",
15+
"pretest": "yarn build:test",
16+
"test": "nyc --reporter=html --reporter=text-summary ava -v test/test.js"
17+
},
18+
"devDependencies": {
19+
"@babel/cli": "^7.2.0",
20+
"@babel/core": "^7.2.0",
21+
"@babel/preset-env": "^7.2.0",
22+
"ava": "^0.25.0",
23+
"nyc": "^13.1.0",
24+
"rollup": "^0.67.4",
25+
"rollup-plugin-babel": "4.0.3",
26+
"rollup-plugin-istanbul": "^2.0.1",
27+
"rollup-plugin-uglify-es": "^0.0.1",
28+
"vue": "^2.5.17"
29+
},
30+
"dependencies": {
31+
"@babel/plugin-syntax-jsx": "^7.2.0"
32+
},
33+
"peerDependencies": {
34+
"@babel/core": "^7.0.0-0"
35+
},
36+
"nyc": {
37+
"exclude": [
38+
"dist",
39+
"test"
40+
]
41+
}
42+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
node: '8',
15+
},
16+
modules: false,
17+
loose: true,
18+
},
19+
],
20+
],
21+
}),
22+
uglify(),
23+
],
24+
output: [
25+
{
26+
file: 'dist/plugin.js',
27+
format: 'cjs',
28+
},
29+
],
30+
}
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/plugin.testing.js',
9+
format: 'cjs',
10+
},
11+
],
12+
}

0 commit comments

Comments
 (0)