first commit

This commit is contained in:
monjack
2025-06-20 18:01:48 +08:00
commit 6daa6d65c1
24611 changed files with 2512443 additions and 0 deletions

View File

@ -0,0 +1,48 @@
## @vue/babel-sugar-inject-h
Syntactic sugar for automatic `h` inject in JSX.
### Babel Compatibility Notes
- This repo is only compatible with Babel 7.x, for 6.x please use [vuejs/babel-plugin-transform-vue-jsx](https://github.com/vuejs/babel-plugin-transform-vue-jsx)
### Usage
Install the dependencies:
```sh
# for yarn:
yarn add @vue/babel-sugar-inject-h
# for npm:
npm install @vue/babel-sugar-inject-h --save
```
In your `.babelrc`:
```json
{
"plugins": ["@vue/babel-sugar-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 specifically declare `h` as first parameter in your `render()` function.
```js
// Without @vue/babel-sugar-inject-h
export default {
render (h) {
return <button />
}
}
// With @vue/babel-sugar-inject-h
export default {
render () {
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 firstParamIsH=(e,n)=>{const t=n.get("params");return t.length&&e.isIdentifier(t[0])&&"h"===t[0].node.name},hasJSX=(e,n)=>{const t={hasJSX:!1};n.traverse({JSXElement(){this.hasJSX=!0}},t);return t.hasJSX},isInsideJSXExpression=(e,n)=>{if(!n.parentPath)return!1;if(e.isJSXExpressionContainer(n.parentPath))return!0;return isInsideJSXExpression(e,n.parentPath)};var index=e=>{const n=e.types;return{inherits:syntaxJsx,visitor:{Program(e){e.traverse({"ObjectMethod|ClassMethod"(e){if(!firstParamIsH(n,e)&&hasJSX(n,e)&&!isInsideJSXExpression(n,e)){const t="render"===e.node.key.name;e.get("body").unshiftContainer("body",n.variableDeclaration("const",[n.variableDeclarator(n.identifier("h"),t?n.memberExpression(n.identifier("arguments"),n.numericLiteral(0),!0):n.memberExpression(n.thisExpression(),n.identifier("$createElement")))]))}}})}}}};module.exports=index;

View File

@ -0,0 +1,46 @@
{
"name": "@vue/babel-sugar-inject-h",
"version": "1.4.0",
"description": "Babel syntactic sugar for h automatic injection for Vue JSX",
"main": "dist/plugin.js",
"repository": "https://github.com/vuejs/jsx/tree/master/packages/babel-sugar-inject-h",
"author": "Nick Messing <dot.nick.dot.messing@gmail.com>",
"license": "MIT",
"private": false,
"publishConfig": {
"access": "public"
},
"files": [],
"scripts": {
"prepublish": "yarn build",
"build": "rollup -c",
"build:test": "rollup -c rollup.config.testing.js",
"pretest": "yarn build:test && cd ../babel-plugin-transform-vue-jsx && yarn build:test",
"test": "nyc --reporter=html --reporter=text-summary ava -v test/test.js"
},
"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"
},
"dependencies": {
"@babel/plugin-syntax-jsx": "^7.2.0"
},
"peerDependencies": {
"@babel/core": "^7.0.0-0"
},
"nyc": {
"exclude": [
"dist",
"test"
]
},
"gitHead": "6566e12067f5d6c02d3849b574a1b84de5634008"
}