Socket
Socket
Sign inDemoInstall

@lingui/babel-plugin-extract-messages

Package Overview
Dependencies
Maintainers
1
Versions
145
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@lingui/babel-plugin-extract-messages - npm Package Compare versions

Comparing version 3.12.1 to 3.13.0

140

index.js

@@ -41,31 +41,103 @@ "use strict";

comment = _ref.comment,
props = (0, _objectWithoutProperties2.default)(_ref, ["id", "message", "origin", "comment"]);
context = _ref.context,
props = (0, _objectWithoutProperties2.default)(_ref, ["id", "message", "origin", "comment", "context"]);
// prevent from adding undefined msgid
if (id === undefined) return;
var extractedComments = comment ? [comment] : [];
if (messages.has(id)) {
var message = messages.get(id); // only set/check default language when it's defined.
if (context) {
if (messages.has(context)) {
var existingContext = messages.get(context);
if (message.message && newDefault && message.message !== newDefault) {
throw path.buildCodeFrameError("Different defaults for the same message ID.");
}
if (existingContext.has(id)) {
var message = messages.get(id); // only set/check default language when it's defined.
if (newDefault) {
message.message = newDefault;
if (message.message && newDefault && message.message !== newDefault) {
throw path.buildCodeFrameError("Different defaults for the same message ID.");
}
if (newDefault) {
message.message = newDefault;
}
;
[].push.apply(message.origin, origin);
if (comment) {
;
[].push.apply(message.extractedComments, [comment]);
}
} else {
existingContext.set(id, _objectSpread(_objectSpread({}, props), {}, {
message: newDefault,
origin: origin,
extractedComments: extractedComments
}));
messages.set(context, existingContext);
}
} else {
var newContext = new Map();
newContext.set(id, _objectSpread(_objectSpread({}, props), {}, {
message: newDefault,
origin: origin,
extractedComments: extractedComments
}));
messages.set(context, newContext);
}
} else {
if (messages.has(id)) {
var _message = messages.get(id); // only set/check default language when it's defined.
;
[].push.apply(message.origin, origin);
if (comment) {
if (_message.message && newDefault && _message.message !== newDefault) {
throw path.buildCodeFrameError("Different defaults for the same message ID.");
}
if (newDefault) {
_message.message = newDefault;
}
;
[].push.apply(message.extractedComments, [comment]);
[].push.apply(_message.origin, origin);
if (comment) {
;
[].push.apply(_message.extractedComments, [comment]);
}
} else {
messages.set(id, _objectSpread(_objectSpread({}, props), {}, {
message: newDefault,
origin: origin,
extractedComments: extractedComments
}));
}
}
}
/**
* An ES6 Map type is not possible to encode with JSON.stringify,
* so we can instead use a replacer function as an argument to
* tell the JSON parser how to serialize / deserialize the Maps
* it encounters.
*/
function mapReplacer(key, value) {
if (value instanceof Map) {
var object = {};
value.forEach(function (v, k) {
return object[k] = v;
});
return object;
}
return value;
}
function extractStringContatentation(t, node, error) {
if (t.isStringLiteral(node)) {
return node.value;
} else if (t.isBinaryExpression(node)) {
return extractStringContatentation(t, node.left, error) + extractStringContatentation(t, node.right, error);
} else {
var extractedComments = comment ? [comment] : [];
messages.set(id, _objectSpread(_objectSpread({}, props), {}, {
message: newDefault,
origin: origin,
extractedComments: extractedComments
}));
throw error;
}

@@ -136,3 +208,3 @@ }

if (key === "id" || key === "message" || key === "comment") {
if (key === "id" || key === "message" || key === "comment" || key === "context") {
if (item.value.value) {

@@ -185,3 +257,3 @@ acc[key] = item.value.value;

var copyOptions = ["message", "comment"];
var copyOptions = ["message", "comment", "context"];

@@ -236,3 +308,3 @@ if (t.isObjectExpression(path.node.arguments[2])) {

var props = {};
var copyProps = ["id", "message", "comment"];
var copyProps = ["id", "message", "comment", "context"];
path.node.properties.filter(function (_ref8) {

@@ -242,13 +314,27 @@ var key = _ref8.key;

}).forEach(function (_ref9, i) {
var _value$quasis$, _value$quasis$$value;
var key = _ref9.key,
value = _ref9.value;
// By default, the value is just the string value of the object property.
var valueToExtract = value.value;
if (key.name === "comment" && !t.isStringLiteral(value)) {
throw path.get("properties.".concat(i, ".value")).buildCodeFrameError("Only strings are supported as comments.");
// Comments can be single or multi-line strings.
var errorIfNotAString = path.get("properties.".concat(i, ".value")).buildCodeFrameError("Only strings are supported as comments.");
if (t.isBinaryExpression(value)) {
valueToExtract = extractStringContatentation(t, value, errorIfNotAString);
} else {
throw errorIfNotAString;
}
} else if (key.name === "id") {
var isIdLiteral = !value.value && t.isTemplateLiteral(value);
if (isIdLiteral) {
var _value$quasis$, _value$quasis$$value;
valueToExtract = value === null || value === void 0 ? void 0 : (_value$quasis$ = value.quasis[0]) === null || _value$quasis$ === void 0 ? void 0 : (_value$quasis$$value = _value$quasis$.value) === null || _value$quasis$$value === void 0 ? void 0 : _value$quasis$$value.cooked;
}
}
var isIdLiteral = !value.value && key.name === "id" && t.isTemplateLiteral(value);
props[key.name] = isIdLiteral ? value === null || value === void 0 ? void 0 : (_value$quasis$ = value.quasis[0]) === null || _value$quasis$ === void 0 ? void 0 : (_value$quasis$$value = _value$quasis$.value) === null || _value$quasis$$value === void 0 ? void 0 : _value$quasis$$value.cooked : value.value;
props[key.name] = valueToExtract;
});

@@ -313,5 +399,5 @@ collectMessage(path, file, props);

_fs.default.writeFileSync(catalogFilename, JSON.stringify(catalog, null, 2));
_fs.default.writeFileSync(catalogFilename, JSON.stringify(catalog, mapReplacer, 2));
}
};
}

4

package.json
{
"name": "@lingui/babel-plugin-extract-messages",
"version": "3.12.1",
"version": "3.13.0",
"description": "Babel plugin for collecting messages from source code for internationalization",

@@ -33,5 +33,5 @@ "main": "index.js",

"@babel/runtime": "^7.11.2",
"@lingui/conf": "^3.12.1",
"@lingui/conf": "^3.13.0",
"mkdirp": "^1.0.4"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc