You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(model-api-gen): indentation in generated TypeScript files
The generator uses string templates to generate the TypeScript code.
It's hard to get the indentation right with them.
There is now a post-processing step that searches for curly brackets to
determine the correct indentation level.
Also, all the empty lines are removed, because it was inconsistent where
they were inserted.
val typedPropertyText =if (feature.type isPrimitivePropertyType) {
113
130
when ((feature.type asPrimitivePropertyType).primitive) {
114
131
Primitive.INT-> {
@@ -121,7 +138,7 @@ class TypescriptMMGenerator(val outputDir: Path, val nameConfig: NameConfig = Na
121
138
return str ? parseInt(str) : 0;
122
139
}
123
140
124
-
""".trimIndent()
141
+
"""
125
142
}
126
143
Primitive.BOOLEAN-> {
127
144
"""
@@ -132,25 +149,26 @@ class TypescriptMMGenerator(val outputDir: Path, val nameConfig: NameConfig = Na
132
149
return this.$rawValueName === "true";
133
150
}
134
151
135
-
""".trimIndent()
152
+
"""
136
153
}
137
-
Primitive.STRING->"""
154
+
Primitive.STRING->
155
+
"""
138
156
public set ${feature.generatedName}(value: string) {
139
157
this.$rawValueName = value;
140
158
}
141
159
public get ${feature.generatedName}(): string {
142
160
return this.$rawValueName ?? "";
143
161
}
144
162
145
-
""".trimIndent()
163
+
"""
146
164
}
147
165
} else {
148
166
""
149
167
}
150
168
"""
151
169
$rawPropertyText
152
170
$typedPropertyText
153
-
""".trimIndent()
171
+
"""
154
172
}
155
173
isProcessedReferenceLink-> {
156
174
val typeRef = feature.type.resolved
@@ -164,15 +182,15 @@ class TypescriptMMGenerator(val outputDir: Path, val nameConfig: NameConfig = Na
164
182
let target = this._node.getReferenceTargetNode("${feature.originalName}");
165
183
return target ? LanguageRegistry.INSTANCE.wrapNode(target) as $entityType : undefined;
166
184
}
167
-
""".trimIndent()
185
+
"""
168
186
}
169
187
isProcessedChildLink-> {
170
188
val accessorClassName =if (feature.multiple) "ChildListAccessor"else"SingleChildAccessor"
171
189
val typeRef = feature.type.resolved
172
190
val languagePrefix = typeRef.languagePrefix(concept.language)
173
191
"""
174
192
public ${feature.generatedName}: $accessorClassName<$languagePrefix${typeRef.nodeWrapperInterfaceName()}> = new $accessorClassName(this._node, "${feature.originalName}")
175
-
""".trimIndent()
193
+
"""
176
194
}
177
195
else->""
178
196
}
@@ -182,26 +200,26 @@ class TypescriptMMGenerator(val outputDir: Path, val nameConfig: NameConfig = Na
182
200
isProcessedProperty-> {
183
201
val rawPropertyText ="""
184
202
${feature.rawValueName()}: string | undefined
185
-
""".trimIndent()
203
+
"""
186
204
val typedPropertyText =if (feature.type isPrimitivePropertyType) {
187
205
when ((feature.type asPrimitivePropertyType).primitive) {
188
206
Primitive.BOOLEAN-> {
189
207
"""
190
208
${feature.generatedName}: boolean
191
209
192
-
""".trimIndent()
210
+
"""
193
211
}
194
212
Primitive.INT-> {
195
213
"""
196
214
${feature.generatedName}: number
197
215
198
-
""".trimIndent()
216
+
"""
199
217
}
200
218
Primitive.STRING-> {
201
219
"""
202
220
${feature.generatedName}: string
203
221
204
-
""".trimIndent()
222
+
"""
205
223
}
206
224
}
207
225
} else {
@@ -210,7 +228,7 @@ class TypescriptMMGenerator(val outputDir: Path, val nameConfig: NameConfig = Na
210
228
"""
211
229
$rawPropertyText
212
230
$typedPropertyText
213
-
""".trimIndent()
231
+
"""
214
232
}
215
233
isProcessedReferenceLink-> {
216
234
val typeRef = feature.type.resolved
@@ -219,13 +237,13 @@ class TypescriptMMGenerator(val outputDir: Path, val nameConfig: NameConfig = Na
219
237
"""
220
238
set ${feature.generatedName}(value: $entityType | undefined);
221
239
get ${feature.generatedName}(): $entityType | undefined;
222
-
""".trimIndent()
240
+
"""
223
241
}
224
242
isProcessedChildLink-> {
225
243
val accessorClassName =if (feature.multiple) "ChildListAccessor"else"SingleChildAccessor"
0 commit comments