MCPcopy
hub / github.com/formatjs/formatjs / getICUMessageValue

Function getICUMessageValue

packages/babel-plugin-formatjs/utils.ts:155–196  ·  view source on GitHub ↗
(
  messagePath?:
    | NodePath<t.StringLiteral>
    | NodePath<t.TemplateLiteral>
    | NodePath<t.JSXExpressionContainer>,
  {isJSXSource = false} = {},
  preserveWhitespace?: Options['preserveWhitespace']
)

Source from the content-addressed store, hash-verified

153}
154
155function getICUMessageValue(
156 messagePath?:
157 | NodePath<t.StringLiteral>
158 | NodePath<t.TemplateLiteral>
159 | NodePath<t.JSXExpressionContainer>,
160 {isJSXSource = false} = {},
161 preserveWhitespace?: Options['preserveWhitespace']
162) {
163 if (!messagePath) {
164 return ''
165 }
166 let message = getMessageDescriptorValue(messagePath, true)
167
168 if (!preserveWhitespace) {
169 message = normalizeMessageWhitespace(message)
170 }
171
172 try {
173 parse(message)
174 } catch (parseError) {
175 if (
176 isJSXSource &&
177 messagePath.isLiteral() &&
178 message.indexOf('\\\\') >= 0
179 ) {
180 throw messagePath.buildCodeFrameError(
181 '[React Intl] Message failed to parse. ' +
182 'It looks like `\\`s were used for escaping, ' +
183 "this won't work with JSX string literals. " +
184 'Wrap with `{}`. ' +
185 'See: http://facebook.github.io/react/docs/jsx-gotchas.html'
186 )
187 }
188
189 throw messagePath.buildCodeFrameError(
190 '[React Intl] Message failed to parse. ' +
191 'See: https://formatjs.github.io/docs/core-concepts/icu-syntax' +
192 `\n${parseError}`
193 )
194 }
195 return message
196}
197const EXTRACTED = Symbol('FormatJSExtracted')
198/**
199 * Tag a node as extracted

Callers 1

Calls 3

parseFunction · 0.90

Tested by

no test coverage detected