Search in sources :

Example 1 with ModuleIdentifier

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);
}
Also used : CompilationLevel(com.google.javascript.jscomp.CompilationLevel) LanguageMode(com.google.javascript.jscomp.CompilerOptions.LanguageMode) WarningLevel(com.google.javascript.jscomp.WarningLevel) CompilerOptions(com.google.javascript.jscomp.CompilerOptions) DependencyOptions(com.google.javascript.jscomp.DependencyOptions) ModuleIdentifier(com.google.javascript.jscomp.ModuleIdentifier)

Example 2 with ModuleIdentifier

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();
}
Also used : Compiler(com.google.javascript.jscomp.Compiler) CompilerOptions(com.google.javascript.jscomp.CompilerOptions) SourceFile(com.google.javascript.jscomp.SourceFile) ModuleIdentifier(com.google.javascript.jscomp.ModuleIdentifier) Result(com.google.javascript.jscomp.Result) Test(org.junit.Test) GwtIncompatible(com.google.common.annotations.GwtIncompatible)

Example 3 with ModuleIdentifier

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();
}
Also used : Compiler(com.google.javascript.jscomp.Compiler) CompilerOptions(com.google.javascript.jscomp.CompilerOptions) SourceFile(com.google.javascript.jscomp.SourceFile) ModuleIdentifier(com.google.javascript.jscomp.ModuleIdentifier) Result(com.google.javascript.jscomp.Result) Test(org.junit.Test) GwtIncompatible(com.google.common.annotations.GwtIncompatible)

Aggregations

CompilerOptions (com.google.javascript.jscomp.CompilerOptions)3 ModuleIdentifier (com.google.javascript.jscomp.ModuleIdentifier)3 GwtIncompatible (com.google.common.annotations.GwtIncompatible)2 Compiler (com.google.javascript.jscomp.Compiler)2 Result (com.google.javascript.jscomp.Result)2 SourceFile (com.google.javascript.jscomp.SourceFile)2 Test (org.junit.Test)2 CompilationLevel (com.google.javascript.jscomp.CompilationLevel)1 LanguageMode (com.google.javascript.jscomp.CompilerOptions.LanguageMode)1 DependencyOptions (com.google.javascript.jscomp.DependencyOptions)1 WarningLevel (com.google.javascript.jscomp.WarningLevel)1