Skip to content

Commit a488b56

Browse files
authored
Merge pull request #36 from davejcameron/dc.subscript-regex-equals
Fix regex literals starting with equals
2 parents 53cd528 + ddd057e commit a488b56

2 files changed

Lines changed: 5 additions & 2 deletions

File tree

feature/regex.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ import { token, skip, err, next, idx, cur } from '../parse.js';
1414
const SLASH = 47, BSLASH = 92;
1515

1616
token('/', 140, a => {
17-
// left operand = division; `//` `/*` `/?` `/+` `/=` = not a regex start
17+
// left operand = division or assignment; `//` `/*` `/?` `/+` = not a regex start
1818
const c = cur.charCodeAt(idx);
19-
if (a || c === SLASH || c === 42 || c === 43 || c === 63 || c === 61) return;
19+
if (a || c === SLASH || c === 42 || c === 43 || c === 63) return;
2020
const pattern = next(c => c === BSLASH ? 2 : c && c !== SLASH); // \x = 2 chars, else 1 until /
2121
cur.charCodeAt(idx) === SLASH || err('Unterminated regex');
2222
skip();

test/feature/regex.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import test, { is, throws } from 'tst'
22
import { parse, compile } from '../../subscript.js'
33
import '../../feature/regex.js'
4+
import '../../eval/regex.js'
45

56
const run = (code, ctx = {}) => compile(parse(code))(ctx)
67

@@ -40,6 +41,8 @@ test('regex: division disambiguation', t => {
4041
test('regex: in expressions', t => {
4142
is(run('x.match(/\\d+/)', { x: 'abc123def' })[0], '123')
4243
is(run('x.replace(/a/g, "b")', { x: 'aaa' }), 'bbb')
44+
is(run('x.replace(/=/g, "")', { x: 'a=b=c' }), 'abc')
45+
is(run('x.replace(/=>/g, ":")', { x: 'a=>b=>c' }), 'a:b:c')
4346
})
4447

4548
test('regex: JSON serializable', t => {

0 commit comments

Comments
 (0)