This commit is contained in:
2023-08-11 10:45:20 +08:00
commit 161ca982f3
31850 changed files with 2706500 additions and 0 deletions

View File

@ -0,0 +1,54 @@
## @vue/babel-sugar-composition-api-inject-h
> Ported from [luwanquan/babel-preset-vca-jsx](https://github.com/luwanquan/babel-preset-vca-jsx) by [@luwanquan](https://github.com/luwanquan)
Syntactic sugar for automatic `h` inject in JSX with @vue/composition-api.
### Babel Compatibility Notes
- This repo is only compatible with Babel 7.x
### Usage
Install the dependencies:
```sh
# for yarn:
yarn add @vue/babel-sugar-composition-api-inject-h
# for npm:
npm install @vue/babel-sugar-composition-api-inject-h --save
```
In your `.babelrc`:
```json
{
"plugins": ["@vue/babel-sugar-composition-api-inject-h"]
}
```
However it is recommended to use the [configurable preset](../babel-preset-jsx/README.md) instead.
### Details
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`.
```js
// Without @vue/babel-sugar-inject-h
import { h } from '@vue/composition-api'
export default {
setup() {
return () => <button />
},
}
```
```js
// With @vue/babel-sugar-inject-h
export default {
setup() {
return () => <button />
},
}
```

View File

@ -0,0 +1 @@
"use strict";function _interopDefault(e){return e&&"object"==typeof e&&"default"in e?e.default:e}var syntaxJsx=_interopDefault(require("@babel/plugin-syntax-jsx"));const hasJSX=(e,t)=>{const n={hasJSX:!1};t.traverse({JSXElement(){this.hasJSX=!0}},n);return n.hasJSX},remove$createElement=(e,t)=>{t.traverse({ObjectMethod(t){"setup"===t.node.key.name&&t.traverse({VariableDeclaration(t){t.traverse({MemberExpression(n){e.isThisExpression(n.node.object)&&e.isIdentifier(n.node.property)&&"$createElement"===n.node.property.name&&t.remove()}})}})}})},autoImportH=(e,t,n)=>{if(hasJSX(e,t)){const i=t.get("body").filter(e=>e.isImportDeclaration()).map(e=>e.node),o=i.filter(e=>e.source.value===n),r=o.some(t=>t.specifiers.some(t=>e.isImportSpecifier(t)&&"h"===t.local.name));if(!r){const i=e.importSpecifier(e.identifier("h"),e.identifier("h"));o.length>0?o[0].specifiers.push(i):t.unshiftContainer("body",e.importDeclaration([i],e.stringLiteral(n)))}}};var index=(e,{importSource:importSource="@vue/composition-api"}={})=>{const t=e.types;return{inherits:syntaxJsx,visitor:{Program(e){remove$createElement(t,e),autoImportH(t,e,importSource)}}}};module.exports=index;

View File

@ -0,0 +1,78 @@
{
"_from": "@vue/babel-sugar-composition-api-inject-h@^1.4.0",
"_id": "@vue/babel-sugar-composition-api-inject-h@1.4.0",
"_inBundle": false,
"_integrity": "sha512-VQq6zEddJHctnG4w3TfmlVp5FzDavUSut/DwR0xVoe/mJKXyMcsIibL42wPntozITEoY90aBV0/1d2KjxHU52g==",
"_location": "/@vue/babel-sugar-composition-api-inject-h",
"_phantomChildren": {},
"_requested": {
"type": "range",
"registry": true,
"raw": "@vue/babel-sugar-composition-api-inject-h@^1.4.0",
"name": "@vue/babel-sugar-composition-api-inject-h",
"escapedName": "@vue%2fbabel-sugar-composition-api-inject-h",
"scope": "@vue",
"rawSpec": "^1.4.0",
"saveSpec": null,
"fetchSpec": "^1.4.0"
},
"_requiredBy": [
"/@vue/babel-preset-jsx"
],
"_resolved": "https://registry.npmjs.org/@vue/babel-sugar-composition-api-inject-h/-/babel-sugar-composition-api-inject-h-1.4.0.tgz",
"_shasum": "187e1389f8871d89ece743bb50aed713be9d6c85",
"_spec": "@vue/babel-sugar-composition-api-inject-h@^1.4.0",
"_where": "C:\\Users\\zhouxueli\\Desktop\\scheduling-app\\node_modules\\@vue\\babel-preset-jsx",
"author": {
"name": "luwanquan",
"email": "luwanquan@f-road.com.cn"
},
"bundleDependencies": false,
"dependencies": {
"@babel/plugin-syntax-jsx": "^7.2.0"
},
"deprecated": false,
"description": "Babel syntactic sugar for h automatic injection for Vue JSX with @vue/composition-api",
"devDependencies": {
"@babel/cli": "^7.2.0",
"@babel/core": "^7.2.0",
"@babel/preset-env": "^7.2.0",
"ava": "^0.25.0",
"nyc": "^13.1.0",
"rollup": "^0.67.4",
"rollup-plugin-babel": "4.0.3",
"rollup-plugin-istanbul": "^2.0.1",
"rollup-plugin-uglify-es": "^0.0.1",
"vue": "^2.5.17"
},
"files": [],
"gitHead": "6566e12067f5d6c02d3849b574a1b84de5634008",
"license": "MIT",
"main": "dist/plugin.js",
"name": "@vue/babel-sugar-composition-api-inject-h",
"nyc": {
"exclude": [
"dist",
"test"
]
},
"peerDependencies": {
"@babel/core": "^7.0.0-0"
},
"private": false,
"publishConfig": {
"access": "public"
},
"repository": {
"type": "git",
"url": "https://github.com/vuejs/jsx/tree/master/packages/babel-sugar-composition-api-inject-h"
},
"scripts": {
"build": "rollup -c",
"build:test": "rollup -c rollup.config.testing.js",
"prepublish": "yarn build",
"pretest": "yarn build:test",
"test": "nyc --reporter=html --reporter=text-summary ava -v test/test.js"
},
"version": "1.4.0"
}