Skip to content

Commit

Permalink
Deprecate properties toString and text of JSDocBlock
Browse files Browse the repository at this point in the history
Currently, the method `GeneratedFile.jsDoc` returns a `JSDocBlock` that leaks implementation details through the properties "toString" and "text".

This PR marks the properties as deprecated, so that we can remove them in the future. This will allow us to accept JSDoc blocks as object literals in `GeneratedFile.print`, in line with similar objects.
  • Loading branch information
timostamm committed Feb 19, 2024
1 parent 0f32996 commit 0255fc1
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
7 changes: 5 additions & 2 deletions packages/protoplugin/src/ecmascript/generated-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import { makeImportPathRelative } from "./import-path.js";
import type { JSDocBlock } from "./jsdoc.js";
import { createJsDocBlock } from "./jsdoc.js";
import {
createExportDeclaration,
ExportDeclaration,
LiteralProtoInt64,
LiteralString,
Expand Down Expand Up @@ -227,7 +226,11 @@ export function createGeneratedFile(
return createImportSymbol(name, importPath);
},
exportDecl(declaration, name) {
return createExportDeclaration(declaration, name);
return {
kind: "es_export_decl",
declaration,
name,
};
},
string(string) {
// We do not use LiteralString, which was added later, to maintain backwards compatibility
Expand Down
7 changes: 7 additions & 0 deletions packages/protoplugin/src/ecmascript/jsdoc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,18 @@ import type { AnyDesc, DescFile } from "@bufbuild/protobuf";

export type JSDocBlock = {
readonly kind: "es_jsdoc";
/**
* @deprecated In a future release, we will make this property optional.
*/
text: string;
indentation?: string;
/**
* @deprecated In a future release, we will remove this method.
*/
toString(): string;
};

// TODO simplify type JSDocBlock to bring it in line with others in opaque-printables.ts
export function createJsDocBlock(
textOrDesc: string | Exclude<AnyDesc, DescFile>,
indentation?: string,
Expand Down
11 changes: 0 additions & 11 deletions packages/protoplugin/src/ecmascript/opaque-printables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,3 @@ export type ExportDeclaration = {
declaration: string;
name: string | DescMessage | DescEnum | DescExtension;
};

export function createExportDeclaration(
declaration: string,
name: ExportDeclaration["name"],
): ExportDeclaration {
return {
kind: "es_export_decl",
declaration,
name,
};
}

0 comments on commit 0255fc1

Please sign in to comment.