[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; return;
} }
if (!hasOwnProperty.call(to, key) || !isObj(val)) { if (!hasOwnProperty.call(to, key) || !isObj(val) || typeof val === 'function') {
to[key] = val; to[key] = val;
} else { } else {
to[key] = deepAssign(Object(to[key]), from[key]); to[key] = deepAssign(Object(to[key]), from[key]);

View File

@ -1,4 +1,5 @@
import { deepClone } from '../deep-clone'; import { deepClone } from '../deep-clone';
import { deepAssign } from '../deep-assign';
import { isDef, get } from '..'; import { isDef, get } from '..';
import { raf, cancelRaf } from '../dom/raf'; import { raf, cancelRaf } from '../dom/raf';
import { later } from '../../../test/utils'; import { later } from '../../../test/utils';
@ -21,6 +22,23 @@ test('deepClone', () => {
expect(deepClone(1)).toEqual(1); 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', () => { test('isDef', () => {
expect(isDef(null)).toBeFalsy(); expect(isDef(null)).toBeFalsy();
expect(isDef(undefined)).toBeFalsy(); expect(isDef(undefined)).toBeFalsy();