import { toCamelCase } from '../utils/identifier' ; import { IVariableTable , IVariableValueDTO , IVariable } from './types' ; export default class VariableTable implements IVariableTable { public get ( variableName ) { return this . _table . get ( this . normalizeName ( variableName ) ) ; } /**
     * Add a variable into the variable table.
     * If the variable table already has the same variable, cover it with the new one.
     */ public add ( variable ) { this . _table . set ( this . normalizeName ( variable . name ) , variable ) ; } public delete ( variableName ) { this . _table . delete ( this . normalizeName ( variableName ) ) ; } public variables ( ) { return Array . from ( this . _table . values ( ) ) ; } public batchAssign ( variableValues ) { variableValues . forEach ( ( item ) => { const variable = this . get ( item . name ) ; if ( variable ) { variable . value = item . value ; } } ) ; } private normalizeName ( variableName ) { return toCamelCase ( variableName ) ; } private _table = new Map < string , IVariable > ( ) ; }