Add support for comments

pull/251/head
Anton Medvedev 1 year ago
parent a1feb3c997
commit b92c38fa8e
No known key found for this signature in database

@ -399,6 +399,33 @@ function* parseJson(stdin) {
while (isWhitespace(lastChar)) {
next()
}
skipComment()
}
function skipComment() {
if (lastChar === '/') {
next()
if (lastChar === '/') {
while (!done && lastChar !== '\n') {
next()
}
skipWhitespace()
} else if (lastChar === '*') {
while (!done) {
next()
if (lastChar === '*') {
next()
if (lastChar === '/') {
next()
break
}
}
}
skipWhitespace()
} else {
throw new SyntaxError(errorSnippet())
}
}
}
function isWhitespace(ch) {

@ -69,6 +69,11 @@ void async function main() {
t.equal(stdout, '[\n 1\n]\n')
})
await test('parseJson - comments', async t => {
const {stdout} = await run('/* comment */ [1 // comment\n]')
t.equal(stdout, '[\n 1\n]\n')
})
await test('transform - anonymous function', async t => {
const {stdout} = await run({'key': 'value'}, '\'function (x) { return x.key }\'')
t.equal(stdout, 'value\n')

Loading…
Cancel
Save