diff --git a/src/IonSharedSymbolTable.ts b/src/IonSharedSymbolTable.ts index 02ac4c9c..dfef857b 100644 --- a/src/IonSharedSymbolTable.ts +++ b/src/IonSharedSymbolTable.ts @@ -30,7 +30,7 @@ export class SharedSymbolTable { // Iterate through the symbol array in reverse order so if the same string appears more than // once the smaller symbol ID is stored. for (let m = _symbols.length - 1; m >= 0; m--) { - this._idsByText[_symbols[m]] = m; + this._idsByText.set(_symbols[m], m); } } @@ -61,6 +61,6 @@ export class SharedSymbolTable { } getSymbolId(text: string): number | undefined { - return this._idsByText[text]; + return this._idsByText.get(text); } } diff --git a/test/IonLocalSymbolTable.ts b/test/IonLocalSymbolTable.ts index 05b76402..d59c9d25 100644 --- a/test/IonLocalSymbolTable.ts +++ b/test/IonLocalSymbolTable.ts @@ -140,4 +140,16 @@ describe('Local symbol table', () => { assert.equal(originalId, duplicateId, "Duplicate symbol was not given original id"); assert.equal(originalLength + 1, symbolTable.symbols.length, "Duplicate symbol added to symbol table"); }); -}); \ No newline at end of file + + // See https://github.com/amzn/ion-js/issues/645 + it('SST Object properties are not treated as symbols (Issue #645)', () => { + const symbolTable = defaultLocalSymbolTable(); + symbolTable.addSymbol("foo"); + assert.equal(symbolTable.getSymbolId("foo"), 10); + + // 'size' has not been added to the symbol table. + // It is, however, a property (an accessor) on the 'Map' data type. + // Asking for its symbol ID should return undefined. + assert.isUndefined(symbolTable.getSymbolId("size")); + }); +});