import {expect, test} from 'vitest'; import evaluate from '@/swcx/evaluate.js'; import expression from '@/swcx/test/expression.js'; const scopeTest = test.extend({ scope: async ({}, use) => { await use({ S: {O: {x: 32}}, get(k) { return this.S[k]; }, set(k, v) { return this.S[k] = v; } }); }, }); scopeTest('evaluates member expression', async ({scope}) => { let evaluated; evaluated = evaluate(await expression('O.x'), {scope}); expect(evaluated.value) .to.equal(32); }); scopeTest('evaluates optional member expression', async ({scope}) => { let evaluated; evaluated = evaluate(await expression('O?.y'), {scope}); expect(evaluated.value) .to.equal(undefined); }); scopeTest('evaluates computed member expression', async ({scope}) => { let evaluated; evaluated = evaluate(await expression('O["x"]'), {scope}); expect(evaluated.value) .to.equal(32); }); scopeTest('evaluates async member expression', async ({scope}) => { let evaluated; evaluated = evaluate(await expression('O[await "x"]'), {scope}); expect(evaluated.async) .to.equal(true); expect(await evaluated.value) .to.equal(32); });