11import pluginTester from 'babel-plugin-tester'
22import { buildPlugin } from '../../src/plugin'
33import { ObjectExpression } from '../../src/visitors/object_expression'
4+ import { ArrayExpression } from '../../src/visitors/array_expression'
45
56pluginTester ( {
6- plugin : buildPlugin ( [ ObjectExpression ] ) ,
7+ plugin : buildPlugin ( [ ObjectExpression , ArrayExpression ] ) ,
78 tests : [ {
89 title : 'empty object' ,
910 pluginOptions : {
@@ -59,8 +60,8 @@ pluginTester({
5960 const a = {
6061 method(arg) {
6162 return arg
62- },
63- b: 1
63+ },
64+ b: 1
6465 }
6566 ` ,
6667 output : `
@@ -95,28 +96,6 @@ pluginTester({
9596 ['c']: 'c_val'
9697 }
9798 `
98- } , {
99- title : 'does not convert objects which have double quotes in string' ,
100- pluginOptions : {
101- minJSONStringSize : 0
102- } ,
103- code : `const a = { b: 'ab\"c' }` ,
104- output : `
105- const a = {
106- b: 'ab\"c'
107- }
108- `
109- } , {
110- title : 'does not convert objects which have double quotes in string' ,
111- pluginOptions : {
112- minJSONStringSize : 0
113- } ,
114- code : `const a = { b: 'ab"c' }` ,
115- output : `
116- const a = {
117- b: 'ab"c'
118- }
119- `
12099 } , {
121100 title : 'does not convert objects which have invalid numeric key' ,
122101 pluginOptions : {
@@ -149,6 +128,13 @@ pluginTester({
149128 } ,
150129 code : `const a = { b: "ab\'c" }` ,
151130 output : `const a = JSON.parse('{"b":"ab\\'c"}')`
131+ } , {
132+ title : 'string (include double quote)' ,
133+ pluginOptions : {
134+ minJSONStringSize : 0
135+ } ,
136+ code : `const a = { b: 'ab"c' }` ,
137+ output : `const a = JSON.parse('{"b":"ab\\\\\"c"}')`
152138 } , {
153139 title : 'number' ,
154140 pluginOptions : {
@@ -171,7 +157,7 @@ pluginTester({
171157 code : `const a = { b: false }` ,
172158 output : `const a = JSON.parse('{"b":false}')`
173159 } , {
174- title : 'Array' ,
160+ title : 'Object (with Array) ' ,
175161 pluginOptions : {
176162 minJSONStringSize : 0
177163 } ,
@@ -198,5 +184,12 @@ pluginTester({
198184 } ,
199185 code : `const a = { 1: "123", 23: 45, b: "b_val" }` ,
200186 output : `const a = JSON.parse('{"1":"123","23":45,"b":"b_val"}')`
187+ } , {
188+ title : 'Array' ,
189+ pluginOptions : {
190+ minJSONStringSize : 0
191+ } ,
192+ code : `const a = [1, "two", {three: 3}]` ,
193+ output : `const a = JSON.parse('[1,"two",{"three":3}]')`
201194 } , ]
202195} )
0 commit comments