invalid-rest-eachblock-binding

pull/10714/head
Simon Holthausen 3 years ago
parent 2faae5914b
commit 0f774533bd

@ -298,13 +298,24 @@ const validation = {
// TODO handle mutations of non-state/props in runes mode
}
const binding = context.state.scope.get(left.name);
if (node.name === 'group') {
const binding = context.state.scope.get(left.name);
if (!binding) {
error(node, 'INTERNAL', 'Cannot find declaration for bind:group');
}
}
if (binding?.kind === 'each' && binding.metadata?.inside_rest) {
warn(
context.state.analysis.warnings,
binding.node,
context.path,
'invalid-rest-eachblock-binding',
binding.node.name
);
}
const parent = context.path.at(-1);
if (

@ -112,7 +112,8 @@ export class Scope {
prop_alias: null,
expression: null,
mutation: null,
reassigned: false
reassigned: false,
metadata: null
};
this.declarations.set(node.name, binding);
this.root.conflicts.add(node.name);
@ -534,7 +535,25 @@ export function create_scopes(ast, root, allow_reactive_declarations, parent) {
// declarations
for (const id of extract_identifiers(node.context)) {
scope.declare(id, 'each', 'const');
const binding = scope.declare(id, 'each', 'const');
let inside_rest = false;
let is_rest_id = false;
walk(node.context, null, {
Identifier(node) {
if (inside_rest && node === id) {
is_rest_id = true;
}
},
RestElement(_, { next }) {
const prev = inside_rest;
inside_rest = true;
next();
inside_rest = prev;
}
});
binding.metadata = { inside_rest: is_rest_id };
}
if (node.context.type !== 'Identifier') {
scope.declare(b.id('$$item'), 'derived', 'synthetic');

@ -288,6 +288,11 @@ export interface Binding {
expression: Expression | ((id: Identifier) => Expression) | null;
/** If this is set, all mutations should use this expression */
mutation: ((assignment: AssignmentExpression, context: Context<any, any>) => Expression) | null;
/** Additional metadata, varies per binding type */
metadata: {
/** `true` if is (inside) a rest parameter */
inside_rest?: boolean;
} | null;
}
export * from './template.js';

@ -197,7 +197,10 @@ const a11y = {
/** @satisfies {Warnings} */
const state = {
'static-state-reference': () =>
`State referenced in its own scope will never update. Did you mean to reference it inside a closure?`
`State referenced in its own scope will never update. Did you mean to reference it inside a closure?`,
/** @param {string} name */
'invalid-rest-eachblock-binding': (name) =>
`The rest operator (...) will create a new object and binding '${name}' with the original object will not work`
};
/** @satisfies {Warnings} */

@ -1,4 +0,0 @@
import { test } from '../../test';
// TODO this likely works in the new world - remove this warning?
export default test({ skip: true });

@ -1,4 +0,0 @@
import { test } from '../../test';
// TODO this likely works in the new world - remove this warning?
export default test({ skip: true });

@ -1,4 +0,0 @@
import { test } from '../../test';
// TODO this maybe works in the new world - remove this warning?
export default test({ skip: true });

@ -1,4 +0,0 @@
import { test } from '../../test';
// TODO this likely works in the new world - remove this warning?
export default test({ skip: true });
Loading…
Cancel
Save