@lingui/macro
Advanced tools
Comparing version 3.2.0 to 3.2.1
146
index.js
@@ -1,1 +0,145 @@ | ||
export { default } from "./src" | ||
"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; |
{ | ||
"name": "@lingui/macro", | ||
"version": "3.2.0", | ||
"version": "3.2.1", | ||
"description": "Macro for generating messages in ICU MessageFormat syntax", | ||
@@ -32,3 +32,3 @@ "main": "index.ts", | ||
"@babel/runtime": "^7.11.2", | ||
"@lingui/conf": "^3.2.0", | ||
"@lingui/conf": "3.2.1", | ||
"ramda": "^0.27.1" | ||
@@ -38,4 +38,3 @@ }, | ||
"babel-plugin-macros": "^2.5.1" | ||
}, | ||
"gitHead": "192e01250c12672bfe126dcb0f86a349cc7afe86" | ||
} | ||
} |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 3 instances 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
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
41232
10
836
0
5
+ Added@lingui/conf@3.2.1(transitive)
+ Addedcosmiconfig@7.1.0(transitive)
- Removed@cspotcode/source-map-support@0.8.1(transitive)
- Removed@jridgewell/resolve-uri@3.1.2(transitive)
- Removed@jridgewell/sourcemap-codec@1.5.0(transitive)
- Removed@jridgewell/trace-mapping@0.3.9(transitive)
- Removed@lingui/conf@3.17.2(transitive)
- Removed@tsconfig/node10@1.0.11(transitive)
- Removed@tsconfig/node12@1.0.11(transitive)
- Removed@tsconfig/node14@1.0.3(transitive)
- Removed@tsconfig/node16@1.0.4(transitive)
- Removedacorn@8.14.0(transitive)
- Removedacorn-walk@8.3.4(transitive)
- Removedarg@4.1.3(transitive)
- Removedargparse@2.0.1(transitive)
- Removedcosmiconfig@8.3.6(transitive)
- Removedcosmiconfig-typescript-loader@4.4.0(transitive)
- Removedcreate-require@1.1.1(transitive)
- Removeddiff@4.0.2(transitive)
- Removedjs-yaml@4.1.0(transitive)
- Removedlodash.get@4.4.2(transitive)
- Removedmake-error@1.3.6(transitive)
- Removedts-node@10.9.2(transitive)
- Removedtypescript@5.6.3(transitive)
- Removedv8-compile-cache-lib@3.0.1(transitive)
- Removedyn@3.1.1(transitive)
Updated@lingui/conf@3.2.1