Skip to content

Commit

Permalink
- fix invalid js syntax due to possible trailing comma characters (",").
Browse files Browse the repository at this point in the history
  when esbuild minification is enabled, esbuild condenses the original javascript code prepared by `GenericLoader.parseToJs`, and replaces the newlines with with either a semicolon or a comma delimiter (";" or ",").
  this means that when we strip away our dynamic import statements and `imports_beginning_marker` and `imports_ending_marker`, we will be potentially left with a bunch of commas with nothing in between, resulting in an incorrect js code, therefore becoming un-importable by `GenericLoader.unparseFromJs`.
  • Loading branch information
omar-azmi committed Dec 13, 2024
1 parent fee03ff commit bd2d59a
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,12 @@ const
imports_ending_marker = "globalThis.end_of_imports()",
import_statements_block_regex = new RegExp(
escapeStringForRegex(imports_beginning_marker)
+ "[\,\;]*" // if esbuild minification is enabled, then either a ";" or a "," delimiter will be placed between statements instead of a new line.
+ `(?<importStatements>.*?)`
+ escapeStringForRegex(imports_ending_marker),
"gs",
),
import_statement_regex = new RegExp("await\\s+import\\(\\s*\"(?<importPath>.*?)\"\\s*\\)", "g"),
import_statement_regex = new RegExp("await\\s+import\\(\\s*\"(?<importPath>.*?)\"\\s*\\)[\,\;]*", "g"),
deps_list_to_js_fn = zipArraysMapperFactory<[string, string], string>(
([import_key, import_path]): string => {
return `
Expand Down

0 comments on commit bd2d59a

Please sign in to comment.