Skip to content

Commit

Permalink
Remove empty lines from generated declarations
Browse files Browse the repository at this point in the history
  • Loading branch information
sgrishchenko committed Jun 23, 2024
1 parent 55b98e1 commit 2a86c17
Show file tree
Hide file tree
Showing 59 changed files with 30 additions and 307 deletions.
2 changes: 1 addition & 1 deletion src/converter/plugins/AccessorsPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export class AccessorsPlugin implements ConverterPlugin {

return `
${ifPresent(inheritanceModifier, it => `${it} `)}${modifier}${name}: ${type}
`;
`.trim();
}

return null
Expand Down
2 changes: 1 addition & 1 deletion src/converter/plugins/AnnotationPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class AnnotationPlugin implements ConverterPlugin {
return `
${annotations.join("\n")}
${next(node)}
`;
`.trim();
}

return null
Expand Down
2 changes: 1 addition & 1 deletion src/converter/plugins/InheritedTypeLiteralPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export function convertInheritedTypeLiteral(
${ifPresent(inheritanceModifier, it => `${it} `)}external interface ${name}${ifPresent(typeParameters, it => `<${it}> `)}${(ifPresent(fullHeritageClauses, it => ` : ${it}`))} {
${ifPresent(accessors, it => `${it}\n`)}${members}${ifPresent(injectedMembers, it => `\n${it}`)}
}
`
`.trim()
}

