updated node modules

This commit is contained in:
Marc Wäckerlin
2016-09-12 14:54:14 +00:00
parent d7955e5d0f
commit d2455ba530
560 changed files with 94515 additions and 37458 deletions

View File

@@ -8,10 +8,12 @@ var nodes = require('../nodes');
*/
module.exports = function currentMedia(){
var self = this;
return new nodes.String(lookForMedia(this.closestBlock.node) || '');
function lookForMedia(node){
if ('media' == node.nodeName) {
node.val = self.visit(node.val);
return node.toString();
} else if (node.block.parent.node) {
return lookForMedia(node.block.parent.node);

View File

@@ -6,13 +6,17 @@ var utils = require('../utils')
*
* @param {String} name
* @param {Expression} expr
* @param {Boolean} [global]
* @api public
*/
module.exports = function define(name, expr){
module.exports = function define(name, expr, global){
utils.assertType(name, 'string', 'name');
expr = utils.unwrap(expr);
var scope = this.currentScope;
if (global && global.toBoolean().isTrue) {
scope = this.global.scope;
}
var node = new nodes.Ident(name.val, expr);
scope.add(node);
return nodes.null;

View File

@@ -55,6 +55,7 @@ exports.selectors = require('./selectors');
exports.shift = require('./shift');
exports.split = require('./split');
exports.substr = require('./substr');
exports.slice = require('./slice');
exports.tan = require('./tan');
exports.trace = require('./trace');
exports.transparentify = require('./transparentify');

View File

@@ -284,3 +284,14 @@ cache()
/$cache_placeholder_for_{$id}
$stylus_mixin_cache[$key] = $id
{block}
// Percentage function to convert a number, e.g. ".45", into a percentage, e.g. "45%"
percentage(num)
return unit(num * 100, '%')
// Returns the position of a `value` within a `list`
index(list, value)
for val, i in list
return i if val == value

View File

@@ -1,29 +1,43 @@
var utils = require('../utils')
, nodes = require('../nodes');
var VALID_FLAGS = 'igm';
/**
* Test if `val` matches the given `pattern`.
* retrieves the matches when matching a `val`(string)
* against a `pattern`(regular expression).
*
* Examples:
* $regex = '^(height|width)?([<>=]{1,})(.*)'
*
* match('^foo(bar)?', foo)
* match('^foo(bar)?', foobar)
* match('^foo(bar)?', 'foo')
* match('^foo(bar)?', 'foobar')
* // => true
* match($regex,'height>=sm')
* // => ('height>=sm' 'height' '>=' 'sm')
* // => also truthy
*
* match('^foo(bar)?', 'bar')
* // => false
* match($regex, 'lorem ipsum')
* // => null
*
* @param {String} pattern
* @param {String|Ident} val
* @return {Boolean}
* @param {String|Ident} [flags='']
* @return {String|Null}
* @api public
*/
module.exports = function match(pattern, val){
module.exports = function match(pattern, val, flags){
utils.assertType(pattern, 'string', 'pattern');
utils.assertString(val, 'val');
var re = new RegExp(pattern.val);
return new nodes.Boolean(re.test(val.string));
var re = new RegExp(pattern.val, validateFlags(flags) ? flags.string : '');
return val.string.match(re);
};
function validateFlags(flags) {
flags = flags && flags.string;
if (flags) {
return flags.split('').every(function(flag) {
return ~VALID_FLAGS.indexOf(flag);
});
}
return false;
}

28
nodejs/node_modules/stylus/lib/functions/slice.js generated vendored Normal file
View File

@@ -0,0 +1,28 @@
var utils = require('../utils'),
nodes = require('../nodes');
/**
* This is a heler function for the slice method
*
* @param {String|Ident} vals
* @param {Unit} start [0]
* @param {Unit} end [vals.length]
* @return {String|Literal|Null}
* @api public
*/
(module.exports = function slice(val, start, end) {
start = start && start.nodes[0].val;
end = end && end.nodes[0].val;
val = utils.unwrap(val).nodes;
if (val.length > 1) {
return utils.coerce(val.slice(start, end), true);
}
var result = val[0].string.slice(start, end);
return val[0] instanceof nodes.Ident
? new nodes.Ident(result)
: new nodes.String(result);
}).raw = true;

View File

@@ -34,6 +34,14 @@ var defaultMimes = {
, '.woff2': 'application/font-woff2'
};
/**
* Supported encoding types
*/
var encodingTypes = {
BASE_64: 'base64',
UTF8: 'charset=utf-8'
}
/**
* Return a url() function with the given `options`.
*
@@ -61,9 +69,16 @@ module.exports = function(options) {
var sizeLimit = null != options.limit ? options.limit : 30000;
var mimes = options.mimes || defaultMimes;
function fn(url){
/**
* @param {object} url - The path to the image you want to encode.
* @param {object} enc - The encoding for the image. Defaults to base64, the
* other valid option is `utf8`.
*/
function fn(url, enc){
// Compile the url
var compiler = new Compiler(url);
var compiler = new Compiler(url)
, encoding = encodingTypes.BASE_64;
compiler.isURL = true;
url = url.nodes.map(function(node){
return compiler.visit(node);
@@ -76,7 +91,8 @@ module.exports = function(options) {
, hash = url.hash || ''
, literal = new nodes.Literal('url("' + url.href + '")')
, paths = _paths.concat(this.paths)
, buf;
, buf
, result;
// Not supported
if (!mime) return literal;
@@ -103,8 +119,18 @@ module.exports = function(options) {
// Too large
if (false !== sizeLimit && buf.length > sizeLimit) return literal;
if (enc && 'utf8' == enc.first.val.toLowerCase()) {
encoding = encodingTypes.UTF8;
result = buf.toString('utf8').replace(/\s+/g, ' ')
.replace(/[{}\|\\\^~\[\]`"<>#%]/g, function(match) {
return '%' + match[0].charCodeAt(0).toString(16).toUpperCase();
}).trim();
} else {
result = buf.toString(encoding) + hash;
}
// Encode
return new nodes.Literal('url("data:' + mime + ';base64,' + buf.toString('base64') + hash + '")');
return new nodes.Literal('url("data:' + mime + ';' + encoding + ',' + result + '")');
};
fn.raw = true;

View File

@@ -81,7 +81,7 @@ function Lexer(str, options) {
.replace(/\s+$/, '\n')
.replace(/\r\n?/g, '\n')
.replace(/\\ *\n/g, '\r')
.replace(/([,(:](?!\/\/[^ ])) *(?:\/\/[^\n]*)?\n\s*/g, comment)
.replace(/([,(:](?!\/\/[^ ])) *(?:\/\/[^\n]*|\/\*.*?\*\/)?\n\s*/g, comment)
.replace(/\s*\n[ \t]*([,)])/g, comment);
};

View File

@@ -174,7 +174,7 @@ Node.prototype = {
operate: function(op, right){
switch (op) {
case 'is a':
if ('string' == right.nodeName) {
if ('string' == right.first.nodeName) {
return nodes.Boolean(this.nodeName == right.val);
} else {
throw new Error('"is a" expects a string, got ' + right.toString());

View File

@@ -1633,7 +1633,8 @@ Parser.prototype = {
switch (op.type) {
case '?=':
var defined = new nodes.BinOp('is defined', node)
, lookup = new nodes.Ident(name);
, lookup = new nodes.Expression;
lookup.push(new nodes.Ident(name));
node = new nodes.Ternary(defined, lookup, node);
break;
case '+=':

View File

@@ -126,23 +126,24 @@ Renderer.prototype.render = function(fn){
*/
Renderer.prototype.deps = function(filename){
if (filename) this.options.filename = filename;
var opts = utils.merge({ cache: false }, this.options);
if (filename) opts.filename = filename;
var DepsResolver = require('./visitor/deps-resolver')
, parser = new Parser(this.str, this.options);
, parser = new Parser(this.str, opts);
try {
nodes.filename = this.options.filename;
nodes.filename = opts.filename;
// parse
var ast = parser.parse()
, resolver = new DepsResolver(ast, this.options);
, resolver = new DepsResolver(ast, opts);
// resolve dependencies
return resolver.resolve();
} catch (err) {
var options = {};
options.input = err.input || this.str;
options.filename = err.filename || this.options.filename;
options.filename = err.filename || opts.filename;
options.lineno = err.lineno || parser.lexer.lineno;
options.column = err.column || parser.lexer.column;
throw utils.formatException(err, options);

View File

@@ -56,6 +56,7 @@ SelectorParser.prototype.skipSpaces = function() {
SelectorParser.prototype.advance = function() {
return this.root()
|| this.relative()
|| this.initial()
|| this.escaped()
|| this.parent()
|| this.partial()
@@ -94,6 +95,18 @@ SelectorParser.prototype.relative = function(multi) {
}
};
/**
* '~/'
*/
SelectorParser.prototype.initial = function() {
if (!this.pos && '~' == this.str[0] && '/' == this.str[1]) {
this.nested = false;
this.skip(2);
return this.stack[0];
}
};
/**
* '\' ('&' | '^')
*/
@@ -114,6 +127,8 @@ SelectorParser.prototype.escaped = function() {
SelectorParser.prototype.parent = function() {
if ('&' == this.str[0]) {
this.nested = false;
if (!this.pos && (!this.stack.length || this.raw)) {
var i = 0;
while (' ' == this.str[++i]) ;
@@ -123,7 +138,6 @@ SelectorParser.prototype.parent = function() {
}
}
this.nested = false;
this.skip(1);
if (!this.raw)
return this.stack[this.stack.length - 1];
@@ -177,6 +191,7 @@ SelectorParser.prototype.number = function() {
SelectorParser.prototype.range = function() {
var start = this.number()
, ret;
if ('..' == this.str.slice(0, 2)) {
this.skip(2);
var end = this.number()
@@ -195,8 +210,10 @@ SelectorParser.prototype.range = function() {
ret = this.parts.slice(start, end + 1).map(function(part) {
var selector = new SelectorParser(part, this.stack, this.parts);
selector.raw = true;
return selector.parse().val.trim();
}, this).join(' ');
return selector.parse();
}, this).map(function(selector) {
return (selector.nested ? ' ' : '') + selector.val;
}).join('').trim();
}
} else {
ret = this.stack[

View File

@@ -462,7 +462,7 @@ exports.compileSelectors = function(arr, leaveHidden){
for (var i = 0, len = buf.length; i < len; ++i) {
parts.push(buf[i]);
parents.push(str);
child = new Parser(buf[i], parents, parts).parse();
var child = new Parser(buf[i], parents, parts).parse();
if (child.nested) {
str += ' ' + child.val;

View File

@@ -30,7 +30,6 @@ var Compiler = module.exports = function Compiler(root, options) {
this.firebug = options.firebug;
this.linenos = options.linenos;
this.spaces = options['indent spaces'] || 2;
this.includeCSS = options['include css'];
this.indents = 1;
Visitor.call(this, root);
this.stack = [];

View File

@@ -41,6 +41,15 @@ function importFile(node, file, literal) {
}
}
// Avoid overflows from importing the same file over again
if (~importStack.indexOf(file))
throw new Error('import loop has been found');
var str = fs.readFileSync(file, 'utf8');
// shortcut for empty files
if (!str.trim()) return nodes.null;
// Expose imports
node.path = file;
node.dirname = dirname(file);
@@ -49,17 +58,12 @@ function importFile(node, file, literal) {
node.mtime = stat.mtime;
this.paths.push(node.dirname);
// Avoid overflows from importing the same file over again
if (~importStack.indexOf(file))
throw new Error('import loop has been found');
if (this.options._imports) this.options._imports.push(node.clone());
// Parse the file
importStack.push(file);
nodes.filename = file;
var str = fs.readFileSync(file, 'utf8');
if (literal) {
literal = new nodes.Literal(str.replace(/\r\n?/g, '\n'));
literal.lineno = literal.column = 1;
@@ -76,7 +80,7 @@ function importFile(node, file, literal) {
var line = parser.lexer.lineno
, column = parser.lexer.column;
if (this.includeCSS && this.resolveURL) {
if (literal && this.includeCSS && this.resolveURL) {
this.warn('ParseError: ' + file + ':' + line + ':' + column + '. This file included as-is');
return literal;
} else {
@@ -213,10 +217,20 @@ Evaluator.prototype.populateGlobalScope = function(){
scope.add(node);
});
// expose url function
scope.add(new nodes.Ident(
'embedurl',
new nodes.Function('embedurl', require('../functions/url')({
limit: false
}))
));
// user-defined globals
var globals = this.globals;
Object.keys(globals).forEach(function(name){
scope.add(new nodes.Ident(name, globals[name]));
var val = globals[name];
if (!val.nodeName) val = new nodes.Literal(val);
scope.add(new nodes.Ident(name, val));
});
};
@@ -977,7 +991,7 @@ Evaluator.prototype.invokeFunction = function(fn, args, content){
var arg = args.map[node.name] || args.nodes[i++];
node = node.clone();
if (arg) {
arg.isEmpty ? args.nodes[i - 1] = node.val : node.val = arg;
arg.isEmpty ? args.nodes[i - 1] = this.visit(node) : node.val = arg;
} else {
args.push(node.val);
}
@@ -989,7 +1003,7 @@ Evaluator.prototype.invokeFunction = function(fn, args, content){
}
scope.add(node);
});
}, this);
// mixin block
if (content) scope.add(new nodes.Ident('block', content, true));

View File

@@ -38,8 +38,9 @@ var SourceMapper = module.exports = function SourceMapper(root, options){
this.basePath = sourcemap.basePath || '.';
this.inline = sourcemap.inline;
this.comment = sourcemap.comment;
if (extname(this.dest) === '.css') {
if (this.dest && extname(this.dest) === '.css') {
this.basename = basename(this.dest);
this.dest = dirname(this.dest);
} else {
this.basename = basename(this.filename, extname(this.filename)) + '.css';
}