@vue/compiler-sfc 2.7.0 → 2.7.3
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.js +70 -67
- package/package.json +1 -1
package/dist/compiler-sfc.js
CHANGED
|
@@ -329,7 +329,7 @@ function hasChanged(x, y) {
|
|
|
329
329
|
return x === 0 && 1 / x !== 1 / y;
|
|
330
330
|
}
|
|
331
331
|
else {
|
|
332
|
-
return x === x
|
|
332
|
+
return x === x || y === y;
|
|
333
333
|
}
|
|
334
334
|
}
|
|
335
335
|
|
|
@@ -646,6 +646,7 @@ const DEFAULT_FILENAME = 'anonymous.vue';
|
|
|
646
646
|
const splitRE$1 = /\r?\n/g;
|
|
647
647
|
const replaceRE = /./g;
|
|
648
648
|
const isSpecialTag = makeMap('script,style,template', true);
|
|
649
|
+
const isNeedIndentLang = makeMap('pug,jade');
|
|
649
650
|
/**
|
|
650
651
|
* Parse a single-file component (*.vue) file into an SFC Descriptor Object.
|
|
651
652
|
*/
|
|
@@ -740,7 +741,9 @@ function parseComponent(source, options = {}) {
|
|
|
740
741
|
if (depth === 1 && currentBlock) {
|
|
741
742
|
currentBlock.end = start;
|
|
742
743
|
let text = source.slice(currentBlock.start, currentBlock.end);
|
|
743
|
-
if (options.deindent
|
|
744
|
+
if (options.deindent ||
|
|
745
|
+
// certain langs like pug are indent sensitive, preserve old behavior
|
|
746
|
+
(currentBlock.lang && isNeedIndentLang(currentBlock.lang))) {
|
|
744
747
|
text = deIndent(text);
|
|
745
748
|
}
|
|
746
749
|
// pad content so that linters and pre-processors can output correct
|
|
@@ -3347,7 +3350,9 @@ const LIFECYCLE_HOOKS = [
|
|
|
3347
3350
|
'activated',
|
|
3348
3351
|
'deactivated',
|
|
3349
3352
|
'errorCaptured',
|
|
3350
|
-
'serverPrefetch'
|
|
3353
|
+
'serverPrefetch',
|
|
3354
|
+
'renderTracked',
|
|
3355
|
+
'renderTriggered'
|
|
3351
3356
|
];
|
|
3352
3357
|
|
|
3353
3358
|
var config = {
|
|
@@ -5186,6 +5191,13 @@ let shouldObserve = true;
|
|
|
5186
5191
|
function toggleObserving(value) {
|
|
5187
5192
|
shouldObserve = value;
|
|
5188
5193
|
}
|
|
5194
|
+
// ssr mock dep
|
|
5195
|
+
const mockDep = {
|
|
5196
|
+
notify: noop,
|
|
5197
|
+
depend: noop,
|
|
5198
|
+
addSub: noop,
|
|
5199
|
+
removeSub: noop
|
|
5200
|
+
};
|
|
5189
5201
|
/**
|
|
5190
5202
|
* Observer class that is attached to each observed
|
|
5191
5203
|
* object. Once attached, the observer converts the target
|
|
@@ -5193,76 +5205,60 @@ function toggleObserving(value) {
|
|
|
5193
5205
|
* collect dependencies and dispatch updates.
|
|
5194
5206
|
*/
|
|
5195
5207
|
class Observer {
|
|
5196
|
-
constructor(value, shallow = false) {
|
|
5208
|
+
constructor(value, shallow = false, mock = false) {
|
|
5197
5209
|
this.value = value;
|
|
5198
5210
|
this.shallow = shallow;
|
|
5211
|
+
this.mock = mock;
|
|
5199
5212
|
// this.value = value
|
|
5200
|
-
this.dep = new Dep();
|
|
5213
|
+
this.dep = mock ? mockDep : new Dep();
|
|
5201
5214
|
this.vmCount = 0;
|
|
5202
5215
|
def(value, '__ob__', this);
|
|
5203
5216
|
if (isArray(value)) {
|
|
5204
|
-
if (
|
|
5205
|
-
|
|
5206
|
-
|
|
5207
|
-
|
|
5208
|
-
|
|
5217
|
+
if (!mock) {
|
|
5218
|
+
if (hasProto) {
|
|
5219
|
+
value.__proto__ = arrayMethods;
|
|
5220
|
+
/* eslint-enable no-proto */
|
|
5221
|
+
}
|
|
5222
|
+
else {
|
|
5223
|
+
for (let i = 0, l = arrayKeys.length; i < l; i++) {
|
|
5224
|
+
const key = arrayKeys[i];
|
|
5225
|
+
def(value, key, arrayMethods[key]);
|
|
5226
|
+
}
|
|
5227
|
+
}
|
|
5209
5228
|
}
|
|
5210
5229
|
if (!shallow) {
|
|
5211
5230
|
this.observeArray(value);
|
|
5212
5231
|
}
|
|
5213
5232
|
}
|
|
5214
5233
|
else {
|
|
5215
|
-
|
|
5216
|
-
|
|
5217
|
-
|
|
5218
|
-
|
|
5219
|
-
|
|
5220
|
-
|
|
5221
|
-
|
|
5222
|
-
|
|
5223
|
-
|
|
5224
|
-
|
|
5225
|
-
for (let i = 0; i < keys.length; i++) {
|
|
5226
|
-
const key = keys[i];
|
|
5227
|
-
defineReactive(obj, key, NO_INIITIAL_VALUE, undefined, shallow);
|
|
5234
|
+
/**
|
|
5235
|
+
* Walk through all properties and convert them into
|
|
5236
|
+
* getter/setters. This method should only be called when
|
|
5237
|
+
* value type is Object.
|
|
5238
|
+
*/
|
|
5239
|
+
const keys = Object.keys(value);
|
|
5240
|
+
for (let i = 0; i < keys.length; i++) {
|
|
5241
|
+
const key = keys[i];
|
|
5242
|
+
defineReactive(value, key, NO_INIITIAL_VALUE, undefined, shallow, mock);
|
|
5243
|
+
}
|
|
5228
5244
|
}
|
|
5229
5245
|
}
|
|
5230
5246
|
/**
|
|
5231
5247
|
* Observe a list of Array items.
|
|
5232
5248
|
*/
|
|
5233
|
-
observeArray(
|
|
5234
|
-
for (let i = 0, l =
|
|
5235
|
-
observe(
|
|
5249
|
+
observeArray(value) {
|
|
5250
|
+
for (let i = 0, l = value.length; i < l; i++) {
|
|
5251
|
+
observe(value[i], false, this.mock);
|
|
5236
5252
|
}
|
|
5237
5253
|
}
|
|
5238
5254
|
}
|
|
5239
5255
|
// helpers
|
|
5240
|
-
/**
|
|
5241
|
-
* Augment a target Object or Array by intercepting
|
|
5242
|
-
* the prototype chain using __proto__
|
|
5243
|
-
*/
|
|
5244
|
-
function protoAugment(target, src) {
|
|
5245
|
-
/* eslint-disable no-proto */
|
|
5246
|
-
target.__proto__ = src;
|
|
5247
|
-
/* eslint-enable no-proto */
|
|
5248
|
-
}
|
|
5249
|
-
/**
|
|
5250
|
-
* Augment a target Object or Array by defining
|
|
5251
|
-
* hidden properties.
|
|
5252
|
-
*/
|
|
5253
|
-
/* istanbul ignore next */
|
|
5254
|
-
function copyAugment(target, src, keys) {
|
|
5255
|
-
for (let i = 0, l = keys.length; i < l; i++) {
|
|
5256
|
-
const key = keys[i];
|
|
5257
|
-
def(target, key, src[key]);
|
|
5258
|
-
}
|
|
5259
|
-
}
|
|
5260
5256
|
/**
|
|
5261
5257
|
* Attempt to create an observer instance for a value,
|
|
5262
5258
|
* returns the new observer if successfully observed,
|
|
5263
5259
|
* or the existing observer if the value already has one.
|
|
5264
5260
|
*/
|
|
5265
|
-
function observe(value, shallow) {
|
|
5261
|
+
function observe(value, shallow, ssrMockReactivity) {
|
|
5266
5262
|
if (!isObject$1(value) || isRef(value) || value instanceof VNode) {
|
|
5267
5263
|
return;
|
|
5268
5264
|
}
|
|
@@ -5271,18 +5267,18 @@ function observe(value, shallow) {
|
|
|
5271
5267
|
ob = value.__ob__;
|
|
5272
5268
|
}
|
|
5273
5269
|
else if (shouldObserve &&
|
|
5274
|
-
!isServerRendering() &&
|
|
5270
|
+
(ssrMockReactivity || !isServerRendering()) &&
|
|
5275
5271
|
(isArray(value) || isPlainObject(value)) &&
|
|
5276
5272
|
Object.isExtensible(value) &&
|
|
5277
|
-
!value.__v_skip) {
|
|
5278
|
-
ob = new Observer(value, shallow);
|
|
5273
|
+
!value.__v_skip /* ReactiveFlags.SKIP */) {
|
|
5274
|
+
ob = new Observer(value, shallow, ssrMockReactivity);
|
|
5279
5275
|
}
|
|
5280
5276
|
return ob;
|
|
5281
5277
|
}
|
|
5282
5278
|
/**
|
|
5283
5279
|
* Define a reactive property on an Object.
|
|
5284
5280
|
*/
|
|
5285
|
-
function defineReactive(obj, key, val, customSetter, shallow) {
|
|
5281
|
+
function defineReactive(obj, key, val, customSetter, shallow, mock) {
|
|
5286
5282
|
const dep = new Dep();
|
|
5287
5283
|
const property = Object.getOwnPropertyDescriptor(obj, key);
|
|
5288
5284
|
if (property && property.configurable === false) {
|
|
@@ -5295,7 +5291,7 @@ function defineReactive(obj, key, val, customSetter, shallow) {
|
|
|
5295
5291
|
(val === NO_INIITIAL_VALUE || arguments.length === 2)) {
|
|
5296
5292
|
val = obj[key];
|
|
5297
5293
|
}
|
|
5298
|
-
let childOb = !shallow && observe(val);
|
|
5294
|
+
let childOb = !shallow && observe(val, false, mock);
|
|
5299
5295
|
Object.defineProperty(obj, key, {
|
|
5300
5296
|
enumerable: true,
|
|
5301
5297
|
configurable: true,
|
|
@@ -5319,7 +5315,7 @@ function defineReactive(obj, key, val, customSetter, shallow) {
|
|
|
5319
5315
|
}
|
|
5320
5316
|
}
|
|
5321
5317
|
}
|
|
5322
|
-
return isRef(value) ? value.value : value;
|
|
5318
|
+
return isRef(value) && !shallow ? value.value : value;
|
|
5323
5319
|
},
|
|
5324
5320
|
set: function reactiveSetter(newVal) {
|
|
5325
5321
|
const value = getter ? getter.call(obj) : val;
|
|
@@ -5343,7 +5339,7 @@ function defineReactive(obj, key, val, customSetter, shallow) {
|
|
|
5343
5339
|
else {
|
|
5344
5340
|
val = newVal;
|
|
5345
5341
|
}
|
|
5346
|
-
childOb = !shallow && observe(newVal);
|
|
5342
|
+
childOb = !shallow && observe(newVal, false, mock);
|
|
5347
5343
|
if (process.env.NODE_ENV !== 'production') {
|
|
5348
5344
|
dep.notify({
|
|
5349
5345
|
type: "set" /* TriggerOpTypes.SET */,
|
|
@@ -5368,16 +5364,20 @@ function set(target, key, val) {
|
|
|
5368
5364
|
process.env.NODE_ENV !== 'production' && warn$3(`Set operation on key "${key}" failed: target is readonly.`);
|
|
5369
5365
|
return;
|
|
5370
5366
|
}
|
|
5367
|
+
const ob = target.__ob__;
|
|
5371
5368
|
if (isArray(target) && isValidArrayIndex(key)) {
|
|
5372
5369
|
target.length = Math.max(target.length, key);
|
|
5373
5370
|
target.splice(key, 1, val);
|
|
5371
|
+
// when mocking for SSR, array methods are not hijacked
|
|
5372
|
+
if (!ob.shallow && ob.mock) {
|
|
5373
|
+
observe(val, false, true);
|
|
5374
|
+
}
|
|
5374
5375
|
return val;
|
|
5375
5376
|
}
|
|
5376
5377
|
if (key in target && !(key in Object.prototype)) {
|
|
5377
5378
|
target[key] = val;
|
|
5378
5379
|
return val;
|
|
5379
5380
|
}
|
|
5380
|
-
const ob = target.__ob__;
|
|
5381
5381
|
if (target._isVue || (ob && ob.vmCount)) {
|
|
5382
5382
|
process.env.NODE_ENV !== 'production' &&
|
|
5383
5383
|
warn$3('Avoid adding reactive properties to a Vue instance or its root $data ' +
|
|
@@ -5388,7 +5388,7 @@ function set(target, key, val) {
|
|
|
5388
5388
|
target[key] = val;
|
|
5389
5389
|
return val;
|
|
5390
5390
|
}
|
|
5391
|
-
defineReactive(ob.value, key, val);
|
|
5391
|
+
defineReactive(ob.value, key, val, undefined, ob.shallow, ob.mock);
|
|
5392
5392
|
if (process.env.NODE_ENV !== 'production') {
|
|
5393
5393
|
ob.dep.notify({
|
|
5394
5394
|
type: "add" /* TriggerOpTypes.ADD */,
|
|
@@ -8360,18 +8360,14 @@ function compileScript(sfc, options = { id: '' }) {
|
|
|
8360
8360
|
function error(msg, node, end = node.end + startOffset) {
|
|
8361
8361
|
throw new Error(`[@vue/compiler-sfc] ${msg}\n\n${filename}\n${generateCodeFrame(source, node.start + startOffset, end)}`);
|
|
8362
8362
|
}
|
|
8363
|
-
function registerUserImport(source, local, imported, isType, isFromSetup
|
|
8363
|
+
function registerUserImport(source, local, imported, isType, isFromSetup) {
|
|
8364
8364
|
if (source === 'vue' && imported) {
|
|
8365
8365
|
userImportAlias[imported] = local;
|
|
8366
8366
|
}
|
|
8367
8367
|
// template usage check is only needed in non-inline mode, so we can skip
|
|
8368
8368
|
// the work if inlineTemplate is true.
|
|
8369
|
-
let isUsedInTemplate =
|
|
8370
|
-
if (
|
|
8371
|
-
isTS &&
|
|
8372
|
-
sfc.template &&
|
|
8373
|
-
!sfc.template.src &&
|
|
8374
|
-
!sfc.template.lang) {
|
|
8369
|
+
let isUsedInTemplate = true;
|
|
8370
|
+
if (isTS && sfc.template && !sfc.template.src && !sfc.template.lang) {
|
|
8375
8371
|
isUsedInTemplate = isImportUsed(local, sfc);
|
|
8376
8372
|
}
|
|
8377
8373
|
userImports[local] = {
|
|
@@ -8622,7 +8618,7 @@ function compileScript(sfc, options = { id: '' }) {
|
|
|
8622
8618
|
specifier.imported.name;
|
|
8623
8619
|
registerUserImport(node.source.value, specifier.local.name, imported, node.importKind === 'type' ||
|
|
8624
8620
|
(specifier.type === 'ImportSpecifier' &&
|
|
8625
|
-
specifier.importKind === 'type'), false
|
|
8621
|
+
specifier.importKind === 'type'), false);
|
|
8626
8622
|
}
|
|
8627
8623
|
}
|
|
8628
8624
|
else if (node.type === 'ExportDefaultDeclaration') {
|
|
@@ -8791,7 +8787,7 @@ function compileScript(sfc, options = { id: '' }) {
|
|
|
8791
8787
|
else {
|
|
8792
8788
|
registerUserImport(source, local, imported, node.importKind === 'type' ||
|
|
8793
8789
|
(specifier.type === 'ImportSpecifier' &&
|
|
8794
|
-
specifier.importKind === 'type'), true
|
|
8790
|
+
specifier.importKind === 'type'), true);
|
|
8795
8791
|
}
|
|
8796
8792
|
}
|
|
8797
8793
|
if (node.specifiers.length && removed === node.specifiers.length) {
|
|
@@ -9526,7 +9522,11 @@ function resolveTemplateUsageCheckString(sfc) {
|
|
|
9526
9522
|
for (let i = 0; i < attrs.length; i++) {
|
|
9527
9523
|
const { name, value } = attrs[i];
|
|
9528
9524
|
if (dirRE.test(name)) {
|
|
9529
|
-
const baseName =
|
|
9525
|
+
const baseName = onRE.test(name)
|
|
9526
|
+
? 'on'
|
|
9527
|
+
: bindRE.test(name)
|
|
9528
|
+
? 'bind'
|
|
9529
|
+
: name.replace(dirRE, '');
|
|
9530
9530
|
if (!isBuiltInDir$1(baseName)) {
|
|
9531
9531
|
code += `,v${capitalize(camelize(baseName))}`;
|
|
9532
9532
|
}
|
|
@@ -9552,6 +9552,9 @@ function processExp(exp, dir) {
|
|
|
9552
9552
|
if (dir === 'slot') {
|
|
9553
9553
|
exp = `(${exp})=>{}`;
|
|
9554
9554
|
}
|
|
9555
|
+
else if (dir === 'on') {
|
|
9556
|
+
exp = `()=>{${exp}}`;
|
|
9557
|
+
}
|
|
9555
9558
|
else if (dir === 'for') {
|
|
9556
9559
|
const inMatch = exp.match(forAliasRE);
|
|
9557
9560
|
if (inMatch) {
|
|
@@ -9807,7 +9810,7 @@ function transform(node, transformAssetUrlsOptions) {
|
|
|
9807
9810
|
return;
|
|
9808
9811
|
}
|
|
9809
9812
|
const imageCandidates = value
|
|
9810
|
-
.
|
|
9813
|
+
.slice(1, -1)
|
|
9811
9814
|
.split(',')
|
|
9812
9815
|
.map(s => {
|
|
9813
9816
|
// The attribute value arrives here with all whitespace, except
|