lib/visitor/evaluator.js
function importFile(node, file, literal) {
  var importStack = this.importStack
    , Parser = require('../parser')
    , stat;

  // Handling the `require`
  if (node.once) {
    if (this.requireHistory[file]) return nodes.null;
    this.requireHistory[file] = true;

    if (literal && !this.includeCSS) {
      return node;
    }
  }

  // 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);
  // Store the modified time
  stat = fs.statSync(file);
  node.mtime = stat.mtime;
  this.paths.push(node.dirname);

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

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

  if (literal) {
    literal = new nodes.Literal(str.replace(/\r\n?/g, '\n'));
    literal.lineno = literal.column = 1;
    if (!this.resolveURL) return literal;
  }

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

  try {
    block = parser.parse();
  } catch (err) {
    var line = parser.lexer.lineno
      , column = parser.lexer.column;

    if (literal && this.includeCSS && this.resolveURL) {
      this.warn('ParseError: ' + file + ':' + line + ':' + column + '. This file included as-is');
      return literal;
    } else {
      err.filename = file;
      err.lineno = line;
      err.column = column;
      err.input = str;
      throw err;
    }
  }

  // Evaluate imported "root"
  block = block.clone(this.currentBlock);
  block.parent = this.currentBlock;
  block.scope = false;
  var ret = this.visit(block);
  importStack.pop();
  if (!this.resolveURL || this.resolveURL.nocheck) this.paths.pop();

  return ret;
}
function importFile(node, file, literal) {
  var importStack = this.importStack
    , Parser = require('../parser')
    , stat;

  // Handling the `require`
  if (node.once) {
    if (this.requireHistory[file]) return nodes.null;
    this.requireHistory[file] = true;

    if (literal && !this.includeCSS) {
      return node;
    }
  }

  // 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);
  // Store the modified time
  stat = fs.statSync(file);
  node.mtime = stat.mtime;
  this.paths.push(node.dirname);

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

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

  if (literal) {
    literal = new nodes.Literal(str.replace(/\r\n?/g, '\n'));
    literal.lineno = literal.column = 1;
    if (!this.resolveURL) return literal;
  }

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

  try {
    block = parser.parse();
  } catch (err) {
    var line = parser.lexer.lineno
      , column = parser.lexer.column;

    if (literal && this.includeCSS && this.resolveURL) {
      this.warn('ParseError: ' + file + ':' + line + ':' + column + '. This file included as-is');
      return literal;
    } else {
      err.filename = file;
      err.lineno = line;
      err.column = column;
      err.input = str;
      throw err;
    }
  }

  // Evaluate imported "root"
  block = block.clone(this.currentBlock);
  block.parent = this.currentBlock;
  block.scope = false;
  var ret = this.visit(block);
  importStack.pop();
  if (!this.resolveURL || this.resolveURL.nocheck) this.paths.pop();

  return ret;
}
function importFile ( node , file , literal ) { var importStack = this . importStack , Parser = require ( '../parser' ) , stat ; // Handling the `require` if ( node . once ) { if ( this . requireHistory [ file ] ) return nodes . null ; this . requireHistory [ file ] = true ; if ( literal && ! this . includeCSS ) { return node ; } } // 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 ) ; // Store the modified time stat = fs . statSync ( file ) ; node . mtime = stat . mtime ; this . paths . push ( node . dirname ) ; if ( this . options . _imports ) this . options . _imports . push ( node . clone ( ) ) ; // Parse the file importStack . push ( file ) ; nodes . filename = file ; if ( literal ) { literal = new nodes . Literal ( str . replace ( / \r\n? / g , '\n' ) ) ; literal . lineno = literal . column = 1 ; if ( ! this . resolveURL ) return literal ; } // parse var block = new nodes . Block , parser = new Parser ( str , utils . merge ( { root : block } , this . options ) ) ; try { block = parser . parse ( ) ; } catch ( err ) { var line = parser . lexer . lineno , column = parser . lexer . column ; if ( literal && this . includeCSS && this . resolveURL ) { this . warn ( 'ParseError: ' + file + ':' + line + ':' + column + '. This file included as-is' ) ; return literal ; } else { err . filename = file ; err . lineno = line ; err . column = column ; err . input = str ; throw err ; } } // Evaluate imported "root" block = block . clone ( this . currentBlock ) ; block . parent = this . currentBlock ; block . scope = false ; var ret = this . visit ( block ) ; importStack . pop ( ) ; if ( ! this . resolveURL || this . resolveURL . nocheck ) this . paths . pop ( ) ; return ret ; }
Import `file` and return Block node.

@api private
Import file and return Block node .