mirror of
https://github.com/less/less.js.git
synced 2026-05-01 03:00:22 -04:00
Rename @plugin to @use extensions
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
var LessError = require('../less-error'),
|
||||
tree = require("../tree");
|
||||
tree = require("../tree"),
|
||||
less = require("../.");
|
||||
|
||||
var FunctionImporter = module.exports = function FunctionImporter(context, fileInfo) {
|
||||
var ExtensionImporter = module.exports = function ExtensionImporter(context, fileInfo) {
|
||||
this.fileInfo = fileInfo;
|
||||
};
|
||||
|
||||
FunctionImporter.prototype.eval = function(contents, callback) {
|
||||
ExtensionImporter.prototype.eval = function(contents, callback) {
|
||||
var loaded = {},
|
||||
loader,
|
||||
registry;
|
||||
@@ -22,11 +23,11 @@ FunctionImporter.prototype.eval = function(contents, callback) {
|
||||
};
|
||||
|
||||
try {
|
||||
loader = new Function("functions", "tree", "fileInfo", contents);
|
||||
loader(registry, tree, this.fileInfo);
|
||||
loader = new Function("functions", "tree", "fileInfo", "less", contents);
|
||||
loader(registry, tree, this.fileInfo, less);
|
||||
} catch(e) {
|
||||
callback(new LessError({
|
||||
message: "Plugin evaluation error: '" + e.name + ': ' + e.message.replace(/["]/g, "'") + "'" ,
|
||||
message: "Extension evaluation error: '" + e.name + ': ' + e.message.replace(/["]/g, "'") + "'" ,
|
||||
filename: this.fileInfo.filename
|
||||
}), null );
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
var contexts = require("./contexts"),
|
||||
Parser = require('./parser/parser'),
|
||||
FunctionImporter = require('./plugins/function-importer');
|
||||
ExtensionImporter = require('./extension/importer');
|
||||
|
||||
module.exports = function(environment) {
|
||||
|
||||
@@ -66,7 +66,7 @@ module.exports = function(environment) {
|
||||
}
|
||||
|
||||
if (tryAppendLessExtension) {
|
||||
path = fileManager.tryAppendExtension(path, importOptions.plugin ? ".js" : ".less");
|
||||
path = fileManager.tryAppendExtension(path, importOptions.isExtension ? ".js" : ".less");
|
||||
}
|
||||
|
||||
var loadFileCallback = function(loadedFile) {
|
||||
@@ -102,8 +102,8 @@ module.exports = function(environment) {
|
||||
newFileInfo.reference = true;
|
||||
}
|
||||
|
||||
if (importOptions.plugin) {
|
||||
new FunctionImporter(newEnv, newFileInfo).eval(contents, function (e, root) {
|
||||
if (importOptions.isExtension) {
|
||||
new ExtensionImporter(newEnv, newFileInfo).eval(contents, function (e, root) {
|
||||
fileParsedFunc(e, root, resolvedFilename);
|
||||
});
|
||||
} else if (importOptions.inline) {
|
||||
|
||||
@@ -2,7 +2,7 @@ module.exports = function(environment, fileManagers) {
|
||||
var SourceMapOutput, SourceMapBuilder, ParseTree, ImportManager, Environment;
|
||||
|
||||
var less = {
|
||||
version: [2, 7, 1],
|
||||
version: [2, 8, 0],
|
||||
data: require('./data'),
|
||||
tree: require('./tree'),
|
||||
Environment: (Environment = require("./environment/environment")),
|
||||
|
||||
@@ -1384,35 +1384,39 @@ var Parser = function Parser(context, imports, fileInfo) {
|
||||
},
|
||||
|
||||
//
|
||||
// A @plugin directive, used to import compiler extensions dynamically.
|
||||
// A @use directive, used to import scoped extensions dynamically.
|
||||
//
|
||||
// @plugin "lib";
|
||||
// @use "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 () {
|
||||
extension: function () {
|
||||
var path,
|
||||
index = parserInput.i,
|
||||
dir = parserInput.$re(/^@plugin?\s+/);
|
||||
dir = parserInput.$re(/^@use?|@plugin?\s+/);
|
||||
|
||||
if (dir && dir.indexOf("@p") > -1) {
|
||||
parserInput.i -= dir.length;
|
||||
return error('@plugin is deprecated. Use @use');
|
||||
}
|
||||
if (dir) {
|
||||
var options = { plugin : true };
|
||||
var options = { isExtension : true };
|
||||
|
||||
if ((path = this.entities.quoted() || this.entities.url())) {
|
||||
|
||||
if (!parserInput.$char(';')) {
|
||||
parserInput.i = index;
|
||||
error("missing semi-colon on plugin");
|
||||
error("missing semi-colon on @use");
|
||||
}
|
||||
|
||||
return new(tree.Import)(path, null, options, index, fileInfo);
|
||||
}
|
||||
else {
|
||||
parserInput.i = index;
|
||||
error("malformed plugin statement");
|
||||
error("malformed @use statement");
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -1428,7 +1432,7 @@ var Parser = function Parser(context, imports, fileInfo) {
|
||||
|
||||
if (parserInput.currentChar() !== '@') { return; }
|
||||
|
||||
value = this['import']() || this.plugin() || this.media();
|
||||
value = this['import']() || this.extension() || this.media();
|
||||
if (value) {
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ Import.prototype.accept = function (visitor) {
|
||||
this.features = visitor.visit(this.features);
|
||||
}
|
||||
this.path = visitor.visit(this.path);
|
||||
if (!this.options.plugin && !this.options.inline && this.root) {
|
||||
if (!this.options.isExtension && !this.options.inline && this.root) {
|
||||
this.root = visitor.visit(this.root);
|
||||
}
|
||||
};
|
||||
@@ -126,7 +126,7 @@ Import.prototype.doEval = function (context) {
|
||||
var ruleset, registry,
|
||||
features = this.features && this.features.eval(context);
|
||||
|
||||
if (this.options.plugin) {
|
||||
if (this.options.isExtension) {
|
||||
registry = context.frames[0] && context.frames[0].functionRegistry;
|
||||
if ( registry && this.root && this.root.functions ) {
|
||||
registry.addMultiple( this.root.functions );
|
||||
|
||||
@@ -103,7 +103,7 @@ ImportVisitor.prototype = {
|
||||
|
||||
var importVisitor = this,
|
||||
inlineCSS = importNode.options.inline,
|
||||
isPlugin = importNode.options.plugin,
|
||||
isExtension = importNode.options.isExtension,
|
||||
isOptional = importNode.options.optional,
|
||||
duplicateImport = importedAtRoot || fullPath in importVisitor.recursionDetector;
|
||||
|
||||
@@ -129,7 +129,7 @@ ImportVisitor.prototype = {
|
||||
importNode.root = root;
|
||||
importNode.importedFilename = fullPath;
|
||||
|
||||
if (!inlineCSS && !isPlugin && (context.importMultiple || !duplicateImport)) {
|
||||
if (!inlineCSS && !isExtension && (context.importMultiple || !duplicateImport)) {
|
||||
importVisitor.recursionDetector[fullPath] = true;
|
||||
|
||||
var oldContext = this.context;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "less",
|
||||
"version": "2.7.1",
|
||||
"version": "2.8.0",
|
||||
"description": "Leaner CSS",
|
||||
"homepage": "http://lesscss.org",
|
||||
"author": {
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
@plugin "../plugin/plugin-tree-nodes";
|
||||
@use "../extension/extension-tree-nodes";
|
||||
test-undefined();
|
||||
@@ -1,3 +1,3 @@
|
||||
SyntaxError: Function 'test-undefined' is undefined in {path}functions-1.less on line 2, column 1:
|
||||
1 @plugin "../plugin/plugin-tree-nodes";
|
||||
1 @use "../extension/extension-tree-nodes";
|
||||
2 test-undefined();
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
@plugin "../plugin/plugin-tree-nodes";
|
||||
@use "../extension/extension-tree-nodes";
|
||||
test-keyword();
|
||||
@@ -1,3 +1,3 @@
|
||||
SyntaxError: Keyword node returned by a function is not valid here in {path}functions-10-keyword.less on line 2, column 1:
|
||||
1 @plugin "../plugin/plugin-tree-nodes";
|
||||
1 @use "../extension/extension-tree-nodes";
|
||||
2 test-keyword();
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
@plugin "../plugin/plugin-tree-nodes";
|
||||
@use "../extension/extension-tree-nodes";
|
||||
test-operation();
|
||||
@@ -1,3 +1,3 @@
|
||||
SyntaxError: Operation node returned by a function is not valid here in {path}functions-11-operation.less on line 2, column 1:
|
||||
1 @plugin "../plugin/plugin-tree-nodes";
|
||||
1 @use "../extension/extension-tree-nodes";
|
||||
2 test-operation();
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
@plugin "../plugin/plugin-tree-nodes";
|
||||
@use "../extension/extension-tree-nodes";
|
||||
test-quoted();
|
||||
@@ -1,3 +1,3 @@
|
||||
SyntaxError: Quoted node returned by a function is not valid here in {path}functions-12-quoted.less on line 2, column 1:
|
||||
1 @plugin "../plugin/plugin-tree-nodes";
|
||||
1 @use "../extension/extension-tree-nodes";
|
||||
2 test-quoted();
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
@plugin "../plugin/plugin-tree-nodes";
|
||||
@use "../extension/extension-tree-nodes";
|
||||
test-selector();
|
||||
@@ -1,3 +1,3 @@
|
||||
SyntaxError: Selector node returned by a function is not valid here in {path}functions-13-selector.less on line 2, column 1:
|
||||
1 @plugin "../plugin/plugin-tree-nodes";
|
||||
1 @use "../extension/extension-tree-nodes";
|
||||
2 test-selector();
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
@plugin "../plugin/plugin-tree-nodes";
|
||||
@use "../extension/extension-tree-nodes";
|
||||
test-url();
|
||||
@@ -1,3 +1,3 @@
|
||||
SyntaxError: Url node returned by a function is not valid here in {path}functions-14-url.less on line 2, column 1:
|
||||
1 @plugin "../plugin/plugin-tree-nodes";
|
||||
1 @use "../extension/extension-tree-nodes";
|
||||
2 test-url();
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
@plugin "../plugin/plugin-tree-nodes";
|
||||
@use "../extension/extension-tree-nodes";
|
||||
test-value();
|
||||
@@ -1,3 +1,3 @@
|
||||
SyntaxError: Value node returned by a function is not valid here in {path}functions-15-value.less on line 2, column 1:
|
||||
1 @plugin "../plugin/plugin-tree-nodes";
|
||||
1 @use "../extension/extension-tree-nodes";
|
||||
2 test-value();
|
||||
|
||||
1
test/less/errors/functions-16-old-syntax.less
Normal file
1
test/less/errors/functions-16-old-syntax.less
Normal file
@@ -0,0 +1 @@
|
||||
@plugin "../extension/extension-tree-nodes";
|
||||
2
test/less/errors/functions-16-old-syntax.txt
Normal file
2
test/less/errors/functions-16-old-syntax.txt
Normal file
@@ -0,0 +1,2 @@
|
||||
SyntaxError: @plugin is deprecated. Use @use in {path}functions-16-old-syntax.less on line 1, column 1:
|
||||
1 @plugin "../extension/extension-tree-nodes";
|
||||
@@ -1,2 +1,2 @@
|
||||
@plugin "../plugin/plugin-tree-nodes";
|
||||
@use "../extension/extension-tree-nodes";
|
||||
test-alpha();
|
||||
@@ -1,3 +1,3 @@
|
||||
SyntaxError: Alpha node returned by a function is not valid here in {path}functions-2-alpha.less on line 2, column 1:
|
||||
1 @plugin "../plugin/plugin-tree-nodes";
|
||||
1 @use "../extension/extension-tree-nodes";
|
||||
2 test-alpha();
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
@plugin "../plugin/plugin-tree-nodes";
|
||||
@use "../extension/extension-tree-nodes";
|
||||
test-assignment();
|
||||
@@ -1,3 +1,3 @@
|
||||
SyntaxError: Assignment node returned by a function is not valid here in {path}functions-3-assignment.less on line 2, column 1:
|
||||
1 @plugin "../plugin/plugin-tree-nodes";
|
||||
1 @use "../extension/extension-tree-nodes";
|
||||
2 test-assignment();
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
@plugin "../plugin/plugin-tree-nodes";
|
||||
@use "../extension/extension-tree-nodes";
|
||||
test-call();
|
||||
@@ -1,3 +1,3 @@
|
||||
SyntaxError: Function 'foo' is undefined in {path}functions-4-call.less on line 2, column 1:
|
||||
1 @plugin "../plugin/plugin-tree-nodes";
|
||||
1 @use "../extension/extension-tree-nodes";
|
||||
2 test-call();
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
@plugin "../plugin/plugin-tree-nodes";
|
||||
@use "../extension/extension-tree-nodes";
|
||||
test-color();
|
||||
@@ -1,3 +1,3 @@
|
||||
SyntaxError: Color node returned by a function is not valid here in {path}functions-5-color.less on line 2, column 1:
|
||||
1 @plugin "../plugin/plugin-tree-nodes";
|
||||
1 @use "../extension/extension-tree-nodes";
|
||||
2 test-color();
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
@plugin "../plugin/plugin-tree-nodes";
|
||||
@use "../extension/extension-tree-nodes";
|
||||
test-condition();
|
||||
@@ -1,3 +1,3 @@
|
||||
SyntaxError: Condition node returned by a function is not valid here in {path}functions-6-condition.less on line 2, column 1:
|
||||
1 @plugin "../plugin/plugin-tree-nodes";
|
||||
1 @use "../extension/extension-tree-nodes";
|
||||
2 test-condition();
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
@plugin "../plugin/plugin-tree-nodes";
|
||||
@use "../extension/extension-tree-nodes";
|
||||
test-dimension();
|
||||
@@ -1,3 +1,3 @@
|
||||
SyntaxError: Dimension node returned by a function is not valid here in {path}functions-7-dimension.less on line 2, column 1:
|
||||
1 @plugin "../plugin/plugin-tree-nodes";
|
||||
1 @use "../extension/extension-tree-nodes";
|
||||
2 test-dimension();
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
@plugin "../plugin/plugin-tree-nodes";
|
||||
@use "../extension/extension-tree-nodes";
|
||||
test-element();
|
||||
@@ -1,3 +1,3 @@
|
||||
SyntaxError: Element node returned by a function is not valid here in {path}functions-8-element.less on line 2, column 1:
|
||||
1 @plugin "../plugin/plugin-tree-nodes";
|
||||
1 @use "../extension/extension-tree-nodes";
|
||||
2 test-element();
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
@plugin "../plugin/plugin-tree-nodes";
|
||||
@use "../extension/extension-tree-nodes";
|
||||
test-expression();
|
||||
@@ -1,3 +1,3 @@
|
||||
SyntaxError: Expression node returned by a function is not valid here in {path}functions-9-expression.less on line 2, column 1:
|
||||
1 @plugin "../plugin/plugin-tree-nodes";
|
||||
1 @use "../extension/extension-tree-nodes";
|
||||
2 test-expression();
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
@plugin "../plugin/plugin-tree-nodes.js";
|
||||
@use "../extension/extension-tree-nodes.js";
|
||||
test-undefined();
|
||||
@@ -1,3 +1,3 @@
|
||||
SyntaxError: Function 'test-undefined' is undefined in {path}root-func-undefined-2.less on line 2, column 1:
|
||||
1 @plugin "../plugin/plugin-tree-nodes.js";
|
||||
1 @use "../extension/extension-tree-nodes.js";
|
||||
2 test-undefined();
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
@plugin "plugin-transitive";
|
||||
@use "extension-transitive";
|
||||
|
||||
.other {
|
||||
trans : test-transitive();
|
||||
@@ -1,8 +1,8 @@
|
||||
// importing plugin globally
|
||||
@plugin "./plugin/plugin-global";
|
||||
@use "./extension/extension-global";
|
||||
|
||||
// transitively include plugins from importing another sheet
|
||||
@import "./plugin/plugin-transitive";
|
||||
@import "./extension/extension-transitive";
|
||||
|
||||
|
||||
// `test-global` function should be reachable
|
||||
@@ -18,7 +18,7 @@
|
||||
// `test-local` function should be reachable
|
||||
// `test-shadow` function should return local version, shadowing global version
|
||||
.local {
|
||||
@plugin "./plugin/plugin-local";
|
||||
@use "./extension/extension-local";
|
||||
global : test-global();
|
||||
local : test-local();
|
||||
shadow : test-shadow();
|
||||
@@ -28,19 +28,19 @@
|
||||
// calling a mixin or detached ruleset should not bubble local plugins
|
||||
// imported inside either into the parent scope.
|
||||
.mixin() {
|
||||
@plugin "./plugin/plugin-local";
|
||||
@use "./extension/extension-local";
|
||||
mixin-local : test-local();
|
||||
mixin-global : test-global();
|
||||
mixin-shadow : test-shadow();
|
||||
}
|
||||
@ruleset : {
|
||||
@plugin "./plugin/plugin-local";
|
||||
@use "./extension/extension-local";
|
||||
ruleset-local : test-local();
|
||||
ruleset-global : test-global();
|
||||
ruleset-shadow : test-shadow();
|
||||
};
|
||||
#ns {
|
||||
@plugin "./plugin/plugin-local";
|
||||
@use "./extension/extension-local";
|
||||
.mixin() {
|
||||
ns-mixin-global : test-global();
|
||||
ns-mixin-local : test-local();
|
||||
@@ -76,12 +76,12 @@
|
||||
|
||||
.test {
|
||||
@media screen {
|
||||
@plugin "./plugin/plugin-local";
|
||||
@use "./extension/extension-local";
|
||||
result : test-local();
|
||||
}
|
||||
}
|
||||
|
||||
@plugin "./plugin/plugin-tree-nodes";
|
||||
@use "./extension/extension-tree-nodes";
|
||||
@ruleset2: test-detached-ruleset();
|
||||
.root {
|
||||
@ruleset2();
|
||||
|
||||
Reference in New Issue
Block a user