Skip to content

Commit

Permalink
Ensure the runtime is appended to output bundles.
Browse files Browse the repository at this point in the history
Needed for ES6 modules in bundles.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=186339854
  • Loading branch information
johnplaisted authored and dimvar committed Feb 21, 2018
1 parent 77d8fd1 commit c71f8af
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
15 changes: 15 additions & 0 deletions src/com/google/javascript/jscomp/AbstractCommandLineRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,11 @@ protected CommandLineConfig getCommandLineConfig() {
protected abstract void prepForBundleAndAppendTo(
Appendable out, CompilerInput input, String content) throws IOException;

/**
* Writes whatever runtime libraries are needed to bundle.
*/
protected abstract void appendRuntimeTo(Appendable out) throws IOException;

/**
* Returns the instance of the Options to use when {@link #run()} is called. createCompiler() is
* called before createOptions(), so getCompiler() will not return null when createOptions() is
Expand Down Expand Up @@ -2034,6 +2039,16 @@ void printManifestTo(Iterable<CompilerInput> inputs, Appendable out)
@VisibleForTesting
void printBundleTo(Iterable<CompilerInput> inputs, Appendable out)
throws IOException {
if (!compiler.getOptions().preventLibraryInjection) {
// ES6 modules will need a runtime in a bundle. Skip appending this runtime if there are no
// ES6 modules to cut down on size.
for (CompilerInput input : inputs) {
if ("es6".equals(input.getLoadFlags().get("module"))) {
appendRuntimeTo(out);
break;
}
}
}

for (CompilerInput input : inputs) {
// Every module has an empty file in it. This makes it easier to implement
Expand Down
8 changes: 7 additions & 1 deletion src/com/google/javascript/jscomp/CommandLineRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -1834,7 +1834,13 @@ protected Compiler createCompiler() {
@Override
protected void prepForBundleAndAppendTo(Appendable out, CompilerInput input, String content)
throws IOException {
ClosureBundler.appendInput(out, input, content);
new ClosureBundler().withPath(input.getName()).appendInput(out, input, content);
}

@Override
protected void appendRuntimeTo(Appendable out)
throws IOException {
new ClosureBundler().appendRuntimeTo(out);
}

@Override
Expand Down

0 comments on commit c71f8af

Please sign in to comment.