@@ -80,9 +80,7 @@ function parse(source, root, options) {
80
80
pkg ,
81
81
imports ,
82
82
weakImports ,
83
- edition = "proto2" ,
84
- isProto3 = false ,
85
- isProto2 = true ;
83
+ edition = "proto2" ;
86
84
87
85
var ptr = root ;
88
86
@@ -151,13 +149,17 @@ function parse(source, root, options) {
151
149
function readRanges ( target , acceptStrings ) {
152
150
var token , start ;
153
151
do {
154
- if ( acceptStrings && ( ( token = peek ( ) ) === "\"" || token === "'" ) )
155
- target . push ( readString ( ) ) ;
156
- else {
152
+ if ( acceptStrings && ( ( token = peek ( ) ) === "\"" || token === "'" ) ) {
153
+ var str = readString ( ) ;
154
+ target . push ( str ) ;
155
+ if ( edition >= 2023 ) {
156
+ throw illegal ( str , "id" ) ;
157
+ }
158
+ } else {
157
159
try {
158
160
target . push ( [ start = parseId ( next ( ) ) , skip ( "to" , true ) ? parseId ( next ( ) ) : start ] ) ;
159
161
} catch ( err ) {
160
- if ( typeRefRe . test ( token ) && ( ! isProto2 && ! isProto3 ) ) {
162
+ if ( acceptStrings && typeRefRe . test ( token ) && edition >= 2023 ) {
161
163
target . push ( token ) ;
162
164
} else {
163
165
throw err ;
@@ -278,11 +280,9 @@ function parse(source, root, options) {
278
280
function parseSyntax ( ) {
279
281
skip ( "=" ) ;
280
282
edition = readString ( ) ;
281
- isProto3 = edition === "proto3" ;
282
- isProto2 = edition === "proto2" ;
283
283
284
284
/* istanbul ignore if */
285
- if ( ! isProto3 && ! isProto2 )
285
+ if ( edition < 2023 )
286
286
throw illegal ( edition , "syntax" ) ;
287
287
288
288
skip ( ";" ) ;
@@ -291,8 +291,6 @@ function parse(source, root, options) {
291
291
function parseEdition ( ) {
292
292
skip ( "=" ) ;
293
293
edition = readString ( ) ;
294
- isProto3 = false ;
295
- isProto2 = false ;
296
294
const supportedEditions = [ "2023" ] ;
297
295
298
296
/* istanbul ignore if */
@@ -370,7 +368,7 @@ function parse(source, root, options) {
370
368
break ;
371
369
372
370
case "required" :
373
- if ( ! isProto2 )
371
+ if ( edition !== "proto2" )
374
372
throw illegal ( token ) ;
375
373
/* eslint-disable no-fallthrough */
376
374
case "repeated" :
@@ -379,9 +377,9 @@ function parse(source, root, options) {
379
377
380
378
case "optional" :
381
379
/* istanbul ignore if */
382
- if ( isProto3 ) {
380
+ if ( edition === "proto3" ) {
383
381
parseField ( type , "proto3_optional" ) ;
384
- } else if ( ! isProto2 ) {
382
+ } else if ( edition !== "proto2" ) {
385
383
throw illegal ( token ) ;
386
384
} else {
387
385
parseField ( type , "optional" ) ;
@@ -402,7 +400,7 @@ function parse(source, root, options) {
402
400
403
401
default :
404
402
/* istanbul ignore if */
405
- if ( isProto2 || ! typeRefRe . test ( token ) ) {
403
+ if ( edition === "proto2" || ! typeRefRe . test ( token ) ) {
406
404
throw illegal ( token ) ;
407
405
}
408
406
@@ -478,6 +476,9 @@ function parse(source, root, options) {
478
476
}
479
477
480
478
function parseGroup ( parent , rule ) {
479
+ if ( edition >= 2023 ) {
480
+ throw illegal ( "group" ) ;
481
+ }
481
482
var name = next ( ) ;
482
483
483
484
/* istanbul ignore if */
@@ -507,7 +508,7 @@ function parse(source, root, options) {
507
508
508
509
case "optional" :
509
510
/* istanbul ignore if */
510
- if ( isProto3 ) {
511
+ if ( edition === "proto3" ) {
511
512
parseField ( type , "proto3_optional" ) ;
512
513
} else {
513
514
parseField ( type , "optional" ) ;
@@ -605,6 +606,7 @@ function parse(source, root, options) {
605
606
606
607
case "reserved" :
607
608
readRanges ( enm . reserved || ( enm . reserved = [ ] ) , true ) ;
609
+ if ( enm . reserved === undefined ) enm . reserved = [ ] ;
608
610
break ;
609
611
610
612
default :
@@ -865,7 +867,7 @@ function parse(source, root, options) {
865
867
866
868
case "optional" :
867
869
/* istanbul ignore if */
868
- if ( isProto3 ) {
870
+ if ( edition === "proto3" ) {
869
871
parseField ( parent , "proto3_optional" , reference ) ;
870
872
} else {
871
873
parseField ( parent , "optional" , reference ) ;
@@ -874,7 +876,7 @@ function parse(source, root, options) {
874
876
875
877
default :
876
878
/* istanbul ignore if */
877
- if ( isProto2 || ! typeRefRe . test ( token ) )
879
+ if ( edition === "proto2" || ! typeRefRe . test ( token ) )
878
880
throw illegal ( token ) ;
879
881
push ( token ) ;
880
882
parseField ( parent , "optional" , reference ) ;
0 commit comments