55import * as assert from 'assert' ;
66import { expect } from 'chai' ;
77import { ArrayASTNode , ObjectASTNode , PropertyASTNode } from '../src/languageservice/jsonASTTypes' ;
8- import { parse } from './../src/languageservice/parser/yamlParser07' ;
8+ import { parse , YAMLDocument } from './../src/languageservice/parser/yamlParser07' ;
99import { aliasDepth } from '../src/languageservice/parser/ast-converter' ;
1010
1111describe ( 'YAML parser' , ( ) => {
@@ -248,16 +248,20 @@ describe('YAML parser', () => {
248248 it ( 'parse aliases up to a depth' , ( ) => {
249249 // If maxRefCount is set to 1, it will only resolve one layer of aliases, which means
250250 // `b` below will inherit `a`, but `c` will not inherit `a`.
251- aliasDepth . maxRefCount = 1 ;
252- const parsedDocument = parse ( `
251+ let parsedDocument : YAMLDocument ;
252+ try {
253+ aliasDepth . maxRefCount = 1 ;
254+ parsedDocument = parse ( `
253255a: &a
254256 foo: "web"
255257b: &b
256258 <<: *a
257259c: &c
258260 <<: *b
259261` ) ;
260- aliasDepth . maxRefCount = 1000 ;
262+ } finally {
263+ aliasDepth . maxRefCount = 1000 ;
264+ }
261265
262266 const anode : ObjectASTNode = ( parsedDocument . documents [ 0 ] . root . children [ 0 ] as PropertyASTNode ) . valueNode as ObjectASTNode ;
263267 const aval = anode . properties [ 0 ] . valueNode ;
@@ -278,8 +282,10 @@ c: &c
278282 it ( 'parse aliases up to a depth for multiple objects' , ( ) => {
279283 // In the below configuration, `c` will not inherit `a` because of depth issues
280284 // but the following object `o` will still resolve correctly.
281- aliasDepth . maxRefCount = 1 ;
282- const parsedDocument = parse ( `
285+ let parsedDocument : YAMLDocument ;
286+ try {
287+ aliasDepth . maxRefCount = 1 ;
288+ parsedDocument = parse ( `
283289a: &a
284290 foo: "web"
285291b: &b
@@ -290,7 +296,9 @@ c: &c
290296o: &o
291297 <<: *a
292298` ) ;
293- aliasDepth . maxRefCount = 1000 ;
299+ } finally {
300+ aliasDepth . maxRefCount = 1000 ;
301+ }
294302
295303 const onode : ObjectASTNode = ( parsedDocument . documents [ 0 ] . root . children [ 3 ] as PropertyASTNode ) . valueNode as ObjectASTNode ;
296304 const ovalprops : PropertyASTNode = ( onode . properties [ 0 ] . valueNode as ObjectASTNode ) . properties [ 0 ] ;
0 commit comments