Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix exception in macros babel plugin #1156

Merged
merged 1 commit into from
Mar 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/macros/src/babel/evaluate-json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,9 @@ export class Evaluator {

if (path.isObjectExpression()) {
let props = assertArray(path.get('properties')).map(p => {
if (p.isSpreadElement()) {
return [{ confident: false }, { confident: false }];
}
let key = assertNotArray(p.get('key'));
let keyEvalValue = this.evaluateKey(key);
let value = assertNotArray(p.get('value'));
Expand Down
5 changes: 5 additions & 0 deletions packages/macros/tests/babel/eval.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ describe('evaluation', function () {
expect(code).toMatch(`result = 42`);
});

test('object literal non-nullish member access parses OK', () => {
let code = transform(`const result = { ...content\n}?.[0].content;`);
expect(code).toMatch(`const result = { ...content\n}?.[0].content;`);
});

test('optional chaining nullish member access', () => {
let code = transform(`const result = knownUndefinedValue?.x;`);
expect(code).toMatch(`result = undefined`);
Expand Down