com.google.javascript.jscomp.CompilationLevel Java Examples

The following examples show how to use com.google.javascript.jscomp.CompilationLevel. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CompileTask.java    From astor with GNU General Public License v2.0 8 votes vote down vote up
public CompileTask() {
  this.languageIn = CompilerOptions.LanguageMode.ECMASCRIPT3;
  this.warningLevel = WarningLevel.DEFAULT;
  this.debugOptions = false;
  this.compilationLevel = CompilationLevel.SIMPLE_OPTIMIZATIONS;
  this.customExternsOnly = false;
  this.manageDependencies = false;
  this.prettyPrint = false;
  this.printInputDelimiter = false;
  this.generateExports = false;
  this.replaceProperties = false;
  this.forceRecompile = false;
  this.replacePropertiesPrefix = "closure.define.";
  this.defineParams = Lists.newLinkedList();
  this.externFileLists = Lists.newLinkedList();
  this.sourceFileLists = Lists.newLinkedList();
  this.sourcePaths = Lists.newLinkedList();
  this.warnings = Lists.newLinkedList();
}
 
Example #2
Source File: GoogleClosureOutputProcessorTest.java    From spring-soy-view with Apache License 2.0 6 votes vote down vote up
@Test
public void testAdvancedJsFailbackToOriginal() throws Exception {
    googleClosureOutputProcessor.setCompilationLevel(CompilationLevel.ADVANCED_OPTIMIZATIONS.name());
    final String js = "function myFunction()\n" +
            "{\n" +
            "var x=\"\",i;\n" +
            "for (i=0;i<5;i++)\n" +
            "  {\n" +
            "  x=x + \"The number is \" + i + \"<br>\";\n" +
            "  }\n" +
            "document.getElementById(\"demo\").innerHTML=x;\n" +
            "}";
    final StringReader reader = new StringReader(js);

    final StringWriter writer = new StringWriter();
    googleClosureOutputProcessor.process(reader, writer);

    final String compiled = writer.getBuffer().toString();
    assertEquals(js, compiled);
}
 
Example #3
Source File: CompilerTest.java    From JQF with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Before
public void initCompiler() {
    // Don't use threads
    compiler.disableThreads();
    // Don't print things
    options.setPrintConfig(false);
    // Enable all safe optimizations
    CompilationLevel.SIMPLE_OPTIMIZATIONS.setOptionsForCompilationLevel(options);
}
 
Example #4
Source File: JavaScriptCompilerMojoTest.java    From wisdom with Apache License 2.0 5 votes vote down vote up
@Test
public void testAggregatedSourceMapIsCreated() throws IOException, MojoExecutionException, MojoFailureException {
    JavaScriptCompilerMojo mojo = new JavaScriptCompilerMojo();
    mojo.googleClosureMinifierSuffix = "-min";
    mojo.basedir = new File("target/junk/root");
    mojo.buildDirectory = new File(mojo.basedir, "target");
    MavenProject project = mock(MavenProject.class);
    when(project.getArtifactId()).thenReturn("my-artifact");
    mojo.project = project;
    mojo.googleClosureCompilationLevel = CompilationLevel.ADVANCED_OPTIMIZATIONS;
    mojo.googleClosureMap = true;

    Aggregation aggregation = new Aggregation();
    aggregation.setMinification(true);

    JavaScript javascript = new JavaScript();
    javascript.setAggregations(singletonList(new Aggregation()));
    mojo.javascript = javascript;

    mojo.execute();

    File map = new File(mojo.getDefaultOutputFile(aggregation).getParentFile(), "my-artifact-min.js.map");

    assertThat(mojo.getDefaultOutputFile(aggregation)).hasContent("\n//# sourceMappingURL=my-artifact-min.js.map");
    assertThat(map).exists();
    assertThat(lineIterator(map)).contains("\"file\":\"my-artifact-min.js\",");
}
 
