@@ -13,24 +13,27 @@ export interface CompiledContext {
1313}
1414
1515export 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