Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@lingui/babel-plugin-transform-react

Package Overview
Dependencies
Maintainers
1
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@lingui/babel-plugin-transform-react - npm Package Compare versions

Comparing version 2.5.0 to 2.6.0

35

index.js

@@ -15,2 +15,6 @@ "use strict";

var _slicedToArray2 = require("babel-runtime/helpers/slicedToArray");
var _slicedToArray3 = _interopRequireDefault(_slicedToArray2);
var _includes = require("babel-runtime/core-js/array/includes");

@@ -378,9 +382,24 @@

return {
pre: function pre() {
// Reset import declaration for each file.
// Regression introduced in https://github.com/lingui/js-lingui/issues/62
importDeclarations = {};
},
visitor: {
Program: function Program(path, state) {
// Reset import declaration for each file.
// Regression introduced in https://github.com/lingui/js-lingui/issues/62
importDeclarations = {};
visitor: {
var importedNames = state.opts.importedNames;
if (importedNames) {
importedNames.forEach(function (name) {
if (typeof name === "string") {
name = [name, name];
}
var _name2 = name,
_name3 = (0, _slicedToArray3.default)(_name2, 2),
imported = _name3[0],
local = _name3[1];
importDeclarations[imported] = local;
});
}
},
ImportDeclaration: function ImportDeclaration(path) {

@@ -414,3 +433,3 @@ var node = path.node;

},
JSXElement: function JSXElement(path, file) {
JSXElement: function JSXElement(path, state) {
if (!importDeclarations || !(0, _keys2.default)(importDeclarations).length) {

@@ -427,3 +446,3 @@ return;

var props = processElement(node, file, initialProps(),
var props = processElement(node, state, initialProps(),
/* root= */true);

@@ -430,0 +449,0 @@

{
"name": "@lingui/babel-plugin-transform-react",
"version": "2.5.0",
"version": "2.6.0",
"description": "Transform React components to ICU message format",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -24,2 +24,4 @@ [![License][Badge-License]][License]

Without options:
```json

@@ -31,2 +33,14 @@ {

With options:
```json
{
"plugins": [
["@lingui/babel-plugin-transform-react", {
"importedNames": []
}]
]
}
```
### Via CLI

@@ -46,2 +60,58 @@

## Options
### `importedNames`
`array`, defaults to `[]`
This option transforms components without explicit imports. For example following options:
```json
{
"plugins": [
["@lingui/babel-plugin-transform-react", {
"importedNames": ["Trans"]
}]
]
}
```
Transforms all `Trans` components without explicit import, which means this file:
```js
<Trans>Hello World</Trans>;
<Select value="this node is ignored" onChange={() => {}} />;
```
Will be transformed into:
```js
<Trans id="Hello World" />;
<Select value="this node is ignored" onChange={() => {}} />;
```
`Select` is left intact even though it's `@lingui/react` component, because it's
not included in `importedNames`.
Aliases are supported as well:
```json
{
"plugins": [
["@lingui/babel-plugin-transform-react", {
"importedNames": [
["Trans", "T"]
]
}]
]
}
```
Again, `T` component in following file will be tranformed:
```js
<T>Hello World</T>;
<Select value="this node is ignored" onChange={() => {}} />;
```
## License

@@ -48,0 +118,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc