@tolgee/cli 2.8.4 → 2.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +116 -94
- package/dist/client/ApiClient.js +40 -32
- package/dist/client/ExportClient.js +24 -11
- package/dist/client/ImportClient.js +25 -16
- package/dist/client/TolgeeClient.js +1 -5
- package/dist/client/errorFromLoadable.js +3 -2
- package/dist/client/getApiKeyInformation.js +16 -6
- package/dist/commands/extract/check.js +38 -27
- package/dist/commands/extract/print.js +46 -35
- package/dist/commands/login.js +39 -26
- package/dist/commands/pull.js +60 -43
- package/dist/commands/push.js +167 -117
- package/dist/commands/sync/compare.js +43 -31
- package/dist/commands/sync/sync.js +118 -99
- package/dist/commands/sync/syncUtils.js +2 -1
- package/dist/commands/tag.js +52 -38
- package/dist/config/credentials.js +110 -93
- package/dist/config/tolgeerc.js +51 -35
- package/dist/extractor/extractor.js +45 -31
- package/dist/extractor/parser/extractComment.js +1 -1
- package/dist/extractor/parser/generateReport.js +8 -6
- package/dist/extractor/parser/iterator.js +2 -1
- package/dist/extractor/parser/mergerMachine.js +2 -11
- package/dist/extractor/parser/nodeUtils.js +1 -1
- package/dist/extractor/parser/parser.js +4 -2
- package/dist/extractor/parser/rules/tNsSourceGeneral.js +1 -1
- package/dist/extractor/parser/tree/getTranslateProps.js +21 -16
- package/dist/extractor/parser/tree/getValue.js +1 -1
- package/dist/extractor/parser/tree/parseTag.js +1 -1
- package/dist/extractor/parserNgx/ParserNgx.js +1 -3
- package/dist/extractor/parserNgx/ngxMapper.js +2 -1
- package/dist/extractor/parserNgx/ngxTreeTransform.js +3 -2
- package/dist/extractor/parserNgx/rules/translatePipe.js +1 -1
- package/dist/extractor/parserReact/ParserReact.js +1 -3
- package/dist/extractor/parserSvelte/ParserSvelte.js +1 -3
- package/dist/extractor/parserVue/ParserVue.js +1 -3
- package/dist/extractor/parserVue/tokenMergers/hyphenPropsMerger.js +1 -4
- package/dist/extractor/parserVue/vueTreeTransform.js +13 -2
- package/dist/extractor/runner.js +53 -39
- package/dist/extractor/tokenizer.js +50 -35
- package/dist/extractor/visualizers/printTokens.js +2 -1
- package/dist/extractor/visualizers/visualizeRules.js +4 -7
- package/dist/extractor/warnings.js +3 -2
- package/dist/extractor/worker.js +29 -16
- package/dist/options.js +2 -1
- package/dist/utils/apiKeyList.js +31 -19
- package/dist/utils/ask.js +35 -21
- package/dist/utils/checkPathNotAFile.js +22 -11
- package/dist/utils/filesTemplate.js +147 -0
- package/dist/utils/mapExportFormat.js +2 -0
- package/dist/utils/mapImportFormat.js +1 -1
- package/dist/utils/moduleLoader.js +37 -23
- package/dist/utils/prepareDir.js +20 -9
- package/dist/utils/valueToArray.js +8 -0
- package/package.json +2 -2
- package/schema.json +20 -4
@@ -1,123 +1,140 @@
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
8
|
+
});
|
9
|
+
};
|
1
10
|
import { join, dirname } from 'path';
|
2
11
|
import { mkdir, readFile, writeFile } from 'fs/promises';
|
3
12
|
import { warn } from '../utils/logger.js';
|
4
13
|
import { CONFIG_PATH } from '../constants.js';
|
5
14
|
const API_TOKENS_FILE = join(CONFIG_PATH, 'authentication.json');
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
15
|
+
function ensureConfigPath() {
|
16
|
+
return __awaiter(this, void 0, void 0, function* () {
|
17
|
+
try {
|
18
|
+
yield mkdir(dirname(API_TOKENS_FILE));
|
19
|
+
}
|
20
|
+
catch (e) {
|
21
|
+
if (e.code !== 'EEXIST') {
|
22
|
+
throw e;
|
23
|
+
}
|
13
24
|
}
|
14
|
-
}
|
25
|
+
});
|
15
26
|
}
|
16
|
-
export
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
catch (e) {
|
23
|
-
if (e.code !== 'ENOENT') {
|
24
|
-
throw e;
|
27
|
+
export function loadStore() {
|
28
|
+
return __awaiter(this, void 0, void 0, function* () {
|
29
|
+
try {
|
30
|
+
yield ensureConfigPath();
|
31
|
+
const storeData = yield readFile(API_TOKENS_FILE, 'utf8');
|
32
|
+
return JSON.parse(storeData);
|
25
33
|
}
|
26
|
-
|
27
|
-
|
34
|
+
catch (e) {
|
35
|
+
if (e.code !== 'ENOENT') {
|
36
|
+
throw e;
|
37
|
+
}
|
38
|
+
}
|
39
|
+
return {};
|
40
|
+
});
|
28
41
|
}
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
42
|
+
function saveStore(store) {
|
43
|
+
return __awaiter(this, void 0, void 0, function* () {
|
44
|
+
const blob = JSON.stringify(store);
|
45
|
+
yield writeFile(API_TOKENS_FILE, blob, {
|
46
|
+
mode: 0o600,
|
47
|
+
encoding: 'utf8',
|
48
|
+
});
|
34
49
|
});
|
35
50
|
}
|
36
|
-
|
37
|
-
return
|
38
|
-
|
39
|
-
[instance.hostname]: {
|
40
|
-
...(store[instance.hostname] || {}),
|
41
|
-
user: pat,
|
42
|
-
},
|
51
|
+
function storePat(store, instance, pat) {
|
52
|
+
return __awaiter(this, void 0, void 0, function* () {
|
53
|
+
return saveStore(Object.assign(Object.assign({}, store), { [instance.hostname]: Object.assign(Object.assign({}, (store[instance.hostname] || {})), { user: pat }) }));
|
43
54
|
});
|
44
55
|
}
|
45
|
-
|
46
|
-
return
|
47
|
-
|
48
|
-
[instance.hostname]: {
|
49
|
-
...(store[instance.hostname] || {}),
|
50
|
-
projects: {
|
51
|
-
...(store[instance.hostname]?.projects || {}),
|
52
|
-
[project.id.toString(10)]: pak,
|
53
|
-
},
|
54
|
-
projectDetails: {
|
55
|
-
...(store[instance.hostname]?.projectDetails || {}),
|
56
|
-
[project.id.toString(10)]: { name: project.name },
|
57
|
-
},
|
58
|
-
},
|
56
|
+
function storePak(store, instance, project, pak) {
|
57
|
+
return __awaiter(this, void 0, void 0, function* () {
|
58
|
+
var _a, _b;
|
59
|
+
return saveStore(Object.assign(Object.assign({}, store), { [instance.hostname]: Object.assign(Object.assign({}, (store[instance.hostname] || {})), { projects: Object.assign(Object.assign({}, (((_a = store[instance.hostname]) === null || _a === void 0 ? void 0 : _a.projects) || {})), { [project.id.toString(10)]: pak }), projectDetails: Object.assign(Object.assign({}, (((_b = store[instance.hostname]) === null || _b === void 0 ? void 0 : _b.projectDetails) || {})), { [project.id.toString(10)]: { name: project.name } }) }) }));
|
59
60
|
});
|
60
61
|
}
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
62
|
+
function removePak(store, instance, projectId) {
|
63
|
+
return __awaiter(this, void 0, void 0, function* () {
|
64
|
+
var _a, _b;
|
65
|
+
(_a = store[instance.hostname].projects) === null || _a === void 0 ? true : delete _a[projectId.toString(10)];
|
66
|
+
(_b = store[instance.hostname].projectDetails) === null || _b === void 0 ? true : delete _b[projectId.toString(10)];
|
67
|
+
return saveStore(store);
|
68
|
+
});
|
65
69
|
}
|
66
|
-
export
|
67
|
-
|
68
|
-
|
70
|
+
export function savePat(instance, pat) {
|
71
|
+
return __awaiter(this, void 0, void 0, function* () {
|
72
|
+
const store = yield loadStore();
|
73
|
+
return storePat(store, instance, pat);
|
74
|
+
});
|
69
75
|
}
|
70
|
-
export
|
71
|
-
|
72
|
-
|
76
|
+
export function savePak(instance, project, pak) {
|
77
|
+
return __awaiter(this, void 0, void 0, function* () {
|
78
|
+
const store = yield loadStore();
|
79
|
+
return storePak(store, instance, project, pak);
|
80
|
+
});
|
73
81
|
}
|
74
|
-
export
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
const scopedStore = store[instance.hostname];
|
80
|
-
if (scopedStore.user) {
|
81
|
-
if (scopedStore.user.expires !== 0 &&
|
82
|
-
Date.now() > scopedStore.user.expires) {
|
83
|
-
warn(`Your personal access token for ${instance.hostname} expired.`);
|
84
|
-
await storePat(store, instance, undefined);
|
82
|
+
export function getApiKey(instance, projectId) {
|
83
|
+
return __awaiter(this, void 0, void 0, function* () {
|
84
|
+
var _a;
|
85
|
+
const store = yield loadStore();
|
86
|
+
if (!store[instance.hostname]) {
|
85
87
|
return null;
|
86
88
|
}
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
89
|
+
const scopedStore = store[instance.hostname];
|
90
|
+
if (scopedStore.user) {
|
91
|
+
if (scopedStore.user.expires !== 0 &&
|
92
|
+
Date.now() > scopedStore.user.expires) {
|
93
|
+
warn(`Your personal access token for ${instance.hostname} expired.`);
|
94
|
+
yield storePat(store, instance, undefined);
|
95
|
+
return null;
|
96
|
+
}
|
97
|
+
return scopedStore.user.token;
|
98
|
+
}
|
99
|
+
if (projectId <= 0) {
|
97
100
|
return null;
|
98
101
|
}
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
+
const pak = (_a = scopedStore.projects) === null || _a === void 0 ? void 0 : _a[projectId.toString(10)];
|
103
|
+
if (pak) {
|
104
|
+
if (pak.expires !== 0 && Date.now() > pak.expires) {
|
105
|
+
warn(`Your project API key for project #${projectId} on ${instance.hostname} expired.`);
|
106
|
+
yield removePak(store, instance, projectId);
|
107
|
+
return null;
|
108
|
+
}
|
109
|
+
return pak.token;
|
110
|
+
}
|
111
|
+
return null;
|
112
|
+
});
|
102
113
|
}
|
103
|
-
export
|
104
|
-
|
105
|
-
|
106
|
-
|
114
|
+
export function saveApiKey(instance, token) {
|
115
|
+
return __awaiter(this, void 0, void 0, function* () {
|
116
|
+
const store = yield loadStore();
|
117
|
+
if (token.type === 'PAT') {
|
118
|
+
return storePat(store, instance, {
|
119
|
+
token: token.key,
|
120
|
+
expires: token.expires,
|
121
|
+
});
|
122
|
+
}
|
123
|
+
return storePak(store, instance, token.project, {
|
107
124
|
token: token.key,
|
108
125
|
expires: token.expires,
|
109
126
|
});
|
110
|
-
}
|
111
|
-
return storePak(store, instance, token.project, {
|
112
|
-
token: token.key,
|
113
|
-
expires: token.expires,
|
114
127
|
});
|
115
128
|
}
|
116
|
-
export
|
117
|
-
|
118
|
-
|
119
|
-
|
129
|
+
export function removeApiKeys(api) {
|
130
|
+
return __awaiter(this, void 0, void 0, function* () {
|
131
|
+
const store = yield loadStore();
|
132
|
+
delete store[api.hostname];
|
133
|
+
return saveStore(store);
|
134
|
+
});
|
120
135
|
}
|
121
|
-
export
|
122
|
-
return
|
136
|
+
export function clearAuthStore() {
|
137
|
+
return __awaiter(this, void 0, void 0, function* () {
|
138
|
+
return saveStore({});
|
139
|
+
});
|
123
140
|
}
|
package/dist/config/tolgeerc.js
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
8
|
+
});
|
9
|
+
};
|
1
10
|
import { cosmiconfig, defaultLoaders } from 'cosmiconfig';
|
2
11
|
import { Validator } from 'jsonschema';
|
3
12
|
import { readFile } from 'fs/promises';
|
@@ -5,18 +14,20 @@ import { fileURLToPath } from 'url';
|
|
5
14
|
import { dirname, join, resolve } from 'path';
|
6
15
|
import { error, exitWithError } from '../utils/logger.js';
|
7
16
|
import { existsSync } from 'fs';
|
17
|
+
import { valueToArray } from '../utils/valueToArray.js';
|
8
18
|
const explorer = cosmiconfig('tolgee', {
|
9
19
|
loaders: {
|
10
20
|
noExt: defaultLoaders['.json'],
|
11
21
|
},
|
12
22
|
});
|
13
23
|
function parseConfig(input, configDir) {
|
14
|
-
|
24
|
+
var _a, _b, _c, _d;
|
25
|
+
const rc = Object.assign({}, input);
|
15
26
|
if (rc.apiUrl !== undefined) {
|
16
27
|
try {
|
17
28
|
new URL(rc.apiUrl);
|
18
29
|
}
|
19
|
-
catch {
|
30
|
+
catch (_e) {
|
20
31
|
throw new Error('Invalid config: apiUrl is an invalid URL');
|
21
32
|
}
|
22
33
|
}
|
@@ -38,46 +49,51 @@ function parseConfig(input, configDir) {
|
|
38
49
|
rc.patterns = rc.patterns.map((pattern) => resolve(configDir, pattern).replace(/\\/g, '/'));
|
39
50
|
}
|
40
51
|
// convert relative paths in config to absolute
|
41
|
-
if (rc.push
|
42
|
-
rc.push.files = rc.push.files.map((r) => ({
|
43
|
-
...r,
|
44
|
-
path: resolve(configDir, r.path).replace(/\\/g, '/'),
|
45
|
-
}));
|
52
|
+
if ((_a = rc.push) === null || _a === void 0 ? void 0 : _a.files) {
|
53
|
+
rc.push.files = rc.push.files.map((r) => (Object.assign(Object.assign({}, r), { path: resolve(configDir, r.path).replace(/\\/g, '/') })));
|
46
54
|
}
|
47
55
|
// convert relative paths in config to absolute
|
48
|
-
if (rc.
|
56
|
+
if ((_b = rc.push) === null || _b === void 0 ? void 0 : _b.filesTemplate) {
|
57
|
+
rc.push.filesTemplate = (_c = valueToArray(rc.push.filesTemplate)) === null || _c === void 0 ? void 0 : _c.map((template) => resolve(configDir, template).replace(/\\/g, '/'));
|
58
|
+
}
|
59
|
+
// convert relative paths in config to absolute
|
60
|
+
if (((_d = rc.pull) === null || _d === void 0 ? void 0 : _d.path) !== undefined) {
|
49
61
|
rc.pull.path = resolve(configDir, rc.pull.path).replace(/\\/g, '/');
|
50
62
|
}
|
51
63
|
return rc;
|
52
64
|
}
|
53
|
-
|
54
|
-
|
55
|
-
|
65
|
+
function getSchema() {
|
66
|
+
return __awaiter(this, void 0, void 0, function* () {
|
67
|
+
const path = join(fileURLToPath(new URL('.', import.meta.url)), '..', '..', 'schema.json');
|
68
|
+
return JSON.parse((yield readFile(path)).toString());
|
69
|
+
});
|
56
70
|
}
|
57
|
-
export default
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
71
|
+
export default function loadTolgeeRc(path) {
|
72
|
+
return __awaiter(this, void 0, void 0, function* () {
|
73
|
+
let res;
|
74
|
+
if (path) {
|
75
|
+
try {
|
76
|
+
res = yield explorer.load(path);
|
77
|
+
}
|
78
|
+
catch (e) {
|
79
|
+
error(e.message);
|
80
|
+
throw new Error(`Can't open config file on path "${path}"`);
|
81
|
+
}
|
62
82
|
}
|
63
|
-
|
64
|
-
|
65
|
-
throw new Error(`Can't open config file on path "${path}"`);
|
83
|
+
else {
|
84
|
+
res = yield explorer.search();
|
66
85
|
}
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
exitWithError(errMessage);
|
81
|
-
}
|
82
|
-
return config;
|
86
|
+
if (!res || res.isEmpty)
|
87
|
+
return null;
|
88
|
+
const config = parseConfig(res.config, dirname(path || '.'));
|
89
|
+
const validator = new Validator();
|
90
|
+
const schema = yield getSchema();
|
91
|
+
const result = validator.validate(config, schema);
|
92
|
+
if (result.errors.length) {
|
93
|
+
const { message, property } = result.errors[0];
|
94
|
+
const errMessage = `Tolgee config: '${property.replace('instance.', '')}' ${message}`;
|
95
|
+
exitWithError(errMessage);
|
96
|
+
}
|
97
|
+
return config;
|
98
|
+
});
|
83
99
|
}
|
@@ -1,3 +1,12 @@
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
8
|
+
});
|
9
|
+
};
|
1
10
|
import tokenizer from './tokenizer.js';
|
2
11
|
import { ParserReact } from './parserReact/ParserReact.js';
|
3
12
|
import { tokensList } from './visualizers/printTokens.js';
|
@@ -17,37 +26,42 @@ function pickParser(format) {
|
|
17
26
|
return ParserNgx();
|
18
27
|
}
|
19
28
|
}
|
20
|
-
export
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
onAccept =
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
29
|
+
export function extractTreeAndReport(code, fileName, parserType, options) {
|
30
|
+
return __awaiter(this, void 0, void 0, function* () {
|
31
|
+
var _a;
|
32
|
+
const debug = (_a = options.verbose) === null || _a === void 0 ? void 0 : _a.includes('extractor');
|
33
|
+
const tokens = (yield tokenizer(code, fileName));
|
34
|
+
const parser = pickParser(parserType);
|
35
|
+
const tokensMerged = [];
|
36
|
+
const tokensWithRules = [];
|
37
|
+
let onAccept = undefined;
|
38
|
+
if (debug) {
|
39
|
+
onAccept = (token, type) => {
|
40
|
+
tokensMerged.push(token);
|
41
|
+
tokensWithRules.push(Object.assign(Object.assign({}, token), { customType: type }));
|
42
|
+
};
|
43
|
+
}
|
44
|
+
const result = parser.parse({
|
45
|
+
tokens,
|
46
|
+
onAccept,
|
47
|
+
options,
|
48
|
+
});
|
49
|
+
if (debug) {
|
50
|
+
console.log(JSON.stringify(result.tree, null, 2) +
|
51
|
+
'\n' +
|
52
|
+
tokensList(tokensMerged) +
|
53
|
+
'\n' +
|
54
|
+
visualizeRules(tokensMerged, code) +
|
55
|
+
'\n' +
|
56
|
+
visualizeRules(tokensWithRules, code) +
|
57
|
+
'\n');
|
58
|
+
}
|
59
|
+
return result;
|
37
60
|
});
|
38
|
-
if (debug) {
|
39
|
-
console.log(JSON.stringify(result.tree, null, 2) +
|
40
|
-
'\n' +
|
41
|
-
tokensList(tokensMerged) +
|
42
|
-
'\n' +
|
43
|
-
visualizeRules(tokensMerged, code) +
|
44
|
-
'\n' +
|
45
|
-
visualizeRules(tokensWithRules, code) +
|
46
|
-
'\n');
|
47
|
-
}
|
48
|
-
return result;
|
49
61
|
}
|
50
|
-
export default
|
51
|
-
|
52
|
-
|
62
|
+
export default function extractor(code, fileName, parserType, options) {
|
63
|
+
return __awaiter(this, void 0, void 0, function* () {
|
64
|
+
const result = yield extractTreeAndReport(code, fileName, parserType, options);
|
65
|
+
return result.report;
|
66
|
+
});
|
53
67
|
}
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import { extractString, isString } from './nodeUtils.js';
|
2
2
|
function shouldBeIgnored(context, line) {
|
3
3
|
const commentAtLine = context.commentMap.get(line - 1);
|
4
|
-
const isIgnore = commentAtLine
|
4
|
+
const isIgnore = (commentAtLine === null || commentAtLine === void 0 ? void 0 : commentAtLine.type) === 'MAGIC_COMMENT' && commentAtLine.kind === 'ignore';
|
5
5
|
if (isIgnore) {
|
6
6
|
context.unusedComments.delete(commentAtLine);
|
7
7
|
}
|
@@ -9,7 +9,7 @@ function shouldBeIgnored(context, line) {
|
|
9
9
|
}
|
10
10
|
function commentKeyInfoOnLine(context, line) {
|
11
11
|
const commentAtLine = context.commentMap.get(line - 1);
|
12
|
-
const isKeyInfo = commentAtLine
|
12
|
+
const isKeyInfo = (commentAtLine === null || commentAtLine === void 0 ? void 0 : commentAtLine.type) === 'MAGIC_COMMENT' && commentAtLine.kind === 'key';
|
13
13
|
if (isKeyInfo) {
|
14
14
|
context.unusedComments.delete(commentAtLine);
|
15
15
|
return keyInfoFromComment(context, commentAtLine);
|
@@ -17,14 +17,16 @@ function commentKeyInfoOnLine(context, line) {
|
|
17
17
|
return undefined;
|
18
18
|
}
|
19
19
|
function keyInfoFromComment(context, info) {
|
20
|
+
var _a;
|
20
21
|
return {
|
21
22
|
keyName: info.keyName,
|
22
|
-
namespace: info.namespace
|
23
|
+
namespace: (_a = info.namespace) !== null && _a !== void 0 ? _a : context.options.defaultNamespace,
|
23
24
|
defaultValue: info.defaultValue,
|
24
25
|
line: info.line,
|
25
26
|
};
|
26
27
|
}
|
27
28
|
function reportKey(context, node, contextNs) {
|
29
|
+
var _a;
|
28
30
|
const { strictNamespace, defaultNamespace } = context.options;
|
29
31
|
const { keys, warnings } = context;
|
30
32
|
const { keyName, namespace: keyNs, defaultValue, line, dependsOnContext, optionsDynamic, } = node;
|
@@ -52,10 +54,10 @@ function reportKey(context, node, contextNs) {
|
|
52
54
|
warnings.push({ line, warning: 'W_DYNAMIC_OPTIONS' });
|
53
55
|
return;
|
54
56
|
}
|
55
|
-
const namespace = keyNs
|
57
|
+
const namespace = keyNs !== null && keyNs !== void 0 ? keyNs : (dependsOnContext ? contextNs === null || contextNs === void 0 ? void 0 : contextNs.name : undefined);
|
56
58
|
if (namespace && !isString(namespace)) {
|
57
59
|
// namespace is dynamic
|
58
|
-
if (namespace === contextNs
|
60
|
+
if (namespace === (contextNs === null || contextNs === void 0 ? void 0 : contextNs.name)) {
|
59
61
|
// namespace coming from context
|
60
62
|
warnings.push({ line, warning: 'W_UNRESOLVABLE_NAMESPACE' });
|
61
63
|
}
|
@@ -75,7 +77,7 @@ function reportKey(context, node, contextNs) {
|
|
75
77
|
keys.push({
|
76
78
|
line,
|
77
79
|
keyName: extractString(keyName),
|
78
|
-
namespace: extractString(namespace)
|
80
|
+
namespace: (_a = extractString(namespace)) !== null && _a !== void 0 ? _a : defaultNamespace,
|
79
81
|
defaultValue: extractString(defaultValue),
|
80
82
|
});
|
81
83
|
}
|
@@ -6,7 +6,8 @@ export const createIterator = (items) => {
|
|
6
6
|
let currentContext = undefined;
|
7
7
|
const self = {
|
8
8
|
getLineNumber() {
|
9
|
-
|
9
|
+
var _a;
|
10
|
+
return (_a = currentItem === null || currentItem === void 0 ? void 0 : currentItem.line) !== null && _a !== void 0 ? _a : 0;
|
10
11
|
},
|
11
12
|
current() {
|
12
13
|
return currentItem;
|
@@ -9,17 +9,8 @@ export const endOptions = {
|
|
9
9
|
MERGE_CUSTOM,
|
10
10
|
};
|
11
11
|
function createNewToken(tokens, customType, merger) {
|
12
|
-
const mergerData = merger
|
13
|
-
return {
|
14
|
-
customType,
|
15
|
-
type: 'custom',
|
16
|
-
startIndex: tokens[0].startIndex,
|
17
|
-
endIndex: tokens[tokens.length - 1].endIndex,
|
18
|
-
scopes: [],
|
19
|
-
line: tokens[0].line,
|
20
|
-
token: tokens.map((t) => t.token).join(''),
|
21
|
-
...mergerData,
|
22
|
-
};
|
12
|
+
const mergerData = merger === null || merger === void 0 ? void 0 : merger(tokens);
|
13
|
+
return Object.assign({ customType, type: 'custom', startIndex: tokens[0].startIndex, endIndex: tokens[tokens.length - 1].endIndex, scopes: [], line: tokens[0].line, token: tokens.map((t) => t.token).join('') }, mergerData);
|
23
14
|
}
|
24
15
|
export function createMachine(machine) {
|
25
16
|
function* generator(tokens) {
|
@@ -14,7 +14,7 @@ export function extractValue(node) {
|
|
14
14
|
return node && node.type === 'primitive' ? node.value : undefined;
|
15
15
|
}
|
16
16
|
export function simplifyNode(node) {
|
17
|
-
if (node
|
17
|
+
if ((node === null || node === void 0 ? void 0 : node.type) === 'expr' && node.values.length === 1) {
|
18
18
|
return node.values[0];
|
19
19
|
}
|
20
20
|
return node;
|
@@ -37,9 +37,10 @@ export const Parser = ({ mappers, blocks, rules, merger, treeTransform, }) => {
|
|
37
37
|
}
|
38
38
|
return {
|
39
39
|
parse({ tokens, onAccept, options }) {
|
40
|
+
var _a;
|
40
41
|
for (const t of tokens) {
|
41
42
|
// use first mapper, which gives some result
|
42
|
-
const type = mappers.find((mapper) => mapper(t))
|
43
|
+
const type = (_a = mappers.find((mapper) => mapper(t))) === null || _a === void 0 ? void 0 : _a(t);
|
43
44
|
t.customType = type;
|
44
45
|
}
|
45
46
|
const mergedComments = [...createMachine(commentsMerger)(tokens)];
|
@@ -79,8 +80,9 @@ export const Parser = ({ mappers, blocks, rules, merger, treeTransform, }) => {
|
|
79
80
|
let depth = 0;
|
80
81
|
function withLabel(fn) {
|
81
82
|
return (...args) => {
|
83
|
+
var _a;
|
82
84
|
let label;
|
83
|
-
const currentTokenName = context.tokens.current()
|
85
|
+
const currentTokenName = ((_a = context.tokens.current()) === null || _a === void 0 ? void 0 : _a.customType) || '';
|
84
86
|
const isTrigger = currentTokenName.startsWith('trigger.');
|
85
87
|
if (!isTrigger) {
|
86
88
|
depth += 1;
|
@@ -21,7 +21,7 @@ export const tNsSourceGeneral = (context) => {
|
|
21
21
|
values: [],
|
22
22
|
};
|
23
23
|
const [firstArg, ...otherArgs] = args.values;
|
24
|
-
if (firstArg
|
24
|
+
if ((firstArg === null || firstArg === void 0 ? void 0 : firstArg.type) === 'array') {
|
25
25
|
// useTranslate(['namespace', ...])
|
26
26
|
const [firstItem, ...otherItems] = firstArg.values;
|
27
27
|
result.name = firstItem;
|
@@ -1,23 +1,31 @@
|
|
1
|
-
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
2
|
+
var t = {};
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
4
|
+
t[p] = s[p];
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
8
|
+
t[p[i]] = s[p[i]];
|
9
|
+
}
|
10
|
+
return t;
|
11
|
+
};
|
12
|
+
export function getCombinedOptions(_a, line) {
|
13
|
+
var { ns, noWrap, orEmpty, params, language } = _a, rest = __rest(_a, ["ns", "noWrap", "orEmpty", "params", "language"]);
|
2
14
|
const options = {
|
3
15
|
ns: ns,
|
4
16
|
noWrap: noWrap,
|
5
17
|
orEmpty: orEmpty,
|
6
18
|
language: language,
|
7
19
|
};
|
8
|
-
return {
|
9
|
-
...options,
|
10
|
-
params: {
|
20
|
+
return Object.assign(Object.assign({}, options), { params: {
|
11
21
|
type: 'dict',
|
12
22
|
line,
|
13
|
-
value: {
|
14
|
-
...rest,
|
15
|
-
},
|
23
|
+
value: Object.assign({}, rest),
|
16
24
|
unknown: [],
|
17
|
-
}
|
18
|
-
};
|
25
|
+
} });
|
19
26
|
}
|
20
27
|
export const getTranslateProps = (node) => {
|
28
|
+
var _a;
|
21
29
|
const [keyOrProps, ...params] = node.values;
|
22
30
|
let result = {
|
23
31
|
type: 'dict',
|
@@ -26,12 +34,12 @@ export const getTranslateProps = (node) => {
|
|
26
34
|
unknown: [],
|
27
35
|
};
|
28
36
|
let options = undefined;
|
29
|
-
if (keyOrProps
|
37
|
+
if ((keyOrProps === null || keyOrProps === void 0 ? void 0 : keyOrProps.type) === 'dict') {
|
30
38
|
result = keyOrProps;
|
31
39
|
}
|
32
40
|
else {
|
33
41
|
result.value.key = keyOrProps;
|
34
|
-
if (params[0]
|
42
|
+
if (((_a = params[0]) === null || _a === void 0 ? void 0 : _a.type) === 'primitive' || params.length >= 2) {
|
35
43
|
result.value.defaultValue = params[0];
|
36
44
|
options = params[1];
|
37
45
|
}
|
@@ -40,11 +48,8 @@ export const getTranslateProps = (node) => {
|
|
40
48
|
}
|
41
49
|
}
|
42
50
|
let optionsDynamic = false;
|
43
|
-
if (options
|
44
|
-
result.value = {
|
45
|
-
...getCombinedOptions(options.value, options.line),
|
46
|
-
...result.value,
|
47
|
-
};
|
51
|
+
if ((options === null || options === void 0 ? void 0 : options.type) === 'dict') {
|
52
|
+
result.value = Object.assign(Object.assign({}, getCombinedOptions(options.value, options.line)), result.value);
|
48
53
|
result.unknown.push(...options.unknown);
|
49
54
|
}
|
50
55
|
else if (options) {
|