Skip to content

Commit

Permalink
fix(setup): Allow retuning frozen objects on the setup (#366)
Browse files Browse the repository at this point in the history
  • Loading branch information
pikax committed Jun 10, 2020
1 parent 34c0fad commit bca3a69
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/reactivity/reactive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ export function reactive<T extends object>(obj: T): UnwrapRef<T> {
* Make sure obj can't be a reactive
*/
export function markRaw<T extends object>(obj: T): T {
if (!isPlainObject(obj)) {
if (!isPlainObject(obj) || !Object.isExtensible(obj)) {
return obj;
}

Expand Down
13 changes: 13 additions & 0 deletions test/setup.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,19 @@ describe('setup', () => {
expect(warn).not.toHaveBeenCalled();
});

it('Should allow to return Object.freeze', () => {
const vm = new Vue({
template: `<div>{{foo.bar}}</div>`,
setup() {
const foo = Object.freeze({ bar: 'baz' });
return {
foo,
};
},
}).$mount();
expect(vm.$el.textContent).toBe('baz');
});

it('this should be undefined', () => {
const vm = new Vue({
template: '<div></div>',
Expand Down

0 comments on commit bca3a69

Please sign in to comment.