Skip to content
Closed
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
1 change: 1 addition & 0 deletions packages/protobuf-example/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"compilerOptions": {
"target": "es2016",
"strict": true,
"exactOptionalPropertyTypes": true,
"moduleResolution": "Node"
}
}
15 changes: 9 additions & 6 deletions packages/protobuf/src/create-descriptor-set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,10 @@ function addEnum(
cart: Cart
): void {
assert(proto.name, `invalid EnumDescriptorProto: missing name`);
const sharedPrefix = findEnumSharedPrefix(
proto.name,
proto.value.map((v) => v.name ?? "")
);
const desc: DescEnum = {
kind: "enum",
proto,
Expand All @@ -222,10 +226,7 @@ function addEnum(
name: proto.name,
typeName: makeTypeName(proto, parent, file),
values: [],
sharedPrefix: findEnumSharedPrefix(
proto.name,
proto.value.map((v) => v.name ?? "")
),
...(sharedPrefix !== undefined ? { sharedPrefix } : {}),
toString(): string {
return `enum ${this.typeName}`;
},
Expand Down Expand Up @@ -867,10 +868,12 @@ function findComments(
if (location.path.some((value, index) => sourcePath[index] !== value)) {
continue;
}
const leading = location.leadingComments;
const trailing = location.trailingComments;
return {
leadingDetached: location.leadingDetachedComments,
leading: location.leadingComments,
trailing: location.trailingComments,
...(leading !== undefined ? { leading } : {}),
...(trailing !== undefined ? { trailing } : {}),
sourcePath,
};
}
Expand Down
14 changes: 9 additions & 5 deletions packages/protobuf/src/create-registry-from-desc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ export function createRegistryFromDescriptors(
idempotency: method.idempotency,
// We do not surface options at this time
// options: {},
};
} as MethodInfo;
}
return (services[typeName] = {
typeName: desc.typeName,
Expand Down Expand Up @@ -232,11 +232,12 @@ function makeMapFieldInfo(
field: DescField & { fieldKind: "map" },
resolver: Resolver
): PartialFieldInfo {
const jsonName = field.jsonName;
const base = {
kind: "map",
no: field.number,
name: field.name,
jsonName: field.jsonName,
...(jsonName !== undefined ? { jsonName } : {}),
K: field.mapKey,
} as const;
if (field.mapValue.message) {
Expand Down Expand Up @@ -281,11 +282,12 @@ function makeMapFieldInfo(
function makeScalarFieldInfo(
field: DescField & { fieldKind: "scalar" }
): PartialFieldInfo {
const jsonName = field.jsonName;
const base = {
kind: "scalar",
no: field.number,
name: field.name,
jsonName: field.jsonName,
...(jsonName !== undefined ? { jsonName } : {}),
T: field.scalar,
} as const;
if (field.repeated) {
Expand Down Expand Up @@ -321,11 +323,12 @@ function makeMessageFieldInfo(
messageType,
`message "${field.message.typeName}" for ${field.toString()} not found`
);
const jsonName = field.jsonName;
const base = {
kind: "message",
no: field.number,
name: field.name,
jsonName: field.jsonName,
...(jsonName !== undefined ? { jsonName } : {}),
T: messageType,
} as const;
if (field.repeated) {
Expand Down Expand Up @@ -360,11 +363,12 @@ function makeEnumFieldInfo(
enumType,
`enum "${field.enum.typeName}" for ${field.toString()} not found`
);
const jsonName = field.jsonName;
const base = {
kind: "enum",
no: field.number,
name: field.name,
jsonName: field.jsonName,
...(jsonName !== undefined ? { jsonName } : {}),
T: enumType,
} as const;
if (field.repeated) {
Expand Down
2 changes: 1 addition & 1 deletion packages/protobuf/src/descriptor-set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ export interface DescMethod {
/**
* The idempotency level declared in the protobuf source, if any.
*/
readonly idempotency?: MethodIdempotency;
readonly idempotency?: MethodIdempotency | undefined;
/**
* Marked as deprecated in the protobuf source.
*/
Expand Down
2 changes: 1 addition & 1 deletion packages/protobuf/src/service-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ interface miShared<
readonly name: string;
readonly I: MessageType<I>;
readonly O: MessageType<O>;
readonly idempotency?: MethodIdempotency;
readonly idempotency?: MethodIdempotency | undefined;
// We do not surface options at this time
// options: OptionsMap;
}
Expand Down
6 changes: 1 addition & 5 deletions packages/protoplugin-test/src/transpile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function transpile(
name: "test-plugin",
version: "v99.0.0",
generateTs: genTs,
parseOption,
...(parseOption !== undefined ? { parseOption } : {}),
});
const res = plugin.run(req);
return function linesOf(filename: string): string[] {
Expand Down Expand Up @@ -124,16 +124,12 @@ describe("transpile", function () {
return {
leadingDetached: [],
sourcePath: [],
leading: undefined,
trailing: undefined,
};
},
getSyntaxComments() {
return {
leadingDetached: [],
sourcePath: [],
leading: undefined,
trailing: undefined,
};
},
};
Expand Down
4 changes: 2 additions & 2 deletions packages/protoplugin/src/ecmascript/generated-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ function buildPrintablesFromFragments(
type MakeImportStatementFn = (
typeOnly: boolean,
from: string,
names: { name: string; alias?: string }[]
names: { name: string; alias?: string | undefined }[]
) => void;

function processImports(
Expand Down Expand Up @@ -374,7 +374,7 @@ function processImports(
// Make import statements.
const handledSource = new Set<string>();
const buildNames = (map: Map<string, string | undefined>) => {
const names: { name: string; alias?: string }[] = [];
const names: { name: string; alias: string | undefined }[] = [];
map.forEach((value, key) => names.push({ name: key, alias: value }));
names.sort((a, b) => a.name.localeCompare(b.name));
return names;
Expand Down
3 changes: 2 additions & 1 deletion packages/protoplugin/src/ecmascript/transpile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,9 @@ const defaultOptions: ts.CompilerOptions = {
* npm does not support that yet.
*/
function createTranspiler(options: ts.CompilerOptions, files: FileInfo[]) {
const { target } = options;
const fsMap = createDefaultMapFromNodeModules({
target: options.target,
...(target !== undefined ? { target } : {}),
});

files.forEach((file) => {
Expand Down
1 change: 1 addition & 0 deletions tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"strictFunctionTypes": true,
"strictBindCallApply": true,
"strictPropertyInitialization": true,
"exactOptionalPropertyTypes": true,
"noImplicitThis": true,
"useUnknownInCatchVariables": true,
"noUnusedLocals": true,
Expand Down