Add Selector Resolve Nested to your project:
npm install @csstools/selector-resolve-nested --save-dev
import { resolveNestedSelector } from '@csstools/selector-resolve-nested';
import parser from 'postcss-selector-parser';
const a = parser().astSync('.foo &');
const b = parser().astSync('.bar');
resolveNestedSelector(a, b); // '.foo .bar'