Skip to content

Commit

Permalink
temp: package
Browse files Browse the repository at this point in the history
  • Loading branch information
ZEROM22 committed Dec 26, 2024
1 parent c4752c1 commit a1f8119
Show file tree
Hide file tree
Showing 5 changed files with 167 additions and 37 deletions.
116 changes: 94 additions & 22 deletions packages/typedoc-signature/lib/concise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@ export function enumMemberReflection(ctx: Context, r: J.Reflection): Signature {
if (r.type) {
const b = type(ctx, r.type)
s.push(...b)
} else {
// todo: The default enum is int. Each case must be +1
}

return s
Expand Down Expand Up @@ -109,6 +107,21 @@ export function functionsDeclaration(ctx: Context, f: J.Reflection): Signature {

let t: Token

if (f.type) {
const rp = genericParameters(f.type)
if (rp.length !== 0) {
t = new TextToken()
t.text = "<"
s.push(t)

s.push(...rp)

t = new TextToken()
t.text = ">"
s.push(t)
}
}

const b = parameters(f)
s.push(...b)

Expand Down Expand Up @@ -149,18 +162,19 @@ export function methodDeclaration(ctx: Context, m: J.Reflection): Signature {

let t: Token

if (m.type && isReferenceType(m.type) && m.type.refersToTypeParameter) {
t = new TextToken()
t.text = "<"
s.push(t)
if (m.type) {
const rp = genericParameters(m.type)
if (rp.length !== 0) {
t = new TextToken()
t.text = "<"
s.push(t)

t = new TypeToken()
t.text = m.type.name
s.push(t)
s.push(...rp)

t = new TextToken()
t.text = ">"
s.push(t)
t = new TextToken()
t.text = ">"
s.push(t)
}
}

const b = parameters(m)
Expand Down Expand Up @@ -376,8 +390,7 @@ export function referenceType(ctx: Context, r: J.ReferenceType): Signature {
s.push(t)

for (const a of r.typeArguments) {
let b = type(ctx, a)
b = ctx.f.preprocess(b)
const b = type(ctx, a)
s.push(...b)

t = new TextToken()
Expand Down Expand Up @@ -424,14 +437,15 @@ export function reflectionType(ctx: Context, r: J.ReflectionType): Signature {
s.push(t)

t = new TextToken()
t.text = ": "
if (c.flags.isOptional) {
t.text = `?${t.text}`
t.text += "?"
}
t.text += ": "
s.push(t)

const b = type(ctx, c.type)
s.push(...b)

t = new TextToken()
t.text = "; "
s.push(t)
Expand All @@ -442,11 +456,33 @@ export function reflectionType(ctx: Context, r: J.ReflectionType): Signature {
t = new TextToken()
t.text = "}"
s.push(t)
} else {
} else if (r.declaration.indexSignatures) {
t = new TextToken()
t.text = "{"
s.push(t)

for (const is of r.declaration.indexSignatures) {
const b = parameters(is)
for (const tt of b) {
if (tt instanceof TextToken && tt.text === "(") {
tt.text = "["
}
if (tt instanceof TextToken && tt.text === ")") {
tt.text = "]"
}
}
s.push(...b)

if (is.type) {
t = new TextToken()
t.text = ": "
s.push(t)

const b = type(ctx, is.type)
s.push(...b)
}
}

t = new TextToken()
t.text = "}"
s.push(t)
Expand Down Expand Up @@ -476,8 +512,7 @@ export function templateLiteralType(ctx: Context, tt: J.TemplateLiteralType): Si
t.text = "${"
s.push(t)

let b = type(ctx, e)
b = ctx.f.preprocess(b)
const b = type(ctx, e)
s.push(...b)

t = new TextToken()
Expand Down Expand Up @@ -565,7 +600,7 @@ export function fragments(ctx: Context, f: Fragment[]): void {
if (ft) {
const t = ctx.t.reflectionOf(ft)
if (!t) {
console.log(`Reflection for fragment ${e.name} not found`)
console.error(`Reflection for fragment ${e.name} not found`)
continue
}
if (!isParameterReflection(t)) {
Expand All @@ -576,7 +611,7 @@ export function fragments(ctx: Context, f: Fragment[]): void {
e.signature.concise.push(...b)
}
} else {
console.log(`Trail for fragment ${e.name} not found`)
console.error(`Trail for fragment ${e.name} not found`)
}
}
}
Expand Down Expand Up @@ -606,10 +641,47 @@ function reference(ctx: Context, t: number, n: string): Token | Reference {
r.token = new TypeToken()
r.token.text = n
} else {
console.log(`Reflection id not found for ${n} typedoc reference id = ${t}`)
console.error(`Reflection id not found for ${n} typedoc reference id = ${t}`)
r = new TypeToken()
r.text = n
}

return r
}

function genericParameters(st: J.SomeType): Signature {
const s: Signature = []
let t: Token

if (isReferenceType(st) && st.refersToTypeParameter) {
t = new TypeToken()
t.text = st.name
s.push(t)
}
if (isUnionType(st) && st.types) {
for (const tp of st.types) {
if (isReferenceType(st) || isUnionType(st)) {
const p = genericParameters(tp)
if (p.length !== 0) {
s.push(...p)

t = new TextToken()
t.text = ", "
s.push(t)
}
}
}
s.pop()
}
if (isArrayType(st) && isReferenceType(st.elementType) && st.elementType.refersToTypeParameter) {
t = new TypeToken()
t.text = st.elementType.name
s.push(t)

t = new TextToken()
t.text = "[]"
s.push(t)
}

return s
}
6 changes: 3 additions & 3 deletions packages/typedoc-signature/lib/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,20 @@ export function compute(ct: Transport): void {

let ft = ct.trailOf(e.declaration)
if (!ft) {
console.log(`Trail for ${e.declaration.name} id = ${e.id} not found`)
console.error(`Trail for ${e.declaration.name} id = ${e.id} not found`)
continue
}

const t = ct.reflectionOf(ft)
if (!t) {
console.log(`Target for ${e.declaration.name} id = ${e.id} not found`)
console.error(`Target for ${e.declaration.name} id = ${e.id} not found`)
continue
}

ft = ft.slice(0, -1)
const p = ct.reflectionOf(ft)
if (!t) {
console.log(`Parent for ${e.declaration.name} id = ${e.id} not found`)
console.error(`Parent for ${e.declaration.name} id = ${e.id} not found`)
continue
}

Expand Down
78 changes: 66 additions & 12 deletions packages/typedoc-signature/lib/verbose.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {
isUnionType,
} from "@onlyoffice/typedoc-util-is-type"
import {type JSONOutput as J} from "typedoc"
import {isStringLiteral} from "../../strings/lib/main.ts"
import {Console} from "./console.ts"
import {type Context} from "./context.ts"

Expand Down Expand Up @@ -209,8 +210,6 @@ export function enumMemberReflection(ctx: Context, r: J.Reflection): Signature {
let b = type(ctx, r.type)
b = ctx.f.preprocess(b)
s.push(...b)
} else {
// todo: The default enum is int. Each case must be +1.
}

return s
Expand Down Expand Up @@ -252,6 +251,11 @@ export function enumReflection(ctx: Context, r: J.Reflection): Signature {
s.push(...newline(ctx))

const b = value(ctx, c)
for (const e of b) {
if (e instanceof TextToken && e.text === ": ") {
e.text = " = "
}
}
s.push(...b)

t = new TextToken()
Expand Down Expand Up @@ -550,7 +554,11 @@ export function variableDeclaration(ctx: Context, r: J.Reflection): Signature {
let t: Token

t = new KeywordToken()
t.text = "type"
if (r.flags.isConst) {
t.text = "const"
} else {
t.text = "let"
}
s.push(t)

t = new TextToken()
Expand All @@ -562,7 +570,7 @@ export function variableDeclaration(ctx: Context, r: J.Reflection): Signature {
s.push(t)

t = new TextToken()
t.text = " = "
t.text = ": "
s.push(t)

if (r.type) {
Expand Down Expand Up @@ -629,6 +637,12 @@ export function value(ctx: Context, r: J.Reflection): Signature {
return s
}

if (r.flags.isRest) {
t = new TextToken()
t.text += "..."
s.push(t)
}

t = new ParameterToken()
t.text = r.name
s.push(t)
Expand All @@ -654,9 +668,16 @@ export function value(ctx: Context, r: J.Reflection): Signature {
t.text = " = "
s.push(t)

t = new TextToken()
t.text = String(r.defaultValue)
s.push(t)
if (isStringLiteral(r.defaultValue)) {
t = new StringToken()
const v = r.defaultValue.slice(1, -1)
t.text = `"${v}"`
s.push(t)
} else {
t = new TextToken()
t.text = String(r.defaultValue)
s.push(t)
}
}

s = ctx.f.preprocess(s)
Expand Down Expand Up @@ -807,17 +828,17 @@ export function referenceType(ctx: Context, r: J.ReferenceType): Signature {
const s: Signature = []
let t: Token

let id
let id: number | undefined
if (typeof r.target === "number") {
id = ctx.t.idOf(r.target)
if (!id) {
console.log(`Reflection id not found for ${r.name} typedoc reference id = ${r.target}`)
console.error(`Reflection id not found for ${r.name} typedoc reference id = ${r.target}`)
}
} else {
console.log(`ReflectionSymbolId not supported for ${r.name}`)
console.error(`ReflectionSymbolId not supported for ${r.name}`)
}

if (id) {
if (id !== undefined) {
const rt = new Reference()
rt.id = String(id)
rt.token = new TypeToken()
Expand Down Expand Up @@ -911,11 +932,44 @@ export function reflectionType(ctx: Context, r: J.ReflectionType): Signature {
t = new TextToken()
t.text = "}"
s.push(t)
} else {
} else if (r.declaration.indexSignatures) {
t = new TextToken()
t.text = "{"
s.push(t)

ctx.s.in()
for (const is of r.declaration.indexSignatures) {
s.push(...newline(ctx))

let ts: Signature = []

const b = parameters(is, ctx)
for (const tt of b) {
if (tt instanceof TextToken && tt.text === "(") {
tt.text = "["
}
if (tt instanceof TextToken && tt.text === ")") {
tt.text = "]"
}
}
ts.push(...b)

if (is.type) {
t = new TextToken()
t.text = ": "
ts.push(t)

const b = type(ctx, is.type)
ts.push(...b)
}

ts = ctx.f.preprocess(ts)
s.push(...ts)
}
ctx.s.out()

s.push(...newline(ctx))

t = new TextToken()
t.text = "}"
s.push(t)
Expand Down
1 change: 1 addition & 0 deletions packages/typedoc-signature/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"@onlyoffice/console": "workspace:^",
"@onlyoffice/library-declaration": "workspace:^",
"@onlyoffice/signature": "workspace:^",
"@onlyoffice/strings": "workspace:^",
"@onlyoffice/typedoc-transformer": "workspace:^",
"@onlyoffice/typedoc-transport": "workspace:^",
"@onlyoffice/typedoc-util-is-reflection": "workspace:^",
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a1f8119

Please sign in to comment.