Skip to content

Commit

Permalink
chore: code prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
zongwenjian committed Feb 28, 2022
1 parent 89ab7e5 commit 8bbc485
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 23 deletions.
2 changes: 1 addition & 1 deletion kiwi-cli/src/export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function exportMessages(file?: string, lang?: string) {
console.log('All the messages have been translated.');
return;
}

const content = tsvFormatRows(messagesToTranslate);
const sourceFile = file || `./export-${lang}`;
fs.writeFileSync(sourceFile, content);
Expand Down
26 changes: 12 additions & 14 deletions kiwi-cli/src/extract/findChineseText.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import * as compilerVue from 'vue-template-compiler';
import * as babel from '@babel/core';
const DOUBLE_BYTE_REGEX = /[^\x00-\xff]/g;


function transerI18n(code, filename, lang) {
if (lang === 'ts') {
return typescriptI18n(code, filename);
Expand Down Expand Up @@ -245,24 +244,23 @@ function findTextInVue(code: string) {
let expressTemp = findVueText(vueAst);
expressTemp.forEach(item => {
item.arrf = [item.start, item.end];

});
matches = expressTemp;
let outcode = vueObejct.render.toString().replace('with(this)', 'function a()');
let vueTemp = transerI18n(outcode, 'as.vue', null);

/**删除所有的html中的头部空格 */
vueTemp = vueTemp.map(item => {
return item.trim();
});
vueTemp = Array.from(new Set(vueTemp))
let codeStaticArr = []

vueTemp = Array.from(new Set(vueTemp));
let codeStaticArr = [];
vueObejct.staticRenderFns.forEach(item => {
let childcode = item.toString().replace('with(this)', 'function a()')
let vueTempChild = transerI18n(childcode, 'as.vue', null)
codeStaticArr = codeStaticArr.concat(Array.from(new Set(vueTempChild)))
})
let childcode = item.toString().replace('with(this)', 'function a()');
let vueTempChild = transerI18n(childcode, 'as.vue', null);
codeStaticArr = codeStaticArr.concat(Array.from(new Set(vueTempChild)));
});
vueTemp = Array.from(new Set(codeStaticArr.concat(vueTemp)));
vueTemp.forEach(item => {
let items = item
Expand All @@ -275,12 +273,12 @@ function findTextInVue(code: string) {
.replace(/\*/g, '\\*')
.replace(/\^/g, '\\^');
let rex = new RegExp(items, 'g');
let codeTemplate = code.substring((vueObejct.ast as any).start, (vueObejct.ast as any).end)
let codeTemplate = code.substring((vueObejct.ast as any).start, (vueObejct.ast as any).end);
while ((result = rex.exec(codeTemplate))) {
let res = result;
let last = rex.lastIndex;
last = last - (res[0].length - res[0].trimRight().length);
const range = {start:res.index,end: last}
const range = { start: res.index, end: last };
matches.push({
arrf: [res.index, last],
range,
Expand Down Expand Up @@ -327,7 +325,7 @@ function findTextInVueTs(code: string, fileName: string, startNum: number) {
const start = node.getStart();
const end = node.getEnd();
/** 加一,减一的原因是,去除引号 */
const range = {start: start + startNum, end: end + startNum}
const range = { start: start + startNum, end: end + startNum };
matches.push({
range,
text,
Expand All @@ -344,7 +342,7 @@ function findTextInVueTs(code: string, fileName: string, startNum: number) {
const start = node.getStart();
const end = node.getEnd();
/** 加一,减一的原因是,去除`号 */
const range = {start: start + startNum, end: end + startNum}
const range = { start: start + startNum, end: end + startNum };
matches.push({
range,
text: code.slice(start + 1, end - 1),
Expand Down
2 changes: 1 addition & 1 deletion kiwi-demo/src/A.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
import I18N from 'src/utils/I18N';
let a = I18N.src.A.danWei
let a = I18N.src.A.danWei;
14 changes: 7 additions & 7 deletions kiwi-linter/src/findChineseText.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,12 +283,12 @@ function findTextInVue(code, fileName) {
return item.trim();
});
vueTemp = [...new Set(vueTemp)];
let codeStaticArr = []
let codeStaticArr = [];
vueObejct.staticRenderFns.forEach(item => {
let childcode = item.toString().replace('with(this)', 'function a()')
let vueTempChild = transerI18n(childcode, 'as.vue', null)
codeStaticArr = codeStaticArr.concat([...new Set(vueTempChild)])
})
let childcode = item.toString().replace('with(this)', 'function a()');
let vueTempChild = transerI18n(childcode, 'as.vue', null);
codeStaticArr = codeStaticArr.concat([...new Set(vueTempChild)]);
});
vueTemp = [...new Set(codeStaticArr.concat(vueTemp))];
vueTemp.forEach(item => {
let items = item
Expand All @@ -301,7 +301,7 @@ function findTextInVue(code, fileName) {
.replace(/\*/g, '\\*')
.replace(/\^/g, '\\^');
let rex = new RegExp(items, 'g');
let codeTemplate = code.substring(vueObejct.ast.start, vueObejct.ast.end)
let codeTemplate = code.substring((vueObejct.ast as any).start, (vueObejct.ast as any).end);
while ((result = rex.exec(codeTemplate))) {
let res = result;
let last = rex.lastIndex;
Expand Down Expand Up @@ -338,7 +338,7 @@ function findTextInVue(code, fileName) {
if (canBe) return item;
});
const sfc = compilerVue.parseComponent(code.toString());

return matchesTempResult.concat(findTextInVueTs(sfc.script.content, fileName, sfc.script.start));
}
/**
Expand Down

0 comments on commit 8bbc485

Please sign in to comment.