diff --git a/lib/less/parser/parser.js b/lib/less/parser/parser.js index 52cf6489..1ebe6cd1 100644 --- a/lib/less/parser/parser.js +++ b/lib/less/parser/parser.js @@ -2,7 +2,8 @@ var LessError = require('../less-error'), tree = require("../tree"), visitors = require("../visitors"), getParserInput = require("./parser-input"), - utils = require("../utils"); + utils = require("../utils"), + functionRegistry = require('../functions/function-registry'); // // less.js - parser @@ -185,6 +186,7 @@ var Parser = function Parser(context, imports, fileInfo) { tree.Node.prototype.rootNode = root; root.root = true; root.firstRoot = true; + // root.functionRegistry = functionRegistry.inherit(); } catch (e) { return callback(new LessError(e, imports, fileInfo.filename)); diff --git a/test/browser/less/plugin/plugin.js b/test/browser/less/plugin/plugin.js index 78fa62b2..8065d815 100644 --- a/test/browser/less/plugin/plugin.js +++ b/test/browser/less/plugin/plugin.js @@ -1,7 +1,7 @@ registerPlugin({ install: function(less, pluginManager, functions) { functions.add('func', function() { - return less.Anonymous(location.href); + return less.anonymous(location.href); }); } }); \ No newline at end of file diff --git a/test/index.js b/test/index.js index 0c2392bd..648d9c05 100644 --- a/test/index.js +++ b/test/index.js @@ -58,4 +58,5 @@ testMap.forEach(function(args) { lessTester.testSyncronous({syncImport: true}, "import"); lessTester.testSyncronous({syncImport: true}, "css"); lessTester.testNoOptions(); +lessTester.testJSImport(); lessTester.finished(); diff --git a/test/less-test.js b/test/less-test.js index 431fd039..9ab051d7 100644 --- a/test/less-test.js +++ b/test/less-test.js @@ -155,6 +155,24 @@ module.exports = function() { }); } + // https://github.com/less/less.js/issues/3112 + function testJSImport() { + process.stdout.write("- Testing root function registry"); + less.functions.functionRegistry.add('ext', function() { + return new less.tree.Anonymous('file'); + }); + var expected = "@charset \"utf-8\";\n"; + toCSS({}, require('path').join(process.cwd(), 'test/less/root-registry/root.less'), function(error, output) { + if (error) { + return fail("ERROR: " + error); + } + if (output.css === expected) { + return ok('OK'); + } + difference("FAIL", expected, output.css); + }); + } + function globalReplacements(input, directory, filename) { var path = require('path'); var p = filename ? path.join(path.dirname(filename), '/') : path.join(process.cwd(), directory), @@ -422,6 +440,7 @@ module.exports = function() { testEmptySourcemap: testEmptySourcemap, testNoOptions: testNoOptions, prepBomTest: prepBomTest, + testJSImport: testJSImport, finished: finished }; }; diff --git a/test/less/root-registry/file.less b/test/less/root-registry/file.less new file mode 100644 index 00000000..55cfd4ea --- /dev/null +++ b/test/less/root-registry/file.less @@ -0,0 +1 @@ +@charset "utf-8"; \ No newline at end of file diff --git a/test/less/root-registry/root.less b/test/less/root-registry/root.less new file mode 100644 index 00000000..a77c8c1e --- /dev/null +++ b/test/less/root-registry/root.less @@ -0,0 +1,3 @@ +// https://github.com/less/less.js/issues/3112 +@file: ext(); +@import '@{file}'; \ No newline at end of file