Skip to content

Commit 3f677f0

Browse files
committed
move contextDefinitions in ContextEvaluator to Map<string, CompiledContext>
1 parent e183550 commit 3f677f0

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

packages/cubejs-schema-compiler/src/compiler/ContextEvaluator.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,27 @@ export interface CompiledContext {
1313
}
1414

1515
export class ContextEvaluator implements CompilerInterface {
16-
private cubeEvaluator: CubeEvaluator;
16+
private readonly cubeEvaluator: CubeEvaluator;
1717

18-
private contextDefinitions: Record<string, CompiledContext>;
18+
private contextDefinitions: Map<string, CompiledContext>;
1919

2020
public constructor(cubeEvaluator: CubeEvaluator) {
2121
this.cubeEvaluator = cubeEvaluator;
22-
this.contextDefinitions = {};
22+
this.contextDefinitions = new Map<string, CompiledContext>();
2323
}
2424

25-
public compile(contexts: ContextInput[], _errorReporter?: ErrorReporter): void {
25+
public compile(contexts: ContextInput[], errorReporter?: ErrorReporter): void {
2626
if (contexts.length === 0) {
2727
return;
2828
}
2929

30-
// TODO: handle duplications, context names must be uniq
31-
this.contextDefinitions = {};
30+
this.contextDefinitions = new Map<string, CompiledContext>();
3231
for (const context of contexts) {
33-
this.contextDefinitions[context.name] = this.compileContext(context);
32+
if (errorReporter && this.contextDefinitions.has(context.name)) {
33+
errorReporter.error(`Context "${context.name}" already exists!`);
34+
} else {
35+
this.contextDefinitions.set(context.name, this.compileContext(context));
36+
}
3437
}
3538
}
3639

@@ -42,6 +45,6 @@ export class ContextEvaluator implements CompilerInterface {
4245
}
4346

4447
public get contextList(): string[] {
45-
return Object.keys(this.contextDefinitions);
48+
return Array.from(this.contextDefinitions.keys());
4649
}
4750
}

0 commit comments

Comments
 (0)