@esgettext/tools 1.0.0 → 1.2.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/LICENSE +1 -1
- package/README.md +197 -22
- package/dist/command.js +2 -0
- package/dist/commands/convert.js +286 -0
- package/dist/commands/install.js +257 -0
- package/dist/commands/msgfmt-all.js +219 -0
- package/dist/commands/msgmerge-all.js +230 -0
- package/dist/commands/xgettext/file-resolver.js +20 -0
- package/dist/commands/xgettext/files-collector.js +39 -0
- package/dist/commands/xgettext.js +534 -0
- package/dist/configuration.js +277 -0
- package/dist/esgettext-package-json.js +2 -0
- package/dist/index.js +135 -0
- package/dist/package.js +10 -12
- package/dist/parser/javascript.js +9 -28
- package/dist/parser/parser.js +176 -148
- package/dist/parser/po.js +144 -128
- package/dist/parser/typescript.js +10 -28
- package/dist/pot/catalog.js +134 -83
- package/dist/pot/entry.js +173 -115
- package/dist/pot/keyword.js +66 -92
- package/package.json +38 -25
- package/bin/esgettext-install.js +0 -5
- package/bin/esgettext-mo2json.js +0 -5
- package/bin/esgettext-msgfmt-all.js +0 -5
- package/bin/esgettext-msgmerge-all.js +0 -5
- package/bin/esgettext-xgettext.js +0 -5
- package/dist/cli/getopt.d.ts +0 -34
- package/dist/cli/getopt.js +0 -150
- package/dist/cli/getopt.js.map +0 -1
- package/dist/cli/getopt.spec.d.ts +0 -1
- package/dist/cli/getopt.spec.js +0 -164
- package/dist/cli/getopt.spec.js.map +0 -1
- package/dist/cli/install.d.ts +0 -1
- package/dist/cli/install.js +0 -91
- package/dist/cli/install.js.map +0 -1
- package/dist/cli/mo2json-cli.d.ts +0 -1
- package/dist/cli/mo2json-cli.js +0 -48
- package/dist/cli/mo2json-cli.js.map +0 -1
- package/dist/cli/msgfmt-all.d.ts +0 -1
- package/dist/cli/msgfmt-all.js +0 -99
- package/dist/cli/msgfmt-all.js.map +0 -1
- package/dist/cli/msgmerge-all.d.ts +0 -1
- package/dist/cli/msgmerge-all.js +0 -85
- package/dist/cli/msgmerge-all.js.map +0 -1
- package/dist/cli/xgettext-cli.d.ts +0 -1
- package/dist/cli/xgettext-cli.js +0 -303
- package/dist/cli/xgettext-cli.js.map +0 -1
- package/dist/install/install.d.ts +0 -10
- package/dist/install/install.js +0 -157
- package/dist/install/install.js.map +0 -1
- package/dist/msgfmt-all/msgfmt-all.d.ts +0 -8
- package/dist/msgfmt-all/msgfmt-all.js +0 -142
- package/dist/msgfmt-all/msgfmt-all.js.map +0 -1
- package/dist/msgmerge-all/msgmerge-all.d.ts +0 -9
- package/dist/msgmerge-all/msgmerge-all.js +0 -157
- package/dist/msgmerge-all/msgmerge-all.js.map +0 -1
- package/dist/package.d.ts +0 -4
- package/dist/package.js.map +0 -1
- package/dist/parser/__snapshots__/javascript.spec.js.snap +0 -56
- package/dist/parser/__snapshots__/po.spec.js.snap +0 -176
- package/dist/parser/javascript.d.ts +0 -4
- package/dist/parser/javascript.js.map +0 -1
- package/dist/parser/javascript.spec.d.ts +0 -1
- package/dist/parser/javascript.spec.js +0 -436
- package/dist/parser/javascript.spec.js.map +0 -1
- package/dist/parser/parser.d.ts +0 -45
- package/dist/parser/parser.js.map +0 -1
- package/dist/parser/po.d.ts +0 -22
- package/dist/parser/po.js.map +0 -1
- package/dist/parser/po.spec.d.ts +0 -1
- package/dist/parser/po.spec.js +0 -296
- package/dist/parser/po.spec.js.map +0 -1
- package/dist/parser/typescript.d.ts +0 -4
- package/dist/parser/typescript.js.map +0 -1
- package/dist/parser/typescript.spec.d.ts +0 -1
- package/dist/parser/typescript.spec.js +0 -106
- package/dist/parser/typescript.spec.js.map +0 -1
- package/dist/pot/__snapshots__/catalog.spec.js.snap +0 -591
- package/dist/pot/catalog.d.ts +0 -26
- package/dist/pot/catalog.js.map +0 -1
- package/dist/pot/catalog.spec.d.ts +0 -1
- package/dist/pot/catalog.spec.js +0 -240
- package/dist/pot/catalog.spec.js.map +0 -1
- package/dist/pot/entry.d.ts +0 -35
- package/dist/pot/entry.js.map +0 -1
- package/dist/pot/entry.spec.d.ts +0 -1
- package/dist/pot/entry.spec.js +0 -317
- package/dist/pot/entry.spec.js.map +0 -1
- package/dist/pot/keyword.d.ts +0 -17
- package/dist/pot/keyword.js.map +0 -1
- package/dist/pot/keyword.spec.d.ts +0 -1
- package/dist/pot/keyword.spec.js +0 -54
- package/dist/pot/keyword.spec.js.map +0 -1
- package/dist/xgettext/__snapshots__/xgettext.spec.js.snap +0 -462
- package/dist/xgettext/file-resolver.d.ts +0 -5
- package/dist/xgettext/file-resolver.js +0 -23
- package/dist/xgettext/file-resolver.js.map +0 -1
- package/dist/xgettext/file-resolver.spec.d.ts +0 -1
- package/dist/xgettext/file-resolver.spec.js +0 -22
- package/dist/xgettext/file-resolver.spec.js.map +0 -1
- package/dist/xgettext/files-collector.d.ts +0 -5
- package/dist/xgettext/files-collector.js +0 -41
- package/dist/xgettext/files-collector.js.map +0 -1
- package/dist/xgettext/files-collector.spec.d.ts +0 -1
- package/dist/xgettext/files-collector.spec.js +0 -78
- package/dist/xgettext/files-collector.spec.js.map +0 -1
- package/dist/xgettext/xgettext.d.ts +0 -16
- package/dist/xgettext/xgettext.js +0 -335
- package/dist/xgettext/xgettext.js.map +0 -1
- package/dist/xgettext/xgettext.spec.d.ts +0 -1
- package/dist/xgettext/xgettext.spec.js +0 -743
- package/dist/xgettext/xgettext.spec.js.map +0 -1
package/dist/parser/parser.js
CHANGED
|
@@ -27,40 +27,41 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
29
|
exports.Parser = void 0;
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
if (options === void 0) { options = {}; }
|
|
40
|
-
var _this = this;
|
|
30
|
+
const iconv_lite_1 = require("iconv-lite");
|
|
31
|
+
const traverse_1 = __importDefault(require("@babel/traverse"));
|
|
32
|
+
const t = __importStar(require("@babel/types"));
|
|
33
|
+
const runtime_1 = require("@esgettext/runtime");
|
|
34
|
+
const entry_1 = require("../pot/entry");
|
|
35
|
+
const keyword_1 = require("../pot/keyword");
|
|
36
|
+
const gtx = runtime_1.Textdomain.getInstance('tools');
|
|
37
|
+
class Parser {
|
|
38
|
+
constructor(catalog, options = {}) {
|
|
41
39
|
this.catalog = catalog;
|
|
42
40
|
this.options = options;
|
|
41
|
+
this.filename = '';
|
|
42
|
+
this.errors = 0;
|
|
43
|
+
this.comments = [];
|
|
43
44
|
this.keywords = {};
|
|
44
|
-
(options.keyword || Parser.cookedDefaultKeywords()).forEach(
|
|
45
|
-
|
|
45
|
+
(options.keyword || Parser.cookedDefaultKeywords()).forEach(keyword => {
|
|
46
|
+
this.keywords[keyword.method] = keyword;
|
|
46
47
|
});
|
|
47
48
|
if (options.instance) {
|
|
48
49
|
this.instances = new Array();
|
|
49
|
-
for (
|
|
50
|
+
for (let i = 0; i < options.instance.length; ++i) {
|
|
50
51
|
this.instances[i] = options.instance[i].split('.').reverse();
|
|
51
52
|
}
|
|
52
53
|
}
|
|
53
54
|
}
|
|
54
|
-
|
|
55
|
+
parse(buf, filename) {
|
|
55
56
|
this.filename = filename;
|
|
56
|
-
|
|
57
|
+
const encoding = typeof this.options.fromCode === 'undefined'
|
|
57
58
|
? 'ascii'
|
|
58
59
|
: this.options.fromCode;
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
60
|
+
const canonical = this.canonicalizeEncoding(encoding);
|
|
61
|
+
let input;
|
|
62
|
+
let pos = 0;
|
|
62
63
|
if ('ascii' === canonical) {
|
|
63
|
-
if (buf.find(
|
|
64
|
+
if (buf.find((ord, idx) => {
|
|
64
65
|
if (ord > 0x7f) {
|
|
65
66
|
pos = idx;
|
|
66
67
|
return true;
|
|
@@ -69,17 +70,22 @@ var Parser = (function () {
|
|
|
69
70
|
return false;
|
|
70
71
|
}
|
|
71
72
|
})) {
|
|
72
|
-
|
|
73
|
+
const loc = {
|
|
73
74
|
start: {
|
|
74
75
|
line: 1,
|
|
75
|
-
column:
|
|
76
|
-
index:
|
|
76
|
+
column: 1,
|
|
77
|
+
index: 1,
|
|
78
|
+
},
|
|
79
|
+
end: {
|
|
80
|
+
line: 0,
|
|
81
|
+
column: 0,
|
|
82
|
+
index: 0,
|
|
77
83
|
},
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
identifierName: null
|
|
84
|
+
filename,
|
|
85
|
+
identifierName: null,
|
|
81
86
|
};
|
|
82
|
-
|
|
87
|
+
// Find the offending character.
|
|
88
|
+
for (let i = 0; i < pos; ++i) {
|
|
83
89
|
if (buf[i] === 10) {
|
|
84
90
|
++loc.start.line;
|
|
85
91
|
loc.start.column = 1;
|
|
@@ -95,7 +101,7 @@ var Parser = (function () {
|
|
|
95
101
|
input = buf.toString();
|
|
96
102
|
}
|
|
97
103
|
else if ('utf8' === canonical) {
|
|
98
|
-
|
|
104
|
+
const loc = this.findNonUtf8(buf);
|
|
99
105
|
if (loc !== null) {
|
|
100
106
|
this.error(gtx._('invalid multibyte sequence'), loc);
|
|
101
107
|
return false;
|
|
@@ -103,18 +109,19 @@ var Parser = (function () {
|
|
|
103
109
|
input = buf.toString();
|
|
104
110
|
}
|
|
105
111
|
else {
|
|
112
|
+
// Convert.
|
|
106
113
|
try {
|
|
107
114
|
input = (0, iconv_lite_1.decode)(buf, this.options.fromCode);
|
|
108
115
|
}
|
|
109
116
|
catch (e) {
|
|
110
|
-
|
|
111
|
-
console.error(
|
|
117
|
+
const usedFilename = '-' === filename ? gtx._('[standard input]') : filename;
|
|
118
|
+
console.error(`${usedFilename}: ${e}`);
|
|
112
119
|
return false;
|
|
113
120
|
}
|
|
114
121
|
}
|
|
115
122
|
return this.doParse(input, filename);
|
|
116
|
-
}
|
|
117
|
-
|
|
123
|
+
}
|
|
124
|
+
extract(filename, ast) {
|
|
118
125
|
this.errors = 0;
|
|
119
126
|
this.comments = this.filterComments(ast.comments);
|
|
120
127
|
this.filename = filename;
|
|
@@ -125,33 +132,38 @@ var Parser = (function () {
|
|
|
125
132
|
this.extractStrings(ast);
|
|
126
133
|
}
|
|
127
134
|
return !this.errors;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
var _this = this;
|
|
135
|
+
}
|
|
136
|
+
extractStrings(ast) {
|
|
131
137
|
(0, traverse_1.default)(ast, {
|
|
132
|
-
CallExpression:
|
|
133
|
-
|
|
138
|
+
CallExpression: path => {
|
|
139
|
+
this.extractArguments(path);
|
|
134
140
|
},
|
|
135
141
|
});
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
|
|
142
|
+
}
|
|
143
|
+
extractAllStrings(ast) {
|
|
144
|
+
// Step 1: Transform string concatenations into one string.
|
|
139
145
|
(0, traverse_1.default)(ast, {
|
|
140
|
-
StringLiteral:
|
|
141
|
-
|
|
146
|
+
StringLiteral: path => {
|
|
147
|
+
this.concatStrings(path);
|
|
142
148
|
},
|
|
143
149
|
});
|
|
150
|
+
// Step 2: Extract the remaining strings. Those that are part of a
|
|
151
|
+
// binary expression have not been recognized in step 1 and must be
|
|
152
|
+
// ignored.
|
|
144
153
|
(0, traverse_1.default)(ast, {
|
|
145
|
-
StringLiteral:
|
|
154
|
+
StringLiteral: path => {
|
|
146
155
|
if (!t.isBinaryExpression(path.parentPath.node)) {
|
|
147
|
-
|
|
148
|
-
|
|
156
|
+
const loc = path.node.loc;
|
|
157
|
+
this.addEntry({
|
|
158
|
+
msgid: path.node.value,
|
|
159
|
+
loc: loc,
|
|
160
|
+
});
|
|
149
161
|
}
|
|
150
162
|
},
|
|
151
163
|
});
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
for (
|
|
164
|
+
}
|
|
165
|
+
checkPath(wanted, got) {
|
|
166
|
+
for (let i = 0; i < got.length; ++i) {
|
|
155
167
|
if (i >= wanted.length) {
|
|
156
168
|
return true;
|
|
157
169
|
}
|
|
@@ -160,25 +172,25 @@ var Parser = (function () {
|
|
|
160
172
|
}
|
|
161
173
|
}
|
|
162
174
|
return true;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
if (!this.
|
|
175
|
+
}
|
|
176
|
+
checkInstance(instance) {
|
|
177
|
+
if (!this.instances) {
|
|
166
178
|
return true;
|
|
167
179
|
}
|
|
168
|
-
for (
|
|
180
|
+
for (let i = 0; i < this.instances.length; ++i) {
|
|
169
181
|
if (this.checkPath(this.instances[i], instance)) {
|
|
170
182
|
return true;
|
|
171
183
|
}
|
|
172
184
|
}
|
|
173
185
|
return false;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
|
|
186
|
+
}
|
|
187
|
+
extractArguments(path) {
|
|
188
|
+
let method;
|
|
177
189
|
if (t.isIdentifier(path.node.callee) && !this.instances) {
|
|
178
190
|
method = path.node.callee.name;
|
|
179
191
|
}
|
|
180
192
|
else if (t.isMemberExpression(path.node.callee)) {
|
|
181
|
-
|
|
193
|
+
const instance = new Array();
|
|
182
194
|
method = this.methodFromMemberExpression(path.node.callee, instance);
|
|
183
195
|
if (method === null) {
|
|
184
196
|
return;
|
|
@@ -194,7 +206,8 @@ var Parser = (function () {
|
|
|
194
206
|
if (!Object.prototype.hasOwnProperty.call(this.keywords, method)) {
|
|
195
207
|
return;
|
|
196
208
|
}
|
|
197
|
-
|
|
209
|
+
// Enough arguments?
|
|
210
|
+
const keywordSpec = this.keywords[method];
|
|
198
211
|
if (keywordSpec.totalArgs &&
|
|
199
212
|
path.node.arguments.length !== keywordSpec.totalArgs) {
|
|
200
213
|
return;
|
|
@@ -209,27 +222,33 @@ var Parser = (function () {
|
|
|
209
222
|
keywordSpec.context > path.node.arguments.length) {
|
|
210
223
|
return;
|
|
211
224
|
}
|
|
212
|
-
|
|
225
|
+
const msgid = this.extractArgument(path.node.arguments[keywordSpec.singular - 1]);
|
|
213
226
|
if (msgid === null) {
|
|
214
227
|
return;
|
|
215
228
|
}
|
|
216
|
-
|
|
229
|
+
let msgidPlural;
|
|
217
230
|
if (keywordSpec.plural) {
|
|
218
231
|
msgidPlural = this.extractArgument(path.node.arguments[keywordSpec.plural - 1]);
|
|
219
232
|
if (msgidPlural === null) {
|
|
220
233
|
return;
|
|
221
234
|
}
|
|
222
235
|
}
|
|
223
|
-
|
|
236
|
+
let msgctxt;
|
|
224
237
|
if (keywordSpec.context) {
|
|
225
238
|
msgctxt = this.extractArgument(path.node.arguments[keywordSpec.context - 1]);
|
|
226
239
|
if (msgctxt === null) {
|
|
227
240
|
return;
|
|
228
241
|
}
|
|
229
242
|
}
|
|
230
|
-
this.addEntry({
|
|
231
|
-
|
|
232
|
-
|
|
243
|
+
this.addEntry({
|
|
244
|
+
msgid: msgid,
|
|
245
|
+
loc: path.node.loc,
|
|
246
|
+
method,
|
|
247
|
+
msgidPlural,
|
|
248
|
+
msgctxt,
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
extractArgument(argument) {
|
|
233
252
|
if (t.isStringLiteral(argument)) {
|
|
234
253
|
return argument.value;
|
|
235
254
|
}
|
|
@@ -240,19 +259,19 @@ var Parser = (function () {
|
|
|
240
259
|
return this.extractTemplateLiteral(argument);
|
|
241
260
|
}
|
|
242
261
|
return null;
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
|
|
262
|
+
}
|
|
263
|
+
extractBinaryExpression(exp) {
|
|
264
|
+
const left = this.extractArgument(exp.left);
|
|
246
265
|
if (left === null) {
|
|
247
266
|
return null;
|
|
248
267
|
}
|
|
249
|
-
|
|
268
|
+
const right = this.extractArgument(exp.right);
|
|
250
269
|
if (right === null) {
|
|
251
270
|
return null;
|
|
252
271
|
}
|
|
253
272
|
return left + right;
|
|
254
|
-
}
|
|
255
|
-
|
|
273
|
+
}
|
|
274
|
+
extractTemplateLiteral(literal) {
|
|
256
275
|
if (literal.expressions.length === 0 &&
|
|
257
276
|
literal.quasis.length === 1 &&
|
|
258
277
|
t.isTemplateElement(literal.quasis[0])) {
|
|
@@ -262,39 +281,40 @@ var Parser = (function () {
|
|
|
262
281
|
' allowed as arguments to gettext functions because they' +
|
|
263
282
|
' are not constant'), literal.loc);
|
|
264
283
|
return null;
|
|
265
|
-
}
|
|
266
|
-
|
|
284
|
+
}
|
|
285
|
+
concatStrings(path) {
|
|
267
286
|
if (!t.isBinaryExpression(path.parent)) {
|
|
268
287
|
return;
|
|
269
288
|
}
|
|
270
|
-
|
|
289
|
+
const parentPath = path.parentPath;
|
|
271
290
|
if (parentPath.node.operator === '+' &&
|
|
272
291
|
t.isStringLiteral(parentPath.node.left) &&
|
|
273
292
|
t.isStringLiteral(parentPath.node.right)) {
|
|
274
|
-
|
|
293
|
+
const node = t.stringLiteral(parentPath.node.left.value + parentPath.node.right.value);
|
|
294
|
+
node.loc = parentPath.node.loc;
|
|
295
|
+
parentPath.replaceInline(node);
|
|
275
296
|
}
|
|
276
|
-
}
|
|
277
|
-
|
|
297
|
+
}
|
|
298
|
+
addEntry(props) {
|
|
278
299
|
props.flag = new Array();
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
var extractedComments = commentBlocks.map(function (block) { return block.value.trim(); });
|
|
300
|
+
const dict = props.loc;
|
|
301
|
+
let references = [];
|
|
302
|
+
if (dict !== null && typeof dict !== 'undefined') {
|
|
303
|
+
const filename = '-' === dict.filename ? '[stdin]' : dict.filename;
|
|
304
|
+
references = [`${filename}:${props.loc.start.line}`];
|
|
305
|
+
}
|
|
306
|
+
const commentBlocks = this.findPrecedingComments(props.loc);
|
|
307
|
+
let extractedComments = commentBlocks.map(block => block.value.trim());
|
|
288
308
|
if (typeof props.method !== 'undefined') {
|
|
289
309
|
extractedComments = extractedComments
|
|
290
|
-
.map(
|
|
291
|
-
|
|
310
|
+
.map(comment => {
|
|
311
|
+
const match = /xgettext:(.*)/.exec(comment);
|
|
292
312
|
if (match) {
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
tokens.forEach(
|
|
297
|
-
if (
|
|
313
|
+
const str = match[1];
|
|
314
|
+
const validTokens = ['fuzzy', 'wrap', 'no-wrap'];
|
|
315
|
+
const tokens = str.split(/[ \x09-\x0d]+/);
|
|
316
|
+
tokens.forEach(token => {
|
|
317
|
+
if (validTokens.includes(token) ||
|
|
298
318
|
/^(?:[a-z]+-)+(?:format|check)$/.exec(token)) {
|
|
299
319
|
props.flag.push(token);
|
|
300
320
|
}
|
|
@@ -303,7 +323,7 @@ var Parser = (function () {
|
|
|
303
323
|
}
|
|
304
324
|
return comment;
|
|
305
325
|
})
|
|
306
|
-
.filter(
|
|
326
|
+
.filter(comment => comment !== '');
|
|
307
327
|
}
|
|
308
328
|
if (!props.flag.includes('no-perl-brace-format') &&
|
|
309
329
|
/\{[_a-zA-Z][_a-zA-Z0-9]*\}/.exec(props.msgid)) {
|
|
@@ -314,12 +334,11 @@ var Parser = (function () {
|
|
|
314
334
|
msgidPlural: props.msgidPlural,
|
|
315
335
|
msgctxt: props.msgctxt,
|
|
316
336
|
flags: props.flag,
|
|
317
|
-
references
|
|
318
|
-
extractedComments
|
|
337
|
+
references,
|
|
338
|
+
extractedComments,
|
|
319
339
|
}));
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
if (instance === void 0) { instance = []; }
|
|
340
|
+
}
|
|
341
|
+
methodFromMemberExpression(me, instance = []) {
|
|
323
342
|
if (t.isIdentifier(me.object)) {
|
|
324
343
|
if (t.isLiteral(me.property) && me.computed) {
|
|
325
344
|
instance.push(this.literalValue(me.property));
|
|
@@ -338,20 +357,22 @@ var Parser = (function () {
|
|
|
338
357
|
else if (t.isMemberExpression(me.object) &&
|
|
339
358
|
t.isIdentifier(me.property) &&
|
|
340
359
|
!me.computed) {
|
|
360
|
+
// Recurse.
|
|
341
361
|
instance.push(me.property.name);
|
|
342
362
|
return this.methodFromMemberExpression(me.object, instance);
|
|
343
363
|
}
|
|
344
364
|
else if (t.isMemberExpression(me.object) &&
|
|
345
365
|
t.isLiteral(me.property) &&
|
|
346
366
|
me.computed) {
|
|
367
|
+
// Recurse.
|
|
347
368
|
instance.push(this.literalValue(me.property));
|
|
348
369
|
return this.methodFromMemberExpression(me.object, instance);
|
|
349
370
|
}
|
|
350
371
|
else {
|
|
351
372
|
return null;
|
|
352
373
|
}
|
|
353
|
-
}
|
|
354
|
-
|
|
374
|
+
}
|
|
375
|
+
literalValue(node) {
|
|
355
376
|
if (t.isStringLiteral(node)) {
|
|
356
377
|
return node.value;
|
|
357
378
|
}
|
|
@@ -364,11 +385,13 @@ var Parser = (function () {
|
|
|
364
385
|
else {
|
|
365
386
|
return null;
|
|
366
387
|
}
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
|
|
388
|
+
}
|
|
389
|
+
findPrecedingComments(loc) {
|
|
390
|
+
let last;
|
|
391
|
+
// Find the last relevant comment, which is the first one that
|
|
392
|
+
// immediately precedes the location.
|
|
370
393
|
for (last = 0; last < this.comments.length; ++last) {
|
|
371
|
-
|
|
394
|
+
const commentLocation = this.comments[last].loc;
|
|
372
395
|
if (commentLocation.end.line === loc.start.line ||
|
|
373
396
|
commentLocation.end.line === loc.start.line - 1) {
|
|
374
397
|
break;
|
|
@@ -382,35 +405,37 @@ var Parser = (function () {
|
|
|
382
405
|
this.comments.splice(0, this.comments.length);
|
|
383
406
|
return [];
|
|
384
407
|
}
|
|
385
|
-
|
|
386
|
-
|
|
408
|
+
// Now go back and find all adjacent comments.
|
|
409
|
+
let ptr = this.comments[last].loc;
|
|
410
|
+
const preceding = this.comments.splice(0, last + 1);
|
|
387
411
|
if (!last) {
|
|
388
412
|
return preceding;
|
|
389
413
|
}
|
|
390
|
-
|
|
414
|
+
let first;
|
|
391
415
|
for (first = preceding.length - 2; first >= 0; --first) {
|
|
392
|
-
|
|
393
|
-
if (commentLocation
|
|
416
|
+
const commentLocation = preceding[first].loc;
|
|
417
|
+
if (commentLocation &&
|
|
418
|
+
commentLocation.end.line < ptr.start.line - 1) {
|
|
394
419
|
break;
|
|
395
420
|
}
|
|
396
421
|
ptr = commentLocation;
|
|
397
422
|
}
|
|
398
423
|
return preceding.slice(first + 1);
|
|
399
|
-
}
|
|
400
|
-
|
|
424
|
+
}
|
|
425
|
+
filterComments(comments) {
|
|
401
426
|
if (this.options.addAllComments) {
|
|
402
427
|
return comments;
|
|
403
428
|
}
|
|
404
|
-
|
|
429
|
+
const markers = this.options.addComments
|
|
405
430
|
? this.options.addComments
|
|
406
431
|
: new Array();
|
|
407
|
-
return comments.filter(
|
|
432
|
+
return comments.filter(block => {
|
|
408
433
|
if (block.value.includes('xgettext:')) {
|
|
409
434
|
return true;
|
|
410
435
|
}
|
|
411
436
|
else {
|
|
412
|
-
for (
|
|
413
|
-
|
|
437
|
+
for (let i = 0; i < markers.length; ++i) {
|
|
438
|
+
const marker = markers[i].trim();
|
|
414
439
|
if (marker === block.value.trim().substr(0, marker.length)) {
|
|
415
440
|
return true;
|
|
416
441
|
}
|
|
@@ -418,11 +443,11 @@ var Parser = (function () {
|
|
|
418
443
|
}
|
|
419
444
|
return false;
|
|
420
445
|
});
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
return Parser.defaultKeywords().map(
|
|
424
|
-
}
|
|
425
|
-
|
|
446
|
+
}
|
|
447
|
+
static cookedDefaultKeywords() {
|
|
448
|
+
return Parser.defaultKeywords().map(keyword => keyword_1.Keyword.from(keyword));
|
|
449
|
+
}
|
|
450
|
+
static defaultKeywords() {
|
|
426
451
|
return [
|
|
427
452
|
'_',
|
|
428
453
|
'_x',
|
|
@@ -449,27 +474,28 @@ var Parser = (function () {
|
|
|
449
474
|
'N_lp:2c,3',
|
|
450
475
|
'N_lpx:2c,3',
|
|
451
476
|
];
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
console.warn(gtx._x('{location}: warning: {msg}', { location
|
|
459
|
-
}
|
|
460
|
-
|
|
477
|
+
}
|
|
478
|
+
warn(msg, loc) {
|
|
479
|
+
const start = `${loc.start.line}:${loc.start.column}`;
|
|
480
|
+
const end = loc.end.line > 0 ? `-${loc.end.line}:${loc.end.column}` : '';
|
|
481
|
+
const filename = '-' === this.filename ? gtx._('[standard input]') : this.filename;
|
|
482
|
+
const location = `${filename}:${start}${end}`;
|
|
483
|
+
console.warn(gtx._x('{location}: warning: {msg}', { location, msg }));
|
|
484
|
+
}
|
|
485
|
+
error(msg, loc) {
|
|
461
486
|
++this.errors;
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
console.error(gtx._x('{location}:
|
|
467
|
-
}
|
|
468
|
-
|
|
469
|
-
|
|
487
|
+
const start = `${loc.start.line}:${loc.start.column}`;
|
|
488
|
+
const end = loc.end && loc.end.line > 0 ? `-${loc.end.line}:${loc.end.column}` : '';
|
|
489
|
+
const filename = '-' === this.filename ? gtx._('[standard input]') : this.filename;
|
|
490
|
+
const location = `${filename}:${start}${end}`;
|
|
491
|
+
console.error(gtx._x('{location}: Error: {msg}', { location, msg }));
|
|
492
|
+
}
|
|
493
|
+
canonicalizeEncoding(encoding) {
|
|
494
|
+
// This is taken from iconv-lite.
|
|
495
|
+
const canonical = ('' + encoding)
|
|
470
496
|
.toLowerCase()
|
|
471
497
|
.replace(/:[0-9]{4}$|[^0-9a-z]/g, '');
|
|
472
|
-
|
|
498
|
+
const asciiAliases = [
|
|
473
499
|
'ascii8bit',
|
|
474
500
|
'usascii',
|
|
475
501
|
'ansix34',
|
|
@@ -489,18 +515,22 @@ var Parser = (function () {
|
|
|
489
515
|
else {
|
|
490
516
|
return canonical;
|
|
491
517
|
}
|
|
492
|
-
}
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
518
|
+
}
|
|
519
|
+
findNonUtf8(buf) {
|
|
520
|
+
let i = 0;
|
|
521
|
+
const loc = {
|
|
496
522
|
start: {
|
|
497
523
|
line: 1,
|
|
498
524
|
column: 1,
|
|
499
|
-
index: 0
|
|
525
|
+
index: 0,
|
|
526
|
+
},
|
|
527
|
+
end: {
|
|
528
|
+
line: 0,
|
|
529
|
+
column: 0,
|
|
530
|
+
index: 0,
|
|
500
531
|
},
|
|
501
|
-
end: null,
|
|
502
532
|
filename: '',
|
|
503
|
-
identifierName: ''
|
|
533
|
+
identifierName: '',
|
|
504
534
|
};
|
|
505
535
|
while (i < buf.length) {
|
|
506
536
|
if (buf[i] === 0x09 ||
|
|
@@ -575,8 +605,6 @@ var Parser = (function () {
|
|
|
575
605
|
return loc;
|
|
576
606
|
}
|
|
577
607
|
return null;
|
|
578
|
-
}
|
|
579
|
-
|
|
580
|
-
}());
|
|
608
|
+
}
|
|
609
|
+
}
|
|
581
610
|
exports.Parser = Parser;
|
|
582
|
-
//# sourceMappingURL=parser.js.map
|