Socket
Socket
Sign inDemoInstall

@lingui/babel-plugin-extract-messages

Package Overview
Dependencies
Maintainers
3
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 4.0.0-next.1 to 4.0.0-next.2

27

./build/index.js

@@ -21,3 +21,3 @@ "use strict";

}
function getTextFromExpression(t, exp, hub) {
function getTextFromExpression(t, exp, hub, emitErrorOnVariable = true) {
if (t.isStringLiteral(exp)) {

@@ -27,3 +27,3 @@ return exp.value;

if (t.isBinaryExpression(exp)) {
return getTextFromExpression(t, exp.left, hub) + getTextFromExpression(t, exp.right, hub);
return getTextFromExpression(t, exp.left, hub, emitErrorOnVariable) + getTextFromExpression(t, exp.right, hub, emitErrorOnVariable);
}

@@ -38,3 +38,5 @@ if (t.isTemplateLiteral(exp)) {

}
console.warn(hub.buildError(exp, "Only strings or template literals could be extracted.", SyntaxError).message);
if (emitErrorOnVariable) {
console.warn(hub.buildError(exp, "Only strings or template literals could be extracted.", SyntaxError).message);
}
}

@@ -57,7 +59,2 @@ function extractFromObjectExpression(t, exp, hub, keys) {

let localTransComponentName;
// We need to remember all processed nodes. When JSX expressions are
// replaced with CallExpressions, all children are traversed for each CallExpression.
// Then, i18n._ methods are visited multiple times for each parent CallExpression.
const visitedNodes = new WeakSet();
function isTransComponent(node) {

@@ -128,3 +125,2 @@ return t.isJSXElement(node) && t.isJSXIdentifier(node.openingElement.name, {

CallExpression(path, ctx) {
if (visitedNodes.has(path.node)) return;
const hasComment = [path.node, path.parent].some(node => hasI18nComment(node));

@@ -140,9 +136,5 @@ const firstArgument = path.node.arguments[0];

let props = {
id: firstArgument.value
id: getTextFromExpression(t, firstArgument, ctx.file.hub, false)
};
if (!props.id) {
// don't rise warning when translating from variables
if (!t.isIdentifier(firstArgument)) {
console.warn(path.buildCodeFrameError("Missing message ID, skipping.").message);
}
return;

@@ -157,10 +149,8 @@ }

}
visitedNodes.add(path.node);
collectMessage(path, props, ctx);
},
StringLiteral(path, ctx) {
if (!hasI18nComment(path.node) || visitedNodes.has(path.node)) {
if (!hasI18nComment(path.node)) {
return;
}
visitedNodes.add(path.node);
const props = {

@@ -177,6 +167,5 @@ id: path.node.value

ObjectExpression(path, ctx) {
if (!hasI18nComment(path.node) || visitedNodes.has(path.node)) {
if (!hasI18nComment(path.node)) {
return;
}
visitedNodes.add(path.node);
const props = extractFromObjectExpression(t, path.node, ctx.file.hub, ["id", "message", "comment", "context"]);

@@ -183,0 +172,0 @@ if (!props.id) {

@@ -21,3 +21,3 @@ "use strict";

}
function getTextFromExpression(t, exp, hub) {
function getTextFromExpression(t, exp, hub, emitErrorOnVariable = true) {
if (t.isStringLiteral(exp)) {

@@ -27,3 +27,3 @@ return exp.value;

if (t.isBinaryExpression(exp)) {
return getTextFromExpression(t, exp.left, hub) + getTextFromExpression(t, exp.right, hub);
return getTextFromExpression(t, exp.left, hub, emitErrorOnVariable) + getTextFromExpression(t, exp.right, hub, emitErrorOnVariable);
}

@@ -38,3 +38,5 @@ if (t.isTemplateLiteral(exp)) {

}
console.warn(hub.buildError(exp, "Only strings or template literals could be extracted.", SyntaxError).message);
if (emitErrorOnVariable) {
console.warn(hub.buildError(exp, "Only strings or template literals could be extracted.", SyntaxError).message);
}
}

@@ -57,7 +59,2 @@ function extractFromObjectExpression(t, exp, hub, keys) {

let localTransComponentName;
// We need to remember all processed nodes. When JSX expressions are
// replaced with CallExpressions, all children are traversed for each CallExpression.
// Then, i18n._ methods are visited multiple times for each parent CallExpression.
const visitedNodes = new WeakSet();
function isTransComponent(node) {

@@ -128,3 +125,2 @@ return t.isJSXElement(node) && t.isJSXIdentifier(node.openingElement.name, {

CallExpression(path, ctx) {
if (visitedNodes.has(path.node)) return;
const hasComment = [path.node, path.parent].some(node => hasI18nComment(node));

@@ -140,9 +136,5 @@ const firstArgument = path.node.arguments[0];

let props = {
id: firstArgument.value
id: getTextFromExpression(t, firstArgument, ctx.file.hub, false)
};
if (!props.id) {
// don't rise warning when translating from variables
if (!t.isIdentifier(firstArgument)) {
console.warn(path.buildCodeFrameError("Missing message ID, skipping.").message);
}
return;

@@ -157,10 +149,8 @@ }

}
visitedNodes.add(path.node);
collectMessage(path, props, ctx);
},
StringLiteral(path, ctx) {
if (!hasI18nComment(path.node) || visitedNodes.has(path.node)) {
if (!hasI18nComment(path.node)) {
return;
}
visitedNodes.add(path.node);
const props = {

@@ -177,6 +167,5 @@ id: path.node.value

ObjectExpression(path, ctx) {
if (!hasI18nComment(path.node) || visitedNodes.has(path.node)) {
if (!hasI18nComment(path.node)) {
return;
}
visitedNodes.add(path.node);
const props = extractFromObjectExpression(t, path.node, ctx.file.hub, ["id", "message", "comment", "context"]);

@@ -183,0 +172,0 @@ if (!props.id) {

{
"name": "@lingui/babel-plugin-extract-messages",
"version": "4.0.0-next.1",
"version": "4.0.0-next.2",
"description": "Babel plugin for collecting messages from source code for internationalization",

@@ -44,3 +44,3 @@ "main": "./build/index.js",

},
"gitHead": "27ee8e213ff6d0c7a0cd2b21c573d7f6da43fd85"
"gitHead": "556ab57e20c2ac9d384a22424c6a90c2ba0dd133"
}
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