diff --git a/lib/less/parser/parser.js b/lib/less/parser/parser.js index a6c22433..f6d45eda 100644 --- a/lib/less/parser/parser.js +++ b/lib/less/parser/parser.js @@ -1212,7 +1212,7 @@ var Parser = function Parser(context, imports, fileInfo) { }, importOption: function() { - var opt = parserInput.$re(/^(less|css|multiple|once|inline|reference|optional|plugin)/); + var opt = parserInput.$re(/^(less|css|multiple|once|inline|reference|optional)/); if (opt) { return opt[1]; } @@ -1290,6 +1290,41 @@ var Parser = function Parser(context, imports, fileInfo) { } }, + // + // A @plugin directive, used to import compiler extensions dynamically. + // + // @plugin "lib"; + // + // Depending on our environment, importing is done differently: + // In the browser, it's an XHR request, in Node, it would be a + // file-system operation. The function used for importing is + // stored in `import`, which we pass to the Import constructor. + // + plugin: function () { + var path, + index = parserInput.i, + dir = parserInput.$re(/^@plugin?\s+/); + + if (dir) { + var options = { plugin : true }; + + if ((path = this.entities.quoted() || this.entities.url())) { + + if (!parserInput.$(';')) { + parserInput.i = index; + error("missing semi-colon on plugin"); + } + + return new(tree.Import)(path, null, options, index, fileInfo); + } + else + { + parserInput.i = index; + error("malformed plugin statement"); + } + } + }, + // // A CSS Directive // @@ -1301,7 +1336,7 @@ var Parser = function Parser(context, imports, fileInfo) { if (parserInput.currentChar() !== '@') { return; } - value = this['import']() || this.media(); + value = this['import']() || this.plugin() || this.media(); if (value) { return value; } diff --git a/test/less/import-plugin-scoped.less b/test/less/import-plugin-scoped.less index a986e8dd..7c0fa782 100644 --- a/test/less/import-plugin-scoped.less +++ b/test/less/import-plugin-scoped.less @@ -1,5 +1,5 @@ .in-scope { - @import (plugin) "./plugins/test"; + @plugin "./plugins/test"; result : test(); } diff --git a/test/less/import-plugin.less b/test/less/import-plugin.less index 81c2e967..7ee43e30 100644 --- a/test/less/import-plugin.less +++ b/test/less/import-plugin.less @@ -1,4 +1,4 @@ -@import (plugin) "./plugins/test"; +@plugin "./plugins/test"; .test { result : test();