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

Store variable name containing number throws undefined error #7120

Closed
sangxxh opened this issue Jan 11, 2022 · 3 comments · Fixed by sveltejs/svelte-preprocess#461
Closed

Comments

@sangxxh
Copy link
Contributor

sangxxh commented Jan 11, 2022

Describe the bug

I had some stores that were named web3, web3Auth, etc. When importing and using them, the usage will throw an error that the variable is not defined.

Renaming the variables to something else that doesn't contain a number will solve the issue.

Minor issue but this naming is not a problem with pure JS, so something seems to be going wrong here with Svelte.

Reproduction

Create a file num0.ts with this content:

import { readable } from 'svelte/store';

export const num0 = readable(0);

Create a component with this content:

<script lang="ts">
  import { num0 } from "./stores/num0";

  $num0; // <- observe error here
</script>

Logs

index.mjs:2023 Uncaught ReferenceError: num0 is not defined
    at instance (index.mjs:2023:1)
    at init (index.mjs:1809:11)
    at new App (index.mjs:2023:1)
    at main.ts:3:13
    at main.ts:8:2
instance @ index.mjs:2023
init @ index.mjs:1809
App @ index.mjs:2023
(anonymous) @ main.ts:3
(anonymous) @ main.ts:8

System Info

System:
    OS: Linux 5.4 Ubuntu 20.04.3 LTS (Focal Fossa)
    CPU: (8) x64 Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz
    Memory: 7.59 GB / 11.63 GB
    Container: Yes
    Shell: 5.0.17 - /bin/bash
  Binaries:
    Node: 14.16.0 - ~/.nvm/versions/node/v14.16.0/bin/node
    Yarn: 1.22.17 - ~/.nvm/versions/node/v14.16.0/bin/yarn
    npm: 6.14.11 - ~/.nvm/versions/node/v14.16.0/bin/npm
  npmPackages:
    rollup: ^2.3.4 => 2.63.0
    svelte: ^3.0.0 => 3.45.0

Severity

annoyance

@Prinzhorn
Copy link
Contributor

Minor issue but this naming is not a problem with pure JS

You are using TS after all 😄 . What's the TS output? Does it repro with JS? This might not be an issue with Svelte directly but with your TS setup.

@dummdidumm
Copy link
Member

If it's not reproducible without TS then it might be a svelte-preprocess issue

@tanhauhau
Copy link
Member

tanhauhau commented Jan 12, 2022

only replicable when adding lang="ts" so it's svelte-preprocess issue

dummdidumm pushed a commit to sveltejs/svelte-preprocess that referenced this issue Jan 12, 2022
Fixes sveltejs/svelte#7120

the original regex had +-=, which forgot to escape -, resulting ignoring any characters between + to =
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants