[bugfix] Locale: can not modify functional message (#3498)

This commit is contained in:
neverland 2019-06-13 17:20:20 +08:00 committed by GitHub
parent 1327ccb831
commit 639450709f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 3 deletions

View File

@ -11,7 +11,7 @@ function assignKey(to: ObjectIndex, from: ObjectIndex, key: string) {
return;
}
if (!hasOwnProperty.call(to, key) || !isObj(val)) {
if (!hasOwnProperty.call(to, key) || !isObj(val) || typeof val === 'function') {
to[key] = val;
} else {
to[key] = deepAssign(Object(to[key]), from[key]);

View File

@ -1,4 +1,5 @@
import { deepClone } from '../deep-clone';
import { deepAssign } from '../deep-assign';
import { isDef, get } from '..';
import { raf, cancelRaf } from '../dom/raf';
import { later } from '../../../test/utils';
@ -11,7 +12,7 @@ import { camelize } from '../format/string';
test('deepClone', () => {
const a = { foo: 0 };
const b = { foo: 0, bar: 1 };
const fn = () => { };
const fn = () => {};
const arr = [a, b];
expect(deepClone(a)).toEqual(a);
expect(deepClone(b)).toEqual(b);
@ -21,13 +22,30 @@ test('deepClone', () => {
expect(deepClone(1)).toEqual(1);
});
test('deepAssign', () => {
const fn = () => {};
expect(deepAssign({}, { foo: null })).toEqual({});
expect(deepAssign({}, { foo: undefined })).toEqual({});
expect(deepAssign({ fn: null }, { fn })).toEqual({ fn });
expect(deepAssign({ foo: 0 }, { bar: 1 })).toEqual({ foo: 0, bar: 1 });
expect(deepAssign({ foo: { bar: false } }, { foo: { bar: true, foo: false } })).toEqual(
{
foo: {
bar: true,
foo: false
}
}
);
});
test('isDef', () => {
expect(isDef(null)).toBeFalsy();
expect(isDef(undefined)).toBeFalsy();
expect(isDef(1)).toBeTruthy();
expect(isDef('1')).toBeTruthy();
expect(isDef({})).toBeTruthy();
expect(isDef(() => { })).toBeTruthy();
expect(isDef(() => {})).toBeTruthy();
});
test('camelize', () => {