babel-plugin-formatjs
Advanced tools
Comparing version 8.3.0 to 8.4.0
38
index.js
@@ -139,29 +139,8 @@ "use strict"; | ||
} | ||
function isFormatMessageDestructuring(scope) { | ||
var binding = scope.getBinding('formatMessage'); | ||
var block = scope.block; | ||
var declNode = binding === null || binding === void 0 ? void 0 : binding.path.node; | ||
// things like `const {formatMessage} = intl; formatMessage(...)` | ||
if (core_1.types.isVariableDeclarator(declNode)) { | ||
// things like `const {formatMessage} = useIntl(); formatMessage(...)` | ||
if (core_1.types.isCallExpression(declNode.init)) { | ||
if (core_1.types.isIdentifier(declNode.init.callee)) { | ||
return declNode.init.callee.name === 'useIntl'; | ||
} | ||
} | ||
return (core_1.types.isObjectPattern(declNode.id) && | ||
declNode.id.properties.find(function (value) { return value.key.name === 'intl'; })); | ||
} | ||
// things like const fn = ({ intl: { formatMessage }}) => { formatMessage(...) } | ||
if (core_1.types.isFunctionDeclaration(block) && | ||
block.params.length && | ||
core_1.types.isObjectPattern(block.params[0])) { | ||
return block.params[0].properties.find(function (value) { return value.key.name === 'intl'; }); | ||
} | ||
return false; | ||
} | ||
function isFormatMessageCall(callee, path) { | ||
if (callee.isIdentifier() && | ||
callee.node.name === 'formatMessage' && | ||
isFormatMessageDestructuring(path.scope)) { | ||
function isFormatMessageCall(callee, additionalFunctionNames) { | ||
var fnNames = new Set(tslib_1.__spreadArrays([ | ||
'formatMessage', | ||
'$formatMessage' | ||
], additionalFunctionNames)); | ||
if (callee.isIdentifier() && fnNames.has(callee.node.name)) { | ||
return true; | ||
@@ -343,3 +322,3 @@ } | ||
var messages = this.ReactIntlMessages; | ||
var _b = opts.moduleSourceName, moduleSourceName = _b === void 0 ? 'react-intl' : _b, overrideIdFn = opts.overrideIdFn, idInterpolationPattern = opts.idInterpolationPattern, removeDefaultMessage = opts.removeDefaultMessage, extractFromFormatMessageCall = opts.extractFromFormatMessageCall, ast = opts.ast; | ||
var _b = opts.moduleSourceName, moduleSourceName = _b === void 0 ? 'react-intl' : _b, overrideIdFn = opts.overrideIdFn, idInterpolationPattern = opts.idInterpolationPattern, removeDefaultMessage = opts.removeDefaultMessage, extractFromFormatMessageCall = opts.extractFromFormatMessageCall, _c = opts.additionalFunctionNames, additionalFunctionNames = _c === void 0 ? [] : _c, ast = opts.ast; | ||
var callee = path.get('callee'); | ||
@@ -393,3 +372,4 @@ /** | ||
// Check that this is `intl.formatMessage` call | ||
if (extractFromFormatMessageCall && isFormatMessageCall(callee, path)) { | ||
if (extractFromFormatMessageCall && | ||
isFormatMessageCall(callee, additionalFunctionNames)) { | ||
var messageDescriptor = path.get('arguments')[0]; | ||
@@ -396,0 +376,0 @@ if (messageDescriptor.isObjectExpression()) { |
@@ -12,2 +12,3 @@ /** | ||
additionalComponentNames?: string[]; | ||
additionalFunctionNames?: string[]; | ||
pragma?: string; | ||
@@ -14,0 +15,0 @@ extractFromFormatMessageCall?: boolean; |
@@ -12,2 +12,3 @@ { | ||
"additionalComponentNames": { "type": "array", "items": { "type": "string" } }, | ||
"additionalFunctionNames": { "type": "array", "items": { "type": "string" } }, | ||
"pragma": { "type": "string" }, | ||
@@ -14,0 +15,0 @@ "extractFromFormatMessageCall": { "type": "boolean" }, |
{ | ||
"name": "babel-plugin-formatjs", | ||
"version": "8.3.0", | ||
"version": "8.4.0", | ||
"description": "Extracts string messages for translation from modules that use React Intl.", | ||
@@ -5,0 +5,0 @@ "repository": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
24982
458