File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -261,17 +261,9 @@ proto.write = function (buffer) {
261261 break ;
262262 default :
263263 this . tState = START ;
264- var result = Number ( this . string ) ;
265-
266- if ( isNaN ( result ) ) {
267- return this . charError ( buffer , i ) ;
268- }
269-
270- if ( ( this . string . match ( / [ 0 - 9 ] + / ) == this . string ) && ( result . toString ( ) != this . string ) ) {
271- // Long string of digits which is an ID string and not valid and/or safe JavaScript integer Number
272- this . onToken ( STRING , this . string ) ;
273- } else {
274- this . onToken ( NUMBER , result ) ;
264+ var error = this . numberReviver ( this . string ) ;
265+ if ( error ) {
266+ return error ;
275267 }
276268
277269 this . offset += this . string . length - 1 ;
@@ -408,6 +400,23 @@ proto.onToken = function (token, value) {
408400 }
409401} ;
410402
403+ // Override to implement your own number reviver.
404+ // Any value returned is treated as error and will interrupt parsing.
405+ proto . numberReviver = function ( text ) {
406+ var result = Number ( text ) ;
407+
408+ if ( isNaN ( result ) ) {
409+ return this . charError ( buffer , i ) ;
410+ }
411+
412+ if ( ( text . match ( / [ 0 - 9 ] + / ) == text ) && ( result . toString ( ) != text ) ) {
413+ // Long string of digits which is an ID string and not valid and/or safe JavaScript integer Number
414+ this . onToken ( STRING , text ) ;
415+ } else {
416+ this . onToken ( NUMBER , result ) ;
417+ }
418+ }
419+
411420Parser . C = C ;
412421
413422module . exports = Parser ;
You can’t perform that action at this time.
0 commit comments