Skip to content
Closed
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
18 changes: 16 additions & 2 deletions feature/access.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,29 @@
* Property access: a.b, a[b], a(b), [1,2,3] - parse half
* For private fields (#x), see class.js
*/
import { access, binary } from '../parse.js';
import { access, cur, err, expr, idx, next, parse, skip, token } from '../parse.js';

const ACCESS = 170;
const HASH = 35, _0 = 48, _9 = 57;

// a[b]
access('[]', ACCESS);

// a.b
binary('.', ACCESS);
token('.', ACCESS, a => {
if (!a) return;

parse.space();
if (cur.charCodeAt(idx) === HASH) {
skip();
const id = next(parse.id);
return id ? ['.', a, '#' + id] : err('Expected property name');
}

const cc = cur.charCodeAt(idx);
const prop = cc >= _0 && cc <= _9 ? expr(ACCESS) : next(parse.id) || expr(ACCESS);
return ['.', a, prop || err('Expected property name')];
});

// a(b,c,d), a()
access('()', ACCESS);
5 changes: 5 additions & 0 deletions test/jessie.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ test('jessie: inherits justin', () => {
is(parse('{a: 1}'), ['{}', [':', 'a', [, 1]]])
})

test('jessie: reserved words in member access', () => {
is(parse('record.function.kind'), ['.', ['.', 'record', 'function'], 'kind'])
is(parse('record.class.name'), ['.', ['.', 'record', 'class'], 'name'])
})

// === variables ===

test('jessie: variables', () => {
Expand Down
Loading