@vue/compiler-dom 3.2.46 → 3.3.0-alpha.1

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.
@@ -2,482 +2,485 @@ import { registerRuntimeHelpers, isBuiltInType, createSimpleExpression, createCo
2
2
  export * from '@vue/compiler-core';
3
3
  import { isVoidTag, isHTMLTag, isSVGTag, makeMap, parseStringStyle, capitalize, extend } from '@vue/shared';
4
4
 
5
- const V_MODEL_RADIO = Symbol((process.env.NODE_ENV !== 'production') ? `vModelRadio` : ``);
6
- const V_MODEL_CHECKBOX = Symbol((process.env.NODE_ENV !== 'production') ? `vModelCheckbox` : ``);
7
- const V_MODEL_TEXT = Symbol((process.env.NODE_ENV !== 'production') ? `vModelText` : ``);
8
- const V_MODEL_SELECT = Symbol((process.env.NODE_ENV !== 'production') ? `vModelSelect` : ``);
9
- const V_MODEL_DYNAMIC = Symbol((process.env.NODE_ENV !== 'production') ? `vModelDynamic` : ``);
10
- const V_ON_WITH_MODIFIERS = Symbol((process.env.NODE_ENV !== 'production') ? `vOnModifiersGuard` : ``);
11
- const V_ON_WITH_KEYS = Symbol((process.env.NODE_ENV !== 'production') ? `vOnKeysGuard` : ``);
12
- const V_SHOW = Symbol((process.env.NODE_ENV !== 'production') ? `vShow` : ``);
13
- const TRANSITION = Symbol((process.env.NODE_ENV !== 'production') ? `Transition` : ``);
14
- const TRANSITION_GROUP = Symbol((process.env.NODE_ENV !== 'production') ? `TransitionGroup` : ``);
5
+ const V_MODEL_RADIO = Symbol(process.env.NODE_ENV !== "production" ? `vModelRadio` : ``);
6
+ const V_MODEL_CHECKBOX = Symbol(process.env.NODE_ENV !== "production" ? `vModelCheckbox` : ``);
7
+ const V_MODEL_TEXT = Symbol(process.env.NODE_ENV !== "production" ? `vModelText` : ``);
8
+ const V_MODEL_SELECT = Symbol(process.env.NODE_ENV !== "production" ? `vModelSelect` : ``);
9
+ const V_MODEL_DYNAMIC = Symbol(process.env.NODE_ENV !== "production" ? `vModelDynamic` : ``);
10
+ const V_ON_WITH_MODIFIERS = Symbol(process.env.NODE_ENV !== "production" ? `vOnModifiersGuard` : ``);
11
+ const V_ON_WITH_KEYS = Symbol(process.env.NODE_ENV !== "production" ? `vOnKeysGuard` : ``);
12
+ const V_SHOW = Symbol(process.env.NODE_ENV !== "production" ? `vShow` : ``);
13
+ const TRANSITION = Symbol(process.env.NODE_ENV !== "production" ? `Transition` : ``);
14
+ const TRANSITION_GROUP = Symbol(process.env.NODE_ENV !== "production" ? `TransitionGroup` : ``);
15
15
  registerRuntimeHelpers({
16
- [V_MODEL_RADIO]: `vModelRadio`,
17
- [V_MODEL_CHECKBOX]: `vModelCheckbox`,
18
- [V_MODEL_TEXT]: `vModelText`,
19
- [V_MODEL_SELECT]: `vModelSelect`,
20
- [V_MODEL_DYNAMIC]: `vModelDynamic`,
21
- [V_ON_WITH_MODIFIERS]: `withModifiers`,
22
- [V_ON_WITH_KEYS]: `withKeys`,
23
- [V_SHOW]: `vShow`,
24
- [TRANSITION]: `Transition`,
25
- [TRANSITION_GROUP]: `TransitionGroup`
16
+ [V_MODEL_RADIO]: `vModelRadio`,
17
+ [V_MODEL_CHECKBOX]: `vModelCheckbox`,
18
+ [V_MODEL_TEXT]: `vModelText`,
19
+ [V_MODEL_SELECT]: `vModelSelect`,
20
+ [V_MODEL_DYNAMIC]: `vModelDynamic`,
21
+ [V_ON_WITH_MODIFIERS]: `withModifiers`,
22
+ [V_ON_WITH_KEYS]: `withKeys`,
23
+ [V_SHOW]: `vShow`,
24
+ [TRANSITION]: `Transition`,
25
+ [TRANSITION_GROUP]: `TransitionGroup`
26
26
  });
27
27
 
28
- /* eslint-disable no-restricted-globals */
29
28
  let decoder;
30
29
  function decodeHtmlBrowser(raw, asAttr = false) {
31
- if (!decoder) {
32
- decoder = document.createElement('div');
33
- }
34
- if (asAttr) {
35
- decoder.innerHTML = `<div foo="${raw.replace(/"/g, '&quot;')}">`;
36
- return decoder.children[0].getAttribute('foo');
37
- }
38
- else {
39
- decoder.innerHTML = raw;
40
- return decoder.textContent;
41
- }
30
+ if (!decoder) {
31
+ decoder = document.createElement("div");
32
+ }
33
+ if (asAttr) {
34
+ decoder.innerHTML = `<div foo="${raw.replace(/"/g, "&quot;")}">`;
35
+ return decoder.children[0].getAttribute("foo");
36
+ } else {
37
+ decoder.innerHTML = raw;
38
+ return decoder.textContent;
39
+ }
42
40
  }
43
41
 
44
- const isRawTextContainer = /*#__PURE__*/ makeMap('style,iframe,script,noscript', true);
42
+ const isRawTextContainer = /* @__PURE__ */ makeMap(
43
+ "style,iframe,script,noscript",
44
+ true
45
+ );
45
46
  const parserOptions = {
46
- isVoidTag,
47
- isNativeTag: tag => isHTMLTag(tag) || isSVGTag(tag),
48
- isPreTag: tag => tag === 'pre',
49
- decodeEntities: decodeHtmlBrowser ,
50
- isBuiltInComponent: (tag) => {
51
- if (isBuiltInType(tag, `Transition`)) {
52
- return TRANSITION;
53
- }
54
- else if (isBuiltInType(tag, `TransitionGroup`)) {
55
- return TRANSITION_GROUP;
56
- }
57
- },
58
- // https://html.spec.whatwg.org/multipage/parsing.html#tree-construction-dispatcher
59
- getNamespace(tag, parent) {
60
- let ns = parent ? parent.ns : 0 /* DOMNamespaces.HTML */;
61
- if (parent && ns === 2 /* DOMNamespaces.MATH_ML */) {
62
- if (parent.tag === 'annotation-xml') {
63
- if (tag === 'svg') {
64
- return 1 /* DOMNamespaces.SVG */;
65
- }
66
- if (parent.props.some(a => a.type === 6 /* NodeTypes.ATTRIBUTE */ &&
67
- a.name === 'encoding' &&
68
- a.value != null &&
69
- (a.value.content === 'text/html' ||
70
- a.value.content === 'application/xhtml+xml'))) {
71
- ns = 0 /* DOMNamespaces.HTML */;
72
- }
73
- }
74
- else if (/^m(?:[ions]|text)$/.test(parent.tag) &&
75
- tag !== 'mglyph' &&
76
- tag !== 'malignmark') {
77
- ns = 0 /* DOMNamespaces.HTML */;
78
- }
79
- }
80
- else if (parent && ns === 1 /* DOMNamespaces.SVG */) {
81
- if (parent.tag === 'foreignObject' ||
82
- parent.tag === 'desc' ||
83
- parent.tag === 'title') {
84
- ns = 0 /* DOMNamespaces.HTML */;
85
- }
86
- }
87
- if (ns === 0 /* DOMNamespaces.HTML */) {
88
- if (tag === 'svg') {
89
- return 1 /* DOMNamespaces.SVG */;
90
- }
91
- if (tag === 'math') {
92
- return 2 /* DOMNamespaces.MATH_ML */;
93
- }
47
+ isVoidTag,
48
+ isNativeTag: (tag) => isHTMLTag(tag) || isSVGTag(tag),
49
+ isPreTag: (tag) => tag === "pre",
50
+ decodeEntities: decodeHtmlBrowser ,
51
+ isBuiltInComponent: (tag) => {
52
+ if (isBuiltInType(tag, `Transition`)) {
53
+ return TRANSITION;
54
+ } else if (isBuiltInType(tag, `TransitionGroup`)) {
55
+ return TRANSITION_GROUP;
56
+ }
57
+ },
58
+ // https://html.spec.whatwg.org/multipage/parsing.html#tree-construction-dispatcher
59
+ getNamespace(tag, parent) {
60
+ let ns = parent ? parent.ns : 0;
61
+ if (parent && ns === 2) {
62
+ if (parent.tag === "annotation-xml") {
63
+ if (tag === "svg") {
64
+ return 1;
94
65
  }
95
- return ns;
96
- },
97
- // https://html.spec.whatwg.org/multipage/parsing.html#parsing-html-fragments
98
- getTextMode({ tag, ns }) {
99
- if (ns === 0 /* DOMNamespaces.HTML */) {
100
- if (tag === 'textarea' || tag === 'title') {
101
- return 1 /* TextModes.RCDATA */;
102
- }
103
- if (isRawTextContainer(tag)) {
104
- return 2 /* TextModes.RAWTEXT */;
105
- }
66
+ if (parent.props.some(
67
+ (a) => a.type === 6 && a.name === "encoding" && a.value != null && (a.value.content === "text/html" || a.value.content === "application/xhtml+xml")
68
+ )) {
69
+ ns = 0;
106
70
  }
107
- return 0 /* TextModes.DATA */;
71
+ } else if (/^m(?:[ions]|text)$/.test(parent.tag) && tag !== "mglyph" && tag !== "malignmark") {
72
+ ns = 0;
73
+ }
74
+ } else if (parent && ns === 1) {
75
+ if (parent.tag === "foreignObject" || parent.tag === "desc" || parent.tag === "title") {
76
+ ns = 0;
77
+ }
78
+ }
79
+ if (ns === 0) {
80
+ if (tag === "svg") {
81
+ return 1;
82
+ }
83
+ if (tag === "math") {
84
+ return 2;
85
+ }
86
+ }
87
+ return ns;
88
+ },
89
+ // https://html.spec.whatwg.org/multipage/parsing.html#parsing-html-fragments
90
+ getTextMode({ tag, ns }) {
91
+ if (ns === 0) {
92
+ if (tag === "textarea" || tag === "title") {
93
+ return 1;
94
+ }
95
+ if (isRawTextContainer(tag)) {
96
+ return 2;
97
+ }
108
98
  }
99
+ return 0;
100
+ }
109
101
  };
110
102
 
111
- // Parse inline CSS strings for static style attributes into an object.
112
- // This is a NodeTransform since it works on the static `style` attribute and
113
- // converts it into a dynamic equivalent:
114
- // style="color: red" -> :style='{ "color": "red" }'
115
- // It is then processed by `transformElement` and included in the generated
116
- // props.
117
- const transformStyle = node => {
118
- if (node.type === 1 /* NodeTypes.ELEMENT */) {
119
- node.props.forEach((p, i) => {
120
- if (p.type === 6 /* NodeTypes.ATTRIBUTE */ && p.name === 'style' && p.value) {
121
- // replace p with an expression node
122
- node.props[i] = {
123
- type: 7 /* NodeTypes.DIRECTIVE */,
124
- name: `bind`,
125
- arg: createSimpleExpression(`style`, true, p.loc),
126
- exp: parseInlineCSS(p.value.content, p.loc),
127
- modifiers: [],
128
- loc: p.loc
129
- };
130
- }
131
- });
132
- }
103
+ const transformStyle = (node) => {
104
+ if (node.type === "element") {
105
+ node.props.forEach((p, i) => {
106
+ if (p.type === 6 && p.name === "style" && p.value) {
107
+ node.props[i] = {
108
+ type: 7,
109
+ name: `bind`,
110
+ arg: createSimpleExpression(`style`, true, p.loc),
111
+ exp: parseInlineCSS(p.value.content, p.loc),
112
+ modifiers: [],
113
+ loc: p.loc
114
+ };
115
+ }
116
+ });
117
+ }
133
118
  };
134
119
  const parseInlineCSS = (cssText, loc) => {
135
- const normalized = parseStringStyle(cssText);
136
- return createSimpleExpression(JSON.stringify(normalized), false, loc, 3 /* ConstantTypes.CAN_STRINGIFY */);
120
+ const normalized = parseStringStyle(cssText);
121
+ return createSimpleExpression(
122
+ JSON.stringify(normalized),
123
+ false,
124
+ loc,
125
+ 3
126
+ );
137
127
  };
138
128
 
139
129
  function createDOMCompilerError(code, loc) {
140
- return createCompilerError(code, loc, (process.env.NODE_ENV !== 'production') || !true ? DOMErrorMessages : undefined);
130
+ return createCompilerError(
131
+ code,
132
+ loc,
133
+ process.env.NODE_ENV !== "production" || false ? DOMErrorMessages : void 0
134
+ );
141
135
  }
142
136
  const DOMErrorMessages = {
143
- [51 /* DOMErrorCodes.X_V_HTML_NO_EXPRESSION */]: `v-html is missing expression.`,
144
- [52 /* DOMErrorCodes.X_V_HTML_WITH_CHILDREN */]: `v-html will override element children.`,
145
- [53 /* DOMErrorCodes.X_V_TEXT_NO_EXPRESSION */]: `v-text is missing expression.`,
146
- [54 /* DOMErrorCodes.X_V_TEXT_WITH_CHILDREN */]: `v-text will override element children.`,
147
- [55 /* DOMErrorCodes.X_V_MODEL_ON_INVALID_ELEMENT */]: `v-model can only be used on <input>, <textarea> and <select> elements.`,
148
- [56 /* DOMErrorCodes.X_V_MODEL_ARG_ON_ELEMENT */]: `v-model argument is not supported on plain elements.`,
149
- [57 /* DOMErrorCodes.X_V_MODEL_ON_FILE_INPUT_ELEMENT */]: `v-model cannot be used on file inputs since they are read-only. Use a v-on:change listener instead.`,
150
- [58 /* DOMErrorCodes.X_V_MODEL_UNNECESSARY_VALUE */]: `Unnecessary value binding used alongside v-model. It will interfere with v-model's behavior.`,
151
- [59 /* DOMErrorCodes.X_V_SHOW_NO_EXPRESSION */]: `v-show is missing expression.`,
152
- [60 /* DOMErrorCodes.X_TRANSITION_INVALID_CHILDREN */]: `<Transition> expects exactly one child element or component.`,
153
- [61 /* DOMErrorCodes.X_IGNORED_SIDE_EFFECT_TAG */]: `Tags with side effect (<script> and <style>) are ignored in client component templates.`
137
+ [51]: `v-html is missing expression.`,
138
+ [52]: `v-html will override element children.`,
139
+ [53]: `v-text is missing expression.`,
140
+ [54]: `v-text will override element children.`,
141
+ [55]: `v-model can only be used on <input>, <textarea> and <select> elements.`,
142
+ [56]: `v-model argument is not supported on plain elements.`,
143
+ [57]: `v-model cannot be used on file inputs since they are read-only. Use a v-on:change listener instead.`,
144
+ [58]: `Unnecessary value binding used alongside v-model. It will interfere with v-model's behavior.`,
145
+ [59]: `v-show is missing expression.`,
146
+ [60]: `<Transition> expects exactly one child element or component.`,
147
+ [61]: `Tags with side effect (<script> and <style>) are ignored in client component templates.`
154
148
  };
155
149
 
156
150
  const transformVHtml = (dir, node, context) => {
157
- const { exp, loc } = dir;
158
- if (!exp) {
159
- context.onError(createDOMCompilerError(51 /* DOMErrorCodes.X_V_HTML_NO_EXPRESSION */, loc));
160
- }
161
- if (node.children.length) {
162
- context.onError(createDOMCompilerError(52 /* DOMErrorCodes.X_V_HTML_WITH_CHILDREN */, loc));
163
- node.children.length = 0;
164
- }
165
- return {
166
- props: [
167
- createObjectProperty(createSimpleExpression(`innerHTML`, true, loc), exp || createSimpleExpression('', true))
168
- ]
169
- };
151
+ const { exp, loc } = dir;
152
+ if (!exp) {
153
+ context.onError(
154
+ createDOMCompilerError(51, loc)
155
+ );
156
+ }
157
+ if (node.children.length) {
158
+ context.onError(
159
+ createDOMCompilerError(52, loc)
160
+ );
161
+ node.children.length = 0;
162
+ }
163
+ return {
164
+ props: [
165
+ createObjectProperty(
166
+ createSimpleExpression(`innerHTML`, true, loc),
167
+ exp || createSimpleExpression("", true)
168
+ )
169
+ ]
170
+ };
170
171
  };
171
172
 
172
173
  const transformVText = (dir, node, context) => {
173
- const { exp, loc } = dir;
174
- if (!exp) {
175
- context.onError(createDOMCompilerError(53 /* DOMErrorCodes.X_V_TEXT_NO_EXPRESSION */, loc));
176
- }
177
- if (node.children.length) {
178
- context.onError(createDOMCompilerError(54 /* DOMErrorCodes.X_V_TEXT_WITH_CHILDREN */, loc));
179
- node.children.length = 0;
180
- }
181
- return {
182
- props: [
183
- createObjectProperty(createSimpleExpression(`textContent`, true), exp
184
- ? getConstantType(exp, context) > 0
185
- ? exp
186
- : createCallExpression(context.helperString(TO_DISPLAY_STRING), [exp], loc)
187
- : createSimpleExpression('', true))
188
- ]
189
- };
174
+ const { exp, loc } = dir;
175
+ if (!exp) {
176
+ context.onError(
177
+ createDOMCompilerError(53, loc)
178
+ );
179
+ }
180
+ if (node.children.length) {
181
+ context.onError(
182
+ createDOMCompilerError(54, loc)
183
+ );
184
+ node.children.length = 0;
185
+ }
186
+ return {
187
+ props: [
188
+ createObjectProperty(
189
+ createSimpleExpression(`textContent`, true),
190
+ exp ? getConstantType(exp, context) > 0 ? exp : createCallExpression(
191
+ context.helperString(TO_DISPLAY_STRING),
192
+ [exp],
193
+ loc
194
+ ) : createSimpleExpression("", true)
195
+ )
196
+ ]
197
+ };
190
198
  };
191
199
 
192
200
  const transformModel = (dir, node, context) => {
193
- const baseResult = transformModel$1(dir, node, context);
194
- // base transform has errors OR component v-model (only need props)
195
- if (!baseResult.props.length || node.tagType === 1 /* ElementTypes.COMPONENT */) {
196
- return baseResult;
197
- }
198
- if (dir.arg) {
199
- context.onError(createDOMCompilerError(56 /* DOMErrorCodes.X_V_MODEL_ARG_ON_ELEMENT */, dir.arg.loc));
200
- }
201
- function checkDuplicatedValue() {
202
- const value = findProp(node, 'value');
203
- if (value) {
204
- context.onError(createDOMCompilerError(58 /* DOMErrorCodes.X_V_MODEL_UNNECESSARY_VALUE */, value.loc));
205
- }
201
+ const baseResult = transformModel$1(dir, node, context);
202
+ if (!baseResult.props.length || node.tagType === 1) {
203
+ return baseResult;
204
+ }
205
+ if (dir.arg) {
206
+ context.onError(
207
+ createDOMCompilerError(
208
+ 56,
209
+ dir.arg.loc
210
+ )
211
+ );
212
+ }
213
+ function checkDuplicatedValue() {
214
+ const value = findProp(node, "value");
215
+ if (value) {
216
+ context.onError(
217
+ createDOMCompilerError(
218
+ 58,
219
+ value.loc
220
+ )
221
+ );
206
222
  }
207
- const { tag } = node;
208
- const isCustomElement = context.isCustomElement(tag);
209
- if (tag === 'input' ||
210
- tag === 'textarea' ||
211
- tag === 'select' ||
212
- isCustomElement) {
213
- let directiveToUse = V_MODEL_TEXT;
214
- let isInvalidType = false;
215
- if (tag === 'input' || isCustomElement) {
216
- const type = findProp(node, `type`);
217
- if (type) {
218
- if (type.type === 7 /* NodeTypes.DIRECTIVE */) {
219
- // :type="foo"
220
- directiveToUse = V_MODEL_DYNAMIC;
221
- }
222
- else if (type.value) {
223
- switch (type.value.content) {
224
- case 'radio':
225
- directiveToUse = V_MODEL_RADIO;
226
- break;
227
- case 'checkbox':
228
- directiveToUse = V_MODEL_CHECKBOX;
229
- break;
230
- case 'file':
231
- isInvalidType = true;
232
- context.onError(createDOMCompilerError(57 /* DOMErrorCodes.X_V_MODEL_ON_FILE_INPUT_ELEMENT */, dir.loc));
233
- break;
234
- default:
235
- // text type
236
- (process.env.NODE_ENV !== 'production') && checkDuplicatedValue();
237
- break;
238
- }
239
- }
240
- }
241
- else if (hasDynamicKeyVBind(node)) {
242
- // element has bindings with dynamic keys, which can possibly contain
243
- // "type".
244
- directiveToUse = V_MODEL_DYNAMIC;
245
- }
246
- else {
247
- // text type
248
- (process.env.NODE_ENV !== 'production') && checkDuplicatedValue();
249
- }
250
- }
251
- else if (tag === 'select') {
252
- directiveToUse = V_MODEL_SELECT;
253
- }
254
- else {
255
- // textarea
256
- (process.env.NODE_ENV !== 'production') && checkDuplicatedValue();
257
- }
258
- // inject runtime directive
259
- // by returning the helper symbol via needRuntime
260
- // the import will replaced a resolveDirective call.
261
- if (!isInvalidType) {
262
- baseResult.needRuntime = context.helper(directiveToUse);
223
+ }
224
+ const { tag } = node;
225
+ const isCustomElement = context.isCustomElement(tag);
226
+ if (tag === "input" || tag === "textarea" || tag === "select" || isCustomElement) {
227
+ let directiveToUse = V_MODEL_TEXT;
228
+ let isInvalidType = false;
229
+ if (tag === "input" || isCustomElement) {
230
+ const type = findProp(node, `type`);
231
+ if (type) {
232
+ if (type.type === 7) {
233
+ directiveToUse = V_MODEL_DYNAMIC;
234
+ } else if (type.value) {
235
+ switch (type.value.content) {
236
+ case "radio":
237
+ directiveToUse = V_MODEL_RADIO;
238
+ break;
239
+ case "checkbox":
240
+ directiveToUse = V_MODEL_CHECKBOX;
241
+ break;
242
+ case "file":
243
+ isInvalidType = true;
244
+ context.onError(
245
+ createDOMCompilerError(
246
+ 57,
247
+ dir.loc
248
+ )
249
+ );
250
+ break;
251
+ default:
252
+ process.env.NODE_ENV !== "production" && checkDuplicatedValue();
253
+ break;
254
+ }
263
255
  }
256
+ } else if (hasDynamicKeyVBind(node)) {
257
+ directiveToUse = V_MODEL_DYNAMIC;
258
+ } else {
259
+ process.env.NODE_ENV !== "production" && checkDuplicatedValue();
260
+ }
261
+ } else if (tag === "select") {
262
+ directiveToUse = V_MODEL_SELECT;
263
+ } else {
264
+ process.env.NODE_ENV !== "production" && checkDuplicatedValue();
264
265
  }
265
- else {
266
- context.onError(createDOMCompilerError(55 /* DOMErrorCodes.X_V_MODEL_ON_INVALID_ELEMENT */, dir.loc));
266
+ if (!isInvalidType) {
267
+ baseResult.needRuntime = context.helper(directiveToUse);
267
268
  }
268
- // native vmodel doesn't need the `modelValue` props since they are also
269
- // passed to the runtime as `binding.value`. removing it reduces code size.
270
- baseResult.props = baseResult.props.filter(p => !(p.key.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */ &&
271
- p.key.content === 'modelValue'));
272
- return baseResult;
269
+ } else {
270
+ context.onError(
271
+ createDOMCompilerError(
272
+ 55,
273
+ dir.loc
274
+ )
275
+ );
276
+ }
277
+ baseResult.props = baseResult.props.filter(
278
+ (p) => !(p.key.type === 4 && p.key.content === "modelValue")
279
+ );
280
+ return baseResult;
273
281
  };
274
282
 
275
- const isEventOptionModifier = /*#__PURE__*/ makeMap(`passive,once,capture`);
276
- const isNonKeyModifier = /*#__PURE__*/ makeMap(
277
- // event propagation management
278
- `stop,prevent,self,` +
279
- // system modifiers + exact
280
- `ctrl,shift,alt,meta,exact,` +
281
- // mouse
282
- `middle`);
283
- // left & right could be mouse or key modifiers based on event type
284
- const maybeKeyModifier = /*#__PURE__*/ makeMap('left,right');
285
- const isKeyboardEvent = /*#__PURE__*/ makeMap(`onkeyup,onkeydown,onkeypress`, true);
283
+ const isEventOptionModifier = /* @__PURE__ */ makeMap(`passive,once,capture`);
284
+ const isNonKeyModifier = /* @__PURE__ */ makeMap(
285
+ // event propagation management
286
+ `stop,prevent,self,ctrl,shift,alt,meta,exact,middle`
287
+ );
288
+ const maybeKeyModifier = /* @__PURE__ */ makeMap("left,right");
289
+ const isKeyboardEvent = /* @__PURE__ */ makeMap(
290
+ `onkeyup,onkeydown,onkeypress`,
291
+ true
292
+ );
286
293
  const resolveModifiers = (key, modifiers, context, loc) => {
287
- const keyModifiers = [];
288
- const nonKeyModifiers = [];
289
- const eventOptionModifiers = [];
290
- for (let i = 0; i < modifiers.length; i++) {
291
- const modifier = modifiers[i];
292
- if (modifier === 'native' &&
293
- checkCompatEnabled("COMPILER_V_ON_NATIVE" /* CompilerDeprecationTypes.COMPILER_V_ON_NATIVE */, context, loc)) {
294
- eventOptionModifiers.push(modifier);
294
+ const keyModifiers = [];
295
+ const nonKeyModifiers = [];
296
+ const eventOptionModifiers = [];
297
+ for (let i = 0; i < modifiers.length; i++) {
298
+ const modifier = modifiers[i];
299
+ if (modifier === "native" && checkCompatEnabled(
300
+ "COMPILER_V_ON_NATIVE",
301
+ context,
302
+ loc
303
+ )) {
304
+ eventOptionModifiers.push(modifier);
305
+ } else if (isEventOptionModifier(modifier)) {
306
+ eventOptionModifiers.push(modifier);
307
+ } else {
308
+ if (maybeKeyModifier(modifier)) {
309
+ if (isStaticExp(key)) {
310
+ if (isKeyboardEvent(key.content)) {
311
+ keyModifiers.push(modifier);
312
+ } else {
313
+ nonKeyModifiers.push(modifier);
314
+ }
315
+ } else {
316
+ keyModifiers.push(modifier);
317
+ nonKeyModifiers.push(modifier);
295
318
  }
296
- else if (isEventOptionModifier(modifier)) {
297
- // eventOptionModifiers: modifiers for addEventListener() options,
298
- // e.g. .passive & .capture
299
- eventOptionModifiers.push(modifier);
300
- }
301
- else {
302
- // runtimeModifiers: modifiers that needs runtime guards
303
- if (maybeKeyModifier(modifier)) {
304
- if (isStaticExp(key)) {
305
- if (isKeyboardEvent(key.content)) {
306
- keyModifiers.push(modifier);
307
- }
308
- else {
309
- nonKeyModifiers.push(modifier);
310
- }
311
- }
312
- else {
313
- keyModifiers.push(modifier);
314
- nonKeyModifiers.push(modifier);
315
- }
316
- }
317
- else {
318
- if (isNonKeyModifier(modifier)) {
319
- nonKeyModifiers.push(modifier);
320
- }
321
- else {
322
- keyModifiers.push(modifier);
323
- }
324
- }
319
+ } else {
320
+ if (isNonKeyModifier(modifier)) {
321
+ nonKeyModifiers.push(modifier);
322
+ } else {
323
+ keyModifiers.push(modifier);
325
324
  }
325
+ }
326
326
  }
327
- return {
328
- keyModifiers,
329
- nonKeyModifiers,
330
- eventOptionModifiers
331
- };
327
+ }
328
+ return {
329
+ keyModifiers,
330
+ nonKeyModifiers,
331
+ eventOptionModifiers
332
+ };
332
333
  };
333
334
  const transformClick = (key, event) => {
334
- const isStaticClick = isStaticExp(key) && key.content.toLowerCase() === 'onclick';
335
- return isStaticClick
336
- ? createSimpleExpression(event, true)
337
- : key.type !== 4 /* NodeTypes.SIMPLE_EXPRESSION */
338
- ? createCompoundExpression([
339
- `(`,
340
- key,
341
- `) === "onClick" ? "${event}" : (`,
342
- key,
343
- `)`
344
- ])
345
- : key;
335
+ const isStaticClick = isStaticExp(key) && key.content.toLowerCase() === "onclick";
336
+ return isStaticClick ? createSimpleExpression(event, true) : key.type !== 4 ? createCompoundExpression([
337
+ `(`,
338
+ key,
339
+ `) === "onClick" ? "${event}" : (`,
340
+ key,
341
+ `)`
342
+ ]) : key;
346
343
  };
347
344
  const transformOn = (dir, node, context) => {
348
- return transformOn$1(dir, node, context, baseResult => {
349
- const { modifiers } = dir;
350
- if (!modifiers.length)
351
- return baseResult;
352
- let { key, value: handlerExp } = baseResult.props[0];
353
- const { keyModifiers, nonKeyModifiers, eventOptionModifiers } = resolveModifiers(key, modifiers, context, dir.loc);
354
- // normalize click.right and click.middle since they don't actually fire
355
- if (nonKeyModifiers.includes('right')) {
356
- key = transformClick(key, `onContextmenu`);
357
- }
358
- if (nonKeyModifiers.includes('middle')) {
359
- key = transformClick(key, `onMouseup`);
360
- }
361
- if (nonKeyModifiers.length) {
362
- handlerExp = createCallExpression(context.helper(V_ON_WITH_MODIFIERS), [
363
- handlerExp,
364
- JSON.stringify(nonKeyModifiers)
365
- ]);
366
- }
367
- if (keyModifiers.length &&
368
- // if event name is dynamic, always wrap with keys guard
369
- (!isStaticExp(key) || isKeyboardEvent(key.content))) {
370
- handlerExp = createCallExpression(context.helper(V_ON_WITH_KEYS), [
371
- handlerExp,
372
- JSON.stringify(keyModifiers)
373
- ]);
374
- }
375
- if (eventOptionModifiers.length) {
376
- const modifierPostfix = eventOptionModifiers.map(capitalize).join('');
377
- key = isStaticExp(key)
378
- ? createSimpleExpression(`${key.content}${modifierPostfix}`, true)
379
- : createCompoundExpression([`(`, key, `) + "${modifierPostfix}"`]);
380
- }
381
- return {
382
- props: [createObjectProperty(key, handlerExp)]
383
- };
384
- });
385
- };
386
-
387
- const transformShow = (dir, node, context) => {
388
- const { exp, loc } = dir;
389
- if (!exp) {
390
- context.onError(createDOMCompilerError(59 /* DOMErrorCodes.X_V_SHOW_NO_EXPRESSION */, loc));
345
+ return transformOn$1(dir, node, context, (baseResult) => {
346
+ const { modifiers } = dir;
347
+ if (!modifiers.length)
348
+ return baseResult;
349
+ let { key, value: handlerExp } = baseResult.props[0];
350
+ const { keyModifiers, nonKeyModifiers, eventOptionModifiers } = resolveModifiers(key, modifiers, context, dir.loc);
351
+ if (nonKeyModifiers.includes("right")) {
352
+ key = transformClick(key, `onContextmenu`);
353
+ }
354
+ if (nonKeyModifiers.includes("middle")) {
355
+ key = transformClick(key, `onMouseup`);
356
+ }
357
+ if (nonKeyModifiers.length) {
358
+ handlerExp = createCallExpression(context.helper(V_ON_WITH_MODIFIERS), [
359
+ handlerExp,
360
+ JSON.stringify(nonKeyModifiers)
361
+ ]);
362
+ }
363
+ if (keyModifiers.length && // if event name is dynamic, always wrap with keys guard
364
+ (!isStaticExp(key) || isKeyboardEvent(key.content))) {
365
+ handlerExp = createCallExpression(context.helper(V_ON_WITH_KEYS), [
366
+ handlerExp,
367
+ JSON.stringify(keyModifiers)
368
+ ]);
369
+ }
370
+ if (eventOptionModifiers.length) {
371
+ const modifierPostfix = eventOptionModifiers.map(capitalize).join("");
372
+ key = isStaticExp(key) ? createSimpleExpression(`${key.content}${modifierPostfix}`, true) : createCompoundExpression([`(`, key, `) + "${modifierPostfix}"`]);
391
373
  }
392
374
  return {
393
- props: [],
394
- needRuntime: context.helper(V_SHOW)
375
+ props: [createObjectProperty(key, handlerExp)]
395
376
  };
377
+ });
378
+ };
379
+
380
+ const transformShow = (dir, node, context) => {
381
+ const { exp, loc } = dir;
382
+ if (!exp) {
383
+ context.onError(
384
+ createDOMCompilerError(59, loc)
385
+ );
386
+ }
387
+ return {
388
+ props: [],
389
+ needRuntime: context.helper(V_SHOW)
390
+ };
396
391
  };
397
392
 
398
393
  const transformTransition = (node, context) => {
399
- if (node.type === 1 /* NodeTypes.ELEMENT */ &&
400
- node.tagType === 1 /* ElementTypes.COMPONENT */) {
401
- const component = context.isBuiltInComponent(node.tag);
402
- if (component === TRANSITION) {
403
- return () => {
404
- if (!node.children.length) {
405
- return;
406
- }
407
- // warn multiple transition children
408
- if (hasMultipleChildren(node)) {
409
- context.onError(createDOMCompilerError(60 /* DOMErrorCodes.X_TRANSITION_INVALID_CHILDREN */, {
410
- start: node.children[0].loc.start,
411
- end: node.children[node.children.length - 1].loc.end,
412
- source: ''
413
- }));
414
- }
415
- // check if it's s single child w/ v-show
416
- // if yes, inject "persisted: true" to the transition props
417
- const child = node.children[0];
418
- if (child.type === 1 /* NodeTypes.ELEMENT */) {
419
- for (const p of child.props) {
420
- if (p.type === 7 /* NodeTypes.DIRECTIVE */ && p.name === 'show') {
421
- node.props.push({
422
- type: 6 /* NodeTypes.ATTRIBUTE */,
423
- name: 'persisted',
424
- value: undefined,
425
- loc: node.loc
426
- });
427
- }
428
- }
429
- }
430
- };
394
+ if (node.type === "element" && node.tagType === 1) {
395
+ const component = context.isBuiltInComponent(node.tag);
396
+ if (component === TRANSITION) {
397
+ return () => {
398
+ if (!node.children.length) {
399
+ return;
431
400
  }
401
+ if (hasMultipleChildren(node)) {
402
+ context.onError(
403
+ createDOMCompilerError(
404
+ 60,
405
+ {
406
+ start: node.children[0].loc.start,
407
+ end: node.children[node.children.length - 1].loc.end,
408
+ source: ""
409
+ }
410
+ )
411
+ );
412
+ }
413
+ const child = node.children[0];
414
+ if (child.type === "element") {
415
+ for (const p of child.props) {
416
+ if (p.type === 7 && p.name === "show") {
417
+ node.props.push({
418
+ type: 6,
419
+ name: "persisted",
420
+ value: void 0,
421
+ loc: node.loc
422
+ });
423
+ }
424
+ }
425
+ }
426
+ };
432
427
  }
428
+ }
433
429
  };
434
430
  function hasMultipleChildren(node) {
435
- // #1352 filter out potential comment nodes.
436
- const children = (node.children = node.children.filter(c => c.type !== 3 /* NodeTypes.COMMENT */ &&
437
- !(c.type === 2 /* NodeTypes.TEXT */ && !c.content.trim())));
438
- const child = children[0];
439
- return (children.length !== 1 ||
440
- child.type === 11 /* NodeTypes.FOR */ ||
441
- (child.type === 9 /* NodeTypes.IF */ && child.branches.some(hasMultipleChildren)));
431
+ const children = node.children = node.children.filter(
432
+ (c) => c.type !== "comment" && !(c.type === "text" && !c.content.trim())
433
+ );
434
+ const child = children[0];
435
+ return children.length !== 1 || child.type === 11 || child.type === 9 && child.branches.some(hasMultipleChildren);
442
436
  }
443
437
 
444
438
  const ignoreSideEffectTags = (node, context) => {
445
- if (node.type === 1 /* NodeTypes.ELEMENT */ &&
446
- node.tagType === 0 /* ElementTypes.ELEMENT */ &&
447
- (node.tag === 'script' || node.tag === 'style')) {
448
- context.onError(createDOMCompilerError(61 /* DOMErrorCodes.X_IGNORED_SIDE_EFFECT_TAG */, node.loc));
449
- context.removeNode();
450
- }
439
+ if (node.type === "element" && node.tagType === 0 && (node.tag === "script" || node.tag === "style")) {
440
+ context.onError(
441
+ createDOMCompilerError(61, node.loc)
442
+ );
443
+ context.removeNode();
444
+ }
451
445
  };
452
446
 
453
447
  const DOMNodeTransforms = [
454
- transformStyle,
455
- ...((process.env.NODE_ENV !== 'production') ? [transformTransition] : [])
448
+ transformStyle,
449
+ ...process.env.NODE_ENV !== "production" ? [transformTransition] : []
456
450
  ];
457
451
  const DOMDirectiveTransforms = {
458
- cloak: noopDirectiveTransform,
459
- html: transformVHtml,
460
- text: transformVText,
461
- model: transformModel,
462
- on: transformOn,
463
- show: transformShow
452
+ cloak: noopDirectiveTransform,
453
+ html: transformVHtml,
454
+ text: transformVText,
455
+ model: transformModel,
456
+ // override compiler-core
457
+ on: transformOn,
458
+ // override compiler-core
459
+ show: transformShow
464
460
  };
465
461
  function compile(template, options = {}) {
466
- return baseCompile(template, extend({}, parserOptions, options, {
467
- nodeTransforms: [
468
- // ignore <script> and <tag>
469
- // this is not put inside DOMNodeTransforms because that list is used
470
- // by compiler-ssr to generate vnode fallback branches
471
- ignoreSideEffectTags,
472
- ...DOMNodeTransforms,
473
- ...(options.nodeTransforms || [])
474
- ],
475
- directiveTransforms: extend({}, DOMDirectiveTransforms, options.directiveTransforms || {}),
476
- transformHoist: null
477
- }));
462
+ return baseCompile(
463
+ template,
464
+ extend({}, parserOptions, options, {
465
+ nodeTransforms: [
466
+ // ignore <script> and <tag>
467
+ // this is not put inside DOMNodeTransforms because that list is used
468
+ // by compiler-ssr to generate vnode fallback branches
469
+ ignoreSideEffectTags,
470
+ ...DOMNodeTransforms,
471
+ ...options.nodeTransforms || []
472
+ ],
473
+ directiveTransforms: extend(
474
+ {},
475
+ DOMDirectiveTransforms,
476
+ options.directiveTransforms || {}
477
+ ),
478
+ transformHoist: null
479
+ })
480
+ );
478
481
  }
479
482
  function parse(template, options = {}) {
480
- return baseParse(template, extend({}, parserOptions, options));
483
+ return baseParse(template, extend({}, parserOptions, options));
481
484
  }
482
485
 
483
486
  export { DOMDirectiveTransforms, DOMNodeTransforms, TRANSITION, TRANSITION_GROUP, V_MODEL_CHECKBOX, V_MODEL_DYNAMIC, V_MODEL_RADIO, V_MODEL_SELECT, V_MODEL_TEXT, V_ON_WITH_KEYS, V_ON_WITH_MODIFIERS, V_SHOW, compile, createDOMCompilerError, parse, parserOptions, transformStyle };