diff --git a/packages/sandbox/src/sandbox.js b/packages/sandbox/src/sandbox.js index a162321..0b6c452 100644 --- a/packages/sandbox/src/sandbox.js +++ b/packages/sandbox/src/sandbox.js @@ -372,7 +372,21 @@ export default class Sandbox { for (let i = 0; i < properties.length; i++) { if (types.isObjectProperty(properties[i])) { const {computed, key, value} = properties[i]; - const k = computed ? this.evaluate(key) : {value: key.name}; + let k; + if (computed) { + k = this.evaluate(key); + } + else if (types.isIdentifier(key)) { + k = {value: key.name}; + } + else if (types.isStringLiteral(key)) { + k = {value: key.value}; + } + else { + // eslint-disable-next-line no-console + console.error("evaluateObjectExpression(): Can't handle key type", key.type); + k = {value: undefined}; + } const v = this.evaluate(value); // eslint-disable-next-line no-bitwise isAsync |= k.async | v.async; diff --git a/packages/sandbox/test/object-expression.js b/packages/sandbox/test/object-expression.js index 0e4e212..8f4533a 100644 --- a/packages/sandbox/test/object-expression.js +++ b/packages/sandbox/test/object-expression.js @@ -18,6 +18,8 @@ it('evaluates async ObjectExpression', async () => { it('evaluates ObjectExpression', () => { expect(new Sandbox(parse('({a: 1, b: 2})')).next().value) .to.deep.include({value: {a: 1, b: 2}}); + expect(new Sandbox(parse('({"a": 1, "b": 2})')).next().value) + .to.deep.include({value: {a: 1, b: 2}}); }); it('evaluates async SpreadElement', async () => {