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