Skip to content

Commit c673035

Browse files
parser: Show empty strings in error messages (#2176)
1 parent cb69e09 commit c673035

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/language/__tests__/parser-test.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ describe('Parser', () => {
7575
message: 'Syntax Error: Unexpected "...".',
7676
locations: [{ line: 1, column: 1 }],
7777
});
78+
79+
expectSyntaxError('{ ""').to.deep.include({
80+
message: 'Syntax Error: Expected Name, found String "".',
81+
locations: [{ line: 1, column: 3 }],
82+
});
7883
});
7984

8085
it('parse provides useful error when using source', () => {

src/language/parser.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1556,9 +1556,8 @@ defineToJSON(Loc, function() {
15561556
* A helper function to describe a token as a string for debugging
15571557
*/
15581558
function getTokenDesc(token: Token): string {
1559-
return (
1560-
getTokenKindDesc(token.kind) + (token.value ? ` "${token.value}"` : '')
1561-
);
1559+
const value = token.value;
1560+
return getTokenKindDesc(token.kind) + (value != null ? ` "${value}"` : '');
15621561
}
15631562

15641563
/**

0 commit comments

Comments
 (0)