Scripts should be embedded in <svg> with <script href> or <script xlink:href> rather than <script src>, but Parcel doesnāt find scripts with that syntax.
There are also other tags on which it fails to follow xlink:href, like <a>.
$ tail -n +1 *
==> index.html <==
<!DOCTYPE html>
<svg xmlns:xlink="http://www.w3.org/1999/xlink">
<script xlink:href="script.js"></script>
</svg>
==> script.js <==
alert(1);
$ parcel build index.html
⨠Built in 327ms.
dist/index.html 101 B 266ms
$ ls dist
index.html script.d1ea37cd.js script.d1ea37cd.js.map
$ ls dist
index.html
Maybe Parcel should follow all href and xlink:href attributes regardless of tag? But if you want a list of applicable tags, MDN has one for href and xlink:href.
I wanted to embed TypeScript in a standalone SVG file, which didnāt work because Parcel doesnāt scan standalone SVGs for dependencies at all (#3571), but experimentation with inline SVG revealed this additional bug.
See above.
| Software | Version(s) |
| ---------------- | ---------- |
| Parcel | 1.12.3
| Node | 12.10.0
| npm/Yarn | 1.17.3
| Operating System | Ubuntu 19.10
Is it canonical behavior for SVG though, to allow embedded scripts?
I mean, nothing technically stops it from working, but SVG isn't exclusively a browser technology and maybe not treating it like any other HTML is actually more anticipated behavior.
The same original argument could be made about XML files as well, but it would be totally weird to treat XML files as HTML files.
@kirillrogovoy Yes. Did you see the link at the top of my report to the MDN page for the SVG <script> element? It references the relevant specification. It shows that thereās wide browser support. You can try my test case for yourself to see that it works before being processed by Parcel.
I donāt understand why the existence of some SVG user agents that donāt support <script> constitutes an argument that Parcel should break <script> for people who choose to use it on browsers where it does workā¦
Furthermore, this particular bug is about code inlined into an HTML file, which _is_ a browser technology, even though I donāt see the relevance of that argument.
I would like to see Parcel support for SVG files, but thatās a separate bug. As for XML filesāwhy not? It seems reasonable to treat them as XHTML or SVG if thereās xmlns marking them as such. (Itās XML, thereās no need to blindly guess.) I donāt personally have a use case for XML files, so Iāll leave that as a bug for someone else to file.
Fair enough!
I'm curious to see what the maintainers think, but the case for inlined SVG makes total sense to me.
@DeMoorJasper I didn't find that information in CONTRIBUTING.md, so asking here: what's the current policy for fixing bugs in v1/v2. Should I forgo the v1 and go straight to v2, or should I fix both?
@kirillrogovoy we aren't really releasing any more updates for v1 so probably best to just fix this for v2
I didn't suggest the support for xlink:href though, because that very doc you linked marks it as deprecated in SVG 2
SVG 2 is a candidate recommendation; SVG 1.1 is still much more common and only supports xlink:href. Do you really think Parcel should require its users to upgrade to candidate technologies? Is there any harm in leaving that decision to the user?
Fixed by #3608.