mirror of
https://github.com/less/less.js.git
synced 2026-01-22 21:58:14 -05:00
Updated plugin import syntax
- Updated parser to recognize `@plugin` and removed parsing support for the (plugin) import option. - Updated plugin import unit tests to `@plugin` syntax
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
.in-scope {
|
||||
@import (plugin) "./plugins/test";
|
||||
@plugin "./plugins/test";
|
||||
result : test();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
@import (plugin) "./plugins/test";
|
||||
@plugin "./plugins/test";
|
||||
|
||||
.test {
|
||||
result : test();
|
||||
|
||||
Reference in New Issue
Block a user