How to use the stylus/lib/nodes.filename function in stylus

To help you get started, we’ve selected a few stylus examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github shama / stylus-loader / lib / evaluator.js View on Github external
// Expose imports
  node.path = file;
  node.dirname = dirname(file);
  // Store the modified time
  stat = fs.statSync(file);
  node.mtime = stat.mtime;
  this.paths.push(node.dirname);

  // Avoid overflows from importing the same file over again
  if (file === importStack[importStack.length - 1]) return nodes.null;

  if (this.options._imports) this.options._imports.push(node.clone());

  // Parse the file
  importStack.push(file);
  nodes.filename = file;

  var str;
  if (this.cache.sources && this.cache.sources[file]) {
    str = this.cache.sources[file];
  } else {
    str = fs.readFileSync(file, 'utf8');
  }

  if (literal && !this.resolveURL) return new nodes.Literal(str.replace(/\r\n?/g, '\n'));

  // parse
  var block = new nodes.Block
    , parser = new Parser(str, utils.merge({ root: block }, this.options));

  try {
    block = parser.parse();
github mockingbot / ibot / scripts / stylus-enhanced-evaluator.js View on Github external
// Expose imports
  node.path = file
  node.dirname = path.dirname(file)
  // Store the modified time
  stat = fs.statSync(file)
  node.mtime = stat.mtime
  this.paths.push(node.dirname)

  // Avoid overflows from importing the same file over again
  if (file === importStack[importStack.length - 1]) return nodes.null

  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 && !this.resolveURL)
    return new nodes.Literal(str.replace(/\r\n?/g, "\n"))

  // parse
  var block = new nodes.Block(),
    parser = new Parser(str, utils.merge({ root: block }, this.options))

  try {
    block = parser.parse()
  } catch (err) {
    err.filename = file
    err.lineno = parser.lexer.lineno
    err.input = str