File tree Expand file tree Collapse file tree 2 files changed +63
-22
lines changed
Expand file tree Collapse file tree 2 files changed +63
-22
lines changed Original file line number Diff line number Diff line change 11import { isRef } from './ref'
2- import { proxy , isFunction , isObject , isArray } from '../utils'
2+ import { proxy , isFunction , isPlainObject , isArray } from '../utils'
33import { isReactive } from './reactive'
44
55export function unwrapRefProxy ( value : any ) {
6- if ( isFunction ( value ) ) {
7- return value
8- }
9-
10- if ( isRef ( value ) ) {
11- return value
12- }
13-
14- if ( isArray ( value ) ) {
15- return value
16- }
17-
18- if ( isReactive ( value ) ) {
19- return value
20- }
21-
22- if ( ! isObject ( value ) ) {
23- return value
24- }
25-
26- if ( ! Object . isExtensible ( value ) ) {
6+ if (
7+ isFunction ( value ) ||
8+ isRef ( value ) ||
9+ isArray ( value ) ||
10+ isReactive ( value ) ||
11+ ! isPlainObject ( value ) ||
12+ ! Object . isExtensible ( value )
13+ ) {
2714 return value
2815 }
2916
Original file line number Diff line number Diff line change @@ -568,6 +568,60 @@ describe('setup', () => {
568568 ) . toMatchObject ( [ { value : 1 } ] )
569569 } )
570570
571+ it ( 'should not unwrap built-in objects on the template' , ( ) => {
572+ const date = new Date ( '2020-01-01' )
573+ const regex = / a ( b ) .* /
574+ const dateString = date . toString ( )
575+ const regexString = regex . toString ( )
576+ const mathString = Math . toString ( )
577+
578+ const vm = new Vue ( {
579+ setup ( ) {
580+ return {
581+ raw_date : date ,
582+ nested_date : {
583+ a : date ,
584+ b : date ,
585+ } ,
586+ raw_regex : regex ,
587+ nested_regex : {
588+ a : regex ,
589+ b : regex ,
590+ } ,
591+ math : Math ,
592+ }
593+ } ,
594+ template : `<div>
595+ <p id="raw_date">{{raw_date}}</p>
596+ <p id="nested_date">{{nested_date}}</p>
597+ <p id="raw_regex">{{raw_regex}}</p>
598+ <p id="nested_regex_a">{{nested_regex.a}}</p>
599+ <p id="nested_regex_b">{{nested_regex.b}}</p>
600+ <p id="math">{{math}}</p>
601+ </div>` ,
602+ } ) . $mount ( )
603+
604+ expect ( vm . $el . querySelector ( '#raw_date' ) . textContent ) . toBe ( dateString )
605+ expect (
606+ JSON . parse ( vm . $el . querySelector ( '#nested_date' ) . textContent )
607+ ) . toMatchObject (
608+ JSON . parse (
609+ JSON . stringify ( {
610+ a : date ,
611+ b : date ,
612+ } )
613+ )
614+ )
615+ expect ( vm . $el . querySelector ( '#raw_regex' ) . textContent ) . toBe ( regexString )
616+ expect ( vm . $el . querySelector ( '#nested_regex_a' ) . textContent ) . toBe (
617+ regexString
618+ )
619+ expect ( vm . $el . querySelector ( '#nested_regex_b' ) . textContent ) . toBe (
620+ regexString
621+ )
622+ expect ( vm . $el . querySelector ( '#math' ) . textContent ) . toBe ( mathString )
623+ } )
624+
571625 describe ( 'Methods' , ( ) => {
572626 it ( 'binds methods when calling with parenthesis' , async ( ) => {
573627 let context = null
You can’t perform that action at this time.
0 commit comments