@@ -19,7 +19,7 @@ import {
1919 SyntaxKind
2020} from '../main' ;
2121
22- namespace ParseOptions {
22+ namespace ParseOptionsConfigs {
2323 export const DEFAULT = {
2424 allowTrailingComma : false
2525 } ;
@@ -61,7 +61,7 @@ export function getLocation(text: string, position: number): Location {
6161 try {
6262
6363 visit ( text , {
64- onObjectBegin : ( offset : number , length : number ) => {
64+ onObjectBegin : ( offset : number ) => {
6565 if ( position <= offset ) {
6666 throw earlyReturnException ;
6767 }
@@ -79,21 +79,21 @@ export function getLocation(text: string, position: number): Location {
7979 throw earlyReturnException ;
8080 }
8181 } ,
82- onObjectEnd : ( offset : number , length : number ) => {
82+ onObjectEnd : ( offset : number ) => {
8383 if ( position <= offset ) {
8484 throw earlyReturnException ;
8585 }
8686 previousNode = undefined ;
8787 segments . pop ( ) ;
8888 } ,
89- onArrayBegin : ( offset : number , length : number ) => {
89+ onArrayBegin : ( offset : number ) => {
9090 if ( position <= offset ) {
9191 throw earlyReturnException ;
9292 }
9393 previousNode = undefined ;
9494 segments . push ( 0 ) ;
9595 } ,
96- onArrayEnd : ( offset : number , length : number ) => {
96+ onArrayEnd : ( offset : number ) => {
9797 if ( position <= offset ) {
9898 throw earlyReturnException ;
9999 }
@@ -110,7 +110,7 @@ export function getLocation(text: string, position: number): Location {
110110 throw earlyReturnException ;
111111 }
112112 } ,
113- onSeparator : ( sep : string , offset : number , length : number ) => {
113+ onSeparator : ( sep : string , offset : number ) => {
114114 if ( position <= offset ) {
115115 throw earlyReturnException ;
116116 }
@@ -159,7 +159,7 @@ export function getLocation(text: string, position: number): Location {
159159 * Parses the given text and returns the object the JSON content represents. On invalid input, the parser tries to be as fault tolerant as possible, but still return a result.
160160 * Therefore always check the errors list to find out if the input was valid.
161161 */
162- export function parse ( text : string , errors : ParseError [ ] = [ ] , options : ParseOptions = ParseOptions . DEFAULT ) : any {
162+ export function parse ( text : string , errors : ParseError [ ] = [ ] , options : ParseOptions = ParseOptionsConfigs . DEFAULT ) : any {
163163 let currentProperty : string | null = null ;
164164 let currentParent : any = [ ] ;
165165 const previousParents : any [ ] = [ ] ;
@@ -209,7 +209,7 @@ export function parse(text: string, errors: ParseError[] = [], options: ParseOpt
209209/**
210210 * Parses the given text and returns a tree representation the JSON content. On invalid input, the parser tries to be as fault tolerant as possible, but still return a result.
211211 */
212- export function parseTree ( text : string , errors : ParseError [ ] = [ ] , options : ParseOptions = ParseOptions . DEFAULT ) : Node | undefined {
212+ export function parseTree ( text : string , errors : ParseError [ ] = [ ] , options : ParseOptions = ParseOptionsConfigs . DEFAULT ) : Node | undefined {
213213 let currentParent : NodeImpl = { type : 'array' , offset : - 1 , length : - 1 , children : [ ] , parent : undefined } ; // artificial root
214214
215215 function ensurePropertyComplete ( endOffset : number ) {
@@ -239,7 +239,7 @@ export function parseTree(text: string, errors: ParseError[] = [], options: Pars
239239 currentParent = currentParent . parent ! ;
240240 ensurePropertyComplete ( offset + length ) ;
241241 } ,
242- onArrayBegin : ( offset : number , length : number ) => {
242+ onArrayBegin : ( offset : number ) => {
243243 currentParent = onValue ( { type : 'array' , offset, length : - 1 , parent : currentParent , children : [ ] } ) ;
244244 } ,
245245 onArrayEnd : ( offset : number , length : number ) => {
@@ -251,7 +251,7 @@ export function parseTree(text: string, errors: ParseError[] = [], options: Pars
251251 onValue ( { type : getNodeType ( value ) , offset, length, parent : currentParent , value } ) ;
252252 ensurePropertyComplete ( offset + length ) ;
253253 } ,
254- onSeparator : ( sep : string , offset : number , length : number ) => {
254+ onSeparator : ( sep : string , offset : number ) => {
255255 if ( currentParent . type === 'property' ) {
256256 if ( sep === ':' ) {
257257 currentParent . colonOffset = offset ;
@@ -335,7 +335,7 @@ export function getNodeValue(node: Node): any {
335335 switch ( node . type ) {
336336 case 'array' :
337337 return node . children ! . map ( getNodeValue ) ;
338- case 'object' :
338+ case 'object' : {
339339 const obj = Object . create ( null ) ;
340340 for ( let prop of node . children ! ) {
341341 const valueNode = prop . children ! [ 1 ] ;
@@ -344,6 +344,7 @@ export function getNodeValue(node: Node): any {
344344 }
345345 }
346346 return obj ;
347+ }
347348 case 'null' :
348349 case 'string' :
349350 case 'number' :
@@ -383,7 +384,7 @@ export function findNodeAtOffset(node: Node, offset: number, includeRightBound =
383384/**
384385 * Parses the given text and invokes the visitor functions for each object, array and literal reached.
385386 */
386- export function visit ( text : string , visitor : JSONVisitor , options : ParseOptions = ParseOptions . DEFAULT ) : any {
387+ export function visit ( text : string , visitor : JSONVisitor , options : ParseOptions = ParseOptionsConfigs . DEFAULT ) : any {
387388
388389 const _scanner = createScanner ( text , false ) ;
389390 // Important: Only pass copies of this to visitor functions to prevent accidental modification, and
@@ -512,16 +513,17 @@ export function visit(text: string, visitor: JSONVisitor, options: ParseOptions
512513
513514 function parseLiteral ( ) : boolean {
514515 switch ( _scanner . getToken ( ) ) {
515- case SyntaxKind . NumericLiteral :
516- const tokenValue = _scanner . getTokenValue ( ) ;
517- let value = Number ( tokenValue ) ;
516+ case SyntaxKind . NumericLiteral : {
517+ const tokenValue = _scanner . getTokenValue ( ) ;
518+ let value = Number ( tokenValue ) ;
518519
519- if ( isNaN ( value ) ) {
520- handleError ( ParseErrorCode . InvalidNumberFormat ) ;
521- value = 0 ;
522- }
520+ if ( isNaN ( value ) ) {
521+ handleError ( ParseErrorCode . InvalidNumberFormat ) ;
522+ value = 0 ;
523+ }
523524
524- onLiteralValue ( value ) ;
525+ onLiteralValue ( value ) ;
526+ }
525527 break ;
526528 case SyntaxKind . NullKeyword :
527529 onLiteralValue ( null ) ;
0 commit comments