@@ -55,6 +55,10 @@ class lessc {
55
55
public $ imPrefix = '! ' ; // special character to add !important
56
56
public $ parentSelector = '& ' ;
57
57
58
+ // set the the parser that generated the current line when compiling
59
+ // so we know how to create error messages
60
+ protected $ sourceParser = null ;
61
+
58
62
static protected $ precedence = array (
59
63
'=< ' => 0 ,
60
64
'>= ' => 0 ,
@@ -982,7 +986,8 @@ function mixImports($block) {
982
986
if ($ prop [0 ] == 'import ' ) {
983
987
list (, $ path ) = $ prop ;
984
988
$ this ->addParsedFile ($ path );
985
- $ root = $ this ->createChild ($ path )->parseTree ();
989
+ $ child_less = $ this ->createChild ($ path );
990
+ $ root = $ child_less ->parseTree ();
986
991
987
992
$ root ->parent = $ block ;
988
993
$ this ->mixImports ($ root );
@@ -992,7 +997,10 @@ function mixImports($block) {
992
997
993
998
// splice in all the props
994
999
foreach ($ root ->props as $ sub_prop ) {
995
- // TODO fix the position to point to right file
1000
+ if (isset ($ sub_prop [-1 ])) {
1001
+ // leave a reference to the imported file for error messages
1002
+ $ sub_prop [-1 ] = array ($ child_less , $ sub_prop [-1 ]);
1003
+ }
996
1004
$ props [] = $ sub_prop ;
997
1005
}
998
1006
} else {
@@ -1264,8 +1272,16 @@ function zipSetArgs($args, $values) {
1264
1272
1265
1273
// compile a prop and update $lines or $blocks appropriately
1266
1274
function compileProp ($ prop , $ block , $ tags , &$ _lines , &$ _blocks ) {
1275
+ // set error position context
1267
1276
if (isset ($ prop [-1 ])) {
1268
- $ this ->count = $ prop [-1 ];
1277
+ if (is_array ($ prop [-1 ])) {
1278
+ list ($ less , $ count ) = $ prop [-1 ];
1279
+ $ parentParser = $ this ->sourceParser ;
1280
+ $ this ->sourceParser = $ less ;
1281
+ $ this ->count = $ count ;
1282
+ } else {
1283
+ $ this ->count = $ prop [-1 ];
1284
+ }
1269
1285
} else {
1270
1286
$ this ->count = -1 ;
1271
1287
}
@@ -1335,6 +1351,10 @@ function compileProp($prop, $block, $tags, &$_lines, &$_blocks) {
1335
1351
default :
1336
1352
$ this ->throwError ("unknown op: {$ prop [0 ]}\n" );
1337
1353
}
1354
+
1355
+ if (isset ($ parentParser )) {
1356
+ $ this ->sourceParser = $ parentParser ;
1357
+ }
1338
1358
}
1339
1359
1340
1360
@@ -2252,7 +2272,10 @@ function parse($str = null, $initial_variables = null) {
2252
2272
* Uses the current value of $this->count to show line and line number
2253
2273
*/
2254
2274
function throwError ($ msg = 'parse error ' ) {
2255
- if ($ this ->count > 0 ) {
2275
+ if (!empty ($ this ->sourceParser )) {
2276
+ $ this ->sourceParser ->count = $ this ->count ;
2277
+ return $ this ->sourceParser ->throwError ($ msg );
2278
+ } elseif ($ this ->count > 0 ) {
2256
2279
$ line = $ this ->line + substr_count (substr ($ this ->buffer , 0 , $ this ->count ), "\n" );
2257
2280
if (isset ($ this ->fileName )) {
2258
2281
$ loc = $ this ->fileName .' on line ' .$ line ;
@@ -2262,9 +2285,9 @@ function throwError($msg = 'parse error') {
2262
2285
2263
2286
if ($ this ->peek ("(.*?)( \n|$) " , $ m ))
2264
2287
throw new exception ($ msg .': failed at ` ' .$ m [1 ].'` ' .$ loc );
2265
- } else {
2266
- throw new exception ($ msg );
2267
2288
}
2289
+
2290
+ throw new exception ($ msg );
2268
2291
}
2269
2292
2270
2293
/**
0 commit comments