@lingui/macro
Advanced tools
Comparing version 3.0.0-8 to 3.0.0-9
@@ -127,31 +127,27 @@ "use strict"; | ||
(0, _defineProperty2.default)(this, "replaceDefineMessage", function (path) { | ||
// TODO: Add argument validation. | ||
// reset the expression counter | ||
_this._expressionIndex = (0, _utils.makeCounter)(); | ||
var descriptor = _this.processDescriptor(path.node.arguments[0]); | ||
_this.replacePathWithMessage(path, descriptor); | ||
_this.addExtractMark(path); | ||
path.replaceWith(descriptor); | ||
}); | ||
(0, _defineProperty2.default)(this, "processDescriptor", function (descriptor) { | ||
var idNode = descriptor.properties.find(function (property) { | ||
return property.key.name === _constants.ID; | ||
}); | ||
var messageNode = descriptor.properties.find(function (property) { | ||
var messageIndex = descriptor.properties.findIndex(function (property) { | ||
return property.key.name === _constants.MESSAGE; | ||
}); | ||
var commentNode = descriptor.properties.find(function (property) { | ||
return property.key.name === _constants.COMMENT; | ||
}); | ||
var i18nArgs = { | ||
id: idNode != null ? idNode.value.value : null, | ||
comment: commentNode != null ? commentNode.value.value : null, | ||
message: null, | ||
values: {} | ||
}; | ||
if (messageNode == null) { | ||
return i18nArgs; | ||
if (messageIndex === -1) { | ||
return descriptor; | ||
} // if there's `message` property, replace macros with formatted message | ||
var tokens = _this.tokenizeNode(messageNode.value, true); | ||
var node = descriptor.properties[messageIndex]; | ||
var tokens = _this.tokenizeNode(node.value, true); | ||
var messageNode = node.value; | ||
if (tokens != null) { | ||
@@ -164,10 +160,22 @@ var messageFormat = new _icu.default(); | ||
i18nArgs.message = normalizeWhitespace(messageRaw); | ||
i18nArgs.values = values; | ||
} else { | ||
i18nArgs.message = messageNode.value; | ||
} | ||
var message = normalizeWhitespace(messageRaw); | ||
messageNode = _this.types.stringLiteral(message); | ||
return i18nArgs; | ||
_this.addValues(descriptor.properties, values); | ||
} // Don't override custom ID | ||
var hasId = descriptor.properties.findIndex(function (property) { | ||
return property.key.name === _constants.ID; | ||
}) !== -1; | ||
descriptor.properties[messageIndex] = _this.types.objectProperty(_this.types.identifier(hasId ? _constants.MESSAGE : _constants.ID), messageNode); | ||
return descriptor; | ||
}); | ||
(0, _defineProperty2.default)(this, "addValues", function (obj, values) { | ||
var valuesObject = Object.keys(values).map(function (key) { | ||
return _this.types.objectProperty(_this.types.identifier(key), values[key]); | ||
}); | ||
if (!valuesObject.length) return; | ||
obj.push(_this.types.objectProperty(_this.types.identifier("values"), _this.types.objectExpression(valuesObject))); | ||
}); | ||
(0, _defineProperty2.default)(this, "tokenizeNode", function (node) { | ||
@@ -174,0 +182,0 @@ var ignoreExpression = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; |
{ | ||
"name": "@lingui/macro", | ||
"version": "3.0.0-8", | ||
"version": "3.0.0-9", | ||
"description": "Macro for generating messages in ICU MessageFormat syntax", | ||
@@ -5,0 +5,0 @@ "main": "index.ts", |
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
39941
812
5