Skip to content

feat!: add Edition 2024 Support #2060

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file modified cli/bin/pbjs
100644 → 100755
Empty file.
Empty file modified cli/bin/pbts
100644 → 100755
Empty file.
9 changes: 6 additions & 3 deletions src/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ var Root; // cyclic

/* eslint-disable no-warning-comments */
// TODO: Replace with embedded proto.
var editions2023Defaults = {enum_type: "OPEN", field_presence: "EXPLICIT", json_format: "ALLOW", message_encoding: "LENGTH_PREFIXED", repeated_field_encoding: "PACKED", utf8_validation: "VERIFY"};
var proto2Defaults = {enum_type: "CLOSED", field_presence: "EXPLICIT", json_format: "LEGACY_BEST_EFFORT", message_encoding: "LENGTH_PREFIXED", repeated_field_encoding: "EXPANDED", utf8_validation: "NONE"};
var proto3Defaults = {enum_type: "OPEN", field_presence: "IMPLICIT", json_format: "ALLOW", message_encoding: "LENGTH_PREFIXED", repeated_field_encoding: "PACKED", utf8_validation: "VERIFY"};
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" };
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" };
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" };
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" };

/**
* Constructs a new reflection object instance.
Expand Down Expand Up @@ -213,6 +214,8 @@ ReflectionObject.prototype._resolveFeatures = function _resolveFeatures(edition)
defaults = Object.assign({}, proto3Defaults);
} else if (edition === "2023") {
defaults = Object.assign({}, editions2023Defaults);
} else if (edition === "2024") {
defaults = Object.assign({}, editions2024Defaults);
} else {
throw new Error("Unknown edition: " + edition);
}
Expand Down
45 changes: 44 additions & 1 deletion src/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,16 @@
var token = peek();
var whichImports;
switch (token) {
case "option":
if (edition < "2024") {
throw illegal("option");
}
// Import options are only used for resolving options, which we don't
// do. We can just throw them out.
next();
readString();
skip(";");
return;
case "weak":
whichImports = weakImports || (weakImports = []);
next();
Expand Down Expand Up @@ -291,7 +301,7 @@
function parseEdition() {
skip("=");
edition = readString();
const supportedEditions = ["2023"];
const supportedEditions = ["2023", "2024"];

/* istanbul ignore if */
if (!supportedEditions.includes(edition))
Expand All @@ -317,6 +327,21 @@
parseEnum(parent, token);
return true;

case "export":
case "local":
if (edition < "2024") {
return false;
}
token = next();
if (token === "export" || token === "local") {
return false;
}
if (token !== "message" && token !== "enum") {
return false;
}
// TODO: actually enforce visiblity modifiers like protoc does.

Check warning on line 342 in src/parse.js

View workflow job for this annotation

GitHub Actions / lint

Unexpected 'todo' comment: 'TODO: actually enforce visiblity...'

Check warning on line 342 in src/parse.js

View workflow job for this annotation

GitHub Actions / lint

Unexpected 'todo' comment: 'TODO: actually enforce visiblity...'
return parseCommon(parent, token);

case "service":
parseService(parent, token);
return true;
Expand Down Expand Up @@ -523,6 +548,24 @@
parseEnum(type, token);
break;

case "export":
case "local":
if (edition < "2024") {
throw illegal(token);
}
token = next();
switch (token) {
case "message":
parseType(type, token);
break;
case "enum":
parseType(type, token);
break;
default:
throw illegal(token);
}
break;

/* istanbul ignore next */
default:
throw illegal(token); // there are no groups with proto3 semantics
Expand Down
9 changes: 9 additions & 0 deletions tests/data/import-option-bad.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
edition = "2024";

import option "nonexistent.proto";

option features.(pb.nonexistent).foo = BAR;

message Foo {
string legacy = 1;
}
50 changes: 43 additions & 7 deletions tests/feature_resolution_editions.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,20 +66,22 @@ var tape = require("tape");

var protobuf = require("..");

var protoEditions2024 = `edition = "2024"; message Foo {}`;
var protoEditions2023 = `edition = "2023"; message Foo {}`;

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

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