Example #5
Source File: JsOptimizerUtil.java    From netty-cookbook with Apache License 2.0 5 votes vote down vote up
/**
	 * @param code
	 *            JavaScript source code to compile.
	 * @return The compiled version of the code.
	 */
	public static String compile(String code) {
		
//		System.out.println("------------------------");
//		System.out.println(code);
//		System.out.println("------------------------");
		
		Compiler compiler = new Compiler();

		CompilerOptions options = new CompilerOptions();
		// Advanced mode is used here, but additional options could be set, too.
		CompilationLevel.SIMPLE_OPTIMIZATIONS.setOptionsForCompilationLevel(options);

		// To get the complete set of externs, the logic in
		// CompilerRunner.getDefaultExterns() should be used here.
		SourceFile extern = SourceFile.fromCode("externs.js", "");

		// The dummy input name "input.js" is used here so that any warnings or
		// errors will cite line numbers in terms of input.js.
		SourceFile input = SourceFile.fromCode("input.js", code);

		// compile() returns a Result, but it is not needed here.
		compiler.compile(extern, input, options);

		// The compiler is responsible for generating the compiled code; it is
		// not
		// accessible via the Result.
		return compiler.toSource();
	}
 
Example #6
Source File: CompileTask.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Set the compilation level.
 * @param value The optimization level by string name.
 *     (whitespace, simple, advanced).
 */
public void setCompilationLevel(String value) {
  if ("simple".equalsIgnoreCase(value)) {
    this.compilationLevel = CompilationLevel.SIMPLE_OPTIMIZATIONS;
  } else if ("advanced".equalsIgnoreCase(value)) {
    this.compilationLevel = CompilationLevel.ADVANCED_OPTIMIZATIONS;
  } else if ("whitespace".equalsIgnoreCase(value)) {
    this.compilationLevel = CompilationLevel.WHITESPACE_ONLY;
  } else {
    throw new BuildException(
        "Unrecognized 'compilation' option value (" + value + ")");
  }
}
 
Example #7
Source File: ClosureCompiler.java    From caja with Apache License 2.0 5 votes vote down vote up
public static String build(Task task, List<File> inputs) {
  List<SourceFile> externs;
  try {
    externs = CommandLineRunner.getDefaultExterns();
  } catch (IOException e) {
    throw new BuildException(e);
  }

  List<SourceFile> jsInputs = new ArrayList<SourceFile>();
  for (File f : inputs) {
    jsInputs.add(SourceFile.fromFile(f));
  }

  CompilerOptions options = new CompilerOptions();
  CompilationLevel.ADVANCED_OPTIMIZATIONS
      .setOptionsForCompilationLevel(options);
  WarningLevel.VERBOSE.setOptionsForWarningLevel(options);
  for (DiagnosticGroup dg : diagnosticGroups) {
    options.setWarningLevel(dg, CheckLevel.ERROR);
  }

  options.setCodingConvention(new GoogleCodingConvention());

  Compiler compiler = new Compiler();
  MessageFormatter formatter =
      options.errorFormat.toFormatter(compiler, false);
  AntErrorManager errorManager = new AntErrorManager(formatter, task);
  compiler.setErrorManager(errorManager);

  Result r = compiler.compile(externs, jsInputs, options);
  if (!r.success) {
    return null;
  }

  String wrapped = "(function(){" + compiler.toSource() + "})();\n";
  return wrapped;
}
 
Example #8
Source File: HtmlCompressorTest.java    From htmlcompressor with Apache License 2.0 5 votes vote down vote up
@Test
public void testCompressJavaScriptClosure() throws Exception {
	String source = readResource("testCompressJavaScript.html");
	String result = readResource("testCompressJavaScriptClosureResult.html");
	
	HtmlCompressor compressor = new HtmlCompressor();
	compressor.setCompressJavaScript(true);
	compressor.setJavaScriptCompressor(new ClosureJavaScriptCompressor(CompilationLevel.ADVANCED_OPTIMIZATIONS));
	compressor.setRemoveIntertagSpaces(true);
	
	assertEquals(result, compressor.compress(source));
}
 
