ezno_checker/
options.rs

1/// Options for type checking
2/// TODO figure out compat with tsc
3#[cfg_attr(feature = "serde-serialize", derive(serde::Deserialize), serde(default))]
4#[cfg_attr(target_family = "wasm", derive(tsify::Tsify))]
5#[allow(clippy::struct_excessive_bools)]
6#[derive(Clone)]
7pub struct TypeCheckOptions {
8	/// Parameters cannot be reassigned
9	pub constant_parameters: bool,
10
11	/// Missing arguments are treated as undefined (thats how JS works)
12	pub allow_elided_arguments: bool,
13
14	/// Addition arguments are allowed
15	pub allow_extra_arguments: bool,
16
17	/// Given a `function x`, `x = 2` is not possible
18	pub constant_function_declarations: bool,
19
20	/// Whether auto casts can happen. aka `{} + 2` is allowed using the Object's primitive default
21	/// TODO maybe levels
22	pub strict_casts: bool,
23
24	/// Any types displayed will be in debug view
25	pub debug_types: bool,
26
27	/// Enables `as` casts
28	pub allow_type_casts: bool,
29
30	/// For post type check optimisations and LSP. Stores both expressions and type annotations
31	pub store_type_mappings: bool,
32
33	/// ?
34	pub extra_syntax: bool,
35
36	/// TODO WIP
37	pub parse_comments: bool,
38
39	/// Allows partial syntax and collects other information for using in editor
40	pub lsp_mode: bool,
41
42	/// Can be used for linting
43	pub record_all_assignments_and_reads: bool,
44
45	/// Technically the `i` in `for (let i = 0; i < ...)` can be reassigned to `any` type. But this behavior isn't great
46	/// and adds work for the inference engine. So this instead picks a basic type instead. This will
47	/// raise errors in valid javascript
48	pub infer_sensible_constraints_in_for_loops: bool,
49
50	/// Evaluate exports to detect dead code
51	pub evaluate_exports: bool,
52
53	pub max_inline_count: u16,
54
55	pub measure_time: bool,
56
57	/// Enables two things:
58	/// - range and modulo class inference
59	/// - modifications to ranges and classes based on operations
60	pub advanced_numbers: bool,
61
62	/// Printing internal diagnostics in dts
63	pub debug_dts: bool,
64}
65
66impl Default for TypeCheckOptions {
67	fn default() -> Self {
68		Self {
69			constant_parameters: false,
70			allow_elided_arguments: false,
71			allow_extra_arguments: false,
72			constant_function_declarations: true,
73			debug_types: false,
74			parse_comments: true,
75			strict_casts: false,
76			store_type_mappings: false,
77			lsp_mode: false,
78			record_all_assignments_and_reads: false,
79			infer_sensible_constraints_in_for_loops: true,
80			// TODO false at some point hopefully!
81			allow_type_casts: true,
82			evaluate_exports: false,
83			max_inline_count: 300,
84			measure_time: false,
85			debug_dts: false,
86			extra_syntax: true,
87			advanced_numbers: false,
88		}
89	}
90}