Skip to content

Commit 19f80a4

Browse files
committed
Fix parsing of bare keywords without extra symbols
1 parent 1ce8bfc commit 19f80a4

5 files changed

Lines changed: 29 additions & 14 deletions

File tree

‎build/index.cjs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ function parse(source) {
205205
for (let i = 1; i < name.length; i++)
206206
if (next(), ch !== name[i])
207207
throw new SyntaxError(errorSnippet());
208-
if (next(), isWhitespace(ch) || ch === "," || ch === "}" || ch === "]" || ch === void 0)
208+
if (next(), isWhitespace(ch) || ch === "," || ch === "}" || ch === "]" || done)
209209
return value2;
210210
throw new SyntaxError(errorSnippet());
211211
}

‎build/index.js‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎build/maml.min.js‎

Lines changed: 11 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/parse.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ export function parse(source: string): any {
311311
ch === ',' ||
312312
ch === '}' ||
313313
ch === ']' ||
314-
ch === undefined
314+
done
315315
) {
316316
return value
317317
}

‎test/parse.test.js‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,21 @@ describe('parse', () => {
5151
})
5252

5353
describe('extra', () => {
54+
test('true without extra symbols', () => {
55+
const output = parse('true')
56+
expect(output).toStrictEqual(true)
57+
})
58+
59+
test('false without extra symbols', () => {
60+
const output = parse('false')
61+
expect(output).toStrictEqual(false)
62+
})
63+
64+
test('null without extra symbols', () => {
65+
const output = parse('null')
66+
expect(output).toStrictEqual(null)
67+
})
68+
5469
test('bigint', () => {
5570
const output = parse(`9007199254740992`) // Number.MAX_SAFE_INTEGER + 1
5671
expect(output).toStrictEqual(9007199254740992n)

0 commit comments

Comments
 (0)