• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2021 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16// singleton to print debug logs
17import * as ts from "typescript";
18import { CmdOptions } from "./cmdOptions";
19
20export function LOGD(tag: any, ...args: any[]) {
21    if (CmdOptions.isEnableDebugLog()) {
22        if (tag) {
23            console.log(tag + ": " + args);
24        } else {
25            console.log(args);
26        }
27    }
28}
29
30export function LOGE(tag: any, ...args: any[]) {
31    if (tag) {
32        console.error(tag + ": " + args);
33    } else {
34        console.error(args);
35    }
36}
37
38export function printAstRecursively(node: ts.Node, indentLevel: number, sourceFile: ts.SourceFile) {
39    if (CmdOptions.isEnableDebugLog()) {
40        const indentation = "-".repeat(indentLevel);
41        let nodeContent = ts.SyntaxKind[node.kind] + ": ";
42        if (node.kind == ts.SyntaxKind.Identifier) {
43            // @ts-ignore
44            nodeContent += (<ts.Identifier>node).escapedText;
45        }
46        console.log(`${indentation}${nodeContent}`);
47
48        node.forEachChild(child =>
49            printAstRecursively(child, indentLevel + 1, sourceFile)
50        );
51    }
52}
53