Skip to content

Commit

Permalink
Updated InlineFunctions pass to not inline functions with rest parame…
Browse files Browse the repository at this point in the history
…ters

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=158872868
  • Loading branch information
bellashim authored and Tyler Breisacher committed Jun 13, 2017
1 parent 96ff594 commit d29f4c1
Show file tree
Hide file tree
Showing 4 changed files with 234 additions and 268 deletions.
8 changes: 6 additions & 2 deletions src/com/google/javascript/jscomp/DefinitionsRemover.java
Expand Up @@ -34,6 +34,7 @@ class DefinitionsRemover {
* @return an {@link Definition} object if the node contains a definition or {@code null}
* otherwise.
*/

static Definition getDefinition(Node n, boolean isExtern) {
Node parent = n.getParent();
if (parent == null) {
Expand All @@ -52,8 +53,10 @@ static Definition getDefinition(Node n, boolean isExtern) {
return new AssignmentDefinition(parent, isExtern);
} else if (NodeUtil.isObjectLitKey(n)) {
return new ObjectLiteralPropertyDefinition(parent, n, n.getFirstChild(), isExtern);
} else if (parent.isParamList()) {
Node function = parent.getParent();
} else if (NodeUtil.getEnclosingType(n, Token.PARAM_LIST) != null
&& !n.isParamList() && !n.isRest()) {
Node paramList = NodeUtil.getEnclosingType(n, Token.PARAM_LIST);
Node function = paramList.getParent();
return new FunctionArgumentDefinition(function, n, isExtern);
} else if (parent.getToken() == Token.COLON && parent.getFirstChild() == n && isExtern) {
Node grandparent = parent.getParent();
Expand Down Expand Up @@ -174,6 +177,7 @@ abstract static class IncompleteDefinition extends Definition {
IncompleteDefinition(Node lValue, boolean inExterns) {
super(inExterns);
Preconditions.checkNotNull(lValue);

Preconditions.checkArgument(
ALLOWED_TYPES.contains(lValue.getToken()),
"Unexpected lValue type %s",
Expand Down
Expand Up @@ -38,6 +38,8 @@ class FunctionArgumentInjector {
// identifier can be used, so we use "this".
static final String THIS_MARKER = "this";

static final String REST_MARKER = "REST";

private FunctionArgumentInjector() {
// A private constructor to prevent instantiation.
}
Expand Down Expand Up @@ -549,7 +551,11 @@ private static void gatherLocalNames(Node n, Set<String> names) {
private static Set<String> getFunctionParameterSet(Node fnNode) {
Set<String> set = new HashSet<>();
for (Node n : NodeUtil.getFunctionParameters(fnNode).children()) {
set.add(n.getString());
if (n.isRest()){
set.add(REST_MARKER);
} else {
set.add(n.getString());
}
}
return set;
}
Expand Down

0 comments on commit d29f4c1

Please sign in to comment.