throwSyntaxError failed to report position if the macro is invoked in the first line
Created by: hax
Test case:
macro.sjs:
macro TEST {
case { $name } => {
throwSyntaxError('TestError', 'test error', #{ $name })
}
}
export TEST
test.sjs:
TEST
(NOTE: if add a blank line before 'TEST', everything is ok)
sjs -m ./macro test.sjs
Expect:
/Users/hax/sweet.js/lib/sweet.js:99
throw new SyntaxError(syn.printSyntaxError(source$2, err))
^
SyntaxError: [TestError] test error
1: TEST
^
at expand$2 (/Users/hax/sweet.js/lib/sweet.js:99:27)
at parse (/Users/hax/sweet.js/lib/sweet.js:135:29)
at Object.compile (/Users/hax/sweet.js/lib/sweet.js:143:19)
at Object.exports.run (/Users/hax/sweet.js/lib/sjs.js:85:27)
at Object.<anonymous> (/Users/hax/sweet.js/bin/sjs:7:23)
at Module._compile (module.js:449:26)
at Object.Module._extensions..js (module.js:467:10)
at Module.load (module.js:349:32)
at Function.Module._load (module.js:305:12)
at Function.Module.runMain (module.js:490:10)
Actual:
/Users/hax/sweet.js/lib/syntax.js:346
name + '] ' + err.message + '\n' + pre + line + '\n' + Array(offset + pre.leng
^
RangeError: Invalid array length
at Object.printSyntaxError (/Users/hax/sweet.js/lib/syntax.js:346:94)
at expand$2 (/Users/hax/sweet.js/lib/sweet.js:99:47)
at parse (/Users/hax/sweet.js/lib/sweet.js:135:29)
at Object.compile (/Users/hax/sweet.js/lib/sweet.js:143:19)
at Object.exports.run (/Users/hax/sweet.js/lib/sjs.js:85:27)
at Object.<anonymous> (/Users/hax/sweet.js/bin/sjs:7:23)
at Module._compile (module.js:449:26)
at Object.Module._extensions..js (module.js:467:10)
at Module.load (module.js:349:32)
at Function.Module._load (module.js:305:12)