public static Config createConfig(boolean isIdeMode, boolean parseJsDocDocumentation, boolean preserveJsDocWhitespace, LanguageMode languageMode, Set<String> extraAnnotationNames) { initResourceConfig(); Set<String> effectiveAnnotationNames; if (extraAnnotationNames == null) { effectiveAnnotationNames = annotationNames; } else { effectiveAnnotationNames = new HashSet<String>(annotationNames); effectiveAnnotationNames.addAll(extraAnnotationNames); } return new Config(effectiveAnnotationNames, suppressionNames, isIdeMode, parseJsDocDocumentation, preserveJsDocWhitespace, languageMode); }
@Override public boolean equals(Object o) { if (o == this) { return true; } if (o instanceof Config) { Config that = (Config) o; return (this.languageMode.equals(that.languageMode())) && (this.strictMode.equals(that.strictMode())) && (this.jsDocParsingMode.equals(that.jsDocParsingMode())) && (this.runMode.equals(that.runMode())) && (this.annotations.equals(that.annotations())) && (this.suppressionNames.equals(that.suppressionNames())) && (this.parseInlineSourceMaps == that.parseInlineSourceMaps()); } return false; }
Config(Set<String> annotationWhitelist, Set<String> suppressionNames, boolean isIdeMode, boolean parseJsDocDocumentation, boolean preserveJsDocWhitespace, LanguageMode languageMode) { this.annotationNames = buildAnnotationNames(annotationWhitelist); this.parseJsDocDocumentation = parseJsDocDocumentation; this.preserveJsDocWhitespace = preserveJsDocWhitespace; this.suppressionNames = suppressionNames; this.isIdeMode = isIdeMode; this.languageMode = languageMode; }
private static com.google.javascript.jscomp.parsing.parser.Parser.Config newParserConfig( Config config) { LanguageMode languageMode = config.languageMode(); boolean isStrictMode = config.strictMode().isStrict(); Mode parserConfigLanguageMode = null; switch (languageMode) { case TYPESCRIPT: parserConfigLanguageMode = Mode.TYPESCRIPT; break; case ECMASCRIPT3: parserConfigLanguageMode = Mode.ES3; break; case ECMASCRIPT5: parserConfigLanguageMode = Mode.ES5; break; case ECMASCRIPT6: case ECMASCRIPT7: parserConfigLanguageMode = Mode.ES6_OR_ES7; break; case ECMASCRIPT8: case ECMASCRIPT_2018: parserConfigLanguageMode = Mode.ES8_OR_GREATER; break; case ES_NEXT: parserConfigLanguageMode = Mode.ES_NEXT; break; } return new com.google.javascript.jscomp.parsing.parser.Parser.Config( checkNotNull(parserConfigLanguageMode), isStrictMode); }
JsDocInfoParser(JsDocTokenStream stream, String comment, int commentPosition, Node templateNode, Config config, ErrorReporter errorReporter) { this.stream = stream; boolean parseDocumentation = config.jsDocParsingMode().shouldParseDescriptions(); this.jsdocBuilder = new JSDocInfoBuilder(parseDocumentation); if (comment != null) { this.jsdocBuilder.recordOriginalCommentString(comment); this.jsdocBuilder.recordOriginalCommentPosition(commentPosition); } this.annotations = config.annotations(); this.suppressionNames = config.suppressionNames(); this.preserveWhitespace = config.jsDocParsingMode().shouldPreserveWhitespace(); this.errorReporter = errorReporter; this.templateNode = templateNode == null ? IR.script() : templateNode; }
private IRFactory(String sourceString, StaticSourceFile sourceFile, Config config, ErrorReporter errorReporter, ImmutableList<Comment> comments) { this.sourceString = sourceString; this.nextCommentIter = comments.iterator(); this.currentComment = skipNonJsDoc(nextCommentIter); this.sourceFile = sourceFile; // The template node properties are applied to all nodes in this transform. this.templateNode = createTemplateNode(); this.fileLevelJsDocBuilder = new JSDocInfoBuilder(config.jsDocParsingMode().shouldParseDescriptions()); // Sometimes this will be null in tests. this.sourceName = sourceFile == null ? null : sourceFile.getName(); this.config = config; this.errorReporter = errorReporter; this.transformDispatcher = new TransformDispatcher(); if (config.strictMode().isStrict()) { reservedKeywords = ES5_STRICT_RESERVED_KEYWORDS; } else if (config.languageMode() == LanguageMode.ECMASCRIPT3) { reservedKeywords = null; // use TokenStream.isKeyword instead } else { reservedKeywords = ES5_RESERVED_KEYWORDS; } }
boolean isEs5OrBetterMode() { return config.languageMode().featureSet.contains(FeatureSet.ES5); }
try { SourceFile file = new SourceFile(sourceName, sourceString); boolean keepGoing = config.runMode() == Config.RunMode.KEEP_GOING; Es6ErrorReporter es6ErrorReporter = new Es6ErrorReporter(errorReporter, keepGoing); com.google.javascript.jscomp.parsing.parser.Parser.Config es6config = newParserConfig(config); root.putProp(Node.FEATURE_SET, features); if (config.jsDocParsingMode().shouldParseDescriptions()) { comments = p.getComments();
private static JsDocInfoParser getParser(String toParse) { Config config = Config.builder() .setLanguageMode(LanguageMode.ECMASCRIPT3) .setStrictMode(Config.StrictMode.SLOPPY) .build(); JsDocInfoParser parser = new JsDocInfoParser( new JsDocTokenStream(toParse), toParse, 0, null, config, ErrorReporter.NULL_INSTANCE); return parser; }
final ImmutableSet<String> annotationNames() { return annotations().keySet(); }
private boolean inStrictContext() { // TODO(johnlenz): in ECMASCRIPT5/6 is a "mixed" mode and we should track the context // that we are in, if we want to support it. return config.strictMode().isStrict(); }
checkState(config.runMode() == Config.RunMode.KEEP_GOING); bodyNode = IR.block();
boolean isSupportedForInputLanguageMode(Feature feature) { return config.languageMode().featureSet.has(feature); }
public static Config createConfig( LanguageMode languageMode, JsDocParsing jsdocParsingMode, RunMode runMode, Set<String> extraAnnotationNames, boolean parseInlineSourceMaps, StrictMode strictMode) { initResourceConfig(); Set<String> effectiveAnnotationNames; if (extraAnnotationNames == null) { effectiveAnnotationNames = annotationNames; } else { effectiveAnnotationNames = new HashSet<>(annotationNames); effectiveAnnotationNames.addAll(extraAnnotationNames); } return Config.builder() .setExtraAnnotationNames(effectiveAnnotationNames) .setJsDocParsingMode(jsdocParsingMode) .setRunMode(runMode) .setSuppressionNames(suppressionNames) .setLanguageMode(languageMode) .setParseInlineSourceMaps(parseInlineSourceMaps) .setStrictMode(strictMode) .build(); }
/** Reports an illegal setter and returns true if the language mode is too low. */ boolean maybeReportSetter(ParseTree node) { features = features.with(Feature.SETTER); if (config.languageMode() == LanguageMode.ECMASCRIPT3) { errorReporter.error( SETTER_ERROR_MESSAGE, sourceName, lineno(node), 0); return true; } return false; }
Config.builder() .setLanguageMode(Config.LanguageMode.ECMASCRIPT6) .setStrictMode(Config.StrictMode.SLOPPY)
private static JsDocInfoParser getParser(String toParse) { Config config = new Config( new HashSet<String>(), new HashSet<String>(), false, LanguageMode.ECMASCRIPT3); JsDocInfoParser parser = new JsDocInfoParser( new JsDocTokenStream(toParse), toParse, 0, null, config, NullErrorReporter.forOldRhino()); return parser; }
/** Reports an illegal getter and returns true if the language mode is too low. */ boolean maybeReportGetter(ParseTree node) { features = features.with(Feature.GETTER); if (config.languageMode() == LanguageMode.ECMASCRIPT3) { errorReporter.error( GETTER_ERROR_MESSAGE, sourceName, lineno(node), 0); return true; } return false; }
Config config = new Config(new HashSet<String>(), new HashSet<String>(), true, LanguageMode.ECMASCRIPT6);
private void maybeWarnReservedKeyword(IdentifierToken token) { String identifier = token.value; boolean isIdentifier = false; if (TokenStream.isKeyword(identifier)) { features = features.with(Feature.ES3_KEYWORDS_AS_IDENTIFIERS); isIdentifier = config.languageMode() == LanguageMode.ECMASCRIPT3; } if (reservedKeywords != null && reservedKeywords.contains(identifier)) { features = features.with(Feature.KEYWORDS_AS_PROPERTIES); isIdentifier = config.languageMode() == LanguageMode.ECMASCRIPT3; } if (isIdentifier) { errorReporter.error( "identifier is a reserved word", sourceName, lineno(token.location.start), charno(token.location.start)); } }