fix: parens can't be in words

This commit is contained in:
Chris Wanstrath 2025-12-05 15:25:33 -08:00
parent 07a42d9767
commit e1859c1bda
2 changed files with 21 additions and 0 deletions

View File

@ -425,6 +425,26 @@ f
) )
}) })
test('function call w/ parens', () => {
expect('echo(bold hello world)').toMatchTokens(
{ type: 'Identifier', value: 'echo' },
{ type: 'OpenParen' },
{ type: 'Identifier', value: 'bold' },
{ type: 'Identifier', value: 'hello' },
{ type: 'Identifier', value: 'world' },
{ type: 'CloseParen' },
)
expect('echo (bold hello world)').toMatchTokens(
{ type: 'Identifier', value: 'echo' },
{ type: 'OpenParen' },
{ type: 'Identifier', value: 'bold' },
{ type: 'Identifier', value: 'hello' },
{ type: 'Identifier', value: 'world' },
{ type: 'CloseParen' },
)
})
test('assignment', () => { test('assignment', () => {
expect('x = 5').toMatchTokens( expect('x = 5').toMatchTokens(
{ type: 'Identifier', value: 'x' }, { type: 'Identifier', value: 'x' },

View File

@ -507,6 +507,7 @@ const isWordChar = (ch: number): boolean => {
!isWhitespace(ch) && !isWhitespace(ch) &&
ch !== 10 /* \n */ && ch !== 10 /* \n */ &&
ch !== 59 /* ; */ && ch !== 59 /* ; */ &&
ch !== 40 /* ( */ &&
ch !== 41 /* ) */ && ch !== 41 /* ) */ &&
ch !== 93 /* ] */ && ch !== 93 /* ] */ &&
ch !== -1 /* EOF */ ch !== -1 /* EOF */