babel-gettext-extractor
Advanced tools
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
15843
187
+ Addedbabel-code-frame@6.26.0(transitive)
+ Addedbabel-core@6.26.3(transitive)
+ Addedbabel-generator@6.26.1(transitive)
+ Addedbabel-helpers@6.24.1(transitive)
+ Addedbabel-messages@6.23.0(transitive)
+ Addedbabel-register@6.26.0(transitive)
+ Addedbabel-runtime@6.26.0(transitive)
+ Addedbabel-template@6.26.0(transitive)
+ Addedbabel-traverse@6.26.0(transitive)
+ Addedbabel-types@6.26.0(transitive)
+ Addedbabylon@6.18.0(transitive)
+ Addedcore-js@2.6.12(transitive)
+ Addeddetect-indent@4.0.0(transitive)
+ Addedglobals@9.18.0(transitive)
+ Addedhome-or-tmp@2.0.0(transitive)
+ Addedinvariant@2.2.4(transitive)
+ Addedjs-tokens@3.0.2(transitive)
+ Addedjsesc@1.3.0(transitive)
+ Addedjson5@0.5.1(transitive)
+ Addedlodash@4.17.21(transitive)
+ Addedloose-envify@1.4.0(transitive)
+ Addedminimatch@3.1.2(transitive)
+ Addedos-homedir@1.0.2(transitive)
+ Addedregenerator-runtime@0.11.1(transitive)
+ Addedrepeating@2.0.1(transitive)
+ Addedsource-map-support@0.4.18(transitive)
- Removedacorn@5.7.4(transitive)
- Removedalign-text@0.1.4(transitive)
- Removedalter@0.2.0(transitive)
- Removedamdefine@1.0.1(transitive)
- Removedast-traverse@0.1.1(transitive)
- Removedast-types@0.8.120.9.6(transitive)
- Removedbabel-core@5.8.38(transitive)
- Removedbabel-plugin-constant-folding@1.0.1(transitive)
- Removedbabel-plugin-dead-code-elimination@1.0.2(transitive)
- Removedbabel-plugin-eval@1.0.1(transitive)
- Removedbabel-plugin-inline-environment-variables@1.0.1(transitive)
- Removedbabel-plugin-jscript@1.0.4(transitive)
- Removedbabel-plugin-member-expression-literals@1.0.1(transitive)
- Removedbabel-plugin-property-literals@1.0.1(transitive)
- Removedbabel-plugin-proto-to-assign@1.0.4(transitive)
- Removedbabel-plugin-react-constant-elements@1.0.3(transitive)
- Removedbabel-plugin-react-display-name@1.0.3(transitive)
- Removedbabel-plugin-remove-console@1.0.1(transitive)
- Removedbabel-plugin-remove-debugger@1.0.1(transitive)
- Removedbabel-plugin-runtime@1.0.7(transitive)
- Removedbabel-plugin-undeclared-variables-check@1.0.2(transitive)
- Removedbabel-plugin-undefined-to-void@1.1.6(transitive)
- Removedbabylon@5.8.38(transitive)
- Removedbluebird@2.11.0(transitive)
- Removedbreakable@1.0.0(transitive)
- Removedcamelcase@1.2.1(transitive)
- Removedcenter-align@0.1.3(transitive)
- Removedcliui@2.1.0(transitive)
- Removedcommander@2.20.3(transitive)
- Removedcommoner@0.10.8(transitive)
- Removedcore-js@1.2.7(transitive)
- Removeddecamelize@1.2.0(transitive)
- Removeddefined@1.0.1(transitive)
- Removeddefs@1.1.1(transitive)
- Removeddetect-indent@3.0.1(transitive)
- Removeddetective@4.7.1(transitive)
- Removedesprima@2.7.33.1.3(transitive)
- Removedesprima-fb@15001.1001.0-dev-harmony-fb(transitive)
- Removedfs-readdir-recursive@0.1.2(transitive)
- Removedfunction-bind@1.1.2(transitive)
- Removedget-stdin@4.0.1(transitive)
- Removedglob@5.0.15(transitive)
- Removedglobals@6.4.1(transitive)
- Removedgraceful-fs@4.2.11(transitive)
- Removedhasown@2.0.2(transitive)
- Removedhome-or-tmp@1.0.0(transitive)
- Removediconv-lite@0.4.24(transitive)
- Removedinflight@1.0.6(transitive)
- Removedinherits@2.0.4(transitive)
- Removedinvert-kv@1.0.0(transitive)
- Removedis-buffer@1.1.6(transitive)
- Removedis-core-module@2.15.1(transitive)
- Removedis-integer@1.0.7(transitive)
- Removedjs-tokens@1.0.1(transitive)
- Removedjsesc@0.5.0(transitive)
- Removedjson5@0.4.0(transitive)
- Removedkind-of@3.2.2(transitive)
- Removedlazy-cache@1.0.4(transitive)
- Removedlcid@1.0.0(transitive)
- Removedleven@1.0.2(transitive)
- Removedlodash@3.10.1(transitive)
- Removedlongest@1.0.1(transitive)
- Removedminimatch@2.0.10(transitive)
- Removedobject-assign@4.1.1(transitive)
- Removedonce@1.4.0(transitive)
- Removedos-locale@1.4.0(transitive)
- Removedoutput-file-sync@1.1.2(transitive)
- Removedpath-exists@1.0.0(transitive)
- Removedpath-parse@1.0.7(transitive)
- Removedq@1.5.1(transitive)
- Removedrecast@0.10.330.11.23(transitive)
- Removedregenerate@1.4.2(transitive)
- Removedregenerator@0.8.40(transitive)
- Removedregexpu@1.3.0(transitive)
- Removedregjsgen@0.2.0(transitive)
- Removedregjsparser@0.1.5(transitive)
- Removedrepeat-string@1.6.1(transitive)
- Removedrepeating@1.1.3(transitive)
- Removedresolve@1.22.8(transitive)
- Removedright-align@0.1.3(transitive)
- Removedshebang-regex@1.0.0(transitive)
- Removedsimple-fmt@0.1.0(transitive)
- Removedsimple-is@0.2.0(transitive)
- Removedsource-map@0.1.32(transitive)
- Removedsource-map-support@0.2.10(transitive)
- Removedstable@0.1.8(transitive)
- Removedstringmap@0.2.2(transitive)
- Removedstringset@0.2.1(transitive)
- Removedsupports-preserve-symlinks-flag@1.0.0(transitive)
- Removedthrough@2.3.8(transitive)
- Removedtry-resolve@1.0.1(transitive)
- Removedtryor@0.1.2(transitive)
- Removeduser-home@1.1.1(transitive)
- Removedwindow-size@0.1.4(transitive)
- Removedwordwrap@0.0.2(transitive)
- Removedwrappy@1.0.2(transitive)
- Removedy18n@3.2.2(transitive)
- Removedyargs@3.27.0(transitive)
Updatedbabel-core@^6.0.0