@tutao/licc 3.106.4 → 3.107.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.
@@ -3,7 +3,7 @@ export class Accumulator {
3
3
  appender;
4
4
  code = "";
5
5
  imports = new Set();
6
- constructor(appender = (code) => this.code += code) {
6
+ constructor(appender = (code) => (this.code += code)) {
7
7
  this.appender = appender;
8
8
  }
9
9
  line(code = "") {
@@ -17,9 +17,7 @@ export class Accumulator {
17
17
  const lineJoiner = opts?.suffix ?? "";
18
18
  const trailingJoiner = opts?.trailing ?? false;
19
19
  lines.forEach((line, idx) => {
20
- const joiner = trailingJoiner || idx < lines.length - 1
21
- ? lineJoiner
22
- : "";
20
+ const joiner = trailingJoiner || idx < lines.length - 1 ? lineJoiner : "";
23
21
  this.line(line + joiner);
24
22
  });
25
23
  return this;
@@ -1,4 +1,4 @@
1
- import { getArgs, minusculize } from "./common.js";
1
+ import { getArgs, minusculize, } from "./common.js";
2
2
  import { Accumulator } from "./Accumulator.js";
3
3
  import { parseType } from "./Parser.js";
4
4
  export class KotlinGenerator {
@@ -170,7 +170,7 @@ export class KotlinGenerator {
170
170
  }
171
171
  generateExtraFiles() {
172
172
  return {
173
- "NativeInterface": KotlinGenerator.generateNativeInterface()
173
+ NativeInterface: KotlinGenerator.generateNativeInterface(),
174
174
  };
175
175
  }
176
176
  generateTypeRef(outDir, definitionPath, definition) {
@@ -186,9 +186,9 @@ export class KotlinGenerator {
186
186
  }
187
187
  generateEnum({ name, values, doc }) {
188
188
  return new Accumulator()
189
- .do(acc => this.generateDocComment(acc, doc))
189
+ .do((acc) => this.generateDocComment(acc, doc))
190
190
  .line(`enum class ${name} {`)
191
- .indented(acc => acc.lines(values.map(value => `${value},`)))
191
+ .indented((acc) => acc.lines(values.map((value) => `${value},`)))
192
192
  .line("}")
193
193
  .finish();
194
194
  }
@@ -204,14 +204,14 @@ function renderKotlinType(parsed) {
204
204
  const renderedListInner = renderKotlinType(parsed.generics[0]);
205
205
  return {
206
206
  externals: renderedListInner.externals,
207
- name: maybeNullable(`List<${renderedListInner.name}>`, nullable)
207
+ name: maybeNullable(`List<${renderedListInner.name}>`, nullable),
208
208
  };
209
209
  case "Map":
210
210
  const renderedKey = renderKotlinType(parsed.generics[0]);
211
211
  const renderedValue = renderKotlinType(parsed.generics[1]);
212
212
  return {
213
213
  externals: [...renderedKey.externals, ...renderedValue.externals],
214
- name: maybeNullable(`Map<${renderedKey.name}, ${renderedValue.name}>`, nullable)
214
+ name: maybeNullable(`Map<${renderedKey.name}, ${renderedValue.name}>`, nullable),
215
215
  };
216
216
  case "string":
217
217
  return { externals: [], name: maybeNullable("String", nullable) };
package/dist/Parser.js CHANGED
@@ -1,19 +1,146 @@
1
1
  export const PRIMITIVES = ["string", "boolean", "number", "bytes", "void"];
2
2
  const KOTLIN_KEYWORDS = [
3
- "as", "break", "class", "continue", "do", "else", "false", "for", "fun", "if", "in", "interface", "is", "null", "object", "package", "return", "super",
4
- "this", "throw", "true", "try", "typealias", "typeof", "val", "var", "when", "while"
3
+ "as",
4
+ "break",
5
+ "class",
6
+ "continue",
7
+ "do",
8
+ "else",
9
+ "false",
10
+ "for",
11
+ "fun",
12
+ "if",
13
+ "in",
14
+ "interface",
15
+ "is",
16
+ "null",
17
+ "object",
18
+ "package",
19
+ "return",
20
+ "super",
21
+ "this",
22
+ "throw",
23
+ "true",
24
+ "try",
25
+ "typealias",
26
+ "typeof",
27
+ "val",
28
+ "var",
29
+ "when",
30
+ "while",
5
31
  ];
6
32
  const TYPESCRIPT_KEYWORDS = [
7
- "var", "const", "let", "break", "return", "case", "catch", "class", "continue", "debugger", "default", "delete", "do", "else", "enum", "export", "extends",
8
- "false", "finally", "for", "function", "if", "import", "in", "instanceOf", "new", "null", "return", "super", "switch", "this", "throw", "true", "try",
9
- "typeOf", "void", "while", "with"
33
+ "var",
34
+ "const",
35
+ "let",
36
+ "break",
37
+ "return",
38
+ "case",
39
+ "catch",
40
+ "class",
41
+ "continue",
42
+ "debugger",
43
+ "default",
44
+ "delete",
45
+ "do",
46
+ "else",
47
+ "enum",
48
+ "export",
49
+ "extends",
50
+ "false",
51
+ "finally",
52
+ "for",
53
+ "function",
54
+ "if",
55
+ "import",
56
+ "in",
57
+ "instanceOf",
58
+ "new",
59
+ "null",
60
+ "return",
61
+ "super",
62
+ "switch",
63
+ "this",
64
+ "throw",
65
+ "true",
66
+ "try",
67
+ "typeOf",
68
+ "void",
69
+ "while",
70
+ "with",
10
71
  ];
11
72
  const SWIFT_KEYWORDS = [
12
- "Class", "deinit", "Enum", "extension", "Func", "import", "Init", "internal", "Let", "operator", "private", "protocol", "public", "static", "struct", "subscript",
13
- "typealias", "var", "break", "case", "continue", "default", "do", "else", "fallthrough", "for", "if", "in", "return", "switch", "where", "while",
14
- "as", "dynamicType", "false", "is", "nil", "self", "Self", "super", "true", "_COLUMN_", "_FILE_", "_FUNCTION_", "_LINE_",
15
- "associativity", "convenience", "dynamic", "didSet", "final", "get", "infix", "inout", "lazy", "left", "mutating", "none", "nonmutating",
16
- "optional", "override", "postfix", "precedence", "prefix", "Protocol", "required", "right", "set", "Type", "unowned", "weak", "willSet"
73
+ "Class",
74
+ "deinit",
75
+ "Enum",
76
+ "extension",
77
+ "Func",
78
+ "import",
79
+ "Init",
80
+ "internal",
81
+ "Let",
82
+ "operator",
83
+ "private",
84
+ "protocol",
85
+ "public",
86
+ "static",
87
+ "struct",
88
+ "subscript",
89
+ "typealias",
90
+ "var",
91
+ "break",
92
+ "case",
93
+ "continue",
94
+ "default",
95
+ "do",
96
+ "else",
97
+ "fallthrough",
98
+ "for",
99
+ "if",
100
+ "in",
101
+ "return",
102
+ "switch",
103
+ "where",
104
+ "while",
105
+ "as",
106
+ "dynamicType",
107
+ "false",
108
+ "is",
109
+ "nil",
110
+ "self",
111
+ "Self",
112
+ "super",
113
+ "true",
114
+ "_COLUMN_",
115
+ "_FILE_",
116
+ "_FUNCTION_",
117
+ "_LINE_",
118
+ "associativity",
119
+ "convenience",
120
+ "dynamic",
121
+ "didSet",
122
+ "final",
123
+ "get",
124
+ "infix",
125
+ "inout",
126
+ "lazy",
127
+ "left",
128
+ "mutating",
129
+ "none",
130
+ "nonmutating",
131
+ "optional",
132
+ "override",
133
+ "postfix",
134
+ "precedence",
135
+ "prefix",
136
+ "Protocol",
137
+ "required",
138
+ "right",
139
+ "set",
140
+ "Type",
141
+ "unowned",
142
+ "weak",
143
+ "willSet",
17
144
  ];
18
145
  const FORBIDDEN_IDENTIFIERS = new Set([...KOTLIN_KEYWORDS, ...TYPESCRIPT_KEYWORDS, ...SWIFT_KEYWORDS]);
19
146
  /**
@@ -1,4 +1,4 @@
1
- import { getArgs, minusculize } from "./common.js";
1
+ import { getArgs, minusculize, } from "./common.js";
2
2
  import { Accumulator } from "./Accumulator.js";
3
3
  import { parseType } from "./Parser.js";
4
4
  export class SwiftGenerator {
@@ -42,8 +42,7 @@ export class SwiftGenerator {
42
42
  const lastArg = args[args.length - 1];
43
43
  for (const argument of args) {
44
44
  const renderedArgument = typeNameSwift(argument.type);
45
- const argLine = `_ ${argument.name}: ${renderedArgument.name}` +
46
- ((argument === lastArg) ? "" : ",");
45
+ const argLine = `_ ${argument.name}: ${renderedArgument.name}` + (argument === lastArg ? "" : ",");
47
46
  argGenerator.line(argLine);
48
47
  }
49
48
  const renderedReturn = typeNameSwift(methodDefinition.ret);
@@ -104,29 +103,25 @@ export class SwiftGenerator {
104
103
  generateGlobalDispatcher(name, facadeNames) {
105
104
  return new Accumulator()
106
105
  .line(`public class ${name} {`)
107
- .indented(acc => acc
108
- .lines(facadeNames.map(facadeName => `private let ${minusculize(facadeName)}: ${facadeName}ReceiveDispatcher`))
106
+ .indented((acc) => acc
107
+ .lines(facadeNames.map((facadeName) => `private let ${minusculize(facadeName)}: ${facadeName}ReceiveDispatcher`))
109
108
  .line()
110
109
  .line(`init(`)
111
- .indented(acc => acc
112
- .lines(facadeNames.map(name => `${minusculize(name)} : ${name}`), { suffix: ",", trailing: false }))
110
+ .indented((acc) => acc.lines(facadeNames.map((name) => `${minusculize(name)} : ${name}`), { suffix: ",", trailing: false }))
113
111
  .line(`) {`)
114
- .indented(acc => acc
115
- .lines(facadeNames.map(name => `self.${minusculize(name)} = ${name}ReceiveDispatcher(facade: ${minusculize(name)})`)))
112
+ .indented((acc) => acc.lines(facadeNames.map((name) => `self.${minusculize(name)} = ${name}ReceiveDispatcher(facade: ${minusculize(name)})`)))
116
113
  .line(`}`)
117
114
  .line()
118
115
  .line(`func dispatch(facadeName: String, methodName: String, args: Array<String>) async throws -> String {`)
119
- .indented(acc => acc
116
+ .indented((acc) => acc
120
117
  .line(`switch facadeName {`)
121
- .indented(acc => {
118
+ .indented((acc) => {
122
119
  for (let facadeName of facadeNames) {
123
120
  acc.line(`case "${facadeName}":`)
124
121
  .indent()
125
122
  .line(`return try await self.${minusculize(facadeName)}.dispatch(method: methodName, arg: args)`);
126
123
  }
127
- acc.line(`default:`)
128
- .indent()
129
- .line(`fatalError("licc messed up! " + facadeName)`);
124
+ acc.line(`default:`).indent().line(`fatalError("licc messed up! " + facadeName)`);
130
125
  })
131
126
  .line(`}`))
132
127
  .line(`}`))
@@ -174,7 +169,7 @@ export class SwiftGenerator {
174
169
  }
175
170
  generateExtraFiles() {
176
171
  return {
177
- "NativeInterface": SwiftGenerator.generateNativeInterface()
172
+ NativeInterface: SwiftGenerator.generateNativeInterface(),
178
173
  };
179
174
  }
180
175
  static generateNativeInterface() {
@@ -194,9 +189,9 @@ export class SwiftGenerator {
194
189
  }
195
190
  generateEnum({ name, values, doc }) {
196
191
  return new Accumulator()
197
- .do(acc => this.generateDocComment(acc, doc))
192
+ .do((acc) => this.generateDocComment(acc, doc))
198
193
  .line(`public enum ${name}: Int {`)
199
- .indented(acc => acc.lines(values.map((value, index) => `case ${value} = ${index}`)))
194
+ .indented((acc) => acc.lines(values.map((value, index) => `case ${value} = ${index}`)))
200
195
  .line("}")
201
196
  .finish();
202
197
  }
@@ -216,7 +211,7 @@ function renderSwiftType(parsed) {
216
211
  const renderedValue = renderSwiftType(parsed.generics[1]);
217
212
  return {
218
213
  externals: [...renderedKey.externals, ...renderedValue.externals],
219
- name: maybeNullable(`[${renderedKey.name} : ${renderedValue.name}]`, nullable)
214
+ name: maybeNullable(`[${renderedKey.name} : ${renderedValue.name}]`, nullable),
220
215
  };
221
216
  case "string":
222
217
  return { externals: [], name: maybeNullable("String", nullable) };
@@ -146,17 +146,15 @@ export class TypescriptGenerator {
146
146
  const acc = new Accumulator();
147
147
  let tsPath = definition.location.typescript;
148
148
  const isRelative = tsPath.startsWith(".");
149
- const actualPath = (isRelative)
150
- ? path.relative(path.resolve(outDir), path.resolve(definitionPath, tsPath))
151
- : tsPath;
149
+ const actualPath = isRelative ? path.relative(path.resolve(outDir), path.resolve(definitionPath, tsPath)) : tsPath;
152
150
  acc.line(`export {${definition.name}} from "${actualPath}"`);
153
151
  return acc.finish();
154
152
  }
155
153
  generateEnum({ name, values, doc }) {
156
154
  return new Accumulator()
157
- .do(acc => this.generateDocComment(acc, doc))
155
+ .do((acc) => this.generateDocComment(acc, doc))
158
156
  .line(`export const enum ${name} {`)
159
- .indented(acc => acc.lines(values.map((value, index) => `${value} = ${index},`)))
157
+ .indented((acc) => acc.lines(values.map((value, index) => `${value} = ${index},`)))
160
158
  .line("}")
161
159
  .finish();
162
160
  }
@@ -168,14 +166,14 @@ function renderTypescriptType(parsed) {
168
166
  const renderedListInner = renderTypescriptType(parsed.generics[0]);
169
167
  return {
170
168
  externals: renderedListInner.externals,
171
- name: maybeNullable(`ReadonlyArray<${renderedListInner.name}>`, nullable)
169
+ name: maybeNullable(`ReadonlyArray<${renderedListInner.name}>`, nullable),
172
170
  };
173
171
  case "Map":
174
172
  const renderedKey = renderTypescriptType(parsed.generics[0]);
175
173
  const renderedValue = renderTypescriptType(parsed.generics[1]);
176
174
  return {
177
175
  externals: [...renderedKey.externals, ...renderedValue.externals],
178
- name: maybeNullable(`Record<${renderedKey.name}, ${renderedValue.name}>`, nullable)
176
+ name: maybeNullable(`Record<${renderedKey.name}, ${renderedValue.name}>`, nullable),
179
177
  };
180
178
  case "string":
181
179
  return { externals: [], name: maybeNullable("string", nullable) };
package/dist/common.js CHANGED
@@ -7,12 +7,12 @@ export function getArgs(methName, methodDef) {
7
7
  else if (entries.length > 1) {
8
8
  throw new Error(`Syntax Error: method ${methName} argument ${i} has too many entries`);
9
9
  }
10
- return { "name": entries[0][0], "type": entries[0][1] };
10
+ return { name: entries[0][0], type: entries[0][1] };
11
11
  });
12
12
  }
13
13
  export function capitalize(input) {
14
- return input.replace(/^\w/, c => c.toUpperCase());
14
+ return input.replace(/^\w/, (c) => c.toUpperCase());
15
15
  }
16
16
  export function minusculize(input) {
17
- return input.replace(/^\w/, c => c.toLowerCase());
17
+ return input.replace(/^\w/, (c) => c.toLowerCase());
18
18
  }