UNPKG

@codeque/core

Version:

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

66 lines (60 loc) 2.15 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createMatchWildcardsInPropValueNodesComparator = void 0; var _matchStringOrIdentifierAliases = require("../../../searchStages/matchStringOrIdentifierAliases"); /* * Supports matching string or identifier wildcards in nodes that contains prop and value in the same node. * eg. TextAttribute in HTML which is { prop: 'propName', value: 'value', ...otherKeys } */ const createMatchWildcardsInPropValueNodesComparator = ({ nodeType, keysWithWildcards, keysToTraverse }) => ({ queryNode, fileNode, searchSettings, matchContext }, _, { fileKeysToTraverseForOtherMatches, log }) => { if (queryNode?.type === nodeType && fileNode?.type === nodeType) { const { wildcardUtils } = searchSettings.parserSettings; const { caseInsensitive } = searchSettings; let levelMatch = true; keysWithWildcards.forEach(key => { const queryNodeStringContent = queryNode[key]; const fileNodeStringContent = fileNode[key]; const wildcardsMeta = wildcardUtils.getStringWildcardsFromString(queryNodeStringContent); if (wildcardsMeta.length > 0) { levelMatch = levelMatch && (0, _matchStringOrIdentifierAliases.matchStringOrIdentifierAliases)({ queryValue: queryNodeStringContent, fileValue: fileNodeStringContent, wildcardsMeta, matchContext, wildcardUtils, caseInsensitive }); } else { /** * If there are no wildcards in given prop, compare prop values directly */ levelMatch = levelMatch && queryNodeStringContent === fileNodeStringContent; } }); // We always want to return here, otherwise generic string wildcard matching would take over and match incorrectly return { levelMatch, queryKeysToTraverseForValidatingMatch: keysToTraverse, fileKeysToTraverseForValidatingMatch: keysToTraverse, fileKeysToTraverseForOtherMatches }; } }; exports.createMatchWildcardsInPropValueNodesComparator = createMatchWildcardsInPropValueNodesComparator;