Debian Codegraph @

src/com/google/javascript/jscomp/CheckDebuggerStatement.java

raw symbols SCIP
1 /*
2 * Copyright 2011 The Closure Compiler Authors.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package com.google.javascript.jscomp;
17
18 import com.google.javascript.jscomp.DiagnosticType;
19 import com.google.javascript.jscomp.NodeTraversal.AbstractPostOrderCallback;
20 import com.google.javascript.rhino.Node;
21
22 /**
23 * {@link CheckDebuggerStatement} checks for the presence of the "debugger"
24 * statement in JavaScript code. It is appropriate to use this statement while
25 * developing JavaScript; however, it is generally undesirable to include it in
26 * production code.
27 *
28 * @author [email protected] (Michael Bolin)
29 */
30 class CheckDebuggerStatement extends AbstractPostOrderCallback
31 implements CompilerPass {
32
33 static final DiagnosticType DEBUGGER_STATEMENT_PRESENT =
34 DiagnosticType.disabled("JSC_DEBUGGER_STATEMENT_PRESENT",
35 "Using the debugger statement can halt your application if the user " +
36 "has a JavaScript debugger running.");
37
38 private final AbstractCompiler compiler;
39
40 public CheckDebuggerStatement(AbstractCompiler compiler) {
41 this.compiler = compiler;
42 }
43
44 @Override
45 public void process(Node externs, Node root) {
46 NodeTraversal.traverse(compiler, root, this);
47 }
48
49 @Override
50 public void visit(NodeTraversal t, Node n, Node parent) {
51 if (n.isDebugger()) {
52 t.report(n, DEBUGGER_STATEMENT_PRESENT);
53 }
54 }
55 }