Svelte: Allow regular script tags

Created on 5 Mar 2017  Â·  3Comments  Â·  Source: sveltejs/svelte

Would be great to have a way to include a regular script tag (not component definition).
REPL

Some considerations off the top of my head:

  • Maybe only interpret top-level script tags as Svelte code
  • Can svelte code even have an src attribute?

Also, I encountered the issue when using Svelte as a primary server-side renderer:

<html>
  <body>
    <div id="mount"></div>
    <script src="/app.js"></script>
  </body>
</html>

Does component code even make sense when using SSR?

Most helpful comment

I think that approach is good, it's how it behaves in Ractive and it seems to work okay. Was occasionally a source of confusion if you left a preceding element open (since the component script becomes a regular script) but since the parser is now quite strict about that sort of thing it shouldn't be an issue.

Does component code even make sense when using SSR?

Definitely – without it you can't do this sort of thing:

<body>
  <main><App/></main>
  <script src='bundle.js'></script>
</body>

All 3 comments

Initial idea - replacing the test here with name in specials && parser.stack.length === 1. I believe this would make <script> and <style> elements only be treated specially if they are on the top level. I don't know whether such a sweeping change is the right way to approach this.

I think that approach is good, it's how it behaves in Ractive and it seems to work okay. Was occasionally a source of confusion if you left a preceding element open (since the component script becomes a regular script) but since the parser is now quite strict about that sort of thing it shouldn't be an issue.

Does component code even make sense when using SSR?

Definitely – without it you can't do this sort of thing:

<body>
  <main><App/></main>
  <script src='bundle.js'></script>
</body>
Was this page helpful?
0 / 5 - 0 ratings

Related issues

mmjmanders picture mmjmanders  Â·  3Comments

angelozehr picture angelozehr  Â·  3Comments

ricardobeat picture ricardobeat  Â·  3Comments

Rich-Harris picture Rich-Harris  Â·  3Comments

juniorsd picture juniorsd  Â·  3Comments