first commit
This commit is contained in:
56
app_vue/node_modules/@vue/babel-sugar-functional-vue/README.md
generated
vendored
Normal file
56
app_vue/node_modules/@vue/babel-sugar-functional-vue/README.md
generated
vendored
Normal file
@ -0,0 +1,56 @@
|
||||
## @vue/babel-sugar-functional-vue
|
||||
|
||||
Syntactic sugar for functional components.
|
||||
|
||||
### 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-functional-vue
|
||||
# for npm:
|
||||
npm install @vue/babel-sugar-functional-vue --save
|
||||
```
|
||||
|
||||
In your `.babelrc`:
|
||||
|
||||
```json
|
||||
{
|
||||
"plugins": ["@vue/babel-sugar-functional-vue"]
|
||||
}
|
||||
```
|
||||
|
||||
However it is recommended to use the [configurable preset](../babel-preset-jsx/README.md) instead.
|
||||
|
||||
### Details
|
||||
|
||||
This plugin transpiles arrow functions that return JSX into functional components but only if it's an uppercase variable declaration or default export:
|
||||
|
||||
```js
|
||||
// Original:
|
||||
export const A = ({ props, listeners }) => <div onClick={listeners.click}>{props.msg}</div>
|
||||
export const b = ({ props, listeners }) => <div onClick={listeners.click}>{props.msg}</div>
|
||||
export default ({ props, listeners }) => <div onClick={listeners.click}>{props.msg}</div>
|
||||
|
||||
// Result:
|
||||
export const A = {
|
||||
functional: true,
|
||||
render: (h, {
|
||||
props,
|
||||
listeners
|
||||
}) => <div onClick={listeners.click}>{props.msg}</div>
|
||||
}
|
||||
export const b = ({ props, listeners }) => <div onClick={listeners.click}>{props.msg}</div>
|
||||
export default {
|
||||
functional: true,
|
||||
render: (h, {
|
||||
props,
|
||||
listeners
|
||||
}) => <div onClick={listeners.click}>{props.msg}</div>
|
||||
}
|
||||
```
|
12
app_vue/node_modules/@vue/babel-sugar-functional-vue/dist/plugin.js
generated
vendored
Normal file
12
app_vue/node_modules/@vue/babel-sugar-functional-vue/dist/plugin.js
generated
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
"use strict";function _interopDefault(a){return a&&"object"==typeof a&&"default"in a?a["default"]:a}var syntaxJsx=_interopDefault(require("@babel/plugin-syntax-jsx"));/**
|
||||
* Check if expression is in method
|
||||
* @param t
|
||||
* @param path
|
||||
* @param parentLimitPath
|
||||
* @returns boolean
|
||||
*/const isInMethod=(a,b,c)=>!!(b&&b!==c)&&(!!a.isObjectMethod(b)||isInMethod(a,b.parentPath,c)),hasJSX=(a,b)=>{let c=!1;return b.traverse({JSXElement(d){isInMethod(a,d,b)||(c=!0)}}),c},isFunctionalComponentDeclarator=(a,b)=>{const c=b.get("id.name").node[0];return!("A">c||"Z"<c)&&hasJSX(a,b)},convertFunctionalComponent=(a,b,c=null)=>{const d=[a.identifier("h"),...b.node.params],e=b.node.body,f=[a.objectProperty(a.identifier("functional"),a.booleanLiteral(!0)),a.objectProperty(a.identifier("render"),a.arrowFunctionExpression(d,e))];"development"===process.env.NODE_ENV&&c&&f.unshift(a.objectProperty(a.identifier("name"),a.stringLiteral(c))),b.replaceWith(a.objectExpression(f))};/**
|
||||
* Check path has JSX
|
||||
* @param t
|
||||
* @param path
|
||||
* @returns boolean
|
||||
*/var index=a=>{const b=a.types;return{inherits:syntaxJsx,visitor:{Program(a){a.traverse({ExportDefaultDeclaration:{exit(a){b.isArrowFunctionExpression(a.node.declaration)&&hasJSX(b,a)&&convertFunctionalComponent(b,a.get("declaration"))}},VariableDeclaration:{exit(a){if(1===a.node.declarations.length&&b.isVariableDeclarator(a.node.declarations[0])&&b.isArrowFunctionExpression(a.node.declarations[0].init)){const c=a.get("declarations")[0];if(isFunctionalComponentDeclarator(b,c)){const c=a.node.declarations[0].id.name;convertFunctionalComponent(b,a.get("declarations")[0].get("init"),c)}}}}})}}}};module.exports=index;
|
46
app_vue/node_modules/@vue/babel-sugar-functional-vue/package.json
generated
vendored
Normal file
46
app_vue/node_modules/@vue/babel-sugar-functional-vue/package.json
generated
vendored
Normal file
@ -0,0 +1,46 @@
|
||||
{
|
||||
"name": "@vue/babel-sugar-functional-vue",
|
||||
"version": "1.4.0",
|
||||
"description": "Babel syntactic sugar for functional components",
|
||||
"main": "dist/plugin.js",
|
||||
"repository": "https://github.com/vuejs/jsx/tree/master/packages/babel-sugar-functional-vue",
|
||||
"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-babel-minify": "^6.2.0",
|
||||
"rollup-plugin-istanbul": "^2.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"
|
||||
}
|
Reference in New Issue
Block a user