-
Notifications
You must be signed in to change notification settings - Fork 349
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: import fails when folder name overlaps with file name (#1000)
* reproduce error * correct the output using linked version of ts-poet * update to latest version of ts-poet * running bin2ts with latest ts-poet removes braces
- Loading branch information
1 parent
14f4635
commit 1e68e6f
Showing
18 changed files
with
432 additions
and
26 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
syntax = "proto3"; | ||
package simple2; | ||
|
||
enum SimpleEnum { | ||
IMPORT_DEFAULT = 0; | ||
IMPORT_FOO = 10; | ||
IMPORT_BAR = 11; | ||
} | ||
|
||
message Simple { | ||
string simple2Name = 1; | ||
int32 simple2Age = 2; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
/* eslint-disable */ | ||
import * as _m0 from "protobufjs/minimal"; | ||
|
||
export const protobufPackage = "simple2"; | ||
|
||
export enum SimpleEnum { | ||
IMPORT_DEFAULT = 0, | ||
IMPORT_FOO = 10, | ||
IMPORT_BAR = 11, | ||
UNRECOGNIZED = -1, | ||
} | ||
|
||
export function simpleEnumFromJSON(object: any): SimpleEnum { | ||
switch (object) { | ||
case 0: | ||
case "IMPORT_DEFAULT": | ||
return SimpleEnum.IMPORT_DEFAULT; | ||
case 10: | ||
case "IMPORT_FOO": | ||
return SimpleEnum.IMPORT_FOO; | ||
case 11: | ||
case "IMPORT_BAR": | ||
return SimpleEnum.IMPORT_BAR; | ||
case -1: | ||
case "UNRECOGNIZED": | ||
default: | ||
return SimpleEnum.UNRECOGNIZED; | ||
} | ||
} | ||
|
||
export function simpleEnumToJSON(object: SimpleEnum): string { | ||
switch (object) { | ||
case SimpleEnum.IMPORT_DEFAULT: | ||
return "IMPORT_DEFAULT"; | ||
case SimpleEnum.IMPORT_FOO: | ||
return "IMPORT_FOO"; | ||
case SimpleEnum.IMPORT_BAR: | ||
return "IMPORT_BAR"; | ||
case SimpleEnum.UNRECOGNIZED: | ||
default: | ||
return "UNRECOGNIZED"; | ||
} | ||
} | ||
|
||
export interface Simple { | ||
simple2Name: string; | ||
simple2Age: number; | ||
} | ||
|
||
function createBaseSimple(): Simple { | ||
return { simple2Name: "", simple2Age: 0 }; | ||
} | ||
|
||
export const Simple = { | ||
encode(message: Simple, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { | ||
if (message.simple2Name !== "") { | ||
writer.uint32(10).string(message.simple2Name); | ||
} | ||
if (message.simple2Age !== 0) { | ||
writer.uint32(16).int32(message.simple2Age); | ||
} | ||
return writer; | ||
}, | ||
|
||
decode(input: _m0.Reader | Uint8Array, length?: number): Simple { | ||
const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input); | ||
let end = length === undefined ? reader.len : reader.pos + length; | ||
const message = createBaseSimple(); | ||
while (reader.pos < end) { | ||
const tag = reader.uint32(); | ||
switch (tag >>> 3) { | ||
case 1: | ||
if (tag !== 10) { | ||
break; | ||
} | ||
|
||
message.simple2Name = reader.string(); | ||
continue; | ||
case 2: | ||
if (tag !== 16) { | ||
break; | ||
} | ||
|
||
message.simple2Age = reader.int32(); | ||
continue; | ||
} | ||
if ((tag & 7) === 4 || tag === 0) { | ||
break; | ||
} | ||
reader.skipType(tag & 7); | ||
} | ||
return message; | ||
}, | ||
|
||
fromJSON(object: any): Simple { | ||
return { | ||
simple2Name: isSet(object.simple2Name) ? globalThis.String(object.simple2Name) : "", | ||
simple2Age: isSet(object.simple2Age) ? globalThis.Number(object.simple2Age) : 0, | ||
}; | ||
}, | ||
|
||
toJSON(message: Simple): unknown { | ||
const obj: any = {}; | ||
if (message.simple2Name !== "") { | ||
obj.simple2Name = message.simple2Name; | ||
} | ||
if (message.simple2Age !== 0) { | ||
obj.simple2Age = Math.round(message.simple2Age); | ||
} | ||
return obj; | ||
}, | ||
|
||
create<I extends Exact<DeepPartial<Simple>, I>>(base?: I): Simple { | ||
return Simple.fromPartial(base ?? ({} as any)); | ||
}, | ||
fromPartial<I extends Exact<DeepPartial<Simple>, I>>(object: I): Simple { | ||
const message = createBaseSimple(); | ||
message.simple2Name = object.simple2Name ?? ""; | ||
message.simple2Age = object.simple2Age ?? 0; | ||
return message; | ||
}, | ||
}; | ||
|
||
type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined; | ||
|
||
export type DeepPartial<T> = T extends Builtin ? T | ||
: T extends globalThis.Array<infer U> ? globalThis.Array<DeepPartial<U>> | ||
: T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>> | ||
: T extends {} ? { [K in keyof T]?: DeepPartial<T[K]> } | ||
: Partial<T>; | ||
|
||
type KeysOfUnion<T> = T extends T ? keyof T : never; | ||
export type Exact<P, I extends P> = P extends Builtin ? P | ||
: P & { [K in keyof P]: Exact<P[K], I[K]> } & { [K in Exclude<keyof I, KeysOfUnion<P>>]: never }; | ||
|
||
function isSet(value: any): boolean { | ||
return value !== null && value !== undefined; | ||
} |
7 changes: 7 additions & 0 deletions
7
integration/avoid-import-conflicts-folder-name/ui/simple-test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { SimpleEnums } from "./simple"; | ||
|
||
describe("avoid-import-conflicts-folder-name", () => { | ||
it("compiles", () => { | ||
expect(SimpleEnums).not.toBeUndefined(); | ||
}); | ||
}); |
Binary file not shown.
22 changes: 22 additions & 0 deletions
22
integration/avoid-import-conflicts-folder-name/ui/simple.proto
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
syntax = "proto3"; | ||
package simple; | ||
|
||
import "ui.proto"; | ||
|
||
enum SimpleEnum { | ||
LOCAL_DEFAULT = 0; | ||
LOCAL_FOO = 1; | ||
LOCAL_BAR = 2; | ||
} | ||
|
||
message Simple { | ||
string name = 1; | ||
simple2.Simple otherSimple = 2; | ||
} | ||
|
||
message SimpleEnums { | ||
SimpleEnum local_enum = 1; | ||
simple2.SimpleEnum import_enum = 2; | ||
} | ||
|
||
|
Oops, something went wrong.