Skip to content
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
11 changes: 11 additions & 0 deletions feature/accessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,24 @@
import { token, expr, skip, space, next, parse, cur, idx } from '../parse.js';

const ASSIGN = 20;
const LF = 10, CR = 13;
const OPAREN = 40, CPAREN = 41, OBRACE = 123, CBRACE = 125;

const hasLineTerminator = (from, to) => {
while (from < to) {
const c = cur.charCodeAt(from++);
if (c === LF || c === CR) return true;
}
return false;
};

// Shared parser for get/set — returns false if not valid accessor pattern (falls through to identifier)
// Returns false (not undefined) to signal "fall through without setting reserved"
const accessor = (kind) => a => {
if (a) return; // not prefix
const from = idx;
space();
if (parse.semi || hasLineTerminator(from, idx)) return false;
const name = next(parse.id);
if (!name) return false; // no property name = not accessor (e.g. `{ get: 1 }`)
space();
Expand Down
7 changes: 7 additions & 0 deletions test/jessie.js
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,13 @@ test('jessie: ASI return', () => {
is(ast[2], 'x')
})

test('jessie: ASI separates returned accessor keyword identifiers', () => {
is(parse('return set;\nfor (const x of xs) { y(x) }'),
[';', ['return', 'set'], ['for', ['of', ['const', 'x'], 'xs'], ['()', 'y', 'x']]])
is(parse('return get;\nwhile (x) { y }'),
[';', ['return', 'get'], ['while', 'x', 'y']])
})

test('jessie: no ASI before . after block expression with semicolon', () => {
is(parse(`f(() => {
x;
Expand Down
Loading