@vue/compiler-sfc 3.2.35 → 3.2.38
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-sfc.cjs.js +142 -74
- package/dist/compiler-sfc.esm-browser.js +850 -755
- package/package.json +6 -6
package/dist/compiler-sfc.cjs.js
CHANGED
|
@@ -109,8 +109,6 @@ function sum (o) {
|
|
|
109
109
|
var hashSum = sum;
|
|
110
110
|
|
|
111
111
|
const CSS_VARS_HELPER = `useCssVars`;
|
|
112
|
-
// match v-bind() with max 2-levels of nested parens.
|
|
113
|
-
const cssVarRE = /v-bind\s*\(((?:[^)(]+|\((?:[^)(]+|\([^)(]*\))*\))*)\)/g;
|
|
114
112
|
function genCssVarsFromList(vars, id, isProd, isSSR = false) {
|
|
115
113
|
return `{\n ${vars
|
|
116
114
|
.map(key => `"${isSSR ? `--` : ``}${genVarName(id, key, isProd)}": (${key})`)
|
|
@@ -132,31 +130,89 @@ function normalizeExpression(exp) {
|
|
|
132
130
|
}
|
|
133
131
|
return exp;
|
|
134
132
|
}
|
|
133
|
+
const vBindRE = /v-bind\s*\(/g;
|
|
135
134
|
function parseCssVars(sfc) {
|
|
136
135
|
const vars = [];
|
|
137
136
|
sfc.styles.forEach(style => {
|
|
138
137
|
let match;
|
|
139
138
|
// ignore v-bind() in comments /* ... */
|
|
140
139
|
const content = style.content.replace(/\/\*([\s\S]*?)\*\//g, '');
|
|
141
|
-
while ((match =
|
|
142
|
-
const
|
|
143
|
-
|
|
144
|
-
|
|
140
|
+
while ((match = vBindRE.exec(content))) {
|
|
141
|
+
const start = match.index + match[0].length;
|
|
142
|
+
const end = lexBinding(content, start);
|
|
143
|
+
if (end !== null) {
|
|
144
|
+
const variable = normalizeExpression(content.slice(start, end));
|
|
145
|
+
if (!vars.includes(variable)) {
|
|
146
|
+
vars.push(variable);
|
|
147
|
+
}
|
|
145
148
|
}
|
|
146
149
|
}
|
|
147
150
|
});
|
|
148
151
|
return vars;
|
|
149
152
|
}
|
|
153
|
+
function lexBinding(content, start) {
|
|
154
|
+
let state = 0 /* LexerState.inParens */;
|
|
155
|
+
let parenDepth = 0;
|
|
156
|
+
for (let i = start; i < content.length; i++) {
|
|
157
|
+
const char = content.charAt(i);
|
|
158
|
+
switch (state) {
|
|
159
|
+
case 0 /* LexerState.inParens */:
|
|
160
|
+
if (char === `'`) {
|
|
161
|
+
state = 1 /* LexerState.inSingleQuoteString */;
|
|
162
|
+
}
|
|
163
|
+
else if (char === `"`) {
|
|
164
|
+
state = 2 /* LexerState.inDoubleQuoteString */;
|
|
165
|
+
}
|
|
166
|
+
else if (char === `(`) {
|
|
167
|
+
parenDepth++;
|
|
168
|
+
}
|
|
169
|
+
else if (char === `)`) {
|
|
170
|
+
if (parenDepth > 0) {
|
|
171
|
+
parenDepth--;
|
|
172
|
+
}
|
|
173
|
+
else {
|
|
174
|
+
return i;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
break;
|
|
178
|
+
case 1 /* LexerState.inSingleQuoteString */:
|
|
179
|
+
if (char === `'`) {
|
|
180
|
+
state = 0 /* LexerState.inParens */;
|
|
181
|
+
}
|
|
182
|
+
break;
|
|
183
|
+
case 2 /* LexerState.inDoubleQuoteString */:
|
|
184
|
+
if (char === `"`) {
|
|
185
|
+
state = 0 /* LexerState.inParens */;
|
|
186
|
+
}
|
|
187
|
+
break;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
return null;
|
|
191
|
+
}
|
|
150
192
|
const cssVarsPlugin = opts => {
|
|
151
193
|
const { id, isProd } = opts;
|
|
152
194
|
return {
|
|
153
195
|
postcssPlugin: 'vue-sfc-vars',
|
|
154
196
|
Declaration(decl) {
|
|
155
197
|
// rewrite CSS variables
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
198
|
+
const value = decl.value;
|
|
199
|
+
if (vBindRE.test(value)) {
|
|
200
|
+
vBindRE.lastIndex = 0;
|
|
201
|
+
let transformed = '';
|
|
202
|
+
let lastIndex = 0;
|
|
203
|
+
let match;
|
|
204
|
+
while ((match = vBindRE.exec(value))) {
|
|
205
|
+
const start = match.index + match[0].length;
|
|
206
|
+
const end = lexBinding(value, start);
|
|
207
|
+
if (end !== null) {
|
|
208
|
+
const variable = normalizeExpression(value.slice(start, end));
|
|
209
|
+
transformed +=
|
|
210
|
+
value.slice(lastIndex, match.index) +
|
|
211
|
+
`var(--${genVarName(id, variable, isProd)})`;
|
|
212
|
+
lastIndex = end + 1;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
decl.value = transformed + value.slice(lastIndex);
|
|
160
216
|
}
|
|
161
217
|
}
|
|
162
218
|
};
|
|
@@ -171,7 +227,7 @@ function genCssVarsCode(vars, bindings, id, isProd) {
|
|
|
171
227
|
bindingMetadata: bindings.__isScriptSetup === false ? undefined : bindings
|
|
172
228
|
});
|
|
173
229
|
const transformed = CompilerDOM.processExpression(exp, context);
|
|
174
|
-
const transformedString = transformed.type === 4 /* SIMPLE_EXPRESSION */
|
|
230
|
+
const transformedString = transformed.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */
|
|
175
231
|
? transformed.content
|
|
176
232
|
: transformed.children
|
|
177
233
|
.map(c => {
|
|
@@ -1038,7 +1094,7 @@ const createAssetUrlTransformWithOptions = (options) => {
|
|
|
1038
1094
|
* ```
|
|
1039
1095
|
*/
|
|
1040
1096
|
const transformAssetUrl = (node, context, options = defaultAssetUrlOptions) => {
|
|
1041
|
-
if (node.type === 1 /* ELEMENT */) {
|
|
1097
|
+
if (node.type === 1 /* NodeTypes.ELEMENT */) {
|
|
1042
1098
|
if (!node.props.length) {
|
|
1043
1099
|
return;
|
|
1044
1100
|
}
|
|
@@ -1050,7 +1106,7 @@ const transformAssetUrl = (node, context, options = defaultAssetUrlOptions) => {
|
|
|
1050
1106
|
}
|
|
1051
1107
|
const assetAttrs = (attrs || []).concat(wildCardAttrs || []);
|
|
1052
1108
|
node.props.forEach((attr, index) => {
|
|
1053
|
-
if (attr.type !== 6 /* ATTRIBUTE */ ||
|
|
1109
|
+
if (attr.type !== 6 /* NodeTypes.ATTRIBUTE */ ||
|
|
1054
1110
|
!assetAttrs.includes(attr.name) ||
|
|
1055
1111
|
!attr.value ||
|
|
1056
1112
|
isExternalUrl(attr.value.content) ||
|
|
@@ -1080,7 +1136,7 @@ const transformAssetUrl = (node, context, options = defaultAssetUrlOptions) => {
|
|
|
1080
1136
|
// absolute url (e.g. webpack file-loader)
|
|
1081
1137
|
const exp = getImportsExpressionExp(url.path, url.hash, attr.loc, context);
|
|
1082
1138
|
node.props[index] = {
|
|
1083
|
-
type: 7 /* DIRECTIVE */,
|
|
1139
|
+
type: 7 /* NodeTypes.DIRECTIVE */,
|
|
1084
1140
|
name: 'bind',
|
|
1085
1141
|
arg: compilerCore.createSimpleExpression(attr.name, true, attr.loc),
|
|
1086
1142
|
exp,
|
|
@@ -1101,30 +1157,30 @@ function getImportsExpressionExp(path, hash, loc, context) {
|
|
|
1101
1157
|
}
|
|
1102
1158
|
else {
|
|
1103
1159
|
name = `_imports_${context.imports.length}`;
|
|
1104
|
-
exp = compilerCore.createSimpleExpression(name, false, loc, 3 /* CAN_STRINGIFY */);
|
|
1160
|
+
exp = compilerCore.createSimpleExpression(name, false, loc, 3 /* ConstantTypes.CAN_STRINGIFY */);
|
|
1105
1161
|
context.imports.push({ exp, path });
|
|
1106
1162
|
}
|
|
1107
1163
|
if (!hash) {
|
|
1108
1164
|
return exp;
|
|
1109
1165
|
}
|
|
1110
1166
|
const hashExp = `${name} + '${hash}'`;
|
|
1111
|
-
const finalExp = compilerCore.createSimpleExpression(hashExp, false, loc, 3 /* CAN_STRINGIFY */);
|
|
1167
|
+
const finalExp = compilerCore.createSimpleExpression(hashExp, false, loc, 3 /* ConstantTypes.CAN_STRINGIFY */);
|
|
1112
1168
|
if (!context.hoistStatic) {
|
|
1113
1169
|
return finalExp;
|
|
1114
1170
|
}
|
|
1115
1171
|
const existingHoistIndex = context.hoists.findIndex(h => {
|
|
1116
1172
|
return (h &&
|
|
1117
|
-
h.type === 4 /* SIMPLE_EXPRESSION */ &&
|
|
1173
|
+
h.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */ &&
|
|
1118
1174
|
!h.isStatic &&
|
|
1119
1175
|
h.content === hashExp);
|
|
1120
1176
|
});
|
|
1121
1177
|
if (existingHoistIndex > -1) {
|
|
1122
|
-
return compilerCore.createSimpleExpression(`_hoisted_${existingHoistIndex + 1}`, false, loc, 3 /* CAN_STRINGIFY */);
|
|
1178
|
+
return compilerCore.createSimpleExpression(`_hoisted_${existingHoistIndex + 1}`, false, loc, 3 /* ConstantTypes.CAN_STRINGIFY */);
|
|
1123
1179
|
}
|
|
1124
1180
|
return context.hoist(finalExp);
|
|
1125
1181
|
}
|
|
1126
1182
|
else {
|
|
1127
|
-
return compilerCore.createSimpleExpression(`''`, false, loc, 3 /* CAN_STRINGIFY */);
|
|
1183
|
+
return compilerCore.createSimpleExpression(`''`, false, loc, 3 /* ConstantTypes.CAN_STRINGIFY */);
|
|
1128
1184
|
}
|
|
1129
1185
|
}
|
|
1130
1186
|
|
|
@@ -1135,10 +1191,10 @@ const createSrcsetTransformWithOptions = (options) => {
|
|
|
1135
1191
|
return (node, context) => transformSrcset(node, context, options);
|
|
1136
1192
|
};
|
|
1137
1193
|
const transformSrcset = (node, context, options = defaultAssetUrlOptions) => {
|
|
1138
|
-
if (node.type === 1 /* ELEMENT */) {
|
|
1194
|
+
if (node.type === 1 /* NodeTypes.ELEMENT */) {
|
|
1139
1195
|
if (srcsetTags.includes(node.tag) && node.props.length) {
|
|
1140
1196
|
node.props.forEach((attr, index) => {
|
|
1141
|
-
if (attr.name === 'srcset' && attr.type === 6 /* ATTRIBUTE */) {
|
|
1197
|
+
if (attr.name === 'srcset' && attr.type === 6 /* NodeTypes.ATTRIBUTE */) {
|
|
1142
1198
|
if (!attr.value)
|
|
1143
1199
|
return;
|
|
1144
1200
|
const value = attr.value.content;
|
|
@@ -1203,17 +1259,17 @@ const transformSrcset = (node, context, options = defaultAssetUrlOptions) => {
|
|
|
1203
1259
|
if (path) {
|
|
1204
1260
|
const existingImportsIndex = context.imports.findIndex(i => i.path === path);
|
|
1205
1261
|
if (existingImportsIndex > -1) {
|
|
1206
|
-
exp = compilerCore.createSimpleExpression(`_imports_${existingImportsIndex}`, false, attr.loc, 3 /* CAN_STRINGIFY */);
|
|
1262
|
+
exp = compilerCore.createSimpleExpression(`_imports_${existingImportsIndex}`, false, attr.loc, 3 /* ConstantTypes.CAN_STRINGIFY */);
|
|
1207
1263
|
}
|
|
1208
1264
|
else {
|
|
1209
|
-
exp = compilerCore.createSimpleExpression(`_imports_${context.imports.length}`, false, attr.loc, 3 /* CAN_STRINGIFY */);
|
|
1265
|
+
exp = compilerCore.createSimpleExpression(`_imports_${context.imports.length}`, false, attr.loc, 3 /* ConstantTypes.CAN_STRINGIFY */);
|
|
1210
1266
|
context.imports.push({ exp, path });
|
|
1211
1267
|
}
|
|
1212
1268
|
compoundExpression.children.push(exp);
|
|
1213
1269
|
}
|
|
1214
1270
|
}
|
|
1215
1271
|
else {
|
|
1216
|
-
const exp = compilerCore.createSimpleExpression(`"${url}"`, false, attr.loc, 3 /* CAN_STRINGIFY */);
|
|
1272
|
+
const exp = compilerCore.createSimpleExpression(`"${url}"`, false, attr.loc, 3 /* ConstantTypes.CAN_STRINGIFY */);
|
|
1217
1273
|
compoundExpression.children.push(exp);
|
|
1218
1274
|
}
|
|
1219
1275
|
const isNotLast = imageCandidates.length - 1 > index;
|
|
@@ -1230,10 +1286,10 @@ const transformSrcset = (node, context, options = defaultAssetUrlOptions) => {
|
|
|
1230
1286
|
let exp = compoundExpression;
|
|
1231
1287
|
if (context.hoistStatic) {
|
|
1232
1288
|
exp = context.hoist(compoundExpression);
|
|
1233
|
-
exp.constType = 3 /* CAN_STRINGIFY */;
|
|
1289
|
+
exp.constType = 3 /* ConstantTypes.CAN_STRINGIFY */;
|
|
1234
1290
|
}
|
|
1235
1291
|
node.props[index] = {
|
|
1236
|
-
type: 7 /* DIRECTIVE */,
|
|
1292
|
+
type: 7 /* NodeTypes.DIRECTIVE */,
|
|
1237
1293
|
name: 'bind',
|
|
1238
1294
|
arg: compilerCore.createSimpleExpression('srcset', true, attr.loc),
|
|
1239
1295
|
exp,
|
|
@@ -3295,9 +3351,14 @@ function rewriteDefault(input, as, parserPlugins) {
|
|
|
3295
3351
|
plugins: parserPlugins
|
|
3296
3352
|
}).program.body;
|
|
3297
3353
|
ast.forEach(node => {
|
|
3298
|
-
var _a;
|
|
3299
3354
|
if (node.type === 'ExportDefaultDeclaration') {
|
|
3300
|
-
|
|
3355
|
+
if (node.declaration.type === 'ClassDeclaration') {
|
|
3356
|
+
s.overwrite(node.start, node.declaration.id.start, `class `);
|
|
3357
|
+
s.append(`\nconst ${as} = ${node.declaration.id.name}`);
|
|
3358
|
+
}
|
|
3359
|
+
else {
|
|
3360
|
+
s.overwrite(node.start, node.declaration.start, `const ${as} = `);
|
|
3361
|
+
}
|
|
3301
3362
|
}
|
|
3302
3363
|
if (node.type === 'ExportNamedDeclaration') {
|
|
3303
3364
|
for (const specifier of node.specifiers) {
|
|
@@ -3314,7 +3375,7 @@ function rewriteDefault(input, as, parserPlugins) {
|
|
|
3314
3375
|
}
|
|
3315
3376
|
else {
|
|
3316
3377
|
const end = specifierEnd(input, specifier.exported.end, node.end);
|
|
3317
|
-
s.prepend(`import { ${input.slice(specifier.local.start, specifier.local.end)} } from '${
|
|
3378
|
+
s.prepend(`import { ${input.slice(specifier.local.start, specifier.local.end)} } from '${node.source.value}'\n`);
|
|
3318
3379
|
s.overwrite(specifier.start, end, ``);
|
|
3319
3380
|
s.append(`\nconst ${as} = ${specifier.local.name}`);
|
|
3320
3381
|
continue;
|
|
@@ -3402,8 +3463,12 @@ function compileScript(sfc, options) {
|
|
|
3402
3463
|
}
|
|
3403
3464
|
if (options.babelParserPlugins)
|
|
3404
3465
|
plugins.push(...options.babelParserPlugins);
|
|
3405
|
-
if (isTS)
|
|
3406
|
-
plugins.push('typescript'
|
|
3466
|
+
if (isTS) {
|
|
3467
|
+
plugins.push('typescript');
|
|
3468
|
+
if (!plugins.includes('decorators')) {
|
|
3469
|
+
plugins.push('decorators-legacy');
|
|
3470
|
+
}
|
|
3471
|
+
}
|
|
3407
3472
|
if (!scriptSetup) {
|
|
3408
3473
|
if (!script) {
|
|
3409
3474
|
throw new Error(`[@vue/compiler-sfc] SFC contains no <script> tags.`);
|
|
@@ -4131,7 +4196,7 @@ function compileScript(sfc, options) {
|
|
|
4131
4196
|
if (isTS) {
|
|
4132
4197
|
// runtime enum
|
|
4133
4198
|
if (node.type === 'TSEnumDeclaration') {
|
|
4134
|
-
registerBinding(setupBindings, node.id, "setup-const" /* SETUP_CONST */);
|
|
4199
|
+
registerBinding(setupBindings, node.id, "setup-const" /* BindingTypes.SETUP_CONST */);
|
|
4135
4200
|
}
|
|
4136
4201
|
// move all Type declarations to outer scope
|
|
4137
4202
|
if (node.type.startsWith('TS') ||
|
|
@@ -4193,22 +4258,22 @@ function compileScript(sfc, options) {
|
|
|
4193
4258
|
}
|
|
4194
4259
|
if (propsRuntimeDecl) {
|
|
4195
4260
|
for (const key of getObjectOrArrayExpressionKeys(propsRuntimeDecl)) {
|
|
4196
|
-
bindingMetadata[key] = "props" /* PROPS */;
|
|
4261
|
+
bindingMetadata[key] = "props" /* BindingTypes.PROPS */;
|
|
4197
4262
|
}
|
|
4198
4263
|
}
|
|
4199
4264
|
for (const key in typeDeclaredProps) {
|
|
4200
|
-
bindingMetadata[key] = "props" /* PROPS */;
|
|
4265
|
+
bindingMetadata[key] = "props" /* BindingTypes.PROPS */;
|
|
4201
4266
|
}
|
|
4202
4267
|
// props aliases
|
|
4203
4268
|
if (propsDestructureDecl) {
|
|
4204
4269
|
if (propsDestructureRestId) {
|
|
4205
4270
|
bindingMetadata[propsDestructureRestId] =
|
|
4206
|
-
"setup-reactive-const" /* SETUP_REACTIVE_CONST */;
|
|
4271
|
+
"setup-reactive-const" /* BindingTypes.SETUP_REACTIVE_CONST */;
|
|
4207
4272
|
}
|
|
4208
4273
|
for (const key in propsDestructuredBindings) {
|
|
4209
4274
|
const { local } = propsDestructuredBindings[key];
|
|
4210
4275
|
if (local !== key) {
|
|
4211
|
-
bindingMetadata[local] = "props-aliased" /* PROPS_ALIASED */;
|
|
4276
|
+
bindingMetadata[local] = "props-aliased" /* BindingTypes.PROPS_ALIASED */;
|
|
4212
4277
|
(bindingMetadata.__propsAliases ||
|
|
4213
4278
|
(bindingMetadata.__propsAliases = {}))[local] = key;
|
|
4214
4279
|
}
|
|
@@ -4221,8 +4286,8 @@ function compileScript(sfc, options) {
|
|
|
4221
4286
|
imported === '*' ||
|
|
4222
4287
|
(imported === 'default' && source.endsWith('.vue')) ||
|
|
4223
4288
|
source === 'vue'
|
|
4224
|
-
? "setup-const" /* SETUP_CONST */
|
|
4225
|
-
: "setup-maybe-ref" /* SETUP_MAYBE_REF */;
|
|
4289
|
+
? "setup-const" /* BindingTypes.SETUP_CONST */
|
|
4290
|
+
: "setup-maybe-ref" /* BindingTypes.SETUP_MAYBE_REF */;
|
|
4226
4291
|
}
|
|
4227
4292
|
for (const key in scriptBindings) {
|
|
4228
4293
|
bindingMetadata[key] = scriptBindings[key];
|
|
@@ -4233,7 +4298,7 @@ function compileScript(sfc, options) {
|
|
|
4233
4298
|
// known ref bindings
|
|
4234
4299
|
if (refBindings) {
|
|
4235
4300
|
for (const key of refBindings) {
|
|
4236
|
-
bindingMetadata[key] = "setup-ref" /* SETUP_REF */;
|
|
4301
|
+
bindingMetadata[key] = "setup-ref" /* BindingTypes.SETUP_REF */;
|
|
4237
4302
|
}
|
|
4238
4303
|
}
|
|
4239
4304
|
// 8. inject `useCssVars` calls
|
|
@@ -4366,7 +4431,7 @@ function compileScript(sfc, options) {
|
|
|
4366
4431
|
if (!hasDefaultExportName && filename && filename !== DEFAULT_FILENAME) {
|
|
4367
4432
|
const match = filename.match(/([^/\\]+)\.\w+$/);
|
|
4368
4433
|
if (match) {
|
|
4369
|
-
runtimeOptions += `\n
|
|
4434
|
+
runtimeOptions += `\n __name: '${match[1]}',`;
|
|
4370
4435
|
}
|
|
4371
4436
|
}
|
|
4372
4437
|
if (hasInlinedSsrRenderFn) {
|
|
@@ -4467,8 +4532,8 @@ function walkDeclaration(node, bindings, userImportAlias) {
|
|
|
4467
4532
|
if (isCallOf(init, userReactiveBinding)) {
|
|
4468
4533
|
// treat reactive() calls as let since it's meant to be mutable
|
|
4469
4534
|
bindingType = isConst
|
|
4470
|
-
? "setup-reactive-const" /* SETUP_REACTIVE_CONST */
|
|
4471
|
-
: "setup-let" /* SETUP_LET */;
|
|
4535
|
+
? "setup-reactive-const" /* BindingTypes.SETUP_REACTIVE_CONST */
|
|
4536
|
+
: "setup-let" /* BindingTypes.SETUP_LET */;
|
|
4472
4537
|
}
|
|
4473
4538
|
else if (
|
|
4474
4539
|
// if a declaration is a const literal, we can mark it so that
|
|
@@ -4476,19 +4541,19 @@ function walkDeclaration(node, bindings, userImportAlias) {
|
|
|
4476
4541
|
isDefineCall ||
|
|
4477
4542
|
(isConst && canNeverBeRef(init, userReactiveBinding))) {
|
|
4478
4543
|
bindingType = isCallOf(init, DEFINE_PROPS)
|
|
4479
|
-
? "setup-reactive-const" /* SETUP_REACTIVE_CONST */
|
|
4480
|
-
: "setup-const" /* SETUP_CONST */;
|
|
4544
|
+
? "setup-reactive-const" /* BindingTypes.SETUP_REACTIVE_CONST */
|
|
4545
|
+
: "setup-const" /* BindingTypes.SETUP_CONST */;
|
|
4481
4546
|
}
|
|
4482
4547
|
else if (isConst) {
|
|
4483
4548
|
if (isCallOf(init, userImportAlias['ref'] || 'ref')) {
|
|
4484
|
-
bindingType = "setup-ref" /* SETUP_REF */;
|
|
4549
|
+
bindingType = "setup-ref" /* BindingTypes.SETUP_REF */;
|
|
4485
4550
|
}
|
|
4486
4551
|
else {
|
|
4487
|
-
bindingType = "setup-maybe-ref" /* SETUP_MAYBE_REF */;
|
|
4552
|
+
bindingType = "setup-maybe-ref" /* BindingTypes.SETUP_MAYBE_REF */;
|
|
4488
4553
|
}
|
|
4489
4554
|
}
|
|
4490
4555
|
else {
|
|
4491
|
-
bindingType = "setup-let" /* SETUP_LET */;
|
|
4556
|
+
bindingType = "setup-let" /* BindingTypes.SETUP_LET */;
|
|
4492
4557
|
}
|
|
4493
4558
|
registerBinding(bindings, id, bindingType);
|
|
4494
4559
|
}
|
|
@@ -4511,7 +4576,7 @@ function walkDeclaration(node, bindings, userImportAlias) {
|
|
|
4511
4576
|
node.type === 'ClassDeclaration') {
|
|
4512
4577
|
// export function foo() {} / export class Foo {}
|
|
4513
4578
|
// export declarations must be named.
|
|
4514
|
-
bindings[node.id.name] = "setup-const" /* SETUP_CONST */;
|
|
4579
|
+
bindings[node.id.name] = "setup-const" /* BindingTypes.SETUP_CONST */;
|
|
4515
4580
|
}
|
|
4516
4581
|
}
|
|
4517
4582
|
function walkObjectPattern(node, bindings, isConst, isDefineCall = false) {
|
|
@@ -4520,10 +4585,10 @@ function walkObjectPattern(node, bindings, isConst, isDefineCall = false) {
|
|
|
4520
4585
|
if (p.key.type === 'Identifier' && p.key === p.value) {
|
|
4521
4586
|
// shorthand: const { x } = ...
|
|
4522
4587
|
const type = isDefineCall
|
|
4523
|
-
? "setup-const" /* SETUP_CONST */
|
|
4588
|
+
? "setup-const" /* BindingTypes.SETUP_CONST */
|
|
4524
4589
|
: isConst
|
|
4525
|
-
? "setup-maybe-ref" /* SETUP_MAYBE_REF */
|
|
4526
|
-
: "setup-let" /* SETUP_LET */;
|
|
4590
|
+
? "setup-maybe-ref" /* BindingTypes.SETUP_MAYBE_REF */
|
|
4591
|
+
: "setup-let" /* BindingTypes.SETUP_LET */;
|
|
4527
4592
|
registerBinding(bindings, p.key, type);
|
|
4528
4593
|
}
|
|
4529
4594
|
else {
|
|
@@ -4533,7 +4598,7 @@ function walkObjectPattern(node, bindings, isConst, isDefineCall = false) {
|
|
|
4533
4598
|
else {
|
|
4534
4599
|
// ...rest
|
|
4535
4600
|
// argument can only be identifier when destructuring
|
|
4536
|
-
const type = isConst ? "setup-const" /* SETUP_CONST */ : "setup-let" /* SETUP_LET */;
|
|
4601
|
+
const type = isConst ? "setup-const" /* BindingTypes.SETUP_CONST */ : "setup-let" /* BindingTypes.SETUP_LET */;
|
|
4537
4602
|
registerBinding(bindings, p.argument, type);
|
|
4538
4603
|
}
|
|
4539
4604
|
}
|
|
@@ -4546,15 +4611,15 @@ function walkArrayPattern(node, bindings, isConst, isDefineCall = false) {
|
|
|
4546
4611
|
function walkPattern(node, bindings, isConst, isDefineCall = false) {
|
|
4547
4612
|
if (node.type === 'Identifier') {
|
|
4548
4613
|
const type = isDefineCall
|
|
4549
|
-
? "setup-const" /* SETUP_CONST */
|
|
4614
|
+
? "setup-const" /* BindingTypes.SETUP_CONST */
|
|
4550
4615
|
: isConst
|
|
4551
|
-
? "setup-maybe-ref" /* SETUP_MAYBE_REF */
|
|
4552
|
-
: "setup-let" /* SETUP_LET */;
|
|
4616
|
+
? "setup-maybe-ref" /* BindingTypes.SETUP_MAYBE_REF */
|
|
4617
|
+
: "setup-let" /* BindingTypes.SETUP_LET */;
|
|
4553
4618
|
registerBinding(bindings, node, type);
|
|
4554
4619
|
}
|
|
4555
4620
|
else if (node.type === 'RestElement') {
|
|
4556
4621
|
// argument can only be identifier when destructuring
|
|
4557
|
-
const type = isConst ? "setup-const" /* SETUP_CONST */ : "setup-let" /* SETUP_LET */;
|
|
4622
|
+
const type = isConst ? "setup-const" /* BindingTypes.SETUP_CONST */ : "setup-let" /* BindingTypes.SETUP_LET */;
|
|
4558
4623
|
registerBinding(bindings, node.argument, type);
|
|
4559
4624
|
}
|
|
4560
4625
|
else if (node.type === 'ObjectPattern') {
|
|
@@ -4566,10 +4631,10 @@ function walkPattern(node, bindings, isConst, isDefineCall = false) {
|
|
|
4566
4631
|
else if (node.type === 'AssignmentPattern') {
|
|
4567
4632
|
if (node.left.type === 'Identifier') {
|
|
4568
4633
|
const type = isDefineCall
|
|
4569
|
-
? "setup-const" /* SETUP_CONST */
|
|
4634
|
+
? "setup-const" /* BindingTypes.SETUP_CONST */
|
|
4570
4635
|
: isConst
|
|
4571
|
-
? "setup-maybe-ref" /* SETUP_MAYBE_REF */
|
|
4572
|
-
: "setup-let" /* SETUP_LET */;
|
|
4636
|
+
? "setup-maybe-ref" /* BindingTypes.SETUP_MAYBE_REF */
|
|
4637
|
+
: "setup-let" /* BindingTypes.SETUP_LET */;
|
|
4573
4638
|
registerBinding(bindings, node.left, type);
|
|
4574
4639
|
}
|
|
4575
4640
|
else {
|
|
@@ -4789,7 +4854,7 @@ function analyzeBindingsFromOptions(node) {
|
|
|
4789
4854
|
// props: ['foo']
|
|
4790
4855
|
// props: { foo: ... }
|
|
4791
4856
|
for (const key of getObjectOrArrayExpressionKeys(property.value)) {
|
|
4792
|
-
bindings[key] = "props" /* PROPS */;
|
|
4857
|
+
bindings[key] = "props" /* BindingTypes.PROPS */;
|
|
4793
4858
|
}
|
|
4794
4859
|
}
|
|
4795
4860
|
// inject
|
|
@@ -4797,7 +4862,7 @@ function analyzeBindingsFromOptions(node) {
|
|
|
4797
4862
|
// inject: ['foo']
|
|
4798
4863
|
// inject: { foo: {} }
|
|
4799
4864
|
for (const key of getObjectOrArrayExpressionKeys(property.value)) {
|
|
4800
|
-
bindings[key] = "options" /* OPTIONS */;
|
|
4865
|
+
bindings[key] = "options" /* BindingTypes.OPTIONS */;
|
|
4801
4866
|
}
|
|
4802
4867
|
}
|
|
4803
4868
|
// computed & methods
|
|
@@ -4806,7 +4871,7 @@ function analyzeBindingsFromOptions(node) {
|
|
|
4806
4871
|
// methods: { foo() {} }
|
|
4807
4872
|
// computed: { foo() {} }
|
|
4808
4873
|
for (const key of getObjectExpressionKeys(property.value)) {
|
|
4809
|
-
bindings[key] = "options" /* OPTIONS */;
|
|
4874
|
+
bindings[key] = "options" /* BindingTypes.OPTIONS */;
|
|
4810
4875
|
}
|
|
4811
4876
|
}
|
|
4812
4877
|
}
|
|
@@ -4826,8 +4891,8 @@ function analyzeBindingsFromOptions(node) {
|
|
|
4826
4891
|
for (const key of getObjectExpressionKeys(bodyItem.argument)) {
|
|
4827
4892
|
bindings[key] =
|
|
4828
4893
|
property.key.name === 'setup'
|
|
4829
|
-
? "setup-maybe-ref" /* SETUP_MAYBE_REF */
|
|
4830
|
-
: "data" /* DATA */;
|
|
4894
|
+
? "setup-maybe-ref" /* BindingTypes.SETUP_MAYBE_REF */
|
|
4895
|
+
: "data" /* BindingTypes.DATA */;
|
|
4831
4896
|
}
|
|
4832
4897
|
}
|
|
4833
4898
|
}
|
|
@@ -4879,14 +4944,14 @@ function resolveTemplateUsageCheckString(sfc) {
|
|
|
4879
4944
|
CompilerDOM.transform(CompilerDOM.createRoot([ast]), {
|
|
4880
4945
|
nodeTransforms: [
|
|
4881
4946
|
node => {
|
|
4882
|
-
if (node.type === 1 /* ELEMENT */) {
|
|
4947
|
+
if (node.type === 1 /* NodeTypes.ELEMENT */) {
|
|
4883
4948
|
if (!CompilerDOM.parserOptions.isNativeTag(node.tag) &&
|
|
4884
4949
|
!CompilerDOM.parserOptions.isBuiltInComponent(node.tag)) {
|
|
4885
4950
|
code += `,${shared.camelize(node.tag)},${shared.capitalize(shared.camelize(node.tag))}`;
|
|
4886
4951
|
}
|
|
4887
4952
|
for (let i = 0; i < node.props.length; i++) {
|
|
4888
4953
|
const prop = node.props[i];
|
|
4889
|
-
if (prop.type === 7 /* DIRECTIVE */) {
|
|
4954
|
+
if (prop.type === 7 /* NodeTypes.DIRECTIVE */) {
|
|
4890
4955
|
if (!isBuiltInDir(prop.name)) {
|
|
4891
4956
|
code += `,v${shared.capitalize(shared.camelize(prop.name))}`;
|
|
4892
4957
|
}
|
|
@@ -4896,7 +4961,7 @@ function resolveTemplateUsageCheckString(sfc) {
|
|
|
4896
4961
|
}
|
|
4897
4962
|
}
|
|
4898
4963
|
}
|
|
4899
|
-
else if (node.type === 5 /* INTERPOLATION */) {
|
|
4964
|
+
else if (node.type === 5 /* NodeTypes.INTERPOLATION */) {
|
|
4900
4965
|
code += `,${processExp(node.content.content)}`;
|
|
4901
4966
|
}
|
|
4902
4967
|
}
|
|
@@ -4912,6 +4977,9 @@ function processExp(exp, dir) {
|
|
|
4912
4977
|
if (dir === 'slot') {
|
|
4913
4978
|
exp = `(${exp})=>{}`;
|
|
4914
4979
|
}
|
|
4980
|
+
else if (dir === 'on') {
|
|
4981
|
+
exp = `()=>{${exp}}`;
|
|
4982
|
+
}
|
|
4915
4983
|
else if (dir === 'for') {
|
|
4916
4984
|
const inMatch = exp.match(forAliasRE);
|
|
4917
4985
|
if (inMatch) {
|
|
@@ -5001,15 +5069,15 @@ function parse(source, { sourceMap = true, filename = DEFAULT_FILENAME, sourceRo
|
|
|
5001
5069
|
if ((!parent && tag !== 'template') ||
|
|
5002
5070
|
// <template lang="xxx"> should also be treated as raw text
|
|
5003
5071
|
(tag === 'template' &&
|
|
5004
|
-
props.some(p => p.type === 6 /* ATTRIBUTE */ &&
|
|
5072
|
+
props.some(p => p.type === 6 /* NodeTypes.ATTRIBUTE */ &&
|
|
5005
5073
|
p.name === 'lang' &&
|
|
5006
5074
|
p.value &&
|
|
5007
5075
|
p.value.content &&
|
|
5008
5076
|
p.value.content !== 'html'))) {
|
|
5009
|
-
return 2 /* RAWTEXT */;
|
|
5077
|
+
return 2 /* TextModes.RAWTEXT */;
|
|
5010
5078
|
}
|
|
5011
5079
|
else {
|
|
5012
|
-
return 0 /* DATA */;
|
|
5080
|
+
return 0 /* TextModes.DATA */;
|
|
5013
5081
|
}
|
|
5014
5082
|
},
|
|
5015
5083
|
onError: e => {
|
|
@@ -5017,7 +5085,7 @@ function parse(source, { sourceMap = true, filename = DEFAULT_FILENAME, sourceRo
|
|
|
5017
5085
|
}
|
|
5018
5086
|
});
|
|
5019
5087
|
ast.children.forEach(node => {
|
|
5020
|
-
if (node.type !== 1 /* ELEMENT */) {
|
|
5088
|
+
if (node.type !== 1 /* NodeTypes.ELEMENT */) {
|
|
5021
5089
|
return;
|
|
5022
5090
|
}
|
|
5023
5091
|
// we only want to keep the nodes that are not empty (when the tag is not a template)
|
|
@@ -5148,7 +5216,7 @@ function createBlock(node, source, pad) {
|
|
|
5148
5216
|
block.content = padContent(source, block, pad) + block.content;
|
|
5149
5217
|
}
|
|
5150
5218
|
node.props.forEach(p => {
|
|
5151
|
-
if (p.type === 6 /* ATTRIBUTE */) {
|
|
5219
|
+
if (p.type === 6 /* NodeTypes.ATTRIBUTE */) {
|
|
5152
5220
|
attrs[p.name] = p.value ? p.value.content || true : true;
|
|
5153
5221
|
if (p.name === 'lang') {
|
|
5154
5222
|
block.lang = p.value && p.value.content;
|
|
@@ -5216,7 +5284,7 @@ function padContent(content, block, pad) {
|
|
|
5216
5284
|
}
|
|
5217
5285
|
function hasSrc(node) {
|
|
5218
5286
|
return node.props.some(p => {
|
|
5219
|
-
if (p.type !== 6 /* ATTRIBUTE */) {
|
|
5287
|
+
if (p.type !== 6 /* NodeTypes.ATTRIBUTE */) {
|
|
5220
5288
|
return false;
|
|
5221
5289
|
}
|
|
5222
5290
|
return p.name === 'src';
|
|
@@ -5229,7 +5297,7 @@ function hasSrc(node) {
|
|
|
5229
5297
|
function isEmpty(node) {
|
|
5230
5298
|
for (let i = 0; i < node.children.length; i++) {
|
|
5231
5299
|
const child = node.children[i];
|
|
5232
|
-
if (child.type !== 2 /* TEXT */ || child.content.trim() !== '') {
|
|
5300
|
+
if (child.type !== 2 /* NodeTypes.TEXT */ || child.content.trim() !== '') {
|
|
5233
5301
|
return false;
|
|
5234
5302
|
}
|
|
5235
5303
|
}
|