idlize
51 строка · 1.8 Кб
1/*
2* Copyright (c) 2022-2023 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 * as ts from "typescript"17import { AbstractVisitor } from "./AbstractVisitor";18import { FunctionKind, FunctionTable, isAnyMemoKind, isFunctionOrMethod, Tracer } from "./util";19
20export class DumpVisitor extends AbstractVisitor {21constructor(22public tracer: Tracer,23public sourceFile: ts.SourceFile,24public functionTable: FunctionTable,25ctx: ts.TransformationContext26) {27super(ctx)28}29
30declarationKind(node: ts.FunctionLikeDeclarationBase): FunctionKind {31const originalNode = ts.getOriginalNode(node) as ts.FunctionLikeDeclarationBase32return this.functionTable.get(originalNode) ?? FunctionKind.REGULAR33}34
35isAnyMemo(node: ts.FunctionLikeDeclarationBase): boolean {36return isAnyMemoKind(this.declarationKind(node))37}38
39visitor(beforeChildren: ts.Node): ts.Node {40const node = this.visitEachChild(beforeChildren)41let transformed: ts.Node|undefined = undefined42
43if (isFunctionOrMethod(node)) {44if (isAnyMemoKind(this.declarationKind(node))) {45this.tracer.keepTransformedFunction(node, this.sourceFile)46}47return node48}49return transformed ?? node50}51}