Debian Codegraph @

test/com/google/javascript/jscomp/PrepareAstTest.java

raw symbols SCIP
1 /*
2 * Copyright 2009 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
17 package com.google.javascript.jscomp;
18
19 import com.google.common.base.Preconditions;
20 import com.google.javascript.rhino.Node;
21 import com.google.javascript.rhino.Token;
22
23
24 /**
25 * Tests for PrepareAst.
26 * @author [email protected] (Nick Santos)
27 */
28 public class PrepareAstTest extends CompilerTestCase {
29
30 public PrepareAstTest() {
31 super.enableLineNumberCheck(true);
32 }
33
34 @Override
35 public CompilerPass getProcessor(Compiler compiler) {
36 return null; // unused
37 }
38
39 public void testJsDocNormalization() throws Exception {
40 Node root = parseExpectedJs(
41 "var x = {/** @return {number} */ a: function() {}," +
42 " c: /** @type {string} */ ('d')};");
43 Node objlit = root.getFirstChild().getFirstChild().getFirstChild()
44 .getFirstChild();
45 assertEquals(Token.OBJECTLIT, objlit.getType());
46
47 Node firstKey = objlit.getFirstChild();
48 Node firstVal = firstKey.getFirstChild();
49
50 Node secondKey = firstKey.getNext();
51 Node secondVal = secondKey.getFirstChild();
52 assertNotNull(firstKey.getJSDocInfo());
53 assertNotNull(firstVal.getJSDocInfo());
54 assertNull(secondKey.getJSDocInfo());
55 assertNotNull(secondVal.getJSDocInfo());
56 }
57
58 public void testFreeCall1() throws Exception {
59 Node root = parseExpectedJs("foo();");
60 Node script = root.getFirstChild();
61 Preconditions.checkState(script.isScript());
62 Node firstExpr = script.getFirstChild();
63 Node call = firstExpr.getFirstChild();
64 Preconditions.checkState(call.isCall());
65
66 assertTrue(call.getBooleanProp(Node.FREE_CALL));
67 }
68
69 public void testFreeCall2() throws Exception {
70 Node root = parseExpectedJs("x.foo();");
71 Node script = root.getFirstChild();
72 Preconditions.checkState(script.isScript());
73 Node firstExpr = script.getFirstChild();
74 Node call = firstExpr.getFirstChild();
75 Preconditions.checkState(call.isCall());
76
77 assertFalse(call.getBooleanProp(Node.FREE_CALL));
78 }
79 }