Repository: sveltejs/svelte (JavaScript) — Bug Fix

Issue:
Component Not Defined not working for buildin javascript objects
**Describe the bug**
```
<String />
```
Compiles and results in a runtime error of `string.$$ is undefined`: [REPL](https://svelte.dev/repl/1ad764d626f54d60b4b03cef168d6b85).

`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.


Component Not Defined not working for buildin javascript objects
**Describe the bug**
```
<String />
```
Compiles and results in a runtime error of `string.$$ is undefined`: [REPL](https://svelte.dev/repl/1ad764d626f54d60b4b03cef168d6b85).

`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.




Discussion:
`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.
`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.

Resolving patch:
diff --git a/src/compiler/compile/Component.ts b/src/compiler/compile/Component.ts
--- a/src/compiler/compile/Component.ts
+++ b/src/compiler/compile/Component.ts
@@ -1289,7 +1289,7 @@ export default class Component {
 
 		if (this.var_lookup.has(name) && !this.var_lookup.get(name).global) return;
 		if (template_scope && template_scope.names.has(name)) return;
-		if (globals.has(name)) return;
+		if (globals.has(name) && node.type !== 'InlineComponent') return;
 
 		let message = `'${name}' is not defined`;
 		if (!this.ast.instance)


Test patch:
diff --git a/test/validator/samples/missing-component-global/input.svelte b/test/validator/samples/missing-component-global/input.svelte
new file mode 100644
--- /dev/null
+++ b/test/validator/samples/missing-component-global/input.svelte
@@ -0,0 +1,3 @@
+<div>
+	<String/>
+</div>
\ No newline at end of file
diff --git a/test/validator/samples/missing-component-global/warnings.json b/test/validator/samples/missing-component-global/warnings.json
new file mode 100644
--- /dev/null
+++ b/test/validator/samples/missing-component-global/warnings.json
@@ -0,0 +1,15 @@
+[{
+	"code": "missing-declaration",
+	"message": "'String' is not defined. Consider adding a <script> block with 'export let String' to declare a prop",
+	"start": {
+		"line": 2,
+		"column": 1,
+		"character": 7
+	},
+	"end": {
+		"line": 2,
+		"column": 10,
+		"character": 16
+	},
+	"pos": 7
+}]
\ No newline at end of file