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

Unclear error message comes if const is already declared in <script> section #7221

Closed
baseballyama opened this issue Feb 4, 2022 · 1 comment · Fixed by #7222
Closed
Labels
bug compiler Changes relating to the compiler

Comments

@baseballyama
Copy link
Member

Describe the bug

If I declare const or function inside {@const} tag and it is already declared in <script> section, an error occurs in the rollup.

The compiler needs to check duplication or rename it automatically.
(I think it would be better to check for duplicates and give the appropriate error message to avoid confusion.)

Reproduction

https://svelte.dev/repl/10aee9db38db4ec5b5c4a3fac24045ae?version=3.46.4

Logs

rollup v2.60.0
bundles src/main.js → public/build/bundle.js...
[!] Error: Unexpected token (Note that you need plugins to import files that are not JavaScript)
src/App.svelte (9:19)
 7:   <p>{dummy_const(item)}</p>
 8:   {@const bar = array.map((item) => {
 9:     const dummy_const = (item) => item * 2;
                         ^
10:     return dummy_const(item);
11:   })}
Error: Unexpected token (Note that you need plugins to import files that are not JavaScript)
    at error (/Users/baseballyama/Desktop/git/svelte-contributes/svelte-general/my-app/node_modules/rollup/dist/shared/rollup.js:158:30)
    at Module.error (/Users/baseballyama/Desktop/git/svelte-contributes/svelte-general/my-app/node_modules/rollup/dist/shared/rollup.js:12382:16)
    at Module.tryParse (/Users/baseballyama/Desktop/git/svelte-contributes/svelte-general/my-app/node_modules/rollup/dist/shared/rollup.js:12785:25)
    at Module.setSource (/Users/baseballyama/Desktop/git/svelte-contributes/svelte-general/my-app/node_modules/rollup/dist/shared/rollup.js:12688:24)
    at ModuleLoader.addModuleSource (/Users/baseballyama/Desktop/git/svelte-contributes/svelte-general/my-app/node_modules/rollup/dist/shared/rollup.js:22152:20)

System Info

System:
    OS: macOS 12.1
    CPU: (10) arm64 Apple M1 Pro
    Memory: 324.19 MB / 32.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 17.0.1 - /opt/homebrew/bin/node
    npm: 8.3.0 - /opt/homebrew/bin/npm
  Browsers:
    Chrome: 98.0.4758.80
    Firefox: 96.0.3
    Safari: 15.2
  npmPackages:
    rollup: ^2.3.4 => 2.60.0 
    svelte: ^3.0.0 => 3.46.3

Severity

annoyance

@dummdidumm dummdidumm added bug compiler Changes relating to the compiler labels Feb 4, 2022
@dummdidumm
Copy link
Member

I think the code should compile in the given form, as it's OK to redeclare a variable in a new context.

const foo = '';
() => {
  const foo = 1; // valid
}

@tanhauhau tanhauhau linked a pull request Apr 8, 2022 that will close this issue
5 tasks
dummdidumm pushed a commit that referenced this issue Apr 8, 2022
Fixes #7423
Fixes #7431
Fixes #7206
Fixes #7431
Fixes #7221

Co-authored-by: tanhauhau <lhtan93@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug compiler Changes relating to the compiler
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants