@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.
Files changed (125) hide show
  1. package/README.md +196 -21
  2. package/dist/command.d.ts +11 -0
  3. package/dist/command.js +3 -0
  4. package/dist/command.js.map +1 -0
  5. package/dist/commands/convert.d.ts +24 -0
  6. package/dist/commands/convert.js +284 -0
  7. package/dist/commands/convert.js.map +1 -0
  8. package/dist/commands/install.d.ts +22 -0
  9. package/dist/commands/install.js +249 -0
  10. package/dist/commands/install.js.map +1 -0
  11. package/dist/commands/msgfmt-all.d.ts +20 -0
  12. package/dist/commands/msgfmt-all.js +200 -0
  13. package/dist/commands/msgfmt-all.js.map +1 -0
  14. package/dist/commands/msgmerge-all.d.ts +21 -0
  15. package/dist/commands/msgmerge-all.js +212 -0
  16. package/dist/commands/msgmerge-all.js.map +1 -0
  17. package/dist/{xgettext → commands/xgettext}/file-resolver.d.ts +1 -1
  18. package/dist/commands/xgettext/file-resolver.js +21 -0
  19. package/dist/commands/xgettext/file-resolver.js.map +1 -0
  20. package/dist/commands/xgettext/file-resolver.spec.js +22 -0
  21. package/dist/commands/xgettext/file-resolver.spec.js.map +1 -0
  22. package/dist/commands/xgettext/files-collector.js +39 -0
  23. package/dist/commands/xgettext/files-collector.js.map +1 -0
  24. package/dist/{xgettext → commands/xgettext}/files-collector.spec.js +39 -21
  25. package/dist/commands/xgettext/files-collector.spec.js.map +1 -0
  26. package/dist/commands/xgettext.d.ts +29 -0
  27. package/dist/commands/xgettext.js +525 -0
  28. package/dist/commands/xgettext.js.map +1 -0
  29. package/dist/commands/xgettext.spec.js +897 -0
  30. package/dist/commands/xgettext.spec.js.map +1 -0
  31. package/dist/configuration.d.ts +36 -0
  32. package/dist/configuration.js +261 -0
  33. package/dist/configuration.js.map +1 -0
  34. package/dist/esgettext-package-json.d.ts +15 -0
  35. package/dist/esgettext-package-json.js +3 -0
  36. package/dist/esgettext-package-json.js.map +1 -0
  37. package/dist/index.d.ts +2 -0
  38. package/dist/index.js +84 -0
  39. package/dist/index.js.map +1 -0
  40. package/dist/package.d.ts +1 -0
  41. package/dist/package.js +10 -11
  42. package/dist/package.js.map +1 -1
  43. package/dist/parser/javascript.js +7 -27
  44. package/dist/parser/javascript.js.map +1 -1
  45. package/dist/parser/javascript.spec.js +271 -172
  46. package/dist/parser/javascript.spec.js.map +1 -1
  47. package/dist/parser/parser.js +159 -146
  48. package/dist/parser/parser.js.map +1 -1
  49. package/dist/parser/po.d.ts +1 -1
  50. package/dist/parser/po.js +111 -128
  51. package/dist/parser/po.js.map +1 -1
  52. package/dist/parser/po.spec.js +349 -159
  53. package/dist/parser/po.spec.js.map +1 -1
  54. package/dist/parser/typescript.js +8 -27
  55. package/dist/parser/typescript.js.map +1 -1
  56. package/dist/parser/typescript.spec.js +56 -41
  57. package/dist/parser/typescript.spec.js.map +1 -1
  58. package/dist/pot/catalog.js +98 -82
  59. package/dist/pot/catalog.js.map +1 -1
  60. package/dist/pot/catalog.spec.js +47 -43
  61. package/dist/pot/catalog.spec.js.map +1 -1
  62. package/dist/pot/entry.js +102 -114
  63. package/dist/pot/entry.js.map +1 -1
  64. package/dist/pot/entry.spec.js +255 -139
  65. package/dist/pot/entry.spec.js.map +1 -1
  66. package/dist/pot/keyword.js +57 -88
  67. package/dist/pot/keyword.js.map +1 -1
  68. package/dist/pot/keyword.spec.js +26 -26
  69. package/dist/pot/keyword.spec.js.map +1 -1
  70. package/package.json +36 -24
  71. package/bin/esgettext-install.js +0 -5
  72. package/bin/esgettext-mo2json.js +0 -5
  73. package/bin/esgettext-msgfmt-all.js +0 -5
  74. package/bin/esgettext-msgmerge-all.js +0 -5
  75. package/bin/esgettext-xgettext.js +0 -5
  76. package/dist/cli/getopt.d.ts +0 -34
  77. package/dist/cli/getopt.js +0 -150
  78. package/dist/cli/getopt.js.map +0 -1
  79. package/dist/cli/getopt.spec.d.ts +0 -1
  80. package/dist/cli/getopt.spec.js +0 -164
  81. package/dist/cli/getopt.spec.js.map +0 -1
  82. package/dist/cli/install.d.ts +0 -1
  83. package/dist/cli/install.js +0 -91
  84. package/dist/cli/install.js.map +0 -1
  85. package/dist/cli/mo2json-cli.d.ts +0 -1
  86. package/dist/cli/mo2json-cli.js +0 -48
  87. package/dist/cli/mo2json-cli.js.map +0 -1
  88. package/dist/cli/msgfmt-all.d.ts +0 -1
  89. package/dist/cli/msgfmt-all.js +0 -99
  90. package/dist/cli/msgfmt-all.js.map +0 -1
  91. package/dist/cli/msgmerge-all.d.ts +0 -1
  92. package/dist/cli/msgmerge-all.js +0 -85
  93. package/dist/cli/msgmerge-all.js.map +0 -1
  94. package/dist/cli/xgettext-cli.d.ts +0 -1
  95. package/dist/cli/xgettext-cli.js +0 -303
  96. package/dist/cli/xgettext-cli.js.map +0 -1
  97. package/dist/install/install.d.ts +0 -10
  98. package/dist/install/install.js +0 -157
  99. package/dist/install/install.js.map +0 -1
  100. package/dist/msgfmt-all/msgfmt-all.d.ts +0 -8
  101. package/dist/msgfmt-all/msgfmt-all.js +0 -142
  102. package/dist/msgfmt-all/msgfmt-all.js.map +0 -1
  103. package/dist/msgmerge-all/msgmerge-all.d.ts +0 -9
  104. package/dist/msgmerge-all/msgmerge-all.js +0 -157
  105. package/dist/msgmerge-all/msgmerge-all.js.map +0 -1
  106. package/dist/parser/__snapshots__/javascript.spec.js.snap +0 -56
  107. package/dist/parser/__snapshots__/po.spec.js.snap +0 -176
  108. package/dist/pot/__snapshots__/catalog.spec.js.snap +0 -591
  109. package/dist/xgettext/__snapshots__/xgettext.spec.js.snap +0 -462
  110. package/dist/xgettext/file-resolver.js +0 -23
  111. package/dist/xgettext/file-resolver.js.map +0 -1
  112. package/dist/xgettext/file-resolver.spec.js +0 -22
  113. package/dist/xgettext/file-resolver.spec.js.map +0 -1
  114. package/dist/xgettext/files-collector.js +0 -41
  115. package/dist/xgettext/files-collector.js.map +0 -1
  116. package/dist/xgettext/files-collector.spec.js.map +0 -1
  117. package/dist/xgettext/xgettext.d.ts +0 -16
  118. package/dist/xgettext/xgettext.js +0 -335
  119. package/dist/xgettext/xgettext.js.map +0 -1
  120. package/dist/xgettext/xgettext.spec.js +0 -743
  121. package/dist/xgettext/xgettext.spec.js.map +0 -1
  122. /package/dist/{xgettext → commands/xgettext}/file-resolver.spec.d.ts +0 -0
  123. /package/dist/{xgettext → commands/xgettext}/files-collector.d.ts +0 -0
  124. /package/dist/{xgettext → commands/xgettext}/files-collector.spec.d.ts +0 -0
  125. /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
