@dcloudio/uni-cli-shared 3.0.0-4080720251210001 → 3.0.0-5000320260312001
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/dist/constants.d.ts +3 -0
- package/dist/constants.js +6 -1
- package/dist/deps.js +6 -1
- package/dist/dom2/index.d.ts +1 -0
- package/dist/dom2/index.js +17 -0
- package/dist/dom2/sharedData.d.ts +2 -0
- package/dist/dom2/sharedData.js +19 -0
- package/dist/easycom.js +34 -5
- package/dist/env/define.d.ts +3 -0
- package/dist/env/define.js +12 -0
- package/dist/hbx/alias.js +15 -17
- package/dist/hbx/index.d.ts +1 -1
- package/dist/hbx/index.js +4 -2
- package/dist/hbx/log.d.ts +5 -0
- package/dist/hbx/log.js +44 -1
- package/dist/i18n.js +4 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/json/app/manifest/index.d.ts +1 -0
- package/dist/json/app/manifest/index.js +3 -1
- package/dist/json/mp/pages.js +0 -5
- package/dist/json/pages.d.ts +2 -2
- package/dist/json/pages.js +4 -1
- package/dist/json/uni-x/index.d.ts +1 -1
- package/dist/json/utils.js +31 -22
- package/dist/logs/console.js +1 -1
- package/dist/logs/index.d.ts +11 -0
- package/dist/logs/index.js +34 -1
- package/dist/messages/en.d.ts +6 -3
- package/dist/messages/en.js +6 -3
- package/dist/messages/index.d.ts +11 -5
- package/dist/messages/zh_CN.d.ts +5 -2
- package/dist/messages/zh_CN.js +5 -2
- package/dist/mp/assets.d.ts +1 -0
- package/dist/mp/assets.js +27 -1
- package/dist/mp/externalClasses.d.ts +38 -2
- package/dist/mp/externalClasses.js +90 -4
- package/dist/mp/index.d.ts +4 -3
- package/dist/mp/index.js +11 -1
- package/dist/mp/plugin.d.ts +1 -0
- package/dist/mp/plugin.js +14 -1
- package/dist/mp/style.d.ts +1 -0
- package/dist/mp/style.js +8 -1
- package/dist/mp/usingComponents.d.ts +1 -0
- package/dist/mp/usingComponents.js +17 -1
- package/dist/postcss/index.d.ts +2 -0
- package/dist/postcss/index.js +3 -1
- package/dist/postcss/plugins/stylePluginExternal.d.ts +17 -0
- package/dist/postcss/plugins/stylePluginExternal.js +127 -0
- package/dist/postcss/plugins/stylePluginScoped.js +30 -0
- package/dist/preprocess/context.js +2 -0
- package/dist/preprocess/index.d.ts +9 -6
- package/dist/preprocess/index.js +33 -8
- package/dist/resolve.js +5 -1
- package/dist/uni_modules.js +20 -4
- package/dist/utils.d.ts +2 -2
- package/dist/utils.js +9 -6
- package/dist/utsUtils.d.ts +1 -0
- package/dist/utsUtils.js +2 -1
- package/dist/vite/autoImport.js +91 -6
- package/dist/vite/plugins/console.js +1 -1
- package/dist/vite/plugins/cssScoped.js +2 -1
- package/dist/vite/plugins/easycom.js +7 -0
- package/dist/vite/plugins/json.js +69 -2
- package/dist/vite/plugins/pre.js +4 -2
- package/dist/vite/plugins/sfc.js +1 -1
- package/dist/vite/plugins/stats.js +32 -0
- package/dist/vite/plugins/uts/ext-api.js +1 -1
- package/dist/vite/plugins/uts/uni_modules.js +12 -0
- package/dist/vite/plugins/uts/uvue.js +7 -2
- package/dist/vite/plugins/vitejs/plugins/asset.d.ts +1 -0
- package/dist/vite/plugins/vitejs/plugins/asset.js +19 -1
- package/dist/vite/plugins/vitejs/plugins/css.d.ts +2 -1
- package/dist/vite/plugins/vitejs/plugins/css.js +27 -10
- package/dist/vite/utils/ast.d.ts +2 -1
- package/dist/vite/utils/ast.js +5 -1
- package/dist/vue/parse.d.ts +2 -0
- package/dist/vue/parse.js +3 -1
- package/dist/vue/transforms/index.d.ts +1 -0
- package/dist/vue/transforms/index.js +1 -0
- package/dist/vue/transforms/transformLineBreak.d.ts +2 -0
- package/dist/vue/transforms/transformLineBreak.js +15 -0
- package/dist/vue/transforms/transformTag.d.ts +1 -1
- package/dist/vue/transforms/transformTag.js +5 -0
- package/dist/vue/transforms/x/transformMPBuiltInTag.js +2 -2
- package/dist/vue/utils.js +8 -1
- package/lib/@vue/compiler-core/dist/compiler-core.cjs.js +42 -23
- package/lib/@vue/compiler-core/dist/compiler-core.cjs.prod.js +42 -23
- package/lib/@vue/compiler-core/dist/compiler-core.esm-bundler.js +39 -19
- package/lib/@vue/compiler-sfc/dist/compiler-sfc.cjs.js +4635 -1024
- package/lib/@vue/compiler-sfc/dist/compiler-sfc.esm-browser.js +8762 -7849
- package/lib/dom2/app/@vitejs/plugin-vue/LICENSE +21 -0
- package/lib/dom2/app/@vitejs/plugin-vue/README.md +278 -0
- package/lib/dom2/app/@vitejs/plugin-vue/dist/index.cjs +3353 -0
- package/lib/dom2/app/@vitejs/plugin-vue/dist/index.d.cts +113 -0
- package/lib/dom2/app/@vitejs/plugin-vue/dist/index.d.mts +111 -0
- package/lib/dom2/app/@vitejs/plugin-vue/dist/index.d.ts +113 -0
- package/lib/dom2/app/@vitejs/plugin-vue/dist/index.mjs +3338 -0
- package/lib/dom2/app/@vitejs/plugin-vue/package.json +50 -0
- package/lib/dom2/app/@vue/compiler-core/LICENSE +21 -0
- package/lib/dom2/app/@vue/compiler-core/README.md +1 -0
- package/lib/dom2/app/@vue/compiler-core/dist/compiler-core.cjs.js +5492 -0
- package/lib/dom2/app/@vue/compiler-core/dist/compiler-core.cjs.prod.js +5436 -0
- package/lib/dom2/app/@vue/compiler-core/dist/compiler-core.d.ts +1187 -0
- package/lib/dom2/app/@vue/compiler-core/dist/compiler-core.esm-bundler.js +4335 -0
- package/lib/dom2/app/@vue/compiler-core/index.js +7 -0
- package/lib/dom2/app/@vue/compiler-core/package.json +58 -0
- package/lib/dom2/app/@vue/compiler-dom/LICENSE +21 -0
- package/lib/dom2/app/@vue/compiler-dom/README.md +1 -0
- package/lib/dom2/app/@vue/compiler-dom/dist/compiler-dom.cjs.js +762 -0
- package/lib/dom2/app/@vue/compiler-dom/dist/compiler-dom.cjs.prod.js +736 -0
- package/lib/dom2/app/@vue/compiler-dom/dist/compiler-dom.d.ts +73 -0
- package/lib/dom2/app/@vue/compiler-dom/dist/compiler-dom.esm-browser.js +5051 -0
- package/lib/dom2/app/@vue/compiler-dom/dist/compiler-dom.esm-browser.prod.js +11 -0
- package/lib/dom2/app/@vue/compiler-dom/dist/compiler-dom.esm-bundler.js +557 -0
- package/lib/dom2/app/@vue/compiler-dom/dist/compiler-dom.global.js +5234 -0
- package/lib/dom2/app/@vue/compiler-dom/dist/compiler-dom.global.prod.js +11 -0
- package/lib/dom2/app/@vue/compiler-dom/index.js +7 -0
- package/lib/dom2/app/@vue/compiler-dom/package.json +57 -0
- package/lib/dom2/app/@vue/compiler-sfc/LICENSE +21 -0
- package/lib/dom2/app/@vue/compiler-sfc/README.md +80 -0
- package/lib/dom2/app/@vue/compiler-sfc/dist/compiler-sfc.cjs.js +15528 -0
- package/lib/dom2/app/@vue/compiler-sfc/dist/compiler-sfc.d.ts +11595 -0
- package/lib/dom2/app/@vue/compiler-sfc/dist/compiler-sfc.esm-browser.js +41525 -0
- package/lib/dom2/app/@vue/compiler-sfc/package.json +68 -0
- package/lib/dom2/app/@vue/compiler-vapor/LICENSE +21 -0
- package/lib/dom2/app/@vue/compiler-vapor/README.md +1 -0
- package/lib/dom2/app/@vue/compiler-vapor/dist/compiler-vapor.cjs.js +3584 -0
- package/lib/dom2/app/@vue/compiler-vapor/dist/compiler-vapor.d.ts +22858 -0
- package/lib/dom2/app/@vue/compiler-vapor/dist/compiler-vapor.esm-browser.js +22438 -0
- package/lib/dom2/app/@vue/compiler-vapor/package.json +51 -0
- package/lib/dom2/app/@vue/compiler-vapor-dom2/dist/compiler-vapor-dom2.cjs.js +1 -0
- package/lib/dom2/app/@vue/compiler-vapor-dom2/package.json +56 -0
- package/lib/dom2/app/@vue/shared/LICENSE +21 -0
- package/lib/dom2/app/@vue/shared/README.md +3 -0
- package/lib/dom2/app/@vue/shared/dist/shared.cjs.js +773 -0
- package/lib/dom2/app/@vue/shared/dist/shared.cjs.prod.js +773 -0
- package/lib/dom2/app/@vue/shared/dist/shared.d.ts +412 -0
- package/lib/dom2/app/@vue/shared/dist/shared.esm-bundler.js +688 -0
- package/lib/dom2/app/@vue/shared/index.js +7 -0
- package/lib/dom2/app/@vue/shared/package.json +47 -0
- package/lib/preprocess/lib/preprocess.js +9 -3
- package/lib/vapor/@vue/compiler-core/dist/compiler-core.cjs.js +1 -1
- package/lib/vapor/@vue/compiler-core/dist/compiler-core.cjs.prod.js +1 -1
- package/package.json +8 -6
|
@@ -0,0 +1,4335 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @vue/compiler-core v3.6.0-beta.5
|
|
3
|
+
* (c) 2018-present Yuxi (Evan) You and Vue contributors
|
|
4
|
+
* @license MIT
|
|
5
|
+
**/
|
|
6
|
+
import { EMPTY_OBJ, NO, NOOP, PatchFlagNames, camelize, capitalize, extend, generateCodeFrame, getModifierPropName, isArray, isBuiltInDirective, isObject, isOn, isReservedProp, isString, isSymbol, makeMap, slotFlagsText, toHandlerKey } from "@vue/shared";
|
|
7
|
+
|
|
8
|
+
//#region packages/compiler-core/src/runtimeHelpers.ts
|
|
9
|
+
const FRAGMENT = Symbol(!!(process.env.NODE_ENV !== "production") ? `Fragment` : ``);
|
|
10
|
+
const TELEPORT = Symbol(!!(process.env.NODE_ENV !== "production") ? `Teleport` : ``);
|
|
11
|
+
const SUSPENSE = Symbol(!!(process.env.NODE_ENV !== "production") ? `Suspense` : ``);
|
|
12
|
+
const KEEP_ALIVE = Symbol(!!(process.env.NODE_ENV !== "production") ? `KeepAlive` : ``);
|
|
13
|
+
const BASE_TRANSITION = Symbol(!!(process.env.NODE_ENV !== "production") ? `BaseTransition` : ``);
|
|
14
|
+
const OPEN_BLOCK = Symbol(!!(process.env.NODE_ENV !== "production") ? `openBlock` : ``);
|
|
15
|
+
const CREATE_BLOCK = Symbol(!!(process.env.NODE_ENV !== "production") ? `createBlock` : ``);
|
|
16
|
+
const CREATE_ELEMENT_BLOCK = Symbol(!!(process.env.NODE_ENV !== "production") ? `createElementBlock` : ``);
|
|
17
|
+
const CREATE_VNODE = Symbol(!!(process.env.NODE_ENV !== "production") ? `createVNode` : ``);
|
|
18
|
+
const CREATE_ELEMENT_VNODE = Symbol(!!(process.env.NODE_ENV !== "production") ? `createElementVNode` : ``);
|
|
19
|
+
const CREATE_COMMENT = Symbol(!!(process.env.NODE_ENV !== "production") ? `createCommentVNode` : ``);
|
|
20
|
+
const CREATE_TEXT = Symbol(!!(process.env.NODE_ENV !== "production") ? `createTextVNode` : ``);
|
|
21
|
+
const CREATE_STATIC = Symbol(!!(process.env.NODE_ENV !== "production") ? `createStaticVNode` : ``);
|
|
22
|
+
const RESOLVE_COMPONENT = Symbol(!!(process.env.NODE_ENV !== "production") ? `resolveComponent` : ``);
|
|
23
|
+
const RESOLVE_DYNAMIC_COMPONENT = Symbol(!!(process.env.NODE_ENV !== "production") ? `resolveDynamicComponent` : ``);
|
|
24
|
+
const RESOLVE_DIRECTIVE = Symbol(!!(process.env.NODE_ENV !== "production") ? `resolveDirective` : ``);
|
|
25
|
+
const RESOLVE_FILTER = Symbol(!!(process.env.NODE_ENV !== "production") ? `resolveFilter` : ``);
|
|
26
|
+
const WITH_DIRECTIVES = Symbol(!!(process.env.NODE_ENV !== "production") ? `withDirectives` : ``);
|
|
27
|
+
const RENDER_LIST = Symbol(!!(process.env.NODE_ENV !== "production") ? `renderList` : ``);
|
|
28
|
+
const RENDER_SLOT = Symbol(!!(process.env.NODE_ENV !== "production") ? `renderSlot` : ``);
|
|
29
|
+
const CREATE_SLOTS = Symbol(!!(process.env.NODE_ENV !== "production") ? `createSlots` : ``);
|
|
30
|
+
const TO_DISPLAY_STRING = Symbol(!!(process.env.NODE_ENV !== "production") ? `toDisplayString` : ``);
|
|
31
|
+
const MERGE_PROPS = Symbol(!!(process.env.NODE_ENV !== "production") ? `mergeProps` : ``);
|
|
32
|
+
const NORMALIZE_CLASS = Symbol(!!(process.env.NODE_ENV !== "production") ? `normalizeClass` : ``);
|
|
33
|
+
const NORMALIZE_STYLE = Symbol(!!(process.env.NODE_ENV !== "production") ? `normalizeStyle` : ``);
|
|
34
|
+
const NORMALIZE_PROPS = Symbol(!!(process.env.NODE_ENV !== "production") ? `normalizeProps` : ``);
|
|
35
|
+
const GUARD_REACTIVE_PROPS = Symbol(!!(process.env.NODE_ENV !== "production") ? `guardReactiveProps` : ``);
|
|
36
|
+
const TO_HANDLERS = Symbol(!!(process.env.NODE_ENV !== "production") ? `toHandlers` : ``);
|
|
37
|
+
const CAMELIZE = Symbol(!!(process.env.NODE_ENV !== "production") ? `camelize` : ``);
|
|
38
|
+
const CAPITALIZE = Symbol(!!(process.env.NODE_ENV !== "production") ? `capitalize` : ``);
|
|
39
|
+
const TO_HANDLER_KEY = Symbol(!!(process.env.NODE_ENV !== "production") ? `toHandlerKey` : ``);
|
|
40
|
+
const SET_BLOCK_TRACKING = Symbol(!!(process.env.NODE_ENV !== "production") ? `setBlockTracking` : ``);
|
|
41
|
+
/**
|
|
42
|
+
* @deprecated no longer needed in 3.5+ because we no longer hoist element nodes
|
|
43
|
+
* but kept for backwards compat
|
|
44
|
+
*/
|
|
45
|
+
const PUSH_SCOPE_ID = Symbol(!!(process.env.NODE_ENV !== "production") ? `pushScopeId` : ``);
|
|
46
|
+
/**
|
|
47
|
+
* @deprecated kept for backwards compat
|
|
48
|
+
*/
|
|
49
|
+
const POP_SCOPE_ID = Symbol(!!(process.env.NODE_ENV !== "production") ? `popScopeId` : ``);
|
|
50
|
+
const WITH_CTX = Symbol(!!(process.env.NODE_ENV !== "production") ? `withCtx` : ``);
|
|
51
|
+
const UNREF = Symbol(!!(process.env.NODE_ENV !== "production") ? `unref` : ``);
|
|
52
|
+
const IS_REF = Symbol(!!(process.env.NODE_ENV !== "production") ? `isRef` : ``);
|
|
53
|
+
const WITH_MEMO = Symbol(!!(process.env.NODE_ENV !== "production") ? `withMemo` : ``);
|
|
54
|
+
const IS_MEMO_SAME = Symbol(!!(process.env.NODE_ENV !== "production") ? `isMemoSame` : ``);
|
|
55
|
+
const helperNameMap = {
|
|
56
|
+
[FRAGMENT]: `Fragment`,
|
|
57
|
+
[TELEPORT]: `Teleport`,
|
|
58
|
+
[SUSPENSE]: `Suspense`,
|
|
59
|
+
[KEEP_ALIVE]: `KeepAlive`,
|
|
60
|
+
[BASE_TRANSITION]: `BaseTransition`,
|
|
61
|
+
[OPEN_BLOCK]: `openBlock`,
|
|
62
|
+
[CREATE_BLOCK]: `createBlock`,
|
|
63
|
+
[CREATE_ELEMENT_BLOCK]: `createElementBlock`,
|
|
64
|
+
[CREATE_VNODE]: `createVNode`,
|
|
65
|
+
[CREATE_ELEMENT_VNODE]: `createElementVNode`,
|
|
66
|
+
[CREATE_COMMENT]: `createCommentVNode`,
|
|
67
|
+
[CREATE_TEXT]: `createTextVNode`,
|
|
68
|
+
[CREATE_STATIC]: `createStaticVNode`,
|
|
69
|
+
[RESOLVE_COMPONENT]: `resolveComponent`,
|
|
70
|
+
[RESOLVE_DYNAMIC_COMPONENT]: `resolveDynamicComponent`,
|
|
71
|
+
[RESOLVE_DIRECTIVE]: `resolveDirective`,
|
|
72
|
+
[RESOLVE_FILTER]: `resolveFilter`,
|
|
73
|
+
[WITH_DIRECTIVES]: `withDirectives`,
|
|
74
|
+
[RENDER_LIST]: `renderList`,
|
|
75
|
+
[RENDER_SLOT]: `renderSlot`,
|
|
76
|
+
[CREATE_SLOTS]: `createSlots`,
|
|
77
|
+
[TO_DISPLAY_STRING]: `toDisplayString`,
|
|
78
|
+
[MERGE_PROPS]: `mergeProps`,
|
|
79
|
+
[NORMALIZE_CLASS]: `normalizeClass`,
|
|
80
|
+
[NORMALIZE_STYLE]: `normalizeStyle`,
|
|
81
|
+
[NORMALIZE_PROPS]: `normalizeProps`,
|
|
82
|
+
[GUARD_REACTIVE_PROPS]: `guardReactiveProps`,
|
|
83
|
+
[TO_HANDLERS]: `toHandlers`,
|
|
84
|
+
[CAMELIZE]: `camelize`,
|
|
85
|
+
[CAPITALIZE]: `capitalize`,
|
|
86
|
+
[TO_HANDLER_KEY]: `toHandlerKey`,
|
|
87
|
+
[SET_BLOCK_TRACKING]: `setBlockTracking`,
|
|
88
|
+
[PUSH_SCOPE_ID]: `pushScopeId`,
|
|
89
|
+
[POP_SCOPE_ID]: `popScopeId`,
|
|
90
|
+
[WITH_CTX]: `withCtx`,
|
|
91
|
+
[UNREF]: `unref`,
|
|
92
|
+
[IS_REF]: `isRef`,
|
|
93
|
+
[WITH_MEMO]: `withMemo`,
|
|
94
|
+
[IS_MEMO_SAME]: `isMemoSame`
|
|
95
|
+
};
|
|
96
|
+
function registerRuntimeHelpers(helpers) {
|
|
97
|
+
Object.getOwnPropertySymbols(helpers).forEach((s) => {
|
|
98
|
+
helperNameMap[s] = helpers[s];
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
//#endregion
|
|
103
|
+
//#region packages/compiler-core/src/ast.ts
|
|
104
|
+
const NodeTypes = {
|
|
105
|
+
"ROOT": 0,
|
|
106
|
+
"0": "ROOT",
|
|
107
|
+
"ELEMENT": 1,
|
|
108
|
+
"1": "ELEMENT",
|
|
109
|
+
"TEXT": 2,
|
|
110
|
+
"2": "TEXT",
|
|
111
|
+
"COMMENT": 3,
|
|
112
|
+
"3": "COMMENT",
|
|
113
|
+
"SIMPLE_EXPRESSION": 4,
|
|
114
|
+
"4": "SIMPLE_EXPRESSION",
|
|
115
|
+
"INTERPOLATION": 5,
|
|
116
|
+
"5": "INTERPOLATION",
|
|
117
|
+
"ATTRIBUTE": 6,
|
|
118
|
+
"6": "ATTRIBUTE",
|
|
119
|
+
"DIRECTIVE": 7,
|
|
120
|
+
"7": "DIRECTIVE",
|
|
121
|
+
"COMPOUND_EXPRESSION": 8,
|
|
122
|
+
"8": "COMPOUND_EXPRESSION",
|
|
123
|
+
"IF": 9,
|
|
124
|
+
"9": "IF",
|
|
125
|
+
"IF_BRANCH": 10,
|
|
126
|
+
"10": "IF_BRANCH",
|
|
127
|
+
"FOR": 11,
|
|
128
|
+
"11": "FOR",
|
|
129
|
+
"TEXT_CALL": 12,
|
|
130
|
+
"12": "TEXT_CALL",
|
|
131
|
+
"VNODE_CALL": 13,
|
|
132
|
+
"13": "VNODE_CALL",
|
|
133
|
+
"JS_CALL_EXPRESSION": 14,
|
|
134
|
+
"14": "JS_CALL_EXPRESSION",
|
|
135
|
+
"JS_OBJECT_EXPRESSION": 15,
|
|
136
|
+
"15": "JS_OBJECT_EXPRESSION",
|
|
137
|
+
"JS_PROPERTY": 16,
|
|
138
|
+
"16": "JS_PROPERTY",
|
|
139
|
+
"JS_ARRAY_EXPRESSION": 17,
|
|
140
|
+
"17": "JS_ARRAY_EXPRESSION",
|
|
141
|
+
"JS_FUNCTION_EXPRESSION": 18,
|
|
142
|
+
"18": "JS_FUNCTION_EXPRESSION",
|
|
143
|
+
"JS_CONDITIONAL_EXPRESSION": 19,
|
|
144
|
+
"19": "JS_CONDITIONAL_EXPRESSION",
|
|
145
|
+
"JS_CACHE_EXPRESSION": 20,
|
|
146
|
+
"20": "JS_CACHE_EXPRESSION",
|
|
147
|
+
"JS_BLOCK_STATEMENT": 21,
|
|
148
|
+
"21": "JS_BLOCK_STATEMENT",
|
|
149
|
+
"JS_TEMPLATE_LITERAL": 22,
|
|
150
|
+
"22": "JS_TEMPLATE_LITERAL",
|
|
151
|
+
"JS_IF_STATEMENT": 23,
|
|
152
|
+
"23": "JS_IF_STATEMENT",
|
|
153
|
+
"JS_ASSIGNMENT_EXPRESSION": 24,
|
|
154
|
+
"24": "JS_ASSIGNMENT_EXPRESSION",
|
|
155
|
+
"JS_SEQUENCE_EXPRESSION": 25,
|
|
156
|
+
"25": "JS_SEQUENCE_EXPRESSION",
|
|
157
|
+
"JS_RETURN_STATEMENT": 26,
|
|
158
|
+
"26": "JS_RETURN_STATEMENT"
|
|
159
|
+
};
|
|
160
|
+
const ElementTypes = {
|
|
161
|
+
"ELEMENT": 0,
|
|
162
|
+
"0": "ELEMENT",
|
|
163
|
+
"COMPONENT": 1,
|
|
164
|
+
"1": "COMPONENT",
|
|
165
|
+
"SLOT": 2,
|
|
166
|
+
"2": "SLOT",
|
|
167
|
+
"TEMPLATE": 3,
|
|
168
|
+
"3": "TEMPLATE"
|
|
169
|
+
};
|
|
170
|
+
/**
|
|
171
|
+
* Static types have several levels.
|
|
172
|
+
* Higher levels implies lower levels. e.g. a node that can be stringified
|
|
173
|
+
* can always be hoisted and skipped for patch.
|
|
174
|
+
*/
|
|
175
|
+
const ConstantTypes = {
|
|
176
|
+
"NOT_CONSTANT": 0,
|
|
177
|
+
"0": "NOT_CONSTANT",
|
|
178
|
+
"CAN_SKIP_PATCH": 1,
|
|
179
|
+
"1": "CAN_SKIP_PATCH",
|
|
180
|
+
"CAN_CACHE": 2,
|
|
181
|
+
"2": "CAN_CACHE",
|
|
182
|
+
"CAN_STRINGIFY": 3,
|
|
183
|
+
"3": "CAN_STRINGIFY"
|
|
184
|
+
};
|
|
185
|
+
const locStub = {
|
|
186
|
+
start: {
|
|
187
|
+
line: 1,
|
|
188
|
+
column: 1,
|
|
189
|
+
offset: 0
|
|
190
|
+
},
|
|
191
|
+
end: {
|
|
192
|
+
line: 1,
|
|
193
|
+
column: 1,
|
|
194
|
+
offset: 0
|
|
195
|
+
},
|
|
196
|
+
source: ""
|
|
197
|
+
};
|
|
198
|
+
function createRoot(children, source = "") {
|
|
199
|
+
return {
|
|
200
|
+
type: 0,
|
|
201
|
+
source,
|
|
202
|
+
children,
|
|
203
|
+
helpers: /* @__PURE__ */ new Set(),
|
|
204
|
+
components: [],
|
|
205
|
+
directives: [],
|
|
206
|
+
hoists: [],
|
|
207
|
+
imports: [],
|
|
208
|
+
cached: [],
|
|
209
|
+
temps: 0,
|
|
210
|
+
codegenNode: void 0,
|
|
211
|
+
loc: locStub
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
function createVNodeCall(context, tag, props, children, patchFlag, dynamicProps, directives, isBlock = false, disableTracking = false, isComponent = false, loc = locStub) {
|
|
215
|
+
if (context) {
|
|
216
|
+
if (isBlock) {
|
|
217
|
+
context.helper(OPEN_BLOCK);
|
|
218
|
+
context.helper(getVNodeBlockHelper(context.inSSR, isComponent));
|
|
219
|
+
} else context.helper(getVNodeHelper(context.inSSR, isComponent));
|
|
220
|
+
if (directives) context.helper(WITH_DIRECTIVES);
|
|
221
|
+
}
|
|
222
|
+
return {
|
|
223
|
+
type: 13,
|
|
224
|
+
tag,
|
|
225
|
+
props,
|
|
226
|
+
children,
|
|
227
|
+
patchFlag,
|
|
228
|
+
dynamicProps,
|
|
229
|
+
directives,
|
|
230
|
+
isBlock,
|
|
231
|
+
disableTracking,
|
|
232
|
+
isComponent,
|
|
233
|
+
loc
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
function createArrayExpression(elements, loc = locStub) {
|
|
237
|
+
return {
|
|
238
|
+
type: 17,
|
|
239
|
+
loc,
|
|
240
|
+
elements
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
function createObjectExpression(properties, loc = locStub) {
|
|
244
|
+
return {
|
|
245
|
+
type: 15,
|
|
246
|
+
loc,
|
|
247
|
+
properties
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
function createObjectProperty(key, value) {
|
|
251
|
+
return {
|
|
252
|
+
type: 16,
|
|
253
|
+
loc: locStub,
|
|
254
|
+
key: isString(key) ? createSimpleExpression(key, true) : key,
|
|
255
|
+
value
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
function createSimpleExpression(content, isStatic = false, loc = locStub, constType = 0) {
|
|
259
|
+
return {
|
|
260
|
+
type: 4,
|
|
261
|
+
loc,
|
|
262
|
+
content,
|
|
263
|
+
isStatic,
|
|
264
|
+
constType: isStatic ? 3 : constType
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
function createInterpolation(content, loc) {
|
|
268
|
+
return {
|
|
269
|
+
type: 5,
|
|
270
|
+
loc,
|
|
271
|
+
content: isString(content) ? createSimpleExpression(content, false, loc) : content
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
function createCompoundExpression(children, loc = locStub) {
|
|
275
|
+
return {
|
|
276
|
+
type: 8,
|
|
277
|
+
loc,
|
|
278
|
+
children
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
function createCallExpression(callee, args = [], loc = locStub) {
|
|
282
|
+
return {
|
|
283
|
+
type: 14,
|
|
284
|
+
loc,
|
|
285
|
+
callee,
|
|
286
|
+
arguments: args
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
function createFunctionExpression(params, returns = void 0, newline = false, isSlot = false, loc = locStub) {
|
|
290
|
+
return {
|
|
291
|
+
type: 18,
|
|
292
|
+
params,
|
|
293
|
+
returns,
|
|
294
|
+
newline,
|
|
295
|
+
isSlot,
|
|
296
|
+
loc
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
function createConditionalExpression(test, consequent, alternate, newline = true) {
|
|
300
|
+
return {
|
|
301
|
+
type: 19,
|
|
302
|
+
test,
|
|
303
|
+
consequent,
|
|
304
|
+
alternate,
|
|
305
|
+
newline,
|
|
306
|
+
loc: locStub
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
function createCacheExpression(index, value, needPauseTracking = false, inVOnce = false) {
|
|
310
|
+
return {
|
|
311
|
+
type: 20,
|
|
312
|
+
index,
|
|
313
|
+
value,
|
|
314
|
+
needPauseTracking,
|
|
315
|
+
inVOnce,
|
|
316
|
+
needArraySpread: false,
|
|
317
|
+
loc: locStub
|
|
318
|
+
};
|
|
319
|
+
}
|
|
320
|
+
function createBlockStatement(body) {
|
|
321
|
+
return {
|
|
322
|
+
type: 21,
|
|
323
|
+
body,
|
|
324
|
+
loc: locStub
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
function createTemplateLiteral(elements) {
|
|
328
|
+
return {
|
|
329
|
+
type: 22,
|
|
330
|
+
elements,
|
|
331
|
+
loc: locStub
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
function createIfStatement(test, consequent, alternate) {
|
|
335
|
+
return {
|
|
336
|
+
type: 23,
|
|
337
|
+
test,
|
|
338
|
+
consequent,
|
|
339
|
+
alternate,
|
|
340
|
+
loc: locStub
|
|
341
|
+
};
|
|
342
|
+
}
|
|
343
|
+
function createAssignmentExpression(left, right) {
|
|
344
|
+
return {
|
|
345
|
+
type: 24,
|
|
346
|
+
left,
|
|
347
|
+
right,
|
|
348
|
+
loc: locStub
|
|
349
|
+
};
|
|
350
|
+
}
|
|
351
|
+
function createSequenceExpression(expressions) {
|
|
352
|
+
return {
|
|
353
|
+
type: 25,
|
|
354
|
+
expressions,
|
|
355
|
+
loc: locStub
|
|
356
|
+
};
|
|
357
|
+
}
|
|
358
|
+
function createReturnStatement(returns) {
|
|
359
|
+
return {
|
|
360
|
+
type: 26,
|
|
361
|
+
returns,
|
|
362
|
+
loc: locStub
|
|
363
|
+
};
|
|
364
|
+
}
|
|
365
|
+
function getVNodeHelper(ssr, isComponent) {
|
|
366
|
+
return ssr || isComponent ? CREATE_VNODE : CREATE_ELEMENT_VNODE;
|
|
367
|
+
}
|
|
368
|
+
function getVNodeBlockHelper(ssr, isComponent) {
|
|
369
|
+
return ssr || isComponent ? CREATE_BLOCK : CREATE_ELEMENT_BLOCK;
|
|
370
|
+
}
|
|
371
|
+
function convertToBlock(node, { helper, removeHelper, inSSR }) {
|
|
372
|
+
if (!node.isBlock) {
|
|
373
|
+
node.isBlock = true;
|
|
374
|
+
removeHelper(getVNodeHelper(inSSR, node.isComponent));
|
|
375
|
+
helper(OPEN_BLOCK);
|
|
376
|
+
helper(getVNodeBlockHelper(inSSR, node.isComponent));
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
//#endregion
|
|
381
|
+
//#region packages/compiler-core/src/tokenizer.ts
|
|
382
|
+
const defaultDelimitersOpen = new Uint8Array([123, 123]);
|
|
383
|
+
const defaultDelimitersClose = new Uint8Array([125, 125]);
|
|
384
|
+
/**
|
|
385
|
+
* HTML only allows ASCII alpha characters (a-z and A-Z) at the beginning of a
|
|
386
|
+
* tag name.
|
|
387
|
+
*/
|
|
388
|
+
function isTagStartChar(c) {
|
|
389
|
+
return c >= 97 && c <= 122 || c >= 65 && c <= 90;
|
|
390
|
+
}
|
|
391
|
+
function isWhitespace(c) {
|
|
392
|
+
return c === 32 || c === 10 || c === 9 || c === 12 || c === 13;
|
|
393
|
+
}
|
|
394
|
+
function isEndOfTagSection(c) {
|
|
395
|
+
return c === 47 || c === 62 || isWhitespace(c);
|
|
396
|
+
}
|
|
397
|
+
function toCharCodes(str) {
|
|
398
|
+
const ret = new Uint8Array(str.length);
|
|
399
|
+
for (let i = 0; i < str.length; i++) ret[i] = str.charCodeAt(i);
|
|
400
|
+
return ret;
|
|
401
|
+
}
|
|
402
|
+
/**
|
|
403
|
+
* Sequences used to match longer strings.
|
|
404
|
+
*
|
|
405
|
+
* We don't have `Script`, `Style`, or `Title` here. Instead, we re-use the *End
|
|
406
|
+
* sequences with an increased offset.
|
|
407
|
+
*/
|
|
408
|
+
const Sequences = {
|
|
409
|
+
Cdata: new Uint8Array([
|
|
410
|
+
67,
|
|
411
|
+
68,
|
|
412
|
+
65,
|
|
413
|
+
84,
|
|
414
|
+
65,
|
|
415
|
+
91
|
|
416
|
+
]),
|
|
417
|
+
CdataEnd: new Uint8Array([
|
|
418
|
+
93,
|
|
419
|
+
93,
|
|
420
|
+
62
|
|
421
|
+
]),
|
|
422
|
+
CommentEnd: new Uint8Array([
|
|
423
|
+
45,
|
|
424
|
+
45,
|
|
425
|
+
62
|
|
426
|
+
]),
|
|
427
|
+
ScriptEnd: new Uint8Array([
|
|
428
|
+
60,
|
|
429
|
+
47,
|
|
430
|
+
115,
|
|
431
|
+
99,
|
|
432
|
+
114,
|
|
433
|
+
105,
|
|
434
|
+
112,
|
|
435
|
+
116
|
|
436
|
+
]),
|
|
437
|
+
StyleEnd: new Uint8Array([
|
|
438
|
+
60,
|
|
439
|
+
47,
|
|
440
|
+
115,
|
|
441
|
+
116,
|
|
442
|
+
121,
|
|
443
|
+
108,
|
|
444
|
+
101
|
|
445
|
+
]),
|
|
446
|
+
TitleEnd: new Uint8Array([
|
|
447
|
+
60,
|
|
448
|
+
47,
|
|
449
|
+
116,
|
|
450
|
+
105,
|
|
451
|
+
116,
|
|
452
|
+
108,
|
|
453
|
+
101
|
|
454
|
+
]),
|
|
455
|
+
TextareaEnd: new Uint8Array([
|
|
456
|
+
60,
|
|
457
|
+
47,
|
|
458
|
+
116,
|
|
459
|
+
101,
|
|
460
|
+
120,
|
|
461
|
+
116,
|
|
462
|
+
97,
|
|
463
|
+
114,
|
|
464
|
+
101,
|
|
465
|
+
97
|
|
466
|
+
])
|
|
467
|
+
};
|
|
468
|
+
var Tokenizer = class {
|
|
469
|
+
get inSFCRoot() {
|
|
470
|
+
return this.mode === 2 && this.stack.length === 0;
|
|
471
|
+
}
|
|
472
|
+
constructor(stack, cbs) {
|
|
473
|
+
this.stack = stack;
|
|
474
|
+
this.cbs = cbs;
|
|
475
|
+
this.state = 1;
|
|
476
|
+
this.buffer = "";
|
|
477
|
+
this.sectionStart = 0;
|
|
478
|
+
this.index = 0;
|
|
479
|
+
this.entityStart = 0;
|
|
480
|
+
this.baseState = 1;
|
|
481
|
+
this.inRCDATA = false;
|
|
482
|
+
this.inXML = false;
|
|
483
|
+
this.inVPre = false;
|
|
484
|
+
this.newlines = [];
|
|
485
|
+
this.mode = 0;
|
|
486
|
+
this.delimiterOpen = defaultDelimitersOpen;
|
|
487
|
+
this.delimiterClose = defaultDelimitersClose;
|
|
488
|
+
this.delimiterIndex = -1;
|
|
489
|
+
this.currentSequence = void 0;
|
|
490
|
+
this.sequenceIndex = 0;
|
|
491
|
+
}
|
|
492
|
+
reset() {
|
|
493
|
+
this.state = 1;
|
|
494
|
+
this.mode = 0;
|
|
495
|
+
this.buffer = "";
|
|
496
|
+
this.sectionStart = 0;
|
|
497
|
+
this.index = 0;
|
|
498
|
+
this.baseState = 1;
|
|
499
|
+
this.inRCDATA = false;
|
|
500
|
+
this.currentSequence = void 0;
|
|
501
|
+
this.newlines.length = 0;
|
|
502
|
+
this.delimiterOpen = defaultDelimitersOpen;
|
|
503
|
+
this.delimiterClose = defaultDelimitersClose;
|
|
504
|
+
}
|
|
505
|
+
/**
|
|
506
|
+
* Generate Position object with line / column information using recorded
|
|
507
|
+
* newline positions. We know the index is always going to be an already
|
|
508
|
+
* processed index, so all the newlines up to this index should have been
|
|
509
|
+
* recorded.
|
|
510
|
+
*/
|
|
511
|
+
getPos(index) {
|
|
512
|
+
let line = 1;
|
|
513
|
+
let column = index + 1;
|
|
514
|
+
const length = this.newlines.length;
|
|
515
|
+
let j = -1;
|
|
516
|
+
if (length > 100) {
|
|
517
|
+
let l = -1;
|
|
518
|
+
let r = length;
|
|
519
|
+
while (l + 1 < r) {
|
|
520
|
+
const m = l + r >>> 1;
|
|
521
|
+
this.newlines[m] < index ? l = m : r = m;
|
|
522
|
+
}
|
|
523
|
+
j = l;
|
|
524
|
+
} else for (let i = length - 1; i >= 0; i--) if (index > this.newlines[i]) {
|
|
525
|
+
j = i;
|
|
526
|
+
break;
|
|
527
|
+
}
|
|
528
|
+
if (j >= 0) {
|
|
529
|
+
line = j + 2;
|
|
530
|
+
column = index - this.newlines[j];
|
|
531
|
+
}
|
|
532
|
+
return {
|
|
533
|
+
column,
|
|
534
|
+
line,
|
|
535
|
+
offset: index
|
|
536
|
+
};
|
|
537
|
+
}
|
|
538
|
+
peek() {
|
|
539
|
+
return this.buffer.charCodeAt(this.index + 1);
|
|
540
|
+
}
|
|
541
|
+
stateText(c) {
|
|
542
|
+
if (c === 60) {
|
|
543
|
+
if (this.index > this.sectionStart) this.cbs.ontext(this.sectionStart, this.index);
|
|
544
|
+
this.state = 5;
|
|
545
|
+
this.sectionStart = this.index;
|
|
546
|
+
} else if (!this.inVPre && c === this.delimiterOpen[0]) {
|
|
547
|
+
this.state = 2;
|
|
548
|
+
this.delimiterIndex = 0;
|
|
549
|
+
this.stateInterpolationOpen(c);
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
stateInterpolationOpen(c) {
|
|
553
|
+
if (c === this.delimiterOpen[this.delimiterIndex]) if (this.delimiterIndex === this.delimiterOpen.length - 1) {
|
|
554
|
+
const start = this.index + 1 - this.delimiterOpen.length;
|
|
555
|
+
if (start > this.sectionStart) this.cbs.ontext(this.sectionStart, start);
|
|
556
|
+
this.state = 3;
|
|
557
|
+
this.sectionStart = start;
|
|
558
|
+
} else this.delimiterIndex++;
|
|
559
|
+
else if (this.inRCDATA) {
|
|
560
|
+
this.state = 32;
|
|
561
|
+
this.stateInRCDATA(c);
|
|
562
|
+
} else {
|
|
563
|
+
this.state = 1;
|
|
564
|
+
this.stateText(c);
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
stateInterpolation(c) {
|
|
568
|
+
if (c === this.delimiterClose[0]) {
|
|
569
|
+
this.state = 4;
|
|
570
|
+
this.delimiterIndex = 0;
|
|
571
|
+
this.stateInterpolationClose(c);
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
stateInterpolationClose(c) {
|
|
575
|
+
if (c === this.delimiterClose[this.delimiterIndex]) if (this.delimiterIndex === this.delimiterClose.length - 1) {
|
|
576
|
+
this.cbs.oninterpolation(this.sectionStart, this.index + 1);
|
|
577
|
+
if (this.inRCDATA) this.state = 32;
|
|
578
|
+
else this.state = 1;
|
|
579
|
+
this.sectionStart = this.index + 1;
|
|
580
|
+
} else this.delimiterIndex++;
|
|
581
|
+
else {
|
|
582
|
+
this.state = 3;
|
|
583
|
+
this.stateInterpolation(c);
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
stateSpecialStartSequence(c) {
|
|
587
|
+
const isEnd = this.sequenceIndex === this.currentSequence.length;
|
|
588
|
+
if (!(isEnd ? isEndOfTagSection(c) : (c | 32) === this.currentSequence[this.sequenceIndex])) this.inRCDATA = false;
|
|
589
|
+
else if (!isEnd) {
|
|
590
|
+
this.sequenceIndex++;
|
|
591
|
+
return;
|
|
592
|
+
}
|
|
593
|
+
this.sequenceIndex = 0;
|
|
594
|
+
this.state = 6;
|
|
595
|
+
this.stateInTagName(c);
|
|
596
|
+
}
|
|
597
|
+
/** Look for an end tag. For <title> and <textarea>, also decode entities. */
|
|
598
|
+
stateInRCDATA(c) {
|
|
599
|
+
if (this.sequenceIndex === this.currentSequence.length) {
|
|
600
|
+
if (c === 62 || isWhitespace(c)) {
|
|
601
|
+
const endOfText = this.index - this.currentSequence.length;
|
|
602
|
+
if (this.sectionStart < endOfText) {
|
|
603
|
+
const actualIndex = this.index;
|
|
604
|
+
this.index = endOfText;
|
|
605
|
+
this.cbs.ontext(this.sectionStart, endOfText);
|
|
606
|
+
this.index = actualIndex;
|
|
607
|
+
}
|
|
608
|
+
this.sectionStart = endOfText + 2;
|
|
609
|
+
this.stateInClosingTagName(c);
|
|
610
|
+
this.inRCDATA = false;
|
|
611
|
+
return;
|
|
612
|
+
}
|
|
613
|
+
this.sequenceIndex = 0;
|
|
614
|
+
}
|
|
615
|
+
if ((c | 32) === this.currentSequence[this.sequenceIndex]) this.sequenceIndex += 1;
|
|
616
|
+
else if (this.sequenceIndex === 0) {
|
|
617
|
+
if (this.currentSequence === Sequences.TitleEnd || this.currentSequence === Sequences.TextareaEnd && !this.inSFCRoot) {
|
|
618
|
+
if (!this.inVPre && c === this.delimiterOpen[0]) {
|
|
619
|
+
this.state = 2;
|
|
620
|
+
this.delimiterIndex = 0;
|
|
621
|
+
this.stateInterpolationOpen(c);
|
|
622
|
+
}
|
|
623
|
+
} else if (this.fastForwardTo(60)) this.sequenceIndex = 1;
|
|
624
|
+
} else this.sequenceIndex = Number(c === 60);
|
|
625
|
+
}
|
|
626
|
+
stateCDATASequence(c) {
|
|
627
|
+
if (c === Sequences.Cdata[this.sequenceIndex]) {
|
|
628
|
+
if (++this.sequenceIndex === Sequences.Cdata.length) {
|
|
629
|
+
this.state = 28;
|
|
630
|
+
this.currentSequence = Sequences.CdataEnd;
|
|
631
|
+
this.sequenceIndex = 0;
|
|
632
|
+
this.sectionStart = this.index + 1;
|
|
633
|
+
}
|
|
634
|
+
} else {
|
|
635
|
+
this.sequenceIndex = 0;
|
|
636
|
+
this.state = 23;
|
|
637
|
+
this.stateInDeclaration(c);
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
/**
|
|
641
|
+
* When we wait for one specific character, we can speed things up
|
|
642
|
+
* by skipping through the buffer until we find it.
|
|
643
|
+
*
|
|
644
|
+
* @returns Whether the character was found.
|
|
645
|
+
*/
|
|
646
|
+
fastForwardTo(c) {
|
|
647
|
+
while (++this.index < this.buffer.length) {
|
|
648
|
+
const cc = this.buffer.charCodeAt(this.index);
|
|
649
|
+
if (cc === 10) this.newlines.push(this.index);
|
|
650
|
+
if (cc === c) return true;
|
|
651
|
+
}
|
|
652
|
+
this.index = this.buffer.length - 1;
|
|
653
|
+
return false;
|
|
654
|
+
}
|
|
655
|
+
/**
|
|
656
|
+
* Comments and CDATA end with `-->` and `]]>`.
|
|
657
|
+
*
|
|
658
|
+
* Their common qualities are:
|
|
659
|
+
* - Their end sequences have a distinct character they start with.
|
|
660
|
+
* - That character is then repeated, so we have to check multiple repeats.
|
|
661
|
+
* - All characters but the start character of the sequence can be skipped.
|
|
662
|
+
*/
|
|
663
|
+
stateInCommentLike(c) {
|
|
664
|
+
if (c === this.currentSequence[this.sequenceIndex]) {
|
|
665
|
+
if (++this.sequenceIndex === this.currentSequence.length) {
|
|
666
|
+
if (this.currentSequence === Sequences.CdataEnd) this.cbs.oncdata(this.sectionStart, this.index - 2);
|
|
667
|
+
else this.cbs.oncomment(this.sectionStart, this.index - 2);
|
|
668
|
+
this.sequenceIndex = 0;
|
|
669
|
+
this.sectionStart = this.index + 1;
|
|
670
|
+
this.state = 1;
|
|
671
|
+
}
|
|
672
|
+
} else if (this.sequenceIndex === 0) {
|
|
673
|
+
if (this.fastForwardTo(this.currentSequence[0])) this.sequenceIndex = 1;
|
|
674
|
+
} else if (c !== this.currentSequence[this.sequenceIndex - 1]) this.sequenceIndex = 0;
|
|
675
|
+
}
|
|
676
|
+
startSpecial(sequence, offset) {
|
|
677
|
+
this.enterRCDATA(sequence, offset);
|
|
678
|
+
this.state = 31;
|
|
679
|
+
}
|
|
680
|
+
enterRCDATA(sequence, offset) {
|
|
681
|
+
this.inRCDATA = true;
|
|
682
|
+
this.currentSequence = sequence;
|
|
683
|
+
this.sequenceIndex = offset;
|
|
684
|
+
}
|
|
685
|
+
stateBeforeTagName(c) {
|
|
686
|
+
if (c === 33) {
|
|
687
|
+
this.state = 22;
|
|
688
|
+
this.sectionStart = this.index + 1;
|
|
689
|
+
} else if (c === 63) {
|
|
690
|
+
this.state = 24;
|
|
691
|
+
this.sectionStart = this.index + 1;
|
|
692
|
+
} else if (isTagStartChar(c)) {
|
|
693
|
+
this.sectionStart = this.index;
|
|
694
|
+
if (this.mode === 0) this.state = 6;
|
|
695
|
+
else if (this.inSFCRoot) this.state = 34;
|
|
696
|
+
else if (!this.inXML) if (c === 116) this.state = 30;
|
|
697
|
+
else this.state = c === 115 ? 29 : 6;
|
|
698
|
+
else this.state = 6;
|
|
699
|
+
} else if (c === 47) this.state = 8;
|
|
700
|
+
else {
|
|
701
|
+
this.state = 1;
|
|
702
|
+
this.stateText(c);
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
stateInTagName(c) {
|
|
706
|
+
if (isEndOfTagSection(c)) this.handleTagName(c);
|
|
707
|
+
}
|
|
708
|
+
stateInSFCRootTagName(c) {
|
|
709
|
+
if (isEndOfTagSection(c)) {
|
|
710
|
+
const tag = this.buffer.slice(this.sectionStart, this.index);
|
|
711
|
+
if (tag !== "template") this.enterRCDATA(toCharCodes(`</` + tag), 0);
|
|
712
|
+
this.handleTagName(c);
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
handleTagName(c) {
|
|
716
|
+
this.cbs.onopentagname(this.sectionStart, this.index);
|
|
717
|
+
this.sectionStart = -1;
|
|
718
|
+
this.state = 11;
|
|
719
|
+
this.stateBeforeAttrName(c);
|
|
720
|
+
}
|
|
721
|
+
stateBeforeClosingTagName(c) {
|
|
722
|
+
if (isWhitespace(c)) {} else if (c === 62) {
|
|
723
|
+
if (!!(process.env.NODE_ENV !== "production") || false) this.cbs.onerr(14, this.index);
|
|
724
|
+
this.state = 1;
|
|
725
|
+
this.sectionStart = this.index + 1;
|
|
726
|
+
} else {
|
|
727
|
+
this.state = isTagStartChar(c) ? 9 : 27;
|
|
728
|
+
this.sectionStart = this.index;
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
stateInClosingTagName(c) {
|
|
732
|
+
if (c === 62 || isWhitespace(c)) {
|
|
733
|
+
this.cbs.onclosetag(this.sectionStart, this.index);
|
|
734
|
+
this.sectionStart = -1;
|
|
735
|
+
this.state = 10;
|
|
736
|
+
this.stateAfterClosingTagName(c);
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
stateAfterClosingTagName(c) {
|
|
740
|
+
if (c === 62) {
|
|
741
|
+
this.state = 1;
|
|
742
|
+
this.sectionStart = this.index + 1;
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
stateBeforeAttrName(c) {
|
|
746
|
+
if (c === 62) {
|
|
747
|
+
this.cbs.onopentagend(this.index);
|
|
748
|
+
if (this.inRCDATA) this.state = 32;
|
|
749
|
+
else this.state = 1;
|
|
750
|
+
this.sectionStart = this.index + 1;
|
|
751
|
+
} else if (c === 47) {
|
|
752
|
+
this.state = 7;
|
|
753
|
+
if ((!!(process.env.NODE_ENV !== "production") || false) && this.peek() !== 62) this.cbs.onerr(22, this.index);
|
|
754
|
+
} else if (c === 60 && this.peek() === 47) {
|
|
755
|
+
this.cbs.onopentagend(this.index);
|
|
756
|
+
this.state = 5;
|
|
757
|
+
this.sectionStart = this.index;
|
|
758
|
+
} else if (!isWhitespace(c)) {
|
|
759
|
+
if ((!!(process.env.NODE_ENV !== "production") || false) && c === 61) this.cbs.onerr(19, this.index);
|
|
760
|
+
this.handleAttrStart(c);
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
handleAttrStart(c) {
|
|
764
|
+
if (c === 118 && this.peek() === 45) {
|
|
765
|
+
this.state = 13;
|
|
766
|
+
this.sectionStart = this.index;
|
|
767
|
+
} else if (c === 46 || c === 58 || c === 64 || c === 35) {
|
|
768
|
+
this.cbs.ondirname(this.index, this.index + 1);
|
|
769
|
+
this.state = 14;
|
|
770
|
+
this.sectionStart = this.index + 1;
|
|
771
|
+
} else {
|
|
772
|
+
this.state = 12;
|
|
773
|
+
this.sectionStart = this.index;
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
stateInSelfClosingTag(c) {
|
|
777
|
+
if (c === 62) {
|
|
778
|
+
this.cbs.onselfclosingtag(this.index);
|
|
779
|
+
this.state = 1;
|
|
780
|
+
this.sectionStart = this.index + 1;
|
|
781
|
+
this.inRCDATA = false;
|
|
782
|
+
} else if (!isWhitespace(c)) {
|
|
783
|
+
this.state = 11;
|
|
784
|
+
this.stateBeforeAttrName(c);
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
stateInAttrName(c) {
|
|
788
|
+
if (c === 61 || isEndOfTagSection(c)) {
|
|
789
|
+
this.cbs.onattribname(this.sectionStart, this.index);
|
|
790
|
+
this.handleAttrNameEnd(c);
|
|
791
|
+
} else if ((!!(process.env.NODE_ENV !== "production") || false) && (c === 34 || c === 39 || c === 60)) this.cbs.onerr(17, this.index);
|
|
792
|
+
}
|
|
793
|
+
stateInDirName(c) {
|
|
794
|
+
if (c === 61 || isEndOfTagSection(c)) {
|
|
795
|
+
this.cbs.ondirname(this.sectionStart, this.index);
|
|
796
|
+
this.handleAttrNameEnd(c);
|
|
797
|
+
} else if (c === 58) {
|
|
798
|
+
this.cbs.ondirname(this.sectionStart, this.index);
|
|
799
|
+
this.state = 14;
|
|
800
|
+
this.sectionStart = this.index + 1;
|
|
801
|
+
} else if (c === 46) {
|
|
802
|
+
this.cbs.ondirname(this.sectionStart, this.index);
|
|
803
|
+
this.state = 16;
|
|
804
|
+
this.sectionStart = this.index + 1;
|
|
805
|
+
}
|
|
806
|
+
}
|
|
807
|
+
stateInDirArg(c) {
|
|
808
|
+
if (c === 61 || isEndOfTagSection(c)) {
|
|
809
|
+
this.cbs.ondirarg(this.sectionStart, this.index);
|
|
810
|
+
this.handleAttrNameEnd(c);
|
|
811
|
+
} else if (c === 91) this.state = 15;
|
|
812
|
+
else if (c === 46) {
|
|
813
|
+
this.cbs.ondirarg(this.sectionStart, this.index);
|
|
814
|
+
this.state = 16;
|
|
815
|
+
this.sectionStart = this.index + 1;
|
|
816
|
+
}
|
|
817
|
+
}
|
|
818
|
+
stateInDynamicDirArg(c) {
|
|
819
|
+
if (c === 93) this.state = 14;
|
|
820
|
+
else if (c === 61 || isEndOfTagSection(c)) {
|
|
821
|
+
this.cbs.ondirarg(this.sectionStart, this.index + 1);
|
|
822
|
+
this.handleAttrNameEnd(c);
|
|
823
|
+
if (!!(process.env.NODE_ENV !== "production") || false) this.cbs.onerr(27, this.index);
|
|
824
|
+
}
|
|
825
|
+
}
|
|
826
|
+
stateInDirModifier(c) {
|
|
827
|
+
if (c === 61 || isEndOfTagSection(c)) {
|
|
828
|
+
this.cbs.ondirmodifier(this.sectionStart, this.index);
|
|
829
|
+
this.handleAttrNameEnd(c);
|
|
830
|
+
} else if (c === 46) {
|
|
831
|
+
this.cbs.ondirmodifier(this.sectionStart, this.index);
|
|
832
|
+
this.sectionStart = this.index + 1;
|
|
833
|
+
}
|
|
834
|
+
}
|
|
835
|
+
handleAttrNameEnd(c) {
|
|
836
|
+
this.sectionStart = this.index;
|
|
837
|
+
this.state = 17;
|
|
838
|
+
this.cbs.onattribnameend(this.index);
|
|
839
|
+
this.stateAfterAttrName(c);
|
|
840
|
+
}
|
|
841
|
+
stateAfterAttrName(c) {
|
|
842
|
+
if (c === 61) this.state = 18;
|
|
843
|
+
else if (c === 47 || c === 62) {
|
|
844
|
+
this.cbs.onattribend(0, this.sectionStart);
|
|
845
|
+
this.sectionStart = -1;
|
|
846
|
+
this.state = 11;
|
|
847
|
+
this.stateBeforeAttrName(c);
|
|
848
|
+
} else if (!isWhitespace(c)) {
|
|
849
|
+
this.cbs.onattribend(0, this.sectionStart);
|
|
850
|
+
this.handleAttrStart(c);
|
|
851
|
+
}
|
|
852
|
+
}
|
|
853
|
+
stateBeforeAttrValue(c) {
|
|
854
|
+
if (c === 34) {
|
|
855
|
+
this.state = 19;
|
|
856
|
+
this.sectionStart = this.index + 1;
|
|
857
|
+
} else if (c === 39) {
|
|
858
|
+
this.state = 20;
|
|
859
|
+
this.sectionStart = this.index + 1;
|
|
860
|
+
} else if (!isWhitespace(c)) {
|
|
861
|
+
this.sectionStart = this.index;
|
|
862
|
+
this.state = 21;
|
|
863
|
+
this.stateInAttrValueNoQuotes(c);
|
|
864
|
+
}
|
|
865
|
+
}
|
|
866
|
+
handleInAttrValue(c, quote) {
|
|
867
|
+
if (c === quote || this.fastForwardTo(quote)) {
|
|
868
|
+
this.cbs.onattribdata(this.sectionStart, this.index);
|
|
869
|
+
this.sectionStart = -1;
|
|
870
|
+
this.cbs.onattribend(quote === 34 ? 3 : 2, this.index + 1);
|
|
871
|
+
this.state = 11;
|
|
872
|
+
}
|
|
873
|
+
}
|
|
874
|
+
stateInAttrValueDoubleQuotes(c) {
|
|
875
|
+
this.handleInAttrValue(c, 34);
|
|
876
|
+
}
|
|
877
|
+
stateInAttrValueSingleQuotes(c) {
|
|
878
|
+
this.handleInAttrValue(c, 39);
|
|
879
|
+
}
|
|
880
|
+
stateInAttrValueNoQuotes(c) {
|
|
881
|
+
if (isWhitespace(c) || c === 62) {
|
|
882
|
+
this.cbs.onattribdata(this.sectionStart, this.index);
|
|
883
|
+
this.sectionStart = -1;
|
|
884
|
+
this.cbs.onattribend(1, this.index);
|
|
885
|
+
this.state = 11;
|
|
886
|
+
this.stateBeforeAttrName(c);
|
|
887
|
+
} else if ((!!(process.env.NODE_ENV !== "production") || false) && c === 34 || c === 39 || c === 60 || c === 61 || c === 96) this.cbs.onerr(18, this.index);
|
|
888
|
+
}
|
|
889
|
+
stateBeforeDeclaration(c) {
|
|
890
|
+
if (c === 91) {
|
|
891
|
+
this.state = 26;
|
|
892
|
+
this.sequenceIndex = 0;
|
|
893
|
+
} else this.state = c === 45 ? 25 : 23;
|
|
894
|
+
}
|
|
895
|
+
stateInDeclaration(c) {
|
|
896
|
+
if (c === 62 || this.fastForwardTo(62)) {
|
|
897
|
+
this.state = 1;
|
|
898
|
+
this.sectionStart = this.index + 1;
|
|
899
|
+
}
|
|
900
|
+
}
|
|
901
|
+
stateInProcessingInstruction(c) {
|
|
902
|
+
if (c === 62 || this.fastForwardTo(62)) {
|
|
903
|
+
this.cbs.onprocessinginstruction(this.sectionStart, this.index);
|
|
904
|
+
this.state = 1;
|
|
905
|
+
this.sectionStart = this.index + 1;
|
|
906
|
+
}
|
|
907
|
+
}
|
|
908
|
+
stateBeforeComment(c) {
|
|
909
|
+
if (c === 45) {
|
|
910
|
+
this.state = 28;
|
|
911
|
+
this.currentSequence = Sequences.CommentEnd;
|
|
912
|
+
this.sequenceIndex = 2;
|
|
913
|
+
this.sectionStart = this.index + 1;
|
|
914
|
+
} else this.state = 23;
|
|
915
|
+
}
|
|
916
|
+
stateInSpecialComment(c) {
|
|
917
|
+
if (c === 62 || this.fastForwardTo(62)) {
|
|
918
|
+
this.cbs.oncomment(this.sectionStart, this.index);
|
|
919
|
+
this.state = 1;
|
|
920
|
+
this.sectionStart = this.index + 1;
|
|
921
|
+
}
|
|
922
|
+
}
|
|
923
|
+
stateBeforeSpecialS(c) {
|
|
924
|
+
if (c === Sequences.ScriptEnd[3]) this.startSpecial(Sequences.ScriptEnd, 4);
|
|
925
|
+
else if (c === Sequences.StyleEnd[3]) this.startSpecial(Sequences.StyleEnd, 4);
|
|
926
|
+
else {
|
|
927
|
+
this.state = 6;
|
|
928
|
+
this.stateInTagName(c);
|
|
929
|
+
}
|
|
930
|
+
}
|
|
931
|
+
stateBeforeSpecialT(c) {
|
|
932
|
+
if (c === Sequences.TitleEnd[3]) this.startSpecial(Sequences.TitleEnd, 4);
|
|
933
|
+
else if (c === Sequences.TextareaEnd[3]) this.startSpecial(Sequences.TextareaEnd, 4);
|
|
934
|
+
else {
|
|
935
|
+
this.state = 6;
|
|
936
|
+
this.stateInTagName(c);
|
|
937
|
+
}
|
|
938
|
+
}
|
|
939
|
+
startEntity() {}
|
|
940
|
+
stateInEntity() {}
|
|
941
|
+
/**
|
|
942
|
+
* Iterates through the buffer, calling the function corresponding to the current state.
|
|
943
|
+
*
|
|
944
|
+
* States that are more likely to be hit are higher up, as a performance improvement.
|
|
945
|
+
*/
|
|
946
|
+
parse(input) {
|
|
947
|
+
this.buffer = input;
|
|
948
|
+
while (this.index < this.buffer.length) {
|
|
949
|
+
const c = this.buffer.charCodeAt(this.index);
|
|
950
|
+
if (c === 10 && this.state !== 33) this.newlines.push(this.index);
|
|
951
|
+
switch (this.state) {
|
|
952
|
+
case 1:
|
|
953
|
+
this.stateText(c);
|
|
954
|
+
break;
|
|
955
|
+
case 2:
|
|
956
|
+
this.stateInterpolationOpen(c);
|
|
957
|
+
break;
|
|
958
|
+
case 3:
|
|
959
|
+
this.stateInterpolation(c);
|
|
960
|
+
break;
|
|
961
|
+
case 4:
|
|
962
|
+
this.stateInterpolationClose(c);
|
|
963
|
+
break;
|
|
964
|
+
case 31:
|
|
965
|
+
this.stateSpecialStartSequence(c);
|
|
966
|
+
break;
|
|
967
|
+
case 32:
|
|
968
|
+
this.stateInRCDATA(c);
|
|
969
|
+
break;
|
|
970
|
+
case 26:
|
|
971
|
+
this.stateCDATASequence(c);
|
|
972
|
+
break;
|
|
973
|
+
case 19:
|
|
974
|
+
this.stateInAttrValueDoubleQuotes(c);
|
|
975
|
+
break;
|
|
976
|
+
case 12:
|
|
977
|
+
this.stateInAttrName(c);
|
|
978
|
+
break;
|
|
979
|
+
case 13:
|
|
980
|
+
this.stateInDirName(c);
|
|
981
|
+
break;
|
|
982
|
+
case 14:
|
|
983
|
+
this.stateInDirArg(c);
|
|
984
|
+
break;
|
|
985
|
+
case 15:
|
|
986
|
+
this.stateInDynamicDirArg(c);
|
|
987
|
+
break;
|
|
988
|
+
case 16:
|
|
989
|
+
this.stateInDirModifier(c);
|
|
990
|
+
break;
|
|
991
|
+
case 28:
|
|
992
|
+
this.stateInCommentLike(c);
|
|
993
|
+
break;
|
|
994
|
+
case 27:
|
|
995
|
+
this.stateInSpecialComment(c);
|
|
996
|
+
break;
|
|
997
|
+
case 11:
|
|
998
|
+
this.stateBeforeAttrName(c);
|
|
999
|
+
break;
|
|
1000
|
+
case 6:
|
|
1001
|
+
this.stateInTagName(c);
|
|
1002
|
+
break;
|
|
1003
|
+
case 34:
|
|
1004
|
+
this.stateInSFCRootTagName(c);
|
|
1005
|
+
break;
|
|
1006
|
+
case 9:
|
|
1007
|
+
this.stateInClosingTagName(c);
|
|
1008
|
+
break;
|
|
1009
|
+
case 5:
|
|
1010
|
+
this.stateBeforeTagName(c);
|
|
1011
|
+
break;
|
|
1012
|
+
case 17:
|
|
1013
|
+
this.stateAfterAttrName(c);
|
|
1014
|
+
break;
|
|
1015
|
+
case 20:
|
|
1016
|
+
this.stateInAttrValueSingleQuotes(c);
|
|
1017
|
+
break;
|
|
1018
|
+
case 18:
|
|
1019
|
+
this.stateBeforeAttrValue(c);
|
|
1020
|
+
break;
|
|
1021
|
+
case 8:
|
|
1022
|
+
this.stateBeforeClosingTagName(c);
|
|
1023
|
+
break;
|
|
1024
|
+
case 10:
|
|
1025
|
+
this.stateAfterClosingTagName(c);
|
|
1026
|
+
break;
|
|
1027
|
+
case 29:
|
|
1028
|
+
this.stateBeforeSpecialS(c);
|
|
1029
|
+
break;
|
|
1030
|
+
case 30:
|
|
1031
|
+
this.stateBeforeSpecialT(c);
|
|
1032
|
+
break;
|
|
1033
|
+
case 21:
|
|
1034
|
+
this.stateInAttrValueNoQuotes(c);
|
|
1035
|
+
break;
|
|
1036
|
+
case 7:
|
|
1037
|
+
this.stateInSelfClosingTag(c);
|
|
1038
|
+
break;
|
|
1039
|
+
case 23:
|
|
1040
|
+
this.stateInDeclaration(c);
|
|
1041
|
+
break;
|
|
1042
|
+
case 22:
|
|
1043
|
+
this.stateBeforeDeclaration(c);
|
|
1044
|
+
break;
|
|
1045
|
+
case 25:
|
|
1046
|
+
this.stateBeforeComment(c);
|
|
1047
|
+
break;
|
|
1048
|
+
case 24:
|
|
1049
|
+
this.stateInProcessingInstruction(c);
|
|
1050
|
+
break;
|
|
1051
|
+
case 33:
|
|
1052
|
+
this.stateInEntity();
|
|
1053
|
+
break;
|
|
1054
|
+
}
|
|
1055
|
+
this.index++;
|
|
1056
|
+
}
|
|
1057
|
+
this.cleanup();
|
|
1058
|
+
this.finish();
|
|
1059
|
+
}
|
|
1060
|
+
/**
|
|
1061
|
+
* Remove data that has already been consumed from the buffer.
|
|
1062
|
+
*/
|
|
1063
|
+
cleanup() {
|
|
1064
|
+
if (this.sectionStart !== this.index) {
|
|
1065
|
+
if (this.state === 1 || this.state === 32 && this.sequenceIndex === 0) {
|
|
1066
|
+
this.cbs.ontext(this.sectionStart, this.index);
|
|
1067
|
+
this.sectionStart = this.index;
|
|
1068
|
+
} else if (this.state === 19 || this.state === 20 || this.state === 21) {
|
|
1069
|
+
this.cbs.onattribdata(this.sectionStart, this.index);
|
|
1070
|
+
this.sectionStart = this.index;
|
|
1071
|
+
}
|
|
1072
|
+
}
|
|
1073
|
+
}
|
|
1074
|
+
finish() {
|
|
1075
|
+
this.handleTrailingData();
|
|
1076
|
+
this.cbs.onend();
|
|
1077
|
+
}
|
|
1078
|
+
/** Handle any trailing data. */
|
|
1079
|
+
handleTrailingData() {
|
|
1080
|
+
const endIndex = this.buffer.length;
|
|
1081
|
+
if (this.sectionStart >= endIndex) return;
|
|
1082
|
+
if (this.state === 28) if (this.currentSequence === Sequences.CdataEnd) this.cbs.oncdata(this.sectionStart, endIndex);
|
|
1083
|
+
else this.cbs.oncomment(this.sectionStart, endIndex);
|
|
1084
|
+
else if (this.state === 6 || this.state === 11 || this.state === 18 || this.state === 17 || this.state === 12 || this.state === 13 || this.state === 14 || this.state === 15 || this.state === 16 || this.state === 20 || this.state === 19 || this.state === 21 || this.state === 9) {} else this.cbs.ontext(this.sectionStart, endIndex);
|
|
1085
|
+
}
|
|
1086
|
+
emitCodePoint(cp, consumed) {}
|
|
1087
|
+
};
|
|
1088
|
+
|
|
1089
|
+
//#endregion
|
|
1090
|
+
//#region packages/compiler-core/src/compat/compatConfig.ts
|
|
1091
|
+
const CompilerDeprecationTypes = {
|
|
1092
|
+
"COMPILER_IS_ON_ELEMENT": "COMPILER_IS_ON_ELEMENT",
|
|
1093
|
+
"COMPILER_V_BIND_SYNC": "COMPILER_V_BIND_SYNC",
|
|
1094
|
+
"COMPILER_V_BIND_OBJECT_ORDER": "COMPILER_V_BIND_OBJECT_ORDER",
|
|
1095
|
+
"COMPILER_V_ON_NATIVE": "COMPILER_V_ON_NATIVE",
|
|
1096
|
+
"COMPILER_V_IF_V_FOR_PRECEDENCE": "COMPILER_V_IF_V_FOR_PRECEDENCE",
|
|
1097
|
+
"COMPILER_NATIVE_TEMPLATE": "COMPILER_NATIVE_TEMPLATE",
|
|
1098
|
+
"COMPILER_INLINE_TEMPLATE": "COMPILER_INLINE_TEMPLATE",
|
|
1099
|
+
"COMPILER_FILTERS": "COMPILER_FILTERS"
|
|
1100
|
+
};
|
|
1101
|
+
const deprecationData = {
|
|
1102
|
+
["COMPILER_IS_ON_ELEMENT"]: {
|
|
1103
|
+
message: "Platform-native elements with \"is\" prop will no longer be treated as components in Vue 3 unless the \"is\" value is explicitly prefixed with \"vue:\".",
|
|
1104
|
+
link: `https://v3-migration.vuejs.org/breaking-changes/custom-elements-interop.html`
|
|
1105
|
+
},
|
|
1106
|
+
["COMPILER_V_BIND_SYNC"]: {
|
|
1107
|
+
message: (key) => `.sync modifier for v-bind has been removed. Use v-model with argument instead. \`v-bind:${key}.sync\` should be changed to \`v-model:${key}\`.`,
|
|
1108
|
+
link: `https://v3-migration.vuejs.org/breaking-changes/v-model.html`
|
|
1109
|
+
},
|
|
1110
|
+
["COMPILER_V_BIND_OBJECT_ORDER"]: {
|
|
1111
|
+
message: "v-bind=\"obj\" usage is now order sensitive and behaves like JavaScript object spread: it will now overwrite an existing non-mergeable attribute that appears before v-bind in the case of conflict. To retain 2.x behavior, move v-bind to make it the first attribute. You can also suppress this warning if the usage is intended.",
|
|
1112
|
+
link: `https://v3-migration.vuejs.org/breaking-changes/v-bind.html`
|
|
1113
|
+
},
|
|
1114
|
+
["COMPILER_V_ON_NATIVE"]: {
|
|
1115
|
+
message: `.native modifier for v-on has been removed as is no longer necessary.`,
|
|
1116
|
+
link: `https://v3-migration.vuejs.org/breaking-changes/v-on-native-modifier-removed.html`
|
|
1117
|
+
},
|
|
1118
|
+
["COMPILER_V_IF_V_FOR_PRECEDENCE"]: {
|
|
1119
|
+
message: "v-if / v-for precedence when used on the same element has changed in Vue 3: v-if now takes higher precedence and will no longer have access to v-for scope variables. It is best to avoid the ambiguity with <template> tags or use a computed property that filters v-for data source.",
|
|
1120
|
+
link: `https://v3-migration.vuejs.org/breaking-changes/v-if-v-for.html`
|
|
1121
|
+
},
|
|
1122
|
+
["COMPILER_NATIVE_TEMPLATE"]: { message: "<template> with no special directives will render as a native template element instead of its inner content in Vue 3." },
|
|
1123
|
+
["COMPILER_INLINE_TEMPLATE"]: {
|
|
1124
|
+
message: `"inline-template" has been removed in Vue 3.`,
|
|
1125
|
+
link: `https://v3-migration.vuejs.org/breaking-changes/inline-template-attribute.html`
|
|
1126
|
+
},
|
|
1127
|
+
["COMPILER_FILTERS"]: {
|
|
1128
|
+
message: "filters have been removed in Vue 3. The \"|\" symbol will be treated as native JavaScript bitwise OR operator. Use method calls or computed properties instead.",
|
|
1129
|
+
link: `https://v3-migration.vuejs.org/breaking-changes/filters.html`
|
|
1130
|
+
}
|
|
1131
|
+
};
|
|
1132
|
+
function getCompatValue(key, { compatConfig }) {
|
|
1133
|
+
const value = compatConfig && compatConfig[key];
|
|
1134
|
+
if (key === "MODE") return value || 3;
|
|
1135
|
+
else return value;
|
|
1136
|
+
}
|
|
1137
|
+
function isCompatEnabled(key, context) {
|
|
1138
|
+
const mode = getCompatValue("MODE", context);
|
|
1139
|
+
const value = getCompatValue(key, context);
|
|
1140
|
+
return mode === 3 ? value === true : value !== false;
|
|
1141
|
+
}
|
|
1142
|
+
function checkCompatEnabled(key, context, loc, ...args) {
|
|
1143
|
+
const enabled = isCompatEnabled(key, context);
|
|
1144
|
+
if (!!(process.env.NODE_ENV !== "production") && enabled) warnDeprecation(key, context, loc, ...args);
|
|
1145
|
+
return enabled;
|
|
1146
|
+
}
|
|
1147
|
+
function warnDeprecation(key, context, loc, ...args) {
|
|
1148
|
+
if (getCompatValue(key, context) === "suppress-warning") return;
|
|
1149
|
+
const { message, link } = deprecationData[key];
|
|
1150
|
+
const msg = `(deprecation ${key}) ${typeof message === "function" ? message(...args) : message}${link ? `\n Details: ${link}` : ``}`;
|
|
1151
|
+
const err = new SyntaxError(msg);
|
|
1152
|
+
err.code = key;
|
|
1153
|
+
if (loc) err.loc = loc;
|
|
1154
|
+
context.onWarn(err);
|
|
1155
|
+
}
|
|
1156
|
+
|
|
1157
|
+
//#endregion
|
|
1158
|
+
//#region packages/compiler-core/src/errors.ts
|
|
1159
|
+
function defaultOnError(error) {
|
|
1160
|
+
throw error;
|
|
1161
|
+
}
|
|
1162
|
+
function defaultOnWarn(msg) {
|
|
1163
|
+
process.env.NODE_ENV !== "production" && console.warn(`[Vue warn] ${msg.message}`);
|
|
1164
|
+
}
|
|
1165
|
+
function createCompilerError(code, loc, messages, additionalMessage) {
|
|
1166
|
+
const msg = !!(process.env.NODE_ENV !== "production") || false ? (messages || errorMessages)[code] + (additionalMessage || ``) : `https://vuejs.org/error-reference/#compiler-${code}`;
|
|
1167
|
+
const error = new SyntaxError(String(msg));
|
|
1168
|
+
error.code = code;
|
|
1169
|
+
error.loc = loc;
|
|
1170
|
+
return error;
|
|
1171
|
+
}
|
|
1172
|
+
const ErrorCodes = {
|
|
1173
|
+
"ABRUPT_CLOSING_OF_EMPTY_COMMENT": 0,
|
|
1174
|
+
"0": "ABRUPT_CLOSING_OF_EMPTY_COMMENT",
|
|
1175
|
+
"CDATA_IN_HTML_CONTENT": 1,
|
|
1176
|
+
"1": "CDATA_IN_HTML_CONTENT",
|
|
1177
|
+
"DUPLICATE_ATTRIBUTE": 2,
|
|
1178
|
+
"2": "DUPLICATE_ATTRIBUTE",
|
|
1179
|
+
"END_TAG_WITH_ATTRIBUTES": 3,
|
|
1180
|
+
"3": "END_TAG_WITH_ATTRIBUTES",
|
|
1181
|
+
"END_TAG_WITH_TRAILING_SOLIDUS": 4,
|
|
1182
|
+
"4": "END_TAG_WITH_TRAILING_SOLIDUS",
|
|
1183
|
+
"EOF_BEFORE_TAG_NAME": 5,
|
|
1184
|
+
"5": "EOF_BEFORE_TAG_NAME",
|
|
1185
|
+
"EOF_IN_CDATA": 6,
|
|
1186
|
+
"6": "EOF_IN_CDATA",
|
|
1187
|
+
"EOF_IN_COMMENT": 7,
|
|
1188
|
+
"7": "EOF_IN_COMMENT",
|
|
1189
|
+
"EOF_IN_SCRIPT_HTML_COMMENT_LIKE_TEXT": 8,
|
|
1190
|
+
"8": "EOF_IN_SCRIPT_HTML_COMMENT_LIKE_TEXT",
|
|
1191
|
+
"EOF_IN_TAG": 9,
|
|
1192
|
+
"9": "EOF_IN_TAG",
|
|
1193
|
+
"INCORRECTLY_CLOSED_COMMENT": 10,
|
|
1194
|
+
"10": "INCORRECTLY_CLOSED_COMMENT",
|
|
1195
|
+
"INCORRECTLY_OPENED_COMMENT": 11,
|
|
1196
|
+
"11": "INCORRECTLY_OPENED_COMMENT",
|
|
1197
|
+
"INVALID_FIRST_CHARACTER_OF_TAG_NAME": 12,
|
|
1198
|
+
"12": "INVALID_FIRST_CHARACTER_OF_TAG_NAME",
|
|
1199
|
+
"MISSING_ATTRIBUTE_VALUE": 13,
|
|
1200
|
+
"13": "MISSING_ATTRIBUTE_VALUE",
|
|
1201
|
+
"MISSING_END_TAG_NAME": 14,
|
|
1202
|
+
"14": "MISSING_END_TAG_NAME",
|
|
1203
|
+
"MISSING_WHITESPACE_BETWEEN_ATTRIBUTES": 15,
|
|
1204
|
+
"15": "MISSING_WHITESPACE_BETWEEN_ATTRIBUTES",
|
|
1205
|
+
"NESTED_COMMENT": 16,
|
|
1206
|
+
"16": "NESTED_COMMENT",
|
|
1207
|
+
"UNEXPECTED_CHARACTER_IN_ATTRIBUTE_NAME": 17,
|
|
1208
|
+
"17": "UNEXPECTED_CHARACTER_IN_ATTRIBUTE_NAME",
|
|
1209
|
+
"UNEXPECTED_CHARACTER_IN_UNQUOTED_ATTRIBUTE_VALUE": 18,
|
|
1210
|
+
"18": "UNEXPECTED_CHARACTER_IN_UNQUOTED_ATTRIBUTE_VALUE",
|
|
1211
|
+
"UNEXPECTED_EQUALS_SIGN_BEFORE_ATTRIBUTE_NAME": 19,
|
|
1212
|
+
"19": "UNEXPECTED_EQUALS_SIGN_BEFORE_ATTRIBUTE_NAME",
|
|
1213
|
+
"UNEXPECTED_NULL_CHARACTER": 20,
|
|
1214
|
+
"20": "UNEXPECTED_NULL_CHARACTER",
|
|
1215
|
+
"UNEXPECTED_QUESTION_MARK_INSTEAD_OF_TAG_NAME": 21,
|
|
1216
|
+
"21": "UNEXPECTED_QUESTION_MARK_INSTEAD_OF_TAG_NAME",
|
|
1217
|
+
"UNEXPECTED_SOLIDUS_IN_TAG": 22,
|
|
1218
|
+
"22": "UNEXPECTED_SOLIDUS_IN_TAG",
|
|
1219
|
+
"X_INVALID_END_TAG": 23,
|
|
1220
|
+
"23": "X_INVALID_END_TAG",
|
|
1221
|
+
"X_MISSING_END_TAG": 24,
|
|
1222
|
+
"24": "X_MISSING_END_TAG",
|
|
1223
|
+
"X_MISSING_INTERPOLATION_END": 25,
|
|
1224
|
+
"25": "X_MISSING_INTERPOLATION_END",
|
|
1225
|
+
"X_MISSING_DIRECTIVE_NAME": 26,
|
|
1226
|
+
"26": "X_MISSING_DIRECTIVE_NAME",
|
|
1227
|
+
"X_MISSING_DYNAMIC_DIRECTIVE_ARGUMENT_END": 27,
|
|
1228
|
+
"27": "X_MISSING_DYNAMIC_DIRECTIVE_ARGUMENT_END",
|
|
1229
|
+
"X_V_IF_NO_EXPRESSION": 28,
|
|
1230
|
+
"28": "X_V_IF_NO_EXPRESSION",
|
|
1231
|
+
"X_V_IF_SAME_KEY": 29,
|
|
1232
|
+
"29": "X_V_IF_SAME_KEY",
|
|
1233
|
+
"X_V_ELSE_NO_ADJACENT_IF": 30,
|
|
1234
|
+
"30": "X_V_ELSE_NO_ADJACENT_IF",
|
|
1235
|
+
"X_V_FOR_NO_EXPRESSION": 31,
|
|
1236
|
+
"31": "X_V_FOR_NO_EXPRESSION",
|
|
1237
|
+
"X_V_FOR_MALFORMED_EXPRESSION": 32,
|
|
1238
|
+
"32": "X_V_FOR_MALFORMED_EXPRESSION",
|
|
1239
|
+
"X_V_FOR_TEMPLATE_KEY_PLACEMENT": 33,
|
|
1240
|
+
"33": "X_V_FOR_TEMPLATE_KEY_PLACEMENT",
|
|
1241
|
+
"X_V_BIND_NO_EXPRESSION": 34,
|
|
1242
|
+
"34": "X_V_BIND_NO_EXPRESSION",
|
|
1243
|
+
"X_V_ON_NO_EXPRESSION": 35,
|
|
1244
|
+
"35": "X_V_ON_NO_EXPRESSION",
|
|
1245
|
+
"X_V_SLOT_UNEXPECTED_DIRECTIVE_ON_SLOT_OUTLET": 36,
|
|
1246
|
+
"36": "X_V_SLOT_UNEXPECTED_DIRECTIVE_ON_SLOT_OUTLET",
|
|
1247
|
+
"X_V_SLOT_MIXED_SLOT_USAGE": 37,
|
|
1248
|
+
"37": "X_V_SLOT_MIXED_SLOT_USAGE",
|
|
1249
|
+
"X_V_SLOT_DUPLICATE_SLOT_NAMES": 38,
|
|
1250
|
+
"38": "X_V_SLOT_DUPLICATE_SLOT_NAMES",
|
|
1251
|
+
"X_V_SLOT_EXTRANEOUS_DEFAULT_SLOT_CHILDREN": 39,
|
|
1252
|
+
"39": "X_V_SLOT_EXTRANEOUS_DEFAULT_SLOT_CHILDREN",
|
|
1253
|
+
"X_V_SLOT_MISPLACED": 40,
|
|
1254
|
+
"40": "X_V_SLOT_MISPLACED",
|
|
1255
|
+
"X_V_MODEL_NO_EXPRESSION": 41,
|
|
1256
|
+
"41": "X_V_MODEL_NO_EXPRESSION",
|
|
1257
|
+
"X_V_MODEL_MALFORMED_EXPRESSION": 42,
|
|
1258
|
+
"42": "X_V_MODEL_MALFORMED_EXPRESSION",
|
|
1259
|
+
"X_V_MODEL_ON_SCOPE_VARIABLE": 43,
|
|
1260
|
+
"43": "X_V_MODEL_ON_SCOPE_VARIABLE",
|
|
1261
|
+
"X_V_MODEL_ON_PROPS": 44,
|
|
1262
|
+
"44": "X_V_MODEL_ON_PROPS",
|
|
1263
|
+
"X_V_MODEL_ON_CONST": 45,
|
|
1264
|
+
"45": "X_V_MODEL_ON_CONST",
|
|
1265
|
+
"X_INVALID_EXPRESSION": 46,
|
|
1266
|
+
"46": "X_INVALID_EXPRESSION",
|
|
1267
|
+
"X_KEEP_ALIVE_INVALID_CHILDREN": 47,
|
|
1268
|
+
"47": "X_KEEP_ALIVE_INVALID_CHILDREN",
|
|
1269
|
+
"X_PREFIX_ID_NOT_SUPPORTED": 48,
|
|
1270
|
+
"48": "X_PREFIX_ID_NOT_SUPPORTED",
|
|
1271
|
+
"X_MODULE_MODE_NOT_SUPPORTED": 49,
|
|
1272
|
+
"49": "X_MODULE_MODE_NOT_SUPPORTED",
|
|
1273
|
+
"X_CACHE_HANDLER_NOT_SUPPORTED": 50,
|
|
1274
|
+
"50": "X_CACHE_HANDLER_NOT_SUPPORTED",
|
|
1275
|
+
"X_SCOPE_ID_NOT_SUPPORTED": 51,
|
|
1276
|
+
"51": "X_SCOPE_ID_NOT_SUPPORTED",
|
|
1277
|
+
"X_VNODE_HOOKS": 52,
|
|
1278
|
+
"52": "X_VNODE_HOOKS",
|
|
1279
|
+
"X_V_BIND_INVALID_SAME_NAME_ARGUMENT": 53,
|
|
1280
|
+
"53": "X_V_BIND_INVALID_SAME_NAME_ARGUMENT",
|
|
1281
|
+
"__EXTEND_POINT__": 54,
|
|
1282
|
+
"54": "__EXTEND_POINT__"
|
|
1283
|
+
};
|
|
1284
|
+
const errorMessages = {
|
|
1285
|
+
[0]: "Illegal comment.",
|
|
1286
|
+
[1]: "CDATA section is allowed only in XML context.",
|
|
1287
|
+
[2]: "Duplicate attribute.",
|
|
1288
|
+
[3]: "End tag cannot have attributes.",
|
|
1289
|
+
[4]: "Illegal '/' in tags.",
|
|
1290
|
+
[5]: "Unexpected EOF in tag.",
|
|
1291
|
+
[6]: "Unexpected EOF in CDATA section.",
|
|
1292
|
+
[7]: "Unexpected EOF in comment.",
|
|
1293
|
+
[8]: "Unexpected EOF in script.",
|
|
1294
|
+
[9]: "Unexpected EOF in tag.",
|
|
1295
|
+
[10]: "Incorrectly closed comment.",
|
|
1296
|
+
[11]: "Incorrectly opened comment.",
|
|
1297
|
+
[12]: "Illegal tag name. Use '<' to print '<'.",
|
|
1298
|
+
[13]: "Attribute value was expected.",
|
|
1299
|
+
[14]: "End tag name was expected.",
|
|
1300
|
+
[15]: "Whitespace was expected.",
|
|
1301
|
+
[16]: "Unexpected '<!--' in comment.",
|
|
1302
|
+
[17]: "Attribute name cannot contain U+0022 (\"), U+0027 ('), and U+003C (<).",
|
|
1303
|
+
[18]: "Unquoted attribute value cannot contain U+0022 (\"), U+0027 ('), U+003C (<), U+003D (=), and U+0060 (`).",
|
|
1304
|
+
[19]: "Attribute name cannot start with '='.",
|
|
1305
|
+
[21]: "'<?' is allowed only in XML context.",
|
|
1306
|
+
[20]: `Unexpected null character.`,
|
|
1307
|
+
[22]: "Illegal '/' in tags.",
|
|
1308
|
+
[23]: "Invalid end tag.",
|
|
1309
|
+
[24]: "Element is missing end tag.",
|
|
1310
|
+
[25]: "Interpolation end sign was not found.",
|
|
1311
|
+
[27]: "End bracket for dynamic directive argument was not found. Note that dynamic directive argument cannot contain spaces.",
|
|
1312
|
+
[26]: "Legal directive name was expected.",
|
|
1313
|
+
[28]: `v-if/v-else-if is missing expression.`,
|
|
1314
|
+
[29]: `v-if/else branches must use unique keys.`,
|
|
1315
|
+
[30]: `v-else/v-else-if has no adjacent v-if or v-else-if.`,
|
|
1316
|
+
[31]: `v-for is missing expression.`,
|
|
1317
|
+
[32]: `v-for has invalid expression.`,
|
|
1318
|
+
[33]: `<template v-for> key should be placed on the <template> tag.`,
|
|
1319
|
+
[34]: `v-bind is missing expression.`,
|
|
1320
|
+
[53]: `v-bind with same-name shorthand only allows static argument.`,
|
|
1321
|
+
[35]: `v-on is missing expression.`,
|
|
1322
|
+
[36]: `Unexpected custom directive on <slot> outlet.`,
|
|
1323
|
+
[37]: "Mixed v-slot usage on both the component and nested <template>. When there are multiple named slots, all slots should use <template> syntax to avoid scope ambiguity.",
|
|
1324
|
+
[38]: `Duplicate slot names found. `,
|
|
1325
|
+
[39]: "Extraneous children found when component already has explicitly named default slot. These children will be ignored.",
|
|
1326
|
+
[40]: `v-slot can only be used on components or <template> tags.`,
|
|
1327
|
+
[41]: `v-model is missing expression.`,
|
|
1328
|
+
[42]: `v-model value must be a valid JavaScript member expression.`,
|
|
1329
|
+
[43]: `v-model cannot be used on v-for or v-slot scope variables because they are not writable.`,
|
|
1330
|
+
[44]: `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.`,
|
|
1331
|
+
[45]: `v-model cannot be used on a const binding because it is not writable.`,
|
|
1332
|
+
[46]: `Error parsing JavaScript expression: `,
|
|
1333
|
+
[47]: `<KeepAlive> expects exactly one child component.`,
|
|
1334
|
+
[52]: `@vnode-* hooks in templates are no longer supported. Use the vue: prefix instead. For example, @vnode-mounted should be changed to @vue:mounted. @vnode-* hooks support has been removed in 3.4.`,
|
|
1335
|
+
[48]: `"prefixIdentifiers" option is not supported in this build of compiler.`,
|
|
1336
|
+
[49]: `ES module mode is not supported in this build of compiler.`,
|
|
1337
|
+
[50]: `"cacheHandlers" option is only supported when the "prefixIdentifiers" option is enabled.`,
|
|
1338
|
+
[51]: `"scopeId" option is only supported in module mode.`,
|
|
1339
|
+
[54]: ``
|
|
1340
|
+
};
|
|
1341
|
+
|
|
1342
|
+
//#endregion
|
|
1343
|
+
//#region packages/compiler-core/src/babelUtils.ts
|
|
1344
|
+
/**
|
|
1345
|
+
* Return value indicates whether the AST walked can be a constant
|
|
1346
|
+
*/
|
|
1347
|
+
function walkIdentifiers(root, onIdentifier, includeAll = false, parentStack = [], knownIds = Object.create(null)) {}
|
|
1348
|
+
function isReferencedIdentifier(id, parent, parentStack) {
|
|
1349
|
+
return false;
|
|
1350
|
+
}
|
|
1351
|
+
function isInDestructureAssignment(parent, parentStack) {
|
|
1352
|
+
if (parent && (parent.type === "ObjectProperty" || parent.type === "ArrayPattern")) {
|
|
1353
|
+
let i = parentStack.length;
|
|
1354
|
+
while (i--) {
|
|
1355
|
+
const p = parentStack[i];
|
|
1356
|
+
if (p.type === "AssignmentExpression") return true;
|
|
1357
|
+
else if (p.type !== "ObjectProperty" && !p.type.endsWith("Pattern")) break;
|
|
1358
|
+
}
|
|
1359
|
+
}
|
|
1360
|
+
return false;
|
|
1361
|
+
}
|
|
1362
|
+
function isInNewExpression(parentStack) {
|
|
1363
|
+
let i = parentStack.length;
|
|
1364
|
+
while (i--) {
|
|
1365
|
+
const p = parentStack[i];
|
|
1366
|
+
if (p.type === "NewExpression") return true;
|
|
1367
|
+
else if (p.type !== "MemberExpression") break;
|
|
1368
|
+
}
|
|
1369
|
+
return false;
|
|
1370
|
+
}
|
|
1371
|
+
function walkFunctionParams(node, onIdent) {
|
|
1372
|
+
for (const p of node.params) for (const id of extractIdentifiers(p)) onIdent(id);
|
|
1373
|
+
}
|
|
1374
|
+
function walkBlockDeclarations(block, onIdent) {
|
|
1375
|
+
const body = block.type === "SwitchCase" ? block.consequent : block.body;
|
|
1376
|
+
for (const stmt of body) if (stmt.type === "VariableDeclaration") {
|
|
1377
|
+
if (stmt.declare) continue;
|
|
1378
|
+
for (const decl of stmt.declarations) for (const id of extractIdentifiers(decl.id)) onIdent(id);
|
|
1379
|
+
} else if (stmt.type === "FunctionDeclaration" || stmt.type === "ClassDeclaration") {
|
|
1380
|
+
if (stmt.declare || !stmt.id) continue;
|
|
1381
|
+
onIdent(stmt.id);
|
|
1382
|
+
} else if (isForStatement(stmt)) walkForStatement(stmt, true, onIdent);
|
|
1383
|
+
else if (stmt.type === "SwitchStatement") walkSwitchStatement(stmt, true, onIdent);
|
|
1384
|
+
}
|
|
1385
|
+
function isForStatement(stmt) {
|
|
1386
|
+
return stmt.type === "ForOfStatement" || stmt.type === "ForInStatement" || stmt.type === "ForStatement";
|
|
1387
|
+
}
|
|
1388
|
+
function walkForStatement(stmt, isVar, onIdent) {
|
|
1389
|
+
const variable = stmt.type === "ForStatement" ? stmt.init : stmt.left;
|
|
1390
|
+
if (variable && variable.type === "VariableDeclaration" && (variable.kind === "var" ? isVar : !isVar)) for (const decl of variable.declarations) for (const id of extractIdentifiers(decl.id)) onIdent(id);
|
|
1391
|
+
}
|
|
1392
|
+
function walkSwitchStatement(stmt, isVar, onIdent) {
|
|
1393
|
+
for (const cs of stmt.cases) {
|
|
1394
|
+
for (const stmt of cs.consequent) if (stmt.type === "VariableDeclaration" && (stmt.kind === "var" ? isVar : !isVar)) for (const decl of stmt.declarations) for (const id of extractIdentifiers(decl.id)) onIdent(id);
|
|
1395
|
+
walkBlockDeclarations(cs, onIdent);
|
|
1396
|
+
}
|
|
1397
|
+
}
|
|
1398
|
+
function extractIdentifiers(param, nodes = []) {
|
|
1399
|
+
switch (param.type) {
|
|
1400
|
+
case "Identifier":
|
|
1401
|
+
nodes.push(param);
|
|
1402
|
+
break;
|
|
1403
|
+
case "MemberExpression":
|
|
1404
|
+
let object = param;
|
|
1405
|
+
while (object.type === "MemberExpression") object = object.object;
|
|
1406
|
+
nodes.push(object);
|
|
1407
|
+
break;
|
|
1408
|
+
case "ObjectPattern":
|
|
1409
|
+
for (const prop of param.properties) if (prop.type === "RestElement") extractIdentifiers(prop.argument, nodes);
|
|
1410
|
+
else extractIdentifiers(prop.value, nodes);
|
|
1411
|
+
break;
|
|
1412
|
+
case "ArrayPattern":
|
|
1413
|
+
param.elements.forEach((element) => {
|
|
1414
|
+
if (element) extractIdentifiers(element, nodes);
|
|
1415
|
+
});
|
|
1416
|
+
break;
|
|
1417
|
+
case "RestElement":
|
|
1418
|
+
extractIdentifiers(param.argument, nodes);
|
|
1419
|
+
break;
|
|
1420
|
+
case "AssignmentPattern":
|
|
1421
|
+
extractIdentifiers(param.left, nodes);
|
|
1422
|
+
break;
|
|
1423
|
+
}
|
|
1424
|
+
return nodes;
|
|
1425
|
+
}
|
|
1426
|
+
const isFunctionType = (node) => {
|
|
1427
|
+
return /Function(?:Expression|Declaration)$|Method$/.test(node.type);
|
|
1428
|
+
};
|
|
1429
|
+
const isStaticProperty = (node) => !!node && (node.type === "ObjectProperty" || node.type === "ObjectMethod") && !node.computed;
|
|
1430
|
+
const isStaticPropertyKey = (node, parent) => isStaticProperty(parent) && parent.key === node;
|
|
1431
|
+
const TS_NODE_TYPES = [
|
|
1432
|
+
"TSAsExpression",
|
|
1433
|
+
"TSTypeAssertion",
|
|
1434
|
+
"TSNonNullExpression",
|
|
1435
|
+
"TSInstantiationExpression",
|
|
1436
|
+
"TSSatisfiesExpression"
|
|
1437
|
+
];
|
|
1438
|
+
function unwrapTSNode(node) {
|
|
1439
|
+
if (TS_NODE_TYPES.includes(node.type)) return unwrapTSNode(node.expression);
|
|
1440
|
+
else return node;
|
|
1441
|
+
}
|
|
1442
|
+
function isStaticNode(node) {
|
|
1443
|
+
node = unwrapTSNode(node);
|
|
1444
|
+
switch (node.type) {
|
|
1445
|
+
case "UnaryExpression": return isStaticNode(node.argument);
|
|
1446
|
+
case "LogicalExpression":
|
|
1447
|
+
case "BinaryExpression": return isStaticNode(node.left) && isStaticNode(node.right);
|
|
1448
|
+
case "ConditionalExpression": return isStaticNode(node.test) && isStaticNode(node.consequent) && isStaticNode(node.alternate);
|
|
1449
|
+
case "SequenceExpression":
|
|
1450
|
+
case "TemplateLiteral": return node.expressions.every((expr) => isStaticNode(expr));
|
|
1451
|
+
case "ParenthesizedExpression": return isStaticNode(node.expression);
|
|
1452
|
+
case "StringLiteral":
|
|
1453
|
+
case "NumericLiteral":
|
|
1454
|
+
case "BooleanLiteral":
|
|
1455
|
+
case "NullLiteral":
|
|
1456
|
+
case "BigIntLiteral": return true;
|
|
1457
|
+
}
|
|
1458
|
+
return false;
|
|
1459
|
+
}
|
|
1460
|
+
function isConstantNode(node, bindings) {
|
|
1461
|
+
if (isStaticNode(node)) return true;
|
|
1462
|
+
node = unwrapTSNode(node);
|
|
1463
|
+
switch (node.type) {
|
|
1464
|
+
case "Identifier": return bindings[node.name] === "literal-const";
|
|
1465
|
+
case "RegExpLiteral": return true;
|
|
1466
|
+
case "ObjectExpression": return node.properties.every((prop) => {
|
|
1467
|
+
if (prop.type === "ObjectMethod") return false;
|
|
1468
|
+
if (prop.type === "SpreadElement") return isConstantNode(prop.argument, bindings);
|
|
1469
|
+
return (!prop.computed || isConstantNode(prop.key, bindings)) && isConstantNode(prop.value, bindings);
|
|
1470
|
+
});
|
|
1471
|
+
case "ArrayExpression": return node.elements.every((element) => {
|
|
1472
|
+
if (element === null) return true;
|
|
1473
|
+
if (element.type === "SpreadElement") return isConstantNode(element.argument, bindings);
|
|
1474
|
+
return isConstantNode(element, bindings);
|
|
1475
|
+
});
|
|
1476
|
+
}
|
|
1477
|
+
return false;
|
|
1478
|
+
}
|
|
1479
|
+
|
|
1480
|
+
//#endregion
|
|
1481
|
+
//#region packages/compiler-core/src/utils.ts
|
|
1482
|
+
const isStaticExp = (p) => p.type === 4 && p.isStatic;
|
|
1483
|
+
function isCoreComponent(tag) {
|
|
1484
|
+
switch (tag) {
|
|
1485
|
+
case "Teleport":
|
|
1486
|
+
case "teleport": return TELEPORT;
|
|
1487
|
+
case "Suspense":
|
|
1488
|
+
case "suspense": return SUSPENSE;
|
|
1489
|
+
case "KeepAlive":
|
|
1490
|
+
case "keep-alive": return KEEP_ALIVE;
|
|
1491
|
+
case "BaseTransition":
|
|
1492
|
+
case "base-transition": return BASE_TRANSITION;
|
|
1493
|
+
}
|
|
1494
|
+
}
|
|
1495
|
+
const nonIdentifierRE = /^$|^\d|[^\$\w\xA0-\uFFFF]/;
|
|
1496
|
+
const isSimpleIdentifier = (name) => !nonIdentifierRE.test(name);
|
|
1497
|
+
var MemberExpLexState = /* @__PURE__ */ function(MemberExpLexState) {
|
|
1498
|
+
MemberExpLexState[MemberExpLexState["inMemberExp"] = 0] = "inMemberExp";
|
|
1499
|
+
MemberExpLexState[MemberExpLexState["inBrackets"] = 1] = "inBrackets";
|
|
1500
|
+
MemberExpLexState[MemberExpLexState["inParens"] = 2] = "inParens";
|
|
1501
|
+
MemberExpLexState[MemberExpLexState["inString"] = 3] = "inString";
|
|
1502
|
+
return MemberExpLexState;
|
|
1503
|
+
}(MemberExpLexState || {});
|
|
1504
|
+
const validFirstIdentCharRE = /[A-Za-z_$\xA0-\uFFFF]/;
|
|
1505
|
+
const validIdentCharRE = /[\.\?\w$\xA0-\uFFFF]/;
|
|
1506
|
+
const whitespaceRE = /\s+[.[]\s*|\s*[.[]\s+/g;
|
|
1507
|
+
const getExpSource = (exp) => exp.type === 4 ? exp.content : exp.loc.source;
|
|
1508
|
+
/**
|
|
1509
|
+
* Simple lexer to check if an expression is a member expression. This is
|
|
1510
|
+
* lax and only checks validity at the root level (i.e. does not validate exps
|
|
1511
|
+
* inside square brackets), but it's ok since these are only used on template
|
|
1512
|
+
* expressions and false positives are invalid expressions in the first place.
|
|
1513
|
+
*/
|
|
1514
|
+
const isMemberExpressionBrowser = (exp) => {
|
|
1515
|
+
const path = getExpSource(exp).trim().replace(whitespaceRE, (s) => s.trim());
|
|
1516
|
+
let state = MemberExpLexState.inMemberExp;
|
|
1517
|
+
let stateStack = [];
|
|
1518
|
+
let currentOpenBracketCount = 0;
|
|
1519
|
+
let currentOpenParensCount = 0;
|
|
1520
|
+
let currentStringType = null;
|
|
1521
|
+
for (let i = 0; i < path.length; i++) {
|
|
1522
|
+
const char = path.charAt(i);
|
|
1523
|
+
switch (state) {
|
|
1524
|
+
case MemberExpLexState.inMemberExp:
|
|
1525
|
+
if (char === "[") {
|
|
1526
|
+
stateStack.push(state);
|
|
1527
|
+
state = MemberExpLexState.inBrackets;
|
|
1528
|
+
currentOpenBracketCount++;
|
|
1529
|
+
} else if (char === "(") {
|
|
1530
|
+
stateStack.push(state);
|
|
1531
|
+
state = MemberExpLexState.inParens;
|
|
1532
|
+
currentOpenParensCount++;
|
|
1533
|
+
} else if (!(i === 0 ? validFirstIdentCharRE : validIdentCharRE).test(char)) return false;
|
|
1534
|
+
break;
|
|
1535
|
+
case MemberExpLexState.inBrackets:
|
|
1536
|
+
if (char === `'` || char === `"` || char === "`") {
|
|
1537
|
+
stateStack.push(state);
|
|
1538
|
+
state = MemberExpLexState.inString;
|
|
1539
|
+
currentStringType = char;
|
|
1540
|
+
} else if (char === `[`) currentOpenBracketCount++;
|
|
1541
|
+
else if (char === `]`) {
|
|
1542
|
+
if (!--currentOpenBracketCount) state = stateStack.pop();
|
|
1543
|
+
}
|
|
1544
|
+
break;
|
|
1545
|
+
case MemberExpLexState.inParens:
|
|
1546
|
+
if (char === `'` || char === `"` || char === "`") {
|
|
1547
|
+
stateStack.push(state);
|
|
1548
|
+
state = MemberExpLexState.inString;
|
|
1549
|
+
currentStringType = char;
|
|
1550
|
+
} else if (char === `(`) currentOpenParensCount++;
|
|
1551
|
+
else if (char === `)`) {
|
|
1552
|
+
if (i === path.length - 1) return false;
|
|
1553
|
+
if (!--currentOpenParensCount) state = stateStack.pop();
|
|
1554
|
+
}
|
|
1555
|
+
break;
|
|
1556
|
+
case MemberExpLexState.inString:
|
|
1557
|
+
if (char === currentStringType) {
|
|
1558
|
+
state = stateStack.pop();
|
|
1559
|
+
currentStringType = null;
|
|
1560
|
+
}
|
|
1561
|
+
break;
|
|
1562
|
+
}
|
|
1563
|
+
}
|
|
1564
|
+
return !currentOpenBracketCount && !currentOpenParensCount;
|
|
1565
|
+
};
|
|
1566
|
+
const isMemberExpressionNode = NOOP;
|
|
1567
|
+
const isMemberExpression = isMemberExpressionBrowser;
|
|
1568
|
+
const fnExpRE = /^\s*(?:async\s*)?(?:\([^)]*?\)|[\w$_]+)\s*(?::[^=]+)?=>|^\s*(?:async\s+)?function(?:\s+[\w$]+)?\s*\(/;
|
|
1569
|
+
const isFnExpressionBrowser = (exp) => fnExpRE.test(getExpSource(exp));
|
|
1570
|
+
const isFnExpressionNode = NOOP;
|
|
1571
|
+
const isFnExpression = isFnExpressionBrowser;
|
|
1572
|
+
function advancePositionWithClone(pos, source, numberOfCharacters = source.length) {
|
|
1573
|
+
return advancePositionWithMutation({
|
|
1574
|
+
offset: pos.offset,
|
|
1575
|
+
line: pos.line,
|
|
1576
|
+
column: pos.column
|
|
1577
|
+
}, source, numberOfCharacters);
|
|
1578
|
+
}
|
|
1579
|
+
function advancePositionWithMutation(pos, source, numberOfCharacters = source.length) {
|
|
1580
|
+
let linesCount = 0;
|
|
1581
|
+
let lastNewLinePos = -1;
|
|
1582
|
+
for (let i = 0; i < numberOfCharacters; i++) if (source.charCodeAt(i) === 10) {
|
|
1583
|
+
linesCount++;
|
|
1584
|
+
lastNewLinePos = i;
|
|
1585
|
+
}
|
|
1586
|
+
pos.offset += numberOfCharacters;
|
|
1587
|
+
pos.line += linesCount;
|
|
1588
|
+
pos.column = lastNewLinePos === -1 ? pos.column + numberOfCharacters : numberOfCharacters - lastNewLinePos;
|
|
1589
|
+
return pos;
|
|
1590
|
+
}
|
|
1591
|
+
function assert(condition, msg) {
|
|
1592
|
+
/* v8 ignore next 3 */
|
|
1593
|
+
if (!condition) throw new Error(msg || `unexpected compiler condition`);
|
|
1594
|
+
}
|
|
1595
|
+
/** find directive */
|
|
1596
|
+
function findDir(node, name, allowEmpty = false) {
|
|
1597
|
+
for (let i = 0; i < node.props.length; i++) {
|
|
1598
|
+
const p = node.props[i];
|
|
1599
|
+
if (p.type === 7 && (allowEmpty || p.exp) && (isString(name) ? p.name === name : name.test(p.name))) return p;
|
|
1600
|
+
}
|
|
1601
|
+
}
|
|
1602
|
+
function findProp(node, name, dynamicOnly = false, allowEmpty = false) {
|
|
1603
|
+
for (let i = 0; i < node.props.length; i++) {
|
|
1604
|
+
const p = node.props[i];
|
|
1605
|
+
if (p.type === 6) {
|
|
1606
|
+
if (dynamicOnly) continue;
|
|
1607
|
+
if (p.name === name && (p.value || allowEmpty)) return p;
|
|
1608
|
+
} else if (p.name === "bind" && (p.exp || allowEmpty) && isStaticArgOf(p.arg, name)) return p;
|
|
1609
|
+
}
|
|
1610
|
+
}
|
|
1611
|
+
function isStaticArgOf(arg, name) {
|
|
1612
|
+
return !!(arg && isStaticExp(arg) && arg.content === name);
|
|
1613
|
+
}
|
|
1614
|
+
function hasDynamicKeyVBind(node) {
|
|
1615
|
+
return node.props.some((p) => p.type === 7 && p.name === "bind" && (!p.arg || p.arg.type !== 4 || !p.arg.isStatic));
|
|
1616
|
+
}
|
|
1617
|
+
function isText(node) {
|
|
1618
|
+
return node.type === 5 || node.type === 2;
|
|
1619
|
+
}
|
|
1620
|
+
function isVPre(p) {
|
|
1621
|
+
return p.type === 7 && p.name === "pre";
|
|
1622
|
+
}
|
|
1623
|
+
function isVSlot(p) {
|
|
1624
|
+
return p.type === 7 && p.name === "slot";
|
|
1625
|
+
}
|
|
1626
|
+
function isTemplateNode(node) {
|
|
1627
|
+
return node.type === 1 && node.tagType === 3;
|
|
1628
|
+
}
|
|
1629
|
+
function isSlotOutlet(node) {
|
|
1630
|
+
return node.type === 1 && node.tagType === 2;
|
|
1631
|
+
}
|
|
1632
|
+
const propsHelperSet = new Set([NORMALIZE_PROPS, GUARD_REACTIVE_PROPS]);
|
|
1633
|
+
function getUnnormalizedProps(props, callPath = []) {
|
|
1634
|
+
if (props && !isString(props) && props.type === 14) {
|
|
1635
|
+
const callee = props.callee;
|
|
1636
|
+
if (!isString(callee) && propsHelperSet.has(callee)) return getUnnormalizedProps(props.arguments[0], callPath.concat(props));
|
|
1637
|
+
}
|
|
1638
|
+
return [props, callPath];
|
|
1639
|
+
}
|
|
1640
|
+
function injectProp(node, prop, context) {
|
|
1641
|
+
let propsWithInjection;
|
|
1642
|
+
/**
|
|
1643
|
+
* 1. mergeProps(...)
|
|
1644
|
+
* 2. toHandlers(...)
|
|
1645
|
+
* 3. normalizeProps(...)
|
|
1646
|
+
* 4. normalizeProps(guardReactiveProps(...))
|
|
1647
|
+
*
|
|
1648
|
+
* we need to get the real props before normalization
|
|
1649
|
+
*/
|
|
1650
|
+
let props = node.type === 13 ? node.props : node.arguments[2];
|
|
1651
|
+
let callPath = [];
|
|
1652
|
+
let parentCall;
|
|
1653
|
+
if (props && !isString(props) && props.type === 14) {
|
|
1654
|
+
const ret = getUnnormalizedProps(props);
|
|
1655
|
+
props = ret[0];
|
|
1656
|
+
callPath = ret[1];
|
|
1657
|
+
parentCall = callPath[callPath.length - 1];
|
|
1658
|
+
}
|
|
1659
|
+
if (props == null || isString(props)) propsWithInjection = createObjectExpression([prop]);
|
|
1660
|
+
else if (props.type === 14) {
|
|
1661
|
+
const first = props.arguments[0];
|
|
1662
|
+
if (!isString(first) && first.type === 15) {
|
|
1663
|
+
if (!hasProp(prop, first)) first.properties.unshift(prop);
|
|
1664
|
+
} else if (props.callee === TO_HANDLERS) propsWithInjection = createCallExpression(context.helper(MERGE_PROPS), [createObjectExpression([prop]), props]);
|
|
1665
|
+
else props.arguments.unshift(createObjectExpression([prop]));
|
|
1666
|
+
!propsWithInjection && (propsWithInjection = props);
|
|
1667
|
+
} else if (props.type === 15) {
|
|
1668
|
+
if (!hasProp(prop, props)) props.properties.unshift(prop);
|
|
1669
|
+
propsWithInjection = props;
|
|
1670
|
+
} else {
|
|
1671
|
+
propsWithInjection = createCallExpression(context.helper(MERGE_PROPS), [createObjectExpression([prop]), props]);
|
|
1672
|
+
if (parentCall && parentCall.callee === GUARD_REACTIVE_PROPS) parentCall = callPath[callPath.length - 2];
|
|
1673
|
+
}
|
|
1674
|
+
if (node.type === 13) if (parentCall) parentCall.arguments[0] = propsWithInjection;
|
|
1675
|
+
else node.props = propsWithInjection;
|
|
1676
|
+
else if (parentCall) parentCall.arguments[0] = propsWithInjection;
|
|
1677
|
+
else node.arguments[2] = propsWithInjection;
|
|
1678
|
+
}
|
|
1679
|
+
function hasProp(prop, props) {
|
|
1680
|
+
let result = false;
|
|
1681
|
+
if (prop.key.type === 4) {
|
|
1682
|
+
const propKeyName = prop.key.content;
|
|
1683
|
+
result = props.properties.some((p) => p.key.type === 4 && p.key.content === propKeyName);
|
|
1684
|
+
}
|
|
1685
|
+
return result;
|
|
1686
|
+
}
|
|
1687
|
+
function toValidAssetId(name, type) {
|
|
1688
|
+
return `_${type}_${name.replace(/[^\w]/g, (searchValue, replaceValue) => {
|
|
1689
|
+
return searchValue === "-" ? "_" : name.charCodeAt(replaceValue).toString();
|
|
1690
|
+
})}`;
|
|
1691
|
+
}
|
|
1692
|
+
function hasScopeRef(node, ids) {
|
|
1693
|
+
if (!node || Object.keys(ids).length === 0) return false;
|
|
1694
|
+
switch (node.type) {
|
|
1695
|
+
case 1:
|
|
1696
|
+
for (let i = 0; i < node.props.length; i++) {
|
|
1697
|
+
const p = node.props[i];
|
|
1698
|
+
if (p.type === 7 && (hasScopeRef(p.arg, ids) || hasScopeRef(p.exp, ids))) return true;
|
|
1699
|
+
}
|
|
1700
|
+
return node.children.some((c) => hasScopeRef(c, ids));
|
|
1701
|
+
case 11:
|
|
1702
|
+
if (hasScopeRef(node.source, ids)) return true;
|
|
1703
|
+
return node.children.some((c) => hasScopeRef(c, ids));
|
|
1704
|
+
case 9: return node.branches.some((b) => hasScopeRef(b, ids));
|
|
1705
|
+
case 10:
|
|
1706
|
+
if (hasScopeRef(node.condition, ids)) return true;
|
|
1707
|
+
return node.children.some((c) => hasScopeRef(c, ids));
|
|
1708
|
+
case 4: return !node.isStatic && isSimpleIdentifier(node.content) && !!ids[node.content];
|
|
1709
|
+
case 8: return node.children.some((c) => isObject(c) && hasScopeRef(c, ids));
|
|
1710
|
+
case 5:
|
|
1711
|
+
case 12: return hasScopeRef(node.content, ids);
|
|
1712
|
+
case 2:
|
|
1713
|
+
case 3:
|
|
1714
|
+
case 20: return false;
|
|
1715
|
+
default:
|
|
1716
|
+
if (!!(process.env.NODE_ENV !== "production")) {}
|
|
1717
|
+
return false;
|
|
1718
|
+
}
|
|
1719
|
+
}
|
|
1720
|
+
function getMemoedVNodeCall(node) {
|
|
1721
|
+
if (node.type === 14 && node.callee === WITH_MEMO) return node.arguments[1].returns;
|
|
1722
|
+
else return node;
|
|
1723
|
+
}
|
|
1724
|
+
function filterNonCommentChildren(node) {
|
|
1725
|
+
return node.children.filter((n) => !isCommentOrWhitespace(n));
|
|
1726
|
+
}
|
|
1727
|
+
function hasSingleChild(node) {
|
|
1728
|
+
return filterNonCommentChildren(node).length === 1;
|
|
1729
|
+
}
|
|
1730
|
+
function isSingleIfBlock(parent) {
|
|
1731
|
+
let hasEncounteredIf = false;
|
|
1732
|
+
for (const c of filterNonCommentChildren(parent)) if (c.type === 9 || c.type === 1 && findDir(c, "if")) {
|
|
1733
|
+
if (hasEncounteredIf) return false;
|
|
1734
|
+
hasEncounteredIf = true;
|
|
1735
|
+
} else if (!hasEncounteredIf || !(c.type === 1 && findDir(c, /^else(-if)?$/, true))) return false;
|
|
1736
|
+
return true;
|
|
1737
|
+
}
|
|
1738
|
+
const forAliasRE = /([\s\S]*?)\s+(?:in|of)\s+(\S[\s\S]*)/;
|
|
1739
|
+
function isAllWhitespace(str) {
|
|
1740
|
+
for (let i = 0; i < str.length; i++) if (!isWhitespace(str.charCodeAt(i))) return false;
|
|
1741
|
+
return true;
|
|
1742
|
+
}
|
|
1743
|
+
function isWhitespaceText(node) {
|
|
1744
|
+
return node.type === 2 && isAllWhitespace(node.content) || node.type === 12 && isWhitespaceText(node.content);
|
|
1745
|
+
}
|
|
1746
|
+
function isCommentOrWhitespace(node) {
|
|
1747
|
+
return node.type === 3 || isWhitespaceText(node);
|
|
1748
|
+
}
|
|
1749
|
+
|
|
1750
|
+
//#endregion
|
|
1751
|
+
//#region packages/compiler-core/src/parser.ts
|
|
1752
|
+
const defaultParserOptions = {
|
|
1753
|
+
parseMode: "base",
|
|
1754
|
+
ns: 0,
|
|
1755
|
+
delimiters: [`{{`, `}}`],
|
|
1756
|
+
getNamespace: () => 0,
|
|
1757
|
+
isVoidTag: NO,
|
|
1758
|
+
isPreTag: NO,
|
|
1759
|
+
isIgnoreNewlineTag: NO,
|
|
1760
|
+
isCustomElement: NO,
|
|
1761
|
+
onError: defaultOnError,
|
|
1762
|
+
onWarn: defaultOnWarn,
|
|
1763
|
+
comments: !!(process.env.NODE_ENV !== "production"),
|
|
1764
|
+
prefixIdentifiers: false
|
|
1765
|
+
};
|
|
1766
|
+
let currentOptions = defaultParserOptions;
|
|
1767
|
+
let currentRoot = null;
|
|
1768
|
+
let currentInput = "";
|
|
1769
|
+
let currentOpenTag = null;
|
|
1770
|
+
let currentProp = null;
|
|
1771
|
+
let currentAttrValue = "";
|
|
1772
|
+
let currentAttrStartIndex = -1;
|
|
1773
|
+
let currentAttrEndIndex = -1;
|
|
1774
|
+
let inPre = 0;
|
|
1775
|
+
let inVPre = false;
|
|
1776
|
+
let currentVPreBoundary = null;
|
|
1777
|
+
const stack = [];
|
|
1778
|
+
const tokenizer = new Tokenizer(stack, {
|
|
1779
|
+
onerr: emitError,
|
|
1780
|
+
ontext(start, end) {
|
|
1781
|
+
onText(getSlice(start, end), start, end);
|
|
1782
|
+
},
|
|
1783
|
+
ontextentity(char, start, end) {
|
|
1784
|
+
onText(char, start, end);
|
|
1785
|
+
},
|
|
1786
|
+
oninterpolation(start, end) {
|
|
1787
|
+
if (inVPre) return onText(getSlice(start, end), start, end);
|
|
1788
|
+
let innerStart = start + tokenizer.delimiterOpen.length;
|
|
1789
|
+
let innerEnd = end - tokenizer.delimiterClose.length;
|
|
1790
|
+
while (isWhitespace(currentInput.charCodeAt(innerStart))) innerStart++;
|
|
1791
|
+
while (isWhitespace(currentInput.charCodeAt(innerEnd - 1))) innerEnd--;
|
|
1792
|
+
let exp = getSlice(innerStart, innerEnd);
|
|
1793
|
+
if (exp.includes("&")) exp = currentOptions.decodeEntities(exp, false);
|
|
1794
|
+
addNode({
|
|
1795
|
+
type: 5,
|
|
1796
|
+
content: createExp(exp, false, getLoc(innerStart, innerEnd)),
|
|
1797
|
+
loc: getLoc(start, end)
|
|
1798
|
+
});
|
|
1799
|
+
},
|
|
1800
|
+
onopentagname(start, end) {
|
|
1801
|
+
const name = getSlice(start, end);
|
|
1802
|
+
currentOpenTag = {
|
|
1803
|
+
type: 1,
|
|
1804
|
+
tag: name,
|
|
1805
|
+
ns: currentOptions.getNamespace(name, stack[0], currentOptions.ns),
|
|
1806
|
+
tagType: 0,
|
|
1807
|
+
props: [],
|
|
1808
|
+
children: [],
|
|
1809
|
+
loc: getLoc(start - 1, end),
|
|
1810
|
+
codegenNode: void 0
|
|
1811
|
+
};
|
|
1812
|
+
},
|
|
1813
|
+
onopentagend(end) {
|
|
1814
|
+
endOpenTag(end);
|
|
1815
|
+
},
|
|
1816
|
+
onclosetag(start, end) {
|
|
1817
|
+
const name = getSlice(start, end);
|
|
1818
|
+
if (!currentOptions.isVoidTag(name)) {
|
|
1819
|
+
let found = false;
|
|
1820
|
+
for (let i = 0; i < stack.length; i++) if (stack[i].tag.toLowerCase() === name.toLowerCase()) {
|
|
1821
|
+
found = true;
|
|
1822
|
+
if (i > 0) emitError(24, stack[0].loc.start.offset);
|
|
1823
|
+
for (let j = 0; j <= i; j++) onCloseTag(stack.shift(), end, j < i);
|
|
1824
|
+
break;
|
|
1825
|
+
}
|
|
1826
|
+
if (!found) emitError(23, backTrack(start, 60));
|
|
1827
|
+
}
|
|
1828
|
+
},
|
|
1829
|
+
onselfclosingtag(end) {
|
|
1830
|
+
const name = currentOpenTag.tag;
|
|
1831
|
+
currentOpenTag.isSelfClosing = true;
|
|
1832
|
+
endOpenTag(end);
|
|
1833
|
+
if (stack[0] && stack[0].tag === name) onCloseTag(stack.shift(), end);
|
|
1834
|
+
},
|
|
1835
|
+
onattribname(start, end) {
|
|
1836
|
+
currentProp = {
|
|
1837
|
+
type: 6,
|
|
1838
|
+
name: getSlice(start, end),
|
|
1839
|
+
nameLoc: getLoc(start, end),
|
|
1840
|
+
value: void 0,
|
|
1841
|
+
loc: getLoc(start)
|
|
1842
|
+
};
|
|
1843
|
+
},
|
|
1844
|
+
ondirname(start, end) {
|
|
1845
|
+
const raw = getSlice(start, end);
|
|
1846
|
+
const name = raw === "." || raw === ":" ? "bind" : raw === "@" ? "on" : raw === "#" ? "slot" : raw.slice(2);
|
|
1847
|
+
if (!inVPre && name === "") emitError(26, start);
|
|
1848
|
+
if (inVPre || name === "") currentProp = {
|
|
1849
|
+
type: 6,
|
|
1850
|
+
name: raw,
|
|
1851
|
+
nameLoc: getLoc(start, end),
|
|
1852
|
+
value: void 0,
|
|
1853
|
+
loc: getLoc(start)
|
|
1854
|
+
};
|
|
1855
|
+
else {
|
|
1856
|
+
currentProp = {
|
|
1857
|
+
type: 7,
|
|
1858
|
+
name,
|
|
1859
|
+
rawName: raw,
|
|
1860
|
+
exp: void 0,
|
|
1861
|
+
arg: void 0,
|
|
1862
|
+
modifiers: raw === "." ? [createSimpleExpression("prop")] : [],
|
|
1863
|
+
loc: getLoc(start)
|
|
1864
|
+
};
|
|
1865
|
+
if (name === "pre") {
|
|
1866
|
+
inVPre = tokenizer.inVPre = true;
|
|
1867
|
+
currentVPreBoundary = currentOpenTag;
|
|
1868
|
+
const props = currentOpenTag.props;
|
|
1869
|
+
for (let i = 0; i < props.length; i++) if (props[i].type === 7) props[i] = dirToAttr(props[i]);
|
|
1870
|
+
}
|
|
1871
|
+
}
|
|
1872
|
+
},
|
|
1873
|
+
ondirarg(start, end) {
|
|
1874
|
+
if (start === end) return;
|
|
1875
|
+
const arg = getSlice(start, end);
|
|
1876
|
+
if (inVPre && !isVPre(currentProp)) {
|
|
1877
|
+
currentProp.name += arg;
|
|
1878
|
+
setLocEnd(currentProp.nameLoc, end);
|
|
1879
|
+
} else {
|
|
1880
|
+
const isStatic = arg[0] !== `[`;
|
|
1881
|
+
currentProp.arg = createExp(isStatic ? arg : arg.slice(1, -1), isStatic, getLoc(start, end), isStatic ? 3 : 0);
|
|
1882
|
+
}
|
|
1883
|
+
},
|
|
1884
|
+
ondirmodifier(start, end) {
|
|
1885
|
+
const mod = getSlice(start, end);
|
|
1886
|
+
if (inVPre && !isVPre(currentProp)) {
|
|
1887
|
+
currentProp.name += "." + mod;
|
|
1888
|
+
setLocEnd(currentProp.nameLoc, end);
|
|
1889
|
+
} else if (currentProp.name === "slot") {
|
|
1890
|
+
const arg = currentProp.arg;
|
|
1891
|
+
if (arg) {
|
|
1892
|
+
arg.content += "." + mod;
|
|
1893
|
+
setLocEnd(arg.loc, end);
|
|
1894
|
+
}
|
|
1895
|
+
} else {
|
|
1896
|
+
const exp = createSimpleExpression(mod, true, getLoc(start, end));
|
|
1897
|
+
currentProp.modifiers.push(exp);
|
|
1898
|
+
}
|
|
1899
|
+
},
|
|
1900
|
+
onattribdata(start, end) {
|
|
1901
|
+
currentAttrValue += getSlice(start, end);
|
|
1902
|
+
if (currentAttrStartIndex < 0) currentAttrStartIndex = start;
|
|
1903
|
+
currentAttrEndIndex = end;
|
|
1904
|
+
},
|
|
1905
|
+
onattribentity(char, start, end) {
|
|
1906
|
+
currentAttrValue += char;
|
|
1907
|
+
if (currentAttrStartIndex < 0) currentAttrStartIndex = start;
|
|
1908
|
+
currentAttrEndIndex = end;
|
|
1909
|
+
},
|
|
1910
|
+
onattribnameend(end) {
|
|
1911
|
+
const start = currentProp.loc.start.offset;
|
|
1912
|
+
const name = getSlice(start, end);
|
|
1913
|
+
if (currentProp.type === 7) currentProp.rawName = name;
|
|
1914
|
+
if (currentOpenTag.props.some((p) => (p.type === 7 ? p.rawName : p.name) === name)) emitError(2, start);
|
|
1915
|
+
},
|
|
1916
|
+
onattribend(quote, end) {
|
|
1917
|
+
if (currentOpenTag && currentProp) {
|
|
1918
|
+
setLocEnd(currentProp.loc, end);
|
|
1919
|
+
if (quote !== 0) {
|
|
1920
|
+
if (currentAttrValue.includes("&")) currentAttrValue = currentOptions.decodeEntities(currentAttrValue, true);
|
|
1921
|
+
if (currentProp.type === 6) {
|
|
1922
|
+
if (currentProp.name === "class") currentAttrValue = condense(currentAttrValue).trim();
|
|
1923
|
+
if (quote === 1 && !currentAttrValue) emitError(13, end);
|
|
1924
|
+
currentProp.value = {
|
|
1925
|
+
type: 2,
|
|
1926
|
+
content: currentAttrValue,
|
|
1927
|
+
loc: quote === 1 ? getLoc(currentAttrStartIndex, currentAttrEndIndex) : getLoc(currentAttrStartIndex - 1, currentAttrEndIndex + 1)
|
|
1928
|
+
};
|
|
1929
|
+
if (tokenizer.inSFCRoot && currentOpenTag.tag === "template" && currentProp.name === "lang" && currentAttrValue && currentAttrValue !== "html") tokenizer.enterRCDATA(toCharCodes(`</template`), 0);
|
|
1930
|
+
} else {
|
|
1931
|
+
let expParseMode = ExpParseMode.Normal;
|
|
1932
|
+
currentProp.exp = createExp(currentAttrValue, false, getLoc(currentAttrStartIndex, currentAttrEndIndex), 0, expParseMode);
|
|
1933
|
+
if (currentProp.name === "for") currentProp.forParseResult = parseForExpression(currentProp.exp);
|
|
1934
|
+
let syncIndex = -1;
|
|
1935
|
+
if (currentProp.name === "bind" && (syncIndex = currentProp.modifiers.findIndex((mod) => mod.content === "sync")) > -1 && checkCompatEnabled("COMPILER_V_BIND_SYNC", currentOptions, currentProp.loc, currentProp.arg.loc.source)) {
|
|
1936
|
+
currentProp.name = "model";
|
|
1937
|
+
currentProp.modifiers.splice(syncIndex, 1);
|
|
1938
|
+
}
|
|
1939
|
+
}
|
|
1940
|
+
}
|
|
1941
|
+
if (currentProp.type !== 7 || currentProp.name !== "pre") currentOpenTag.props.push(currentProp);
|
|
1942
|
+
}
|
|
1943
|
+
currentAttrValue = "";
|
|
1944
|
+
currentAttrStartIndex = currentAttrEndIndex = -1;
|
|
1945
|
+
},
|
|
1946
|
+
oncomment(start, end) {
|
|
1947
|
+
if (currentOptions.comments) addNode({
|
|
1948
|
+
type: 3,
|
|
1949
|
+
content: getSlice(start, end),
|
|
1950
|
+
loc: getLoc(start - 4, end + 3)
|
|
1951
|
+
});
|
|
1952
|
+
},
|
|
1953
|
+
onend() {
|
|
1954
|
+
const end = currentInput.length;
|
|
1955
|
+
if ((!!(process.env.NODE_ENV !== "production") || false) && tokenizer.state !== 1) switch (tokenizer.state) {
|
|
1956
|
+
case 5:
|
|
1957
|
+
case 8:
|
|
1958
|
+
emitError(5, end);
|
|
1959
|
+
break;
|
|
1960
|
+
case 3:
|
|
1961
|
+
case 4:
|
|
1962
|
+
emitError(25, tokenizer.sectionStart);
|
|
1963
|
+
break;
|
|
1964
|
+
case 28:
|
|
1965
|
+
if (tokenizer.currentSequence === Sequences.CdataEnd) emitError(6, end);
|
|
1966
|
+
else emitError(7, end);
|
|
1967
|
+
break;
|
|
1968
|
+
case 6:
|
|
1969
|
+
case 7:
|
|
1970
|
+
case 9:
|
|
1971
|
+
case 11:
|
|
1972
|
+
case 12:
|
|
1973
|
+
case 13:
|
|
1974
|
+
case 14:
|
|
1975
|
+
case 15:
|
|
1976
|
+
case 16:
|
|
1977
|
+
case 17:
|
|
1978
|
+
case 18:
|
|
1979
|
+
case 19:
|
|
1980
|
+
case 20:
|
|
1981
|
+
case 21:
|
|
1982
|
+
emitError(9, end);
|
|
1983
|
+
break;
|
|
1984
|
+
default: break;
|
|
1985
|
+
}
|
|
1986
|
+
for (let index = 0; index < stack.length; index++) {
|
|
1987
|
+
onCloseTag(stack[index], end - 1);
|
|
1988
|
+
emitError(24, stack[index].loc.start.offset);
|
|
1989
|
+
}
|
|
1990
|
+
},
|
|
1991
|
+
oncdata(start, end) {
|
|
1992
|
+
if (stack[0].ns !== 0) onText(getSlice(start, end), start, end);
|
|
1993
|
+
else emitError(1, start - 9);
|
|
1994
|
+
},
|
|
1995
|
+
onprocessinginstruction(start) {
|
|
1996
|
+
if ((stack[0] ? stack[0].ns : currentOptions.ns) === 0) emitError(21, start - 1);
|
|
1997
|
+
}
|
|
1998
|
+
});
|
|
1999
|
+
const forIteratorRE = /,([^,\}\]]*)(?:,([^,\}\]]*))?$/;
|
|
2000
|
+
const stripParensRE = /^\(|\)$/g;
|
|
2001
|
+
function parseForExpression(input) {
|
|
2002
|
+
const loc = input.loc;
|
|
2003
|
+
const exp = input.content;
|
|
2004
|
+
const inMatch = exp.match(forAliasRE);
|
|
2005
|
+
if (!inMatch) return;
|
|
2006
|
+
const [, LHS, RHS] = inMatch;
|
|
2007
|
+
const createAliasExpression = (content, offset, asParam = false) => {
|
|
2008
|
+
const start = loc.start.offset + offset;
|
|
2009
|
+
return createExp(content, false, getLoc(start, start + content.length), 0, asParam ? ExpParseMode.Params : ExpParseMode.Normal);
|
|
2010
|
+
};
|
|
2011
|
+
const result = {
|
|
2012
|
+
source: createAliasExpression(RHS.trim(), exp.indexOf(RHS, LHS.length)),
|
|
2013
|
+
value: void 0,
|
|
2014
|
+
key: void 0,
|
|
2015
|
+
index: void 0,
|
|
2016
|
+
finalized: false
|
|
2017
|
+
};
|
|
2018
|
+
let valueContent = LHS.trim().replace(stripParensRE, "").trim();
|
|
2019
|
+
const trimmedOffset = LHS.indexOf(valueContent);
|
|
2020
|
+
const iteratorMatch = valueContent.match(forIteratorRE);
|
|
2021
|
+
if (iteratorMatch) {
|
|
2022
|
+
valueContent = valueContent.replace(forIteratorRE, "").trim();
|
|
2023
|
+
const keyContent = iteratorMatch[1].trim();
|
|
2024
|
+
let keyOffset;
|
|
2025
|
+
if (keyContent) {
|
|
2026
|
+
keyOffset = exp.indexOf(keyContent, trimmedOffset + valueContent.length);
|
|
2027
|
+
result.key = createAliasExpression(keyContent, keyOffset, true);
|
|
2028
|
+
}
|
|
2029
|
+
if (iteratorMatch[2]) {
|
|
2030
|
+
const indexContent = iteratorMatch[2].trim();
|
|
2031
|
+
if (indexContent) result.index = createAliasExpression(indexContent, exp.indexOf(indexContent, result.key ? keyOffset + keyContent.length : trimmedOffset + valueContent.length), true);
|
|
2032
|
+
}
|
|
2033
|
+
}
|
|
2034
|
+
if (valueContent) result.value = createAliasExpression(valueContent, trimmedOffset, true);
|
|
2035
|
+
return result;
|
|
2036
|
+
}
|
|
2037
|
+
function getSlice(start, end) {
|
|
2038
|
+
return currentInput.slice(start, end);
|
|
2039
|
+
}
|
|
2040
|
+
function endOpenTag(end) {
|
|
2041
|
+
if (tokenizer.inSFCRoot) currentOpenTag.innerLoc = getLoc(end + 1, end + 1);
|
|
2042
|
+
addNode(currentOpenTag);
|
|
2043
|
+
const { tag, ns } = currentOpenTag;
|
|
2044
|
+
if (ns === 0 && currentOptions.isPreTag(tag)) inPre++;
|
|
2045
|
+
if (currentOptions.isVoidTag(tag)) onCloseTag(currentOpenTag, end);
|
|
2046
|
+
else {
|
|
2047
|
+
stack.unshift(currentOpenTag);
|
|
2048
|
+
if (ns === 1 || ns === 2) tokenizer.inXML = true;
|
|
2049
|
+
}
|
|
2050
|
+
currentOpenTag = null;
|
|
2051
|
+
}
|
|
2052
|
+
function onText(content, start, end) {
|
|
2053
|
+
{
|
|
2054
|
+
const tag = stack[0] && stack[0].tag;
|
|
2055
|
+
if (tag !== "script" && tag !== "style" && content.includes("&")) content = currentOptions.decodeEntities(content, false);
|
|
2056
|
+
}
|
|
2057
|
+
const parent = stack[0] || currentRoot;
|
|
2058
|
+
const lastNode = parent.children[parent.children.length - 1];
|
|
2059
|
+
if (lastNode && lastNode.type === 2) {
|
|
2060
|
+
lastNode.content += content;
|
|
2061
|
+
setLocEnd(lastNode.loc, end);
|
|
2062
|
+
} else parent.children.push({
|
|
2063
|
+
type: 2,
|
|
2064
|
+
content,
|
|
2065
|
+
loc: getLoc(start, end)
|
|
2066
|
+
});
|
|
2067
|
+
}
|
|
2068
|
+
function onCloseTag(el, end, isImplied = false) {
|
|
2069
|
+
if (isImplied) setLocEnd(el.loc, backTrack(end, 60));
|
|
2070
|
+
else setLocEnd(el.loc, lookAhead(end, 62) + 1);
|
|
2071
|
+
if (tokenizer.inSFCRoot) {
|
|
2072
|
+
if (el.children.length) el.innerLoc.end = extend({}, el.children[el.children.length - 1].loc.end);
|
|
2073
|
+
else el.innerLoc.end = extend({}, el.innerLoc.start);
|
|
2074
|
+
el.innerLoc.source = getSlice(el.innerLoc.start.offset, el.innerLoc.end.offset);
|
|
2075
|
+
}
|
|
2076
|
+
const { tag, ns, children } = el;
|
|
2077
|
+
if (!inVPre) {
|
|
2078
|
+
if (tag === "slot") el.tagType = 2;
|
|
2079
|
+
else if (isFragmentTemplate(el)) el.tagType = 3;
|
|
2080
|
+
else if (isComponent(el)) el.tagType = 1;
|
|
2081
|
+
}
|
|
2082
|
+
if (!tokenizer.inRCDATA) el.children = condenseWhitespace(children);
|
|
2083
|
+
if (ns === 0 && currentOptions.isIgnoreNewlineTag(tag)) {
|
|
2084
|
+
const first = children[0];
|
|
2085
|
+
if (first && first.type === 2) first.content = first.content.replace(/^\r?\n/, "");
|
|
2086
|
+
}
|
|
2087
|
+
if (ns === 0 && currentOptions.isPreTag(tag)) inPre--;
|
|
2088
|
+
if (currentVPreBoundary === el) {
|
|
2089
|
+
inVPre = tokenizer.inVPre = false;
|
|
2090
|
+
currentVPreBoundary = null;
|
|
2091
|
+
}
|
|
2092
|
+
if (tokenizer.inXML && (stack[0] ? stack[0].ns : currentOptions.ns) === 0) tokenizer.inXML = false;
|
|
2093
|
+
{
|
|
2094
|
+
const props = el.props;
|
|
2095
|
+
if (!!(process.env.NODE_ENV !== "production") && isCompatEnabled("COMPILER_V_IF_V_FOR_PRECEDENCE", currentOptions)) {
|
|
2096
|
+
let hasIf = false;
|
|
2097
|
+
let hasFor = false;
|
|
2098
|
+
for (let i = 0; i < props.length; i++) {
|
|
2099
|
+
const p = props[i];
|
|
2100
|
+
if (p.type === 7) {
|
|
2101
|
+
if (p.name === "if") hasIf = true;
|
|
2102
|
+
else if (p.name === "for") hasFor = true;
|
|
2103
|
+
}
|
|
2104
|
+
if (hasIf && hasFor) {
|
|
2105
|
+
warnDeprecation("COMPILER_V_IF_V_FOR_PRECEDENCE", currentOptions, el.loc);
|
|
2106
|
+
break;
|
|
2107
|
+
}
|
|
2108
|
+
}
|
|
2109
|
+
}
|
|
2110
|
+
if (!tokenizer.inSFCRoot && isCompatEnabled("COMPILER_NATIVE_TEMPLATE", currentOptions) && el.tag === "template" && !isFragmentTemplate(el)) {
|
|
2111
|
+
process.env.NODE_ENV !== "production" && warnDeprecation("COMPILER_NATIVE_TEMPLATE", currentOptions, el.loc);
|
|
2112
|
+
const parent = stack[0] || currentRoot;
|
|
2113
|
+
const index = parent.children.indexOf(el);
|
|
2114
|
+
parent.children.splice(index, 1, ...el.children);
|
|
2115
|
+
}
|
|
2116
|
+
const inlineTemplateProp = props.find((p) => p.type === 6 && p.name === "inline-template");
|
|
2117
|
+
if (inlineTemplateProp && checkCompatEnabled("COMPILER_INLINE_TEMPLATE", currentOptions, inlineTemplateProp.loc) && el.children.length) inlineTemplateProp.value = {
|
|
2118
|
+
type: 2,
|
|
2119
|
+
content: getSlice(el.children[0].loc.start.offset, el.children[el.children.length - 1].loc.end.offset),
|
|
2120
|
+
loc: inlineTemplateProp.loc
|
|
2121
|
+
};
|
|
2122
|
+
}
|
|
2123
|
+
}
|
|
2124
|
+
function lookAhead(index, c) {
|
|
2125
|
+
let i = index;
|
|
2126
|
+
while (currentInput.charCodeAt(i) !== c && i < currentInput.length - 1) i++;
|
|
2127
|
+
return i;
|
|
2128
|
+
}
|
|
2129
|
+
function backTrack(index, c) {
|
|
2130
|
+
let i = index;
|
|
2131
|
+
while (currentInput.charCodeAt(i) !== c && i >= 0) i--;
|
|
2132
|
+
return i;
|
|
2133
|
+
}
|
|
2134
|
+
const specialTemplateDir = new Set([
|
|
2135
|
+
"if",
|
|
2136
|
+
"else",
|
|
2137
|
+
"else-if",
|
|
2138
|
+
"for",
|
|
2139
|
+
"slot"
|
|
2140
|
+
]);
|
|
2141
|
+
function isFragmentTemplate({ tag, props }) {
|
|
2142
|
+
if (tag === "template") {
|
|
2143
|
+
for (let i = 0; i < props.length; i++) if (props[i].type === 7 && specialTemplateDir.has(props[i].name)) return true;
|
|
2144
|
+
}
|
|
2145
|
+
return false;
|
|
2146
|
+
}
|
|
2147
|
+
function isComponent({ tag, props }) {
|
|
2148
|
+
if (currentOptions.isCustomElement(tag)) return false;
|
|
2149
|
+
if (tag === "component" || isUpperCase(tag.charCodeAt(0)) || isCoreComponent(tag) || currentOptions.isBuiltInComponent && currentOptions.isBuiltInComponent(tag) || currentOptions.isNativeTag && !currentOptions.isNativeTag(tag)) return true;
|
|
2150
|
+
for (let i = 0; i < props.length; i++) {
|
|
2151
|
+
const p = props[i];
|
|
2152
|
+
if (p.type === 6) {
|
|
2153
|
+
if (p.name === "is" && p.value) {
|
|
2154
|
+
if (p.value.content.startsWith("vue:")) return true;
|
|
2155
|
+
else if (checkCompatEnabled("COMPILER_IS_ON_ELEMENT", currentOptions, p.loc)) return true;
|
|
2156
|
+
}
|
|
2157
|
+
} else if (p.name === "bind" && isStaticArgOf(p.arg, "is") && checkCompatEnabled("COMPILER_IS_ON_ELEMENT", currentOptions, p.loc)) return true;
|
|
2158
|
+
}
|
|
2159
|
+
return false;
|
|
2160
|
+
}
|
|
2161
|
+
function isUpperCase(c) {
|
|
2162
|
+
return c > 64 && c < 91;
|
|
2163
|
+
}
|
|
2164
|
+
const windowsNewlineRE = /\r\n/g;
|
|
2165
|
+
function condenseWhitespace(nodes) {
|
|
2166
|
+
const shouldCondense = currentOptions.whitespace !== "preserve";
|
|
2167
|
+
let removedWhitespace = false;
|
|
2168
|
+
for (let i = 0; i < nodes.length; i++) {
|
|
2169
|
+
const node = nodes[i];
|
|
2170
|
+
if (node.type === 2) if (!inPre) {
|
|
2171
|
+
if (isAllWhitespace(node.content)) {
|
|
2172
|
+
const prev = nodes[i - 1] && nodes[i - 1].type;
|
|
2173
|
+
const next = nodes[i + 1] && nodes[i + 1].type;
|
|
2174
|
+
if (!prev || !next || shouldCondense && (prev === 3 && (next === 3 || next === 1) || prev === 1 && (next === 3 || next === 1 && hasNewlineChar(node.content)))) {
|
|
2175
|
+
removedWhitespace = true;
|
|
2176
|
+
nodes[i] = null;
|
|
2177
|
+
} else node.content = " ";
|
|
2178
|
+
} else if (shouldCondense) node.content = condense(node.content);
|
|
2179
|
+
} else node.content = node.content.replace(windowsNewlineRE, "\n");
|
|
2180
|
+
}
|
|
2181
|
+
return removedWhitespace ? nodes.filter(Boolean) : nodes;
|
|
2182
|
+
}
|
|
2183
|
+
function hasNewlineChar(str) {
|
|
2184
|
+
for (let i = 0; i < str.length; i++) {
|
|
2185
|
+
const c = str.charCodeAt(i);
|
|
2186
|
+
if (c === 10 || c === 13) return true;
|
|
2187
|
+
}
|
|
2188
|
+
return false;
|
|
2189
|
+
}
|
|
2190
|
+
function condense(str) {
|
|
2191
|
+
let ret = "";
|
|
2192
|
+
let prevCharIsWhitespace = false;
|
|
2193
|
+
for (let i = 0; i < str.length; i++) if (isWhitespace(str.charCodeAt(i))) {
|
|
2194
|
+
if (!prevCharIsWhitespace) {
|
|
2195
|
+
ret += " ";
|
|
2196
|
+
prevCharIsWhitespace = true;
|
|
2197
|
+
}
|
|
2198
|
+
} else {
|
|
2199
|
+
ret += str[i];
|
|
2200
|
+
prevCharIsWhitespace = false;
|
|
2201
|
+
}
|
|
2202
|
+
return ret;
|
|
2203
|
+
}
|
|
2204
|
+
function addNode(node) {
|
|
2205
|
+
(stack[0] || currentRoot).children.push(node);
|
|
2206
|
+
}
|
|
2207
|
+
function getLoc(start, end) {
|
|
2208
|
+
return {
|
|
2209
|
+
start: tokenizer.getPos(start),
|
|
2210
|
+
end: end == null ? end : tokenizer.getPos(end),
|
|
2211
|
+
source: end == null ? end : getSlice(start, end)
|
|
2212
|
+
};
|
|
2213
|
+
}
|
|
2214
|
+
function cloneLoc(loc) {
|
|
2215
|
+
return getLoc(loc.start.offset, loc.end.offset);
|
|
2216
|
+
}
|
|
2217
|
+
function setLocEnd(loc, end) {
|
|
2218
|
+
loc.end = tokenizer.getPos(end);
|
|
2219
|
+
loc.source = getSlice(loc.start.offset, end);
|
|
2220
|
+
}
|
|
2221
|
+
function dirToAttr(dir) {
|
|
2222
|
+
const attr = {
|
|
2223
|
+
type: 6,
|
|
2224
|
+
name: dir.rawName,
|
|
2225
|
+
nameLoc: getLoc(dir.loc.start.offset, dir.loc.start.offset + dir.rawName.length),
|
|
2226
|
+
value: void 0,
|
|
2227
|
+
loc: dir.loc
|
|
2228
|
+
};
|
|
2229
|
+
if (dir.exp) {
|
|
2230
|
+
const loc = dir.exp.loc;
|
|
2231
|
+
if (loc.end.offset < dir.loc.end.offset) {
|
|
2232
|
+
loc.start.offset--;
|
|
2233
|
+
loc.start.column--;
|
|
2234
|
+
loc.end.offset++;
|
|
2235
|
+
loc.end.column++;
|
|
2236
|
+
}
|
|
2237
|
+
attr.value = {
|
|
2238
|
+
type: 2,
|
|
2239
|
+
content: dir.exp.content,
|
|
2240
|
+
loc
|
|
2241
|
+
};
|
|
2242
|
+
}
|
|
2243
|
+
return attr;
|
|
2244
|
+
}
|
|
2245
|
+
var ExpParseMode = /* @__PURE__ */ function(ExpParseMode) {
|
|
2246
|
+
ExpParseMode[ExpParseMode["Normal"] = 0] = "Normal";
|
|
2247
|
+
ExpParseMode[ExpParseMode["Params"] = 1] = "Params";
|
|
2248
|
+
ExpParseMode[ExpParseMode["Statements"] = 2] = "Statements";
|
|
2249
|
+
ExpParseMode[ExpParseMode["Skip"] = 3] = "Skip";
|
|
2250
|
+
return ExpParseMode;
|
|
2251
|
+
}(ExpParseMode || {});
|
|
2252
|
+
function createExp(content, isStatic = false, loc, constType = 0, parseMode = ExpParseMode.Normal) {
|
|
2253
|
+
return createSimpleExpression(content, isStatic, loc, constType);
|
|
2254
|
+
}
|
|
2255
|
+
function emitError(code, index, message) {
|
|
2256
|
+
currentOptions.onError(createCompilerError(code, getLoc(index, index), void 0, message));
|
|
2257
|
+
}
|
|
2258
|
+
function reset() {
|
|
2259
|
+
tokenizer.reset();
|
|
2260
|
+
currentOpenTag = null;
|
|
2261
|
+
currentProp = null;
|
|
2262
|
+
currentAttrValue = "";
|
|
2263
|
+
currentAttrStartIndex = -1;
|
|
2264
|
+
currentAttrEndIndex = -1;
|
|
2265
|
+
stack.length = 0;
|
|
2266
|
+
}
|
|
2267
|
+
function baseParse(input, options) {
|
|
2268
|
+
reset();
|
|
2269
|
+
currentInput = input;
|
|
2270
|
+
currentOptions = extend({}, defaultParserOptions);
|
|
2271
|
+
if (options) {
|
|
2272
|
+
let key;
|
|
2273
|
+
for (key in options) if (options[key] != null) currentOptions[key] = options[key];
|
|
2274
|
+
}
|
|
2275
|
+
if (!!(process.env.NODE_ENV !== "production")) {
|
|
2276
|
+
if (!currentOptions.decodeEntities) throw new Error(`[@vue/compiler-core] decodeEntities option is required in browser builds.`);
|
|
2277
|
+
}
|
|
2278
|
+
tokenizer.mode = currentOptions.parseMode === "html" ? 1 : currentOptions.parseMode === "sfc" ? 2 : 0;
|
|
2279
|
+
tokenizer.inXML = currentOptions.ns === 1 || currentOptions.ns === 2;
|
|
2280
|
+
const delimiters = options && options.delimiters;
|
|
2281
|
+
if (delimiters) {
|
|
2282
|
+
tokenizer.delimiterOpen = toCharCodes(delimiters[0]);
|
|
2283
|
+
tokenizer.delimiterClose = toCharCodes(delimiters[1]);
|
|
2284
|
+
}
|
|
2285
|
+
const root = currentRoot = createRoot([], input);
|
|
2286
|
+
tokenizer.parse(currentInput);
|
|
2287
|
+
root.loc = getLoc(0, input.length);
|
|
2288
|
+
root.children = condenseWhitespace(root.children);
|
|
2289
|
+
currentRoot = null;
|
|
2290
|
+
return root;
|
|
2291
|
+
}
|
|
2292
|
+
|
|
2293
|
+
//#endregion
|
|
2294
|
+
//#region packages/compiler-core/src/transforms/cacheStatic.ts
|
|
2295
|
+
function cacheStatic(root, context) {
|
|
2296
|
+
walk(root, void 0, context, !!getSingleElementRoot(root));
|
|
2297
|
+
}
|
|
2298
|
+
function getSingleElementRoot(root) {
|
|
2299
|
+
const children = root.children.filter((x) => x.type !== 3);
|
|
2300
|
+
return children.length === 1 && children[0].type === 1 && !isSlotOutlet(children[0]) ? children[0] : null;
|
|
2301
|
+
}
|
|
2302
|
+
function walk(node, parent, context, doNotHoistNode = false, inFor = false) {
|
|
2303
|
+
const { children } = node;
|
|
2304
|
+
const toCache = [];
|
|
2305
|
+
for (let i = 0; i < children.length; i++) {
|
|
2306
|
+
const child = children[i];
|
|
2307
|
+
if (child.type === 1 && child.tagType === 0) {
|
|
2308
|
+
const constantType = doNotHoistNode ? 0 : getConstantType(child, context);
|
|
2309
|
+
if (constantType > 0) {
|
|
2310
|
+
if (constantType >= 2) {
|
|
2311
|
+
child.codegenNode.patchFlag = -1;
|
|
2312
|
+
toCache.push(child);
|
|
2313
|
+
continue;
|
|
2314
|
+
}
|
|
2315
|
+
} else {
|
|
2316
|
+
const codegenNode = child.codegenNode;
|
|
2317
|
+
if (codegenNode.type === 13) {
|
|
2318
|
+
const flag = codegenNode.patchFlag;
|
|
2319
|
+
if ((flag === void 0 || flag === 512 || flag === 1) && getGeneratedPropsConstantType(child, context) >= 2) {
|
|
2320
|
+
const props = getNodeProps(child);
|
|
2321
|
+
if (props) codegenNode.props = context.hoist(props);
|
|
2322
|
+
}
|
|
2323
|
+
if (codegenNode.dynamicProps) codegenNode.dynamicProps = context.hoist(codegenNode.dynamicProps);
|
|
2324
|
+
}
|
|
2325
|
+
}
|
|
2326
|
+
} else if (child.type === 12) {
|
|
2327
|
+
if ((doNotHoistNode ? 0 : getConstantType(child, context)) >= 2) {
|
|
2328
|
+
if (child.codegenNode.type === 14 && child.codegenNode.arguments.length > 0) child.codegenNode.arguments.push(-1 + (!!(process.env.NODE_ENV !== "production") ? ` /* ${PatchFlagNames[-1]} */` : ``));
|
|
2329
|
+
toCache.push(child);
|
|
2330
|
+
continue;
|
|
2331
|
+
}
|
|
2332
|
+
}
|
|
2333
|
+
if (child.type === 1) {
|
|
2334
|
+
const isComponent = child.tagType === 1;
|
|
2335
|
+
if (isComponent) context.scopes.vSlot++;
|
|
2336
|
+
walk(child, node, context, false, inFor);
|
|
2337
|
+
if (isComponent) context.scopes.vSlot--;
|
|
2338
|
+
} else if (child.type === 11) walk(child, node, context, child.children.length === 1, true);
|
|
2339
|
+
else if (child.type === 9) for (let i = 0; i < child.branches.length; i++) walk(child.branches[i], node, context, child.branches[i].children.length === 1, inFor);
|
|
2340
|
+
}
|
|
2341
|
+
let cachedAsArray = false;
|
|
2342
|
+
if (toCache.length === children.length && node.type === 1) {
|
|
2343
|
+
if (node.tagType === 0 && node.codegenNode && node.codegenNode.type === 13 && isArray(node.codegenNode.children)) {
|
|
2344
|
+
node.codegenNode.children = getCacheExpression(createArrayExpression(node.codegenNode.children));
|
|
2345
|
+
cachedAsArray = true;
|
|
2346
|
+
} else if (node.tagType === 1 && node.codegenNode && node.codegenNode.type === 13 && node.codegenNode.children && !isArray(node.codegenNode.children) && node.codegenNode.children.type === 15) {
|
|
2347
|
+
const slot = getSlotNode(node.codegenNode, "default");
|
|
2348
|
+
if (slot) {
|
|
2349
|
+
slot.returns = getCacheExpression(createArrayExpression(slot.returns));
|
|
2350
|
+
cachedAsArray = true;
|
|
2351
|
+
}
|
|
2352
|
+
} else if (node.tagType === 3 && parent && parent.type === 1 && parent.tagType === 1 && parent.codegenNode && parent.codegenNode.type === 13 && parent.codegenNode.children && !isArray(parent.codegenNode.children) && parent.codegenNode.children.type === 15) {
|
|
2353
|
+
const slotName = findDir(node, "slot", true);
|
|
2354
|
+
const slot = slotName && slotName.arg && getSlotNode(parent.codegenNode, slotName.arg);
|
|
2355
|
+
if (slot) {
|
|
2356
|
+
slot.returns = getCacheExpression(createArrayExpression(slot.returns));
|
|
2357
|
+
cachedAsArray = true;
|
|
2358
|
+
}
|
|
2359
|
+
}
|
|
2360
|
+
}
|
|
2361
|
+
if (!cachedAsArray) for (const child of toCache) child.codegenNode = context.cache(child.codegenNode);
|
|
2362
|
+
function getCacheExpression(value) {
|
|
2363
|
+
const exp = context.cache(value);
|
|
2364
|
+
exp.needArraySpread = true;
|
|
2365
|
+
return exp;
|
|
2366
|
+
}
|
|
2367
|
+
function getSlotNode(node, name) {
|
|
2368
|
+
if (node.children && !isArray(node.children) && node.children.type === 15) {
|
|
2369
|
+
const slot = node.children.properties.find((p) => p.key === name || p.key.content === name);
|
|
2370
|
+
return slot && slot.value;
|
|
2371
|
+
}
|
|
2372
|
+
}
|
|
2373
|
+
if (toCache.length && context.transformHoist) context.transformHoist(children, context, node);
|
|
2374
|
+
}
|
|
2375
|
+
function getConstantType(node, context) {
|
|
2376
|
+
const { constantCache } = context;
|
|
2377
|
+
switch (node.type) {
|
|
2378
|
+
case 1:
|
|
2379
|
+
if (node.tagType !== 0) return 0;
|
|
2380
|
+
const cached = constantCache.get(node);
|
|
2381
|
+
if (cached !== void 0) return cached;
|
|
2382
|
+
const codegenNode = node.codegenNode;
|
|
2383
|
+
if (codegenNode.type !== 13) return 0;
|
|
2384
|
+
if (codegenNode.isBlock && node.tag !== "svg" && node.tag !== "foreignObject" && node.tag !== "math") return 0;
|
|
2385
|
+
if (codegenNode.patchFlag === void 0) {
|
|
2386
|
+
let returnType = 3;
|
|
2387
|
+
const generatedPropsType = getGeneratedPropsConstantType(node, context);
|
|
2388
|
+
if (generatedPropsType === 0) {
|
|
2389
|
+
constantCache.set(node, 0);
|
|
2390
|
+
return 0;
|
|
2391
|
+
}
|
|
2392
|
+
if (generatedPropsType < returnType) returnType = generatedPropsType;
|
|
2393
|
+
for (let i = 0; i < node.children.length; i++) {
|
|
2394
|
+
const childType = getConstantType(node.children[i], context);
|
|
2395
|
+
if (childType === 0) {
|
|
2396
|
+
constantCache.set(node, 0);
|
|
2397
|
+
return 0;
|
|
2398
|
+
}
|
|
2399
|
+
if (childType < returnType) returnType = childType;
|
|
2400
|
+
}
|
|
2401
|
+
if (returnType > 1) for (let i = 0; i < node.props.length; i++) {
|
|
2402
|
+
const p = node.props[i];
|
|
2403
|
+
if (p.type === 7 && p.name === "bind" && p.exp) {
|
|
2404
|
+
const expType = getConstantType(p.exp, context);
|
|
2405
|
+
if (expType === 0) {
|
|
2406
|
+
constantCache.set(node, 0);
|
|
2407
|
+
return 0;
|
|
2408
|
+
}
|
|
2409
|
+
if (expType < returnType) returnType = expType;
|
|
2410
|
+
}
|
|
2411
|
+
}
|
|
2412
|
+
if (codegenNode.isBlock) {
|
|
2413
|
+
for (let i = 0; i < node.props.length; i++) if (node.props[i].type === 7) {
|
|
2414
|
+
constantCache.set(node, 0);
|
|
2415
|
+
return 0;
|
|
2416
|
+
}
|
|
2417
|
+
context.removeHelper(OPEN_BLOCK);
|
|
2418
|
+
context.removeHelper(getVNodeBlockHelper(context.inSSR, codegenNode.isComponent));
|
|
2419
|
+
codegenNode.isBlock = false;
|
|
2420
|
+
context.helper(getVNodeHelper(context.inSSR, codegenNode.isComponent));
|
|
2421
|
+
}
|
|
2422
|
+
constantCache.set(node, returnType);
|
|
2423
|
+
return returnType;
|
|
2424
|
+
} else {
|
|
2425
|
+
constantCache.set(node, 0);
|
|
2426
|
+
return 0;
|
|
2427
|
+
}
|
|
2428
|
+
case 2:
|
|
2429
|
+
case 3: return 3;
|
|
2430
|
+
case 9:
|
|
2431
|
+
case 11:
|
|
2432
|
+
case 10: return 0;
|
|
2433
|
+
case 5:
|
|
2434
|
+
case 12: return getConstantType(node.content, context);
|
|
2435
|
+
case 4: return node.constType;
|
|
2436
|
+
case 8:
|
|
2437
|
+
let returnType = 3;
|
|
2438
|
+
for (let i = 0; i < node.children.length; i++) {
|
|
2439
|
+
const child = node.children[i];
|
|
2440
|
+
if (isString(child) || isSymbol(child)) continue;
|
|
2441
|
+
const childType = getConstantType(child, context);
|
|
2442
|
+
if (childType === 0) return 0;
|
|
2443
|
+
else if (childType < returnType) returnType = childType;
|
|
2444
|
+
}
|
|
2445
|
+
return returnType;
|
|
2446
|
+
case 20: return 2;
|
|
2447
|
+
default:
|
|
2448
|
+
if (!!(process.env.NODE_ENV !== "production")) {}
|
|
2449
|
+
return 0;
|
|
2450
|
+
}
|
|
2451
|
+
}
|
|
2452
|
+
const allowHoistedHelperSet = new Set([
|
|
2453
|
+
NORMALIZE_CLASS,
|
|
2454
|
+
NORMALIZE_STYLE,
|
|
2455
|
+
NORMALIZE_PROPS,
|
|
2456
|
+
GUARD_REACTIVE_PROPS
|
|
2457
|
+
]);
|
|
2458
|
+
function getConstantTypeOfHelperCall(value, context) {
|
|
2459
|
+
if (value.type === 14 && !isString(value.callee) && allowHoistedHelperSet.has(value.callee)) {
|
|
2460
|
+
const arg = value.arguments[0];
|
|
2461
|
+
if (arg.type === 4) return getConstantType(arg, context);
|
|
2462
|
+
else if (arg.type === 14) return getConstantTypeOfHelperCall(arg, context);
|
|
2463
|
+
}
|
|
2464
|
+
return 0;
|
|
2465
|
+
}
|
|
2466
|
+
function getGeneratedPropsConstantType(node, context) {
|
|
2467
|
+
let returnType = 3;
|
|
2468
|
+
const props = getNodeProps(node);
|
|
2469
|
+
if (props && props.type === 15) {
|
|
2470
|
+
const { properties } = props;
|
|
2471
|
+
for (let i = 0; i < properties.length; i++) {
|
|
2472
|
+
const { key, value } = properties[i];
|
|
2473
|
+
const keyType = getConstantType(key, context);
|
|
2474
|
+
if (keyType === 0) return keyType;
|
|
2475
|
+
if (keyType < returnType) returnType = keyType;
|
|
2476
|
+
let valueType;
|
|
2477
|
+
if (value.type === 4) valueType = getConstantType(value, context);
|
|
2478
|
+
else if (value.type === 14) valueType = getConstantTypeOfHelperCall(value, context);
|
|
2479
|
+
else valueType = 0;
|
|
2480
|
+
if (valueType === 0) return valueType;
|
|
2481
|
+
if (valueType < returnType) returnType = valueType;
|
|
2482
|
+
}
|
|
2483
|
+
}
|
|
2484
|
+
return returnType;
|
|
2485
|
+
}
|
|
2486
|
+
function getNodeProps(node) {
|
|
2487
|
+
const codegenNode = node.codegenNode;
|
|
2488
|
+
if (codegenNode.type === 13) return codegenNode.props;
|
|
2489
|
+
}
|
|
2490
|
+
|
|
2491
|
+
//#endregion
|
|
2492
|
+
//#region packages/compiler-core/src/transform.ts
|
|
2493
|
+
function getSelfName(filename) {
|
|
2494
|
+
const nameMatch = filename.replace(/\?.*$/, "").match(/([^/\\]+)\.\w+$/);
|
|
2495
|
+
return nameMatch ? capitalize(camelize(nameMatch[1])) : null;
|
|
2496
|
+
}
|
|
2497
|
+
function createTransformContext(root, { filename = "", prefixIdentifiers = false, hoistStatic = false, hmr = false, cacheHandlers = false, nodeTransforms = [], directiveTransforms = {}, transformHoist = null, isBuiltInComponent = NOOP, isCustomElement = NOOP, isUserComponent = (element) => {
|
|
2498
|
+
return element.tagType === 1;
|
|
2499
|
+
}, expressionPlugins = [], scopeId = null, slotted = true, ssr = false, inSSR = false, ssrCssVars = ``, bindingMetadata = EMPTY_OBJ, inline = false, isTS = false, onError = defaultOnError, onWarn = defaultOnWarn, compatConfig }) {
|
|
2500
|
+
const context = {
|
|
2501
|
+
filename,
|
|
2502
|
+
selfName: getSelfName(filename),
|
|
2503
|
+
prefixIdentifiers,
|
|
2504
|
+
hoistStatic,
|
|
2505
|
+
hmr,
|
|
2506
|
+
cacheHandlers,
|
|
2507
|
+
nodeTransforms,
|
|
2508
|
+
directiveTransforms,
|
|
2509
|
+
transformHoist,
|
|
2510
|
+
isBuiltInComponent,
|
|
2511
|
+
isCustomElement,
|
|
2512
|
+
isUserComponent,
|
|
2513
|
+
expressionPlugins,
|
|
2514
|
+
scopeId,
|
|
2515
|
+
slotted,
|
|
2516
|
+
ssr,
|
|
2517
|
+
inSSR,
|
|
2518
|
+
ssrCssVars,
|
|
2519
|
+
bindingMetadata,
|
|
2520
|
+
inline,
|
|
2521
|
+
isTS,
|
|
2522
|
+
onError,
|
|
2523
|
+
onWarn,
|
|
2524
|
+
compatConfig,
|
|
2525
|
+
root,
|
|
2526
|
+
helpers: /* @__PURE__ */ new Map(),
|
|
2527
|
+
components: /* @__PURE__ */ new Set(),
|
|
2528
|
+
directives: /* @__PURE__ */ new Set(),
|
|
2529
|
+
hoists: [],
|
|
2530
|
+
imports: [],
|
|
2531
|
+
cached: [],
|
|
2532
|
+
constantCache: /* @__PURE__ */ new WeakMap(),
|
|
2533
|
+
temps: 0,
|
|
2534
|
+
identifiers: Object.create(null),
|
|
2535
|
+
scopes: {
|
|
2536
|
+
vFor: 0,
|
|
2537
|
+
vSlot: 0,
|
|
2538
|
+
vPre: 0,
|
|
2539
|
+
vOnce: 0
|
|
2540
|
+
},
|
|
2541
|
+
parent: null,
|
|
2542
|
+
grandParent: null,
|
|
2543
|
+
currentNode: root,
|
|
2544
|
+
childIndex: 0,
|
|
2545
|
+
inVOnce: false,
|
|
2546
|
+
helper(name) {
|
|
2547
|
+
const count = context.helpers.get(name) || 0;
|
|
2548
|
+
context.helpers.set(name, count + 1);
|
|
2549
|
+
return name;
|
|
2550
|
+
},
|
|
2551
|
+
removeHelper(name) {
|
|
2552
|
+
const count = context.helpers.get(name);
|
|
2553
|
+
if (count) {
|
|
2554
|
+
const currentCount = count - 1;
|
|
2555
|
+
if (!currentCount) context.helpers.delete(name);
|
|
2556
|
+
else context.helpers.set(name, currentCount);
|
|
2557
|
+
}
|
|
2558
|
+
},
|
|
2559
|
+
helperString(name) {
|
|
2560
|
+
return `_${helperNameMap[context.helper(name)]}`;
|
|
2561
|
+
},
|
|
2562
|
+
replaceNode(node) {
|
|
2563
|
+
/* v8 ignore start */
|
|
2564
|
+
if (!!(process.env.NODE_ENV !== "production")) {
|
|
2565
|
+
if (!context.currentNode) throw new Error(`Node being replaced is already removed.`);
|
|
2566
|
+
if (!context.parent) throw new Error(`Cannot replace root node.`);
|
|
2567
|
+
}
|
|
2568
|
+
/* v8 ignore stop */
|
|
2569
|
+
context.parent.children[context.childIndex] = context.currentNode = node;
|
|
2570
|
+
},
|
|
2571
|
+
removeNode(node) {
|
|
2572
|
+
/* v8 ignore next 3 */
|
|
2573
|
+
if (!!(process.env.NODE_ENV !== "production") && !context.parent) throw new Error(`Cannot remove root node.`);
|
|
2574
|
+
const list = context.parent.children;
|
|
2575
|
+
const removalIndex = node ? list.indexOf(node) : context.currentNode ? context.childIndex : -1;
|
|
2576
|
+
/* v8 ignore next 3 */
|
|
2577
|
+
if (!!(process.env.NODE_ENV !== "production") && removalIndex < 0) throw new Error(`node being removed is not a child of current parent`);
|
|
2578
|
+
if (!node || node === context.currentNode) {
|
|
2579
|
+
context.currentNode = null;
|
|
2580
|
+
context.onNodeRemoved();
|
|
2581
|
+
} else if (context.childIndex > removalIndex) {
|
|
2582
|
+
context.childIndex--;
|
|
2583
|
+
context.onNodeRemoved();
|
|
2584
|
+
}
|
|
2585
|
+
context.parent.children.splice(removalIndex, 1);
|
|
2586
|
+
},
|
|
2587
|
+
onNodeRemoved: NOOP,
|
|
2588
|
+
addIdentifiers(exp) {},
|
|
2589
|
+
removeIdentifiers(exp) {},
|
|
2590
|
+
hoist(exp) {
|
|
2591
|
+
if (isString(exp)) exp = createSimpleExpression(exp);
|
|
2592
|
+
context.hoists.push(exp);
|
|
2593
|
+
const identifier = createSimpleExpression(`_hoisted_${context.hoists.length}`, false, exp.loc, 2);
|
|
2594
|
+
identifier.hoisted = exp;
|
|
2595
|
+
return identifier;
|
|
2596
|
+
},
|
|
2597
|
+
cache(exp, isVNode = false, inVOnce = false) {
|
|
2598
|
+
const cacheExp = createCacheExpression(context.cached.length, exp, isVNode, inVOnce);
|
|
2599
|
+
context.cached.push(cacheExp);
|
|
2600
|
+
return cacheExp;
|
|
2601
|
+
}
|
|
2602
|
+
};
|
|
2603
|
+
context.filters = /* @__PURE__ */ new Set();
|
|
2604
|
+
return context;
|
|
2605
|
+
}
|
|
2606
|
+
function transform(root, options) {
|
|
2607
|
+
const context = createTransformContext(root, options);
|
|
2608
|
+
traverseNode(root, context);
|
|
2609
|
+
if (options.hoistStatic) cacheStatic(root, context);
|
|
2610
|
+
if (!options.ssr) createRootCodegen(root, context);
|
|
2611
|
+
root.helpers = new Set([...context.helpers.keys()]);
|
|
2612
|
+
root.components = [...context.components];
|
|
2613
|
+
root.directives = [...context.directives];
|
|
2614
|
+
root.imports = context.imports;
|
|
2615
|
+
root.hoists = context.hoists;
|
|
2616
|
+
root.temps = context.temps;
|
|
2617
|
+
root.cached = context.cached;
|
|
2618
|
+
root.transformed = true;
|
|
2619
|
+
root.filters = [...context.filters];
|
|
2620
|
+
}
|
|
2621
|
+
function createRootCodegen(root, context) {
|
|
2622
|
+
const { helper } = context;
|
|
2623
|
+
const { children } = root;
|
|
2624
|
+
if (children.length === 1) {
|
|
2625
|
+
const singleElementRootChild = getSingleElementRoot(root);
|
|
2626
|
+
if (singleElementRootChild && singleElementRootChild.codegenNode) {
|
|
2627
|
+
const codegenNode = singleElementRootChild.codegenNode;
|
|
2628
|
+
if (codegenNode.type === 13) convertToBlock(codegenNode, context);
|
|
2629
|
+
root.codegenNode = codegenNode;
|
|
2630
|
+
} else root.codegenNode = children[0];
|
|
2631
|
+
} else if (children.length > 1) {
|
|
2632
|
+
let patchFlag = 64;
|
|
2633
|
+
if (!!(process.env.NODE_ENV !== "production") && children.filter((c) => c.type !== 3).length === 1) patchFlag |= 2048;
|
|
2634
|
+
root.codegenNode = createVNodeCall(context, helper(FRAGMENT), void 0, root.children, patchFlag, void 0, void 0, true, void 0, false);
|
|
2635
|
+
}
|
|
2636
|
+
}
|
|
2637
|
+
function traverseChildren(parent, context) {
|
|
2638
|
+
let i = 0;
|
|
2639
|
+
const nodeRemoved = () => {
|
|
2640
|
+
i--;
|
|
2641
|
+
};
|
|
2642
|
+
for (; i < parent.children.length; i++) {
|
|
2643
|
+
const child = parent.children[i];
|
|
2644
|
+
if (isString(child)) continue;
|
|
2645
|
+
context.grandParent = context.parent;
|
|
2646
|
+
context.parent = parent;
|
|
2647
|
+
context.childIndex = i;
|
|
2648
|
+
context.onNodeRemoved = nodeRemoved;
|
|
2649
|
+
traverseNode(child, context);
|
|
2650
|
+
}
|
|
2651
|
+
}
|
|
2652
|
+
function traverseNode(node, context) {
|
|
2653
|
+
context.currentNode = node;
|
|
2654
|
+
const { nodeTransforms } = context;
|
|
2655
|
+
const exitFns = [];
|
|
2656
|
+
for (let i = 0; i < nodeTransforms.length; i++) {
|
|
2657
|
+
const onExit = nodeTransforms[i](node, context);
|
|
2658
|
+
if (onExit) if (isArray(onExit)) exitFns.push(...onExit);
|
|
2659
|
+
else exitFns.push(onExit);
|
|
2660
|
+
if (!context.currentNode) return;
|
|
2661
|
+
else node = context.currentNode;
|
|
2662
|
+
}
|
|
2663
|
+
switch (node.type) {
|
|
2664
|
+
case 3:
|
|
2665
|
+
if (!context.ssr) context.helper(CREATE_COMMENT);
|
|
2666
|
+
break;
|
|
2667
|
+
case 5:
|
|
2668
|
+
if (!context.ssr) context.helper(TO_DISPLAY_STRING);
|
|
2669
|
+
break;
|
|
2670
|
+
case 9:
|
|
2671
|
+
for (let i = 0; i < node.branches.length; i++) traverseNode(node.branches[i], context);
|
|
2672
|
+
break;
|
|
2673
|
+
case 10:
|
|
2674
|
+
case 11:
|
|
2675
|
+
case 1:
|
|
2676
|
+
case 0:
|
|
2677
|
+
traverseChildren(node, context);
|
|
2678
|
+
break;
|
|
2679
|
+
}
|
|
2680
|
+
context.currentNode = node;
|
|
2681
|
+
let i = exitFns.length;
|
|
2682
|
+
while (i--) exitFns[i]();
|
|
2683
|
+
}
|
|
2684
|
+
function createStructuralDirectiveTransform(name, fn) {
|
|
2685
|
+
const matches = isString(name) ? (n) => n === name : (n) => name.test(n);
|
|
2686
|
+
return (node, context) => {
|
|
2687
|
+
if (node.type === 1) {
|
|
2688
|
+
const { props } = node;
|
|
2689
|
+
if (node.tagType === 3 && props.some(isVSlot)) return;
|
|
2690
|
+
const exitFns = [];
|
|
2691
|
+
for (let i = 0; i < props.length; i++) {
|
|
2692
|
+
const prop = props[i];
|
|
2693
|
+
if (prop.type === 7 && matches(prop.name)) {
|
|
2694
|
+
props.splice(i, 1);
|
|
2695
|
+
i--;
|
|
2696
|
+
const onExit = fn(node, prop, context);
|
|
2697
|
+
if (onExit) exitFns.push(onExit);
|
|
2698
|
+
}
|
|
2699
|
+
}
|
|
2700
|
+
return exitFns;
|
|
2701
|
+
}
|
|
2702
|
+
};
|
|
2703
|
+
}
|
|
2704
|
+
|
|
2705
|
+
//#endregion
|
|
2706
|
+
//#region packages/compiler-core/src/codegen.ts
|
|
2707
|
+
const PURE_ANNOTATION = `/*@__PURE__*/`;
|
|
2708
|
+
const aliasHelper = (s) => `${helperNameMap[s]}: _${helperNameMap[s]}`;
|
|
2709
|
+
const NewlineType = {
|
|
2710
|
+
"Start": 0,
|
|
2711
|
+
"0": "Start",
|
|
2712
|
+
"End": -1,
|
|
2713
|
+
"-1": "End",
|
|
2714
|
+
"None": -2,
|
|
2715
|
+
"-2": "None",
|
|
2716
|
+
"Unknown": -3,
|
|
2717
|
+
"-3": "Unknown"
|
|
2718
|
+
};
|
|
2719
|
+
function createCodegenContext(ast, { mode = "function", prefixIdentifiers = mode === "module", sourceMap = false, filename = `template.vue.html`, scopeId = null, optimizeImports = false, runtimeGlobalName = `Vue`, runtimeModuleName = `vue`, ssrRuntimeModuleName = "vue/server-renderer", ssr = false, isTS = false, inSSR = false }) {
|
|
2720
|
+
const context = {
|
|
2721
|
+
mode,
|
|
2722
|
+
prefixIdentifiers,
|
|
2723
|
+
sourceMap,
|
|
2724
|
+
filename,
|
|
2725
|
+
scopeId,
|
|
2726
|
+
optimizeImports,
|
|
2727
|
+
runtimeGlobalName,
|
|
2728
|
+
runtimeModuleName,
|
|
2729
|
+
ssrRuntimeModuleName,
|
|
2730
|
+
ssr,
|
|
2731
|
+
isTS,
|
|
2732
|
+
inSSR,
|
|
2733
|
+
source: ast.source,
|
|
2734
|
+
code: ``,
|
|
2735
|
+
column: 1,
|
|
2736
|
+
line: 1,
|
|
2737
|
+
offset: 0,
|
|
2738
|
+
indentLevel: 0,
|
|
2739
|
+
pure: false,
|
|
2740
|
+
map: void 0,
|
|
2741
|
+
helper(key) {
|
|
2742
|
+
return `_${helperNameMap[key]}`;
|
|
2743
|
+
},
|
|
2744
|
+
push(code, newlineIndex = -2, node) {
|
|
2745
|
+
context.code += code;
|
|
2746
|
+
},
|
|
2747
|
+
indent() {
|
|
2748
|
+
newline(++context.indentLevel);
|
|
2749
|
+
},
|
|
2750
|
+
deindent(withoutNewLine = false) {
|
|
2751
|
+
if (withoutNewLine) --context.indentLevel;
|
|
2752
|
+
else newline(--context.indentLevel);
|
|
2753
|
+
},
|
|
2754
|
+
newline() {
|
|
2755
|
+
newline(context.indentLevel);
|
|
2756
|
+
}
|
|
2757
|
+
};
|
|
2758
|
+
function newline(n) {
|
|
2759
|
+
context.push("\n" + ` `.repeat(n), 0);
|
|
2760
|
+
}
|
|
2761
|
+
return context;
|
|
2762
|
+
}
|
|
2763
|
+
function generate(ast, options = {}) {
|
|
2764
|
+
const context = createCodegenContext(ast, options);
|
|
2765
|
+
if (options.onContextCreated) options.onContextCreated(context);
|
|
2766
|
+
const { mode, push, prefixIdentifiers, indent, deindent, newline, scopeId, ssr } = context;
|
|
2767
|
+
const helpers = Array.from(ast.helpers);
|
|
2768
|
+
const hasHelpers = helpers.length > 0;
|
|
2769
|
+
const useWithBlock = !prefixIdentifiers && mode !== "module";
|
|
2770
|
+
genFunctionPreamble(ast, context);
|
|
2771
|
+
push(`function ${ssr ? `ssrRender` : `render`}(${(ssr ? [
|
|
2772
|
+
"_ctx",
|
|
2773
|
+
"_push",
|
|
2774
|
+
"_parent",
|
|
2775
|
+
"_attrs"
|
|
2776
|
+
] : ["_ctx", "_cache"]).join(", ")}) {`);
|
|
2777
|
+
indent();
|
|
2778
|
+
if (useWithBlock) {
|
|
2779
|
+
push(`with (_ctx) {`);
|
|
2780
|
+
indent();
|
|
2781
|
+
if (hasHelpers) {
|
|
2782
|
+
push(`const { ${helpers.map(aliasHelper).join(", ")} } = _Vue\n`, -1);
|
|
2783
|
+
newline();
|
|
2784
|
+
}
|
|
2785
|
+
}
|
|
2786
|
+
if (ast.components.length) {
|
|
2787
|
+
genAssets(ast.components, "component", context);
|
|
2788
|
+
if (ast.directives.length || ast.temps > 0) newline();
|
|
2789
|
+
}
|
|
2790
|
+
if (ast.directives.length) {
|
|
2791
|
+
genAssets(ast.directives, "directive", context);
|
|
2792
|
+
if (ast.temps > 0) newline();
|
|
2793
|
+
}
|
|
2794
|
+
if (ast.filters && ast.filters.length) {
|
|
2795
|
+
newline();
|
|
2796
|
+
genAssets(ast.filters, "filter", context);
|
|
2797
|
+
newline();
|
|
2798
|
+
}
|
|
2799
|
+
if (ast.temps > 0) {
|
|
2800
|
+
push(`let `);
|
|
2801
|
+
for (let i = 0; i < ast.temps; i++) push(`${i > 0 ? `, ` : ``}_temp${i}`);
|
|
2802
|
+
}
|
|
2803
|
+
if (ast.components.length || ast.directives.length || ast.temps) {
|
|
2804
|
+
push(`\n`, 0);
|
|
2805
|
+
newline();
|
|
2806
|
+
}
|
|
2807
|
+
if (!ssr) push(`return `);
|
|
2808
|
+
if (ast.codegenNode) genNode(ast.codegenNode, context);
|
|
2809
|
+
else push(`null`);
|
|
2810
|
+
if (useWithBlock) {
|
|
2811
|
+
deindent();
|
|
2812
|
+
push(`}`);
|
|
2813
|
+
}
|
|
2814
|
+
deindent();
|
|
2815
|
+
push(`}`);
|
|
2816
|
+
return {
|
|
2817
|
+
ast,
|
|
2818
|
+
code: context.code,
|
|
2819
|
+
preamble: ``,
|
|
2820
|
+
map: context.map ? context.map.toJSON() : void 0,
|
|
2821
|
+
helpers: ast.helpers
|
|
2822
|
+
};
|
|
2823
|
+
}
|
|
2824
|
+
function genFunctionPreamble(ast, context) {
|
|
2825
|
+
const { ssr, prefixIdentifiers, push, newline, runtimeModuleName, runtimeGlobalName, ssrRuntimeModuleName } = context;
|
|
2826
|
+
const VueBinding = runtimeGlobalName;
|
|
2827
|
+
const helpers = Array.from(ast.helpers);
|
|
2828
|
+
if (helpers.length > 0) {
|
|
2829
|
+
push(`const _Vue = ${VueBinding}\n`, -1);
|
|
2830
|
+
if (ast.hoists.length) push(`const { ${[
|
|
2831
|
+
CREATE_VNODE,
|
|
2832
|
+
CREATE_ELEMENT_VNODE,
|
|
2833
|
+
CREATE_COMMENT,
|
|
2834
|
+
CREATE_TEXT,
|
|
2835
|
+
CREATE_STATIC
|
|
2836
|
+
].filter((helper) => helpers.includes(helper)).map(aliasHelper).join(", ")} } = _Vue\n`, -1);
|
|
2837
|
+
}
|
|
2838
|
+
genHoists(ast.hoists, context);
|
|
2839
|
+
newline();
|
|
2840
|
+
push(`return `);
|
|
2841
|
+
}
|
|
2842
|
+
function genAssets(assets, type, { helper, push, newline, isTS }) {
|
|
2843
|
+
const resolver = helper(type === "filter" ? RESOLVE_FILTER : type === "component" ? RESOLVE_COMPONENT : RESOLVE_DIRECTIVE);
|
|
2844
|
+
for (let i = 0; i < assets.length; i++) {
|
|
2845
|
+
let id = assets[i];
|
|
2846
|
+
const maybeSelfReference = id.endsWith("__self");
|
|
2847
|
+
if (maybeSelfReference) id = id.slice(0, -6);
|
|
2848
|
+
push(`const ${toValidAssetId(id, type)} = ${resolver}(${JSON.stringify(id)}${maybeSelfReference ? `, true` : ``})${isTS ? `!` : ``}`);
|
|
2849
|
+
if (i < assets.length - 1) newline();
|
|
2850
|
+
}
|
|
2851
|
+
}
|
|
2852
|
+
function genHoists(hoists, context) {
|
|
2853
|
+
if (!hoists.length) return;
|
|
2854
|
+
context.pure = true;
|
|
2855
|
+
const { push, newline } = context;
|
|
2856
|
+
newline();
|
|
2857
|
+
for (let i = 0; i < hoists.length; i++) {
|
|
2858
|
+
const exp = hoists[i];
|
|
2859
|
+
if (exp) {
|
|
2860
|
+
push(`const _hoisted_${i + 1} = `);
|
|
2861
|
+
genNode(exp, context);
|
|
2862
|
+
newline();
|
|
2863
|
+
}
|
|
2864
|
+
}
|
|
2865
|
+
context.pure = false;
|
|
2866
|
+
}
|
|
2867
|
+
function isText$1(n) {
|
|
2868
|
+
return isString(n) || n.type === 4 || n.type === 2 || n.type === 5 || n.type === 8;
|
|
2869
|
+
}
|
|
2870
|
+
function genNodeListAsArray(nodes, context) {
|
|
2871
|
+
const multilines = nodes.length > 3 || !!(process.env.NODE_ENV !== "production") && nodes.some((n) => isArray(n) || !isText$1(n));
|
|
2872
|
+
context.push(`[`);
|
|
2873
|
+
multilines && context.indent();
|
|
2874
|
+
genNodeList(nodes, context, multilines);
|
|
2875
|
+
multilines && context.deindent();
|
|
2876
|
+
context.push(`]`);
|
|
2877
|
+
}
|
|
2878
|
+
function genNodeList(nodes, context, multilines = false, comma = true) {
|
|
2879
|
+
const { push, newline } = context;
|
|
2880
|
+
for (let i = 0; i < nodes.length; i++) {
|
|
2881
|
+
const node = nodes[i];
|
|
2882
|
+
if (isString(node)) push(node, -3);
|
|
2883
|
+
else if (isArray(node)) genNodeListAsArray(node, context);
|
|
2884
|
+
else genNode(node, context);
|
|
2885
|
+
if (i < nodes.length - 1) if (multilines) {
|
|
2886
|
+
comma && push(",");
|
|
2887
|
+
newline();
|
|
2888
|
+
} else comma && push(", ");
|
|
2889
|
+
}
|
|
2890
|
+
}
|
|
2891
|
+
function genNode(node, context) {
|
|
2892
|
+
if (isString(node)) {
|
|
2893
|
+
context.push(node, -3);
|
|
2894
|
+
return;
|
|
2895
|
+
}
|
|
2896
|
+
if (isSymbol(node)) {
|
|
2897
|
+
context.push(context.helper(node));
|
|
2898
|
+
return;
|
|
2899
|
+
}
|
|
2900
|
+
switch (node.type) {
|
|
2901
|
+
case 1:
|
|
2902
|
+
case 9:
|
|
2903
|
+
case 11:
|
|
2904
|
+
process.env.NODE_ENV !== "production" && assert(node.codegenNode != null, "Codegen node is missing for element/if/for node. Apply appropriate transforms first.");
|
|
2905
|
+
genNode(node.codegenNode, context);
|
|
2906
|
+
break;
|
|
2907
|
+
case 2:
|
|
2908
|
+
genText(node, context);
|
|
2909
|
+
break;
|
|
2910
|
+
case 4:
|
|
2911
|
+
genExpression(node, context);
|
|
2912
|
+
break;
|
|
2913
|
+
case 5:
|
|
2914
|
+
genInterpolation(node, context);
|
|
2915
|
+
break;
|
|
2916
|
+
case 12:
|
|
2917
|
+
genNode(node.codegenNode, context);
|
|
2918
|
+
break;
|
|
2919
|
+
case 8:
|
|
2920
|
+
genCompoundExpression(node, context);
|
|
2921
|
+
break;
|
|
2922
|
+
case 3:
|
|
2923
|
+
genComment(node, context);
|
|
2924
|
+
break;
|
|
2925
|
+
case 13:
|
|
2926
|
+
genVNodeCall(node, context);
|
|
2927
|
+
break;
|
|
2928
|
+
case 14:
|
|
2929
|
+
genCallExpression(node, context);
|
|
2930
|
+
break;
|
|
2931
|
+
case 15:
|
|
2932
|
+
genObjectExpression(node, context);
|
|
2933
|
+
break;
|
|
2934
|
+
case 17:
|
|
2935
|
+
genArrayExpression(node, context);
|
|
2936
|
+
break;
|
|
2937
|
+
case 18:
|
|
2938
|
+
genFunctionExpression(node, context);
|
|
2939
|
+
break;
|
|
2940
|
+
case 19:
|
|
2941
|
+
genConditionalExpression(node, context);
|
|
2942
|
+
break;
|
|
2943
|
+
case 20:
|
|
2944
|
+
genCacheExpression(node, context);
|
|
2945
|
+
break;
|
|
2946
|
+
case 21:
|
|
2947
|
+
genNodeList(node.body, context, true, false);
|
|
2948
|
+
break;
|
|
2949
|
+
case 22: break;
|
|
2950
|
+
case 23: break;
|
|
2951
|
+
case 24: break;
|
|
2952
|
+
case 25: break;
|
|
2953
|
+
case 26: break;
|
|
2954
|
+
case 10: break;
|
|
2955
|
+
default: if (!!(process.env.NODE_ENV !== "production")) {
|
|
2956
|
+
assert(false, `unhandled codegen node type: ${node.type}`);
|
|
2957
|
+
return node;
|
|
2958
|
+
}
|
|
2959
|
+
}
|
|
2960
|
+
}
|
|
2961
|
+
function genText(node, context) {
|
|
2962
|
+
context.push(JSON.stringify(node.content), -3, node);
|
|
2963
|
+
}
|
|
2964
|
+
function genExpression(node, context) {
|
|
2965
|
+
const { content, isStatic } = node;
|
|
2966
|
+
context.push(isStatic ? JSON.stringify(content) : content, -3, node);
|
|
2967
|
+
}
|
|
2968
|
+
function genInterpolation(node, context) {
|
|
2969
|
+
const { push, helper, pure } = context;
|
|
2970
|
+
if (pure) push(PURE_ANNOTATION);
|
|
2971
|
+
push(`${helper(TO_DISPLAY_STRING)}(`);
|
|
2972
|
+
genNode(node.content, context);
|
|
2973
|
+
push(`)`);
|
|
2974
|
+
}
|
|
2975
|
+
function genCompoundExpression(node, context) {
|
|
2976
|
+
for (let i = 0; i < node.children.length; i++) {
|
|
2977
|
+
const child = node.children[i];
|
|
2978
|
+
if (isString(child)) context.push(child, -3);
|
|
2979
|
+
else genNode(child, context);
|
|
2980
|
+
}
|
|
2981
|
+
}
|
|
2982
|
+
function genExpressionAsPropertyKey(node, context) {
|
|
2983
|
+
const { push } = context;
|
|
2984
|
+
if (node.type === 8) {
|
|
2985
|
+
push(`[`);
|
|
2986
|
+
genCompoundExpression(node, context);
|
|
2987
|
+
push(`]`);
|
|
2988
|
+
} else if (node.isStatic) push(isSimpleIdentifier(node.content) ? node.content : JSON.stringify(node.content), -2, node);
|
|
2989
|
+
else push(`[${node.content}]`, -3, node);
|
|
2990
|
+
}
|
|
2991
|
+
function genComment(node, context) {
|
|
2992
|
+
const { push, helper, pure } = context;
|
|
2993
|
+
if (pure) push(PURE_ANNOTATION);
|
|
2994
|
+
push(`${helper(CREATE_COMMENT)}(${JSON.stringify(node.content)})`, -3, node);
|
|
2995
|
+
}
|
|
2996
|
+
function genVNodeCall(node, context) {
|
|
2997
|
+
const { push, helper, pure } = context;
|
|
2998
|
+
const { tag, props, children, patchFlag, dynamicProps, directives, isBlock, disableTracking, isComponent } = node;
|
|
2999
|
+
let patchFlagString;
|
|
3000
|
+
if (patchFlag) if (!!(process.env.NODE_ENV !== "production")) if (patchFlag < 0) patchFlagString = patchFlag + ` /* ${PatchFlagNames[patchFlag]} */`;
|
|
3001
|
+
else patchFlagString = patchFlag + ` /* ${Object.keys(PatchFlagNames).map(Number).filter((n) => n > 0 && patchFlag & n).map((n) => PatchFlagNames[n]).join(`, `)} */`;
|
|
3002
|
+
else patchFlagString = String(patchFlag);
|
|
3003
|
+
if (directives) push(helper(WITH_DIRECTIVES) + `(`);
|
|
3004
|
+
if (isBlock) push(`(${helper(OPEN_BLOCK)}(${disableTracking ? `true` : ``}), `);
|
|
3005
|
+
if (pure) push(PURE_ANNOTATION);
|
|
3006
|
+
push(helper(isBlock ? getVNodeBlockHelper(context.inSSR, isComponent) : getVNodeHelper(context.inSSR, isComponent)) + `(`, -2, node);
|
|
3007
|
+
genNodeList(genNullableArgs([
|
|
3008
|
+
tag,
|
|
3009
|
+
props,
|
|
3010
|
+
children,
|
|
3011
|
+
patchFlagString,
|
|
3012
|
+
dynamicProps
|
|
3013
|
+
]), context);
|
|
3014
|
+
push(`)`);
|
|
3015
|
+
if (isBlock) push(`)`);
|
|
3016
|
+
if (directives) {
|
|
3017
|
+
push(`, `);
|
|
3018
|
+
genNode(directives, context);
|
|
3019
|
+
push(`)`);
|
|
3020
|
+
}
|
|
3021
|
+
}
|
|
3022
|
+
function genNullableArgs(args) {
|
|
3023
|
+
let i = args.length;
|
|
3024
|
+
while (i--) if (args[i] != null) break;
|
|
3025
|
+
return args.slice(0, i + 1).map((arg) => arg || `null`);
|
|
3026
|
+
}
|
|
3027
|
+
function genCallExpression(node, context) {
|
|
3028
|
+
const { push, helper, pure } = context;
|
|
3029
|
+
const callee = isString(node.callee) ? node.callee : helper(node.callee);
|
|
3030
|
+
if (pure) push(PURE_ANNOTATION);
|
|
3031
|
+
push(callee + `(`, -2, node);
|
|
3032
|
+
genNodeList(node.arguments, context);
|
|
3033
|
+
push(`)`);
|
|
3034
|
+
}
|
|
3035
|
+
function genObjectExpression(node, context) {
|
|
3036
|
+
const { push, indent, deindent, newline } = context;
|
|
3037
|
+
const { properties } = node;
|
|
3038
|
+
if (!properties.length) {
|
|
3039
|
+
push(`{}`, -2, node);
|
|
3040
|
+
return;
|
|
3041
|
+
}
|
|
3042
|
+
const multilines = properties.length > 1 || !!(process.env.NODE_ENV !== "production") && properties.some((p) => p.value.type !== 4);
|
|
3043
|
+
push(multilines ? `{` : `{ `);
|
|
3044
|
+
multilines && indent();
|
|
3045
|
+
for (let i = 0; i < properties.length; i++) {
|
|
3046
|
+
const { key, value } = properties[i];
|
|
3047
|
+
genExpressionAsPropertyKey(key, context);
|
|
3048
|
+
push(`: `);
|
|
3049
|
+
genNode(value, context);
|
|
3050
|
+
if (i < properties.length - 1) {
|
|
3051
|
+
push(`,`);
|
|
3052
|
+
newline();
|
|
3053
|
+
}
|
|
3054
|
+
}
|
|
3055
|
+
multilines && deindent();
|
|
3056
|
+
push(multilines ? `}` : ` }`);
|
|
3057
|
+
}
|
|
3058
|
+
function genArrayExpression(node, context) {
|
|
3059
|
+
genNodeListAsArray(node.elements, context);
|
|
3060
|
+
}
|
|
3061
|
+
function genFunctionExpression(node, context) {
|
|
3062
|
+
const { push, indent, deindent } = context;
|
|
3063
|
+
const { params, returns, body, newline, isSlot } = node;
|
|
3064
|
+
if (isSlot) push(`_${helperNameMap[WITH_CTX]}(`);
|
|
3065
|
+
push(`(`, -2, node);
|
|
3066
|
+
if (isArray(params)) genNodeList(params, context);
|
|
3067
|
+
else if (params) genNode(params, context);
|
|
3068
|
+
push(`) => `);
|
|
3069
|
+
if (newline || body) {
|
|
3070
|
+
push(`{`);
|
|
3071
|
+
indent();
|
|
3072
|
+
}
|
|
3073
|
+
if (returns) {
|
|
3074
|
+
if (newline) push(`return `);
|
|
3075
|
+
if (isArray(returns)) genNodeListAsArray(returns, context);
|
|
3076
|
+
else genNode(returns, context);
|
|
3077
|
+
} else if (body) genNode(body, context);
|
|
3078
|
+
if (newline || body) {
|
|
3079
|
+
deindent();
|
|
3080
|
+
push(`}`);
|
|
3081
|
+
}
|
|
3082
|
+
if (isSlot) {
|
|
3083
|
+
if (node.isNonScopedSlot) push(`, undefined, true`);
|
|
3084
|
+
push(`)`);
|
|
3085
|
+
}
|
|
3086
|
+
}
|
|
3087
|
+
function genConditionalExpression(node, context) {
|
|
3088
|
+
const { test, consequent, alternate, newline: needNewline } = node;
|
|
3089
|
+
const { push, indent, deindent, newline } = context;
|
|
3090
|
+
if (test.type === 4) {
|
|
3091
|
+
const needsParens = !isSimpleIdentifier(test.content);
|
|
3092
|
+
needsParens && push(`(`);
|
|
3093
|
+
genExpression(test, context);
|
|
3094
|
+
needsParens && push(`)`);
|
|
3095
|
+
} else {
|
|
3096
|
+
push(`(`);
|
|
3097
|
+
genNode(test, context);
|
|
3098
|
+
push(`)`);
|
|
3099
|
+
}
|
|
3100
|
+
needNewline && indent();
|
|
3101
|
+
context.indentLevel++;
|
|
3102
|
+
needNewline || push(` `);
|
|
3103
|
+
push(`? `);
|
|
3104
|
+
genNode(consequent, context);
|
|
3105
|
+
context.indentLevel--;
|
|
3106
|
+
needNewline && newline();
|
|
3107
|
+
needNewline || push(` `);
|
|
3108
|
+
push(`: `);
|
|
3109
|
+
const isNested = alternate.type === 19;
|
|
3110
|
+
if (!isNested) context.indentLevel++;
|
|
3111
|
+
genNode(alternate, context);
|
|
3112
|
+
if (!isNested) context.indentLevel--;
|
|
3113
|
+
needNewline && deindent(true);
|
|
3114
|
+
}
|
|
3115
|
+
function genCacheExpression(node, context) {
|
|
3116
|
+
const { push, helper, indent, deindent, newline } = context;
|
|
3117
|
+
const { needPauseTracking, needArraySpread } = node;
|
|
3118
|
+
if (needArraySpread) push(`[...(`);
|
|
3119
|
+
push(`_cache[${node.index}] || (`);
|
|
3120
|
+
if (needPauseTracking) {
|
|
3121
|
+
indent();
|
|
3122
|
+
push(`${helper(SET_BLOCK_TRACKING)}(-1`);
|
|
3123
|
+
if (node.inVOnce) push(`, true`);
|
|
3124
|
+
push(`),`);
|
|
3125
|
+
newline();
|
|
3126
|
+
push(`(`);
|
|
3127
|
+
}
|
|
3128
|
+
push(`_cache[${node.index}] = `);
|
|
3129
|
+
genNode(node.value, context);
|
|
3130
|
+
if (needPauseTracking) {
|
|
3131
|
+
push(`).cacheIndex = ${node.index},`);
|
|
3132
|
+
newline();
|
|
3133
|
+
push(`${helper(SET_BLOCK_TRACKING)}(1),`);
|
|
3134
|
+
newline();
|
|
3135
|
+
push(`_cache[${node.index}]`);
|
|
3136
|
+
deindent();
|
|
3137
|
+
}
|
|
3138
|
+
push(`)`);
|
|
3139
|
+
if (needArraySpread) push(`)]`);
|
|
3140
|
+
}
|
|
3141
|
+
|
|
3142
|
+
//#endregion
|
|
3143
|
+
//#region packages/compiler-core/src/validateExpression.ts
|
|
3144
|
+
const prohibitedKeywordRE = new RegExp("\\b" + "arguments,await,break,case,catch,class,const,continue,debugger,default,delete,do,else,export,extends,finally,for,function,if,import,let,new,return,super,switch,throw,try,var,void,while,with,yield".split(",").join("\\b|\\b") + "\\b");
|
|
3145
|
+
const stripStringRE = /'(?:[^'\\]|\\.)*'|"(?:[^"\\]|\\.)*"|`(?:[^`\\]|\\.)*\$\{|\}(?:[^`\\]|\\.)*`|`(?:[^`\\]|\\.)*`/g;
|
|
3146
|
+
/**
|
|
3147
|
+
* Validate a non-prefixed expression.
|
|
3148
|
+
* This is only called when using the in-browser runtime compiler since it
|
|
3149
|
+
* doesn't prefix expressions.
|
|
3150
|
+
*/
|
|
3151
|
+
function validateBrowserExpression(node, context, asParams = false, asRawStatements = false) {
|
|
3152
|
+
const exp = node.content;
|
|
3153
|
+
if (!exp.trim()) return;
|
|
3154
|
+
try {
|
|
3155
|
+
new Function(asRawStatements ? ` ${exp} ` : `return ${asParams ? `(${exp}) => {}` : `(${exp})`}`);
|
|
3156
|
+
} catch (e) {
|
|
3157
|
+
let message = e.message;
|
|
3158
|
+
const keywordMatch = exp.replace(stripStringRE, "").match(prohibitedKeywordRE);
|
|
3159
|
+
if (keywordMatch) message = `avoid using JavaScript keyword as property name: "${keywordMatch[0]}"`;
|
|
3160
|
+
context.onError(createCompilerError(46, node.loc, void 0, message));
|
|
3161
|
+
}
|
|
3162
|
+
}
|
|
3163
|
+
|
|
3164
|
+
//#endregion
|
|
3165
|
+
//#region packages/compiler-core/src/transforms/transformExpression.ts
|
|
3166
|
+
const isLiteralWhitelisted = /* @__PURE__ */ makeMap("true,false,null,this");
|
|
3167
|
+
const transformExpression = (node, context) => {
|
|
3168
|
+
if (node.type === 5) node.content = processExpression(node.content, context);
|
|
3169
|
+
else if (node.type === 1) {
|
|
3170
|
+
const memo = findDir(node, "memo");
|
|
3171
|
+
for (let i = 0; i < node.props.length; i++) {
|
|
3172
|
+
const dir = node.props[i];
|
|
3173
|
+
if (dir.type === 7 && dir.name !== "for") {
|
|
3174
|
+
const exp = dir.exp;
|
|
3175
|
+
const arg = dir.arg;
|
|
3176
|
+
if (exp && exp.type === 4 && !(dir.name === "on" && arg) && !(memo && arg && arg.type === 4 && arg.content === "key")) dir.exp = processExpression(exp, context, dir.name === "slot");
|
|
3177
|
+
if (arg && arg.type === 4 && !arg.isStatic) dir.arg = processExpression(arg, context);
|
|
3178
|
+
}
|
|
3179
|
+
}
|
|
3180
|
+
}
|
|
3181
|
+
};
|
|
3182
|
+
function processExpression(node, context, asParams = false, asRawStatements = false, localVars = Object.create(context.identifiers)) {
|
|
3183
|
+
if (!!(process.env.NODE_ENV !== "production")) validateBrowserExpression(node, context, asParams, asRawStatements);
|
|
3184
|
+
return node;
|
|
3185
|
+
}
|
|
3186
|
+
function stringifyExpression(exp) {
|
|
3187
|
+
if (isString(exp)) return exp;
|
|
3188
|
+
else if (exp.type === 4) return exp.content;
|
|
3189
|
+
else return exp.children.map(stringifyExpression).join("");
|
|
3190
|
+
}
|
|
3191
|
+
|
|
3192
|
+
//#endregion
|
|
3193
|
+
//#region packages/compiler-core/src/transforms/vIf.ts
|
|
3194
|
+
const transformIf = createStructuralDirectiveTransform(/^(?:if|else|else-if)$/, (node, dir, context) => {
|
|
3195
|
+
return processIf(node, dir, context, (ifNode, branch, isRoot) => {
|
|
3196
|
+
const siblings = context.parent.children;
|
|
3197
|
+
let i = siblings.indexOf(ifNode);
|
|
3198
|
+
let key = 0;
|
|
3199
|
+
while (i-- >= 0) {
|
|
3200
|
+
const sibling = siblings[i];
|
|
3201
|
+
if (sibling && sibling.type === 9) key += sibling.branches.length;
|
|
3202
|
+
}
|
|
3203
|
+
return () => {
|
|
3204
|
+
if (isRoot) ifNode.codegenNode = createCodegenNodeForBranch(branch, key, context);
|
|
3205
|
+
else {
|
|
3206
|
+
const parentCondition = getParentCondition(ifNode.codegenNode);
|
|
3207
|
+
parentCondition.alternate = createCodegenNodeForBranch(branch, key + ifNode.branches.length - 1, context);
|
|
3208
|
+
}
|
|
3209
|
+
};
|
|
3210
|
+
});
|
|
3211
|
+
});
|
|
3212
|
+
function processIf(node, dir, context, processCodegen) {
|
|
3213
|
+
if (dir.name !== "else" && (!dir.exp || !dir.exp.content.trim())) {
|
|
3214
|
+
const loc = dir.exp ? dir.exp.loc : node.loc;
|
|
3215
|
+
context.onError(createCompilerError(28, dir.loc));
|
|
3216
|
+
dir.exp = createSimpleExpression(`true`, false, loc);
|
|
3217
|
+
}
|
|
3218
|
+
if (!!(process.env.NODE_ENV !== "production") && dir.exp) validateBrowserExpression(dir.exp, context);
|
|
3219
|
+
if (dir.name === "if") {
|
|
3220
|
+
const branch = createIfBranch(node, dir);
|
|
3221
|
+
const ifNode = {
|
|
3222
|
+
type: 9,
|
|
3223
|
+
loc: cloneLoc(node.loc),
|
|
3224
|
+
branches: [branch]
|
|
3225
|
+
};
|
|
3226
|
+
context.replaceNode(ifNode);
|
|
3227
|
+
if (processCodegen) return processCodegen(ifNode, branch, true);
|
|
3228
|
+
} else {
|
|
3229
|
+
const siblings = context.parent.children;
|
|
3230
|
+
const comments = [];
|
|
3231
|
+
let i = siblings.indexOf(node);
|
|
3232
|
+
while (i-- >= -1) {
|
|
3233
|
+
const sibling = siblings[i];
|
|
3234
|
+
if (sibling && isCommentOrWhitespace(sibling)) {
|
|
3235
|
+
context.removeNode(sibling);
|
|
3236
|
+
if (!!(process.env.NODE_ENV !== "production") && sibling.type === 3) comments.unshift(sibling);
|
|
3237
|
+
continue;
|
|
3238
|
+
}
|
|
3239
|
+
if (sibling && sibling.type === 9) {
|
|
3240
|
+
if ((dir.name === "else-if" || dir.name === "else") && sibling.branches[sibling.branches.length - 1].condition === void 0) context.onError(createCompilerError(30, node.loc));
|
|
3241
|
+
context.removeNode();
|
|
3242
|
+
const branch = createIfBranch(node, dir);
|
|
3243
|
+
if (!!(process.env.NODE_ENV !== "production") && comments.length && !(context.parent && context.parent.type === 1 && (context.parent.tag === "transition" || context.parent.tag === "Transition"))) branch.children = [...comments, ...branch.children];
|
|
3244
|
+
if (!!(process.env.NODE_ENV !== "production") || false) {
|
|
3245
|
+
const key = branch.userKey;
|
|
3246
|
+
if (key) sibling.branches.forEach(({ userKey }) => {
|
|
3247
|
+
if (isSameKey(userKey, key)) context.onError(createCompilerError(29, branch.userKey.loc));
|
|
3248
|
+
});
|
|
3249
|
+
}
|
|
3250
|
+
sibling.branches.push(branch);
|
|
3251
|
+
const onExit = processCodegen && processCodegen(sibling, branch, false);
|
|
3252
|
+
traverseNode(branch, context);
|
|
3253
|
+
if (onExit) onExit();
|
|
3254
|
+
context.currentNode = null;
|
|
3255
|
+
} else context.onError(createCompilerError(30, node.loc));
|
|
3256
|
+
break;
|
|
3257
|
+
}
|
|
3258
|
+
}
|
|
3259
|
+
}
|
|
3260
|
+
function createIfBranch(node, dir) {
|
|
3261
|
+
const isTemplateIf = node.tagType === 3;
|
|
3262
|
+
return {
|
|
3263
|
+
type: 10,
|
|
3264
|
+
loc: node.loc,
|
|
3265
|
+
condition: dir.name === "else" ? void 0 : dir.exp,
|
|
3266
|
+
children: isTemplateIf && !findDir(node, "for") ? node.children : [node],
|
|
3267
|
+
userKey: findProp(node, `key`),
|
|
3268
|
+
isTemplateIf
|
|
3269
|
+
};
|
|
3270
|
+
}
|
|
3271
|
+
function createCodegenNodeForBranch(branch, keyIndex, context) {
|
|
3272
|
+
if (branch.condition) return createConditionalExpression(branch.condition, createChildrenCodegenNode(branch, keyIndex, context), createCallExpression(context.helper(CREATE_COMMENT), [!!(process.env.NODE_ENV !== "production") ? "\"v-if\"" : "\"\"", "true"]));
|
|
3273
|
+
else return createChildrenCodegenNode(branch, keyIndex, context);
|
|
3274
|
+
}
|
|
3275
|
+
function createChildrenCodegenNode(branch, keyIndex, context) {
|
|
3276
|
+
const { helper } = context;
|
|
3277
|
+
const keyProperty = createObjectProperty(`key`, createSimpleExpression(`${keyIndex}`, false, locStub, 2));
|
|
3278
|
+
const { children } = branch;
|
|
3279
|
+
const firstChild = children[0];
|
|
3280
|
+
if (children.length !== 1 || firstChild.type !== 1) if (children.length === 1 && firstChild.type === 11) {
|
|
3281
|
+
const vnodeCall = firstChild.codegenNode;
|
|
3282
|
+
injectProp(vnodeCall, keyProperty, context);
|
|
3283
|
+
return vnodeCall;
|
|
3284
|
+
} else {
|
|
3285
|
+
let patchFlag = 64;
|
|
3286
|
+
if (!!(process.env.NODE_ENV !== "production") && !branch.isTemplateIf && children.filter((c) => c.type !== 3).length === 1) patchFlag |= 2048;
|
|
3287
|
+
return createVNodeCall(context, helper(FRAGMENT), createObjectExpression([keyProperty]), children, patchFlag, void 0, void 0, true, false, false, branch.loc);
|
|
3288
|
+
}
|
|
3289
|
+
else {
|
|
3290
|
+
const ret = firstChild.codegenNode;
|
|
3291
|
+
const vnodeCall = getMemoedVNodeCall(ret);
|
|
3292
|
+
if (vnodeCall.type === 13) convertToBlock(vnodeCall, context);
|
|
3293
|
+
injectProp(vnodeCall, keyProperty, context);
|
|
3294
|
+
return ret;
|
|
3295
|
+
}
|
|
3296
|
+
}
|
|
3297
|
+
function isSameKey(a, b) {
|
|
3298
|
+
if (!a || a.type !== b.type) return false;
|
|
3299
|
+
if (a.type === 6) {
|
|
3300
|
+
if (a.value.content !== b.value.content) return false;
|
|
3301
|
+
} else {
|
|
3302
|
+
const exp = a.exp;
|
|
3303
|
+
const branchExp = b.exp;
|
|
3304
|
+
if (exp.type !== branchExp.type) return false;
|
|
3305
|
+
if (exp.type !== 4 || exp.isStatic !== branchExp.isStatic || exp.content !== branchExp.content) return false;
|
|
3306
|
+
}
|
|
3307
|
+
return true;
|
|
3308
|
+
}
|
|
3309
|
+
function getParentCondition(node) {
|
|
3310
|
+
while (true) if (node.type === 19) if (node.alternate.type === 19) node = node.alternate;
|
|
3311
|
+
else return node;
|
|
3312
|
+
else if (node.type === 20) node = node.value;
|
|
3313
|
+
}
|
|
3314
|
+
|
|
3315
|
+
//#endregion
|
|
3316
|
+
//#region packages/compiler-core/src/transforms/vFor.ts
|
|
3317
|
+
const transformFor = createStructuralDirectiveTransform("for", (node, dir, context) => {
|
|
3318
|
+
const { helper, removeHelper } = context;
|
|
3319
|
+
return processFor(node, dir, context, (forNode) => {
|
|
3320
|
+
const renderExp = createCallExpression(helper(RENDER_LIST), [forNode.source]);
|
|
3321
|
+
const isTemplate = isTemplateNode(node);
|
|
3322
|
+
const memo = findDir(node, "memo");
|
|
3323
|
+
const keyProp = findProp(node, `key`, false, true);
|
|
3324
|
+
const isDirKey = keyProp && keyProp.type === 7;
|
|
3325
|
+
let keyExp = keyProp && (keyProp.type === 6 ? keyProp.value ? createSimpleExpression(keyProp.value.content, true) : void 0 : keyProp.exp);
|
|
3326
|
+
if (memo && keyExp && isDirKey) {}
|
|
3327
|
+
const keyProperty = keyProp && keyExp ? createObjectProperty(`key`, keyExp) : null;
|
|
3328
|
+
const isStableFragment = forNode.source.type === 4 && forNode.source.constType > 0;
|
|
3329
|
+
const fragmentFlag = isStableFragment ? 64 : keyProp ? 128 : 256;
|
|
3330
|
+
forNode.codegenNode = createVNodeCall(context, helper(FRAGMENT), void 0, renderExp, fragmentFlag, void 0, void 0, true, !isStableFragment, false, node.loc);
|
|
3331
|
+
return () => {
|
|
3332
|
+
let childBlock;
|
|
3333
|
+
const { children } = forNode;
|
|
3334
|
+
if ((!!(process.env.NODE_ENV !== "production") || false) && isTemplate) node.children.some((c) => {
|
|
3335
|
+
if (c.type === 1) {
|
|
3336
|
+
const key = findProp(c, "key");
|
|
3337
|
+
if (key) {
|
|
3338
|
+
context.onError(createCompilerError(33, key.loc));
|
|
3339
|
+
return true;
|
|
3340
|
+
}
|
|
3341
|
+
}
|
|
3342
|
+
});
|
|
3343
|
+
const needFragmentWrapper = children.length !== 1 || children[0].type !== 1;
|
|
3344
|
+
const slotOutlet = isSlotOutlet(node) ? node : isTemplate && node.children.length === 1 && isSlotOutlet(node.children[0]) ? node.children[0] : null;
|
|
3345
|
+
if (slotOutlet) {
|
|
3346
|
+
childBlock = slotOutlet.codegenNode;
|
|
3347
|
+
if (isTemplate && keyProperty) injectProp(childBlock, keyProperty, context);
|
|
3348
|
+
} else if (needFragmentWrapper) childBlock = createVNodeCall(context, helper(FRAGMENT), keyProperty ? createObjectExpression([keyProperty]) : void 0, node.children, 64, void 0, void 0, true, void 0, false);
|
|
3349
|
+
else {
|
|
3350
|
+
childBlock = children[0].codegenNode;
|
|
3351
|
+
if (isTemplate && keyProperty) injectProp(childBlock, keyProperty, context);
|
|
3352
|
+
if (childBlock.isBlock !== !isStableFragment) if (childBlock.isBlock) {
|
|
3353
|
+
removeHelper(OPEN_BLOCK);
|
|
3354
|
+
removeHelper(getVNodeBlockHelper(context.inSSR, childBlock.isComponent));
|
|
3355
|
+
} else removeHelper(getVNodeHelper(context.inSSR, childBlock.isComponent));
|
|
3356
|
+
childBlock.isBlock = !isStableFragment;
|
|
3357
|
+
if (childBlock.isBlock) {
|
|
3358
|
+
helper(OPEN_BLOCK);
|
|
3359
|
+
helper(getVNodeBlockHelper(context.inSSR, childBlock.isComponent));
|
|
3360
|
+
} else helper(getVNodeHelper(context.inSSR, childBlock.isComponent));
|
|
3361
|
+
}
|
|
3362
|
+
if (memo) {
|
|
3363
|
+
const loop = createFunctionExpression(createForLoopParams(forNode.parseResult, [createSimpleExpression(`_cached`)]));
|
|
3364
|
+
loop.body = createBlockStatement([
|
|
3365
|
+
createCompoundExpression([
|
|
3366
|
+
`const _memo = (`,
|
|
3367
|
+
memo.exp,
|
|
3368
|
+
`)`
|
|
3369
|
+
]),
|
|
3370
|
+
createCompoundExpression([
|
|
3371
|
+
`if (_cached`,
|
|
3372
|
+
...keyExp ? [` && _cached.key === `, keyExp] : [],
|
|
3373
|
+
` && ${context.helperString(IS_MEMO_SAME)}(_cached, _memo)) return _cached`
|
|
3374
|
+
]),
|
|
3375
|
+
createCompoundExpression([`const _item = `, childBlock]),
|
|
3376
|
+
createSimpleExpression(`_item.memo = _memo`),
|
|
3377
|
+
createSimpleExpression(`return _item`)
|
|
3378
|
+
]);
|
|
3379
|
+
renderExp.arguments.push(loop, createSimpleExpression(`_cache`), createSimpleExpression(String(context.cached.length)));
|
|
3380
|
+
context.cached.push(null);
|
|
3381
|
+
} else renderExp.arguments.push(createFunctionExpression(createForLoopParams(forNode.parseResult), childBlock, true));
|
|
3382
|
+
};
|
|
3383
|
+
});
|
|
3384
|
+
});
|
|
3385
|
+
function processFor(node, dir, context, processCodegen) {
|
|
3386
|
+
if (!dir.exp) {
|
|
3387
|
+
context.onError(createCompilerError(31, dir.loc));
|
|
3388
|
+
return;
|
|
3389
|
+
}
|
|
3390
|
+
const parseResult = dir.forParseResult;
|
|
3391
|
+
if (!parseResult) {
|
|
3392
|
+
context.onError(createCompilerError(32, dir.loc));
|
|
3393
|
+
return;
|
|
3394
|
+
}
|
|
3395
|
+
finalizeForParseResult(parseResult, context);
|
|
3396
|
+
const { addIdentifiers, removeIdentifiers, scopes } = context;
|
|
3397
|
+
const { source, value, key, index } = parseResult;
|
|
3398
|
+
const forNode = {
|
|
3399
|
+
type: 11,
|
|
3400
|
+
loc: dir.loc,
|
|
3401
|
+
source,
|
|
3402
|
+
valueAlias: value,
|
|
3403
|
+
keyAlias: key,
|
|
3404
|
+
objectIndexAlias: index,
|
|
3405
|
+
parseResult,
|
|
3406
|
+
children: isTemplateNode(node) ? node.children : [node]
|
|
3407
|
+
};
|
|
3408
|
+
context.replaceNode(forNode);
|
|
3409
|
+
scopes.vFor++;
|
|
3410
|
+
const onExit = processCodegen && processCodegen(forNode);
|
|
3411
|
+
return () => {
|
|
3412
|
+
scopes.vFor--;
|
|
3413
|
+
if (onExit) onExit();
|
|
3414
|
+
};
|
|
3415
|
+
}
|
|
3416
|
+
function finalizeForParseResult(result, context) {
|
|
3417
|
+
if (result.finalized) return;
|
|
3418
|
+
if (!!(process.env.NODE_ENV !== "production") && true) {
|
|
3419
|
+
validateBrowserExpression(result.source, context);
|
|
3420
|
+
if (result.key) validateBrowserExpression(result.key, context, true);
|
|
3421
|
+
if (result.index) validateBrowserExpression(result.index, context, true);
|
|
3422
|
+
if (result.value) validateBrowserExpression(result.value, context, true);
|
|
3423
|
+
}
|
|
3424
|
+
result.finalized = true;
|
|
3425
|
+
}
|
|
3426
|
+
function createForLoopParams({ value, key, index }, memoArgs = []) {
|
|
3427
|
+
return createParamsList([
|
|
3428
|
+
value,
|
|
3429
|
+
key,
|
|
3430
|
+
index,
|
|
3431
|
+
...memoArgs
|
|
3432
|
+
]);
|
|
3433
|
+
}
|
|
3434
|
+
function createParamsList(args) {
|
|
3435
|
+
let i = args.length;
|
|
3436
|
+
while (i--) if (args[i]) break;
|
|
3437
|
+
return args.slice(0, i + 1).map((arg, i) => arg || createSimpleExpression(`_`.repeat(i + 1), false));
|
|
3438
|
+
}
|
|
3439
|
+
|
|
3440
|
+
//#endregion
|
|
3441
|
+
//#region packages/compiler-core/src/transforms/vSlot.ts
|
|
3442
|
+
const defaultFallback = createSimpleExpression(`undefined`, false);
|
|
3443
|
+
const trackSlotScopes = (node, context) => {
|
|
3444
|
+
if (node.type === 1 && (node.tagType === 1 || node.tagType === 3)) {
|
|
3445
|
+
const vSlot = findDir(node, "slot");
|
|
3446
|
+
if (vSlot) {
|
|
3447
|
+
vSlot.exp;
|
|
3448
|
+
context.scopes.vSlot++;
|
|
3449
|
+
return () => {
|
|
3450
|
+
context.scopes.vSlot--;
|
|
3451
|
+
};
|
|
3452
|
+
}
|
|
3453
|
+
}
|
|
3454
|
+
};
|
|
3455
|
+
const trackVForSlotScopes = (node, context) => {
|
|
3456
|
+
let vFor;
|
|
3457
|
+
if (isTemplateNode(node) && node.props.some(isVSlot) && (vFor = findDir(node, "for"))) {
|
|
3458
|
+
const result = vFor.forParseResult;
|
|
3459
|
+
if (result) {
|
|
3460
|
+
finalizeForParseResult(result, context);
|
|
3461
|
+
const { value, key, index } = result;
|
|
3462
|
+
const { addIdentifiers, removeIdentifiers } = context;
|
|
3463
|
+
value && addIdentifiers(value);
|
|
3464
|
+
key && addIdentifiers(key);
|
|
3465
|
+
index && addIdentifiers(index);
|
|
3466
|
+
return () => {
|
|
3467
|
+
value && removeIdentifiers(value);
|
|
3468
|
+
key && removeIdentifiers(key);
|
|
3469
|
+
index && removeIdentifiers(index);
|
|
3470
|
+
};
|
|
3471
|
+
}
|
|
3472
|
+
}
|
|
3473
|
+
};
|
|
3474
|
+
const buildClientSlotFn = (props, _vForExp, children, loc) => createFunctionExpression(props, children, false, true, children.length ? children[0].loc : loc);
|
|
3475
|
+
function buildSlots(node, context, buildSlotFn = buildClientSlotFn) {
|
|
3476
|
+
context.helper(WITH_CTX);
|
|
3477
|
+
const { children, loc } = node;
|
|
3478
|
+
const slotsProperties = [];
|
|
3479
|
+
const dynamicSlots = [];
|
|
3480
|
+
let hasDynamicSlots = context.scopes.vSlot > 0 || context.scopes.vFor > 0;
|
|
3481
|
+
const onComponentSlot = findDir(node, "slot", true);
|
|
3482
|
+
if (onComponentSlot) {
|
|
3483
|
+
const { arg, exp } = onComponentSlot;
|
|
3484
|
+
if (arg && !isStaticExp(arg)) hasDynamicSlots = true;
|
|
3485
|
+
slotsProperties.push(createObjectProperty(arg || createSimpleExpression("default", true), buildSlotFn(exp, void 0, children, loc)));
|
|
3486
|
+
}
|
|
3487
|
+
let hasTemplateSlots = false;
|
|
3488
|
+
let hasNamedDefaultSlot = false;
|
|
3489
|
+
const implicitDefaultChildren = [];
|
|
3490
|
+
const seenSlotNames = /* @__PURE__ */ new Set();
|
|
3491
|
+
let conditionalBranchIndex = 0;
|
|
3492
|
+
for (let i = 0; i < children.length; i++) {
|
|
3493
|
+
const slotElement = children[i];
|
|
3494
|
+
let slotDir;
|
|
3495
|
+
if (!isTemplateNode(slotElement) || !(slotDir = findDir(slotElement, "slot", true))) {
|
|
3496
|
+
if (slotElement.type !== 3) implicitDefaultChildren.push(slotElement);
|
|
3497
|
+
continue;
|
|
3498
|
+
}
|
|
3499
|
+
if (onComponentSlot) {
|
|
3500
|
+
context.onError(createCompilerError(37, slotDir.loc));
|
|
3501
|
+
break;
|
|
3502
|
+
}
|
|
3503
|
+
hasTemplateSlots = true;
|
|
3504
|
+
const { children: slotChildren, loc: slotLoc } = slotElement;
|
|
3505
|
+
const { arg: slotName = createSimpleExpression(`default`, true), exp: slotProps, loc: dirLoc } = slotDir;
|
|
3506
|
+
let staticSlotName;
|
|
3507
|
+
if (isStaticExp(slotName)) staticSlotName = slotName ? slotName.content : `default`;
|
|
3508
|
+
else hasDynamicSlots = true;
|
|
3509
|
+
const vFor = findDir(slotElement, "for");
|
|
3510
|
+
const slotFunction = buildSlotFn(slotProps, vFor, slotChildren, slotLoc);
|
|
3511
|
+
let vIf;
|
|
3512
|
+
let vElse;
|
|
3513
|
+
if (vIf = findDir(slotElement, "if")) {
|
|
3514
|
+
hasDynamicSlots = true;
|
|
3515
|
+
dynamicSlots.push(createConditionalExpression(vIf.exp, buildDynamicSlot(slotName, slotFunction, conditionalBranchIndex++), defaultFallback));
|
|
3516
|
+
} else if (vElse = findDir(slotElement, /^else(?:-if)?$/, true)) {
|
|
3517
|
+
let j = i;
|
|
3518
|
+
let prev;
|
|
3519
|
+
while (j--) {
|
|
3520
|
+
prev = children[j];
|
|
3521
|
+
if (!isCommentOrWhitespace(prev)) break;
|
|
3522
|
+
}
|
|
3523
|
+
if (prev && isTemplateNode(prev) && findDir(prev, /^(?:else-)?if$/)) {
|
|
3524
|
+
let conditional = dynamicSlots[dynamicSlots.length - 1];
|
|
3525
|
+
while (conditional.alternate.type === 19) conditional = conditional.alternate;
|
|
3526
|
+
conditional.alternate = vElse.exp ? createConditionalExpression(vElse.exp, buildDynamicSlot(slotName, slotFunction, conditionalBranchIndex++), defaultFallback) : buildDynamicSlot(slotName, slotFunction, conditionalBranchIndex++);
|
|
3527
|
+
} else context.onError(createCompilerError(30, vElse.loc));
|
|
3528
|
+
} else if (vFor) {
|
|
3529
|
+
hasDynamicSlots = true;
|
|
3530
|
+
const parseResult = vFor.forParseResult;
|
|
3531
|
+
if (parseResult) {
|
|
3532
|
+
finalizeForParseResult(parseResult, context);
|
|
3533
|
+
dynamicSlots.push(createCallExpression(context.helper(RENDER_LIST), [parseResult.source, createFunctionExpression(createForLoopParams(parseResult), buildDynamicSlot(slotName, slotFunction), true)]));
|
|
3534
|
+
} else context.onError(createCompilerError(32, vFor.loc));
|
|
3535
|
+
} else {
|
|
3536
|
+
if (staticSlotName) {
|
|
3537
|
+
if (seenSlotNames.has(staticSlotName)) {
|
|
3538
|
+
context.onError(createCompilerError(38, dirLoc));
|
|
3539
|
+
continue;
|
|
3540
|
+
}
|
|
3541
|
+
seenSlotNames.add(staticSlotName);
|
|
3542
|
+
if (staticSlotName === "default") hasNamedDefaultSlot = true;
|
|
3543
|
+
}
|
|
3544
|
+
slotsProperties.push(createObjectProperty(slotName, slotFunction));
|
|
3545
|
+
}
|
|
3546
|
+
}
|
|
3547
|
+
if (!onComponentSlot) {
|
|
3548
|
+
const buildDefaultSlotProperty = (props, children) => {
|
|
3549
|
+
const fn = buildSlotFn(props, void 0, children, loc);
|
|
3550
|
+
if (context.compatConfig) fn.isNonScopedSlot = true;
|
|
3551
|
+
return createObjectProperty(`default`, fn);
|
|
3552
|
+
};
|
|
3553
|
+
if (!hasTemplateSlots) slotsProperties.push(buildDefaultSlotProperty(void 0, children));
|
|
3554
|
+
else if (implicitDefaultChildren.length && !implicitDefaultChildren.every(isWhitespaceText)) if (hasNamedDefaultSlot) context.onError(createCompilerError(39, implicitDefaultChildren[0].loc));
|
|
3555
|
+
else slotsProperties.push(buildDefaultSlotProperty(void 0, implicitDefaultChildren));
|
|
3556
|
+
}
|
|
3557
|
+
const slotFlag = hasDynamicSlots ? 2 : hasForwardedSlots(node.children) ? 3 : 1;
|
|
3558
|
+
let slots = createObjectExpression(slotsProperties.concat(createObjectProperty(`_`, createSimpleExpression(slotFlag + (!!(process.env.NODE_ENV !== "production") ? ` /* ${slotFlagsText[slotFlag]} */` : ``), false))), loc);
|
|
3559
|
+
if (dynamicSlots.length) slots = createCallExpression(context.helper(CREATE_SLOTS), [slots, createArrayExpression(dynamicSlots)]);
|
|
3560
|
+
return {
|
|
3561
|
+
slots,
|
|
3562
|
+
hasDynamicSlots
|
|
3563
|
+
};
|
|
3564
|
+
}
|
|
3565
|
+
function buildDynamicSlot(name, fn, index) {
|
|
3566
|
+
const props = [createObjectProperty(`name`, name), createObjectProperty(`fn`, fn)];
|
|
3567
|
+
if (index != null) props.push(createObjectProperty(`key`, createSimpleExpression(String(index), true)));
|
|
3568
|
+
return createObjectExpression(props);
|
|
3569
|
+
}
|
|
3570
|
+
function hasForwardedSlots(children) {
|
|
3571
|
+
for (let i = 0; i < children.length; i++) {
|
|
3572
|
+
const child = children[i];
|
|
3573
|
+
switch (child.type) {
|
|
3574
|
+
case 1:
|
|
3575
|
+
if (child.tagType === 2 || hasForwardedSlots(child.children)) return true;
|
|
3576
|
+
break;
|
|
3577
|
+
case 9:
|
|
3578
|
+
if (hasForwardedSlots(child.branches)) return true;
|
|
3579
|
+
break;
|
|
3580
|
+
case 10:
|
|
3581
|
+
case 11:
|
|
3582
|
+
if (hasForwardedSlots(child.children)) return true;
|
|
3583
|
+
break;
|
|
3584
|
+
default: break;
|
|
3585
|
+
}
|
|
3586
|
+
}
|
|
3587
|
+
return false;
|
|
3588
|
+
}
|
|
3589
|
+
|
|
3590
|
+
//#endregion
|
|
3591
|
+
//#region packages/compiler-core/src/transforms/transformElement.ts
|
|
3592
|
+
const directiveImportMap = /* @__PURE__ */ new WeakMap();
|
|
3593
|
+
const transformElement = (node, context) => {
|
|
3594
|
+
return function postTransformElement() {
|
|
3595
|
+
node = context.currentNode;
|
|
3596
|
+
if (!(node.type === 1 && (node.tagType === 0 || node.tagType === 1))) return;
|
|
3597
|
+
const { tag, props } = node;
|
|
3598
|
+
const isComponent = node.tagType === 1;
|
|
3599
|
+
let vnodeTag = isComponent ? resolveComponentType(node, context) : `"${tag}"`;
|
|
3600
|
+
const isDynamicComponent = isObject(vnodeTag) && vnodeTag.callee === RESOLVE_DYNAMIC_COMPONENT;
|
|
3601
|
+
let vnodeProps;
|
|
3602
|
+
let vnodeChildren;
|
|
3603
|
+
let patchFlag = 0;
|
|
3604
|
+
let vnodeDynamicProps;
|
|
3605
|
+
let dynamicPropNames;
|
|
3606
|
+
let vnodeDirectives;
|
|
3607
|
+
let shouldUseBlock = isDynamicComponent || vnodeTag === TELEPORT || vnodeTag === SUSPENSE || !isComponent && (tag === "svg" || tag === "foreignObject" || tag === "math");
|
|
3608
|
+
if (props.length > 0) {
|
|
3609
|
+
const propsBuildResult = buildProps(node, context, void 0, isComponent, isDynamicComponent);
|
|
3610
|
+
vnodeProps = propsBuildResult.props;
|
|
3611
|
+
patchFlag = propsBuildResult.patchFlag;
|
|
3612
|
+
dynamicPropNames = propsBuildResult.dynamicPropNames;
|
|
3613
|
+
const directives = propsBuildResult.directives;
|
|
3614
|
+
vnodeDirectives = directives && directives.length ? createArrayExpression(directives.map((dir) => buildDirectiveArgs(dir, context))) : void 0;
|
|
3615
|
+
if (propsBuildResult.shouldUseBlock) shouldUseBlock = true;
|
|
3616
|
+
}
|
|
3617
|
+
if (node.children.length > 0) {
|
|
3618
|
+
if (vnodeTag === KEEP_ALIVE) {
|
|
3619
|
+
shouldUseBlock = true;
|
|
3620
|
+
patchFlag |= 1024;
|
|
3621
|
+
if (!!(process.env.NODE_ENV !== "production") && node.children.length > 1) context.onError(createCompilerError(47, {
|
|
3622
|
+
start: node.children[0].loc.start,
|
|
3623
|
+
end: node.children[node.children.length - 1].loc.end,
|
|
3624
|
+
source: ""
|
|
3625
|
+
}));
|
|
3626
|
+
}
|
|
3627
|
+
if (isComponent && vnodeTag !== TELEPORT && vnodeTag !== KEEP_ALIVE) {
|
|
3628
|
+
const { slots, hasDynamicSlots } = buildSlots(node, context);
|
|
3629
|
+
vnodeChildren = slots;
|
|
3630
|
+
if (hasDynamicSlots) patchFlag |= 1024;
|
|
3631
|
+
} else if (node.children.length === 1 && vnodeTag !== TELEPORT) {
|
|
3632
|
+
const child = node.children[0];
|
|
3633
|
+
const type = child.type;
|
|
3634
|
+
const hasDynamicTextChild = type === 5 || type === 8;
|
|
3635
|
+
if (hasDynamicTextChild && getConstantType(child, context) === 0) patchFlag |= 1;
|
|
3636
|
+
if (hasDynamicTextChild || type === 2) vnodeChildren = child;
|
|
3637
|
+
else vnodeChildren = node.children;
|
|
3638
|
+
} else vnodeChildren = node.children;
|
|
3639
|
+
}
|
|
3640
|
+
if (dynamicPropNames && dynamicPropNames.length) vnodeDynamicProps = stringifyDynamicPropNames(dynamicPropNames);
|
|
3641
|
+
node.codegenNode = createVNodeCall(context, vnodeTag, vnodeProps, vnodeChildren, patchFlag === 0 ? void 0 : patchFlag, vnodeDynamicProps, vnodeDirectives, !!shouldUseBlock, false, isComponent, node.loc);
|
|
3642
|
+
};
|
|
3643
|
+
};
|
|
3644
|
+
function resolveComponentType(node, context, ssr = false) {
|
|
3645
|
+
let { tag } = node;
|
|
3646
|
+
const isExplicitDynamic = isComponentTag(tag);
|
|
3647
|
+
const isProp = findProp(node, "is", false, true);
|
|
3648
|
+
if (isProp) {
|
|
3649
|
+
if (isExplicitDynamic || isCompatEnabled("COMPILER_IS_ON_ELEMENT", context)) {
|
|
3650
|
+
let exp;
|
|
3651
|
+
if (isProp.type === 6) exp = isProp.value && createSimpleExpression(isProp.value.content, true);
|
|
3652
|
+
else {
|
|
3653
|
+
exp = isProp.exp;
|
|
3654
|
+
if (!exp) exp = createSimpleExpression(`is`, false, isProp.arg.loc);
|
|
3655
|
+
}
|
|
3656
|
+
if (exp) return createCallExpression(context.helper(RESOLVE_DYNAMIC_COMPONENT), [exp]);
|
|
3657
|
+
} else if (isProp.type === 6 && isProp.value.content.startsWith("vue:")) tag = isProp.value.content.slice(4);
|
|
3658
|
+
}
|
|
3659
|
+
const builtIn = isCoreComponent(tag) || context.isBuiltInComponent(tag);
|
|
3660
|
+
if (builtIn) {
|
|
3661
|
+
if (!ssr) context.helper(builtIn);
|
|
3662
|
+
return builtIn;
|
|
3663
|
+
}
|
|
3664
|
+
context.helper(RESOLVE_COMPONENT);
|
|
3665
|
+
context.components.add(tag);
|
|
3666
|
+
return toValidAssetId(tag, `component`);
|
|
3667
|
+
}
|
|
3668
|
+
function buildProps(node, context, props = node.props, isComponent, isDynamicComponent, ssr = false) {
|
|
3669
|
+
const { tag, loc: elementLoc, children } = node;
|
|
3670
|
+
let properties = [];
|
|
3671
|
+
const mergeArgs = [];
|
|
3672
|
+
const runtimeDirectives = [];
|
|
3673
|
+
const hasChildren = children.length > 0;
|
|
3674
|
+
let shouldUseBlock = false;
|
|
3675
|
+
let patchFlag = 0;
|
|
3676
|
+
let hasRef = false;
|
|
3677
|
+
let hasClassBinding = false;
|
|
3678
|
+
let hasStyleBinding = false;
|
|
3679
|
+
let hasHydrationEventBinding = false;
|
|
3680
|
+
let hasDynamicKeys = false;
|
|
3681
|
+
let hasVnodeHook = false;
|
|
3682
|
+
const dynamicPropNames = [];
|
|
3683
|
+
const pushMergeArg = (arg) => {
|
|
3684
|
+
if (properties.length) {
|
|
3685
|
+
mergeArgs.push(createObjectExpression(dedupeProperties(properties), elementLoc));
|
|
3686
|
+
properties = [];
|
|
3687
|
+
}
|
|
3688
|
+
if (arg) mergeArgs.push(arg);
|
|
3689
|
+
};
|
|
3690
|
+
const pushRefVForMarker = () => {
|
|
3691
|
+
if (context.scopes.vFor > 0) properties.push(createObjectProperty(createSimpleExpression("ref_for", true), createSimpleExpression("true")));
|
|
3692
|
+
};
|
|
3693
|
+
const analyzePatchFlag = ({ key, value }) => {
|
|
3694
|
+
if (isStaticExp(key)) {
|
|
3695
|
+
const name = key.content;
|
|
3696
|
+
const isEventHandler = isOn(name);
|
|
3697
|
+
if (isEventHandler && (!isComponent || isDynamicComponent) && name.toLowerCase() !== "onclick" && name !== "onUpdate:modelValue" && !isReservedProp(name)) hasHydrationEventBinding = true;
|
|
3698
|
+
if (isEventHandler && isReservedProp(name)) hasVnodeHook = true;
|
|
3699
|
+
if (isEventHandler && value.type === 14) value = value.arguments[0];
|
|
3700
|
+
if (value.type === 20 || (value.type === 4 || value.type === 8) && getConstantType(value, context) > 0) return;
|
|
3701
|
+
if (name === "ref") hasRef = true;
|
|
3702
|
+
else if (name === "class") hasClassBinding = true;
|
|
3703
|
+
else if (name === "style") hasStyleBinding = true;
|
|
3704
|
+
else if (name !== "key" && !dynamicPropNames.includes(name)) dynamicPropNames.push(name);
|
|
3705
|
+
if (isComponent && (name === "class" || name === "style") && !dynamicPropNames.includes(name)) dynamicPropNames.push(name);
|
|
3706
|
+
} else hasDynamicKeys = true;
|
|
3707
|
+
};
|
|
3708
|
+
for (let i = 0; i < props.length; i++) {
|
|
3709
|
+
const prop = props[i];
|
|
3710
|
+
if (prop.type === 6) {
|
|
3711
|
+
const { loc, name, nameLoc, value } = prop;
|
|
3712
|
+
let isStatic = true;
|
|
3713
|
+
if (name === "ref") {
|
|
3714
|
+
hasRef = true;
|
|
3715
|
+
pushRefVForMarker();
|
|
3716
|
+
}
|
|
3717
|
+
if (name === "is" && (isComponentTag(tag) || value && value.content.startsWith("vue:") || isCompatEnabled("COMPILER_IS_ON_ELEMENT", context))) continue;
|
|
3718
|
+
properties.push(createObjectProperty(createSimpleExpression(name, true, nameLoc), createSimpleExpression(value ? value.content : "", isStatic, value ? value.loc : loc)));
|
|
3719
|
+
} else {
|
|
3720
|
+
const { name, arg, exp, loc, modifiers } = prop;
|
|
3721
|
+
const isVBind = name === "bind";
|
|
3722
|
+
const isVOn = name === "on";
|
|
3723
|
+
if (name === "slot") {
|
|
3724
|
+
if (!isComponent) context.onError(createCompilerError(40, loc));
|
|
3725
|
+
continue;
|
|
3726
|
+
}
|
|
3727
|
+
if (name === "once" || name === "memo") continue;
|
|
3728
|
+
if (name === "is" || isVBind && isStaticArgOf(arg, "is") && (isComponentTag(tag) || isCompatEnabled("COMPILER_IS_ON_ELEMENT", context))) continue;
|
|
3729
|
+
if (isVOn && ssr) continue;
|
|
3730
|
+
if (isVBind && isStaticArgOf(arg, "key") || isVOn && hasChildren && isStaticArgOf(arg, "vue:before-update")) shouldUseBlock = true;
|
|
3731
|
+
if (isVBind && isStaticArgOf(arg, "ref")) pushRefVForMarker();
|
|
3732
|
+
if (!arg && (isVBind || isVOn)) {
|
|
3733
|
+
hasDynamicKeys = true;
|
|
3734
|
+
if (exp) if (isVBind) {
|
|
3735
|
+
pushMergeArg();
|
|
3736
|
+
if (!!(process.env.NODE_ENV !== "production")) {
|
|
3737
|
+
if (mergeArgs.some((arg) => {
|
|
3738
|
+
if (arg.type === 15) return arg.properties.some(({ key }) => {
|
|
3739
|
+
if (key.type !== 4 || !key.isStatic) return true;
|
|
3740
|
+
return key.content !== "class" && key.content !== "style" && !isOn(key.content);
|
|
3741
|
+
});
|
|
3742
|
+
else return true;
|
|
3743
|
+
})) checkCompatEnabled("COMPILER_V_BIND_OBJECT_ORDER", context, loc);
|
|
3744
|
+
}
|
|
3745
|
+
if (isCompatEnabled("COMPILER_V_BIND_OBJECT_ORDER", context)) {
|
|
3746
|
+
mergeArgs.unshift(exp);
|
|
3747
|
+
continue;
|
|
3748
|
+
}
|
|
3749
|
+
pushRefVForMarker();
|
|
3750
|
+
pushMergeArg();
|
|
3751
|
+
mergeArgs.push(exp);
|
|
3752
|
+
} else pushMergeArg({
|
|
3753
|
+
type: 14,
|
|
3754
|
+
loc,
|
|
3755
|
+
callee: context.helper(TO_HANDLERS),
|
|
3756
|
+
arguments: isComponent ? [exp] : [exp, `true`]
|
|
3757
|
+
});
|
|
3758
|
+
else context.onError(createCompilerError(isVBind ? 34 : 35, loc));
|
|
3759
|
+
continue;
|
|
3760
|
+
}
|
|
3761
|
+
if (isVBind && modifiers.some((mod) => mod.content === "prop")) patchFlag |= 32;
|
|
3762
|
+
const directiveTransform = context.directiveTransforms[name];
|
|
3763
|
+
if (directiveTransform) {
|
|
3764
|
+
const { props, needRuntime } = directiveTransform(prop, node, context);
|
|
3765
|
+
!ssr && props.forEach(analyzePatchFlag);
|
|
3766
|
+
if (isVOn && arg && !isStaticExp(arg)) pushMergeArg(createObjectExpression(props, elementLoc));
|
|
3767
|
+
else properties.push(...props);
|
|
3768
|
+
if (needRuntime) {
|
|
3769
|
+
runtimeDirectives.push(prop);
|
|
3770
|
+
if (isSymbol(needRuntime)) directiveImportMap.set(prop, needRuntime);
|
|
3771
|
+
}
|
|
3772
|
+
} else if (!isBuiltInDirective(name)) {
|
|
3773
|
+
runtimeDirectives.push(prop);
|
|
3774
|
+
if (hasChildren) shouldUseBlock = true;
|
|
3775
|
+
}
|
|
3776
|
+
}
|
|
3777
|
+
}
|
|
3778
|
+
let propsExpression = void 0;
|
|
3779
|
+
if (mergeArgs.length) {
|
|
3780
|
+
pushMergeArg();
|
|
3781
|
+
if (mergeArgs.length > 1) propsExpression = createCallExpression(context.helper(MERGE_PROPS), mergeArgs, elementLoc);
|
|
3782
|
+
else propsExpression = mergeArgs[0];
|
|
3783
|
+
} else if (properties.length) propsExpression = createObjectExpression(dedupeProperties(properties), elementLoc);
|
|
3784
|
+
if (hasDynamicKeys) patchFlag |= 16;
|
|
3785
|
+
else {
|
|
3786
|
+
if (hasClassBinding && !isComponent) patchFlag |= 2;
|
|
3787
|
+
if (hasStyleBinding && !isComponent) patchFlag |= 4;
|
|
3788
|
+
if (dynamicPropNames.length) patchFlag |= 8;
|
|
3789
|
+
if (hasHydrationEventBinding) patchFlag |= 32;
|
|
3790
|
+
}
|
|
3791
|
+
if (!shouldUseBlock && (patchFlag === 0 || patchFlag === 32) && (hasRef || hasVnodeHook || runtimeDirectives.length > 0)) patchFlag |= 512;
|
|
3792
|
+
if (!context.inSSR && propsExpression) switch (propsExpression.type) {
|
|
3793
|
+
case 15:
|
|
3794
|
+
let classKeyIndex = -1;
|
|
3795
|
+
let styleKeyIndex = -1;
|
|
3796
|
+
let hasDynamicKey = false;
|
|
3797
|
+
for (let i = 0; i < propsExpression.properties.length; i++) {
|
|
3798
|
+
const key = propsExpression.properties[i].key;
|
|
3799
|
+
if (isStaticExp(key)) {
|
|
3800
|
+
if (key.content === "class") classKeyIndex = i;
|
|
3801
|
+
else if (key.content === "style") styleKeyIndex = i;
|
|
3802
|
+
} else if (!key.isHandlerKey) hasDynamicKey = true;
|
|
3803
|
+
}
|
|
3804
|
+
const classProp = propsExpression.properties[classKeyIndex];
|
|
3805
|
+
const styleProp = propsExpression.properties[styleKeyIndex];
|
|
3806
|
+
if (!hasDynamicKey) {
|
|
3807
|
+
if (classProp && !isStaticExp(classProp.value)) classProp.value = createCallExpression(context.helper(NORMALIZE_CLASS), [classProp.value]);
|
|
3808
|
+
if (styleProp && (hasStyleBinding || styleProp.value.type === 4 && styleProp.value.content.trim()[0] === `[` || styleProp.value.type === 17)) styleProp.value = createCallExpression(context.helper(NORMALIZE_STYLE), [styleProp.value]);
|
|
3809
|
+
} else propsExpression = createCallExpression(context.helper(NORMALIZE_PROPS), [propsExpression]);
|
|
3810
|
+
break;
|
|
3811
|
+
case 14: break;
|
|
3812
|
+
default:
|
|
3813
|
+
propsExpression = createCallExpression(context.helper(NORMALIZE_PROPS), [createCallExpression(context.helper(GUARD_REACTIVE_PROPS), [propsExpression])]);
|
|
3814
|
+
break;
|
|
3815
|
+
}
|
|
3816
|
+
return {
|
|
3817
|
+
props: propsExpression,
|
|
3818
|
+
directives: runtimeDirectives,
|
|
3819
|
+
patchFlag,
|
|
3820
|
+
dynamicPropNames,
|
|
3821
|
+
shouldUseBlock
|
|
3822
|
+
};
|
|
3823
|
+
}
|
|
3824
|
+
function dedupeProperties(properties) {
|
|
3825
|
+
const knownProps = /* @__PURE__ */ new Map();
|
|
3826
|
+
const deduped = [];
|
|
3827
|
+
for (let i = 0; i < properties.length; i++) {
|
|
3828
|
+
const prop = properties[i];
|
|
3829
|
+
if (prop.key.type === 8 || !prop.key.isStatic) {
|
|
3830
|
+
deduped.push(prop);
|
|
3831
|
+
continue;
|
|
3832
|
+
}
|
|
3833
|
+
const name = prop.key.content;
|
|
3834
|
+
const existing = knownProps.get(name);
|
|
3835
|
+
if (existing) {
|
|
3836
|
+
if (name === "style" || name === "class" || isOn(name)) mergeAsArray(existing, prop);
|
|
3837
|
+
} else {
|
|
3838
|
+
knownProps.set(name, prop);
|
|
3839
|
+
deduped.push(prop);
|
|
3840
|
+
}
|
|
3841
|
+
}
|
|
3842
|
+
return deduped;
|
|
3843
|
+
}
|
|
3844
|
+
function mergeAsArray(existing, incoming) {
|
|
3845
|
+
if (existing.value.type === 17) existing.value.elements.push(incoming.value);
|
|
3846
|
+
else existing.value = createArrayExpression([existing.value, incoming.value], existing.loc);
|
|
3847
|
+
}
|
|
3848
|
+
function buildDirectiveArgs(dir, context) {
|
|
3849
|
+
const dirArgs = [];
|
|
3850
|
+
const runtime = directiveImportMap.get(dir);
|
|
3851
|
+
if (runtime) dirArgs.push(context.helperString(runtime));
|
|
3852
|
+
else {
|
|
3853
|
+
context.helper(RESOLVE_DIRECTIVE);
|
|
3854
|
+
context.directives.add(dir.name);
|
|
3855
|
+
dirArgs.push(toValidAssetId(dir.name, `directive`));
|
|
3856
|
+
}
|
|
3857
|
+
const { loc } = dir;
|
|
3858
|
+
if (dir.exp) dirArgs.push(dir.exp);
|
|
3859
|
+
if (dir.arg) {
|
|
3860
|
+
if (!dir.exp) dirArgs.push(`void 0`);
|
|
3861
|
+
dirArgs.push(dir.arg);
|
|
3862
|
+
}
|
|
3863
|
+
if (Object.keys(dir.modifiers).length) {
|
|
3864
|
+
if (!dir.arg) {
|
|
3865
|
+
if (!dir.exp) dirArgs.push(`void 0`);
|
|
3866
|
+
dirArgs.push(`void 0`);
|
|
3867
|
+
}
|
|
3868
|
+
const trueExpression = createSimpleExpression(`true`, false, loc);
|
|
3869
|
+
dirArgs.push(createObjectExpression(dir.modifiers.map((modifier) => createObjectProperty(modifier, trueExpression)), loc));
|
|
3870
|
+
}
|
|
3871
|
+
return createArrayExpression(dirArgs, dir.loc);
|
|
3872
|
+
}
|
|
3873
|
+
function stringifyDynamicPropNames(props) {
|
|
3874
|
+
let propsNamesString = `[`;
|
|
3875
|
+
for (let i = 0, l = props.length; i < l; i++) {
|
|
3876
|
+
propsNamesString += JSON.stringify(props[i]);
|
|
3877
|
+
if (i < l - 1) propsNamesString += ", ";
|
|
3878
|
+
}
|
|
3879
|
+
return propsNamesString + `]`;
|
|
3880
|
+
}
|
|
3881
|
+
function isComponentTag(tag) {
|
|
3882
|
+
return tag === "component" || tag === "Component";
|
|
3883
|
+
}
|
|
3884
|
+
|
|
3885
|
+
//#endregion
|
|
3886
|
+
//#region packages/compiler-core/src/transforms/transformSlotOutlet.ts
|
|
3887
|
+
const transformSlotOutlet = (node, context) => {
|
|
3888
|
+
if (isSlotOutlet(node)) {
|
|
3889
|
+
const { children, loc } = node;
|
|
3890
|
+
const { slotName, slotProps } = processSlotOutlet(node, context);
|
|
3891
|
+
const slotArgs = [
|
|
3892
|
+
context.prefixIdentifiers ? `_ctx.$slots` : `$slots`,
|
|
3893
|
+
slotName,
|
|
3894
|
+
"{}",
|
|
3895
|
+
"undefined",
|
|
3896
|
+
"true"
|
|
3897
|
+
];
|
|
3898
|
+
let expectedLen = 2;
|
|
3899
|
+
if (slotProps) {
|
|
3900
|
+
slotArgs[2] = slotProps;
|
|
3901
|
+
expectedLen = 3;
|
|
3902
|
+
}
|
|
3903
|
+
if (children.length) {
|
|
3904
|
+
slotArgs[3] = createFunctionExpression([], children, false, false, loc);
|
|
3905
|
+
expectedLen = 4;
|
|
3906
|
+
}
|
|
3907
|
+
if (context.scopeId && !context.slotted) expectedLen = 5;
|
|
3908
|
+
slotArgs.splice(expectedLen);
|
|
3909
|
+
node.codegenNode = createCallExpression(context.helper(RENDER_SLOT), slotArgs, loc);
|
|
3910
|
+
}
|
|
3911
|
+
};
|
|
3912
|
+
function processSlotOutlet(node, context) {
|
|
3913
|
+
let slotName = `"default"`;
|
|
3914
|
+
let slotProps = void 0;
|
|
3915
|
+
const nonNameProps = [];
|
|
3916
|
+
for (let i = 0; i < node.props.length; i++) {
|
|
3917
|
+
const p = node.props[i];
|
|
3918
|
+
if (p.type === 6) {
|
|
3919
|
+
if (p.value) if (p.name === "name") slotName = JSON.stringify(p.value.content);
|
|
3920
|
+
else {
|
|
3921
|
+
p.name = camelize(p.name);
|
|
3922
|
+
nonNameProps.push(p);
|
|
3923
|
+
}
|
|
3924
|
+
} else if (p.name === "bind" && isStaticArgOf(p.arg, "name")) {
|
|
3925
|
+
if (p.exp) slotName = p.exp;
|
|
3926
|
+
else if (p.arg && p.arg.type === 4) slotName = p.exp = createSimpleExpression(camelize(p.arg.content), false, p.arg.loc);
|
|
3927
|
+
} else {
|
|
3928
|
+
if (p.name === "bind" && p.arg && isStaticExp(p.arg)) p.arg.content = camelize(p.arg.content);
|
|
3929
|
+
nonNameProps.push(p);
|
|
3930
|
+
}
|
|
3931
|
+
}
|
|
3932
|
+
if (nonNameProps.length > 0) {
|
|
3933
|
+
const { props, directives } = buildProps(node, context, nonNameProps, false, false);
|
|
3934
|
+
slotProps = props;
|
|
3935
|
+
if (directives.length) context.onError(createCompilerError(36, directives[0].loc));
|
|
3936
|
+
}
|
|
3937
|
+
return {
|
|
3938
|
+
slotName,
|
|
3939
|
+
slotProps
|
|
3940
|
+
};
|
|
3941
|
+
}
|
|
3942
|
+
|
|
3943
|
+
//#endregion
|
|
3944
|
+
//#region packages/compiler-core/src/transforms/vOn.ts
|
|
3945
|
+
const transformOn = (dir, node, context, augmentor) => {
|
|
3946
|
+
const { loc, modifiers, arg } = dir;
|
|
3947
|
+
if (!dir.exp && !modifiers.length) context.onError(createCompilerError(35, loc));
|
|
3948
|
+
let eventName;
|
|
3949
|
+
if (arg.type === 4) if (arg.isStatic) {
|
|
3950
|
+
let rawName = arg.content;
|
|
3951
|
+
if (!!(process.env.NODE_ENV !== "production") && rawName.startsWith("vnode")) context.onError(createCompilerError(52, arg.loc));
|
|
3952
|
+
if (rawName.startsWith("vue:")) rawName = `vnode-${rawName.slice(4)}`;
|
|
3953
|
+
eventName = createSimpleExpression(node.tagType !== 0 || rawName.startsWith("vnode") || !/[A-Z]/.test(rawName) ? toHandlerKey(camelize(rawName)) : `on:${rawName}`, true, arg.loc);
|
|
3954
|
+
} else eventName = createCompoundExpression([
|
|
3955
|
+
`${context.helperString(TO_HANDLER_KEY)}(`,
|
|
3956
|
+
arg,
|
|
3957
|
+
`)`
|
|
3958
|
+
]);
|
|
3959
|
+
else {
|
|
3960
|
+
eventName = arg;
|
|
3961
|
+
eventName.children.unshift(`${context.helperString(TO_HANDLER_KEY)}(`);
|
|
3962
|
+
eventName.children.push(`)`);
|
|
3963
|
+
}
|
|
3964
|
+
let exp = dir.exp;
|
|
3965
|
+
if (exp && !exp.content.trim()) exp = void 0;
|
|
3966
|
+
let shouldCache = context.cacheHandlers && !exp && !context.inVOnce;
|
|
3967
|
+
if (exp) {
|
|
3968
|
+
const isMemberExp = isMemberExpression(exp, context);
|
|
3969
|
+
const isInlineStatement = !(isMemberExp || isFnExpression(exp, context));
|
|
3970
|
+
const hasMultipleStatements = exp.content.includes(`;`);
|
|
3971
|
+
if (!!(process.env.NODE_ENV !== "production") && true) validateBrowserExpression(exp, context, false, hasMultipleStatements);
|
|
3972
|
+
if (isInlineStatement || shouldCache && isMemberExp) exp = createCompoundExpression([
|
|
3973
|
+
`${isInlineStatement ? `$event` : `(...args)`} => ${hasMultipleStatements ? `{` : `(`}`,
|
|
3974
|
+
exp,
|
|
3975
|
+
hasMultipleStatements ? `}` : `)`
|
|
3976
|
+
]);
|
|
3977
|
+
}
|
|
3978
|
+
let ret = { props: [createObjectProperty(eventName, exp || createSimpleExpression(`() => {}`, false, loc))] };
|
|
3979
|
+
if (augmentor) ret = augmentor(ret);
|
|
3980
|
+
if (shouldCache) ret.props[0].value = context.cache(ret.props[0].value);
|
|
3981
|
+
ret.props.forEach((p) => p.key.isHandlerKey = true);
|
|
3982
|
+
return ret;
|
|
3983
|
+
};
|
|
3984
|
+
|
|
3985
|
+
//#endregion
|
|
3986
|
+
//#region packages/compiler-core/src/transforms/vBind.ts
|
|
3987
|
+
const transformBind = (dir, _node, context) => {
|
|
3988
|
+
const { modifiers, loc } = dir;
|
|
3989
|
+
const arg = dir.arg;
|
|
3990
|
+
let { exp } = dir;
|
|
3991
|
+
if (exp && exp.type === 4 && !exp.content.trim()) exp = void 0;
|
|
3992
|
+
if (arg.type !== 4) {
|
|
3993
|
+
arg.children.unshift(`(`);
|
|
3994
|
+
arg.children.push(`) || ""`);
|
|
3995
|
+
} else if (!arg.isStatic) arg.content = arg.content ? `${arg.content} || ""` : `""`;
|
|
3996
|
+
if (modifiers.some((mod) => mod.content === "camel")) if (arg.type === 4) if (arg.isStatic) arg.content = camelize(arg.content);
|
|
3997
|
+
else arg.content = `${context.helperString(CAMELIZE)}(${arg.content})`;
|
|
3998
|
+
else {
|
|
3999
|
+
arg.children.unshift(`${context.helperString(CAMELIZE)}(`);
|
|
4000
|
+
arg.children.push(`)`);
|
|
4001
|
+
}
|
|
4002
|
+
if (!context.inSSR) {
|
|
4003
|
+
if (modifiers.some((mod) => mod.content === "prop")) injectPrefix(arg, ".");
|
|
4004
|
+
if (modifiers.some((mod) => mod.content === "attr")) injectPrefix(arg, "^");
|
|
4005
|
+
}
|
|
4006
|
+
return { props: [createObjectProperty(arg, exp)] };
|
|
4007
|
+
};
|
|
4008
|
+
const injectPrefix = (arg, prefix) => {
|
|
4009
|
+
if (arg.type === 4) if (arg.isStatic) arg.content = prefix + arg.content;
|
|
4010
|
+
else arg.content = `\`${prefix}\${${arg.content}}\``;
|
|
4011
|
+
else {
|
|
4012
|
+
arg.children.unshift(`'${prefix}' + (`);
|
|
4013
|
+
arg.children.push(`)`);
|
|
4014
|
+
}
|
|
4015
|
+
};
|
|
4016
|
+
|
|
4017
|
+
//#endregion
|
|
4018
|
+
//#region packages/compiler-core/src/transforms/transformText.ts
|
|
4019
|
+
const transformText = (node, context) => {
|
|
4020
|
+
if (node.type === 0 || node.type === 1 || node.type === 11 || node.type === 10) return () => {
|
|
4021
|
+
const children = node.children;
|
|
4022
|
+
let currentContainer = void 0;
|
|
4023
|
+
let hasText = false;
|
|
4024
|
+
for (let i = 0; i < children.length; i++) {
|
|
4025
|
+
const child = children[i];
|
|
4026
|
+
if (isText(child)) {
|
|
4027
|
+
hasText = true;
|
|
4028
|
+
for (let j = i + 1; j < children.length; j++) {
|
|
4029
|
+
const next = children[j];
|
|
4030
|
+
if (isText(next)) {
|
|
4031
|
+
if (!currentContainer) currentContainer = children[i] = createCompoundExpression([child], child.loc);
|
|
4032
|
+
currentContainer.children.push(` + `, next);
|
|
4033
|
+
children.splice(j, 1);
|
|
4034
|
+
j--;
|
|
4035
|
+
} else {
|
|
4036
|
+
currentContainer = void 0;
|
|
4037
|
+
break;
|
|
4038
|
+
}
|
|
4039
|
+
}
|
|
4040
|
+
}
|
|
4041
|
+
}
|
|
4042
|
+
if (!hasText || children.length === 1 && (node.type === 0 || node.type === 1 && node.tagType === 0 && !node.props.find((p) => p.type === 7 && !context.directiveTransforms[p.name]) && !(node.tag === "template"))) return;
|
|
4043
|
+
for (let i = 0; i < children.length; i++) {
|
|
4044
|
+
const child = children[i];
|
|
4045
|
+
if (isText(child) || child.type === 8) {
|
|
4046
|
+
const callArgs = [];
|
|
4047
|
+
if (child.type !== 2 || child.content !== " ") callArgs.push(child);
|
|
4048
|
+
if (!context.ssr && getConstantType(child, context) === 0) callArgs.push(1 + (!!(process.env.NODE_ENV !== "production") ? ` /* ${PatchFlagNames[1]} */` : ``));
|
|
4049
|
+
children[i] = {
|
|
4050
|
+
type: 12,
|
|
4051
|
+
content: child,
|
|
4052
|
+
loc: child.loc,
|
|
4053
|
+
codegenNode: createCallExpression(context.helper(CREATE_TEXT), callArgs)
|
|
4054
|
+
};
|
|
4055
|
+
}
|
|
4056
|
+
}
|
|
4057
|
+
};
|
|
4058
|
+
};
|
|
4059
|
+
|
|
4060
|
+
//#endregion
|
|
4061
|
+
//#region packages/compiler-core/src/transforms/vOnce.ts
|
|
4062
|
+
const seen$1 = /* @__PURE__ */ new WeakSet();
|
|
4063
|
+
const transformOnce = (node, context) => {
|
|
4064
|
+
if (node.type === 1 && findDir(node, "once", true)) {
|
|
4065
|
+
if (seen$1.has(node) || context.inVOnce || context.inSSR) return;
|
|
4066
|
+
seen$1.add(node);
|
|
4067
|
+
context.inVOnce = true;
|
|
4068
|
+
context.helper(SET_BLOCK_TRACKING);
|
|
4069
|
+
return () => {
|
|
4070
|
+
context.inVOnce = false;
|
|
4071
|
+
const cur = context.currentNode;
|
|
4072
|
+
if (cur.codegenNode) cur.codegenNode = context.cache(cur.codegenNode, true, true);
|
|
4073
|
+
};
|
|
4074
|
+
}
|
|
4075
|
+
};
|
|
4076
|
+
|
|
4077
|
+
//#endregion
|
|
4078
|
+
//#region packages/compiler-core/src/transforms/vModel.ts
|
|
4079
|
+
const transformModel = (dir, node, context) => {
|
|
4080
|
+
const { exp, arg } = dir;
|
|
4081
|
+
if (!exp) {
|
|
4082
|
+
context.onError(createCompilerError(41, dir.loc));
|
|
4083
|
+
return createTransformProps();
|
|
4084
|
+
}
|
|
4085
|
+
const rawExp = exp.loc.source.trim();
|
|
4086
|
+
const expString = exp.type === 4 ? exp.content : rawExp;
|
|
4087
|
+
const bindingType = context.bindingMetadata[rawExp];
|
|
4088
|
+
if (bindingType === "props" || bindingType === "props-aliased") {
|
|
4089
|
+
context.onError(createCompilerError(44, exp.loc));
|
|
4090
|
+
return createTransformProps();
|
|
4091
|
+
}
|
|
4092
|
+
if (bindingType === "literal-const" || bindingType === "setup-const") {
|
|
4093
|
+
context.onError(createCompilerError(45, exp.loc));
|
|
4094
|
+
return createTransformProps();
|
|
4095
|
+
}
|
|
4096
|
+
if (!expString.trim() || !isMemberExpression(exp, context) && true) {
|
|
4097
|
+
context.onError(createCompilerError(42, exp.loc));
|
|
4098
|
+
return createTransformProps();
|
|
4099
|
+
}
|
|
4100
|
+
const propName = arg ? arg : createSimpleExpression("modelValue", true);
|
|
4101
|
+
const eventName = arg ? isStaticExp(arg) ? `onUpdate:${camelize(arg.content)}` : createCompoundExpression(["\"onUpdate:\" + ", arg]) : `onUpdate:modelValue`;
|
|
4102
|
+
let assignmentExp;
|
|
4103
|
+
assignmentExp = createCompoundExpression([
|
|
4104
|
+
`${context.isTS ? `($event: any)` : `$event`} => ((`,
|
|
4105
|
+
exp,
|
|
4106
|
+
`) = $event)`
|
|
4107
|
+
]);
|
|
4108
|
+
const props = [createObjectProperty(propName, dir.exp), createObjectProperty(eventName, assignmentExp)];
|
|
4109
|
+
if (dir.modifiers.length && node.tagType === 1) {
|
|
4110
|
+
const modifiers = dir.modifiers.map((m) => m.content).map((m) => (isSimpleIdentifier(m) ? m : JSON.stringify(m)) + `: true`).join(`, `);
|
|
4111
|
+
const modifiersKey = arg ? isStaticExp(arg) ? getModifierPropName(arg.content) : createCompoundExpression([arg, " + \"Modifiers\""]) : `modelModifiers`;
|
|
4112
|
+
props.push(createObjectProperty(modifiersKey, createSimpleExpression(`{ ${modifiers} }`, false, dir.loc, 2)));
|
|
4113
|
+
}
|
|
4114
|
+
return createTransformProps(props);
|
|
4115
|
+
};
|
|
4116
|
+
function createTransformProps(props = []) {
|
|
4117
|
+
return { props };
|
|
4118
|
+
}
|
|
4119
|
+
|
|
4120
|
+
//#endregion
|
|
4121
|
+
//#region packages/compiler-core/src/compat/transformFilter.ts
|
|
4122
|
+
const validDivisionCharRE = /[\w).+\-_$\]]/;
|
|
4123
|
+
const transformFilter = (node, context) => {
|
|
4124
|
+
if (!isCompatEnabled("COMPILER_FILTERS", context)) return;
|
|
4125
|
+
if (node.type === 5) rewriteFilter(node.content, context);
|
|
4126
|
+
else if (node.type === 1) node.props.forEach((prop) => {
|
|
4127
|
+
if (prop.type === 7 && prop.name !== "for" && prop.exp) rewriteFilter(prop.exp, context);
|
|
4128
|
+
});
|
|
4129
|
+
};
|
|
4130
|
+
function rewriteFilter(node, context) {
|
|
4131
|
+
if (node.type === 4) parseFilter(node, context);
|
|
4132
|
+
else for (let i = 0; i < node.children.length; i++) {
|
|
4133
|
+
const child = node.children[i];
|
|
4134
|
+
if (typeof child !== "object") continue;
|
|
4135
|
+
if (child.type === 4) parseFilter(child, context);
|
|
4136
|
+
else if (child.type === 8) rewriteFilter(node, context);
|
|
4137
|
+
else if (child.type === 5) rewriteFilter(child.content, context);
|
|
4138
|
+
}
|
|
4139
|
+
}
|
|
4140
|
+
function parseFilter(node, context) {
|
|
4141
|
+
const exp = node.content;
|
|
4142
|
+
let inSingle = false;
|
|
4143
|
+
let inDouble = false;
|
|
4144
|
+
let inTemplateString = false;
|
|
4145
|
+
let inRegex = false;
|
|
4146
|
+
let curly = 0;
|
|
4147
|
+
let square = 0;
|
|
4148
|
+
let paren = 0;
|
|
4149
|
+
let lastFilterIndex = 0;
|
|
4150
|
+
let c, prev, i, expression, filters = [];
|
|
4151
|
+
for (i = 0; i < exp.length; i++) {
|
|
4152
|
+
prev = c;
|
|
4153
|
+
c = exp.charCodeAt(i);
|
|
4154
|
+
if (inSingle) {
|
|
4155
|
+
if (c === 39 && prev !== 92) inSingle = false;
|
|
4156
|
+
} else if (inDouble) {
|
|
4157
|
+
if (c === 34 && prev !== 92) inDouble = false;
|
|
4158
|
+
} else if (inTemplateString) {
|
|
4159
|
+
if (c === 96 && prev !== 92) inTemplateString = false;
|
|
4160
|
+
} else if (inRegex) {
|
|
4161
|
+
if (c === 47 && prev !== 92) inRegex = false;
|
|
4162
|
+
} else if (c === 124 && exp.charCodeAt(i + 1) !== 124 && exp.charCodeAt(i - 1) !== 124 && !curly && !square && !paren) if (expression === void 0) {
|
|
4163
|
+
lastFilterIndex = i + 1;
|
|
4164
|
+
expression = exp.slice(0, i).trim();
|
|
4165
|
+
} else pushFilter();
|
|
4166
|
+
else {
|
|
4167
|
+
switch (c) {
|
|
4168
|
+
case 34:
|
|
4169
|
+
inDouble = true;
|
|
4170
|
+
break;
|
|
4171
|
+
case 39:
|
|
4172
|
+
inSingle = true;
|
|
4173
|
+
break;
|
|
4174
|
+
case 96:
|
|
4175
|
+
inTemplateString = true;
|
|
4176
|
+
break;
|
|
4177
|
+
case 40:
|
|
4178
|
+
paren++;
|
|
4179
|
+
break;
|
|
4180
|
+
case 41:
|
|
4181
|
+
paren--;
|
|
4182
|
+
break;
|
|
4183
|
+
case 91:
|
|
4184
|
+
square++;
|
|
4185
|
+
break;
|
|
4186
|
+
case 93:
|
|
4187
|
+
square--;
|
|
4188
|
+
break;
|
|
4189
|
+
case 123:
|
|
4190
|
+
curly++;
|
|
4191
|
+
break;
|
|
4192
|
+
case 125:
|
|
4193
|
+
curly--;
|
|
4194
|
+
break;
|
|
4195
|
+
}
|
|
4196
|
+
if (c === 47) {
|
|
4197
|
+
let j = i - 1;
|
|
4198
|
+
let p;
|
|
4199
|
+
for (; j >= 0; j--) {
|
|
4200
|
+
p = exp.charAt(j);
|
|
4201
|
+
if (p !== " ") break;
|
|
4202
|
+
}
|
|
4203
|
+
if (!p || !validDivisionCharRE.test(p)) inRegex = true;
|
|
4204
|
+
}
|
|
4205
|
+
}
|
|
4206
|
+
}
|
|
4207
|
+
if (expression === void 0) expression = exp.slice(0, i).trim();
|
|
4208
|
+
else if (lastFilterIndex !== 0) pushFilter();
|
|
4209
|
+
function pushFilter() {
|
|
4210
|
+
filters.push(exp.slice(lastFilterIndex, i).trim());
|
|
4211
|
+
lastFilterIndex = i + 1;
|
|
4212
|
+
}
|
|
4213
|
+
if (filters.length) {
|
|
4214
|
+
process.env.NODE_ENV !== "production" && warnDeprecation("COMPILER_FILTERS", context, node.loc);
|
|
4215
|
+
for (i = 0; i < filters.length; i++) expression = wrapFilter(expression, filters[i], context);
|
|
4216
|
+
node.content = expression;
|
|
4217
|
+
node.ast = void 0;
|
|
4218
|
+
}
|
|
4219
|
+
}
|
|
4220
|
+
function wrapFilter(exp, filter, context) {
|
|
4221
|
+
context.helper(RESOLVE_FILTER);
|
|
4222
|
+
const i = filter.indexOf("(");
|
|
4223
|
+
if (i < 0) {
|
|
4224
|
+
context.filters.add(filter);
|
|
4225
|
+
return `${toValidAssetId(filter, "filter")}(${exp})`;
|
|
4226
|
+
} else {
|
|
4227
|
+
const name = filter.slice(0, i);
|
|
4228
|
+
const args = filter.slice(i + 1);
|
|
4229
|
+
context.filters.add(name);
|
|
4230
|
+
return `${toValidAssetId(name, "filter")}(${exp}${args !== ")" ? "," + args : args}`;
|
|
4231
|
+
}
|
|
4232
|
+
}
|
|
4233
|
+
|
|
4234
|
+
//#endregion
|
|
4235
|
+
//#region packages/compiler-core/src/transforms/vMemo.ts
|
|
4236
|
+
const seen = /* @__PURE__ */ new WeakSet();
|
|
4237
|
+
const transformMemo = (node, context) => {
|
|
4238
|
+
if (node.type === 1) {
|
|
4239
|
+
const dir = findDir(node, "memo");
|
|
4240
|
+
if (!dir || seen.has(node) || context.inSSR) return;
|
|
4241
|
+
seen.add(node);
|
|
4242
|
+
return () => {
|
|
4243
|
+
const codegenNode = node.codegenNode || context.currentNode.codegenNode;
|
|
4244
|
+
if (codegenNode && codegenNode.type === 13) {
|
|
4245
|
+
if (node.tagType !== 1) convertToBlock(codegenNode, context);
|
|
4246
|
+
node.codegenNode = createCallExpression(context.helper(WITH_MEMO), [
|
|
4247
|
+
dir.exp,
|
|
4248
|
+
createFunctionExpression(void 0, codegenNode),
|
|
4249
|
+
`_cache`,
|
|
4250
|
+
String(context.cached.length)
|
|
4251
|
+
]);
|
|
4252
|
+
context.cached.push(null);
|
|
4253
|
+
}
|
|
4254
|
+
};
|
|
4255
|
+
}
|
|
4256
|
+
};
|
|
4257
|
+
|
|
4258
|
+
//#endregion
|
|
4259
|
+
//#region packages/compiler-core/src/transforms/transformVBindShorthand.ts
|
|
4260
|
+
const transformVBindShorthand = (node, context) => {
|
|
4261
|
+
if (node.type === 1) {
|
|
4262
|
+
for (const prop of node.props) if (prop.type === 7 && prop.name === "bind" && (!prop.exp || prop.exp.type === 4 && !prop.exp.content.trim()) && prop.arg) {
|
|
4263
|
+
const arg = prop.arg;
|
|
4264
|
+
if (arg.type !== 4 || !arg.isStatic) {
|
|
4265
|
+
context.onError(createCompilerError(53, arg.loc));
|
|
4266
|
+
prop.exp = createSimpleExpression("", true, arg.loc);
|
|
4267
|
+
} else {
|
|
4268
|
+
const propName = camelize(arg.content);
|
|
4269
|
+
if (validFirstIdentCharRE.test(propName[0]) || propName[0] === "-") prop.exp = createSimpleExpression(propName, false, arg.loc);
|
|
4270
|
+
}
|
|
4271
|
+
}
|
|
4272
|
+
}
|
|
4273
|
+
};
|
|
4274
|
+
|
|
4275
|
+
//#endregion
|
|
4276
|
+
//#region packages/compiler-core/src/compile.ts
|
|
4277
|
+
function getBaseTransformPreset(prefixIdentifiers) {
|
|
4278
|
+
return [[
|
|
4279
|
+
transformVBindShorthand,
|
|
4280
|
+
transformOnce,
|
|
4281
|
+
transformIf,
|
|
4282
|
+
transformMemo,
|
|
4283
|
+
transformFor,
|
|
4284
|
+
...[transformFilter],
|
|
4285
|
+
...!!(process.env.NODE_ENV !== "production") ? [transformExpression] : [],
|
|
4286
|
+
transformSlotOutlet,
|
|
4287
|
+
transformElement,
|
|
4288
|
+
trackSlotScopes,
|
|
4289
|
+
transformText
|
|
4290
|
+
], {
|
|
4291
|
+
on: transformOn,
|
|
4292
|
+
bind: transformBind,
|
|
4293
|
+
model: transformModel
|
|
4294
|
+
}];
|
|
4295
|
+
}
|
|
4296
|
+
function baseCompile(source, options = {}) {
|
|
4297
|
+
const onError = options.onError || defaultOnError;
|
|
4298
|
+
const isModuleMode = options.mode === "module";
|
|
4299
|
+
if (options.prefixIdentifiers === true) onError(createCompilerError(48));
|
|
4300
|
+
else if (isModuleMode) onError(createCompilerError(49));
|
|
4301
|
+
/* v8 ignore stop */
|
|
4302
|
+
const prefixIdentifiers = false;
|
|
4303
|
+
if (options.cacheHandlers) onError(createCompilerError(50));
|
|
4304
|
+
if (options.scopeId && !isModuleMode) onError(createCompilerError(51));
|
|
4305
|
+
const resolvedOptions = extend({}, options, { prefixIdentifiers });
|
|
4306
|
+
const ast = isString(source) ? baseParse(source, resolvedOptions) : source;
|
|
4307
|
+
const [nodeTransforms, directiveTransforms] = getBaseTransformPreset(prefixIdentifiers);
|
|
4308
|
+
transform(ast, extend({}, resolvedOptions, {
|
|
4309
|
+
nodeTransforms: [...nodeTransforms, ...options.nodeTransforms || []],
|
|
4310
|
+
directiveTransforms: extend({}, directiveTransforms, options.directiveTransforms || {})
|
|
4311
|
+
}));
|
|
4312
|
+
return generate(ast, resolvedOptions);
|
|
4313
|
+
}
|
|
4314
|
+
|
|
4315
|
+
//#endregion
|
|
4316
|
+
//#region packages/compiler-core/src/options.ts
|
|
4317
|
+
const BindingTypes = {
|
|
4318
|
+
"DATA": "data",
|
|
4319
|
+
"PROPS": "props",
|
|
4320
|
+
"PROPS_ALIASED": "props-aliased",
|
|
4321
|
+
"SETUP_LET": "setup-let",
|
|
4322
|
+
"SETUP_CONST": "setup-const",
|
|
4323
|
+
"SETUP_REACTIVE_CONST": "setup-reactive-const",
|
|
4324
|
+
"SETUP_MAYBE_REF": "setup-maybe-ref",
|
|
4325
|
+
"SETUP_REF": "setup-ref",
|
|
4326
|
+
"OPTIONS": "options",
|
|
4327
|
+
"LITERAL_CONST": "literal-const"
|
|
4328
|
+
};
|
|
4329
|
+
|
|
4330
|
+
//#endregion
|
|
4331
|
+
//#region packages/compiler-core/src/transforms/noopDirectiveTransform.ts
|
|
4332
|
+
const noopDirectiveTransform = () => ({ props: [] });
|
|
4333
|
+
|
|
4334
|
+
//#endregion
|
|
4335
|
+
export { BASE_TRANSITION, BindingTypes, CAMELIZE, CAPITALIZE, CREATE_BLOCK, CREATE_COMMENT, CREATE_ELEMENT_BLOCK, CREATE_ELEMENT_VNODE, CREATE_SLOTS, CREATE_STATIC, CREATE_TEXT, CREATE_VNODE, CompilerDeprecationTypes, ConstantTypes, ElementTypes, ErrorCodes, FRAGMENT, GUARD_REACTIVE_PROPS, IS_MEMO_SAME, IS_REF, KEEP_ALIVE, MERGE_PROPS, NORMALIZE_CLASS, NORMALIZE_PROPS, NORMALIZE_STYLE, NewlineType, NodeTypes, OPEN_BLOCK, POP_SCOPE_ID, PUSH_SCOPE_ID, RENDER_LIST, RENDER_SLOT, RESOLVE_COMPONENT, RESOLVE_DIRECTIVE, RESOLVE_DYNAMIC_COMPONENT, RESOLVE_FILTER, SET_BLOCK_TRACKING, SUSPENSE, TELEPORT, TO_DISPLAY_STRING, TO_HANDLERS, TO_HANDLER_KEY, TS_NODE_TYPES, UNREF, WITH_CTX, WITH_DIRECTIVES, WITH_MEMO, advancePositionWithClone, advancePositionWithMutation, assert, baseCompile, baseParse, buildDirectiveArgs, buildProps, buildSlots, checkCompatEnabled, convertToBlock, createArrayExpression, createAssignmentExpression, createBlockStatement, createCacheExpression, createCallExpression, createCompilerError, createCompoundExpression, createConditionalExpression, createExp, createForLoopParams, createFunctionExpression, createIfStatement, createInterpolation, createObjectExpression, createObjectProperty, createReturnStatement, createRoot, createSequenceExpression, createSimpleExpression, createStructuralDirectiveTransform, createTemplateLiteral, createTransformContext, createVNodeCall, defaultOnError, defaultOnWarn, errorMessages, extractIdentifiers, filterNonCommentChildren, findDir, findProp, forAliasRE, generate, generateCodeFrame, getBaseTransformPreset, getConstantType, getMemoedVNodeCall, getSelfName, getVNodeBlockHelper, getVNodeHelper, hasDynamicKeyVBind, hasScopeRef, hasSingleChild, helperNameMap, injectProp, isAllWhitespace, isCommentOrWhitespace, isConstantNode, isCoreComponent, isFnExpression, isFnExpressionBrowser, isFnExpressionNode, isFunctionType, isInDestructureAssignment, isInNewExpression, isLiteralWhitelisted, isMemberExpression, isMemberExpressionBrowser, isMemberExpressionNode, isReferencedIdentifier, isSimpleIdentifier, isSingleIfBlock, isSlotOutlet, isStaticArgOf, isStaticExp, isStaticNode, isStaticProperty, isStaticPropertyKey, isTemplateNode, isText, isVPre, isVSlot, isWhitespaceText, locStub, noopDirectiveTransform, processExpression, processFor, processIf, processSlotOutlet, registerRuntimeHelpers, resolveComponentType, stringifyExpression, toValidAssetId, trackSlotScopes, trackVForSlotScopes, transform, transformBind, transformElement, transformExpression, transformModel, transformOn, transformVBindShorthand, traverseNode, unwrapTSNode, validFirstIdentCharRE, walkBlockDeclarations, walkFunctionParams, walkIdentifiers, warnDeprecation };
|