@dcloudio/uni-app-uts 3.0.0-alpha-3071320230417001
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 +2 -0
- package/dist/index.js +18 -0
- package/dist/plugins/index.d.ts +2 -0
- package/dist/plugins/index.js +121 -0
- package/dist/plugins/mainUTS.d.ts +4 -0
- package/dist/plugins/mainUTS.js +25 -0
- package/dist/plugins/manifestJson.d.ts +2 -0
- package/dist/plugins/manifestJson.js +57 -0
- package/dist/plugins/pagesJson.d.ts +2 -0
- package/dist/plugins/pagesJson.js +65 -0
- package/dist/plugins/pre.d.ts +7 -0
- package/dist/plugins/pre.js +52 -0
- package/dist/plugins/utils.d.ts +4 -0
- package/dist/plugins/utils.js +29 -0
- package/dist/plugins/uvue/code/script.d.ts +4 -0
- package/dist/plugins/uvue/code/script.js +28 -0
- package/dist/plugins/uvue/code/style.d.ts +4 -0
- package/dist/plugins/uvue/code/style.js +7 -0
- package/dist/plugins/uvue/code/template/compiler/codegen.d.ts +20 -0
- package/dist/plugins/uvue/code/template/compiler/codegen.js +419 -0
- package/dist/plugins/uvue/code/template/compiler/errors.d.ts +70 -0
- package/dist/plugins/uvue/code/template/compiler/errors.js +82 -0
- package/dist/plugins/uvue/code/template/compiler/index.d.ts +8 -0
- package/dist/plugins/uvue/code/template/compiler/index.js +43 -0
- package/dist/plugins/uvue/code/template/compiler/options.d.ts +60 -0
- package/dist/plugins/uvue/code/template/compiler/options.js +2 -0
- package/dist/plugins/uvue/code/template/compiler/transform.d.ts +52 -0
- package/dist/plugins/uvue/code/template/compiler/transform.js +267 -0
- package/dist/plugins/uvue/code/template/index.d.ts +3 -0
- package/dist/plugins/uvue/code/template/index.js +12 -0
- package/dist/plugins/uvue/code/template/utils.d.ts +2 -0
- package/dist/plugins/uvue/code/template/utils.js +7 -0
- package/dist/plugins/uvue/descriptorCache.d.ts +22 -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 +2 -0
- package/dist/plugins/uvue/index.js +78 -0
- package/package.json +36 -0
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { CompilerError } from '@vue/compiler-core';
|
|
2
|
+
import { RawSourceMap } from 'source-map';
|
|
3
|
+
import { DirectiveTransform, NodeTransform } from './transform';
|
|
4
|
+
interface SharedTransformCodegenOptions {
|
|
5
|
+
targetLanguage: 'kotlin' | 'swift';
|
|
6
|
+
/**
|
|
7
|
+
* Transform expressions like {{ foo }} to `_ctx.foo`.
|
|
8
|
+
* @default false
|
|
9
|
+
*/
|
|
10
|
+
prefixIdentifiers?: boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Filename for source map generation.
|
|
13
|
+
* Also used for self-recursive reference in templates
|
|
14
|
+
* @default ''
|
|
15
|
+
*/
|
|
16
|
+
filename?: string;
|
|
17
|
+
}
|
|
18
|
+
export interface CodegenOptions extends SharedTransformCodegenOptions {
|
|
19
|
+
/**
|
|
20
|
+
* function
|
|
21
|
+
* @default 'default'
|
|
22
|
+
*/
|
|
23
|
+
mode?: 'default' | 'function';
|
|
24
|
+
/**
|
|
25
|
+
* Generate source map?
|
|
26
|
+
* @default false
|
|
27
|
+
*/
|
|
28
|
+
sourceMap?: boolean;
|
|
29
|
+
}
|
|
30
|
+
export interface ErrorHandlingOptions {
|
|
31
|
+
onWarn?: (warning: CompilerError) => void;
|
|
32
|
+
onError?: (error: CompilerError) => void;
|
|
33
|
+
}
|
|
34
|
+
export interface TransformOptions extends SharedTransformCodegenOptions, ErrorHandlingOptions {
|
|
35
|
+
/**
|
|
36
|
+
* An array of node transforms to be applied to every AST node.
|
|
37
|
+
*/
|
|
38
|
+
nodeTransforms?: NodeTransform[];
|
|
39
|
+
/**
|
|
40
|
+
* An object of { name: transform } to be applied to every directive attribute
|
|
41
|
+
* node found on element nodes.
|
|
42
|
+
*/
|
|
43
|
+
directiveTransforms?: Record<string, DirectiveTransform | undefined>;
|
|
44
|
+
/**
|
|
45
|
+
* If the pairing runtime provides additional built-in elements, use this to
|
|
46
|
+
* mark them as built-in so the compiler will generate component vnodes
|
|
47
|
+
* for them.
|
|
48
|
+
*/
|
|
49
|
+
isBuiltInComponent?: (tag: string) => symbol | void;
|
|
50
|
+
/**
|
|
51
|
+
* Used by some transforms that expects only native elements
|
|
52
|
+
*/
|
|
53
|
+
isCustomElement?: (tag: string) => boolean | void;
|
|
54
|
+
}
|
|
55
|
+
export type CompilerOptions = TransformOptions & CodegenOptions;
|
|
56
|
+
export interface CodegenResult {
|
|
57
|
+
code: string;
|
|
58
|
+
map?: RawSourceMap;
|
|
59
|
+
}
|
|
60
|
+
export {};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { CacheExpression, ComponentNode, ConstantTypes, DirectiveNode, ElementNode, ExpressionNode, JSChildNode, ParentNode, PlainElementNode, Property, RootNode, TemplateChildNode, TemplateLiteral, TemplateNode } from '@vue/compiler-core';
|
|
2
|
+
import { TransformOptions } from './options';
|
|
3
|
+
export type NodeTransform = (node: RootNode | TemplateChildNode, context: TransformContext) => void | (() => void) | (() => void)[];
|
|
4
|
+
export type DirectiveTransform = (dir: DirectiveNode, node: ElementNode, context: TransformContext, augmentor?: (ret: DirectiveTransformResult) => DirectiveTransformResult) => DirectiveTransformResult;
|
|
5
|
+
export interface DirectiveTransformResult {
|
|
6
|
+
props: Property[];
|
|
7
|
+
needRuntime?: boolean | symbol;
|
|
8
|
+
ssrTagParts?: TemplateLiteral['elements'];
|
|
9
|
+
}
|
|
10
|
+
export type StructuralDirectiveTransform = (node: ElementNode, dir: DirectiveNode, context: TransformContext) => void | (() => void);
|
|
11
|
+
export interface ImportItem {
|
|
12
|
+
exp: string | ExpressionNode;
|
|
13
|
+
path: string;
|
|
14
|
+
}
|
|
15
|
+
export interface TransformContext extends Required<Omit<TransformOptions, 'filename'>> {
|
|
16
|
+
selfName: string | null;
|
|
17
|
+
root: RootNode;
|
|
18
|
+
helpers: Map<symbol, number>;
|
|
19
|
+
components: Set<string>;
|
|
20
|
+
directives: Set<string>;
|
|
21
|
+
imports: ImportItem[];
|
|
22
|
+
temps: number;
|
|
23
|
+
cached: number;
|
|
24
|
+
identifiers: {
|
|
25
|
+
[name: string]: number | undefined;
|
|
26
|
+
};
|
|
27
|
+
scopes: {
|
|
28
|
+
vFor: number;
|
|
29
|
+
vSlot: number;
|
|
30
|
+
vPre: number;
|
|
31
|
+
vOnce: number;
|
|
32
|
+
};
|
|
33
|
+
parent: ParentNode | null;
|
|
34
|
+
childIndex: number;
|
|
35
|
+
currentNode: RootNode | TemplateChildNode | null;
|
|
36
|
+
inVOnce: boolean;
|
|
37
|
+
helper<T extends symbol>(name: T): T;
|
|
38
|
+
removeHelper<T extends symbol>(name: T): void;
|
|
39
|
+
helperString(name: symbol): string;
|
|
40
|
+
replaceNode(node: TemplateChildNode): void;
|
|
41
|
+
removeNode(node?: TemplateChildNode): void;
|
|
42
|
+
onNodeRemoved(): void;
|
|
43
|
+
addIdentifiers(exp: ExpressionNode | string): void;
|
|
44
|
+
removeIdentifiers(exp: ExpressionNode | string): void;
|
|
45
|
+
cache<T extends JSChildNode>(exp: T, isVNode?: boolean): CacheExpression | T;
|
|
46
|
+
constantCache: Map<TemplateChildNode, ConstantTypes>;
|
|
47
|
+
}
|
|
48
|
+
export declare function createTransformContext(root: RootNode, { targetLanguage, filename, prefixIdentifiers, nodeTransforms, directiveTransforms, isBuiltInComponent, isCustomElement, onError, onWarn, }: TransformOptions): TransformContext;
|
|
49
|
+
export declare function transform(root: RootNode, options: TransformOptions): void;
|
|
50
|
+
export declare function isSingleElementRoot(root: RootNode, child: TemplateChildNode): child is PlainElementNode | ComponentNode | TemplateNode;
|
|
51
|
+
export declare function traverseChildren(parent: ParentNode, context: TransformContext): void;
|
|
52
|
+
export declare function traverseNode(node: RootNode | TemplateChildNode, context: TransformContext): void;
|
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.traverseNode = exports.traverseChildren = exports.isSingleElementRoot = exports.transform = exports.createTransformContext = 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
|
+
function createTransformContext(root, { targetLanguage, filename = '', prefixIdentifiers = false, nodeTransforms = [], directiveTransforms = {}, isBuiltInComponent = shared_1.NOOP, isCustomElement = shared_1.NOOP, onError = errors_1.defaultOnError, onWarn = errors_1.defaultOnWarn, }) {
|
|
8
|
+
const nameMatch = filename.replace(/\?.*$/, '').match(/([^/\\]+)\.\w+$/);
|
|
9
|
+
const context = {
|
|
10
|
+
// options
|
|
11
|
+
targetLanguage,
|
|
12
|
+
selfName: nameMatch && (0, shared_1.capitalize)((0, shared_1.camelize)(nameMatch[1])),
|
|
13
|
+
prefixIdentifiers,
|
|
14
|
+
nodeTransforms,
|
|
15
|
+
directiveTransforms,
|
|
16
|
+
isBuiltInComponent,
|
|
17
|
+
isCustomElement,
|
|
18
|
+
onError,
|
|
19
|
+
onWarn,
|
|
20
|
+
// state
|
|
21
|
+
root,
|
|
22
|
+
helpers: new Map(),
|
|
23
|
+
components: new Set(),
|
|
24
|
+
directives: new Set(),
|
|
25
|
+
imports: [],
|
|
26
|
+
constantCache: new Map(),
|
|
27
|
+
temps: 0,
|
|
28
|
+
cached: 0,
|
|
29
|
+
identifiers: Object.create(null),
|
|
30
|
+
scopes: {
|
|
31
|
+
vFor: 0,
|
|
32
|
+
vSlot: 0,
|
|
33
|
+
vPre: 0,
|
|
34
|
+
vOnce: 0,
|
|
35
|
+
},
|
|
36
|
+
parent: null,
|
|
37
|
+
currentNode: root,
|
|
38
|
+
childIndex: 0,
|
|
39
|
+
inVOnce: false,
|
|
40
|
+
// methods
|
|
41
|
+
helper(name) {
|
|
42
|
+
const count = context.helpers.get(name) || 0;
|
|
43
|
+
context.helpers.set(name, count + 1);
|
|
44
|
+
return name;
|
|
45
|
+
},
|
|
46
|
+
removeHelper(name) {
|
|
47
|
+
const count = context.helpers.get(name);
|
|
48
|
+
if (count) {
|
|
49
|
+
const currentCount = count - 1;
|
|
50
|
+
if (!currentCount) {
|
|
51
|
+
context.helpers.delete(name);
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
context.helpers.set(name, currentCount);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
helperString(name) {
|
|
59
|
+
return `_${compiler_core_1.helperNameMap[context.helper(name)]}`;
|
|
60
|
+
},
|
|
61
|
+
replaceNode(node) {
|
|
62
|
+
if (!context.currentNode) {
|
|
63
|
+
throw new Error(`Node being replaced is already removed.`);
|
|
64
|
+
}
|
|
65
|
+
if (!context.parent) {
|
|
66
|
+
throw new Error(`Cannot replace root node.`);
|
|
67
|
+
}
|
|
68
|
+
context.parent.children[context.childIndex] = context.currentNode = node;
|
|
69
|
+
},
|
|
70
|
+
removeNode(node) {
|
|
71
|
+
if (!context.parent) {
|
|
72
|
+
throw new Error(`Cannot remove root node.`);
|
|
73
|
+
}
|
|
74
|
+
const list = context.parent.children;
|
|
75
|
+
const removalIndex = node
|
|
76
|
+
? list.indexOf(node)
|
|
77
|
+
: context.currentNode
|
|
78
|
+
? context.childIndex
|
|
79
|
+
: -1;
|
|
80
|
+
/* istanbul ignore if */
|
|
81
|
+
if (removalIndex < 0) {
|
|
82
|
+
throw new Error(`node being removed is not a child of current parent`);
|
|
83
|
+
}
|
|
84
|
+
if (!node || node === context.currentNode) {
|
|
85
|
+
// current node removed
|
|
86
|
+
context.currentNode = null;
|
|
87
|
+
context.onNodeRemoved();
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
// sibling node removed
|
|
91
|
+
if (context.childIndex > removalIndex) {
|
|
92
|
+
context.childIndex--;
|
|
93
|
+
context.onNodeRemoved();
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
context.parent.children.splice(removalIndex, 1);
|
|
97
|
+
},
|
|
98
|
+
onNodeRemoved: () => { },
|
|
99
|
+
addIdentifiers(exp) {
|
|
100
|
+
// identifier tracking only happens in non-browser builds.
|
|
101
|
+
if ((0, shared_1.isString)(exp)) {
|
|
102
|
+
addId(exp);
|
|
103
|
+
}
|
|
104
|
+
else if (exp.identifiers) {
|
|
105
|
+
exp.identifiers.forEach(addId);
|
|
106
|
+
}
|
|
107
|
+
else if (exp.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */) {
|
|
108
|
+
addId(exp.content);
|
|
109
|
+
}
|
|
110
|
+
},
|
|
111
|
+
removeIdentifiers(exp) {
|
|
112
|
+
if ((0, shared_1.isString)(exp)) {
|
|
113
|
+
removeId(exp);
|
|
114
|
+
}
|
|
115
|
+
else if (exp.identifiers) {
|
|
116
|
+
exp.identifiers.forEach(removeId);
|
|
117
|
+
}
|
|
118
|
+
else if (exp.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */) {
|
|
119
|
+
removeId(exp.content);
|
|
120
|
+
}
|
|
121
|
+
},
|
|
122
|
+
cache(exp, isVNode = false) {
|
|
123
|
+
return (0, compiler_core_1.createCacheExpression)(context.cached++, exp, isVNode);
|
|
124
|
+
},
|
|
125
|
+
};
|
|
126
|
+
function addId(id) {
|
|
127
|
+
const { identifiers } = context;
|
|
128
|
+
if (identifiers[id] === undefined) {
|
|
129
|
+
identifiers[id] = 0;
|
|
130
|
+
}
|
|
131
|
+
identifiers[id]++;
|
|
132
|
+
}
|
|
133
|
+
function removeId(id) {
|
|
134
|
+
context.identifiers[id]--;
|
|
135
|
+
}
|
|
136
|
+
return context;
|
|
137
|
+
}
|
|
138
|
+
exports.createTransformContext = createTransformContext;
|
|
139
|
+
function transform(root, options) {
|
|
140
|
+
const context = createTransformContext(root, options);
|
|
141
|
+
traverseNode(root, context);
|
|
142
|
+
createRootCodegen(root, context);
|
|
143
|
+
}
|
|
144
|
+
exports.transform = transform;
|
|
145
|
+
function isSingleElementRoot(root, child) {
|
|
146
|
+
const { children } = root;
|
|
147
|
+
return (children.length === 1 &&
|
|
148
|
+
child.type === 1 /* NodeTypes.ELEMENT */ &&
|
|
149
|
+
!(0, compiler_core_1.isSlotOutlet)(child));
|
|
150
|
+
}
|
|
151
|
+
exports.isSingleElementRoot = isSingleElementRoot;
|
|
152
|
+
function createRootCodegen(root, context) {
|
|
153
|
+
const { children } = root;
|
|
154
|
+
if (children.length === 1) {
|
|
155
|
+
const child = children[0];
|
|
156
|
+
// if the single child is an element, turn it into a block.
|
|
157
|
+
if (isSingleElementRoot(root, child) && child.codegenNode) {
|
|
158
|
+
// single element root is never hoisted so codegenNode will never be
|
|
159
|
+
// SimpleExpressionNode
|
|
160
|
+
const codegenNode = child.codegenNode;
|
|
161
|
+
if (codegenNode.type === 13 /* NodeTypes.VNODE_CALL */) {
|
|
162
|
+
(0, compiler_core_1.makeBlock)(codegenNode, context);
|
|
163
|
+
}
|
|
164
|
+
root.codegenNode = codegenNode;
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
// - single <slot/>, IfNode, ForNode: already blocks.
|
|
168
|
+
// - single text node: always patched.
|
|
169
|
+
// root codegen falls through via genNode()
|
|
170
|
+
root.codegenNode = child;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
else if (children.length > 1) {
|
|
174
|
+
// root has multiple nodes - return a fragment block.
|
|
175
|
+
// let patchFlag = PatchFlags.STABLE_FRAGMENT
|
|
176
|
+
// let patchFlagText = PatchFlagNames[PatchFlags.STABLE_FRAGMENT]
|
|
177
|
+
// // check if the fragment actually contains a single valid child with
|
|
178
|
+
// // the rest being comments
|
|
179
|
+
// if (
|
|
180
|
+
// children.filter(c => c.type !== NodeTypes.COMMENT).length === 1
|
|
181
|
+
// ) {
|
|
182
|
+
// patchFlag |= PatchFlags.DEV_ROOT_FRAGMENT
|
|
183
|
+
// patchFlagText += `, ${PatchFlagNames[PatchFlags.DEV_ROOT_FRAGMENT]}`
|
|
184
|
+
// }
|
|
185
|
+
// root.codegenNode = createVNodeCall(
|
|
186
|
+
// context,
|
|
187
|
+
// helper(FRAGMENT),
|
|
188
|
+
// undefined,
|
|
189
|
+
// root.children,
|
|
190
|
+
// patchFlag + ` /* ${patchFlagText} */`,
|
|
191
|
+
// undefined,
|
|
192
|
+
// undefined,
|
|
193
|
+
// true,
|
|
194
|
+
// undefined,
|
|
195
|
+
// false /* isComponent */
|
|
196
|
+
// )
|
|
197
|
+
}
|
|
198
|
+
else {
|
|
199
|
+
// no children = noop. codegen will return null.
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
function traverseChildren(parent, context) {
|
|
203
|
+
let i = 0;
|
|
204
|
+
const nodeRemoved = () => {
|
|
205
|
+
i--;
|
|
206
|
+
};
|
|
207
|
+
for (; i < parent.children.length; i++) {
|
|
208
|
+
const child = parent.children[i];
|
|
209
|
+
if ((0, shared_1.isString)(child))
|
|
210
|
+
continue;
|
|
211
|
+
context.parent = parent;
|
|
212
|
+
context.childIndex = i;
|
|
213
|
+
context.onNodeRemoved = nodeRemoved;
|
|
214
|
+
traverseNode(child, context);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
exports.traverseChildren = traverseChildren;
|
|
218
|
+
function traverseNode(node, context) {
|
|
219
|
+
context.currentNode = node;
|
|
220
|
+
// apply transform plugins
|
|
221
|
+
const { nodeTransforms } = context;
|
|
222
|
+
const exitFns = [];
|
|
223
|
+
for (let i = 0; i < nodeTransforms.length; i++) {
|
|
224
|
+
const onExit = nodeTransforms[i](node, context);
|
|
225
|
+
if (onExit) {
|
|
226
|
+
if ((0, shared_1.isArray)(onExit)) {
|
|
227
|
+
exitFns.push(...onExit);
|
|
228
|
+
}
|
|
229
|
+
else {
|
|
230
|
+
exitFns.push(onExit);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
if (!context.currentNode) {
|
|
234
|
+
// node was removed
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
else {
|
|
238
|
+
// node may have been replaced
|
|
239
|
+
node = context.currentNode;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
switch (node.type) {
|
|
243
|
+
case 3 /* NodeTypes.COMMENT */:
|
|
244
|
+
break;
|
|
245
|
+
case 5 /* NodeTypes.INTERPOLATION */:
|
|
246
|
+
break;
|
|
247
|
+
// for container types, further traverse downwards
|
|
248
|
+
case 9 /* NodeTypes.IF */:
|
|
249
|
+
for (let i = 0; i < node.branches.length; i++) {
|
|
250
|
+
traverseNode(node.branches[i], context);
|
|
251
|
+
}
|
|
252
|
+
break;
|
|
253
|
+
case 10 /* NodeTypes.IF_BRANCH */:
|
|
254
|
+
case 11 /* NodeTypes.FOR */:
|
|
255
|
+
case 1 /* NodeTypes.ELEMENT */:
|
|
256
|
+
case 0 /* NodeTypes.ROOT */:
|
|
257
|
+
traverseChildren(node, context);
|
|
258
|
+
break;
|
|
259
|
+
}
|
|
260
|
+
// exit transforms
|
|
261
|
+
context.currentNode = node;
|
|
262
|
+
let i = exitFns.length;
|
|
263
|
+
while (i--) {
|
|
264
|
+
exitFns[i]();
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
exports.traverseNode = traverseNode;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.genTemplate = void 0;
|
|
4
|
+
const compiler_1 = require("./compiler");
|
|
5
|
+
const utils_1 = require("./utils");
|
|
6
|
+
function genTemplate(template, options) {
|
|
7
|
+
if (!template) {
|
|
8
|
+
return (0, utils_1.genRenderFunctionDecl)(options) + ` { return null }`;
|
|
9
|
+
}
|
|
10
|
+
return (0, compiler_1.compile)(template.content, options).code;
|
|
11
|
+
}
|
|
12
|
+
exports.genTemplate = genTemplate;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.genRenderFunctionDecl = void 0;
|
|
4
|
+
function genRenderFunctionDecl({ targetLanguage, filename, }) {
|
|
5
|
+
return `${targetLanguage === 'kotlin' ? '@Suppress("UNUSED_PARAMETER") ' : ''}function ${filename}Render(ctx: ${filename}): VNode | null`;
|
|
6
|
+
}
|
|
7
|
+
exports.genRenderFunctionDecl = genRenderFunctionDecl;
|
|
@@ -0,0 +1,22 @@
|
|
|
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
|
+
}
|
|
8
|
+
export interface SFCParseResult {
|
|
9
|
+
descriptor: SFCDescriptor;
|
|
10
|
+
errors: Array<CompilerError | SyntaxError>;
|
|
11
|
+
}
|
|
12
|
+
declare module '@vue/compiler-sfc' {
|
|
13
|
+
interface SFCDescriptor {
|
|
14
|
+
id: string;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
export declare function createDescriptor(filename: string, source: string, { root, sourceMap, compiler }: ResolvedOptions): SFCParseResult;
|
|
18
|
+
export declare function getPrevDescriptor(filename: string): SFCDescriptor | undefined;
|
|
19
|
+
export declare function setPrevDescriptor(filename: string, entry: SFCDescriptor): void;
|
|
20
|
+
export declare function getDescriptor(filename: string, options: ResolvedOptions, createIfNotFound?: boolean): SFCDescriptor | undefined;
|
|
21
|
+
export declare function getSrcDescriptor(filename: string): SFCDescriptor;
|
|
22
|
+
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,78 @@
|
|
|
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.uniAppUVuePlugin = void 0;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
9
|
+
const uni_cli_shared_1 = require("@dcloudio/uni-cli-shared");
|
|
10
|
+
const descriptorCache_1 = require("./descriptorCache");
|
|
11
|
+
const error_1 = require("./error");
|
|
12
|
+
const utils_1 = require("../utils");
|
|
13
|
+
const script_1 = require("./code/script");
|
|
14
|
+
const template_1 = require("./code/template");
|
|
15
|
+
const style_1 = require("./code/style");
|
|
16
|
+
function resolveAppVue(inputDir) {
|
|
17
|
+
const appUVue = path_1.default.resolve(inputDir, 'app.uvue');
|
|
18
|
+
if (fs_extra_1.default.existsSync(appUVue)) {
|
|
19
|
+
return (0, uni_cli_shared_1.normalizePath)(appUVue);
|
|
20
|
+
}
|
|
21
|
+
return (0, uni_cli_shared_1.normalizePath)(path_1.default.resolve(inputDir, 'App.vue'));
|
|
22
|
+
}
|
|
23
|
+
function uniAppUVuePlugin() {
|
|
24
|
+
const options = {
|
|
25
|
+
root: process.env.UNI_INPUT_DIR,
|
|
26
|
+
sourceMap: false,
|
|
27
|
+
// eslint-disable-next-line no-restricted-globals
|
|
28
|
+
compiler: require('@vue/compiler-sfc'),
|
|
29
|
+
};
|
|
30
|
+
const appVue = resolveAppVue(process.env.UNI_INPUT_DIR);
|
|
31
|
+
function isAppVue(id) {
|
|
32
|
+
return (0, uni_cli_shared_1.normalizePath)(id) === appVue;
|
|
33
|
+
}
|
|
34
|
+
return {
|
|
35
|
+
name: 'uni:app-uvue',
|
|
36
|
+
apply: 'build',
|
|
37
|
+
transform(code, id) {
|
|
38
|
+
const { filename } = (0, uni_cli_shared_1.parseVueRequest)(id);
|
|
39
|
+
const isVue = filename.endsWith('.vue') || filename.endsWith('.uvue');
|
|
40
|
+
if (!isVue) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
// prev descriptor is only set and used for hmr
|
|
44
|
+
const { descriptor, errors } = (0, descriptorCache_1.createDescriptor)(filename, code, options);
|
|
45
|
+
if (errors.length) {
|
|
46
|
+
errors.forEach((error) => this.error((0, error_1.createRollupError)(filename, error)));
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
const isApp = isAppVue(id);
|
|
50
|
+
const fileName = path_1.default.relative(process.env.UNI_INPUT_DIR, id);
|
|
51
|
+
const className = (0, utils_1.genClassName)(fileName);
|
|
52
|
+
// 生成 script 文件
|
|
53
|
+
this.emitFile({
|
|
54
|
+
type: 'asset',
|
|
55
|
+
fileName,
|
|
56
|
+
source: (0, script_1.genScript)(descriptor.script, { filename: className }) +
|
|
57
|
+
'\n' +
|
|
58
|
+
(0, style_1.genStyle)(descriptor.styles, { filename: className }) +
|
|
59
|
+
'\n' +
|
|
60
|
+
(!isApp
|
|
61
|
+
? (0, template_1.genTemplate)(descriptor.template, {
|
|
62
|
+
targetLanguage: process.env.UNI_UVUE_TARGET_LANGUAGE,
|
|
63
|
+
mode: 'function',
|
|
64
|
+
filename: className,
|
|
65
|
+
})
|
|
66
|
+
: ''),
|
|
67
|
+
});
|
|
68
|
+
const content = descriptor.script?.content;
|
|
69
|
+
if (content) {
|
|
70
|
+
return (0, utils_1.parseImports)(content);
|
|
71
|
+
}
|
|
72
|
+
return {
|
|
73
|
+
code: 'export default {}',
|
|
74
|
+
};
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
exports.uniAppUVuePlugin = uniAppUVuePlugin;
|
package/package.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@dcloudio/uni-app-uts",
|
|
3
|
+
"version": "3.0.0-alpha-3071320230417001",
|
|
4
|
+
"description": "uni-app-uts",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"bin",
|
|
9
|
+
"dist",
|
|
10
|
+
"lib"
|
|
11
|
+
],
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "git+https://github.com/dcloudio/uni-app.git",
|
|
15
|
+
"directory": "packages/uni-app-uts"
|
|
16
|
+
},
|
|
17
|
+
"scripts": {
|
|
18
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
19
|
+
},
|
|
20
|
+
"license": "Apache-2.0",
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@dcloudio/uni-cli-shared": "3.0.0-alpha-3071320230417001",
|
|
23
|
+
"@rollup/pluginutils": "^4.2.0",
|
|
24
|
+
"@vue/compiler-core": "3.2.47",
|
|
25
|
+
"@vue/compiler-sfc": "3.2.47",
|
|
26
|
+
"@vue/shared": "3.2.47",
|
|
27
|
+
"debug": "^4.3.3",
|
|
28
|
+
"es-module-lexer": "^1.2.1",
|
|
29
|
+
"fs-extra": "^10.0.0",
|
|
30
|
+
"source-map": "^0.6.1"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@types/debug": "^4.1.7",
|
|
34
|
+
"@types/fs-extra": "^9.0.13"
|
|
35
|
+
}
|
|
36
|
+
}
|