Socket
Socket
Sign inDemoInstall

babel-plugin-lingui-transform-js

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-lingui-transform-js - npm Package Compare versions

Comparing version 1.0.4 to 1.0.6

11

CHANGELOG.md

@@ -6,2 +6,13 @@ # Change Log

<a name="1.0.5"></a>
## [1.0.5](https://github.com/lingui/js-lingui/compare/babel-plugin-lingui-transform-js@1.0.4...babel-plugin-lingui-transform-js@1.0.5) (2017-11-24)
### Bug Fixes
* Allow expressions inside template literals ([28c3803](https://github.com/lingui/js-lingui/commit/28c3803))
<a name="1.0.4"></a>

@@ -8,0 +19,0 @@ ## [1.0.4](https://github.com/lingui/js-lingui/compare/babel-plugin-lingui-transform-js@1.0.3...babel-plugin-lingui-transform-js@1.0.4) (2017-10-02)

43

dist/index.es.js

@@ -12,2 +12,9 @@ import _Object$values from 'babel-runtime/core-js/object/values';

var generatorFactory = function generatorFactory() {
var index = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
return function () {
return index++;
};
};
// Plugin function

@@ -17,2 +24,4 @@ var index = function (_ref) {

var argumentGenerator = void 0;
var isI18nMethod = function isI18nMethod(node) {

@@ -68,10 +77,5 @@ return t.isMemberExpression(node.tag) && t.isIdentifier(node.tag.object, { name: 'i18n' }) && t.isIdentifier(node.tag.property, { name: 't' });

var _exp = attr.value;
// value must be a variable
if (!t.isIdentifier(_exp)) {
throw file.buildCodeFrameError(node.callee, 'Value must be a variable.');
}
variable = _exp.name;
props.values[variable] = t.objectProperty(_exp, _exp);
variable = t.isIdentifier(_exp) ? _exp.name : argumentGenerator();
var _key = t.isIdentifier(_exp) ? _exp : t.numericLiteral(variable);
props.values[variable] = t.objectProperty(_key, _exp);
} else if (choicesType !== 'select' && name === 'offset') {

@@ -115,3 +119,3 @@ // offset is static parameter, so it must be either string or number

if (!variable) {
if (variable === undefined) {
throw file.buildCodeFrameError(node.callee, 'Value argument is missing.');

@@ -143,11 +147,14 @@ }

} else if (isFormatMethod(node.callee)) {
var _variable = node.arguments[0];
var _exp2 = node.arguments[0];
// missing value
if (!_variable || !t.isIdentifier(_variable)) {
if (_exp2 === undefined) {
throw file.buildCodeFrameError(node.callee, 'The first argument of format function must be a variable.');
}
var _variable = t.isIdentifier(_exp2) ? _exp2.name : argumentGenerator();
var _key2 = t.isIdentifier(_exp2) ? _exp2 : t.numericLiteral(_variable);
var type = node.callee.property.name;
var parts = [_variable.name, // variable name
var parts = [_variable, // variable name
type // format type

@@ -180,3 +187,3 @@ ];

props.values[_variable.name] = t.objectProperty(_variable, _variable);
props.values[_variable] = t.objectProperty(_key2, _exp2);
props.text += '' + parts.join(',');

@@ -200,3 +207,3 @@ }

props.text += item.value.raw;
} else if (t.isCallExpression(item)) {
} else if (t.isCallExpression(item) && (isI18nMethod(item.callee) || isChoiceMethod(item.callee) || isFormatMethod(item.callee))) {
var _processMethod = processMethod(item, file, _extends({}, props, { text: '' })),

@@ -207,4 +214,6 @@ text = _processMethod.text;

} else {
props.text += '{' + item.name + '}';
props.values[item.name] = t.objectProperty(item, item);
var name = t.isIdentifier(item) ? item.name : argumentGenerator();
var key = t.isIdentifier(item) ? item : t.numericLiteral(name);
props.text += '{' + name + '}';
props.values[name] = t.objectProperty(key, item);
}

@@ -219,2 +228,4 @@ });

argumentGenerator = generatorFactory();
// 1. Collect all parameters and generate message ID

@@ -221,0 +232,0 @@

@@ -16,2 +16,9 @@ 'use strict';

var generatorFactory = function generatorFactory() {
var index = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
return function () {
return index++;
};
};
// Plugin function

@@ -21,2 +28,4 @@ var index = function (_ref) {

var argumentGenerator = void 0;
var isI18nMethod = function isI18nMethod(node) {

@@ -72,10 +81,5 @@ return t.isMemberExpression(node.tag) && t.isIdentifier(node.tag.object, { name: 'i18n' }) && t.isIdentifier(node.tag.property, { name: 't' });

var _exp = attr.value;
// value must be a variable
if (!t.isIdentifier(_exp)) {
throw file.buildCodeFrameError(node.callee, 'Value must be a variable.');
}
variable = _exp.name;
props.values[variable] = t.objectProperty(_exp, _exp);
variable = t.isIdentifier(_exp) ? _exp.name : argumentGenerator();
var _key = t.isIdentifier(_exp) ? _exp : t.numericLiteral(variable);
props.values[variable] = t.objectProperty(_key, _exp);
} else if (choicesType !== 'select' && name === 'offset') {

@@ -119,3 +123,3 @@ // offset is static parameter, so it must be either string or number

if (!variable) {
if (variable === undefined) {
throw file.buildCodeFrameError(node.callee, 'Value argument is missing.');

@@ -147,11 +151,14 @@ }

} else if (isFormatMethod(node.callee)) {
var _variable = node.arguments[0];
var _exp2 = node.arguments[0];
// missing value
if (!_variable || !t.isIdentifier(_variable)) {
if (_exp2 === undefined) {
throw file.buildCodeFrameError(node.callee, 'The first argument of format function must be a variable.');
}
var _variable = t.isIdentifier(_exp2) ? _exp2.name : argumentGenerator();
var _key2 = t.isIdentifier(_exp2) ? _exp2 : t.numericLiteral(_variable);
var type = node.callee.property.name;
var parts = [_variable.name, // variable name
var parts = [_variable, // variable name
type // format type

@@ -184,3 +191,3 @@ ];

props.values[_variable.name] = t.objectProperty(_variable, _variable);
props.values[_variable] = t.objectProperty(_key2, _exp2);
props.text += '' + parts.join(',');

@@ -204,3 +211,3 @@ }

props.text += item.value.raw;
} else if (t.isCallExpression(item)) {
} else if (t.isCallExpression(item) && (isI18nMethod(item.callee) || isChoiceMethod(item.callee) || isFormatMethod(item.callee))) {
var _processMethod = processMethod(item, file, _extends({}, props, { text: '' })),

@@ -211,4 +218,6 @@ text = _processMethod.text;

} else {
props.text += '{' + item.name + '}';
props.values[item.name] = t.objectProperty(item, item);
var name = t.isIdentifier(item) ? item.name : argumentGenerator();
var key = t.isIdentifier(item) ? item : t.numericLiteral(name);
props.text += '{' + name + '}';
props.values[name] = t.objectProperty(key, item);
}

@@ -223,2 +232,4 @@ });

argumentGenerator = generatorFactory();
// 1. Collect all parameters and generate message ID

@@ -225,0 +236,0 @@

{
"name": "babel-plugin-lingui-transform-js",
"version": "1.0.4",
"version": "1.0.6",
"description": "Transform lingui-i18n methods to ICU message format",

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

Sorry, the diff of this file is not supported yet

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