Skip to content
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

support for generating es6 imports and .d.ts files #1

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

lukfugl
Copy link
Member

@lukfugl lukfugl commented Dec 9, 2024

Builds on protocolbuffers#150, adding:

  • support for library option with ES6
  • .d.ts generation when requested (generate_dts flag) and compatible (library option set and import_style set to es6)

Tested compilation of Derivita's omaha/base/ast.proto and inspecting the generated omaha/base/ast_proto.js and omaha/base/ast_proto.d.ts files.

@lukfugl lukfugl requested a review from ribrdb December 9, 2024 18:26
Copy link

@ribrdb ribrdb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you temporarily add the output of running this on test.proto so I can see the output?

@@ -0,0 +1,1013 @@
declare namespace proto.jspb.test {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't want namespaces in the es6 output. I think we can just remove this and unindent the contents.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed. For nested messages and enums, I still use export namespace Foo { class Bar ... } to represent Foo.Bar, which as I understand it should merge with the sibling export class Foo { }.

@@ -0,0 +1,1013 @@
declare namespace proto.jspb.test {
export class Empty extends jspb.Message {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to import dependencies.

declare namespace proto.jspb.test {
export class Empty extends jspb.Message {
constructor(data?: any[] | null);
toObject(includeInstance?: boolean): GlobalObject;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GlobalObject is a clutz specific hack for aliasing that we shouldn't need with es6.
Although I wonder if we need to do anything special if we're importing a message named Object. I guess if we use import * that won't be an issue.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replaced with { [key: string]: unknown } in return values. Currently also that for arguments, though as I type this I'm realizing in arguments it probably needs to be any for the values.

// @ts-nocheck

import * as jspb from 'google-protobuf';
var goog = jspb;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This probably wiill need to be something like import { goog } from 'closure-library/goog.js.
But that may be fine to figure out later.

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.

3 participants