@dcloudio/uni-mp-compiler 0.0.1-nvue3.3030820220125001
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/dist/ast.d.ts +16 -0
- package/dist/ast.js +91 -0
- package/dist/codegen.d.ts +14 -0
- package/dist/codegen.js +322 -0
- package/dist/compile.d.ts +13 -0
- package/dist/compile.js +108 -0
- package/dist/decodeHtml.d.ts +2 -0
- package/dist/decodeHtml.js +131 -0
- package/dist/errors.d.ts +16 -0
- package/dist/errors.js +19 -0
- package/dist/identifier.d.ts +7 -0
- package/dist/identifier.js +35 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +40 -0
- package/dist/namedChars.json +2233 -0
- package/dist/options.d.ts +88 -0
- package/dist/options.js +2 -0
- package/dist/parserOptions.d.ts +7 -0
- package/dist/parserOptions.js +63 -0
- package/dist/runtimeHelpers.d.ts +13 -0
- package/dist/runtimeHelpers.js +32 -0
- package/dist/template/codegen.d.ts +19 -0
- package/dist/template/codegen.js +381 -0
- package/dist/transform.d.ts +73 -0
- package/dist/transform.js +518 -0
- package/dist/transforms/transformClass.d.ts +5 -0
- package/dist/transforms/transformClass.js +162 -0
- package/dist/transforms/transformComponent.d.ts +11 -0
- package/dist/transforms/transformComponent.js +179 -0
- package/dist/transforms/transformElement.d.ts +9 -0
- package/dist/transforms/transformElement.js +191 -0
- package/dist/transforms/transformExpression.d.ts +5 -0
- package/dist/transforms/transformExpression.js +283 -0
- package/dist/transforms/transformIdentifier.d.ts +2 -0
- package/dist/transforms/transformIdentifier.js +95 -0
- package/dist/transforms/transformKey.d.ts +4 -0
- package/dist/transforms/transformKey.js +18 -0
- package/dist/transforms/transformRef.d.ts +3 -0
- package/dist/transforms/transformRef.js +126 -0
- package/dist/transforms/transformRoot.d.ts +2 -0
- package/dist/transforms/transformRoot.js +42 -0
- package/dist/transforms/transformSlot.d.ts +3 -0
- package/dist/transforms/transformSlot.js +144 -0
- package/dist/transforms/transformStyle.d.ts +5 -0
- package/dist/transforms/transformStyle.js +156 -0
- package/dist/transforms/transformTag.d.ts +2 -0
- package/dist/transforms/transformTag.js +15 -0
- package/dist/transforms/utils.d.ts +25 -0
- package/dist/transforms/utils.js +133 -0
- package/dist/transforms/vBind.d.ts +2 -0
- package/dist/transforms/vBind.js +49 -0
- package/dist/transforms/vFor.d.ts +35 -0
- package/dist/transforms/vFor.js +299 -0
- package/dist/transforms/vHtml.d.ts +2 -0
- package/dist/transforms/vHtml.js +35 -0
- package/dist/transforms/vIf.d.ts +13 -0
- package/dist/transforms/vIf.js +139 -0
- package/dist/transforms/vModel.d.ts +2 -0
- package/dist/transforms/vModel.js +178 -0
- package/dist/transforms/vOn.d.ts +8 -0
- package/dist/transforms/vOn.js +166 -0
- package/dist/transforms/vSlot.d.ts +16 -0
- package/dist/transforms/vSlot.js +274 -0
- package/package.json +36 -0
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.transformIdentifier = void 0;
|
|
4
|
+
const compiler_core_1 = require("@vue/compiler-core");
|
|
5
|
+
const utils_1 = require("./utils");
|
|
6
|
+
const transformClass_1 = require("./transformClass");
|
|
7
|
+
const transformStyle_1 = require("./transformStyle");
|
|
8
|
+
const runtimeHelpers_1 = require("../runtimeHelpers");
|
|
9
|
+
const transformSlot_1 = require("./transformSlot");
|
|
10
|
+
const vSlot_1 = require("./vSlot");
|
|
11
|
+
const transformRef_1 = require("./transformRef");
|
|
12
|
+
const transformComponent_1 = require("./transformComponent");
|
|
13
|
+
const uni_cli_shared_1 = require("@dcloudio/uni-cli-shared");
|
|
14
|
+
const transformIdentifier = (node, context) => {
|
|
15
|
+
return function transformIdentifier() {
|
|
16
|
+
if (node.type === 5 /* INTERPOLATION */) {
|
|
17
|
+
node.content = (0, utils_1.rewriteExpression)((0, compiler_core_1.createCompoundExpression)([
|
|
18
|
+
`${context.helperString(runtimeHelpers_1.TO_DISPLAY_STRING)}(`,
|
|
19
|
+
node.content,
|
|
20
|
+
`)`,
|
|
21
|
+
]), context);
|
|
22
|
+
}
|
|
23
|
+
else if ((0, compiler_core_1.isSlotOutlet)(node)) {
|
|
24
|
+
(0, transformSlot_1.rewriteSlot)(node, context);
|
|
25
|
+
}
|
|
26
|
+
else if (node.type === 1 /* ELEMENT */) {
|
|
27
|
+
let hasClassBinding = false;
|
|
28
|
+
let hasStyleBinding = false;
|
|
29
|
+
(0, transformRef_1.rewriteRef)(node, context);
|
|
30
|
+
if ((0, uni_cli_shared_1.isUserComponent)(node, context)) {
|
|
31
|
+
(0, transformComponent_1.rewriteBinding)(node, context);
|
|
32
|
+
}
|
|
33
|
+
const { props } = node;
|
|
34
|
+
for (let i = 0; i < props.length; i++) {
|
|
35
|
+
const dir = props[i];
|
|
36
|
+
if (dir.type === 7 /* DIRECTIVE */) {
|
|
37
|
+
const arg = dir.arg;
|
|
38
|
+
if (arg) {
|
|
39
|
+
// TODO 指令暂不不支持动态参数,v-bind:[arg] v-on:[event]
|
|
40
|
+
if (!(arg.type === 4 /* SIMPLE_EXPRESSION */ && arg.isStatic)) {
|
|
41
|
+
// v-slot:[slotName] 支持
|
|
42
|
+
if (dir.name === 'slot') {
|
|
43
|
+
(0, vSlot_1.rewriteVSlot)(dir, context);
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
props.splice(i, 1);
|
|
47
|
+
i--;
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
const exp = dir.exp;
|
|
53
|
+
if (exp) {
|
|
54
|
+
if (isBuiltIn(dir)) {
|
|
55
|
+
// noop
|
|
56
|
+
}
|
|
57
|
+
else if ((0, transformClass_1.isClassBinding)(dir)) {
|
|
58
|
+
hasClassBinding = true;
|
|
59
|
+
(0, transformClass_1.rewriteClass)(i, dir, props, context);
|
|
60
|
+
}
|
|
61
|
+
else if ((0, transformStyle_1.isStyleBinding)(dir)) {
|
|
62
|
+
hasStyleBinding = true;
|
|
63
|
+
(0, transformStyle_1.rewriteStyle)(i, dir, props, context);
|
|
64
|
+
}
|
|
65
|
+
else if ((0, transformComponent_1.isPropsBinding)(dir)) {
|
|
66
|
+
(0, transformComponent_1.rewritePropsBinding)(dir, node, context);
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
dir.exp = (0, utils_1.rewriteExpression)(exp, context);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
if (hasClassBinding) {
|
|
75
|
+
const staticClassIndex = (0, transformClass_1.findStaticClassIndex)(props);
|
|
76
|
+
if (staticClassIndex > -1) {
|
|
77
|
+
props.splice(staticClassIndex, 1);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
if (hasStyleBinding) {
|
|
81
|
+
const staticStyleIndex = (0, transformStyle_1.findStaticStyleIndex)(props);
|
|
82
|
+
if (staticStyleIndex > -1) {
|
|
83
|
+
props.splice(staticStyleIndex, 1);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
exports.transformIdentifier = transformIdentifier;
|
|
90
|
+
const builtInProps = [utils_1.ATTR_VUE_SLOTS];
|
|
91
|
+
function isBuiltIn({ arg, exp }) {
|
|
92
|
+
return ((arg === null || arg === void 0 ? void 0 : arg.type) === 4 /* SIMPLE_EXPRESSION */ &&
|
|
93
|
+
builtInProps.includes(arg.content) &&
|
|
94
|
+
(exp === null || exp === void 0 ? void 0 : exp.type) === 4 /* SIMPLE_EXPRESSION */);
|
|
95
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { DirectiveNode } from '@vue/compiler-core';
|
|
2
|
+
import { ForElementNode } from './vFor';
|
|
3
|
+
export declare function isSelfKey({ arg, exp }: DirectiveNode, vFor: ForElementNode['vFor'] | false): boolean | undefined;
|
|
4
|
+
export declare function rewriteSelfKey(dir: DirectiveNode): void;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.rewriteSelfKey = exports.isSelfKey = void 0;
|
|
4
|
+
function isSelfKey({ arg, exp }, vFor) {
|
|
5
|
+
return (vFor &&
|
|
6
|
+
arg &&
|
|
7
|
+
exp &&
|
|
8
|
+
arg.type === 4 /* SIMPLE_EXPRESSION */ &&
|
|
9
|
+
arg.content === 'key' &&
|
|
10
|
+
exp.type === 4 /* SIMPLE_EXPRESSION */ &&
|
|
11
|
+
exp.content === vFor.valueAlias);
|
|
12
|
+
}
|
|
13
|
+
exports.isSelfKey = isSelfKey;
|
|
14
|
+
function rewriteSelfKey(dir) {
|
|
15
|
+
;
|
|
16
|
+
dir.exp.content = '*this';
|
|
17
|
+
}
|
|
18
|
+
exports.rewriteSelfKey = rewriteSelfKey;
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.rewriteRef = void 0;
|
|
4
|
+
const types_1 = require("@babel/types");
|
|
5
|
+
const compiler_core_1 = require("@vue/compiler-core");
|
|
6
|
+
const uni_cli_shared_1 = require("@dcloudio/uni-cli-shared");
|
|
7
|
+
const utils_1 = require("./utils");
|
|
8
|
+
const runtimeHelpers_1 = require("../runtimeHelpers");
|
|
9
|
+
const codegen_1 = require("../codegen");
|
|
10
|
+
const ast_1 = require("../ast");
|
|
11
|
+
function rewriteRef(node, context) {
|
|
12
|
+
const vueIdProp = (0, compiler_core_1.findProp)(node, utils_1.ATTR_VUE_ID);
|
|
13
|
+
if (!vueIdProp) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
const refProp = (0, compiler_core_1.findProp)(node, 'u-' + uni_cli_shared_1.VUE_REF) || (0, compiler_core_1.findProp)(node, 'u-' + uni_cli_shared_1.VUE_REF_IN_FOR);
|
|
17
|
+
if (!refProp) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
if ((0, compiler_core_1.findProp)(node, 'ref')) {
|
|
21
|
+
// 支付宝小程序
|
|
22
|
+
const code = parseAlipayRefCode(refProp, context);
|
|
23
|
+
if (code && context.inline && !(0, uni_cli_shared_1.isDirectiveNode)(refProp)) {
|
|
24
|
+
refProp.value.content = code;
|
|
25
|
+
const refPropIndex = node.props.findIndex((prop) => prop === refProp);
|
|
26
|
+
node.props.splice(refPropIndex, 1, (0, uni_cli_shared_1.createBindDirectiveNode)(refProp.name, code));
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
rewriteRefProp(refProp, vueIdProp, context);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.rewriteRef = rewriteRef;
|
|
34
|
+
function parseRef(prop, context) {
|
|
35
|
+
let expr;
|
|
36
|
+
let refKey = '';
|
|
37
|
+
const isDir = (0, uni_cli_shared_1.isDirectiveNode)(prop);
|
|
38
|
+
if (isDir) {
|
|
39
|
+
if (prop.exp) {
|
|
40
|
+
expr = (0, ast_1.parseExpr)(prop.exp, context, prop.exp);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
const { value } = prop;
|
|
45
|
+
if (value && value.content) {
|
|
46
|
+
if (context.inline && context.bindingMetadata[value.content]) {
|
|
47
|
+
expr = (0, types_1.identifier)(value.content);
|
|
48
|
+
refKey = value.content;
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
expr = (0, types_1.stringLiteral)(value.content);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return { expr, refKey };
|
|
56
|
+
}
|
|
57
|
+
function parseRefCode(prop, context) {
|
|
58
|
+
const { expr, refKey } = parseRef(prop, context);
|
|
59
|
+
if (!expr) {
|
|
60
|
+
return { code: '', refKey };
|
|
61
|
+
}
|
|
62
|
+
return { code: (0, codegen_1.genBabelExpr)(expr), refKey };
|
|
63
|
+
}
|
|
64
|
+
function rewriteRefProp(prop, vueIdProp, context) {
|
|
65
|
+
let id = '';
|
|
66
|
+
if ((0, uni_cli_shared_1.isDirectiveNode)(vueIdProp)) {
|
|
67
|
+
const vueIdExpr = (0, ast_1.parseExpr)(vueIdProp.exp, context, vueIdProp.exp);
|
|
68
|
+
if (vueIdExpr) {
|
|
69
|
+
id = (0, codegen_1.genBabelExpr)(vueIdExpr);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
id = `'${vueIdProp.value.content}'`;
|
|
74
|
+
}
|
|
75
|
+
if (!id) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
const { code, refKey } = parseRefCode(prop, context);
|
|
79
|
+
const opts = Object.create(null);
|
|
80
|
+
if (refKey) {
|
|
81
|
+
opts.k = refKey;
|
|
82
|
+
}
|
|
83
|
+
if (context.inVFor) {
|
|
84
|
+
opts.f = 1;
|
|
85
|
+
}
|
|
86
|
+
(0, utils_1.parseExprWithRewrite)(context.helperString(runtimeHelpers_1.SET_REF) +
|
|
87
|
+
'(' +
|
|
88
|
+
code +
|
|
89
|
+
', ' +
|
|
90
|
+
id +
|
|
91
|
+
(Object.keys(opts).length ? ', ' + JSON.stringify(opts) : '') +
|
|
92
|
+
')', prop.loc, context);
|
|
93
|
+
}
|
|
94
|
+
function parseAlipayRefCode(prop, context) {
|
|
95
|
+
var _a;
|
|
96
|
+
let expr;
|
|
97
|
+
const isDir = (0, uni_cli_shared_1.isDirectiveNode)(prop);
|
|
98
|
+
if (isDir) {
|
|
99
|
+
if (prop.exp) {
|
|
100
|
+
expr = (0, ast_1.parseExpr)(prop.exp, context, prop.exp);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
if ((_a = prop.value) === null || _a === void 0 ? void 0 : _a.content) {
|
|
105
|
+
expr = context.inline
|
|
106
|
+
? processInlineRef(prop, context)
|
|
107
|
+
: (0, types_1.stringLiteral)(prop.value.content);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
if (!expr) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
return (0, codegen_1.genBabelExpr)(expr);
|
|
114
|
+
}
|
|
115
|
+
function processInlineRef(prop, context) {
|
|
116
|
+
const properties = [];
|
|
117
|
+
const { refKey } = parseRef(prop, context);
|
|
118
|
+
properties.push((0, types_1.objectProperty)((0, types_1.identifier)('r'), (0, types_1.identifier)(prop.value.content)));
|
|
119
|
+
if (refKey) {
|
|
120
|
+
properties.push((0, types_1.objectProperty)((0, types_1.identifier)('k'), (0, types_1.stringLiteral)(refKey)));
|
|
121
|
+
}
|
|
122
|
+
if (context.inVFor) {
|
|
123
|
+
properties.push((0, types_1.objectProperty)((0, types_1.identifier)('f'), (0, types_1.numericLiteral)(1)));
|
|
124
|
+
}
|
|
125
|
+
return (0, types_1.arrowFunctionExpression)([], (0, types_1.objectExpression)(properties));
|
|
126
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.transformRoot = void 0;
|
|
4
|
+
const compiler_core_1 = require("@vue/compiler-core");
|
|
5
|
+
const uni_cli_shared_1 = require("@dcloudio/uni-cli-shared");
|
|
6
|
+
const ast_1 = require("../ast");
|
|
7
|
+
const types_1 = require("@babel/types");
|
|
8
|
+
const codegen_1 = require("../codegen");
|
|
9
|
+
const transformRoot = (node, context) => {
|
|
10
|
+
if (node.type !== 0 /* ROOT */) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
if (context.bindingCssVars.length) {
|
|
14
|
+
node.children.forEach((child) => {
|
|
15
|
+
if (child.type !== 1 /* ELEMENT */) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
addCssVars(child, context);
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
exports.transformRoot = transformRoot;
|
|
23
|
+
const CSS_VARS = '__cssVars()';
|
|
24
|
+
function addCssVars(node, context) {
|
|
25
|
+
var _a;
|
|
26
|
+
const styleProp = (0, compiler_core_1.findProp)(node, 'style', true);
|
|
27
|
+
if (!styleProp) {
|
|
28
|
+
node.props.push((0, uni_cli_shared_1.createBindDirectiveNode)('style', CSS_VARS));
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
if (((_a = styleProp.exp) === null || _a === void 0 ? void 0 : _a.type) === 4 /* SIMPLE_EXPRESSION */) {
|
|
32
|
+
let expr = (0, ast_1.parseExpr)(styleProp.exp.content, context);
|
|
33
|
+
if ((0, types_1.isArrayExpression)(expr)) {
|
|
34
|
+
expr.elements.push((0, types_1.identifier)(CSS_VARS));
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
expr = (0, types_1.arrayExpression)([expr, (0, types_1.identifier)(CSS_VARS)]);
|
|
38
|
+
}
|
|
39
|
+
styleProp.exp.content = (0, codegen_1.genBabelExpr)(expr);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.rewriteSlot = void 0;
|
|
4
|
+
const compiler_core_1 = require("@vue/compiler-core");
|
|
5
|
+
const shared_1 = require("@vue/shared");
|
|
6
|
+
const uni_shared_1 = require("@dcloudio/uni-shared");
|
|
7
|
+
const runtimeHelpers_1 = require("../runtimeHelpers");
|
|
8
|
+
const codegen_1 = require("../codegen");
|
|
9
|
+
const transform_1 = require("../transform");
|
|
10
|
+
const transformElement_1 = require("./transformElement");
|
|
11
|
+
const utils_1 = require("./utils");
|
|
12
|
+
const uni_cli_shared_1 = require("@dcloudio/uni-cli-shared");
|
|
13
|
+
const __1 = require("..");
|
|
14
|
+
function rewriteSlot(node, context) {
|
|
15
|
+
let slotName = `"${uni_shared_1.SLOT_DEFAULT_NAME}"`;
|
|
16
|
+
let hasOtherDir = false;
|
|
17
|
+
const nonNameProps = [];
|
|
18
|
+
const { props } = node;
|
|
19
|
+
// 默认插槽强制设置name
|
|
20
|
+
if (!(0, compiler_core_1.findProp)(node, 'name')) {
|
|
21
|
+
props.unshift((0, uni_cli_shared_1.createAttributeNode)('name', 'default'));
|
|
22
|
+
}
|
|
23
|
+
for (let i = 0; i < props.length; i++) {
|
|
24
|
+
const p = props[i];
|
|
25
|
+
if (p.type === 6 /* ATTRIBUTE */) {
|
|
26
|
+
if (p.value) {
|
|
27
|
+
if (p.name === 'name') {
|
|
28
|
+
p.value.content = (0, uni_shared_1.dynamicSlotName)(p.value.content);
|
|
29
|
+
slotName = JSON.stringify(p.value.content);
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
p.name = (0, shared_1.camelize)(p.name);
|
|
33
|
+
nonNameProps.push(p);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
if (p.name !== 'bind') {
|
|
39
|
+
hasOtherDir = true;
|
|
40
|
+
}
|
|
41
|
+
if (p.name === 'bind' && (0, compiler_core_1.isStaticArgOf)(p.arg, 'name')) {
|
|
42
|
+
if (p.exp) {
|
|
43
|
+
p.exp = (0, utils_1.rewriteExpression)((0, compiler_core_1.createCompoundExpression)([
|
|
44
|
+
context.helperString(__1.DYNAMIC_SLOT) + '(',
|
|
45
|
+
p.exp,
|
|
46
|
+
')',
|
|
47
|
+
]), context);
|
|
48
|
+
slotName = p.exp;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
if (p.name === 'bind' && p.arg && (0, compiler_core_1.isStaticExp)(p.arg)) {
|
|
53
|
+
p.arg.content = (0, shared_1.camelize)(p.arg.content);
|
|
54
|
+
}
|
|
55
|
+
nonNameProps.push(p);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
if (hasOtherDir) {
|
|
60
|
+
context.onError((0, compiler_core_1.createCompilerError)(36 /* X_V_SLOT_UNEXPECTED_DIRECTIVE_ON_SLOT_OUTLET */, node.loc));
|
|
61
|
+
}
|
|
62
|
+
if (nonNameProps.length > 0) {
|
|
63
|
+
(0, transformElement_1.processProps)(node, context, nonNameProps);
|
|
64
|
+
const properties = [];
|
|
65
|
+
nonNameProps.forEach((prop) => {
|
|
66
|
+
if (prop.type === 7 /* DIRECTIVE */ && prop.name === 'bind') {
|
|
67
|
+
const property = transformProperty(prop, context);
|
|
68
|
+
property && properties.push(property);
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
if (properties.length) {
|
|
72
|
+
transformScopedSlotName(node, context);
|
|
73
|
+
const vForIndexAlias = parseVForIndexAlias(context);
|
|
74
|
+
(0, utils_1.rewriteExpression)((0, compiler_core_1.createCompoundExpression)([
|
|
75
|
+
context.helperString(runtimeHelpers_1.RENDER_SLOT) + '(',
|
|
76
|
+
slotName,
|
|
77
|
+
',',
|
|
78
|
+
`{${properties.join(',')}}`,
|
|
79
|
+
`${vForIndexAlias ? ',' + vForIndexAlias : ''}`,
|
|
80
|
+
')',
|
|
81
|
+
]), context);
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
// 非作用域默认插槽直接移除命名
|
|
85
|
+
if (slotName === `"${uni_shared_1.SLOT_DEFAULT_NAME}"`) {
|
|
86
|
+
(0, utils_1.removeAttribute)(node, 'name');
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
// 非作用域默认插槽直接移除命名
|
|
92
|
+
if (slotName === `"${uni_shared_1.SLOT_DEFAULT_NAME}"`) {
|
|
93
|
+
(0, utils_1.removeAttribute)(node, 'name');
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
exports.rewriteSlot = rewriteSlot;
|
|
98
|
+
function parseVForIndexAlias(context) {
|
|
99
|
+
let { currentScope } = context;
|
|
100
|
+
while (currentScope) {
|
|
101
|
+
if ((0, transform_1.isVForScope)(currentScope) && !(0, transform_1.isScopedSlotVFor)(currentScope)) {
|
|
102
|
+
return currentScope.indexAlias;
|
|
103
|
+
}
|
|
104
|
+
currentScope = currentScope.parent;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
function transformScopedSlotName(node, context) {
|
|
108
|
+
if (!context.miniProgram.slot.dynamicSlotNames) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
const slotKey = parseScopedSlotKey(context);
|
|
112
|
+
if (!slotKey) {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
const nameProps = (0, compiler_core_1.findProp)(node, 'name');
|
|
116
|
+
if (nameProps && nameProps.type === 6 /* ATTRIBUTE */ && nameProps.value) {
|
|
117
|
+
const { props } = node;
|
|
118
|
+
props.splice(props.indexOf(nameProps), 1, (0, uni_cli_shared_1.createBindDirectiveNode)('name', (0, utils_1.rewriteExpression)((0, compiler_core_1.createSimpleExpression)(`"${nameProps.value.content}-"+` + slotKey), context).content));
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
function parseScopedSlotKey(context) {
|
|
122
|
+
let { currentScope } = context;
|
|
123
|
+
const indexs = [];
|
|
124
|
+
while (currentScope) {
|
|
125
|
+
if ((0, transform_1.isVForScope)(currentScope)) {
|
|
126
|
+
indexs.push(currentScope.indexAlias);
|
|
127
|
+
}
|
|
128
|
+
currentScope = currentScope.parent;
|
|
129
|
+
}
|
|
130
|
+
const inFor = !!indexs.length;
|
|
131
|
+
if (inFor) {
|
|
132
|
+
return indexs.reverse().join(`+'-'+`);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
function transformProperty(dir, context) {
|
|
136
|
+
if (!dir.arg || !dir.exp) {
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
const isStaticArg = dir.arg.type === 4 /* SIMPLE_EXPRESSION */ && dir.arg.isStatic;
|
|
140
|
+
if (isStaticArg) {
|
|
141
|
+
return `${dir.arg.content}:${(0, codegen_1.genExpr)(dir.exp)}`;
|
|
142
|
+
}
|
|
143
|
+
return `[${(0, codegen_1.genExpr)(dir.arg)}||'']:${(0, codegen_1.genExpr)(dir.exp)}`;
|
|
144
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { DirectiveNode, AttributeNode } from '@vue/compiler-core';
|
|
2
|
+
import { TransformContext } from '../transform';
|
|
3
|
+
export declare function isStyleBinding({ arg, exp }: DirectiveNode): boolean | undefined;
|
|
4
|
+
export declare function findStaticStyleIndex(props: (AttributeNode | DirectiveNode)[]): number;
|
|
5
|
+
export declare function rewriteStyle(index: number, styleBindingProp: DirectiveNode, props: (AttributeNode | DirectiveNode)[], context: TransformContext): void;
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.rewriteStyle = exports.findStaticStyleIndex = exports.isStyleBinding = void 0;
|
|
4
|
+
const types_1 = require("@babel/types");
|
|
5
|
+
const compiler_core_1 = require("@vue/compiler-core");
|
|
6
|
+
const shared_1 = require("@vue/shared");
|
|
7
|
+
const runtimeHelpers_1 = require("../runtimeHelpers");
|
|
8
|
+
const ast_1 = require("../ast");
|
|
9
|
+
const codegen_1 = require("../codegen");
|
|
10
|
+
const utils_1 = require("./utils");
|
|
11
|
+
function isStyleBinding({ arg, exp }) {
|
|
12
|
+
return (arg && arg.type === 4 /* SIMPLE_EXPRESSION */ && arg.content === 'style');
|
|
13
|
+
}
|
|
14
|
+
exports.isStyleBinding = isStyleBinding;
|
|
15
|
+
function findStaticStyleIndex(props) {
|
|
16
|
+
return props.findIndex((prop) => prop.name === 'style');
|
|
17
|
+
}
|
|
18
|
+
exports.findStaticStyleIndex = findStaticStyleIndex;
|
|
19
|
+
function rewriteStyle(index, styleBindingProp, props, context) {
|
|
20
|
+
if (!styleBindingProp.exp) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
const expr = (0, ast_1.parseExpr)(styleBindingProp.exp, context);
|
|
24
|
+
if (!expr) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
let styleBidingExpr = expr;
|
|
28
|
+
if ((0, types_1.isObjectExpression)(expr)) {
|
|
29
|
+
styleBidingExpr = createStyleBindingByObjectExpression(rewriteStyleObjectExpression(expr, styleBindingProp.loc, context));
|
|
30
|
+
}
|
|
31
|
+
else if ((0, types_1.isArrayExpression)(expr)) {
|
|
32
|
+
styleBidingExpr = createStyleBindingByArrayExpression(rewriteStyleArrayExpression(expr, context));
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
styleBidingExpr = (0, ast_1.parseExpr)(rewriteStyleExpression(styleBindingProp.exp, context).content, context);
|
|
36
|
+
}
|
|
37
|
+
if (!styleBidingExpr) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
const staticStylePropIndex = findStaticStyleIndex(props);
|
|
41
|
+
if (staticStylePropIndex > -1) {
|
|
42
|
+
const staticStyle = props[staticStylePropIndex].value
|
|
43
|
+
.content;
|
|
44
|
+
if (staticStyle.trim()) {
|
|
45
|
+
if (index > staticStylePropIndex) {
|
|
46
|
+
styleBidingExpr = (0, types_1.binaryExpression)('+', addSemicolon((0, types_1.stringLiteral)(staticStyle)), styleBidingExpr);
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
styleBidingExpr = (0, types_1.binaryExpression)('+', addSemicolon(styleBidingExpr), (0, types_1.stringLiteral)(staticStyle));
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
styleBindingProp.exp = (0, compiler_core_1.createSimpleExpression)((0, codegen_1.genBabelExpr)(styleBidingExpr));
|
|
54
|
+
}
|
|
55
|
+
exports.rewriteStyle = rewriteStyle;
|
|
56
|
+
function rewriteStyleExpression(expr, context) {
|
|
57
|
+
return (0, utils_1.rewriteExpression)((0, compiler_core_1.createCompoundExpression)([
|
|
58
|
+
context.helperString(runtimeHelpers_1.STRINGIFY_STYLE) + '(',
|
|
59
|
+
expr,
|
|
60
|
+
')',
|
|
61
|
+
]), context);
|
|
62
|
+
}
|
|
63
|
+
function rewriteStyleArrayExpression(expr, context) {
|
|
64
|
+
expr.elements.forEach((prop, index) => {
|
|
65
|
+
if (!(0, types_1.isStringLiteral)(prop)) {
|
|
66
|
+
const code = (0, codegen_1.genBabelExpr)((0, types_1.arrayExpression)([(0, types_1.isSpreadElement)(prop) ? prop.argument : prop]));
|
|
67
|
+
expr.elements[index] = (0, types_1.identifier)(rewriteStyleExpression((0, compiler_core_1.createSimpleExpression)(code.slice(1, -1), false), context).content);
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
return expr;
|
|
71
|
+
}
|
|
72
|
+
function rewriteStyleObjectExpression(expr, loc, context) {
|
|
73
|
+
expr.properties.forEach((prop, index) => {
|
|
74
|
+
if ((0, types_1.isSpreadElement)(prop)) {
|
|
75
|
+
// <view :style="{...obj}"/>
|
|
76
|
+
// <view style="{{a}}"/>
|
|
77
|
+
const newExpr = (0, utils_1.rewriteSpreadElement)(runtimeHelpers_1.STRINGIFY_STYLE, prop, loc, context);
|
|
78
|
+
if (newExpr) {
|
|
79
|
+
prop.argument = newExpr;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
else if ((0, types_1.isObjectProperty)(prop)) {
|
|
83
|
+
const { key, value, computed } = prop;
|
|
84
|
+
if (computed) {
|
|
85
|
+
// {[handle(computedKey)]:1} => {[a]:1}
|
|
86
|
+
const newExpr = (0, utils_1.rewirteWithHelper)(runtimeHelpers_1.HYPHENATE, key, loc, context);
|
|
87
|
+
if (newExpr) {
|
|
88
|
+
prop.key = newExpr;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
// {fontSize:'15px'} => {'font-size':'15px'}
|
|
93
|
+
prop.key = (0, ast_1.parseStringLiteral)(prop.key);
|
|
94
|
+
prop.key.value = (0, shared_1.hyphenate)(prop.key.value) + ':';
|
|
95
|
+
}
|
|
96
|
+
// {fontSize:`${fontSize}px`} => {'font-size':a}
|
|
97
|
+
if ((0, utils_1.isStaticLiteral)(value)) {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
const newExpr = (0, utils_1.parseExprWithRewrite)((0, codegen_1.genBabelExpr)(value), loc, context, value);
|
|
102
|
+
if (newExpr) {
|
|
103
|
+
prop.value = newExpr;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
return expr;
|
|
109
|
+
}
|
|
110
|
+
function addSemicolon(expr) {
|
|
111
|
+
return createBinaryExpression(expr, (0, types_1.stringLiteral)(';'));
|
|
112
|
+
}
|
|
113
|
+
function createBinaryExpression(left, right) {
|
|
114
|
+
return (0, types_1.binaryExpression)('+', left, right);
|
|
115
|
+
}
|
|
116
|
+
function createStyleBindingByArrayExpression(expr) {
|
|
117
|
+
let result;
|
|
118
|
+
function concat(expr) {
|
|
119
|
+
if (!result) {
|
|
120
|
+
result = expr;
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
result = createBinaryExpression(addSemicolon(result), expr);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
expr.elements.forEach((prop) => {
|
|
127
|
+
if ((0, types_1.isStringLiteral)(prop) || (0, types_1.isIdentifier)(prop)) {
|
|
128
|
+
concat(prop);
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
return result;
|
|
132
|
+
}
|
|
133
|
+
function createStyleBindingByObjectExpression(expr) {
|
|
134
|
+
let result;
|
|
135
|
+
function concat(expr) {
|
|
136
|
+
if (!result) {
|
|
137
|
+
result = expr;
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
result = createBinaryExpression(addSemicolon(result), expr);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
expr.properties.forEach((prop) => {
|
|
144
|
+
if ((0, types_1.isSpreadElement)(prop)) {
|
|
145
|
+
concat(prop.argument);
|
|
146
|
+
}
|
|
147
|
+
else if ((0, types_1.isObjectProperty)(prop)) {
|
|
148
|
+
const { key, value } = prop;
|
|
149
|
+
const expr = createBinaryExpression((0, types_1.isStringLiteral)(key)
|
|
150
|
+
? key // 之前已经补充了:
|
|
151
|
+
: createBinaryExpression(key, (0, types_1.stringLiteral)(':')), value);
|
|
152
|
+
concat(expr);
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
return result;
|
|
156
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.transformTag = void 0;
|
|
4
|
+
const uni_cli_shared_1 = require("@dcloudio/uni-cli-shared");
|
|
5
|
+
const transformTag = (node, _) => {
|
|
6
|
+
if (!(0, uni_cli_shared_1.isElementNode)(node)) {
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
const newTag = uni_cli_shared_1.HTML_TO_MINI_PROGRAM_TAGS[node.tag];
|
|
10
|
+
if (newTag) {
|
|
11
|
+
node.tag = newTag;
|
|
12
|
+
node.tagType = 0 /* ELEMENT */;
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
exports.transformTag = transformTag;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Expression, Identifier, MemberExpression, SpreadElement } from '@babel/types';
|
|
2
|
+
import { ElementNode, ExpressionNode, SimpleExpressionNode, SourceLocation, TransformContext as VueTransformContext } from '@vue/compiler-core';
|
|
3
|
+
import { CodegenScope } from '../options';
|
|
4
|
+
import { TransformContext } from '../transform';
|
|
5
|
+
export declare const ATTR_VUE_ID = "u-i";
|
|
6
|
+
export declare const ATTR_VUE_SLOTS = "u-s";
|
|
7
|
+
export declare const ATTR_VUE_PROPS = "u-p";
|
|
8
|
+
export declare const ATTR_VUE_REF: string;
|
|
9
|
+
export declare const ATTR_VUE_REF_IN_FOR: string;
|
|
10
|
+
export declare const ATTR_COM_TYPE = "u-t";
|
|
11
|
+
export declare const SCOPED_SLOT_IDENTIFIER = "__SCOPED_SLOT__";
|
|
12
|
+
export declare function rewriteSpreadElement(name: symbol, expr: SpreadElement, loc: SourceLocation, context: TransformContext): Identifier | MemberExpression | undefined;
|
|
13
|
+
export declare function rewirteWithHelper(name: symbol, expr: Expression, loc: SourceLocation, context: TransformContext): Identifier | MemberExpression | undefined;
|
|
14
|
+
export declare function parseExprWithRewrite(code: string, loc: SourceLocation, context: TransformContext, node?: Expression): Identifier | MemberExpression | undefined;
|
|
15
|
+
export declare function parseExprWithRewriteClass(code: string, loc: SourceLocation, context: TransformContext, node: Expression): Identifier | MemberExpression | undefined;
|
|
16
|
+
export declare function rewriteExpressionWithoutProperty(node: ExpressionNode, context: TransformContext, babelNode?: Expression, scope?: CodegenScope): SimpleExpressionNode;
|
|
17
|
+
export declare function rewriteExpression(node: ExpressionNode, context: TransformContext | VueTransformContext, babelNode?: Expression, scope?: CodegenScope, { property, ignoreLiteral, referencedScope, }?: {
|
|
18
|
+
property: boolean;
|
|
19
|
+
ignoreLiteral: boolean;
|
|
20
|
+
referencedScope?: CodegenScope;
|
|
21
|
+
}): SimpleExpressionNode;
|
|
22
|
+
export declare function findReferencedScope(node: Expression, scope: CodegenScope): CodegenScope;
|
|
23
|
+
export declare function isReferencedByIds(node: Expression, knownIds: string[]): boolean;
|
|
24
|
+
export declare function isStaticLiteral(value: object | null | undefined): boolean;
|
|
25
|
+
export declare function removeAttribute(node: ElementNode, name: string): void;
|