@dcloudio/uni-app-uts 3.0.0-3080720230630001

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.
Files changed (70) hide show
  1. package/LICENSE +202 -0
  2. package/dist/index.d.ts +4 -0
  3. package/dist/index.js +30 -0
  4. package/dist/plugins/css.d.ts +2 -0
  5. package/dist/plugins/css.js +94 -0
  6. package/dist/plugins/index.d.ts +2 -0
  7. package/dist/plugins/index.js +203 -0
  8. package/dist/plugins/mainUTS.d.ts +2 -0
  9. package/dist/plugins/mainUTS.js +24 -0
  10. package/dist/plugins/manifestJson.d.ts +2 -0
  11. package/dist/plugins/manifestJson.js +68 -0
  12. package/dist/plugins/pagesJson.d.ts +2 -0
  13. package/dist/plugins/pagesJson.js +84 -0
  14. package/dist/plugins/pre.d.ts +7 -0
  15. package/dist/plugins/pre.js +52 -0
  16. package/dist/plugins/utils.d.ts +8 -0
  17. package/dist/plugins/utils.js +85 -0
  18. package/dist/plugins/uvue/code/script.d.ts +4 -0
  19. package/dist/plugins/uvue/code/script.js +14 -0
  20. package/dist/plugins/uvue/code/style.d.ts +12 -0
  21. package/dist/plugins/uvue/code/style.js +90 -0
  22. package/dist/plugins/uvue/code/template.d.ts +3 -0
  23. package/dist/plugins/uvue/code/template.js +16 -0
  24. package/dist/plugins/uvue/compiler/codegen.d.ts +22 -0
  25. package/dist/plugins/uvue/compiler/codegen.js +579 -0
  26. package/dist/plugins/uvue/compiler/errors.d.ts +70 -0
  27. package/dist/plugins/uvue/compiler/errors.js +82 -0
  28. package/dist/plugins/uvue/compiler/index.d.ts +9 -0
  29. package/dist/plugins/uvue/compiler/index.js +65 -0
  30. package/dist/plugins/uvue/compiler/options.d.ts +92 -0
  31. package/dist/plugins/uvue/compiler/options.js +2 -0
  32. package/dist/plugins/uvue/compiler/runtimeHelpers.d.ts +10 -0
  33. package/dist/plugins/uvue/compiler/runtimeHelpers.js +25 -0
  34. package/dist/plugins/uvue/compiler/transform.d.ts +53 -0
  35. package/dist/plugins/uvue/compiler/transform.js +294 -0
  36. package/dist/plugins/uvue/compiler/transforms/transformExpression.d.ts +5 -0
  37. package/dist/plugins/uvue/compiler/transforms/transformExpression.js +208 -0
  38. package/dist/plugins/uvue/compiler/transforms/transformInterpolation.d.ts +4 -0
  39. package/dist/plugins/uvue/compiler/transforms/transformInterpolation.js +107 -0
  40. package/dist/plugins/uvue/compiler/transforms/transformSlotOutlet.d.ts +10 -0
  41. package/dist/plugins/uvue/compiler/transforms/transformSlotOutlet.js +79 -0
  42. package/dist/plugins/uvue/compiler/transforms/transformText.d.ts +2 -0
  43. package/dist/plugins/uvue/compiler/transforms/transformText.js +99 -0
  44. package/dist/plugins/uvue/compiler/transforms/vBind.d.ts +2 -0
  45. package/dist/plugins/uvue/compiler/transforms/vBind.js +83 -0
  46. package/dist/plugins/uvue/compiler/transforms/vFor.d.ts +12 -0
  47. package/dist/plugins/uvue/compiler/transforms/vFor.js +325 -0
  48. package/dist/plugins/uvue/compiler/transforms/vIf.d.ts +4 -0
  49. package/dist/plugins/uvue/compiler/transforms/vIf.js +212 -0
  50. package/dist/plugins/uvue/compiler/transforms/vModel.d.ts +2 -0
  51. package/dist/plugins/uvue/compiler/transforms/vModel.js +51 -0
  52. package/dist/plugins/uvue/compiler/transforms/vOn.d.ts +8 -0
  53. package/dist/plugins/uvue/compiler/transforms/vOn.js +136 -0
  54. package/dist/plugins/uvue/compiler/transforms/vShow.d.ts +2 -0
  55. package/dist/plugins/uvue/compiler/transforms/vShow.js +11 -0
  56. package/dist/plugins/uvue/compiler/transforms/vText.d.ts +2 -0
  57. package/dist/plugins/uvue/compiler/transforms/vText.js +29 -0
  58. package/dist/plugins/uvue/compiler/utils.d.ts +5 -0
  59. package/dist/plugins/uvue/compiler/utils.js +37 -0
  60. package/dist/plugins/uvue/descriptorCache.d.ts +24 -0
  61. package/dist/plugins/uvue/descriptorCache.js +57 -0
  62. package/dist/plugins/uvue/error.d.ts +3 -0
  63. package/dist/plugins/uvue/error.js +22 -0
  64. package/dist/plugins/uvue/index.d.ts +13 -0
  65. package/dist/plugins/uvue/index.js +188 -0
  66. package/lib/automator/apis/App.uts +144 -0
  67. package/lib/automator/apis/Page.uts +55 -0
  68. package/lib/automator/apis/util.uts +63 -0
  69. package/lib/automator/index.uts +106 -0
  70. package/package.json +42 -0
