Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into image-size
Browse files Browse the repository at this point in the history
  • Loading branch information
bassjobsen committed Apr 1, 2015
2 parents 16a0285 + fc93876 commit ea43e7d
Show file tree
Hide file tree
Showing 29 changed files with 229 additions and 90 deletions.
2 changes: 1 addition & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ module.exports = function (grunt) {
command: 'node test'
},
benchmark: {
command: 'node benchmark/less-benchmark.js'
command: 'node benchmark/index.js'
},
"sourcemap-test": {
command: [
Expand Down
5 changes: 3 additions & 2 deletions lib/less-rhino/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*jshint rhino:true, unused: false */
/*global name:true, less, loadStyleSheet, os */
/* jshint rhino:true, unused: false */
/* jscs:disable validateIndentation */
/* global name:true, less, loadStyleSheet, os */

function formatError(ctx, options) {
options = options || {};
Expand Down
3 changes: 1 addition & 2 deletions lib/less/parser/parser-input.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,7 @@ module.exports = function() {
currentPos = parserInput.i;

if (!current.length) {
if (j < chunks.length - 1)
{
if (j < chunks.length - 1) {
current = chunks[++j];
skipWhitespace(0); // skip space at the beginning of a chunk
return true; // things changed
Expand Down
9 changes: 3 additions & 6 deletions lib/less/parser/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,7 @@ var Parser = function Parser(context, imports, fileInfo) {
primary: function () {
var mixin = this.mixin, root = [], node;

while (true)
{
while (true) {
while (true) {
node = this.comment();
if (!node) { break; }
Expand Down Expand Up @@ -1207,8 +1206,7 @@ var Parser = function Parser(context, imports, fileInfo) {
features = features && new(tree.Value)(features);
return new(tree.Import)(path, features, options, index, fileInfo);
}
else
{
else {
parserInput.i = index;
error("malformed import statement");
}
Expand Down Expand Up @@ -1360,8 +1358,7 @@ var Parser = function Parser(context, imports, fileInfo) {

return new(tree.Import)(path, null, options, index, fileInfo);
}
else
{
else {
parserInput.i = index;
error("malformed plugin statement");
}
Expand Down
3 changes: 1 addition & 2 deletions lib/less/source-map-output.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,7 @@ module.exports = function (environment) {

if (this._outputSourceFiles) {
for (var filename in this._contentsMap) {
if (this._contentsMap.hasOwnProperty(filename))
{
if (this._contentsMap.hasOwnProperty(filename)) {
var source = this._contentsMap[filename];
if (this._contentsIgnoredCharsMap[filename]) {
source = source.slice(this._contentsIgnoredCharsMap[filename]);
Expand Down
2 changes: 1 addition & 1 deletion lib/less/tree/dimension.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ Dimension.prototype.convertTo = function (conversions) {
conversions = derivedConversions;
}
applyUnit = function (atomicUnit, denominator) {
/*jshint loopfunc:true */
/* jshint loopfunc:true */
if (group.hasOwnProperty(atomicUnit)) {
if (denominator) {
value = value / (group[atomicUnit] / group[targetUnit]);
Expand Down
18 changes: 11 additions & 7 deletions lib/less/tree/import.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,11 @@ Import.prototype.isVariableImport = function () {
};
Import.prototype.evalForImport = function (context) {
var path = this.path;

if (path instanceof URL) {
path = path.value;
}

return new Import(path.eval(context), this.features, this.options, this.index, this.currentFileInfo);
};
Import.prototype.evalPath = function (context) {
Expand All @@ -108,6 +110,14 @@ Import.prototype.eval = function (context) {
var ruleset, registry,
features = this.features && this.features.eval(context);

if (this.options.plugin) {
registry = context.frames[0] && context.frames[0].functionRegistry;
if ( registry && this.root && this.root.functions ) {
registry.addMultiple( this.root.functions );
}
return [];
}

if (this.skip) {
if (typeof this.skip === "function") {
this.skip = this.skip();
Expand All @@ -117,13 +127,7 @@ Import.prototype.eval = function (context) {
}
}

if (this.options.plugin) {
registry = context.frames[0] && context.frames[0].functionRegistry;
if ( registry && this.root.functions ) {
registry.addMultiple( this.root.functions );
}
return [];
} else if (this.options.inline) {
if (this.options.inline) {
var contents = new Anonymous(this.root, 0, {filename: this.importedFilename}, true, true);
return this.features ? new Media([contents], this.features.value) : [contents];
} else if (this.css) {
Expand Down
1 change: 1 addition & 0 deletions lib/less/tree/media.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ Media.prototype.eval = function (context) {
context.mediaPath.push(media);
context.mediaBlocks.push(media);

this.rules[0].functionRegistry = context.frames[0].functionRegistry.inherit();
context.frames.unshift(this.rules[0]);
media.rules = [this.rules[0].eval(context)];
context.frames.shift();
Expand Down
4 changes: 3 additions & 1 deletion lib/less/tree/mixin-definition.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ Definition.prototype.evalParams = function (context, mixinEnv, args, evaldArgume
params = this.params.slice(0),
i, j, val, name, isNamedFound, argIndex, argsLength = 0;

if (mixinEnv.frames && mixinEnv.frames[0] && mixinEnv.frames[0].functionRegistry) {
frame.functionRegistry = mixinEnv.frames[0].functionRegistry.inherit();
}
mixinEnv = new contexts.Eval(mixinEnv, [frame].concat(mixinEnv.frames));
frame.functionRegistry = context.frames[0].functionRegistry.inherit();

if (args) {
args = args.slice(0);
Expand Down
11 changes: 10 additions & 1 deletion lib/less/tree/ruleset.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,16 @@ Ruleset.prototype.eval = function (context) {

// inherit a function registry from the frames stack when possible;
// otherwise from the global registry
ruleset.functionRegistry = ((context.frames[0] && context.frames[0].functionRegistry) || globalFunctionRegistry).inherit();
ruleset.functionRegistry = (function (frames) {
var i = 0,
n = frames.length,
found;
for ( ; i !== n ; ++i ) {
found = frames[ i ].functionRegistry;
if ( found ) { return found; }
}
return globalFunctionRegistry;
}(context.frames)).inherit();

// push the current ruleset to the frames stack
var ctxFrames = context.frames;
Expand Down
3 changes: 1 addition & 2 deletions lib/less/visitors/extend-visitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,7 @@ ProcessExtendsVisitor.prototype = {
if (iterationCount > 100) {
var selectorOne = "{unable to calculate}";
var selectorTwo = "{unable to calculate}";
try
{
try {
selectorOne = extendsToAdd[0].selfSelectors[0].toCSS();
selectorTwo = extendsToAdd[0].selector.toCSS();
}
Expand Down
14 changes: 12 additions & 2 deletions lib/less/visitors/import-visitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ ImportVisitor.prototype = {

var importVisitor = this,
inlineCSS = importNode.options.inline,
isPlugin = importNode.options.plugin,
duplicateImport = importedAtRoot || fullPath in importVisitor.recursionDetector;

if (!context.importMultiple) {
Expand All @@ -123,7 +124,7 @@ ImportVisitor.prototype = {
importNode.root = root;
importNode.importedFilename = fullPath;

if (!inlineCSS && (context.importMultiple || !duplicateImport)) {
if (!inlineCSS && !isPlugin && (context.importMultiple || !duplicateImport)) {
importVisitor.recursionDetector[fullPath] = true;

var oldContext = this.context;
Expand All @@ -144,7 +145,16 @@ ImportVisitor.prototype = {
}
},
visitRule: function (ruleNode, visitArgs) {
visitArgs.visitDeeper = false;
if (ruleNode.value.type === "DetachedRuleset") {
this.context.frames.unshift(ruleNode);
} else {
visitArgs.visitDeeper = false;
}
},
visitRuleOut : function(ruleNode) {
if (ruleNode.value.type === "DetachedRuleset") {
this.context.frames.shift();
}
},
visitDirective: function (directiveNode, visitArgs) {
this.context.frames.unshift(directiveNode);
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"jam": {
"main": "./dist/less.js"
},
"browser": "./dist/less.js",
"engines": {
"node": ">=0.10.0"
},
Expand All @@ -58,7 +59,7 @@
"grunt-contrib-jasmine": "^0.8.2",
"grunt-contrib-jshint": "^0.11.0",
"grunt-contrib-uglify": "^0.8.0",
"grunt-jscs": "^1.2.0",
"grunt-jscs": "^1.6.0",
"grunt-shell": "^1.1.1",
"grunt-browserify": "~3.5.0",
"jit-grunt": "^0.9.1",
Expand Down
3 changes: 2 additions & 1 deletion test/browser/runner-global-vars-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ var less = {
errorReporting: "console",
globalVars: {
"@global-var": "red"
}};
}
};
22 changes: 11 additions & 11 deletions test/browser/runner-main-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ var less = {
};
less.strictMath = true;
less.functions = {
add: function(a, b) {
return new(less.tree.Dimension)(a.value + b.value);
},
increment: function(a) {
return new(less.tree.Dimension)(a.value + 1);
},
_color: function(str) {
if (str.value === "evil red") {
return new(less.tree.Color)("600");
}
}
add: function(a, b) {
return new(less.tree.Dimension)(a.value + b.value);
},
increment: function(a) {
return new(less.tree.Dimension)(a.value + 1);
},
_color: function(str) {
if (str.value === "evil red") {
return new(less.tree.Color)("600");
}
}
};
6 changes: 0 additions & 6 deletions test/css/import-plugin-scoped.css

This file was deleted.

6 changes: 0 additions & 6 deletions test/css/import-plugin-tiered.css

This file was deleted.

3 changes: 0 additions & 3 deletions test/css/import-plugin.css

This file was deleted.

44 changes: 44 additions & 0 deletions test/css/plugin.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
.other {
trans: transitive;
}
.class {
trans: transitive;
global: global;
local: test-local();
shadow: global;
}
.class .local {
global: global;
local: local;
shadow: local;
}
.class {
ns-mixin-global: global;
ns-mixin-local: local;
ns-mixin-shadow: local;
mixin-local: local;
mixin-global: global;
mixin-shadow: local;
ruleset-local: local;
ruleset-global: global;
ruleset-shadow: local;
class-local: test-local();
}
@media screen {
.test {
result: global;
}
}
@font-face {
result: global;
}
@media screen and (min-width: 100px) and (max-width: 400px) {
.test {
result: global;
}
}
@media screen {
.test {
result: local;
}
}
9 changes: 0 additions & 9 deletions test/less/import-plugin-scoped.less

This file was deleted.

5 changes: 0 additions & 5 deletions test/less/import-plugin-tiered.less

This file was deleted.

5 changes: 0 additions & 5 deletions test/less/import-plugin.less

This file was deleted.

Loading

0 comments on commit ea43e7d

Please sign in to comment.