Helper function for both HotSwapCompilerPass#hotSwapScript and CompilerPass#process.

@param root Root of AST to rewrite
18676
private void process(Node root, boolean hotSwap) {
    checkState(contextStack.isEmpty());
    contextStack.push(LexicalContext.newGlobalContext(root));
    if (hotSwap) {
      TranspilationPasses.hotSwapTranspile(compiler, root, transpiledFeatures, this);
    } else {
      TranspilationPasses.processTranspile(compiler, root, transpiledFeatures, this);
    }
    TranspilationPasses.maybeMarkFeaturesAsTranspiledAway(compiler, transpiledFeatures);
    checkState(contextStack.element().function == null);
    contextStack.remove();
    checkState(contextStack.isEmpty());
  }
1061266
@SuppressWarnings("unchecked")
    <T extends JCExpression, Z extends ArgumentType<T>> void processArg(T that, Function<T, Z> argumentTypeFactory) {
        UniquePos pos = new UniquePos(that);
        processArg(that, () -> {
            T speculativeTree = (T)deferredAttr.attribSpeculative(that, env, attr.new MethodAttrInfo() {
                @Override
                protected boolean needsArgumentAttr(JCTree tree) {
                    return !new UniquePos(tree).equals(pos);
                }
            });
            return argumentTypeFactory.apply(speculativeTree);
        });
    }
1057609
public void processAnnotations(List<JCCompilationUnit> roots,
                                   Collection<String> classnames) {
        if (shouldStop(CompileState.PROCESS)) {
            // Errors were encountered.
            // Unless all the errors are resolve errors, the errors were parse errors
            // or other errors during enter which cannot be fixed by running
            // any annotation processors.
            if (unrecoverableError()) {
                deferredDiagnosticHandler.reportDeferredDiagnostics();
                log.popDiagnosticHandler(deferredDiagnosticHandler);
                return ;
            }
        }

        // ASSERT: processAnnotations and procEnvImpl should have been set up by
        // by initProcessAnnotations

        // NOTE: The !classnames.isEmpty() checks should be refactored to Main.

        if (!processAnnotations) {
            // If there are no annotation processors present, and
            // annotation processing is to occur with compilation,
            // emit a warning.
            if (options.isSet(PROC, "only")) {
                log.warning("proc.proc-only.requested.no.procs");
                todo.clear();
            }
            // If not processing annotations, classnames must be empty
            if (!classnames.isEmpty()) {
                log.error("proc.no.explicit.annotation.processing.requested",
                          classnames);
            }
            Assert.checkNull(deferredDiagnosticHandler);
            return ; // continue regular compilation
        }

        Assert.checkNonNull(deferredDiagnosticHandler);

        try {
            List<ClassSymbol> classSymbols = List.nil();
            List<PackageSymbol> pckSymbols = List.nil();
            if (!classnames.isEmpty()) {
                 // Check for explicit request for annotation
                 // processing
                if (!explicitAnnotationProcessingRequested()) {
                    log.error("proc.no.explicit.annotation.processing.requested",
                              classnames);
                    deferredDiagnosticHandler.reportDeferredDiagnostics();
                    log.popDiagnosticHandler(deferredDiagnosticHandler);
                    return ; // TODO: Will this halt compilation?
                } else {
                    boolean errors = false;
                    for (String nameStr : classnames) {
                        Symbol sym = resolveBinaryNameOrIdent(nameStr);
                        if (sym == null ||
                            (sym.kind == PCK && !processPcks) ||
                            sym.kind == ABSENT_TYP) {
                            if (sym != silentFail)
                                log.error(Errors.ProcCantFindClass(nameStr));
                            errors = true;
                            continue;
                        }
                        try {
                            if (sym.kind == PCK)
                                sym.complete();
                            if (sym.exists()) {
                                if (sym.kind == PCK)
                                    pckSymbols = pckSymbols.prepend((PackageSymbol)sym);
                                else
                                    classSymbols = classSymbols.prepend((ClassSymbol)sym);
                                continue;
                            }
                            Assert.check(sym.kind == PCK);
                            log.warning(Warnings.ProcPackageDoesNotExist(nameStr));
                            pckSymbols = pckSymbols.prepend((PackageSymbol)sym);
                        } catch (CompletionFailure e) {
                            log.error(Errors.ProcCantFindClass(nameStr));
                            errors = true;
                            continue;
                        }
                    }
                    if (errors) {
                        deferredDiagnosticHandler.reportDeferredDiagnostics();
                        log.popDiagnosticHandler(deferredDiagnosticHandler);
                        return ;
                    }
                }
            }
            try {
                annotationProcessingOccurred =
                        procEnvImpl.doProcessing(roots,
                                                 classSymbols,
                                                 pckSymbols,
                                                 deferredDiagnosticHandler);
                // doProcessing will have handled deferred diagnostics
            } finally {
                procEnvImpl.close();
            }
        } catch (CompletionFailure ex) {
            log.error("cant.access", ex.sym, ex.getDetailValue());
            if (deferredDiagnosticHandler != null) {
                deferredDiagnosticHandler.reportDeferredDiagnostics();
                log.popDiagnosticHandler(deferredDiagnosticHandler);
            }
        }
    }
