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:
rjgotten
2015-03-15 11:05:37 +01:00
parent a9e0848b6e
commit 9518763128
3 changed files with 39 additions and 4 deletions

View File

@@ -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;
}

View File

@@ -1,5 +1,5 @@
.in-scope {
@import (plugin) "./plugins/test";
@plugin "./plugins/test";
result : test();
}

View File

@@ -1,4 +1,4 @@
@import (plugin) "./plugins/test";
@plugin "./plugins/test";
.test {
result : test();