• 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 
16 #include <algorithm>
17 #include <cstddef>
18 #include <iostream>
19 #include <ostream>
20 #include <string>
21 #include <cstring>
22 #include "util.h"
23 #include "public/es2panda_lib.h"
24 
25 // NOLINTBEGIN
26 
27 static es2panda_Impl *impl = nullptr;
28 static auto source = std::string("function main() { 1 + 2 }");
29 
main(int argc,char ** argv)30 int main(int argc, char **argv)
31 {
32     if (argc < MIN_ARGC) {
33         return 1;
34     }
35 
36     if (GetImpl() == nullptr) {
37         return NULLPTR_IMPL_ERROR_CODE;
38     }
39     impl = GetImpl();
40     const char **args = const_cast<const char **>(&(argv[1]));
41     auto config = impl->CreateConfig(argc - 1, args);
42     auto context = impl->CreateContextFromString(config, source.data(), argv[argc - 1]);
43     if (context == nullptr) {
44         std::cerr << "FAILED TO CREATE CONTEXT" << std::endl;
45         return NULLPTR_CONTEXT_ERROR_CODE;
46     }
47 
48     impl->ProceedToState(context, ES2PANDA_STATE_PARSED);
49     CheckForErrors("PARSE", context);
50 
51     auto outDir = impl->ArkTsConfigOutDirConst(
52         context,
53         impl->OptionsUtilArkTSConfigConst(context, const_cast<es2panda_Options *>(impl->ConfigGetOptions(config))));
54     if (strstr(outDir, "bin") == nullptr) {
55         return TEST_ERROR_CODE;
56     }
57 
58     if (impl->ContextState(context) == ES2PANDA_STATE_ERROR) {
59         return PROCEED_ERROR_CODE;
60     }
61     impl->DestroyContext(context);
62     impl->DestroyConfig(config);
63 
64     return 0;
65 }
66 
67 // NOLINTEND
68