UNPKG

726 BJavaScriptView Raw
1"use strict";
2
3module.exports = function() {
4 let table = new Map();
5 let unusedKeys = new Set();
6
7 this.set = function(key, value) {
8 if (table.has(key)) {
9 throw new ReferenceError(`The variable ${key} has already been defined`);
10 }
11 table.set(key, value);
12 unusedKeys.add(key);
13 };
14 this.get = function(key) {
15 if (!table.has(key)) {
16 throw new ReferenceError(`The variable ${key} does not exist`);
17 }
18 unusedKeys.delete(key);
19 return table.get(key);
20 };
21 this.end = function() {
22 if (unusedKeys.size) {
23 throw new SyntaxError(`The variable "${Array.from(unusedKeys)[0]}" is not used`);
24 }
25 };
26};
\No newline at end of file