i18next-scanner
Advanced tools
Comparing version 1.9.2 to 1.9.3
@@ -53,3 +53,2 @@ 'use strict'; | ||
customTransform.call(this, file, enc, done); | ||
return; | ||
@@ -72,3 +71,2 @@ } | ||
customFlush.call(this, done); | ||
return; | ||
@@ -75,0 +73,0 @@ } |
@@ -379,22 +379,35 @@ 'use strict'; | ||
if (endsWithComma) { | ||
var _opts = _extends({}, opts), | ||
propsFilter = _opts.propsFilter; | ||
var code = matchBalancedParentheses(content.substr(re.lastIndex)); | ||
var syntax = (0, _esprima.parse)('(' + code + ')'); | ||
var props = (0, _get2.default)(syntax, 'body[0].expression.properties') || []; | ||
// http://i18next.com/docs/options/ | ||
var supportedOptions = ['defaultValue', 'count', 'context', 'ns']; | ||
props.forEach(function (prop) { | ||
if ((0, _includes2.default)(supportedOptions, prop.key.name)) { | ||
if (prop.value.type === 'Literal') { | ||
options[prop.key.name] = prop.value.value; | ||
} else if (prop.value.type === 'TemplateLiteral') { | ||
options[prop.key.name] = prop.value.quasis.map(function (element) { | ||
return element.value.cooked; | ||
}).join(''); | ||
} else { | ||
// Unable to get value of the property | ||
options[prop.key.name] = ''; | ||
if (typeof propsFilter === 'function') { | ||
code = propsFilter(code); | ||
} | ||
try { | ||
var syntax = (0, _esprima.parse)('(' + code + ')'); | ||
var props = (0, _get2.default)(syntax, 'body[0].expression.properties') || []; | ||
// http://i18next.com/docs/options/ | ||
var supportedOptions = ['defaultValue', 'count', 'context', 'ns']; | ||
props.forEach(function (prop) { | ||
if ((0, _includes2.default)(supportedOptions, prop.key.name)) { | ||
if (prop.value.type === 'Literal') { | ||
options[prop.key.name] = prop.value.value; | ||
} else if (prop.value.type === 'TemplateLiteral') { | ||
options[prop.key.name] = prop.value.quasis.map(function (element) { | ||
return element.value.cooked; | ||
}).join(''); | ||
} else { | ||
// Unable to get value of the property | ||
options[prop.key.name] = ''; | ||
} | ||
} | ||
} | ||
}); | ||
}); | ||
} catch (err) { | ||
_this2.debuglog('Unable to parse code "' + code + '"'); | ||
_this2.debuglog(err); | ||
} | ||
} | ||
@@ -401,0 +414,0 @@ |
{ | ||
"name": "i18next-scanner", | ||
"version": "1.9.2", | ||
"version": "1.9.3", | ||
"description": "Scan your code, extract translation keys/values, and merge them into i18n resource files.", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/i18next/i18next-scanner", |
@@ -28,3 +28,2 @@ import fs from 'fs'; | ||
customTransform.call(this, file, enc, done); | ||
return; | ||
@@ -44,3 +43,2 @@ } | ||
customFlush.call(this, done); | ||
return; | ||
@@ -47,0 +45,0 @@ } |
@@ -293,27 +293,39 @@ /* eslint no-console: 0 */ | ||
if (endsWithComma) { | ||
const code = matchBalancedParentheses(content.substr(re.lastIndex)); | ||
const syntax = parse('(' + code + ')'); | ||
const props = get(syntax, 'body[0].expression.properties') || []; | ||
// http://i18next.com/docs/options/ | ||
const supportedOptions = [ | ||
'defaultValue', | ||
'count', | ||
'context', | ||
'ns' | ||
]; | ||
const { propsFilter } = { ...opts }; | ||
props.forEach((prop) => { | ||
if (includes(supportedOptions, prop.key.name)) { | ||
if (prop.value.type === 'Literal') { | ||
options[prop.key.name] = prop.value.value; | ||
} else if (prop.value.type === 'TemplateLiteral') { | ||
options[prop.key.name] = prop.value.quasis | ||
.map(element => element.value.cooked) | ||
.join(''); | ||
} else { | ||
// Unable to get value of the property | ||
options[prop.key.name] = ''; | ||
let code = matchBalancedParentheses(content.substr(re.lastIndex)); | ||
if (typeof propsFilter === 'function') { | ||
code = propsFilter(code); | ||
} | ||
try { | ||
const syntax = parse('(' + code + ')'); | ||
const props = get(syntax, 'body[0].expression.properties') || []; | ||
// http://i18next.com/docs/options/ | ||
const supportedOptions = [ | ||
'defaultValue', | ||
'count', | ||
'context', | ||
'ns' | ||
]; | ||
props.forEach((prop) => { | ||
if (includes(supportedOptions, prop.key.name)) { | ||
if (prop.value.type === 'Literal') { | ||
options[prop.key.name] = prop.value.value; | ||
} else if (prop.value.type === 'TemplateLiteral') { | ||
options[prop.key.name] = prop.value.quasis | ||
.map(element => element.value.cooked) | ||
.join(''); | ||
} else { | ||
// Unable to get value of the property | ||
options[prop.key.name] = ''; | ||
} | ||
} | ||
} | ||
}); | ||
}); | ||
} catch (err) { | ||
this.debuglog(`Unable to parse code "${code}"`); | ||
this.debuglog(err); | ||
} | ||
} | ||
@@ -320,0 +332,0 @@ |
@@ -349,3 +349,3 @@ import fs from 'fs'; | ||
const content = fs.readFileSync(path.resolve(__dirname, 'fixtures/plural.js'), 'utf-8'); | ||
parser.parseFuncFromString(content); | ||
parser.parseFuncFromString(content, { propsFilter: props => props }); | ||
t.same(parser.get(), { | ||
@@ -386,3 +386,3 @@ en: { | ||
const content = fs.readFileSync(path.resolve(__dirname, 'fixtures/context.js'), 'utf-8'); | ||
parser.parseFuncFromString(content); | ||
parser.parseFuncFromString(content, { propsFilter: props => props }); | ||
t.same(parser.get(), { | ||
@@ -555,2 +555,2 @@ en: { | ||
t.end(); | ||
}); | ||
}); |
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
123605
2511