1
1
/*!
2
- * LESS - Leaner CSS v1.5.0-b4
2
+ * LESS - Leaner CSS v1.5.1
3
3
* http://lesscss.org
4
4
*
5
5
* Copyright (c) 2009-2013, Alexis Sellier <[email protected] >
@@ -73,7 +73,8 @@ less.Parser = function Parser(env) {
73
73
furthest , // furthest index the parser has gone to
74
74
chunks , // chunkified input
75
75
current , // index of current chunk, in `input`
76
- parser ;
76
+ parser ,
77
+ rootFilename = env && env . filename ;
77
78
78
79
// Top parser on an import tree must be sure there is one "env"
79
80
// which will then be passed around by reference.
@@ -95,7 +96,7 @@ less.Parser = function Parser(env) {
95
96
var fileParsedFunc = function ( e , root , fullPath ) {
96
97
parserImports . queue . splice ( parserImports . queue . indexOf ( path ) , 1 ) ; // Remove the path from the queue
97
98
98
- var importedPreviously = fullPath in parserImports . files ;
99
+ var importedPreviously = fullPath in parserImports . files || fullPath === rootFilename ;
99
100
100
101
parserImports . files [ fullPath ] = root ; // Store the root
101
102
@@ -493,6 +494,7 @@ less.Parser = function Parser(env) {
493
494
rootNode : evaldRoot ,
494
495
contentsMap : parser . imports . contents ,
495
496
sourceMapFilename : options . sourceMapFilename ,
497
+ sourceMapURL : options . sourceMapURL ,
496
498
outputFilename : options . sourceMapOutputFilename ,
497
499
sourceMapBasepath : options . sourceMapBasepath ,
498
500
sourceMapRootpath : options . sourceMapRootpath ,
@@ -510,7 +512,9 @@ less.Parser = function Parser(env) {
510
512
}
511
513
512
514
if ( options . cleancss && less . mode === 'node' ) {
513
- return require ( 'clean-css' ) . process ( css ) ;
515
+ var CleanCSS = require ( 'clean-css' ) ;
516
+ //TODO would be nice for no advanced to be an option
517
+ return new CleanCSS ( { keepSpecialComments : '*' , processImport : false , noRebase : true , noAdvanced : true } ) . minify ( css ) ;
514
518
} else if ( options . compress ) {
515
519
return css . replace ( / ( ^ ( \s ) + ) | ( ( \s ) + $ ) / g, "" ) ;
516
520
} else {
@@ -1302,7 +1306,7 @@ less.Parser = function Parser(env) {
1302
1306
$ ( this . comments ) ;
1303
1307
if ( ! $ ( ',' ) ) { break ; }
1304
1308
if ( s . condition ) {
1305
- error ( "Guards are only currently allowed on a single selector" ) ;
1309
+ error ( "Guards are only currently allowed on a single selector. " ) ;
1306
1310
}
1307
1311
$ ( this . comments ) ;
1308
1312
}
@@ -1643,7 +1647,7 @@ less.Parser = function Parser(env) {
1643
1647
var a , b , index = i , condition ;
1644
1648
1645
1649
if ( a = $ ( this . condition ) ) {
1646
- while ( $ ( ',' ) && ( b = $ ( this . condition ) ) ) {
1650
+ while ( peek ( / ^ , \s * ( n o t \s * ) ? \( / ) && $ ( ',' ) && ( b = $ ( this . condition ) ) ) {
1647
1651
condition = new ( tree . Condition ) ( 'or' , condition || a , b , index ) ;
1648
1652
}
1649
1653
return condition || a ;
@@ -3624,9 +3628,16 @@ tree.Extend.prototype = {
3624
3628
} ,
3625
3629
findSelfSelectors : function ( selectors ) {
3626
3630
var selfElements = [ ] ,
3627
- i ;
3631
+ i ,
3632
+ selectorElements ;
3628
3633
3629
3634
for ( i = 0 ; i < selectors . length ; i ++ ) {
3635
+ selectorElements = selectors [ i ] . elements ;
3636
+ // duplicate the logic in genCSS function inside the selector node.
3637
+ // future TODO - move both logics into the selector joiner visitor
3638
+ if ( i > 0 && selectorElements . length && selectorElements [ 0 ] . combinator . value === "" ) {
3639
+ selectorElements [ 0 ] . combinator . value = ' ' ;
3640
+ }
3630
3641
selfElements = selfElements . concat ( selectors [ i ] . elements ) ;
3631
3642
}
3632
3643
@@ -4373,7 +4384,7 @@ tree.Quoted.prototype = {
4373
4384
var v = new ( tree . Variable ) ( '@' + name , that . index , that . currentFileInfo ) . eval ( env , true ) ;
4374
4385
return ( v instanceof tree . Quoted ) ? v . value : v . toCSS ( ) ;
4375
4386
} ) ;
4376
- return new ( tree . Quoted ) ( this . quote + value + this . quote , value , this . escaped , this . index ) ;
4387
+ return new ( tree . Quoted ) ( this . quote + value + this . quote , value , this . escaped , this . index , this . currentFileInfo ) ;
4377
4388
} ,
4378
4389
compare : function ( x ) {
4379
4390
if ( ! x . toCSS ) {
@@ -4626,9 +4637,9 @@ tree.Ruleset.prototype = {
4626
4637
if ( rule !== self ) {
4627
4638
for ( var j = 0 ; j < rule . selectors . length ; j ++ ) {
4628
4639
if ( match = selector . match ( rule . selectors [ j ] ) ) {
4629
- if ( selector . elements . length > rule . selectors [ j ] . elements . length ) {
4640
+ if ( selector . elements . length > match ) {
4630
4641
Array . prototype . push . apply ( rules , rule . find (
4631
- new ( tree . Selector ) ( selector . elements . slice ( 1 ) ) , self ) ) ;
4642
+ new ( tree . Selector ) ( selector . elements . slice ( match ) ) , self ) ) ;
4632
4643
} else {
4633
4644
rules . push ( rule ) ;
4634
4645
}
@@ -4954,15 +4965,15 @@ tree.Selector.prototype = {
4954
4965
max = Math . min ( len , olen ) ;
4955
4966
4956
4967
if ( olen === 0 || len < olen ) {
4957
- return false ;
4968
+ return 0 ;
4958
4969
} else {
4959
4970
for ( i = 0 ; i < max ; i ++ ) {
4960
4971
if ( elements [ i ] . value !== oelements [ i ] . value ) {
4961
- return false ;
4972
+ return 0 ;
4962
4973
}
4963
4974
}
4964
4975
}
4965
- return true ;
4976
+ return max ; // return number of matched selectors
4966
4977
} ,
4967
4978
eval : function ( env ) {
4968
4979
var evaldCondition = this . condition && this . condition . eval ( env ) ;
@@ -5724,6 +5735,7 @@ tree.Variable.prototype = {
5724
5735
for ( i = 0 ; i < rulesetNode . rules . length ; i ++ ) {
5725
5736
if ( rulesetNode . rules [ i ] instanceof tree . Extend ) {
5726
5737
allSelectorsExtendList . push ( rulesetNode . rules [ i ] ) ;
5738
+ rulesetNode . extendOnEveryPath = true ;
5727
5739
}
5728
5740
}
5729
5741
@@ -5907,7 +5919,7 @@ tree.Variable.prototype = {
5907
5919
selectorPath = rulesetNode . paths [ pathIndex ] ;
5908
5920
5909
5921
// extending extends happens initially, before the main pass
5910
- if ( selectorPath [ selectorPath . length - 1 ] . extendList . length ) { continue ; }
5922
+ if ( rulesetNode . extendOnEveryPath || selectorPath [ selectorPath . length - 1 ] . extendList . length ) { continue ; }
5911
5923
5912
5924
matches = this . findMatch ( allExtends [ extendIndex ] , selectorPath ) ;
5913
5925
@@ -6008,6 +6020,24 @@ tree.Variable.prototype = {
6008
6020
elementValue2 = elementValue2 . value . value || elementValue2 . value ;
6009
6021
return elementValue1 === elementValue2 ;
6010
6022
}
6023
+ elementValue1 = elementValue1 . value ;
6024
+ elementValue2 = elementValue2 . value ;
6025
+ if ( elementValue1 instanceof tree . Selector ) {
6026
+ if ( ! ( elementValue2 instanceof tree . Selector ) || elementValue1 . elements . length !== elementValue2 . elements . length ) {
6027
+ return false ;
6028
+ }
6029
+ for ( var i = 0 ; i < elementValue1 . elements . length ; i ++ ) {
6030
+ if ( elementValue1 . elements [ i ] . combinator . value !== elementValue2 . elements [ i ] . combinator . value ) {
6031
+ if ( i !== 0 || ( elementValue1 . elements [ i ] . combinator . value || ' ' ) !== ( elementValue2 . elements [ i ] . combinator . value || ' ' ) ) {
6032
+ return false ;
6033
+ }
6034
+ }
6035
+ if ( ! this . isElementValuesEqual ( elementValue1 . elements [ i ] . value , elementValue2 . elements [ i ] . value ) ) {
6036
+ return false ;
6037
+ }
6038
+ }
6039
+ return true ;
6040
+ }
6011
6041
return false ;
6012
6042
} ,
6013
6043
extendSelector :function ( matches , selectorPath , replacementSelector ) {
@@ -6064,7 +6094,6 @@ tree.Variable.prototype = {
6064
6094
6065
6095
if ( currentSelectorPathIndex < selectorPath . length && currentSelectorPathElementIndex > 0 ) {
6066
6096
path [ path . length - 1 ] . elements = path [ path . length - 1 ] . elements . concat ( selectorPath [ currentSelectorPathIndex ] . elements . slice ( currentSelectorPathElementIndex ) ) ;
6067
- currentSelectorPathElementIndex = 0 ;
6068
6097
currentSelectorPathIndex ++ ;
6069
6098
}
6070
6099
@@ -6103,6 +6132,7 @@ tree.Variable.prototype = {
6103
6132
this . _contentsMap = options . contentsMap ;
6104
6133
this . _sourceMapFilename = options . sourceMapFilename ;
6105
6134
this . _outputFilename = options . outputFilename ;
6135
+ this . _sourceMapURL = options . sourceMapURL ;
6106
6136
this . _sourceMapBasepath = options . sourceMapBasepath ;
6107
6137
this . _sourceMapRootpath = options . sourceMapRootpath ;
6108
6138
this . _outputSourceFiles = options . outputSourceFiles ;
@@ -6188,21 +6218,23 @@ tree.Variable.prototype = {
6188
6218
this . _rootNode . genCSS ( env , this ) ;
6189
6219
6190
6220
if ( this . _css . length > 0 ) {
6191
- var sourceMapFilename ,
6221
+ var sourceMapURL ,
6192
6222
sourceMapContent = JSON . stringify ( this . _sourceMapGenerator . toJSON ( ) ) ;
6193
6223
6194
- if ( this . _sourceMapFilename ) {
6195
- sourceMapFilename = this . normalizeFilename ( this . _sourceMapFilename ) ;
6224
+ if ( this . _sourceMapURL ) {
6225
+ sourceMapURL = this . _sourceMapURL ;
6226
+ } else if ( this . _sourceMapFilename ) {
6227
+ sourceMapURL = this . normalizeFilename ( this . _sourceMapFilename ) ;
6196
6228
}
6197
6229
6198
6230
if ( this . _writeSourceMap ) {
6199
6231
this . _writeSourceMap ( sourceMapContent ) ;
6200
6232
} else {
6201
- sourceMapFilename = "data:application/json," + encodeURIComponent ( sourceMapContent ) ;
6233
+ sourceMapURL = "data:application/json," + encodeURIComponent ( sourceMapContent ) ;
6202
6234
}
6203
6235
6204
- if ( sourceMapFilename ) {
6205
- this . _css . push ( "/*# sourceMappingURL=" + sourceMapFilename + " */" ) ;
6236
+ if ( sourceMapURL ) {
6237
+ this . _css . push ( "/*# sourceMappingURL=" + sourceMapURL + " */" ) ;
6206
6238
}
6207
6239
}
6208
6240
@@ -6221,7 +6253,8 @@ var isFileProtocol = /^(file|chrome(-extension)?|resource|qrc|app):/.test(locati
6221
6253
less . env = less . env || ( location . hostname == '127.0.0.1' ||
6222
6254
location . hostname == '0.0.0.0' ||
6223
6255
location . hostname == 'localhost' ||
6224
- location . port . length > 0 ||
6256
+ ( location . port &&
6257
+ location . port . length > 0 ) ||
6225
6258
isFileProtocol ? 'development'
6226
6259
: 'production' ) ;
6227
6260
@@ -6265,6 +6298,7 @@ if (dumpLineNumbers) {
6265
6298
var typePattern = / ^ t e x t \/ ( x - ) ? l e s s $ / ;
6266
6299
var cache = null ;
6267
6300
var fileCache = { } ;
6301
+ var varsPre = "" ;
6268
6302
6269
6303
function log ( str , level ) {
6270
6304
if ( less . env == 'development' && typeof ( console ) !== 'undefined' && less . logLevel >= level ) {
@@ -6507,9 +6541,15 @@ function loadStyles(newVars) {
6507
6541
var env = new less . tree . parseEnv ( less ) ,
6508
6542
lessText = style . innerHTML || '' ;
6509
6543
env . filename = document . location . href . replace ( / # .* $ / , '' ) ;
6510
- if ( newVars ) {
6544
+
6545
+ if ( newVars || varsPre ) {
6511
6546
env . useFileCache = true ;
6512
- lessText += "\n" + newVars ;
6547
+
6548
+ lessText = varsPre + lessText ;
6549
+
6550
+ if ( newVars ) {
6551
+ lessText += "\n" + newVars ;
6552
+ }
6513
6553
}
6514
6554
6515
6555
/*jshint loopfunc:true */
@@ -6712,6 +6752,8 @@ function loadFile(originalHref, currentFileInfo, callback, env, newVars) {
6712
6752
}
6713
6753
6714
6754
doXHR ( href , env . mime , function ( data , lastModified ) {
6755
+ data = varsPre + data ;
6756
+
6715
6757
// per file cache
6716
6758
fileCache [ href ] = data ;
6717
6759
@@ -6731,7 +6773,7 @@ function loadStyleSheet(sheet, callback, reload, remaining, newVars) {
6731
6773
var env = new less . tree . parseEnv ( less ) ;
6732
6774
env . mime = sheet . type ;
6733
6775
6734
- if ( newVars ) {
6776
+ if ( newVars || varsPre ) {
6735
6777
env . useFileCache = true ;
6736
6778
}
6737
6779
@@ -6798,6 +6840,18 @@ function initRunningMode(){
6798
6840
}
6799
6841
}
6800
6842
6843
+ function serializeVars ( vars ) {
6844
+ var s = "" ;
6845
+
6846
+ for ( var name in vars ) {
6847
+ s += ( ( name . slice ( 0 , 1 ) === '@' ) ? '' : '@' ) + name + ': ' +
6848
+ ( ( vars [ name ] . slice ( - 1 ) === ';' ) ? vars [ name ] : vars [ name ] + ';' ) ;
6849
+ }
6850
+
6851
+ return s ;
6852
+ }
6853
+
6854
+
6801
6855
//
6802
6856
// Watch mode
6803
6857
//
@@ -6840,12 +6894,7 @@ for (var i = 0; i < links.length; i++) {
6840
6894
// CSS without reloading less-files
6841
6895
//
6842
6896
less . modifyVars = function ( record ) {
6843
- var newVars = "" ;
6844
- for ( var name in record ) {
6845
- newVars += ( ( name . slice ( 0 , 1 ) === '@' ) ? '' : '@' ) + name + ': ' +
6846
- ( ( record [ name ] . slice ( - 1 ) === ';' ) ? record [ name ] : record [ name ] + ';' ) ;
6847
- }
6848
- less . refresh ( false , newVars ) ;
6897
+ less . refresh ( false , serializeVars ( record ) ) ;
6849
6898
} ;
6850
6899
6851
6900
less . refresh = function ( reload , newVars ) {
@@ -6872,6 +6921,10 @@ less.refresh = function (reload, newVars) {
6872
6921
loadStyles ( newVars ) ;
6873
6922
} ;
6874
6923
6924
+ if ( less . globalVars ) {
6925
+ varsPre = serializeVars ( less . globalVars ) + "\n" ;
6926
+ }
6927
+
6875
6928
less . refreshStyles = loadStyles ;
6876
6929
6877
6930
less . Parser . fileLoader = loadFile ;
0 commit comments