diff --git a/src/com/google/javascript/jscomp/DefaultPassConfig.java b/src/com/google/javascript/jscomp/DefaultPassConfig.java index 7ad4c81280d..161c15274c1 100644 --- a/src/com/google/javascript/jscomp/DefaultPassConfig.java +++ b/src/com/google/javascript/jscomp/DefaultPassConfig.java @@ -31,7 +31,6 @@ 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.lint.CheckArguments; import com.google.javascript.jscomp.lint.CheckDuplicateCase; import com.google.javascript.jscomp.lint.CheckEmptyStatements; import com.google.javascript.jscomp.lint.CheckEnums; @@ -1558,7 +1557,6 @@ protected HotSwapCompilerPass create(AbstractCompiler compiler) { @Override protected HotSwapCompilerPass create(AbstractCompiler compiler) { ImmutableList.Builder callbacks = ImmutableList.builder() - .add(new CheckArguments(compiler)) .add(new CheckEmptyStatements(compiler)) .add(new CheckEnums(compiler)) .add(new CheckInterfaces(compiler)) diff --git a/src/com/google/javascript/jscomp/DiagnosticGroups.java b/src/com/google/javascript/jscomp/DiagnosticGroups.java index 3cef2cf94df..280a613b0c7 100644 --- a/src/com/google/javascript/jscomp/DiagnosticGroups.java +++ b/src/com/google/javascript/jscomp/DiagnosticGroups.java @@ -20,7 +20,6 @@ import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; -import com.google.javascript.jscomp.lint.CheckArguments; import com.google.javascript.jscomp.lint.CheckDuplicateCase; import com.google.javascript.jscomp.lint.CheckEmptyStatements; import com.google.javascript.jscomp.lint.CheckEnums; @@ -468,7 +467,6 @@ public DiagnosticGroup forName(String name) { // provide optional suggestions. public static final DiagnosticGroup LINT_CHECKS = DiagnosticGroups.registerGroup("lintChecks", // undocumented - CheckArguments.BAD_ARGUMENTS_USAGE, CheckEmptyStatements.USELESS_EMPTY_STATEMENT, CheckEnums.COMPUTED_PROP_NAME_IN_ENUM, CheckEnums.DUPLICATE_ENUM_VALUE, diff --git a/src/com/google/javascript/jscomp/LintPassConfig.java b/src/com/google/javascript/jscomp/LintPassConfig.java index 01166857f1d..41d58cec184 100644 --- a/src/com/google/javascript/jscomp/LintPassConfig.java +++ b/src/com/google/javascript/jscomp/LintPassConfig.java @@ -17,7 +17,6 @@ import com.google.common.collect.ImmutableList; import com.google.javascript.jscomp.NodeTraversal.Callback; -import com.google.javascript.jscomp.lint.CheckArguments; import com.google.javascript.jscomp.lint.CheckDuplicateCase; import com.google.javascript.jscomp.lint.CheckEmptyStatements; import com.google.javascript.jscomp.lint.CheckEnums; @@ -107,7 +106,6 @@ protected CompilerPass create(AbstractCompiler compiler) { return new CombinedCompilerPass( compiler, ImmutableList.of( - new CheckArguments(compiler), new CheckDuplicateCase(compiler), new CheckEmptyStatements(compiler), new CheckEnums(compiler), diff --git a/src/com/google/javascript/jscomp/lint/CheckArguments.java b/src/com/google/javascript/jscomp/lint/CheckArguments.java deleted file mode 100644 index 011d41dacf1..00000000000 --- a/src/com/google/javascript/jscomp/lint/CheckArguments.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright 2015 The Closure Compiler Authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.google.javascript.jscomp.lint; - -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.AbstractPostOrderCallback; -import com.google.javascript.jscomp.Var; -import com.google.javascript.rhino.Node; - - -/** - * Check for the 'arguments' object being used in ways which are unlikely to be optimized well, - * and which we cannot transpile correctly. - */ -public final class CheckArguments extends AbstractPostOrderCallback implements CompilerPass { - public static final DiagnosticType BAD_ARGUMENTS_USAGE = - DiagnosticType.warning( - "JSC_BAD_ARGUMENTS_USAGE", - "This use of the 'arguments' object is discouraged. See " - + "https://github.com/google/closure-compiler/wiki/Lint-warning-about-%60arguments%60"); - - private final AbstractCompiler compiler; - - public CheckArguments(AbstractCompiler compiler) { - this.compiler = compiler; - } - - @Override - public void process(Node externs, Node root) { - NodeTraversal.traverseEs6(compiler, root, this); - } - - @Override - public void visit(NodeTraversal t, Node n, Node parent) { - if (!n.isName()) { - return; - } - - Var var = t.getScope().getVar(n.getString()); - if (var != null && var.isArguments()) { - checkArgumentsUsage(n, parent); - } - } - - private void checkArgumentsUsage(Node arguments, Node parent) { - if (parent.isSpread() - || (parent.isGetProp() && parent.matchesQualifiedName("arguments.length")) - || (parent.isForOf() && arguments == parent.getSecondChild()) - || (parent.isGetElem() && arguments == parent.getFirstChild())) { - // No warning. - return; - } - - if (parent.isCall() && arguments == parent.getLastChild()) { - Node callee = parent.getFirstChild(); - if (callee.isGetProp() && callee.getLastChild().getString().equals("apply")) { - // Probably a call to Function.apply(), so don't warn. - return; - } - } - - report(arguments); - } - - private void report(Node arguments) { - compiler.report(JSError.make(arguments, BAD_ARGUMENTS_USAGE)); - } -} - diff --git a/test/com/google/javascript/jscomp/lint/CheckArgumentsTest.java b/test/com/google/javascript/jscomp/lint/CheckArgumentsTest.java deleted file mode 100644 index d69efa971a8..00000000000 --- a/test/com/google/javascript/jscomp/lint/CheckArgumentsTest.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2015 The Closure Compiler Authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.javascript.jscomp.lint; - -import static com.google.javascript.jscomp.lint.CheckArguments.BAD_ARGUMENTS_USAGE; - -import com.google.javascript.jscomp.Compiler; -import com.google.javascript.jscomp.CompilerPass; -import com.google.javascript.jscomp.Es6CompilerTestCase; - -public final class CheckArgumentsTest extends Es6CompilerTestCase { - @Override - public CompilerPass getProcessor(Compiler compiler) { - return new CheckArguments(compiler); - } - - public void testCheckArguments_noWarning() { - testSameEs6("function f() { for (let a of arguments) {} }"); - testSameEs6("function f() { return [...arguments]; }"); - testSameEs6("function f() { return arguments[1]; }"); - testSameEs6("function f() { for (var i=0; i