跳至內容
在此頁面

錯誤回報

Stylus 內建了絕佳的錯誤回報功能,適用於語法、解析和評估錯誤,並提供堆疊追蹤、行號和檔案名稱。

解析錯誤

解析錯誤範例

     body
       form input
         == padding 5px
     body
       form input
         == padding 5px

產生

ParseError: test.styl:3:16
  1| body
  2|    form input
  3|      == padding 5px
---------------------^
  4|

illegal unary "==", missing left-hand operand
ParseError: test.styl:3:16
  1| body
  2|    form input
  3|      == padding 5px
---------------------^
  4|

illegal unary "==", missing left-hand operand

評估錯誤

這個「執行時期」或評估錯誤是由於傳遞字串給 border-radius(),而不是預期的 Unit(使用我們的輔助程式 ensure(n, 'unit'))。

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'

產生

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')

expected a unit, but got string
    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')

expected a unit, but got string
    at ensure() (test.styl:2:17)
    at border-radius() (test.styl:6:16)
    at "body" (test.styl:10:18)