fix: string literal object keys
This commit is contained in:
parent
40d85508b3
commit
d257c285e8
|
@ -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;
|
||||
|
|
|
@ -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 () => {
|
||||
|
|
Loading…
Reference in New Issue
Block a user