• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 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
16import { HeritageClause, Node, SourceFile, SyntaxKind } from 'typescript';
17
18/**
19 * get heritage info
20 * @param node
21 * @param sourceFile
22 * @returns
23 */
24export function getHeritageClauseDeclaration(node: Node, sourceFile: SourceFile): HeritageClauseEntity {
25  const HeritageClauseNode = node as HeritageClause;
26  const clauseToken = HeritageClauseNode.token === SyntaxKind.ExtendsKeyword ? 'extends' : 'implements';
27  const types: Array<string> = [];
28
29  HeritageClauseNode.types.forEach(value => {
30    types.push(sourceFile.text.substring(value.pos, value.end).trimStart().trimEnd());
31  });
32
33  return {
34    clauseToken: clauseToken,
35    types: types
36  };
37}
38
39export interface HeritageClauseEntity {
40  clauseToken: string,
41  types: Array<string>
42}
43