Skip to content

Commit

Permalink
feat(meta-css): improve doc interpolation
Browse files Browse the repository at this point in the history
- also process doc strings for template args
- extract __interpolateDoc() helper
  • Loading branch information
postspectacular committed Mar 17, 2024
1 parent e8d45a5 commit 9509cc3
Showing 1 changed file with 23 additions and 19 deletions.
42 changes: 23 additions & 19 deletions packages/meta-css/src/generate.ts
Expand Up @@ -35,6 +35,7 @@ import {
type CompiledSpecs,
type GeneratorConfig,
type Spec,
type SpecDoc,
type TemplateSpec,
} from "./api.js";
import { watchInputs as $watch, maybeWriteText } from "./utils.js";
Expand Down Expand Up @@ -225,25 +226,13 @@ export const expandSpec = (
defs[name].__user = spec.user;
}
if (spec.doc != null) {
defs[name].__doc = {
group: __withVariations(
spec.doc.group ?? "TODO",
currVarID,
varValue,
currKey,
currValue
),
desc: spec.doc.desc
? __withVariations(
spec.doc.desc,
currVarID,
varValue,
currKey,
currValue
)
: undefined,
args: spec.doc.args,
};
defs[name].__doc = __interpolateDoc(
spec.doc,
currVarID,
varValue,
currKey,
currValue
);
}
} else if (!ownNames.has(name)) {
illegalArgs(`duplicate class ID: ${name}`);
Expand Down Expand Up @@ -350,3 +339,18 @@ const __withVariations = (
.replace(/<var>/g, $var)
.replace(/<k>/g, k)
.replace(/<v>/g, String(v));

/** @internal */
const __interpolateDoc = (
{ group, desc, args }: SpecDoc,
vid: string,
$var: string,
k: string,
v: NumOrString
) => ({
group: group ? __withVariations(group, vid, $var, k, v) : "TODO",
desc: desc ? __withVariations(desc, vid, $var, k, v) : undefined,
args: args
? args.map((a) => __withVariations(a, vid, $var, k, v))
: undefined,
});

0 comments on commit 9509cc3

Please sign in to comment.