Svelte generates code referencing undefined variables like div_nodes
See original GitHub issueHi. I’m trying to use ESLint on the final IIFE .js
that Svelte generates, in order to get the no-undef
lint (usage of undefined variable).
.eslintrc.js
module.exports = {
parserOptions: {
ecmaVersion: 2019,
sourceType: 'module',
},
env: {
es6: true,
browser: true,
node: true,
},
plugins: [
'svelte3',
'@typescript-eslint/eslint-plugin'
],
overrides: [
{
files: ['**/*.svelte'],
processor: 'svelte3/svelte3',
extends: "eslint:recommended",
},
{
files: ['**/*.js'],
rules: {
"no-undef": "warn",
},
},
],
}
This gives me:
/path/to/bundle.js
1668:43 warning 'form_nodes' is not defined no-undef
Offending code in bundle.js
:
l: function claim(nodes) {
if (default_slot) { default_slot.l(form_nodes); }
throw new Error("options.hydrate only works if the component was compiled with the `hydratable: true` option");
},
Form.svelte
is just <form><slot /></form>
(I simplified it for the purpose of this report). If I add content to the default slot, or other HTML tags (children) to <form>
, the issue is still there. Searching for form_nodes
and _nodes
in bundle.js
gives me no results aside of the function above. If I change Form.svelte
content to <div><slot /></form>
, I get warning about undefined div_nodes
.
Are <...>_nodes
in the code above intended to be undefined
? How can I set them? Or what else can I do to get the results I want (getting “… is not defined” errors at compile time, not runtime)?
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (6 by maintainers)
Current shot at this:
Seems to address this particular issue, and doesn’t break any tests.
still causes three js sample tests to fail (producing unexpected claim methods in blocks), and I’m not sure why. (Maybe something about
claim
being empty vshydrate
being empty?) You can keep poking at this if you’d like, but I don’t think I’m going to.