66 * found in the LICENSE file at https://angular.io/license
77 */
88
9- import { JsonParseMode , parseJson , parseJsonAst } from './parser' ;
9+ import { JsonParseMode , parseJsonAst } from './parser' ;
1010
1111// Node 6 compatibility.
1212// eslint-disable-next-line @typescript-eslint/no-explicit-any
1313function entries ( x : { [ key : string ] : any } ) : any {
1414 return Object . keys ( x ) . map ( ( k ) => [ k , x [ k ] ] ) ;
1515}
1616
17- describe ( 'parseJson and parseJsonAst' , ( ) => {
17+ describe ( 'parseJsonAst' , ( ) => {
1818 describe ( 'generic' , ( ) => {
1919 const numbers = { } ;
2020 const errors = [ '' , '-abcdefghijklmnopqrstuvwxyz' ] ;
@@ -25,15 +25,13 @@ describe('parseJson and parseJsonAst', () => {
2525 expect ( ast . start ) . toEqual ( { offset : start [ 0 ] , line : start [ 1 ] , character : start [ 2 ] } ) ;
2626 expect ( ast . end ) . toEqual ( { offset : end [ 0 ] , line : end [ 1 ] , character : end [ 2 ] } ) ;
2727 expect ( ast . value ) . toEqual ( JSON . parse ( n ) ) ;
28- expect ( parseJson ( n ) ) . toEqual ( JSON . parse ( n ) ) ;
2928 expect ( ast . text ) . toBe ( text === undefined ? n : text ) ;
3029 } ) ;
3130 }
3231
3332 for ( const n of errors ) {
3433 it ( `errors for ${ JSON . stringify ( n ) } ` , ( ) => {
3534 expect ( ( ) => parseJsonAst ( n ) ) . toThrow ( ) ;
36- expect ( ( ) => parseJson ( n ) ) . toThrow ( ) ;
3735 expect ( ( ) => JSON . parse ( n ) ) . toThrow ( ) ;
3836 } ) ;
3937 }
@@ -98,15 +96,13 @@ describe('parseJson and parseJsonAst', () => {
9896 expect ( ast . start ) . toEqual ( { offset : start [ 0 ] , line : start [ 1 ] , character : start [ 2 ] } ) ;
9997 expect ( ast . end ) . toEqual ( { offset : end [ 0 ] , line : end [ 1 ] , character : end [ 2 ] } ) ;
10098 expect ( ast . value ) . toEqual ( JSON . parse ( n ) ) ;
101- expect ( parseJson ( n ) ) . toEqual ( JSON . parse ( n ) ) ;
10299 expect ( ast . text ) . toBe ( text === undefined ? n : text ) ;
103100 } ) ;
104101 }
105102
106103 for ( const n of errors ) {
107104 it ( `errors for ${ JSON . stringify ( n ) } ` , ( ) => {
108105 expect ( ( ) => parseJsonAst ( n ) ) . toThrow ( ) ;
109- expect ( ( ) => parseJson ( n ) ) . toThrow ( ) ;
110106 expect ( ( ) => JSON . parse ( n ) ) . toThrow ( ) ;
111107 } ) ;
112108 }
@@ -144,15 +140,13 @@ describe('parseJson and parseJsonAst', () => {
144140 expect ( ast . start ) . toEqual ( { offset : start [ 0 ] , line : start [ 1 ] , character : start [ 2 ] } ) ;
145141 expect ( ast . end ) . toEqual ( { offset : end [ 0 ] , line : end [ 1 ] , character : end [ 2 ] } ) ;
146142 expect ( ast . value ) . toEqual ( JSON . parse ( n ) ) ;
147- expect ( parseJson ( n ) ) . toEqual ( JSON . parse ( n ) ) ;
148143 expect ( ast . text ) . toBe ( text === undefined ? n : text ) ;
149144 } ) ;
150145 }
151146
152147 for ( const n of errors ) {
153148 it ( `errors for ${ JSON . stringify ( n ) } ` , ( ) => {
154149 expect ( ( ) => parseJsonAst ( n ) ) . toThrow ( ) ;
155- expect ( ( ) => parseJson ( n ) ) . toThrow ( ) ;
156150 expect ( ( ) => JSON . parse ( n ) ) . toThrow ( ) ;
157151 } ) ;
158152 }
@@ -180,7 +174,6 @@ describe('parseJson and parseJsonAst', () => {
180174 for ( const n of errors ) {
181175 it ( `errors for ${ JSON . stringify ( n ) } ` , ( ) => {
182176 expect ( ( ) => parseJsonAst ( n ) ) . toThrow ( ) ;
183- expect ( ( ) => parseJson ( n ) ) . toThrow ( ) ;
184177 expect ( ( ) => JSON . parse ( n ) ) . toThrow ( ) ;
185178 } ) ;
186179 }
@@ -223,15 +216,13 @@ describe('parseJson and parseJsonAst', () => {
223216 expect ( ast . start ) . toEqual ( { offset : start [ 0 ] , line : start [ 1 ] , character : start [ 2 ] } ) ;
224217 expect ( ast . end ) . toEqual ( { offset : end [ 0 ] , line : end [ 1 ] , character : end [ 2 ] } ) ;
225218 expect ( ast . value ) . toEqual ( JSON . parse ( n ) ) ;
226- expect ( parseJson ( n ) ) . toEqual ( JSON . parse ( n ) ) ;
227219 expect ( ast . text ) . toBe ( text === undefined ? n : text ) ;
228220 } ) ;
229221 }
230222
231223 for ( const n of errors ) {
232224 it ( `errors for ${ JSON . stringify ( n ) } ` , ( ) => {
233225 expect ( ( ) => parseJsonAst ( n ) ) . toThrow ( ) ;
234- expect ( ( ) => parseJson ( n ) ) . toThrow ( ) ;
235226 expect ( ( ) => JSON . parse ( n ) ) . toThrow ( ) ;
236227 } ) ;
237228 }
@@ -269,15 +260,13 @@ describe('parseJson and parseJsonAst', () => {
269260 expect ( ast . start ) . toEqual ( { offset : start [ 0 ] , line : start [ 1 ] , character : start [ 2 ] } ) ;
270261 expect ( ast . end ) . toEqual ( { offset : end [ 0 ] , line : end [ 1 ] , character : end [ 2 ] } ) ;
271262 expect ( ast . value ) . toEqual ( JSON . parse ( n ) ) ;
272- expect ( parseJson ( n ) ) . toEqual ( JSON . parse ( n ) ) ;
273263 expect ( ast . text ) . toBe ( text === undefined ? n : text ) ;
274264 } ) ;
275265 }
276266
277267 for ( const n of errors ) {
278268 it ( `errors for ${ JSON . stringify ( n ) } ` , ( ) => {
279269 expect ( ( ) => parseJsonAst ( n ) ) . toThrow ( ) ;
280- expect ( ( ) => parseJson ( n ) ) . toThrow ( ) ;
281270 expect ( ( ) => JSON . parse ( n ) ) . toThrow ( ) ;
282271 } ) ;
283272 }
@@ -322,76 +311,15 @@ describe('parseJson and parseJsonAst', () => {
322311 expect ( ast . start ) . toEqual ( { offset : start [ 0 ] , line : start [ 1 ] , character : start [ 2 ] } ) ;
323312 expect ( ast . end ) . toEqual ( { offset : end [ 0 ] , line : end [ 1 ] , character : end [ 2 ] } ) ;
324313 expect ( ast . value ) . toEqual ( value ) ;
325- expect ( parseJson ( n , JsonParseMode . Loose ) ) . toEqual ( value ) ;
326314 expect ( ast . text ) . toBe ( text === undefined ? n : text ) ;
327315 } ) ;
328316 }
329317
330318 for ( const n of errors ) {
331319 it ( `errors for ${ JSON . stringify ( n ) } ` , ( ) => {
332320 expect ( ( ) => parseJsonAst ( n , JsonParseMode . Loose ) ) . toThrow ( ) ;
333- expect ( ( ) => parseJson ( n , JsonParseMode . Loose ) ) . toThrow ( ) ;
334321 expect ( ( ) => JSON . parse ( n ) ) . toThrow ( ) ;
335322 } ) ;
336323 }
337324 } ) ;
338-
339- describe ( 'complex' , ( ) => {
340- it ( 'strips comments' , ( ) => {
341- expect (
342- parseJson (
343- `
344- // THIS IS A COMMENT
345- {
346- /* THIS IS ALSO A COMMENT */ // IGNORED BECAUSE COMMENT
347- // AGAIN, COMMENT /* THIS SHOULD NOT BE WEIRD
348- "a": "this // should not be a comment",
349- "a2": "this /* should also not be a comment",
350- /* MULTIPLE
351- LINE
352- COMMENT
353- \\o/ */
354- "b" /* COMMENT */: /* YOU GUESSED IT */ 1 // COMMENT
355- , /* STILL VALID */
356- "c": 2
357- }
358- ` ,
359- JsonParseMode . Loose ,
360- ) ,
361- ) . toEqual ( {
362- a : 'this // should not be a comment' ,
363- a2 : 'this /* should also not be a comment' ,
364- b : 1 ,
365- c : 2 ,
366- } ) ;
367- } ) ;
368-
369- it ( 'works with json5.org example' , ( ) => {
370- const input = `{
371- // comments
372- unquoted: 'and you can quote me on that',
373- 'singleQuotes': 'I can use "double quotes" here',
374- lineBreaks: "Look, Mom! \\
375- No \\\\n's!",
376- hexadecimal: 0xdecaf,
377- leadingDecimalPoint: .8675309, andTrailing: 8675309.,
378- positiveSign: +1,
379- trailingComma: 'in objects', andIn: ['arrays',],
380- "backwardsCompatible": "with JSON",
381- }` ;
382-
383- expect ( parseJson ( input , JsonParseMode . Json5 ) ) . toEqual ( {
384- unquoted : 'and you can quote me on that' ,
385- singleQuotes : 'I can use "double quotes" here' ,
386- lineBreaks : "Look, Mom! \nNo \\n's!" ,
387- hexadecimal : 0xdecaf ,
388- leadingDecimalPoint : 0.8675309 ,
389- andTrailing : 8675309 ,
390- positiveSign : + 1 ,
391- trailingComma : 'in objects' ,
392- andIn : [ 'arrays' ] ,
393- backwardsCompatible : 'with JSON' ,
394- } ) ;
395- } ) ;
396- } ) ;
397325} ) ;
0 commit comments