• 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 { FunctionSignature, ScriptFunction } from '../../generated';
17import { isSameNativeObject } from '../peers/ArktsObject';
18import { AstNode } from '../peers/AstNode';
19import { updateThenAttach } from '../utilities/private';
20
21export function updateScriptFunction(
22    original: ScriptFunction,
23    databody: AstNode | undefined,
24    datasignature: FunctionSignature | undefined,
25    datafuncFlags: number,
26    dataflags: number
27): ScriptFunction {
28    if (
29        isSameNativeObject(databody, original.body) &&
30        isSameNativeObject(datasignature?.params, original.params) &&
31        isSameNativeObject(datasignature?.typeParams, original.typeParams) &&
32        isSameNativeObject(datasignature?.returnType, original.returnTypeAnnotation) &&
33        isSameNativeObject(datasignature?.hasReceiver, original.hasReceiver) &&
34        isSameNativeObject(datafuncFlags, original.flags) &&
35        isSameNativeObject(dataflags, original.modifiers)
36    ) {
37        return original;
38    }
39
40    const update = updateThenAttach(
41        ScriptFunction.updateScriptFunction,
42        (node: ScriptFunction, original: ScriptFunction) => (!!original.id ? node.setIdent(original.id) : node),
43        (node: ScriptFunction, original: ScriptFunction) => node.setAnnotations(original.annotations)
44    );
45    return update(original, databody, datasignature, datafuncFlags, dataflags);
46}
47