UNPKG

@codeque/core

Version:

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

71 lines (62 loc) 2.1 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.matchWildcardsInDimension = void 0; var _matchStringOrIdentifierAliases = require("../../searchStages/matchStringOrIdentifierAliases"); /* * Adds support for matching wildcard in "Dimension" unit and value * Q: {width: 0x0px} C: {width: 5px} * Q: {width: 5$$} C: {width: 5px} * Q: {width: 0x0$$} C: {width: 5px} */ const matchWildcardsInDimension = ({ queryNode, fileNode, searchSettings, matchContext }, _, { fileKeysToTraverseForOtherMatches, log }) => { if (queryNode?.type === 'Dimension' && fileNode?.type === 'Dimension') { const { wildcardUtils } = searchSettings.parserSettings; const { caseInsensitive } = searchSettings; let levelMatch = true; const queryNodeStringContent = queryNode.unit; const fileNodeStringContent = fileNode.unit; 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; } /** * Compare values only if there is no numeric wildcard in query */ if (queryNode.value !== wildcardUtils.numericWildcard) { levelMatch = levelMatch && queryNode.value === fileNode.value; } // We always want to return here, otherwise generic string wildcard matching would take over and match incorrectly return { levelMatch, queryKeysToTraverseForValidatingMatch: [], fileKeysToTraverseForValidatingMatch: [], fileKeysToTraverseForOtherMatches }; } }; exports.matchWildcardsInDimension = matchWildcardsInDimension;