warn only for imported variable

pull/5302/head
Tan Li Hau 5 years ago
parent 1f44aa5787
commit 93420d8ab0

@ -628,11 +628,13 @@ export default class Component {
} }
const writable = node.type === 'VariableDeclaration' && (node.kind === 'var' || node.kind === 'let'); const writable = node.type === 'VariableDeclaration' && (node.kind === 'var' || node.kind === 'let');
const imported = node.type.startsWith('Import');
this.add_var({ this.add_var({
name, name,
initialised: instance_scope.initialised_declarations.has(name), initialised: instance_scope.initialised_declarations.has(name),
writable writable,
imported
}); });
this.node_for_declaration.set(name, node); this.node_for_declaration.set(name, node);

@ -239,10 +239,10 @@ export default class Element extends Node {
} }
validate() { validate() {
if (this.component.var_lookup.has(this.name) || this.scope.names.has(this.name)) { if (this.component.var_lookup.has(this.name) && this.component.var_lookup.get(this.name).imported) {
this.component.warn(this, { this.component.warn(this, {
code: 'lowercase-component-name', code: 'lowercase-component-name',
message: `A lowercase tag <${this.name}> will be treated as a regular HTML element`, message: `A lowercase tag <${this.name}> will be treated as a regular HTML element`
}); });
} }

@ -161,6 +161,7 @@ export interface Var {
hoistable?: boolean; hoistable?: boolean;
subscribable?: boolean; subscribable?: boolean;
is_reactive_dependency?: boolean; is_reactive_dependency?: boolean;
imported?: boolean;
} }
export interface CssResult { export interface CssResult {

@ -1,6 +0,0 @@
<script>
let array;
</script>
{#each array as item}
<item />
{/each}

@ -1,17 +0,0 @@
[
{
"code": "lowercase-component-name",
"end": {
"character": 64,
"column": 10,
"line": 5
},
"message": "A lowercase tag <item> will be treated as a regular HTML element",
"pos": 56,
"start": {
"character": 56,
"column": 2,
"line": 5
}
}
]

@ -1,5 +1,7 @@
<script> <script>
import thisShouldWarnMe from './MyComponent.svelte'; import thisShouldWarnMe from './MyComponent.svelte';
let i;
</script> </script>
<thisShouldWarnMe /> <thisShouldWarnMe />
<i />

@ -2,16 +2,16 @@
{ {
"code": "lowercase-component-name", "code": "lowercase-component-name",
"message": "A lowercase tag <thisShouldWarnMe> will be treated as a regular HTML element", "message": "A lowercase tag <thisShouldWarnMe> will be treated as a regular HTML element",
"pos": 75, "pos": 84,
"end": {
"character": 95,
"column": 20,
"line": 5
},
"start": { "start": {
"character": 75, "character": 84,
"column": 0, "column": 0,
"line": 5 "line": 6
},
"end": {
"character": 104,
"column": 20,
"line": 6
} }
} }
] ]

Loading…
Cancel
Save