fix: string literal object keys

This commit is contained in:
cha0s 2021-04-20 06:47:28 -05:00
parent 40d85508b3
commit d257c285e8
2 changed files with 17 additions and 1 deletions

View File

@ -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;

View File

@ -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 () => {