@@ -73,6 +73,7 @@ less.Parser = function Parser(env) {
73
73
paths : env && env . paths || [ ] , // Search paths, when importing
74
74
queue : [ ] , // Files which haven't been imported yet
75
75
files : { } , // Holds the imported parse trees
76
+ contents : { } , // Holds the imported file contents
76
77
mime : env && env . mime , // MIME type of .less files
77
78
error : null , // Error in parsing/evaluating an import
78
79
push : function ( path , callback ) {
@@ -82,9 +83,10 @@ less.Parser = function Parser(env) {
82
83
//
83
84
// Import a file asynchronously
84
85
//
85
- less . Parser . importer ( path , this . paths , function ( e , root ) {
86
+ less . Parser . importer ( path , this . paths , function ( e , root , contents ) {
86
87
that . queue . splice ( that . queue . indexOf ( path ) , 1 ) ; // Remove the path from the queue
87
88
that . files [ path ] = root ; // Store the root
89
+ that . contents [ path ] = contents ;
88
90
89
91
if ( e && ! that . error ) { that . error = e }
90
92
callback ( e , root ) ;
@@ -189,7 +191,15 @@ less.Parser = function Parser(env) {
189
191
}
190
192
}
191
193
192
- function getLocation ( index ) {
194
+ function getInput ( e , env ) {
195
+ if ( e . filename && env . filename && ( e . filename !== env . filename ) ) {
196
+ return parser . imports . contents [ e . filename ] ;
197
+ } else {
198
+ return input ;
199
+ }
200
+ }
201
+
202
+ function getLocation ( index , input ) {
193
203
for ( var n = index , column = - 1 ;
194
204
n >= 0 && input . charAt ( n ) !== '\n' ;
195
205
n -- ) { column ++ }
@@ -199,18 +209,19 @@ less.Parser = function Parser(env) {
199
209
}
200
210
201
211
function LessError ( e , env ) {
202
- var lines = input . split ( '\n' ) ,
203
- loc = getLocation ( e . index ) ,
212
+ var input = getInput ( e , env ) ,
213
+ loc = getLocation ( e . index , input ) ,
204
214
line = loc . line ,
205
- col = loc . column ;
215
+ col = loc . column ,
216
+ lines = input . split ( '\n' ) ;
206
217
207
- this . type = e . type || 'SyntaxError ' ;
218
+ this . type = e . type || 'Syntax ' ;
208
219
this . message = e . message ;
209
220
this . filename = e . filename || env . filename ;
210
221
this . index = e . index ;
211
222
this . line = typeof ( line ) === 'number' ? line + 1 : null ;
212
- this . callLine = e . call && ( getLocation ( e . call ) + 1 ) ;
213
- this . callExtract = lines [ getLocation ( e . call ) ] ;
223
+ this . callLine = e . call && ( getLocation ( e . call , input ) + 1 ) ;
224
+ this . callExtract = lines [ getLocation ( e . call , input ) ] ;
214
225
this . stack = e . stack ;
215
226
this . column = col ;
216
227
this . extract = [
@@ -559,7 +570,7 @@ less.Parser = function Parser(env) {
559
570
560
571
if ( ! $ ( ')' ) ) return ;
561
572
562
- if ( name ) { return new ( tree . Call ) ( name , args , index ) }
573
+ if ( name ) { return new ( tree . Call ) ( name , args , index , env . filename ) }
563
574
} ,
564
575
arguments : function ( ) {
565
576
var args = [ ] , arg ;
@@ -635,7 +646,7 @@ less.Parser = function Parser(env) {
635
646
var name , index = i ;
636
647
637
648
if ( input . charAt ( i ) === '@' && ( name = $ ( / ^ @ @ ? [ \w - ] + / ) ) ) {
638
- return new ( tree . Variable ) ( name , index ) ;
649
+ return new ( tree . Variable ) ( name , index , env . filename ) ;
639
650
}
640
651
} ,
641
652
@@ -746,7 +757,7 @@ less.Parser = function Parser(env) {
746
757
}
747
758
748
759
if ( elements . length > 0 && ( $ ( ';' ) || peek ( '}' ) ) ) {
749
- return new ( tree . mixin . Call ) ( elements , args , index , important ) ;
760
+ return new ( tree . mixin . Call ) ( elements , args , index , env . filename , important ) ;
750
761
}
751
762
} ,
752
763
0 commit comments