• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2025 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    global,
18    passNode,
19    unpackNode,
20    assertValidPeer,
21    AstNode,
22    Es2pandaAstNodeType,
23    KNativePointer,
24    nodeByType,
25} from '../../reexport-for-generated';
26
27import { LoopStatement } from './LoopStatement';
28import { Expression } from './Expression';
29import { Statement } from './Statement';
30export class ForOfStatement extends LoopStatement {
31    constructor(pointer: KNativePointer) {
32        assertValidPeer(pointer, Es2pandaAstNodeType.AST_NODE_TYPE_FOR_OF_STATEMENT);
33        super(pointer);
34    }
35    static createForOfStatement(
36        left: AstNode | undefined,
37        right: Expression | undefined,
38        body: Statement | undefined,
39        isAwait: boolean
40    ): ForOfStatement {
41        return new ForOfStatement(
42            global.generatedEs2panda._CreateForOfStatement(
43                global.context,
44                passNode(left),
45                passNode(right),
46                passNode(body),
47                isAwait
48            )
49        );
50    }
51    static updateForOfStatement(
52        original: ForOfStatement | undefined,
53        left: AstNode | undefined,
54        right: Expression | undefined,
55        body: Statement | undefined,
56        isAwait: boolean
57    ): ForOfStatement {
58        return new ForOfStatement(
59            global.generatedEs2panda._UpdateForOfStatement(
60                global.context,
61                passNode(original),
62                passNode(left),
63                passNode(right),
64                passNode(body),
65                isAwait
66            )
67        );
68    }
69    get left(): AstNode | undefined {
70        return unpackNode(global.generatedEs2panda._ForOfStatementLeft(global.context, this.peer));
71    }
72    get right(): Expression | undefined {
73        return unpackNode(global.generatedEs2panda._ForOfStatementRight(global.context, this.peer));
74    }
75    get body(): Statement | undefined {
76        return unpackNode(global.generatedEs2panda._ForOfStatementBody(global.context, this.peer));
77    }
78    get isAwait(): boolean {
79        return global.generatedEs2panda._ForOfStatementIsAwaitConst(global.context, this.peer);
80    }
81    protected readonly brandForOfStatement: undefined;
82}
83export function isForOfStatement(node: object | undefined): node is ForOfStatement {
84    return node instanceof ForOfStatement;
85}
86if (!nodeByType.has(Es2pandaAstNodeType.AST_NODE_TYPE_FOR_OF_STATEMENT)) {
87    nodeByType.set(Es2pandaAstNodeType.AST_NODE_TYPE_FOR_OF_STATEMENT, ForOfStatement);
88}
89