@tolgee/cli 2.1.0 → 2.1.2

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.
@@ -19,6 +19,8 @@ export const generalMapper = (token) => {
19
19
  case 'string.quoted.single.ts':
20
20
  case 'string.quoted.double.ts':
21
21
  return 'string.body';
22
+ case 'constant.character.escape.ts':
23
+ return 'escaped.character';
22
24
  // template strings
23
25
  case 'punctuation.definition.string.template.begin.ts':
24
26
  return 'string.teplate.begin';
@@ -7,20 +7,23 @@ function shouldBeIgnored(context, line) {
7
7
  }
8
8
  return isIgnore;
9
9
  }
10
- function keyInfoFromComment(context, line) {
10
+ function commentKeyInfoOnLine(context, line) {
11
11
  const commentAtLine = context.commentMap.get(line - 1);
12
12
  const isKeyInfo = commentAtLine?.type === 'MAGIC_COMMENT' && commentAtLine.kind === 'key';
13
13
  if (isKeyInfo) {
14
14
  context.unusedComments.delete(commentAtLine);
15
- return {
16
- keyName: commentAtLine.keyName,
17
- namespace: commentAtLine.namespace,
18
- defaultValue: commentAtLine.defaultValue,
19
- line: commentAtLine.line,
20
- };
15
+ return keyInfoFromComment(context, commentAtLine);
21
16
  }
22
17
  return undefined;
23
18
  }
19
+ function keyInfoFromComment(context, info) {
20
+ return {
21
+ keyName: info.keyName,
22
+ namespace: info.namespace ?? context.options.defaultNamespace,
23
+ defaultValue: info.defaultValue,
24
+ line: info.line,
25
+ };
26
+ }
24
27
  function reportKey(context, node, contextNs) {
25
28
  const { strictNamespace, defaultNamespace } = context.options;
26
29
  const { keys, warnings } = context;
@@ -28,7 +31,7 @@ function reportKey(context, node, contextNs) {
28
31
  if (shouldBeIgnored(context, line)) {
29
32
  return { keys, warnings };
30
33
  }
31
- const overrideInfo = keyInfoFromComment(context, node.line);
34
+ const overrideInfo = commentKeyInfoOnLine(context, node.line);
32
35
  if (overrideInfo) {
33
36
  // key info is overriten by comment
34
37
  keys.push(overrideInfo);
@@ -146,12 +149,7 @@ export function generateReport({ node, contextNs, comments, options, }) {
146
149
  context.warnings.push({ line: value.line, warning: value.kind });
147
150
  }
148
151
  else if (value.type === 'MAGIC_COMMENT' && value.kind === 'key') {
149
- context.keys.push({
150
- keyName: value.keyName,
151
- namespace: value.namespace,
152
- defaultValue: value.defaultValue,
153
- line: value.line,
154
- });
152
+ context.keys.push(keyInfoFromComment(context, value));
155
153
  }
156
154
  else if (value.type === 'MAGIC_COMMENT' && value.kind === 'ignore') {
157
155
  context.warnings.push({ line: value.line, warning: 'W_UNUSED_IGNORE' });
@@ -1,3 +1,4 @@
1
+ import unescape from 'unescape-js';
1
2
  export const stringMerger = {
2
3
  initial: 0 /* S.Idle */,
3
4
  step: (state, token, end) => {
@@ -8,43 +9,47 @@ export const stringMerger = {
8
9
  return 1 /* S.RegularString */;
9
10
  }
10
11
  else if (type === 'string.teplate.begin') {
11
- return 3 /* S.TemplateString */;
12
+ return 2 /* S.TemplateString */;
12
13
  }
13
14
  break;
14
15
  case 1 /* S.RegularString */:
15
16
  if (type === 'string.body') {
16
- return 2 /* S.RegularStringEnd */;
17
+ return 1 /* S.RegularString */;
17
18
  }
18
- else if (type === 'string.end') {
19
- return end.MERGE_ALL;
19
+ else if (type === 'escaped.character') {
20
+ return 1 /* S.RegularString */;
20
21
  }
21
- break;
22
- case 2 /* S.RegularStringEnd */:
23
- if (type === 'string.end') {
22
+ else if (type === 'string.end') {
24
23
  return end.MERGE_ALL;
25
24
  }
26
25
  break;
27
- case 3 /* S.TemplateString */:
26
+ case 2 /* S.TemplateString */:
28
27
  if (type === 'string.template.body') {
29
- return 4 /* S.TemplateStringEnd */;
28
+ return 2 /* S.TemplateString */;
29
+ }
30
+ else if (type === 'escaped.character') {
31
+ return 2 /* S.TemplateString */;
30
32
  }
31
33
  else if (type === 'string.template.end') {
32
34
  return end.MERGE_ALL;
33
35
  }
34
36
  break;
35
- case 4 /* S.TemplateStringEnd */:
36
- if (type === 'string.template.end') {
37
- return end.MERGE_ALL;
38
- }
39
37
  }
40
38
  },
41
39
  customType: 'string',
42
40
  resultToken: (matched) => {
43
- if (matched.length === 3) {
44
- return matched[1].token;
45
- }
46
- else {
47
- return '';
48
- }
41
+ const escaped = matched
42
+ .map((t) => {
43
+ switch (t.customType) {
44
+ case 'string.template.body':
45
+ case 'string.body':
46
+ case 'escaped.character':
47
+ return t.token;
48
+ default:
49
+ return '';
50
+ }
51
+ })
52
+ .join('');
53
+ return unescape(escaped);
49
54
  },
50
55
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tolgee/cli",
3
- "version": "2.1.0",
3
+ "version": "2.1.2",
4
4
  "type": "module",
5
5
  "description": "A tool to interact with the Tolgee Platform through CLI",
6
6
  "repository": {
@@ -37,6 +37,7 @@
37
37
  "json5": "^2.2.3",
38
38
  "jsonschema": "^1.4.1",
39
39
  "openapi-fetch": "^0.9.7",
40
+ "unescape-js": "^1.1.4",
40
41
  "vscode-oniguruma": "^1.7.0",
41
42
  "vscode-textmate": "^9.0.0",
42
43
  "yauzl": "^2.10.0"