@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,226 +1,394 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- var catalog_1 = require("../pot/catalog");
4
- var po_1 = require("./po");
5
- var date = '2020-04-23 08:50+0300';
6
- var warnSpy = jest.spyOn(global.console, 'warn').mockImplementation(function () {
3
+ const catalog_1 = require("../pot/catalog");
4
+ const po_1 = require("./po");
5
+ const date = '2020-04-23 08:50+0300';
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('parse po files', function () {
11
- describe('simple file', function () {
12
- afterEach(function () {
10
+ describe('parse po files', () => {
11
+ describe('simple file', () => {
12
+ afterEach(() => {
13
13
  warnSpy.mockClear();
14
14
  errorSpy.mockClear();
15
15
  });
16
- it('should parse', function () {
17
- var pot = "# Translations for smell-o-vision.\n# Copyright (C) 2020 SmellOVision Inc.\n# This file is distributed under the same license as the smell-o-vision package.\n# John Doe <john.doe@example.com>, 2020.\n#\nmsgid \"\"\nmsgstr \"\"\n\"Project-Id-Version: smell-o-vision 0.1.1\\n\"\n\"Report-Msgid-Bugs-To: jane.appleseed@example.com\\n\"\n\"POT-Creation-Date: 2020-04-23 08:50+0300\\n\"\n\"PO-Revision-Date: 2020-04-25 23:04+0300\\n\"\n\"Last-Translator: John Doe <John.Doe@example.com>\\n\"\n\"Language-Team: Finnish <fi@li.org>\\n\"\n\"Language: Finnish\\n\"\n\"MIME-Version: 1.0\\n\"\n\"Content-Type: text/plain; charset=utf-8\\n\"\n\"Content-Transfer-Encoding: 8bit\\n\"\n\nmsgid \"no comment\"\nmsgstr \"\"\n\n#, perl-brace-format, no-perl-format\nmsgid \"Hello, {name}!\"\nmsgstr \"\"\n\n#: src/example.ts:2304 src/other.ts:1303\nmsgid \"strawberry\"\nmsgstr \"\"\n\nmsgid \"One universe\"\nmsgid_plural \"Parallel universes\"\nmsgstr[0] \"\"\nmsgstr[1] \"\"\n\nmsgctxt \"escapes\"\nmsgid \"\\\\\\a\\b\\t\\n\\v\\f\\r\\\"\"\nmsgstr \"\"\n\nmsgid \"\"\n\"Multi-line msgid\"\nmsgstr \"\"\n\nmsgctxt \"\"\n\"multi-line\"\nmsgid \"Hello, world!\\n\"\nmsgstr \"\"\n\nmsgid \"One world\"\nmsgid_plural \"\"\n\"Many worlds\"\nmsgstr[0] \"\"\nmsgstr[1] \"\"\n\nmsgid \"The translation has to be discarded.\"\nmsgstr \"Die \u00DCbersetzung muss verworfen werden.\"\n\nmsgid \"And this one, too.\"\nmsgid_plural \"And these ones, too.\"\nmsgstr[0] \"For a very long time ...\"\nmsgstr[1] \"For a very long time ...\"\nmsgstr[2] \"For a very long time ...\"\nmsgstr[3] \"For a very long time ...\"\nmsgstr[4] \"For a very long time ...\"\nmsgstr[5] \"For a very long time ...\"\nmsgstr[6] \"For a very long time ...\"\nmsgstr[7] \"For a very long time ...\"\n\n#. TRANSLATORS: This is the day of the week, not our star.\n#. It is the abbreviation for Sunday.\nmsgid \"Sun\"\nmsgstr \"\"\n\n#~ msgid \"obsolete entry\"\n#~ msgstr \"\"\n";
18
- var catalog = new catalog_1.Catalog({ date: date });
19
- var parser = new po_1.PoParser(catalog);
20
- var input = Buffer.from(pot);
16
+ it('should parse', () => {
17
+ const pot = `# Translations for smell-o-vision.
18
+ # Copyright (C) 2020 SmellOVision Inc.
19
+ # This file is distributed under the same license as the smell-o-vision package.
20
+ # John Doe <john.doe@example.com>, 2020.
21
+ #
22
+ msgid ""
23
+ msgstr ""
24
+ "Project-Id-Version: smell-o-vision 0.1.1\\n"
25
+ "Report-Msgid-Bugs-To: jane.appleseed@example.com\\n"
26
+ "POT-Creation-Date: 2020-04-23 08:50+0300\\n"
27
+ "PO-Revision-Date: 2020-04-25 23:04+0300\\n"
28
+ "Last-Translator: John Doe <John.Doe@example.com>\\n"
29
+ "Language-Team: Finnish <fi@li.org>\\n"
30
+ "Language: Finnish\\n"
31
+ "MIME-Version: 1.0\\n"
32
+ "Content-Type: text/plain; charset=utf-8\\n"
33
+ "Content-Transfer-Encoding: 8bit\\n"
34
+
35
+ msgid "no comment"
36
+ msgstr ""
37
+
38
+ #, perl-brace-format, no-perl-format
39
+ msgid "Hello, {name}!"
40
+ msgstr ""
41
+
42
+ #: src/example.ts:2304 src/other.ts:1303
43
+ msgid "strawberry"
44
+ msgstr ""
45
+
46
+ msgid "One universe"
47
+ msgid_plural "Parallel universes"
48
+ msgstr[0] ""
49
+ msgstr[1] ""
50
+
51
+ msgctxt "escapes"
52
+ msgid "\\\\\\a\\b\\t\\n\\v\\f\\r\\""
53
+ msgstr ""
54
+
55
+ msgid ""
56
+ "Multi-line msgid"
57
+ msgstr ""
58
+
59
+ msgctxt ""
60
+ "multi-line"
61
+ msgid "Hello, world!\\n"
62
+ msgstr ""
63
+
64
+ msgid "One world"
65
+ msgid_plural ""
66
+ "Many worlds"
67
+ msgstr[0] ""
68
+ msgstr[1] ""
69
+
70
+ msgid "The translation has to be discarded."
71
+ msgstr "Die Übersetzung muss verworfen werden."
72
+
73
+ msgid "And this one, too."
74
+ msgid_plural "And these ones, too."
75
+ msgstr[0] "For a very long time ..."
76
+ msgstr[1] "For a very long time ..."
77
+ msgstr[2] "For a very long time ..."
78
+ msgstr[3] "For a very long time ..."
79
+ msgstr[4] "For a very long time ..."
80
+ msgstr[5] "For a very long time ..."
81
+ msgstr[6] "For a very long time ..."
82
+ msgstr[7] "For a very long time ..."
83
+
84
+ #. TRANSLATORS: This is the day of the week, not our star.
85
+ #. It is the abbreviation for Sunday.
86
+ msgid "Sun"
87
+ msgstr ""
88
+
89
+ #~ msgid "obsolete entry"
90
+ #~ msgstr ""
91
+ `;
92
+ const catalog = new catalog_1.Catalog({ date });
93
+ const parser = new po_1.PoParser(catalog);
94
+ const input = Buffer.from(pot);
21
95
  parser.parse(input, 'example.js');
22
96
  expect(catalog.toString()).toMatchSnapshot();
23
97
  expect(warnSpy).not.toHaveBeenCalled();
24
98
  expect(errorSpy).not.toHaveBeenCalled();
25
99
  });
26
100
  });
27
- describe('errors', function () {
28
- afterEach(function () {
101
+ describe('errors', () => {
102
+ afterEach(() => {
29
103
  warnSpy.mockClear();
30
104
  errorSpy.mockClear();
31
105
  });
32
- it('should discard lone strings', function () {
33
- var catalog = new catalog_1.Catalog({ date: date });
34
- var parser = new po_1.PoParser(catalog);
35
- var pot = "msgid \"okay\"\nmsgstr \"\"\n\n\"does not belong here\"\n";
36
- var input = Buffer.from(pot);
106
+ it('should discard lone strings', () => {
107
+ const catalog = new catalog_1.Catalog({ date });
108
+ const parser = new po_1.PoParser(catalog);
109
+ const pot = `msgid "okay"
110
+ msgstr ""
111
+
112
+ "does not belong here"
113
+ `;
114
+ const input = Buffer.from(pot);
37
115
  expect(parser.parse(input, 'example.ts')).toBeFalsy();
38
116
  expect(errorSpy).toHaveBeenCalledTimes(1);
39
- expect(errorSpy).toHaveBeenCalledWith('example.ts:4:1: error: syntax error');
117
+ expect(errorSpy).toHaveBeenCalledWith('example.ts:4:1: Error: syntax error');
40
118
  expect(warnSpy).not.toHaveBeenCalled();
41
119
  });
42
- it('should discard lone strings reading from standard input', function () {
43
- var catalog = new catalog_1.Catalog({ date: date });
44
- var parser = new po_1.PoParser(catalog);
45
- var pot = "msgid \"okay\"\nmsgstr \"\"\n\n\"does not belong here\"\n";
46
- var input = Buffer.from(pot);
120
+ it('should discard lone strings reading from standard input', () => {
121
+ const catalog = new catalog_1.Catalog({ date });
122
+ const parser = new po_1.PoParser(catalog);
123
+ const pot = `msgid "okay"
124
+ msgstr ""
125
+
126
+ "does not belong here"
127
+ `;
128
+ const input = Buffer.from(pot);
47
129
  expect(parser.parse(input, '-')).toBeFalsy();
48
130
  expect(errorSpy).toHaveBeenCalledTimes(1);
49
- expect(errorSpy).toHaveBeenCalledWith('[standard input]:4:1: error: syntax error');
131
+ expect(errorSpy).toHaveBeenCalledWith('[standard input]:4:1: Error: syntax error');
50
132
  expect(warnSpy).not.toHaveBeenCalled();
51
133
  });
52
- it('should bail out on unexpected input', function () {
53
- var catalog = new catalog_1.Catalog({ date: date });
54
- var parser = new po_1.PoParser(catalog);
55
- var pot = "msgid \"okay\"\nmsgstr \"\"\n\nMSGID \"uppercase not allowed\"\nmsgstr \"\"\n";
56
- var input = Buffer.from(pot);
134
+ it('should bail out on unexpected input', () => {
135
+ const catalog = new catalog_1.Catalog({ date });
136
+ const parser = new po_1.PoParser(catalog);
137
+ let pot = `msgid "okay"
138
+ msgstr ""
139
+
140
+ MSGID "uppercase not allowed"
141
+ msgstr ""
142
+ `;
143
+ let input = Buffer.from(pot);
57
144
  expect(parser.parse(input, 'example.ts')).toBeFalsy();
58
145
  expect(errorSpy).toHaveBeenCalledTimes(2);
59
- expect(errorSpy).toHaveBeenNthCalledWith(1, 'example.ts:4:1: error: keyword "MSGID" unknown');
60
- expect(errorSpy).toHaveBeenNthCalledWith(2, 'example.ts:4:6: error: syntax error');
146
+ expect(errorSpy).toHaveBeenNthCalledWith(1, 'example.ts:4:1: Error: keyword "MSGID" unknown');
147
+ expect(errorSpy).toHaveBeenNthCalledWith(2, 'example.ts:4:6: Error: syntax error');
61
148
  expect(warnSpy).not.toHaveBeenCalled();
62
- pot = "msgid \"okay\"\nmsgstr \"\"\n\nnsgid \"no, no, no\"\nmsgstr \"\"\n";
149
+ pot = `msgid "okay"
150
+ msgstr ""
151
+
152
+ nsgid "no, no, no"
153
+ msgstr ""
154
+ `;
63
155
  input = Buffer.from(pot);
64
156
  expect(parser.parse(input, 'example.ts')).toBeFalsy();
65
157
  expect(errorSpy).toHaveBeenCalledTimes(4);
66
- expect(errorSpy).toHaveBeenNthCalledWith(3, 'example.ts:4:1: error: keyword "nsgid" unknown');
67
- expect(errorSpy).toHaveBeenNthCalledWith(4, 'example.ts:4:6: error: syntax error');
158
+ expect(errorSpy).toHaveBeenNthCalledWith(3, 'example.ts:4:1: Error: keyword "nsgid" unknown');
159
+ expect(errorSpy).toHaveBeenNthCalledWith(4, 'example.ts:4:6: Error: syntax error');
68
160
  expect(warnSpy).not.toHaveBeenCalled();
69
161
  });
70
- it('should bail out on garbage', function () {
71
- var catalog = new catalog_1.Catalog({ date: date });
72
- var parser = new po_1.PoParser(catalog);
73
- var pot = "msgid \"okay\"\nmsgstr \"\"\n\n'garbage'\n";
74
- var input = Buffer.from(pot);
162
+ it('should bail out on garbage', () => {
163
+ const catalog = new catalog_1.Catalog({ date });
164
+ const parser = new po_1.PoParser(catalog);
165
+ const pot = `msgid "okay"
166
+ msgstr ""
167
+
168
+ 'garbage'
169
+ `;
170
+ const input = Buffer.from(pot);
75
171
  expect(parser.parse(input, 'example.ts')).toBeFalsy();
76
172
  expect(errorSpy).toHaveBeenCalledTimes(1);
77
- expect(errorSpy).toHaveBeenNthCalledWith(1, 'example.ts:4:1: error: syntax error');
173
+ expect(errorSpy).toHaveBeenNthCalledWith(1, 'example.ts:4:1: Error: syntax error');
78
174
  expect(warnSpy).not.toHaveBeenCalled();
79
175
  });
80
- it('should bail out on entries w/o msgid', function () {
81
- var catalog = new catalog_1.Catalog({ date: date });
82
- var parser = new po_1.PoParser(catalog);
83
- var pot = "msgid \"okay\"\nmsgstr \"\"\n\n# Missing msgid.\nmsgstr \"\"\n";
84
- var input = Buffer.from(pot);
176
+ it('should bail out on entries w/o msgid', () => {
177
+ const catalog = new catalog_1.Catalog({ date });
178
+ const parser = new po_1.PoParser(catalog);
179
+ const pot = `msgid "okay"
180
+ msgstr ""
181
+
182
+ # Missing msgid.
183
+ msgstr ""
184
+ `;
185
+ const input = Buffer.from(pot);
85
186
  expect(parser.parse(input, 'example.ts')).toBeFalsy();
86
187
  expect(errorSpy).toHaveBeenCalledTimes(1);
87
- expect(errorSpy).toHaveBeenNthCalledWith(1, 'example.ts:6:1: error: missing "msgid" section');
188
+ expect(errorSpy).toHaveBeenNthCalledWith(1, 'example.ts:6:1: Error: missing "msgid" section');
88
189
  expect(warnSpy).not.toHaveBeenCalled();
89
190
  });
90
- it('should bail out on duplicate entries', function () {
91
- var catalog = new catalog_1.Catalog({ date: date });
92
- var parser = new po_1.PoParser(catalog);
93
- var pot = "msgid \"okay\"\nmsgstr \"\"\n\nmsgid \"okay\"\nmsgstr \"\"\n";
94
- var input = Buffer.from(pot);
191
+ it('should bail out on duplicate entries', () => {
192
+ const catalog = new catalog_1.Catalog({ date });
193
+ const parser = new po_1.PoParser(catalog);
194
+ const pot = `msgid "okay"
195
+ msgstr ""
196
+
197
+ msgid "okay"
198
+ msgstr ""
199
+ `;
200
+ const input = Buffer.from(pot);
95
201
  expect(parser.parse(input, 'example.ts')).toBeFalsy();
96
202
  expect(errorSpy).toHaveBeenCalledTimes(2);
97
- expect(errorSpy).toHaveBeenNthCalledWith(1, 'example.ts:4:1: error: duplicate message definition...');
98
- expect(errorSpy).toHaveBeenNthCalledWith(2, 'example.ts:1:1: error: ...this is the location of the first definition');
203
+ expect(errorSpy).toHaveBeenNthCalledWith(1, 'example.ts:4:1: Error: duplicate message definition...');
204
+ expect(errorSpy).toHaveBeenNthCalledWith(2, 'example.ts:1:1: Error: ...this is the location of the first definition');
99
205
  expect(warnSpy).not.toHaveBeenCalled();
100
206
  });
101
- it('should bail out on duplicate msgid sections', function () {
102
- var catalog = new catalog_1.Catalog({ date: date });
103
- var parser = new po_1.PoParser(catalog);
104
- var pot = "msgid \"okay\"\nmsgstr \"\"\n\nmsgid \"not\"\nmsgstr \"\"\nmsgid \"okay\"\n";
105
- var input = Buffer.from(pot);
207
+ it('should bail out on duplicate msgid sections', () => {
208
+ const catalog = new catalog_1.Catalog({ date });
209
+ const parser = new po_1.PoParser(catalog);
210
+ const pot = `msgid "okay"
211
+ msgstr ""
212
+
213
+ msgid "not"
214
+ msgstr ""
215
+ msgid "okay"
216
+ `;
217
+ const input = Buffer.from(pot);
106
218
  expect(parser.parse(input, 'example.ts')).toBeFalsy();
107
219
  expect(errorSpy).toHaveBeenCalledTimes(1);
108
- expect(errorSpy).toHaveBeenNthCalledWith(1, 'example.ts:6:1: error: duplicate "msgid" section');
220
+ expect(errorSpy).toHaveBeenNthCalledWith(1, 'example.ts:6:1: Error: duplicate "msgid" section');
109
221
  expect(warnSpy).not.toHaveBeenCalled();
110
222
  });
111
- it('should bail out on duplicate msgstr sections', function () {
112
- var catalog = new catalog_1.Catalog({ date: date });
113
- var parser = new po_1.PoParser(catalog);
114
- var pot = "msgid \"okay\"\nmsgstr \"\"\n\nmsgid \"not\"\nmsgstr \"\"\nmsgstr \"okay\"\n";
115
- var input = Buffer.from(pot);
223
+ it('should bail out on duplicate msgstr sections', () => {
224
+ const catalog = new catalog_1.Catalog({ date });
225
+ const parser = new po_1.PoParser(catalog);
226
+ const pot = `msgid "okay"
227
+ msgstr ""
228
+
229
+ msgid "not"
230
+ msgstr ""
231
+ msgstr "okay"
232
+ `;
233
+ const input = Buffer.from(pot);
116
234
  expect(parser.parse(input, 'example.ts')).toBeFalsy();
117
235
  expect(errorSpy).toHaveBeenCalledTimes(1);
118
- expect(errorSpy).toHaveBeenNthCalledWith(1, 'example.ts:6:1: error: duplicate "msgstr" section');
236
+ expect(errorSpy).toHaveBeenNthCalledWith(1, 'example.ts:6:1: Error: duplicate "msgstr" section');
119
237
  expect(warnSpy).not.toHaveBeenCalled();
120
238
  });
121
- it('should bail out on duplicate msgid_plural sections', function () {
122
- var catalog = new catalog_1.Catalog({ date: date });
123
- var parser = new po_1.PoParser(catalog);
124
- var pot = "msgid \"okay\"\nmsgstr \"\"\n\nmsgid \"not\"\nmsgid_plural \"really\"\nmsgid_plural \"really\"\nmsgstr[0] \"\"\nmsgstr[1] \"\"\n";
125
- var input = Buffer.from(pot);
239
+ it('should bail out on duplicate msgid_plural sections', () => {
240
+ const catalog = new catalog_1.Catalog({ date });
241
+ const parser = new po_1.PoParser(catalog);
242
+ const pot = `msgid "okay"
243
+ msgstr ""
244
+
245
+ msgid "not"
246
+ msgid_plural "really"
247
+ msgid_plural "really"
248
+ msgstr[0] ""
249
+ msgstr[1] ""
250
+ `;
251
+ const input = Buffer.from(pot);
126
252
  expect(parser.parse(input, 'example.ts')).toBeFalsy();
127
253
  expect(errorSpy).toHaveBeenCalledTimes(1);
128
- expect(errorSpy).toHaveBeenNthCalledWith(1, 'example.ts:6:1: error: duplicate "msgid_plural" section');
254
+ expect(errorSpy).toHaveBeenNthCalledWith(1, 'example.ts:6:1: Error: duplicate "msgid_plural" section');
129
255
  expect(warnSpy).not.toHaveBeenCalled();
130
256
  });
131
- it('should bail out on duplicate msgctxt sections', function () {
132
- var catalog = new catalog_1.Catalog({ date: date });
133
- var parser = new po_1.PoParser(catalog);
134
- var pot = "msgid \"okay\"\nmsgstr \"\"\n\nmsgctxt \"Menu\"\nmsgctxt \"File\"\nmsgid \"Hello, world!\"\nmsgstr \"\"\n";
135
- var input = Buffer.from(pot);
257
+ it('should bail out on duplicate msgctxt sections', () => {
258
+ const catalog = new catalog_1.Catalog({ date });
259
+ const parser = new po_1.PoParser(catalog);
260
+ const pot = `msgid "okay"
261
+ msgstr ""
262
+
263
+ msgctxt "Menu"
264
+ msgctxt "File"
265
+ msgid "Hello, world!"
266
+ msgstr ""
267
+ `;
268
+ const input = Buffer.from(pot);
136
269
  expect(parser.parse(input, 'example.ts')).toBeFalsy();
137
270
  expect(errorSpy).toHaveBeenCalledTimes(1);
138
- expect(errorSpy).toHaveBeenNthCalledWith(1, 'example.ts:5:1: error: duplicate "msgctxt" section');
271
+ expect(errorSpy).toHaveBeenNthCalledWith(1, 'example.ts:5:1: Error: duplicate "msgctxt" section');
139
272
  expect(warnSpy).not.toHaveBeenCalled();
140
273
  });
141
- it('should enforce consistent use of #~', function () {
142
- var catalog = new catalog_1.Catalog({ date: date });
143
- var parser = new po_1.PoParser(catalog);
144
- var pot = "msgid \"okay\"\nmsgstr \"\"\n\nmsgid \"not\"\n#~ msgstr \"okay\"\nmsgstr \"okay\"\n";
145
- var input = Buffer.from(pot);
274
+ it('should enforce consistent use of #~', () => {
275
+ const catalog = new catalog_1.Catalog({ date });
276
+ const parser = new po_1.PoParser(catalog);
277
+ const pot = `msgid "okay"
278
+ msgstr ""
279
+
280
+ msgid "not"
281
+ #~ msgstr "okay"
282
+ msgstr "okay"
283
+ `;
284
+ const input = Buffer.from(pot);
146
285
  expect(parser.parse(input, 'example.ts')).toBeFalsy();
147
286
  expect(errorSpy).toHaveBeenCalledTimes(1);
148
- expect(errorSpy).toHaveBeenNthCalledWith(1, 'example.ts:5:1: error: inconsistent use of #~');
287
+ expect(errorSpy).toHaveBeenNthCalledWith(1, 'example.ts:5:1: Error: inconsistent use of #~');
149
288
  expect(warnSpy).not.toHaveBeenCalled();
150
289
  });
151
- it('should bail out on non-strings for msgids', function () {
152
- var catalog = new catalog_1.Catalog({ date: date });
153
- var parser = new po_1.PoParser(catalog);
154
- var pot = "msgid \"okay\"\nmsgstr \"\"\n\nmsgid not\nmsgstr \"okay\"\n";
155
- var input = Buffer.from(pot);
290
+ it('should bail out on non-strings for msgids', () => {
291
+ const catalog = new catalog_1.Catalog({ date });
292
+ const parser = new po_1.PoParser(catalog);
293
+ const pot = `msgid "okay"
294
+ msgstr ""
295
+
296
+ msgid not
297
+ msgstr "okay"
298
+ `;
299
+ const input = Buffer.from(pot);
156
300
  expect(parser.parse(input, 'example.ts')).toBeFalsy();
157
301
  expect(errorSpy).toHaveBeenCalledTimes(1);
158
- expect(errorSpy).toHaveBeenNthCalledWith(1, 'example.ts:4:14: error: syntax error');
302
+ expect(errorSpy).toHaveBeenNthCalledWith(1, 'example.ts:4:14: Error: syntax error');
159
303
  expect(warnSpy).not.toHaveBeenCalled();
160
304
  });
161
- it('should bail out on unterminated strings', function () {
162
- var catalog = new catalog_1.Catalog({ date: date });
163
- var parser = new po_1.PoParser(catalog);
164
- var pot = "msgid \"okay\"\nmsgstr \"\"\n\nmsgid \"not\nmsgstr \"okay\"\n";
165
- var input = Buffer.from(pot);
305
+ it('should bail out on unterminated strings', () => {
306
+ const catalog = new catalog_1.Catalog({ date });
307
+ const parser = new po_1.PoParser(catalog);
308
+ const pot = `msgid "okay"
309
+ msgstr ""
310
+
311
+ msgid "not
312
+ msgstr "okay"
313
+ `;
314
+ const input = Buffer.from(pot);
166
315
  expect(parser.parse(input, 'example.ts')).toBeFalsy();
167
316
  expect(errorSpy).toHaveBeenCalledTimes(1);
168
- expect(errorSpy).toHaveBeenNthCalledWith(1, 'example.ts:4:11: error: end-of-line within string');
317
+ expect(errorSpy).toHaveBeenNthCalledWith(1, 'example.ts:4:11: Error: end-of-line within string');
169
318
  expect(warnSpy).not.toHaveBeenCalled();
170
319
  });
171
- it('should bail out on trailing backslashes', function () {
172
- var catalog = new catalog_1.Catalog({ date: date });
173
- var parser = new po_1.PoParser(catalog);
174
- var pot = "msgid \"okay\"\nmsgstr \"\"\n\nmsgid \"not\\\"\nmsgstr \"okay\"\n";
175
- var input = Buffer.from(pot);
320
+ it('should bail out on trailing backslashes', () => {
321
+ const catalog = new catalog_1.Catalog({ date });
322
+ const parser = new po_1.PoParser(catalog);
323
+ const pot = `msgid "okay"
324
+ msgstr ""
325
+
326
+ msgid "not\\"
327
+ msgstr "okay"
328
+ `;
329
+ const input = Buffer.from(pot);
176
330
  expect(parser.parse(input, 'example.ts')).toBeFalsy();
177
331
  expect(errorSpy).toHaveBeenCalledTimes(1);
178
- expect(errorSpy).toHaveBeenNthCalledWith(1, 'example.ts:4:7: error: end-of-line within string');
332
+ expect(errorSpy).toHaveBeenNthCalledWith(1, 'example.ts:4:7: Error: end-of-line within string');
179
333
  expect(warnSpy).not.toHaveBeenCalled();
180
334
  });
181
- it('should bail out on invalid control sequences', function () {
182
- var catalog = new catalog_1.Catalog({ date: date });
183
- var parser = new po_1.PoParser(catalog);
184
- var pot = "msgid \"okay\"\nmsgstr \"\"\n\nmsgid \"beware of \\x-rays\"\nmsgstr \"\"\n";
185
- var input = Buffer.from(pot);
335
+ it('should bail out on invalid control sequences', () => {
336
+ const catalog = new catalog_1.Catalog({ date });
337
+ const parser = new po_1.PoParser(catalog);
338
+ const pot = `msgid "okay"
339
+ msgstr ""
340
+
341
+ msgid "beware of \\x-rays"
342
+ msgstr ""
343
+ `;
344
+ const input = Buffer.from(pot);
186
345
  expect(parser.parse(input, 'example.ts')).toBeFalsy();
187
346
  expect(errorSpy).toHaveBeenCalledTimes(1);
188
- expect(errorSpy).toHaveBeenNthCalledWith(1, 'example.ts:4:18: error: invalid control sequence');
347
+ expect(errorSpy).toHaveBeenNthCalledWith(1, 'example.ts:4:18: Error: invalid control sequence');
189
348
  expect(warnSpy).not.toHaveBeenCalled();
190
349
  });
191
350
  });
192
- describe('warnings', function () {
193
- afterEach(function () {
351
+ describe('warnings', () => {
352
+ afterEach(() => {
194
353
  warnSpy.mockClear();
195
354
  errorSpy.mockClear();
196
355
  });
197
- it('should warn about empty flags', function () {
198
- var catalog = new catalog_1.Catalog({ date: date });
199
- var parser = new po_1.PoParser(catalog);
200
- var pot = "#, fuzzy ,, perl-brace-format\nmsgid \"Hello, {name}!\"\nmsgstr \"\"\n";
201
- var input = Buffer.from(pot);
356
+ it('should warn about empty flags', () => {
357
+ const catalog = new catalog_1.Catalog({ date });
358
+ const parser = new po_1.PoParser(catalog);
359
+ const pot = `#, fuzzy ,, perl-brace-format
360
+ msgid "Hello, {name}!"
361
+ msgstr ""
362
+ `;
363
+ const input = Buffer.from(pot);
202
364
  parser.parse(input, 'example.js');
203
365
  expect(catalog.toString()).toMatchSnapshot();
204
366
  expect(warnSpy).toHaveBeenCalledTimes(1);
205
367
  expect(warnSpy).toHaveBeenNthCalledWith(1, 'example.js:1:11: warning: ignoring empty flag');
206
368
  expect(errorSpy).not.toHaveBeenCalled();
207
369
  });
208
- it('should warn about empty flags reading from standard input', function () {
209
- var catalog = new catalog_1.Catalog({ date: date });
210
- var parser = new po_1.PoParser(catalog);
211
- var pot = "#, fuzzy ,, perl-brace-format\nmsgid \"Hello, {name}!\"\nmsgstr \"\"\n";
212
- var input = Buffer.from(pot);
370
+ it('should warn about empty flags reading from standard input', () => {
371
+ const catalog = new catalog_1.Catalog({ date });
372
+ const parser = new po_1.PoParser(catalog);
373
+ const pot = `#, fuzzy ,, perl-brace-format
374
+ msgid "Hello, {name}!"
375
+ msgstr ""
376
+ `;
377
+ const input = Buffer.from(pot);
213
378
  parser.parse(input, '-');
214
379
  expect(catalog.toString()).toMatchSnapshot();
215
380
  expect(warnSpy).toHaveBeenCalledTimes(1);
216
381
  expect(warnSpy).toHaveBeenNthCalledWith(1, '[standard input]:1:11: warning: ignoring empty flag');
217
382
  expect(errorSpy).not.toHaveBeenCalled();
218
383
  });
219
- it('should warn about invalid references', function () {
220
- var catalog = new catalog_1.Catalog({ date: date });
221
- var parser = new po_1.PoParser(catalog);
222
- var pot = "#: src/here.js:2304 somewhere\nmsgid \"Hello, {name}!\"\nmsgstr \"\"\n";
223
- var input = Buffer.from(pot);
384
+ it('should warn about invalid references', () => {
385
+ const catalog = new catalog_1.Catalog({ date });
386
+ const parser = new po_1.PoParser(catalog);
387
+ const pot = `#: src/here.js:2304 somewhere
388
+ msgid "Hello, {name}!"
389
+ msgstr ""
390
+ `;
391
+ const input = Buffer.from(pot);
224
392
  parser.parse(input, 'example.js');
225
393
  expect(catalog.toString()).toMatchSnapshot();
226
394
  expect(warnSpy).toHaveBeenCalledTimes(1);
@@ -228,63 +396,85 @@ describe('parse po files', function () {
228
396
  expect(errorSpy).not.toHaveBeenCalled();
229
397
  });
230
398
  });
231
- describe('encoding', function () {
232
- afterEach(function () {
399
+ describe('encoding', () => {
400
+ afterEach(() => {
233
401
  warnSpy.mockClear();
234
402
  errorSpy.mockClear();
235
403
  });
236
- it('should accept cp1252', function () {
237
- var catalog = new catalog_1.Catalog({ date: date });
238
- var parser = new po_1.PoParser(catalog);
239
- var pot = "msgid \"\"\nmsgstr \"\"\n\"Project-Id-Version: PACKAGE VERSION\\n\"\n\"Content-Type: text/plain; charset=CP1252\\n\"\n";
240
- var input = Buffer.from(pot);
404
+ it('should accept cp1252', () => {
405
+ const catalog = new catalog_1.Catalog({ date });
406
+ const parser = new po_1.PoParser(catalog);
407
+ const pot = `msgid ""
408
+ msgstr ""
409
+ "Project-Id-Version: PACKAGE VERSION\\n"
410
+ "Content-Type: text/plain; charset=CP1252\\n"
411
+ `;
412
+ const input = Buffer.from(pot);
241
413
  parser.parse(input, 'example.ts');
242
414
  expect(catalog.toString()).toMatchSnapshot();
243
415
  expect(errorSpy).not.toHaveBeenCalled();
244
416
  expect(warnSpy).not.toHaveBeenCalled();
245
417
  });
246
- it('should throw on unsupported encodings', function () {
247
- var catalog = new catalog_1.Catalog({ date: date });
248
- var parser = new po_1.PoParser(catalog);
249
- var pot = "msgid \"\"\nmsgstr \"\"\n\"Project-Id-Version: PACKAGE VERSION\\n\"\n\"Content-Type: text/plain; charset=CP1252\\n\"\n";
250
- var input = Buffer.from(pot);
418
+ it('should throw on unsupported encodings', () => {
419
+ const catalog = new catalog_1.Catalog({ date });
420
+ const parser = new po_1.PoParser(catalog);
421
+ const pot = `msgid ""
422
+ msgstr ""
423
+ "Project-Id-Version: PACKAGE VERSION\\n"
424
+ "Content-Type: text/plain; charset=CP1252\\n"
425
+ `;
426
+ const input = Buffer.from(pot);
251
427
  expect(parser.parse(input, 'example.ts', 'invalid')).toBeFalsy();
252
428
  expect(errorSpy).toHaveBeenCalledTimes(1);
253
429
  expect(errorSpy).toHaveBeenNthCalledWith(1, 'unsupported encoding "invalid"');
254
430
  expect(warnSpy).not.toHaveBeenCalled();
255
431
  });
256
- it('should re-parse a lone header', function () {
257
- var catalog = new catalog_1.Catalog({ date: date });
258
- var parser = new po_1.PoParser(catalog);
259
- var pot = "msgid \"\"\nmsgstr \"\"\n\"Project-Id-Version: PACKAGE VERSION\\n\"\n\"Content-Type: text/plain; charset=iso-8859-1\\n\"";
260
- var input = Buffer.from(pot);
432
+ it('should re-parse a lone header', () => {
433
+ const catalog = new catalog_1.Catalog({ date });
434
+ const parser = new po_1.PoParser(catalog);
435
+ const pot = `msgid ""
436
+ msgstr ""
437
+ "Project-Id-Version: PACKAGE VERSION\\n"
438
+ "Content-Type: text/plain; charset=iso-8859-1\\n"`;
439
+ const input = Buffer.from(pot);
261
440
  parser.parse(input, 'example.ts');
262
441
  expect(errorSpy).not.toHaveBeenCalled();
263
442
  expect(warnSpy).not.toHaveBeenCalled();
264
443
  });
265
- it('should not reparse w/o content-type header', function () {
266
- var catalog = new catalog_1.Catalog({ date: date });
267
- var parser = new po_1.PoParser(catalog);
268
- var pot = "msgid \"\"\nmsgstr \"\"\n\"Project-Id-Version: PACKAGE VERSION\\n\"\n\"Content-Transfer-Encoding: 8bit\\n\"";
269
- var input = Buffer.from(pot);
444
+ it('should not reparse w/o content-type header', () => {
445
+ const catalog = new catalog_1.Catalog({ date });
446
+ const parser = new po_1.PoParser(catalog);
447
+ const pot = `msgid ""
448
+ msgstr ""
449
+ "Project-Id-Version: PACKAGE VERSION\\n"
450
+ "Content-Transfer-Encoding: 8bit\\n"`;
451
+ const input = Buffer.from(pot);
270
452
  parser.parse(input, 'example.ts');
271
453
  expect(errorSpy).not.toHaveBeenCalled();
272
454
  expect(warnSpy).not.toHaveBeenCalled();
273
455
  });
274
- it('should not reparse w/o charset', function () {
275
- var catalog = new catalog_1.Catalog({ date: date });
276
- var parser = new po_1.PoParser(catalog);
277
- var pot = "msgid \"\"\nmsgstr \"\"\n\"Project-Id-Version: PACKAGE VERSION\\n\"\n\"Content-Type: text/plain\\n\"\n\"Content-Transfer-Encoding: 8bit\\n\"";
278
- var input = Buffer.from(pot);
456
+ it('should not reparse w/o charset', () => {
457
+ const catalog = new catalog_1.Catalog({ date });
458
+ const parser = new po_1.PoParser(catalog);
459
+ const pot = `msgid ""
460
+ msgstr ""
461
+ "Project-Id-Version: PACKAGE VERSION\\n"
462
+ "Content-Type: text/plain\\n"
463
+ "Content-Transfer-Encoding: 8bit\\n"`;
464
+ const input = Buffer.from(pot);
279
465
  parser.parse(input, 'example.ts');
280
466
  expect(errorSpy).not.toHaveBeenCalled();
281
467
  expect(warnSpy).not.toHaveBeenCalled();
282
468
  });
283
- it('should not reparse for unknown encoding', function () {
284
- var catalog = new catalog_1.Catalog({ date: date });
285
- var parser = new po_1.PoParser(catalog);
286
- var pot = "msgid \"\"\nmsgstr \"\"\n\"Project-Id-Version: PACKAGE VERSION\\n\"\n\"Content-Type: text/plain; charset=invalid\\n\"\n\"Content-Transfer-Encoding: 8bit\\n\"";
287
- var input = Buffer.from(pot);
469
+ it('should not reparse for unknown encoding', () => {
470
+ const catalog = new catalog_1.Catalog({ date });
471
+ const parser = new po_1.PoParser(catalog);
472
+ const pot = `msgid ""
473
+ msgstr ""
474
+ "Project-Id-Version: PACKAGE VERSION\\n"
475
+ "Content-Type: text/plain; charset=invalid\\n"
476
+ "Content-Transfer-Encoding: 8bit\\n"`;
477
+ const input = Buffer.from(pot);
288
478
  parser.parse(input, 'example.ts');
289
479
  expect(warnSpy).toHaveBeenCalledTimes(2);
290
480
  expect(warnSpy).toHaveBeenNthCalledWith(1, 'example.ts:5:1: warning: the charset "invalid" is not a portable encoding name.');