"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const utils_1 = require("../utils"); const svelte_store_1 = require("./reference-helpers/svelte-store"); const compat_1 = require("../utils/compat"); exports.default = (0, utils_1.createRule)('require-store-reactive-access', { meta: { docs: { description: 'disallow to use of the store itself as an operand. Need to use $ prefix or get function.', category: 'Possible Errors', // TODO Switch to recommended in the major version. // recommended: true, recommended: false }, fixable: 'code', schema: [], messages: { usingRawStoreInText: 'Use the $ prefix or the get function to access reactive values instead of accessing the raw store.' }, type: 'problem' }, create(context) { if (!(0, compat_1.getSourceCode)(context).parserServices.isSvelte) { return {}; } const isStore = (0, svelte_store_1.createStoreChecker)(context); /** Verify for expression node */ function verifyExpression(node, options) { if (!node) return; if (isStore(node, { consistent: options?.consistent })) { context.report({ node, messageId: 'usingRawStoreInText', fix: node.type === 'Identifier' && !options?.disableFix ? (fixer) => fixer.insertTextBefore(node, '$') : null }); } } return { SvelteMustacheTag(node) { if (canAcceptStoreMustache(node)) { return; } // Check for

{store}

, etc. verifyExpression(node.expression); }, SvelteShorthandAttribute(node) { if (canAcceptStoreAttributeElement(node.parent.parent)) { return; } // Check for

verifyExpression(node.value, { disableFix: true }); }, SvelteSpreadAttribute(node) { // Check for verifyExpression(node.argument); }, SvelteDirective(node) { if (node.kind === 'Action' || node.kind === 'Animation' || node.kind === 'Transition') { if (node.key.name.type !== 'Identifier') { return; } // Check for