var editions2023Defaults = {enum_type: 'OPEN', field_presence: 'EXPLICIT', json_format: 'ALLOW', message_encoding: 'LENGTH_PREFIXED', repeated_field_encoding: 'PACKED', utf8_validation: 'VERIFY'}
var proto2Defaults = {enum_type: 'CLOSED', field_presence: 'EXPLICIT', json_format: 'LEGACY_BEST_EFFORT', message_encoding: 'LENGTH_PREFIXED', repeated_field_encoding: 'EXPANDED', utf8_validation: 'NONE'}
var proto3Defaults = {enum_type: 'OPEN', field_presence: 'IMPLICIT', json_format: 'ALLOW', message_encoding: 'LENGTH_PREFIXED', repeated_field_encoding: 'PACKED', utf8_validation: 'VERIFY'}
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" };
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" };
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" };
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" };

tape.test("feature resolution defaults", function(test) {
var rootEditions = protobuf.parse(protoEditions2023).root;
var rootEditions = protobuf.parse(protoEditions2024).root;
rootEditions.resolveAll();
test.same(rootEditions.Foo._features, editions2023Defaults);
test.same(rootEditions.Foo._features, editions2024Defaults);

var rootProto2 = protobuf.parse(proto2).root;
rootProto2.resolveAll();
Expand Down Expand Up @@ -136,6 +138,8 @@ tape.test("aggregate feature parsing", function(test) {
message_encoding: 'LENGTH_PREFIXED',
repeated_field_encoding: 'PACKED',
utf8_validation: 'NONE',
enforce_naming_style: "STYLE_LEGACY",
default_symbol_visibility: "EXPORT_ALL"
})

test.end();
Expand All @@ -160,6 +164,8 @@ tape.test("feature resolution inheritance file to message", function(test) {
message_encoding: 'LENGTH_PREFIXED',
repeated_field_encoding: 'PACKED',
utf8_validation: 'VERIFY',
enforce_naming_style: "STYLE_LEGACY",
default_symbol_visibility: "EXPORT_ALL",
'(abc)': { d_e: 'deeply_nested_false' }
})

Expand All @@ -185,6 +191,8 @@ tape.test("feature resolution inheritance message to field", function(test) {
message_encoding: 'LENGTH_PREFIXED',
repeated_field_encoding: 'PACKED',
utf8_validation: 'VERIFY',
enforce_naming_style: "STYLE_LEGACY",
default_symbol_visibility: "EXPORT_ALL",
'(abc)': { d_e: 'deeply_nested_false' }
})

Expand Down Expand Up @@ -213,6 +221,8 @@ tape.test("feature resolution inheritance message to nested message", function(t
message_encoding: 'LENGTH_PREFIXED',
repeated_field_encoding: 'PACKED',
utf8_validation: 'VERIFY',
enforce_naming_style: "STYLE_LEGACY",
default_symbol_visibility: "EXPORT_ALL",
'(abc)': { d_e: 'deeply_nested_true' }
});
test.end();
Expand All @@ -238,6 +248,8 @@ tape.test("feature resolution inheritance enum to enum value", function(test) {
message_encoding: 'LENGTH_PREFIXED',
repeated_field_encoding: 'EXPANDED',
utf8_validation: 'VERIFY',
enforce_naming_style: "STYLE_LEGACY",
default_symbol_visibility: "EXPORT_ALL",
'(abc)': { d_e: 'deeply_nested_false' }
})

Expand All @@ -248,7 +260,9 @@ tape.test("feature resolution inheritance enum to enum value", function(test) {
message_encoding: 'LENGTH_PREFIXED',
repeated_field_encoding: 'PACKED',
utf8_validation: 'VERIFY',
'(abc)': { d_e: 'deeply_nested_false' }
enforce_naming_style: "STYLE_LEGACY",
default_symbol_visibility: "EXPORT_ALL",
'(abc)': { d_e: 'deeply_nested_false' }
});

test.end();
Expand All @@ -274,6 +288,8 @@ tape.test("feature resolution inheritance message to oneofs", function(test) {
message_encoding: 'LENGTH_PREFIXED',
repeated_field_encoding: 'PACKED',
utf8_validation: 'VERIFY',
enforce_naming_style: "STYLE_LEGACY",
default_symbol_visibility: "EXPORT_ALL",
'(abc)': { d_e: 'deeply_nested_false' }
})

Expand Down Expand Up @@ -301,7 +317,9 @@ tape.test("feature resolution inheritance oneofs", function(test) {
message_encoding: 'LENGTH_PREFIXED',
repeated_field_encoding: 'PACKED',
utf8_validation: 'VERIFY',
'(abc)': { d_e: 'deeply_nested_false' }
enforce_naming_style: "STYLE_LEGACY",
default_symbol_visibility: "EXPORT_ALL",
'(abc)': { d_e: 'deeply_nested_false' }
})

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

Expand Down Expand Up @@ -338,6 +358,8 @@ tape.test("feature resolution inheritance file to extensions", function(test) {
message_encoding: 'LENGTH_PREFIXED',
repeated_field_encoding: 'PACKED',
utf8_validation: 'NONE',
enforce_naming_style: "STYLE_LEGACY",
default_symbol_visibility: "EXPORT_ALL",
'(abc)': { d_e: 'deeply_nested_false' }
})

Expand Down Expand Up @@ -365,6 +387,8 @@ tape.test("feature resolution inheritance message to extensions", function(test)
message_encoding: 'LENGTH_PREFIXED',
repeated_field_encoding: 'PACKED',
utf8_validation: 'NONE',
enforce_naming_style: "STYLE_LEGACY",
default_symbol_visibility: "EXPORT_ALL",
'(abc)': { d_e: 'deeply_nested_false' }
})

Expand All @@ -391,6 +415,8 @@ tape.test("feature resolution inheritance message to enum", function(test) {
message_encoding: 'LENGTH_PREFIXED',
repeated_field_encoding: 'PACKED',
utf8_validation: 'NONE',
enforce_naming_style: "STYLE_LEGACY",
default_symbol_visibility: "EXPORT_ALL",
'(abc)': { d_e: 'deeply_nested_false' }
})

Expand All @@ -401,6 +427,8 @@ tape.test("feature resolution inheritance message to enum", function(test) {
message_encoding: 'LENGTH_PREFIXED',
repeated_field_encoding: 'PACKED',
utf8_validation: 'NONE',
enforce_naming_style: "STYLE_LEGACY",
default_symbol_visibility: "EXPORT_ALL",
'(abc)': { d_e: 'deeply_nested_false' }
})

Expand All @@ -425,6 +453,8 @@ tape.test("feature resolution inheritance file to enum", function(test) {
message_encoding: 'LENGTH_PREFIXED',
repeated_field_encoding: 'PACKED',
utf8_validation: 'NONE',
enforce_naming_style: "STYLE_LEGACY",
default_symbol_visibility: "EXPORT_ALL",
'(abc)': { d_e: 'deeply_nested_false' }
})

Expand All @@ -451,6 +481,8 @@ tape.test("feature resolution inheritance file to service and service to method"
message_encoding: 'LENGTH_PREFIXED',
repeated_field_encoding: 'PACKED',
utf8_validation: 'VERIFY',
enforce_naming_style: "STYLE_LEGACY",
default_symbol_visibility: "EXPORT_ALL",
'(abc)': { d_e: 'deeply_nested_false' }
})

Expand All @@ -461,6 +493,8 @@ tape.test("feature resolution inheritance file to service and service to method"
message_encoding: 'LENGTH_PREFIXED',
repeated_field_encoding: 'PACKED',
utf8_validation: 'NONE',
enforce_naming_style: "STYLE_LEGACY",
default_symbol_visibility: "EXPORT_ALL",
'(abc)': { d_e: 'deeply_nested_false' }
})

Expand All @@ -480,6 +514,8 @@ tape.test("feature resolution editions precedence", function(test) {
message_encoding: 'LENGTH_PREFIXED',
repeated_field_encoding: 'PACKED',
utf8_validation: 'VERIFY',
enforce_naming_style: "STYLE_LEGACY",
default_symbol_visibility: "EXPORT_ALL",
amazing_feature: 'G'
})
test.end();
Expand Down
Loading
Loading