Class FeatureSet

  • All Implemented Interfaces:
    java.io.Serializable

    @Immutable
    public final class FeatureSet
    extends java.lang.Object
    implements java.io.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:
    Serialized Form
    • Field Detail

      • 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.
      • ES6_MODULES

        public static final FeatureSet ES6_MODULES
        All ES6 features, including modules.
      • ES6

        public static final FeatureSet ES6
        The full set of ES6 features, not including modules.
      • ES7_MODULES

        public static final FeatureSet ES7_MODULES
      • ES8_MODULES

        public static final FeatureSet ES8_MODULES
      • ES2018_MODULES

        public static final FeatureSet ES2018_MODULES
      • ES2019_MODULES

        public static final FeatureSet ES2019_MODULES
      • ES2020_MODULES

        public static final FeatureSet ES2020_MODULES
      • ES_NEXT_IN

        public static final FeatureSet ES_NEXT_IN
      • ES_UNSUPPORTED

        public static final FeatureSet ES_UNSUPPORTED
      • TYPESCRIPT

        public static final FeatureSet TYPESCRIPT
      • BROWSER_2020

        public static final FeatureSet BROWSER_2020
      • TS_UNSUPPORTED

        public static final FeatureSet TS_UNSUPPORTED
    • Method Detail

      • version

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

        public java.lang.String versionForDebugging()
        Returns a string representation useful for debugging.

        This is not suitable for encoding in deps.js or depgraph files, because it may return strings like 'otiSupported' and 'ntiSupported' which are not real language modes.

      • contains

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

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

        public FeatureSet with​(java.util.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.
      • getFeatures

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

        public boolean equals​(java.lang.Object other)
        Overrides:
        equals in class java.lang.Object
      • hashCode

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

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

        public static FeatureSet valueOf​(java.lang.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.everything() 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.