Skip to content

Commit

Permalink
Merge pull request #1156 from embroider-build/macro-exception
Browse files Browse the repository at this point in the history
fix exception in macros babel plugin
  • Loading branch information
ef4 authored Mar 8, 2022
2 parents 8ec7098 + b2ea3f3 commit cf9a93b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
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

0 comments on commit cf9a93b

Please sign in to comment.