diff --git a/src/preprocess.js b/src/preprocess.js index 1fb19c4..f8b48ad 100644 --- a/src/preprocess.js +++ b/src/preprocess.js @@ -63,7 +63,7 @@ export const preprocess = text => { } const { ast, warnings, vars, mapper } = result; - const references_and_reassignments = `{${vars.filter(v => v.referenced).map(v => v.name)};${vars.filter(v => v.reassigned || v.export_name).map(v => v.name + '=0')}}`; + 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 @@ -184,7 +184,7 @@ export const preprocess = text => { }, }); - block.transformed_code += `{${vars.filter(v => v.referenced_from_script).map(v => v.name)}}`; + block.transformed_code += `{${vars.filter(v => v.referenced_from_script || v.name[0] === '$').map(v => v.name)}}`; } // return processed string diff --git a/test/samples/unused-write-only-store/.eslintrc.js b/test/samples/unused-write-only-store/.eslintrc.js new file mode 100644 index 0000000..0930ca2 --- /dev/null +++ b/test/samples/unused-write-only-store/.eslintrc.js @@ -0,0 +1,5 @@ +module.exports = { + rules: { + "no-unused-vars": "error", + }, +}; diff --git a/test/samples/unused-write-only-store/Input.svelte b/test/samples/unused-write-only-store/Input.svelte new file mode 100644 index 0000000..667a5f6 --- /dev/null +++ b/test/samples/unused-write-only-store/Input.svelte @@ -0,0 +1,12 @@ + +
$imported = 'clicked' }/> diff --git a/test/samples/unused-write-only-store/expected.json b/test/samples/unused-write-only-store/expected.json new file mode 100644 index 0000000..fe51488 --- /dev/null +++ b/test/samples/unused-write-only-store/expected.json @@ -0,0 +1 @@ +[]