import { query as q } from '@renovatebot/good-enough-parser'; import { regEx } from '../../../../util/regex.ts'; import type { Ctx } from '../types.ts'; import { cleanupTempVars, qValueMatcher, storeInTokenMap } from './common.ts'; import { handleApplyFrom } from './handlers.ts'; // apply from: 'foo.gradle' // apply(from = property("foo")) const qApplyFromFile = q .alt( q .alt( q .opt(q.sym(regEx(/^(?:rootProject|project)$/)).op('.')) .sym('file'), q.opt(q.sym('new')).sym('File'), ) .tree({ maxDepth: 1, startsWith: '(', endsWith: ')', search: q .begin() .opt( q .join(qValueMatcher, q.op(',')) .handler((ctx) => storeInTokenMap(ctx, 'parentPath')), ) .join(qValueMatcher) .end(), }), qValueMatcher, ) .handler((ctx) => storeInTokenMap(ctx, 'scriptFile')); export const qApplyFrom = q .sym('apply') .alt( q // apply from: rootProject.file("basedir", "foo/bar.gradle") .sym('from') .op(':') .join(qApplyFromFile), q // apply(from = File(base, "bar.gradle")) .tree({ maxDepth: 1, maxMatches: 1, startsWith: '(', endsWith: ')', search: q.begin().sym('from').op('=').join(qApplyFromFile).end(), }), ) .handler(handleApplyFrom) .handler(cleanupTempVars);