src/parse.js
function getDeclarationDeps($ast, declaration, scope) {
  if(scope !== SCOPE_EXPLICIT) {
    return {};
  }

  const depParentNodes = $ast(declaration).parents(node => {
    if(node.node.type === 'mixin') {
      return true;
    } else if(node.node.type === 'atrule') {
      const atruleIdentNode = $ast(node).children('atkeyword').children('ident');
      return atruleIdentNode.length() > 0 && atruleIdentNode.first().value() === 'function'
    } else {
      return false;
    }
  });

  if(depParentNodes.length() === 0) {
    return {};
  }

  const depParentNode = depParentNodes.last();
  const depKeywordNode = depParentNode.children('atkeyword').children('ident');

  if(depKeywordNode.length() === 0) {
    return {};
  }

  const atKeyword = depKeywordNode.first().value();

  if(!DEP_HOST[atKeyword]) {
    return {};
  }

  const depHostNode = DEP_HOST[atKeyword](depParentNode);
  const atKeywordIdentifierNode = depHostNode.children('ident');

  if(atKeywordIdentifierNode.length() === 0) {
    return {};
  }

  const atIdentifier = atKeywordIdentifierNode.first().value();
  const argumentsNode = depHostNode.children('arguments');

  // Count arguments to mixin/function @atrule
  const requiredArgsCount = argumentsNode.children('variable').length();
  const optionalArgsCount = argumentsNode.children('declaration').length();
  const totalArgsCount = requiredArgsCount + optionalArgsCount;

  if(!DEP_KEYWORDS[atKeyword]) {
    return {};
  }

  return {
    [DEP_KEYWORDS[atKeyword]]: {
      name: atIdentifier,
      argsCount: {
        total: totalArgsCount,
        required: requiredArgsCount,
        optional: optionalArgsCount,
      },
    },
  };
}
function getDeclarationDeps($ast, declaration, scope) {
  if(scope !== SCOPE_EXPLICIT) {
    return {};
  }

  const depParentNodes = $ast(declaration).parents(node => {
    if(node.node.type === 'mixin') {
      return true;
    } else if(node.node.type === 'atrule') {
      const atruleIdentNode = $ast(node).children('atkeyword').children('ident');
      return atruleIdentNode.length() > 0 && atruleIdentNode.first().value() === 'function'
    } else {
      return false;
    }
  });

  if(depParentNodes.length() === 0) {
    return {};
  }

  const depParentNode = depParentNodes.last();
  const depKeywordNode = depParentNode.children('atkeyword').children('ident');

  if(depKeywordNode.length() === 0) {
    return {};
  }

  const atKeyword = depKeywordNode.first().value();

  if(!DEP_HOST[atKeyword]) {
    return {};
  }

  const depHostNode = DEP_HOST[atKeyword](depParentNode);
  const atKeywordIdentifierNode = depHostNode.children('ident');

  if(atKeywordIdentifierNode.length() === 0) {
    return {};
  }

  const atIdentifier = atKeywordIdentifierNode.first().value();
  const argumentsNode = depHostNode.children('arguments');

  // Count arguments to mixin/function @atrule
  const requiredArgsCount = argumentsNode.children('variable').length();
  const optionalArgsCount = argumentsNode.children('declaration').length();
  const totalArgsCount = requiredArgsCount + optionalArgsCount;

  if(!DEP_KEYWORDS[atKeyword]) {
    return {};
  }

  return {
    [DEP_KEYWORDS[atKeyword]]: {
      name: atIdentifier,
      argsCount: {
        total: totalArgsCount,
        required: requiredArgsCount,
        optional: optionalArgsCount,
      },
    },
  };
}
function getDeclarationDeps ( $ast , declaration , scope ) { if ( scope !== SCOPE_EXPLICIT ) { return { } ; } const depParentNodes = $ast ( declaration ) . parents ( node => { if ( node . node . type === 'mixin' ) { return true ; } else if ( node . node . type === 'atrule' ) { const atruleIdentNode = $ast ( node ) . children ( 'atkeyword' ) . children ( 'ident' ) ; return atruleIdentNode . length ( ) > 0 && atruleIdentNode . first ( ) . value ( ) === 'function' } else { return false ; } } ) ; if ( depParentNodes . length ( ) === 0 ) { return { } ; } const depParentNode = depParentNodes . last ( ) ; const depKeywordNode = depParentNode . children ( 'atkeyword' ) . children ( 'ident' ) ; if ( depKeywordNode . length ( ) === 0 ) { return { } ; } const atKeyword = depKeywordNode . first ( ) . value ( ) ; if ( ! DEP_HOST [ atKeyword ] ) { return { } ; } const depHostNode = DEP_HOST [ atKeyword ] ( depParentNode ) ; const atKeywordIdentifierNode = depHostNode . children ( 'ident' ) ; if ( atKeywordIdentifierNode . length ( ) === 0 ) { return { } ; } const atIdentifier = atKeywordIdentifierNode . first ( ) . value ( ) ; const argumentsNode = depHostNode . children ( 'arguments' ) ; // Count arguments to mixin/function @atrule const requiredArgsCount = argumentsNode . children ( 'variable' ) . length ( ) ; const optionalArgsCount = argumentsNode . children ( 'declaration' ) . length ( ) ; const totalArgsCount = requiredArgsCount + optionalArgsCount ; if ( ! DEP_KEYWORDS [ atKeyword ] ) { return { } ; } return { [ DEP_KEYWORDS [ atKeyword ] ] : { name : atIdentifier , argsCount : { total : totalArgsCount , required : requiredArgsCount , optional : optionalArgsCount , } , } , } ; }
Get dependencies required to extract variables such as mixins or function invocations
Get dependencies required to extract variables such as mixins or function invocations