tools/isobuild/import-scanner.js
// combination is done, oldFile should be kept and newFile discarded.
combination is done, oldFile should be kept and newFile discarded.
combination is done oldFile should be kept and newFile discarded .
_combineFiles(oldFile, newFile) {
    const scanner = this;
    function checkProperty(name) {
      if (has(oldFile, name)) {
        if (! has(newFile, name)) {
          newFile[name] = oldFile[name];
        }
      } else if (has(newFile, name)) {
        oldFile[name] = newFile[name];
      }
      if (oldFile[name] !== newFile[name]) {
        const fuzzyCase =
          oldFile.sourcePath.toLowerCase() === newFile.sourcePath.toLowerCase();
        throw new Error(
          "Attempting to combine different files" +
            ( fuzzyCase ? " (is the filename case slightly different?)" : "") +
            ":\n" +
            inspect(omit(oldFile, "dataString")) + "\n" +
            inspect(omit(newFile, "dataString")) + "\n"
        );
      }
    }
    checkProperty("lazy");
    checkProperty("bare");
    function getChunk(file) {
      const consumer = file.sourceMap &&
        new SourceMapConsumer(file.sourceMap);
      const node = consumer &&
        SourceNode.fromStringWithSourceMap(
          scanner._getDataString(file),
          consumer
        );
      return node || scanner._getDataString(file);
    }
    const {
      code: combinedDataString,
      map: combinedSourceMap,
    } = new SourceNode(null, null, null, [
      getChunk(oldFile),
      "\n\n",
      getChunk(newFile)
    ]).toStringWithSourceMap({
      file: oldFile.servePath || newFile.servePath
    });
    oldFile.dataString = combinedDataString;
    oldFile.data = Buffer.from(oldFile.dataString, "utf8");
    oldFile.hash = sha1(oldFile.data);
    alignImportedStatuses(oldFile, newFile);
    oldFile.sourceMap = combinedSourceMap.toJSON();
    if (! oldFile.sourceMap.mappings) {
      oldFile.sourceMap = null;
    }
  }
_combineFiles ( oldFile , newFile ) { const scanner = this ; function checkProperty ( name ) { if ( has ( oldFile , name ) ) { if ( ! has ( newFile , name ) ) { newFile [ name ] = oldFile [ name ] ; } } else if ( has ( newFile , name ) ) { oldFile [ name ] = newFile [ name ] ; } if ( oldFile [ name ] !== newFile [ name ] ) { const fuzzyCase = oldFile . sourcePath . toLowerCase ( ) === newFile . sourcePath . toLowerCase ( ) ; throw new Error ( "Attempting to combine different files" + ( fuzzyCase ? " (is the filename case slightly different?)" : "" ) + ":\n" + inspect ( omit ( oldFile , "dataString" ) ) + "\n" + inspect ( omit ( newFile , "dataString" ) ) + "\n" ) ; } } checkProperty ( "lazy" ) ; checkProperty ( "bare" ) ; function getChunk ( file ) { const consumer = file . sourceMap && new SourceMapConsumer ( file . sourceMap ) ; const node = consumer && SourceNode . fromStringWithSourceMap ( scanner . _getDataString ( file ) , consumer ) ; return node || scanner . _getDataString ( file ) ; } const { code : combinedDataString , map : combinedSourceMap , } = new SourceNode ( null , null , null , [ getChunk ( oldFile ) , "\n\n" , getChunk ( newFile ) ] ) . toStringWithSourceMap ( { file : oldFile . servePath || newFile . servePath } ) ; oldFile . dataString = combinedDataString ; oldFile . data = Buffer . from ( oldFile . dataString , "utf8" ) ; oldFile . hash = sha1 ( oldFile . data ) ; alignImportedStatuses ( oldFile , newFile ) ; oldFile . sourceMap = combinedSourceMap . toJSON ( ) ; if ( ! oldFile . sourceMap . mappings ) { oldFile . sourceMap = null ; } }
combination is done, oldFile should be kept and newFile discarded.
combination is done oldFile should be kept and newFile discarded .
// Since we're concatenating the files together, they must be either // both lazy or both eager. Same for bareness.