MCPcopy Create free account
hub / github.com/babel/babel / parseAndBuildMetadata

Function parseAndBuildMetadata

packages/babel-template/src/parse.ts:37–71  ·  view source on GitHub ↗
(
  formatter: Formatter<T>,
  code: string,
  opts: TemplateOpts,
)

Source from the content-addressed store, hash-verified

35const PATTERN = /^[_$A-Z0-9]+$/;
36
37export default function parseAndBuildMetadata<T>(
38 formatter: Formatter<T>,
39 code: string,
40 opts: TemplateOpts,
41): Metadata {
42 const {
43 placeholderAllowlist,
44 placeholderPattern,
45 preserveComments = false,
46 syntacticPlaceholders,
47 } = opts;
48
49 const ast = parseWithCodeFrame(code, opts.parser, syntacticPlaceholders);
50
51 removePropertiesDeep(ast, {
52 preserveComments,
53 });
54
55 formatter.validate(ast);
56
57 const state: MetadataState = {
58 syntactic: { placeholders: [], placeholderNames: new Set() },
59 legacy: { placeholders: [], placeholderNames: new Set() },
60 placeholderAllowlist,
61 placeholderPattern,
62 syntacticPlaceholders,
63 };
64
65 traverse(ast, placeholderVisitorHandler, state);
66
67 return {
68 ast,
69 ...(state.syntactic.placeholders.length ? state.syntactic : state.legacy),
70 };
71}
72
73function placeholderVisitorHandler(
74 node: t.Node,

Callers 2

stringTemplateFunction · 0.85
buildLiteralDataFunction · 0.85

Calls 3

removePropertiesDeepFunction · 0.90
traverseFunction · 0.90
parseWithCodeFrameFunction · 0.85

Tested by

no test coverage detected