@lingui/babel-plugin-extract-messages 4.8.0-next.0 → 4.8.0-next.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -75,11 +75,8 @@ function hasI18nComment(node) {
75
75
  return hasComment(node, "i18n");
76
76
  }
77
77
  function index({ types: t }) {
78
- let localTransComponentName;
79
- function isTransComponent(node) {
80
- return t.isJSXElement(node) && t.isJSXIdentifier(node.openingElement.name, {
81
- name: localTransComponentName
82
- });
78
+ function isTransComponent(path) {
79
+ return path.isJSXElement() && path.get("openingElement").get("name").referencesImport("@lingui/react", "Trans");
83
80
  }
84
81
  const isI18nMethod = (node) => t.isMemberExpression(node) && (t.isIdentifier(node.object, { name: I18N_OBJECT }) || t.isMemberExpression(node.object) && t.isIdentifier(node.object.property, { name: I18N_OBJECT })) && (t.isIdentifier(node.property, { name: "_" }) || t.isIdentifier(node.property, { name: "t" }));
85
82
  const extractFromMessageDescriptor = (path, ctx) => {
@@ -99,27 +96,10 @@ function index({ types: t }) {
99
96
  };
100
97
  return {
101
98
  visitor: {
102
- // Get the local name of Trans component. Usually it's just `Trans`, but
103
- // it might be different when the import is aliased:
104
- // import { Trans as T } from '@lingui/react';
105
- ImportDeclaration(path) {
106
- const { node } = path;
107
- const moduleName = node.source.value;
108
- if (!["@lingui/react", "@lingui/core"].includes(moduleName))
109
- return;
110
- const importDeclarations = {};
111
- if (moduleName === "@lingui/react") {
112
- node.specifiers.forEach((specifier) => {
113
- specifier = specifier;
114
- importDeclarations[specifier.imported.name] = specifier.local.name;
115
- });
116
- localTransComponentName = importDeclarations["Trans"] || "Trans";
117
- }
118
- },
119
99
  // Extract translation from <Trans /> component.
120
100
  JSXElement(path, ctx) {
121
101
  const { node } = path;
122
- if (!localTransComponentName || !isTransComponent(node))
102
+ if (!isTransComponent(path))
123
103
  return;
124
104
  const attrs = node.openingElement.attributes || [];
125
105
  const props = attrs.reduce((acc, item) => {
package/dist/index.mjs CHANGED
@@ -73,11 +73,8 @@ function hasI18nComment(node) {
73
73
  return hasComment(node, "i18n");
74
74
  }
75
75
  function index({ types: t }) {
76
- let localTransComponentName;
77
- function isTransComponent(node) {
78
- return t.isJSXElement(node) && t.isJSXIdentifier(node.openingElement.name, {
79
- name: localTransComponentName
80
- });
76
+ function isTransComponent(path) {
77
+ return path.isJSXElement() && path.get("openingElement").get("name").referencesImport("@lingui/react", "Trans");
81
78
  }
82
79
  const isI18nMethod = (node) => t.isMemberExpression(node) && (t.isIdentifier(node.object, { name: I18N_OBJECT }) || t.isMemberExpression(node.object) && t.isIdentifier(node.object.property, { name: I18N_OBJECT })) && (t.isIdentifier(node.property, { name: "_" }) || t.isIdentifier(node.property, { name: "t" }));
83
80
  const extractFromMessageDescriptor = (path, ctx) => {
@@ -97,27 +94,10 @@ function index({ types: t }) {
97
94
  };
98
95
  return {
99
96
  visitor: {
100
- // Get the local name of Trans component. Usually it's just `Trans`, but
101
- // it might be different when the import is aliased:
102
- // import { Trans as T } from '@lingui/react';
103
- ImportDeclaration(path) {
104
- const { node } = path;
105
- const moduleName = node.source.value;
106
- if (!["@lingui/react", "@lingui/core"].includes(moduleName))
107
- return;
108
- const importDeclarations = {};
109
- if (moduleName === "@lingui/react") {
110
- node.specifiers.forEach((specifier) => {
111
- specifier = specifier;
112
- importDeclarations[specifier.imported.name] = specifier.local.name;
113
- });
114
- localTransComponentName = importDeclarations["Trans"] || "Trans";
115
- }
116
- },
117
97
  // Extract translation from <Trans /> component.
118
98
  JSXElement(path, ctx) {
119
99
  const { node } = path;
120
- if (!localTransComponentName || !isTransComponent(node))
100
+ if (!isTransComponent(path))
121
101
  return;
122
102
  const attrs = node.openingElement.attributes || [];
123
103
  const props = attrs.reduce((acc, item) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lingui/babel-plugin-extract-messages",
3
- "version": "4.8.0-next.0",
3
+ "version": "4.8.0-next.1",
4
4
  "description": "Babel plugin for collecting messages from source code for internationalization",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.mjs",
@@ -43,8 +43,9 @@
43
43
  "@babel/core": "^7.21.0",
44
44
  "@babel/traverse": "7.20.12",
45
45
  "@babel/types": "^7.20.7",
46
- "@lingui/jest-mocks": "^3.0.3",
46
+ "@lingui/jest-mocks": "3.0.3",
47
+ "@lingui/macro": "4.8.0-next.1",
47
48
  "unbuild": "2.0.0"
48
49
  },
49
- "gitHead": "d085ac65d66ce6c2f866b703b6346e53ff0bf6b3"
50
+ "gitHead": "62a736f74796c6c3e5bfd23d2e95154fc7f3ff42"
50
51
  }