Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/preprocess.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,17 @@ export const preprocess = text => {
}
const { ast, warnings, vars, mapper } = result;

const global_style = result.ast?.css?.attributes.some(attr => attr.name === 'global');

const references_and_reassignments = `{${vars.filter(v => v.referenced || v.name[0] === '$').map(v => v.name)};${vars.filter(v => v.reassigned || v.export_name).map(v => v.name + '=0')}}`;
state.var_names = new Set(vars.map(v => v.name));

// convert warnings to linting messages
const filtered_warnings = processor_options.ignore_warnings ? warnings.filter(warning => !processor_options.ignore_warnings(warning)) : warnings;
state.messages = filtered_warnings.map(({ code, message, start, end }) => {
state.messages = filtered_warnings.filter(warning => {
// ignore "css-unused-selector" warnings if `<style global>`
return !(global_style && warning.code === 'css-unused-selector');
}).map(({ code, message, start, end }) => {
const start_pos = processor_options.typescript && start ?
mapper.get_original_position(start) :
start && { line: start.line, column: start.column + 1 };
Expand Down
3 changes: 3 additions & 0 deletions test/samples/global-style/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
rules: {},
};
5 changes: 5 additions & 0 deletions test/samples/global-style/Input.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<style global>
h1 {
color: red;
}
</style>
1 change: 1 addition & 0 deletions test/samples/global-style/expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]