Included libraries end up getting newlines expanding.
easel opened this issue ยท 7 comments
I don't have an easy repro on hand yet, but the solution may be obvious. If the included library (@aws-sdk/s3 in the case) as a line with a \n, it gets replaced with a literal newline, like this:
if (xmlData[i] === " " || xmlData[i] === " " || xmlData[i] === "\n" || xmlData[i] === "\r")
becomes
if (xmlData[i] === " " || xmlData[i] === " " || xmlData[i] === "
" || xmlData[i] === "\r")
Obviously this fails to parse.
I also faced this when I tried to include react-js
, I can't think of a solution yet. It might be esbuild's default behaviour. I am yet to fully understand this. Do you have any thoughts?
I dug into this some more. There are at least two things going on.
The first one is that esbuild optimizes template literals. So for instance this:
`the quick ` + '\n' `red fox`
becomes
`the quick
red fox`
which I think is actually ok. You can see this happening by just running esbuild on an input file with a construction such as above.
The second thing is the bigger problem. Somewhere in the chain that writes the esbuild output it's expanding \n
. I can't figure out where, there's not really that much code, but in my test branch the interesting thing is it's happening to both the tap snapshot and the input file, so it's got to be some sort of overzealous text handling routine.
You can easily see the problem by building something with let x = '\n'
and comparing the output from esbuild (the --write-esbuild-output
option works great for this) to what gets written into plv8ify-dist. I've been able to work around the issue by just copying and pasting the headers and footers from plv8ify-dist to the top and bottom of the output.js file and renaming it.
Perhaps that's the easiest implementation here? Write the esbuild output to a temp file and then use the lowest level file io stuff to write the header, read/write the output.js, and write the footer?
Thanks for the detailed write-up.
Perhaps that's the easiest implementation here? Write the esbuild output to a temp file and then use the lowest level file io stuff to write the header, read/write the output.js, and write the footer?
Sounds good to me, feel free to take a stab at it in a PR? If you don't have the time, then I am happy to attempt this over the weekend ๐๐ผ
Released in 0.0.26
@divyenduz fix looks great, thanks for beating me to it. template literal expansion is sneaky!