pull/11327/head
Rich Harris 2 years ago
parent 40d29df182
commit 0d8effa0d6

@ -1,87 +0,0 @@
## duplicate_props_rune
> Cannot use `$props()` more than once
## invalid_assignment
> Cannot assign to %thing%
## invalid_bindable_location
> `$bindable()` can only be used inside a `$props()` declaration
## invalid_binding
> Cannot bind to %thing%
## invalid_derived_export
> Cannot export derived state from a module. To expose the current derived value, export a function returning its value
## invalid_each_assignment
> Cannot reassign or bind to each block argument in runes mode. Use the array and index variables instead (e.g. `array[i] = value` instead of `entry = value`)
## invalid_effect_location
> `$effect()` can only be used as an expression statement
## invalid_host_location
> `$host()` can only be used inside custom element component instances
## invalid_legacy_export
> Cannot use `export let` in runes mode — use $props instead
## invalid_legacy_props
> Cannot use `$$props` in runes mode
## invalid_legacy_reactive_statement
> `$:` is not allowed in runes mode, use `$derived` or `$effect` instead
## invalid_legacy_rest_props
> Cannot use `$$restProps` in runes mode
## invalid_props_id
> `$props()` can only be used with an object destructuring pattern
## invalid_props_location
> `$props()` can only be used at the top level of components as a variable declaration initializer
## invalid_props_pattern
> `$props()` assignment must not contain nested properties or computed keys
## invalid_rune_args
> `%rune%` cannot be called with arguments
## invalid_rune_args_length
> `%rune%` must be called with %args%
## invalid_rune_usage
> Cannot use %rune% rune in non-runes mode
## invalid_runes_mode_import
> %name% cannot be used in runes mode
## invalid_snippet_assignment
> Cannot reassign or bind to snippet parameter
## invalid_state_export
> Cannot export state from a module if it is reassigned. Either export a function returning the state value or only mutate the state value's properties
## invalid_state_location
> `%rune%(...)` can only be used as a variable declaration initializer or a class field

@ -1,3 +1,15 @@
## bindable_invalid_location
> `$bindable()` can only be used inside a `$props()` declaration
## constant_assignment
> Cannot assign to %thing%
## constant_binding
> Cannot bind to %thing%
## declaration_duplicate
> `%name%` has already been declared
@ -6,6 +18,10 @@
> Cannot declare same variable name which is imported inside `<script context="module">`
## derived_invalid_export
> Cannot export derived state from a module. To expose the current derived value, export a function returning its value
## dollar_binding_invalid
> The $ name is reserved, and cannot be used for variables and imports
@ -14,18 +30,90 @@
> The $ prefix is reserved, and cannot be used for variables and imports
## each_item_invalid_assignment
> Cannot reassign or bind to each block argument in runes mode. Use the array and index variables instead (e.g. `array[i] = value` instead of `entry = value`)
## effect_invalid_placement
> `$effect()` can only be used as an expression statement
## global_reference_invalid
> `%name%` is an illegal variable name. To reference a global variable called `%name%`, use `globalThis.%name%`
## host_invalid_placement
> `$host()` can only be used inside custom element component instances
## legacy_export_invalid
> Cannot use `export let` in runes mode — use $props instead
## legacy_props_invalid
> Cannot use `$$props` in runes mode
## legacy_reactive_statement_invalid
> `$:` is not allowed in runes mode, use `$derived` or `$effect` instead
## legacy_rest_props_invalid
> Cannot use `$$restProps` in runes mode
## module_illegal_default_export
> A component cannot have a default export
## props_duplicate
> Cannot use `$props()` more than once
## props_invalid_identifier
> `$props()` can only be used with an object destructuring pattern
## props_invalid_pattern
> `$props()` assignment must not contain nested properties or computed keys
## props_invalid_placement
> `$props()` can only be used at the top level of components as a variable declaration initializer
## reactive_declaration_cycle
> Cyclical dependency detected: %cycle%
## rune_invalid_arguments
> `%rune%` cannot be called with arguments
## rune_invalid_arguments_length
> `%rune%` must be called with %args%
## rune_invalid_usage
> Cannot use %rune% rune in non-runes mode
## runes_mode_invalid_import
> %name% cannot be used in runes mode
## snippet_parameter_assignment
> Cannot reassign or bind to snippet parameter
## state_invalid_export
> Cannot export state from a module if it is reassigned. Either export a function returning the state value or only mutate the state value's properties
## state_invalid_placement
> `%rune%(...)` can only be used as a variable declaration initializer or a class field
## store_invalid_scoped_subscription
> Cannot subscribe to stores that are not declared at the top level of the component

@ -205,293 +205,293 @@ export function options_unrecognised(node, keypath) {
}
/**
* Cannot use `$props()` more than once
* `%name%` has already been declared
* @param {null | number | NodeLike} node
* @param {string} name
* @returns {never}
*/
export function duplicate_props_rune(node) {
e(node, "duplicate_props_rune", "Cannot use `$props()` more than once");
export function declaration_duplicate(node, name) {
e(node, "declaration_duplicate", `\`${name}\` has already been declared`);
}
/**
* Cannot assign to %thing%
* Cannot declare same variable name which is imported inside `<script context="module">`
* @param {null | number | NodeLike} node
* @param {string} thing
* @returns {never}
*/
export function invalid_assignment(node, thing) {
e(node, "invalid_assignment", `Cannot assign to ${thing}`);
export function declaration_duplicate_module_import(node) {
e(node, "declaration_duplicate_module_import", "Cannot declare same variable name which is imported inside `<script context=\"module\">`");
}
/**
* `$bindable()` can only be used inside a `$props()` declaration
* The $ name is reserved, and cannot be used for variables and imports
* @param {null | number | NodeLike} node
* @returns {never}
*/
export function invalid_bindable_location(node) {
e(node, "invalid_bindable_location", "`$bindable()` can only be used inside a `$props()` declaration");
export function dollar_binding_invalid(node) {
e(node, "dollar_binding_invalid", "The $ name is reserved, and cannot be used for variables and imports");
}
/**
* Cannot bind to %thing%
* The $ prefix is reserved, and cannot be used for variables and imports
* @param {null | number | NodeLike} node
* @param {string} thing
* @returns {never}
*/
export function invalid_binding(node, thing) {
e(node, "invalid_binding", `Cannot bind to ${thing}`);
export function dollar_prefix_invalid(node) {
e(node, "dollar_prefix_invalid", "The $ prefix is reserved, and cannot be used for variables and imports");
}
/**
* Cannot export derived state from a module. To expose the current derived value, export a function returning its value
* `%name%` is an illegal variable name. To reference a global variable called `%name%`, use `globalThis.%name%`
* @param {null | number | NodeLike} node
* @param {string} name
* @returns {never}
*/
export function invalid_derived_export(node) {
e(node, "invalid_derived_export", "Cannot export derived state from a module. To expose the current derived value, export a function returning its value");
export function global_reference_invalid(node, name) {
e(node, "global_reference_invalid", `\`${name}\` is an illegal variable name. To reference a global variable called \`${name}\`, use \`globalThis.${name}\``);
}
/**
* Cannot reassign or bind to each block argument in runes mode. Use the array and index variables instead (e.g. `array[i] = value` instead of `entry = value`)
* A component cannot have a default export
* @param {null | number | NodeLike} node
* @returns {never}
*/
export function invalid_each_assignment(node) {
e(node, "invalid_each_assignment", "Cannot reassign or bind to each block argument in runes mode. Use the array and index variables instead (e.g. `array[i] = value` instead of `entry = value`)");
export function module_illegal_default_export(node) {
e(node, "module_illegal_default_export", "A component cannot have a default export");
}
/**
* `$effect()` can only be used as an expression statement
* Cyclical dependency detected: %cycle%
* @param {null | number | NodeLike} node
* @param {string} cycle
* @returns {never}
*/
export function invalid_effect_location(node) {
e(node, "invalid_effect_location", "`$effect()` can only be used as an expression statement");
export function reactive_declaration_cycle(node, cycle) {
e(node, "reactive_declaration_cycle", `Cyclical dependency detected: ${cycle}`);
}
/**
* `$host()` can only be used inside custom element component instances
* Cannot subscribe to stores that are not declared at the top level of the component
* @param {null | number | NodeLike} node
* @returns {never}
*/
export function invalid_host_location(node) {
e(node, "invalid_host_location", "`$host()` can only be used inside custom element component instances");
export function store_invalid_scoped_subscription(node) {
e(node, "store_invalid_scoped_subscription", "Cannot subscribe to stores that are not declared at the top level of the component");
}
/**
* Cannot use `export let` in runes mode use $props instead
* Cannot reference store value inside `<script context="module">`
* @param {null | number | NodeLike} node
* @returns {never}
*/
export function invalid_legacy_export(node) {
e(node, "invalid_legacy_export", "Cannot use `export let` in runes mode — use $props instead");
export function store_invalid_subscription(node) {
e(node, "store_invalid_subscription", "Cannot reference store value inside `<script context=\"module\">`");
}
/**
* Cannot use `$$props` in runes mode
* `$bindable()` can only be used inside a `$props()` declaration
* @param {null | number | NodeLike} node
* @returns {never}
*/
export function invalid_legacy_props(node) {
e(node, "invalid_legacy_props", "Cannot use `$$props` in runes mode");
export function bindable_invalid_location(node) {
e(node, "bindable_invalid_location", "`$bindable()` can only be used inside a `$props()` declaration");
}
/**
* `$:` is not allowed in runes mode, use `$derived` or `$effect` instead
* Cannot assign to %thing%
* @param {null | number | NodeLike} node
* @param {string} thing
* @returns {never}
*/
export function invalid_legacy_reactive_statement(node) {
e(node, "invalid_legacy_reactive_statement", "`$:` is not allowed in runes mode, use `$derived` or `$effect` instead");
export function constant_assignment(node, thing) {
e(node, "constant_assignment", `Cannot assign to ${thing}`);
}
/**
* Cannot use `$$restProps` in runes mode
* Cannot bind to %thing%
* @param {null | number | NodeLike} node
* @param {string} thing
* @returns {never}
*/
export function invalid_legacy_rest_props(node) {
e(node, "invalid_legacy_rest_props", "Cannot use `$$restProps` in runes mode");
export function constant_binding(node, thing) {
e(node, "constant_binding", `Cannot bind to ${thing}`);
}
/**
* `$props()` can only be used with an object destructuring pattern
* Cannot export derived state from a module. To expose the current derived value, export a function returning its value
* @param {null | number | NodeLike} node
* @returns {never}
*/
export function invalid_props_id(node) {
e(node, "invalid_props_id", "`$props()` can only be used with an object destructuring pattern");
export function derived_invalid_export(node) {
e(node, "derived_invalid_export", "Cannot export derived state from a module. To expose the current derived value, export a function returning its value");
}
/**
* `$props()` can only be used at the top level of components as a variable declaration initializer
* Cannot reassign or bind to each block argument in runes mode. Use the array and index variables instead (e.g. `array[i] = value` instead of `entry = value`)
* @param {null | number | NodeLike} node
* @returns {never}
*/
export function invalid_props_location(node) {
e(node, "invalid_props_location", "`$props()` can only be used at the top level of components as a variable declaration initializer");
export function each_item_invalid_assignment(node) {
e(node, "each_item_invalid_assignment", "Cannot reassign or bind to each block argument in runes mode. Use the array and index variables instead (e.g. `array[i] = value` instead of `entry = value`)");
}
/**
* `$props()` assignment must not contain nested properties or computed keys
* `$effect()` can only be used as an expression statement
* @param {null | number | NodeLike} node
* @returns {never}
*/
export function invalid_props_pattern(node) {
e(node, "invalid_props_pattern", "`$props()` assignment must not contain nested properties or computed keys");
export function effect_invalid_placement(node) {
e(node, "effect_invalid_placement", "`$effect()` can only be used as an expression statement");
}
/**
* `%rune%` cannot be called with arguments
* `$host()` can only be used inside custom element component instances
* @param {null | number | NodeLike} node
* @param {string} rune
* @returns {never}
*/
export function invalid_rune_args(node, rune) {
e(node, "invalid_rune_args", `\`${rune}\` cannot be called with arguments`);
export function host_invalid_placement(node) {
e(node, "host_invalid_placement", "`$host()` can only be used inside custom element component instances");
}
/**
* `%rune%` must be called with %args%
* Cannot use `export let` in runes mode use $props instead
* @param {null | number | NodeLike} node
* @param {string} rune
* @param {string} args
* @returns {never}
*/
export function invalid_rune_args_length(node, rune, args) {
e(node, "invalid_rune_args_length", `\`${rune}\` must be called with ${args}`);
export function legacy_export_invalid(node) {
e(node, "legacy_export_invalid", "Cannot use `export let` in runes mode — use $props instead");
}
/**
* Cannot use %rune% rune in non-runes mode
* Cannot use `$$props` in runes mode
* @param {null | number | NodeLike} node
* @param {string} rune
* @returns {never}
*/
export function invalid_rune_usage(node, rune) {
e(node, "invalid_rune_usage", `Cannot use ${rune} rune in non-runes mode`);
export function legacy_props_invalid(node) {
e(node, "legacy_props_invalid", "Cannot use `$$props` in runes mode");
}
/**
* %name% cannot be used in runes mode
* `$:` is not allowed in runes mode, use `$derived` or `$effect` instead
* @param {null | number | NodeLike} node
* @param {string} name
* @returns {never}
*/
export function invalid_runes_mode_import(node, name) {
e(node, "invalid_runes_mode_import", `${name} cannot be used in runes mode`);
export function legacy_reactive_statement_invalid(node) {
e(node, "legacy_reactive_statement_invalid", "`$:` is not allowed in runes mode, use `$derived` or `$effect` instead");
}
/**
* Cannot reassign or bind to snippet parameter
* Cannot use `$$restProps` in runes mode
* @param {null | number | NodeLike} node
* @returns {never}
*/
export function invalid_snippet_assignment(node) {
e(node, "invalid_snippet_assignment", "Cannot reassign or bind to snippet parameter");
export function legacy_rest_props_invalid(node) {
e(node, "legacy_rest_props_invalid", "Cannot use `$$restProps` in runes mode");
}
/**
* Cannot export state from a module if it is reassigned. Either export a function returning the state value or only mutate the state value's properties
* Cannot use `$props()` more than once
* @param {null | number | NodeLike} node
* @returns {never}
*/
export function invalid_state_export(node) {
e(node, "invalid_state_export", "Cannot export state from a module if it is reassigned. Either export a function returning the state value or only mutate the state value's properties");
export function props_duplicate(node) {
e(node, "props_duplicate", "Cannot use `$props()` more than once");
}
/**
* `%rune%(...)` can only be used as a variable declaration initializer or a class field
* `$props()` can only be used with an object destructuring pattern
* @param {null | number | NodeLike} node
* @param {string} rune
* @returns {never}
*/
export function invalid_state_location(node, rune) {
e(node, "invalid_state_location", `\`${rune}(...)\` can only be used as a variable declaration initializer or a class field`);
export function props_invalid_identifier(node) {
e(node, "props_invalid_identifier", "`$props()` can only be used with an object destructuring pattern");
}
/**
* `%name%` has already been declared
* `$props()` assignment must not contain nested properties or computed keys
* @param {null | number | NodeLike} node
* @param {string} name
* @returns {never}
*/
export function declaration_duplicate(node, name) {
e(node, "declaration_duplicate", `\`${name}\` has already been declared`);
export function props_invalid_pattern(node) {
e(node, "props_invalid_pattern", "`$props()` assignment must not contain nested properties or computed keys");
}
/**
* Cannot declare same variable name which is imported inside `<script context="module">`
* `$props()` can only be used at the top level of components as a variable declaration initializer
* @param {null | number | NodeLike} node
* @returns {never}
*/
export function declaration_duplicate_module_import(node) {
e(node, "declaration_duplicate_module_import", "Cannot declare same variable name which is imported inside `<script context=\"module\">`");
export function props_invalid_placement(node) {
e(node, "props_invalid_placement", "`$props()` can only be used at the top level of components as a variable declaration initializer");
}
/**
* The $ name is reserved, and cannot be used for variables and imports
* `%rune%` cannot be called with arguments
* @param {null | number | NodeLike} node
* @param {string} rune
* @returns {never}
*/
export function dollar_binding_invalid(node) {
e(node, "dollar_binding_invalid", "The $ name is reserved, and cannot be used for variables and imports");
export function rune_invalid_arguments(node, rune) {
e(node, "rune_invalid_arguments", `\`${rune}\` cannot be called with arguments`);
}
/**
* The $ prefix is reserved, and cannot be used for variables and imports
* `%rune%` must be called with %args%
* @param {null | number | NodeLike} node
* @param {string} rune
* @param {string} args
* @returns {never}
*/
export function dollar_prefix_invalid(node) {
e(node, "dollar_prefix_invalid", "The $ prefix is reserved, and cannot be used for variables and imports");
export function rune_invalid_arguments_length(node, rune, args) {
e(node, "rune_invalid_arguments_length", `\`${rune}\` must be called with ${args}`);
}
/**
* `%name%` is an illegal variable name. To reference a global variable called `%name%`, use `globalThis.%name%`
* Cannot use %rune% rune in non-runes mode
* @param {null | number | NodeLike} node
* @param {string} name
* @param {string} rune
* @returns {never}
*/
export function global_reference_invalid(node, name) {
e(node, "global_reference_invalid", `\`${name}\` is an illegal variable name. To reference a global variable called \`${name}\`, use \`globalThis.${name}\``);
export function rune_invalid_usage(node, rune) {
e(node, "rune_invalid_usage", `Cannot use ${rune} rune in non-runes mode`);
}
/**
* A component cannot have a default export
* %name% cannot be used in runes mode
* @param {null | number | NodeLike} node
* @param {string} name
* @returns {never}
*/
export function module_illegal_default_export(node) {
e(node, "module_illegal_default_export", "A component cannot have a default export");
export function runes_mode_invalid_import(node, name) {
e(node, "runes_mode_invalid_import", `${name} cannot be used in runes mode`);
}
/**
* Cyclical dependency detected: %cycle%
* Cannot reassign or bind to snippet parameter
* @param {null | number | NodeLike} node
* @param {string} cycle
* @returns {never}
*/
export function reactive_declaration_cycle(node, cycle) {
e(node, "reactive_declaration_cycle", `Cyclical dependency detected: ${cycle}`);
export function snippet_parameter_assignment(node) {
e(node, "snippet_parameter_assignment", "Cannot reassign or bind to snippet parameter");
}
/**
* Cannot subscribe to stores that are not declared at the top level of the component
* Cannot export state from a module if it is reassigned. Either export a function returning the state value or only mutate the state value's properties
* @param {null | number | NodeLike} node
* @returns {never}
*/
export function store_invalid_scoped_subscription(node) {
e(node, "store_invalid_scoped_subscription", "Cannot subscribe to stores that are not declared at the top level of the component");
export function state_invalid_export(node) {
e(node, "state_invalid_export", "Cannot export state from a module if it is reassigned. Either export a function returning the state value or only mutate the state value's properties");
}
/**
* Cannot reference store value inside `<script context="module">`
* `%rune%(...)` can only be used as a variable declaration initializer or a class field
* @param {null | number | NodeLike} node
* @param {string} rune
* @returns {never}
*/
export function store_invalid_subscription(node) {
e(node, "store_invalid_subscription", "Cannot reference store value inside `<script context=\"module\">`");
export function state_invalid_placement(node, rune) {
e(node, "state_invalid_placement", `\`${rune}(...)\` can only be used as a variable declaration initializer or a class field`);
}
/**

@ -414,12 +414,12 @@ export function analyze_component(root, source, options) {
if (analysis.runes) {
const props_refs = module.scope.references.get('$$props');
if (props_refs) {
e.invalid_legacy_props(props_refs[0].node);
e.legacy_props_invalid(props_refs[0].node);
}
const rest_props_refs = module.scope.references.get('$$restProps');
if (rest_props_refs) {
e.invalid_legacy_rest_props(rest_props_refs[0].node);
e.legacy_rest_props_invalid(rest_props_refs[0].node);
}
for (const { ast, scope, scopes } of [module, instance, template]) {

@ -345,15 +345,15 @@ const validation = {
}
if (binding.kind === 'derived') {
e.invalid_binding(node.expression, 'derived state');
e.constant_binding(node.expression, 'derived state');
}
if (context.state.analysis.runes && binding.kind === 'each') {
e.invalid_each_assignment(node);
e.each_item_invalid_assignment(node);
}
if (binding.kind === 'snippet') {
e.invalid_snippet_assignment(node);
e.snippet_parameter_assignment(node);
}
}
@ -482,7 +482,7 @@ const validation = {
specifier.imported.name === 'beforeUpdate' ||
specifier.imported.name === 'afterUpdate'
) {
e.invalid_runes_mode_import(specifier, specifier.imported.name);
e.runes_mode_invalid_import(specifier, specifier.imported.name);
}
}
}
@ -739,7 +739,7 @@ export const validation_legacy = merge(validation, a11y_validators, {
}
if (state.scope.get(callee.name)?.kind !== 'store_sub') {
e.invalid_rune_usage(node.init, callee.name);
e.rune_invalid_usage(node.init, callee.name);
}
},
AssignmentExpression(node, { state, path }) {
@ -772,11 +772,11 @@ function validate_export(node, scope, name) {
if (!binding) return;
if (binding.kind === 'derived') {
e.invalid_derived_export(node);
e.derived_invalid_export(node);
}
if ((binding.kind === 'state' || binding.kind === 'frozen_state') && binding.reassigned) {
e.invalid_state_export(node);
e.state_invalid_export(node);
}
}
@ -794,7 +794,7 @@ function validate_call_expression(node, scope, path) {
if (rune === '$props') {
if (parent.type === 'VariableDeclarator') return;
e.invalid_props_location(node);
e.props_invalid_placement(node);
}
if (rune === '$bindable') {
@ -807,7 +807,7 @@ function validate_call_expression(node, scope, path) {
return;
}
}
e.invalid_bindable_location(node);
e.bindable_invalid_location(node);
}
if (
@ -818,46 +818,46 @@ function validate_call_expression(node, scope, path) {
) {
if (parent.type === 'VariableDeclarator') return;
if (parent.type === 'PropertyDefinition' && !parent.static && !parent.computed) return;
e.invalid_state_location(node, rune);
e.state_invalid_placement(node, rune);
}
if (rune === '$effect' || rune === '$effect.pre') {
if (parent.type !== 'ExpressionStatement') {
e.invalid_effect_location(node);
e.effect_invalid_placement(node);
}
if (node.arguments.length !== 1) {
e.invalid_rune_args_length(node, rune, 'exactly one argument');
e.rune_invalid_arguments_length(node, rune, 'exactly one argument');
}
}
if (rune === '$effect.active') {
if (node.arguments.length !== 0) {
e.invalid_rune_args(node, rune);
e.rune_invalid_arguments(node, rune);
}
}
if (rune === '$effect.root') {
if (node.arguments.length !== 1) {
e.invalid_rune_args_length(node, rune, 'exactly one argument');
e.rune_invalid_arguments_length(node, rune, 'exactly one argument');
}
}
if (rune === '$inspect') {
if (node.arguments.length < 1) {
e.invalid_rune_args_length(node, rune, 'one or more arguments');
e.rune_invalid_arguments_length(node, rune, 'one or more arguments');
}
}
if (rune === '$inspect().with') {
if (node.arguments.length !== 1) {
e.invalid_rune_args_length(node, rune, 'exactly one argument');
e.rune_invalid_arguments_length(node, rune, 'exactly one argument');
}
}
if (rune === '$state.snapshot') {
if (node.arguments.length !== 1) {
e.invalid_rune_args_length(node, rune, 'exactly one argument');
e.rune_invalid_arguments_length(node, rune, 'exactly one argument');
}
}
}
@ -899,7 +899,7 @@ export const validation_runes_js = {
},
CallExpression(node, { state, path }) {
if (get_rune(node, state.scope) === '$host') {
e.invalid_host_location(node);
e.host_invalid_placement(node);
}
validate_call_expression(node, state.scope, path);
},
@ -912,13 +912,13 @@ export const validation_runes_js = {
const args = /** @type {import('estree').CallExpression} */ (init).arguments;
if ((rune === '$derived' || rune === '$derived.by') && args.length !== 1) {
e.invalid_rune_args_length(node, rune, 'exactly one argument');
e.rune_invalid_arguments_length(node, rune, 'exactly one argument');
} else if (rune === '$state' && args.length > 1) {
e.invalid_rune_args_length(node, rune, 'zero or one arguments');
e.rune_invalid_arguments_length(node, rune, 'zero or one arguments');
} else if (rune === '$props') {
e.invalid_props_location(node);
e.props_invalid_placement(node);
} else if (rune === '$bindable') {
e.invalid_bindable_location(node);
e.bindable_invalid_location(node);
}
},
AssignmentExpression(node, { state }) {
@ -1002,9 +1002,9 @@ function validate_no_const_assignment(node, argument, scope, is_binding) {
const thing = 'constant';
if (is_binding) {
e.invalid_binding(node, thing);
e.constant_binding(node, thing);
} else {
e.invalid_assignment(node, thing);
e.constant_assignment(node, thing);
}
}
}
@ -1023,16 +1023,16 @@ function validate_assignment(node, argument, state) {
if (state.analysis.runes) {
if (binding?.kind === 'derived') {
e.invalid_assignment(node, 'derived state');
e.constant_assignment(node, 'derived state');
}
if (binding?.kind === 'each') {
e.invalid_each_assignment(node);
e.each_item_invalid_assignment(node);
}
}
if (binding?.kind === 'snippet') {
e.invalid_snippet_assignment(node);
e.snippet_parameter_assignment(node);
}
}
@ -1048,7 +1048,7 @@ function validate_assignment(node, argument, state) {
if (object.type === 'ThisExpression' && property?.type === 'PrivateIdentifier') {
if (state.private_derived_state.includes(property.name)) {
e.invalid_assignment(node, 'derived state');
e.constant_assignment(node, 'derived state');
}
}
}
@ -1056,7 +1056,7 @@ function validate_assignment(node, argument, state) {
export const validation_runes = merge(validation, a11y_validators, {
LabeledStatement(node, { path }) {
if (node.label.name !== '$' || path.at(-1)?.type !== 'Program') return;
e.invalid_legacy_reactive_statement(node);
e.legacy_reactive_statement_invalid(node);
},
ExportNamedDeclaration(node, { state, next }) {
if (state.ast_type === 'module') {
@ -1074,7 +1074,7 @@ export const validation_runes = merge(validation, a11y_validators, {
if (node.declaration?.type !== 'VariableDeclaration') return;
if (node.declaration.kind !== 'let') return;
if (state.analysis.instance.scope !== state.scope) return;
e.invalid_legacy_export(node);
e.legacy_export_invalid(node);
}
},
ExportSpecifier(node, { state }) {
@ -1085,12 +1085,12 @@ export const validation_runes = merge(validation, a11y_validators, {
CallExpression(node, { state, path }) {
const rune = get_rune(node, state.scope);
if (rune === '$bindable' && node.arguments.length > 1) {
e.invalid_rune_args_length(node, '$bindable', 'zero or one arguments');
e.rune_invalid_arguments_length(node, '$bindable', 'zero or one arguments');
} else if (rune === '$host') {
if (node.arguments.length > 0) {
e.invalid_rune_args(node, '$host');
e.rune_invalid_arguments(node, '$host');
} else if (state.ast_type === 'module' || !state.analysis.custom_element) {
e.invalid_host_location(node);
e.host_invalid_placement(node);
}
}
@ -1102,7 +1102,7 @@ export const validation_runes = merge(validation, a11y_validators, {
context.type === 'Identifier' &&
(context.name === '$state' || context.name === '$derived')
) {
e.invalid_state_location(node, context.name);
e.state_invalid_placement(node, context.name);
}
next({ ...state });
},
@ -1123,39 +1123,39 @@ export const validation_runes = merge(validation, a11y_validators, {
// TODO some of this is duplicated with above, seems off
if ((rune === '$derived' || rune === '$derived.by') && args.length !== 1) {
e.invalid_rune_args_length(node, rune, 'exactly one argument');
e.rune_invalid_arguments_length(node, rune, 'exactly one argument');
} else if (rune === '$state' && args.length > 1) {
e.invalid_rune_args_length(node, rune, 'zero or one arguments');
e.rune_invalid_arguments_length(node, rune, 'zero or one arguments');
} else if (rune === '$props') {
if (state.has_props_rune) {
e.duplicate_props_rune(node);
e.props_duplicate(node);
}
state.has_props_rune = true;
if (args.length > 0) {
e.invalid_rune_args(node, rune);
e.rune_invalid_arguments(node, rune);
}
if (node.id.type !== 'ObjectPattern') {
e.invalid_props_id(node);
e.props_invalid_identifier(node);
}
if (state.scope !== state.analysis.instance.scope) {
e.invalid_props_location(node);
e.props_invalid_placement(node);
}
for (const property of node.id.properties) {
if (property.type === 'Property') {
if (property.computed) {
e.invalid_props_pattern(property);
e.props_invalid_pattern(property);
}
const value =
property.value.type === 'AssignmentPattern' ? property.value.left : property.value;
if (value.type !== 'Identifier') {
e.invalid_props_pattern(property);
e.props_invalid_pattern(property);
}
}
}

@ -2,7 +2,7 @@ import { test } from '../../test';
export default test({
error: {
code: 'invalid_state_location',
code: 'state_invalid_placement',
message:
'`$state(...)` can only be used as a variable declaration initializer or a class field',
position: [33, 41]

@ -2,7 +2,7 @@ import { test } from '../../test';
export default test({
error: {
code: 'invalid_derived_export',
code: 'derived_invalid_export',
message:
'Cannot export derived state from a module. To expose the current derived value, export a function returning its value',
position: [24, 66]

@ -2,7 +2,7 @@ import { test } from '../../test';
export default test({
error: {
code: 'invalid_state_export',
code: 'state_invalid_export',
message:
"Cannot export state from a module if it is reassigned. Either export a function returning the state value or only mutate the state value's properties",
position: [76, 114]

@ -2,7 +2,7 @@ import { test } from '../../test';
export default test({
error: {
code: 'invalid_state_export',
code: 'state_invalid_export',
message:
"Cannot export state from a module if it is reassigned. Either export a function returning the state value or only mutate the state value's properties",
position: [46, 86]

@ -2,7 +2,7 @@ import { test } from '../../test';
export default test({
error: {
code: 'invalid_snippet_assignment',
code: 'snippet_parameter_assignment',
message: 'Cannot reassign or bind to snippet parameter'
}
});

@ -2,7 +2,7 @@ import { test } from '../../test';
export default test({
error: {
code: 'invalid_snippet_assignment',
code: 'snippet_parameter_assignment',
message: 'Cannot reassign or bind to snippet parameter'
}
});

@ -2,7 +2,7 @@ import { test } from '../../test';
export default test({
error: {
code: 'invalid_assignment',
code: 'constant_assignment',
message: 'Cannot assign to constant'
}
});

@ -2,7 +2,7 @@ import { test } from '../../test';
export default test({
error: {
code: 'invalid_assignment',
code: 'constant_assignment',
message: 'Cannot assign to constant'
}
});

@ -2,7 +2,7 @@ import { test } from '../../test';
export default test({
error: {
code: 'invalid_runes_mode_import',
code: 'runes_mode_invalid_import',
message: 'beforeUpdate cannot be used in runes mode'
}
});

@ -2,7 +2,7 @@ import { test } from '../../test';
export default test({
error: {
code: 'duplicate_props_rune',
code: 'props_duplicate',
message: 'Cannot use `$props()` more than once'
}
});

@ -2,7 +2,7 @@ import { test } from '../../test';
export default test({
error: {
code: 'invalid_legacy_export',
code: 'legacy_export_invalid',
message: 'Cannot use `export let` in runes mode — use $props instead'
}
});

@ -2,7 +2,7 @@ import { test } from '../../test';
export default test({
error: {
code: 'invalid_state_export',
code: 'state_invalid_export',
message:
"Cannot export state from a module if it is reassigned. Either export a function returning the state value or only mutate the state value's properties",
position: [28, 53]

@ -2,7 +2,7 @@ import { test } from '../../test';
export default test({
error: {
code: 'invalid_each_assignment',
code: 'each_item_invalid_assignment',
message:
'Cannot reassign or bind to each block argument in runes mode. Use the array and index variables instead (e.g. `array[i] = value` instead of `entry = value`)'
}

@ -2,7 +2,7 @@ import { test } from '../../test';
export default test({
error: {
code: 'invalid_each_assignment',
code: 'each_item_invalid_assignment',
message:
'Cannot reassign or bind to each block argument in runes mode. Use the array and index variables instead (e.g. `array[i] = value` instead of `entry = value`)'
}

@ -2,7 +2,7 @@ import { test } from '../../test';
export default test({
error: {
code: 'invalid_assignment',
code: 'constant_assignment',
message: 'Cannot assign to constant'
}
});

@ -2,7 +2,7 @@ import { test } from '../../test';
export default test({
error: {
code: 'invalid_assignment',
code: 'constant_assignment',
message: 'Cannot assign to constant'
}
});

@ -2,7 +2,7 @@ import { test } from '../../test';
export default test({
error: {
code: 'invalid_assignment',
code: 'constant_assignment',
message: 'Cannot assign to derived state'
}
});

@ -2,7 +2,7 @@ import { test } from '../../test';
export default test({
error: {
code: 'invalid_binding',
code: 'constant_binding',
message: 'Cannot bind to derived state'
}
});

@ -2,7 +2,7 @@ import { test } from '../../test';
export default test({
error: {
code: 'invalid_assignment',
code: 'constant_assignment',
message: 'Cannot assign to derived state'
}
});

@ -2,7 +2,7 @@ import { test } from '../../test';
export default test({
error: {
code: 'invalid_assignment',
code: 'constant_assignment',
message: 'Cannot assign to derived state'
}
});

@ -2,7 +2,7 @@ import { test } from '../../test';
export default test({
error: {
code: 'invalid_assignment',
code: 'constant_assignment',
message: 'Cannot assign to derived state'
}
});

@ -2,7 +2,7 @@ import { test } from '../../test';
export default test({
error: {
code: 'invalid_state_location',
code: 'state_invalid_placement',
message: '`$state(...)` can only be used as a variable declaration initializer or a class field'
}
});

@ -2,7 +2,7 @@ import { test } from '../../test';
export default test({
error: {
code: 'invalid_rune_args_length',
code: 'rune_invalid_arguments_length',
message: '`$bindable` must be called with zero or one arguments'
}
});

@ -2,7 +2,7 @@ import { test } from '../../test';
export default test({
error: {
code: 'invalid_bindable_location',
code: 'bindable_invalid_location',
message: '`$bindable()` can only be used inside a `$props()` declaration'
}
});

@ -2,7 +2,7 @@ import { test } from '../../test';
export default test({
error: {
code: 'invalid_rune_args_length',
code: 'rune_invalid_arguments_length',
message: '`$derived` must be called with exactly one argument'
}
});

@ -2,7 +2,7 @@ import { test } from '../../test';
export default test({
error: {
code: 'invalid_state_location',
code: 'state_invalid_placement',
message:
'`$derived(...)` can only be used as a variable declaration initializer or a class field'
}

@ -2,7 +2,7 @@ import { test } from '../../test';
export default test({
error: {
code: 'invalid_rune_args_length',
code: 'rune_invalid_arguments_length',
message: '`$effect` must be called with exactly one argument'
}
});

@ -2,7 +2,7 @@ import { test } from '../../test';
export default test({
error: {
code: 'invalid_effect_location',
code: 'effect_invalid_placement',
message: '`$effect()` can only be used as an expression statement'
}
});

@ -2,7 +2,7 @@ import { test } from '../../test';
export default test({
error: {
code: 'invalid_host_location',
code: 'host_invalid_placement',
message: '`$host()` can only be used inside custom element component instances'
}
});

@ -2,7 +2,7 @@ import { test } from '../../test';
export default test({
error: {
code: 'invalid_rune_args',
code: 'rune_invalid_arguments',
message: '`$props` cannot be called with arguments'
}
});

@ -2,7 +2,7 @@ import { test } from '../../test';
export default test({
error: {
code: 'invalid_props_location',
code: 'props_invalid_placement',
message:
'`$props()` can only be used at the top level of components as a variable declaration initializer'
}

@ -2,7 +2,7 @@ import { test } from '../../test';
export default test({
error: {
code: 'invalid_rune_args_length',
code: 'rune_invalid_arguments_length',
message: '`$state` must be called with zero or one arguments'
}
});

@ -2,7 +2,7 @@ import { test } from '../../test';
export default test({
error: {
code: 'invalid_state_location',
code: 'state_invalid_placement',
message: '`$state(...)` can only be used as a variable declaration initializer or a class field'
}
});

@ -2,7 +2,7 @@ import { test } from '../../test';
export default test({
error: {
code: 'invalid_rune_args_length',
code: 'rune_invalid_arguments_length',
message: '`$state.snapshot` must be called with exactly one argument'
}
});

@ -1,6 +1,6 @@
[
{
"code": "invalid_assignment",
"code": "constant_assignment",
"message": "Cannot assign to constant",
"start": {
"line": 13,

@ -1,6 +1,6 @@
[
{
"code": "invalid_assignment",
"code": "constant_assignment",
"message": "Cannot assign to constant",
"start": {
"line": 14,

@ -1,6 +1,6 @@
[
{
"code": "invalid_assignment",
"code": "constant_assignment",
"message": "Cannot assign to constant",
"start": {
"line": 17,

@ -1,6 +1,6 @@
[
{
"code": "invalid_assignment",
"code": "constant_assignment",
"message": "Cannot assign to constant",
"start": {
"line": 3,

@ -1,6 +1,6 @@
[
{
"code": "invalid_assignment",
"code": "constant_assignment",
"message": "Cannot assign to constant",
"start": {
"line": 3,

@ -1,6 +1,6 @@
[
{
"code": "invalid_assignment",
"code": "constant_assignment",
"message": "Cannot assign to constant",
"start": {
"line": 16,

@ -1,6 +1,6 @@
[
{
"code": "invalid_binding",
"code": "constant_binding",
"message": "Cannot bind to constant",
"start": {
"line": 6,

@ -1,6 +1,6 @@
[
{
"code": "invalid_binding",
"code": "constant_binding",
"message": "Cannot bind to constant",
"start": {
"line": 6,

@ -1,6 +1,6 @@
[
{
"code": "invalid_binding",
"code": "constant_binding",
"message": "Cannot bind to constant",
"start": {
"line": 5,

@ -1,6 +1,6 @@
[
{
"code": "invalid_binding",
"code": "constant_binding",
"message": "Cannot bind to constant",
"start": {
"line": 5,

@ -1,6 +1,6 @@
[
{
"code": "invalid_binding",
"code": "constant_binding",
"message": "Cannot bind to constant",
"start": {
"line": 6,

@ -1,6 +1,6 @@
[
{
"code": "invalid_assignment",
"code": "constant_assignment",
"message": "Cannot assign to constant",
"start": {
"line": 7,

@ -1,6 +1,6 @@
[
{
"code": "invalid_binding",
"code": "constant_binding",
"message": "Cannot bind to constant",
"start": {
"line": 7,

Loading…
Cancel
Save