Skip to content

Commit

Permalink
TypeScript output should automatically find the Promise library
Browse files Browse the repository at this point in the history
  • Loading branch information
sasial-dev committed Jul 1, 2024
1 parent 7e6c97f commit ed2eb5f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
10 changes: 4 additions & 6 deletions zap/src/output/luau/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -476,12 +476,10 @@ impl<'src> ClientOutput<'src> {
if !self.config.fndecls.is_empty() {
self.push_line("local function_call_id = 0");

if !self.config.async_lib.is_empty() {
if self.config.typescript {
self.push_line(&format!("local Promise = {}.Promise", self.config.async_lib))
} else {
self.push_line(&format!("local {} = {}", self.config.yield_type, self.config.async_lib))
}
if self.config.typescript && self.config.yield_type == YieldType::Promise {
self.push_line("local Promise = _G[script].Promise")
} else if !self.config.async_lib.is_empty() {
self.push_line(&format!("local {} = {}", self.config.yield_type, self.config.async_lib))
}
}

Expand Down
2 changes: 1 addition & 1 deletion zap/src/output/luau/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ pub trait Output {
self.push_line("--!optimize 2");
self.push_line("--!nocheck");
self.push_line("--!nolint");
self.push_line("--#selene: allow(unused_variable, incorrect_standard_library_use)");
self.push_line("--#selene: allow(unused_variable, incorrect_standard_library_use, global_usage)");

self.push_line(&format!(
"-- {scope} generated by Zap v{} (https://github.com/red-blox/zap)",
Expand Down
6 changes: 3 additions & 3 deletions zap/src/parser/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ impl<'src> Converter<'src> {

let casing = self.casing_opt(&config.opts);
let yield_type = self.yield_type_opt(typescript, &config.opts);
let async_lib = self.async_lib(yield_type, &config.opts);
let async_lib = self.async_lib(yield_type, &config.opts, typescript);

let config = Config {
tydecls,
Expand All @@ -121,7 +121,7 @@ impl<'src> Converter<'src> {
(config, self.reports)
}

fn async_lib(&mut self, yield_type: YieldType, opts: &[SyntaxOpt<'src>]) -> &'src str {
fn async_lib(&mut self, yield_type: YieldType, opts: &[SyntaxOpt<'src>], typescript: bool) -> &'src str {
let (async_lib, async_lib_span) = self.str_opt("async_lib", "", opts);

if let Some(span) = async_lib_span {
Expand All @@ -136,7 +136,7 @@ impl<'src> Converter<'src> {
expected: "that `async_lib` cannot be defined when using a `yield_type` of `yield`",
});
}
} else if async_lib.is_empty() && yield_type != YieldType::Yield {
} else if async_lib.is_empty() && yield_type != YieldType::Yield && !typescript {
self.report(Report::AnalyzeMissingOptValue {
expected: "`async_lib`",
required_when: "`yield_type` is set to `promise` or `future`.",
Expand Down

0 comments on commit ed2eb5f

Please sign in to comment.