Repository navigation
Expand file tree
/
Copy pathCompileJS.h
More file actions
71 lines (60 loc) · 1.92 KB
/
Copy pathCompileJS.h
File metadata and controls
71 lines (60 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#ifndef HERMES_COMPILEJS_H
#define HERMES_COMPILEJS_H
#include <optional>
#include <string>
#include <vector>
namespace hermes {
/// Interface for receiving errors, warnings and notes produced by compileJS.
class DiagnosticHandler {
public:
enum Kind {
Error,
Warning,
Note,
};
struct Diagnostic {
Kind kind;
int line; /// 1-based index
int column; /// 1-based index
std::string message;
/// 0-based char indices in half-open intervals
std::vector<std::pair<unsigned, unsigned>> ranges;
};
/// Called once for each diagnostic message produced during compilation.
virtual void handle(const Diagnostic &diagnostic) = 0;
virtual ~DiagnosticHandler() = default;
};
/// Compiles JS source \p str and if compilation is successful, returns true
/// and outputs to \p bytecode otherwise returns false.
/// \param sourceURL this will be used as the "file name" of the buffer for
/// errors, stack traces, etc.
/// \param optimize this will enable optimizations.
/// \param emitAsyncBreakCheck this will make the bytecode interruptable.
/// \param diagHandler if not null, receives any and all errors, warnings and
/// notes produced during compilation.
/// \param sourceMapBuf optional source map string.
bool compileJS(
const std::string &str,
const std::string &sourceURL,
std::string &bytecode,
bool optimize,
bool emitAsyncBreakCheck,
DiagnosticHandler *diagHandler,
std::optional<std::string_view> sourceMapBuf = std::nullopt);
bool compileJS(
const std::string &str,
std::string &bytecode,
bool optimize = true);
bool compileJS(
const std::string &str,
const std::string &sourceURL,
std::string &bytecode,
bool optimize = true);
} // namespace hermes
#endif