Skip to content

Commit

Permalink
Omit all empty fill files from the bundle.
Browse files Browse the repository at this point in the history
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=212513767
  • Loading branch information
tjgq authored and blickly committed Sep 11, 2018
1 parent 2ad0590 commit 6f01d69
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
27 changes: 11 additions & 16 deletions src/com/google/javascript/jscomp/AbstractCommandLineRunner.java
Expand Up @@ -2098,31 +2098,26 @@ void printBundleTo(Iterable<CompilerInput> inputs, Appendable out) throws IOExce
}

for (CompilerInput input : inputs) {
// Every module has an empty file in it. This makes it easier to implement
// cross-module code motion.
//
// But it also leads to a weird edge case because
// a) If we don't have a module spec, we create a singleton module, and
// b) If we print a bundle file, we copy the original input files.
//
// This means that in the (rare) case where we have no inputs, and no
// module spec, and we're printing a bundle file, we'll have a fake
// input file that shouldn't be copied. So we special-case this, to
// make all the other cases simpler.
if (input.getName().equals(Compiler.createFillFileName(JSModule.SINGLETON_MODULE_NAME))) {
checkState(1 == Iterables.size(inputs));
return;
String name = input.getName();
String code = input.getSourceFile().getCode();

// Ignore empty fill files created by the compiler to facilitate cross-module code motion.
// Note that non-empty fill files (ones whose code has actually been moved into) are still
// emitted. In particular, this ensures that if there are no (real) inputs the bundle will be
// empty.
if (Compiler.isFillFileName(name) && code.isEmpty()) {
continue;
}

String rootRelativePath = rootRelativePathsMap.get(input.getName());
String rootRelativePath = rootRelativePathsMap.get(name);
String displayName = rootRelativePath != null
? rootRelativePath
: input.getName();
out.append("//");
out.append(displayName);
out.append("\n");

prepForBundleAndAppendTo(out, input, input.getSourceFile().getCode());
prepForBundleAndAppendTo(out, input, code);

out.append("\n");
}
Expand Down
9 changes: 8 additions & 1 deletion src/com/google/javascript/jscomp/Compiler.java
Expand Up @@ -128,6 +128,8 @@ public class Compiler extends AbstractCompiler implements ErrorHandler, SourceFi
private static final String CONFIG_RESOURCE =
"com.google.javascript.jscomp.parsing.ParserConfig";

private static final String FILL_FILE_SUFFIX = "$fillFile";

CompilerOptions options = null;

private PassConfig passes = null;
Expand Down Expand Up @@ -563,7 +565,12 @@ private void checkFirstModule(List<JSModule> modules) {
* an empty module.
*/
static String createFillFileName(String moduleName) {
return moduleName + "$fillFile";
return moduleName + FILL_FILE_SUFFIX;
}

/** Returns whether a file name was created by {@link createFillFileName}. */
static boolean isFillFileName(String fileName) {
return fileName.endsWith(FILL_FILE_SUFFIX);
}

/**
Expand Down

0 comments on commit 6f01d69

Please sign in to comment.