File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -105,7 +105,18 @@ class Container extends Node {
105105 */
106106 walk ( callback ) {
107107 return this . each ( ( child , i ) => {
108- let result = callback ( child , i )
108+ let result
109+ try {
110+ result = callback ( child , i )
111+ } catch ( e ) {
112+ e . postcssNode = child
113+ if ( e . stack && child . source && / \n \s { 4 } a t / . test ( e . stack ) ) {
114+ const s = child . source
115+ e . stack = e . stack . replace ( / \n \s { 4 } a t / ,
116+ `$&${ s . input . from } :${ s . start . line } :${ s . start . column } $&` )
117+ }
118+ throw e
119+ }
109120 if ( result !== false && child . walk ) {
110121 result = child . walk ( callback )
111122 }
Original file line number Diff line number Diff line change @@ -182,6 +182,24 @@ it('walk() breaks iteration', () => {
182182 expect ( indexes ) . toEqual ( [ 0 ] )
183183} )
184184
185+ it ( 'walk() adds CSS position to error stack' , ( ) => {
186+ const error = new Error ( 'T' )
187+ error . stack = 'Error: T\n at b (b.js:2:4)\n at a (a.js:2:1)'
188+ const root = parse ( example , { from : '/c.css' } )
189+ let catched
190+ try {
191+ root . walk ( ( ) => {
192+ throw error
193+ } )
194+ } catch ( e ) {
195+ catched = e
196+ }
197+ expect ( catched ) . toBe ( error )
198+ expect ( catched . postcssNode . toString ( ) ) . toEqual ( 'a { a: 1; b: 2 }' )
199+ expect ( catched . stack ) . toEqual (
200+ 'Error: T\n at /c.css:1:1\n at b (b.js:2:4)\n at a (a.js:2:1)' )
201+ } )
202+
185203it ( 'walkDecls() iterates' , ( ) => {
186204 const props = [ ]
187205 const indexes = [ ]
You can’t perform that action at this time.
0 commit comments