Skip to content

Commit

Permalink
Move the .i.js generation compiler pass to its own package
Browse files Browse the repository at this point in the history
This requires making public a few NodeUtil utilities that were previously
package-private, but I think it's worth the tradeoff.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=179217544
  • Loading branch information
blickly authored and Tyler Breisacher committed Dec 18, 2017
1 parent 00287ef commit 6620976
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 17 deletions.
1 change: 1 addition & 0 deletions src/com/google/javascript/jscomp/DefaultPassConfig.java
Expand Up @@ -40,6 +40,7 @@
import com.google.javascript.jscomp.ExtractPrototypeMemberDeclarations.Pattern;
import com.google.javascript.jscomp.NodeTraversal.Callback;
import com.google.javascript.jscomp.PassFactory.HotSwapPassFactory;
import com.google.javascript.jscomp.ijs.ConvertToTypedInterface;
import com.google.javascript.jscomp.lint.CheckArrayWithGoogObject;
import com.google.javascript.jscomp.lint.CheckDuplicateCase;
import com.google.javascript.jscomp.lint.CheckEmptyStatements;
Expand Down
22 changes: 11 additions & 11 deletions src/com/google/javascript/jscomp/NodeUtil.java
Expand Up @@ -1034,7 +1034,7 @@ static boolean isEnumDecl(Node n) {
* /** @const * / var goog = goog || {};
* /** @const * / goog.math = goog.math || {};
*/
static boolean isNamespaceDecl(Node n) {
public static boolean isNamespaceDecl(Node n) {
JSDocInfo jsdoc = getBestJSDocInfo(n);
if (jsdoc != null && !jsdoc.getTypeNodes().isEmpty()) {
return false;
Expand Down Expand Up @@ -1814,7 +1814,7 @@ static boolean isSimpleFunctionDeclaration(Node fn) {
&& (isExprAssign(grandparent) || parent.isName());
}

enum ValueType {
public enum ValueType {
UNDETERMINED,
NULL,
VOID,
Expand All @@ -1828,7 +1828,7 @@ enum ValueType {
* Apply the supplied predicate against
* all possible result Nodes of the expression.
*/
static ValueType getKnownValueType(Node n) {
public static ValueType getKnownValueType(Node n) {
switch (n.getToken()) {
case CAST:
return getKnownValueType(n.getFirstChild());
Expand Down Expand Up @@ -2715,7 +2715,7 @@ public boolean apply(Node n) {
Token.NAMESPACE_ELEMENTS,
Token.INTERFACE_MEMBERS);

static boolean isStatementParent(Node parent) {
public static boolean isStatementParent(Node parent) {
// It is not possible to determine definitely if a node is a statement
// or not if it is not part of the AST. A FUNCTION node can be
// either part of an expression or a statement.
Expand Down Expand Up @@ -3910,7 +3910,7 @@ private static void useSourceInfoForNewQName(Node newQName, Node basisNode) {
/**
* Gets the root node of a qualified name. Must be either NAME, THIS or SUPER.
*/
static Node getRootOfQualifiedName(Node qName) {
public static Node getRootOfQualifiedName(Node qName) {
for (Node current = qName; true; current = current.getFirstChild()) {
if (current.isName() || current.isThis() || current.isSuper()) {
return current;
Expand Down Expand Up @@ -4129,7 +4129,7 @@ private static void getLhsNodesHelper(Node n, List<Node> lhsNodes) {
}

/** Retrieves lhs nodes declared in the current declaration or ASSIGN statement. */
static List<Node> findLhsNodesInNode(Node declNode) {
public static List<Node> findLhsNodesInNode(Node declNode) {
checkArgument(
isNameDeclaration(declNode)
|| declNode.isParamList()
Expand Down Expand Up @@ -5053,7 +5053,7 @@ private static boolean isToStringMethodCall(Node call) {

/** Return declared JSDoc type for the given name declaration, or null if none present. */
@Nullable
static JSTypeExpression getDeclaredTypeExpression(Node declaration) {
public static JSTypeExpression getDeclaredTypeExpression(Node declaration) {
checkArgument(declaration.isName() || declaration.isStringKey());
JSDocInfo nameJsdoc = getBestJSDocInfo(declaration);
if (nameJsdoc != null) {
Expand All @@ -5080,7 +5080,7 @@ public static JSDocInfo getBestJSDocInfo(Node n) {
}

@Nullable
static Node getBestJSDocInfoNode(Node n) {
public static Node getBestJSDocInfoNode(Node n) {
if (n.isExprResult()) {
return getBestJSDocInfoNode(n.getFirstChild());
}
Expand Down Expand Up @@ -5113,7 +5113,7 @@ static Node getBestJSDocInfoNode(Node n) {
}

/** Find the l-value that the given r-value is being assigned to. */
static Node getBestLValue(Node n) {
public static Node getBestLValue(Node n) {
Node parent = n.getParent();
boolean isFunctionDeclaration = isFunctionDeclaration(n);
if (isFunctionDeclaration) {
Expand All @@ -5136,7 +5136,7 @@ static Node getBestLValue(Node n) {
}

/** Gets the r-value (or initializer) of a node returned by getBestLValue. */
static Node getRValueOfLValue(Node n) {
public static Node getRValueOfLValue(Node n) {
Node parent = n.getParent();
switch (parent.getToken()) {
case ASSIGN:
Expand Down Expand Up @@ -5546,7 +5546,7 @@ static void markNewScopesChanged(Node node, AbstractCompiler compiler) {
}

/** Recurses through a tree, marking all function nodes deleted. */
static void markFunctionsDeleted(Node node, AbstractCompiler compiler) {
public static void markFunctionsDeleted(Node node, AbstractCompiler compiler) {
if (node.isFunction()) {
compiler.reportFunctionDeleted(node);
}
Expand Down
2 changes: 1 addition & 1 deletion src/com/google/javascript/jscomp/Var.java
Expand Up @@ -197,7 +197,7 @@ boolean isParam() {
return declarationType() == Token.PARAM_LIST;
}

boolean isDefaultParam() {
public boolean isDefaultParam() {
Node parent = nameNode.getParent();
return parent.getParent().isParamList() && parent.isDefaultValue()
&& parent.getFirstChild() == nameNode;
Expand Down
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.javascript.jscomp;
package com.google.javascript.jscomp.ijs;

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
Expand All @@ -25,7 +25,15 @@
import com.google.common.collect.ListMultimap;
import com.google.common.collect.MultimapBuilder;
import com.google.common.collect.Ordering;
import com.google.javascript.jscomp.AbstractCompiler;
import com.google.javascript.jscomp.CompilerPass;
import com.google.javascript.jscomp.DiagnosticType;
import com.google.javascript.jscomp.JSError;
import com.google.javascript.jscomp.NodeTraversal;
import com.google.javascript.jscomp.NodeTraversal.AbstractShallowStatementCallback;
import com.google.javascript.jscomp.NodeUtil;
import com.google.javascript.jscomp.Scope;
import com.google.javascript.jscomp.Var;
import com.google.javascript.rhino.IR;
import com.google.javascript.rhino.JSDocInfo;
import com.google.javascript.rhino.JSDocInfo.Visibility;
Expand Down Expand Up @@ -53,7 +61,7 @@
*
* @author blickly@google.com (Ben Lickly)
*/
class ConvertToTypedInterface implements CompilerPass {
public class ConvertToTypedInterface implements CompilerPass {

static final DiagnosticType CONSTANT_WITHOUT_EXPLICIT_TYPE =
DiagnosticType.warning(
Expand All @@ -71,7 +79,7 @@ class ConvertToTypedInterface implements CompilerPass {

private final AbstractCompiler compiler;

ConvertToTypedInterface(AbstractCompiler compiler) {
public ConvertToTypedInterface(AbstractCompiler compiler) {
this.compiler = compiler;
}

Expand Down Expand Up @@ -100,7 +108,8 @@ public void processFile(Node scriptNode) {
new SimplifyDeclarations(compiler, currentFile).simplifyAll();
}

private static @Nullable Var findNameDeclaration(Scope scope, Node rhs) {
@Nullable
private static Var findNameDeclaration(Scope scope, Node rhs) {
if (!rhs.isName()) {
return null;
}
Expand Down
Expand Up @@ -14,9 +14,12 @@
* limitations under the License.
*/

package com.google.javascript.jscomp;
package com.google.javascript.jscomp.ijs;

import com.google.javascript.jscomp.Compiler;
import com.google.javascript.jscomp.CompilerOptions.LanguageMode;
import com.google.javascript.jscomp.CompilerPass;
import com.google.javascript.jscomp.CompilerTestCase;

/** Unit tests for {@link ConvertToTypedInterface}. */
public final class ConvertToTypedInterfaceTest extends CompilerTestCase {
Expand Down

0 comments on commit 6620976

Please sign in to comment.