@esgettext/tools 1.0.0 → 1.1.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/README.md +196 -21
- package/dist/command.d.ts +11 -0
- package/dist/command.js +3 -0
- package/dist/command.js.map +1 -0
- package/dist/commands/convert.d.ts +24 -0
- package/dist/commands/convert.js +284 -0
- package/dist/commands/convert.js.map +1 -0
- package/dist/commands/install.d.ts +22 -0
- package/dist/commands/install.js +249 -0
- package/dist/commands/install.js.map +1 -0
- package/dist/commands/msgfmt-all.d.ts +20 -0
- package/dist/commands/msgfmt-all.js +200 -0
- package/dist/commands/msgfmt-all.js.map +1 -0
- package/dist/commands/msgmerge-all.d.ts +21 -0
- package/dist/commands/msgmerge-all.js +212 -0
- package/dist/commands/msgmerge-all.js.map +1 -0
- package/dist/{xgettext → commands/xgettext}/file-resolver.d.ts +1 -1
- package/dist/commands/xgettext/file-resolver.js +21 -0
- package/dist/commands/xgettext/file-resolver.js.map +1 -0
- package/dist/commands/xgettext/file-resolver.spec.js +22 -0
- package/dist/commands/xgettext/file-resolver.spec.js.map +1 -0
- package/dist/commands/xgettext/files-collector.js +39 -0
- package/dist/commands/xgettext/files-collector.js.map +1 -0
- package/dist/{xgettext → commands/xgettext}/files-collector.spec.js +39 -21
- package/dist/commands/xgettext/files-collector.spec.js.map +1 -0
- package/dist/commands/xgettext.d.ts +29 -0
- package/dist/commands/xgettext.js +525 -0
- package/dist/commands/xgettext.js.map +1 -0
- package/dist/commands/xgettext.spec.js +897 -0
- package/dist/commands/xgettext.spec.js.map +1 -0
- package/dist/configuration.d.ts +36 -0
- package/dist/configuration.js +261 -0
- package/dist/configuration.js.map +1 -0
- package/dist/esgettext-package-json.d.ts +15 -0
- package/dist/esgettext-package-json.js +3 -0
- package/dist/esgettext-package-json.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +84 -0
- package/dist/index.js.map +1 -0
- package/dist/package.d.ts +1 -0
- package/dist/package.js +10 -11
- package/dist/package.js.map +1 -1
- package/dist/parser/javascript.js +7 -27
- package/dist/parser/javascript.js.map +1 -1
- package/dist/parser/javascript.spec.js +271 -172
- package/dist/parser/javascript.spec.js.map +1 -1
- package/dist/parser/parser.js +159 -146
- package/dist/parser/parser.js.map +1 -1
- package/dist/parser/po.d.ts +1 -1
- package/dist/parser/po.js +111 -128
- package/dist/parser/po.js.map +1 -1
- package/dist/parser/po.spec.js +349 -159
- package/dist/parser/po.spec.js.map +1 -1
- package/dist/parser/typescript.js +8 -27
- package/dist/parser/typescript.js.map +1 -1
- package/dist/parser/typescript.spec.js +56 -41
- package/dist/parser/typescript.spec.js.map +1 -1
- package/dist/pot/catalog.js +98 -82
- package/dist/pot/catalog.js.map +1 -1
- package/dist/pot/catalog.spec.js +47 -43
- package/dist/pot/catalog.spec.js.map +1 -1
- package/dist/pot/entry.js +102 -114
- package/dist/pot/entry.js.map +1 -1
- package/dist/pot/entry.spec.js +255 -139
- package/dist/pot/entry.spec.js.map +1 -1
- package/dist/pot/keyword.js +57 -88
- package/dist/pot/keyword.js.map +1 -1
- package/dist/pot/keyword.spec.js +26 -26
- package/dist/pot/keyword.spec.js.map +1 -1
- package/package.json +36 -24
- 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/parser/__snapshots__/javascript.spec.js.snap +0 -56
- package/dist/parser/__snapshots__/po.spec.js.snap +0 -176
- package/dist/pot/__snapshots__/catalog.spec.js.snap +0 -591
- package/dist/xgettext/__snapshots__/xgettext.spec.js.snap +0 -462
- package/dist/xgettext/file-resolver.js +0 -23
- package/dist/xgettext/file-resolver.js.map +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.js +0 -41
- package/dist/xgettext/files-collector.js.map +0 -1
- 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.js +0 -743
- package/dist/xgettext/xgettext.spec.js.map +0 -1
- /package/dist/{xgettext → commands/xgettext}/file-resolver.spec.d.ts +0 -0
- /package/dist/{xgettext → commands/xgettext}/files-collector.d.ts +0 -0
- /package/dist/{xgettext → commands/xgettext}/files-collector.spec.d.ts +0 -0
- /package/dist/{xgettext → commands}/xgettext.spec.d.ts +0 -0
|
@@ -1,431 +1,530 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
const catalog_1 = require("../pot/catalog");
|
|
4
|
+
const keyword_1 = require("../pot/keyword");
|
|
5
|
+
const javascript_1 = require("./javascript");
|
|
6
|
+
const warnSpy = jest.spyOn(global.console, 'warn').mockImplementation(() => {
|
|
7
7
|
});
|
|
8
|
-
|
|
8
|
+
const errorSpy = jest.spyOn(global.console, 'error').mockImplementation(() => {
|
|
9
9
|
});
|
|
10
|
-
describe('JavaScript parser',
|
|
11
|
-
describe('strings',
|
|
12
|
-
afterEach(
|
|
10
|
+
describe('JavaScript parser', () => {
|
|
11
|
+
describe('strings', () => {
|
|
12
|
+
afterEach(() => {
|
|
13
13
|
warnSpy.mockClear();
|
|
14
14
|
errorSpy.mockClear();
|
|
15
15
|
});
|
|
16
|
-
it('should extract all kinds of strings',
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
it('should extract all kinds of strings', () => {
|
|
17
|
+
const catalog = new catalog_1.Catalog();
|
|
18
|
+
const p = new javascript_1.JavaScriptParser(catalog, { extractAll: true });
|
|
19
|
+
const code = `
|
|
20
|
+
// Directive.
|
|
21
|
+
_("double-quoted string");
|
|
22
|
+
|
|
23
|
+
// Function call.
|
|
24
|
+
_('single-quoted string');
|
|
25
|
+
|
|
26
|
+
// perl-brace-format.
|
|
27
|
+
_x('Hello, {name}!');
|
|
28
|
+
`;
|
|
20
29
|
expect(p.parse(Buffer.from(code), 'example.js')).toBeTruthy();
|
|
21
30
|
expect(catalog.toString({ omitHeader: true })).toMatchSnapshot();
|
|
22
31
|
expect(errorSpy).not.toHaveBeenCalled();
|
|
23
32
|
expect(warnSpy).not.toHaveBeenCalled();
|
|
24
33
|
});
|
|
25
|
-
it('should extract concatenated strings',
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
34
|
+
it('should extract concatenated strings', () => {
|
|
35
|
+
const catalog = new catalog_1.Catalog();
|
|
36
|
+
const p = new javascript_1.JavaScriptParser(catalog, { extractAll: true });
|
|
37
|
+
const code = '"concatenated" + " str" + "i" + "n" + "g";';
|
|
38
|
+
const buf = Buffer.from(code);
|
|
30
39
|
expect(p.parse(buf, 'example.js')).toBeTruthy();
|
|
31
|
-
|
|
40
|
+
const expected = `#: example.js:1
|
|
41
|
+
msgid "concatenated string"
|
|
42
|
+
msgstr ""
|
|
43
|
+
`;
|
|
32
44
|
expect(catalog.toString({ omitHeader: true })).toEqual(expected);
|
|
33
45
|
expect(errorSpy).not.toHaveBeenCalled();
|
|
34
46
|
expect(warnSpy).not.toHaveBeenCalled();
|
|
35
47
|
});
|
|
36
|
-
it('should not extract concatenated strings with a leading variable',
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
48
|
+
it('should not extract concatenated strings with a leading variable', () => {
|
|
49
|
+
const catalog = new catalog_1.Catalog();
|
|
50
|
+
const p = new javascript_1.JavaScriptParser(catalog, { extractAll: true });
|
|
51
|
+
const code = 'prefix + "concatenated" + " string";';
|
|
52
|
+
const buf = Buffer.from(code);
|
|
41
53
|
expect(p.parse(buf, 'example.js')).toBeTruthy();
|
|
42
54
|
expect(catalog.toString({ omitHeader: true })).toEqual('');
|
|
43
55
|
expect(errorSpy).not.toHaveBeenCalled();
|
|
44
56
|
expect(warnSpy).not.toHaveBeenCalled();
|
|
45
57
|
});
|
|
46
|
-
it('should not extract concatenated strings mixed with a variable',
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
58
|
+
it('should not extract concatenated strings mixed with a variable', () => {
|
|
59
|
+
const catalog = new catalog_1.Catalog();
|
|
60
|
+
const p = new javascript_1.JavaScriptParser(catalog, { extractAll: true });
|
|
61
|
+
const code = '"concatenated" + sep + "string";';
|
|
62
|
+
const buf = Buffer.from(code);
|
|
51
63
|
expect(p.parse(buf, 'example.js')).toBeTruthy();
|
|
52
64
|
expect(catalog.toString({ omitHeader: true })).toEqual('');
|
|
53
65
|
expect(errorSpy).not.toHaveBeenCalled();
|
|
54
66
|
expect(warnSpy).not.toHaveBeenCalled();
|
|
55
67
|
});
|
|
56
|
-
it('should not extract concatenated strings with a trailing variable',
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
68
|
+
it('should not extract concatenated strings with a trailing variable', () => {
|
|
69
|
+
const catalog = new catalog_1.Catalog();
|
|
70
|
+
const p = new javascript_1.JavaScriptParser(catalog, { extractAll: true });
|
|
71
|
+
const code = '"concatenated" + " string" + suffix;';
|
|
72
|
+
const buf = Buffer.from(code);
|
|
61
73
|
expect(p.parse(buf, 'example.js')).toBeTruthy();
|
|
62
74
|
expect(catalog.toString({ omitHeader: true })).toEqual('');
|
|
63
75
|
expect(errorSpy).not.toHaveBeenCalled();
|
|
64
76
|
expect(warnSpy).not.toHaveBeenCalled();
|
|
65
77
|
});
|
|
66
78
|
});
|
|
67
|
-
describe('comments',
|
|
68
|
-
afterEach(
|
|
79
|
+
describe('comments', () => {
|
|
80
|
+
afterEach(() => {
|
|
69
81
|
warnSpy.mockClear();
|
|
70
82
|
errorSpy.mockClear();
|
|
71
83
|
});
|
|
72
|
-
it('should extract all kinds of comments',
|
|
73
|
-
|
|
74
|
-
|
|
84
|
+
it('should extract all kinds of comments', () => {
|
|
85
|
+
const catalog = new catalog_1.Catalog();
|
|
86
|
+
const p = new javascript_1.JavaScriptParser(catalog, {
|
|
75
87
|
extractAll: true,
|
|
76
88
|
addAllComments: true,
|
|
77
89
|
});
|
|
78
|
-
|
|
90
|
+
const code = `
|
|
91
|
+
// Single-line comment.
|
|
92
|
+
_('single line');
|
|
93
|
+
|
|
94
|
+
/* Block comment. */
|
|
95
|
+
_('block');
|
|
96
|
+
|
|
97
|
+
// Single-line
|
|
98
|
+
/* and block combined. */
|
|
99
|
+
_('single + block');
|
|
100
|
+
|
|
101
|
+
/* Block */
|
|
102
|
+
// and single-line combined.
|
|
103
|
+
_('block + single');
|
|
104
|
+
|
|
105
|
+
// Skip this.
|
|
106
|
+
|
|
107
|
+
// But catch this.
|
|
108
|
+
_('only immediately preceding');
|
|
109
|
+
|
|
110
|
+
// Only for one string.
|
|
111
|
+
_('catcher'); _('loser');
|
|
112
|
+
|
|
113
|
+
// And this is ignored, too.
|
|
114
|
+
`;
|
|
79
115
|
expect(p.parse(Buffer.from(code), 'example.js')).toBeTruthy();
|
|
80
116
|
expect(catalog.toString({ omitHeader: true })).toMatchSnapshot();
|
|
81
117
|
expect(errorSpy).not.toHaveBeenCalled();
|
|
82
118
|
expect(warnSpy).not.toHaveBeenCalled();
|
|
83
119
|
});
|
|
84
120
|
});
|
|
85
|
-
describe('messages',
|
|
86
|
-
afterEach(
|
|
121
|
+
describe('messages', () => {
|
|
122
|
+
afterEach(() => {
|
|
87
123
|
warnSpy.mockClear();
|
|
88
124
|
errorSpy.mockClear();
|
|
89
125
|
});
|
|
90
|
-
it('should extract a single argument',
|
|
91
|
-
|
|
92
|
-
|
|
126
|
+
it('should extract a single argument', () => {
|
|
127
|
+
const catalog = new catalog_1.Catalog();
|
|
128
|
+
const p = new javascript_1.JavaScriptParser(catalog, {
|
|
93
129
|
keyword: [new keyword_1.Keyword('_')],
|
|
94
130
|
});
|
|
95
|
-
|
|
131
|
+
const code = '_("Hello, world!")';
|
|
96
132
|
expect(p.parse(Buffer.from(code), 'example.js')).toBeTruthy();
|
|
97
|
-
|
|
133
|
+
const expected = `#: example.js:1
|
|
134
|
+
msgid "Hello, world!"
|
|
135
|
+
msgstr ""
|
|
136
|
+
`;
|
|
98
137
|
expect(catalog.toString({ omitHeader: true })).toEqual(expected);
|
|
99
138
|
expect(errorSpy).not.toHaveBeenCalled();
|
|
100
139
|
expect(warnSpy).not.toHaveBeenCalled();
|
|
101
140
|
});
|
|
102
|
-
it('should extract singular and plural form',
|
|
103
|
-
|
|
104
|
-
|
|
141
|
+
it('should extract singular and plural form', () => {
|
|
142
|
+
const catalog = new catalog_1.Catalog();
|
|
143
|
+
const p = new javascript_1.JavaScriptParser(catalog, {
|
|
105
144
|
keyword: [new keyword_1.Keyword('_n', ['1', '2'])],
|
|
106
145
|
});
|
|
107
|
-
|
|
146
|
+
const code = '_n("There was an error!", "There were errors!", n)';
|
|
108
147
|
expect(p.parse(Buffer.from(code), 'example.js')).toBeTruthy();
|
|
109
|
-
|
|
148
|
+
const expected = `#: example.js:1
|
|
149
|
+
msgid "There was an error!"
|
|
150
|
+
msgid_plural "There were errors!"
|
|
151
|
+
msgstr[0] ""
|
|
152
|
+
msgstr[1] ""
|
|
153
|
+
`;
|
|
110
154
|
expect(catalog.toString({ omitHeader: true })).toEqual(expected);
|
|
111
155
|
expect(errorSpy).not.toHaveBeenCalled();
|
|
112
156
|
expect(warnSpy).not.toHaveBeenCalled();
|
|
113
157
|
});
|
|
114
|
-
it('should extract context, singular and plural form',
|
|
115
|
-
|
|
116
|
-
|
|
158
|
+
it('should extract context, singular and plural form', () => {
|
|
159
|
+
const catalog = new catalog_1.Catalog();
|
|
160
|
+
const p = new javascript_1.JavaScriptParser(catalog, {
|
|
117
161
|
keyword: [new keyword_1.Keyword('_np', ['1c', '2', '3'])],
|
|
118
162
|
});
|
|
119
|
-
|
|
163
|
+
const code = '_np("context", "There was an error!", "There were errors!", n)';
|
|
120
164
|
expect(p.parse(Buffer.from(code), 'example.js')).toBeTruthy();
|
|
121
|
-
|
|
165
|
+
const expected = `#: example.js:1
|
|
166
|
+
msgctxt "context"
|
|
167
|
+
msgid "There was an error!"
|
|
168
|
+
msgid_plural "There were errors!"
|
|
169
|
+
msgstr[0] ""
|
|
170
|
+
msgstr[1] ""
|
|
171
|
+
`;
|
|
122
172
|
expect(catalog.toString({ omitHeader: true })).toEqual(expected);
|
|
123
173
|
expect(errorSpy).not.toHaveBeenCalled();
|
|
124
174
|
expect(warnSpy).not.toHaveBeenCalled();
|
|
125
175
|
});
|
|
126
|
-
it('should handle other callees',
|
|
127
|
-
|
|
128
|
-
|
|
176
|
+
it('should handle other callees', () => {
|
|
177
|
+
const catalog = new catalog_1.Catalog();
|
|
178
|
+
const p = new javascript_1.JavaScriptParser(catalog, {
|
|
129
179
|
keyword: [new keyword_1.Keyword('_')],
|
|
130
180
|
});
|
|
131
|
-
|
|
181
|
+
const code = '"string".trim()';
|
|
132
182
|
expect(p.parse(Buffer.from(code), 'example.js')).toBeTruthy();
|
|
133
183
|
expect(catalog.toString({ omitHeader: true })).toEqual('');
|
|
134
184
|
expect(errorSpy).not.toHaveBeenCalled();
|
|
135
185
|
expect(warnSpy).not.toHaveBeenCalled();
|
|
136
186
|
});
|
|
137
|
-
it('should not extract from unknown methods',
|
|
138
|
-
|
|
139
|
-
|
|
187
|
+
it('should not extract from unknown methods', () => {
|
|
188
|
+
const catalog = new catalog_1.Catalog();
|
|
189
|
+
const p = new javascript_1.JavaScriptParser(catalog, {
|
|
140
190
|
keyword: [new keyword_1.Keyword('_')],
|
|
141
191
|
});
|
|
142
|
-
|
|
192
|
+
const code = 'gettext("string")';
|
|
143
193
|
expect(p.parse(Buffer.from(code), 'example.js')).toBeTruthy();
|
|
144
194
|
expect(catalog.toString({ omitHeader: true })).toEqual('');
|
|
145
195
|
expect(errorSpy).not.toHaveBeenCalled();
|
|
146
196
|
expect(warnSpy).not.toHaveBeenCalled();
|
|
147
197
|
});
|
|
148
|
-
it('should honor the total arguments spec',
|
|
149
|
-
|
|
150
|
-
|
|
198
|
+
it('should honor the total arguments spec', () => {
|
|
199
|
+
const catalog = new catalog_1.Catalog();
|
|
200
|
+
const p = new javascript_1.JavaScriptParser(catalog, {
|
|
151
201
|
keyword: [new keyword_1.Keyword('_', ['1t'])],
|
|
152
202
|
});
|
|
153
|
-
|
|
203
|
+
const code = '_("Hello", "world")';
|
|
154
204
|
expect(p.parse(Buffer.from(code), 'example.js')).toBeTruthy();
|
|
155
205
|
expect(catalog.toString({ omitHeader: true })).toEqual('');
|
|
156
206
|
expect(errorSpy).not.toHaveBeenCalled();
|
|
157
207
|
expect(warnSpy).not.toHaveBeenCalled();
|
|
158
208
|
});
|
|
159
|
-
it('should not extract non existing singular arguments',
|
|
160
|
-
|
|
161
|
-
|
|
209
|
+
it('should not extract non existing singular arguments', () => {
|
|
210
|
+
const catalog = new catalog_1.Catalog();
|
|
211
|
+
const p = new javascript_1.JavaScriptParser(catalog, {
|
|
162
212
|
keyword: [new keyword_1.Keyword('_')],
|
|
163
213
|
});
|
|
164
|
-
|
|
214
|
+
const code = '_()';
|
|
165
215
|
expect(p.parse(Buffer.from(code), 'example.js')).toBeTruthy();
|
|
166
216
|
expect(catalog.toString({ omitHeader: true })).toEqual('');
|
|
167
217
|
expect(errorSpy).not.toHaveBeenCalled();
|
|
168
218
|
expect(warnSpy).not.toHaveBeenCalled();
|
|
169
219
|
});
|
|
170
|
-
it('should not extract non existing plural arguments',
|
|
171
|
-
|
|
172
|
-
|
|
220
|
+
it('should not extract non existing plural arguments', () => {
|
|
221
|
+
const catalog = new catalog_1.Catalog();
|
|
222
|
+
const p = new javascript_1.JavaScriptParser(catalog, {
|
|
173
223
|
keyword: [new keyword_1.Keyword('_n', ['1', '2'])],
|
|
174
224
|
});
|
|
175
|
-
|
|
225
|
+
const code = '_n("One universe")';
|
|
176
226
|
expect(p.parse(Buffer.from(code), 'example.js')).toBeTruthy();
|
|
177
227
|
expect(catalog.toString({ omitHeader: true })).toEqual('');
|
|
178
228
|
expect(errorSpy).not.toHaveBeenCalled();
|
|
179
229
|
expect(warnSpy).not.toHaveBeenCalled();
|
|
180
230
|
});
|
|
181
|
-
it('should not extract non existing context arguments',
|
|
182
|
-
|
|
183
|
-
|
|
231
|
+
it('should not extract non existing context arguments', () => {
|
|
232
|
+
const catalog = new catalog_1.Catalog();
|
|
233
|
+
const p = new javascript_1.JavaScriptParser(catalog, {
|
|
184
234
|
keyword: [new keyword_1.Keyword('_pn', ['1', '2', '3c'])],
|
|
185
235
|
});
|
|
186
|
-
|
|
236
|
+
const code = '_pn("one world", "many worlds")';
|
|
187
237
|
expect(p.parse(Buffer.from(code), 'example.js')).toBeTruthy();
|
|
188
238
|
expect(catalog.toString({ omitHeader: true })).toEqual('');
|
|
189
239
|
expect(errorSpy).not.toHaveBeenCalled();
|
|
190
240
|
expect(warnSpy).not.toHaveBeenCalled();
|
|
191
241
|
});
|
|
192
|
-
it('should reject variables as singular arguments',
|
|
193
|
-
|
|
194
|
-
|
|
242
|
+
it('should reject variables as singular arguments', () => {
|
|
243
|
+
const catalog = new catalog_1.Catalog();
|
|
244
|
+
const p = new javascript_1.JavaScriptParser(catalog, {
|
|
195
245
|
keyword: [new keyword_1.Keyword('_np', ['1c', '2', '3'])],
|
|
196
246
|
});
|
|
197
|
-
|
|
247
|
+
const code = '_np("world", earth, "many earths")';
|
|
198
248
|
expect(p.parse(Buffer.from(code), 'example.js')).toBeTruthy();
|
|
199
249
|
expect(catalog.toString({ omitHeader: true })).toEqual('');
|
|
200
250
|
expect(errorSpy).not.toHaveBeenCalled();
|
|
201
251
|
expect(warnSpy).not.toHaveBeenCalled();
|
|
202
252
|
});
|
|
203
|
-
it('should allow simple template literals as singular arguments',
|
|
204
|
-
|
|
205
|
-
|
|
253
|
+
it('should allow simple template literals as singular arguments', () => {
|
|
254
|
+
const catalog = new catalog_1.Catalog();
|
|
255
|
+
const p = new javascript_1.JavaScriptParser(catalog, {
|
|
206
256
|
keyword: [new keyword_1.Keyword('_np', ['1c', '2', '3'])],
|
|
207
257
|
});
|
|
208
|
-
|
|
258
|
+
const code = '_np("world", `one earth`, "many earths")';
|
|
209
259
|
expect(p.parse(Buffer.from(code), 'example.js')).toBeTruthy();
|
|
210
|
-
|
|
260
|
+
const expected = `#: example.js:1
|
|
261
|
+
msgctxt "world"
|
|
262
|
+
msgid "one earth"
|
|
263
|
+
msgid_plural "many earths"
|
|
264
|
+
msgstr[0] ""
|
|
265
|
+
msgstr[1] ""
|
|
266
|
+
`;
|
|
211
267
|
expect(catalog.toString({ omitHeader: true })).toEqual(expected);
|
|
212
268
|
expect(errorSpy).not.toHaveBeenCalled();
|
|
213
269
|
expect(warnSpy).not.toHaveBeenCalled();
|
|
214
270
|
});
|
|
215
|
-
it('should reject template literals with embedded expressions as singular arguments',
|
|
216
|
-
|
|
217
|
-
|
|
271
|
+
it('should reject template literals with embedded expressions as singular arguments', () => {
|
|
272
|
+
const catalog = new catalog_1.Catalog();
|
|
273
|
+
const p = new javascript_1.JavaScriptParser(catalog, {
|
|
218
274
|
keyword: [new keyword_1.Keyword('_np', ['1c', '2', '3'])],
|
|
219
275
|
});
|
|
220
|
-
|
|
276
|
+
const code = '_np("world", `one ${planet}`, "many earths")';
|
|
221
277
|
expect(p.parse(Buffer.from(code), 'example.js')).toBeFalsy();
|
|
222
278
|
expect(catalog.toString({ omitHeader: true })).toEqual('');
|
|
223
279
|
expect(errorSpy).toHaveBeenCalledTimes(1);
|
|
224
|
-
expect(errorSpy).toHaveBeenNthCalledWith(1, 'example.js:1:13-1:28:
|
|
280
|
+
expect(errorSpy).toHaveBeenNthCalledWith(1, 'example.js:1:13-1:28: Error: template literals with embedded' +
|
|
225
281
|
' expressions are not allowed as arguments to gettext' +
|
|
226
282
|
' functions because they are not constant');
|
|
227
283
|
expect(warnSpy).not.toHaveBeenCalled();
|
|
228
284
|
});
|
|
229
|
-
it('should reject variables as plural arguments',
|
|
230
|
-
|
|
231
|
-
|
|
285
|
+
it('should reject variables as plural arguments', () => {
|
|
286
|
+
const catalog = new catalog_1.Catalog();
|
|
287
|
+
const p = new javascript_1.JavaScriptParser(catalog, {
|
|
232
288
|
keyword: [new keyword_1.Keyword('_np', ['1c', '2', '3'])],
|
|
233
289
|
});
|
|
234
|
-
|
|
290
|
+
const code = '_np("world", "earth", earths)';
|
|
235
291
|
expect(p.parse(Buffer.from(code), 'example.js')).toBeTruthy();
|
|
236
292
|
expect(catalog.toString({ omitHeader: true })).toEqual('');
|
|
237
293
|
expect(errorSpy).not.toHaveBeenCalled();
|
|
238
294
|
expect(warnSpy).not.toHaveBeenCalled();
|
|
239
295
|
});
|
|
240
|
-
it('should allow simple template literals as plural arguments',
|
|
241
|
-
|
|
242
|
-
|
|
296
|
+
it('should allow simple template literals as plural arguments', () => {
|
|
297
|
+
const catalog = new catalog_1.Catalog();
|
|
298
|
+
const p = new javascript_1.JavaScriptParser(catalog, {
|
|
243
299
|
keyword: [new keyword_1.Keyword('_np', ['1c', '2', '3'])],
|
|
244
300
|
});
|
|
245
|
-
|
|
301
|
+
const code = '_np("world", "one earth", `many earths`)';
|
|
246
302
|
expect(p.parse(Buffer.from(code), 'example.js')).toBeTruthy();
|
|
247
|
-
|
|
303
|
+
const expected = `#: example.js:1
|
|
304
|
+
msgctxt "world"
|
|
305
|
+
msgid "one earth"
|
|
306
|
+
msgid_plural "many earths"
|
|
307
|
+
msgstr[0] ""
|
|
308
|
+
msgstr[1] ""
|
|
309
|
+
`;
|
|
248
310
|
expect(catalog.toString({ omitHeader: true })).toEqual(expected);
|
|
249
311
|
expect(errorSpy).not.toHaveBeenCalled();
|
|
250
312
|
expect(warnSpy).not.toHaveBeenCalled();
|
|
251
313
|
});
|
|
252
|
-
it('should reject template literals with embedded expressions as plural arguments',
|
|
253
|
-
|
|
254
|
-
|
|
314
|
+
it('should reject template literals with embedded expressions as plural arguments', () => {
|
|
315
|
+
const catalog = new catalog_1.Catalog();
|
|
316
|
+
const p = new javascript_1.JavaScriptParser(catalog, {
|
|
255
317
|
keyword: [new keyword_1.Keyword('_np', ['1c', '2', '3'])],
|
|
256
318
|
});
|
|
257
|
-
|
|
319
|
+
const code = '_np("world", "one earth", `many ${planets}`)';
|
|
258
320
|
expect(p.parse(Buffer.from(code), 'example.js')).toBeFalsy();
|
|
259
321
|
expect(catalog.toString({ omitHeader: true })).toEqual('');
|
|
260
322
|
expect(errorSpy).toHaveBeenCalledTimes(1);
|
|
261
|
-
expect(errorSpy).toHaveBeenNthCalledWith(1, 'example.js:1:26-1:43:
|
|
323
|
+
expect(errorSpy).toHaveBeenNthCalledWith(1, 'example.js:1:26-1:43: Error: template literals with embedded' +
|
|
262
324
|
' expressions are not allowed as arguments to gettext' +
|
|
263
325
|
' functions because they are not constant');
|
|
264
326
|
expect(warnSpy).not.toHaveBeenCalled();
|
|
265
327
|
});
|
|
266
|
-
it('should reject variables as msgctxt arguments',
|
|
267
|
-
|
|
268
|
-
|
|
328
|
+
it('should reject variables as msgctxt arguments', () => {
|
|
329
|
+
const catalog = new catalog_1.Catalog();
|
|
330
|
+
const p = new javascript_1.JavaScriptParser(catalog, {
|
|
269
331
|
keyword: [new keyword_1.Keyword('_np', ['1c', '2', '3'])],
|
|
270
332
|
});
|
|
271
|
-
|
|
333
|
+
const code = '_np(world, "earth", "many earths")';
|
|
272
334
|
expect(p.parse(Buffer.from(code), 'example.js')).toBeTruthy();
|
|
273
335
|
expect(catalog.toString({ omitHeader: true })).toEqual('');
|
|
274
336
|
expect(errorSpy).not.toHaveBeenCalled();
|
|
275
337
|
expect(warnSpy).not.toHaveBeenCalled();
|
|
276
338
|
});
|
|
277
|
-
it('should allow simple template literals as msgctxt arguments',
|
|
278
|
-
|
|
279
|
-
|
|
339
|
+
it('should allow simple template literals as msgctxt arguments', () => {
|
|
340
|
+
const catalog = new catalog_1.Catalog();
|
|
341
|
+
const p = new javascript_1.JavaScriptParser(catalog, {
|
|
280
342
|
keyword: [new keyword_1.Keyword('_np', ['1c', '2', '3'])],
|
|
281
343
|
});
|
|
282
|
-
|
|
344
|
+
const code = '_np(`world`, "one earth", "many earths")';
|
|
283
345
|
expect(p.parse(Buffer.from(code), 'example.js')).toBeTruthy();
|
|
284
|
-
|
|
346
|
+
const expected = `#: example.js:1
|
|
347
|
+
msgctxt "world"
|
|
348
|
+
msgid "one earth"
|
|
349
|
+
msgid_plural "many earths"
|
|
350
|
+
msgstr[0] ""
|
|
351
|
+
msgstr[1] ""
|
|
352
|
+
`;
|
|
285
353
|
expect(catalog.toString({ omitHeader: true })).toEqual(expected);
|
|
286
354
|
expect(errorSpy).not.toHaveBeenCalled();
|
|
287
355
|
expect(warnSpy).not.toHaveBeenCalled();
|
|
288
356
|
});
|
|
289
|
-
it('should reject template literals with embedded expressions as msgctxt arguments',
|
|
290
|
-
|
|
291
|
-
|
|
357
|
+
it('should reject template literals with embedded expressions as msgctxt arguments', () => {
|
|
358
|
+
const catalog = new catalog_1.Catalog();
|
|
359
|
+
const p = new javascript_1.JavaScriptParser(catalog, {
|
|
292
360
|
keyword: [new keyword_1.Keyword('_np', ['1c', '2', '3'])],
|
|
293
361
|
});
|
|
294
|
-
|
|
362
|
+
const code = '_np("world", "one earth", `many ${planets}`)';
|
|
295
363
|
expect(p.parse(Buffer.from(code), 'example.js')).toBeFalsy();
|
|
296
364
|
expect(catalog.toString({ omitHeader: true })).toEqual('');
|
|
297
365
|
expect(errorSpy).toHaveBeenCalledTimes(1);
|
|
298
|
-
expect(errorSpy).toHaveBeenNthCalledWith(1, 'example.js:1:26-1:43:
|
|
366
|
+
expect(errorSpy).toHaveBeenNthCalledWith(1, 'example.js:1:26-1:43: Error: template literals with embedded' +
|
|
299
367
|
' expressions are not allowed as arguments to gettext' +
|
|
300
368
|
' functions because they are not constant');
|
|
301
369
|
expect(warnSpy).not.toHaveBeenCalled();
|
|
302
370
|
});
|
|
303
371
|
});
|
|
304
|
-
describe('encoding',
|
|
305
|
-
afterEach(
|
|
372
|
+
describe('encoding', () => {
|
|
373
|
+
afterEach(() => {
|
|
306
374
|
warnSpy.mockClear();
|
|
307
375
|
errorSpy.mockClear();
|
|
308
376
|
});
|
|
309
|
-
it('should decode to JavaScript strings',
|
|
310
|
-
|
|
311
|
-
|
|
377
|
+
it('should decode to JavaScript strings', () => {
|
|
378
|
+
const catalog = new catalog_1.Catalog();
|
|
379
|
+
const p = new javascript_1.JavaScriptParser(catalog, {
|
|
312
380
|
keyword: [new keyword_1.Keyword('_')],
|
|
313
381
|
});
|
|
314
|
-
|
|
382
|
+
const code = '_("Hello, world!")';
|
|
315
383
|
expect(p.parse(Buffer.from(code), 'example.js')).toBeTruthy();
|
|
316
|
-
|
|
384
|
+
const expected = `#: example.js:1
|
|
385
|
+
msgid "Hello, world!"
|
|
386
|
+
msgstr ""
|
|
387
|
+
`;
|
|
317
388
|
expect(catalog.toString({ omitHeader: true })).toEqual(expected);
|
|
318
389
|
expect(errorSpy).not.toHaveBeenCalled();
|
|
319
390
|
expect(warnSpy).not.toHaveBeenCalled();
|
|
320
391
|
});
|
|
321
392
|
});
|
|
322
|
-
describe('binary expressions',
|
|
323
|
-
afterEach(
|
|
393
|
+
describe('binary expressions', () => {
|
|
394
|
+
afterEach(() => {
|
|
324
395
|
warnSpy.mockClear();
|
|
325
396
|
errorSpy.mockClear();
|
|
326
397
|
});
|
|
327
|
-
it('should extract concatenated strings',
|
|
328
|
-
|
|
329
|
-
|
|
398
|
+
it('should extract concatenated strings', () => {
|
|
399
|
+
const catalog = new catalog_1.Catalog();
|
|
400
|
+
const p = new javascript_1.JavaScriptParser(catalog, {
|
|
330
401
|
keyword: [new keyword_1.Keyword('_')],
|
|
331
402
|
});
|
|
332
|
-
|
|
403
|
+
const code = '_("It\'s a " + "sad" + " and beautiful world!")';
|
|
333
404
|
expect(p.parse(Buffer.from(code), 'example.js')).toBeTruthy();
|
|
334
|
-
|
|
405
|
+
const expected = `#: example.js:1
|
|
406
|
+
msgid "It's a sad and beautiful world!"
|
|
407
|
+
msgstr ""
|
|
408
|
+
`;
|
|
335
409
|
expect(catalog.toString({ omitHeader: true })).toEqual(expected);
|
|
336
410
|
expect(errorSpy).not.toHaveBeenCalled();
|
|
337
411
|
expect(warnSpy).not.toHaveBeenCalled();
|
|
338
412
|
});
|
|
339
|
-
it('should extract concatenated strings with simple template literals',
|
|
340
|
-
|
|
341
|
-
|
|
413
|
+
it('should extract concatenated strings with simple template literals', () => {
|
|
414
|
+
const catalog = new catalog_1.Catalog();
|
|
415
|
+
const p = new javascript_1.JavaScriptParser(catalog, {
|
|
342
416
|
keyword: [new keyword_1.Keyword('_')],
|
|
343
417
|
});
|
|
344
|
-
|
|
418
|
+
const code = '_("It\'s a " + `sad` + " and beautiful world!")';
|
|
345
419
|
expect(p.parse(Buffer.from(code), 'example.js')).toBeTruthy();
|
|
346
|
-
|
|
420
|
+
const expected = `#: example.js:1
|
|
421
|
+
msgid "It's a sad and beautiful world!"
|
|
422
|
+
msgstr ""
|
|
423
|
+
`;
|
|
347
424
|
expect(catalog.toString({ omitHeader: true })).toEqual(expected);
|
|
348
425
|
expect(errorSpy).not.toHaveBeenCalled();
|
|
349
426
|
expect(warnSpy).not.toHaveBeenCalled();
|
|
350
427
|
});
|
|
351
|
-
it('should ignore concatenated strings with variables',
|
|
352
|
-
|
|
353
|
-
|
|
428
|
+
it('should ignore concatenated strings with variables', () => {
|
|
429
|
+
const catalog = new catalog_1.Catalog();
|
|
430
|
+
const p = new javascript_1.JavaScriptParser(catalog, {
|
|
354
431
|
keyword: [new keyword_1.Keyword('_')],
|
|
355
432
|
});
|
|
356
|
-
|
|
433
|
+
const code = '_("It\'s a " + what + " and beautiful world!")';
|
|
357
434
|
expect(p.parse(Buffer.from(code), 'example.js')).toBeTruthy();
|
|
358
435
|
expect(catalog.toString({ omitHeader: true })).toEqual('');
|
|
359
436
|
expect(errorSpy).not.toHaveBeenCalled();
|
|
360
437
|
expect(warnSpy).not.toHaveBeenCalled();
|
|
361
438
|
});
|
|
362
|
-
it('should report concatenated strings with interpolations',
|
|
363
|
-
|
|
364
|
-
|
|
439
|
+
it('should report concatenated strings with interpolations', () => {
|
|
440
|
+
const catalog = new catalog_1.Catalog();
|
|
441
|
+
const p = new javascript_1.JavaScriptParser(catalog, {
|
|
365
442
|
keyword: [new keyword_1.Keyword('_')],
|
|
366
443
|
});
|
|
367
|
-
|
|
444
|
+
const code = '_("It\'s " + `a ${what}` + " and beautiful world!")';
|
|
368
445
|
expect(p.parse(Buffer.from(code), 'example.js')).toBeFalsy();
|
|
369
446
|
expect(errorSpy).toHaveBeenCalledTimes(1);
|
|
370
|
-
expect(errorSpy).toHaveBeenCalledWith('example.js:1:12-1:23:
|
|
447
|
+
expect(errorSpy).toHaveBeenCalledWith('example.js:1:12-1:23: Error:' +
|
|
371
448
|
' template literals with embedded expressions are not' +
|
|
372
449
|
' allowed as arguments to gettext functions because' +
|
|
373
450
|
' they are not constant');
|
|
374
451
|
expect(warnSpy).not.toHaveBeenCalled();
|
|
375
452
|
});
|
|
376
453
|
});
|
|
377
|
-
describe('comments above calls',
|
|
378
|
-
afterEach(
|
|
454
|
+
describe('comments above calls', () => {
|
|
455
|
+
afterEach(() => {
|
|
379
456
|
warnSpy.mockClear();
|
|
380
457
|
errorSpy.mockClear();
|
|
381
458
|
});
|
|
382
|
-
it('should extract xgettext: comments',
|
|
383
|
-
|
|
384
|
-
|
|
459
|
+
it('should extract xgettext: comments', () => {
|
|
460
|
+
const catalog = new catalog_1.Catalog();
|
|
461
|
+
const p = new javascript_1.JavaScriptParser(catalog, {
|
|
385
462
|
keyword: [new keyword_1.Keyword('_')],
|
|
386
463
|
});
|
|
387
|
-
|
|
464
|
+
const code = `// xgettext: no-perl-brace-format
|
|
465
|
+
_("It's a {sad} and beautiful world!")
|
|
466
|
+
`;
|
|
388
467
|
expect(p.parse(Buffer.from(code), 'example.js')).toBeTruthy();
|
|
389
|
-
|
|
468
|
+
const expected = `#: example.js:2
|
|
469
|
+
#, no-perl-brace-format
|
|
470
|
+
msgid "It's a {sad} and beautiful world!"
|
|
471
|
+
msgstr ""
|
|
472
|
+
`;
|
|
390
473
|
expect(catalog.toString({ omitHeader: true })).toEqual(expected);
|
|
391
474
|
expect(errorSpy).not.toHaveBeenCalled();
|
|
392
475
|
expect(warnSpy).not.toHaveBeenCalled();
|
|
393
476
|
});
|
|
394
|
-
it('should ignore invalid xgettext: comments',
|
|
395
|
-
|
|
396
|
-
|
|
477
|
+
it('should ignore invalid xgettext: comments', () => {
|
|
478
|
+
const catalog = new catalog_1.Catalog();
|
|
479
|
+
const p = new javascript_1.JavaScriptParser(catalog, {
|
|
397
480
|
keyword: [new keyword_1.Keyword('_')],
|
|
398
481
|
});
|
|
399
|
-
|
|
482
|
+
const code = `// xgettext: down-by-law
|
|
483
|
+
_("It's a sad and beautiful world!")
|
|
484
|
+
`;
|
|
400
485
|
expect(p.parse(Buffer.from(code), 'example.js')).toBeTruthy();
|
|
401
|
-
|
|
486
|
+
const expected = `#: example.js:2
|
|
487
|
+
msgid "It's a sad and beautiful world!"
|
|
488
|
+
msgstr ""
|
|
489
|
+
`;
|
|
402
490
|
expect(catalog.toString({ omitHeader: true })).toEqual(expected);
|
|
403
491
|
expect(errorSpy).not.toHaveBeenCalled();
|
|
404
492
|
expect(warnSpy).not.toHaveBeenCalled();
|
|
405
493
|
});
|
|
406
|
-
it('should extract translator comments',
|
|
407
|
-
|
|
408
|
-
|
|
494
|
+
it('should extract translator comments', () => {
|
|
495
|
+
const catalog = new catalog_1.Catalog();
|
|
496
|
+
const p = new javascript_1.JavaScriptParser(catalog, {
|
|
409
497
|
keyword: [new keyword_1.Keyword('_')],
|
|
410
498
|
addComments: ['TRANSLATORS:'],
|
|
411
499
|
});
|
|
412
|
-
|
|
500
|
+
const code = `// TRANSLATORS: Down by Law
|
|
501
|
+
_("It's a sad and beautiful world!")
|
|
502
|
+
`;
|
|
413
503
|
expect(p.parse(Buffer.from(code), 'example.js')).toBeTruthy();
|
|
414
|
-
|
|
504
|
+
const expected = `#. TRANSLATORS: Down by Law
|
|
505
|
+
#: example.js:2
|
|
506
|
+
msgid "It's a sad and beautiful world!"
|
|
507
|
+
msgstr ""
|
|
508
|
+
`;
|
|
415
509
|
expect(catalog.toString({ omitHeader: true })).toEqual(expected);
|
|
416
510
|
expect(errorSpy).not.toHaveBeenCalled();
|
|
417
511
|
expect(warnSpy).not.toHaveBeenCalled();
|
|
418
512
|
expect(warnSpy).not.toHaveBeenCalled();
|
|
419
513
|
});
|
|
420
|
-
it('should ignore other comments',
|
|
421
|
-
|
|
422
|
-
|
|
514
|
+
it('should ignore other comments', () => {
|
|
515
|
+
const catalog = new catalog_1.Catalog();
|
|
516
|
+
const p = new javascript_1.JavaScriptParser(catalog, {
|
|
423
517
|
keyword: [new keyword_1.Keyword('_')],
|
|
424
518
|
addComments: ['TRANSLATORS:'],
|
|
425
519
|
});
|
|
426
|
-
|
|
520
|
+
const code = `// TERMINATORS: Down by Law
|
|
521
|
+
_("It's a sad and beautiful world!")
|
|
522
|
+
`;
|
|
427
523
|
expect(p.parse(Buffer.from(code), 'example.js')).toBeTruthy();
|
|
428
|
-
|
|
524
|
+
const expected = `#: example.js:2
|
|
525
|
+
msgid "It's a sad and beautiful world!"
|
|
526
|
+
msgstr ""
|
|
527
|
+
`;
|
|
429
528
|
expect(catalog.toString({ omitHeader: true })).toEqual(expected);
|
|
430
529
|
expect(errorSpy).not.toHaveBeenCalled();
|
|
431
530
|
expect(warnSpy).not.toHaveBeenCalled();
|