Skip to content

Commit 09533b0

Browse files
committed
fix: format js code
1 parent c775990 commit 09533b0

File tree

4 files changed

+124
-124
lines changed

4 files changed

+124
-124
lines changed

lib/objc/DNObjectiveCContext.js

Lines changed: 61 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -76,19 +76,19 @@ class DNBlockDefContext extends DNContext {
7676
this.returnType = ''
7777
this.defName = null
7878
this.args = []
79-
}
79+
}
8080

8181
parse() {
8282
var argList = ''
8383
this.args.forEach((element, index) => {
84-
if(index == this.args.length - 1){
84+
if (index == this.args.length - 1) {
8585
argList += element.type + ' ' + element.name
86-
}else{
86+
} else {
8787
argList += element.type + ' ' + element.name + ', '
8888
}
8989
})
9090
var result = 'typedef '
91-
result += this.returnType + ' ' + this.defName + '(' + argList + ');'
91+
result += this.returnType + ' ' + this.defName + '(' + argList + ');'
9292
return result
9393
}
9494
}
@@ -126,7 +126,7 @@ class DNEnumDefContext extends DNContext {
126126
this.macros = []
127127
this.availability = []
128128
}
129-
129+
130130
parse() {
131131
var result = '\n'
132132
if (this.defName) {
@@ -173,73 +173,73 @@ class DNMethodContext extends DNContext {
173173
}
174174

175175
parse() {
176-
if(this.args.length == 0 && this.hasSameMethodDeclaration()){
176+
if (this.args.length == 0 && this.hasSameMethodDeclaration()) {
177177
return ''
178-
}else if(this.args.length == 1 && this.hasSameMethodDeclaration()){
178+
} else if (this.args.length == 1 && this.hasSameMethodDeclaration()) {
179179
return this.parseForOptionalSingleArg()
180180
}
181181

182182
var isInstanceConstr = (this.returnType == this.parent.name) && !this.isClassMethod
183-
if (isInstanceConstr){
183+
if (isInstanceConstr) {
184184
return this.constructorImpl()
185185
} else {
186186
var result = ' ' + this.availability.map((a) => a.parse()).join(' ') + '\n'
187187
result += ' ' + (this.isClassMethod ? 'static ' : '') + this.convertMutableTypeIfNeed(this.returnType) + ' ' + this.methodDeclaration() + this.methodArgs() + ' {\n'
188-
result += this.preHandleMutableArgsIfNeed() + ' ' + this.methodImpl()
188+
result += this.preHandleMutableArgsIfNeed() + ' ' + this.methodImpl()
189189
result += ' }'
190190
return result
191191
}
192192
}
193193

194-
preHandleMutableArgsIfNeed(){
194+
preHandleMutableArgsIfNeed() {
195195
var result = ''
196196
this.args.forEach((element) => {
197197
var rawType = this.rawGenericType(element.type)
198-
if(DNObjectiveCTypeConverter.SupportMutableTypes.indexOf(rawType) > -1){
198+
if (DNObjectiveCTypeConverter.SupportMutableTypes.indexOf(rawType) > -1) {
199199
var tmpArgName = '_' + element.name
200-
result += ' ' + rawType + ' ' + tmpArgName + ' = ' + rawType + '(' + element.name +');\n'
200+
result += ' ' + rawType + ' ' + tmpArgName + ' = ' + rawType + '(' + element.name + ');\n'
201201
element.name = tmpArgName
202202
}
203203
})
204204
return result
205205
}
206206

207-
hasSameMethodDeclaration(){
207+
hasSameMethodDeclaration() {
208208
var methods = this.parent.methods
209-
for(var i = 0 ; i < methods.length; i++){
209+
for (var i = 0; i < methods.length; i++) {
210210
var method = methods[i]
211-
if(this != method && this.methodDeclaration() == method.methodDeclaration() && this.isClassMethod == method.isClassMethod){
211+
if (this != method && this.methodDeclaration() == method.methodDeclaration() && this.isClassMethod == method.isClassMethod) {
212212
return true
213213
}
214214
}
215215
return false
216216
}
217217

218-
methodDeclaration(){
219-
var methodDeclaration = ''
218+
methodDeclaration() {
219+
var methodDeclaration = ''
220220
this.args.forEach((_element, index) => {
221221
methodDeclaration += index >= 1 ? this.names[index].replace(/^\w/, c => c.toUpperCase()) : this.names[index]
222222
})
223223
methodDeclaration = methodDeclaration ? methodDeclaration : this.methodName
224224
return methodDeclaration
225225
}
226226

227-
methodImpl(noArg){
227+
methodImpl(noArg) {
228228
var callerPrefix = (this.isClassMethod ? ' Class(\'' + this.parent.name + '\').' : ' ')
229-
var args = noArg ? '' : ', args: [' + this.args.map(arg => arg.name) + ']'
229+
var args = noArg ? '' : ', args: [' + this.args.map(arg => arg.name) + ']'
230230
var impl = callerPrefix + 'perform(\'' + this.ocMethodName() + '\'.toSEL()' + args + ');\n'
231231

232232
var rawRetType = this.rawGenericType(this.returnType) //remove <> symbol
233233
var isMutableRetType = DNObjectiveCTypeConverter.SupportMutableTypes.indexOf(rawRetType) > -1
234234

235-
if(!isMutableRetType && !this.retValIsObj){
235+
if (!isMutableRetType && !this.retValIsObj) {
236236
return (this.returnType == 'void' ? '' : 'return') + impl
237237
}
238238

239-
var newImpl = 'Pointer<Void> result = ' + impl.replace(');\n','') + ' ,decodeRetVal: false);\n'
240-
if(this.retValIsObj){
239+
var newImpl = 'Pointer<Void> result = ' + impl.replace(');\n', '') + ' ,decodeRetVal: false);\n'
240+
if (this.retValIsObj) {
241241
var supportType = DNObjectiveCTypeConverter.DNDartToOCMap[rawRetType]
242-
if(supportType) {
242+
if (supportType) {
243243
newImpl += ' return ' + supportType + '.fromPointer(result).raw;\n'
244244
} else if (isMutableRetType) {
245245
newImpl += ' return ' + rawRetType + '.fromPointer(result).raw;\n'
@@ -250,41 +250,41 @@ class DNMethodContext extends DNContext {
250250
return newImpl
251251
}
252252

253-
constructorImpl(){
253+
constructorImpl() {
254254
var result = ''
255-
if(this.isSingleInstanceConstr){
256-
// such as NSError(arg x)
255+
if (this.isSingleInstanceConstr) {
256+
// such as NSError(arg x)
257257
result += ' ' + this.parent.name + this.methodArgs() + '\n'
258-
}else{
258+
} else {
259259
// such as NSError.initWithxxxx(arg x)
260260
result += ' ' + this.parent.name + '.' + this.methodDeclaration() + this.methodArgs() + '\n'
261261
}
262-
result += ' : super.fromPointer(_' + this.methodDeclaration() + '(' +this.args.map(arg => arg.name) + '));\n'
262+
result += ' : super.fromPointer(_' + this.methodDeclaration() + '(' + this.args.map(arg => arg.name) + '));\n'
263263
result += '\n';
264264
result += ' static Pointer<Void> _' + this.methodDeclaration() + this.methodArgs() + ' {\n'
265-
result += this.preHandleMutableArgsIfNeed()
266-
result +=' Pointer<Void> target = alloc(Class(\'' + this.parent.name + '\'));\n'
265+
result += this.preHandleMutableArgsIfNeed()
266+
result += ' Pointer<Void> target = alloc(Class(\'' + this.parent.name + '\'));\n'
267267
result += ' SEL sel = \'' + this.ocMethodName() + '\'.toSEL();\n'
268268
result += ' return msgSend(target, sel, ' + 'args: [' + this.args.map(arg => arg.name) + ']' + ', decodeRetVal: false);\n'
269269
result += ' }\n'
270270
return result
271271
}
272272

273-
methodArgs(optional){
273+
methodArgs(optional) {
274274
//convert as follows: int a, String b, {int c, String d}
275275
var argList = optional ? '([' : '('
276276
var nullableArgs = []
277277
this.args.forEach((element, index) => {
278-
if(element.isNullable){
278+
if (element.isNullable) {
279279
nullableArgs.push(element)
280-
}else{
280+
} else {
281281
var argType = element.isOutParam ? 'NSObjectRef<' + element.type + '>' : element.type
282282
var arg = element.anonDef ? element.anonDef : this.convertMutableTypeIfNeed(argType) + ' ' + element.name
283283
argList += arg + (index == this.args.length - 1 && nullableArgs.length == 0 ? '' : ', ')
284284
}
285285
})
286-
287-
if(nullableArgs.length > 0){
286+
287+
if (nullableArgs.length > 0) {
288288
argList += '{'
289289
nullableArgs.forEach((element, index) => {
290290
var argType = element.isOutParam ? 'NSObjectRef<' + element.type + '>' : element.type
@@ -297,7 +297,7 @@ class DNMethodContext extends DNContext {
297297
return argList
298298
}
299299

300-
parseForOptionalSingleArg(){
300+
parseForOptionalSingleArg() {
301301
var optionalArgType = this.args[0].type
302302
var optionalArgName = this.args[0].name
303303
var result = ' ' + (this.isClassMethod ? 'static ' : '') + this.returnType + ' ' + this.methodDeclaration() + '([' + optionalArgType + ' ' + optionalArgName + '])' + ' {\n'
@@ -310,44 +310,44 @@ class DNMethodContext extends DNContext {
310310
return result
311311
}
312312

313-
convertMutableTypeIfNeed(type){
313+
convertMutableTypeIfNeed(type) {
314314
var rawType = this.rawGenericType(type)
315315
var dartType = DNObjectiveCTypeConverter.SupportMutableTypesMap[rawType]
316-
var ret = dartType ? type.replace(rawType,dartType) : type
316+
var ret = dartType ? type.replace(rawType, dartType) : type
317317
return ret
318318
}
319319

320-
rawGenericType(type){
321-
var isGeneric = type.indexOf('<') > -1 && type.indexOf('>') > -1
322-
var rawType = isGeneric ? type.substring(0,type.indexOf('<')) : type
320+
rawGenericType(type) {
321+
var isGeneric = type.indexOf('<') > -1 && type.indexOf('>') > -1
322+
var rawType = isGeneric ? type.substring(0, type.indexOf('<')) : type
323323
return rawType
324324
}
325325

326-
ocMethodName(){
326+
ocMethodName() {
327327
var funcName = ''
328328
this.args.forEach((_element, index) => {
329-
funcName += this.names[index] + (this.args.length >= 1 ? ':' : '')
329+
funcName += this.names[index] + (this.args.length >= 1 ? ':' : '')
330330
})
331331
funcName = funcName ? funcName : this.methodName
332332
return funcName
333333
}
334334
}
335-
class DNMethodDeclarationContext extends DNMethodContext{
335+
class DNMethodDeclarationContext extends DNMethodContext {
336336
constructor(internal) {
337337
super(internal)
338338
}
339339

340-
parse() {
340+
parse() {
341341
// We have to ignore static methods due to this issue: https://github.com/dart-lang/language/issues/356
342-
if (this.isClassMethod || (this.args.length == 0 && this.hasSameMethodDeclaration())){
342+
if (this.isClassMethod || (this.args.length == 0 && this.hasSameMethodDeclaration())) {
343343
return ''
344344
}
345-
345+
346346
var result = ' ' + this.availability.map((a) => a.parse()).join(' ') + '\n'
347347
result += ' ' + this.returnType + ' ' + this.methodDeclaration()
348348

349-
if(this.args.length == 1 && this.hasSameMethodDeclaration()){
350-
result += this.methodArgs(true) +';'
349+
if (this.args.length == 1 && this.hasSameMethodDeclaration()) {
350+
result += this.methodArgs(true) + ';'
351351
}
352352
result += this.methodArgs() + ';'
353353
return result;
@@ -367,7 +367,7 @@ class DNPropertyContext extends DNContext {
367367

368368
parse() {
369369
var annotation = ' ' + this.availability.map((a) => a.parse()).join(' ') + '\n'
370-
var get = annotation + ' ' + this.type + ' get ' + this.name +
370+
var get = annotation + ' ' + this.type + ' get ' + this.name +
371371
' => perform(\'' + this.name + '\'.toSEL());'
372372
if (!this.isReadOnly) {
373373
var set = annotation + ' ' + 'set ' + this.name + '(' + this.type + ' ' + this.name + ')' +
@@ -386,7 +386,7 @@ class DNProtocolContext extends DNContext {
386386
this.protocols = []
387387
}
388388

389-
parse(){
389+
parse() {
390390
var result = 'abstract class ' + this.name
391391
if (typeof this.protocols !== 'undefined' && this.protocols.length > 0) {
392392
result += ' implements ' + this.protocols.join(',')
@@ -437,17 +437,17 @@ class DNClassContext extends DNContext {
437437
}
438438

439439
// mark the method if the class has only one instance construction
440-
preMarkConstructMethods(){
440+
preMarkConstructMethods() {
441441
var markMethod
442442
var hasOneInstanceConstr = false
443-
for(var i = 0 ; i < this.methods.length; i++){
443+
for (var i = 0; i < this.methods.length; i++) {
444444
var method = this.methods[i]
445445
var isInstanceConstr = (method.returnType == this.name) && !method.isClassMethod
446-
if(isInstanceConstr){
447-
if(hasOneInstanceConstr){
446+
if (isInstanceConstr) {
447+
if (hasOneInstanceConstr) {
448448
markMethod.isSingleInstanceConstr = false
449449
break
450-
}else{
450+
} else {
451451
hasOneInstanceConstr = true
452452
method.isSingleInstanceConstr = true
453453
markMethod = method
@@ -482,7 +482,7 @@ class DNCategoryContext extends DNContext {
482482
}
483483

484484
class DNImportContext extends DNContext {
485-
constructor(internal,needExport) {
485+
constructor(internal, needExport) {
486486
super(internal)
487487
this.needExport = needExport
488488
var frameworkCtx = internal.frameworkName
@@ -519,7 +519,7 @@ class DNImportContext extends DNContext {
519519
} else if (packageName) {
520520
result += packageName + '.dart\';'
521521
}
522-
522+
523523
return result
524524
}
525525
}
@@ -548,9 +548,9 @@ class DNRootContext extends DNContext {
548548
return childResult
549549
}).join('\n')
550550
return {
551-
dartCode : result,
552-
packages : packageSet
553-
}
551+
dartCode: result,
552+
packages: packageSet
553+
}
554554
}
555555
}
556556

0 commit comments

Comments
 (0)