extend options, algin with decided syntax

This commit is contained in:
Luke Page
2013-02-28 17:07:45 +00:00
parent b9274743c3
commit 494c5f2681
9 changed files with 69 additions and 50 deletions

View File

@@ -1,7 +1,9 @@
//
// LESS - Leaner CSS v@VERSION
// http://lesscss.org
//
// Copyright (c) 2009-2013, Alexis Sellier
// Licensed under the Apache 2.0 License.
//
/*
* LESS - Leaner CSS v@VERSION
* http://lesscss.org
*
* Copyright (c) 2009-2013, Alexis Sellier
* Licensed under the Apache 2.0 License.
*
* @licence
*/

View File

@@ -1,10 +1,12 @@
//
// LESS - Leaner CSS v1.4.0
// http://lesscss.org
//
// Copyright (c) 2009-2013, Alexis Sellier
// Licensed under the Apache 2.0 License.
//
/*
* LESS - Leaner CSS v1.4.0
* http://lesscss.org
*
* Copyright (c) 2009-2013, Alexis Sellier
* Licensed under the Apache 2.0 License.
*
* @licence
*/
(function (window, undefined) {
//
// Stub out `require` in the browser
@@ -923,21 +925,31 @@ less.Parser = function Parser(env) {
// extend syntax - used to extend selectors
//
extend: function(isRule) {
var elements = [], e, args, index = i;
var elements = [], e, args, index = i, option;
if (!$(isRule ? /^&:extend\(/ : /^:extend\(/)) { return; }
while (e = $(/^[#.](?:[\w-]|\\(?:[a-fA-F0-9]{1,6} ?|[^a-fA-F0-9]))+/)) {
while (true) {
option = $(/^(any|deep|all)(?=\s*\))/);
if (option) { break; }
e = $(/^[#.](?:[\w-]|\\(?:[a-fA-F0-9]{1,6} ?|[^a-fA-F0-9]))+/);
if (!e) { break; }
elements.push(new(tree.Element)(null, e, i));
}
expect(/^\)/);
option = option && option[1];
if (option != "all") {
error(":extend only supports the all option at the moment, please specify it after your selector, e.g. :extend(.a all)");
}
if (isRule) {
expect(/^;/);
}
return new(tree.Extend)(elements, index);
return new(tree.Extend)(elements, option, index);
},
//
@@ -3087,8 +3099,9 @@ tree.Expression.prototype = {
})(require('../tree'));
(function (tree) {
tree.Extend = function Extend(elements, index) {
tree.Extend = function Extend(elements, option, index) {
this.selector = new(tree.Selector)(elements);
this.option = option;
this.index = index;
};

File diff suppressed because one or more lines are too long

View File

@@ -788,21 +788,31 @@ less.Parser = function Parser(env) {
// extend syntax - used to extend selectors
//
extend: function(isRule) {
var elements = [], e, args, index = i;
var elements = [], e, args, index = i, option;
if (!$(isRule ? /^&:extend\(/ : /^:extend\(/)) { return; }
while (e = $(/^[#.](?:[\w-]|\\(?:[a-fA-F0-9]{1,6} ?|[^a-fA-F0-9]))+/)) {
while (true) {
option = $(/^(any|deep|all)(?=\s*\))/);
if (option) { break; }
e = $(/^[#.](?:[\w-]|\\(?:[a-fA-F0-9]{1,6} ?|[^a-fA-F0-9]))+/);
if (!e) { break; }
elements.push(new(tree.Element)(null, e, i));
}
expect(/^\)/);
option = option && option[1];
if (option != "all") {
error(":extend only supports the all option at the moment, please specify it after your selector, e.g. :extend(.a all)");
}
if (isRule) {
expect(/^;/);
}
return new(tree.Extend)(elements, index);
return new(tree.Extend)(elements, option, index);
},
//

View File

@@ -1,7 +1,8 @@
(function (tree) {
tree.Extend = function Extend(elements, index) {
tree.Extend = function Extend(elements, option, index) {
this.selector = new(tree.Selector)(elements);
this.option = option;
this.index = index;
};

View File

@@ -9,11 +9,11 @@
}
.foo {
&:extend(.clearfix);
&:extend(.clearfix all);
color: red;
}
.bar {
&:extend(.clearfix);
&:extend(.clearfix all);
color: blue;
}

View File

@@ -10,13 +10,13 @@
}
.sidebar2 {
&:extend(.sidebar);
&:extend(.sidebar all);
background: blue;
}
.type1 {
.sidebar3 {
&:extend(.sidebar);
&:extend(.sidebar all);
background: green;
}
}

View File

@@ -9,7 +9,7 @@
.intrusion .error {
display: none;
}
.badError:extend(.error) {
.badError:extend(.error all) {
border-width: 3px;
}
@@ -18,11 +18,11 @@
}
.ext1 .ext2
:extend(.foo) {
:extend(.foo all) {
}
.ext3:extend(.foo),
.ext4:extend(.foo) {
.ext3:extend(.foo all),
.ext4:extend(.foo all) {
}
div.ext5,
@@ -31,20 +31,20 @@ div.ext5,
}
.should-not-exist-in-output,
.ext7:extend(.ext5) {
.ext7:extend(.ext5 all) {
}
.ext {
test: 1;
}
// same as
// .a .c:extend(.ext)
// .b .c:extend(.ext)
// .a .c:extend(.ext all)
// .b .c:extend(.ext all)
// .a .c .d
// .b .c .d
.a, .b {
test: 2;
.c:extend(.ext) {
.c:extend(.ext all) {
test: 3;
.d {
test: 4;

View File

@@ -10,7 +10,7 @@
display: none;
}
.badError {
&:extend(.error);
&:extend(.error all);
border-width: 3px;
}
@@ -19,12 +19,12 @@
}
.ext1 .ext2 {
&:extend(.foo);
&:extend(.foo all);
}
.ext3,
.ext4 {
&:extend(.foo);
&:extend(.foo all);
}
div.ext5,
@@ -33,5 +33,5 @@ div.ext5,
}
.ext7 {
&:extend(.ext5);
&:extend(.ext5 all);
}