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

babel-gettext-extractor

Package Overview
Dependencies
Maintainers
2
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-gettext-extractor - npm Package Compare versions

Comparing version 1.0.2 to 2.0.0

50

index.js

@@ -35,16 +35,15 @@ 'use strict';

exports.default = function(_ref) {
exports.default = function() {
var currentFileName;
var data;
var Plugin = _ref.Plugin;
var relocatedComments = {};
return new Plugin('babel-plugin-example', {visitor: {
return {visitor: {
VariableDeclaration: function(node, parent, scope, config) {
var translatorComment = getTranslatorComment(node);
VariableDeclaration: function(nodePath, plugin) {
var translatorComment = getTranslatorComment(nodePath.node);
if (!translatorComment) {
return;
}
node.declarations.forEach(function(declarator) {
nodePath.node.declarations.forEach(function(declarator) {
var comment = getTranslatorComment(declarator);

@@ -58,10 +57,7 @@ if (!comment) {

CallExpression: function(node, parent, scope, config) {
var gtCfg = config.opts && config.opts.extra
&& config.opts.extra.gettext || {};
var functionNames = gtCfg.functionNames || DEFAULT_FUNCTION_NAMES;
var fileName = gtCfg.fileName || DEFAULT_FILE_NAME;
var headers = gtCfg.headers || DEFAULT_HEADERS;
var base = gtCfg.baseDirectory;
CallExpression: function(nodePath, plugin) {
var functionNames = plugin.opts && plugin.opts.functionNames || DEFAULT_FUNCTION_NAMES;
var fileName = plugin.opts && plugin.opts.fileName || DEFAULT_FILE_NAME;
var headers = plugin.opts && plugin.opts.headers || DEFAULT_HEADERS;
var base = plugin.opts && plugin.opts.baseDirectory;
if (base) {

@@ -88,10 +84,12 @@ base = base.match(/^(.*?)\/*$/)[1] + '/';

if (functionNames.hasOwnProperty(node.callee.name)
|| node.callee.property &&
functionNames.hasOwnProperty(node.callee.property.name)) {
var functionName = functionNames[node.callee.name]
|| functionNames[node.callee.property.name];
let callee = nodePath.node.callee;
if (functionNames.hasOwnProperty(callee.name)
|| callee.property &&
functionNames.hasOwnProperty(callee.property.name)) {
var functionName = functionNames[callee.name]
|| functionNames[callee.property.name];
var translate = {};
var args = node.arguments;
var args = nodePath.node.arguments;
for (var i = 0, l = args.length; i < l; i++) {

@@ -116,3 +114,3 @@ var name = functionName[i];

var fn = config.log.filename;
var fn = this.file.opts.filename;
if (base && fn && fn.substr(0, base.length) == base) {

@@ -123,11 +121,11 @@ fn = fn.substr(base.length);

translate.comments = {
reference: fn + ':' + node.loc.start.line
reference: fn + ':' + nodePath.node.loc.start.line
};
var translatorComment = getTranslatorComment(node);
var translatorComment = getTranslatorComment(nodePath.node);
if (!translatorComment) {
translatorComment = getTranslatorComment(parent);
translatorComment = getTranslatorComment(nodePath.parent);
if (!translatorComment) {
translatorComment = relocatedComments[
node.start + '|' + node.end];
nodePath.node.start + '|' + nodePath.node.end];
}

@@ -153,3 +151,3 @@ }

}
}});
}};
};
{
"name": "babel-gettext-extractor",
"version": "1.0.2",
"version": "2.0.0",
"description": " Extract gettext string with babel",

@@ -26,9 +26,9 @@ "main": "index.js",

"dependencies": {
"babel-core": "^5.8.23",
"babel-core": "^6.0.0",
"gettext-parser": "^1.1.1"
},
"devDependencies": {
"babel": "^5.8.23",
"babel": "^6.0.0",
"mocha": "^2.3.4"
}
}

@@ -28,4 +28,4 @@ # babel-gettext-extractor

```js
extra: {
gettext: {
plugins: [
['babel-gettext-extractor', {
headers: <Object>,

@@ -35,4 +35,4 @@ functionNames: <Object>,

baseDirectory: <String>
}
}
}]
]
```

@@ -39,0 +39,0 @@

'use strict';
var assert = require('assert');
var babel = require('babel');
var babel = require('babel-core');
var fs = require('fs');
var plugin = require('../index.js').default;
describe('babel-gettext-plugin', function() {

@@ -14,15 +16,14 @@

var result = babel.transform('let t = _t("code");_t("hello");', {
plugins: ['../index.js'],
extra: {
gettext: {
plugins: [
[plugin, {
functionNames: {
_t: ['msgid']
},
fileName: 'test.po'
}
}
fileName: './test/first.po'
}]
]
});
assert(!!result);
var content = fs.readFileSync('test.po');
var content = fs.readFileSync('./test/first.po');
assert(!!content);

@@ -33,12 +34,11 @@ });

var result = babel.transform('let t = _t("code");_t("hello");', {
plugins: ['../index.js'],
extra: {
gettext: {
fileName: 'test2.po'
}
}
plugins: [
[plugin, {
fileName: './test/test2.po'
}]
]
});
assert(!!result);
assert(!fs.existsSync('test2.po'));
assert(!fs.existsSync('./test/test2.po'));
});

@@ -49,12 +49,11 @@

'"msg", "plurial", 10)', {
plugins: ['../index.js'],
extra: {
gettext: {
fileName: 'test.po'
}
}
plugins: [
[plugin, {
fileName: './test/dnpgettext.po'
}]
]
});
assert(!!result);
var content = fs.readFileSync('test.po');
var content = fs.readFileSync('./test/dnpgettext.po');
assert(!!content);

@@ -66,15 +65,14 @@ });

'let t = _t("code");', {
plugins: ['../index.js'],
extra: {
gettext: {
plugins: [
[plugin, {
functionNames: {
_t: ['msgid']
},
fileName: 'test3.po'
}
}
fileName: './test/comments.po'
}]
]
});
assert(!!result);
var content = fs.readFileSync('test3.po') + '';
var content = fs.readFileSync('./test/comments.po') + '';
assert(content.match(/whatever happens/));

@@ -81,0 +79,0 @@ });

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