babel-plugin-formatjs 11.3.16 → 12.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.d.ts +10 -3
- package/index.js +5 -3
- package/index.js.map +1 -1
- package/package.json +8 -9
package/index.d.ts
CHANGED
|
@@ -1,12 +1,18 @@
|
|
|
1
|
+
import { declare } from "@babel/helper-plugin-utils";
|
|
1
2
|
import { SourceLocation } from "@babel/types";
|
|
2
|
-
import {
|
|
3
|
-
|
|
3
|
+
import { PluginTarget } from "@babel/core";
|
|
4
4
|
//#region packages/babel-plugin-formatjs/types.d.ts
|
|
5
5
|
interface MessageDescriptor {
|
|
6
6
|
id: string;
|
|
7
7
|
defaultMessage?: string;
|
|
8
8
|
description?: string;
|
|
9
9
|
}
|
|
10
|
+
interface State {
|
|
11
|
+
messages: ExtractedMessageDescriptor[];
|
|
12
|
+
meta: Record<string, string>;
|
|
13
|
+
componentNames: string[];
|
|
14
|
+
functionNames: string[];
|
|
15
|
+
}
|
|
10
16
|
type ExtractedMessageDescriptor = MessageDescriptor & Partial<SourceLocation> & {
|
|
11
17
|
file?: string;
|
|
12
18
|
};
|
|
@@ -33,7 +39,8 @@ type ExtractionResult<M = Record<string, string>> = {
|
|
|
33
39
|
meta: M;
|
|
34
40
|
};
|
|
35
41
|
declare const DEFAULT_ID_INTERPOLATION_PATTERN = "[sha512:contenthash:base64:6]";
|
|
36
|
-
|
|
42
|
+
type FormatJSPlugin = PluginTarget & ReturnType<typeof declare<State, Options>>;
|
|
43
|
+
declare const plugin: FormatJSPlugin;
|
|
37
44
|
//#endregion
|
|
38
45
|
export { DEFAULT_ID_INTERPOLATION_PATTERN, ExtractionResult, plugin as default };
|
|
39
46
|
//# sourceMappingURL=index.d.ts.map
|
package/index.js
CHANGED
|
@@ -129,7 +129,7 @@ function getMessagesObjectFromExpression(nodePath) {
|
|
|
129
129
|
while (t.isTSAsExpression(currentPath.node) || t.isTSTypeAssertion(currentPath.node) || t.isTypeCastExpression(currentPath.node)) currentPath = currentPath.get("expression");
|
|
130
130
|
return currentPath;
|
|
131
131
|
}
|
|
132
|
-
const
|
|
132
|
+
const visitCallExpression = function(path, { opts, file: { opts: { filename } } }) {
|
|
133
133
|
const { overrideIdFn, idInterpolationPattern, removeDefaultMessage, ast, preserveWhitespace, flatten, throws, onMsgError } = opts;
|
|
134
134
|
if (wasExtracted(path)) return;
|
|
135
135
|
const { messages, functionNames } = this;
|
|
@@ -197,6 +197,8 @@ const visitor$1 = function(path, { opts, file: { opts: { filename } } }) {
|
|
|
197
197
|
if (messageDescriptor && messageDescriptor.isObjectExpression()) processMessageObject(messageDescriptor);
|
|
198
198
|
}
|
|
199
199
|
};
|
|
200
|
+
const visitor$1 = visitCallExpression;
|
|
201
|
+
const optionalVisitor = visitCallExpression;
|
|
200
202
|
//#endregion
|
|
201
203
|
//#region packages/babel-plugin-formatjs/visitors/jsx-opening-element.ts
|
|
202
204
|
const visitor = function(path, { opts, file: { opts: { filename } } }) {
|
|
@@ -258,7 +260,7 @@ const visitor = function(path, { opts, file: { opts: { filename } } }) {
|
|
|
258
260
|
const babelPluginSyntaxJsx = babelPluginSyntaxJsxNs.default || babelPluginSyntaxJsxNs;
|
|
259
261
|
const DEFAULT_ID_INTERPOLATION_PATTERN = "[sha512:contenthash:base64:6]";
|
|
260
262
|
const plugin = declare((api, options) => {
|
|
261
|
-
api.assertVersion(
|
|
263
|
+
api.assertVersion(8);
|
|
262
264
|
if (!options.idInterpolationPattern) options.idInterpolationPattern = DEFAULT_ID_INTERPOLATION_PATTERN;
|
|
263
265
|
const { pragma } = options;
|
|
264
266
|
const componentNames = new Set(options.additionalComponentNames);
|
|
@@ -297,7 +299,7 @@ const plugin = declare((api, options) => {
|
|
|
297
299
|
},
|
|
298
300
|
JSXOpeningElement: visitor,
|
|
299
301
|
CallExpression: visitor$1,
|
|
300
|
-
OptionalCallExpression:
|
|
302
|
+
OptionalCallExpression: optionalVisitor
|
|
301
303
|
}
|
|
302
304
|
};
|
|
303
305
|
});
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["visitor","CallExpression"],"sources":["../utils.ts","../visitors/call-expression.ts","../visitors/jsx-opening-element.ts","../index.ts"],"sourcesContent":["import type * as t from '@babel/types'\nimport {parse} from '@formatjs/icu-messageformat-parser'\nimport {hoistSelectors} from '@formatjs/icu-messageformat-parser/manipulator.js'\nimport {printAST} from '@formatjs/icu-messageformat-parser/printer.js'\nimport {\n interpolateName,\n normalizeMessageWhitespace,\n} from '@formatjs/ts-transformer'\n\nimport {type NodePath} from '@babel/core'\nimport {\n type ExtractedMessageDescriptor,\n type MessageDescriptor,\n type MessageDescriptorPath,\n type Options,\n} from '#packages/babel-plugin-formatjs/types.js'\n\nconst DESCRIPTOR_PROPS = new Set<keyof MessageDescriptorPath>([\n 'id',\n 'description',\n 'defaultMessage',\n])\n\nfunction evaluatePath(path: NodePath<any>): string {\n const evaluated = path.evaluate()\n if (evaluated.confident) {\n return evaluated.value\n }\n\n throw path.buildCodeFrameError(\n '[React Intl] Messages must be statically evaluate-able for extraction.'\n )\n}\n\nexport function getMessageDescriptorKey(path: NodePath<any>): string {\n if (path.isIdentifier() || path.isJSXIdentifier()) {\n return path.node.name\n }\n\n return evaluatePath(path)\n}\n\nfunction getMessageDescriptorValue(\n path?:\n | NodePath<t.StringLiteral>\n | NodePath<t.JSXExpressionContainer>\n | NodePath<t.TemplateLiteral>,\n isMessageNode?: boolean\n) {\n if (!path) {\n return ''\n }\n if (path.isJSXExpressionContainer()) {\n // If this is already compiled, no need to recompiled it\n if (isMessageNode && path.get('expression').isArrayExpression()) {\n return ''\n }\n path = path.get('expression') as NodePath<t.StringLiteral>\n }\n\n // Always trim the Message Descriptor values.\n const descriptorValue = evaluatePath(path)\n\n return descriptorValue\n}\n\nexport function createMessageDescriptor(\n propPaths: [\n NodePath<t.JSXIdentifier> | NodePath<t.Identifier>,\n NodePath<t.StringLiteral> | NodePath<t.JSXExpressionContainer>,\n ][]\n): MessageDescriptorPath {\n return propPaths.reduce(\n (hash: MessageDescriptorPath, [keyPath, valuePath]) => {\n const key = getMessageDescriptorKey(\n keyPath\n ) as keyof MessageDescriptorPath\n\n if (DESCRIPTOR_PROPS.has(key)) {\n hash[key] = valuePath\n }\n\n return hash\n },\n {\n id: undefined,\n defaultMessage: undefined,\n description: undefined,\n }\n )\n}\n\nexport function evaluateMessageDescriptor(\n descriptorPath: MessageDescriptorPath,\n isJSXSource = false,\n filename: string | undefined,\n idInterpolationPattern?: string,\n overrideIdFn?: Options['overrideIdFn'],\n preserveWhitespace?: Options['preserveWhitespace'],\n flatten?: Options['flatten']\n): MessageDescriptor {\n let id = getMessageDescriptorValue(descriptorPath.id)\n let defaultMessage = getICUMessageValue(\n descriptorPath.defaultMessage,\n {\n isJSXSource,\n },\n preserveWhitespace\n )\n const description = getMessageDescriptorValue(descriptorPath.description)\n\n // GH #3537: Apply flatten transformation before calling overrideIdFn\n // so that the ID generation sees the same message format as the final output\n if (flatten && defaultMessage) {\n try {\n defaultMessage = printAST(hoistSelectors(parse(defaultMessage)))\n } catch (e: any) {\n const loc = descriptorPath.defaultMessage?.node.loc\n const locationStr = loc\n ? ` at line ${loc.start.line}, column ${loc.start.column + 1}`\n : ''\n throw new Error(\n `[formatjs] Cannot flatten message in file \"${filename}\"${locationStr}${id ? ` with id \"${id}\"` : ''}: ${e.message}\\nMessage: ${defaultMessage}`\n )\n }\n }\n\n if (overrideIdFn) {\n id = overrideIdFn(id, defaultMessage, description, filename)\n } else if (!id && idInterpolationPattern && defaultMessage) {\n id = interpolateName(\n {resourcePath: filename} as any,\n idInterpolationPattern,\n {\n content: description\n ? `${defaultMessage}#${description}`\n : defaultMessage,\n }\n )\n }\n const descriptor: MessageDescriptor = {\n id,\n }\n\n if (description) {\n descriptor.description = description\n }\n if (defaultMessage) {\n descriptor.defaultMessage = defaultMessage\n }\n\n return descriptor\n}\n\nfunction getICUMessageValue(\n messagePath?:\n | NodePath<t.StringLiteral>\n | NodePath<t.TemplateLiteral>\n | NodePath<t.JSXExpressionContainer>,\n {isJSXSource = false} = {},\n preserveWhitespace?: Options['preserveWhitespace']\n) {\n if (!messagePath) {\n return ''\n }\n let message = getMessageDescriptorValue(messagePath, true)\n\n if (!preserveWhitespace) {\n message = normalizeMessageWhitespace(message)\n }\n\n try {\n parse(message)\n } catch (parseError) {\n if (\n isJSXSource &&\n messagePath.isLiteral() &&\n message.indexOf('\\\\\\\\') >= 0\n ) {\n throw messagePath.buildCodeFrameError(\n '[React Intl] Message failed to parse. ' +\n 'It looks like `\\\\`s were used for escaping, ' +\n \"this won't work with JSX string literals. \" +\n 'Wrap with `{}`. ' +\n 'See: http://facebook.github.io/react/docs/jsx-gotchas.html'\n )\n }\n\n throw messagePath.buildCodeFrameError(\n '[React Intl] Message failed to parse. ' +\n 'See: https://formatjs.github.io/docs/core-concepts/icu-syntax' +\n `\\n${parseError}`\n )\n }\n return message\n}\nconst EXTRACTED = Symbol('FormatJSExtracted')\n/**\n * Tag a node as extracted\n * Store this in the node itself so that multiple passes work. Specifically\n * if we remove `description` in the 1st pass, 2nd pass will fail since\n * it expect `description` to be there.\n * HACK: We store this in the node instance since this persists across\n * multiple plugin runs\n * @param path\n */\nexport function tagAsExtracted(path: NodePath<any>): void {\n path.node[EXTRACTED] = true\n}\n/**\n * Check if a node was extracted\n * @param path\n */\nexport function wasExtracted(path: NodePath<any>): boolean {\n return !!path.node[EXTRACTED]\n}\n\n/**\n * Store a message in our global messages\n * @param messageDescriptor\n * @param path\n * @param opts\n * @param filename\n * @param messages\n */\nexport function storeMessage(\n {id, description, defaultMessage}: MessageDescriptor,\n path: NodePath<any>,\n {extractSourceLocation}: Options,\n\n filename: string | undefined,\n messages: ExtractedMessageDescriptor[]\n): void {\n if (!id && !defaultMessage) {\n throw path.buildCodeFrameError(\n '[React Intl] Message Descriptors require an `id` or `defaultMessage`.'\n )\n }\n\n let loc = {}\n if (extractSourceLocation) {\n loc = {\n file: filename,\n ...path.node.loc,\n }\n }\n messages.push({id, description, defaultMessage, ...loc})\n}\n","import {type NodePath, type PluginPass} from '@babel/core'\nimport * as t from '@babel/types'\nimport {\n type MessageDescriptor,\n type MessageDescriptorPath,\n type Options,\n type State,\n} from '#packages/babel-plugin-formatjs/types.js'\nimport {type VisitNodeFunction} from '@babel/traverse'\nimport {\n createMessageDescriptor,\n evaluateMessageDescriptor,\n wasExtracted,\n storeMessage,\n tagAsExtracted,\n} from '#packages/babel-plugin-formatjs/utils.js'\nimport {parse} from '@formatjs/icu-messageformat-parser'\n\nfunction assertObjectExpression(\n path: NodePath<any>,\n callee: NodePath<t.Expression | t.V8IntrinsicIdentifier>\n): asserts path is NodePath<t.ObjectExpression> {\n if (!path || !path.isObjectExpression()) {\n throw path.buildCodeFrameError(\n `[React Intl] \\`${\n (callee.get('property') as NodePath<t.Identifier>).node.name\n }()\\` must be called with an object expression with values that are React Intl Message Descriptors, also defined as object expressions.`\n )\n }\n}\n\nfunction isFormatMessageCall(\n callee: NodePath<t.Expression | t.V8IntrinsicIdentifier | t.MemberExpression>,\n functionNames: string[]\n) {\n if (functionNames.find(name => callee.isIdentifier({name}))) {\n return true\n }\n\n // GH #4471: Handle both MemberExpression and OptionalMemberExpression\n // (e.g., intl.formatMessage() and intl.formatMessage?.())\n if (callee.isMemberExpression() || callee.isOptionalMemberExpression()) {\n const property = callee.get('property') as NodePath<t.MemberExpression>\n return !!functionNames.find(name => property.isIdentifier({name}))\n }\n return false\n}\n\nfunction getMessagesObjectFromExpression(\n nodePath: NodePath<any>\n): NodePath<any> {\n let currentPath = nodePath\n while (\n t.isTSAsExpression(currentPath.node) ||\n t.isTSTypeAssertion(currentPath.node) ||\n t.isTypeCastExpression(currentPath.node)\n ) {\n currentPath = currentPath.get('expression') as NodePath<any>\n }\n return currentPath\n}\n\nexport const visitor: VisitNodeFunction<PluginPass & State, t.CallExpression> =\n function (\n path,\n {\n opts,\n file: {\n opts: {filename},\n },\n }\n ) {\n const {\n overrideIdFn,\n idInterpolationPattern,\n removeDefaultMessage,\n ast,\n preserveWhitespace,\n flatten,\n throws,\n onMsgError,\n } = opts as Options\n if (wasExtracted(path)) {\n return\n }\n const {messages, functionNames} = this\n const callee = path.get('callee')\n const args = path.get('arguments')\n\n /**\n * Process MessageDescriptor\n * @param messageDescriptor Message Descriptor\n */\n function processMessageObject(\n messageDescriptor: NodePath<t.ObjectExpression>\n ) {\n assertObjectExpression(messageDescriptor, callee)\n\n const properties = messageDescriptor.get(\n 'properties'\n ) as NodePath<t.ObjectProperty>[]\n\n let descriptorPath: MessageDescriptorPath\n let descriptor: MessageDescriptor\n try {\n descriptorPath = createMessageDescriptor(\n properties.map(\n prop =>\n [prop.get('key'), prop.get('value')] as [\n NodePath<t.Identifier>,\n NodePath<t.StringLiteral>,\n ]\n )\n )\n\n // If the message is already compiled, don't re-compile it\n if (descriptorPath.defaultMessage?.isArrayExpression()) {\n return\n }\n\n descriptor = evaluateMessageDescriptor(\n descriptorPath,\n false,\n filename || undefined,\n idInterpolationPattern,\n overrideIdFn,\n preserveWhitespace,\n flatten\n )\n } catch (e) {\n if (throws === false) {\n tagAsExtracted(path)\n onMsgError?.(filename || '', e as Error)\n return\n }\n throw e\n }\n storeMessage(\n descriptor,\n messageDescriptor,\n opts as Options,\n filename || undefined,\n messages\n )\n\n const firstProp = properties[0]\n const defaultMessageProp = properties.find(prop => {\n const keyProp = prop.get('key')\n return (\n keyProp.isIdentifier({name: 'defaultMessage'}) ||\n keyProp.isStringLiteral({value: 'defaultMessage'})\n )\n })\n const idProp = properties.find(prop => {\n const keyProp = prop.get('key')\n return (\n keyProp.isIdentifier({name: 'id'}) ||\n keyProp.isStringLiteral({value: 'id'})\n )\n })\n\n // Insert ID potentially 1st before removing nodes\n if (idProp) {\n idProp.get('value').replaceWith(t.stringLiteral(descriptor.id))\n } else {\n firstProp.insertBefore(\n t.objectProperty(t.identifier('id'), t.stringLiteral(descriptor.id))\n )\n }\n\n // Remove description\n properties\n .find(prop => {\n const keyProp = prop.get('key')\n return (\n keyProp.isIdentifier({name: 'description'}) ||\n keyProp.isStringLiteral({value: 'description'})\n )\n })\n ?.remove()\n\n // Pre-parse or remove defaultMessage\n if (defaultMessageProp) {\n if (removeDefaultMessage) {\n defaultMessageProp?.remove()\n } else if (descriptor.defaultMessage) {\n const valueProp = defaultMessageProp.get('value')\n if (ast) {\n valueProp.replaceWithSourceString(\n JSON.stringify(parse(descriptor.defaultMessage))\n )\n } else {\n valueProp.replaceWith(t.stringLiteral(descriptor.defaultMessage))\n }\n }\n }\n\n tagAsExtracted(path)\n }\n\n // Check that this is `defineMessages` call\n if (\n callee.isIdentifier({name: 'defineMessages'}) ||\n callee.isIdentifier({name: 'defineMessage'})\n ) {\n const firstArgument = args[0]\n const messagesObj = getMessagesObjectFromExpression(firstArgument)\n\n assertObjectExpression(messagesObj, callee)\n if (callee.isIdentifier({name: 'defineMessage'})) {\n processMessageObject(messagesObj as NodePath<t.ObjectExpression>)\n } else {\n const properties = messagesObj.get('properties')\n if (Array.isArray(properties)) {\n properties\n .map(prop => prop.get('value') as NodePath<t.ObjectExpression>)\n .forEach(processMessageObject)\n }\n }\n }\n\n // Check that this is `intl.formatMessage` call\n if (isFormatMessageCall(callee, functionNames)) {\n const messageDescriptor = args[0]\n if (messageDescriptor && messageDescriptor.isObjectExpression()) {\n processMessageObject(messageDescriptor)\n }\n }\n }\n","import {type NodePath, type PluginPass} from '@babel/core'\n\nimport {\n type MessageDescriptor,\n type MessageDescriptorPath,\n type Options,\n type State,\n} from '#packages/babel-plugin-formatjs/types.js'\nimport * as t from '@babel/types'\nimport {type VisitNodeFunction} from '@babel/traverse'\nimport {parse} from '@formatjs/icu-messageformat-parser'\nimport {\n createMessageDescriptor,\n evaluateMessageDescriptor,\n getMessageDescriptorKey,\n storeMessage,\n tagAsExtracted,\n wasExtracted,\n} from '#packages/babel-plugin-formatjs/utils.js'\n\nexport const visitor: VisitNodeFunction<\n PluginPass & State,\n t.JSXOpeningElement\n> = function (\n path,\n {\n opts,\n file: {\n opts: {filename},\n },\n }\n) {\n const {\n removeDefaultMessage,\n idInterpolationPattern,\n overrideIdFn,\n ast,\n preserveWhitespace,\n flatten,\n throws,\n onMsgError,\n } = opts as Options\n\n const {componentNames, messages} = this\n if (wasExtracted(path)) {\n return\n }\n\n const name = path.get('name')\n\n if (!componentNames.find(n => name.isJSXIdentifier({name: n}))) {\n return\n }\n\n const attributes = path\n .get('attributes')\n .filter(attr => attr.isJSXAttribute())\n\n let descriptorPath: MessageDescriptorPath\n let descriptor: MessageDescriptor\n try {\n descriptorPath = createMessageDescriptor(\n attributes.map(attr => [\n attr.get('name') as NodePath<t.JSXIdentifier>,\n attr.get('value') as\n | NodePath<t.StringLiteral>\n | NodePath<t.JSXExpressionContainer>,\n ])\n )\n\n // In order for a default message to be extracted when\n // declaring a JSX element, it must be done with standard\n // `key=value` attributes. But it's completely valid to\n // write `<FormattedMessage {...descriptor} />`, because it will be\n // skipped here and extracted elsewhere. The descriptor will\n // be extracted only (storeMessage) if a `defaultMessage` prop.\n if (!descriptorPath.defaultMessage) {\n return\n }\n\n descriptor = evaluateMessageDescriptor(\n descriptorPath,\n true,\n filename || undefined,\n idInterpolationPattern,\n overrideIdFn,\n preserveWhitespace,\n flatten\n )\n } catch (e) {\n if (throws === false) {\n tagAsExtracted(path)\n onMsgError?.(filename || '', e as Error)\n return\n }\n throw e\n }\n\n storeMessage(\n descriptor,\n path,\n opts as Options,\n filename || undefined,\n messages\n )\n\n let idAttr: NodePath<t.JSXAttribute> | undefined\n let descriptionAttr: NodePath<t.JSXAttribute> | undefined\n let defaultMessageAttr: NodePath<t.JSXAttribute> | undefined\n const firstAttr = attributes[0]\n for (const attr of attributes) {\n if (!attr.isJSXAttribute()) {\n continue\n }\n switch (\n getMessageDescriptorKey((attr as NodePath<t.JSXAttribute>).get('name'))\n ) {\n case 'description':\n descriptionAttr = attr\n break\n case 'defaultMessage':\n defaultMessageAttr = attr\n break\n case 'id':\n idAttr = attr\n break\n }\n }\n\n // Insert ID before removing node to prevent null node insertBefore\n if (overrideIdFn || (descriptor.id && idInterpolationPattern)) {\n if (idAttr) {\n idAttr.get('value').replaceWith(t.stringLiteral(descriptor.id))\n } else if (firstAttr) {\n firstAttr.insertBefore(\n t.jsxAttribute(t.jsxIdentifier('id'), t.stringLiteral(descriptor.id))\n )\n }\n }\n\n if (descriptionAttr) {\n descriptionAttr.remove()\n }\n\n if (defaultMessageAttr) {\n if (removeDefaultMessage) {\n defaultMessageAttr.remove()\n } else if (ast && descriptor.defaultMessage) {\n defaultMessageAttr\n .get('value')\n .replaceWith(t.jsxExpressionContainer(t.nullLiteral()))\n const valueAttr = defaultMessageAttr.get(\n 'value'\n ) as NodePath<t.JSXExpressionContainer>\n valueAttr\n .get('expression')\n .replaceWithSourceString(\n JSON.stringify(parse(descriptor.defaultMessage))\n )\n }\n }\n\n // Tag the AST node so we don't try to extract it twice.\n tagAsExtracted(path)\n}\n","import {type PluginObj, type PluginPass} from '@babel/core'\nimport {declare} from '@babel/helper-plugin-utils'\nimport babelPluginSyntaxJsxNs from '@babel/plugin-syntax-jsx'\nimport {\n type ExtractedMessageDescriptor,\n type Options,\n type State,\n} from '#packages/babel-plugin-formatjs/types.js'\nimport {visitor as CallExpression} from '#packages/babel-plugin-formatjs/visitors/call-expression.js'\nimport {visitor as JSXOpeningElement} from '#packages/babel-plugin-formatjs/visitors/jsx-opening-element.js'\n\nconst babelPluginSyntaxJsx =\n (babelPluginSyntaxJsxNs as any).default || babelPluginSyntaxJsxNs\n\nexport type ExtractionResult<M = Record<string, string>> = {\n messages: ExtractedMessageDescriptor[]\n meta: M\n}\n\nexport const DEFAULT_ID_INTERPOLATION_PATTERN = '[sha512:contenthash:base64:6]'\n\nconst plugin: (\n api: object,\n options: Options | null | undefined,\n dirname: string\n) => PluginObj<PluginPass> =\n // @ts-expect-error PluginPass doesn't allow custom state but it actually does\n declare<Options, PluginObj>((api, options) => {\n api.assertVersion(7)\n if (!options.idInterpolationPattern) {\n options.idInterpolationPattern = DEFAULT_ID_INTERPOLATION_PATTERN\n }\n\n const {pragma} = options\n const componentNames = new Set<string>(options.additionalComponentNames)\n componentNames.add('FormattedMessage')\n const functionNames = new Set<string>(options.additionalFunctionNames)\n functionNames.add('formatMessage')\n // Short hand\n functionNames.add('$t')\n // Vue\n functionNames.add('$formatMessage')\n return {\n inherits: babelPluginSyntaxJsx,\n pre() {\n this.componentNames = Array.from(componentNames)\n this.functionNames = Array.from(functionNames)\n },\n\n visitor: {\n Program: {\n enter(this: PluginPass & State, path) {\n this.messages = []\n this.meta = {}\n if (!pragma) {\n return\n }\n for (const {leadingComments} of path.node.body) {\n if (!leadingComments) {\n continue\n }\n const pragmaLineNode = leadingComments.find(c =>\n c.value.includes(pragma)\n )\n if (!pragmaLineNode) {\n continue\n }\n\n pragmaLineNode.value\n .split(pragma)[1]\n .trim()\n .split(/\\s+/g)\n .forEach(kv => {\n const [k, v] = kv.split(':')\n this.meta[k] = v\n })\n }\n },\n exit(\n this: PluginPass & State,\n _,\n {\n opts: _opts,\n file: {\n opts: {filename},\n },\n }\n ) {\n const opts = _opts as Options\n if (typeof opts?.onMetaExtracted === 'function') {\n opts.onMetaExtracted(filename || '', this.meta)\n }\n if (typeof opts?.onMsgExtracted === 'function') {\n opts.onMsgExtracted(filename || '', this.messages)\n }\n },\n },\n JSXOpeningElement,\n CallExpression,\n // GH #4471: Handle optional chaining calls (e.g., intl.formatMessage?.())\n OptionalCallExpression: CallExpression,\n },\n }\n })\nexport default plugin\n"],"mappings":";;;;;;;;AAiBA,MAAM,mCAAmB,IAAI,IAAiC;CAC5D;CACA;CACA;AACF,CAAC;AAED,SAAS,aAAa,MAA6B;CACjD,MAAM,YAAY,KAAK,SAAS;CAChC,IAAI,UAAU,WACZ,OAAO,UAAU;CAGnB,MAAM,KAAK,oBACT,wEACF;AACF;AAEA,SAAgB,wBAAwB,MAA6B;CACnE,IAAI,KAAK,aAAa,KAAK,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AM;KACpC,KAAK,WAAW,CAAC;KACjB,KAAK,OAAO,CAAC;KACb,IAAI,CAAC,QACH;KAEF,KAAK,MAAM,EAAC,qBAAoB,KAAK,KAAK,MAAM;MAC9C,IAAI,CAAC,iBACH;MAEF,MAAM,iBAAiB,gBAAgB,MAAK,MAC1C,EAAE,MAAM,SAAS,MAAM,CACzB;MACA,IAAI,CAAC,gBACH;MAGF,eAAe,MACZ,MAAM,MAAM,CAAC,CAAC,EAAE,CAChB,KAAK,CAAC,CACN,MAAM,MAAM,CAAC,CACb,SAAQ,OAAM;OACb,MAAM,CAAC,GAAG,KAAK,GAAG,MAAM,GAAG;OAC3B,KAAK,KAAK,KAAK;MACjB,CAAC;KACL;IACF;IACA,KAEE,GACA,EACE,MAAM,OACN,MAAM,EACJ,MAAM,EAAC,gBAGX;KACA,MAAM,OAAO;KACb,IAAI,OAAO,MAAM,oBAAoB,YACnC,KAAK,gBAAgB,YAAY,IAAI,KAAK,IAAI;KAEhD,IAAI,OAAO,MAAM,mBAAmB,YAClC,KAAK,eAAe,YAAY,IAAI,KAAK,QAAQ;IAErD;GACF;GACA,mBAAA;GACA,gBAAA;GAEA,wBAAwBC;EAC1B;CACF;AACF,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["visitor"],"sources":["../utils.ts","../visitors/call-expression.ts","../visitors/jsx-opening-element.ts","../index.ts"],"sourcesContent":["import type * as t from '@babel/types'\nimport {parse} from '@formatjs/icu-messageformat-parser'\nimport {hoistSelectors} from '@formatjs/icu-messageformat-parser/manipulator.js'\nimport {printAST} from '@formatjs/icu-messageformat-parser/printer.js'\nimport {\n interpolateName,\n normalizeMessageWhitespace,\n} from '@formatjs/ts-transformer'\n\nimport {type NodePath} from '@babel/core'\nimport {\n type ExtractedMessageDescriptor,\n type MessageDescriptor,\n type MessageDescriptorPath,\n type Options,\n} from '#packages/babel-plugin-formatjs/types.js'\n\nconst DESCRIPTOR_PROPS = new Set<keyof MessageDescriptorPath>([\n 'id',\n 'description',\n 'defaultMessage',\n])\n\nfunction evaluatePath(path: NodePath<any>): string {\n const evaluated = path.evaluate()\n if (evaluated.confident) {\n return evaluated.value\n }\n\n throw path.buildCodeFrameError(\n '[React Intl] Messages must be statically evaluate-able for extraction.'\n )\n}\n\nexport function getMessageDescriptorKey(path: NodePath<any>): string {\n if (path.isIdentifier() || path.isJSXIdentifier()) {\n return path.node.name\n }\n\n return evaluatePath(path)\n}\n\nfunction getMessageDescriptorValue(\n path?:\n | NodePath<t.StringLiteral>\n | NodePath<t.JSXExpressionContainer>\n | NodePath<t.TemplateLiteral>,\n isMessageNode?: boolean\n) {\n if (!path) {\n return ''\n }\n if (path.isJSXExpressionContainer()) {\n // If this is already compiled, no need to recompiled it\n if (isMessageNode && path.get('expression').isArrayExpression()) {\n return ''\n }\n path = path.get('expression') as NodePath<t.StringLiteral>\n }\n\n // Always trim the Message Descriptor values.\n const descriptorValue = evaluatePath(path)\n\n return descriptorValue\n}\n\nexport function createMessageDescriptor(\n propPaths: [\n NodePath<t.JSXIdentifier> | NodePath<t.Identifier>,\n NodePath<t.StringLiteral> | NodePath<t.JSXExpressionContainer>,\n ][]\n): MessageDescriptorPath {\n return propPaths.reduce(\n (hash: MessageDescriptorPath, [keyPath, valuePath]) => {\n const key = getMessageDescriptorKey(\n keyPath\n ) as keyof MessageDescriptorPath\n\n if (DESCRIPTOR_PROPS.has(key)) {\n hash[key] = valuePath\n }\n\n return hash\n },\n {\n id: undefined,\n defaultMessage: undefined,\n description: undefined,\n }\n )\n}\n\nexport function evaluateMessageDescriptor(\n descriptorPath: MessageDescriptorPath,\n isJSXSource = false,\n filename: string | undefined,\n idInterpolationPattern?: string,\n overrideIdFn?: Options['overrideIdFn'],\n preserveWhitespace?: Options['preserveWhitespace'],\n flatten?: Options['flatten']\n): MessageDescriptor {\n let id = getMessageDescriptorValue(descriptorPath.id)\n let defaultMessage = getICUMessageValue(\n descriptorPath.defaultMessage,\n {\n isJSXSource,\n },\n preserveWhitespace\n )\n const description = getMessageDescriptorValue(descriptorPath.description)\n\n // GH #3537: Apply flatten transformation before calling overrideIdFn\n // so that the ID generation sees the same message format as the final output\n if (flatten && defaultMessage) {\n try {\n defaultMessage = printAST(hoistSelectors(parse(defaultMessage)))\n } catch (e: any) {\n const loc = descriptorPath.defaultMessage?.node.loc\n const locationStr = loc\n ? ` at line ${loc.start.line}, column ${loc.start.column + 1}`\n : ''\n throw new Error(\n `[formatjs] Cannot flatten message in file \"${filename}\"${locationStr}${id ? ` with id \"${id}\"` : ''}: ${e.message}\\nMessage: ${defaultMessage}`\n )\n }\n }\n\n if (overrideIdFn) {\n id = overrideIdFn(id, defaultMessage, description, filename)\n } else if (!id && idInterpolationPattern && defaultMessage) {\n id = interpolateName(\n {resourcePath: filename} as any,\n idInterpolationPattern,\n {\n content: description\n ? `${defaultMessage}#${description}`\n : defaultMessage,\n }\n )\n }\n const descriptor: MessageDescriptor = {\n id,\n }\n\n if (description) {\n descriptor.description = description\n }\n if (defaultMessage) {\n descriptor.defaultMessage = defaultMessage\n }\n\n return descriptor\n}\n\nfunction getICUMessageValue(\n messagePath?:\n | NodePath<t.StringLiteral>\n | NodePath<t.TemplateLiteral>\n | NodePath<t.JSXExpressionContainer>,\n {isJSXSource = false} = {},\n preserveWhitespace?: Options['preserveWhitespace']\n) {\n if (!messagePath) {\n return ''\n }\n let message = getMessageDescriptorValue(messagePath, true)\n\n if (!preserveWhitespace) {\n message = normalizeMessageWhitespace(message)\n }\n\n try {\n parse(message)\n } catch (parseError) {\n if (\n isJSXSource &&\n messagePath.isLiteral() &&\n message.indexOf('\\\\\\\\') >= 0\n ) {\n throw messagePath.buildCodeFrameError(\n '[React Intl] Message failed to parse. ' +\n 'It looks like `\\\\`s were used for escaping, ' +\n \"this won't work with JSX string literals. \" +\n 'Wrap with `{}`. ' +\n 'See: http://facebook.github.io/react/docs/jsx-gotchas.html'\n )\n }\n\n throw messagePath.buildCodeFrameError(\n '[React Intl] Message failed to parse. ' +\n 'See: https://formatjs.github.io/docs/core-concepts/icu-syntax' +\n `\\n${parseError}`\n )\n }\n return message\n}\nconst EXTRACTED = Symbol('FormatJSExtracted')\n/**\n * Tag a node as extracted\n * Store this in the node itself so that multiple passes work. Specifically\n * if we remove `description` in the 1st pass, 2nd pass will fail since\n * it expect `description` to be there.\n * HACK: We store this in the node instance since this persists across\n * multiple plugin runs\n * @param path\n */\nexport function tagAsExtracted(path: NodePath<any>): void {\n path.node[EXTRACTED] = true\n}\n/**\n * Check if a node was extracted\n * @param path\n */\nexport function wasExtracted(path: NodePath<any>): boolean {\n return !!path.node[EXTRACTED]\n}\n\n/**\n * Store a message in our global messages\n * @param messageDescriptor\n * @param path\n * @param opts\n * @param filename\n * @param messages\n */\nexport function storeMessage(\n {id, description, defaultMessage}: MessageDescriptor,\n path: NodePath<any>,\n {extractSourceLocation}: Options,\n\n filename: string | undefined,\n messages: ExtractedMessageDescriptor[]\n): void {\n if (!id && !defaultMessage) {\n throw path.buildCodeFrameError(\n '[React Intl] Message Descriptors require an `id` or `defaultMessage`.'\n )\n }\n\n let loc = {}\n if (extractSourceLocation) {\n loc = {\n file: filename,\n ...path.node.loc,\n }\n }\n messages.push({id, description, defaultMessage, ...loc})\n}\n","import {type NodePath, type PluginPass} from '@babel/core'\nimport * as t from '@babel/types'\nimport {\n type MessageDescriptor,\n type MessageDescriptorPath,\n type Options,\n type State,\n type VisitorFunction,\n} from '#packages/babel-plugin-formatjs/types.js'\nimport {\n createMessageDescriptor,\n evaluateMessageDescriptor,\n wasExtracted,\n storeMessage,\n tagAsExtracted,\n} from '#packages/babel-plugin-formatjs/utils.js'\nimport {parse} from '@formatjs/icu-messageformat-parser'\n\nfunction assertObjectExpression(\n path: NodePath<any>,\n callee: NodePath<t.Expression | t.Super | t.Import | t.V8IntrinsicIdentifier>\n): asserts path is NodePath<t.ObjectExpression> {\n if (!path || !path.isObjectExpression()) {\n throw path.buildCodeFrameError(\n `[React Intl] \\`${\n (callee.get('property') as NodePath<t.Identifier>).node.name\n }()\\` must be called with an object expression with values that are React Intl Message Descriptors, also defined as object expressions.`\n )\n }\n}\n\nfunction isFormatMessageCall(\n callee: NodePath<t.Expression | t.Super | t.Import | t.V8IntrinsicIdentifier>,\n functionNames: string[]\n) {\n if (functionNames.find(name => callee.isIdentifier({name}))) {\n return true\n }\n\n // GH #4471: Handle both MemberExpression and OptionalMemberExpression\n // (e.g., intl.formatMessage() and intl.formatMessage?.())\n if (callee.isMemberExpression() || callee.isOptionalMemberExpression()) {\n const property = callee.get('property') as NodePath<t.MemberExpression>\n return !!functionNames.find(name => property.isIdentifier({name}))\n }\n return false\n}\n\nfunction getMessagesObjectFromExpression(\n nodePath: NodePath<any>\n): NodePath<any> {\n let currentPath = nodePath\n while (\n t.isTSAsExpression(currentPath.node) ||\n t.isTSTypeAssertion(currentPath.node) ||\n t.isTypeCastExpression(currentPath.node)\n ) {\n currentPath = currentPath.get('expression') as NodePath<any>\n }\n return currentPath\n}\n\ntype CallExpressionPath = Parameters<VisitorFunction<'CallExpression'>>[0]\ntype OptionalCallExpressionPath = Parameters<\n VisitorFunction<'OptionalCallExpression'>\n>[0]\n\nconst visitCallExpression = function (\n this: PluginPass & State,\n path: CallExpressionPath | OptionalCallExpressionPath,\n {\n opts,\n file: {\n opts: {filename},\n },\n }: PluginPass & State\n) {\n const {\n overrideIdFn,\n idInterpolationPattern,\n removeDefaultMessage,\n ast,\n preserveWhitespace,\n flatten,\n throws,\n onMsgError,\n } = opts as Options\n if (wasExtracted(path)) {\n return\n }\n const {messages, functionNames} = this\n const callee = path.get('callee')\n const args = path.get('arguments')\n\n /**\n * Process MessageDescriptor\n * @param messageDescriptor Message Descriptor\n */\n function processMessageObject(\n messageDescriptor: NodePath<t.ObjectExpression>\n ) {\n assertObjectExpression(messageDescriptor, callee)\n\n const properties = messageDescriptor.get(\n 'properties'\n ) as NodePath<t.ObjectProperty>[]\n\n let descriptorPath: MessageDescriptorPath\n let descriptor: MessageDescriptor\n try {\n descriptorPath = createMessageDescriptor(\n properties.map(\n prop =>\n [prop.get('key'), prop.get('value')] as [\n NodePath<t.Identifier>,\n NodePath<t.StringLiteral>,\n ]\n )\n )\n\n // If the message is already compiled, don't re-compile it\n if (descriptorPath.defaultMessage?.isArrayExpression()) {\n return\n }\n\n descriptor = evaluateMessageDescriptor(\n descriptorPath,\n false,\n filename || undefined,\n idInterpolationPattern,\n overrideIdFn,\n preserveWhitespace,\n flatten\n )\n } catch (e) {\n if (throws === false) {\n tagAsExtracted(path)\n onMsgError?.(filename || '', e as Error)\n return\n }\n throw e\n }\n storeMessage(\n descriptor,\n messageDescriptor,\n opts as Options,\n filename || undefined,\n messages\n )\n\n const firstProp = properties[0]\n const defaultMessageProp = properties.find(prop => {\n const keyProp = prop.get('key')\n return (\n keyProp.isIdentifier({name: 'defaultMessage'}) ||\n keyProp.isStringLiteral({value: 'defaultMessage'})\n )\n })\n const idProp = properties.find(prop => {\n const keyProp = prop.get('key')\n return (\n keyProp.isIdentifier({name: 'id'}) ||\n keyProp.isStringLiteral({value: 'id'})\n )\n })\n\n // Insert ID potentially 1st before removing nodes\n if (idProp) {\n idProp.get('value').replaceWith(t.stringLiteral(descriptor.id))\n } else {\n firstProp.insertBefore(\n t.objectProperty(t.identifier('id'), t.stringLiteral(descriptor.id))\n )\n }\n\n // Remove description\n properties\n .find(prop => {\n const keyProp = prop.get('key')\n return (\n keyProp.isIdentifier({name: 'description'}) ||\n keyProp.isStringLiteral({value: 'description'})\n )\n })\n ?.remove()\n\n // Pre-parse or remove defaultMessage\n if (defaultMessageProp) {\n if (removeDefaultMessage) {\n defaultMessageProp?.remove()\n } else if (descriptor.defaultMessage) {\n const valueProp = defaultMessageProp.get('value')\n if (ast) {\n valueProp.replaceWithSourceString(\n JSON.stringify(parse(descriptor.defaultMessage))\n )\n } else {\n valueProp.replaceWith(t.stringLiteral(descriptor.defaultMessage))\n }\n }\n }\n\n tagAsExtracted(path)\n }\n\n // Check that this is `defineMessages` call\n if (\n callee.isIdentifier({name: 'defineMessages'}) ||\n callee.isIdentifier({name: 'defineMessage'})\n ) {\n const firstArgument = args[0]\n const messagesObj = getMessagesObjectFromExpression(firstArgument)\n\n assertObjectExpression(messagesObj, callee)\n if (callee.isIdentifier({name: 'defineMessage'})) {\n processMessageObject(messagesObj as NodePath<t.ObjectExpression>)\n } else {\n const properties = messagesObj.get('properties')\n if (Array.isArray(properties)) {\n properties\n .map(prop => prop.get('value') as NodePath<t.ObjectExpression>)\n .forEach(processMessageObject)\n }\n }\n }\n\n // Check that this is `intl.formatMessage` call\n if (isFormatMessageCall(callee, functionNames)) {\n const messageDescriptor = args[0]\n if (messageDescriptor && messageDescriptor.isObjectExpression()) {\n processMessageObject(messageDescriptor)\n }\n }\n}\n\nexport const visitor: VisitorFunction<'CallExpression'> = visitCallExpression\nexport const optionalVisitor: VisitorFunction<'OptionalCallExpression'> =\n visitCallExpression\n","import {type NodePath} from '@babel/core'\n\nimport {\n type MessageDescriptor,\n type MessageDescriptorPath,\n type Options,\n type VisitorFunction,\n} from '#packages/babel-plugin-formatjs/types.js'\nimport * as t from '@babel/types'\nimport {parse} from '@formatjs/icu-messageformat-parser'\nimport {\n createMessageDescriptor,\n evaluateMessageDescriptor,\n getMessageDescriptorKey,\n storeMessage,\n tagAsExtracted,\n wasExtracted,\n} from '#packages/babel-plugin-formatjs/utils.js'\n\nexport const visitor: VisitorFunction<'JSXOpeningElement'> = function (\n path,\n {\n opts,\n file: {\n opts: {filename},\n },\n }\n) {\n const {\n removeDefaultMessage,\n idInterpolationPattern,\n overrideIdFn,\n ast,\n preserveWhitespace,\n flatten,\n throws,\n onMsgError,\n } = opts as Options\n\n const {componentNames, messages} = this\n if (wasExtracted(path)) {\n return\n }\n\n const name = path.get('name')\n\n if (!componentNames.find(n => name.isJSXIdentifier({name: n}))) {\n return\n }\n\n const attributes = path\n .get('attributes')\n .filter(attr => attr.isJSXAttribute())\n\n let descriptorPath: MessageDescriptorPath\n let descriptor: MessageDescriptor\n try {\n descriptorPath = createMessageDescriptor(\n attributes.map(attr => [\n attr.get('name') as NodePath<t.JSXIdentifier>,\n attr.get('value') as\n | NodePath<t.StringLiteral>\n | NodePath<t.JSXExpressionContainer>,\n ])\n )\n\n // In order for a default message to be extracted when\n // declaring a JSX element, it must be done with standard\n // `key=value` attributes. But it's completely valid to\n // write `<FormattedMessage {...descriptor} />`, because it will be\n // skipped here and extracted elsewhere. The descriptor will\n // be extracted only (storeMessage) if a `defaultMessage` prop.\n if (!descriptorPath.defaultMessage) {\n return\n }\n\n descriptor = evaluateMessageDescriptor(\n descriptorPath,\n true,\n filename || undefined,\n idInterpolationPattern,\n overrideIdFn,\n preserveWhitespace,\n flatten\n )\n } catch (e) {\n if (throws === false) {\n tagAsExtracted(path)\n onMsgError?.(filename || '', e as Error)\n return\n }\n throw e\n }\n\n storeMessage(\n descriptor,\n path,\n opts as Options,\n filename || undefined,\n messages\n )\n\n let idAttr: NodePath<t.JSXAttribute> | undefined\n let descriptionAttr: NodePath<t.JSXAttribute> | undefined\n let defaultMessageAttr: NodePath<t.JSXAttribute> | undefined\n const firstAttr = attributes[0]\n for (const attr of attributes) {\n if (!attr.isJSXAttribute()) {\n continue\n }\n switch (\n getMessageDescriptorKey((attr as NodePath<t.JSXAttribute>).get('name'))\n ) {\n case 'description':\n descriptionAttr = attr\n break\n case 'defaultMessage':\n defaultMessageAttr = attr\n break\n case 'id':\n idAttr = attr\n break\n }\n }\n\n // Insert ID before removing node to prevent null node insertBefore\n if (overrideIdFn || (descriptor.id && idInterpolationPattern)) {\n if (idAttr) {\n idAttr.get('value').replaceWith(t.stringLiteral(descriptor.id))\n } else if (firstAttr) {\n firstAttr.insertBefore(\n t.jsxAttribute(t.jsxIdentifier('id'), t.stringLiteral(descriptor.id))\n )\n }\n }\n\n if (descriptionAttr) {\n descriptionAttr.remove()\n }\n\n if (defaultMessageAttr) {\n if (removeDefaultMessage) {\n defaultMessageAttr.remove()\n } else if (ast && descriptor.defaultMessage) {\n defaultMessageAttr\n .get('value')\n .replaceWith(t.jsxExpressionContainer(t.nullLiteral()))\n const valueAttr = defaultMessageAttr.get(\n 'value'\n ) as NodePath<t.JSXExpressionContainer>\n valueAttr\n .get('expression')\n .replaceWithSourceString(\n JSON.stringify(parse(descriptor.defaultMessage))\n )\n }\n }\n\n // Tag the AST node so we don't try to extract it twice.\n tagAsExtracted(path)\n}\n","import {type PluginPass, type PluginTarget} from '@babel/core'\nimport {declare} from '@babel/helper-plugin-utils'\nimport babelPluginSyntaxJsxNs from '@babel/plugin-syntax-jsx'\nimport {\n type ExtractedMessageDescriptor,\n type Options,\n type State,\n} from '#packages/babel-plugin-formatjs/types.js'\nimport {\n optionalVisitor as OptionalCallExpression,\n visitor as CallExpression,\n} from '#packages/babel-plugin-formatjs/visitors/call-expression.js'\nimport {visitor as JSXOpeningElement} from '#packages/babel-plugin-formatjs/visitors/jsx-opening-element.js'\n\nconst babelPluginSyntaxJsx =\n (babelPluginSyntaxJsxNs as any).default || babelPluginSyntaxJsxNs\n\nexport type ExtractionResult<M = Record<string, string>> = {\n messages: ExtractedMessageDescriptor[]\n meta: M\n}\n\nexport const DEFAULT_ID_INTERPOLATION_PATTERN = '[sha512:contenthash:base64:6]'\n\ntype FormatJSPlugin = PluginTarget & ReturnType<typeof declare<State, Options>>\n\nconst plugin: FormatJSPlugin = declare<State, Options>((api, options) => {\n api.assertVersion(8)\n if (!options.idInterpolationPattern) {\n options.idInterpolationPattern = DEFAULT_ID_INTERPOLATION_PATTERN\n }\n\n const {pragma} = options\n const componentNames = new Set<string>(options.additionalComponentNames)\n componentNames.add('FormattedMessage')\n const functionNames = new Set<string>(options.additionalFunctionNames)\n functionNames.add('formatMessage')\n // Short hand\n functionNames.add('$t')\n // Vue\n functionNames.add('$formatMessage')\n return {\n inherits: babelPluginSyntaxJsx,\n pre() {\n this.componentNames = Array.from(componentNames)\n this.functionNames = Array.from(functionNames)\n },\n\n visitor: {\n Program: {\n enter(this: PluginPass & State, path) {\n this.messages = []\n this.meta = {}\n if (!pragma) {\n return\n }\n for (const {leadingComments} of path.node.body) {\n if (!leadingComments) {\n continue\n }\n const pragmaLineNode = leadingComments.find(c =>\n c.value.includes(pragma)\n )\n if (!pragmaLineNode) {\n continue\n }\n\n pragmaLineNode.value\n .split(pragma)[1]\n .trim()\n .split(/\\s+/g)\n .forEach(kv => {\n const [k, v] = kv.split(':')\n this.meta[k] = v\n })\n }\n },\n exit(\n this: PluginPass & State,\n _,\n {\n opts: _opts,\n file: {\n opts: {filename},\n },\n }\n ) {\n const opts = _opts as Options\n if (typeof opts?.onMetaExtracted === 'function') {\n opts.onMetaExtracted(filename || '', this.meta)\n }\n if (typeof opts?.onMsgExtracted === 'function') {\n opts.onMsgExtracted(filename || '', this.messages)\n }\n },\n },\n JSXOpeningElement,\n CallExpression,\n // GH #4471: Handle optional chaining calls (e.g., intl.formatMessage?.())\n OptionalCallExpression,\n },\n }\n}) as FormatJSPlugin\nexport default plugin\n"],"mappings":";;;;;;;;AAiBA,MAAM,mCAAmB,IAAI,IAAiC;CAC5D;CACA;CACA;AACF,CAAC;AAED,SAAS,aAAa,MAA6B;CACjD,MAAM,YAAY,KAAK,SAAS;CAChC,IAAI,UAAU,WACZ,OAAO,UAAU;CAGnB,MAAM,KAAK,oBACT,wEACF;AACF;AAEA,SAAgB,wBAAwB,MAA6B;CACnE,IAAI,KAAK,aAAa,KAAK,KAAK,gBAAgB,GAC9C,OAAO,KAAK,KAAK;CAGnB,OAAO,aAAa,IAAI;AAC1B;AAEA,SAAS,0BACP,MAIA,eACA;CACA,IAAI,CAAC,MACH,OAAO;CAET,IAAI,KAAK,yBAAyB,GAAG;EAEnC,IAAI,iBAAiB,KAAK,IAAI,YAAY,CAAC,CAAC,kBAAkB,GAC5D,OAAO;EAET,OAAO,KAAK,IAAI,YAAY;CAC9B;CAKA,OAFwB,aAAa,IAEhB;AACvB;AAEA,SAAgB,wBACd,WAIuB;CACvB,OAAO,UAAU,QACd,MAA6B,CAAC,SAAS,eAAe;EACrD,MAAM,M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,OAAM;OACb,MAAM,CAAC,GAAG,KAAK,GAAG,MAAM,GAAG;OAC3B,KAAK,KAAK,KAAK;MACjB,CAAC;KACL;IACF;IACA,KAEE,GACA,EACE,MAAM,OACN,MAAM,EACJ,MAAM,EAAC,gBAGX;KACA,MAAM,OAAO;KACb,IAAI,OAAO,MAAM,oBAAoB,YACnC,KAAK,gBAAgB,YAAY,IAAI,KAAK,IAAI;KAEhD,IAAI,OAAO,MAAM,mBAAmB,YAClC,KAAK,eAAe,YAAY,IAAI,KAAK,QAAQ;IAErD;GACF;GACA,mBAAA;GACA,gBAAA;GAEA,wBAAA;EACF;CACF;AACF,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "babel-plugin-formatjs",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "12.0.0",
|
|
4
4
|
"description": "Extracts string messages for translation from modules that use formatjs.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"babel-plugin",
|
|
@@ -21,15 +21,14 @@
|
|
|
21
21
|
".": "./index.js"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@babel/core": "
|
|
25
|
-
"@babel/helper-plugin-utils": "
|
|
26
|
-
"@babel/plugin-syntax-jsx": "
|
|
27
|
-
"@babel/
|
|
28
|
-
"@
|
|
29
|
-
"@formatjs/
|
|
30
|
-
"@formatjs/ts-transformer": "4.4.16",
|
|
24
|
+
"@babel/core": "8",
|
|
25
|
+
"@babel/helper-plugin-utils": "8",
|
|
26
|
+
"@babel/plugin-syntax-jsx": "8",
|
|
27
|
+
"@babel/types": "8",
|
|
28
|
+
"@formatjs/icu-messageformat-parser": "3.5.15",
|
|
29
|
+
"@formatjs/ts-transformer": "4.4.17",
|
|
31
30
|
"@types/babel__core": "7",
|
|
32
31
|
"@types/babel__helper-plugin-utils": "7",
|
|
33
|
-
"@types/
|
|
32
|
+
"@types/convert-source-map": "2"
|
|
34
33
|
}
|
|
35
34
|
}
|