• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2021 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
16// [delete it when type system adapts for ESM]
17import * as ts from "typescript";
18import * as jshelpers from "./jshelpers";
19import { DiagnosticCode, DiagnosticError } from "./diagnostic";
20
21export class ModuleStmt {
22    private node: ts.Node
23    private moduleRequest: string;
24    private namespace: string = "";
25    private bingdingNameMap: Map<string, string> = new Map<string, string>();
26    private bingdingNodeMap: Map<ts.Node, ts.Node> = new Map<ts.Node, ts.Node>();
27    private isCopy: boolean = true;
28
29    constructor(node: ts.Node, moduleRequest: string = "") {
30        this.node = node;
31        this.moduleRequest = moduleRequest;
32    }
33
34    getNode() {
35        return this.node;
36    }
37
38    getModuleRequest() {
39        return this.moduleRequest;
40    }
41
42    addLocalName(localName: string, importName: string) {
43        if (this.bingdingNameMap.has(localName)) {
44            throw new DiagnosticError(this.node, DiagnosticCode.Duplicate_identifier_0, jshelpers.getSourceFileOfNode(this.node), [localName]);
45        }
46        this.bingdingNameMap.set(localName, importName);
47    }
48
49    getBindingNameMap() {
50        return this.bingdingNameMap;
51    }
52
53    addNodeMap(name: ts.Node, propertyName: ts.Node) {
54        this.bingdingNodeMap.set(name, propertyName);
55    }
56
57    getBindingNodeMap() {
58        return this.bingdingNodeMap;
59    }
60
61    setNameSpace(namespace: string) {
62        this.namespace = namespace;
63    }
64
65    getNameSpace() {
66        return this.namespace;
67    }
68
69    setCopyFlag(isCopy: boolean) {
70        this.isCopy = isCopy;
71    }
72
73    getCopyFlag() {
74        return this.isCopy;
75    }
76}
77