本文整理汇总了Java中com.google.javascript.jscomp.CompilerOptions.setLanguageOut方法的典型用法代码示例。如果您正苦于以下问题:Java CompilerOptions.setLanguageOut方法的具体用法?Java CompilerOptions.setLanguageOut怎么用?Java CompilerOptions.setLanguageOut使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.javascript.jscomp.CompilerOptions
的用法示例。
在下文中一共展示了CompilerOptions.setLanguageOut方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getCompilerOptions
import com.google.javascript.jscomp.CompilerOptions; //导入方法依赖的package包/类
public CompilerOptions getCompilerOptions() {
final CompilerOptions options = new CompilerOptions();
options.setClosurePass(true);
options.setCheckGlobalNamesLevel(CheckLevel.ERROR);
// Report duplicate definitions, e.g. for accidentally duplicated externs.
options.setWarningLevel(DiagnosticGroups.DUPLICATE_VARS, CheckLevel.ERROR);
options.setLanguage(CompilerOptions.LanguageMode.ECMASCRIPT_2015);
options.setLanguageOut(CompilerOptions.LanguageMode.NO_TRANSPILE);
// Do not transpile module declarations
options.setWrapGoogModulesForWhitespaceOnly(false);
// Stop escaping the characters "=&<>"
options.setTrustedStrings(true);
options.setPreferSingleQuotes(true);
// Compiler passes must be disabled to disable down-transpilation to ES5.
options.skipAllCompilerPasses();
// turns off optimizations.
options.setChecksOnly(true);
options.setPreserveDetailedSourceInfo(true);
options.setParseJsDocDocumentation(Config.JsDocParsing.INCLUDE_DESCRIPTIONS_NO_WHITESPACE);
return options;
}
示例2: setOptions
import com.google.javascript.jscomp.CompilerOptions; //导入方法依赖的package包/类
protected void setOptions(CompilerOptions options) {
options.setLanguageIn(LanguageMode.ECMASCRIPT_NEXT);
// TODO(sdh): It would be nice to allow people to output code in
// strict mode. But currently we swallow all the input language
// strictness checks, and there are various tests that are never
// compiled and so are broken when we output 'use strict'. We
// could consider adding some sort of logging/warning/error in
// cases where the input was not strict, though there could still
// be semantic differences even if syntax is strict. Possibly
// the first step would be to allow the option of outputting strict
// and then change the default and see what breaks. b/33005948
options.setLanguageOut(LanguageMode.ECMASCRIPT5);
options.setQuoteKeywordProperties(true);
options.setSkipNonTranspilationPasses(true);
options.setVariableRenaming(VariableRenamingPolicy.OFF);
options.setPropertyRenaming(PropertyRenamingPolicy.OFF);
options.setWrapGoogModulesForWhitespaceOnly(false);
options.setPrettyPrint(true);
options.setSourceMapOutputPath("/dev/null");
options.setSourceMapIncludeSourcesContent(true);
options.setWarningLevel(ES5_WARNINGS, CheckLevel.OFF);
}
示例3: setOptions
import com.google.javascript.jscomp.CompilerOptions; //导入方法依赖的package包/类
@Override
protected void setOptions(CompilerOptions options) {
options.coalesceVariableNames = false;
options.setLanguageOut(CompilerOptions.LanguageMode.ECMASCRIPT5);
// The next two options together sum to the deprecated ECMASCRIPT6, and
// mimic historical behavior of this class.
options.setLanguageIn(CompilerOptions.LanguageMode.ECMASCRIPT_2015);
options.setStrictModeInput(false);
options.setShadowVariables(false);
// Setting the path to any non-null value will trigger source map generation.
// CompilerBasedTransformer attachs the sourcemap to the result.
options.setSourceMapOutputPath("/dev/null");
options.setVariableRenaming(VariableRenamingPolicy.OFF);
options.instrumentForCoverage = true;
options.setInstrumentForCoverageOnly(true);
}
示例4: setOptions
import com.google.javascript.jscomp.CompilerOptions; //导入方法依赖的package包/类
protected void setOptions(CompilerOptions options) {
options.setLanguageIn(LanguageMode.ECMASCRIPT_2017);
// TODO(sdh): It would be nice to allow people to output code in
// strict mode. But currently we swallow all the input language
// strictness checks, and there are various tests that are never
// compiled and so are broken when we output 'use strict'. We
// could consider adding some sort of logging/warning/error in
// cases where the input was not strict, though there could still
// be semantic differences even if syntax is strict. Possibly
// the first step would be to allow the option of outputting strict
// and then change the default and see what breaks. b/33005948
options.setLanguageOut(LanguageMode.ECMASCRIPT5);
options.setQuoteKeywordProperties(true);
options.setSkipNonTranspilationPasses(true);
options.setVariableRenaming(VariableRenamingPolicy.OFF);
options.setPropertyRenaming(PropertyRenamingPolicy.OFF);
options.setWrapGoogModulesForWhitespaceOnly(false);
options.setPrettyPrint(true);
options.setSourceMapOutputPath("/dev/null");
options.setSourceMapIncludeSourcesContent(true);
options.setWarningLevel(ES5_WARNINGS, CheckLevel.OFF);
}
示例5: createCompilerOptions
import com.google.javascript.jscomp.CompilerOptions; //导入方法依赖的package包/类
private CompilerOptions createCompilerOptions() {
CompilerOptions options = new CompilerOptions();
options.setLanguageOut(ECMASCRIPT5);
options.setChecksOnly(true);
options.setStrictModeInput(true);
options.setCheckTypes(true);
options.setPreserveDetailedSourceInfo(true);
return options;
}
示例6: toCompilerOptions
import com.google.javascript.jscomp.CompilerOptions; //导入方法依赖的package包/类
/** Does just enough to enable parsing of source files. */
public CompilerOptions toCompilerOptions() {
CompilerOptions compilerOptions = new CompilerOptions();
if (this.languageIn != null) {
compilerOptions.setLanguageIn(this.languageIn);
}
if (this.languageOut != null) {
compilerOptions.setLanguageOut(this.languageOut);
}
compilerOptions.setClosurePass(true);
return compilerOptions;
}
示例7: getCompilerOptions
import com.google.javascript.jscomp.CompilerOptions; //导入方法依赖的package包/类
public CompilerOptions getCompilerOptions() {
final CompilerOptions options = new CompilerOptions();
options.setClosurePass(true);
DependencyOptions deps = new DependencyOptions();
deps.setDependencySorting(true);
options.setDependencyOptions(deps);
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.
// Report missing types as errors.
options.setCheckGlobalNamesLevel(CheckLevel.ERROR);
// Report duplicate definitions, e.g. for accidentally duplicated externs.
options.setWarningLevel(DiagnosticGroups.DUPLICATE_VARS, CheckLevel.ERROR);
// Late Provides are errors by default, but they do not prevent clutz from transpiling.
options.setWarningLevel(DiagnosticGroups.LATE_PROVIDE, CheckLevel.OFF);
options.setLanguage(LanguageMode.ECMASCRIPT_2017);
options.setLanguageOut(LanguageMode.ECMASCRIPT5);
options.setCheckTypes(true);
options.setInferTypes(true);
// turns off optimizations.
options.setChecksOnly(true);
options.setPreserveDetailedSourceInfo(true);
options.setParseJsDocDocumentation(Config.JsDocParsing.INCLUDE_DESCRIPTIONS_NO_WHITESPACE);
if (partialInput) {
options.setAssumeForwardDeclaredForMissingTypes(true);
options.setWarningLevel(DiagnosticGroups.MISSING_SOURCES_WARNINGS, CheckLevel.OFF);
}
return options;
}
示例8: getCompilerOptions
import com.google.javascript.jscomp.CompilerOptions; //导入方法依赖的package包/类
@VisibleForTesting
public static CompilerOptions getCompilerOptions() {
CompilerOptions options = new CompilerOptions();
options.setLanguageIn(LanguageMode.ECMASCRIPT_NEXT);
options.setLanguageOut(LanguageMode.ECMASCRIPT5);
options.setSummaryDetailLevel(0);
DependencyOptions deps = new DependencyOptions();
deps.setDependencySorting(true);
options.setDependencyOptions(deps);
options.setChecksOnly(true);
options.setContinueAfterErrors(true);
options.setParseJsDocDocumentation(Config.JsDocParsing.INCLUDE_DESCRIPTIONS_NO_WHITESPACE);
options.setCheckSuspiciousCode(true);
options.setCheckSymbols(true);
options.setCheckTypes(true);
options.setBrokenClosureRequiresLevel(CheckLevel.OFF);
// TODO(bangert): Remove this -- we want to rewrite code before closure syntax is removed.
// Unfortunately, setClosurePass is required, or code doesn't type check.
options.setClosurePass(true);
options.setGenerateExports(true);
options.setPreserveClosurePrimitives(true);
options.setWarningLevel(DiagnosticGroups.STRICT_MISSING_REQUIRE, CheckLevel.WARNING);
options.setWarningLevel(DiagnosticGroups.EXTRA_REQUIRE, CheckLevel.WARNING);
options.setWarningLevel(DiagnosticGroups.LINT_CHECKS, CheckLevel.WARNING);
return options;
}
示例9: parse
import com.google.javascript.jscomp.CompilerOptions; //导入方法依赖的package包/类
private Node parse(String source, String expected, LanguageMode languageIn) {
CompilerOptions options = new CompilerOptions();
options.setLanguageIn(languageIn);
options.setLanguageOut(LanguageMode.ECMASCRIPT6_TYPED);
options.setPreserveTypeAnnotations(true);
options.setPrettyPrint(true);
options.setLineLengthThreshold(80);
options.setPreferSingleQuotes(true);
Compiler compiler = new Compiler();
compiler.setErrorManager(testErrorManager);
compiler.initOptions(options);
Node script = compiler.parse(SourceFile.fromCode("[test]", source));
// Verifying that all warnings were seen
assertTrue("Missing an error", testErrorManager.hasEncounteredAllErrors());
assertTrue("Missing a warning", testErrorManager.hasEncounteredAllWarnings());
if (script != null && testErrorManager.getErrorCount() == 0) {
// if it can be parsed, it should round trip.
String actual = new CodePrinter.Builder(script)
.setCompilerOptions(options)
.setTypeRegistry(compiler.getTypeIRegistry())
.build() // does the actual printing.
.trim();
assertThat(actual).isEqualTo(expected);
}
return script;
}
示例10: execute
import com.google.javascript.jscomp.CompilerOptions; //导入方法依赖的package包/类
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
File theBaseDirectory = new File(buldDirectory);
File theBytecoderDirectory = new File(theBaseDirectory, "bytecoder");
theBytecoderDirectory.mkdirs();
try {
ClassLoader theLoader = prepareClassLoader();
Class theTargetClass = theLoader.loadClass(mainClass);
CompileTarget theCompileTarget = new CompileTarget(theLoader, CompileTarget.BackendType.valueOf(backend));
File theBytecoderFileName = new File(theBytecoderDirectory, theCompileTarget.generatedFileName());
BytecodeMethodSignature theSignature = new BytecodeMethodSignature(BytecodePrimitiveTypeRef.VOID,
new BytecodeTypeRef[] { new BytecodeArrayTypeRef(BytecodeObjectTypeRef.fromRuntimeClass(TString.class), 1) });
CompileOptions theOptions = new CompileOptions(new Slf4JLogger(), debugOutput, KnownOptimizer.ALL, relooperEnabled);
CompileResult theCode = theCompileTarget.compileToJS(theOptions, theTargetClass, "main", theSignature);
try (PrintWriter theWriter = new PrintWriter(new FileWriter(theBytecoderFileName))) {
theWriter.println(theCode.getData());
}
if (optimizeWithGoogleClosure) {
Compiler theCompiler = new Compiler();
CompilerOptions theClosureOptions = new CompilerOptions();
theClosureOptions.setLanguageIn(CompilerOptions.LanguageMode.ECMASCRIPT5_STRICT);
theClosureOptions.setLanguageOut(CompilerOptions.LanguageMode.ECMASCRIPT5_STRICT);
CompilationLevel.valueOf(closureOptimizationLevel).setOptionsForCompilationLevel(theClosureOptions);
List<SourceFile> theSourceFiles = CommandLineRunner.getBuiltinExterns(CompilerOptions.Environment.BROWSER);
theSourceFiles.add(SourceFile.fromCode("bytecoder.js", (String) theCode.getData()));
theCompiler.compile(new ArrayList<>(), theSourceFiles, theClosureOptions);
String theClosureCode = theCompiler.toSource();
File theBytecoderClosureFileName = new File(theBytecoderDirectory, "bytecoder-closure.js");
try (PrintWriter theWriter = new PrintWriter(new FileWriter(theBytecoderClosureFileName))) {
theWriter.println(theClosureCode);
}
}
if (theCode instanceof WASMCompileResult) {
WASMCompileResult theWASMCompileResult = (WASMCompileResult) theCode;
int[] theWASM = wat2wasm(theWASMCompileResult);
File theBytecoderWASMFileName = new File(theBytecoderDirectory, "bytecoder.wasm");
try (FileOutputStream theFos = new FileOutputStream(theBytecoderWASMFileName)) {
for (int aTheWASM : theWASM) {
theFos.write(aTheWASM);
}
}
}
} catch (Exception e) {
throw new MojoExecutionException("Error running bytecoder", e);
}
}
示例11: createCompilerOptions
import com.google.javascript.jscomp.CompilerOptions; //导入方法依赖的package包/类
private CompilerOptions createCompilerOptions() {
CompilerOptions options = new CompilerOptions();
this.compilationLevel.setOptionsForCompilationLevel(options);
if (this.debugOptions) {
this.compilationLevel.setDebugOptionsForCompilationLevel(options);
}
options.setEnvironment(this.environment);
options.setPrettyPrint(this.prettyPrint);
options.setPrintInputDelimiter(this.printInputDelimiter);
options.setPreferSingleQuotes(this.preferSingleQuotes);
options.setGenerateExports(this.generateExports);
options.setLanguageIn(this.languageIn);
options.setLanguageOut(this.languageOut);
options.setOutputCharset(this.outputEncoding);
this.warningLevel.setOptionsForWarningLevel(options);
options.setManageClosureDependencies(manageDependencies);
convertEntryPointParameters(options);
options.setTrustedStrings(true);
options.setAngularPass(angularPass);
if (replaceProperties) {
convertPropertiesMap(options);
}
convertDefineParameters(options);
for (Warning warning : warnings) {
CheckLevel level = warning.getLevel();
String groupName = warning.getGroup();
DiagnosticGroup group = new DiagnosticGroups().forName(groupName);
if (group == null) {
throw new BuildException(
"Unrecognized 'warning' option value (" + groupName + ")");
}
options.setWarningLevel(group, level);
}
if (!Strings.isNullOrEmpty(sourceMapFormat)) {
options.setSourceMapFormat(Format.valueOf(sourceMapFormat));
}
if (!Strings.isNullOrEmpty(sourceMapLocationMapping)) {
String[] tokens = sourceMapLocationMapping.split("\\|", -1);
LocationMapping lm = new LocationMapping(tokens[0], tokens[1]);
options.setSourceMapLocationMappings(Arrays.asList(lm));
}
options.setApplyInputSourceMaps(applyInputSourceMaps);
if (sourceMapOutputFile != null) {
File parentFile = sourceMapOutputFile.getParentFile();
if (parentFile.mkdirs()) {
log("Created missing parent directory " + parentFile, Project.MSG_DEBUG);
}
options.setSourceMapOutputPath(parentFile.getAbsolutePath());
}
return options;
}
示例12: applyDefaultOptions
import com.google.javascript.jscomp.CompilerOptions; //导入方法依赖的package包/类
private static void applyDefaultOptions(CompilerOptions options) {
CompilationLevel.SIMPLE_OPTIMIZATIONS.setOptionsForCompilationLevel(options);
WarningLevel.DEFAULT.setOptionsForWarningLevel(options);
options.setLanguageIn(LanguageMode.ECMASCRIPT_2017);
options.setLanguageOut(LanguageMode.ECMASCRIPT5);
}
示例13: provideCompilerOptions
import com.google.javascript.jscomp.CompilerOptions; //导入方法依赖的package包/类
@Provides
CompilerOptions provideCompilerOptions(
AliasTransformListener transformListener,
ModuleCollectionPass moduleCollectionPass,
ProvidedSymbolPass providedSymbolPass,
TypeCollectionPass typeCollectionPass,
@Modules ImmutableSet<Path> modulePaths)
throws IOException {
CompilerOptions options = new CompilerOptions();
if (modulePaths.isEmpty()) {
options.setEnvironment(CompilerOptions.Environment.BROWSER);
options.setModuleResolutionMode(ModuleLoader.ResolutionMode.BROWSER);
} else {
options.setEnvironment(CompilerOptions.Environment.CUSTOM);
options.setModuleResolutionMode(ModuleLoader.ResolutionMode.NODE);
}
options.setModuleRoots(ImmutableList.of());
options.setLanguageIn(LanguageMode.ECMASCRIPT_2017);
options.setLanguageOut(LanguageMode.ECMASCRIPT5);
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.setAliasTransformationHandler(transformListener);
options.addCustomPass(CustomPassExecutionTime.BEFORE_CHECKS, moduleCollectionPass);
options.addCustomPass(CustomPassExecutionTime.BEFORE_CHECKS, providedSymbolPass);
options.addCustomPass(CustomPassExecutionTime.BEFORE_OPTIMIZATIONS, typeCollectionPass);
return options;
}