Skip to content

feat(parse): enforce edition 2024 local visibility across files - #2401

Open
morgan-coded wants to merge 1 commit into
protobufjs:masterfrom
morgan-coded:edition2024-visibility-2400
Open

feat(parse): enforce edition 2024 local visibility across files#2401
morgan-coded wants to merge 1 commit into
protobufjs:masterfrom
morgan-coded:edition2024-visibility-2400

Conversation

@morgan-coded

@morgan-coded morgan-coded commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

Closes #2400.

Rebased onto master and reduced: #2415 landed the parsing and preservation half, so this is now only the resolution check, 21 lines in src/field.js plus tests.

After a successful lookup, Field#resolve rejects a resolved type or enum that is local to a different file:

'.a.Hidden' is local to 'a.proto' and cannot be referenced from 'c.proto'

If either side has no filename, which covers programmatic construction, fromJSON, and bundled common types, the reference cannot be proven to cross files and is allowed.

Tests sit in tests/parse_editions.js beside the existing export/local parsing cases: same-file references still resolve, cross-file local throws, export and unmodified symbols are unaffected, and pre-2024 editions plus proto2/proto3 behave exactly as before. That file goes 29 to 39 tests; the full suite 3201 to 3211, all green, with lint and type checks clean.

Two things left out on purpose, in case you would rather they were in:

  • Service RPC request and response types are not covered. Method#resolve resolves them through lookupType and methods do carry a filename, so the same check would be live there. Sharing it across modules felt like a bigger structural decision than this change should make on its own; it is about 10 lines if you want it here.
  • tryHandleExtension in root.js is deliberately untouched. It is a boolean try inside the deferred-retry loop, so throwing there would break deferred extensions and make errors depend on file load order. Extension fields are still checked through the sister field's own resolve.

The earlier note about visibility not surviving toJSON / fromJSON no longer applies, since #2415 carries it through the descriptor surface.

Symbol visibility is parsed and preserved since protobufjs#2415, but nothing rejects a
reference to a local symbol from another file. Field#resolve now checks the
resolved type or enum and throws when it is local to a different file.

References without a known file name on either side (programmatic construction,
fromJSON, bundled common types) cannot be proven to cross files and are allowed.

Refs protobufjs#2400
@morgan-coded
morgan-coded force-pushed the edition2024-visibility-2400 branch from e2452d2 to 6cabb00 Compare August 27, 2026 02:31
@morgan-coded

Copy link
Copy Markdown
Contributor Author

Rebased this onto master and it shrank a lot. #2415 landed the parsing and preservation since I opened this, so the parse.js half is gone and what's left is just the resolution check: 21 lines in src/field.js plus tests.

Field#resolve throws when a resolved type or enum is local to a different file, and stays quiet when either side has no filename (programmatic construction, fromJSON, bundled types). Suite goes 3201 to 3211, lint and type checks clean. Updated the description with the details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Edition 2024 export/local visibility parses but is not enforced during cross-file resolution

1 participant