Skip to content

Commit f59e0ad

Browse files
aang521SnosMe
andauthored
fix duplicate in export when games have a different type(table/enum) for the same dat name (#222)
* Fix types being exported for poe as enum and object when the poe2 override is a type but the poe1 version is an enum * cleanup --------- Co-authored-by: Alexander Drozdov <snosme@gmail.com>
1 parent 9cd1088 commit f59e0ad

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

src/reader.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ class VersionedTypedefNode<T> implements Iterable<[ValidFor, T]> {
215215
constructor(
216216
public vBase: T | undefined,
217217
public vOverride: T | undefined,
218-
readonly allowSharing: boolean
218+
public allowSharing: boolean
219219
) {}
220220

221221
*[Symbol.iterator](): Iterator<[ValidFor, T]> {
@@ -239,13 +239,14 @@ class VersionedTypedefMap<T extends TypeDefinitionNode> {
239239

240240
constructor(readonly allowSharing: boolean) {}
241241

242-
add(typeNode: T, override: boolean): boolean {
242+
add(typeNode: T, override: boolean, otherMap: VersionedTypedefMap<any>): boolean {
243243
const existingNode = this.data.get(typeNode.name.value);
244+
const nodeInOtherMap = otherMap.data.get(typeNode.name.value);
244245
if (!existingNode) {
245246
this.data.set(typeNode.name.value, new VersionedTypedefNode(
246247
!override ? typeNode : undefined,
247248
override ? typeNode : undefined,
248-
this.allowSharing
249+
nodeInOtherMap != null ? false : this.allowSharing
249250
));
250251
} else if (override) {
251252
if (existingNode.vOverride != null) return false;
@@ -254,6 +255,10 @@ class VersionedTypedefMap<T extends TypeDefinitionNode> {
254255
if (existingNode.vBase != null) return false;
255256
existingNode.vBase = typeNode;
256257
}
258+
259+
if (nodeInOtherMap) {
260+
nodeInOtherMap.allowSharing = false;
261+
}
257262
return true;
258263
}
259264
}
@@ -313,14 +318,14 @@ export function readSchemaSources(
313318

314319
const override = source.name.startsWith('poe2');
315320
if (typeNode.kind === 'EnumTypeDefinition') {
316-
if (!enumDefsMap.add(typeNode, override)) {
321+
if (!enumDefsMap.add(typeNode, override, typeDefsMap)) {
317322
throw new GraphQLError(
318323
'Enum with this name has already been defined.',
319324
{ nodes: typeNode.name }
320325
);
321326
}
322327
} else if (typeNode.kind === 'ObjectTypeDefinition') {
323-
if (!typeDefsMap.add(typeNode, override)) {
328+
if (!typeDefsMap.add(typeNode, override, enumDefsMap)) {
324329
throw new GraphQLError(
325330
'Table with this name has already been defined.',
326331
{ nodes: typeNode.name }

0 commit comments

Comments
 (0)