-
-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[fix] be able to silence more warnings (#6504)
including css-unused-selector, unused-export-let, module-script-reactive-declaration Fixes #5954 Related to #5281
- Loading branch information
1 parent
52b67a0
commit a8c35da
Showing
16 changed files
with
131 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { TemplateNode } from '../interfaces'; | ||
import { flatten } from './flatten'; | ||
|
||
const pattern = /^\s*svelte-ignore\s+([\s\S]+)\s*$/m; | ||
|
||
export function extract_svelte_ignore(text: string): string[] { | ||
const match = pattern.exec(text); | ||
return match ? match[1].split(/[^\S]/).map(x => x.trim()).filter(Boolean) : []; | ||
} | ||
|
||
export function extract_svelte_ignore_from_comments<Node extends { leadingComments?: Array<{value: string}> }>(node: Node): string[] { | ||
return flatten((node.leadingComments || []).map(comment => extract_svelte_ignore(comment.value))); | ||
} | ||
|
||
export function extract_ignores_above_position(position: number, template_nodes: TemplateNode[]): string[] { | ||
const previous_node_idx = template_nodes.findIndex(child => child.end === position); | ||
if (previous_node_idx === -1) { | ||
return []; | ||
} | ||
|
||
for (let i = previous_node_idx; i >= 0; i--) { | ||
const node = template_nodes[i]; | ||
if (node.type !== 'Comment' && node.type !== 'Text') { | ||
return []; | ||
} | ||
if (node.type === 'Comment') { | ||
if (node.ignores.length) { | ||
return node.ignores; | ||
} | ||
} | ||
} | ||
|
||
return []; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
export function flatten<T>(nodes: T[][], target?: T[]): T[]; | ||
export function flatten<T>(nodes: T[], target?: T[]): T[]; | ||
export function flatten(nodes: any[], target: any[] = []): any[] { | ||
for (let i = 0; i < nodes.length; i += 1) { | ||
const node = nodes[i]; | ||
if (Array.isArray(node)) { | ||
flatten(node, target); | ||
} else { | ||
target.push(node); | ||
} | ||
} | ||
|
||
return target; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<!-- svelte-ignore foo bar --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"html": { | ||
"start": 0, | ||
"end": 30, | ||
"type": "Fragment", | ||
"children": [ | ||
{ | ||
"start": 0, | ||
"end": 30, | ||
"type": "Comment", | ||
"data": " svelte-ignore foo bar ", | ||
"ignores": ["foo", "bar"] | ||
} | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<script context="module"> | ||
let foo; | ||
</script> | ||
|
||
<!-- svelte-ignore unused-export-let module-script-reactive-declaration --> | ||
<script> | ||
export let unused; | ||
$: reactive = foo; | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<script context="module"> | ||
let foo; | ||
</script> | ||
|
||
<script> | ||
// svelte-ignore unused-export-let | ||
export let unused; | ||
// svelte-ignore module-script-reactive-declaration | ||
$: reactive = foo; | ||
</script> | ||
|
||
<!-- svelte-ignore css-unused-selector --> | ||
<style> | ||
.unused {} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[] |