551192
private void runHotSwap(
      Node originalRoot, Node js, PassConfig passConfig) {
    for (PassFactory passFactory : passConfig.getChecks()) {
      runHotSwapPass(originalRoot, js, passFactory);
    }
  }
940077
public String render(Node root, boolean processExtendRoots) {
    OutputList output = new OutputList(config.getMaxOutputSize());

    for (Node node : root.getChildren()) {
      lineNumber = node.getLineNumber();
      position = node.getStartPosition();
      String renderStr = node.getMaster().getImage();
      if (context.doesRenderStackContain(renderStr)) {
        // This is a circular rendering. Stop rendering it here.
        addError(new TemplateError(ErrorType.WARNING, ErrorReason.EXCEPTION, ErrorItem.TAG,
            "Rendering cycle detected: '" + renderStr + "'", null, getLineNumber(), node.getStartPosition(),
            null, BasicTemplateErrorCategory.IMPORT_CYCLE_DETECTED, ImmutableMap.of("string", renderStr)));
        output.addNode(new RenderedOutputNode(renderStr));
      } else {
        OutputNode out;
        context.pushRenderStack(renderStr);
        try {
          out = node.render(this);
        } catch (DeferredValueException e) {
          out = new RenderedOutputNode(node.getMaster().getImage());
        }
        context.popRenderStack();
        output.addNode(out);
      }
    }

    // render all extend parents, keeping the last as the root output
    if (processExtendRoots) {
      while (!extendParentRoots.isEmpty()) {
        context.getCurrentPathStack().push(context.getExtendPathStack().peek().orElse(""), lineNumber, position);
        Node parentRoot = extendParentRoots.removeFirst();
        output = new OutputList(config.getMaxOutputSize());

        for (Node node : parentRoot.getChildren()) {
          OutputNode out = node.render(this);
          output.addNode(out);
        }

        context.getExtendPathStack().pop();
        context.getCurrentPathStack().pop();
      }
    }

    resolveBlockStubs(output);

    return output.getValue();
  }
801473
function postprocess(ast, options) {
  visitNode(ast, node => {
    switch (node.type) {
      case "VariableDeclaration": {
        const lastDeclaration = getLast(node.declarations);
        if (lastDeclaration && lastDeclaration.init) {
          overrideLocEnd(node, lastDeclaration);
        }
        break;
      }
    }
  });

  return ast;

  /**
   * - `toOverrideNode` must be the last thing in `toBeOverriddenNode`
   * - do nothing if there's a semicolon on `toOverrideNode.end` (no need to fix)
   */
  function overrideLocEnd(toBeOverriddenNode, toOverrideNode) {
    if (options.originalText[locEnd(toOverrideNode)] === ";") {
      return;
    }
    if (options.parser === "flow") {
      toBeOverriddenNode.range = [
        toBeOverriddenNode.range[0],
        toOverrideNode.range[1]
      ];
    } else {
      toBeOverriddenNode.end = toOverrideNode.end;
    }
    toBeOverriddenNode.loc = Object.assign({}, toBeOverriddenNode.loc, {
      end: toBeOverriddenNode.loc.end
    });
  }

  function locEnd(node) {
    return options.parser === "flow" ? node.range[1] : node.end;
  }
}
25049
public void process(OutputStream outputStream, Object element) throws IOException {
        this.root.processElement(outputStream, element);
    }
172432
@Override
  public void process(Node externs, Node root) {
    ReferenceCollectingCallback callback =
      new ReferenceCollectingCallback(compiler,
          ReferenceCollectingCallback.DO_NOTHING_BEHAVIOR, new Es6SyntacticScopeCreator(compiler));

    callback.process(root);

    for (Var variable : callback.getAllSymbols()) {
      ReferenceCollection referenceCollection =
          callback.getReferences(variable);

      VariableVisibility visibility;

      if (variableIsParameter(variable)) {
        visibility = VariableVisibility.PARAMETER;
      } else if (variable.isLocal()) {
        if (referenceCollection.isEscaped()) {
          visibility = VariableVisibility.CAPTURED_LOCAL;
        } else {
          visibility = VariableVisibility.LOCAL;
        }
      } else if (variable.isGlobal()) {
        visibility = VariableVisibility.GLOBAL;
      } else {
        throw new IllegalStateException("Un-handled variable visibility for " + variable);
      }

      visibilityByDeclaringNameNode.put(variable.getNameNode(), visibility);
    }
  }
