@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.
- package/LICENSE +202 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +30 -0
- package/dist/plugins/css.d.ts +2 -0
- package/dist/plugins/css.js +94 -0
- package/dist/plugins/index.d.ts +2 -0
- package/dist/plugins/index.js +203 -0
- package/dist/plugins/mainUTS.d.ts +2 -0
- package/dist/plugins/mainUTS.js +24 -0
- package/dist/plugins/manifestJson.d.ts +2 -0
- package/dist/plugins/manifestJson.js +68 -0
- package/dist/plugins/pagesJson.d.ts +2 -0
- package/dist/plugins/pagesJson.js +84 -0
- package/dist/plugins/pre.d.ts +7 -0
- package/dist/plugins/pre.js +52 -0
- package/dist/plugins/utils.d.ts +8 -0
- package/dist/plugins/utils.js +85 -0
- package/dist/plugins/uvue/code/script.d.ts +4 -0
- package/dist/plugins/uvue/code/script.js +14 -0
- package/dist/plugins/uvue/code/style.d.ts +12 -0
- package/dist/plugins/uvue/code/style.js +90 -0
- package/dist/plugins/uvue/code/template.d.ts +3 -0
- package/dist/plugins/uvue/code/template.js +16 -0
- package/dist/plugins/uvue/compiler/codegen.d.ts +22 -0
- package/dist/plugins/uvue/compiler/codegen.js +579 -0
- package/dist/plugins/uvue/compiler/errors.d.ts +70 -0
- package/dist/plugins/uvue/compiler/errors.js +82 -0
- package/dist/plugins/uvue/compiler/index.d.ts +9 -0
- package/dist/plugins/uvue/compiler/index.js +65 -0
- package/dist/plugins/uvue/compiler/options.d.ts +92 -0
- package/dist/plugins/uvue/compiler/options.js +2 -0
- package/dist/plugins/uvue/compiler/runtimeHelpers.d.ts +10 -0
- package/dist/plugins/uvue/compiler/runtimeHelpers.js +25 -0
- package/dist/plugins/uvue/compiler/transform.d.ts +53 -0
- package/dist/plugins/uvue/compiler/transform.js +294 -0
- package/dist/plugins/uvue/compiler/transforms/transformExpression.d.ts +5 -0
- package/dist/plugins/uvue/compiler/transforms/transformExpression.js +208 -0
- package/dist/plugins/uvue/compiler/transforms/transformInterpolation.d.ts +4 -0
- package/dist/plugins/uvue/compiler/transforms/transformInterpolation.js +107 -0
- package/dist/plugins/uvue/compiler/transforms/transformSlotOutlet.d.ts +10 -0
- package/dist/plugins/uvue/compiler/transforms/transformSlotOutlet.js +79 -0
- package/dist/plugins/uvue/compiler/transforms/transformText.d.ts +2 -0
- package/dist/plugins/uvue/compiler/transforms/transformText.js +99 -0
- package/dist/plugins/uvue/compiler/transforms/vBind.d.ts +2 -0
- package/dist/plugins/uvue/compiler/transforms/vBind.js +83 -0
- package/dist/plugins/uvue/compiler/transforms/vFor.d.ts +12 -0
- package/dist/plugins/uvue/compiler/transforms/vFor.js +325 -0
- package/dist/plugins/uvue/compiler/transforms/vIf.d.ts +4 -0
- package/dist/plugins/uvue/compiler/transforms/vIf.js +212 -0
- package/dist/plugins/uvue/compiler/transforms/vModel.d.ts +2 -0
- package/dist/plugins/uvue/compiler/transforms/vModel.js +51 -0
- package/dist/plugins/uvue/compiler/transforms/vOn.d.ts +8 -0
- package/dist/plugins/uvue/compiler/transforms/vOn.js +136 -0
- package/dist/plugins/uvue/compiler/transforms/vShow.d.ts +2 -0
- package/dist/plugins/uvue/compiler/transforms/vShow.js +11 -0
- package/dist/plugins/uvue/compiler/transforms/vText.d.ts +2 -0
- package/dist/plugins/uvue/compiler/transforms/vText.js +29 -0
- package/dist/plugins/uvue/compiler/utils.d.ts +5 -0
- package/dist/plugins/uvue/compiler/utils.js +37 -0
- package/dist/plugins/uvue/descriptorCache.d.ts +24 -0
- package/dist/plugins/uvue/descriptorCache.js +57 -0
- package/dist/plugins/uvue/error.d.ts +3 -0
- package/dist/plugins/uvue/error.js +22 -0
- package/dist/plugins/uvue/index.d.ts +13 -0
- package/dist/plugins/uvue/index.js +188 -0
- package/lib/automator/apis/App.uts +144 -0
- package/lib/automator/apis/Page.uts +55 -0
- package/lib/automator/apis/util.uts +63 -0
- package/lib/automator/index.uts +106 -0
- package/package.json +42 -0
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.transformOn = exports.inlineStatementCannotUseEventMsg = void 0;
|
|
4
|
+
const compiler_core_1 = require("@vue/compiler-core");
|
|
5
|
+
const shared_1 = require("@vue/shared");
|
|
6
|
+
const errors_1 = require("../errors");
|
|
7
|
+
const transformExpression_1 = require("./transformExpression");
|
|
8
|
+
const fnExpRE = /^\s*([\w$_]+|(async\s*)?\([^)]*?\))\s*(:[^=]+)?=>|^\s*(async\s+)?function(?:\s+[\w$]+)?\s*\(/;
|
|
9
|
+
exports.inlineStatementCannotUseEventMsg = 'Inline statement cannot use $event, please use a function expression instead.';
|
|
10
|
+
// TODO: inline statement $event type complement
|
|
11
|
+
const transformOn = (dir, node, context, augmentor) => {
|
|
12
|
+
const { loc, modifiers, arg } = dir;
|
|
13
|
+
if (loc.source.indexOf('($event)') !== -1) {
|
|
14
|
+
throw new Error(exports.inlineStatementCannotUseEventMsg);
|
|
15
|
+
}
|
|
16
|
+
if (!dir.exp && !modifiers.length) {
|
|
17
|
+
context.onError((0, errors_1.createCompilerError)(35 /* ErrorCodes.X_V_ON_NO_EXPRESSION */, loc));
|
|
18
|
+
}
|
|
19
|
+
let eventName;
|
|
20
|
+
if (arg.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */) {
|
|
21
|
+
if (arg.isStatic) {
|
|
22
|
+
let rawName = arg.content;
|
|
23
|
+
// TODO deprecate @vnodeXXX usage
|
|
24
|
+
if (rawName.startsWith('vue:')) {
|
|
25
|
+
rawName = `vnode-${rawName.slice(4)}`;
|
|
26
|
+
}
|
|
27
|
+
const eventString = node.tagType !== 0 /* ElementTypes.ELEMENT */ ||
|
|
28
|
+
rawName.startsWith('vnode') ||
|
|
29
|
+
!/[A-Z]/.test(rawName)
|
|
30
|
+
? // for non-element and vnode lifecycle event listeners, auto convert
|
|
31
|
+
// it to camelCase. See issue #2249
|
|
32
|
+
(0, shared_1.toHandlerKey)((0, shared_1.camelize)(rawName))
|
|
33
|
+
: // preserve case for plain element listeners that have uppercase
|
|
34
|
+
// letters, as these may be custom elements' custom events
|
|
35
|
+
`on:${rawName}`;
|
|
36
|
+
eventName = (0, compiler_core_1.createSimpleExpression)(eventString, true, arg.loc);
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
// #2388
|
|
40
|
+
eventName = (0, compiler_core_1.createCompoundExpression)([
|
|
41
|
+
`${context.helperString(compiler_core_1.TO_HANDLER_KEY)}(`,
|
|
42
|
+
arg,
|
|
43
|
+
`)`,
|
|
44
|
+
]);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
// already a compound expression.
|
|
49
|
+
eventName = arg;
|
|
50
|
+
eventName.children.unshift(`${context.helperString(compiler_core_1.TO_HANDLER_KEY)}(`);
|
|
51
|
+
eventName.children.push(`)`);
|
|
52
|
+
}
|
|
53
|
+
// handler processing
|
|
54
|
+
let exp = dir.exp;
|
|
55
|
+
if (exp && !exp.content.trim()) {
|
|
56
|
+
exp = undefined;
|
|
57
|
+
}
|
|
58
|
+
// @ts-ignore
|
|
59
|
+
let shouldCache = context.cacheHandlers && !exp && !context.inVOnce;
|
|
60
|
+
if (exp) {
|
|
61
|
+
// @ts-ignore
|
|
62
|
+
const isMemberExp = (0, compiler_core_1.isMemberExpression)(exp.content, context);
|
|
63
|
+
const isInlineStatement = !(isMemberExp || fnExpRE.test(exp.content));
|
|
64
|
+
const hasMultipleStatements = exp.content.includes(`;`);
|
|
65
|
+
// process the expression since it's been skipped
|
|
66
|
+
if (context.prefixIdentifiers) {
|
|
67
|
+
isInlineStatement && context.addIdentifiers(`$event`);
|
|
68
|
+
exp = dir.exp = (0, transformExpression_1.processExpression)(exp, context, false, hasMultipleStatements);
|
|
69
|
+
isInlineStatement && context.removeIdentifiers(`$event`);
|
|
70
|
+
// with scope analysis, the function is hoistable if it has no reference
|
|
71
|
+
// to scope variables.
|
|
72
|
+
shouldCache =
|
|
73
|
+
// @ts-ignore
|
|
74
|
+
context.cacheHandlers &&
|
|
75
|
+
// unnecessary to cache inside v-once
|
|
76
|
+
!context.inVOnce &&
|
|
77
|
+
// runtime constants don't need to be cached
|
|
78
|
+
// (this is analyzed by compileScript in SFC <script setup>)
|
|
79
|
+
!(exp.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */ && exp.constType > 0) &&
|
|
80
|
+
// #1541 bail if this is a member exp handler passed to a component -
|
|
81
|
+
// we need to use the original function to preserve arity,
|
|
82
|
+
// e.g. <transition> relies on checking cb.length to determine
|
|
83
|
+
// transition end handling. Inline function is ok since its arity
|
|
84
|
+
// is preserved even when cached.
|
|
85
|
+
!(isMemberExp && node.tagType === 1 /* ElementTypes.COMPONENT */) &&
|
|
86
|
+
// bail if the function references closure variables (v-for, v-slot)
|
|
87
|
+
// it must be passed fresh to avoid stale values.
|
|
88
|
+
!(0, compiler_core_1.hasScopeRef)(exp, context.identifiers);
|
|
89
|
+
// If the expression is optimizable and is a member expression pointing
|
|
90
|
+
// to a function, turn it into invocation (and wrap in an arrow function
|
|
91
|
+
// below) so that it always accesses the latest value when called - thus
|
|
92
|
+
// avoiding the need to be patched.
|
|
93
|
+
if (shouldCache && isMemberExp) {
|
|
94
|
+
if (exp.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */) {
|
|
95
|
+
exp.content = `${exp.content} && ${exp.content}(...args)`;
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
exp.children = [...exp.children, ` && `, ...exp.children, `(...args)`];
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
if (isInlineStatement || (shouldCache && isMemberExp)) {
|
|
103
|
+
// wrap inline statement in a function expression
|
|
104
|
+
if (isInlineStatement && exp.loc.source.includes('$event')) {
|
|
105
|
+
throw new Error(exports.inlineStatementCannotUseEventMsg);
|
|
106
|
+
}
|
|
107
|
+
exp = (0, compiler_core_1.createCompoundExpression)([
|
|
108
|
+
`${isInlineStatement ? `()` : `${``}(...args)`
|
|
109
|
+
// } => ${hasMultipleStatements ? `{` : `(`}`,
|
|
110
|
+
} => ${`{`}`,
|
|
111
|
+
exp,
|
|
112
|
+
// hasMultipleStatements ? `}` : `)`
|
|
113
|
+
`}`,
|
|
114
|
+
]);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
let ret = {
|
|
118
|
+
props: [
|
|
119
|
+
(0, compiler_core_1.createObjectProperty)(eventName, exp || (0, compiler_core_1.createSimpleExpression)(`() => {}`, false, loc)),
|
|
120
|
+
],
|
|
121
|
+
};
|
|
122
|
+
// apply extended compiler augmentor
|
|
123
|
+
if (augmentor) {
|
|
124
|
+
ret = augmentor(ret);
|
|
125
|
+
}
|
|
126
|
+
if (shouldCache) {
|
|
127
|
+
// cache handlers so that it's always the same handler being passed down.
|
|
128
|
+
// this avoids unnecessary re-renders when users use inline handlers on
|
|
129
|
+
// components.
|
|
130
|
+
ret.props[0].value = context.cache(ret.props[0].value);
|
|
131
|
+
}
|
|
132
|
+
// mark the key as handler for props normalization check
|
|
133
|
+
ret.props.forEach((p) => (p.key.isHandlerKey = true));
|
|
134
|
+
return ret;
|
|
135
|
+
};
|
|
136
|
+
exports.transformOn = transformOn;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.transformShow = void 0;
|
|
4
|
+
const runtimeHelpers_1 = require("../runtimeHelpers");
|
|
5
|
+
const transformShow = (dir, node, context) => {
|
|
6
|
+
return {
|
|
7
|
+
props: [],
|
|
8
|
+
needRuntime: context.helper(runtimeHelpers_1.V_SHOW),
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
exports.transformShow = transformShow;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.transformVText = void 0;
|
|
4
|
+
const compiler_core_1 = require("@vue/compiler-core");
|
|
5
|
+
// import { createDOMCompilerError, DOMErrorCodes } from '../errors'
|
|
6
|
+
const transformVText = (dir, node, context) => {
|
|
7
|
+
const { exp, loc } = dir;
|
|
8
|
+
// if (!exp) {
|
|
9
|
+
// context.onError(
|
|
10
|
+
// createDOMCompilerError(DOMErrorCodes.X_V_TEXT_NO_EXPRESSION, loc)
|
|
11
|
+
// )
|
|
12
|
+
// }
|
|
13
|
+
// if (node.children.length) {
|
|
14
|
+
// context.onError(
|
|
15
|
+
// createDOMCompilerError(DOMErrorCodes.X_V_TEXT_WITH_CHILDREN, loc)
|
|
16
|
+
// )
|
|
17
|
+
// node.children.length = 0
|
|
18
|
+
// }
|
|
19
|
+
return {
|
|
20
|
+
props: [
|
|
21
|
+
(0, compiler_core_1.createObjectProperty)((0, compiler_core_1.createSimpleExpression)(`value`, true), exp
|
|
22
|
+
? (0, compiler_core_1.getConstantType)(exp, context) > 0
|
|
23
|
+
? exp
|
|
24
|
+
: (0, compiler_core_1.createCallExpression)(context.helperString(compiler_core_1.TO_DISPLAY_STRING), [exp], loc)
|
|
25
|
+
: (0, compiler_core_1.createSimpleExpression)('', true)),
|
|
26
|
+
],
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
exports.transformVText = transformVText;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { CompilerOptions } from './options';
|
|
2
|
+
import { ExpressionNode } from '@vue/compiler-core';
|
|
3
|
+
export declare function genRenderFunctionDecl({ targetLanguage, filename, }: CompilerOptions): string;
|
|
4
|
+
export declare const objectExp: RegExp;
|
|
5
|
+
export declare function object2Map(exp: ExpressionNode | string, wrap?: boolean): string;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.object2Map = exports.objectExp = exports.genRenderFunctionDecl = void 0;
|
|
4
|
+
const shared_1 = require("@vue/shared");
|
|
5
|
+
function genRenderFunctionDecl({ targetLanguage, filename, }) {
|
|
6
|
+
return `${targetLanguage === 'kotlin' ? '@Suppress("UNUSED_PARAMETER") ' : ''}function ${filename}Render(_ctx: ${filename}): VNode | null`;
|
|
7
|
+
}
|
|
8
|
+
exports.genRenderFunctionDecl = genRenderFunctionDecl;
|
|
9
|
+
exports.objectExp = /\{.*\}/g;
|
|
10
|
+
function object2Map(exp, wrap = true) {
|
|
11
|
+
const content = (0, shared_1.isString)(exp) ? exp : exp.content;
|
|
12
|
+
const matched = content.match(exports.objectExp)[0];
|
|
13
|
+
const keyValues = matched.replace(/\{|\}/g, '').split(',');
|
|
14
|
+
let mapConstructor = wrap ? 'new Map<string, any | null>([' : '';
|
|
15
|
+
keyValues.forEach((keyValue, index) => {
|
|
16
|
+
const colonIndex = keyValue.indexOf(':');
|
|
17
|
+
const key = needAddQuotes(exp, keyValue)
|
|
18
|
+
? `'${keyValue.substring(0, colonIndex)}'`
|
|
19
|
+
: keyValue.substring(0, colonIndex);
|
|
20
|
+
const value = keyValue.substring(colonIndex + 1);
|
|
21
|
+
if (key && value) {
|
|
22
|
+
mapConstructor += `[${key},${value}]`;
|
|
23
|
+
if (index < keyValues.length - 1) {
|
|
24
|
+
mapConstructor += ',';
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
mapConstructor += wrap ? '])' : '';
|
|
29
|
+
return content.replace(matched, mapConstructor);
|
|
30
|
+
}
|
|
31
|
+
exports.object2Map = object2Map;
|
|
32
|
+
function needAddQuotes(exp, keyValue) {
|
|
33
|
+
return (!(0, shared_1.isString)(exp) &&
|
|
34
|
+
exp.constType === 3 /* ConstantTypes.CAN_STRINGIFY */ &&
|
|
35
|
+
!keyValue.startsWith("'") &&
|
|
36
|
+
!keyValue.startsWith('"'));
|
|
37
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type * as _compiler from '@vue/compiler-sfc';
|
|
2
|
+
import type { CompilerError, SFCDescriptor } from '@vue/compiler-sfc';
|
|
3
|
+
export interface ResolvedOptions {
|
|
4
|
+
compiler: typeof _compiler;
|
|
5
|
+
root: string;
|
|
6
|
+
sourceMap: boolean;
|
|
7
|
+
targetLanguage?: 'kotlin' | 'swift' | 'javascript';
|
|
8
|
+
classNamePrefix?: string;
|
|
9
|
+
}
|
|
10
|
+
export interface SFCParseResult {
|
|
11
|
+
descriptor: SFCDescriptor;
|
|
12
|
+
errors: Array<CompilerError | SyntaxError>;
|
|
13
|
+
}
|
|
14
|
+
declare module '@vue/compiler-sfc' {
|
|
15
|
+
interface SFCDescriptor {
|
|
16
|
+
id: string;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
export declare function createDescriptor(filename: string, source: string, { root, sourceMap, compiler }: ResolvedOptions): SFCParseResult;
|
|
20
|
+
export declare function getPrevDescriptor(filename: string): SFCDescriptor | undefined;
|
|
21
|
+
export declare function setPrevDescriptor(filename: string, entry: SFCDescriptor): void;
|
|
22
|
+
export declare function getDescriptor(filename: string, options: ResolvedOptions, createIfNotFound?: boolean): SFCDescriptor | undefined;
|
|
23
|
+
export declare function getSrcDescriptor(filename: string): SFCDescriptor;
|
|
24
|
+
export declare function setSrcDescriptor(filename: string, entry: SFCDescriptor): void;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.setSrcDescriptor = exports.getSrcDescriptor = exports.getDescriptor = exports.setPrevDescriptor = exports.getPrevDescriptor = exports.createDescriptor = void 0;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const crypto_1 = require("crypto");
|
|
10
|
+
const uni_cli_shared_1 = require("@dcloudio/uni-cli-shared");
|
|
11
|
+
const cache = new Map();
|
|
12
|
+
const prevCache = new Map();
|
|
13
|
+
function createDescriptor(filename, source, { root, sourceMap, compiler }) {
|
|
14
|
+
const { descriptor, errors } = compiler.parse(source, {
|
|
15
|
+
filename,
|
|
16
|
+
sourceMap,
|
|
17
|
+
});
|
|
18
|
+
// ensure the path is normalized in a way that is consistent inside
|
|
19
|
+
// project (relative to root) and on different systems.
|
|
20
|
+
const normalizedPath = (0, uni_cli_shared_1.normalizePath)(path_1.default.normalize(path_1.default.relative(root, filename)));
|
|
21
|
+
descriptor.id = getHash(normalizedPath);
|
|
22
|
+
cache.set(filename, descriptor);
|
|
23
|
+
return { descriptor, errors };
|
|
24
|
+
}
|
|
25
|
+
exports.createDescriptor = createDescriptor;
|
|
26
|
+
function getPrevDescriptor(filename) {
|
|
27
|
+
return prevCache.get(filename);
|
|
28
|
+
}
|
|
29
|
+
exports.getPrevDescriptor = getPrevDescriptor;
|
|
30
|
+
function setPrevDescriptor(filename, entry) {
|
|
31
|
+
prevCache.set(filename, entry);
|
|
32
|
+
}
|
|
33
|
+
exports.setPrevDescriptor = setPrevDescriptor;
|
|
34
|
+
function getDescriptor(filename, options, createIfNotFound = true) {
|
|
35
|
+
if (cache.has(filename)) {
|
|
36
|
+
return cache.get(filename);
|
|
37
|
+
}
|
|
38
|
+
if (createIfNotFound) {
|
|
39
|
+
const { descriptor, errors } = createDescriptor(filename, fs_1.default.readFileSync(filename, 'utf-8'), options);
|
|
40
|
+
if (errors.length) {
|
|
41
|
+
throw errors[0];
|
|
42
|
+
}
|
|
43
|
+
return descriptor;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
exports.getDescriptor = getDescriptor;
|
|
47
|
+
function getSrcDescriptor(filename) {
|
|
48
|
+
return cache.get(filename);
|
|
49
|
+
}
|
|
50
|
+
exports.getSrcDescriptor = getSrcDescriptor;
|
|
51
|
+
function setSrcDescriptor(filename, entry) {
|
|
52
|
+
cache.set(filename, entry);
|
|
53
|
+
}
|
|
54
|
+
exports.setSrcDescriptor = setSrcDescriptor;
|
|
55
|
+
function getHash(text) {
|
|
56
|
+
return (0, crypto_1.createHash)('sha256').update(text).digest('hex').substring(0, 8);
|
|
57
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createRollupError = void 0;
|
|
4
|
+
function createRollupError(id, error) {
|
|
5
|
+
const { message, name, stack } = error;
|
|
6
|
+
const rollupError = {
|
|
7
|
+
id,
|
|
8
|
+
plugin: 'vue',
|
|
9
|
+
message,
|
|
10
|
+
name,
|
|
11
|
+
stack,
|
|
12
|
+
};
|
|
13
|
+
if ('code' in error && error.loc) {
|
|
14
|
+
rollupError.loc = {
|
|
15
|
+
file: id,
|
|
16
|
+
line: error.loc.start.line,
|
|
17
|
+
column: error.loc.start.column,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
return rollupError;
|
|
21
|
+
}
|
|
22
|
+
exports.createRollupError = createRollupError;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Plugin } from 'vite';
|
|
2
|
+
import type { SFCDescriptor, SFCParseResult } from '@vue/compiler-sfc';
|
|
3
|
+
import type { TransformPluginContext } from 'rollup';
|
|
4
|
+
import { ResolvedOptions } from './descriptorCache';
|
|
5
|
+
export declare function uniAppUVuePlugin(): Plugin;
|
|
6
|
+
interface TransformVueResult {
|
|
7
|
+
errors: SFCParseResult['errors'];
|
|
8
|
+
uts?: string;
|
|
9
|
+
js?: string;
|
|
10
|
+
descriptor: SFCDescriptor;
|
|
11
|
+
}
|
|
12
|
+
export declare function transformVue(code: string, filename: string, options: ResolvedOptions, pluginContext: TransformPluginContext | undefined, isAppVue: ((id: string) => boolean) | undefined, normalizeEasyComSource: (source: string) => string): Promise<TransformVueResult>;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.transformVue = exports.uniAppUVuePlugin = void 0;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
9
|
+
const shared_1 = require("@vue/shared");
|
|
10
|
+
const uni_cli_shared_1 = require("@dcloudio/uni-cli-shared");
|
|
11
|
+
const descriptorCache_1 = require("./descriptorCache");
|
|
12
|
+
const error_1 = require("./error");
|
|
13
|
+
const utils_1 = require("../utils");
|
|
14
|
+
const script_1 = require("./code/script");
|
|
15
|
+
const template_1 = require("./code/template");
|
|
16
|
+
const style_1 = require("./code/style");
|
|
17
|
+
function resolveAppVue(inputDir) {
|
|
18
|
+
const appUVue = path_1.default.resolve(inputDir, 'app.uvue');
|
|
19
|
+
if (fs_extra_1.default.existsSync(appUVue)) {
|
|
20
|
+
return (0, uni_cli_shared_1.normalizePath)(appUVue);
|
|
21
|
+
}
|
|
22
|
+
return (0, uni_cli_shared_1.normalizePath)(path_1.default.resolve(inputDir, 'App.vue'));
|
|
23
|
+
}
|
|
24
|
+
function uniAppUVuePlugin() {
|
|
25
|
+
const options = {
|
|
26
|
+
root: process.env.UNI_INPUT_DIR,
|
|
27
|
+
sourceMap: false,
|
|
28
|
+
// eslint-disable-next-line no-restricted-globals
|
|
29
|
+
compiler: require('@vue/compiler-sfc'),
|
|
30
|
+
targetLanguage: process.env.UNI_UTS_TARGET_LANGUAGE,
|
|
31
|
+
};
|
|
32
|
+
const appVue = resolveAppVue(process.env.UNI_INPUT_DIR);
|
|
33
|
+
function isAppVue(id) {
|
|
34
|
+
return (0, uni_cli_shared_1.normalizePath)(id) === appVue;
|
|
35
|
+
}
|
|
36
|
+
function normalizeEasyComSource(source) {
|
|
37
|
+
// 把源码source调整为.uvue目录
|
|
38
|
+
return (0, utils_1.parseUTSImportFilename)(source);
|
|
39
|
+
}
|
|
40
|
+
return {
|
|
41
|
+
name: 'uni:app-uvue',
|
|
42
|
+
apply: 'build',
|
|
43
|
+
async resolveId(id) {
|
|
44
|
+
// serve sub-part requests (*?vue) as virtual modules
|
|
45
|
+
if ((0, uni_cli_shared_1.parseVueRequest)(id).query.vue) {
|
|
46
|
+
return id;
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
load(id) {
|
|
50
|
+
const { filename, query } = (0, uni_cli_shared_1.parseVueRequest)(id);
|
|
51
|
+
// select corresponding block for sub-part virtual modules
|
|
52
|
+
if (query.vue) {
|
|
53
|
+
if (query.src) {
|
|
54
|
+
return fs_extra_1.default.readFileSync(filename, 'utf-8');
|
|
55
|
+
}
|
|
56
|
+
const descriptor = (0, descriptorCache_1.getDescriptor)(filename, options);
|
|
57
|
+
let block;
|
|
58
|
+
if (query.type === 'style') {
|
|
59
|
+
block = descriptor.styles[query.index];
|
|
60
|
+
}
|
|
61
|
+
else if (query.index != null) {
|
|
62
|
+
block = descriptor.customBlocks[query.index];
|
|
63
|
+
}
|
|
64
|
+
if (block) {
|
|
65
|
+
return {
|
|
66
|
+
code: block.content,
|
|
67
|
+
map: block.map,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
async transform(code, id) {
|
|
73
|
+
const { filename, query } = (0, uni_cli_shared_1.parseVueRequest)(id);
|
|
74
|
+
if (!(0, utils_1.isVue)(filename)) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
if (!query.vue) {
|
|
78
|
+
// main request
|
|
79
|
+
const { errors, uts, js } = await transformVue(code, filename, options, this, isAppVue, normalizeEasyComSource);
|
|
80
|
+
if (errors.length) {
|
|
81
|
+
errors.forEach((error) => this.error((0, error_1.createRollupError)(filename, error)));
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
this.emitFile({
|
|
85
|
+
type: 'asset',
|
|
86
|
+
fileName: (0, utils_1.parseUTSRelativeFilename)(filename),
|
|
87
|
+
source: uts,
|
|
88
|
+
});
|
|
89
|
+
return {
|
|
90
|
+
code: js,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
// sub block request
|
|
95
|
+
const descriptor = query.src
|
|
96
|
+
? (0, descriptorCache_1.getSrcDescriptor)(filename)
|
|
97
|
+
: (0, descriptorCache_1.getDescriptor)(filename, options);
|
|
98
|
+
if (query.type === 'style') {
|
|
99
|
+
return (0, style_1.transformStyle)(code, descriptor, Number(query.index), options, this, filename);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
},
|
|
103
|
+
generateBundle(_, bundle) {
|
|
104
|
+
// 遍历vue文件,填充style,尽量减少全局变量
|
|
105
|
+
Object.keys(bundle).forEach((name) => {
|
|
106
|
+
const file = bundle[name];
|
|
107
|
+
if (file &&
|
|
108
|
+
file.type === 'asset' &&
|
|
109
|
+
(0, utils_1.isVue)(file.fileName) &&
|
|
110
|
+
(0, shared_1.isString)(file.source)) {
|
|
111
|
+
const fileName = (0, uni_cli_shared_1.normalizePath)(file.fileName);
|
|
112
|
+
const classNameComment = `/*${(0, utils_1.genClassName)(fileName, options.classNamePrefix)}Styles*/`;
|
|
113
|
+
if (file.source.includes(classNameComment)) {
|
|
114
|
+
const styleAssetName = fileName + '.style.uts';
|
|
115
|
+
const styleAsset = bundle[styleAssetName];
|
|
116
|
+
if (styleAsset &&
|
|
117
|
+
styleAsset.type === 'asset' &&
|
|
118
|
+
(0, shared_1.isString)(styleAsset.source)) {
|
|
119
|
+
file.source = file.source.replace(classNameComment, styleAsset.source.replace('export ', ''));
|
|
120
|
+
delete bundle[styleAssetName];
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
},
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
exports.uniAppUVuePlugin = uniAppUVuePlugin;
|
|
129
|
+
async function transformVue(code, filename, options, pluginContext, isAppVue = () => false, normalizeEasyComSource) {
|
|
130
|
+
if (!options.compiler) {
|
|
131
|
+
options.compiler = require('@vue/compiler-sfc');
|
|
132
|
+
}
|
|
133
|
+
// prev descriptor is only set and used for hmr
|
|
134
|
+
const { descriptor, errors } = (0, descriptorCache_1.createDescriptor)(filename, code, options);
|
|
135
|
+
if (errors.length) {
|
|
136
|
+
return { errors, descriptor };
|
|
137
|
+
}
|
|
138
|
+
const isApp = isAppVue(filename);
|
|
139
|
+
const fileName = path_1.default.relative(options.root, filename);
|
|
140
|
+
const className = (0, utils_1.genClassName)(fileName, options.classNamePrefix);
|
|
141
|
+
let templateCode = '';
|
|
142
|
+
let templateImportEasyComponentsCode = '';
|
|
143
|
+
let templateImportUTSComponentsCode = '';
|
|
144
|
+
if (!isApp) {
|
|
145
|
+
const templateResult = (0, template_1.genTemplate)(descriptor, {
|
|
146
|
+
targetLanguage: options.targetLanguage,
|
|
147
|
+
mode: 'function',
|
|
148
|
+
filename: className,
|
|
149
|
+
prefixIdentifiers: true,
|
|
150
|
+
sourceMap: true,
|
|
151
|
+
matchEasyCom: (tag, uts) => {
|
|
152
|
+
const source = (0, uni_cli_shared_1.matchEasycom)(tag);
|
|
153
|
+
if (uts && source) {
|
|
154
|
+
return normalizeEasyComSource(source);
|
|
155
|
+
}
|
|
156
|
+
return source;
|
|
157
|
+
},
|
|
158
|
+
parseUTSComponent: uni_cli_shared_1.parseUTSComponent,
|
|
159
|
+
});
|
|
160
|
+
templateCode = templateResult.code;
|
|
161
|
+
templateImportEasyComponentsCode =
|
|
162
|
+
templateResult.importEasyComponents.join('\n');
|
|
163
|
+
templateImportUTSComponentsCode =
|
|
164
|
+
templateResult.importUTSComponents.join('\n');
|
|
165
|
+
}
|
|
166
|
+
// 生成 script 文件
|
|
167
|
+
let utsCode = (0, script_1.genScript)(descriptor, { filename: className }) +
|
|
168
|
+
'\n' +
|
|
169
|
+
(0, style_1.genStyle)(descriptor, { filename: fileName, className }) +
|
|
170
|
+
'\n';
|
|
171
|
+
utsCode += templateCode;
|
|
172
|
+
let jsCode = templateImportEasyComponentsCode + '\n' + templateImportUTSComponentsCode;
|
|
173
|
+
const content = descriptor.script?.content;
|
|
174
|
+
if (content) {
|
|
175
|
+
jsCode += await (0, utils_1.parseImports)(content);
|
|
176
|
+
}
|
|
177
|
+
if (descriptor.styles.length) {
|
|
178
|
+
jsCode += '\n' + (await (0, style_1.genJsStylesCode)(descriptor, pluginContext));
|
|
179
|
+
}
|
|
180
|
+
jsCode += `\nexport default "${className}"`;
|
|
181
|
+
return {
|
|
182
|
+
errors: [],
|
|
183
|
+
uts: utsCode,
|
|
184
|
+
js: jsCode,
|
|
185
|
+
descriptor,
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
exports.transformVue = transformVue;
|