• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2021-2022 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
16const path = require('path');
17const ts = require(path.resolve(__dirname, "../node_modules/typescript"));
18const fs = require("fs");
19const result = require("../check_result.json");
20const { getAPINote, error_type } = require('./utils');
21const { addAPICheckErrorLogs } = require('./compile_info');
22
23function checkDeprecated(node, sourcefile, fileName) {
24    const apiNote = getAPINote(node);
25    const apiNoteArr = apiNote.split('*');
26    let hasDeprecatedError = false;
27    let errorInfo = "";
28    apiNoteArr.forEach(note => {
29        if (note.match(new RegExp('@deprecated'))) {
30            const deprecatedNote = note.replace('@deprecated', '').trim();
31            const regx = /since [0-9]/;
32            const arr = deprecatedNote.match(regx);
33            if (arr != null) {
34                const errorNote = deprecatedNote.replace(arr[0], '');
35                if (/[A-z]/.test(errorNote)) {
36                    hasDeprecatedError = true;
37                    if (errorInfo !== "") {
38                        errorInfo += `,${note}`;
39                    } else {
40                        errorInfo += note;
41                    }
42                } else {
43                    if (/@useinstead/.test(apiNote)) {
44
45                    } else {
46                        hasDeprecatedError = true;
47                        if (errorInfo !== "") {
48                            errorInfo += `,${note}`;
49                        } else {
50                            errorInfo += note;
51                        }
52                    }
53                }
54            } else if (arr == null) {
55                hasDeprecatedError = true;
56                if (errorInfo !== "") {
57                    errorInfo += `,${note}`;
58                } else {
59                    errorInfo += note;
60                }
61            }
62        }
63    });
64
65    if (hasDeprecatedError) {
66        addAPICheckErrorLogs(node, sourcefile, fileName, error_type.UNKNOW_DEPRECATED, errorInfo);
67    }
68}
69exports.checkDeprecated = checkDeprecated;