- var catalog_1 = require("../pot/catalog");
4
- var keyword_1 = require("../pot/keyword");
5
- var javascript_1 = require("./javascript");
6
- var warnSpy = jest.spyOn(global.console, 'warn').mockImplementation(function () {
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
- var errorSpy = jest.spyOn(global.console, 'error').mockImplementation(function () {
8
+ const errorSpy = jest.spyOn(global.console, 'error').mockImplementation(() => {
9
9
  });
10
- describe('JavaScript parser', function () {
11
- describe('strings', function () {
12
- afterEach(function () {
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', function () {
17
- var catalog = new catalog_1.Catalog();
18
- var p = new javascript_1.JavaScriptParser(catalog, { extractAll: true });
19
- var code = "\n// Directive.\n_(\"double-quoted string\");\n\n// Function call.\n_('single-quoted string');\n\n// perl-brace-format.\n_x('Hello, {name}!');\n";
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', function () {
26
- var catalog = new catalog_1.Catalog();
27
- var p = new javascript_1.JavaScriptParser(catalog, { extractAll: true });
28
- var code = '"concatenated" + " str" + "i" + "n" + "g";';
29
- var buf = Buffer.from(code);
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
- var expected = "#: example.js:1\nmsgid \"concatenated string\"\nmsgstr \"\"\n";
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', function () {
37
- var catalog = new catalog_1.Catalog();
38
- var p = new javascript_1.JavaScriptParser(catalog, { extractAll: true });
39
- var code = 'prefix + "concatenated" + " string";';
40
- var buf = Buffer.from(code);
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', function () {
47
- var catalog = new catalog_1.Catalog();
48
- var p = new javascript_1.JavaScriptParser(catalog, { extractAll: true });
49
- var code = '"concatenated" + sep + "string";';
50
- var buf = Buffer.from(code);
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', function () {
57
- var catalog = new catalog_1.Catalog();
58
- var p = new javascript_1.JavaScriptParser(catalog, { extractAll: true });
59
- var code = '"concatenated" + " string" + suffix;';
60
- var buf = Buffer.from(code);
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', function () {
68
- afterEach(function () {
79
+ describe('comments', () => {
80
+ afterEach(() => {
69
81
  warnSpy.mockClear();
70
82
  errorSpy.mockClear();
71
83
  });
72
- it('should extract all kinds of comments', function () {
73
- var catalog = new catalog_1.Catalog();
74
- var p = new javascript_1.JavaScriptParser(catalog, {
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
- var code = "\n// Single-line comment.\n_('single line');\n\n/* Block comment. */\n_('block');\n\n// Single-line\n/* and block combined. */\n_('single + block');\n\n/* Block */\n// and single-line combined.\n_('block + single');\n\n// Skip this.\n\n// But catch this.\n_('only immediately preceding');\n\n// Only for one string.\n_('catcher'); _('loser');\n\n// And this is ignored, too.\n";
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', function () {
86
- afterEach(function () {
121
+ describe('messages', () => {
122
+ afterEach(() => {
87
123
  warnSpy.mockClear();
88
124
  errorSpy.mockClear();
89
125
  });
90
- it('should extract a single argument', function () {
91
- var catalog = new catalog_1.Catalog();
92
- var p = new javascript_1.JavaScriptParser(catalog, {
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
- var code = '_("Hello, world!")';
131
+ const code = '_("Hello, world!")';
96
132
  expect(p.parse(Buffer.from(code), 'example.js')).toBeTruthy();
97
- var expected = "#: example.js:1\nmsgid \"Hello, world!\"\nmsgstr \"\"\n";
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', function () {
103
- var catalog = new catalog_1.Catalog();
104
- var p = new javascript_1.JavaScriptParser(catalog, {
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
- var code = '_n("There was an error!", "There were errors!", n)';
146
+ const code = '_n("There was an error!", "There were errors!", n)';
108
147
  expect(p.parse(Buffer.from(code), 'example.js')).toBeTruthy();
109
- var expected = "#: example.js:1\nmsgid \"There was an error!\"\nmsgid_plural \"There were errors!\"\nmsgstr[0] \"\"\nmsgstr[1] \"\"\n";
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', function () {
115
- var catalog = new catalog_1.Catalog();
116
- var p = new javascript_1.JavaScriptParser(catalog, {
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
- var code = '_np("context", "There was an error!", "There were errors!", n)';
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
- var expected = "#: example.js:1\nmsgctxt \"context\"\nmsgid \"There was an error!\"\nmsgid_plural \"There were errors!\"\nmsgstr[0] \"\"\nmsgstr[1] \"\"\n";
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', function () {
127
- var catalog = new catalog_1.Catalog();
128
- var p = new javascript_1.JavaScriptParser(catalog, {
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
- var code = '"string".trim()';
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', function () {
138
- var catalog = new catalog_1.Catalog();
139
- var p = new javascript_1.JavaScriptParser(catalog, {
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
- var code = 'gettext("string")';
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', function () {
149
- var catalog = new catalog_1.Catalog();
150
- var p = new javascript_1.JavaScriptParser(catalog, {
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
- var code = '_("Hello", "world")';
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', function () {
160
- var catalog = new catalog_1.Catalog();
161
- var p = new javascript_1.JavaScriptParser(catalog, {
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
- var code = '_()';
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', function () {
171
- var catalog = new catalog_1.Catalog();
172
- var p = new javascript_1.JavaScriptParser(catalog, {
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
- var code = '_n("One universe")';
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', function () {
182
- var catalog = new catalog_1.Catalog();
183
- var p = new javascript_1.JavaScriptParser(catalog, {
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
- var code = '_pn("one world", "many worlds")';
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', function () {
193
- var catalog = new catalog_1.Catalog();
194
- var p = new javascript_1.JavaScriptParser(catalog, {
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
- var code = '_np("world", earth, "many earths")';
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', function () {
204
- var catalog = new catalog_1.Catalog();
205
- var p = new javascript_1.JavaScriptParser(catalog, {
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
- var code = '_np("world", `one earth`, "many earths")';
258
+ const code = '_np("world", `one earth`, "many earths")';
209
259
  expect(p.parse(Buffer.from(code), 'example.js')).toBeTruthy();
210
- var expected = "#: example.js:1\nmsgctxt \"world\"\nmsgid \"one earth\"\nmsgid_plural \"many earths\"\nmsgstr[0] \"\"\nmsgstr[1] \"\"\n";
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', function () {
216
- var catalog = new catalog_1.Catalog();
217
- var p = new javascript_1.JavaScriptParser(catalog, {
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
- var code = '_np("world", `one ${planet}`, "many earths")';
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: error: template literals with embedded' +
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', function () {
230
- var catalog = new catalog_1.Catalog();
231
- var p = new javascript_1.JavaScriptParser(catalog, {
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
- var code = '_np("world", "earth", earths)';
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', function () {
241
- var catalog = new catalog_1.Catalog();
242
- var p = new javascript_1.JavaScriptParser(catalog, {
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
- var code = '_np("world", "one earth", `many earths`)';
301
+ const code = '_np("world", "one earth", `many earths`)';
246
302
  expect(p.parse(Buffer.from(code), 'example.js')).toBeTruthy();
247
- var expected = "#: example.js:1\nmsgctxt \"world\"\nmsgid \"one earth\"\nmsgid_plural \"many earths\"\nmsgstr[0] \"\"\nmsgstr[1] \"\"\n";
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', function () {
253
- var catalog = new catalog_1.Catalog();
254
- var p = new javascript_1.JavaScriptParser(catalog, {
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
- var code = '_np("world", "one earth", `many ${planets}`)';
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: error: template literals with embedded' +
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', function () {
267
- var catalog = new catalog_1.Catalog();
268
- var p = new javascript_1.JavaScriptParser(catalog, {
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
- var code = '_np(world, "earth", "many earths")';
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', function () {
278
- var catalog = new catalog_1.Catalog();
279
- var p = new javascript_1.JavaScriptParser(catalog, {
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
- var code = '_np(`world`, "one earth", "many earths")';
344
+ const code = '_np(`world`, "one earth", "many earths")';
283
345
  expect(p.parse(Buffer.from(code), 'example.js')).toBeTruthy();
284
- var expected = "#: example.js:1\nmsgctxt \"world\"\nmsgid \"one earth\"\nmsgid_plural \"many earths\"\nmsgstr[0] \"\"\nmsgstr[1] \"\"\n";
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', function () {
290
- var catalog = new catalog_1.Catalog();
291
- var p = new javascript_1.JavaScriptParser(catalog, {
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
- var code = '_np("world", "one earth", `many ${planets}`)';
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: error: template literals with embedded' +
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', function () {
305
- afterEach(function () {
372
+ describe('encoding', () => {
373
+ afterEach(() => {
306
374
  warnSpy.mockClear();
307
375
  errorSpy.mockClear();
308
376
  });
309
- it('should decode to JavaScript strings', function () {
310
- var catalog = new catalog_1.Catalog();
311
- var p = new javascript_1.JavaScriptParser(catalog, {
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
- var code = '_("Hello, world!")';
382
+ const code = '_("Hello, world!")';
315
383
  expect(p.parse(Buffer.from(code), 'example.js')).toBeTruthy();
316
- var expected = "#: example.js:1\nmsgid \"Hello, world!\"\nmsgstr \"\"\n";
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', function () {
323
- afterEach(function () {
393
+ describe('binary expressions', () => {
394
+ afterEach(() => {
324
395
  warnSpy.mockClear();
325
396
  errorSpy.mockClear();
326
397
  });
327
- it('should extract concatenated strings', function () {
328
- var catalog = new catalog_1.Catalog();
329
- var p = new javascript_1.JavaScriptParser(catalog, {
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
- var code = '_("It\'s a " + "sad" + " and beautiful world!")';
403
+ const code = '_("It\'s a " + "sad" + " and beautiful world!")';
333
404
  expect(p.parse(Buffer.from(code), 'example.js')).toBeTruthy();
334
- var expected = "#: example.js:1\nmsgid \"It's a sad and beautiful world!\"\nmsgstr \"\"\n";
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', function () {
340
- var catalog = new catalog_1.Catalog();
341
- var p = new javascript_1.JavaScriptParser(catalog, {
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
- var code = '_("It\'s a " + `sad` + " and beautiful world!")';
418
+ const code = '_("It\'s a " + `sad` + " and beautiful world!")';
345
419
  expect(p.parse(Buffer.from(code), 'example.js')).toBeTruthy();
346
- var expected = "#: example.js:1\nmsgid \"It's a sad and beautiful world!\"\nmsgstr \"\"\n";
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', function () {
352
- var catalog = new catalog_1.Catalog();
353
- var p = new javascript_1.JavaScriptParser(catalog, {
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
- var code = '_("It\'s a " + what + " and beautiful world!")';
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', function () {
363
- var catalog = new catalog_1.Catalog();
364
- var p = new javascript_1.JavaScriptParser(catalog, {
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
- var code = '_("It\'s " + `a ${what}` + " and beautiful world!")';
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: error:' +
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', function () {
378
- afterEach(function () {
454
+ describe('comments above calls', () => {
455
+ afterEach(() => {
379
456
  warnSpy.mockClear();
380
457
  errorSpy.mockClear();
381
458
  });
382
- it('should extract xgettext: comments', function () {
383
- var catalog = new catalog_1.Catalog();
384
- var p = new javascript_1.JavaScriptParser(catalog, {
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
- var code = "// xgettext: no-perl-brace-format\n_(\"It's a {sad} and beautiful world!\")\n";
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
- var expected = "#: example.js:2\n#, no-perl-brace-format\nmsgid \"It's a {sad} and beautiful world!\"\nmsgstr \"\"\n";
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', function () {
395
- var catalog = new catalog_1.Catalog();
396
- var p = new javascript_1.JavaScriptParser(catalog, {
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
- var code = "// xgettext: down-by-law\n_(\"It's a sad and beautiful world!\")\n";
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
- var expected = "#: example.js:2\nmsgid \"It's a sad and beautiful world!\"\nmsgstr \"\"\n";
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', function () {
407
- var catalog = new catalog_1.Catalog();
408
- var p = new javascript_1.JavaScriptParser(catalog, {
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
- var code = "// TRANSLATORS: Down by Law\n_(\"It's a sad and beautiful world!\")\n";
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
- var expected = "#. TRANSLATORS: Down by Law\n#: example.js:2\nmsgid \"It's a sad and beautiful world!\"\nmsgstr \"\"\n";
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', function () {
421
- var catalog = new catalog_1.Catalog();
422
- var p = new javascript_1.JavaScriptParser(catalog, {
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
- var code = "// TERMINATORS: Down by Law\n_(\"It's a sad and beautiful world!\")\n";
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
- var expected = "#: example.js:2\nmsgid \"It's a sad and beautiful world!\"\nmsgstr \"\"\n";
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();