Search in sources :

Example 16 with FeatureSet

use of com.google.javascript.jscomp.parsing.parser.FeatureSet in project closure-compiler by google.

the class RewritePolyfills method inject.

private void inject(PolyfillUsage polyfillUsage) {
    Polyfill polyfill = polyfillUsage.polyfill();
    final FeatureSet outputFeatureSet = compiler.getOptions().getOutputFeatureSet();
    final FeatureSet featuresRequiredByPolyfill = FeatureSet.valueOf(polyfill.polyfillVersion);
    if (polyfill.kind.equals(Polyfill.Kind.STATIC) && !outputFeatureSet.contains(featuresRequiredByPolyfill)) {
        compiler.report(JSError.make(polyfillUsage.node(), INSUFFICIENT_OUTPUT_VERSION_ERROR, polyfillUsage.name(), outputFeatureSet.version()));
    }
    // version that introduced this symbol?"
    if (!outputFeatureSet.contains(FeatureSet.valueOf(polyfill.nativeVersion)) && !polyfill.library.isEmpty()) {
        libraries.add(polyfill.library);
    }
}
Also used : Polyfill(com.google.javascript.jscomp.PolyfillUsageFinder.Polyfill) FeatureSet(com.google.javascript.jscomp.parsing.parser.FeatureSet)

Example 17 with FeatureSet

use of com.google.javascript.jscomp.parsing.parser.FeatureSet in project closure-compiler by google.

the class TranspilationPasses method processTranspile.

/**
 * Process transpilations if the input language needs transpilation from certain features, on any
 * JS file that has features not present in the compiler's output language mode.
 *
 * @param compiler An AbstractCompiler
 * @param combinedRoot The combined root for all JS files.
 * @param featureSet Ignored
 * @param callbacks The callbacks that should be invoked if a file has ES2015 features.
 * @deprecated Please use a regular NodeTraversal object directly, using `shouldTraverse` to skip
 *     SCRIPT node if desired.
 */
@Deprecated
static void processTranspile(AbstractCompiler compiler, Node combinedRoot, FeatureSet featureSet, NodeTraversal.Callback... callbacks) {
    FeatureSet languageOutFeatures = compiler.getOptions().getOutputFeatureSet();
    for (Node singleRoot = combinedRoot.getFirstChild(); singleRoot != null; singleRoot = singleRoot.getNext()) {
        // added to that file by other transpilation passes.
        if (doesScriptHaveUnsupportedFeatures(singleRoot, languageOutFeatures)) {
            for (NodeTraversal.Callback callback : callbacks) {
                singleRoot.putBooleanProp(Node.TRANSPILED, true);
                NodeTraversal.traverse(compiler, singleRoot, callback);
            }
        }
    }
}
Also used : Node(com.google.javascript.rhino.Node) FeatureSet(com.google.javascript.jscomp.parsing.parser.FeatureSet)

Aggregations

FeatureSet (com.google.javascript.jscomp.parsing.parser.FeatureSet)17 Node (com.google.javascript.rhino.Node)14 MemberDefinition (com.google.javascript.jscomp.PolymerPass.MemberDefinition)4 JSDocInfo (com.google.javascript.rhino.JSDocInfo)4 Nullable (javax.annotation.Nullable)3 ImmutableList (com.google.common.collect.ImmutableList)2 BehaviorDefinition (com.google.javascript.jscomp.PolymerBehaviorExtractor.BehaviorDefinition)2 ArrayList (java.util.ArrayList)2 Name (com.google.javascript.jscomp.GlobalNamespace.Name)1 Ref (com.google.javascript.jscomp.GlobalNamespace.Ref)1 Polyfill (com.google.javascript.jscomp.PolyfillUsageFinder.Polyfill)1 Parser (com.google.javascript.jscomp.parsing.parser.Parser)1 SourceFile (com.google.javascript.jscomp.parsing.parser.SourceFile)1 Comment (com.google.javascript.jscomp.parsing.parser.trees.Comment)1 ProgramTree (com.google.javascript.jscomp.parsing.parser.trees.ProgramTree)1 JSDocInfoBuilder (com.google.javascript.rhino.JSDocInfoBuilder)1 JSTypeExpression (com.google.javascript.rhino.JSTypeExpression)1 StaticSourceFile (com.google.javascript.rhino.StaticSourceFile)1 LinkedHashMap (java.util.LinkedHashMap)1 TreeMap (java.util.TreeMap)1