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

Component Not Defined not working for buildin javascript objects #4070

Closed
bwbroersma opened this issue Dec 8, 2019 · 5 comments · Fixed by #4071
Closed

Component Not Defined not working for buildin javascript objects #4070

bwbroersma opened this issue Dec 8, 2019 · 5 comments · Fixed by #4071

Comments

@bwbroersma
Copy link
Contributor

Describe the bug

<String />

Compiles and results in a runtime error of string.$$ is undefined: REPL.

Math, Map, Set, RexExp, etc. (resulting in other errors)

Instead of <Random /> which would result in 'Random' is not defined. Consider adding a <script> block with 'export let Random' to declare a prop (1:0)

Expected behavior
Check if String is a defined Svelte Component instead of defined in javascript.

@Conduitry
Copy link
Member

String is one of the known globals that we don't warn about not being declared, so I guess this is a proposal to not consider those when encountering names used for components. I'm not sure how much trouble that'd be. We currently don't really distinguish between different ways that variables are used.

@bwbroersma
Copy link
Contributor Author

@Conduitry I guess it's just adding a node.type check in Component.ts:

if (globals.has(name) && node.type != 'InlineComponent') return;

@anlexN
Copy link

anlexN commented Dec 9, 2019

@bwbroersma do you review svelte source code?

@bwbroersma
Copy link
Contributor Author

@anlexN If you wonder how we found this bug: @neoel and I sat down on a project he started making slate-svelte (a svelte rich text editor). During the debugging of a rewrite step from React to Svelte we noticed something strange (I think I noticed the WTF is going on and he immediately said "haha, it's a bug", we forgot to import String from './String.svelte'). After the reply from Conduitry I searched for the error message and poked around: first making a failing test case, then first tried:

if (globals.has(name) && !template_scope) return;

which fixed my test case, but ❌ failed many others 😉, then wondered if it could be solved with the node parameter, so added a console.log(node), rerun the tests, looked at some output, made the final code change, and all test ✔️ succeeded. This is about my way of problem solving in a large unknown codebase, it only works if there are lot's of tests. Also, please consider my patch with this in mind, I have little knowledge about the Svelte internals.

@Conduitry
Copy link
Member

In 3.16.1 this now produces a warning - https://svelte.dev/repl/1ad764d626f54d60b4b03cef168d6b85?version=3.16.1

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.

3 participants