UNPKG

@codeque/core

Version:

Multiline code search for every language. Structural code search for JavaScript, TypeScript, HTML and CSS

48 lines (43 loc) 1.57 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createWildcardForAssignmentPatternOrDefaultParamValuesNodesComparator = void 0; /** * Support for matching function params with default value or object/array destructuring with default value * * Since we comparing query node with nested node from file, we have to do so before wildcards comparison * * Q: const {$$} = query; C: const {data = []} = query * Q: const [$$] = query; C: const [data = []] = query * Q: function some($$) {}; C: function some(param = null) {} */ const createWildcardForAssignmentPatternOrDefaultParamValuesNodesComparator = () => ({ fileNode, queryNode, searchSettings, matchContext }, compareNodes, { queryKeysMapper, fileKeysMapper }) => { const { mode, logger } = searchSettings; const isExact = mode === 'exact'; if (queryNode && fileNode) { if (!isExact && queryNode.type === 'Identifier' && fileNode.type === 'AssignmentPattern' && fileNode.left?.type === 'Identifier') { logger.log('comparing assignment pattern with identifier'); // By comparing nodes this way, we support wildcards in compared identifiers return compareNodes({ fileNode: fileNode.left, queryNode, searchSettings, queryKeysPrefix: queryKeysMapper(''), fileKeysPrefix: fileKeysMapper('left'), matchContext }); } } }; exports.createWildcardForAssignmentPatternOrDefaultParamValuesNodesComparator = createWildcardForAssignmentPatternOrDefaultParamValuesNodesComparator;