Skip to content

Commit ce76b58

Browse files
committed
👕 refactor: generate code
1 parent e72fde2 commit ce76b58

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

lib/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ Object.defineProperty(exports, "__esModule", {
77
exports.default = function (content) {
88
if (this.version && this.version >= 2) {
99
try {
10-
this.cacheable();
11-
this.callback(null, generateCode(content));
10+
this.cacheable && this.cacheable();
11+
this.callback(null, 'module.exports = ' + generateCode(content));
1212
} catch (err) {
1313
this.emitError(err.message);
1414
this.callback(err);
@@ -26,6 +26,6 @@ function generateCode(content) {
2626
var value = typeof content === 'string' ? JSON.parse(content) : content;
2727
value = JSON.stringify(value).replace(/\u2028/g, '\\u2028').replace(/\u2029/g, '\\u2029');
2828

29-
code += 'module.exports = function (Component) {\n Component.options.__i18n = Component.options.__i18n || []\n Component.options.__i18n.push(\'' + value.replace(/\u0027/g, '\\u0027') + '\')\n}\n';
29+
code += 'function (Component) {\n Component.options.__i18n = Component.options.__i18n || []\n Component.options.__i18n.push(\'' + value.replace(/\u0027/g, '\\u0027') + '\')\n}\n';
3030
return code;
3131
}

src/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
export default function (content) {
22
if (this.version && this.version >= 2) {
33
try {
4-
this.cacheable()
5-
this.callback(null, generateCode(content))
4+
this.cacheable && this.cacheable()
5+
this.callback(null, `module.exports = ${generateCode(content)}`)
66
} catch (err) {
77
this.emitError(err.message)
88
this.callback(err)
@@ -24,7 +24,7 @@ function generateCode (content) {
2424
.replace(/\u2028/g, '\\u2028')
2525
.replace(/\u2029/g, '\\u2029')
2626

27-
code += `module.exports = function (Component) {
27+
code += `function (Component) {
2828
Component.options.__i18n = Component.options.__i18n || []
2929
Component.options.__i18n.push('${value.replace(/\u0027/g, '\\u0027')}')
3030
}\n`

0 commit comments

Comments
 (0)