Skip to content

Commit 3515b53

Browse files
feat!: add Edition 2023 Support
1 parent ac9a3b9 commit 3515b53

File tree

7 files changed

+261
-11
lines changed

7 files changed

+261
-11
lines changed

cli/bin/pbjs

100644100755
File mode changed.

cli/bin/pbts

100644100755
File mode changed.

src/object.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ var Root; // cyclic
1010

1111
/* eslint-disable no-warning-comments */
1212
// TODO: Replace with embedded proto.
13-
var editions2023Defaults = {enum_type: "OPEN", field_presence: "EXPLICIT", json_format: "ALLOW", message_encoding: "LENGTH_PREFIXED", repeated_field_encoding: "PACKED", utf8_validation: "VERIFY"};
14-
var proto2Defaults = {enum_type: "CLOSED", field_presence: "EXPLICIT", json_format: "LEGACY_BEST_EFFORT", message_encoding: "LENGTH_PREFIXED", repeated_field_encoding: "EXPANDED", utf8_validation: "NONE"};
15-
var proto3Defaults = {enum_type: "OPEN", field_presence: "IMPLICIT", json_format: "ALLOW", message_encoding: "LENGTH_PREFIXED", repeated_field_encoding: "PACKED", utf8_validation: "VERIFY"};
13+
var editions2024Defaults = {enum_type: "OPEN", field_presence: "EXPLICIT", json_format: "ALLOW", message_encoding: "LENGTH_PREFIXED", repeated_field_encoding: "PACKED", utf8_validation: "VERIFY", enforce_naming_style: "STYLE2024", default_symbol_visibility: "EXPORT_TOP_LEVEL" };
14+
var editions2023Defaults = {enum_type: "OPEN", field_presence: "EXPLICIT", json_format: "ALLOW", message_encoding: "LENGTH_PREFIXED", repeated_field_encoding: "PACKED", utf8_validation: "VERIFY", enforce_naming_style: "STYLE_LEGACY", default_symbol_visibility: "EXPORT_ALL" };
15+
var proto2Defaults = {enum_type: "CLOSED", field_presence: "EXPLICIT", json_format: "LEGACY_BEST_EFFORT", message_encoding: "LENGTH_PREFIXED", repeated_field_encoding: "EXPANDED", utf8_validation: "NONE", enforce_naming_style: "STYLE_LEGACY", default_symbol_visibility: "EXPORT_ALL" };
16+
var proto3Defaults = {enum_type: "OPEN", field_presence: "IMPLICIT", json_format: "ALLOW", message_encoding: "LENGTH_PREFIXED", repeated_field_encoding: "PACKED", utf8_validation: "VERIFY", enforce_naming_style: "STYLE_LEGACY", default_symbol_visibility: "EXPORT_ALL" };
1617

1718
/**
1819
* Constructs a new reflection object instance.
@@ -213,6 +214,8 @@ ReflectionObject.prototype._resolveFeatures = function _resolveFeatures(edition)
213214
defaults = Object.assign({}, proto3Defaults);
214215
} else if (edition === "2023") {
215216
defaults = Object.assign({}, editions2023Defaults);
217+
} else if (edition === "2024") {
218+
defaults = Object.assign({}, editions2024Defaults);
216219
} else {
217220
throw new Error("Unknown edition: " + edition);
218221
}

src/parse.js

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,16 @@ function parse(source, root, options) {
261261
var token = peek();
262262
var whichImports;
263263
switch (token) {
264+
case "option":
265+
if (edition < "2024") {
266+
throw illegal("option");
267+
}
268+
// Import options are only used for resolving options, which we don't
269+
// do. We can just throw them out.
270+
next();
271+
readString();
272+
skip(";");
273+
return;
264274
case "weak":
265275
whichImports = weakImports || (weakImports = []);
266276
next();
@@ -291,7 +301,7 @@ function parse(source, root, options) {
291301
function parseEdition() {
292302
skip("=");
293303
edition = readString();
294-
const supportedEditions = ["2023"];
304+
const supportedEditions = ["2023", "2024"];
295305

296306
/* istanbul ignore if */
297307
if (!supportedEditions.includes(edition))
@@ -317,6 +327,21 @@ function parse(source, root, options) {
317327
parseEnum(parent, token);
318328
return true;
319329

330+
case "export":
331+
case "local":
332+
if (edition < "2024") {
333+
return false;
334+
}
335+
token = next();
336+
if (token === "export" || token === "local") {
337+
return false;
338+
}
339+
if (token !== "message" && token !== "enum") {
340+
return false;
341+
}
342+
// TODO: actually enforce visiblity modifiers like protoc does.
343+
return parseCommon(parent, token);
344+
320345
case "service":
321346
parseService(parent, token);
322347
return true;
@@ -523,6 +548,24 @@ function parse(source, root, options) {
523548
parseEnum(type, token);
524549
break;
525550

551+
case "export":
552+
case "local":
553+
if (edition < "2024") {
554+
throw illegal(token);
555+
}
556+
token = next();
557+
switch (token) {
558+
case "message":
559+
parseType(type, token);
560+
break;
561+
case "enum":
562+
parseType(type, token);
563+
break;
564+
default:
565+
throw illegal(token);
566+
}
567+
break;
568+
526569
/* istanbul ignore next */
527570
default:
528571
throw illegal(token); // there are no groups with proto3 semantics

tests/data/import-option-bad.proto

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
edition = "2024";
2+
3+
import option "nonexistent.proto";
4+
5+
option features.(pb.nonexistent).foo = BAR;
6+
7+
message Foo {
8+
string legacy = 1;
9+
}

tests/feature_resolution_editions.js

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,20 +66,22 @@ var tape = require("tape");
6666

6767
var protobuf = require("..");
6868

69+
var protoEditions2024 = `edition = "2024"; message Foo {}`;
6970
var protoEditions2023 = `edition = "2023"; message Foo {}`;
7071

7172
var proto2 = `syntax = "proto2"; message Foo {}`;
7273

7374
var proto3 = `syntax = "proto3"; message Foo {}`;
7475

75-
var editions2023Defaults = {enum_type: 'OPEN', field_presence: 'EXPLICIT', json_format: 'ALLOW', message_encoding: 'LENGTH_PREFIXED', repeated_field_encoding: 'PACKED', utf8_validation: 'VERIFY'}
76-
var proto2Defaults = {enum_type: 'CLOSED', field_presence: 'EXPLICIT', json_format: 'LEGACY_BEST_EFFORT', message_encoding: 'LENGTH_PREFIXED', repeated_field_encoding: 'EXPANDED', utf8_validation: 'NONE'}
77-
var proto3Defaults = {enum_type: 'OPEN', field_presence: 'IMPLICIT', json_format: 'ALLOW', message_encoding: 'LENGTH_PREFIXED', repeated_field_encoding: 'PACKED', utf8_validation: 'VERIFY'}
76+
var editions2024Defaults = {enum_type: "OPEN", field_presence: "EXPLICIT", json_format: "ALLOW", message_encoding: "LENGTH_PREFIXED", repeated_field_encoding: "PACKED", utf8_validation: "VERIFY", enforce_naming_style: "STYLE2024", default_symbol_visibility: "EXPORT_TOP_LEVEL" };
77+
var editions2023Defaults = {enum_type: "OPEN", field_presence: "EXPLICIT", json_format: "ALLOW", message_encoding: "LENGTH_PREFIXED", repeated_field_encoding: "PACKED", utf8_validation: "VERIFY", enforce_naming_style: "STYLE_LEGACY", default_symbol_visibility: "EXPORT_ALL" };
78+
var proto2Defaults = {enum_type: "CLOSED", field_presence: "EXPLICIT", json_format: "LEGACY_BEST_EFFORT", message_encoding: "LENGTH_PREFIXED", repeated_field_encoding: "EXPANDED", utf8_validation: "NONE", enforce_naming_style: "STYLE_LEGACY", default_symbol_visibility: "EXPORT_ALL" };
79+
var proto3Defaults = {enum_type: "OPEN", field_presence: "IMPLICIT", json_format: "ALLOW", message_encoding: "LENGTH_PREFIXED", repeated_field_encoding: "PACKED", utf8_validation: "VERIFY", enforce_naming_style: "STYLE_LEGACY", default_symbol_visibility: "EXPORT_ALL" };
7880

7981
tape.test("feature resolution defaults", function(test) {
80-
var rootEditions = protobuf.parse(protoEditions2023).root;
82+
var rootEditions = protobuf.parse(protoEditions2024).root;
8183
rootEditions.resolveAll();
82-
test.same(rootEditions.Foo._features, editions2023Defaults);
84+
test.same(rootEditions.Foo._features, editions2024Defaults);
8385

8486
var rootProto2 = protobuf.parse(proto2).root;
8587
rootProto2.resolveAll();
@@ -136,6 +138,8 @@ tape.test("aggregate feature parsing", function(test) {
136138
message_encoding: 'LENGTH_PREFIXED',
137139
repeated_field_encoding: 'PACKED',
138140
utf8_validation: 'NONE',
141+
enforce_naming_style: "STYLE_LEGACY",
142+
default_symbol_visibility: "EXPORT_ALL"
139143
})
140144

141145
test.end();
@@ -160,6 +164,8 @@ tape.test("feature resolution inheritance file to message", function(test) {
160164
message_encoding: 'LENGTH_PREFIXED',
161165
repeated_field_encoding: 'PACKED',
162166
utf8_validation: 'VERIFY',
167+
enforce_naming_style: "STYLE_LEGACY",
168+
default_symbol_visibility: "EXPORT_ALL",
163169
'(abc)': { d_e: 'deeply_nested_false' }
164170
})
165171

@@ -185,6 +191,8 @@ tape.test("feature resolution inheritance message to field", function(test) {
185191
message_encoding: 'LENGTH_PREFIXED',
186192
repeated_field_encoding: 'PACKED',
187193
utf8_validation: 'VERIFY',
194+
enforce_naming_style: "STYLE_LEGACY",
195+
default_symbol_visibility: "EXPORT_ALL",
188196
'(abc)': { d_e: 'deeply_nested_false' }
189197
})
190198

@@ -213,6 +221,8 @@ tape.test("feature resolution inheritance message to nested message", function(t
213221
message_encoding: 'LENGTH_PREFIXED',
214222
repeated_field_encoding: 'PACKED',
215223
utf8_validation: 'VERIFY',
224+
enforce_naming_style: "STYLE_LEGACY",
225+
default_symbol_visibility: "EXPORT_ALL",
216226
'(abc)': { d_e: 'deeply_nested_true' }
217227
});
218228
test.end();
@@ -238,6 +248,8 @@ tape.test("feature resolution inheritance enum to enum value", function(test) {
238248
message_encoding: 'LENGTH_PREFIXED',
239249
repeated_field_encoding: 'EXPANDED',
240250
utf8_validation: 'VERIFY',
251+
enforce_naming_style: "STYLE_LEGACY",
252+
default_symbol_visibility: "EXPORT_ALL",
241253
'(abc)': { d_e: 'deeply_nested_false' }
242254
})
243255

@@ -248,7 +260,9 @@ tape.test("feature resolution inheritance enum to enum value", function(test) {
248260
message_encoding: 'LENGTH_PREFIXED',
249261
repeated_field_encoding: 'PACKED',
250262
utf8_validation: 'VERIFY',
251-
'(abc)': { d_e: 'deeply_nested_false' }
263+
enforce_naming_style: "STYLE_LEGACY",
264+
default_symbol_visibility: "EXPORT_ALL",
265+
'(abc)': { d_e: 'deeply_nested_false' }
252266
});
253267

254268
test.end();
@@ -274,6 +288,8 @@ tape.test("feature resolution inheritance message to oneofs", function(test) {
274288
message_encoding: 'LENGTH_PREFIXED',
275289
repeated_field_encoding: 'PACKED',
276290
utf8_validation: 'VERIFY',
291+
enforce_naming_style: "STYLE_LEGACY",
292+
default_symbol_visibility: "EXPORT_ALL",
277293
'(abc)': { d_e: 'deeply_nested_false' }
278294
})
279295

@@ -301,7 +317,9 @@ tape.test("feature resolution inheritance oneofs", function(test) {
301317
message_encoding: 'LENGTH_PREFIXED',
302318
repeated_field_encoding: 'PACKED',
303319
utf8_validation: 'VERIFY',
304-
'(abc)': { d_e: 'deeply_nested_false' }
320+
enforce_naming_style: "STYLE_LEGACY",
321+
default_symbol_visibility: "EXPORT_ALL",
322+
'(abc)': { d_e: 'deeply_nested_false' }
305323
})
306324

307325
test.same(rootEditionsOverriden.lookup("SomeOneOf").fieldsArray.find(x => x.name === 'b')._features, {
@@ -311,6 +329,8 @@ tape.test("feature resolution inheritance oneofs", function(test) {
311329
message_encoding: 'LENGTH_PREFIXED',
312330
repeated_field_encoding: 'PACKED',
313331
utf8_validation: 'VERIFY',
332+
enforce_naming_style: "STYLE_LEGACY",
333+
default_symbol_visibility: "EXPORT_ALL",
314334
'(abc)': { d_e: 'deeply_nested_false' }
315335
})
316336

@@ -338,6 +358,8 @@ tape.test("feature resolution inheritance file to extensions", function(test) {
338358
message_encoding: 'LENGTH_PREFIXED',
339359
repeated_field_encoding: 'PACKED',
340360
utf8_validation: 'NONE',
361+
enforce_naming_style: "STYLE_LEGACY",
362+
default_symbol_visibility: "EXPORT_ALL",
341363
'(abc)': { d_e: 'deeply_nested_false' }
342364
})
343365

@@ -365,6 +387,8 @@ tape.test("feature resolution inheritance message to extensions", function(test)
365387
message_encoding: 'LENGTH_PREFIXED',
366388
repeated_field_encoding: 'PACKED',
367389
utf8_validation: 'NONE',
390+
enforce_naming_style: "STYLE_LEGACY",
391+
default_symbol_visibility: "EXPORT_ALL",
368392
'(abc)': { d_e: 'deeply_nested_false' }
369393
})
370394

@@ -391,6 +415,8 @@ tape.test("feature resolution inheritance message to enum", function(test) {
391415
message_encoding: 'LENGTH_PREFIXED',
392416
repeated_field_encoding: 'PACKED',
393417
utf8_validation: 'NONE',
418+
enforce_naming_style: "STYLE_LEGACY",
419+
default_symbol_visibility: "EXPORT_ALL",
394420
'(abc)': { d_e: 'deeply_nested_false' }
395421
})
396422

@@ -401,6 +427,8 @@ tape.test("feature resolution inheritance message to enum", function(test) {
401427
message_encoding: 'LENGTH_PREFIXED',
402428
repeated_field_encoding: 'PACKED',
403429
utf8_validation: 'NONE',
430+
enforce_naming_style: "STYLE_LEGACY",
431+
default_symbol_visibility: "EXPORT_ALL",
404432
'(abc)': { d_e: 'deeply_nested_false' }
405433
})
406434

@@ -425,6 +453,8 @@ tape.test("feature resolution inheritance file to enum", function(test) {
425453
message_encoding: 'LENGTH_PREFIXED',
426454
repeated_field_encoding: 'PACKED',
427455
utf8_validation: 'NONE',
456+
enforce_naming_style: "STYLE_LEGACY",
457+
default_symbol_visibility: "EXPORT_ALL",
428458
'(abc)': { d_e: 'deeply_nested_false' }
429459
})
430460

@@ -451,6 +481,8 @@ tape.test("feature resolution inheritance file to service and service to method"
451481
message_encoding: 'LENGTH_PREFIXED',
452482
repeated_field_encoding: 'PACKED',
453483
utf8_validation: 'VERIFY',
484+
enforce_naming_style: "STYLE_LEGACY",
485+
default_symbol_visibility: "EXPORT_ALL",
454486
'(abc)': { d_e: 'deeply_nested_false' }
455487
})
456488

@@ -461,6 +493,8 @@ tape.test("feature resolution inheritance file to service and service to method"
461493
message_encoding: 'LENGTH_PREFIXED',
462494
repeated_field_encoding: 'PACKED',
463495
utf8_validation: 'NONE',
496+
enforce_naming_style: "STYLE_LEGACY",
497+
default_symbol_visibility: "EXPORT_ALL",
464498
'(abc)': { d_e: 'deeply_nested_false' }
465499
})
466500

@@ -480,6 +514,8 @@ tape.test("feature resolution editions precedence", function(test) {
480514
message_encoding: 'LENGTH_PREFIXED',
481515
repeated_field_encoding: 'PACKED',
482516
utf8_validation: 'VERIFY',
517+
enforce_naming_style: "STYLE_LEGACY",
518+
default_symbol_visibility: "EXPORT_ALL",
483519
amazing_feature: 'G'
484520
})
485521
test.end();

0 commit comments

Comments
 (0)