@vue/compiler-dom 3.2.39 → 3.2.41
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/compiler-dom.cjs.js +852 -847
- package/dist/compiler-dom.cjs.prod.js +792 -787
- package/dist/compiler-dom.esm-browser.js +5424 -5412
- package/dist/compiler-dom.esm-browser.prod.js +1 -1
- package/dist/compiler-dom.esm-bundler.js +452 -452
- package/dist/compiler-dom.global.js +5424 -5412
- package/dist/compiler-dom.global.prod.js +1 -1
- package/package.json +3 -3
|
@@ -2,482 +2,482 @@ 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` : ``);
|
|
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`
|
|
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
|
+
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`
|
|
26
26
|
});
|
|
27
27
|
|
|
28
|
-
/* eslint-disable no-restricted-globals */
|
|
29
|
-
let decoder;
|
|
30
|
-
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, '"')}">`;
|
|
36
|
-
return decoder.children[0].getAttribute('foo');
|
|
37
|
-
}
|
|
38
|
-
else {
|
|
39
|
-
decoder.innerHTML = raw;
|
|
40
|
-
return decoder.textContent;
|
|
41
|
-
}
|
|
28
|
+
/* eslint-disable no-restricted-globals */
|
|
29
|
+
let decoder;
|
|
30
|
+
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, '"')}">`;
|
|
36
|
+
return decoder.children[0].getAttribute('foo');
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
decoder.innerHTML = raw;
|
|
40
|
+
return decoder.textContent;
|
|
41
|
+
}
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
const isRawTextContainer = /*#__PURE__*/ makeMap('style,iframe,script,noscript', true);
|
|
45
|
-
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
|
-
}
|
|
94
|
-
}
|
|
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
|
-
}
|
|
106
|
-
}
|
|
107
|
-
return 0 /* TextModes.DATA */;
|
|
108
|
-
}
|
|
44
|
+
const isRawTextContainer = /*#__PURE__*/ makeMap('style,iframe,script,noscript', true);
|
|
45
|
+
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
|
+
}
|
|
94
|
+
}
|
|
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
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return 0 /* TextModes.DATA */;
|
|
108
|
+
}
|
|
109
109
|
};
|
|
110
110
|
|
|
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
|
-
}
|
|
133
|
-
};
|
|
134
|
-
const parseInlineCSS = (cssText, loc) => {
|
|
135
|
-
const normalized = parseStringStyle(cssText);
|
|
136
|
-
return createSimpleExpression(JSON.stringify(normalized), false, loc, 3 /* ConstantTypes.CAN_STRINGIFY */);
|
|
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
|
+
}
|
|
133
|
+
};
|
|
134
|
+
const parseInlineCSS = (cssText, loc) => {
|
|
135
|
+
const normalized = parseStringStyle(cssText);
|
|
136
|
+
return createSimpleExpression(JSON.stringify(normalized), false, loc, 3 /* ConstantTypes.CAN_STRINGIFY */);
|
|
137
137
|
};
|
|
138
138
|
|
|
139
|
-
function createDOMCompilerError(code, loc) {
|
|
140
|
-
return createCompilerError(code, loc, (process.env.NODE_ENV !== 'production') || !true ? DOMErrorMessages : undefined);
|
|
141
|
-
}
|
|
142
|
-
const DOMErrorMessages = {
|
|
143
|
-
[50 /* DOMErrorCodes.X_V_HTML_NO_EXPRESSION */]: `v-html is missing expression.`,
|
|
144
|
-
[51 /* DOMErrorCodes.X_V_HTML_WITH_CHILDREN */]: `v-html will override element children.`,
|
|
145
|
-
[52 /* DOMErrorCodes.X_V_TEXT_NO_EXPRESSION */]: `v-text is missing expression.`,
|
|
146
|
-
[53 /* DOMErrorCodes.X_V_TEXT_WITH_CHILDREN */]: `v-text will override element children.`,
|
|
147
|
-
[54 /* DOMErrorCodes.X_V_MODEL_ON_INVALID_ELEMENT */]: `v-model can only be used on <input>, <textarea> and <select> elements.`,
|
|
148
|
-
[55 /* DOMErrorCodes.X_V_MODEL_ARG_ON_ELEMENT */]: `v-model argument is not supported on plain elements.`,
|
|
149
|
-
[56 /* 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
|
-
[57 /* DOMErrorCodes.X_V_MODEL_UNNECESSARY_VALUE */]: `Unnecessary value binding used alongside v-model. It will interfere with v-model's behavior.`,
|
|
151
|
-
[58 /* DOMErrorCodes.X_V_SHOW_NO_EXPRESSION */]: `v-show is missing expression.`,
|
|
152
|
-
[59 /* DOMErrorCodes.X_TRANSITION_INVALID_CHILDREN */]: `<Transition> expects exactly one child element or component.`,
|
|
153
|
-
[60 /* DOMErrorCodes.X_IGNORED_SIDE_EFFECT_TAG */]: `Tags with side effect (<script> and <style>) are ignored in client component templates.`
|
|
139
|
+
function createDOMCompilerError(code, loc) {
|
|
140
|
+
return createCompilerError(code, loc, (process.env.NODE_ENV !== 'production') || !true ? DOMErrorMessages : undefined);
|
|
141
|
+
}
|
|
142
|
+
const DOMErrorMessages = {
|
|
143
|
+
[50 /* DOMErrorCodes.X_V_HTML_NO_EXPRESSION */]: `v-html is missing expression.`,
|
|
144
|
+
[51 /* DOMErrorCodes.X_V_HTML_WITH_CHILDREN */]: `v-html will override element children.`,
|
|
145
|
+
[52 /* DOMErrorCodes.X_V_TEXT_NO_EXPRESSION */]: `v-text is missing expression.`,
|
|
146
|
+
[53 /* DOMErrorCodes.X_V_TEXT_WITH_CHILDREN */]: `v-text will override element children.`,
|
|
147
|
+
[54 /* DOMErrorCodes.X_V_MODEL_ON_INVALID_ELEMENT */]: `v-model can only be used on <input>, <textarea> and <select> elements.`,
|
|
148
|
+
[55 /* DOMErrorCodes.X_V_MODEL_ARG_ON_ELEMENT */]: `v-model argument is not supported on plain elements.`,
|
|
149
|
+
[56 /* 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
|
+
[57 /* DOMErrorCodes.X_V_MODEL_UNNECESSARY_VALUE */]: `Unnecessary value binding used alongside v-model. It will interfere with v-model's behavior.`,
|
|
151
|
+
[58 /* DOMErrorCodes.X_V_SHOW_NO_EXPRESSION */]: `v-show is missing expression.`,
|
|
152
|
+
[59 /* DOMErrorCodes.X_TRANSITION_INVALID_CHILDREN */]: `<Transition> expects exactly one child element or component.`,
|
|
153
|
+
[60 /* DOMErrorCodes.X_IGNORED_SIDE_EFFECT_TAG */]: `Tags with side effect (<script> and <style>) are ignored in client component templates.`
|
|
154
154
|
};
|
|
155
155
|
|
|
156
|
-
const transformVHtml = (dir, node, context) => {
|
|
157
|
-
const { exp, loc } = dir;
|
|
158
|
-
if (!exp) {
|
|
159
|
-
context.onError(createDOMCompilerError(50 /* DOMErrorCodes.X_V_HTML_NO_EXPRESSION */, loc));
|
|
160
|
-
}
|
|
161
|
-
if (node.children.length) {
|
|
162
|
-
context.onError(createDOMCompilerError(51 /* 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
|
-
};
|
|
156
|
+
const transformVHtml = (dir, node, context) => {
|
|
157
|
+
const { exp, loc } = dir;
|
|
158
|
+
if (!exp) {
|
|
159
|
+
context.onError(createDOMCompilerError(50 /* DOMErrorCodes.X_V_HTML_NO_EXPRESSION */, loc));
|
|
160
|
+
}
|
|
161
|
+
if (node.children.length) {
|
|
162
|
+
context.onError(createDOMCompilerError(51 /* 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
|
+
};
|
|
170
170
|
};
|
|
171
171
|
|
|
172
|
-
const transformVText = (dir, node, context) => {
|
|
173
|
-
const { exp, loc } = dir;
|
|
174
|
-
if (!exp) {
|
|
175
|
-
context.onError(createDOMCompilerError(52 /* DOMErrorCodes.X_V_TEXT_NO_EXPRESSION */, loc));
|
|
176
|
-
}
|
|
177
|
-
if (node.children.length) {
|
|
178
|
-
context.onError(createDOMCompilerError(53 /* 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
|
-
};
|
|
172
|
+
const transformVText = (dir, node, context) => {
|
|
173
|
+
const { exp, loc } = dir;
|
|
174
|
+
if (!exp) {
|
|
175
|
+
context.onError(createDOMCompilerError(52 /* DOMErrorCodes.X_V_TEXT_NO_EXPRESSION */, loc));
|
|
176
|
+
}
|
|
177
|
+
if (node.children.length) {
|
|
178
|
+
context.onError(createDOMCompilerError(53 /* 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
|
+
};
|
|
190
190
|
};
|
|
191
191
|
|
|
192
|
-
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(55 /* 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(57 /* DOMErrorCodes.X_V_MODEL_UNNECESSARY_VALUE */, value.loc));
|
|
205
|
-
}
|
|
206
|
-
}
|
|
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(56 /* 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);
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
else {
|
|
266
|
-
context.onError(createDOMCompilerError(54 /* DOMErrorCodes.X_V_MODEL_ON_INVALID_ELEMENT */, dir.loc));
|
|
267
|
-
}
|
|
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;
|
|
192
|
+
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(55 /* 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(57 /* DOMErrorCodes.X_V_MODEL_UNNECESSARY_VALUE */, value.loc));
|
|
205
|
+
}
|
|
206
|
+
}
|
|
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(56 /* 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);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
else {
|
|
266
|
+
context.onError(createDOMCompilerError(54 /* DOMErrorCodes.X_V_MODEL_ON_INVALID_ELEMENT */, dir.loc));
|
|
267
|
+
}
|
|
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;
|
|
273
273
|
};
|
|
274
274
|
|
|
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);
|
|
286
|
-
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);
|
|
295
|
-
}
|
|
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
|
-
}
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
return {
|
|
328
|
-
keyModifiers,
|
|
329
|
-
nonKeyModifiers,
|
|
330
|
-
eventOptionModifiers
|
|
331
|
-
};
|
|
332
|
-
};
|
|
333
|
-
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;
|
|
346
|
-
};
|
|
347
|
-
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
|
-
});
|
|
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);
|
|
286
|
+
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);
|
|
295
|
+
}
|
|
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
|
+
}
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
return {
|
|
328
|
+
keyModifiers,
|
|
329
|
+
nonKeyModifiers,
|
|
330
|
+
eventOptionModifiers
|
|
331
|
+
};
|
|
332
|
+
};
|
|
333
|
+
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;
|
|
346
|
+
};
|
|
347
|
+
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
385
|
};
|
|
386
386
|
|
|
387
|
-
const transformShow = (dir, node, context) => {
|
|
388
|
-
const { exp, loc } = dir;
|
|
389
|
-
if (!exp) {
|
|
390
|
-
context.onError(createDOMCompilerError(58 /* DOMErrorCodes.X_V_SHOW_NO_EXPRESSION */, loc));
|
|
391
|
-
}
|
|
392
|
-
return {
|
|
393
|
-
props: [],
|
|
394
|
-
needRuntime: context.helper(V_SHOW)
|
|
395
|
-
};
|
|
387
|
+
const transformShow = (dir, node, context) => {
|
|
388
|
+
const { exp, loc } = dir;
|
|
389
|
+
if (!exp) {
|
|
390
|
+
context.onError(createDOMCompilerError(58 /* DOMErrorCodes.X_V_SHOW_NO_EXPRESSION */, loc));
|
|
391
|
+
}
|
|
392
|
+
return {
|
|
393
|
+
props: [],
|
|
394
|
+
needRuntime: context.helper(V_SHOW)
|
|
395
|
+
};
|
|
396
396
|
};
|
|
397
397
|
|
|
398
|
-
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(59 /* 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
|
-
};
|
|
431
|
-
}
|
|
432
|
-
}
|
|
433
|
-
};
|
|
434
|
-
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)));
|
|
398
|
+
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(59 /* 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
|
+
};
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
};
|
|
434
|
+
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)));
|
|
442
442
|
}
|
|
443
443
|
|
|
444
|
-
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(60 /* DOMErrorCodes.X_IGNORED_SIDE_EFFECT_TAG */, node.loc));
|
|
449
|
-
context.removeNode();
|
|
450
|
-
}
|
|
444
|
+
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(60 /* DOMErrorCodes.X_IGNORED_SIDE_EFFECT_TAG */, node.loc));
|
|
449
|
+
context.removeNode();
|
|
450
|
+
}
|
|
451
451
|
};
|
|
452
452
|
|
|
453
|
-
const DOMNodeTransforms = [
|
|
454
|
-
transformStyle,
|
|
455
|
-
...((process.env.NODE_ENV !== 'production') ? [transformTransition] : [])
|
|
456
|
-
];
|
|
457
|
-
const DOMDirectiveTransforms = {
|
|
458
|
-
cloak: noopDirectiveTransform,
|
|
459
|
-
html: transformVHtml,
|
|
460
|
-
text: transformVText,
|
|
461
|
-
model: transformModel,
|
|
462
|
-
on: transformOn,
|
|
463
|
-
show: transformShow
|
|
464
|
-
};
|
|
465
|
-
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
|
-
}));
|
|
478
|
-
}
|
|
479
|
-
function parse(template, options = {}) {
|
|
480
|
-
return baseParse(template, extend({}, parserOptions, options));
|
|
453
|
+
const DOMNodeTransforms = [
|
|
454
|
+
transformStyle,
|
|
455
|
+
...((process.env.NODE_ENV !== 'production') ? [transformTransition] : [])
|
|
456
|
+
];
|
|
457
|
+
const DOMDirectiveTransforms = {
|
|
458
|
+
cloak: noopDirectiveTransform,
|
|
459
|
+
html: transformVHtml,
|
|
460
|
+
text: transformVText,
|
|
461
|
+
model: transformModel,
|
|
462
|
+
on: transformOn,
|
|
463
|
+
show: transformShow
|
|
464
|
+
};
|
|
465
|
+
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
|
+
}));
|
|
478
|
+
}
|
|
479
|
+
function parse(template, options = {}) {
|
|
480
|
+
return baseParse(template, extend({}, parserOptions, options));
|
|
481
481
|
}
|
|
482
482
|
|
|
483
483
|
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 };
|