• 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 { LabelPair } from '../../generated/peers/LabelPair';
17import { BlockStatement, CatchClause, Statement, TryStatement } from '../../generated';
18import { isSameNativeObject } from '../peers/ArktsObject';
19import { attachModifiers, updateThenAttach } from '../utilities/private';
20
21export function updateTryStatement(
22    original: TryStatement,
23    block: BlockStatement | undefined,
24    catchClauses: readonly CatchClause[],
25    finalizer: BlockStatement | undefined,
26    finalizerInsertionsLabelPair: readonly LabelPair[],
27    finalizerInsertionsStatement: readonly Statement[]
28): TryStatement {
29    if (
30        isSameNativeObject(block, original.block) &&
31        isSameNativeObject(catchClauses, original.catchClauses) &&
32        isSameNativeObject(finalizer, original.finallyBlock)
33        /* TODO: no getter for finalizerInsertionsLabelPair */
34        /* TODO: no getter for finalizerInsertionsStatement */
35    ) {
36        return original;
37    }
38
39    const update = updateThenAttach(TryStatement.updateTryStatement, attachModifiers);
40    return update(original, block, catchClauses, finalizer, finalizerInsertionsLabelPair, finalizerInsertionsStatement);
41}
42