svelte: Not implemented undefined (List of Nodes in handle)
Describe the bug
Using svelte 3.42.4, building my project using snowpack fails with the following error:
[08:01:56] [snowpack] ! building files...
[08:02:01] [snowpack] Build Result Error: There was a problem with a file build result.
[08:02:01] [snowpack] Not implemented undefined
[08:02:01] [snowpack] Error: Not implemented undefined
at handle (/Users/cpennington/personal/dicedornot/node_modules/svelte/compiler.js:6178:10)
at /Users/cpennington/personal/dicedornot/node_modules/svelte/compiler.js:6414:19
at Array.map (<anonymous>)
at handle_body (/Users/cpennington/personal/dicedornot/node_modules/svelte/compiler.js:6413:22)
at /Users/cpennington/personal/dicedornot/node_modules/svelte/compiler.js:6495:8
at scoped_fn (/Users/cpennington/personal/dicedornot/node_modules/svelte/compiler.js:6382:11)
at handle (/Users/cpennington/personal/dicedornot/node_modules/svelte/compiler.js:6181:18)
at IfStatement (/Users/cpennington/personal/dicedornot/node_modules/svelte/compiler.js:6532:8)
at handle (/Users/cpennington/personal/dicedornot/node_modules/svelte/compiler.js:6181:18)
at /Users/cpennington/personal/dicedornot/node_modules/svelte/compiler.js:6414:19
The error is happening in this function in compiler.js
/**
* @param {Node} node
* @param {State} state
* @returns {Chunk[]}
*/
function handle(node, state) {
const handler = handlers[node.type];
if (!handler) {
throw new Error(`Not implemented ${node.type}`);
}
const result = handler(node, state);
if (node.leadingComments) {
result.unshift(c(node.leadingComments.map(comment => comment.type === 'Block'
? `/*${comment.value}*/${/** @type {any} */ (comment).has_trailing_newline ? `\n${state.indent}` : ` `}`
: `//${comment.value}${/** @type {any} */ (comment).has_trailing_newline ? `\n${state.indent}` : ` `}`).join(``)));
}
if (node.trailingComments) {
state.comments.push(node.trailingComments[0]); // there is only ever one
}
return result;
}
Some debugging suggests that node being passed into this function is in fact a list of nodes, instead.
The same build completes with svelte 3.35.0.
Reproduction
Check out https://github.com/cpennington/dicedornot/tree/package-upgrade
Run
npm install
npm build
Logs
No response
System Info
npx: installed 1 in 1.857s
System:
OS: macOS 11.4
CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
Memory: 399.40 MB / 16.00 GB
Shell: 3.2.1 - /usr/local/bin/fish
Binaries:
Node: 14.17.3 - ~/.nvm/versions/node/v14.17.3/bin/node
Yarn: 1.22.10 - /usr/local/bin/yarn
npm: 6.14.13 - ~/.nvm/versions/node/v14.17.3/bin/npm
Browsers:
Chrome: 93.0.4577.63
Firefox: 91.0
Safari: 14.1.1
npmPackages:
snowpack: ^3.8.8 => 3.8.8
svelte: ^3.42.4 => 3.42.4
Severity
blocking an upgrade
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 15 (6 by maintainers)
Commits related to this issue
- Fix dapp dependencies Code fix as the update introduce this issue: https://github.com/sveltejs/svelte/issues/6706 — committed to spruceid/tzprofiles by sbihel 4 years ago
- web ui: fix svelte error by changing var to let https://github.com/sveltejs/svelte/issues/6706 — committed to itsdsk/ledpage by itsdsk 3 years ago
Update- I just solved my issue. It may work for you.
Clued in by the code-red part that handled For loops, I’ve verified that the following code causes this error
whereas the following solves the problem.
The latter seems to be the appropriate form but ideally the for (var … ) case would be handled informatively by code-red.
This seems to be caused by this invalid cast from
Node[]->Nodein Component.ts.estree-walkerdoesn’t provide a way to replace a single node with multiple as far as I can see.Adding I had this today but by using
varin an if code blockCan the error be made more helpful?
Thanks. I haven’t narrowed that down to a minimal TypeScript-free repro for 3.38.3 yet, but one thing that is a problem in the latest version of Svelte is that there’s a
varinside a reactive block:I’m actually not sure what this should do.
vars aren’t block scoped, and so this could lead to some fairly confusing behavior. Version 3.40.3 is the latest version that will compile the above component, but if you try to accessnowoutside of the reactive block (which JS scope rules say you should be able to do), you get a runtime error, because in the compiled code the contents of the reactive block end up inside a function (which does prevent thevarscope from leaking out). I’m going to open a separate issue for this case. I think the compiler should explicitly disallowvarinside a reactive block with a more helpful error message.