Search in sources :

Example 1 with DependencyOptions

use of com.google.javascript.jscomp.DependencyOptions 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)

Aggregations

CompilationLevel (com.google.javascript.jscomp.CompilationLevel)1 CompilerOptions (com.google.javascript.jscomp.CompilerOptions)1 LanguageMode (com.google.javascript.jscomp.CompilerOptions.LanguageMode)1 DependencyOptions (com.google.javascript.jscomp.DependencyOptions)1 ModuleIdentifier (com.google.javascript.jscomp.ModuleIdentifier)1 WarningLevel (com.google.javascript.jscomp.WarningLevel)1