export const inheritedTypeLiteralPlugin = createAnonymousDeclarationPlugin(
Expand Down
6 changes: 3 additions & 3 deletions src/converter/plugins/MappedTypePlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ export function convertMappedTypeBody(node: MappedTypeNode, context: ConverterCo
const getter = `
@seskar.js.JsNative
${ifPresent(getterInheritanceModifier, it => `${it} `)}operator fun <${typeParameter}> get(key: ${keyType}): ${type}
`
`.trim()

let setter = ""

if (!readonly) {
setter = `
@seskar.js.JsNative
${ifPresent(setterInheritanceModifier, it => `${it} `)}operator fun <${typeParameter}> set(key: ${keyType}, value: ${type})
`
`.trim()
}

const injectedMembers = (injections ?? [])
Expand Down Expand Up @@ -74,7 +74,7 @@ export const convertMappedType = (
${ifPresent(inheritanceModifier, it => `${it} `)}external interface ${name}${ifPresent(typeParameters, it => `<${it}>`)}${(ifPresent(injectedHeritageClauses, it => ` : ${it}`))} {
${convertMappedTypeBody(node, context, render)}
}
`
`.trim()
}

export const mappedTypePlugin = createAnonymousDeclarationPlugin(
Expand Down
8 changes: 5 additions & 3 deletions src/converter/plugins/StringUnionTypePlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,17 @@ val ${key}: ${name}
const declaration = `
sealed external interface ${name}${ifPresent(injectedHeritageClauses, it => ` : ${it}`)} {
companion object {
${body}${ifPresent(comment, it => (`
${body}${ifPresent(comment, it => (
`
/*
Duplicated names were generated:
${it}
*/
`))}
`.trim()
))}
}
}
`
`.trim()

const nullable = nullableTypes.length > 0

Expand Down
2 changes: 1 addition & 1 deletion src/converter/plugins/TypeLiteralPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export function convertTypeLiteral(
${ifPresent(inheritanceModifier, it => `${it} `)}external interface ${name}${ifPresent(typeParameters, it => `<${it}>`)}${(ifPresent(injectedHeritageClauses, it => ` : ${it}`))} {
${convertTypeLiteralBody(node, context, render)}
}
`
`.trim()
}

export const typeLiteralPlugin = createAnonymousDeclarationPlugin(
Expand Down
2 changes: 1 addition & 1 deletion src/converter/plugins/convertCallSignatureDeclaration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const convertCallSignatureDeclaration = createSimplePlugin((node, context
return `
@seskar.js.JsNative
${ifPresent(inheritanceModifier, it => `${it} `)}operator fun ${ifPresent(typeParameters, it => `<${it}>`)} invoke(${parameters})${ifPresent(returnType, it => `: ${it}`)}
`
`.trim()
}
})
})
4 changes: 2 additions & 2 deletions src/converter/plugins/convertClassDeclaration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,12 @@ export const convertClassDeclaration = createSimplePlugin((node, context, render
companion object {
${staticMembers}${ifPresent(staticInjectedMembers, it => `\n${it}`)}
}
`
`.trim()
}

return `
${ifPresent(inheritanceModifier, it => `${it} `)}${externalModifier}class ${name}${ifPresent(typeParameters, it => `<${it}>`)}${ifPresent(fullHeritageClauses, it => ` : ${it}`)} {
${members}${ifPresent(injectedMembers, it => `\n${it}`)}${companionObject}
}
`
`.trim()
})
2 changes: 1 addition & 1 deletion src/converter/plugins/convertEnumDeclaration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,5 @@ companion object {
${members}
}
}
`
`.trim()
})
4 changes: 2 additions & 2 deletions src/converter/plugins/convertIndexedSignatureDeclaration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ export const convertIndexedSignatureDeclaration = createSimplePlugin((node, cont
const getter = `
@seskar.js.JsNative
${ifPresent(getterInheritanceModifier, it => `${it} `)}operator fun get(key: ${keyType}): ${type}
`
`.trim()

let setter = ""

if (!readonly) {
setter = `
@seskar.js.JsNative
${ifPresent(setterInheritanceModifier, it => `${it} `)}operator fun set(key: ${keyType}, value: ${type})
`
`.trim()
}


Expand Down
2 changes: 1 addition & 1 deletion src/converter/plugins/convertInterfaceDeclaration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,5 @@ export const convertInterfaceDeclaration = createSimplePlugin((node, context, re
${ifPresent(inheritanceModifier, it => `${it} `)}${externalModifier}interface ${name}${ifPresent(typeParameters, it => `<${it}>`)}${ifPresent(fullHeritageClauses, it => ` : ${it}`)} {
${members}${ifPresent(injectedMembers, it => `\n${it}`)}
}
`
`.trim()
})
2 changes: 1 addition & 1 deletion src/converter/plugins/convertModuleDeclaration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const convertModuleDeclaration = createSimplePlugin((node, context, rende
${externalModifier}object ${name} {
${body}
}
`
`.trim()
}

if (namespaceStrategy === "package") {
Expand Down
23 changes: 0 additions & 23 deletions test/functional/base/generated/accessor/simple.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,52 +7,29 @@

package sandbox.base.accessor


external class Simple {

var property: String

}



external class DifferentTypes {

var property: String

}



external class Readonly {

val property: String

}



external class Setteronly {

var property: String

}



external interface Split {

var property: String

}





external interface Anonymous {

var property: String


}
11 changes: 0 additions & 11 deletions test/functional/base/generated/class/parentContstructors.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,38 +7,27 @@

package sandbox.base.`class`


external class GrandparentWithConstructor {
constructor (param: Double)
constructor (param: String)
}



external class ParentWithoutConstructor : GrandparentWithConstructor {
constructor (param: Double)
constructor (param: String)
}



external class ChildWithoutConstructor : ParentWithoutConstructor {
constructor (param: Double)
constructor (param: String)
}



external object NSWithParent {

class ParentWithConstructor {
constructor (param: Double)
constructor (param: Boolean)
}

}



external class ChildWithoutConstructor2 : NSWithParent.ParentWithConstructor {
constructor (param: Double)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,9 @@ package sandbox.base.declarationMerging




external class ExampleClass {

@seskar.js.JsNative
operator fun invoke(param: String): Unit

var a: Double
var b: String
var c: Boolean
Expand Down
1 change: 0 additions & 1 deletion test/functional/base/generated/declarationMerging/enums.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

package sandbox.base.declarationMerging


sealed external interface ExampleEnum {
companion object {
val a: ExampleEnum
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,21 @@

package sandbox.base.declarationMerging


external interface ExampleParentForInterface {

}



external interface SecondExampleParentForInterface {

}



external interface ExampleParentForClass {

}



external interface ExampleInterfaceWithParent : ExampleParentForInterface, SecondExampleParentForInterface {

}





Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,12 @@

package sandbox.base.declarationMerging


external interface Example {

@seskar.js.JsNative
operator fun invoke(param1: String): Unit

var a: Double
var b: String
}





Expand Down
2 changes: 0 additions & 2 deletions test/functional/base/generated/function/bindingPattern.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@

package sandbox.base.function


external interface Path {
var pathname: String
var search: String
var hash: String
}


external fun createPath(options: Path): String
12 changes: 1 addition & 11 deletions test/functional/base/generated/function/stringUnionParam.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ external fun getGPUInfo3(infoType: ((GetGPUInfo3InfoType))): Any?
external fun getGPUInfo4(infoType: (((GetGPUInfo4InfoType)))): Any?

external fun setVibrancy(type: SetVibrancyType?): Unit

sealed external interface GetGPUInfoInfoType {
companion object {
@seskar.js.JsValue("basic")
Expand All @@ -25,8 +24,6 @@ val basic: GetGPUInfoInfoType
val complete: GetGPUInfoInfoType
}
}



sealed external interface GetGPUInfo2InfoType {
companion object {
Expand All @@ -36,8 +33,6 @@ val basic: GetGPUInfo2InfoType
val complete: GetGPUInfo2InfoType
}
}



sealed external interface GetGPUInfo3InfoType {
companion object {
Expand All @@ -47,8 +42,6 @@ val basic: GetGPUInfo3InfoType
val complete: GetGPUInfo3InfoType
}
}



sealed external interface GetGPUInfo4InfoType {
companion object {
Expand All @@ -58,8 +51,6 @@ val basic: GetGPUInfo4InfoType
val complete: GetGPUInfo4InfoType
}
}



sealed external interface SetVibrancyType {
companion object {
Expand All @@ -68,5 +59,4 @@ val light: SetVibrancyType
@seskar.js.JsValue("dark")
val dark: SetVibrancyType
}
}

}
Loading

0 comments on commit 2a86c17

Please sign in to comment.