@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,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.errorMessages = exports.createCompilerError = exports.defaultOnWarn = exports.defaultOnError = void 0;
|
|
4
|
+
function defaultOnError(error) {
|
|
5
|
+
throw error;
|
|
6
|
+
}
|
|
7
|
+
exports.defaultOnError = defaultOnError;
|
|
8
|
+
function defaultOnWarn(msg) {
|
|
9
|
+
console.warn(`[Vue warn] ${msg.message}`);
|
|
10
|
+
}
|
|
11
|
+
exports.defaultOnWarn = defaultOnWarn;
|
|
12
|
+
function createCompilerError(code, loc, messages, additionalMessage) {
|
|
13
|
+
const msg = (messages || exports.errorMessages)[code] + (additionalMessage || ``);
|
|
14
|
+
const error = new SyntaxError(String(msg));
|
|
15
|
+
error.code = code;
|
|
16
|
+
error.loc = loc;
|
|
17
|
+
return error;
|
|
18
|
+
}
|
|
19
|
+
exports.createCompilerError = createCompilerError;
|
|
20
|
+
exports.errorMessages = {
|
|
21
|
+
// parse errors
|
|
22
|
+
[0 /* ErrorCodes.ABRUPT_CLOSING_OF_EMPTY_COMMENT */]: 'Illegal comment.',
|
|
23
|
+
[1 /* ErrorCodes.CDATA_IN_HTML_CONTENT */]: 'CDATA section is allowed only in XML context.',
|
|
24
|
+
[2 /* ErrorCodes.DUPLICATE_ATTRIBUTE */]: 'Duplicate attribute.',
|
|
25
|
+
[3 /* ErrorCodes.END_TAG_WITH_ATTRIBUTES */]: 'End tag cannot have attributes.',
|
|
26
|
+
[4 /* ErrorCodes.END_TAG_WITH_TRAILING_SOLIDUS */]: "Illegal '/' in tags.",
|
|
27
|
+
[5 /* ErrorCodes.EOF_BEFORE_TAG_NAME */]: 'Unexpected EOF in tag.',
|
|
28
|
+
[6 /* ErrorCodes.EOF_IN_CDATA */]: 'Unexpected EOF in CDATA section.',
|
|
29
|
+
[7 /* ErrorCodes.EOF_IN_COMMENT */]: 'Unexpected EOF in comment.',
|
|
30
|
+
[8 /* ErrorCodes.EOF_IN_SCRIPT_HTML_COMMENT_LIKE_TEXT */]: 'Unexpected EOF in script.',
|
|
31
|
+
[9 /* ErrorCodes.EOF_IN_TAG */]: 'Unexpected EOF in tag.',
|
|
32
|
+
[10 /* ErrorCodes.INCORRECTLY_CLOSED_COMMENT */]: 'Incorrectly closed comment.',
|
|
33
|
+
[11 /* ErrorCodes.INCORRECTLY_OPENED_COMMENT */]: 'Incorrectly opened comment.',
|
|
34
|
+
[12 /* ErrorCodes.INVALID_FIRST_CHARACTER_OF_TAG_NAME */]: "Illegal tag name. Use '<' to print '<'.",
|
|
35
|
+
[13 /* ErrorCodes.MISSING_ATTRIBUTE_VALUE */]: 'Attribute value was expected.',
|
|
36
|
+
[14 /* ErrorCodes.MISSING_END_TAG_NAME */]: 'End tag name was expected.',
|
|
37
|
+
[15 /* ErrorCodes.MISSING_WHITESPACE_BETWEEN_ATTRIBUTES */]: 'Whitespace was expected.',
|
|
38
|
+
[16 /* ErrorCodes.NESTED_COMMENT */]: "Unexpected '<!--' in comment.",
|
|
39
|
+
[17 /* ErrorCodes.UNEXPECTED_CHARACTER_IN_ATTRIBUTE_NAME */]: 'Attribute name cannot contain U+0022 ("), U+0027 (\'), and U+003C (<).',
|
|
40
|
+
[18 /* ErrorCodes.UNEXPECTED_CHARACTER_IN_UNQUOTED_ATTRIBUTE_VALUE */]: 'Unquoted attribute value cannot contain U+0022 ("), U+0027 (\'), U+003C (<), U+003D (=), and U+0060 (`).',
|
|
41
|
+
[19 /* ErrorCodes.UNEXPECTED_EQUALS_SIGN_BEFORE_ATTRIBUTE_NAME */]: "Attribute name cannot start with '='.",
|
|
42
|
+
[21 /* ErrorCodes.UNEXPECTED_QUESTION_MARK_INSTEAD_OF_TAG_NAME */]: "'<?' is allowed only in XML context.",
|
|
43
|
+
[20 /* ErrorCodes.UNEXPECTED_NULL_CHARACTER */]: `Unexpected null character.`,
|
|
44
|
+
[22 /* ErrorCodes.UNEXPECTED_SOLIDUS_IN_TAG */]: "Illegal '/' in tags.",
|
|
45
|
+
// Vue-specific parse errors
|
|
46
|
+
[23 /* ErrorCodes.X_INVALID_END_TAG */]: 'Invalid end tag.',
|
|
47
|
+
[24 /* ErrorCodes.X_MISSING_END_TAG */]: 'Element is missing end tag.',
|
|
48
|
+
[25 /* ErrorCodes.X_MISSING_INTERPOLATION_END */]: 'Interpolation end sign was not found.',
|
|
49
|
+
[27 /* ErrorCodes.X_MISSING_DYNAMIC_DIRECTIVE_ARGUMENT_END */]: 'End bracket for dynamic directive argument was not found. ' +
|
|
50
|
+
'Note that dynamic directive argument cannot contain spaces.',
|
|
51
|
+
[26 /* ErrorCodes.X_MISSING_DIRECTIVE_NAME */]: 'Legal directive name was expected.',
|
|
52
|
+
// transform errors
|
|
53
|
+
[28 /* ErrorCodes.X_V_IF_NO_EXPRESSION */]: `v-if/v-else-if is missing expression.`,
|
|
54
|
+
[29 /* ErrorCodes.X_V_IF_SAME_KEY */]: `v-if/else branches must use unique keys.`,
|
|
55
|
+
[30 /* ErrorCodes.X_V_ELSE_NO_ADJACENT_IF */]: `v-else/v-else-if has no adjacent v-if or v-else-if.`,
|
|
56
|
+
[31 /* ErrorCodes.X_V_FOR_NO_EXPRESSION */]: `v-for is missing expression.`,
|
|
57
|
+
[32 /* ErrorCodes.X_V_FOR_MALFORMED_EXPRESSION */]: `v-for has invalid expression.`,
|
|
58
|
+
[33 /* ErrorCodes.X_V_FOR_TEMPLATE_KEY_PLACEMENT */]: `<template v-for> key should be placed on the <template> tag.`,
|
|
59
|
+
[34 /* ErrorCodes.X_V_BIND_NO_EXPRESSION */]: `v-bind is missing expression.`,
|
|
60
|
+
[35 /* ErrorCodes.X_V_ON_NO_EXPRESSION */]: `v-on is missing expression.`,
|
|
61
|
+
[36 /* ErrorCodes.X_V_SLOT_UNEXPECTED_DIRECTIVE_ON_SLOT_OUTLET */]: `Unexpected custom directive on <slot> outlet.`,
|
|
62
|
+
[37 /* ErrorCodes.X_V_SLOT_MIXED_SLOT_USAGE */]: `Mixed v-slot usage on both the component and nested <template>. ` +
|
|
63
|
+
`When there are multiple named slots, all slots should use <template> ` +
|
|
64
|
+
`syntax to avoid scope ambiguity.`,
|
|
65
|
+
[38 /* ErrorCodes.X_V_SLOT_DUPLICATE_SLOT_NAMES */]: `Duplicate slot names found. `,
|
|
66
|
+
[39 /* ErrorCodes.X_V_SLOT_EXTRANEOUS_DEFAULT_SLOT_CHILDREN */]: `Extraneous children found when component already has explicitly named ` +
|
|
67
|
+
`default slot. These children will be ignored.`,
|
|
68
|
+
[40 /* ErrorCodes.X_V_SLOT_MISPLACED */]: `v-slot can only be used on components or <template> tags.`,
|
|
69
|
+
[41 /* ErrorCodes.X_V_MODEL_NO_EXPRESSION */]: `v-model is missing expression.`,
|
|
70
|
+
[42 /* ErrorCodes.X_V_MODEL_MALFORMED_EXPRESSION */]: `v-model value must be a valid JavaScript member expression.`,
|
|
71
|
+
[43 /* ErrorCodes.X_V_MODEL_ON_SCOPE_VARIABLE */]: `v-model cannot be used on v-for or v-slot scope variables because they are not writable.`,
|
|
72
|
+
[44 /* ErrorCodes.X_V_MODEL_ON_PROPS */]: `v-model cannot be used on a prop, because local prop bindings are not writable.\nUse a v-bind binding combined with a v-on listener that emits update:x event instead.`,
|
|
73
|
+
[45 /* ErrorCodes.X_INVALID_EXPRESSION */]: `Error parsing JavaScript expression: `,
|
|
74
|
+
[46 /* ErrorCodes.X_KEEP_ALIVE_INVALID_CHILDREN */]: `<KeepAlive> expects exactly one child component.`,
|
|
75
|
+
// generic errors
|
|
76
|
+
[47 /* ErrorCodes.X_PREFIX_ID_NOT_SUPPORTED */]: `"prefixIdentifiers" option is not supported in this build of compiler.`,
|
|
77
|
+
[48 /* ErrorCodes.X_MODULE_MODE_NOT_SUPPORTED */]: `ES module mode is not supported in this build of compiler.`,
|
|
78
|
+
[49 /* ErrorCodes.X_CACHE_HANDLER_NOT_SUPPORTED */]: `"cacheHandlers" option is only supported when the "prefixIdentifiers" option is enabled.`,
|
|
79
|
+
[50 /* ErrorCodes.X_SCOPE_ID_NOT_SUPPORTED */]: `"scopeId" option is only supported in module mode.`,
|
|
80
|
+
// just to fulfill types
|
|
81
|
+
[51 /* ErrorCodes.__EXTEND_POINT__ */]: ``,
|
|
82
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import './runtimeHelpers';
|
|
2
|
+
import { CodegenResult, CompilerOptions } from './options';
|
|
3
|
+
import { DirectiveTransform, NodeTransform } from './transform';
|
|
4
|
+
export type TransformPreset = [
|
|
5
|
+
NodeTransform[],
|
|
6
|
+
Record<string, DirectiveTransform>
|
|
7
|
+
];
|
|
8
|
+
export declare function getBaseTransformPreset(prefixIdentifiers?: boolean): TransformPreset;
|
|
9
|
+
export declare function compile(template: string, options: CompilerOptions): CodegenResult;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.compile = exports.getBaseTransformPreset = void 0;
|
|
4
|
+
const shared_1 = require("@vue/shared");
|
|
5
|
+
const compiler_core_1 = require("@vue/compiler-core");
|
|
6
|
+
const uni_shared_1 = require("@dcloudio/uni-shared");
|
|
7
|
+
const uni_cli_shared_1 = require("@dcloudio/uni-cli-shared");
|
|
8
|
+
require("./runtimeHelpers");
|
|
9
|
+
const codegen_1 = require("./codegen");
|
|
10
|
+
const transform_1 = require("./transform");
|
|
11
|
+
const vIf_1 = require("./transforms/vIf");
|
|
12
|
+
const vFor_1 = require("./transforms/vFor");
|
|
13
|
+
const vModel_1 = require("./transforms/vModel");
|
|
14
|
+
const vShow_1 = require("./transforms/vShow");
|
|
15
|
+
const vText_1 = require("./transforms/vText");
|
|
16
|
+
const transformInterpolation_1 = require("./transforms/transformInterpolation");
|
|
17
|
+
const transformText_1 = require("./transforms/transformText");
|
|
18
|
+
const vOn_1 = require("./transforms/vOn");
|
|
19
|
+
const vBind_1 = require("./transforms/vBind");
|
|
20
|
+
const transformSlotOutlet_1 = require("./transforms/transformSlotOutlet");
|
|
21
|
+
function getBaseTransformPreset(prefixIdentifiers) {
|
|
22
|
+
return [
|
|
23
|
+
[
|
|
24
|
+
vIf_1.transformIf,
|
|
25
|
+
vFor_1.transformFor,
|
|
26
|
+
// order is important
|
|
27
|
+
compiler_core_1.trackVForSlotScopes,
|
|
28
|
+
compiler_core_1.transformExpression,
|
|
29
|
+
transformSlotOutlet_1.transformSlotOutlet,
|
|
30
|
+
compiler_core_1.transformElement,
|
|
31
|
+
compiler_core_1.trackSlotScopes,
|
|
32
|
+
transformText_1.transformText,
|
|
33
|
+
uni_cli_shared_1.transformTapToClick,
|
|
34
|
+
transformInterpolation_1.transformInterpolation,
|
|
35
|
+
],
|
|
36
|
+
{
|
|
37
|
+
on: vOn_1.transformOn,
|
|
38
|
+
bind: vBind_1.transformBind,
|
|
39
|
+
model: vModel_1.transformModel,
|
|
40
|
+
show: vShow_1.transformShow,
|
|
41
|
+
text: vText_1.transformVText,
|
|
42
|
+
},
|
|
43
|
+
];
|
|
44
|
+
}
|
|
45
|
+
exports.getBaseTransformPreset = getBaseTransformPreset;
|
|
46
|
+
function compile(template, options) {
|
|
47
|
+
const ast = (0, compiler_core_1.baseParse)(template, {
|
|
48
|
+
isNativeTag(tag) {
|
|
49
|
+
return ((0, uni_shared_1.isAppUVueNativeTag)(tag) ||
|
|
50
|
+
!!options.parseUTSComponent?.(tag, options.targetLanguage));
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
const [nodeTransforms, directiveTransforms] = getBaseTransformPreset(options.prefixIdentifiers);
|
|
54
|
+
(0, transform_1.transform)(ast, (0, shared_1.extend)({}, options, {
|
|
55
|
+
prefixIdentifiers: options.prefixIdentifiers,
|
|
56
|
+
nodeTransforms: [
|
|
57
|
+
...nodeTransforms,
|
|
58
|
+
...(options.nodeTransforms || []), // user transforms
|
|
59
|
+
],
|
|
60
|
+
directiveTransforms: (0, shared_1.extend)({}, directiveTransforms, options.directiveTransforms || {} // user transforms
|
|
61
|
+
),
|
|
62
|
+
}));
|
|
63
|
+
return (0, codegen_1.generate)(ast, options);
|
|
64
|
+
}
|
|
65
|
+
exports.compile = compile;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { BindingMetadata, 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
|
+
* Optional binding metadata analyzed from script - used to optimize
|
|
13
|
+
* binding access when `prefixIdentifiers` is enabled.
|
|
14
|
+
*/
|
|
15
|
+
bindingMetadata?: BindingMetadata;
|
|
16
|
+
/**
|
|
17
|
+
* Filename for source map generation.
|
|
18
|
+
* Also used for self-recursive reference in templates
|
|
19
|
+
* @default ''
|
|
20
|
+
*/
|
|
21
|
+
filename?: string;
|
|
22
|
+
}
|
|
23
|
+
export interface CodegenOptions extends SharedTransformCodegenOptions {
|
|
24
|
+
/**
|
|
25
|
+
* function
|
|
26
|
+
* @default 'default'
|
|
27
|
+
*/
|
|
28
|
+
mode?: 'default' | 'function';
|
|
29
|
+
/**
|
|
30
|
+
* Generate source map?
|
|
31
|
+
* @default false
|
|
32
|
+
*/
|
|
33
|
+
sourceMap?: boolean;
|
|
34
|
+
/**
|
|
35
|
+
* 匹配 easycom 组件
|
|
36
|
+
* @param tag
|
|
37
|
+
*/
|
|
38
|
+
matchEasyCom?: (tag: string, uts: boolean) => string | false | undefined | void;
|
|
39
|
+
/**
|
|
40
|
+
* 解析 uts component 组件
|
|
41
|
+
* @param name
|
|
42
|
+
* @param type
|
|
43
|
+
*/
|
|
44
|
+
parseUTSComponent?: (name: string, type: 'kotlin' | 'swift') => {
|
|
45
|
+
className: string;
|
|
46
|
+
namespace: string;
|
|
47
|
+
source: string;
|
|
48
|
+
} | undefined | void;
|
|
49
|
+
}
|
|
50
|
+
export interface ErrorHandlingOptions {
|
|
51
|
+
onWarn?: (warning: CompilerError) => void;
|
|
52
|
+
onError?: (error: CompilerError) => void;
|
|
53
|
+
}
|
|
54
|
+
export interface TransformOptions extends SharedTransformCodegenOptions, ErrorHandlingOptions {
|
|
55
|
+
/**
|
|
56
|
+
* An array of node transforms to be applied to every AST node.
|
|
57
|
+
*/
|
|
58
|
+
nodeTransforms?: NodeTransform[];
|
|
59
|
+
/**
|
|
60
|
+
* An object of { name: transform } to be applied to every directive attribute
|
|
61
|
+
* node found on element nodes.
|
|
62
|
+
*/
|
|
63
|
+
directiveTransforms?: Record<string, DirectiveTransform | undefined>;
|
|
64
|
+
/**
|
|
65
|
+
* If the pairing runtime provides additional built-in elements, use this to
|
|
66
|
+
* mark them as built-in so the compiler will generate component vnodes
|
|
67
|
+
* for them.
|
|
68
|
+
*/
|
|
69
|
+
isBuiltInComponent?: (tag: string) => symbol | void;
|
|
70
|
+
/**
|
|
71
|
+
* Used by some transforms that expects only native elements
|
|
72
|
+
*/
|
|
73
|
+
isCustomElement?: (tag: string) => boolean | void;
|
|
74
|
+
/**
|
|
75
|
+
* SFC scoped styles ID
|
|
76
|
+
*/
|
|
77
|
+
scopeId?: string | null;
|
|
78
|
+
/**
|
|
79
|
+
* Indicates this SFC template has used :slotted in its styles
|
|
80
|
+
* Defaults to `true` for backwards compatibility - SFC tooling should set it
|
|
81
|
+
* to `false` if no `:slotted` usage is detected in `<style>`
|
|
82
|
+
*/
|
|
83
|
+
slotted?: boolean;
|
|
84
|
+
}
|
|
85
|
+
export type CompilerOptions = TransformOptions & CodegenOptions;
|
|
86
|
+
export interface CodegenResult {
|
|
87
|
+
code: string;
|
|
88
|
+
importEasyComponents: string[];
|
|
89
|
+
importUTSComponents: string[];
|
|
90
|
+
map?: RawSourceMap;
|
|
91
|
+
}
|
|
92
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare const IS_TRUE: unique symbol;
|
|
2
|
+
export declare const V_SHOW: unique symbol;
|
|
3
|
+
export declare const RENDER_LIST: unique symbol;
|
|
4
|
+
export declare const FRAGMENT: unique symbol;
|
|
5
|
+
export declare const OPEN_BLOCK: unique symbol;
|
|
6
|
+
export declare const RESOLVE_COMPONENT: unique symbol;
|
|
7
|
+
export declare const RESOLVE_DIRECTIVE: unique symbol;
|
|
8
|
+
export declare const RESOLVE_EASY_COMPONENT: unique symbol;
|
|
9
|
+
export declare const RENDER_SLOT: unique symbol;
|
|
10
|
+
export declare const TO_HANDLERS: unique symbol;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TO_HANDLERS = exports.RENDER_SLOT = exports.RESOLVE_EASY_COMPONENT = exports.RESOLVE_DIRECTIVE = exports.RESOLVE_COMPONENT = exports.OPEN_BLOCK = exports.FRAGMENT = exports.RENDER_LIST = exports.V_SHOW = exports.IS_TRUE = void 0;
|
|
4
|
+
const compiler_core_1 = require("@vue/compiler-core");
|
|
5
|
+
exports.IS_TRUE = Symbol(`isTrue`);
|
|
6
|
+
exports.V_SHOW = Symbol(`vShow`);
|
|
7
|
+
exports.RENDER_LIST = Symbol(`renderList`);
|
|
8
|
+
exports.FRAGMENT = Symbol(`Fragment`);
|
|
9
|
+
exports.OPEN_BLOCK = Symbol(`openBlock`);
|
|
10
|
+
exports.RESOLVE_COMPONENT = Symbol(`resolveComponent`);
|
|
11
|
+
exports.RESOLVE_DIRECTIVE = Symbol(`resolveDirective`);
|
|
12
|
+
exports.RESOLVE_EASY_COMPONENT = Symbol(`resolveEasyComponent`);
|
|
13
|
+
exports.RENDER_SLOT = Symbol(`renderSlot`);
|
|
14
|
+
exports.TO_HANDLERS = Symbol(`toHandlers`);
|
|
15
|
+
(0, compiler_core_1.registerRuntimeHelpers)({
|
|
16
|
+
[exports.IS_TRUE]: 'isTrue',
|
|
17
|
+
[exports.V_SHOW]: 'vShow',
|
|
18
|
+
[exports.RENDER_LIST]: 'RenderHelpers.renderList',
|
|
19
|
+
[exports.FRAGMENT]: 'Fragment',
|
|
20
|
+
[exports.RESOLVE_COMPONENT]: 'resolveComponent',
|
|
21
|
+
[exports.RESOLVE_EASY_COMPONENT]: 'resolveEasyComponent',
|
|
22
|
+
[exports.RESOLVE_DIRECTIVE]: 'resolveDirective',
|
|
23
|
+
[exports.RENDER_SLOT]: `renderSlot`,
|
|
24
|
+
[exports.TO_HANDLERS]: `toHandlers`,
|
|
25
|
+
});
|
|
@@ -0,0 +1,53 @@
|
|
|
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, scopeId, slotted, 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;
|
|
53
|
+
export declare function createStructuralDirectiveTransform(name: string | RegExp, fn: StructuralDirectiveTransform): NodeTransform;
|
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createStructuralDirectiveTransform = 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
|
+
const runtimeHelpers_1 = require("./runtimeHelpers");
|
|
8
|
+
function createTransformContext(root, { targetLanguage, filename = '', prefixIdentifiers = false, nodeTransforms = [], directiveTransforms = {}, scopeId = null, slotted = true, isBuiltInComponent = shared_1.NOOP, isCustomElement = shared_1.NOOP, onError = errors_1.defaultOnError, onWarn = errors_1.defaultOnWarn, }) {
|
|
9
|
+
const nameMatch = filename.replace(/\?.*$/, '').match(/([^/\\]+)\.\w+$/);
|
|
10
|
+
const context = {
|
|
11
|
+
// options
|
|
12
|
+
targetLanguage,
|
|
13
|
+
selfName: nameMatch && (0, shared_1.capitalize)((0, shared_1.camelize)(nameMatch[1])),
|
|
14
|
+
prefixIdentifiers,
|
|
15
|
+
bindingMetadata: {},
|
|
16
|
+
nodeTransforms,
|
|
17
|
+
directiveTransforms,
|
|
18
|
+
isBuiltInComponent,
|
|
19
|
+
isCustomElement,
|
|
20
|
+
scopeId,
|
|
21
|
+
slotted,
|
|
22
|
+
onError,
|
|
23
|
+
onWarn,
|
|
24
|
+
// state
|
|
25
|
+
root,
|
|
26
|
+
helpers: new Map(),
|
|
27
|
+
components: new Set(),
|
|
28
|
+
directives: new Set(),
|
|
29
|
+
imports: [],
|
|
30
|
+
constantCache: new Map(),
|
|
31
|
+
temps: 0,
|
|
32
|
+
cached: 0,
|
|
33
|
+
identifiers: Object.create(null),
|
|
34
|
+
scopes: {
|
|
35
|
+
vFor: 0,
|
|
36
|
+
vSlot: 0,
|
|
37
|
+
vPre: 0,
|
|
38
|
+
vOnce: 0,
|
|
39
|
+
},
|
|
40
|
+
parent: null,
|
|
41
|
+
currentNode: root,
|
|
42
|
+
childIndex: 0,
|
|
43
|
+
inVOnce: false,
|
|
44
|
+
// methods
|
|
45
|
+
helper(name) {
|
|
46
|
+
const count = context.helpers.get(name) || 0;
|
|
47
|
+
context.helpers.set(name, count + 1);
|
|
48
|
+
return name;
|
|
49
|
+
},
|
|
50
|
+
removeHelper(name) {
|
|
51
|
+
const count = context.helpers.get(name);
|
|
52
|
+
if (count) {
|
|
53
|
+
const currentCount = count - 1;
|
|
54
|
+
if (!currentCount) {
|
|
55
|
+
context.helpers.delete(name);
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
context.helpers.set(name, currentCount);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
helperString(name) {
|
|
63
|
+
// return `_${helperNameMap[context.helper(name)]}`
|
|
64
|
+
return `${compiler_core_1.helperNameMap[context.helper(name)]}`;
|
|
65
|
+
},
|
|
66
|
+
replaceNode(node) {
|
|
67
|
+
if (!context.currentNode) {
|
|
68
|
+
throw new Error(`Node being replaced is already removed.`);
|
|
69
|
+
}
|
|
70
|
+
if (!context.parent) {
|
|
71
|
+
throw new Error(`Cannot replace root node.`);
|
|
72
|
+
}
|
|
73
|
+
context.parent.children[context.childIndex] = context.currentNode = node;
|
|
74
|
+
},
|
|
75
|
+
removeNode(node) {
|
|
76
|
+
if (!context.parent) {
|
|
77
|
+
throw new Error(`Cannot remove root node.`);
|
|
78
|
+
}
|
|
79
|
+
const list = context.parent.children;
|
|
80
|
+
const removalIndex = node
|
|
81
|
+
? list.indexOf(node)
|
|
82
|
+
: context.currentNode
|
|
83
|
+
? context.childIndex
|
|
84
|
+
: -1;
|
|
85
|
+
/* istanbul ignore if */
|
|
86
|
+
if (removalIndex < 0) {
|
|
87
|
+
throw new Error(`node being removed is not a child of current parent`);
|
|
88
|
+
}
|
|
89
|
+
if (!node || node === context.currentNode) {
|
|
90
|
+
// current node removed
|
|
91
|
+
context.currentNode = null;
|
|
92
|
+
context.onNodeRemoved();
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
// sibling node removed
|
|
96
|
+
if (context.childIndex > removalIndex) {
|
|
97
|
+
context.childIndex--;
|
|
98
|
+
context.onNodeRemoved();
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
context.parent.children.splice(removalIndex, 1);
|
|
102
|
+
},
|
|
103
|
+
onNodeRemoved: () => { },
|
|
104
|
+
addIdentifiers(exp) {
|
|
105
|
+
// identifier tracking only happens in non-browser builds.
|
|
106
|
+
if ((0, shared_1.isString)(exp)) {
|
|
107
|
+
addId(exp);
|
|
108
|
+
}
|
|
109
|
+
else if (exp.identifiers) {
|
|
110
|
+
exp.identifiers.forEach(addId);
|
|
111
|
+
}
|
|
112
|
+
else if (exp.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */) {
|
|
113
|
+
addId(exp.content);
|
|
114
|
+
}
|
|
115
|
+
},
|
|
116
|
+
removeIdentifiers(exp) {
|
|
117
|
+
if ((0, shared_1.isString)(exp)) {
|
|
118
|
+
removeId(exp);
|
|
119
|
+
}
|
|
120
|
+
else if (exp.identifiers) {
|
|
121
|
+
exp.identifiers.forEach(removeId);
|
|
122
|
+
}
|
|
123
|
+
else if (exp.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */) {
|
|
124
|
+
removeId(exp.content);
|
|
125
|
+
}
|
|
126
|
+
},
|
|
127
|
+
cache(exp, isVNode = false) {
|
|
128
|
+
return (0, compiler_core_1.createCacheExpression)(context.cached++, exp, isVNode);
|
|
129
|
+
},
|
|
130
|
+
};
|
|
131
|
+
function addId(id) {
|
|
132
|
+
const { identifiers } = context;
|
|
133
|
+
if (identifiers[id] === undefined) {
|
|
134
|
+
identifiers[id] = 0;
|
|
135
|
+
}
|
|
136
|
+
identifiers[id]++;
|
|
137
|
+
}
|
|
138
|
+
function removeId(id) {
|
|
139
|
+
context.identifiers[id]--;
|
|
140
|
+
}
|
|
141
|
+
return context;
|
|
142
|
+
}
|
|
143
|
+
exports.createTransformContext = createTransformContext;
|
|
144
|
+
function transform(root, options) {
|
|
145
|
+
const context = createTransformContext(root, options);
|
|
146
|
+
traverseNode(root, context);
|
|
147
|
+
createRootCodegen(root, context);
|
|
148
|
+
root.components = [...context.components];
|
|
149
|
+
}
|
|
150
|
+
exports.transform = transform;
|
|
151
|
+
function isSingleElementRoot(root, child) {
|
|
152
|
+
const { children } = root;
|
|
153
|
+
return (children.length === 1 &&
|
|
154
|
+
child.type === 1 /* NodeTypes.ELEMENT */ &&
|
|
155
|
+
!(0, compiler_core_1.isSlotOutlet)(child));
|
|
156
|
+
}
|
|
157
|
+
exports.isSingleElementRoot = isSingleElementRoot;
|
|
158
|
+
function createRootCodegen(root, context) {
|
|
159
|
+
const { helper } = context;
|
|
160
|
+
const { children } = root;
|
|
161
|
+
if (children.length === 1) {
|
|
162
|
+
const child = children[0];
|
|
163
|
+
// if the single child is an element, turn it into a block.
|
|
164
|
+
if (isSingleElementRoot(root, child) && child.codegenNode) {
|
|
165
|
+
// single element root is never hoisted so codegenNode will never be
|
|
166
|
+
// SimpleExpressionNode
|
|
167
|
+
const codegenNode = child.codegenNode;
|
|
168
|
+
if (codegenNode.type === 13 /* NodeTypes.VNODE_CALL */) {
|
|
169
|
+
(0, compiler_core_1.makeBlock)(codegenNode, context);
|
|
170
|
+
}
|
|
171
|
+
root.codegenNode = codegenNode;
|
|
172
|
+
}
|
|
173
|
+
else {
|
|
174
|
+
// - single <slot/>, IfNode, ForNode: already blocks.
|
|
175
|
+
// - single text node: always patched.
|
|
176
|
+
// root codegen falls through via genNode()
|
|
177
|
+
root.codegenNode = child;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
else if (children.length > 1) {
|
|
181
|
+
// root has multiple nodes - return a fragment block.
|
|
182
|
+
let patchFlag = 64 /* PatchFlags.STABLE_FRAGMENT */;
|
|
183
|
+
let patchFlagText = shared_1.PatchFlagNames[64 /* PatchFlags.STABLE_FRAGMENT */];
|
|
184
|
+
// check if the fragment actually contains a single valid child with
|
|
185
|
+
// the rest being comments
|
|
186
|
+
if (children.filter((c) => c.type !== 3 /* NodeTypes.COMMENT */).length === 1) {
|
|
187
|
+
patchFlag |= 2048 /* PatchFlags.DEV_ROOT_FRAGMENT */;
|
|
188
|
+
patchFlagText += `, ${shared_1.PatchFlagNames[2048 /* PatchFlags.DEV_ROOT_FRAGMENT */]}`;
|
|
189
|
+
}
|
|
190
|
+
root.codegenNode = (0, compiler_core_1.createVNodeCall)(
|
|
191
|
+
// @ts-ignore
|
|
192
|
+
context, helper(runtimeHelpers_1.FRAGMENT), undefined, root.children, patchFlag + ` /* ${patchFlagText} */`, undefined, undefined, true, undefined, false /* isComponent */);
|
|
193
|
+
}
|
|
194
|
+
else {
|
|
195
|
+
// no children = noop. codegen will return null.
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
function traverseChildren(parent, context) {
|
|
199
|
+
let i = 0;
|
|
200
|
+
const nodeRemoved = () => {
|
|
201
|
+
i--;
|
|
202
|
+
};
|
|
203
|
+
for (; i < parent.children.length; i++) {
|
|
204
|
+
const child = parent.children[i];
|
|
205
|
+
if ((0, shared_1.isString)(child))
|
|
206
|
+
continue;
|
|
207
|
+
context.parent = parent;
|
|
208
|
+
context.childIndex = i;
|
|
209
|
+
context.onNodeRemoved = nodeRemoved;
|
|
210
|
+
traverseNode(child, context);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
exports.traverseChildren = traverseChildren;
|
|
214
|
+
function traverseNode(node, context) {
|
|
215
|
+
context.currentNode = node;
|
|
216
|
+
// apply transform plugins
|
|
217
|
+
const { nodeTransforms } = context;
|
|
218
|
+
const exitFns = [];
|
|
219
|
+
for (let i = 0; i < nodeTransforms.length; i++) {
|
|
220
|
+
const onExit = nodeTransforms[i](node, context);
|
|
221
|
+
if (onExit) {
|
|
222
|
+
if ((0, shared_1.isArray)(onExit)) {
|
|
223
|
+
exitFns.push(...onExit);
|
|
224
|
+
}
|
|
225
|
+
else {
|
|
226
|
+
exitFns.push(onExit);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
if (!context.currentNode) {
|
|
230
|
+
// node was removed
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
else {
|
|
234
|
+
// node may have been replaced
|
|
235
|
+
node = context.currentNode;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
switch (node.type) {
|
|
239
|
+
case 3 /* NodeTypes.COMMENT */:
|
|
240
|
+
break;
|
|
241
|
+
case 5 /* NodeTypes.INTERPOLATION */:
|
|
242
|
+
break;
|
|
243
|
+
// for container types, further traverse downwards
|
|
244
|
+
case 9 /* NodeTypes.IF */:
|
|
245
|
+
for (let i = 0; i < node.branches.length; i++) {
|
|
246
|
+
traverseNode(node.branches[i], context);
|
|
247
|
+
}
|
|
248
|
+
break;
|
|
249
|
+
case 10 /* NodeTypes.IF_BRANCH */:
|
|
250
|
+
case 11 /* NodeTypes.FOR */:
|
|
251
|
+
case 1 /* NodeTypes.ELEMENT */:
|
|
252
|
+
case 0 /* NodeTypes.ROOT */:
|
|
253
|
+
traverseChildren(node, context);
|
|
254
|
+
break;
|
|
255
|
+
}
|
|
256
|
+
// exit transforms
|
|
257
|
+
context.currentNode = node;
|
|
258
|
+
let i = exitFns.length;
|
|
259
|
+
while (i--) {
|
|
260
|
+
exitFns[i]();
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
exports.traverseNode = traverseNode;
|
|
264
|
+
function createStructuralDirectiveTransform(name, fn) {
|
|
265
|
+
const matches = (0, shared_1.isString)(name)
|
|
266
|
+
? (n) => n === name
|
|
267
|
+
: (n) => name.test(n);
|
|
268
|
+
return (node, context) => {
|
|
269
|
+
if (node.type === 1 /* NodeTypes.ELEMENT */) {
|
|
270
|
+
const { props } = node;
|
|
271
|
+
// structural directive transforms are not concerned with slots
|
|
272
|
+
// as they are handled separately in vSlot.ts
|
|
273
|
+
if (node.tagType === 3 /* ElementTypes.TEMPLATE */ && props.some(compiler_core_1.isVSlot)) {
|
|
274
|
+
return;
|
|
275
|
+
}
|
|
276
|
+
const exitFns = [];
|
|
277
|
+
for (let i = 0; i < props.length; i++) {
|
|
278
|
+
const prop = props[i];
|
|
279
|
+
if (prop.type === 7 /* NodeTypes.DIRECTIVE */ && matches(prop.name)) {
|
|
280
|
+
// structural directives are removed to avoid infinite recursion
|
|
281
|
+
// also we remove them *before* applying so that it can further
|
|
282
|
+
// traverse itself in case it moves the node around
|
|
283
|
+
props.splice(i, 1);
|
|
284
|
+
i--;
|
|
285
|
+
const onExit = fn(node, prop, context);
|
|
286
|
+
if (onExit)
|
|
287
|
+
exitFns.push(onExit);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
return exitFns;
|
|
291
|
+
}
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
exports.createStructuralDirectiveTransform = createStructuralDirectiveTransform;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { NodeTransform, TransformContext } from '../transform';
|
|
2
|
+
import { ExpressionNode, SimpleExpressionNode } from '@vue/compiler-core';
|
|
3
|
+
export declare const transformExpression: NodeTransform;
|
|
4
|
+
export declare function processExpression(node: SimpleExpressionNode, context: TransformContext, asParams?: boolean, asRawStatements?: boolean, localVars?: Record<string, number>): ExpressionNode;
|
|
5
|
+
export declare function stringifyExpression(exp: ExpressionNode | string): string;
|