lib/helpers.js
function fixImportedSourceMap(file, state, callback) {
  if (!state.map) {
    return callback();
  }

  state.map.sourcesContent = state.map.sourcesContent || [];

  nal.map(state.map.sources, normalizeSourcesAndContent, callback);

  function assignSourcesContent(sourceContent, idx) {
    state.map.sourcesContent[idx] = sourceContent;
  }

  function normalizeSourcesAndContent(sourcePath, idx, cb) {
    var sourceRoot = state.map.sourceRoot || '';
    var sourceContent = state.map.sourcesContent[idx] || null;

    if (isRemoteSource(sourcePath)) {
      assignSourcesContent(sourceContent, idx);
      return cb();
    }

    if (state.map.sourcesContent[idx]) {
      return cb();
    }

    if (sourceRoot && isRemoteSource(sourceRoot)) {
      assignSourcesContent(sourceContent, idx);
      return cb();
    }

    var basePath = path.resolve(file.base, sourceRoot);
    var absPath = path.resolve(state.path, sourceRoot, sourcePath);
    var relPath = path.relative(basePath, absPath);
    var unixRelPath = normalizePath(relPath);

    state.map.sources[idx] = unixRelPath;

    if (absPath !== file.path) {
      // Load content from file async
      return fs.readFile(absPath, onRead);
    }

    // If current file: use content
    assignSourcesContent(state.content, idx);
    cb();

    function onRead(err, data) {
      if (err) {
        assignSourcesContent(null, idx);
        return cb();
      }
      assignSourcesContent(removeBOM(data).toString('utf8'), idx);
      cb();
    }
  }
}
function fixImportedSourceMap(file, state, callback) {
  if (!state.map) {
    return callback();
  }

  state.map.sourcesContent = state.map.sourcesContent || [];

  nal.map(state.map.sources, normalizeSourcesAndContent, callback);

  function assignSourcesContent(sourceContent, idx) {
    state.map.sourcesContent[idx] = sourceContent;
  }

  function normalizeSourcesAndContent(sourcePath, idx, cb) {
    var sourceRoot = state.map.sourceRoot || '';
    var sourceContent = state.map.sourcesContent[idx] || null;

    if (isRemoteSource(sourcePath)) {
      assignSourcesContent(sourceContent, idx);
      return cb();
    }

    if (state.map.sourcesContent[idx]) {
      return cb();
    }

    if (sourceRoot && isRemoteSource(sourceRoot)) {
      assignSourcesContent(sourceContent, idx);
      return cb();
    }

    var basePath = path.resolve(file.base, sourceRoot);
    var absPath = path.resolve(state.path, sourceRoot, sourcePath);
    var relPath = path.relative(basePath, absPath);
    var unixRelPath = normalizePath(relPath);

    state.map.sources[idx] = unixRelPath;

    if (absPath !== file.path) {
      // Load content from file async
      return fs.readFile(absPath, onRead);
    }

    // If current file: use content
    assignSourcesContent(state.content, idx);
    cb();

    function onRead(err, data) {
      if (err) {
        assignSourcesContent(null, idx);
        return cb();
      }
      assignSourcesContent(removeBOM(data).toString('utf8'), idx);
      cb();
    }
  }
}
function fixImportedSourceMap ( file , state , callback ) { if ( ! state . map ) { return callback ( ) ; } state . map . sourcesContent = state . map . sourcesContent || [ ] ; nal . map ( state . map . sources , normalizeSourcesAndContent , callback ) ; function assignSourcesContent ( sourceContent , idx ) { state . map . sourcesContent [ idx ] = sourceContent ; } function normalizeSourcesAndContent ( sourcePath , idx , cb ) { var sourceRoot = state . map . sourceRoot || '' ; var sourceContent = state . map . sourcesContent [ idx ] || null ; if ( isRemoteSource ( sourcePath ) ) { assignSourcesContent ( sourceContent , idx ) ; return cb ( ) ; } if ( state . map . sourcesContent [ idx ] ) { return cb ( ) ; } if ( sourceRoot && isRemoteSource ( sourceRoot ) ) { assignSourcesContent ( sourceContent , idx ) ; return cb ( ) ; } var basePath = path . resolve ( file . base , sourceRoot ) ; var absPath = path . resolve ( state . path , sourceRoot , sourcePath ) ; var relPath = path . relative ( basePath , absPath ) ; var unixRelPath = normalizePath ( relPath ) ; state . map . sources [ idx ] = unixRelPath ; if ( absPath !== file . path ) { // Load content from file async return fs . readFile ( absPath , onRead ) ; } // If current file: use content assignSourcesContent ( state . content , idx ) ; cb ( ) ; function onRead ( err , data ) { if ( err ) { assignSourcesContent ( null , idx ) ; return cb ( ) ; } assignSourcesContent ( removeBOM ( data ) . toString ( 'utf8' ) , idx ) ; cb ( ) ; } } }
Fix source paths and sourceContent for imported source map
Fix source paths and sourceContent for imported source map