错误报告
Stylus 内置了出色的错误报告功能,用于语法、解析和求值错误——包括堆栈跟踪、行号和文件名。
解析错误
解析错误示例:
stylus
body
form input
== padding 5px
body
form input
== padding 5px
生成:
bash
ParseError: test.styl:3:16
1| body
2| form input
3| == padding 5px
---------------------^
4|
非法一元运算符 "==",缺少左操作数
ParseError: test.styl:3:16
1| body
2| form input
3| == padding 5px
---------------------^
4|
非法一元运算符 "==",缺少左操作数
求值错误
这是一个"运行时"或求值错误,由于传递了一个字符串给 border-radius()
,而不是预期的 Unit
(通过使用我们的辅助函数 ensure(n, 'unit')
)。
stylus
ensure(val, type)
unless val is a type
error('expected a ' + type + ', but got ' + typeof(val))
border-radius(n)
ensure(n, 'unit')
-webkit-border-radius n
-moz-border-radius n
border-radius n
body
border-radius '5px'
ensure(val, type)
unless val is a type
error('expected a ' + type + ', but got ' + typeof(val))
border-radius(n)
ensure(n, 'unit')
-webkit-border-radius n
-moz-border-radius n
border-radius n
body
border-radius '5px'
生成:
bash
Error: test.styl:3:62
1| ensure(val, type)
2| unless val is a type
3| error('expected a ' + type + ', but got ' + typeof(val))
-------------------------------------------------------------------^
4|
5| border-radius(n)
6| ensure(n, 'unit')
预期是一个单位,但得到了字符串
at ensure() (test.styl:2:17)
at border-radius() (test.styl:6:16)
at "body" (test.styl:10:18)
Error: test.styl:3:62
1| ensure(val, type)
2| unless val is a type
3| error('expected a ' + type + ', but got ' + typeof(val))
-------------------------------------------------------------------^
4|
5| border-radius(n)
6| ensure(n, 'unit')
预期是一个单位,但得到了字符串
at ensure() (test.styl:2:17)
at border-radius() (test.styl:6:16)
at "body" (test.styl:10:18)