use of com.google.javascript.jscomp.ModuleIdentifier in project closure-compiler by google.
the class GwtRunner method applyOptionsFromFlags.
private static void applyOptionsFromFlags(CompilerOptions options, Flags flags) {
CompilationLevel level = DEFAULT_COMPILATION_LEVEL;
if (flags.compilationLevel != null) {
level = CompilationLevel.fromString(Ascii.toUpperCase(flags.compilationLevel));
if (level == null) {
throw new RuntimeException("Bad value for compilationLevel: " + flags.compilationLevel);
}
}
if (level == CompilationLevel.ADVANCED_OPTIMIZATIONS && !flags.renaming) {
throw new RuntimeException("renaming cannot be disabled when ADVANCED_OPTIMIZATIONS is used");
}
level.setOptionsForCompilationLevel(options);
if (flags.assumeFunctionWrapper) {
level.setWrappedOutputOptimizations(options);
}
if (flags.useTypesForOptimization) {
level.setTypeBasedOptimizationOptions(options);
}
WarningLevel warningLevel = WarningLevel.DEFAULT;
if (flags.warningLevel != null) {
warningLevel = WarningLevel.valueOf(flags.warningLevel);
}
warningLevel.setOptionsForWarningLevel(options);
CompilerOptions.Environment environment = CompilerOptions.Environment.BROWSER;
if (flags.env != null) {
environment = CompilerOptions.Environment.valueOf(Ascii.toUpperCase(flags.env));
}
options.setEnvironment(environment);
CompilerOptions.DependencyMode dependencyMode = CompilerOptions.DependencyMode.NONE;
if (flags.dependencyMode != null) {
dependencyMode = CompilerOptions.DependencyMode.valueOf(Ascii.toUpperCase(flags.dependencyMode));
}
List<ModuleIdentifier> entryPoints = createEntryPoints(getStringArray(flags, "entryPoint"));
DependencyOptions dependencyOptions = createDependencyOptions(dependencyMode, entryPoints);
if (dependencyOptions != null) {
options.setDependencyOptions(dependencyOptions);
}
LanguageMode languageIn = LanguageMode.fromString(flags.languageIn);
if (languageIn != null) {
options.setLanguageIn(languageIn);
}
LanguageMode languageOut = LanguageMode.fromString(flags.languageOut);
if (languageOut != null) {
options.setLanguageOut(languageOut);
}
if (flags.createSourceMap) {
options.setSourceMapOutputPath("%output%");
}
if (flags.defines != null) {
// CompilerOptions also validates types, but uses Preconditions and therefore won't generate
// a useful exception.
flags.defines.validatePrimitiveTypes();
options.setDefineReplacements(flags.defines.asMap());
}
if (flags.extraAnnotationNames != null) {
options.setExtraAnnotationNames(Arrays.asList(flags.extraAnnotationNames));
}
if (flags.tracerMode != null) {
options.setTracerMode(TracerMode.valueOf(flags.tracerMode));
}
if (flags.moduleResolutionMode != null) {
options.setModuleResolutionMode(ResolutionMode.valueOf(flags.moduleResolutionMode));
}
if (flags.isolationMode != null && IsolationMode.valueOf(flags.isolationMode) == IsolationMode.IIFE) {
flags.outputWrapper = "(function(){%output%}).call(this);";
}
options.setAngularPass(flags.angularPass);
options.setApplyInputSourceMaps(flags.applyInputSourceMaps);
options.setChecksOnly(flags.checksOnly);
options.setDartPass(flags.dartPass);
options.setExportLocalPropertyDefinitions(flags.exportLocalPropertyDefinitions);
options.setGenerateExports(flags.generateExports);
options.setNewTypeInference(flags.newTypeInf);
if (flags.polymerPass) {
options.setPolymerVersion(1);
} else if (flags.polymerVersion != null) {
options.setPolymerVersion(flags.polymerVersion.intValue());
}
options.setPreserveTypeAnnotations(flags.preserveTypeAnnotations);
options.setClosurePass(flags.processClosurePrimitives);
options.setProcessCommonJSModules(flags.processCommonJsModules);
options.setRenamePrefixNamespace(flags.renamePrefixNamespace);
if (!flags.renaming) {
options.setVariableRenaming(VariableRenamingPolicy.OFF);
options.setPropertyRenaming(PropertyRenamingPolicy.OFF);
}
options.setRewritePolyfills(flags.rewritePolyfills);
}
use of com.google.javascript.jscomp.ModuleIdentifier in project closure-compiler by google.
the class IntegrationTest method testEs6ModuleEntryPointWithSquareBracketsInFilename.
@Test
@GwtIncompatible("AbstractCommandLineRunner.getBuiltinExterns()")
public void testEs6ModuleEntryPointWithSquareBracketsInFilename() throws Exception {
List<SourceFile> inputs = ImmutableList.of(SourceFile.fromCode("/index[0].js", "import foo from './foo.js'; foo('hello');"), SourceFile.fromCode("/foo.js", "export default (foo) => { alert(foo); }"));
List<ModuleIdentifier> entryPoints = ImmutableList.of(ModuleIdentifier.forFile("/index[0].js"));
CompilerOptions options = new CompilerOptions();
CompilationLevel.ADVANCED_OPTIMIZATIONS.setOptionsForCompilationLevel(options);
options.setDependencyOptions(DependencyOptions.pruneLegacyForEntryPoints(entryPoints));
List<SourceFile> externs = AbstractCommandLineRunner.getBuiltinExterns(options.getEnvironment());
Compiler compiler = new Compiler();
compiler.compile(externs, inputs, options);
Result result = compiler.getResult();
assertThat(result.warnings).isEmpty();
assertThat(result.errors).isEmpty();
}
use of com.google.javascript.jscomp.ModuleIdentifier in project closure-compiler by google.
the class IntegrationTest method testEs6ModuleEntryPoint.
@Test
@GwtIncompatible("AbstractCommandLineRunner.getBuiltinExterns()")
public void testEs6ModuleEntryPoint() throws Exception {
List<SourceFile> inputs = ImmutableList.of(SourceFile.fromCode("/index.js", "import foo from './foo.js'; foo('hello');"), SourceFile.fromCode("/foo.js", "export default (foo) => { alert(foo); }"));
List<ModuleIdentifier> entryPoints = ImmutableList.of(ModuleIdentifier.forFile("/index"));
CompilerOptions options = new CompilerOptions();
CompilationLevel.ADVANCED_OPTIMIZATIONS.setOptionsForCompilationLevel(options);
options.setDependencyOptions(DependencyOptions.pruneLegacyForEntryPoints(entryPoints));
List<SourceFile> externs = AbstractCommandLineRunner.getBuiltinExterns(options.getEnvironment());
Compiler compiler = new Compiler();
compiler.compile(externs, inputs, options);
Result result = compiler.getResult();
assertThat(result.warnings).isEmpty();
assertThat(result.errors).isEmpty();
}
Aggregations