Skip to content

Commit

Permalink
feat(lang): add uspport for computed prop access e.g. `foo.(Symbol.it…
Browse files Browse the repository at this point in the history
…erator)`
  • Loading branch information
kollhof committed Feb 24, 2020
1 parent e450dcc commit 40fe6c6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/lang/prop-access/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import {symbol} from '../symbols';


const member_expr = (ctx, lbp)=> {
// TODO: next tokens can only be a string or an identifier
if (next_is(ctx, '`')) {
// TODO: next tokens can only be a string or an identifier or a group
if (next_is(ctx, '`') || next_is(ctx, '(')) {
return expression(ctx, lbp);
}
const key_ctx = advance(ctx);
Expand Down
17 changes: 17 additions & 0 deletions src/lang/prop-access/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ describe('prop access', ()=> {
});
});


it('parses member expr: foo.`bar spam`', ()=> {
expect(
parse_expr('foo.`bar spam`')
Expand All @@ -34,4 +35,20 @@ describe('prop access', ()=> {
}
});
});


it('parses member expr: foo.(Symbol.iterator)', ()=> {
expect(
parse_expr('foo.(Symbol.iterator)')
).toEqual({
type: 'member',
op: '.',
left: parse_expr(`foo`),
right: parse_expr(' (Symbol.iterator)'),
loc: {
start: {pos: 0, line: 1, column: 0},
end: {pos: 21, line: 1, column: 21}
}
});
});
});

0 comments on commit 40fe6c6

Please sign in to comment.