1159772
@Override
  public void process(Node externs, Node root) {
    checkState(compiler.getLifeCycleStage().isNormalized());
    if (!allowRemovalOfExternProperties) {
      referencedPropertyNames.addAll(compiler.getExternProperties());
    }
    traverseAndRemoveUnusedReferences(root);
    // This pass may remove definitions of getter or setter properties.
    GatherGettersAndSetterProperties.update(compiler, externs, root);
  }
609929
@Override public void process(MPPReader reader, ProjectFile file, DirectoryEntry root) throws MPXJException, IOException
   {
      try
      {
         populateMemberData(reader, file, root);
         processProjectProperties();

         if (!reader.getReadPropertiesOnly())
         {
            processSubProjectData();
            processGraphicalIndicators();
            processCustomValueLists();
            processCalendarData();
            processResourceData();
            processTaskData();
            processConstraintData();
            processAssignmentData();
            postProcessTasks();

            if (reader.getReadPresentationData())
            {
               processViewPropertyData();
               processTableData();
               processViewData();
               processFilterData();
               processGroupData();
               processSavedViewState();
            }
         }
      }

      finally
      {
         clearMemberData();
      }
   }
413087
public void replaceScript(JsAst ast) {
    CompilerInput input = this.getInput(ast.getInputId());
    if (!replaceIncrementalSourceAst(ast)) {
      return;
    }
    Node originalRoot = checkNotNull(input.getAstRoot(this));

    processNewScript(ast, originalRoot);
  }
917175
private boolean isApplicationError(Throwable rootEx, String pkgRoot) {
        
        if (rootEx != null) {
            StackTraceElement[] stackTrace = rootEx.getStackTrace();
            if (stackTrace != null && stackTrace.length > 0) {
                StackTraceElement rootThrower = stackTrace[0];
                String className = rootThrower.getClassName();
                if (className != null && !!!className.startsWith(pkgRoot)) {
                    return true;
                }
            }
        }
        
        return false;
    }
926026
def _process_extends(self, node, **kwargs):
        

        # find all the blocks in this template
        for b in self.ast.find_all(nodes.Block):

            # if not already in `child_blocks` then this is the first time a
            # block with this name has been encountered.
            if b.name not in self.child_blocks:
                self.child_blocks[b.name] = b
            else:

                # otherwise we have seen this block before, so we need to find the last
                # super_block and add the block from this template to the end.
                block = self.child_blocks.get(b.name)
                while hasattr(block, 'super_block'):
                    block = block.super_block
                block.super_block = b

        # load the parent template
        parent_template = JinjaToJS(template_root=self.template_root,
                                    template_name=node.template.value,
                                    js_module_format=self.js_module_format,
                                    runtime_path=self.runtime_path,
                                    include_prefix=self.include_prefix,
                                    include_ext=self.include_ext,
                                    child_blocks=self.child_blocks,
                                    dependencies=self.dependencies)

        # add the parent templates output to the current output
        self.output.write(parent_template.output.getvalue())

        # Raise an exception so we stop parsing this template
        raise ExtendsException
