@@ -138,7 +138,8 @@ var less, tree;
138
138
if ( typeof environment === "object" && ( { } ) . toString . call ( environment ) === "[object Environment]" ) {
139
139
// Rhino
140
140
// Details on how to detect Rhino: https://github.com/ringo/ringojs/issues/88
141
- less = { } ;
141
+ if ( typeof ( window ) === 'undefined' ) { less = { } }
142
+ else { less = window . less = { } }
142
143
tree = less . tree = { } ;
143
144
less . mode = 'rhino' ;
144
145
} else if ( typeof ( window ) === 'undefined' ) {
@@ -208,18 +209,20 @@ less.Parser = function Parser(env) {
208
209
queue : [ ] , // Files which haven't been imported yet
209
210
files : { } , // Holds the imported parse trees
210
211
mime : env && env . mime , // MIME type of .less files
212
+ error : null , // Error in parsing/evaluating an import
211
213
push : function ( path , callback ) {
212
214
var that = this ;
213
215
this . queue . push ( path ) ;
214
216
215
217
//
216
218
// Import a file asynchronously
217
219
//
218
- less . Parser . importer ( path , this . paths , function ( root ) {
220
+ less . Parser . importer ( path , this . paths , function ( e , root ) {
219
221
that . queue . splice ( that . queue . indexOf ( path ) , 1 ) ; // Remove the path from the queue
220
222
that . files [ path ] = root ; // Store the root
221
223
222
- callback ( root ) ;
224
+ if ( e && ! that . error ) { that . error = e }
225
+ callback ( e , root ) ;
223
226
224
227
if ( that . queue . length === 0 ) { finish ( ) } // Call `finish` if we're done importing
225
228
} , env ) ;
@@ -338,7 +341,7 @@ less.Parser = function Parser(env) {
338
341
339
342
this . type = e . type || 'SyntaxError' ;
340
343
this . message = e . message ;
341
- this . filename = env . filename ;
344
+ this . filename = e . filename || env . filename ;
342
345
this . index = e . index ;
343
346
this . line = typeof ( line ) === 'number' ? line + 1 : null ;
344
347
this . callLine = e . call && ( getLocation ( e . call ) + 1 ) ;
@@ -499,6 +502,9 @@ less.Parser = function Parser(env) {
499
502
} catch ( e ) {
500
503
throw new ( LessError ) ( e , env ) ;
501
504
}
505
+
506
+ if ( parser . imports . error ) { throw parser . imports . error }
507
+
502
508
if ( options . yuicompress && less . mode === 'node' ) {
503
509
return require ( './cssmin' ) . compressor . cssmin ( css ) ;
504
510
} else if ( options . compress ) {
@@ -896,11 +902,12 @@ less.Parser = function Parser(env) {
896
902
// the `{...}` block.
897
903
//
898
904
definition : function ( ) {
899
- var name , params = [ ] , match , ruleset , param , value , cond , memo ;
900
-
905
+ var name , params = [ ] , match , ruleset , param , value , cond ;
901
906
if ( ( input . charAt ( i ) !== '.' && input . charAt ( i ) !== '#' ) ||
902
907
peek ( / ^ [ ^ { ] * ( ; | } ) / ) ) return ;
903
908
909
+ save ( ) ;
910
+
904
911
if ( match = $ ( / ^ ( [ # . ] (?: [ \w - ] | \\ (?: [ a - f A - F 0 - 9 ] { 1 , 6 } ? | [ ^ a - f A - F 0 - 9 ] ) ) + ) \s * \( / ) ) {
905
912
name = match [ 1 ] ;
906
913
@@ -921,8 +928,6 @@ less.Parser = function Parser(env) {
921
928
}
922
929
expect ( ')' ) ;
923
930
924
- memo = i ;
925
-
926
931
if ( $ ( / ^ w h e n / ) ) { // Guard
927
932
cond = expect ( this . conditions , 'expected condition' ) ;
928
933
}
@@ -931,6 +936,8 @@ less.Parser = function Parser(env) {
931
936
932
937
if ( ruleset ) {
933
938
return new ( tree . mixin . Definition ) ( name , params , ruleset , cond ) ;
939
+ } else {
940
+ restore ( ) ;
934
941
}
935
942
}
936
943
}
@@ -2203,10 +2210,7 @@ tree.Import = function (path, imports, features) {
2203
2210
2204
2211
// Only pre-compile .less files
2205
2212
if ( ! this . css ) {
2206
- imports . push ( this . path , function ( root ) {
2207
- if ( ! root ) {
2208
- throw new ( Error ) ( "Error parsing " + that . path ) ;
2209
- }
2213
+ imports . push ( this . path , function ( e , root ) {
2210
2214
that . root = root ;
2211
2215
} ) ;
2212
2216
}
0 commit comments