@vue/compiler-sfc 2.7.2 → 2.7.5

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.
Files changed (2) hide show
  1. package/dist/compiler-sfc.js +1004 -1000
  2. package/package.json +1 -1
@@ -646,7 +646,6 @@ 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');
650
649
  /**
651
650
  * Parse a single-file component (*.vue) file into an SFC Descriptor Object.
652
651
  */
@@ -741,9 +740,11 @@ function parseComponent(source, options = {}) {
741
740
  if (depth === 1 && currentBlock) {
742
741
  currentBlock.end = start;
743
742
  let text = source.slice(currentBlock.start, currentBlock.end);
744
- if (options.deindent ||
745
- // certain langs like pug are indent sensitive, preserve old behavior
746
- (currentBlock.lang && isNeedIndentLang(currentBlock.lang))) {
743
+ if (options.deindent === true ||
744
+ // by default, deindent unless it's script with default lang or ts
745
+ (options.deindent !== false &&
746
+ !(currentBlock.type === 'script' &&
747
+ (!currentBlock.lang || currentBlock.lang === 'ts')))) {
747
748
  text = deIndent(text);
748
749
  }
749
750
  // pad content so that linters and pre-processors can output correct
@@ -3350,7 +3351,9 @@ const LIFECYCLE_HOOKS = [
3350
3351
  'activated',
3351
3352
  'deactivated',
3352
3353
  'errorCaptured',
3353
- 'serverPrefetch'
3354
+ 'serverPrefetch',
3355
+ 'renderTracked',
3356
+ 'renderTriggered'
3354
3357
  ];
3355
3358
 
3356
3359
  var config = {
@@ -3442,145 +3445,6 @@ function setCurrentInstance(vm = null) {
3442
3445
  vm && vm._scope.on();
3443
3446
  }
3444
3447
 
3445
- let warn$3 = noop;
3446
- let tip = noop;
3447
- let generateComponentTrace; // work around flow check
3448
- let formatComponentName;
3449
- if (process.env.NODE_ENV !== 'production') {
3450
- const hasConsole = typeof console !== 'undefined';
3451
- const classifyRE = /(?:^|[-_])(\w)/g;
3452
- const classify = str => str.replace(classifyRE, c => c.toUpperCase()).replace(/[-_]/g, '');
3453
- warn$3 = (msg, vm = currentInstance) => {
3454
- const trace = vm ? generateComponentTrace(vm) : '';
3455
- if (hasConsole && !config.silent) {
3456
- console.error(`[Vue warn]: ${msg}${trace}`);
3457
- }
3458
- };
3459
- tip = (msg, vm) => {
3460
- if (hasConsole && !config.silent) {
3461
- console.warn(`[Vue tip]: ${msg}` + (vm ? generateComponentTrace(vm) : ''));
3462
- }
3463
- };
3464
- formatComponentName = (vm, includeFile) => {
3465
- if (vm.$root === vm) {
3466
- return '<Root>';
3467
- }
3468
- const options = isFunction(vm) && vm.cid != null
3469
- ? vm.options
3470
- : vm._isVue
3471
- ? vm.$options || vm.constructor.options
3472
- : vm;
3473
- let name = options.name || options._componentTag;
3474
- const file = options.__file;
3475
- if (!name && file) {
3476
- const match = file.match(/([^/\\]+)\.vue$/);
3477
- name = match && match[1];
3478
- }
3479
- return ((name ? `<${classify(name)}>` : `<Anonymous>`) +
3480
- (file && includeFile !== false ? ` at ${file}` : ''));
3481
- };
3482
- const repeat = (str, n) => {
3483
- let res = '';
3484
- while (n) {
3485
- if (n % 2 === 1)
3486
- res += str;
3487
- if (n > 1)
3488
- str += str;
3489
- n >>= 1;
3490
- }
3491
- return res;
3492
- };
3493
- generateComponentTrace = (vm) => {
3494
- if (vm._isVue && vm.$parent) {
3495
- const tree = [];
3496
- let currentRecursiveSequence = 0;
3497
- while (vm) {
3498
- if (tree.length > 0) {
3499
- const last = tree[tree.length - 1];
3500
- if (last.constructor === vm.constructor) {
3501
- currentRecursiveSequence++;
3502
- vm = vm.$parent;
3503
- continue;
3504
- }
3505
- else if (currentRecursiveSequence > 0) {
3506
- tree[tree.length - 1] = [last, currentRecursiveSequence];
3507
- currentRecursiveSequence = 0;
3508
- }
3509
- }
3510
- tree.push(vm);
3511
- vm = vm.$parent;
3512
- }
3513
- return ('\n\nfound in\n\n' +
3514
- tree
3515
- .map((vm, i) => `${i === 0 ? '---> ' : repeat(' ', 5 + i * 2)}${isArray(vm)
3516
- ? `${formatComponentName(vm[0])}... (${vm[1]} recursive calls)`
3517
- : formatComponentName(vm)}`)
3518
- .join('\n'));
3519
- }
3520
- else {
3521
- return `\n\n(found in ${formatComponentName(vm)})`;
3522
- }
3523
- };
3524
- }
3525
-
3526
- let uid = 0;
3527
- /**
3528
- * A dep is an observable that can have multiple
3529
- * directives subscribing to it.
3530
- * @internal
3531
- */
3532
- class Dep {
3533
- constructor() {
3534
- this.id = uid++;
3535
- this.subs = [];
3536
- }
3537
- addSub(sub) {
3538
- this.subs.push(sub);
3539
- }
3540
- removeSub(sub) {
3541
- remove$1(this.subs, sub);
3542
- }
3543
- depend(info) {
3544
- if (Dep.target) {
3545
- Dep.target.addDep(this);
3546
- if (process.env.NODE_ENV !== 'production' && info && Dep.target.onTrack) {
3547
- Dep.target.onTrack(Object.assign({ effect: Dep.target }, info));
3548
- }
3549
- }
3550
- }
3551
- notify(info) {
3552
- // stabilize the subscriber list first
3553
- const subs = this.subs.slice();
3554
- if (process.env.NODE_ENV !== 'production' && !config.async) {
3555
- // subs aren't sorted in scheduler if not running async
3556
- // we need to sort them now to make sure they fire in correct
3557
- // order
3558
- subs.sort((a, b) => a.id - b.id);
3559
- }
3560
- for (let i = 0, l = subs.length; i < l; i++) {
3561
- if (process.env.NODE_ENV !== 'production' && info) {
3562
- const sub = subs[i];
3563
- sub.onTrigger &&
3564
- sub.onTrigger(Object.assign({ effect: subs[i] }, info));
3565
- }
3566
- subs[i].update();
3567
- }
3568
- }
3569
- }
3570
- // The current target watcher being evaluated.
3571
- // This is globally unique because only one watcher
3572
- // can be evaluated at a time.
3573
- Dep.target = null;
3574
- const targetStack = [];
3575
- function pushTarget(target) {
3576
- targetStack.push(target);
3577
- Dep.target = target;
3578
- }
3579
- function popTarget() {
3580
- targetStack.pop();
3581
- Dep.target = targetStack[targetStack.length - 1];
3582
- }
3583
-
3584
3448
  /**
3585
3449
  * @internal
3586
3450
  */
@@ -3647,6 +3511,89 @@ function cloneVNode(vnode) {
3647
3511
  return cloned;
3648
3512
  }
3649
3513
 
3514
+ /* not type checking this file because flow doesn't play well with Proxy */
3515
+ if (process.env.NODE_ENV !== 'production') {
3516
+ makeMap('Infinity,undefined,NaN,isFinite,isNaN,' +
3517
+ 'parseFloat,parseInt,decodeURI,decodeURIComponent,encodeURI,encodeURIComponent,' +
3518
+ 'Math,Number,Date,Array,Object,Boolean,String,RegExp,Map,Set,JSON,Intl,BigInt,' +
3519
+ 'require' // for Webpack/Browserify
3520
+ );
3521
+ const hasProxy = typeof Proxy !== 'undefined' && isNative(Proxy);
3522
+ if (hasProxy) {
3523
+ const isBuiltInModifier = makeMap('stop,prevent,self,ctrl,shift,alt,meta,exact');
3524
+ config.keyCodes = new Proxy(config.keyCodes, {
3525
+ set(target, key, value) {
3526
+ if (isBuiltInModifier(key)) {
3527
+ warn$3(`Avoid overwriting built-in modifier in config.keyCodes: .${key}`);
3528
+ return false;
3529
+ }
3530
+ else {
3531
+ target[key] = value;
3532
+ return true;
3533
+ }
3534
+ }
3535
+ });
3536
+ }
3537
+ }
3538
+
3539
+ let uid = 0;
3540
+ /**
3541
+ * A dep is an observable that can have multiple
3542
+ * directives subscribing to it.
3543
+ * @internal
3544
+ */
3545
+ class Dep {
3546
+ constructor() {
3547
+ this.id = uid++;
3548
+ this.subs = [];
3549
+ }
3550
+ addSub(sub) {
3551
+ this.subs.push(sub);
3552
+ }
3553
+ removeSub(sub) {
3554
+ remove$1(this.subs, sub);
3555
+ }
3556
+ depend(info) {
3557
+ if (Dep.target) {
3558
+ Dep.target.addDep(this);
3559
+ if (process.env.NODE_ENV !== 'production' && info && Dep.target.onTrack) {
3560
+ Dep.target.onTrack(Object.assign({ effect: Dep.target }, info));
3561
+ }
3562
+ }
3563
+ }
3564
+ notify(info) {
3565
+ // stabilize the subscriber list first
3566
+ const subs = this.subs.slice();
3567
+ if (process.env.NODE_ENV !== 'production' && !config.async) {
3568
+ // subs aren't sorted in scheduler if not running async
3569
+ // we need to sort them now to make sure they fire in correct
3570
+ // order
3571
+ subs.sort((a, b) => a.id - b.id);
3572
+ }
3573
+ for (let i = 0, l = subs.length; i < l; i++) {
3574
+ if (process.env.NODE_ENV !== 'production' && info) {
3575
+ const sub = subs[i];
3576
+ sub.onTrigger &&
3577
+ sub.onTrigger(Object.assign({ effect: subs[i] }, info));
3578
+ }
3579
+ subs[i].update();
3580
+ }
3581
+ }
3582
+ }
3583
+ // The current target watcher being evaluated.
3584
+ // This is globally unique because only one watcher
3585
+ // can be evaluated at a time.
3586
+ Dep.target = null;
3587
+ const targetStack = [];
3588
+ function pushTarget(target) {
3589
+ targetStack.push(target);
3590
+ Dep.target = target;
3591
+ }
3592
+ function popTarget() {
3593
+ targetStack.pop();
3594
+ Dep.target = targetStack[targetStack.length - 1];
3595
+ }
3596
+
3650
3597
  /*
3651
3598
  * not type checking this file because flow doesn't play well with
3652
3599
  * dynamically accessing methods on Array prototype
@@ -3698,53 +3645,252 @@ methodsToPatch.forEach(function (method) {
3698
3645
  });
3699
3646
  });
3700
3647
 
3701
- function isReadonly(value) {
3702
- return !!(value && value.__v_isReadonly);
3703
- }
3704
-
3705
- function isRef(r) {
3706
- return !!(r && r.__v_isRef === true);
3707
- }
3708
-
3709
- const seenObjects = new _Set();
3648
+ const arrayKeys = Object.getOwnPropertyNames(arrayMethods);
3649
+ const NO_INIITIAL_VALUE = {};
3710
3650
  /**
3711
- * Recursively traverse an object to evoke all converted
3712
- * getters, so that every nested property inside the object
3713
- * is collected as a "deep" dependency.
3651
+ * In some cases we may want to disable observation inside a component's
3652
+ * update computation.
3714
3653
  */
3715
- function traverse(val) {
3716
- _traverse(val, seenObjects);
3717
- seenObjects.clear();
3718
- return val;
3654
+ let shouldObserve = true;
3655
+ function toggleObserving(value) {
3656
+ shouldObserve = value;
3719
3657
  }
3720
- function _traverse(val, seen) {
3721
- let i, keys;
3722
- const isA = isArray(val);
3723
- if ((!isA && !isObject$1(val)) ||
3724
- Object.isFrozen(val) ||
3725
- val instanceof VNode) {
3726
- return;
3727
- }
3728
- if (val.__ob__) {
3729
- const depId = val.__ob__.dep.id;
3730
- if (seen.has(depId)) {
3731
- return;
3658
+ // ssr mock dep
3659
+ const mockDep = {
3660
+ notify: noop,
3661
+ depend: noop,
3662
+ addSub: noop,
3663
+ removeSub: noop
3664
+ };
3665
+ /**
3666
+ * Observer class that is attached to each observed
3667
+ * object. Once attached, the observer converts the target
3668
+ * object's property keys into getter/setters that
3669
+ * collect dependencies and dispatch updates.
3670
+ */
3671
+ class Observer {
3672
+ constructor(value, shallow = false, mock = false) {
3673
+ this.value = value;
3674
+ this.shallow = shallow;
3675
+ this.mock = mock;
3676
+ // this.value = value
3677
+ this.dep = mock ? mockDep : new Dep();
3678
+ this.vmCount = 0;
3679
+ def(value, '__ob__', this);
3680
+ if (isArray(value)) {
3681
+ if (!mock) {
3682
+ if (hasProto) {
3683
+ value.__proto__ = arrayMethods;
3684
+ /* eslint-enable no-proto */
3685
+ }
3686
+ else {
3687
+ for (let i = 0, l = arrayKeys.length; i < l; i++) {
3688
+ const key = arrayKeys[i];
3689
+ def(value, key, arrayMethods[key]);
3690
+ }
3691
+ }
3692
+ }
3693
+ if (!shallow) {
3694
+ this.observeArray(value);
3695
+ }
3696
+ }
3697
+ else {
3698
+ /**
3699
+ * Walk through all properties and convert them into
3700
+ * getter/setters. This method should only be called when
3701
+ * value type is Object.
3702
+ */
3703
+ const keys = Object.keys(value);
3704
+ for (let i = 0; i < keys.length; i++) {
3705
+ const key = keys[i];
3706
+ defineReactive(value, key, NO_INIITIAL_VALUE, undefined, shallow, mock);
3707
+ }
3732
3708
  }
3733
- seen.add(depId);
3734
3709
  }
3735
- if (isA) {
3736
- i = val.length;
3737
- while (i--)
3738
- _traverse(val[i], seen);
3710
+ /**
3711
+ * Observe a list of Array items.
3712
+ */
3713
+ observeArray(value) {
3714
+ for (let i = 0, l = value.length; i < l; i++) {
3715
+ observe(value[i], false, this.mock);
3716
+ }
3717
+ }
3718
+ }
3719
+ // helpers
3720
+ /**
3721
+ * Attempt to create an observer instance for a value,
3722
+ * returns the new observer if successfully observed,
3723
+ * or the existing observer if the value already has one.
3724
+ */
3725
+ function observe(value, shallow, ssrMockReactivity) {
3726
+ if (!isObject$1(value) || isRef(value) || value instanceof VNode) {
3727
+ return;
3728
+ }
3729
+ let ob;
3730
+ if (hasOwn(value, '__ob__') && value.__ob__ instanceof Observer) {
3731
+ ob = value.__ob__;
3732
+ }
3733
+ else if (shouldObserve &&
3734
+ (ssrMockReactivity || !isServerRendering()) &&
3735
+ (isArray(value) || isPlainObject(value)) &&
3736
+ Object.isExtensible(value) &&
3737
+ !value.__v_skip /* ReactiveFlags.SKIP */) {
3738
+ ob = new Observer(value, shallow, ssrMockReactivity);
3739
+ }
3740
+ return ob;
3741
+ }
3742
+ /**
3743
+ * Define a reactive property on an Object.
3744
+ */
3745
+ function defineReactive(obj, key, val, customSetter, shallow, mock) {
3746
+ const dep = new Dep();
3747
+ const property = Object.getOwnPropertyDescriptor(obj, key);
3748
+ if (property && property.configurable === false) {
3749
+ return;
3750
+ }
3751
+ // cater for pre-defined getter/setters
3752
+ const getter = property && property.get;
3753
+ const setter = property && property.set;
3754
+ if ((!getter || setter) &&
3755
+ (val === NO_INIITIAL_VALUE || arguments.length === 2)) {
3756
+ val = obj[key];
3757
+ }
3758
+ let childOb = !shallow && observe(val, false, mock);
3759
+ Object.defineProperty(obj, key, {
3760
+ enumerable: true,
3761
+ configurable: true,
3762
+ get: function reactiveGetter() {
3763
+ const value = getter ? getter.call(obj) : val;
3764
+ if (Dep.target) {
3765
+ if (process.env.NODE_ENV !== 'production') {
3766
+ dep.depend({
3767
+ target: obj,
3768
+ type: "get" /* TrackOpTypes.GET */,
3769
+ key
3770
+ });
3771
+ }
3772
+ else {
3773
+ dep.depend();
3774
+ }
3775
+ if (childOb) {
3776
+ childOb.dep.depend();
3777
+ if (isArray(value)) {
3778
+ dependArray(value);
3779
+ }
3780
+ }
3781
+ }
3782
+ return isRef(value) && !shallow ? value.value : value;
3783
+ },
3784
+ set: function reactiveSetter(newVal) {
3785
+ const value = getter ? getter.call(obj) : val;
3786
+ if (!hasChanged(value, newVal)) {
3787
+ return;
3788
+ }
3789
+ if (process.env.NODE_ENV !== 'production' && customSetter) {
3790
+ customSetter();
3791
+ }
3792
+ if (setter) {
3793
+ setter.call(obj, newVal);
3794
+ }
3795
+ else if (getter) {
3796
+ // #7981: for accessor properties without setter
3797
+ return;
3798
+ }
3799
+ else if (isRef(value) && !isRef(newVal)) {
3800
+ value.value = newVal;
3801
+ return;
3802
+ }
3803
+ else {
3804
+ val = newVal;
3805
+ }
3806
+ childOb = !shallow && observe(newVal, false, mock);
3807
+ if (process.env.NODE_ENV !== 'production') {
3808
+ dep.notify({
3809
+ type: "set" /* TriggerOpTypes.SET */,
3810
+ target: obj,
3811
+ key,
3812
+ newValue: newVal,
3813
+ oldValue: value
3814
+ });
3815
+ }
3816
+ else {
3817
+ dep.notify();
3818
+ }
3819
+ }
3820
+ });
3821
+ return dep;
3822
+ }
3823
+ function set(target, key, val) {
3824
+ if (process.env.NODE_ENV !== 'production' && (isUndef(target) || isPrimitive(target))) {
3825
+ warn$3(`Cannot set reactive property on undefined, null, or primitive value: ${target}`);
3826
+ }
3827
+ if (isReadonly(target)) {
3828
+ process.env.NODE_ENV !== 'production' && warn$3(`Set operation on key "${key}" failed: target is readonly.`);
3829
+ return;
3830
+ }
3831
+ const ob = target.__ob__;
3832
+ if (isArray(target) && isValidArrayIndex(key)) {
3833
+ target.length = Math.max(target.length, key);
3834
+ target.splice(key, 1, val);
3835
+ // when mocking for SSR, array methods are not hijacked
3836
+ if (ob && !ob.shallow && ob.mock) {
3837
+ observe(val, false, true);
3838
+ }
3839
+ return val;
3840
+ }
3841
+ if (key in target && !(key in Object.prototype)) {
3842
+ target[key] = val;
3843
+ return val;
3844
+ }
3845
+ if (target._isVue || (ob && ob.vmCount)) {
3846
+ process.env.NODE_ENV !== 'production' &&
3847
+ warn$3('Avoid adding reactive properties to a Vue instance or its root $data ' +
3848
+ 'at runtime - declare it upfront in the data option.');
3849
+ return val;
3850
+ }
3851
+ if (!ob) {
3852
+ target[key] = val;
3853
+ return val;
3854
+ }
3855
+ defineReactive(ob.value, key, val, undefined, ob.shallow, ob.mock);
3856
+ if (process.env.NODE_ENV !== 'production') {
3857
+ ob.dep.notify({
3858
+ type: "add" /* TriggerOpTypes.ADD */,
3859
+ target: target,
3860
+ key,
3861
+ newValue: val,
3862
+ oldValue: undefined
3863
+ });
3739
3864
  }
3740
3865
  else {
3741
- keys = Object.keys(val);
3742
- i = keys.length;
3743
- while (i--)
3744
- _traverse(val[keys[i]], seen);
3866
+ ob.dep.notify();
3867
+ }
3868
+ return val;
3869
+ }
3870
+ /**
3871
+ * Collect dependencies on array elements when the array is touched, since
3872
+ * we cannot intercept array element access like property getters.
3873
+ */
3874
+ function dependArray(value) {
3875
+ for (let e, i = 0, l = value.length; i < l; i++) {
3876
+ e = value[i];
3877
+ if (e && e.__ob__) {
3878
+ e.__ob__.dep.depend();
3879
+ }
3880
+ if (isArray(e)) {
3881
+ dependArray(e);
3882
+ }
3745
3883
  }
3746
3884
  }
3747
3885
 
3886
+ function isReadonly(value) {
3887
+ return !!(value && value.__v_isReadonly);
3888
+ }
3889
+
3890
+ function isRef(r) {
3891
+ return !!(r && r.__v_isRef === true);
3892
+ }
3893
+
3748
3894
  if (process.env.NODE_ENV !== 'production') ;
3749
3895
 
3750
3896
  const normalizeEvent = cached((name) => {
@@ -3948,252 +4094,113 @@ function normalizeArrayChildren(children, nestedIndex) {
3948
4094
  return res;
3949
4095
  }
3950
4096
 
3951
- /* not type checking this file because flow doesn't play well with Proxy */
3952
- if (process.env.NODE_ENV !== 'production') {
3953
- makeMap('Infinity,undefined,NaN,isFinite,isNaN,' +
3954
- 'parseFloat,parseInt,decodeURI,decodeURIComponent,encodeURI,encodeURIComponent,' +
3955
- 'Math,Number,Date,Array,Object,Boolean,String,RegExp,Map,Set,JSON,Intl,BigInt,' +
3956
- 'require' // for Webpack/Browserify
3957
- );
3958
- const hasProxy = typeof Proxy !== 'undefined' && isNative(Proxy);
3959
- if (hasProxy) {
3960
- const isBuiltInModifier = makeMap('stop,prevent,self,ctrl,shift,alt,meta,exact');
3961
- config.keyCodes = new Proxy(config.keyCodes, {
3962
- set(target, key, value) {
3963
- if (isBuiltInModifier(key)) {
3964
- warn$3(`Avoid overwriting built-in modifier in config.keyCodes: .${key}`);
3965
- return false;
3966
- }
3967
- else {
3968
- target[key] = value;
3969
- return true;
3970
- }
3971
- }
3972
- });
3973
- }
3974
- }
3975
-
3976
- function syncSetupAttrs(to, from, prev, instance) {
3977
- let changed = false;
3978
- for (const key in from) {
3979
- if (!(key in to)) {
3980
- changed = true;
3981
- defineProxyAttr(to, key, instance);
3982
- }
3983
- else if (from[key] !== prev[key]) {
3984
- changed = true;
3985
- }
4097
+ const SIMPLE_NORMALIZE = 1;
4098
+ const ALWAYS_NORMALIZE = 2;
4099
+ // wrapper function for providing a more flexible interface
4100
+ // without getting yelled at by flow
4101
+ function createElement(context, tag, data, children, normalizationType, alwaysNormalize) {
4102
+ if (isArray(data) || isPrimitive(data)) {
4103
+ normalizationType = children;
4104
+ children = data;
4105
+ data = undefined;
3986
4106
  }
3987
- for (const key in to) {
3988
- if (!(key in from)) {
3989
- changed = true;
3990
- delete to[key];
3991
- }
4107
+ if (isTrue(alwaysNormalize)) {
4108
+ normalizationType = ALWAYS_NORMALIZE;
3992
4109
  }
3993
- return changed;
4110
+ return _createElement(context, tag, data, children, normalizationType);
3994
4111
  }
3995
- function defineProxyAttr(proxy, key, instance) {
3996
- Object.defineProperty(proxy, key, {
3997
- enumerable: true,
3998
- configurable: true,
3999
- get() {
4000
- return instance.$attrs[key];
4001
- }
4002
- });
4003
- }
4004
-
4005
- function resolveInject(inject, vm) {
4006
- if (inject) {
4007
- // inject is :any because flow is not smart enough to figure out cached
4008
- const result = Object.create(null);
4009
- const keys = hasSymbol ? Reflect.ownKeys(inject) : Object.keys(inject);
4010
- for (let i = 0; i < keys.length; i++) {
4011
- const key = keys[i];
4012
- // #6574 in case the inject object is observed...
4013
- if (key === '__ob__')
4014
- continue;
4015
- const provideKey = inject[key].from;
4016
- if (provideKey in vm._provided) {
4017
- result[key] = vm._provided[provideKey];
4018
- }
4019
- else if ('default' in inject[key]) {
4020
- const provideDefault = inject[key].default;
4021
- result[key] = isFunction(provideDefault)
4022
- ? provideDefault.call(vm)
4023
- : provideDefault;
4024
- }
4025
- else if (process.env.NODE_ENV !== 'production') {
4026
- warn$3(`Injection "${key}" not found`, vm);
4027
- }
4028
- }
4029
- return result;
4112
+ function _createElement(context, tag, data, children, normalizationType) {
4113
+ if (isDef(data) && isDef(data.__ob__)) {
4114
+ process.env.NODE_ENV !== 'production' &&
4115
+ warn$3(`Avoid using observed data object as vnode data: ${JSON.stringify(data)}\n` + 'Always create fresh vnode data objects in each render!', context);
4116
+ return createEmptyVNode();
4030
4117
  }
4031
- }
4032
-
4033
- function resolveConstructorOptions(Ctor) {
4034
- let options = Ctor.options;
4035
- if (Ctor.super) {
4036
- const superOptions = resolveConstructorOptions(Ctor.super);
4037
- const cachedSuperOptions = Ctor.superOptions;
4038
- if (superOptions !== cachedSuperOptions) {
4039
- // super option changed,
4040
- // need to resolve new options.
4041
- Ctor.superOptions = superOptions;
4042
- // check if there are any late-modified/attached options (#4976)
4043
- const modifiedOptions = resolveModifiedOptions(Ctor);
4044
- // update base extend options
4045
- if (modifiedOptions) {
4046
- extend(Ctor.extendOptions, modifiedOptions);
4047
- }
4048
- options = Ctor.options = mergeOptions(superOptions, Ctor.extendOptions);
4049
- if (options.name) {
4050
- options.components[options.name] = Ctor;
4051
- }
4052
- }
4118
+ // object syntax in v-bind
4119
+ if (isDef(data) && isDef(data.is)) {
4120
+ tag = data.is;
4053
4121
  }
4054
- return options;
4055
- }
4056
- function resolveModifiedOptions(Ctor) {
4057
- let modified;
4058
- const latest = Ctor.options;
4059
- const sealed = Ctor.sealedOptions;
4060
- for (const key in latest) {
4061
- if (latest[key] !== sealed[key]) {
4062
- if (!modified)
4063
- modified = {};
4064
- modified[key] = latest[key];
4065
- }
4122
+ if (!tag) {
4123
+ // in case of component :is set to falsy value
4124
+ return createEmptyVNode();
4066
4125
  }
4067
- return modified;
4068
- }
4069
-
4070
- /**
4071
- * Runtime helper for resolving raw children VNodes into a slot object.
4072
- */
4073
- function resolveSlots(children, context) {
4074
- if (!children || !children.length) {
4075
- return {};
4126
+ // warn against non-primitive key
4127
+ if (process.env.NODE_ENV !== 'production' && isDef(data) && isDef(data.key) && !isPrimitive(data.key)) {
4128
+ warn$3('Avoid using non-primitive value as key, ' +
4129
+ 'use string/number value instead.', context);
4076
4130
  }
4077
- const slots = {};
4078
- for (let i = 0, l = children.length; i < l; i++) {
4079
- const child = children[i];
4080
- const data = child.data;
4081
- // remove slot attribute if the node is resolved as a Vue slot node
4082
- if (data && data.attrs && data.attrs.slot) {
4083
- delete data.attrs.slot;
4084
- }
4085
- // named slots should only be respected if the vnode was rendered in the
4086
- // same context.
4087
- if ((child.context === context || child.fnContext === context) &&
4088
- data &&
4089
- data.slot != null) {
4090
- const name = data.slot;
4091
- const slot = slots[name] || (slots[name] = []);
4092
- if (child.tag === 'template') {
4093
- slot.push.apply(slot, child.children || []);
4094
- }
4095
- else {
4096
- slot.push(child);
4097
- }
4131
+ // support single function children as default scoped slot
4132
+ if (isArray(children) && isFunction(children[0])) {
4133
+ data = data || {};
4134
+ data.scopedSlots = { default: children[0] };
4135
+ children.length = 0;
4136
+ }
4137
+ if (normalizationType === ALWAYS_NORMALIZE) {
4138
+ children = normalizeChildren(children);
4139
+ }
4140
+ else if (normalizationType === SIMPLE_NORMALIZE) {
4141
+ children = simpleNormalizeChildren(children);
4142
+ }
4143
+ let vnode, ns;
4144
+ if (typeof tag === 'string') {
4145
+ let Ctor;
4146
+ ns = (context.$vnode && context.$vnode.ns) || config.getTagNamespace(tag);
4147
+ if ((!data || !data.pre) &&
4148
+ isDef((Ctor = resolveAsset(context.$options, 'components', tag)))) {
4149
+ // component
4150
+ vnode = createComponent(Ctor, data, context, children, tag);
4098
4151
  }
4099
4152
  else {
4100
- (slots.default || (slots.default = [])).push(child);
4101
- }
4102
- }
4103
- // ignore slots that contains only whitespace
4104
- for (const name in slots) {
4105
- if (slots[name].every(isWhitespace)) {
4106
- delete slots[name];
4153
+ // unknown or unlisted namespaced elements
4154
+ // check at runtime because it may get assigned a namespace when its
4155
+ // parent normalizes children
4156
+ vnode = new VNode(tag, data, children, undefined, undefined, context);
4107
4157
  }
4108
4158
  }
4109
- return slots;
4110
- }
4111
- function isWhitespace(node) {
4112
- return (node.isComment && !node.asyncFactory) || node.text === ' ';
4113
- }
4114
-
4115
- function isAsyncPlaceholder(node) {
4116
- // @ts-expect-error not really boolean type
4117
- return node.isComment && node.asyncFactory;
4118
- }
4119
-
4120
- function normalizeScopedSlots(ownerVm, scopedSlots, normalSlots, prevScopedSlots) {
4121
- let res;
4122
- const hasNormalSlots = Object.keys(normalSlots).length > 0;
4123
- const isStable = scopedSlots ? !!scopedSlots.$stable : !hasNormalSlots;
4124
- const key = scopedSlots && scopedSlots.$key;
4125
- if (!scopedSlots) {
4126
- res = {};
4159
+ else {
4160
+ // direct component options / constructor
4161
+ vnode = createComponent(tag, data, context, children);
4127
4162
  }
4128
- else if (scopedSlots._normalized) {
4129
- // fast path 1: child component re-render only, parent did not change
4130
- return scopedSlots._normalized;
4163
+ if (isArray(vnode)) {
4164
+ return vnode;
4131
4165
  }
4132
- else if (isStable &&
4133
- prevScopedSlots &&
4134
- prevScopedSlots !== emptyObject &&
4135
- key === prevScopedSlots.$key &&
4136
- !hasNormalSlots &&
4137
- !prevScopedSlots.$hasNormal) {
4138
- // fast path 2: stable scoped slots w/ no normal slots to proxy,
4139
- // only need to normalize once
4140
- return prevScopedSlots;
4166
+ else if (isDef(vnode)) {
4167
+ if (isDef(ns))
4168
+ applyNS(vnode, ns);
4169
+ if (isDef(data))
4170
+ registerDeepBindings(data);
4171
+ return vnode;
4141
4172
  }
4142
4173
  else {
4143
- res = {};
4144
- for (const key in scopedSlots) {
4145
- if (scopedSlots[key] && key[0] !== '$') {
4146
- res[key] = normalizeScopedSlot(ownerVm, normalSlots, key, scopedSlots[key]);
4147
- }
4148
- }
4174
+ return createEmptyVNode();
4149
4175
  }
4150
- // expose normal slots on scopedSlots
4151
- for (const key in normalSlots) {
4152
- if (!(key in res)) {
4153
- res[key] = proxyNormalSlot(normalSlots, key);
4154
- }
4176
+ }
4177
+ function applyNS(vnode, ns, force) {
4178
+ vnode.ns = ns;
4179
+ if (vnode.tag === 'foreignObject') {
4180
+ // use default namespace inside foreignObject
4181
+ ns = undefined;
4182
+ force = true;
4155
4183
  }
4156
- // avoriaz seems to mock a non-extensible $scopedSlots object
4157
- // and when that is passed down this would cause an error
4158
- if (scopedSlots && Object.isExtensible(scopedSlots)) {
4159
- scopedSlots._normalized = res;
4184
+ if (isDef(vnode.children)) {
4185
+ for (let i = 0, l = vnode.children.length; i < l; i++) {
4186
+ const child = vnode.children[i];
4187
+ if (isDef(child.tag) &&
4188
+ (isUndef(child.ns) || (isTrue(force) && child.tag !== 'svg'))) {
4189
+ applyNS(child, ns, force);
4190
+ }
4191
+ }
4160
4192
  }
4161
- def(res, '$stable', isStable);
4162
- def(res, '$key', key);
4163
- def(res, '$hasNormal', hasNormalSlots);
4164
- return res;
4165
4193
  }
4166
- function normalizeScopedSlot(vm, normalSlots, key, fn) {
4167
- const normalized = function () {
4168
- const cur = currentInstance;
4169
- setCurrentInstance(vm);
4170
- let res = arguments.length ? fn.apply(null, arguments) : fn({});
4171
- res =
4172
- res && typeof res === 'object' && !isArray(res)
4173
- ? [res] // single vnode
4174
- : normalizeChildren(res);
4175
- const vnode = res && res[0];
4176
- setCurrentInstance(cur);
4177
- return res &&
4178
- (!vnode ||
4179
- (res.length === 1 && vnode.isComment && !isAsyncPlaceholder(vnode))) // #9658, #10391
4180
- ? undefined
4181
- : res;
4182
- };
4183
- // this is a slot using the new v-slot syntax without scope. although it is
4184
- // compiled as a scoped slot, render fn users would expect it to be present
4185
- // on this.$slots because the usage is semantically a normal slot.
4186
- if (fn.proxy) {
4187
- Object.defineProperty(normalSlots, key, {
4188
- get: normalized,
4189
- enumerable: true,
4190
- configurable: true
4191
- });
4194
+ // ref #5318
4195
+ // necessary to ensure parent re-render when deep bindings like :style and
4196
+ // :class are used on slot nodes
4197
+ function registerDeepBindings(data) {
4198
+ if (isObject$1(data.style)) {
4199
+ traverse(data.style);
4200
+ }
4201
+ if (isObject$1(data.class)) {
4202
+ traverse(data.class);
4192
4203
  }
4193
- return normalized;
4194
- }
4195
- function proxyNormalSlot(slots, key) {
4196
- return () => slots[key];
4197
4204
  }
4198
4205
 
4199
4206
  /**
@@ -4360,7 +4367,7 @@ function renderStatic(index, isInFor) {
4360
4367
  return tree;
4361
4368
  }
4362
4369
  // otherwise, render a fresh tree.
4363
- tree = cached[index] = this.$options.staticRenderFns[index].call(this._renderProxy, null, this // for render fns generated for functional component templates
4370
+ tree = cached[index] = this.$options.staticRenderFns[index].call(this._renderProxy, this._c, this // for render fns generated for functional component templates
4364
4371
  );
4365
4372
  markStatic$1(tree, `__static__${index}`, false);
4366
4373
  return tree;
@@ -4474,417 +4481,162 @@ function installRenderHelpers(target) {
4474
4481
  target._p = prependModifier;
4475
4482
  }
4476
4483
 
4477
- function FunctionalRenderContext(data, props, children, parent, Ctor) {
4478
- const options = Ctor.options;
4479
- // ensure the createElement function in functional components
4480
- // gets a unique context - this is necessary for correct named slot check
4481
- let contextVm;
4482
- if (hasOwn(parent, '_uid')) {
4483
- contextVm = Object.create(parent);
4484
- contextVm._original = parent;
4485
- }
4486
- else {
4487
- // the context vm passed in is a functional context as well.
4488
- // in this case we want to make sure we are able to get a hold to the
4489
- // real context instance.
4490
- contextVm = parent;
4491
- // @ts-ignore
4492
- parent = parent._original;
4484
+ /**
4485
+ * Runtime helper for resolving raw children VNodes into a slot object.
4486
+ */
4487
+ function resolveSlots(children, context) {
4488
+ if (!children || !children.length) {
4489
+ return {};
4493
4490
  }
4494
- const isCompiled = isTrue(options._compiled);
4495
- const needNormalization = !isCompiled;
4496
- this.data = data;
4497
- this.props = props;
4498
- this.children = children;
4499
- this.parent = parent;
4500
- this.listeners = data.on || emptyObject;
4501
- this.injections = resolveInject(options.inject, parent);
4502
- this.slots = () => {
4503
- if (!this.$slots) {
4504
- normalizeScopedSlots(parent, data.scopedSlots, (this.$slots = resolveSlots(children, parent)));
4505
- }
4506
- return this.$slots;
4507
- };
4508
- Object.defineProperty(this, 'scopedSlots', {
4509
- enumerable: true,
4510
- get() {
4511
- return normalizeScopedSlots(parent, data.scopedSlots, this.slots());
4491
+ const slots = {};
4492
+ for (let i = 0, l = children.length; i < l; i++) {
4493
+ const child = children[i];
4494
+ const data = child.data;
4495
+ // remove slot attribute if the node is resolved as a Vue slot node
4496
+ if (data && data.attrs && data.attrs.slot) {
4497
+ delete data.attrs.slot;
4512
4498
  }
4513
- });
4514
- // support for compiled functional template
4515
- if (isCompiled) {
4516
- // exposing $options for renderStatic()
4517
- this.$options = options;
4518
- // pre-resolve slots for renderSlot()
4519
- this.$slots = this.slots();
4520
- this.$scopedSlots = normalizeScopedSlots(parent, data.scopedSlots, this.$slots);
4521
- }
4522
- if (options._scopeId) {
4523
- this._c = (a, b, c, d) => {
4524
- const vnode = createElement(contextVm, a, b, c, d, needNormalization);
4525
- if (vnode && !isArray(vnode)) {
4526
- vnode.fnScopeId = options._scopeId;
4527
- vnode.fnContext = parent;
4499
+ // named slots should only be respected if the vnode was rendered in the
4500
+ // same context.
4501
+ if ((child.context === context || child.fnContext === context) &&
4502
+ data &&
4503
+ data.slot != null) {
4504
+ const name = data.slot;
4505
+ const slot = slots[name] || (slots[name] = []);
4506
+ if (child.tag === 'template') {
4507
+ slot.push.apply(slot, child.children || []);
4528
4508
  }
4529
- return vnode;
4530
- };
4509
+ else {
4510
+ slot.push(child);
4511
+ }
4512
+ }
4513
+ else {
4514
+ (slots.default || (slots.default = [])).push(child);
4515
+ }
4531
4516
  }
4532
- else {
4533
- this._c = (a, b, c, d) => createElement(contextVm, a, b, c, d, needNormalization);
4517
+ // ignore slots that contains only whitespace
4518
+ for (const name in slots) {
4519
+ if (slots[name].every(isWhitespace)) {
4520
+ delete slots[name];
4521
+ }
4534
4522
  }
4523
+ return slots;
4535
4524
  }
4536
- installRenderHelpers(FunctionalRenderContext.prototype);
4537
- function createFunctionalComponent(Ctor, propsData, data, contextVm, children) {
4538
- const options = Ctor.options;
4539
- const props = {};
4540
- const propOptions = options.props;
4541
- if (isDef(propOptions)) {
4542
- for (const key in propOptions) {
4543
- props[key] = validateProp(key, propOptions, propsData || emptyObject);
4544
- }
4525
+ function isWhitespace(node) {
4526
+ return (node.isComment && !node.asyncFactory) || node.text === ' ';
4527
+ }
4528
+
4529
+ function isAsyncPlaceholder(node) {
4530
+ // @ts-expect-error not really boolean type
4531
+ return node.isComment && node.asyncFactory;
4532
+ }
4533
+
4534
+ function normalizeScopedSlots(ownerVm, scopedSlots, normalSlots, prevScopedSlots) {
4535
+ let res;
4536
+ const hasNormalSlots = Object.keys(normalSlots).length > 0;
4537
+ const isStable = scopedSlots ? !!scopedSlots.$stable : !hasNormalSlots;
4538
+ const key = scopedSlots && scopedSlots.$key;
4539
+ if (!scopedSlots) {
4540
+ res = {};
4545
4541
  }
4546
- else {
4547
- if (isDef(data.attrs))
4548
- mergeProps(props, data.attrs);
4549
- if (isDef(data.props))
4550
- mergeProps(props, data.props);
4542
+ else if (scopedSlots._normalized) {
4543
+ // fast path 1: child component re-render only, parent did not change
4544
+ return scopedSlots._normalized;
4551
4545
  }
4552
- const renderContext = new FunctionalRenderContext(data, props, children, contextVm, Ctor);
4553
- const vnode = options.render.call(null, renderContext._c, renderContext);
4554
- if (vnode instanceof VNode) {
4555
- return cloneAndMarkFunctionalResult(vnode, data, renderContext.parent, options, renderContext);
4546
+ else if (isStable &&
4547
+ prevScopedSlots &&
4548
+ prevScopedSlots !== emptyObject &&
4549
+ key === prevScopedSlots.$key &&
4550
+ !hasNormalSlots &&
4551
+ !prevScopedSlots.$hasNormal) {
4552
+ // fast path 2: stable scoped slots w/ no normal slots to proxy,
4553
+ // only need to normalize once
4554
+ return prevScopedSlots;
4556
4555
  }
4557
- else if (isArray(vnode)) {
4558
- const vnodes = normalizeChildren(vnode) || [];
4559
- const res = new Array(vnodes.length);
4560
- for (let i = 0; i < vnodes.length; i++) {
4561
- res[i] = cloneAndMarkFunctionalResult(vnodes[i], data, renderContext.parent, options, renderContext);
4556
+ else {
4557
+ res = {};
4558
+ for (const key in scopedSlots) {
4559
+ if (scopedSlots[key] && key[0] !== '$') {
4560
+ res[key] = normalizeScopedSlot(ownerVm, normalSlots, key, scopedSlots[key]);
4561
+ }
4562
4562
  }
4563
- return res;
4564
4563
  }
4565
- }
4566
- function cloneAndMarkFunctionalResult(vnode, data, contextVm, options, renderContext) {
4567
- // #7817 clone node before setting fnContext, otherwise if the node is reused
4568
- // (e.g. it was from a cached normal slot) the fnContext causes named slots
4569
- // that should not be matched to match.
4570
- const clone = cloneVNode(vnode);
4571
- clone.fnContext = contextVm;
4572
- clone.fnOptions = options;
4573
- if (process.env.NODE_ENV !== 'production') {
4574
- (clone.devtoolsMeta = clone.devtoolsMeta || {}).renderContext =
4575
- renderContext;
4564
+ // expose normal slots on scopedSlots
4565
+ for (const key in normalSlots) {
4566
+ if (!(key in res)) {
4567
+ res[key] = proxyNormalSlot(normalSlots, key);
4568
+ }
4576
4569
  }
4577
- if (data.slot) {
4578
- (clone.data || (clone.data = {})).slot = data.slot;
4570
+ // avoriaz seems to mock a non-extensible $scopedSlots object
4571
+ // and when that is passed down this would cause an error
4572
+ if (scopedSlots && Object.isExtensible(scopedSlots)) {
4573
+ scopedSlots._normalized = res;
4579
4574
  }
4580
- return clone;
4575
+ def(res, '$stable', isStable);
4576
+ def(res, '$key', key);
4577
+ def(res, '$hasNormal', hasNormalSlots);
4578
+ return res;
4581
4579
  }
4582
- function mergeProps(to, from) {
4583
- for (const key in from) {
4584
- to[camelize(key)] = from[key];
4580
+ function normalizeScopedSlot(vm, normalSlots, key, fn) {
4581
+ const normalized = function () {
4582
+ const cur = currentInstance;
4583
+ setCurrentInstance(vm);
4584
+ let res = arguments.length ? fn.apply(null, arguments) : fn({});
4585
+ res =
4586
+ res && typeof res === 'object' && !isArray(res)
4587
+ ? [res] // single vnode
4588
+ : normalizeChildren(res);
4589
+ const vnode = res && res[0];
4590
+ setCurrentInstance(cur);
4591
+ return res &&
4592
+ (!vnode ||
4593
+ (res.length === 1 && vnode.isComment && !isAsyncPlaceholder(vnode))) // #9658, #10391
4594
+ ? undefined
4595
+ : res;
4596
+ };
4597
+ // this is a slot using the new v-slot syntax without scope. although it is
4598
+ // compiled as a scoped slot, render fn users would expect it to be present
4599
+ // on this.$slots because the usage is semantically a normal slot.
4600
+ if (fn.proxy) {
4601
+ Object.defineProperty(normalSlots, key, {
4602
+ get: normalized,
4603
+ enumerable: true,
4604
+ configurable: true
4605
+ });
4585
4606
  }
4607
+ return normalized;
4608
+ }
4609
+ function proxyNormalSlot(slots, key) {
4610
+ return () => slots[key];
4586
4611
  }
4587
4612
 
4588
- // inline hooks to be invoked on component VNodes during patch
4589
- const componentVNodeHooks = {
4590
- init(vnode, hydrating) {
4591
- if (vnode.componentInstance &&
4592
- !vnode.componentInstance._isDestroyed &&
4593
- vnode.data.keepAlive) {
4594
- // kept-alive components, treat as a patch
4595
- const mountedNode = vnode; // work around flow
4596
- componentVNodeHooks.prepatch(mountedNode, mountedNode);
4613
+ function syncSetupAttrs(to, from, prev, instance) {
4614
+ let changed = false;
4615
+ for (const key in from) {
4616
+ if (!(key in to)) {
4617
+ changed = true;
4618
+ defineProxyAttr(to, key, instance);
4597
4619
  }
4598
- else {
4599
- const child = (vnode.componentInstance = createComponentInstanceForVnode(vnode, activeInstance));
4600
- child.$mount(hydrating ? vnode.elm : undefined, hydrating);
4620
+ else if (from[key] !== prev[key]) {
4621
+ changed = true;
4601
4622
  }
4602
- },
4603
- prepatch(oldVnode, vnode) {
4604
- const options = vnode.componentOptions;
4605
- const child = (vnode.componentInstance = oldVnode.componentInstance);
4606
- updateChildComponent(child, options.propsData, // updated props
4607
- options.listeners, // updated listeners
4608
- vnode, // new parent vnode
4609
- options.children // new children
4610
- );
4611
- },
4612
- insert(vnode) {
4613
- const { context, componentInstance } = vnode;
4614
- if (!componentInstance._isMounted) {
4615
- componentInstance._isMounted = true;
4616
- callHook(componentInstance, 'mounted');
4617
- }
4618
- if (vnode.data.keepAlive) {
4619
- if (context._isMounted) {
4620
- // vue-router#1212
4621
- // During updates, a kept-alive component's child components may
4622
- // change, so directly walking the tree here may call activated hooks
4623
- // on incorrect children. Instead we push them into a queue which will
4624
- // be processed after the whole patch process ended.
4625
- queueActivatedComponent(componentInstance);
4626
- }
4627
- else {
4628
- activateChildComponent(componentInstance, true /* direct */);
4629
- }
4630
- }
4631
- },
4632
- destroy(vnode) {
4633
- const { componentInstance } = vnode;
4634
- if (!componentInstance._isDestroyed) {
4635
- if (!vnode.data.keepAlive) {
4636
- componentInstance.$destroy();
4637
- }
4638
- else {
4639
- deactivateChildComponent(componentInstance, true /* direct */);
4640
- }
4641
- }
4642
- }
4643
- };
4644
- const hooksToMerge = Object.keys(componentVNodeHooks);
4645
- function createComponent(Ctor, data, context, children, tag) {
4646
- if (isUndef(Ctor)) {
4647
- return;
4648
- }
4649
- const baseCtor = context.$options._base;
4650
- // plain options object: turn it into a constructor
4651
- if (isObject$1(Ctor)) {
4652
- Ctor = baseCtor.extend(Ctor);
4653
- }
4654
- // if at this stage it's not a constructor or an async component factory,
4655
- // reject.
4656
- if (typeof Ctor !== 'function') {
4657
- if (process.env.NODE_ENV !== 'production') {
4658
- warn$3(`Invalid Component definition: ${String(Ctor)}`, context);
4659
- }
4660
- return;
4661
- }
4662
- // async component
4663
- let asyncFactory;
4664
- // @ts-expect-error
4665
- if (isUndef(Ctor.cid)) {
4666
- asyncFactory = Ctor;
4667
- Ctor = resolveAsyncComponent(asyncFactory);
4668
- if (Ctor === undefined) {
4669
- // return a placeholder node for async component, which is rendered
4670
- // as a comment node but preserves all the raw information for the node.
4671
- // the information will be used for async server-rendering and hydration.
4672
- return createAsyncPlaceholder(asyncFactory, data, context, children, tag);
4623
+ }
4624
+ for (const key in to) {
4625
+ if (!(key in from)) {
4626
+ changed = true;
4627
+ delete to[key];
4673
4628
  }
4674
4629
  }
4675
- data = data || {};
4676
- // resolve constructor options in case global mixins are applied after
4677
- // component constructor creation
4678
- resolveConstructorOptions(Ctor);
4679
- // transform component v-model data into props & events
4680
- if (isDef(data.model)) {
4681
- // @ts-expect-error
4682
- transformModel(Ctor.options, data);
4683
- }
4684
- // extract props
4685
- // @ts-expect-error
4686
- const propsData = extractPropsFromVNodeData(data, Ctor, tag);
4687
- // functional component
4688
- // @ts-expect-error
4689
- if (isTrue(Ctor.options.functional)) {
4690
- return createFunctionalComponent(Ctor, propsData, data, context, children);
4691
- }
4692
- // extract listeners, since these needs to be treated as
4693
- // child component listeners instead of DOM listeners
4694
- const listeners = data.on;
4695
- // replace with listeners with .native modifier
4696
- // so it gets processed during parent component patch.
4697
- data.on = data.nativeOn;
4698
- // @ts-expect-error
4699
- if (isTrue(Ctor.options.abstract)) {
4700
- // abstract components do not keep anything
4701
- // other than props & listeners & slot
4702
- // work around flow
4703
- const slot = data.slot;
4704
- data = {};
4705
- if (slot) {
4706
- data.slot = slot;
4707
- }
4708
- }
4709
- // install component management hooks onto the placeholder node
4710
- installComponentHooks(data);
4711
- // return a placeholder vnode
4712
- // @ts-expect-error
4713
- const name = Ctor.options.name || tag;
4714
- const vnode = new VNode(
4715
- // @ts-expect-error
4716
- `vue-component-${Ctor.cid}${name ? `-${name}` : ''}`, data, undefined, undefined, undefined, context,
4717
- // @ts-expect-error
4718
- { Ctor, propsData, listeners, tag, children }, asyncFactory);
4719
- return vnode;
4720
- }
4721
- function createComponentInstanceForVnode(
4722
- // we know it's MountedComponentVNode but flow doesn't
4723
- vnode,
4724
- // activeInstance in lifecycle state
4725
- parent) {
4726
- const options = {
4727
- _isComponent: true,
4728
- _parentVnode: vnode,
4729
- parent
4730
- };
4731
- // check inline-template render functions
4732
- const inlineTemplate = vnode.data.inlineTemplate;
4733
- if (isDef(inlineTemplate)) {
4734
- options.render = inlineTemplate.render;
4735
- options.staticRenderFns = inlineTemplate.staticRenderFns;
4736
- }
4737
- return new vnode.componentOptions.Ctor(options);
4738
- }
4739
- function installComponentHooks(data) {
4740
- const hooks = data.hook || (data.hook = {});
4741
- for (let i = 0; i < hooksToMerge.length; i++) {
4742
- const key = hooksToMerge[i];
4743
- const existing = hooks[key];
4744
- const toMerge = componentVNodeHooks[key];
4745
- // @ts-expect-error
4746
- if (existing !== toMerge && !(existing && existing._merged)) {
4747
- hooks[key] = existing ? mergeHook(toMerge, existing) : toMerge;
4748
- }
4749
- }
4750
- }
4751
- function mergeHook(f1, f2) {
4752
- const merged = (a, b) => {
4753
- // flow complains about extra args which is why we use any
4754
- f1(a, b);
4755
- f2(a, b);
4756
- };
4757
- merged._merged = true;
4758
- return merged;
4759
- }
4760
- // transform component v-model info (value and callback) into
4761
- // prop and event handler respectively.
4762
- function transformModel(options, data) {
4763
- const prop = (options.model && options.model.prop) || 'value';
4764
- const event = (options.model && options.model.event) || 'input';
4765
- (data.attrs || (data.attrs = {}))[prop] = data.model.value;
4766
- const on = data.on || (data.on = {});
4767
- const existing = on[event];
4768
- const callback = data.model.callback;
4769
- if (isDef(existing)) {
4770
- if (isArray(existing)
4771
- ? existing.indexOf(callback) === -1
4772
- : existing !== callback) {
4773
- on[event] = [callback].concat(existing);
4774
- }
4775
- }
4776
- else {
4777
- on[event] = callback;
4778
- }
4779
- }
4780
-
4781
- const SIMPLE_NORMALIZE = 1;
4782
- const ALWAYS_NORMALIZE = 2;
4783
- // wrapper function for providing a more flexible interface
4784
- // without getting yelled at by flow
4785
- function createElement(context, tag, data, children, normalizationType, alwaysNormalize) {
4786
- if (isArray(data) || isPrimitive(data)) {
4787
- normalizationType = children;
4788
- children = data;
4789
- data = undefined;
4790
- }
4791
- if (isTrue(alwaysNormalize)) {
4792
- normalizationType = ALWAYS_NORMALIZE;
4793
- }
4794
- return _createElement(context, tag, data, children, normalizationType);
4795
- }
4796
- function _createElement(context, tag, data, children, normalizationType) {
4797
- if (isDef(data) && isDef(data.__ob__)) {
4798
- process.env.NODE_ENV !== 'production' &&
4799
- warn$3(`Avoid using observed data object as vnode data: ${JSON.stringify(data)}\n` + 'Always create fresh vnode data objects in each render!', context);
4800
- return createEmptyVNode();
4801
- }
4802
- // object syntax in v-bind
4803
- if (isDef(data) && isDef(data.is)) {
4804
- tag = data.is;
4805
- }
4806
- if (!tag) {
4807
- // in case of component :is set to falsy value
4808
- return createEmptyVNode();
4809
- }
4810
- // warn against non-primitive key
4811
- if (process.env.NODE_ENV !== 'production' && isDef(data) && isDef(data.key) && !isPrimitive(data.key)) {
4812
- warn$3('Avoid using non-primitive value as key, ' +
4813
- 'use string/number value instead.', context);
4814
- }
4815
- // support single function children as default scoped slot
4816
- if (isArray(children) && isFunction(children[0])) {
4817
- data = data || {};
4818
- data.scopedSlots = { default: children[0] };
4819
- children.length = 0;
4820
- }
4821
- if (normalizationType === ALWAYS_NORMALIZE) {
4822
- children = normalizeChildren(children);
4823
- }
4824
- else if (normalizationType === SIMPLE_NORMALIZE) {
4825
- children = simpleNormalizeChildren(children);
4826
- }
4827
- let vnode, ns;
4828
- if (typeof tag === 'string') {
4829
- let Ctor;
4830
- ns = (context.$vnode && context.$vnode.ns) || config.getTagNamespace(tag);
4831
- if ((!data || !data.pre) &&
4832
- isDef((Ctor = resolveAsset(context.$options, 'components', tag)))) {
4833
- // component
4834
- vnode = createComponent(Ctor, data, context, children, tag);
4835
- }
4836
- else {
4837
- // unknown or unlisted namespaced elements
4838
- // check at runtime because it may get assigned a namespace when its
4839
- // parent normalizes children
4840
- vnode = new VNode(tag, data, children, undefined, undefined, context);
4841
- }
4842
- }
4843
- else {
4844
- // direct component options / constructor
4845
- vnode = createComponent(tag, data, context, children);
4846
- }
4847
- if (isArray(vnode)) {
4848
- return vnode;
4849
- }
4850
- else if (isDef(vnode)) {
4851
- if (isDef(ns))
4852
- applyNS(vnode, ns);
4853
- if (isDef(data))
4854
- registerDeepBindings(data);
4855
- return vnode;
4856
- }
4857
- else {
4858
- return createEmptyVNode();
4859
- }
4630
+ return changed;
4860
4631
  }
4861
- function applyNS(vnode, ns, force) {
4862
- vnode.ns = ns;
4863
- if (vnode.tag === 'foreignObject') {
4864
- // use default namespace inside foreignObject
4865
- ns = undefined;
4866
- force = true;
4867
- }
4868
- if (isDef(vnode.children)) {
4869
- for (let i = 0, l = vnode.children.length; i < l; i++) {
4870
- const child = vnode.children[i];
4871
- if (isDef(child.tag) &&
4872
- (isUndef(child.ns) || (isTrue(force) && child.tag !== 'svg'))) {
4873
- applyNS(child, ns, force);
4874
- }
4632
+ function defineProxyAttr(proxy, key, instance) {
4633
+ Object.defineProperty(proxy, key, {
4634
+ enumerable: true,
4635
+ configurable: true,
4636
+ get() {
4637
+ return instance.$attrs[key];
4875
4638
  }
4876
- }
4877
- }
4878
- // ref #5318
4879
- // necessary to ensure parent re-render when deep bindings like :style and
4880
- // :class are used on slot nodes
4881
- function registerDeepBindings(data) {
4882
- if (isObject$1(data.style)) {
4883
- traverse(data.style);
4884
- }
4885
- if (isObject$1(data.class)) {
4886
- traverse(data.class);
4887
- }
4639
+ });
4888
4640
  }
4889
4641
 
4890
4642
  function createAsyncPlaceholder(factory, data, context, children, tag) {
@@ -5034,11 +4786,11 @@ function deactivateChildComponent(vm, direct) {
5034
4786
  callHook(vm, 'deactivated');
5035
4787
  }
5036
4788
  }
5037
- function callHook(vm, hook, args) {
4789
+ function callHook(vm, hook, args, setContext = true) {
5038
4790
  // #7573 disable dep collection when invoking lifecycle hooks
5039
4791
  pushTarget();
5040
4792
  const prev = currentInstance;
5041
- setCurrentInstance(vm);
4793
+ setContext && setCurrentInstance(vm);
5042
4794
  const handlers = vm.$options[hook];
5043
4795
  const info = `${hook} hook`;
5044
4796
  if (handlers) {
@@ -5049,7 +4801,7 @@ function callHook(vm, hook, args) {
5049
4801
  if (vm._hasHookEvent) {
5050
4802
  vm.$emit('hook:' + hook);
5051
4803
  }
5052
- setCurrentInstance(prev);
4804
+ setContext && setCurrentInstance(prev);
5053
4805
  popTarget();
5054
4806
  }
5055
4807
 
@@ -5179,247 +4931,499 @@ else if (!isIE &&
5179
4931
  else if (typeof setImmediate !== 'undefined' && isNative(setImmediate)) ;
5180
4932
  else ;
5181
4933
 
5182
- const arrayKeys = Object.getOwnPropertyNames(arrayMethods);
5183
- const NO_INIITIAL_VALUE = {};
4934
+ const seenObjects = new _Set();
5184
4935
  /**
5185
- * In some cases we may want to disable observation inside a component's
5186
- * update computation.
4936
+ * Recursively traverse an object to evoke all converted
4937
+ * getters, so that every nested property inside the object
4938
+ * is collected as a "deep" dependency.
5187
4939
  */
5188
- let shouldObserve = true;
5189
- function toggleObserving(value) {
5190
- shouldObserve = value;
4940
+ function traverse(val) {
4941
+ _traverse(val, seenObjects);
4942
+ seenObjects.clear();
4943
+ return val;
5191
4944
  }
5192
- /**
5193
- * Observer class that is attached to each observed
5194
- * object. Once attached, the observer converts the target
5195
- * object's property keys into getter/setters that
5196
- * collect dependencies and dispatch updates.
5197
- */
5198
- class Observer {
5199
- constructor(value, shallow = false) {
5200
- this.value = value;
5201
- this.shallow = shallow;
5202
- // this.value = value
5203
- this.dep = new Dep();
5204
- this.vmCount = 0;
5205
- def(value, '__ob__', this);
5206
- if (isArray(value)) {
5207
- if (hasProto) {
5208
- protoAugment(value, arrayMethods);
4945
+ function _traverse(val, seen) {
4946
+ let i, keys;
4947
+ const isA = isArray(val);
4948
+ if ((!isA && !isObject$1(val)) ||
4949
+ Object.isFrozen(val) ||
4950
+ val instanceof VNode) {
4951
+ return;
4952
+ }
4953
+ if (val.__ob__) {
4954
+ const depId = val.__ob__.dep.id;
4955
+ if (seen.has(depId)) {
4956
+ return;
4957
+ }
4958
+ seen.add(depId);
4959
+ }
4960
+ if (isA) {
4961
+ i = val.length;
4962
+ while (i--)
4963
+ _traverse(val[i], seen);
4964
+ }
4965
+ else if (isRef(val)) {
4966
+ _traverse(val.value, seen);
4967
+ }
4968
+ else {
4969
+ keys = Object.keys(val);
4970
+ i = keys.length;
4971
+ while (i--)
4972
+ _traverse(val[keys[i]], seen);
4973
+ }
4974
+ }
4975
+
4976
+ function resolveInject(inject, vm) {
4977
+ if (inject) {
4978
+ // inject is :any because flow is not smart enough to figure out cached
4979
+ const result = Object.create(null);
4980
+ const keys = hasSymbol ? Reflect.ownKeys(inject) : Object.keys(inject);
4981
+ for (let i = 0; i < keys.length; i++) {
4982
+ const key = keys[i];
4983
+ // #6574 in case the inject object is observed...
4984
+ if (key === '__ob__')
4985
+ continue;
4986
+ const provideKey = inject[key].from;
4987
+ if (provideKey in vm._provided) {
4988
+ result[key] = vm._provided[provideKey];
5209
4989
  }
5210
- else {
5211
- copyAugment(value, arrayMethods, arrayKeys);
4990
+ else if ('default' in inject[key]) {
4991
+ const provideDefault = inject[key].default;
4992
+ result[key] = isFunction(provideDefault)
4993
+ ? provideDefault.call(vm)
4994
+ : provideDefault;
5212
4995
  }
5213
- if (!shallow) {
5214
- this.observeArray(value);
4996
+ else if (process.env.NODE_ENV !== 'production') {
4997
+ warn$3(`Injection "${key}" not found`, vm);
4998
+ }
4999
+ }
5000
+ return result;
5001
+ }
5002
+ }
5003
+
5004
+ function resolveConstructorOptions(Ctor) {
5005
+ let options = Ctor.options;
5006
+ if (Ctor.super) {
5007
+ const superOptions = resolveConstructorOptions(Ctor.super);
5008
+ const cachedSuperOptions = Ctor.superOptions;
5009
+ if (superOptions !== cachedSuperOptions) {
5010
+ // super option changed,
5011
+ // need to resolve new options.
5012
+ Ctor.superOptions = superOptions;
5013
+ // check if there are any late-modified/attached options (#4976)
5014
+ const modifiedOptions = resolveModifiedOptions(Ctor);
5015
+ // update base extend options
5016
+ if (modifiedOptions) {
5017
+ extend(Ctor.extendOptions, modifiedOptions);
5018
+ }
5019
+ options = Ctor.options = mergeOptions(superOptions, Ctor.extendOptions);
5020
+ if (options.name) {
5021
+ options.components[options.name] = Ctor;
5215
5022
  }
5216
5023
  }
5217
- else {
5218
- this.walk(value, shallow);
5219
- }
5220
5024
  }
5221
- /**
5222
- * Walk through all properties and convert them into
5223
- * getter/setters. This method should only be called when
5224
- * value type is Object.
5225
- */
5226
- walk(obj, shallow) {
5227
- const keys = Object.keys(obj);
5228
- for (let i = 0; i < keys.length; i++) {
5229
- const key = keys[i];
5230
- defineReactive(obj, key, NO_INIITIAL_VALUE, undefined, shallow);
5025
+ return options;
5026
+ }
5027
+ function resolveModifiedOptions(Ctor) {
5028
+ let modified;
5029
+ const latest = Ctor.options;
5030
+ const sealed = Ctor.sealedOptions;
5031
+ for (const key in latest) {
5032
+ if (latest[key] !== sealed[key]) {
5033
+ if (!modified)
5034
+ modified = {};
5035
+ modified[key] = latest[key];
5231
5036
  }
5232
5037
  }
5233
- /**
5234
- * Observe a list of Array items.
5235
- */
5236
- observeArray(items) {
5237
- for (let i = 0, l = items.length; i < l; i++) {
5238
- observe(items[i]);
5038
+ return modified;
5039
+ }
5040
+
5041
+ function FunctionalRenderContext(data, props, children, parent, Ctor) {
5042
+ const options = Ctor.options;
5043
+ // ensure the createElement function in functional components
5044
+ // gets a unique context - this is necessary for correct named slot check
5045
+ let contextVm;
5046
+ if (hasOwn(parent, '_uid')) {
5047
+ contextVm = Object.create(parent);
5048
+ contextVm._original = parent;
5049
+ }
5050
+ else {
5051
+ // the context vm passed in is a functional context as well.
5052
+ // in this case we want to make sure we are able to get a hold to the
5053
+ // real context instance.
5054
+ contextVm = parent;
5055
+ // @ts-ignore
5056
+ parent = parent._original;
5057
+ }
5058
+ const isCompiled = isTrue(options._compiled);
5059
+ const needNormalization = !isCompiled;
5060
+ this.data = data;
5061
+ this.props = props;
5062
+ this.children = children;
5063
+ this.parent = parent;
5064
+ this.listeners = data.on || emptyObject;
5065
+ this.injections = resolveInject(options.inject, parent);
5066
+ this.slots = () => {
5067
+ if (!this.$slots) {
5068
+ normalizeScopedSlots(parent, data.scopedSlots, (this.$slots = resolveSlots(children, parent)));
5069
+ }
5070
+ return this.$slots;
5071
+ };
5072
+ Object.defineProperty(this, 'scopedSlots', {
5073
+ enumerable: true,
5074
+ get() {
5075
+ return normalizeScopedSlots(parent, data.scopedSlots, this.slots());
5239
5076
  }
5077
+ });
5078
+ // support for compiled functional template
5079
+ if (isCompiled) {
5080
+ // exposing $options for renderStatic()
5081
+ this.$options = options;
5082
+ // pre-resolve slots for renderSlot()
5083
+ this.$slots = this.slots();
5084
+ this.$scopedSlots = normalizeScopedSlots(parent, data.scopedSlots, this.$slots);
5240
5085
  }
5241
- }
5242
- // helpers
5243
- /**
5244
- * Augment a target Object or Array by intercepting
5245
- * the prototype chain using __proto__
5246
- */
5247
- function protoAugment(target, src) {
5248
- /* eslint-disable no-proto */
5249
- target.__proto__ = src;
5250
- /* eslint-enable no-proto */
5251
- }
5252
- /**
5253
- * Augment a target Object or Array by defining
5254
- * hidden properties.
5255
- */
5256
- /* istanbul ignore next */
5257
- function copyAugment(target, src, keys) {
5258
- for (let i = 0, l = keys.length; i < l; i++) {
5259
- const key = keys[i];
5260
- def(target, key, src[key]);
5086
+ if (options._scopeId) {
5087
+ this._c = (a, b, c, d) => {
5088
+ const vnode = createElement(contextVm, a, b, c, d, needNormalization);
5089
+ if (vnode && !isArray(vnode)) {
5090
+ vnode.fnScopeId = options._scopeId;
5091
+ vnode.fnContext = parent;
5092
+ }
5093
+ return vnode;
5094
+ };
5095
+ }
5096
+ else {
5097
+ this._c = (a, b, c, d) => createElement(contextVm, a, b, c, d, needNormalization);
5261
5098
  }
5262
5099
  }
5263
- /**
5264
- * Attempt to create an observer instance for a value,
5265
- * returns the new observer if successfully observed,
5266
- * or the existing observer if the value already has one.
5267
- */
5268
- function observe(value, shallow) {
5269
- if (!isObject$1(value) || isRef(value) || value instanceof VNode) {
5270
- return;
5100
+ installRenderHelpers(FunctionalRenderContext.prototype);
5101
+ function createFunctionalComponent(Ctor, propsData, data, contextVm, children) {
5102
+ const options = Ctor.options;
5103
+ const props = {};
5104
+ const propOptions = options.props;
5105
+ if (isDef(propOptions)) {
5106
+ for (const key in propOptions) {
5107
+ props[key] = validateProp(key, propOptions, propsData || emptyObject);
5108
+ }
5271
5109
  }
5272
- let ob;
5273
- if (hasOwn(value, '__ob__') && value.__ob__ instanceof Observer) {
5274
- ob = value.__ob__;
5110
+ else {
5111
+ if (isDef(data.attrs))
5112
+ mergeProps(props, data.attrs);
5113
+ if (isDef(data.props))
5114
+ mergeProps(props, data.props);
5275
5115
  }
5276
- else if (shouldObserve &&
5277
- !isServerRendering() &&
5278
- (isArray(value) || isPlainObject(value)) &&
5279
- Object.isExtensible(value) &&
5280
- !value.__v_skip) {
5281
- ob = new Observer(value, shallow);
5116
+ const renderContext = new FunctionalRenderContext(data, props, children, contextVm, Ctor);
5117
+ const vnode = options.render.call(null, renderContext._c, renderContext);
5118
+ if (vnode instanceof VNode) {
5119
+ return cloneAndMarkFunctionalResult(vnode, data, renderContext.parent, options, renderContext);
5120
+ }
5121
+ else if (isArray(vnode)) {
5122
+ const vnodes = normalizeChildren(vnode) || [];
5123
+ const res = new Array(vnodes.length);
5124
+ for (let i = 0; i < vnodes.length; i++) {
5125
+ res[i] = cloneAndMarkFunctionalResult(vnodes[i], data, renderContext.parent, options, renderContext);
5126
+ }
5127
+ return res;
5282
5128
  }
5283
- return ob;
5284
5129
  }
5285
- /**
5286
- * Define a reactive property on an Object.
5287
- */
5288
- function defineReactive(obj, key, val, customSetter, shallow) {
5289
- const dep = new Dep();
5290
- const property = Object.getOwnPropertyDescriptor(obj, key);
5291
- if (property && property.configurable === false) {
5292
- return;
5130
+ function cloneAndMarkFunctionalResult(vnode, data, contextVm, options, renderContext) {
5131
+ // #7817 clone node before setting fnContext, otherwise if the node is reused
5132
+ // (e.g. it was from a cached normal slot) the fnContext causes named slots
5133
+ // that should not be matched to match.
5134
+ const clone = cloneVNode(vnode);
5135
+ clone.fnContext = contextVm;
5136
+ clone.fnOptions = options;
5137
+ if (process.env.NODE_ENV !== 'production') {
5138
+ (clone.devtoolsMeta = clone.devtoolsMeta || {}).renderContext =
5139
+ renderContext;
5293
5140
  }
5294
- // cater for pre-defined getter/setters
5295
- const getter = property && property.get;
5296
- const setter = property && property.set;
5297
- if ((!getter || setter) &&
5298
- (val === NO_INIITIAL_VALUE || arguments.length === 2)) {
5299
- val = obj[key];
5141
+ if (data.slot) {
5142
+ (clone.data || (clone.data = {})).slot = data.slot;
5300
5143
  }
5301
- let childOb = !shallow && observe(val);
5302
- Object.defineProperty(obj, key, {
5303
- enumerable: true,
5304
- configurable: true,
5305
- get: function reactiveGetter() {
5306
- const value = getter ? getter.call(obj) : val;
5307
- if (Dep.target) {
5308
- if (process.env.NODE_ENV !== 'production') {
5309
- dep.depend({
5310
- target: obj,
5311
- type: "get" /* TrackOpTypes.GET */,
5312
- key
5313
- });
5314
- }
5315
- else {
5316
- dep.depend();
5317
- }
5318
- if (childOb) {
5319
- childOb.dep.depend();
5320
- if (isArray(value)) {
5321
- dependArray(value);
5322
- }
5323
- }
5324
- }
5325
- return isRef(value) && !shallow ? value.value : value;
5326
- },
5327
- set: function reactiveSetter(newVal) {
5328
- const value = getter ? getter.call(obj) : val;
5329
- if (!hasChanged(value, newVal)) {
5330
- return;
5331
- }
5332
- if (process.env.NODE_ENV !== 'production' && customSetter) {
5333
- customSetter();
5334
- }
5335
- if (setter) {
5336
- setter.call(obj, newVal);
5337
- }
5338
- else if (getter) {
5339
- // #7981: for accessor properties without setter
5340
- return;
5341
- }
5342
- else if (isRef(value) && !isRef(newVal)) {
5343
- value.value = newVal;
5344
- return;
5144
+ return clone;
5145
+ }
5146
+ function mergeProps(to, from) {
5147
+ for (const key in from) {
5148
+ to[camelize(key)] = from[key];
5149
+ }
5150
+ }
5151
+
5152
+ function getComponentName(options) {
5153
+ return options.name || options.__name || options._componentTag;
5154
+ }
5155
+ // inline hooks to be invoked on component VNodes during patch
5156
+ const componentVNodeHooks = {
5157
+ init(vnode, hydrating) {
5158
+ if (vnode.componentInstance &&
5159
+ !vnode.componentInstance._isDestroyed &&
5160
+ vnode.data.keepAlive) {
5161
+ // kept-alive components, treat as a patch
5162
+ const mountedNode = vnode; // work around flow
5163
+ componentVNodeHooks.prepatch(mountedNode, mountedNode);
5164
+ }
5165
+ else {
5166
+ const child = (vnode.componentInstance = createComponentInstanceForVnode(vnode, activeInstance));
5167
+ child.$mount(hydrating ? vnode.elm : undefined, hydrating);
5168
+ }
5169
+ },
5170
+ prepatch(oldVnode, vnode) {
5171
+ const options = vnode.componentOptions;
5172
+ const child = (vnode.componentInstance = oldVnode.componentInstance);
5173
+ updateChildComponent(child, options.propsData, // updated props
5174
+ options.listeners, // updated listeners
5175
+ vnode, // new parent vnode
5176
+ options.children // new children
5177
+ );
5178
+ },
5179
+ insert(vnode) {
5180
+ const { context, componentInstance } = vnode;
5181
+ if (!componentInstance._isMounted) {
5182
+ componentInstance._isMounted = true;
5183
+ callHook(componentInstance, 'mounted');
5184
+ }
5185
+ if (vnode.data.keepAlive) {
5186
+ if (context._isMounted) {
5187
+ // vue-router#1212
5188
+ // During updates, a kept-alive component's child components may
5189
+ // change, so directly walking the tree here may call activated hooks
5190
+ // on incorrect children. Instead we push them into a queue which will
5191
+ // be processed after the whole patch process ended.
5192
+ queueActivatedComponent(componentInstance);
5345
5193
  }
5346
5194
  else {
5347
- val = newVal;
5195
+ activateChildComponent(componentInstance, true /* direct */);
5348
5196
  }
5349
- childOb = !shallow && observe(newVal);
5350
- if (process.env.NODE_ENV !== 'production') {
5351
- dep.notify({
5352
- type: "set" /* TriggerOpTypes.SET */,
5353
- target: obj,
5354
- key,
5355
- newValue: newVal,
5356
- oldValue: value
5357
- });
5197
+ }
5198
+ },
5199
+ destroy(vnode) {
5200
+ const { componentInstance } = vnode;
5201
+ if (!componentInstance._isDestroyed) {
5202
+ if (!vnode.data.keepAlive) {
5203
+ componentInstance.$destroy();
5358
5204
  }
5359
5205
  else {
5360
- dep.notify();
5206
+ deactivateChildComponent(componentInstance, true /* direct */);
5361
5207
  }
5362
5208
  }
5363
- });
5364
- return dep;
5365
- }
5366
- function set(target, key, val) {
5367
- if (process.env.NODE_ENV !== 'production' && (isUndef(target) || isPrimitive(target))) {
5368
- warn$3(`Cannot set reactive property on undefined, null, or primitive value: ${target}`);
5369
5209
  }
5370
- if (isReadonly(target)) {
5371
- process.env.NODE_ENV !== 'production' && warn$3(`Set operation on key "${key}" failed: target is readonly.`);
5210
+ };
5211
+ const hooksToMerge = Object.keys(componentVNodeHooks);
5212
+ function createComponent(Ctor, data, context, children, tag) {
5213
+ if (isUndef(Ctor)) {
5372
5214
  return;
5373
5215
  }
5374
- if (isArray(target) && isValidArrayIndex(key)) {
5375
- target.length = Math.max(target.length, key);
5376
- target.splice(key, 1, val);
5377
- return val;
5216
+ const baseCtor = context.$options._base;
5217
+ // plain options object: turn it into a constructor
5218
+ if (isObject$1(Ctor)) {
5219
+ Ctor = baseCtor.extend(Ctor);
5378
5220
  }
5379
- if (key in target && !(key in Object.prototype)) {
5380
- target[key] = val;
5381
- return val;
5221
+ // if at this stage it's not a constructor or an async component factory,
5222
+ // reject.
5223
+ if (typeof Ctor !== 'function') {
5224
+ if (process.env.NODE_ENV !== 'production') {
5225
+ warn$3(`Invalid Component definition: ${String(Ctor)}`, context);
5226
+ }
5227
+ return;
5382
5228
  }
5383
- const ob = target.__ob__;
5384
- if (target._isVue || (ob && ob.vmCount)) {
5385
- process.env.NODE_ENV !== 'production' &&
5386
- warn$3('Avoid adding reactive properties to a Vue instance or its root $data ' +
5387
- 'at runtime - declare it upfront in the data option.');
5388
- return val;
5229
+ // async component
5230
+ let asyncFactory;
5231
+ // @ts-expect-error
5232
+ if (isUndef(Ctor.cid)) {
5233
+ asyncFactory = Ctor;
5234
+ Ctor = resolveAsyncComponent(asyncFactory);
5235
+ if (Ctor === undefined) {
5236
+ // return a placeholder node for async component, which is rendered
5237
+ // as a comment node but preserves all the raw information for the node.
5238
+ // the information will be used for async server-rendering and hydration.
5239
+ return createAsyncPlaceholder(asyncFactory, data, context, children, tag);
5240
+ }
5389
5241
  }
5390
- if (!ob) {
5391
- target[key] = val;
5392
- return val;
5242
+ data = data || {};
5243
+ // resolve constructor options in case global mixins are applied after
5244
+ // component constructor creation
5245
+ resolveConstructorOptions(Ctor);
5246
+ // transform component v-model data into props & events
5247
+ if (isDef(data.model)) {
5248
+ // @ts-expect-error
5249
+ transformModel(Ctor.options, data);
5393
5250
  }
5394
- defineReactive(ob.value, key, val);
5395
- if (process.env.NODE_ENV !== 'production') {
5396
- ob.dep.notify({
5397
- type: "add" /* TriggerOpTypes.ADD */,
5398
- target: target,
5399
- key,
5400
- newValue: val,
5401
- oldValue: undefined
5402
- });
5251
+ // extract props
5252
+ // @ts-expect-error
5253
+ const propsData = extractPropsFromVNodeData(data, Ctor, tag);
5254
+ // functional component
5255
+ // @ts-expect-error
5256
+ if (isTrue(Ctor.options.functional)) {
5257
+ return createFunctionalComponent(Ctor, propsData, data, context, children);
5403
5258
  }
5404
- else {
5405
- ob.dep.notify();
5259
+ // extract listeners, since these needs to be treated as
5260
+ // child component listeners instead of DOM listeners
5261
+ const listeners = data.on;
5262
+ // replace with listeners with .native modifier
5263
+ // so it gets processed during parent component patch.
5264
+ data.on = data.nativeOn;
5265
+ // @ts-expect-error
5266
+ if (isTrue(Ctor.options.abstract)) {
5267
+ // abstract components do not keep anything
5268
+ // other than props & listeners & slot
5269
+ // work around flow
5270
+ const slot = data.slot;
5271
+ data = {};
5272
+ if (slot) {
5273
+ data.slot = slot;
5274
+ }
5406
5275
  }
5407
- return val;
5276
+ // install component management hooks onto the placeholder node
5277
+ installComponentHooks(data);
5278
+ // return a placeholder vnode
5279
+ // @ts-expect-error
5280
+ const name = getComponentName(Ctor.options) || tag;
5281
+ const vnode = new VNode(
5282
+ // @ts-expect-error
5283
+ `vue-component-${Ctor.cid}${name ? `-${name}` : ''}`, data, undefined, undefined, undefined, context,
5284
+ // @ts-expect-error
5285
+ { Ctor, propsData, listeners, tag, children }, asyncFactory);
5286
+ return vnode;
5408
5287
  }
5409
- /**
5410
- * Collect dependencies on array elements when the array is touched, since
5411
- * we cannot intercept array element access like property getters.
5412
- */
5413
- function dependArray(value) {
5414
- for (let e, i = 0, l = value.length; i < l; i++) {
5415
- e = value[i];
5416
- if (e && e.__ob__) {
5417
- e.__ob__.dep.depend();
5288
+ function createComponentInstanceForVnode(
5289
+ // we know it's MountedComponentVNode but flow doesn't
5290
+ vnode,
5291
+ // activeInstance in lifecycle state
5292
+ parent) {
5293
+ const options = {
5294
+ _isComponent: true,
5295
+ _parentVnode: vnode,
5296
+ parent
5297
+ };
5298
+ // check inline-template render functions
5299
+ const inlineTemplate = vnode.data.inlineTemplate;
5300
+ if (isDef(inlineTemplate)) {
5301
+ options.render = inlineTemplate.render;
5302
+ options.staticRenderFns = inlineTemplate.staticRenderFns;
5303
+ }
5304
+ return new vnode.componentOptions.Ctor(options);
5305
+ }
5306
+ function installComponentHooks(data) {
5307
+ const hooks = data.hook || (data.hook = {});
5308
+ for (let i = 0; i < hooksToMerge.length; i++) {
5309
+ const key = hooksToMerge[i];
5310
+ const existing = hooks[key];
5311
+ const toMerge = componentVNodeHooks[key];
5312
+ // @ts-expect-error
5313
+ if (existing !== toMerge && !(existing && existing._merged)) {
5314
+ hooks[key] = existing ? mergeHook(toMerge, existing) : toMerge;
5418
5315
  }
5419
- if (isArray(e)) {
5420
- dependArray(e);
5316
+ }
5317
+ }
5318
+ function mergeHook(f1, f2) {
5319
+ const merged = (a, b) => {
5320
+ // flow complains about extra args which is why we use any
5321
+ f1(a, b);
5322
+ f2(a, b);
5323
+ };
5324
+ merged._merged = true;
5325
+ return merged;
5326
+ }
5327
+ // transform component v-model info (value and callback) into
5328
+ // prop and event handler respectively.
5329
+ function transformModel(options, data) {
5330
+ const prop = (options.model && options.model.prop) || 'value';
5331
+ const event = (options.model && options.model.event) || 'input';
5332
+ (data.attrs || (data.attrs = {}))[prop] = data.model.value;
5333
+ const on = data.on || (data.on = {});
5334
+ const existing = on[event];
5335
+ const callback = data.model.callback;
5336
+ if (isDef(existing)) {
5337
+ if (isArray(existing)
5338
+ ? existing.indexOf(callback) === -1
5339
+ : existing !== callback) {
5340
+ on[event] = [callback].concat(existing);
5421
5341
  }
5422
5342
  }
5343
+ else {
5344
+ on[event] = callback;
5345
+ }
5346
+ }
5347
+
5348
+ let warn$3 = noop;
5349
+ let tip = noop;
5350
+ let generateComponentTrace; // work around flow check
5351
+ let formatComponentName;
5352
+ if (process.env.NODE_ENV !== 'production') {
5353
+ const hasConsole = typeof console !== 'undefined';
5354
+ const classifyRE = /(?:^|[-_])(\w)/g;
5355
+ const classify = str => str.replace(classifyRE, c => c.toUpperCase()).replace(/[-_]/g, '');
5356
+ warn$3 = (msg, vm = currentInstance) => {
5357
+ const trace = vm ? generateComponentTrace(vm) : '';
5358
+ if (hasConsole && !config.silent) {
5359
+ console.error(`[Vue warn]: ${msg}${trace}`);
5360
+ }
5361
+ };
5362
+ tip = (msg, vm) => {
5363
+ if (hasConsole && !config.silent) {
5364
+ console.warn(`[Vue tip]: ${msg}` + (vm ? generateComponentTrace(vm) : ''));
5365
+ }
5366
+ };
5367
+ formatComponentName = (vm, includeFile) => {
5368
+ if (vm.$root === vm) {
5369
+ return '<Root>';
5370
+ }
5371
+ const options = isFunction(vm) && vm.cid != null
5372
+ ? vm.options
5373
+ : vm._isVue
5374
+ ? vm.$options || vm.constructor.options
5375
+ : vm;
5376
+ let name = getComponentName(options);
5377
+ const file = options.__file;
5378
+ if (!name && file) {
5379
+ const match = file.match(/([^/\\]+)\.vue$/);
5380
+ name = match && match[1];
5381
+ }
5382
+ return ((name ? `<${classify(name)}>` : `<Anonymous>`) +
5383
+ (file && includeFile !== false ? ` at ${file}` : ''));
5384
+ };
5385
+ const repeat = (str, n) => {
5386
+ let res = '';
5387
+ while (n) {
5388
+ if (n % 2 === 1)
5389
+ res += str;
5390
+ if (n > 1)
5391
+ str += str;
5392
+ n >>= 1;
5393
+ }
5394
+ return res;
5395
+ };
5396
+ generateComponentTrace = (vm) => {
5397
+ if (vm._isVue && vm.$parent) {
5398
+ const tree = [];
5399
+ let currentRecursiveSequence = 0;
5400
+ while (vm) {
5401
+ if (tree.length > 0) {
5402
+ const last = tree[tree.length - 1];
5403
+ if (last.constructor === vm.constructor) {
5404
+ currentRecursiveSequence++;
5405
+ vm = vm.$parent;
5406
+ continue;
5407
+ }
5408
+ else if (currentRecursiveSequence > 0) {
5409
+ tree[tree.length - 1] = [last, currentRecursiveSequence];
5410
+ currentRecursiveSequence = 0;
5411
+ }
5412
+ }
5413
+ tree.push(vm);
5414
+ vm = vm.$parent;
5415
+ }
5416
+ return ('\n\nfound in\n\n' +
5417
+ tree
5418
+ .map((vm, i) => `${i === 0 ? '---> ' : repeat(' ', 5 + i * 2)}${isArray(vm)
5419
+ ? `${formatComponentName(vm[0])}... (${vm[1]} recursive calls)`
5420
+ : formatComponentName(vm)}`)
5421
+ .join('\n'));
5422
+ }
5423
+ else {
5424
+ return `\n\n(found in ${formatComponentName(vm)})`;
5425
+ }
5426
+ };
5423
5427
  }
5424
5428
 
5425
5429
  /**