@@ -0,0 +1,208 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.stringifyExpression = exports.processExpression = exports.transformExpression = void 0;
4
+ const shared_1 = require("@vue/shared");
5
+ const parser_1 = require("@babel/parser");
6
+ const compiler_core_1 = require("@vue/compiler-core");
7
+ const errors_1 = require("../errors");
8
+ const GLOBALS_WHITE_LISTED = `Infinity,undefined,NaN,isFinite,isNaN,parseFloat,parseInt,decodeURI,
9
+ decodeURIComponent,encodeURI,encodeURIComponent,Math,Number,Date,Array,
10
+ Object,Boolean,String,RegExp,Map,Set,JSON,Intl,BigInt,console`;
11
+ const isGloballyWhitelisted = /*#__PURE__*/ (0, shared_1.makeMap)(GLOBALS_WHITE_LISTED);
12
+ const isLiteralWhitelisted = /*#__PURE__*/ (0, shared_1.makeMap)('true,false,null,this');
13
+ const transformExpression = (node, context) => {
14
+ if (node.type === 5 /* NodeTypes.INTERPOLATION */) {
15
+ node.content = processExpression(node.content, context);
16
+ }
17
+ else if (node.type === 1 /* NodeTypes.ELEMENT */) {
18
+ // handle directives on element
19
+ for (let i = 0; i < node.props.length; i++) {
20
+ const dir = node.props[i];
21
+ // do not process for v-on & v-for since they are special handled
22
+ if (dir.type === 7 /* NodeTypes.DIRECTIVE */ && dir.name !== 'for') {
23
+ const exp = dir.exp;
24
+ const arg = dir.arg;
25
+ // do not process exp if this is v-on:arg - we need special handling
26
+ // for wrapping inline statements.
27
+ if (exp &&
28
+ exp.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */ &&
29
+ !(dir.name === 'on' && arg)) {
30
+ dir.exp = processExpression(exp, context,
31
+ // slot args must be processed as function params
32
+ dir.name === 'slot');
33
+ }
34
+ if (arg && arg.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */ && !arg.isStatic) {
35
+ dir.arg = processExpression(arg, context);
36
+ }
37
+ }
38
+ }
39
+ }
40
+ };
41
+ exports.transformExpression = transformExpression;
42
+ // Important: since this function uses Node.js only dependencies, it should
43
+ // always be used with a leading !__BROWSER__ check so that it can be
44
+ // tree-shaken from the browser build.
45
+ function processExpression(node, context,
46
+ // some expressions like v-slot props & v-for aliases should be parsed as
47
+ // function params
48
+ asParams = false,
49
+ // v-on handler values may contain multiple statements
50
+ asRawStatements = false, localVars = Object.create(context.identifiers)) {
51
+ if (!context.prefixIdentifiers || !node.content.trim()) {
52
+ return node;
53
+ }
54
+ const { bindingMetadata } = context;
55
+ const rewriteIdentifier = (raw, parent, id) => {
56
+ const type = (0, shared_1.hasOwn)(bindingMetadata, raw) && bindingMetadata[raw];
57
+ if (type && type.startsWith('setup')) {
58
+ // setup bindings in non-inline mode
59
+ return `$setup.${raw}`;
60
+ }
61
+ else if (type === "props-aliased" /* BindingTypes.PROPS_ALIASED */) {
62
+ return `$props['${bindingMetadata.__propsAliases[raw]}']`;
63
+ }
64
+ else if (type) {
65
+ return `$${type}.${raw}`;
66
+ }
67
+ // fallback to ctx
68
+ return `_ctx.${raw}`;
69
+ };
70
+ // fast path if expression is a simple identifier.
71
+ const rawExp = node.content;
72
+ // bail constant on parens (function invocation) and dot (member access)
73
+ const bailConstant = rawExp.indexOf(`(`) > -1 || rawExp.indexOf('.') > 0;
74
+ if ((0, compiler_core_1.isSimpleIdentifier)(rawExp)) {
75
+ const isScopeVarReference = context.identifiers[rawExp];
76
+ const isAllowedGlobal = isGloballyWhitelisted(rawExp);
77
+ const isLiteral = isLiteralWhitelisted(rawExp);
78
+ if (!asParams && !isScopeVarReference && !isAllowedGlobal && !isLiteral) {
79
+ // const bindings exposed from setup can be skipped for patching but
80
+ // cannot be hoisted to module scope
81
+ if (bindingMetadata[node.content] === "setup-const" /* BindingTypes.SETUP_CONST */) {
82
+ node.constType = 1 /* ConstantTypes.CAN_SKIP_PATCH */;
83
+ }
84
+ node.content = rewriteIdentifier(rawExp);
85
+ }
86
+ else if (!isScopeVarReference) {
87
+ if (isLiteral) {
88
+ node.constType = 3 /* ConstantTypes.CAN_STRINGIFY */;
89
+ }
90
+ else {
91
+ node.constType = 2 /* ConstantTypes.CAN_HOIST */;
92
+ }
93
+ }
94
+ return node;
95
+ }
96
+ let ast;
97
+ // exp needs to be parsed differently:
98
+ // 1. Multiple inline statements (v-on, with presence of `;`): parse as raw
99
+ // exp, but make sure to pad with spaces for consistent ranges
100
+ // 2. Expressions: wrap with parens (for e.g. object expressions)
101
+ // 3. Function arguments (v-for, v-slot): place in a function argument position
102
+ const source = asRawStatements
103
+ ? ` ${rawExp} `
104
+ : `(${rawExp})${asParams ? `=>{}` : ``}`;
105
+ try {
106
+ ast = (0, parser_1.parse)(source, {
107
+ // plugins: context.expressionPlugins
108
+ }).program;
109
+ }
110
+ catch (e) {
111
+ context.onError((0, errors_1.createCompilerError)(45 /* ErrorCodes.X_INVALID_EXPRESSION */, node.loc, undefined, e.message));
112
+ return node;
113
+ }
114
+ const ids = [];
115
+ const parentStack = [];
116
+ const knownIds = Object.create(context.identifiers);
117
+ (0, compiler_core_1.walkIdentifiers)(ast, (node, parent, _, isReferenced, isLocal) => {
118
+ if ((0, compiler_core_1.isStaticPropertyKey)(node, parent)) {
119
+ return;
120
+ }
121
+ const needPrefix = isReferenced && canPrefix(node);
122
+ if (needPrefix && !isLocal) {
123
+ if ((0, compiler_core_1.isStaticProperty)(parent) && parent.shorthand) {
124
+ // property shorthand like { foo }, we need to add the key since
125
+ // we rewrite the value
126
+ ;
127
+ node.prefix = `${node.name}: `;
128
+ }
129
+ node.name = rewriteIdentifier(node.name, parent, node);
130
+ ids.push(node);
131
+ }
132
+ else {
133
+ // The identifier is considered constant unless it's pointing to a
134
+ // local scope variable (a v-for alias, or a v-slot prop)
135
+ if (!(needPrefix && isLocal) && !bailConstant) {
136
+ ;
137
+ node.isConstant = true;
138
+ }
139
+ // also generate sub-expressions for other identifiers for better
140
+ // source map support. (except for property keys which are static)
141
+ ids.push(node);
142
+ }
143
+ }, true, // invoke on ALL identifiers
144
+ parentStack, knownIds);
145
+ // We break up the compound expression into an array of strings and sub
146
+ // expressions (for identifiers that have been prefixed). In codegen, if
147
+ // an ExpressionNode has the `.children` property, it will be used instead of
148
+ // `.content`.
149
+ const children = [];
150
+ ids.sort((a, b) => a.start - b.start);
151
+ ids.forEach((id, i) => {
152
+ // range is offset by -1 due to the wrapping parens when parsed
153
+ const start = id.start - 1;
154
+ const end = id.end - 1;
155
+ const last = ids[i - 1];
156
+ const leadingText = rawExp.slice(last ? last.end - 1 : 0, start);
157
+ if (leadingText.length || id.prefix) {
158
+ children.push(leadingText + (id.prefix || ``));
159
+ }
160
+ const source = rawExp.slice(start, end);
161
+ children.push((0, compiler_core_1.createSimpleExpression)(id.name, false, {
162
+ source,
163
+ start: (0, compiler_core_1.advancePositionWithClone)(node.loc.start, source, start),
164
+ end: (0, compiler_core_1.advancePositionWithClone)(node.loc.start, source, end),
165
+ }, id.isConstant ? 3 /* ConstantTypes.CAN_STRINGIFY */ : 0 /* ConstantTypes.NOT_CONSTANT */));
166
+ if (i === ids.length - 1 && end < rawExp.length) {
167
+ children.push(rawExp.slice(end));
168
+ }
169
+ });
170
+ let ret;
171
+ if (children.length) {
172
+ ret = (0, compiler_core_1.createCompoundExpression)(children, node.loc);
173
+ }
174
+ else {
175
+ ret = node;
176
+ ret.constType = bailConstant
177
+ ? 0 /* ConstantTypes.NOT_CONSTANT */
178
+ : 3 /* ConstantTypes.CAN_STRINGIFY */;
179
+ }
180
+ ret.identifiers = Object.keys(knownIds);
181
+ return ret;
182
+ }
183
+ exports.processExpression = processExpression;
184
+ function canPrefix(id) {
185
+ // skip whitelisted globals
186
+ if (isGloballyWhitelisted(id.name)) {
187
+ return false;
188
+ }
189
+ // special case for webpack compilation
190
+ if (id.name === 'require') {
191
+ return false;
192
+ }
193
+ return true;
194
+ }
195
+ function stringifyExpression(exp) {
196
+ if ((0, shared_1.isString)(exp)) {
197
+ return exp;
198
+ }
199
+ else if (exp.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */) {
200
+ return exp.content;
201
+ }
202
+ else {
203
+ return exp.children
204
+ .map(stringifyExpression)
205
+ .join('');
206
+ }
207
+ }
208
+ exports.stringifyExpression = stringifyExpression;
@@ -0,0 +1,4 @@
1
+ import { NodeTransform } from '../transform';
2
+ import { TextNode, InterpolationNode, TemplateChildNode } from '@vue/compiler-core';
3
+ export declare function isText(node: TemplateChildNode): node is TextNode | InterpolationNode;
4
+ export declare const transformInterpolation: NodeTransform;
@@ -0,0 +1,107 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.transformInterpolation = exports.isText = void 0;
4
+ const compiler_core_1 = require("@vue/compiler-core");
5
+ // import { CREATE_TEXT } from '../runtimeHelpers'
6
+ function isText(node) {
7
+ return node.type === 5 /* NodeTypes.INTERPOLATION */ || node.type === 2 /* NodeTypes.TEXT */;
8
+ }
9
+ exports.isText = isText;
10
+ // Merge adjacent text nodes and expressions into a single expression
11
+ // e.g. <div>abc {{ d }} {{ e }}</div> should have a single expression node as child.
12
+ const transformInterpolation = (node, context) => {
13
+ if (node.type === 0 /* NodeTypes.ROOT */ ||
14
+ node.type === 1 /* NodeTypes.ELEMENT */ ||
15
+ node.type === 11 /* NodeTypes.FOR */ ||
16
+ node.type === 10 /* NodeTypes.IF_BRANCH */) {
17
+ // perform the transform on node exit so that all expressions have already
18
+ // been processed.
19
+ return () => {
20
+ const children = node.children;
21
+ let currentContainer = undefined;
22
+ // let hasText = false
23
+ for (let i = 0; i < children.length; i++) {
24
+ const child = children[i];
25
+ if (isText(child)) {
26
+ // hasText = true
27
+ for (let j = i + 1; j < children.length; j++) {
28
+ const next = children[j];
29
+ if (isText(next)) {
30
+ if (!currentContainer) {
31
+ currentContainer = children[i] = (0, compiler_core_1.createCompoundExpression)([child], child.loc);
32
+ }
33
+ // merge adjacent text node into current
34
+ currentContainer.children.push(` + `, next);
35
+ children.splice(j, 1);
36
+ j--;
37
+ }
38
+ else {
39
+ currentContainer = undefined;
40
+ break;
41
+ }
42
+ }
43
+ }
44
+ }
45
+ // if (
46
+ // !hasText ||
47
+ // // if this is a plain element with a single text child, leave it
48
+ // // as-is since the runtime has dedicated fast path for this by directly
49
+ // // setting textContent of the element.
50
+ // // for component root it's always normalized anyway.
51
+ // (children.length === 1 &&
52
+ // (node.type === NodeTypes.ROOT ||
53
+ // (node.type === NodeTypes.ELEMENT &&
54
+ // node.tagType === ElementTypes.ELEMENT &&
55
+ // // #3756
56
+ // // custom directives can potentially add DOM elements arbitrarily,
57
+ // // we need to avoid setting textContent of the element at runtime
58
+ // // to avoid accidentally overwriting the DOM elements added
59
+ // // by the user through custom directives.
60
+ // !node.props.find(
61
+ // p =>
62
+ // p.type === NodeTypes.DIRECTIVE &&
63
+ // !context.directiveTransforms[p.name]
64
+ // ) &&
65
+ // // in compat mode, <template> tags with no special directives
66
+ // // will be rendered as a fragment so its children must be
67
+ // // converted into vnodes.
68
+ // (node.tag !== 'template'))))
69
+ // ) {
70
+ // return
71
+ // }
72
+ // pre-convert text nodes into createTextVNode(text) calls to avoid
73
+ // runtime normalization.
74
+ // for (let i = 0; i < children.length; i++) {
75
+ // const child = children[i]
76
+ // if (isText(child) || child.type === NodeTypes.COMPOUND_EXPRESSION) {
77
+ // const callArgs: CallExpression['arguments'] = []
78
+ // // createTextVNode defaults to single whitespace, so if it is a
79
+ // // single space the code could be an empty call to save bytes.
80
+ // if (child.type !== NodeTypes.TEXT || child.content !== ' ') {
81
+ // callArgs.push(child)
82
+ // }
83
+ // // mark dynamic text with flag so it gets patched inside a block
84
+ // if (
85
+ // !context.ssr &&
86
+ // getConstantType(child, context) === ConstantTypes.NOT_CONSTANT
87
+ // ) {
88
+ // callArgs.push(
89
+ // PatchFlags.TEXT +
90
+ // (__DEV__ ? ` /* ${PatchFlagNames[PatchFlags.TEXT]} */` : ``)
91
+ // )
92
+ // }
93
+ // children[i] = {
94
+ // type: NodeTypes.TEXT_CALL,
95
+ // content: child,
96
+ // loc: child.loc,
97
+ // codegenNode: createCallExpression(
98
+ // context.helper(CREATE_TEXT),
99
+ // callArgs
100
+ // )
101
+ // }
102
+ // }
103
+ // }
104
+ };
105
+ }
106
+ };
107
+ exports.transformInterpolation = transformInterpolation;
@@ -0,0 +1,10 @@
1
+ import { NodeTransform, TransformContext } from '../transform';
2
+ import { ExpressionNode, SlotOutletNode } from '@vue/compiler-core';
3
+ import { PropsExpression } from '@vue/compiler-core';
4
+ export declare const transformSlotOutlet: NodeTransform;
5
+ interface SlotOutletProcessResult {
6
+ slotName: string | ExpressionNode;
7
+ slotProps: PropsExpression | undefined;
8
+ }
9
+ export declare function processSlotOutlet(node: SlotOutletNode, context: TransformContext): SlotOutletProcessResult;
10
+ export {};
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.processSlotOutlet = exports.transformSlotOutlet = void 0;
4
+ const compiler_core_1 = require("@vue/compiler-core");
5
+ const compiler_core_2 = require("@vue/compiler-core");
6
+ const runtimeHelpers_1 = require("../runtimeHelpers");
7
+ const shared_1 = require("@vue/shared");
8
+ const transformSlotOutlet = (node, context) => {
9
+ if ((0, compiler_core_2.isSlotOutlet)(node)) {
10
+ const { children, loc } = node;
11
+ const { slotName, slotProps } = processSlotOutlet(node, context);
12
+ const slotArgs = [
13
+ context.prefixIdentifiers ? `_ctx.$slots` : `$slots`,
14
+ slotName,
15
+ '{}',
16
+ 'undefined',
17
+ 'true',
18
+ ];
19
+ let expectedLen = 2;
20
+ if (slotProps) {
21
+ slotArgs[2] = slotProps;
22
+ expectedLen = 3;
23
+ }
24
+ if (children.length) {
25
+ slotArgs[3] = (0, compiler_core_1.createFunctionExpression)([], children, false, false, loc);
26
+ expectedLen = 4;
27
+ }
28
+ if (context.scopeId && !context.slotted) {
29
+ expectedLen = 5;
30
+ }
31
+ slotArgs.splice(expectedLen) // remove unused arguments
32
+ ;
33
+ node.codegenNode = (0, compiler_core_1.createCallExpression)(context.helper(runtimeHelpers_1.RENDER_SLOT), slotArgs, loc);
34
+ }
35
+ };
36
+ exports.transformSlotOutlet = transformSlotOutlet;
37
+ function processSlotOutlet(node, context) {
38
+ let slotName = `"default"`;
39
+ let slotProps = undefined;
40
+ const nonNameProps = [];
41
+ for (let i = 0; i < node.props.length; i++) {
42
+ const p = node.props[i];
43
+ if (p.type === 6 /* NodeTypes.ATTRIBUTE */) {
44
+ if (p.value) {
45
+ if (p.name === 'name') {
46
+ slotName = JSON.stringify(p.value.content);
47
+ }
48
+ else {
49
+ p.name = (0, shared_1.camelize)(p.name);
50
+ nonNameProps.push(p);
51
+ }
52
+ }
53
+ }
54
+ else {
55
+ if (p.name === 'bind' && (0, compiler_core_2.isStaticArgOf)(p.arg, 'name')) {
56
+ if (p.exp)
57
+ slotName = p.exp;
58
+ }
59
+ else {
60
+ if (p.name === 'bind' && p.arg && (0, compiler_core_2.isStaticExp)(p.arg)) {
61
+ p.arg.content = (0, shared_1.camelize)(p.arg.content);
62
+ }
63
+ nonNameProps.push(p);
64
+ }
65
+ }
66
+ }
67
+ if (nonNameProps.length > 0) {
68
+ const { props, directives } = (0, compiler_core_1.buildProps)(node, context, nonNameProps, false, false);
69
+ slotProps = props;
70
+ if (directives.length) {
71
+ context.onError((0, compiler_core_1.createCompilerError)(36 /* ErrorCodes.X_V_SLOT_UNEXPECTED_DIRECTIVE_ON_SLOT_OUTLET */, directives[0].loc));
72
+ }
73
+ }
74
+ return {
75
+ slotName,
76
+ slotProps,
77
+ };
78
+ }
79
+ exports.processSlotOutlet = processSlotOutlet;
@@ -0,0 +1,2 @@
1
+ import { NodeTransform } from '../transform';
2
+ export declare const transformText: NodeTransform;
@@ -0,0 +1,99 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.transformText = void 0;
4
+ const uni_cli_shared_1 = require("@dcloudio/uni-cli-shared");
5
+ function isTextNode({ tag }) {
6
+ return tag === 'text' || tag === 'u-text' || tag === 'button';
7
+ }
8
+ function isTextElement(node) {
9
+ return node.type === 1 /* NodeTypes.ELEMENT */ && node.tag === 'text';
10
+ }
11
+ function isText(node) {
12
+ const { type } = node;
13
+ return (type === 2 /* NodeTypes.TEXT */ ||
14
+ type === 12 /* NodeTypes.TEXT_CALL */ ||
15
+ type === 5 /* NodeTypes.INTERPOLATION */ ||
16
+ type === 8 /* NodeTypes.COMPOUND_EXPRESSION */);
17
+ }
18
+ const transformText = (node, _) => {
19
+ if (!(0, uni_cli_shared_1.isElementNode)(node)) {
20
+ return;
21
+ }
22
+ if (isTextNode(node)) {
23
+ return;
24
+ }
25
+ const { children } = node;
26
+ if (!children.length) {
27
+ return;
28
+ }
29
+ for (let i = 0; i < children.length; i++) {
30
+ const child = children[i];
31
+ if (isTextElement(child)) {
32
+ parseText(child);
33
+ }
34
+ let currentContainer = undefined;
35
+ if (isText(child)) {
36
+ if (!currentContainer) {
37
+ currentContainer = children[i] = createText(node, child);
38
+ }
39
+ for (let j = i + 1; j < children.length; j++) {
40
+ const next = children[j];
41
+ if (isText(next)) {
42
+ // 合并相邻的文本节点
43
+ currentContainer.children.push(next);
44
+ children.splice(j, 1);
45
+ j--;
46
+ }
47
+ else {
48
+ currentContainer = undefined;
49
+ break;
50
+ }
51
+ }
52
+ }
53
+ }
54
+ };
55
+ exports.transformText = transformText;
56
+ /*
57
+ 1. 转换 \\n 为 \n
58
+ 2. u-text 下仅支持 slot 及 文本节点
59
+ */
60
+ function parseText(node) {
61
+ if (node.children.length) {
62
+ let firstTextChild;
63
+ for (let i = 0; i < node.children.length; i++) {
64
+ const child = node.children[i];
65
+ if (isText(child) && typeof child.content === 'string') {
66
+ if (!firstTextChild) {
67
+ firstTextChild = child;
68
+ firstTextChild.content = firstTextChild.content.replace(/\\n/g, '\n');
69
+ }
70
+ else {
71
+ ;
72
+ firstTextChild.content += child.content.replace(/\\n/g, '\n');
73
+ node.children.splice(i, 1);
74
+ i--;
75
+ }
76
+ }
77
+ else if (child.type === 3) {
78
+ node.children.splice(i, 1);
79
+ i--;
80
+ }
81
+ else {
82
+ firstTextChild = null;
83
+ }
84
+ }
85
+ }
86
+ }
87
+ function createText(parent, node) {
88
+ return {
89
+ tag: 'text',
90
+ type: 1 /* NodeTypes.ELEMENT */,
91
+ tagType: 0 /* ElementTypes.ELEMENT */,
92
+ props: [],
93
+ isSelfClosing: false,
94
+ children: [node],
95
+ codegenNode: undefined,
96
+ ns: parent.ns,
97
+ loc: node.loc,
98
+ };
99
+ }
@@ -0,0 +1,2 @@
1
+ import { DirectiveTransform } from '../transform';
2
+ export declare const transformBind: DirectiveTransform;
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.transformBind = void 0;
4
+ const compiler_core_1 = require("@vue/compiler-core");
5
+ const errors_1 = require("../errors");
6
+ const shared_1 = require("@vue/shared");
7
+ const compiler_core_2 = require("@vue/compiler-core");
8
+ const utils_1 = require("../utils");
9
+ // v-bind without arg is handled directly in ./transformElements.ts due to it affecting
10
+ // codegen for the entire props object. This transform here is only for v-bind
11
+ // *with* args.
12
+ const transformBind = (dir, _node, context) => {
13
+ const { exp, modifiers, loc } = dir;
14
+ const arg = dir.arg;
15
+ if (arg.type !== 4 /* NodeTypes.SIMPLE_EXPRESSION */) {
16
+ arg.children.unshift(`(`);
17
+ arg.children.push(`) || ""`);
18
+ }
19
+ else if (!arg.isStatic) {
20
+ arg.content = `${arg.content} !== null ? ${arg.content} : ""`;
21
+ }
22
+ // .sync is replaced by v-model:arg
23
+ if (modifiers.includes('camel')) {
24
+ if (arg.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */) {
25
+ if (arg.isStatic) {
26
+ arg.content = (0, shared_1.camelize)(arg.content);
27
+ }
28
+ else {
29
+ arg.content = `${context.helperString(compiler_core_2.CAMELIZE)}(${arg.content})`;
30
+ }
31
+ }
32
+ else {
33
+ arg.children.unshift(`${context.helperString(compiler_core_2.CAMELIZE)}(`);
34
+ arg.children.push(`)`);
35
+ }
36
+ }
37
+ if (!false) {
38
+ if (modifiers.includes('prop')) {
39
+ injectPrefix(arg, '.');
40
+ }
41
+ if (modifiers.includes('attr')) {
42
+ injectPrefix(arg, '^');
43
+ }
44
+ }
45
+ if (!exp ||
46
+ (exp.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */ && !exp.content.trim())) {
47
+ context.onError((0, errors_1.createCompilerError)(34 /* ErrorCodes.X_V_BIND_NO_EXPRESSION */, loc));
48
+ return {
49
+ props: [(0, compiler_core_1.createObjectProperty)(arg, (0, compiler_core_1.createSimpleExpression)('', true, loc))],
50
+ };
51
+ }
52
+ if (exp.content && utils_1.objectExp.test(exp.content)) {
53
+ ;
54
+ exp.content = (0, utils_1.object2Map)(exp);
55
+ }
56
+ else if (exp.children) {
57
+ ;
58
+ exp.children.forEach((child, index) => {
59
+ if (typeof child === 'string' && utils_1.objectExp.test(child)) {
60
+ ;
61
+ exp.children[index] = (0, utils_1.object2Map)(child);
62
+ }
63
+ });
64
+ }
65
+ return {
66
+ props: [(0, compiler_core_1.createObjectProperty)(arg, exp)],
67
+ };
68
+ };
69
+ exports.transformBind = transformBind;
70
+ const injectPrefix = (arg, prefix) => {
71
+ if (arg.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */) {
72
+ if (arg.isStatic) {
73
+ arg.content = prefix + arg.content;
74
+ }
75
+ else {
76
+ arg.content = `\`${prefix}\${${arg.content}}\``;
77
+ }
78
+ }
79
+ else {
80
+ arg.children.unshift(`'${prefix}' + (`);
81
+ arg.children.push(`)`);
82
+ }
83
+ };
@@ -0,0 +1,12 @@
1
+ import { ExpressionNode, SimpleExpressionNode, ElementNode, DirectiveNode, ForNode } from '@vue/compiler-core';
2
+ import { TransformContext } from '../transform';
3
+ export declare const transformFor: import("../transform").NodeTransform;
4
+ export declare function processFor(node: ElementNode, dir: DirectiveNode, context: TransformContext, processCodegen?: (forNode: ForNode) => (() => void) | undefined): (() => void) | undefined;
5
+ export interface ForParseResult {
6
+ source: ExpressionNode;
7
+ value: ExpressionNode | undefined;
8
+ key: ExpressionNode | undefined;
9
+ index: ExpressionNode | undefined;
10
+ }
11
+ export declare function parseForExpression(input: SimpleExpressionNode, context: TransformContext): ForParseResult | undefined;
12
+ export declare function createForLoopParams({ value, key, index }: ForParseResult, memoArgs?: ExpressionNode[]): ExpressionNode[];