• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2024 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 {
17    ClassDefinition,
18    Expression,
19    Identifier,
20    TSClassImplements,
21    TSTypeParameterDeclaration,
22    TSTypeParameterInstantiation,
23} from '../../generated';
24import { isSameNativeObject } from '../peers/ArktsObject';
25import { AstNode } from '../peers/AstNode';
26import { MethodDefinition } from '../types';
27import { updateThenAttach } from '../utilities/private';
28import { Es2pandaClassDefinitionModifiers, Es2pandaModifierFlags } from '../../generated/Es2pandaEnums';
29import { classDefinitionFlags } from '../utilities/public';
30
31export function updateClassDefinition(
32    original: ClassDefinition,
33    ident: Identifier | undefined,
34    typeParams: TSTypeParameterDeclaration | undefined,
35    superTypeParams: TSTypeParameterInstantiation | undefined,
36    _implements: readonly TSClassImplements[],
37    ctor: MethodDefinition | undefined,
38    superClass: Expression | undefined,
39    body: readonly AstNode[],
40    modifiers: Es2pandaClassDefinitionModifiers,
41    flags: Es2pandaModifierFlags
42): ClassDefinition {
43    if (
44        isSameNativeObject(ident, original.ident) &&
45        isSameNativeObject(typeParams, original.typeParams) &&
46        isSameNativeObject(superTypeParams, original.superTypeParams) &&
47        isSameNativeObject(_implements, original.implements) &&
48        isSameNativeObject(superClass, original.super) &&
49        isSameNativeObject(body, original.body) &&
50        isSameNativeObject(modifiers, original.modifiers) &&
51        isSameNativeObject(flags, classDefinitionFlags(original))
52        /* TODO: no getter for ctor */
53    ) {
54        return original;
55    }
56
57    const update = updateThenAttach(
58        ClassDefinition.updateClassDefinition,
59        (node: ClassDefinition, original: ClassDefinition) => node.setAnnotations(original.annotations)
60    );
61    return update(
62        original,
63        ident,
64        typeParams,
65        superTypeParams,
66        _implements,
67        undefined,
68        superClass,
69        body,
70        modifiers,
71        flags
72    );
73}
74