mirror of
https://github.com/vale981/tridactyl
synced 2025-03-04 17:11:40 -05:00
Make compiler tslint/tslint-sonarts ready
This commit is contained in:
parent
87adde1604
commit
bcd04a349c
17 changed files with 92 additions and 87 deletions
|
@ -9,19 +9,19 @@ export class ClassMetadata {
|
|||
>(),
|
||||
) {}
|
||||
|
||||
setMember(name: string, s: SymbolMetadata) {
|
||||
public setMember(name: string, s: SymbolMetadata) {
|
||||
this.members.set(name, s)
|
||||
}
|
||||
|
||||
getMember(name: string) {
|
||||
public getMember(name: string) {
|
||||
return this.members.get(name)
|
||||
}
|
||||
|
||||
getMembers() {
|
||||
public getMembers() {
|
||||
return this.members.keys()
|
||||
}
|
||||
|
||||
toConstructor() {
|
||||
public toConstructor() {
|
||||
return (
|
||||
`new ClassMetadata(new Map<string, SymbolMetadata>([` +
|
||||
Array.from(this.members.entries())
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { SymbolMetadata } from "./SymbolMetadata"
|
||||
import { ClassMetadata } from "./ClassMetadata"
|
||||
import { SymbolMetadata } from "./SymbolMetadata"
|
||||
|
||||
export class FileMetadata {
|
||||
constructor(
|
||||
|
@ -13,35 +13,35 @@ export class FileMetadata {
|
|||
>(),
|
||||
) {}
|
||||
|
||||
setClass(name: string, c: ClassMetadata) {
|
||||
public setClass(name: string, c: ClassMetadata) {
|
||||
this.classes.set(name, c)
|
||||
}
|
||||
|
||||
getClass(name: string) {
|
||||
public getClass(name: string) {
|
||||
return this.classes.get(name)
|
||||
}
|
||||
|
||||
getClasses() {
|
||||
public getClasses() {
|
||||
return Array.from(this.classes.keys())
|
||||
}
|
||||
|
||||
setFunction(name: string, f: SymbolMetadata) {
|
||||
public setFunction(name: string, f: SymbolMetadata) {
|
||||
this.functions.set(name, f)
|
||||
}
|
||||
|
||||
getFunction(name: string) {
|
||||
public getFunction(name: string) {
|
||||
return this.functions.get(name)
|
||||
}
|
||||
|
||||
getFunctions() {
|
||||
public getFunctions() {
|
||||
return Array.from(this.functions.entries())
|
||||
}
|
||||
|
||||
getFunctionNames() {
|
||||
public getFunctionNames() {
|
||||
return Array.from(this.functions.keys())
|
||||
}
|
||||
|
||||
toConstructor() {
|
||||
public toConstructor() {
|
||||
return (
|
||||
`new FileMetadata(new Map<string, ClassMetadata>([` +
|
||||
Array.from(this.classes.entries())
|
||||
|
|
|
@ -8,15 +8,15 @@ export class ProgramMetadata {
|
|||
>(),
|
||||
) {}
|
||||
|
||||
setFile(name: string, file: FileMetadata) {
|
||||
public setFile(name: string, file: FileMetadata) {
|
||||
this.files.set(name, file)
|
||||
}
|
||||
|
||||
getFile(name: string) {
|
||||
public getFile(name: string) {
|
||||
return this.files.get(name)
|
||||
}
|
||||
|
||||
toConstructor() {
|
||||
public toConstructor() {
|
||||
return (
|
||||
`new ProgramMetadata(new Map<string, FileMetadata>([` +
|
||||
Array.from(this.files.entries())
|
||||
|
|
|
@ -3,7 +3,7 @@ import { Type } from "../types/AllTypes"
|
|||
export class SymbolMetadata {
|
||||
constructor(public doc: string, public type: Type, public hidden = false) {}
|
||||
|
||||
toConstructor() {
|
||||
public toConstructor() {
|
||||
return `new SymbolMetadata(${JSON.stringify(
|
||||
this.doc,
|
||||
)}, ${this.type.toConstructor()}, ${this.hidden})`
|
||||
|
|
|
@ -1,20 +1,18 @@
|
|||
import { Type } from "./Type"
|
||||
|
||||
export class AnyType implements Type {
|
||||
static instance = new AnyType()
|
||||
kind = "any"
|
||||
public static instance = new AnyType()
|
||||
public kind = "any"
|
||||
|
||||
constructor() {}
|
||||
|
||||
toConstructor() {
|
||||
public toConstructor() {
|
||||
return "AnyType.instance"
|
||||
}
|
||||
|
||||
toString() {
|
||||
public toString() {
|
||||
return this.kind
|
||||
}
|
||||
|
||||
convert(argument) {
|
||||
public convert(argument) {
|
||||
return argument
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,19 +1,19 @@
|
|||
import { Type } from "./Type"
|
||||
|
||||
export class ArrayType implements Type {
|
||||
kind = "array"
|
||||
public kind = "array"
|
||||
|
||||
constructor(public elemType: Type) {}
|
||||
|
||||
toConstructor() {
|
||||
public toConstructor() {
|
||||
return `new ArrayType(${this.elemType.toConstructor()})`
|
||||
}
|
||||
|
||||
toString() {
|
||||
public toString() {
|
||||
return `${this.elemType.toString()}[]`
|
||||
}
|
||||
|
||||
convert(argument) {
|
||||
public convert(argument) {
|
||||
if (!Array.isArray(argument)) {
|
||||
try {
|
||||
argument = JSON.parse(argument)
|
||||
|
|
|
@ -1,22 +1,23 @@
|
|||
import { Type } from "./Type"
|
||||
|
||||
export class BooleanType implements Type {
|
||||
static instance = new BooleanType()
|
||||
kind = "boolean"
|
||||
public static instance = new BooleanType()
|
||||
public kind = "boolean"
|
||||
|
||||
constructor() {}
|
||||
|
||||
toConstructor() {
|
||||
public toConstructor() {
|
||||
return "BooleanType.instance"
|
||||
}
|
||||
|
||||
toString() {
|
||||
public toString() {
|
||||
return this.kind
|
||||
}
|
||||
|
||||
convert(argument) {
|
||||
if (argument === "true") return true
|
||||
else if (argument === "false") return false
|
||||
public convert(argument) {
|
||||
if (argument === "true") {
|
||||
return true
|
||||
} else if (argument === "false") {
|
||||
return false
|
||||
}
|
||||
throw new Error("Can't convert ${argument} to boolean")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
import { Type } from "./Type"
|
||||
|
||||
export class FunctionType implements Type {
|
||||
kind = "function"
|
||||
public kind = "function"
|
||||
|
||||
constructor(public args: Type[], public ret: Type) {}
|
||||
|
||||
toConstructor() {
|
||||
public toConstructor() {
|
||||
return (
|
||||
`new FunctionType([` +
|
||||
// Convert every argument type to its string constructor representation
|
||||
|
@ -14,11 +14,11 @@ export class FunctionType implements Type {
|
|||
)
|
||||
}
|
||||
|
||||
toString() {
|
||||
public toString() {
|
||||
return `(${this.args.map(a => a.toString()).join(", ")}) => ${this.ret.toString()}`
|
||||
}
|
||||
|
||||
convert(argument) {
|
||||
public convert(argument) {
|
||||
// Possible strategies:
|
||||
// - eval()
|
||||
// - window[argument]
|
||||
|
|
|
@ -1,20 +1,22 @@
|
|||
import { Type } from "./Type"
|
||||
|
||||
export class LiteralTypeType implements Type {
|
||||
kind = "LiteralType"
|
||||
public kind = "LiteralType"
|
||||
|
||||
constructor(public value: string) {}
|
||||
|
||||
toConstructor() {
|
||||
public toConstructor() {
|
||||
return `new LiteralTypeType(${JSON.stringify(this.value)})`
|
||||
}
|
||||
|
||||
toString() {
|
||||
public toString() {
|
||||
return JSON.stringify(this.value)
|
||||
}
|
||||
|
||||
convert(argument) {
|
||||
if (argument === this.value) return argument
|
||||
public convert(argument) {
|
||||
if (argument === this.value) {
|
||||
return argument
|
||||
}
|
||||
throw new Error(
|
||||
`Argument does not match expected value (${
|
||||
this.value
|
||||
|
|
|
@ -1,24 +1,26 @@
|
|||
import { Type } from "./Type"
|
||||
|
||||
export class NumberType implements Type {
|
||||
static instance = new NumberType()
|
||||
kind = "number"
|
||||
public static instance = new NumberType()
|
||||
public kind = "number"
|
||||
|
||||
constructor() {}
|
||||
|
||||
toConstructor() {
|
||||
public toConstructor() {
|
||||
return "NumberType.instance"
|
||||
}
|
||||
|
||||
toString() {
|
||||
public toString() {
|
||||
return this.kind
|
||||
}
|
||||
|
||||
convert(argument) {
|
||||
public convert(argument) {
|
||||
let n = parseInt(argument)
|
||||
if (!Number.isNaN(n)) return n
|
||||
if (!Number.isNaN(n)) {
|
||||
return n
|
||||
}
|
||||
n = parseFloat(argument)
|
||||
if (!Number.isNaN(n)) return n
|
||||
if (!Number.isNaN(n)) {
|
||||
return n
|
||||
}
|
||||
throw new Error(`Can't convert to number: ${argument}`)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,23 +1,23 @@
|
|||
import { Type } from "./Type"
|
||||
|
||||
export class ObjectType implements Type {
|
||||
kind = "object"
|
||||
public kind = "object"
|
||||
|
||||
// Note: a map that has an empty key ("") uses the corresponding type as default type
|
||||
constructor(public members: Map<string, Type> = new Map<string, Type>()) {}
|
||||
|
||||
toConstructor() {
|
||||
public toConstructor() {
|
||||
return `new ObjectType(new Map<string, Type>([` +
|
||||
Array.from(this.members.entries()).map(([n, m]) => `[${JSON.stringify(n)}, ${m.toConstructor()}]`)
|
||||
.join(", ") +
|
||||
`]))`
|
||||
}
|
||||
|
||||
toString() {
|
||||
public toString() {
|
||||
return this.kind
|
||||
}
|
||||
|
||||
convertMember(memberName: string[], memberValue: string) {
|
||||
public convertMember(memberName: string[], memberValue: string) {
|
||||
let type = this.members.get(memberName[0])
|
||||
if (!type) {
|
||||
// No type, try to get the default type
|
||||
|
@ -27,13 +27,13 @@ export class ObjectType implements Type {
|
|||
return memberValue
|
||||
}
|
||||
}
|
||||
if (type.kind == "object") {
|
||||
if (type.kind === "object") {
|
||||
return (type as ObjectType).convertMember(memberName.slice(1), memberValue)
|
||||
}
|
||||
return type.convert(memberValue)
|
||||
}
|
||||
|
||||
convert(argument) {
|
||||
public convert(argument) {
|
||||
try {
|
||||
return JSON.parse(argument)
|
||||
} catch (e) {
|
||||
|
|
|
@ -1,21 +1,23 @@
|
|||
import { Type } from "./Type"
|
||||
|
||||
export class StringType implements Type {
|
||||
static instance = new StringType()
|
||||
kind = "string"
|
||||
public static instance = new StringType()
|
||||
public kind = "string"
|
||||
|
||||
constructor() {}
|
||||
|
||||
toConstructor() {
|
||||
public toConstructor() {
|
||||
return "StringType.instance"
|
||||
}
|
||||
|
||||
toString() {
|
||||
public toString() {
|
||||
return this.kind
|
||||
}
|
||||
|
||||
convert(argument) {
|
||||
if (typeof argument === "string") return argument
|
||||
public convert(argument) {
|
||||
if (typeof argument === "string") {
|
||||
return argument
|
||||
}
|
||||
throw new Error(`Can't convert to string: ${argument}`)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
import { Type } from "./Type"
|
||||
|
||||
export class TupleType implements Type {
|
||||
kind = "tuple"
|
||||
public kind = "tuple"
|
||||
|
||||
constructor(public elemTypes: Type[]) {}
|
||||
|
||||
toConstructor() {
|
||||
public toConstructor() {
|
||||
return (
|
||||
`new TupleType([` +
|
||||
// Convert every element type to its constructor representation
|
||||
|
@ -14,11 +14,11 @@ export class TupleType implements Type {
|
|||
)
|
||||
}
|
||||
|
||||
toString() {
|
||||
public toString() {
|
||||
return `[${this.elemTypes.map(e => e.toString()).join(", ")}]`
|
||||
}
|
||||
|
||||
convert(argument) {
|
||||
public convert(argument) {
|
||||
if (!Array.isArray(argument)) {
|
||||
try {
|
||||
argument = JSON.parse(argument)
|
||||
|
@ -29,7 +29,7 @@ export class TupleType implements Type {
|
|||
throw new Error(`Can't convert to tuple: ${argument}`)
|
||||
}
|
||||
}
|
||||
if (argument.length != this.elemTypes.length) {
|
||||
if (argument.length !== this.elemTypes.length) {
|
||||
throw new Error(
|
||||
`Error converting tuple: number of elements and type mismatch ${argument}`,
|
||||
)
|
||||
|
|
|
@ -5,5 +5,5 @@ export interface Type {
|
|||
name?: string
|
||||
toConstructor(): string
|
||||
toString(): string
|
||||
convert: (argument: string) => any
|
||||
convert(argument: string): any
|
||||
}
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
import { Type } from "./Type"
|
||||
|
||||
export class TypeReferenceType implements Type {
|
||||
constructor(public kind: string, public args: Type[]) {}
|
||||
public constructor(public kind: string, public args: Type[]) {}
|
||||
|
||||
toConstructor() {
|
||||
public toConstructor() {
|
||||
return (
|
||||
`new TypeReferenceType(${JSON.stringify(this.kind)}, [` +
|
||||
// Turn every type argument into its constructor representation
|
||||
|
@ -12,11 +12,11 @@ export class TypeReferenceType implements Type {
|
|||
)
|
||||
}
|
||||
|
||||
toString() {
|
||||
public toString() {
|
||||
return `${this.kind}<${this.args.map(a => a.toString()).join(", ")}>`
|
||||
}
|
||||
|
||||
convert(argument) {
|
||||
public convert(argument) {
|
||||
throw new Error("Conversion of simple type references not implemented.")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
import { Type } from "./Type"
|
||||
|
||||
export class UnionType implements Type {
|
||||
kind = "union"
|
||||
public kind = "union"
|
||||
|
||||
constructor(public types: Type[]) {}
|
||||
|
||||
toConstructor() {
|
||||
public toConstructor() {
|
||||
return (
|
||||
`new UnionType([` +
|
||||
// Convert every type to its string constructor representation
|
||||
|
@ -14,12 +14,12 @@ export class UnionType implements Type {
|
|||
)
|
||||
}
|
||||
|
||||
toString() {
|
||||
public toString() {
|
||||
return this.types.map(t => t.toString()).join(" | ")
|
||||
}
|
||||
|
||||
convert(argument) {
|
||||
for (let t of this.types) {
|
||||
public convert(argument) {
|
||||
for (const t of this.types) {
|
||||
try {
|
||||
return t.convert(argument)
|
||||
} catch (e) {}
|
||||
|
|
|
@ -1,20 +1,20 @@
|
|||
import { Type } from "./Type"
|
||||
|
||||
export class VoidType implements Type {
|
||||
static instance = new VoidType()
|
||||
kind = "void"
|
||||
public static instance = new VoidType()
|
||||
public kind = "void"
|
||||
|
||||
constructor() {}
|
||||
|
||||
toConstructor() {
|
||||
public toConstructor() {
|
||||
return "VoidType.instance"
|
||||
}
|
||||
|
||||
toString() {
|
||||
public toString() {
|
||||
return this.kind
|
||||
}
|
||||
|
||||
convert(argument) {
|
||||
public convert(argument) {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue