diff --git a/src/main/java/com/google/javascript/clutz/Options.java b/src/main/java/com/google/javascript/clutz/Options.java index 726c7cd2..6d1116e5 100644 --- a/src/main/java/com/google/javascript/clutz/Options.java +++ b/src/main/java/com/google/javascript/clutz/Options.java @@ -41,6 +41,13 @@ public class Options { usage = "emits platform externs, instead of omitting them in favor of TS lib.d.ts") boolean emitPlatformExterns; + @Option(name = "--closure_entry_point", + usage = "only generate output for the given entry points to the program. Must be" + + " goog.provide'd symbols.", + metaVar = "ENTRYPOINT...", + handler = StringArrayOptionHandler.class) + List entryPoints = new ArrayList<>(); + @Argument List arguments = new ArrayList<>(); @@ -50,6 +57,10 @@ public CompilerOptions getCompilerOptions() { final CompilerOptions options = new CompilerOptions(); options.setClosurePass(true); + if (!this.entryPoints.isEmpty()) { + options.setManageClosureDependencies(this.entryPoints); + } + // All diagnostics are WARNINGs (or off) and thus ignored unless debug == true. // Only report issues (and fail for them) that are specifically causing problems for Clutz. // The idea is to not do a general sanity check of Closure code, just make sure Clutz works. diff --git a/src/test/java/com/google/javascript/clutz/OptionsTest.java b/src/test/java/com/google/javascript/clutz/OptionsTest.java index 1460ec99..6b1b010f 100644 --- a/src/test/java/com/google/javascript/clutz/OptionsTest.java +++ b/src/test/java/com/google/javascript/clutz/OptionsTest.java @@ -41,6 +41,17 @@ public void testFilterSourcesDepgraphs() throws Exception { assertThat(opts.output).isEqualTo("output.d.ts"); } + @Test + public void testClosureEntryPoint() throws Exception { + Options opts = new Options(new String[] { + "foo.js", "--closure_entry_point", "entryPoint", "--externs", "extern1.js", "extern2.js", "-o", "output.d.ts" + }); + assertThat(opts.arguments).containsExactly("foo.js"); + assertThat(opts.entryPoints).containsExactly("entryPoint"); + assertThat(opts.externs).containsExactly("extern1.js", "extern2.js").inOrder(); + assertThat(opts.output).isEqualTo("output.d.ts"); + } + @Test public void testHandleEmptyCommandLine() throws Exception { ByteArrayOutputStream out = new ByteArrayOutputStream();