MCPcopy Create free account
hub / github.com/formatjs/formatjs / templateSimpleExpressionNodeVisitor

Function templateSimpleExpressionNodeVisitor

packages/cli-lib/vue_extractor.ts:65–92  ·  view source on GitHub ↗
(parseScriptFn: ScriptParseFn)

Source from the content-addressed store, hash-verified

63}
64
65function templateSimpleExpressionNodeVisitor(parseScriptFn: ScriptParseFn) {
66 return (
67 n:
68 | ElementNode
69 | CompoundExpressionNode
70 | CompoundExpressionNode['children'][0]
71 ) => {
72 if (typeof n !== 'object') {
73 return
74 }
75 if (n.type !== NodeTypes.SIMPLE_EXPRESSION) {
76 return
77 }
78
79 const {content} = n as SimpleExpressionNode
80 // Wrap this in () since a vue comp node attribute can just be
81 // an object literal which, by itself is invalid TS
82 // but with () it becomes an ExpressionStatement
83 try {
84 parseScriptFn(`(${content})`)
85 } catch (e) {
86 console.warn(
87 `Failed to parse "${content}". Ignore this if content has no extractable message`,
88 e
89 )
90 }
91 }
92}
93
94export function parseFile(
95 source: string,

Callers 1

parseFileFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected