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); }
private ParserRunner.ParseResult parse(String source, StaticSourceFile sourceFile) { ErrorReporter errorReporter = new ErrorReporter(){ @Override public void warning(String message, String sourceName, int line, int lineOffset) { logger.log(Level.WARNING, "{0}, sourceName: {1}, line: {2} lineOffset: {3}", new Object[]{message, sourceName, line, lineOffset}); } @Override public void error(String message, String sourceName, int line, int lineOffset) { logger.log(Level.SEVERE, "{0}, sourceName: {1}, line: {2} lineOffset: {3}", new Object[]{message, sourceName, line, lineOffset}); } }; ParserRunner.ParseResult parseResult = ParserRunner.parse( sourceFile, source, config, errorReporter); return parseResult; }
private static synchronized void initResourceConfig() { if (annotationNames != null) { return; } ResourceBundle config = ResourceBundle.getBundle(CONFIG_RESOURCE); annotationNames = extractList(config.getString("jsdoc.annotations")); suppressionNames = extractList(config.getString("jsdoc.suppressions")); reservedVars = extractList(config.getString("compiler.reserved.vars")); }
public static Config createConfig( LanguageMode languageMode, Set<String> extraAnnotationNames, StrictMode strictMode) { return createConfig( languageMode, JsDocParsing.TYPES_ONLY, RunMode.STOP_AFTER_ERROR, extraAnnotationNames, true, strictMode); }
public static Set<String> getReservedVars() { initResourceConfig(); return reservedVars; }
private VariableMap runVariableRenaming( AbstractCompiler compiler, VariableMap prevVariableMap, Node externs, Node root) { char[] reservedChars = options.anonymousFunctionNaming.getReservedCharacters(); boolean preserveAnonymousFunctionNames = options.anonymousFunctionNaming != AnonymousFunctionNamingPolicy.OFF; Set<String> reservedNames = new HashSet<>(); if (options.renamePrefixNamespace != null) { // don't use the prefix name as a global symbol. reservedNames.add(options.renamePrefixNamespace); } reservedNames.addAll(compiler.getExportedNames()); reservedNames.addAll(ParserRunner.getReservedVars()); RenameVars rn = new RenameVars( compiler, options.renamePrefix, options.variableRenaming == VariableRenamingPolicy.LOCAL, preserveAnonymousFunctionNames, options.generatePseudoNames, options.shadowVariables, options.preferStableNames, prevVariableMap, reservedChars, reservedNames, options.nameGenerator); rn.process(externs, root); return rn.getVariableMap(); }
public static FeatureSet detectFeatures(String sourcePath, String sourceString) { SourceFile file = new SourceFile(sourcePath, sourceString); ErrorReporter reporter = IRFactory.NULL_REPORTER; com.google.javascript.jscomp.parsing.parser.Parser.Config config = new com.google.javascript.jscomp.parsing.parser.Parser.Config(mode( IRFactory.NULL_CONFIG.languageMode)); Parser p = new Parser(config, new Es6ErrorReporter(reporter, false), file); ProgramTree tree = p.parseProgram(); StaticSourceFile simpleSourceFile = new SimpleSourceFile(sourcePath, false); return IRFactory.detectFeatures(tree, simpleSourceFile, sourceString).require(p.getFeatures()); }
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); Parser p = new Parser(es6config, es6ErrorReporter, file); ProgramTree tree = p.parseProgram();
protected Config createConfig(Config.LanguageMode mode, Config.StrictMode strictMode) { Config config = ParserRunner.createConfig( mode, options.isParseJsDocDocumentation(), options.canContinueAfterErrors() ? Config.RunMode.KEEP_GOING : Config.RunMode.STOP_AFTER_ERROR, options.extraAnnotationNames, options.parseInlineSourceMaps, strictMode); return config; }
public static Set<String> getReservedVars() { initResourceConfig(); return reservedVars; }
reservedNames.addAll(exportedNames); reservedNames.addAll(ParserRunner.getReservedVars()); RenameVars rn = new RenameVars( compiler,
public static ParseResult parse( StaticSourceFile sourceFile, String sourceString, Config config, ErrorReporter errorReporter) { // TODO(johnlenz): unify "SourceFile", "Es6ErrorReporter" and "Config" SourceFile file = new SourceFile(sourceFile.getName(), sourceString); Es6ErrorReporter es6ErrorReporter = new Es6ErrorReporter(errorReporter, config.isIdeMode); com.google.javascript.jscomp.parsing.parser.Parser.Config es6config = new com.google.javascript.jscomp.parsing.parser.Parser.Config(mode( config.languageMode)); Parser p = new Parser(es6config, es6ErrorReporter, file); ProgramTree tree = p.parseProgram(); Node root = null; List<Comment> comments = ImmutableList.of(); FeatureSet features = p.getFeatures(); if (tree != null && (!es6ErrorReporter.hadError() || config.isIdeMode)) { IRFactory factory = IRFactory.transformTree(tree, sourceFile, sourceString, config, errorReporter); root = factory.getResultNode(); features = features.require(factory.getFeatures()); root.setIsSyntheticBlock(true); root.putProp(Node.FEATURE_SET, features); if (config.isIdeMode) { comments = p.getComments(); } } return new ParseResult(root, comments, features); }
private ParserRunner.ParseResult parse(String source, StaticSourceFile sourceFile) { ErrorReporter errorReporter = new ErrorReporter(){ @Override public void warning(String message, String sourceName, int line, int lineOffset) { logger.log(Level.WARNING, "{0}, sourceName: {1}, line: {2} lineOffset: {3}", new Object[]{message, sourceName, line, lineOffset}); } @Override public void error(String message, String sourceName, int line, int lineOffset) { logger.log(Level.SEVERE, "{0}, sourceName: {1}, line: {2} lineOffset: {3}", new Object[]{message, sourceName, line, lineOffset}); } }; ParserRunner.ParseResult parseResult = ParserRunner.parse( sourceFile, source, config, errorReporter); return parseResult; }
protected Config createConfig(Config.LanguageMode mode) { return ParserRunner.createConfig( isIdeMode(), options.isParseJsDocDocumentation(), options.isPreserveJsDocWhitespace(), mode, options.extraAnnotationNames); }
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(); }
private static synchronized void initResourceConfig() { if (annotationNames != null) { return; } ResourceBundle config = ResourceBundle.getBundle(CONFIG_RESOURCE); annotationNames = extractList(config.getString("jsdoc.annotations")); suppressionNames = extractList(config.getString("jsdoc.suppressions")); reservedVars = extractList(config.getString("compiler.reserved.vars")); }
ParseResult result = ParserRunner.parse( sourceFile, typeTransformationString, config, errorReporter); Node ast = result.ast;
public SourceProcessor(ConfigurationCommon config, String uri, String source) { this.uri = uri; this.source = source; this.instrumenter = new ParseTreeInstrumenter(uri, config.isIncludeFunction(), commentsHandler); this.branchInstrumentor = new BranchInstrumentor(uri, config.isDetectCoalesce(), commentsHandler); this.config = ParserRunner.createConfig(config.getECMAVersion(), INCLUDE_DESCRIPTIONS_WITH_WHITESPACE, KEEP_GOING, null, false, Config.StrictMode.SLOPPY); this.options.setPreferSingleQuotes(true); this.options.setPrettyPrint(true); this.includeBranchCoverage = config.isIncludeBranch(); this.includeFunctionCoverage = config.isIncludeFunction(); this.localStorage = config.isLocalStorage(); this.isolateBrowser = config.isolateBrowser(); }
ParserRunner.ParseResult result = ParserRunner.parse( sourceFile, sourceFile.getCode(),
public SourceProcessor(ConfigurationCommon config, String uri, String source) { this.uri = uri; this.source = source; this.instrumenter = new ParseTreeInstrumenter(uri, config.isIncludeFunction(), commentsHandler); this.branchInstrumentor = new BranchInstrumentor(uri, config.isDetectCoalesce(), commentsHandler); this.config = ParserRunner.createConfig(config.getECMAVersion(), INCLUDE_DESCRIPTIONS_WITH_WHITESPACE, KEEP_GOING, null, false, Config.StrictMode.SLOPPY); this.options.setPreferSingleQuotes(true); this.options.setPrettyPrint(true); this.includeBranchCoverage = config.isIncludeBranch(); this.includeFunctionCoverage = config.isIncludeFunction(); this.localStorage = config.isLocalStorage(); this.isolateBrowser = config.isolateBrowser(); }