initial commit

This commit is contained in:
Zoe
2023-01-03 09:29:04 -06:00
commit 7851137d88
12889 changed files with 2557443 additions and 0 deletions

21
node_modules/@vue/babel-plugin-jsx/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2020-present vuejs
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

376
node_modules/@vue/babel-plugin-jsx/README.md generated vendored Normal file
View File

@@ -0,0 +1,376 @@
# Babel Plugin JSX for Vue 3.0
[![CircleCI](https://circleci.com/gh/vuejs/jsx-next.svg?style=svg)](https://circleci.com/gh/vuejs/vue-next) [![npm package](https://img.shields.io/npm/v/@vue/babel-plugin-jsx.svg?style=flat-square)](https://www.npmjs.com/package/@vue/babel-plugin-jsx)
[![issues-helper](https://img.shields.io/badge/Issues%20Manage%20By-issues--helper-blueviolet?style=flat-square)](https://github.com/actions-cool/issues-helper)
To add Vue JSX support.
English | [简体中文](/packages/babel-plugin-jsx/README-zh_CN.md)
## Installation
Install the plugin with:
```bash
npm install @vue/babel-plugin-jsx -D
```
Then add the plugin to your babel config:
```json
{
"plugins": ["@vue/babel-plugin-jsx"]
}
```
## Usage
### options
#### transformOn
Type: `boolean`
Default: `false`
transform `on: { click: xx }` to `onClick: xxx`
#### optimize
Type: `boolean`
Default: `false`
enable optimization or not. It's not recommended to enable it If you are not familiar with Vue 3.
#### isCustomElement
Type: `(tag: string) => boolean`
Default: `undefined`
configuring custom elements
#### mergeProps
Type: `boolean`
Default: `true`
merge static and dynamic class / style attributes / onXXX handlers
#### enableObjectSlots
Type: `boolean`
Default: `true`
Whether to enable `object slots` (mentioned below the document) syntax". It might be useful in JSX, but it will add a lot of `_isSlot` condition expressions which increase your bundle size. And `v-slots` is still available even if `enableObjectSlots` is turned off.
#### pragma
Type: `string`
Default: `createVNode`
Replace the function used when compiling JSX expressions.
## Syntax
### Content
functional component
```jsx
const App = () => <div>Vue 3.0</div>;
```
with render
```jsx
const App = {
render() {
return <div>Vue 3.0</div>;
},
};
```
```jsx
import { withModifiers, defineComponent } from "vue";
const App = defineComponent({
setup() {
const count = ref(0);
const inc = () => {
count.value++;
};
return () => (
<div onClick={withModifiers(inc, ["self"])}>{count.value}</div>
);
},
});
```
Fragment
```jsx
const App = () => (
<>
<span>I'm</span>
<span>Fragment</span>
</>
);
```
### Attributes / Props
```jsx
const App = () => <input type="email" />;
```
with a dynamic binding:
```jsx
const placeholderText = "email";
const App = () => <input type="email" placeholder={placeholderText} />;
```
### Directives
#### v-show
```jsx
const App = {
data() {
return { visible: true };
},
render() {
return <input v-show={this.visible} />;
},
};
```
#### v-model
> Note: You should pass the second param as string for using `arg`.
```jsx
<input v-model={val} />
```
```jsx
<input v-model:argument={val} />
```
```jsx
<input v-model={[val, ["modifier"]]} />
```
```jsx
<A v-model={[val, "argument", ["modifier"]]} />
```
Will compile to:
```js
h(A, {
argument: val,
argumentModifiers: {
modifier: true,
},
"onUpdate:argument": ($event) => (val = $event),
});
```
#### v-models (Not recommended since v1.1.0)
> Note: You should pass a Two-dimensional Arrays to v-models.
```jsx
<A v-models={[[foo], [bar, "bar"]]} />
```
```jsx
<A
v-models={[
[foo, "foo"],
[bar, "bar"],
]}
/>
```
```jsx
<A
v-models={[
[foo, ["modifier"]],
[bar, "bar", ["modifier"]],
]}
/>
```
Will compile to:
```js
h(A, {
modelValue: foo,
modelModifiers: {
modifier: true,
},
"onUpdate:modelValue": ($event) => (foo = $event),
bar: bar,
barModifiers: {
modifier: true,
},
"onUpdate:bar": ($event) => (bar = $event),
});
```
#### custom directive
Recommended when using string arguments
```jsx
const App = {
directives: { custom: customDirective },
setup() {
return () => <a v-custom:arg={val} />;
},
};
```
```jsx
const App = {
directives: { custom: customDirective },
setup() {
return () => <a v-custom={[val, "arg", ["a", "b"]]} />;
},
};
```
### Slot
> Note: In `jsx`, _`v-slot`_ should be replace with **`v-slots`**
```jsx
const A = (props, { slots }) => (
<>
<h1>{ slots.default ? slots.default() : 'foo' }</h1>
<h2>{ slots.bar?.() }</h2>
</>
);
const App = {
setup() {
const slots = {
bar: () => <span>B</span>,
};
return () => (
<A v-slots={slots}>
<div>A</div>
</A>
);
},
};
// or
const App = {
setup() {
const slots = {
default: () => <div>A</div>,
bar: () => <span>B</span>,
};
return () => <A v-slots={slots} />;
},
};
// or you can use object slots when `enableObjectSlots` is not false.
const App = {
setup() {
return () => (
<>
<A>
{{
default: () => <div>A</div>,
bar: () => <span>B</span>,
}}
</A>
<B>{() => "foo"}</B>
</>
);
},
};
```
### In TypeScript
`tsconfig.json`:
```json
{
"compilerOptions": {
"jsx": "preserve"
}
}
```
## Who is using
<table>
<tbody>
<tr>
<td align="center">
<a target="_blank" href="https://www.antdv.com/">
<img
width="32"
src="https://qn.antdv.com/logo.png"
/>
<br>
<strong>Ant Design Vue</strong>
</a>
</td>
<td align="center">
<a target="_blank" href="https://youzan.github.io/vant/#/zh-CN/">
<img
width="32"
style="vertical-align: -0.32em; margin-right: 8px;"
src="https://img.yzcdn.cn/vant/logo.png"
/>
<br>
<strong>Vant</strong>
</a>
</td>
<td align="center">
<a target="_blank" href="https://github.com/element-plus/element-plus">
<img
height="32"
style="vertical-align: -0.32em; margin-right: 8px;"
src="https://user-images.githubusercontent.com/10731096/91267529-259f3680-e7a6-11ea-9a60-3286f750de01.png"
/>
<br>
<strong>Element Plus</strong>
</a>
</td>
<td align="center">
<a target="_blank" href="https://github.com/leezng/vue-json-pretty">
<img
height="32"
style="vertical-align: -0.32em; margin-right: 8px;"
src="https://raw.githubusercontent.com/leezng/vue-json-pretty/master/static/logo.svg"
/>
<br>
<strong>Vue Json Pretty</strong>
</a>
</td>
</tr>
</tbody>
</table>
## Compatibility
This repo is only compatible with:
- **Babel 7+**
- **Vue 3+**

22
node_modules/@vue/babel-plugin-jsx/dist/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1,22 @@
import * as t from '@babel/types';
import * as BabelCore from '@babel/core';
import { NodePath } from '@babel/traverse';
import type { VueJSXPluginOptions, State } from './interface';
export { VueJSXPluginOptions };
declare const _default: ({ types }: typeof BabelCore) => {
name: string;
inherits: any;
visitor: {
Program: {
enter(path: NodePath<t.Program>, state: State): void;
exit(path: NodePath<t.Program>): void;
};
JSXFragment: {
enter(path: BabelCore.NodePath<t.JSXElement>, state: State): void;
};
JSXElement: {
exit(path: BabelCore.NodePath<t.JSXElement>, state: State): void;
};
};
};
export default _default;

190
node_modules/@vue/babel-plugin-jsx/dist/index.js generated vendored Normal file
View File

@@ -0,0 +1,190 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const t = __importStar(require("@babel/types"));
const template_1 = __importDefault(require("@babel/template"));
const plugin_syntax_jsx_1 = __importDefault(require("@babel/plugin-syntax-jsx"));
const helper_module_imports_1 = require("@babel/helper-module-imports");
const transform_vue_jsx_1 = __importDefault(require("./transform-vue-jsx"));
const sugar_fragment_1 = __importDefault(require("./sugar-fragment"));
const hasJSX = (parentPath) => {
let fileHasJSX = false;
parentPath.traverse({
JSXElement(path) {
// skip ts error
fileHasJSX = true;
path.stop();
},
JSXFragment(path) {
fileHasJSX = true;
path.stop();
},
});
return fileHasJSX;
};
const JSX_ANNOTATION_REGEX = /\*?\s*@jsx\s+([^\s]+)/;
exports.default = ({ types }) => ({
name: 'babel-plugin-jsx',
inherits: plugin_syntax_jsx_1.default,
visitor: Object.assign(Object.assign(Object.assign({}, transform_vue_jsx_1.default), sugar_fragment_1.default), { Program: {
enter(path, state) {
if (hasJSX(path)) {
const importNames = [
'createVNode',
'Fragment',
'resolveComponent',
'withDirectives',
'vShow',
'vModelSelect',
'vModelText',
'vModelCheckbox',
'vModelRadio',
'vModelText',
'vModelDynamic',
'resolveDirective',
'mergeProps',
'createTextVNode',
'isVNode',
];
if ((0, helper_module_imports_1.isModule)(path)) {
// import { createVNode } from "vue";
const importMap = {};
importNames.forEach((name) => {
state.set(name, () => {
if (importMap[name]) {
return types.cloneNode(importMap[name]);
}
const identifier = (0, helper_module_imports_1.addNamed)(path, name, 'vue', {
ensureLiveReference: true,
});
importMap[name] = identifier;
return identifier;
});
});
const { enableObjectSlots = true } = state.opts;
if (enableObjectSlots) {
state.set('@vue/babel-plugin-jsx/runtimeIsSlot', () => {
if (importMap.runtimeIsSlot) {
return importMap.runtimeIsSlot;
}
const { name: isVNodeName } = state.get('isVNode')();
const isSlot = path.scope.generateUidIdentifier('isSlot');
const ast = template_1.default.ast `
function ${isSlot.name}(s) {
return typeof s === 'function' || (Object.prototype.toString.call(s) === '[object Object]' && !${isVNodeName}(s));
}
`;
const lastImport = path.get('body')
.filter((p) => p.isImportDeclaration())
.pop();
if (lastImport) {
lastImport.insertAfter(ast);
}
importMap.runtimeIsSlot = isSlot;
return isSlot;
});
}
}
else {
// var _vue = require('vue');
let sourceName;
importNames.forEach((name) => {
state.set(name, () => {
if (!sourceName) {
sourceName = (0, helper_module_imports_1.addNamespace)(path, 'vue', {
ensureLiveReference: true,
});
}
return t.memberExpression(sourceName, t.identifier(name));
});
});
const helpers = {};
const { enableObjectSlots = true } = state.opts;
if (enableObjectSlots) {
state.set('@vue/babel-plugin-jsx/runtimeIsSlot', () => {
if (helpers.runtimeIsSlot) {
return helpers.runtimeIsSlot;
}
const isSlot = path.scope.generateUidIdentifier('isSlot');
const { object: objectName } = state.get('isVNode')();
const ast = template_1.default.ast `
function ${isSlot.name}(s) {
return typeof s === 'function' || (Object.prototype.toString.call(s) === '[object Object]' && !${objectName.name}.isVNode(s));
}
`;
const nodePaths = path.get('body');
const lastImport = nodePaths
.filter((p) => p.isVariableDeclaration()
&& p.node.declarations.some((d) => { var _a; return ((_a = d.id) === null || _a === void 0 ? void 0 : _a.name) === sourceName.name; }))
.pop();
if (lastImport) {
lastImport.insertAfter(ast);
}
return isSlot;
});
}
}
const { opts: { pragma = '' }, file, } = state;
if (pragma) {
state.set('createVNode', () => t.identifier(pragma));
}
if (file.ast.comments) {
for (const comment of file.ast.comments) {
const jsxMatches = JSX_ANNOTATION_REGEX.exec(comment.value);
if (jsxMatches) {
state.set('createVNode', () => t.identifier(jsxMatches[1]));
}
}
}
}
},
exit(path) {
const body = path.get('body');
const specifiersMap = new Map();
body
.filter((nodePath) => t.isImportDeclaration(nodePath.node)
&& nodePath.node.source.value === 'vue')
.forEach((nodePath) => {
const { specifiers } = nodePath.node;
let shouldRemove = false;
specifiers.forEach((specifier) => {
if (!specifier.loc
&& t.isImportSpecifier(specifier)
&& t.isIdentifier(specifier.imported)) {
specifiersMap.set(specifier.imported.name, specifier);
shouldRemove = true;
}
});
if (shouldRemove) {
nodePath.remove();
}
});
const specifiers = [...specifiersMap.keys()].map((imported) => specifiersMap.get(imported));
if (specifiers.length) {
path.unshiftContainer('body', t.importDeclaration(specifiers, t.stringLiteral('vue')));
}
},
} }),
});
//# sourceMappingURL=index.js.map

1
node_modules/@vue/babel-plugin-jsx/dist/index.js.map generated vendored Normal file

File diff suppressed because one or more lines are too long

23
node_modules/@vue/babel-plugin-jsx/dist/interface.d.ts generated vendored Normal file
View File

@@ -0,0 +1,23 @@
import * as t from '@babel/types';
import * as BabelCore from '@babel/core';
export declare type Slots = t.Identifier | t.ObjectExpression | null;
export declare type State = {
get: (name: string) => any;
set: (name: string, value: any) => any;
opts: VueJSXPluginOptions;
file: BabelCore.BabelFile;
};
export interface VueJSXPluginOptions {
/** transform `on: { click: xx }` to `onClick: xxx` */
transformOn?: boolean;
/** enable optimization or not. */
optimize?: boolean;
/** merge static and dynamic class / style attributes / onXXX handlers */
mergeProps?: boolean;
/** configuring custom elements */
isCustomElement?: (tag: string) => boolean;
/** enable object slots syntax */
enableObjectSlots?: boolean;
/** Replace the function used when compiling JSX expressions */
pragma?: string;
}

3
node_modules/@vue/babel-plugin-jsx/dist/interface.js generated vendored Normal file
View File

@@ -0,0 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=interface.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"interface.js","sourceRoot":"","sources":["../src/interface.ts"],"names":[],"mappings":""}

View File

@@ -0,0 +1,19 @@
import * as t from '@babel/types';
import { NodePath } from '@babel/traverse';
import type { State } from './interface';
export declare type Tag = t.Identifier | t.MemberExpression | t.StringLiteral | t.CallExpression;
declare const parseDirectives: (params: {
name: string;
path: NodePath<t.JSXAttribute>;
value: t.Expression | null;
state: State;
tag: Tag;
isComponent: boolean;
}) => {
directiveName: string;
modifiers: Set<string>[];
values: (t.Expression | null)[];
args: t.Expression[];
directive: t.Expression[] | undefined;
};
export default parseDirectives;

View File

@@ -0,0 +1,172 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const t = __importStar(require("@babel/types"));
const utils_1 = require("./utils");
/**
* Get JSX element type
*
* @param path Path<JSXOpeningElement>
*/
const getType = (path) => {
const typePath = path
.get('attributes')
.find((attribute) => {
if (!t.isJSXAttribute(attribute)) {
return false;
}
return t.isJSXIdentifier(attribute.get('name'))
&& attribute.get('name').node.name === 'type';
});
return typePath ? typePath.get('value').node : null;
};
const parseModifiers = (value) => (t.isArrayExpression(value)
? value.elements
.map((el) => (t.isStringLiteral(el) ? el.value : ''))
.filter(Boolean)
: []);
const parseDirectives = (params) => {
var _a, _b;
const { path, value, state, tag, isComponent, } = params;
const args = [];
const vals = [];
const modifiersSet = [];
let directiveName;
let directiveArgument;
let directiveModifiers;
if ('namespace' in path.node.name) {
[directiveName, directiveArgument] = params.name.split(':');
directiveName = path.node.name.namespace.name;
directiveArgument = path.node.name.name.name;
directiveModifiers = directiveArgument.split('_').slice(1);
}
else {
const underscoreModifiers = params.name.split('_');
directiveName = underscoreModifiers.shift() || '';
directiveModifiers = underscoreModifiers;
}
directiveName = directiveName
.replace(/^v/, '')
.replace(/^-/, '')
.replace(/^\S/, (s) => s.toLowerCase());
if (directiveArgument) {
args.push(t.stringLiteral(directiveArgument));
}
const isVModels = directiveName === 'models';
const isVModel = directiveName === 'model';
if (isVModel && !t.isJSXExpressionContainer(path.get('value'))) {
throw new Error('You have to use JSX Expression inside your v-model');
}
if (isVModels && !isComponent) {
throw new Error('v-models can only use in custom components');
}
const shouldResolve = !['html', 'text', 'model', 'models'].includes(directiveName)
|| (isVModel && !isComponent);
let modifiers = directiveModifiers;
if (t.isArrayExpression(value)) {
const elementsList = isVModels ? value.elements : [value];
elementsList.forEach((element) => {
if (isVModels && !t.isArrayExpression(element)) {
throw new Error('You should pass a Two-dimensional Arrays to v-models');
}
const { elements } = element;
const [first, second, third] = elements;
if (second && !t.isArrayExpression(second) && !t.isSpreadElement(second)) {
args.push(second);
modifiers = parseModifiers(third);
}
else if (t.isArrayExpression(second)) {
if (!shouldResolve) {
args.push(t.nullLiteral());
}
modifiers = parseModifiers(second);
}
else if (!shouldResolve) {
// work as v-model={[value]} or v-models={[[value]]}
args.push(t.nullLiteral());
}
modifiersSet.push(new Set(modifiers));
vals.push(first);
});
}
else if (isVModel && !shouldResolve) {
// work as v-model={value}
args.push(t.nullLiteral());
modifiersSet.push(new Set(directiveModifiers));
}
else {
modifiersSet.push(new Set(directiveModifiers));
}
return {
directiveName,
modifiers: modifiersSet,
values: vals.length ? vals : [value],
args,
directive: shouldResolve ? [
resolveDirective(path, state, tag, directiveName),
vals[0] || value,
((_a = modifiersSet[0]) === null || _a === void 0 ? void 0 : _a.size)
? args[0] || t.unaryExpression('void', t.numericLiteral(0), true)
: args[0],
!!((_b = modifiersSet[0]) === null || _b === void 0 ? void 0 : _b.size) && t.objectExpression([...modifiersSet[0]].map((modifier) => t.objectProperty(t.identifier(modifier), t.booleanLiteral(true)))),
].filter(Boolean) : undefined,
};
};
const resolveDirective = (path, state, tag, directiveName) => {
var _a;
if (directiveName === 'show') {
return (0, utils_1.createIdentifier)(state, 'vShow');
}
if (directiveName === 'model') {
let modelToUse;
const type = getType(path.parentPath);
switch (tag.value) {
case 'select':
modelToUse = (0, utils_1.createIdentifier)(state, 'vModelSelect');
break;
case 'textarea':
modelToUse = (0, utils_1.createIdentifier)(state, 'vModelText');
break;
default:
if (t.isStringLiteral(type) || !type) {
switch ((_a = type) === null || _a === void 0 ? void 0 : _a.value) {
case 'checkbox':
modelToUse = (0, utils_1.createIdentifier)(state, 'vModelCheckbox');
break;
case 'radio':
modelToUse = (0, utils_1.createIdentifier)(state, 'vModelRadio');
break;
default:
modelToUse = (0, utils_1.createIdentifier)(state, 'vModelText');
}
}
else {
modelToUse = (0, utils_1.createIdentifier)(state, 'vModelDynamic');
}
}
return modelToUse;
}
return t.callExpression((0, utils_1.createIdentifier)(state, 'resolveDirective'), [
t.stringLiteral(directiveName),
]);
};
exports.default = parseDirectives;
//# sourceMappingURL=parseDirectives.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,18 @@
export declare const enum PatchFlags {
TEXT = 1,
CLASS = 2,
STYLE = 4,
PROPS = 8,
FULL_PROPS = 16,
HYDRATE_EVENTS = 32,
STABLE_FRAGMENT = 64,
KEYED_FRAGMENT = 128,
UNKEYED_FRAGMENT = 256,
NEED_PATCH = 512,
DYNAMIC_SLOTS = 1024,
HOISTED = -1,
BAIL = -2
}
export declare const PatchFlagNames: {
[x: number]: string;
};

20
node_modules/@vue/babel-plugin-jsx/dist/patchFlags.js generated vendored Normal file
View File

@@ -0,0 +1,20 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.PatchFlagNames = void 0;
// dev only flag -> name mapping
exports.PatchFlagNames = {
[1 /* TEXT */]: 'TEXT',
[2 /* CLASS */]: 'CLASS',
[4 /* STYLE */]: 'STYLE',
[8 /* PROPS */]: 'PROPS',
[16 /* FULL_PROPS */]: 'FULL_PROPS',
[32 /* HYDRATE_EVENTS */]: 'HYDRATE_EVENTS',
[64 /* STABLE_FRAGMENT */]: 'STABLE_FRAGMENT',
[128 /* KEYED_FRAGMENT */]: 'KEYED_FRAGMENT',
[256 /* UNKEYED_FRAGMENT */]: 'UNKEYED_FRAGMENT',
[1024 /* DYNAMIC_SLOTS */]: 'DYNAMIC_SLOTS',
[512 /* NEED_PATCH */]: 'NEED_PATCH',
[-1 /* HOISTED */]: 'HOISTED',
[-2 /* BAIL */]: 'BAIL',
};
//# sourceMappingURL=patchFlags.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"patchFlags.js","sourceRoot":"","sources":["../src/patchFlags.ts"],"names":[],"mappings":";;;AAkBA,gCAAgC;AACnB,QAAA,cAAc,GAAG;IAC5B,cAAiB,EAAE,MAAM;IACzB,eAAkB,EAAE,OAAO;IAC3B,eAAkB,EAAE,OAAO;IAC3B,eAAkB,EAAE,OAAO;IAC3B,qBAAuB,EAAE,YAAY;IACrC,yBAA2B,EAAE,gBAAgB;IAC7C,0BAA4B,EAAE,iBAAiB;IAC/C,0BAA2B,EAAE,gBAAgB;IAC7C,4BAA6B,EAAE,kBAAkB;IACjD,0BAA0B,EAAE,eAAe;IAC3C,sBAAuB,EAAE,YAAY;IACrC,kBAAoB,EAAE,SAAS;IAC/B,eAAiB,EAAE,MAAM;CAC1B,CAAC"}

22
node_modules/@vue/babel-plugin-jsx/dist/slotFlags.d.ts generated vendored Normal file
View File

@@ -0,0 +1,22 @@
declare const enum SlotFlags {
/**
* Stable slots that only reference slot props or context state. The slot
* can fully capture its own dependencies so when passed down the parent won't
* need to force the child to update.
*/
STABLE = 1,
/**
* Slots that reference scope variables (v-for or an outer slot prop), or
* has conditional structure (v-if, v-for). The parent will need to force
* the child to update because the slot does not fully capture its dependencies.
*/
DYNAMIC = 2,
/**
* `<slot/>` being forwarded into a child component. Whether the parent needs
* to update the child is dependent on what kind of slots the parent itself
* received. This has to be refined at runtime, when the child's vnode
* is being created (in `normalizeChildren`)
*/
FORWARDED = 3
}
export default SlotFlags;

3
node_modules/@vue/babel-plugin-jsx/dist/slotFlags.js generated vendored Normal file
View File

@@ -0,0 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=slotFlags.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"slotFlags.js","sourceRoot":"","sources":["../src/slotFlags.ts"],"names":[],"mappings":""}

View File

@@ -0,0 +1,9 @@
import * as t from '@babel/types';
import { NodePath } from '@babel/traverse';
import type { State } from './interface';
declare const _default: {
JSXFragment: {
enter(path: NodePath<t.JSXElement>, state: State): void;
};
};
export default _default;

View File

@@ -0,0 +1,38 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const t = __importStar(require("@babel/types"));
const utils_1 = require("./utils");
const transformFragment = (path, Fragment) => {
const children = path.get('children') || [];
return t.jsxElement(t.jsxOpeningElement(Fragment, []), t.jsxClosingElement(Fragment), children.map(({ node }) => node), false);
};
exports.default = ({
JSXFragment: {
enter(path, state) {
const fragmentCallee = (0, utils_1.createIdentifier)(state, utils_1.FRAGMENT);
path.replaceWith(transformFragment(path, t.isIdentifier(fragmentCallee)
? t.jsxIdentifier(fragmentCallee.name)
: t.jsxMemberExpression(t.jsxIdentifier(fragmentCallee.object.name), t.jsxIdentifier(fragmentCallee.property.name))));
},
},
});
//# sourceMappingURL=sugar-fragment.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"sugar-fragment.js","sourceRoot":"","sources":["../src/sugar-fragment.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,gDAAkC;AAGlC,mCAAqD;AAErD,MAAM,iBAAiB,GAAG,CACxB,IAA4B,EAC5B,QAAiD,EACjD,EAAE;IACF,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC;IAC5C,OAAO,CAAC,CAAC,UAAU,CACjB,CAAC,CAAC,iBAAiB,CAAC,QAAQ,EAAE,EAAE,CAAC,EACjC,CAAC,CAAC,iBAAiB,CAAC,QAAQ,CAAC,EAC7B,QAAQ,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,IAAI,CAAC,EAChC,KAAK,CACN,CAAC;AACJ,CAAC,CAAC;AAEF,kBAAe,CAAC;IACd,WAAW,EAAE;QACX,KAAK,CAAC,IAA4B,EAAE,KAAY;YAC9C,MAAM,cAAc,GAAG,IAAA,wBAAgB,EAAC,KAAK,EAAE,gBAAQ,CAAC,CAAC;YACzD,IAAI,CAAC,WAAW,CAAC,iBAAiB,CAChC,IAAI,EACJ,CAAC,CAAC,YAAY,CAAC,cAAc,CAAC;gBAC5B,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,cAAc,CAAC,IAAI,CAAC;gBACtC,CAAC,CAAC,CAAC,CAAC,mBAAmB,CACrB,CAAC,CAAC,aAAa,CAAE,cAAc,CAAC,MAAuB,CAAC,IAAI,CAAC,EAC7D,CAAC,CAAC,aAAa,CAAE,cAAc,CAAC,QAAyB,CAAC,IAAI,CAAC,CAChE,CACJ,CAAC,CAAC;QACL,CAAC;KACF;CACF,CAAC,CAAC"}

View File

@@ -0,0 +1,9 @@
import * as t from '@babel/types';
import { NodePath } from '@babel/traverse';
import type { State } from './interface';
declare const _default: {
JSXElement: {
exit(path: NodePath<t.JSXElement>, state: State): void;
};
};
export default _default;

View File

@@ -0,0 +1,371 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const t = __importStar(require("@babel/types"));
const helper_module_imports_1 = require("@babel/helper-module-imports");
const utils_1 = require("./utils");
const parseDirectives_1 = __importDefault(require("./parseDirectives"));
const xlinkRE = /^xlink([A-Z])/;
const getJSXAttributeValue = (path, state) => {
const valuePath = path.get('value');
if (valuePath.isJSXElement()) {
return transformJSXElement(valuePath, state);
}
if (valuePath.isStringLiteral()) {
return valuePath.node;
}
if (valuePath.isJSXExpressionContainer()) {
return (0, utils_1.transformJSXExpressionContainer)(valuePath);
}
return null;
};
const buildProps = (path, state) => {
const tag = (0, utils_1.getTag)(path, state);
const isComponent = (0, utils_1.checkIsComponent)(path.get('openingElement'), state);
const props = path.get('openingElement').get('attributes');
const directives = [];
const dynamicPropNames = new Set();
let slots = null;
let patchFlag = 0;
if (props.length === 0) {
return {
tag,
isComponent,
slots,
props: t.nullLiteral(),
directives,
patchFlag,
dynamicPropNames,
};
}
let properties = [];
// patchFlag analysis
let hasRef = false;
let hasClassBinding = false;
let hasStyleBinding = false;
let hasHydrationEventBinding = false;
let hasDynamicKeys = false;
const mergeArgs = [];
const { mergeProps = true } = state.opts;
props
.forEach((prop) => {
if (prop.isJSXAttribute()) {
let name = (0, utils_1.getJSXAttributeName)(prop);
const attributeValue = getJSXAttributeValue(prop, state);
if (!(0, utils_1.isConstant)(attributeValue) || name === 'ref') {
if (!isComponent
&& (0, utils_1.isOn)(name)
// omit the flag for click handlers becaues hydration gives click
// dedicated fast path.
&& name.toLowerCase() !== 'onclick'
// omit v-model handlers
&& name !== 'onUpdate:modelValue') {
hasHydrationEventBinding = true;
}
if (name === 'ref') {
hasRef = true;
}
else if (name === 'class' && !isComponent) {
hasClassBinding = true;
}
else if (name === 'style' && !isComponent) {
hasStyleBinding = true;
}
else if (name !== 'key'
&& !(0, utils_1.isDirective)(name)
&& name !== 'on') {
dynamicPropNames.add(name);
}
}
if (state.opts.transformOn && (name === 'on' || name === 'nativeOn')) {
if (!state.get('transformOn')) {
state.set('transformOn', (0, helper_module_imports_1.addDefault)(path, '@vue/babel-helper-vue-transform-on', { nameHint: '_transformOn' }));
}
mergeArgs.push(t.callExpression(state.get('transformOn'), [attributeValue || t.booleanLiteral(true)]));
return;
}
if ((0, utils_1.isDirective)(name)) {
const { directive, modifiers, values, args, directiveName, } = (0, parseDirectives_1.default)({
tag,
isComponent,
name,
path: prop,
state,
value: attributeValue,
});
if (directiveName === 'slots') {
slots = attributeValue;
return;
}
if (directive) {
directives.push(t.arrayExpression(directive));
}
else if (directiveName === 'html') {
properties.push(t.objectProperty(t.stringLiteral('innerHTML'), values[0]));
dynamicPropNames.add('innerHTML');
}
else if (directiveName === 'text') {
properties.push(t.objectProperty(t.stringLiteral('textContent'), values[0]));
dynamicPropNames.add('textContent');
}
if (['models', 'model'].includes(directiveName)) {
values.forEach((value, index) => {
var _a, _b, _c, _d;
const propName = args[index];
// v-model target with variable
const isDynamic = propName && !t.isStringLiteral(propName) && !t.isNullLiteral(propName);
// must be v-model or v-models and is a component
if (!directive) {
properties.push(t.objectProperty(t.isNullLiteral(propName)
? t.stringLiteral('modelValue') : propName, value, isDynamic));
if (!isDynamic) {
dynamicPropNames.add(((_a = propName) === null || _a === void 0 ? void 0 : _a.value) || 'modelValue');
}
if ((_b = modifiers[index]) === null || _b === void 0 ? void 0 : _b.size) {
properties.push(t.objectProperty(isDynamic
? t.binaryExpression('+', propName, t.stringLiteral('Modifiers'))
: t.stringLiteral(`${((_c = propName) === null || _c === void 0 ? void 0 : _c.value) || 'model'}Modifiers`), t.objectExpression([...modifiers[index]].map((modifier) => t.objectProperty(t.stringLiteral(modifier), t.booleanLiteral(true)))), isDynamic));
}
}
const updateName = isDynamic
? t.binaryExpression('+', t.stringLiteral('onUpdate'), propName)
: t.stringLiteral(`onUpdate:${((_d = propName) === null || _d === void 0 ? void 0 : _d.value) || 'modelValue'}`);
properties.push(t.objectProperty(updateName, t.arrowFunctionExpression([t.identifier('$event')], t.assignmentExpression('=', value, t.identifier('$event'))), isDynamic));
if (!isDynamic) {
dynamicPropNames.add(updateName.value);
}
else {
hasDynamicKeys = true;
}
});
}
}
else {
if (name.match(xlinkRE)) {
name = name.replace(xlinkRE, (_, firstCharacter) => `xlink:${firstCharacter.toLowerCase()}`);
}
properties.push(t.objectProperty(t.stringLiteral(name), attributeValue || t.booleanLiteral(true)));
}
}
else {
if (properties.length && mergeProps) {
mergeArgs.push(t.objectExpression((0, utils_1.dedupeProperties)(properties, mergeProps)));
properties = [];
}
// JSXSpreadAttribute
hasDynamicKeys = true;
(0, utils_1.transformJSXSpreadAttribute)(path, prop, mergeProps, mergeProps ? mergeArgs : properties);
}
});
// patchFlag analysis
if (hasDynamicKeys) {
patchFlag |= 16 /* FULL_PROPS */;
}
else {
if (hasClassBinding) {
patchFlag |= 2 /* CLASS */;
}
if (hasStyleBinding) {
patchFlag |= 4 /* STYLE */;
}
if (dynamicPropNames.size) {
patchFlag |= 8 /* PROPS */;
}
if (hasHydrationEventBinding) {
patchFlag |= 32 /* HYDRATE_EVENTS */;
}
}
if ((patchFlag === 0 || patchFlag === 32 /* HYDRATE_EVENTS */)
&& (hasRef || directives.length > 0)) {
patchFlag |= 512 /* NEED_PATCH */;
}
let propsExpression = t.nullLiteral();
if (mergeArgs.length) {
if (properties.length) {
mergeArgs.push(t.objectExpression((0, utils_1.dedupeProperties)(properties, mergeProps)));
}
if (mergeArgs.length > 1) {
propsExpression = t.callExpression((0, utils_1.createIdentifier)(state, 'mergeProps'), mergeArgs);
}
else {
// single no need for a mergeProps call
propsExpression = mergeArgs[0];
}
}
else if (properties.length) {
// single no need for spread
if (properties.length === 1 && t.isSpreadElement(properties[0])) {
propsExpression = properties[0].argument;
}
else {
propsExpression = t.objectExpression((0, utils_1.dedupeProperties)(properties, mergeProps));
}
}
return {
tag,
props: propsExpression,
isComponent,
slots,
directives,
patchFlag,
dynamicPropNames,
};
};
/**
* Get children from Array of JSX children
* @param paths Array<JSXText | JSXExpressionContainer | JSXElement | JSXFragment>
* @returns Array<Expression | SpreadElement>
*/
const getChildren = (paths, state) => paths
.map((path) => {
if (path.isJSXText()) {
const transformedText = (0, utils_1.transformJSXText)(path);
if (transformedText) {
return t.callExpression((0, utils_1.createIdentifier)(state, 'createTextVNode'), [transformedText]);
}
return transformedText;
}
if (path.isJSXExpressionContainer()) {
const expression = (0, utils_1.transformJSXExpressionContainer)(path);
if (t.isIdentifier(expression)) {
const { name } = expression;
const { referencePaths = [] } = path.scope.getBinding(name) || {};
referencePaths.forEach((referencePath) => {
(0, utils_1.walksScope)(referencePath, name, 2 /* DYNAMIC */);
});
}
return expression;
}
if (t.isJSXSpreadChild(path)) {
return (0, utils_1.transformJSXSpreadChild)(path);
}
if (path.isCallExpression()) {
return path.node;
}
if (path.isJSXElement()) {
return transformJSXElement(path, state);
}
throw new Error(`getChildren: ${path.type} is not supported`);
}).filter(((value) => (value !== undefined
&& value !== null
&& !t.isJSXEmptyExpression(value))));
const transformJSXElement = (path, state) => {
const children = getChildren(path.get('children'), state);
const { tag, props, isComponent, directives, patchFlag, dynamicPropNames, slots, } = buildProps(path, state);
const { optimize = false } = state.opts;
const slotFlag = path.getData('slotFlag') || 1 /* STABLE */;
let VNodeChild;
if (children.length > 1 || slots) {
/*
<A v-slots={slots}>{a}{b}</A>
---> {{ default: () => [a, b], ...slots }}
---> {[a, b]}
*/
VNodeChild = isComponent
? children.length
? t.objectExpression([
!!children.length && t.objectProperty(t.identifier('default'), t.arrowFunctionExpression([], t.arrayExpression((0, utils_1.buildIIFE)(path, children)))),
...(slots ? (t.isObjectExpression(slots)
? slots.properties
: [t.spreadElement(slots)]) : []),
optimize && t.objectProperty(t.identifier('_'), t.numericLiteral(slotFlag)),
].filter(Boolean))
: slots
: t.arrayExpression(children);
}
else if (children.length === 1) {
/*
<A>{a}</A> or <A>{() => a}</A>
*/
const { enableObjectSlots = true } = state.opts;
const child = children[0];
const objectExpression = t.objectExpression([
t.objectProperty(t.identifier('default'), t.arrowFunctionExpression([], t.arrayExpression((0, utils_1.buildIIFE)(path, [child])))),
optimize && t.objectProperty(t.identifier('_'), t.numericLiteral(slotFlag)),
].filter(Boolean));
if (t.isIdentifier(child) && isComponent) {
VNodeChild = enableObjectSlots ? t.conditionalExpression(t.callExpression(state.get('@vue/babel-plugin-jsx/runtimeIsSlot')(), [child]), child, objectExpression) : objectExpression;
}
else if (t.isCallExpression(child) && child.loc && isComponent) { // the element was generated and doesn't have location information
if (enableObjectSlots) {
const { scope } = path;
const slotId = scope.generateUidIdentifier('slot');
if (scope) {
scope.push({
id: slotId,
kind: 'let',
});
}
const alternate = t.objectExpression([
t.objectProperty(t.identifier('default'), t.arrowFunctionExpression([], t.arrayExpression((0, utils_1.buildIIFE)(path, [slotId])))), optimize && t.objectProperty(t.identifier('_'), t.numericLiteral(slotFlag)),
].filter(Boolean));
const assignment = t.assignmentExpression('=', slotId, child);
const condition = t.callExpression(state.get('@vue/babel-plugin-jsx/runtimeIsSlot')(), [assignment]);
VNodeChild = t.conditionalExpression(condition, slotId, alternate);
}
else {
VNodeChild = objectExpression;
}
}
else if (t.isFunctionExpression(child) || t.isArrowFunctionExpression(child)) {
VNodeChild = t.objectExpression([
t.objectProperty(t.identifier('default'), child),
]);
}
else if (t.isObjectExpression(child)) {
VNodeChild = t.objectExpression([
...child.properties,
optimize && t.objectProperty(t.identifier('_'), t.numericLiteral(slotFlag)),
].filter(Boolean));
}
else {
VNodeChild = isComponent ? t.objectExpression([
t.objectProperty(t.identifier('default'), t.arrowFunctionExpression([], t.arrayExpression([child]))),
]) : t.arrayExpression([child]);
}
}
const createVNode = t.callExpression((0, utils_1.createIdentifier)(state, 'createVNode'), [
tag,
props,
VNodeChild || t.nullLiteral(),
!!patchFlag && optimize && t.numericLiteral(patchFlag),
!!dynamicPropNames.size && optimize
&& t.arrayExpression([...dynamicPropNames.keys()].map((name) => t.stringLiteral(name))),
].filter(Boolean));
if (!directives.length) {
return createVNode;
}
return t.callExpression((0, utils_1.createIdentifier)(state, 'withDirectives'), [
createVNode,
t.arrayExpression(directives),
]);
};
exports.default = ({
JSXElement: {
exit(path, state) {
path.replaceWith(transformJSXElement(path, state));
},
},
});
//# sourceMappingURL=transform-vue-jsx.js.map

File diff suppressed because one or more lines are too long

77
node_modules/@vue/babel-plugin-jsx/dist/utils.d.ts generated vendored Normal file
View File

@@ -0,0 +1,77 @@
import * as t from '@babel/types';
import { NodePath } from '@babel/traverse';
import type { State } from './interface';
import SlotFlags from './slotFlags';
export declare const JSX_HELPER_KEY = "JSX_HELPER_KEY";
export declare const FRAGMENT = "Fragment";
export declare const KEEP_ALIVE = "KeepAlive";
/**
* create Identifier
* @param path NodePath
* @param state
* @param name string
* @returns MemberExpression
*/
export declare const createIdentifier: (state: State, name: string) => t.Identifier | t.MemberExpression;
/**
* Checks if string is describing a directive
* @param src string
*/
export declare const isDirective: (src: string) => boolean;
/**
* Should transformed to slots
* @param tag string
* @returns boolean
*/
export declare const shouldTransformedToSlots: (tag: string) => boolean;
/**
* Check if a Node is a component
*
* @param t
* @param path JSXOpeningElement
* @returns boolean
*/
export declare const checkIsComponent: (path: NodePath<t.JSXOpeningElement>, state: State) => boolean;
/**
* Transform JSXMemberExpression to MemberExpression
* @param path JSXMemberExpression
* @returns MemberExpression
*/
export declare const transformJSXMemberExpression: (path: NodePath<t.JSXMemberExpression>) => t.MemberExpression;
/**
* Get tag (first attribute for h) from JSXOpeningElement
* @param path JSXElement
* @param state State
* @returns Identifier | StringLiteral | MemberExpression | CallExpression
*/
export declare const getTag: (path: NodePath<t.JSXElement>, state: State) => t.Identifier | t.CallExpression | t.StringLiteral | t.MemberExpression;
export declare const getJSXAttributeName: (path: NodePath<t.JSXAttribute>) => string;
/**
* Transform JSXText to StringLiteral
* @param path JSXText
* @returns StringLiteral | null
*/
export declare const transformJSXText: (path: NodePath<t.JSXText>) => t.StringLiteral | null;
/**
* Transform JSXExpressionContainer to Expression
* @param path JSXExpressionContainer
* @returns Expression
*/
export declare const transformJSXExpressionContainer: (path: NodePath<t.JSXExpressionContainer>) => (t.Expression);
/**
* Transform JSXSpreadChild
* @param path JSXSpreadChild
* @returns SpreadElement
*/
export declare const transformJSXSpreadChild: (path: NodePath<t.JSXSpreadChild>) => t.SpreadElement;
export declare const walksScope: (path: NodePath, name: string, slotFlag: SlotFlags) => void;
export declare const buildIIFE: (path: NodePath<t.JSXElement>, children: t.Expression[]) => t.Expression[];
export declare const isOn: (key: string) => boolean;
export declare const dedupeProperties: (properties?: t.ObjectProperty[], mergeProps?: boolean | undefined) => t.ObjectProperty[];
/**
* Check if an attribute value is constant
* @param node
* @returns boolean
*/
export declare const isConstant: (node: t.Expression | t.Identifier | t.Literal | t.SpreadElement | null) => boolean;
export declare const transformJSXSpreadAttribute: (nodePath: NodePath, path: NodePath<t.JSXSpreadAttribute>, mergeProps: boolean, args: (t.ObjectProperty | t.Expression | t.SpreadElement)[]) => void;

290
node_modules/@vue/babel-plugin-jsx/dist/utils.js generated vendored Normal file
View File

@@ -0,0 +1,290 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.transformJSXSpreadAttribute = exports.isConstant = exports.dedupeProperties = exports.isOn = exports.buildIIFE = exports.walksScope = exports.transformJSXSpreadChild = exports.transformJSXExpressionContainer = exports.transformJSXText = exports.getJSXAttributeName = exports.getTag = exports.transformJSXMemberExpression = exports.checkIsComponent = exports.shouldTransformedToSlots = exports.isDirective = exports.createIdentifier = exports.KEEP_ALIVE = exports.FRAGMENT = exports.JSX_HELPER_KEY = void 0;
const t = __importStar(require("@babel/types"));
const html_tags_1 = __importDefault(require("html-tags"));
const svg_tags_1 = __importDefault(require("svg-tags"));
exports.JSX_HELPER_KEY = 'JSX_HELPER_KEY';
exports.FRAGMENT = 'Fragment';
exports.KEEP_ALIVE = 'KeepAlive';
/**
* create Identifier
* @param path NodePath
* @param state
* @param name string
* @returns MemberExpression
*/
const createIdentifier = (state, name) => state.get(name)();
exports.createIdentifier = createIdentifier;
/**
* Checks if string is describing a directive
* @param src string
*/
const isDirective = (src) => src.startsWith('v-')
|| (src.startsWith('v') && src.length >= 2 && src[1] >= 'A' && src[1] <= 'Z');
exports.isDirective = isDirective;
/**
* Should transformed to slots
* @param tag string
* @returns boolean
*/
// if _Fragment is already imported, it will end with number
const shouldTransformedToSlots = (tag) => !(tag.match(RegExp(`^_?${exports.FRAGMENT}\\d*$`)) || tag === exports.KEEP_ALIVE);
exports.shouldTransformedToSlots = shouldTransformedToSlots;
/**
* Check if a Node is a component
*
* @param t
* @param path JSXOpeningElement
* @returns boolean
*/
const checkIsComponent = (path, state) => {
var _a, _b;
const namePath = path.get('name');
if (namePath.isJSXMemberExpression()) {
return (0, exports.shouldTransformedToSlots)(namePath.node.property.name); // For withCtx
}
const tag = namePath.node.name;
return !((_b = (_a = state.opts).isCustomElement) === null || _b === void 0 ? void 0 : _b.call(_a, tag)) && (0, exports.shouldTransformedToSlots)(tag) && !html_tags_1.default.includes(tag) && !svg_tags_1.default.includes(tag);
};
exports.checkIsComponent = checkIsComponent;
/**
* Transform JSXMemberExpression to MemberExpression
* @param path JSXMemberExpression
* @returns MemberExpression
*/
const transformJSXMemberExpression = (path) => {
const objectPath = path.node.object;
const propertyPath = path.node.property;
const transformedObject = t.isJSXMemberExpression(objectPath)
? (0, exports.transformJSXMemberExpression)(path.get('object'))
: t.isJSXIdentifier(objectPath)
? t.identifier(objectPath.name)
: t.nullLiteral();
const transformedProperty = t.identifier(propertyPath.name);
return t.memberExpression(transformedObject, transformedProperty);
};
exports.transformJSXMemberExpression = transformJSXMemberExpression;
/**
* Get tag (first attribute for h) from JSXOpeningElement
* @param path JSXElement
* @param state State
* @returns Identifier | StringLiteral | MemberExpression | CallExpression
*/
const getTag = (path, state) => {
var _a, _b;
const namePath = path.get('openingElement').get('name');
if (namePath.isJSXIdentifier()) {
const { name } = namePath.node;
if (!html_tags_1.default.includes(name) && !svg_tags_1.default.includes(name)) {
return (name === exports.FRAGMENT
? (0, exports.createIdentifier)(state, exports.FRAGMENT)
: path.scope.hasBinding(name)
? t.identifier(name)
: ((_b = (_a = state.opts).isCustomElement) === null || _b === void 0 ? void 0 : _b.call(_a, name))
? t.stringLiteral(name)
: t.callExpression((0, exports.createIdentifier)(state, 'resolveComponent'), [t.stringLiteral(name)]));
}
return t.stringLiteral(name);
}
if (namePath.isJSXMemberExpression()) {
return (0, exports.transformJSXMemberExpression)(namePath);
}
throw new Error(`getTag: ${namePath.type} is not supported`);
};
exports.getTag = getTag;
const getJSXAttributeName = (path) => {
const nameNode = path.node.name;
if (t.isJSXIdentifier(nameNode)) {
return nameNode.name;
}
return `${nameNode.namespace.name}:${nameNode.name.name}`;
};
exports.getJSXAttributeName = getJSXAttributeName;
/**
* Transform JSXText to StringLiteral
* @param path JSXText
* @returns StringLiteral | null
*/
const transformJSXText = (path) => {
const { node } = path;
const lines = node.value.split(/\r\n|\n|\r/);
let lastNonEmptyLine = 0;
for (let i = 0; i < lines.length; i++) {
if (lines[i].match(/[^ \t]/)) {
lastNonEmptyLine = i;
}
}
let str = '';
for (let i = 0; i < lines.length; i++) {
const line = lines[i];
const isFirstLine = i === 0;
const isLastLine = i === lines.length - 1;
const isLastNonEmptyLine = i === lastNonEmptyLine;
// replace rendered whitespace tabs with spaces
let trimmedLine = line.replace(/\t/g, ' ');
// trim whitespace touching a newline
if (!isFirstLine) {
trimmedLine = trimmedLine.replace(/^[ ]+/, '');
}
// trim whitespace touching an endline
if (!isLastLine) {
trimmedLine = trimmedLine.replace(/[ ]+$/, '');
}
if (trimmedLine) {
if (!isLastNonEmptyLine) {
trimmedLine += ' ';
}
str += trimmedLine;
}
}
return str !== '' ? t.stringLiteral(str) : null;
};
exports.transformJSXText = transformJSXText;
/**
* Transform JSXExpressionContainer to Expression
* @param path JSXExpressionContainer
* @returns Expression
*/
const transformJSXExpressionContainer = (path) => path.get('expression').node;
exports.transformJSXExpressionContainer = transformJSXExpressionContainer;
/**
* Transform JSXSpreadChild
* @param path JSXSpreadChild
* @returns SpreadElement
*/
const transformJSXSpreadChild = (path) => t.spreadElement(path.get('expression').node);
exports.transformJSXSpreadChild = transformJSXSpreadChild;
const walksScope = (path, name, slotFlag) => {
if (path.scope.hasBinding(name) && path.parentPath) {
if (t.isJSXElement(path.parentPath.node)) {
path.parentPath.setData('slotFlag', slotFlag);
}
(0, exports.walksScope)(path.parentPath, name, slotFlag);
}
};
exports.walksScope = walksScope;
const buildIIFE = (path, children) => {
const { parentPath } = path;
if (t.isAssignmentExpression(parentPath)) {
const { left } = parentPath.node;
if (t.isIdentifier(left)) {
return children.map((child) => {
if (t.isIdentifier(child) && child.name === left.name) {
const insertName = path.scope.generateUidIdentifier(child.name);
parentPath.insertBefore(t.variableDeclaration('const', [
t.variableDeclarator(insertName, t.callExpression(t.functionExpression(null, [], t.blockStatement([t.returnStatement(child)])), [])),
]));
return insertName;
}
return child;
});
}
}
return children;
};
exports.buildIIFE = buildIIFE;
const onRE = /^on[^a-z]/;
const isOn = (key) => onRE.test(key);
exports.isOn = isOn;
const mergeAsArray = (existing, incoming) => {
if (t.isArrayExpression(existing.value)) {
existing.value.elements.push(incoming.value);
}
else {
existing.value = t.arrayExpression([
existing.value,
incoming.value,
]);
}
};
const dedupeProperties = (properties = [], mergeProps) => {
if (!mergeProps) {
return properties;
}
const knownProps = new Map();
const deduped = [];
properties.forEach((prop) => {
if (t.isStringLiteral(prop.key)) {
const { value: name } = prop.key;
const existing = knownProps.get(name);
if (existing) {
if (name === 'style' || name === 'class' || name.startsWith('on')) {
mergeAsArray(existing, prop);
}
}
else {
knownProps.set(name, prop);
deduped.push(prop);
}
}
else {
// v-model target with variable
deduped.push(prop);
}
});
return deduped;
};
exports.dedupeProperties = dedupeProperties;
/**
* Check if an attribute value is constant
* @param node
* @returns boolean
*/
const isConstant = (node) => {
if (t.isIdentifier(node)) {
return node.name === 'undefined';
}
if (t.isArrayExpression(node)) {
const { elements } = node;
return elements.every((element) => element && (0, exports.isConstant)(element));
}
if (t.isObjectExpression(node)) {
return node.properties.every((property) => (0, exports.isConstant)(property.value));
}
if (t.isLiteral(node)) {
return true;
}
return false;
};
exports.isConstant = isConstant;
const transformJSXSpreadAttribute = (nodePath, path, mergeProps, args) => {
const argument = path.get('argument');
const properties = t.isObjectExpression(argument.node) ? argument.node.properties : undefined;
if (!properties) {
if (argument.isIdentifier()) {
(0, exports.walksScope)(nodePath, argument.node.name, 2 /* DYNAMIC */);
}
args.push(mergeProps ? argument.node : t.spreadElement(argument.node));
}
else if (mergeProps) {
args.push(t.objectExpression(properties));
}
else {
args.push(...properties);
}
};
exports.transformJSXSpreadAttribute = transformJSXSpreadAttribute;
//# sourceMappingURL=utils.js.map

1
node_modules/@vue/babel-plugin-jsx/dist/utils.js.map generated vendored Normal file

File diff suppressed because one or more lines are too long

53
node_modules/@vue/babel-plugin-jsx/package.json generated vendored Normal file
View File

@@ -0,0 +1,53 @@
{
"name": "@vue/babel-plugin-jsx",
"version": "1.1.1",
"description": "Babel plugin for Vue 3.0 JSX",
"author": "Amour1688 <lcz_1996@foxmail.com>",
"homepage": "https://github.com/vuejs/jsx-next/tree/dev/packages/babel-plugin-jsx#readme",
"license": "MIT",
"main": "dist/index.js",
"repository": {
"type": "git",
"url": "git+https://github.com/vuejs/jsx-next.git"
},
"scripts": {
"build": "rm -rf dist && tsc",
"watch": "rm -rf dist && tsc --watch",
"lint": "eslint 'src/*.ts'",
"test": "yarn build && jest --coverage",
"prepublishOnly": "yarn build"
},
"bugs": {
"url": "https://github.com/vuejs/jsx-next/issues"
},
"files": [
"dist"
],
"dependencies": {
"@babel/helper-module-imports": "^7.0.0",
"@babel/plugin-syntax-jsx": "^7.0.0",
"@babel/template": "^7.0.0",
"@babel/traverse": "^7.0.0",
"@babel/types": "^7.0.0",
"@vue/babel-helper-vue-transform-on": "^1.0.2",
"camelcase": "^6.0.0",
"html-tags": "^3.1.0",
"svg-tags": "^1.0.0"
},
"devDependencies": {
"@babel/core": "^7.15.5",
"@babel/preset-env": "^7.15.4",
"@types/jest": "^26.0.24",
"@types/svg-tags": "^1.0.0",
"@typescript-eslint/eslint-plugin": "^4.30.0",
"@typescript-eslint/parser": "^4.30.0",
"@vue/compiler-dom": "3.2.8",
"@vue/test-utils": "2.0.0-beta.2",
"jest": "^26.0.1",
"regenerator-runtime": "^0.13.9",
"ts-jest": "^26.1.3",
"typescript": "^4.4.2",
"vue": "3.2.8"
},
"gitHead": "04fb7f7780a47a7c82f8c7f34b548950f288b4e5"
}