Example #9
Source File: ClosureCompiler.java    From AngularBeans with GNU Lesser General Public License v3.0 5 votes vote down vote up
public ClosureCompiler() {
	//We have to ensure a safe concurrency as ModuleGenerator is session-scoped and
	//multiple sessions can generate the script at the same time.
	synchronized (lock) {
		this.options = new CompilerOptions();
		CompilationLevel.WHITESPACE_ONLY.setOptionsForCompilationLevel(options);
		options.setVariableRenaming(VariableRenamingPolicy.OFF);
		options.setAngularPass(true);
		options.setTightenTypes(false);
		options.prettyPrint = false;
	}
}
 
Example #10
Source File: ClosureJavaScriptCompressor.java    From htmlcompressor with Apache License 2.0 4 votes vote down vote up
public ClosureJavaScriptCompressor(CompilationLevel compilationLevel) {
	this.compilationLevel = compilationLevel;
}
 
Example #11
Source File: ClosureJavaScriptCompressor.java    From htmlcompressor with Apache License 2.0 4 votes vote down vote up
@Override
public String compress(String source) {
	
	StringWriter writer = new StringWriter();
	
	//prepare source
	List<JSSourceFile> input = new ArrayList<JSSourceFile>();
	input.add(JSSourceFile.fromCode("source.js", source));
	
	//prepare externs
	List<JSSourceFile> externsList = new ArrayList<JSSourceFile>();
	if(compilationLevel.equals(CompilationLevel.ADVANCED_OPTIMIZATIONS)) {
		//default externs
		if(!customExternsOnly) {
			try {
				externsList = getDefaultExterns();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		//add user defined externs
		if(externs != null) {
			for(JSSourceFile extern : externs) {
				externsList.add(extern);
			}
		}
		//add empty externs
		if(externsList.size() == 0) {
			externsList.add(JSSourceFile.fromCode("externs.js", ""));
		}
	} else {
		//empty externs
		externsList.add(JSSourceFile.fromCode("externs.js", ""));
	}
	
	Compiler.setLoggingLevel(loggingLevel);
	
	Compiler compiler = new Compiler();
	compiler.disableThreads();
	
	compilationLevel.setOptionsForCompilationLevel(compilerOptions);
	warningLevel.setOptionsForWarningLevel(compilerOptions);
	
	Result result = compiler.compile(externsList, input, compilerOptions);
	
	if (result.success) {
		writer.write(compiler.toSource());
	} else {
		writer.write(source);
	}

	return writer.toString();

}
 
Example #12
Source File: JavaScriptCompressorDirective.java    From htmlcompressor with Apache License 2.0 4 votes vote down vote up
public boolean render(InternalContextAdapter context, Writer writer, Node node) 
  		throws IOException, ResourceNotFoundException, ParseErrorException, MethodInvocationException {
  	
  	//render content
  	StringWriter content = new StringWriter();
node.jjtGetChild(0).render(context, content);

//compress
if(enabled) {
	try {
		String result = content.toString();
		
		if(jsCompressor.equalsIgnoreCase(HtmlCompressor.JS_COMPRESSOR_CLOSURE)) {
			//call Closure compressor
			ClosureJavaScriptCompressor closureCompressor = new ClosureJavaScriptCompressor();
			if(closureOptLevel.equalsIgnoreCase(ClosureJavaScriptCompressor.COMPILATION_LEVEL_ADVANCED)) {
				closureCompressor.setCompilationLevel(CompilationLevel.ADVANCED_OPTIMIZATIONS);
			} else if(closureOptLevel.equalsIgnoreCase(ClosureJavaScriptCompressor.COMPILATION_LEVEL_WHITESPACE)) {
				closureCompressor.setCompilationLevel(CompilationLevel.WHITESPACE_ONLY);
			} else {
				closureCompressor.setCompilationLevel(CompilationLevel.SIMPLE_OPTIMIZATIONS);
			}
			
			result = closureCompressor.compress(result);
			
		} else {
			//call YUICompressor
			YuiJavaScriptCompressor yuiCompressor = new YuiJavaScriptCompressor();
			yuiCompressor.setDisableOptimizations(yuiJsDisableOptimizations);
			yuiCompressor.setLineBreak(yuiJsLineBreak);
			yuiCompressor.setNoMunge(yuiJsNoMunge);
			yuiCompressor.setPreserveAllSemiColons(yuiJsPreserveAllSemiColons);
			
			result = yuiCompressor.compress(result);
		}
		
		writer.write(result);
	} catch (Exception e) {
		writer.write(content.toString());
		String msg = "Failed to compress content: "+content.toString();
           log.error(msg, e);
           throw new RuntimeException(msg, e);
           
	}
} else {
	writer.write(content.toString());
}

return true;
  	
  }
 
Example #13
Source File: HtmlCompressorDirective.java    From htmlcompressor with Apache License 2.0 4 votes vote down vote up
@Override
public void init(RuntimeServices rs, InternalContextAdapter context, Node node) throws TemplateInitException {
	super.init(rs, context, node);
	log = rs.getLog();
	
	boolean compressJavaScript = rs.getBoolean("userdirective.compressHtml.compressJavaScript", false);
	
	//set compressor properties
	htmlCompressor.setEnabled(rs.getBoolean("userdirective.compressHtml.enabled", true));
	htmlCompressor.setRemoveComments(rs.getBoolean("userdirective.compressHtml.removeComments", true));
	htmlCompressor.setRemoveMultiSpaces(rs.getBoolean("userdirective.compressHtml.removeMultiSpaces", true));
	htmlCompressor.setRemoveIntertagSpaces(rs.getBoolean("userdirective.compressHtml.removeIntertagSpaces", false));
	htmlCompressor.setRemoveQuotes(rs.getBoolean("userdirective.compressHtml.removeQuotes", false));
	htmlCompressor.setPreserveLineBreaks(rs.getBoolean("userdirective.compressHtml.preserveLineBreaks", false));
	htmlCompressor.setCompressJavaScript(compressJavaScript);
	htmlCompressor.setCompressCss(rs.getBoolean("userdirective.compressHtml.compressCss", false));
	htmlCompressor.setYuiJsNoMunge(rs.getBoolean("userdirective.compressHtml.yuiJsNoMunge", false));
	htmlCompressor.setYuiJsPreserveAllSemiColons(rs.getBoolean("userdirective.compressHtml.yuiJsPreserveAllSemiColons", false));
	htmlCompressor.setYuiJsLineBreak(rs.getInt("userdirective.compressHtml.yuiJsLineBreak", -1));
	htmlCompressor.setYuiCssLineBreak(rs.getInt("userdirective.compressHtml.yuiCssLineBreak", -1));
	htmlCompressor.setSimpleDoctype(rs.getBoolean("userdirective.compressHtml.simpleDoctype", false));
	htmlCompressor.setRemoveScriptAttributes(rs.getBoolean("userdirective.compressHtml.removeScriptAttributes", false));
	htmlCompressor.setRemoveStyleAttributes(rs.getBoolean("userdirective.compressHtml.removeStyleAttributes", false));
	htmlCompressor.setRemoveLinkAttributes(rs.getBoolean("userdirective.compressHtml.removeLinkAttributes", false));
	htmlCompressor.setRemoveFormAttributes(rs.getBoolean("userdirective.compressHtml.removeFormAttributes", false));
	htmlCompressor.setRemoveInputAttributes(rs.getBoolean("userdirective.compressHtml.removeInputAttributes", false));
	htmlCompressor.setSimpleBooleanAttributes(rs.getBoolean("userdirective.compressHtml.simpleBooleanAttributes", false));
	htmlCompressor.setRemoveJavaScriptProtocol(rs.getBoolean("userdirective.compressHtml.removeJavaScriptProtocol", false));
	htmlCompressor.setRemoveHttpProtocol(rs.getBoolean("userdirective.compressHtml.removeHttpProtocol", false));
	htmlCompressor.setRemoveHttpsProtocol(rs.getBoolean("userdirective.compressHtml.removeHttpsProtocol", false));
	
	
	if(compressJavaScript && rs.getString("userdirective.compressHtml.jsCompressor", HtmlCompressor.JS_COMPRESSOR_YUI).equalsIgnoreCase(HtmlCompressor.JS_COMPRESSOR_CLOSURE)) {
		String closureOptLevel = rs.getString("userdirective.compressHtml.closureOptLevel", ClosureJavaScriptCompressor.COMPILATION_LEVEL_SIMPLE);
		
		ClosureJavaScriptCompressor closureCompressor = new ClosureJavaScriptCompressor();
		if(closureOptLevel.equalsIgnoreCase(ClosureJavaScriptCompressor.COMPILATION_LEVEL_ADVANCED)) {
			closureCompressor.setCompilationLevel(CompilationLevel.ADVANCED_OPTIMIZATIONS);
		} else if(closureOptLevel.equalsIgnoreCase(ClosureJavaScriptCompressor.COMPILATION_LEVEL_WHITESPACE)) {
			closureCompressor.setCompilationLevel(CompilationLevel.WHITESPACE_ONLY);
		} else {
			closureCompressor.setCompilationLevel(CompilationLevel.SIMPLE_OPTIMIZATIONS);
		}
		
		htmlCompressor.setJavaScriptCompressor(closureCompressor);
	}
}
 
Example #14
Source File: JavaScriptCompressorTag.java    From htmlcompressor with Apache License 2.0 4 votes vote down vote up
@Override
public int doEndTag() throws JspException {
	
	BodyContent bodyContent = getBodyContent();
	String content = bodyContent.getString();

	try {
		if(enabled) {
			
			String result = content;
			
			if(jsCompressor.equalsIgnoreCase(HtmlCompressor.JS_COMPRESSOR_CLOSURE)) {
				//call Closure compressor
				ClosureJavaScriptCompressor closureCompressor = new ClosureJavaScriptCompressor();
				if(closureOptLevel.equalsIgnoreCase(ClosureJavaScriptCompressor.COMPILATION_LEVEL_ADVANCED)) {
					closureCompressor.setCompilationLevel(CompilationLevel.ADVANCED_OPTIMIZATIONS);
				} else if(closureOptLevel.equalsIgnoreCase(ClosureJavaScriptCompressor.COMPILATION_LEVEL_WHITESPACE)) {
					closureCompressor.setCompilationLevel(CompilationLevel.WHITESPACE_ONLY);
				} else {
					closureCompressor.setCompilationLevel(CompilationLevel.SIMPLE_OPTIMIZATIONS);
				}
				
				result = closureCompressor.compress(content);
				
			} else {
				//call YUICompressor
				YuiJavaScriptCompressor yuiCompressor = new YuiJavaScriptCompressor();
				yuiCompressor.setDisableOptimizations(yuiJsDisableOptimizations);
				yuiCompressor.setLineBreak(yuiJsLineBreak);
				yuiCompressor.setNoMunge(yuiJsNoMunge);
				yuiCompressor.setPreserveAllSemiColons(yuiJsPreserveAllSemiColons);
				
				result = yuiCompressor.compress(content);
			}
			
			bodyContent.clear();
			bodyContent.append(result);
			bodyContent.writeOut(pageContext.getOut());
		} else {
			bodyContent.clear();
			bodyContent.append(content);
			bodyContent.writeOut(pageContext.getOut());
		}

	} catch (Exception e) {
		throw new JspException("Failed to compress javascript",e);
	}
	
	return super.doEndTag();
}
 
Example #15
Source File: HtmlCompressorTag.java    From htmlcompressor with Apache License 2.0 4 votes vote down vote up
@Override
public int doEndTag() throws JspException {
	
	BodyContent bodyContent = getBodyContent();
	String content = bodyContent.getString();
	
	HtmlCompressor htmlCompressor = new HtmlCompressor();
	htmlCompressor.setEnabled(enabled);
	htmlCompressor.setRemoveComments(removeComments);
	htmlCompressor.setRemoveMultiSpaces(removeMultiSpaces);
	htmlCompressor.setRemoveIntertagSpaces(removeIntertagSpaces);
	htmlCompressor.setRemoveQuotes(removeQuotes);
	htmlCompressor.setPreserveLineBreaks(preserveLineBreaks);
	htmlCompressor.setCompressJavaScript(compressJavaScript);
	htmlCompressor.setCompressCss(compressCss);
	htmlCompressor.setYuiJsNoMunge(yuiJsNoMunge);
	htmlCompressor.setYuiJsPreserveAllSemiColons(yuiJsPreserveAllSemiColons);
	htmlCompressor.setYuiJsDisableOptimizations(yuiJsDisableOptimizations);
	htmlCompressor.setYuiJsLineBreak(yuiJsLineBreak);
	htmlCompressor.setYuiCssLineBreak(yuiCssLineBreak);

	htmlCompressor.setSimpleDoctype(simpleDoctype);
	htmlCompressor.setRemoveScriptAttributes(removeScriptAttributes);
	htmlCompressor.setRemoveStyleAttributes(removeStyleAttributes);
	htmlCompressor.setRemoveLinkAttributes(removeLinkAttributes);
	htmlCompressor.setRemoveFormAttributes(removeFormAttributes);
	htmlCompressor.setRemoveInputAttributes(removeInputAttributes);
	htmlCompressor.setSimpleBooleanAttributes(simpleBooleanAttributes);
	htmlCompressor.setRemoveJavaScriptProtocol(removeJavaScriptProtocol);
	htmlCompressor.setRemoveHttpProtocol(removeHttpProtocol);
	htmlCompressor.setRemoveHttpsProtocol(removeHttpsProtocol);
	
	if(compressJavaScript && jsCompressor.equalsIgnoreCase(HtmlCompressor.JS_COMPRESSOR_CLOSURE)) {
		ClosureJavaScriptCompressor closureCompressor = new ClosureJavaScriptCompressor();
		if(closureOptLevel.equalsIgnoreCase(ClosureJavaScriptCompressor.COMPILATION_LEVEL_ADVANCED)) {
			closureCompressor.setCompilationLevel(CompilationLevel.ADVANCED_OPTIMIZATIONS);
		} else if(closureOptLevel.equalsIgnoreCase(ClosureJavaScriptCompressor.COMPILATION_LEVEL_WHITESPACE)) {
			closureCompressor.setCompilationLevel(CompilationLevel.WHITESPACE_ONLY);
		} else {
			closureCompressor.setCompilationLevel(CompilationLevel.SIMPLE_OPTIMIZATIONS);
		}
		htmlCompressor.setJavaScriptCompressor(closureCompressor);
	}
	
	try {
		bodyContent.clear();
		bodyContent.append(htmlCompressor.compress(content));
		bodyContent.writeOut(pageContext.getOut());
	} catch (Exception e) {
		throw new JspException("Failed to compress html",e);
	}
	
	return super.doEndTag();
}
 
Example #16
Source File: MinifyUtil.java    From minifierbeans with Apache License 2.0 4 votes vote down vote up
public String compressSelectedJavaScript(String inputFilename, String content, MinifyProperty minifyProperty) throws IOException {
    Compiler compiler = new Compiler();
    CompilerOptions options = new CompilerOptions();

    compiler.initOptions(options);

    options.setStrictModeInput(false);
    options.setEmitUseStrict(false);
    options.setTrustedStrings(true);

    CompilationLevel.SIMPLE_OPTIMIZATIONS.setOptionsForCompilationLevel(options);

    List<SourceFile> inputs = new ArrayList<SourceFile>();
    inputs.add(SourceFile.fromCode(inputFilename, content));

    StringWriter outputWriter = new StringWriter();

    compiler.compile(CommandLineRunner.getDefaultExterns(), inputs, options);
    outputWriter.flush();

    return compiler.toSource();
}
 
Example #17
Source File: CompilerModule.java    From js-dossier with Apache License 2.0 4 votes vote down vote up
@Provides
CompilerOptions provideCompilerOptions(
    ProvidedSymbolPass providedSymbolPass,
    TypeCollectionPass typeCollectionPass,
    @Modules ImmutableSet<Path> modulePaths,
    Environment environment) {
  CompilerOptions options = new CompilerOptions();

  switch (environment) {
    case BROWSER:
      options.setEnvironment(CompilerOptions.Environment.BROWSER);
      options.setModuleResolutionMode(ModuleLoader.ResolutionMode.BROWSER);
      break;

    case NODE:
      options.setEnvironment(CompilerOptions.Environment.CUSTOM);
      options.setModuleResolutionMode(ModuleLoader.ResolutionMode.NODE);
      break;

    default:
      throw new AssertionError("unexpected environment: " + environment);
  }

  options.setModuleRoots(ImmutableList.of());

  options.setLanguageIn(LanguageMode.STABLE_IN);
  options.setLanguageOut(LanguageMode.STABLE_OUT);

  options.setCodingConvention(new ClosureCodingConvention());
  CompilationLevel.ADVANCED_OPTIMIZATIONS.setOptionsForCompilationLevel(options);
  CompilationLevel.ADVANCED_OPTIMIZATIONS.setTypeBasedOptimizationOptions(options);

  options.setChecksOnly(true);
  options.setContinueAfterErrors(true);
  options.setAllowHotswapReplaceScript(true);
  options.setPreserveDetailedSourceInfo(true);
  options.setParseJsDocDocumentation(Config.JsDocParsing.INCLUDE_DESCRIPTIONS_WITH_WHITESPACE);

  // For easier debugging.
  options.setPrettyPrint(true);

  options.addCustomPass(CustomPassExecutionTime.BEFORE_CHECKS, providedSymbolPass);
  options.addCustomPass(CustomPassExecutionTime.BEFORE_OPTIMIZATIONS, typeCollectionPass);

  return options;
}
 
Example #18
Source File: TioJsCompressor.java    From t-io with Apache License 2.0 4 votes vote down vote up
@Override
public String compress(String srcFilePath, String srcFileContent) {
	return compress(srcFilePath, srcFileContent, LanguageMode.ECMASCRIPT_NEXT, CompilationLevel.SIMPLE_OPTIMIZATIONS);
	//		return compress(srcFilePath, srcFileContent, CompilationLevel.WHITESPACE_ONLY);
}
 
Example #19
Source File: ClosureJavaScriptCompressor.java    From htmlcompressor with Apache License 2.0 2 votes vote down vote up
/**
 * Returns level of optimization that is applied when compiling JavaScript code.
 * 
 * @return <code>CompilationLevel</code> that is applied when compiling JavaScript code.
 * 
 * @see <a href="http://closure-compiler.googlecode.com/svn/trunk/javadoc/com/google/javascript/jscomp/CompilationLevel.html">CompilationLevel</a>
 */
public CompilationLevel getCompilationLevel() {
	return compilationLevel;
}
 
Example #20
Source File: ClosureJavaScriptCompressor.java    From htmlcompressor with Apache License 2.0 2 votes vote down vote up
/**
 * Sets level of optimization that should be applied when compiling JavaScript code. 
 * If none is provided, <code>CompilationLevel.SIMPLE_OPTIMIZATIONS</code> will be used by default. 
 * 
 * <p><b>Warning:</b> Using <code>CompilationLevel.ADVANCED_OPTIMIZATIONS</code> could 
 * break inline JavaScript if externs are not set properly.
 * 
 * @param compilationLevel Optimization level to use, could be set to <code>CompilationLevel.ADVANCED_OPTIMIZATIONS</code>, <code>CompilationLevel.SIMPLE_OPTIMIZATIONS</code>, <code>CompilationLevel.WHITESPACE_ONLY</code> 
 * 
 * @see <a href="http://code.google.com/closure/compiler/docs/api-tutorial3.html">Advanced Compilation and Externs</a>
 * @see <a href="http://code.google.com/closure/compiler/docs/compilation_levels.html">Closure Compiler Compilation Levels</a>
 * @see <a href="http://closure-compiler.googlecode.com/svn/trunk/javadoc/com/google/javascript/jscomp/CompilationLevel.html">CompilationLevel</a>
 */
public void setCompilationLevel(CompilationLevel compilationLevel) {
	this.compilationLevel = compilationLevel;
}