( formatter: Formatter<T>, code: string, opts: TemplateOpts, )
| 35 | const PATTERN = /^[_$A-Z0-9]+$/; |
| 36 | |
| 37 | export 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 | |
| 73 | function placeholderVisitorHandler( |
| 74 | node: t.Node, |
no test coverage detected