/* * Copyright 2009 The Closure Compiler Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.javascript.jscomp; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.google.common.collect.Multimap; import com.google.common.collect.Sets; import com.google.javascript.rhino.IR; import com.google.javascript.rhino.Node; import com.google.javascript.rhino.SourcePosition; import java.io.Serializable; import java.nio.charset.Charset; import java.text.ParseException; import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Set; /** * Compiler options * @author nicksantos@google.com (Nick Santos) */ public class CompilerOptions implements Serializable, Cloneable { // Unused. For people using reflection to circumvent access control. @SuppressWarnings("unused") private boolean manageClosureDependencies = false; // A common enum for compiler passes that can run either globally or locally. public enum Reach { ALL, LOCAL_ONLY, NONE } // TODO(nicksantos): All public properties of this class should be made // package-private, and have a public setter. private static final long serialVersionUID = 7L; /** * The JavaScript language version accepted. */ private LanguageMode languageIn; /** * The JavaScript language version that should be produced. * Currently, this is always the same as {@link #languageIn}. */ private LanguageMode languageOut; /** * Whether the compiler accepts the `const' keyword. */ boolean acceptConstKeyword; /** * Whether the compiler should assume that a function's "this" value * never needs coercion (for example in non-strict "null" or "undefined" will * be coerced to the global "this" and primitives to objects). */ private boolean assumeStrictThis; /** * Configures the compiler for use as an IDE backend. In this mode: *
* Calls to the mutators are expected to resolve very quickly, so * implementations should not perform expensive operations in the mutator * methods. * * @author tylerg@google.com (Tyler Goodwin) */ public interface AliasTransformationHandler { /** * Builds an AliasTransformation implementation and returns it to the * caller. *
* Callers are allowed to request multiple AliasTransformation instances for * the same file, though it is expected that the first and last char values * for multiple instances will not overlap. *
* This method is expected to have a side-effect of storing off the created
* AliasTransformation, which guarantees that invokers of this interface
* cannot leak AliasTransformation to this implementation that the
* implementor did not create
*
* @param sourceFile the source file the aliases re contained in.
* @param position the region of the source file associated with the
* goog.scope call. The item of the SourcePosition is the returned
* AliasTransformation
*/
public AliasTransformation logAliasTransformation(
String sourceFile, SourcePosition
* While aliases defined by goog.scope are expected to by only 1 per file, and
* the only top-level structure in the file, this is not enforced.
*/
public interface AliasTransformation {
/**
* Adds an alias definition to the AliasTransformation instance.
*
* Last definition for a given alias is kept if an alias is inserted
* multiple times (since this is generally the behavior in JavaScript code).
*
* @param alias the name of the alias.
* @param definition the definition of the alias.
*/
void addAlias(String alias, String definition);
}
/**
* A Null implementation of the CodeChanges interface which performs all
* operations as a No-Op
*/
static final AliasTransformationHandler NULL_ALIAS_TRANSFORMATION_HANDLER =
new NullAliasTransformationHandler();
private static class NullAliasTransformationHandler
implements AliasTransformationHandler, Serializable {
private static final long serialVersionUID = 0L;
private static final AliasTransformation NULL_ALIAS_TRANSFORMATION =
new NullAliasTransformation();
@Override
public AliasTransformation logAliasTransformation(
String sourceFile, SourcePosition