833990
private AbstractPlanNode handleWindowedOperators(AbstractPlanNode root) {
        // Get the windowed expression.  We need to set its output
        // schema from the display list.
        WindowFunctionExpression winExpr = m_parsedSelect.getWindowFunctionExpressions().get(0);
        assert(winExpr != null);

        // This will set the output schema to contain the
        // windowed schema column only.  In generateOutputSchema
        // we will add the input columns.
        WindowFunctionPlanNode pnode = new WindowFunctionPlanNode();
        pnode.setWindowFunctionExpression(winExpr);
        // We always need an order by plan node, even if the sort
        // is optimized away by an index.  This may be turned
        // into an inline order by in a MergeReceivePlanNode.
        IndexUseForOrderBy scanNode = findScanNodeForWindowFunction(root);
        AbstractPlanNode cnode = null;
        int winfunc = (scanNode == null) ? SubPlanAssembler.NO_INDEX_USE : scanNode.getWindowFunctionUsesIndex();
        // If we have an index which is compatible with the statement
        // level order by, and we have a window function which can't
        // use the index we have to ignore the statement level order by
        // index use.  We will need to order the input according to the
        // window function first, and that will in general invalidate the
        // statement level order by ordering.
        if ((SubPlanAssembler.STATEMENT_LEVEL_ORDER_BY_INDEX == winfunc)
                || (SubPlanAssembler.NO_INDEX_USE == winfunc)) {
            // No index.  Calculate the expression order here and stuff it into
            // the order by node.  Note that if we support more than one window
            // function this would be the case when scanNode.getWindowFunctionUsesIndex()
            // returns a window function number which is different from the number
            // of winExpr.
            List<AbstractExpression> partitionByExpressions = winExpr.getPartitionByExpressions();
            // If the order by expression list contains a partition by expression then
            // we won't have to sort by it twice.  We sort by the partition by expressions
            // first, and we don't care what order we sort by them.  So, find the
            // sort direction in the order by list and use that in the partition by
            // list, and then mark that it was deleted in the order by
            // list.
            //
            // We choose to make this dontsort rather than dosort because the
            // Java default value for boolean is false, and we want to sort by
            // default.
            boolean dontsort[] = new boolean[winExpr.getOrderbySize()];
            List<AbstractExpression> orderByExpressions = winExpr.getOrderByExpressions();
            List<SortDirectionType>  orderByDirections  = winExpr.getOrderByDirections();
            OrderByPlanNode onode = new OrderByPlanNode();
            for (int idx = 0; idx < winExpr.getPartitionbySize(); ++idx) {
                SortDirectionType pdir = SortDirectionType.ASC;
                AbstractExpression partitionByExpression = partitionByExpressions.get(idx);
                int sidx = winExpr.getSortIndexOfOrderByExpression(partitionByExpression);
                if (0 <= sidx) {
                    pdir = orderByDirections.get(sidx);
                    dontsort[sidx] = true;
                }
                onode.addSortExpression(partitionByExpression, pdir);
            }
            for (int idx = 0; idx < winExpr.getOrderbySize(); ++idx) {
                if (!dontsort[idx]) {
                    AbstractExpression orderByExpr = orderByExpressions.get(idx);
                    SortDirectionType  orderByDir  = orderByDirections.get(idx);
                    onode.addSortExpression(orderByExpr, orderByDir);
                }
            }
            onode.addAndLinkChild(root);
            cnode = onode;
        } else {
            assert(scanNode != null);
            // This means the index is good for this window function.
            // If this is an MP statement we still need to generate the
            // order by node, because we may need to turn it into an
            // inline order by node of a MergeReceive node.
            assert( 0 == scanNode.getWindowFunctionUsesIndex() );
            if (m_partitioning.requiresTwoFragments()) {
                OrderByPlanNode onode = new OrderByPlanNode();
                SortDirectionType dir = scanNode.getSortOrderFromIndexScan();
                assert(dir != SortDirectionType.INVALID);
                // This was created when the index was determined.
                // We cached it in the scan node.
                List<AbstractExpression> orderExprs = scanNode.getFinalExpressionOrderFromIndexScan();
                assert(orderExprs != null);
                for (AbstractExpression ae : orderExprs) {
                    onode.addSortExpression(ae, dir);
                }
                // Link in the OrderByNode.
                onode.addAndLinkChild(root);
                cnode = onode;
            } else {
                // Don't create and link in the order by node.
                cnode = root;
            }
        }
        pnode.addAndLinkChild(cnode);
        return pnode;
    }
1209424
@Override
  public void process(Node externs, Node root) {
    checkState(topLevelStatements.isEmpty(), "process() called more than once");
    NodeTraversal t = new NodeTraversal(compiler, this, scopeCreator);
    t.traverseRoots(externs, root);
  }
827244
@Override
	protected StringBuffer doPostProcessBundle(BundleProcessingStatus status, StringBuffer bundleData)
			throws IOException {

		if (jsEngine == null) {
			initialize(status.getJawrConfig());
		}

		StopWatch stopWatch = new StopWatch();
		stopWatch.start("Processing Autoprefixer on '" + status.getLastPathAdded() + "'");

		String cssSource = bundleData.toString();
		String res = null;
		try {
			res = (String) jsEngine.invokeFunction("process", cssSource, options);

		} catch (NoSuchMethodException | ScriptException e) {
			throw new BundlingProcessException(e);
		}

		stopWatch.stop();
		if (PERF_LOGGER.isDebugEnabled()) {
			PERF_LOGGER.debug(stopWatch.shortSummary());
		}
		return new StringBuffer(res);
	}
241288
private Process executeToAstProcess(String argument) throws IOException {
        try {
            Process p = new ProcessBuilder("python", codeGenBinDirectory + "/jp-to-ast.py", argument).start();
            p.waitFor();
            return p;
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
            throw new RuntimeException(e);
        }
    }