/** Returns a string representation suitable for encoding in depgraph and deps.js files. */ public String version() { if (ES3.contains(this)) { return "es3"; } if (ES5.contains(this)) { return "es5"; } if (ES6_MODULES.contains(this)) { return "es6"; } if (ES7_MODULES.contains(this)) { return "es7"; } if (ES8_MODULES.contains(this)) { return "es8"; } if (ES2018_MODULES.contains(this)) { return "es9"; } if (ES_NEXT.contains(this)) { return "es_next"; } if (TYPESCRIPT.contains(this)) { return "ts"; } throw new IllegalStateException(this.toString()); }
/** * @param script The SCRIPT node representing a JS file * @return If the file has any features which are part of ES6 or higher but not part of ES5. */ static boolean isScriptEs6OrHigher(Node script) { FeatureSet features = NodeUtil.getFeatureSetOfScript(script); return features != null && !FeatureSet.ES5.contains(features); }
/** Returns the lowest {@link LanguageMode} that supports the specified feature set. */ public static LanguageMode minimumRequiredForSet(FeatureSet featureSet) { for (LanguageMode mode : LanguageMode.values()) { if (mode.featureSet.contains(featureSet)) { return mode; } } throw new IllegalStateException("No input language mode supports feature set: " + featureSet); }
static Format fromOptions(CompilerOptions options, boolean outputTypes, boolean prettyPrint) { if (outputTypes) { return Format.TYPED; } if (prettyPrint || options.getOutputFeatureSet().contains(FeatureSet.TYPESCRIPT)) { return Format.PRETTY; } return Format.COMPACT; } }
public boolean shouldQuoteKeywordProperties() { // Never quote properties in .i.js files if (incrementalCheckMode == IncrementalCheckMode.GENERATE_IJS) { return false; } return this.quoteKeywordProperties || FeatureSet.ES3.contains(getOutputFeatureSet()); }
/** * @param script The SCRIPT node representing a JS file * @return If the file has any features not in {@code supportedFeatures} */ static boolean doesScriptHaveUnsupportedFeatures(Node script, FeatureSet supportedFeatures) { FeatureSet features = NodeUtil.getFeatureSetOfScript(script); return features != null && !supportedFeatures.contains(features); }
boolean isEs5OrBetterMode() { return config.languageMode().featureSet.contains(FeatureSet.ES5); }
public boolean needsTranspilationFrom(FeatureSet languageLevel) { // TODO(johnplaisted): This isn't really accurate. This should instead be the *parsed* language, // not the *input* language. return getLanguageIn().toFeatureSet().contains(languageLevel) && !getOutputFeatureSet().contains(languageLevel); }
public Es6InjectRuntimeLibraries(AbstractCompiler compiler) { this.compiler = compiler; this.getterSetterSupported = !FeatureSet.ES3.contains(compiler.getOptions().getOutputFeatureSet()); }
/** * Returns whether the output language is ECMAScript 5 or later. Workarounds for quirks in * browsers that do not support ES5 can be ignored when this is true. */ protected boolean isEcmaScript5OrGreater() { return compiler != null && compiler.getOptions().getOutputFeatureSet().contains(FeatureSet.ES5); }
public DartSuperAccessorsPass(AbstractCompiler compiler) { this.compiler = compiler; CompilerOptions options = compiler.getOptions(); this.renameProperties = options.propertyRenaming == PropertyRenamingPolicy.ALL_UNQUOTED; checkState( options.getOutputFeatureSet().contains(FeatureSet.ES5), "Dart super accessors pass requires ES5+ output"); // We currently rely on JSCompiler_renameProperty, which is not type-aware. // We would need something like goog.reflect.object (with the super class type), // but right now this would yield much larger code. checkState( !options.shouldAmbiguateProperties() && !options.shouldDisambiguateProperties(), "Dart super accessors pass is not compatible with property (dis)ambiguation yet"); }
private boolean languageOutIsAtLeast(LanguageMode mode) { return compiler.getOptions().getOutputFeatureSet().contains(mode.toFeatureSet()); }
@Override protected CompilerPass create(final AbstractCompiler compiler) { return new ClosureOptimizePrimitives( compiler, compiler.getOptions().propertyRenaming == PropertyRenamingPolicy.ALL_UNQUOTED, compiler.getOptions().getOutputFeatureSet().contains(ES6)); }
break; if (untranspilableFeaturesToRemove.contains(Feature.REGEXP_FLAG_S)) { checkForRegExpSFlag(n); if (untranspilableFeaturesToRemove.contains(Feature.REGEXP_LOOKBEHIND)) { checkForLookbehind(n, reg); if (untranspilableFeaturesToRemove.contains(Feature.REGEXP_NAMED_GROUPS)) { checkForNamedGroups(n, reg); if (untranspilableFeaturesToRemove.contains(Feature.REGEXP_UNICODE_PROPERTY_ESCAPE)) { checkForUnicodePropertyEscape(n, reg);
@Override public boolean shouldTraverse(NodeTraversal t, Node n, Node parent) { switch (n.getToken()) { case GETTER_DEF: case SETTER_DEF: if (FeatureSet.ES3.contains(compiler.getOptions().getOutputFeatureSet())) { Es6ToEs3Util.cannotConvert( compiler, n, "ES5 getters/setters (consider using --language_out=ES5)"); return false; } break; case FUNCTION: if (n.isAsyncFunction()) { throw new IllegalStateException("async functions should have already been converted"); } break; default: break; } return true; }
private boolean shouldProcess(Node root) { if (!forTranspileOnly) { return true; } if (compiler.getOptions().getLanguageIn().toFeatureSet().contains(FeatureSet.ES6)) { for (Node singleRoot : root.children()) { if (TranspilationPasses.isScriptEs6OrHigher(singleRoot)) { return true; } } } return false; }
@Override public boolean shouldTraverse(NodeTraversal t, Node n, Node parent) { switch (n.getToken()) { case GETTER_DEF: case SETTER_DEF: if (FeatureSet.ES3.contains(compiler.getOptions().getOutputFeatureSet())) { cannotConvert(n, "ES5 getters/setters (consider using --language_out=ES5)"); return false; } break; case NEW_TARGET: cannotConvertYet(n, "new.target"); break; default: break; } return true; }
@Override public void hotSwapScript(Node scriptRoot, Node originalRoot) { if (!forTranspileOnly || (compiler.getOptions().getLanguageIn().toFeatureSet().contains(FeatureSet.ES6) && TranspilationPasses.isScriptEs6OrHigher(scriptRoot))) { new ReferenceCollectingCallback( compiler, new ReferenceCheckingBehavior(), new Es6SyntacticScopeCreator(compiler)) .hotSwapScript(scriptRoot, originalRoot); } }
if (!options.getOutputFeatureSet().contains(FeatureSet.ES5)) { throw new InvalidOptionsException("Dart requires --language_out=ES5 or higher.");
cfg, scope, null, compiler, new Es6SyntacticScopeCreator(compiler)); if (FeatureSet.ES3.contains(compiler.getOptions().getOutputFeatureSet())) {