src/extract.js
function compileExtractionResult(orderedFiles, extractions) {
  const extractedVariables = { global: {} };

  orderedFiles.map(filename => {
    const globalFileVariables = extractions[filename].variables.global;

    Object.keys(globalFileVariables).map(variableKey => {
      globalFileVariables[variableKey].forEach(extractedVariable => {
        let variable = extractedVariables.global[variableKey];
        let currentVariableSources = [];
        let currentVariableDeclarations = [];

        if(variable) {
          currentVariableSources = variable.sources;
          currentVariableDeclarations = variable.declarations;
        }

        const hasOnlyDefaults = currentVariableDeclarations.every(declaration => declaration.flags.default);
        const currentIsDefault = extractedVariable.declaration.flags.default;

        if(currentVariableDeclarations.length === 0 || !currentIsDefault || hasOnlyDefaults) {
          variable = extractedVariables.global[variableKey] = Object.assign({}, extractedVariable.value);
        }
        variable.sources = currentVariableSources.indexOf(filename) < 0 ? [...currentVariableSources, filename] : currentVariableSources;
        variable.declarations = [...currentVariableDeclarations, {
          expression: extractedVariable.declaration.expression,
          flags: extractedVariable.declaration.flags,
          in: filename,
          position: extractedVariable.declaration.position,
        }];
      });
    });
  });

  return extractedVariables;
}
function compileExtractionResult(orderedFiles, extractions) {
  const extractedVariables = { global: {} };

  orderedFiles.map(filename => {
    const globalFileVariables = extractions[filename].variables.global;

    Object.keys(globalFileVariables).map(variableKey => {
      globalFileVariables[variableKey].forEach(extractedVariable => {
        let variable = extractedVariables.global[variableKey];
        let currentVariableSources = [];
        let currentVariableDeclarations = [];

        if(variable) {
          currentVariableSources = variable.sources;
          currentVariableDeclarations = variable.declarations;
        }

        const hasOnlyDefaults = currentVariableDeclarations.every(declaration => declaration.flags.default);
        const currentIsDefault = extractedVariable.declaration.flags.default;

        if(currentVariableDeclarations.length === 0 || !currentIsDefault || hasOnlyDefaults) {
          variable = extractedVariables.global[variableKey] = Object.assign({}, extractedVariable.value);
        }
        variable.sources = currentVariableSources.indexOf(filename) < 0 ? [...currentVariableSources, filename] : currentVariableSources;
        variable.declarations = [...currentVariableDeclarations, {
          expression: extractedVariable.declaration.expression,
          flags: extractedVariable.declaration.flags,
          in: filename,
          position: extractedVariable.declaration.position,
        }];
      });
    });
  });

  return extractedVariables;
}
function compileExtractionResult ( orderedFiles , extractions ) { const extractedVariables = { global : { } } ; orderedFiles . map ( filename => { const globalFileVariables = extractions [ filename ] . variables . global ; Object . keys ( globalFileVariables ) . map ( variableKey => { globalFileVariables [ variableKey ] . forEach ( extractedVariable => { let variable = extractedVariables . global [ variableKey ] ; let currentVariableSources = [ ] ; let currentVariableDeclarations = [ ] ; if ( variable ) { currentVariableSources = variable . sources ; currentVariableDeclarations = variable . declarations ; } const hasOnlyDefaults = currentVariableDeclarations . every ( declaration => declaration . flags . default ) ; const currentIsDefault = extractedVariable . declaration . flags . default ; if ( currentVariableDeclarations . length === 0 || ! currentIsDefault || hasOnlyDefaults ) { variable = extractedVariables . global [ variableKey ] = Object . assign ( { } , extractedVariable . value ) ; } variable . sources = currentVariableSources . indexOf ( filename ) < 0 ? [ ... currentVariableSources , filename ] : currentVariableSources ; variable . declarations = [ ... currentVariableDeclarations , { expression : extractedVariable . declaration . expression , flags : extractedVariable . declaration . flags , in : filename , position : extractedVariable . declaration . position , } ] ; } ) ; } ) ; } ) ; return extractedVariables ; }
Compile extracted variables per file into a complete result object
Compile extracted variables per file into a complete result object