diff --git a/src/com/google/javascript/jscomp/CommandLineRunner.java b/src/com/google/javascript/jscomp/CommandLineRunner.java index b2445a836ef..3a979e02acc 100644 --- a/src/com/google/javascript/jscomp/CommandLineRunner.java +++ b/src/com/google/javascript/jscomp/CommandLineRunner.java @@ -930,6 +930,14 @@ private static class Flags { + "An alias of 'import' is allowed.") private String dynamicImportAlias = null; + @Option( + name = "--assume_static_inheritance_required", + handler = BooleanOptionHandler.class, + usage = + "Instructs the compiler not to perform potential breaking optimizations " + + "when the code being compiled depends on static inheritance." ) + private boolean assumeStaticInheritanceRequired = false; + @Argument private List arguments = new ArrayList<>(); private final CmdLineParser parser; @@ -1042,6 +1050,7 @@ private void parse(List args) throws CmdLineException { "json_streams", "third_party", "use_types_for_optimization", + "assume_static_inheritance_required", "version")) .build(); @@ -1982,6 +1991,7 @@ protected CompilerOptions createOptions() { options.setProductionInstrumentationArrayName(flags.productionInstrumentationArrayName); options.setAllowDynamicImport(flags.allowDynamicImport); options.setDynamicImportAlias(flags.dynamicImportAlias); + options.setAssumeStaticInheritanceRequired(flags.assumeStaticInheritanceRequired); if (flags.chunkOutputType == ChunkOutputType.ES_MODULES) { if (flags.renamePrefixNamespace != null) { diff --git a/test/com/google/javascript/jscomp/CommandLineRunnerTest.java b/test/com/google/javascript/jscomp/CommandLineRunnerTest.java index 8eff3bf4adc..307beff854a 100644 --- a/test/com/google/javascript/jscomp/CommandLineRunnerTest.java +++ b/test/com/google/javascript/jscomp/CommandLineRunnerTest.java @@ -2926,6 +2926,15 @@ public void testChunkOutputFiles() throws IOException { assertThat(weakFile.exists()).isFalse(); } + @Test + public void testAssumeStaticInheritanceRequired() { + testSame(""); + assertThat(lastCompiler.getOptions().getAssumeStaticInheritanceRequired()).isFalse(); + args.add("--assume_static_inheritance_required"); + testSame(""); + assertThat(lastCompiler.getOptions().getAssumeStaticInheritanceRequired()).isTrue(); + } + /* Helper functions */ private void testSame(String original) {