@lingui/macro
Advanced tools
Comparing version 3.16.1 to 3.17.0
@@ -42,2 +42,4 @@ "use strict"; | ||
const [TransImportModule, TransImportName = "Trans"] = getSymbolSource("Trans"); | ||
const jsMacroTags = new Set(['defineMessage', 'arg', 't', 'plural', 'select', 'selectOrdinal']); | ||
const jsxMacroTags = new Set(['Trans', 'Plural', 'Select', 'SelectOrdinal']); | ||
@@ -54,13 +56,8 @@ function macro({ | ||
const nodes = references[tagName]; | ||
const macroType = getMacroType(tagName); | ||
if (macroType == null) { | ||
throw nodes[0].buildCodeFrameError(`Unknown macro ${tagName}`); | ||
} | ||
if (macroType === "js") { | ||
if (jsMacroTags.has(tagName)) { | ||
nodes.forEach(node => { | ||
jsNodes.push(node.parentPath); | ||
}); | ||
} else { | ||
} else if (jsxMacroTags.has(tagName)) { | ||
nodes.forEach(node => { | ||
@@ -70,2 +67,4 @@ // identifier.openingElement.jsxElement | ||
}); | ||
} else { | ||
throw nodes[0].buildCodeFrameError(`Unknown macro ${tagName}`); | ||
} | ||
@@ -141,19 +140,10 @@ }); | ||
function getMacroType(tagName) { | ||
switch (tagName) { | ||
case "defineMessage": | ||
case "arg": | ||
case "t": | ||
case "plural": | ||
case "select": | ||
case "selectOrdinal": | ||
return "js"; | ||
[...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'); | ||
} | ||
case "Trans": | ||
case "Plural": | ||
case "Select": | ||
case "SelectOrdinal": | ||
return "jsx"; | ||
} | ||
} | ||
}); | ||
}); | ||
@@ -160,0 +150,0 @@ var _default = (0, _babelPluginMacros.createMacro)(macro); |
@@ -142,3 +142,3 @@ "use strict"; | ||
this._expressionIndex = (0, _utils.makeCounter)(); | ||
const descriptor = this.processDescriptor(path.node.arguments[0]); | ||
let descriptor = this.processDescriptor(path.node.arguments[0]); | ||
path.replaceWith(descriptor); | ||
@@ -152,3 +152,3 @@ }; | ||
replaceTAsFunction = (path, linguiInstance) => { | ||
const descriptor = this.processDescriptor(path.node.arguments[0]); | ||
let descriptor = this.processDescriptor(path.node.arguments[0]); | ||
const newNode = this.types.callExpression(this.types.memberExpression(linguiInstance ?? this.types.identifier(this.i18nImportName), this.types.identifier("_")), [descriptor]); | ||
@@ -205,2 +205,7 @@ path.replaceWith(newNode); | ||
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; | ||
@@ -207,0 +212,0 @@ }; |
@@ -6,2 +6,18 @@ # Change Log | ||
# [3.17.0](https://github.com/lingui/js-lingui/compare/v3.16.1...v3.17.0) (2023-02-01) | ||
### Bug Fixes | ||
* **macro:** JS macros don't strip non-essential props in production ([#1389](https://github.com/lingui/js-lingui/issues/1389)) ([0ff55d6](https://github.com/lingui/js-lingui/commit/0ff55d606e4eba496548675e42c744d0d872d838)) | ||
### Features | ||
* **macro:** throw useful error message if macro used without a plugin ([#1355](https://github.com/lingui/js-lingui/issues/1355)) ([7d55904](https://github.com/lingui/js-lingui/commit/7d55904bb76fae384558945863423145978b9bd6)) | ||
## [3.16.1](https://github.com/lingui/js-lingui/compare/v3.16.0...v3.16.1) (2023-01-24) | ||
@@ -8,0 +24,0 @@ |
{ | ||
"name": "@lingui/macro", | ||
"version": "3.16.1", | ||
"version": "3.17.0", | ||
"description": "Macro for generating messages in ICU MessageFormat syntax", | ||
@@ -31,3 +31,3 @@ "main": "./build/index.js", | ||
"@babel/runtime": "^7.11.2", | ||
"@lingui/conf": "3.16.1", | ||
"@lingui/conf": "3.17.0", | ||
"ramda": "^0.27.1" | ||
@@ -43,3 +43,3 @@ }, | ||
}, | ||
"gitHead": "bae762a1ef15d0a4d883bc8c1837603b4e79175e" | ||
"gitHead": "1c8bc46213b35b25da8fe7a80ddcf6f6a5d9d539" | ||
} |
@@ -43,4 +43,4 @@ [![License][badge-license]][license] | ||
[linguijs]: https://github.com/lingui/js-lingui | ||
[documentation]: https://lingui.js.org/ | ||
[reference]: https://lingui.js.org/ref/macro/ | ||
[documentation]: https://lingui.dev | ||
[reference]: https://lingui.dev/ref/macro/ | ||
[package]: https://www.npmjs.com/package/@lingui/macro | ||
@@ -47,0 +47,0 @@ [badge-downloads]: https://img.shields.io/npm/dw/@lingui/macro.svg |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
61376
1235
5
+ Added@lingui/conf@3.17.0(transitive)
+ Addedargparse@2.0.1(transitive)
+ Addedcosmiconfig@8.3.6(transitive)
+ Addedcosmiconfig-typescript-loader@4.4.0(transitive)
+ Addedjs-yaml@4.1.0(transitive)
- Removed@lingui/conf@3.16.1(transitive)
- Removedcosmiconfig-typescript-loader@2.0.2(transitive)
Updated@lingui/conf@3.17.0