Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade from 4.8.0 - 4.9.0: unterminated string literal error during svelte-check, build fails #402

Closed
mlandisbqs opened this issue Sep 7, 2021 · 8 comments · Fixed by #403
Labels
bug Something isn't working

Comments

@mlandisbqs
Copy link

Describe the bug
Isolated to 4.9.0 code changes (4.8.0 compiles the same code without the bug):
https://github.com/sveltejs/svelte-preprocess/compare/v4.8.0...v4.9.0?short_path=61c21cb#diff-96443e2ca98f566a13837889beb8b5a9da9d97c396ad64bc3a28dbf0e3557f37

After the upgrade -- the generated code contains unterminated string literal which typescript then fails to compile.
This happens right here in the code (line 140, src/transformers/typescript.ts):

image

^-- the codestores array includes an entry like this ["'"]

Logs

rc/components/script-response/input-type/single-input-type.svelte.injected.ts:74:224 - error TS1002: Unterminated string literal.

74 const $$vars$$ = [sessionStore,sessionStore,',promptResponse,prompt,$sessionStore,sessionStore,prompt,promptResponse,BqpTextField,label,type,error,optional,unit,textarea,inputAttrs,prompt,value,persistChange,persistChange];
                                                                                                                                                                                                                                  

src/components/script-response/input-type/range-input-type.svelte.injected.ts:89:209 - error TS1002: Unterminated string literal.

89 const $$vars$$ = [',promptResponses,BqpGroup,highlight,$sessionStore,sessionStore,prompt,BqpTextField,type,unit,fromValue,persistChange,BqpTextField,type,unit,fromValue,toValue,isValid,toValue,persistChange];
                                                                                                                                                                                                                   

Expected behavior
codestores should be captured without a single quote value in the array.

Information about your project:

  • Your browser and the version: (e.x. Chrome 52.1, Firefox 48.0, IE 10)

  • Your operating system: (e.x. OS X 10, Ubuntu Linux 19.10, Windows XP, etc)
    MacOs 10.15.4

  • svelte-preprocess version (Please check you can reproduce the issue with the latest release!)
    4.9.0 (same problem on latest release)

  • Whether your project uses Webpack or Rollup
    rollup

@mlandisbqs
Copy link
Author

This looks like it could be related to #401

@kaisermann
Copy link
Member

Hey, @mlandisbqs 👋 Thanks for the report! Can you share your file content or at least all identifiers beginning with $?

@kaisermann kaisermann added the bug Something isn't working label Sep 8, 2021
@mlandisbqs
Copy link
Author

ok - I actually think I see the issue... both of the files that have problems have a string literal with a dollar sign...

image

...I haven't tested removing it yet, but that must be the issue. I'm not sure that I can share the whole component file.

@kaisermann
Copy link
Member

That's more than enough and is probably the culprit. This helps a lot, thanks!

@seanlail
Copy link

seanlail commented Sep 8, 2021

@kaisermann I'm sure you have enough info, but just in case:

I just ran into the same thing with this code:

<script lang="ts">
  export let code = "gbp";

  const symbols: Record<string, string> = { eur: "€", gbp: "£", usd: "$" };

  $: symbol =
    !!code && symbols[code.toLowerCase()] ? symbols[code.toLowerCase()] : "";
</script>

{symbol}
src/components/CurrencySymbol.svelte.injected.ts:11:29 - error TS1002: Unterminated string literal.
11 const $$vars$$ = [",symbol];

and can confirm that removing usd: "$" works

@seanlail
Copy link

seanlail commented Sep 8, 2021

This breaks in 4.8.0 for me. Only 4.7.4 and older worked.

@dummdidumm
Copy link
Member

Found the culprit, will prepare a PR shortly

dummdidumm pushed a commit to dummdidumm/svelte-preprocess that referenced this issue Sep 8, 2021
kaisermann pushed a commit that referenced this issue Sep 8, 2021
Fixes #402

Co-authored-by: Simon Holthausen <simon.holthausen@accso.de>
@kaisermann
Copy link
Member

Fix released in v4.9.4 🎉 . Thanks @dummdidumm!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants