Socket
Socket
Sign inDemoInstall

@lingui/macro

Package Overview
Dependencies
Maintainers
1
Versions
115
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@lingui/macro - npm Package Compare versions

Comparing version 3.1.0 to 3.2.0

CHANGELOG.md

146

index.js

@@ -1,145 +0,1 @@

"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
var _babelPluginMacros = require("babel-plugin-macros");
var _conf = require("@lingui/conf");
var _macroJs = _interopRequireDefault(require("./macroJs"));
var _macroJsx = _interopRequireDefault(require("./macroJsx"));
var config = (0, _conf.getConfig)({
configPath: process.env.LINGUI_CONFIG
});
var _config$runtimeConfig = (0, _slicedToArray2.default)(config.runtimeConfigModule, 2),
i18nImportModule = _config$runtimeConfig[0],
_config$runtimeConfig2 = _config$runtimeConfig[1],
i18nImportName = _config$runtimeConfig2 === void 0 ? "i18n" : _config$runtimeConfig2;
function macro(_ref) {
var references = _ref.references,
state = _ref.state,
babel = _ref.babel;
var jsxNodes = [];
var jsNodes = [];
Object.keys(references).forEach(function (tagName) {
var nodes = references[tagName];
var macroType = getMacroType(tagName);
if (macroType == null) {
throw nodes[0].buildCodeFrameError("Unknown macro ".concat(tagName));
}
if (macroType === "js") {
nodes.forEach(function (node) {
jsNodes.push(node.parentPath);
});
} else {
nodes.forEach(function (node) {
// identifier.openingElement.jsxElement
jsxNodes.push(node.parentPath.parentPath);
});
}
});
jsNodes.filter(isRootPath(jsNodes)).forEach(function (path) {
if (alreadyVisited(path)) return;
var macro = new _macroJs.default(babel, {
i18nImportName: i18nImportName
});
macro.replacePath(path);
});
jsxNodes.filter(isRootPath(jsxNodes)).forEach(function (path) {
if (alreadyVisited(path)) return;
var macro = new _macroJsx.default(babel);
macro.replacePath(path);
});
if (jsNodes.length) {
addImport(babel, state, i18nImportModule, i18nImportName);
}
if (jsxNodes.length) {
addImport(babel, state, "@lingui/react", "Trans");
}
if (process.env.LINGUI_EXTRACT === "1") {
return {
keepImports: true
};
}
}
function addImport(babel, state, module, importName) {
var t = babel.types;
var linguiImport = state.file.path.node.body.find(function (importNode) {
return t.isImportDeclaration(importNode) && importNode.source.value === module && // https://github.com/lingui/js-lingui/issues/777
importNode.importKind !== "type";
});
var tIdentifier = t.identifier(importName); // Handle adding the import or altering the existing import
if (linguiImport) {
if (linguiImport.specifiers.findIndex(function (specifier) {
return specifier.imported && specifier.imported.name === importName;
}) === -1) {
linguiImport.specifiers.push(t.importSpecifier(tIdentifier, tIdentifier));
}
} else {
state.file.path.node.body.unshift(t.importDeclaration([t.importSpecifier(tIdentifier, tIdentifier)], t.stringLiteral(module)));
}
}
function isRootPath(allPath) {
return function (node) {
return function traverse(path) {
if (!path.parentPath) {
return true;
} else {
return !allPath.includes(path.parentPath) && traverse(path.parentPath);
}
}(node);
};
}
var alreadyVisitedCache = [];
function alreadyVisited(path) {
if (alreadyVisitedCache.includes(path)) {
return true;
} else {
alreadyVisitedCache.push(path);
return false;
}
}
function getMacroType(tagName) {
switch (tagName) {
case "defineMessages":
case "defineMessage":
case "arg":
case "t":
case "plural":
case "select":
case "selectOrdinal":
return "js";
case "Trans":
case "Plural":
case "Select":
case "SelectOrdinal":
return "jsx";
}
}
var _default = (0, _babelPluginMacros.createMacro)(macro);
exports.default = _default;
export { default } from "./src"
{
"name": "@lingui/macro",
"version": "3.1.0",
"version": "3.2.0",
"description": "Macro for generating messages in ICU MessageFormat syntax",

@@ -32,3 +32,3 @@ "main": "index.ts",

"@babel/runtime": "^7.11.2",
"@lingui/conf": "3.1.0",
"@lingui/conf": "^3.2.0",
"ramda": "^0.27.1"

@@ -38,3 +38,4 @@ },

"babel-plugin-macros": "^2.5.1"
}
},
"gitHead": "192e01250c12672bfe126dcb0f86a349cc7afe86"
}
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