Comparing version 0.9.1 to 0.9.2
{ | ||
"name": "martok", | ||
"version": "0.9.1", | ||
"version": "0.9.2", | ||
"description": "", | ||
@@ -14,3 +14,5 @@ "main": "dist/src/index.js", | ||
"tagged": "ts-node src/index.ts tests/comparisons/single/tagged.d.ts -o ./schema/martok --package net.sarazan.martok --datePattern standard", | ||
"tagged2": "ts-node src/index.ts tests/comparisons/single/tagged2.d.ts -o ./schema/martok --package net.sarazan.martok --datePattern standard", | ||
"literal": "ts-node src/index.ts tests/comparisons/single/stringLiteral.d.ts -o ./schema/martok --package net.sarazan.martok --datePattern standard", | ||
"faceoff": "ts-node src/index.ts ../../volley/faceoff-backend/src/types -o ./schema/faceoff --package net.sarazan.martok --datePattern standard", | ||
"lint": "eslint . --ext .ts" | ||
@@ -17,0 +19,0 @@ }, |
@@ -93,4 +93,6 @@ import { Martok } from "../Martok"; | ||
.setAnnotation("@Serializable") | ||
.addModifier("data") | ||
.addInternalClasses(...this.generateInnerKlasses(members)); | ||
if (members.length) { | ||
result.addModifier("data"); | ||
} | ||
if (options?.extendSealed) { | ||
@@ -189,8 +191,9 @@ result.setExtends({ | ||
const type = getMemberType(this.checker, node.type); | ||
const ref = this.checker.getTypeFromTypeNode(node.type); | ||
if (type === InternalSymbolName.Type) return undefined; // TODO improve this. | ||
if (!members.length) { | ||
// TODO fix dirty hack for empty types that turn into self-aliases. | ||
if (!members.length && name !== type) { | ||
return `typealias ${name} = ${type}\n`; | ||
} | ||
if (isTypeReferenceNode(node.type)) { | ||
const ref = this.checker.getTypeFromTypeNode(node.type); | ||
const symbol = ref.aliasSymbol ?? ref.getSymbol(); | ||
@@ -197,0 +200,0 @@ return `typealias ${name} = ${symbol?.name}`; |
@@ -37,17 +37,24 @@ import { Martok } from "../Martok"; | ||
): Klass | undefined { | ||
if ( | ||
!( | ||
isTypeAliasDeclaration(node) && | ||
isIntersectionTypeNode(node.type) && | ||
isTypeLiteralNode(node.type.types[0]) && | ||
isParenthesizedTypeNode(node.type.types[1]) && | ||
isUnionTypeNode(node.type.types[1].type) | ||
) | ||
) { | ||
const members: TypeElement[] = []; | ||
if (!isTypeAliasDeclaration(node)) return undefined; | ||
const type = node.type; | ||
if (!(isIntersectionTypeNode(type) || isUnionTypeNode(type))) | ||
return undefined; | ||
const types = type.types.map((value) => { | ||
if (isParenthesizedTypeNode(value)) return value.type; | ||
return value; | ||
}); | ||
for (const type of types) { | ||
if (isTypeLiteralNode(type)) { | ||
members.push(...type.members); | ||
} | ||
} | ||
const union = [type, ...types].find((value) => isUnionTypeNode(value)) as | ||
| UnionTypeNode | ||
| undefined; | ||
if (!union) { | ||
return undefined; | ||
} | ||
const tag = this.getTag(union); | ||
const members = [...getMembers(node, this.checker, true)]; | ||
const union = node.type.types[1].type; | ||
const tag = this.getTag(union); | ||
if (!tag) return undefined; | ||
@@ -65,7 +72,7 @@ const result = new Klass(name) | ||
) | ||
// .addMembers({ | ||
// name: tag.name, | ||
// type: "String", | ||
// abstract: true, | ||
// }) | ||
.addMembers({ | ||
name: tag.name, | ||
type: "String", | ||
abstract: true, | ||
}) | ||
.addInternalClasses( | ||
@@ -82,4 +89,5 @@ ...this.martok.declarations.klasses.generateInnerKlasses(members) | ||
const [type1, ...others] = node.types; | ||
if (!isTypeLiteralNode(type1)) return undefined; | ||
outer: for (const prop1 of type1.members) { | ||
const members1 = getMembers(type1, this.checker, false); | ||
// if (!isTypeLiteralNode(type1)) return undefined; | ||
outer: for (const prop1 of members1) { | ||
const name = prop1.name?.getText(); | ||
@@ -99,6 +107,5 @@ if (!name) continue; | ||
for (const type2 of others) { | ||
if (!isTypeLiteralNode(type2)) continue outer; | ||
const prop2 = type2.members.find( | ||
(value) => value.name?.getText() === name | ||
); | ||
// if (!isTypeLiteralNode(type2)) continue outer; | ||
const members2 = getMembers(type2, this.checker, false); | ||
const prop2 = members2.find((value) => value.name?.getText() === name); | ||
if (!prop2?.name) continue outer; | ||
@@ -105,0 +112,0 @@ const k2 = this.getTagValue(prop2); |
@@ -87,7 +87,7 @@ import * as ts from "typescript"; | ||
this.nameScope.push(scope); | ||
// console.log(`>`, this.nameScope); | ||
console.log(`>`, this.nameScope); | ||
} | ||
public popNameScope(): string { | ||
const result = this.nameScope.pop()!; | ||
// console.log(`>`, this.nameScope); | ||
console.log(`>`, this.nameScope); | ||
return result; | ||
@@ -97,3 +97,3 @@ } | ||
private processFile(file: SourceFile): MartokOutFile { | ||
// console.log(`Process File: ${file.fileName}...`); | ||
console.log(`Process File: ${file.fileName}...`); | ||
const name = TsHelper.getBaseFileName(file.fileName); | ||
@@ -100,0 +100,0 @@ const pkg = this.getFilePackage(file); |
115572
102
2426