@lingui/macro
Advanced tools
Comparing version 3.17.0 to 3.17.1
@@ -6,3 +6,3 @@ "use strict"; | ||
}); | ||
exports.CONTEXT = exports.EXTRACT_MARK = exports.COMMENT = exports.MESSAGE = exports.ID = void 0; | ||
exports.MESSAGE = exports.ID = exports.EXTRACT_MARK = exports.CONTEXT = exports.COMMENT = void 0; | ||
const ID = "id"; | ||
@@ -9,0 +9,0 @@ exports.ID = ID; |
@@ -75,5 +75,3 @@ // @ts-ignore | ||
*/ | ||
export function t( | ||
i18n: I18n | ||
): { | ||
export function t(i18n: I18n): { | ||
(literals: TemplateStringsArray, ...placeholders: any[]): string | ||
@@ -80,0 +78,0 @@ (descriptor: MessageDescriptor): string |
@@ -7,16 +7,16 @@ "use strict"; | ||
exports.default = void 0; | ||
var _types = require("@babel/types"); | ||
const metaOptions = ["id", "comment", "props"]; | ||
const escapedMetaOptionsRe = new RegExp(`^_(${metaOptions.join("|")})$`); | ||
class ICUMessageFormat { | ||
fromTokens(tokens) { | ||
return (Array.isArray(tokens) ? tokens : [tokens]).map(token => this.processToken(token)).filter(Boolean).reduce((props, message) => ({ ...message, | ||
return (Array.isArray(tokens) ? tokens : [tokens]).map(token => this.processToken(token)).filter(Boolean).reduce((props, message) => ({ | ||
...message, | ||
message: props.message + message.message, | ||
values: { ...props.values, | ||
values: { | ||
...props.values, | ||
...message.values | ||
}, | ||
jsxElements: { ...props.jsxElements, | ||
jsxElements: { | ||
...props.jsxElements, | ||
...message.jsxElements | ||
@@ -30,6 +30,4 @@ } | ||
} | ||
processToken(token) { | ||
const jsxElements = {}; | ||
if (token.type === "text") { | ||
@@ -43,7 +41,5 @@ return { | ||
} | ||
const values = token.value !== undefined ? { | ||
[token.name]: token.value | ||
} : {}; | ||
switch (token.format) { | ||
@@ -56,3 +52,2 @@ case "plural": | ||
key = key.replace(escapedMetaOptionsRe, "$1"); | ||
if (key === "offset") { | ||
@@ -62,3 +57,2 @@ // offset has special syntax `offset:number` | ||
} | ||
if (typeof value !== "string") { | ||
@@ -75,3 +69,2 @@ // process tokens from nested formatters | ||
} | ||
return `${key} {${value}}`; | ||
@@ -84,3 +77,2 @@ }).join(" "); | ||
}; | ||
default: | ||
@@ -114,8 +106,5 @@ return { | ||
} | ||
throw new Error(`Unknown token type ${token.type}`); | ||
} | ||
} | ||
exports.default = ICUMessageFormat; |
@@ -80,5 +80,3 @@ import type { ReactElement, ComponentType, ReactNode } from "react" | ||
*/ | ||
export function t( | ||
i18n: I18n | ||
): { | ||
export function t(i18n: I18n): { | ||
(literals: TemplateStringsArray, ...placeholders: any[]): string | ||
@@ -85,0 +83,0 @@ (descriptor: MessageDescriptor): string |
@@ -7,19 +7,11 @@ "use strict"; | ||
exports.default = void 0; | ||
var _babelPluginMacros = require("babel-plugin-macros"); | ||
var _conf = require("@lingui/conf"); | ||
var _macroJs = _interopRequireDefault(require("./macroJs")); | ||
var _macroJsx = _interopRequireDefault(require("./macroJsx")); | ||
var _types = require("@babel/types"); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
const config = (0, _conf.getConfig)({ | ||
configPath: process.env.LINGUI_CONFIG | ||
}); | ||
const getSymbolSource = name => { | ||
@@ -40,8 +32,6 @@ if (Array.isArray(config.runtimeConfigModule)) { | ||
}; | ||
const [i18nImportModule, i18nImportName = "i18n"] = getSymbolSource("i18n"); | ||
const [TransImportModule, TransImportName = "Trans"] = getSymbolSource("Trans"); | ||
const jsMacroTags = new Set(['defineMessage', 'arg', 't', 'plural', 'select', 'selectOrdinal']); | ||
const jsxMacroTags = new Set(['Trans', 'Plural', 'Select', 'SelectOrdinal']); | ||
const jsMacroTags = new Set(["defineMessage", "arg", "t", "plural", "select", "selectOrdinal"]); | ||
const jsxMacroTags = new Set(["Trans", "Plural", "Select", "SelectOrdinal"]); | ||
function macro({ | ||
@@ -57,3 +47,2 @@ references, | ||
const nodes = references[tagName]; | ||
if (jsMacroTags.has(tagName)) { | ||
@@ -84,11 +73,8 @@ nodes.forEach(node => { | ||
}); | ||
if (needsI18nImport) { | ||
addImport(babel, state, i18nImportModule, i18nImportName); | ||
} | ||
if (jsxNodes.length) { | ||
addImport(babel, state, TransImportModule, TransImportName); | ||
} | ||
if (process.env.LINGUI_EXTRACT === "1") { | ||
@@ -100,3 +86,2 @@ return { | ||
} | ||
function addImport(babel, state, module, importName) { | ||
@@ -106,6 +91,7 @@ const { | ||
} = babel; | ||
const linguiImport = state.file.path.node.body.find(importNode => t.isImportDeclaration(importNode) && importNode.source.value === module && // https://github.com/lingui/js-lingui/issues/777 | ||
const linguiImport = state.file.path.node.body.find(importNode => t.isImportDeclaration(importNode) && importNode.source.value === module && | ||
// https://github.com/lingui/js-lingui/issues/777 | ||
importNode.importKind !== "type"); | ||
const tIdentifier = t.identifier(importName); // Handle adding the import or altering the existing import | ||
const tIdentifier = t.identifier(importName); | ||
// Handle adding the import or altering the existing import | ||
if (linguiImport) { | ||
@@ -121,3 +107,2 @@ if (linguiImport.specifiers.findIndex(specifier => (0, _types.isImportSpecifier)(specifier) && (0, _types.isIdentifier)(specifier.imported, { | ||
} | ||
function isRootPath(allPath) { | ||
@@ -132,5 +117,3 @@ return node => function traverse(path) { | ||
} | ||
const alreadyVisitedCache = new WeakSet(); | ||
const alreadyVisited = path => { | ||
@@ -144,14 +127,10 @@ if (alreadyVisitedCache.has(path)) { | ||
}; | ||
[...jsMacroTags, ...jsxMacroTags].forEach(name => { | ||
Object.defineProperty(module.exports, name, { | ||
get() { | ||
throw new Error(`The macro you imported from "@lingui/macro" is being executed outside the context of compilation with babel-plugin-macros. ` + `This indicates that you don't have the babel plugin "babel-plugin-macros" configured correctly. ` + `Please see the documentation for how to configure babel-plugin-macros properly: ` + 'https://github.com/kentcdodds/babel-plugin-macros/blob/main/other/docs/user.md'); | ||
throw new Error(`The macro you imported from "@lingui/macro" is being executed outside the context of compilation with babel-plugin-macros. ` + `This indicates that you don't have the babel plugin "babel-plugin-macros" configured correctly. ` + `Please see the documentation for how to configure babel-plugin-macros properly: ` + "https://github.com/kentcdodds/babel-plugin-macros/blob/main/other/docs/user.md"); | ||
} | ||
}); | ||
}); | ||
var _default = (0, _babelPluginMacros.createMacro)(macro); | ||
exports.default = _default; |
@@ -7,32 +7,22 @@ "use strict"; | ||
exports.default = void 0; | ||
var R = _interopRequireWildcard(require("ramda")); | ||
var _types = require("@babel/types"); | ||
var _icu = _interopRequireDefault(require("./icu")); | ||
var _utils = require("./utils"); | ||
var _constants = require("./constants"); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; } | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } | ||
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
const keepSpaceRe = /(?:\\(?:\r\n|\r|\n))+\s+/g; | ||
const keepNewLineRe = /(?:\r\n|\r|\n)+\s+/g; | ||
function normalizeWhitespace(text) { | ||
return text.replace(keepSpaceRe, " ").replace(keepNewLineRe, "\n").trim(); | ||
} | ||
class MacroJs { | ||
// Babel Types | ||
// Identifier of i18n object | ||
// Positional expressions counter (e.g. for placeholders `Hello {0}, today is {1}`) | ||
_expressionIndex = (0, _utils.makeCounter)(); | ||
constructor({ | ||
@@ -46,3 +36,2 @@ types | ||
} | ||
replacePathWithMessage = (path, { | ||
@@ -54,3 +43,2 @@ message, | ||
args.push(isString(message) ? this.types.stringLiteral(message) : message); | ||
if (Object.keys(values).length) { | ||
@@ -60,20 +48,20 @@ const valuesObject = Object.keys(values).map(key => this.types.objectProperty(this.types.identifier(key), values[key])); | ||
} | ||
const newNode = this.types.callExpression(this.types.memberExpression(linguiInstance ?? this.types.identifier(this.i18nImportName), this.types.identifier("_")), args); | ||
const newNode = this.types.callExpression(this.types.memberExpression(linguiInstance ?? this.types.identifier(this.i18nImportName), this.types.identifier("_")), args); // preserve line number | ||
// preserve line number | ||
newNode.loc = path.node.loc; | ||
path.addComment("leading", _constants.EXTRACT_MARK); | ||
path.replaceWith(newNode); | ||
}; // Returns a boolean indicating if the replacement requires i18n import | ||
}; | ||
// Returns a boolean indicating if the replacement requires i18n import | ||
replacePath = path => { | ||
// reset the expression counter | ||
this._expressionIndex = (0, _utils.makeCounter)(); | ||
if (this.isDefineMessage(path.node)) { | ||
this.replaceDefineMessage(path); | ||
return true; | ||
} // t(i18nInstance)`Message` -> i18nInstance._('Message') | ||
} | ||
// t(i18nInstance)`Message` -> i18nInstance._('Message') | ||
if (this.types.isCallExpression(path.node) && this.types.isTaggedTemplateExpression(path.parentPath.node) && this.types.isIdentifier(path.node.arguments[0]) && this.isIdentifier(path.node.callee, "t")) { | ||
@@ -94,5 +82,5 @@ // Use the first argument as i18n instance instead of the default i18n instance | ||
return false; | ||
} // t(i18nInstance)(messageDescriptor) -> i18nInstance._(messageDescriptor) | ||
} | ||
// t(i18nInstance)(messageDescriptor) -> i18nInstance._(messageDescriptor) | ||
if (this.types.isCallExpression(path.node) && this.types.isCallExpression(path.parentPath.node) && this.types.isIdentifier(path.node.arguments[0]) && this.isIdentifier(path.node.callee, "t")) { | ||
@@ -103,3 +91,2 @@ const i18nInstance = path.node.arguments[0]; | ||
} | ||
if (this.types.isCallExpression(path.node) && this.isIdentifier(path.node.callee, "t")) { | ||
@@ -109,3 +96,2 @@ this.replaceTAsFunction(path); | ||
} | ||
const tokens = this.tokenizeNode(path.node); | ||
@@ -124,2 +110,3 @@ const messageFormat = new _icu.default(); | ||
}; | ||
/** | ||
@@ -146,3 +133,2 @@ * macro `defineMessage` is called with MessageDescriptor. The only | ||
*/ | ||
replaceDefineMessage = path => { | ||
@@ -154,2 +140,3 @@ // reset the expression counter | ||
}; | ||
/** | ||
@@ -159,3 +146,2 @@ * macro `t` is called with MessageDescriptor, after that | ||
*/ | ||
replaceTAsFunction = (path, linguiInstance) => { | ||
@@ -166,2 +152,3 @@ let descriptor = this.processDescriptor(path.node.arguments[0]); | ||
}; | ||
/** | ||
@@ -184,3 +171,2 @@ * `processDescriptor` expand macros inside message descriptor. | ||
*/ | ||
processDescriptor = descriptor_ => { | ||
@@ -190,14 +176,13 @@ const descriptor = descriptor_; | ||
const messageIndex = descriptor.properties.findIndex(property => (0, _types.isObjectProperty)(property) && this.isIdentifier(property.key, _constants.MESSAGE)); | ||
if (messageIndex === -1) { | ||
return descriptor; | ||
} // if there's `message` property, replace macros with formatted message | ||
} | ||
// if there's `message` property, replace macros with formatted message | ||
const node = descriptor.properties[messageIndex]; | ||
const node = descriptor.properties[messageIndex]; // Inside message descriptor the `t` macro in `message` prop is optional. | ||
// Inside message descriptor the `t` macro in `message` prop is optional. | ||
// Template strings are always processed as if they were wrapped by `t`. | ||
const tokens = this.types.isTemplateLiteral(node.value) ? this.tokenizeTemplateLiteral(node.value) : this.tokenizeNode(node.value, true); | ||
let messageNode = node.value; | ||
if (tokens != null) { | ||
@@ -212,12 +197,10 @@ const messageFormat = new _icu.default(); | ||
this.addValues(descriptor.properties, values); | ||
} // Don't override custom ID | ||
} | ||
// Don't override custom ID | ||
const hasId = descriptor.properties.findIndex(property => (0, _types.isObjectProperty)(property) && this.isIdentifier(property.key, _constants.ID)) !== -1; | ||
descriptor.properties[messageIndex] = this.types.objectProperty(this.types.identifier(hasId ? _constants.MESSAGE : _constants.ID), messageNode); | ||
if (process.env.NODE_ENV === "production") { | ||
descriptor.properties = descriptor.properties.filter(property => (0, _types.isObjectProperty)(property) && !this.isIdentifier(property.key, _constants.MESSAGE) && (0, _types.isObjectProperty)(property) && !this.isIdentifier(property.key, _constants.COMMENT)); | ||
} | ||
return descriptor; | ||
@@ -236,3 +219,4 @@ }; | ||
// plural, select and selectOrdinal | ||
return [this.tokenizeChoiceComponent(node)]; // } else if (isFormatMethod(node.callee)) { | ||
return [this.tokenizeChoiceComponent(node)]; | ||
// } else if (isFormatMethod(node.callee)) { | ||
// // date, number | ||
@@ -244,2 +228,3 @@ // return transformFormatMethod(node, file, props, root) | ||
}; | ||
/** | ||
@@ -250,3 +235,2 @@ * `node` is a TemplateLiteral. node.quasi contains | ||
*/ | ||
tokenizeTemplateLiteral = node => { | ||
@@ -272,3 +256,4 @@ const tokenize = R.pipe(R.evolve({ | ||
const format = node.callee.name.toLowerCase(); | ||
const token = { ...this.tokenizeExpression(node.arguments[0]), | ||
const token = { | ||
...this.tokenizeExpression(node.arguments[0]), | ||
format, | ||
@@ -280,3 +265,2 @@ options: { | ||
const props = node.arguments[1].properties; | ||
for (const attr of props) { | ||
@@ -286,9 +270,9 @@ const { | ||
value: attrValue | ||
} = attr; // name is either: | ||
} = attr; | ||
// name is either: | ||
// NumericLiteral => convert to `={number}` | ||
// StringLiteral => key.value | ||
// Identifier => key.name | ||
const name = this.types.isNumericLiteral(key) ? `=${key.value}` : key.name || key.value; | ||
if (format !== "select" && name === "offset") { | ||
@@ -298,3 +282,2 @@ token.options.offset = attrValue.value; | ||
let value; | ||
if (this.types.isTemplateLiteral(attrValue)) { | ||
@@ -307,7 +290,5 @@ value = this.tokenizeTemplateLiteral(attrValue); | ||
} | ||
token.options[name] = value; | ||
} | ||
} | ||
return token; | ||
@@ -323,3 +304,2 @@ }; | ||
} | ||
return { | ||
@@ -340,6 +320,6 @@ type: "arg", | ||
}; | ||
/** | ||
* We clean '//\` ' to just '`' | ||
*/ | ||
clearBackslashes(value) { | ||
@@ -349,7 +329,6 @@ // if not we replace the extra scaped literals | ||
} | ||
/** | ||
* Custom matchers | ||
*/ | ||
isIdentifier = (node, name) => { | ||
@@ -373,5 +352,3 @@ return this.types.isIdentifier(node, { | ||
} | ||
exports.default = MacroJs; | ||
const isString = s => typeof s === "string"; |
@@ -6,28 +6,18 @@ "use strict"; | ||
}); | ||
exports.default = void 0; | ||
exports.normalizeWhitespace = normalizeWhitespace; | ||
exports.default = void 0; | ||
var R = _interopRequireWildcard(require("ramda")); | ||
var _icu = _interopRequireDefault(require("./icu")); | ||
var _utils = require("./utils"); | ||
var _constants = require("./constants"); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; } | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } | ||
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
const pluralRuleRe = /(_[\d\w]+|zero|one|two|few|many|other)/; | ||
const jsx2icuExactChoice = value => value.replace(/_(\d+)/, "=$1").replace(/_(\w+)/, "$1"); | ||
const jsx2icuExactChoice = value => value.replace(/_(\d+)/, "=$1").replace(/_(\w+)/, "$1"); // replace whitespace before/after newline with single space | ||
const keepSpaceRe = /\s*(?:\r\n|\r|\n)+\s*/g; // remove whitespace before/after tag or expression | ||
// replace whitespace before/after newline with single space | ||
const keepSpaceRe = /\s*(?:\r\n|\r|\n)+\s*/g; | ||
// remove whitespace before/after tag or expression | ||
const stripAroundTagsRe = /(?:([>}])(?:\r\n|\r|\n)+\s*|(?:\r\n|\r|\n)+\s*(?=[<{]))/g; | ||
function maybeNodeValue(node) { | ||
@@ -41,13 +31,12 @@ if (!node) return null; | ||
} | ||
function normalizeWhitespace(text) { | ||
return text.replace(stripAroundTagsRe, "$1").replace(keepSpaceRe, " ") // keep escaped newlines | ||
.replace(/\\n/g, "\n").replace(/\\s/g, " ") // we remove trailing whitespace inside Plural | ||
return text.replace(stripAroundTagsRe, "$1").replace(keepSpaceRe, " ") | ||
// keep escaped newlines | ||
.replace(/\\n/g, "\n").replace(/\\s/g, " ") | ||
// we remove trailing whitespace inside Plural | ||
.replace(/(\s+})/gm, "}").trim(); | ||
} | ||
class MacroJSX { | ||
expressionIndex = (0, _utils.makeCounter)(); | ||
elementIndex = (0, _utils.makeCounter)(); | ||
constructor({ | ||
@@ -58,3 +47,2 @@ types | ||
} | ||
safeJsxAttribute = (name, value) => { | ||
@@ -79,3 +67,2 @@ // This handles quoted JSX attributes and html entities. | ||
} = this.stripMacroAttributes(path.node); | ||
if (!id && !message) { | ||
@@ -87,3 +74,2 @@ return; | ||
attributes.push(this.types.jsxAttribute(this.types.jsxIdentifier(_constants.ID), this.types.stringLiteral(id))); | ||
if (process.env.NODE_ENV !== "production") { | ||
@@ -97,3 +83,2 @@ if (message) { | ||
} | ||
if (process.env.NODE_ENV !== "production") { | ||
@@ -104,28 +89,17 @@ if (comment) { | ||
} | ||
if (context) { | ||
attributes.push(this.types.jsxAttribute(this.types.jsxIdentifier(_constants.CONTEXT), this.types.stringLiteral(context))); | ||
} // Parameters for variable substitution | ||
} | ||
// Parameters for variable substitution | ||
const valuesObject = Object.keys(values).map(key => this.types.objectProperty(this.types.identifier(key), values[key])); | ||
if (valuesObject.length) { | ||
attributes.push(this.types.jsxAttribute(this.types.jsxIdentifier("values"), this.types.jsxExpressionContainer(this.types.objectExpression(valuesObject)))); | ||
} // Inline elements | ||
} | ||
// Inline elements | ||
if (Object.keys(jsxElements).length) { | ||
attributes.push(this.types.jsxAttribute(this.types.jsxIdentifier("components"), this.types.jsxExpressionContainer(this.types.objectExpression(Object.keys(jsxElements).map(key => this.types.objectProperty(this.types.identifier(key), jsxElements[key])))))); | ||
} | ||
const newNode = this.types.jsxElement(this.types.jsxOpeningElement(this.types.jsxIdentifier("Trans"), attributes, | ||
/*selfClosing*/ | ||
true), | ||
/*closingElement*/ | ||
null, | ||
/*children*/ | ||
[], | ||
/*selfClosing*/ | ||
true); | ||
const newNode = this.types.jsxElement(this.types.jsxOpeningElement(this.types.jsxIdentifier("Trans"), attributes, /*selfClosing*/true), /*closingElement*/null, /*children*/[], /*selfClosing*/true); | ||
newNode.loc = path.node.loc; | ||
@@ -150,8 +124,7 @@ path.replaceWith(newNode); | ||
let reserved = [_constants.ID, _constants.MESSAGE, _constants.COMMENT, _constants.CONTEXT]; | ||
if (this.isI18nComponent(node)) {// no reserved prop names | ||
if (this.isI18nComponent(node)) { | ||
// no reserved prop names | ||
} else if (this.isChoiceComponent(node)) { | ||
reserved = [...reserved, "_\\w+", "_\\d+", "zero", "one", "two", "few", "many", "other", "value", "offset"]; | ||
} | ||
return { | ||
@@ -184,3 +157,2 @@ id: maybeNodeValue(id), | ||
const exp = node.expression; | ||
if (this.types.isStringLiteral(exp)) { | ||
@@ -193,3 +165,4 @@ // Escape forced newlines to keep them in message. | ||
} else if (this.types.isTemplateLiteral(exp)) { | ||
const tokenize = R.pipe( // Don"t output tokens without text. | ||
const tokenize = R.pipe( | ||
// Don"t output tokens without text. | ||
R.evolve({ | ||
@@ -214,6 +187,8 @@ quasis: R.map(text => { | ||
return this.tokenizeNode(node); | ||
} else if (this.types.isJSXSpreadChild(node)) {// just do nothing | ||
} else if (this.types.isJSXSpreadChild(node)) { | ||
// just do nothing | ||
} else if (this.types.isJSXText(node)) { | ||
return this.tokenizeText(node.value); | ||
} else {// impossible path | ||
} else { | ||
// impossible path | ||
// return this.tokenizeText(node.value) | ||
@@ -225,3 +200,4 @@ } | ||
const format = this.getJsxTagName(node).toLowerCase(); | ||
const props = element.attributes.filter(this.attrName([_constants.ID, _constants.COMMENT, _constants.MESSAGE, _constants.CONTEXT, "key", // we remove <Trans /> react props that are not useful for translation | ||
const props = element.attributes.filter(this.attrName([_constants.ID, _constants.COMMENT, _constants.MESSAGE, _constants.CONTEXT, "key", | ||
// we remove <Trans /> react props that are not useful for translation | ||
"render", "component", "components"], true)); | ||
@@ -237,3 +213,2 @@ const token = { | ||
}; | ||
for (const attr of props) { | ||
@@ -243,9 +218,6 @@ if (this.types.isJSXSpreadAttribute(attr)) { | ||
} | ||
if (this.types.isJSXNamespacedName(attr.name)) { | ||
continue; | ||
} | ||
const name = attr.name.name; | ||
if (name === "value") { | ||
@@ -260,3 +232,2 @@ const exp = this.types.isLiteral(attr.value) ? attr.value : attr.value.expression; | ||
let value; | ||
if (this.types.isStringLiteral(attr.value)) { | ||
@@ -267,3 +238,2 @@ value = attr.value.extra.raw.replace(/(["'])(.*)\1/, "$2"); | ||
} | ||
if (pluralRuleRe.test(name)) { | ||
@@ -276,3 +246,2 @@ token.options[jsx2icuExactChoice(name)] = value; | ||
} | ||
return token; | ||
@@ -307,11 +276,9 @@ }; | ||
}; | ||
expressionToArgument(exp) { | ||
return this.types.isIdentifier(exp) ? exp.name : String(this.expressionIndex()); | ||
} | ||
/** | ||
* We clean '//\` ' to just '`' | ||
**/ | ||
clearBackslashes(value) { | ||
@@ -321,7 +288,6 @@ // if not we replace the extra scaped literals | ||
} | ||
/** | ||
* Custom matchers | ||
*/ | ||
isIdentifier = (node, name) => { | ||
@@ -346,3 +312,2 @@ return this.types.isIdentifier(node, { | ||
} | ||
exports.default = MacroJSX; |
@@ -6,11 +6,7 @@ "use strict"; | ||
}); | ||
exports.makeCounter = void 0; | ||
exports.zip = zip; | ||
exports.makeCounter = void 0; | ||
var R = _interopRequireWildcard(require("ramda")); | ||
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; } | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } | ||
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
/** | ||
@@ -23,5 +19,3 @@ * Custom zip method which takes length of the larger array | ||
} | ||
const makeCounter = (index = 0) => () => index++; | ||
exports.makeCounter = makeCounter; |
@@ -6,2 +6,13 @@ # Change Log | ||
## [3.17.1](https://github.com/lingui/js-lingui/compare/v3.17.0...v3.17.1) (2023-02-07) | ||
### Bug Fixes | ||
* **build:** undeclared dependencies ([#1391](https://github.com/lingui/js-lingui/issues/1391)) ([f390ca4](https://github.com/lingui/js-lingui/commit/f390ca4517144344fcbbbf9c73a42a1a17d0e519)) | ||
# [3.17.0](https://github.com/lingui/js-lingui/compare/v3.16.1...v3.17.0) (2023-02-01) | ||
@@ -8,0 +19,0 @@ |
{ | ||
"name": "@lingui/macro", | ||
"version": "3.17.0", | ||
"version": "3.17.1", | ||
"description": "Macro for generating messages in ICU MessageFormat syntax", | ||
@@ -30,4 +30,5 @@ "main": "./build/index.js", | ||
"dependencies": { | ||
"@babel/runtime": "^7.11.2", | ||
"@lingui/conf": "3.17.0", | ||
"@babel/runtime": "^7.20.13", | ||
"@babel/types": "^7.20.7", | ||
"@lingui/conf": "3.17.1", | ||
"ramda": "^0.27.1" | ||
@@ -43,3 +44,3 @@ }, | ||
}, | ||
"gitHead": "1c8bc46213b35b25da8fe7a80ddcf6f6a5d9d539" | ||
"gitHead": "76ef4e8d1c668578ce2c3829ebf35d22ca5e679c" | ||
} |
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
62222
1252
7
+ Added@babel/types@^7.20.7
+ Added@babel/helper-string-parser@7.25.9(transitive)
+ Added@babel/types@7.26.0(transitive)
+ Added@lingui/conf@3.17.1(transitive)
- Removed@lingui/conf@3.17.0(transitive)
Updated@babel/runtime@^7.20.13
Updated@lingui/conf@3.17.1