java.lang.Object
com.google.javascript.jscomp.parsing.parser.FeatureSet
All Implemented Interfaces:
Serializable

@Immutable public final class FeatureSet extends Object implements Serializable
Represents various aspects of language version and support.

This is somewhat redundant with LanguageMode, but is separate for two reasons: (1) it's used for parsing, which cannot depend on LanguageMode, and (2) it's concerned with slightly different nuances: implemented features and modules rather than strictness.

In the long term, it would be good to disentangle all these concerns and pull out a single LanguageSyntax enum with a separate strict mode flag, and then these could possibly be unified.

Instances of this class are immutable.

See Also:
  • Field Details

    • BARE_MINIMUM

      public static final FeatureSet BARE_MINIMUM
      The bare minimum set of features.
    • ES3

      public static final FeatureSet ES3
      Features from ES3.
    • ES5

      public static final FeatureSet ES5
      Features from ES5 only.
    • ES2015_MODULES

      public static final FeatureSet ES2015_MODULES
      All ES2015 features, including modules.
    • ES2015

      public static final FeatureSet ES2015
      The full set of ES2015 features, not including modules.
    • ES2016_MODULES

      public static final FeatureSet ES2016_MODULES
    • ES2016

      public static final FeatureSet ES2016
    • ES2017_MODULES

      public static final FeatureSet ES2017_MODULES
    • ES2017

      public static final FeatureSet ES2017
    • ES2018_MODULES

      public static final FeatureSet ES2018_MODULES
    • ES2018

      public static final FeatureSet ES2018
    • ES2019_MODULES

      public static final FeatureSet ES2019_MODULES
    • ES2019

      public static final FeatureSet ES2019
    • ES2020_MODULES

      public static final FeatureSet ES2020_MODULES
    • ES2020

      public static final FeatureSet ES2020
    • ES2021_MODULES

      public static final FeatureSet ES2021_MODULES
    • ES2021

      public static final FeatureSet ES2021
    • ES_NEXT

      public static final FeatureSet ES_NEXT
    • ES_UNSTABLE

      public static final FeatureSet ES_UNSTABLE
    • ES_UNSUPPORTED

      public static final FeatureSet ES_UNSUPPORTED
    • BROWSER_2020

      public static final FeatureSet BROWSER_2020
    • BROWSER_2021

      public static final FeatureSet BROWSER_2021
    • BROWSER_2022

      public static final FeatureSet BROWSER_2022
    • BROWSER_2023

      public static final FeatureSet BROWSER_2023
    • BROWSER_2024

      public static final FeatureSet BROWSER_2024
    • BROWSER_2025

      public static final FeatureSet BROWSER_2025
    • ALL

      public static final FeatureSet ALL
  • Method Details

    • version

      public String version()
      Returns a string representation suitable for use in polyfill definition files and encoding in depgraph and deps.js files.
    • versionForDebugging

      @Deprecated @InlineMe(replacement="this.version()") public String versionForDebugging()
      Deprecated.
      Please use version() instead.
      Returns a string representation useful for debugging.
    • without

      public FeatureSet without(FeatureSet.Feature featureToRemove, FeatureSet.Feature... moreFeaturesToRemove)
    • without

      public FeatureSet without(FeatureSet other)
    • withoutTypes

      public FeatureSet withoutTypes()
    • union

      public FeatureSet union(FeatureSet other)
      Returns a new FeatureSet including all features of both this and other.
    • containsAtLeastOneOf

      public boolean containsAtLeastOneOf(FeatureSet other)
      Does this FeatureSet contain at least one of the features of other?
    • contains

      public boolean contains(FeatureSet other)
      Does this FeatureSet contain all of the features of other?
    • contains

      public boolean contains(FeatureSet.Feature feature)
      Does this FeatureSet contain the given feature?
    • with

      public FeatureSet with(FeatureSet.Feature feature)
      Returns a feature set combining all the features from this and feature.
    • with

      public FeatureSet with(FeatureSet.Feature... newFeatures)
      Returns a feature set combining all the features from this and newFeatures.
    • with

      public FeatureSet with(Set<FeatureSet.Feature> newFeatures)
      Returns a feature set combining all the features from this and newFeatures.
    • with

      public FeatureSet with(FeatureSet newFeatures)
      Returns a feature set combining all the features from this and newFeatures.
    • has

      public boolean has(FeatureSet.Feature feature)
      Does this FeatureSet include feature?
    • getFeatures

      public com.google.common.collect.ImmutableSet<FeatureSet.Feature> getFeatures()
    • equals

      public boolean equals(Object other)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • valueOf

      public static FeatureSet valueOf(String name)
      Parses known strings into feature sets.
    • all

      public static FeatureSet all()
      Returns a FeatureSet containing all known features.

      NOTE: PassFactory classes that claim to support FeatureSet.all() should be only those that cannot be broken by new features being added to the language. Mainly these are passes that don't have to actually look at the AST at all, like empty marker passes.

    • latest

      public static FeatureSet latest()