Skip to content

Commit

Permalink
Rename NodeTraversal#getCurrentFile to getCurrentScript
Browse files Browse the repository at this point in the history
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=229965849
  • Loading branch information
lauraharker committed Jan 22, 2019
1 parent bd867f9 commit 6d6b204
Show file tree
Hide file tree
Showing 14 changed files with 30 additions and 24 deletions.
6 changes: 3 additions & 3 deletions src/com/google/javascript/jscomp/Es6ConvertSuper.java
Expand Up @@ -100,8 +100,8 @@ private void addSyntheticConstructor(NodeTraversal t, Node classNode) {
IR.superNode().setJSType(superClass.getJSType()),
IR.spread(astFactory.createArgumentsReference())));
body.addChildToFront(exprResult);
NodeUtil.addFeatureToScript(t.getCurrentFile(), Feature.SUPER);
NodeUtil.addFeatureToScript(t.getCurrentFile(), Feature.SPREAD_EXPRESSIONS);
NodeUtil.addFeatureToScript(t.getCurrentScript(), Feature.SUPER);
NodeUtil.addFeatureToScript(t.getCurrentScript(), Feature.SPREAD_EXPRESSIONS);
}
Node constructor =
astFactory.createFunction(
Expand All @@ -121,7 +121,7 @@ private void addSyntheticConstructor(NodeTraversal t, Node classNode) {
memberDef.useSourceInfoIfMissingFromForTree(classNode);
memberDef.makeNonIndexableRecursive();
classMembers.addChildToFront(memberDef);
NodeUtil.addFeatureToScript(t.getCurrentFile(), Feature.MEMBER_DECLARATIONS);
NodeUtil.addFeatureToScript(t.getCurrentScript(), Feature.MEMBER_DECLARATIONS);
// report newly created constructor
compiler.reportChangeToChangeScope(memberDef.getOnlyChild());
// report change to scope containing the class
Expand Down
2 changes: 1 addition & 1 deletion src/com/google/javascript/jscomp/Es6ExtractClasses.java
Expand Up @@ -196,7 +196,7 @@ private void extractClass(NodeTraversal t, Node classNode, Node parent) {
parent.replaceChild(classNode, classNameRhs);
Node classDeclaration =
IR.constNode(classNameLhs, classNode).useSourceInfoIfMissingFromForTree(classNode);
NodeUtil.addFeatureToScript(t.getCurrentFile(), Feature.CONST_DECLARATIONS);
NodeUtil.addFeatureToScript(t.getCurrentScript(), Feature.CONST_DECLARATIONS);
classDeclaration.setJSDocInfo(JSDocInfoBuilder.maybeCopyFrom(info).build());
statement.getParent().addChildBefore(classDeclaration, statement);

Expand Down
4 changes: 2 additions & 2 deletions src/com/google/javascript/jscomp/Es6RewriteArrowFunction.java
Expand Up @@ -131,7 +131,7 @@ private void addVarDeclarations(NodeTraversal t, ThisAndArgumentsContext context
if (context.needsThisVar) {
Node name = IR.name(THIS_VAR).setJSType(context.getThisType());
Node thisVar = IR.constNode(name, IR.thisNode().setJSType(context.getThisType()));
NodeUtil.addFeatureToScript(t.getCurrentFile(), Feature.CONST_DECLARATIONS);
NodeUtil.addFeatureToScript(t.getCurrentScript(), Feature.CONST_DECLARATIONS);
thisVar.useSourceInfoIfMissingFromForTree(scopeBody);
makeTreeNonIndexable(thisVar);

Expand All @@ -150,7 +150,7 @@ private void addVarDeclarations(NodeTraversal t, ThisAndArgumentsContext context
Node name = IR.name(ARGUMENTS_VAR).setJSType(context.getArgumentsType());
Node argumentsVar =
IR.constNode(name, IR.name("arguments").setJSType(context.getArgumentsType()));
NodeUtil.addFeatureToScript(t.getCurrentFile(), Feature.CONST_DECLARATIONS);
NodeUtil.addFeatureToScript(t.getCurrentScript(), Feature.CONST_DECLARATIONS);
scopeBody.addChildToFront(argumentsVar);

JSDocInfoBuilder jsdoc = new JSDocInfoBuilder(false);
Expand Down
Expand Up @@ -94,7 +94,7 @@ private void visitBlockScopedFunctionDeclaration(NodeTraversal t, Node n, Node p
Node oldNameNode = n.getFirstChild();
Node fnNameNode = oldNameNode.cloneNode();
Node let = IR.declaration(fnNameNode, Token.LET).srcref(n);
NodeUtil.addFeatureToScript(t.getCurrentFile(), Feature.LET_DECLARATIONS);
NodeUtil.addFeatureToScript(t.getCurrentScript(), Feature.LET_DECLARATIONS);

// Prepare the function.
oldNameNode.setString("");
Expand Down
2 changes: 1 addition & 1 deletion src/com/google/javascript/jscomp/Es6RewriteClass.java
Expand Up @@ -271,7 +271,7 @@ private void visitClass(final NodeTraversal t, final Node classNode, final Node
Node ctorVar = IR.let(metadata.getClassNameNode().cloneNode(), constructor);
ctorVar.useSourceInfoIfMissingFromForTree(classNode);
parent.replaceChild(classNode, ctorVar);
NodeUtil.addFeatureToScript(t.getCurrentFile(), Feature.LET_DECLARATIONS);
NodeUtil.addFeatureToScript(t.getCurrentScript(), Feature.LET_DECLARATIONS);
} else {
parent.replaceChild(classNode, constructor);
}
Expand Down
6 changes: 3 additions & 3 deletions src/com/google/javascript/jscomp/Es6RewriteDestructuring.java
Expand Up @@ -684,7 +684,7 @@ private void wrapAssignmentInCallToArrow(NodeTraversal t, Node assignment) {
Node rhs = assignment.getLastChild().detach();
// let temp0 = rhs;
Node newAssignment = IR.let(tempVarModel.cloneNode(), rhs);
NodeUtil.addFeatureToScript(t.getCurrentFile(), Feature.LET_DECLARATIONS);
NodeUtil.addFeatureToScript(t.getCurrentScript(), Feature.LET_DECLARATIONS);
// [x, y] = temp0;
Node replacementExpr =
astFactory.createAssign(assignment.getFirstChild().detach(), tempVarModel.cloneNode());
Expand All @@ -699,7 +699,7 @@ private void wrapAssignmentInCallToArrow(NodeTraversal t, Node assignment) {

// Create a call to the function, and replace the pattern with the call.
Node call = astFactory.createCall(arrowFn);
NodeUtil.addFeatureToScript(t.getCurrentFile(), Feature.ARROW_FUNCTIONS);
NodeUtil.addFeatureToScript(t.getCurrentScript(), Feature.ARROW_FUNCTIONS);
call.useSourceInfoIfMissingFromForTree(assignment);
call.putBooleanProp(Node.FREE_CALL, true);
assignment.getParent().replaceChild(assignment, call);
Expand Down Expand Up @@ -763,7 +763,7 @@ private void visitDestructuringPatternInCatch(NodeTraversal t, Node pattern) {
catchBlock.addChildToFront(
IR.declaration(
pattern, astFactory.createName(tempVarName, pattern.getJSType()), Token.LET));
NodeUtil.addFeatureToScript(t.getCurrentFile(), Feature.LET_DECLARATIONS);
NodeUtil.addFeatureToScript(t.getCurrentScript(), Feature.LET_DECLARATIONS);
}

/** Helper for transpiling DEFAULT_VALUE trees. */
Expand Down
2 changes: 1 addition & 1 deletion src/com/google/javascript/jscomp/Es6RewriteModules.java
Expand Up @@ -702,7 +702,7 @@ private Node createExportsObject(NodeTraversal t, Node script) {
script.addChildToBack(exprResult);
} else if (mutated || importMap.containsKey(withSuffix)) {
addGetterExport(script, nodeForSourceInfo, objLit, exportedName, withSuffix);
NodeUtil.addFeatureToScript(t.getCurrentFile(), Feature.GETTER);
NodeUtil.addFeatureToScript(t.getCurrentScript(), Feature.GETTER);
} else {
// This step is done before type checking and the type checker doesn't understand getters.
// However it does understand aliases. So if an export isn't mutated use an alias to make it
Expand Down
Expand Up @@ -431,7 +431,7 @@ private void visitExportDefault(NodeTraversal t, Node export, Node parent) {
// overwritten but they also act like a const for temporal dead-zone purposes.
Node var = IR.constNode(IR.name(name), export.removeFirstChild());
parent.replaceChild(export, var.useSourceInfoIfMissingFromForTree(export));
NodeUtil.addFeatureToScript(t.getCurrentFile(), Feature.CONST_DECLARATIONS);
NodeUtil.addFeatureToScript(t.getCurrentScript(), Feature.CONST_DECLARATIONS);
}

exportedNameToLocalQName.put("default", new LocalQName(name, export));
Expand Down
Expand Up @@ -162,7 +162,7 @@ private void visitRestParam(NodeTraversal t, Node restParam, Node paramList) {
Node name = IR.name(paramName);
Node let = IR.let(name, newArrayName).useSourceInfoIfMissingFromForTree(functionBody);
newBlock.addChildToFront(let);
NodeUtil.addFeatureToScript(t.getCurrentFile(), Feature.LET_DECLARATIONS);
NodeUtil.addFeatureToScript(t.getCurrentScript(), Feature.LET_DECLARATIONS);

for (Node child : functionBody.children()) {
newBlock.addChildToBack(child.detach());
Expand Down
Expand Up @@ -325,7 +325,7 @@ private void visitInterface(NodeTraversal t, Node n, Node parent) {
Node empty = new Node(Token.EMPTY).useSourceInfoIfMissingFrom(n);
n.replaceChild(superTypes, empty);
members.setToken(Token.CLASS_MEMBERS);
NodeUtil.addFeatureToScript(t.getCurrentFile(), Feature.CLASSES);
NodeUtil.addFeatureToScript(t.getCurrentScript(), Feature.CLASSES);

maybeCreateQualifiedDeclaration(t, n, parent);
t.reportCodeChange();
Expand Down
8 changes: 7 additions & 1 deletion src/com/google/javascript/jscomp/NodeTraversal.java
Expand Up @@ -1325,7 +1325,13 @@ private static String getSourceName(Node n) {
return nullToEmpty(name);
}

public Node getCurrentFile() {
/**
* Returns the SCRIPT node enclosing the current scope, or `null` if unknown
*
* <p>e.g. returns null if {@link #traverseInnerNode(Node, Node, AbstractScope)} was used
*/
@Nullable
Node getCurrentScript() {
return curScript;
}

Expand Down
8 changes: 4 additions & 4 deletions src/com/google/javascript/jscomp/RewriteAsyncFunctions.java
Expand Up @@ -448,12 +448,12 @@ private void convertAsyncFunction(NodeTraversal t, LexicalContext functionContex
// const this$ = this;
newBody.addChildToBack(
astFactory.createThisAliasDeclarationForFunction(ASYNC_THIS, functionContext.function));
NodeUtil.addFeatureToScript(t.getCurrentFile(), Feature.CONST_DECLARATIONS);
NodeUtil.addFeatureToScript(t.getCurrentScript(), Feature.CONST_DECLARATIONS);
}
if (functionContext.mustAddAsyncArgumentsVariable) {
// const arguments$ = arguments;
newBody.addChildToBack(astFactory.createArgumentsAliasDeclaration(ASYNC_ARGUMENTS));
NodeUtil.addFeatureToScript(t.getCurrentFile(), Feature.CONST_DECLARATIONS);
NodeUtil.addFeatureToScript(t.getCurrentScript(), Feature.CONST_DECLARATIONS);
}
for (SuperPropertyWrapperInfo superPropertyWrapperInfo :
functionContext.superPropertyWrappers.asCollection()) {
Expand All @@ -469,7 +469,7 @@ private void convertAsyncFunction(NodeTraversal t, LexicalContext functionContex
compiler.reportChangeToChangeScope(arrowFunction);
// Record that we've added arrow functions and const declarations to this script,
// so later transpilations of those features will run, if needed.
Node enclosingScript = t.getCurrentFile();
Node enclosingScript = t.getCurrentScript();
NodeUtil.addFeatureToScript(enclosingScript, Feature.ARROW_FUNCTIONS);
NodeUtil.addFeatureToScript(enclosingScript, Feature.CONST_DECLARATIONS);
}
Expand All @@ -486,7 +486,7 @@ private void convertAsyncFunction(NodeTraversal t, LexicalContext functionContex
Node generatorFunction =
astFactory.createZeroArgGeneratorFunction("", originalBody, originalFunction.getJSType());
compiler.reportChangeToChangeScope(generatorFunction);
NodeUtil.addFeatureToScript(t.getCurrentFile(), Feature.GENERATORS);
NodeUtil.addFeatureToScript(t.getCurrentScript(), Feature.GENERATORS);

// return $jscomp.asyncExecutePromiseGeneratorFunction(function* () { ... });
newBody.addChildToBack(
Expand Down
6 changes: 3 additions & 3 deletions src/com/google/javascript/jscomp/RewriteAsyncIteration.java
Expand Up @@ -253,7 +253,7 @@ public void visit(NodeTraversal t, Node n, Node parent) {
checkNotNull(ctx.function);
checkState(ctx.function.isAsyncFunction());
replaceForAwaitOf(ctx, n);
NodeUtil.addFeatureToScript(t.getCurrentFile(), Feature.CONST_DECLARATIONS);
NodeUtil.addFeatureToScript(t.getCurrentScript(), Feature.CONST_DECLARATIONS);
break;

// Maintaining references to this/arguments/super
Expand Down Expand Up @@ -626,7 +626,7 @@ private void prependTempVarDeclarations(LexicalContext ctx, NodeTraversal t) {
IR.paramList(),
IR.getprop(superReference, IR.string(replacedMethodName)));
compiler.reportChangeToChangeScope(arrowFunction);
NodeUtil.addFeatureToScript(t.getCurrentFile(), Feature.ARROW_FUNCTIONS);
NodeUtil.addFeatureToScript(t.getCurrentScript(), Feature.ARROW_FUNCTIONS);
String superReplacementName = superPropGetterPrefix + replacedMethodName;
prefixBlock.addChildToBack(IR.constNode(IR.name(superReplacementName), arrowFunction));
}
Expand All @@ -642,7 +642,7 @@ private void prependTempVarDeclarations(LexicalContext ctx, NodeTraversal t) {
|| thisSuperArgsCtx.usedArguments
|| !thisSuperArgsCtx.usedSuperProperties.isEmpty()) {
compiler.reportChangeToChangeScope(function);
NodeUtil.addFeatureToScript(t.getCurrentFile(), Feature.CONST_DECLARATIONS);
NodeUtil.addFeatureToScript(t.getCurrentScript(), Feature.CONST_DECLARATIONS);
}
}
}
2 changes: 1 addition & 1 deletion src/com/google/javascript/jscomp/RuntimeTypeCheck.java
Expand Up @@ -184,7 +184,7 @@ private Node addMarkerToClass(String markerName, @Nullable String unused, Node c

compiler.reportChangeToEnclosingScope(member);
compiler.reportChangeToChangeScope(function);
NodeUtil.addFeatureToScript(traversal.getCurrentFile(), Feature.COMPUTED_PROPERTIES);
NodeUtil.addFeatureToScript(traversal.getCurrentScript(), Feature.COMPUTED_PROPERTIES);
return classMembers;
}

Expand Down

0 comments on commit 6d6b204

Please sign in to comment.