Skip to content

Commit

Permalink
Fix TextEncoder stub name (#3357)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaslihotzki committed May 8, 2023
1 parent 8994cb9 commit 80b616e
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions crates/cli-support/src/js/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1440,7 +1440,7 @@ impl<'a> Context<'a> {
if !self.should_write_global("text_encoder") {
return Ok(());
}
self.expose_text_processor("TextEncoder", "('utf-8')", None)
self.expose_text_processor("TextEncoder", "encode", "('utf-8')", None)
}

fn expose_text_decoder(&mut self) -> Result<(), Error> {
Expand All @@ -1456,6 +1456,7 @@ impl<'a> Context<'a> {
// `fatal` is needed to catch any weird encoding bugs when sending a string from Rust to JS
self.expose_text_processor(
"TextDecoder",
"decode",
"('utf-8', { ignoreBOM: true, fatal: true })",
init,
)?;
Expand All @@ -1466,6 +1467,7 @@ impl<'a> Context<'a> {
fn expose_text_processor(
&mut self,
s: &str,
op: &str,
args: &str,
init: Option<&str>,
) -> Result<(), Error> {
Expand Down Expand Up @@ -1496,7 +1498,7 @@ impl<'a> Context<'a> {
| OutputMode::Web
| OutputMode::NoModules { .. }
| OutputMode::Bundler { browser_only: true } => {
self.global(&format!("const cached{0} = (typeof {0} !== 'undefined' ? new {0}{1} : {{ decode: () => {{ throw Error('{0} not available') }} }} );", s, args))
self.global(&format!("const cached{0} = (typeof {0} !== 'undefined' ? new {0}{1} : {{ {2}: () => {{ throw Error('{0} not available') }} }} );", s, args, op))
}
};

Expand Down

0 comments on commit 80b616e

Please sign in to comment.