Skip to content

Commit

Permalink
#94, what we get out, we can set back.
Browse files Browse the repository at this point in the history
  • Loading branch information
ajvincent committed Jul 6, 2024
1 parent a5a1564 commit 0bc013a
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 40 deletions.
8 changes: 1 addition & 7 deletions stage_2_integration/source/bootstrap/adjustForOverloads.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import assert from "node:assert/strict";

import {
/*
type ClassDeclaration,
type ClassExpression,
*/
type ConstructorDeclaration,
type ConstructorDeclarationStructure,
type ConstructorDeclarationOverloadStructure,
Expand All @@ -13,9 +10,6 @@ import {
type MethodDeclaration,
type MethodDeclarationStructure,
type MethodDeclarationOverloadStructure,
/*
type ObjectLiteralExpression,
*/
type StatementedNodeStructure,
Structure,
type Structures,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import assert from "node:assert/strict";

import {
/*
type ClassDeclaration,
type ClassExpression,
*/
type ConstructorDeclaration,
type ConstructorDeclarationStructure,
type ConstructorDeclarationOverloadStructure,
Expand All @@ -13,9 +10,6 @@ import {
type MethodDeclaration,
type MethodDeclarationStructure,
type MethodDeclarationOverloadStructure,
/*
type ObjectLiteralExpression,
*/
type StatementedNodeStructure,
Structure,
type Structures,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,34 +51,50 @@ describe("adjustForOverloads:", () => {
describe("fixFunctionOverloads works with", () => {
function compareSourceToStructure(
source: string,
expected: StatementStructures[],
shouldLog?: boolean
expected: StatementStructures[]
): void
{
sourceFile.addStatements(source.trim());
const structure: SourceFileStructure = sourceFile.getStructure();
if (shouldLog === true)
console.debug(JSON.stringify(structure, null, 2));
fixFunctionOverloads(structure);
if (shouldLog === false)
console.debug(JSON.stringify(structure, null, 2));

expect<
(string | WriterFunction | StatementStructures)[] | string | WriterFunction
>(structure.statements!).toEqual(expected);

sourceFile.set(structure);

const actualSourceTrimmed = sourceFile.print().replace(/\n/g, " ").replace(/\s\s+/gm, " ").trim();
const expectedSourceTrimmed = source.replace(/\n/g, " ").replace(/\s\s+/gm, " ").trim();

if (actualSourceTrimmed !== expectedSourceTrimmed) {
console.error("\n");
console.error(actualSourceTrimmed);
console.error(expectedSourceTrimmed);
const minLength = Math.min(actualSourceTrimmed.length, expectedSourceTrimmed.length);
let matchIndex: number;
for (matchIndex = 0; matchIndex < minLength; matchIndex++) {
if (actualSourceTrimmed[matchIndex] !== expectedSourceTrimmed[matchIndex])
break;
}
console.error(" ".repeat(matchIndex) + "^");
}

expect(actualSourceTrimmed).toEqual(expectedSourceTrimmed);
}

it("functions having no overloads", () => {
compareSourceToStructure(
`
function foo(x: number): void {
void(x);
void (x);
}
`,
[
{
"name": "foo",
"statements": [
"void(x);"
"void (x);"
],
"parameters": [
{
Expand Down Expand Up @@ -112,16 +128,16 @@ function foo(x: number): void {
it("functions having an overload", () => {
compareSourceToStructure(
`
function foo(x: number, y: string): void
function foo(x: number, y: string): void;
function foo(x: number): void {
void(x);
void (x);
}
`,
[
{
"name": "foo",
"statements": [
"void(x);"
"void (x);"
],
"parameters": [
{
Expand Down Expand Up @@ -194,13 +210,13 @@ function foo(x: number): void {
compareSourceToStructure(
`
class Bar {
constructor(x: number, y: string, z: boolean)
constructor(x: number, y: string)
constructor(x: number, y: string, z: boolean);
constructor(x: number, y: string);
constructor(x: number)
{
void(x);
void(y);
void(z);
void (x);
void (y);
void (z);
}
}
`,
Expand Down Expand Up @@ -306,7 +322,9 @@ class Bar {
},
],
"statements": [
"void(x);", "void(y);", "void(z);"
"void (x);",
"void (y);",
"void (z);"
],
"docs": [],
"typeParameters": [],
Expand Down Expand Up @@ -337,14 +355,14 @@ class Bar {
compareSourceToStructure(
`
class Bar {
static foo(x: number, y: string): boolean
static foo(x: number, y: string): boolean;
static foo(x: number): boolean
{
return Boolean(x);
}
foo(x: number, y: string, z: boolean): boolean
foo(x: number, y: string): boolean
foo(x: number, y: string, z: boolean): boolean;
foo(x: number, y: string): boolean;
foo(x: number): boolean
{
return Boolean(x);
Expand Down Expand Up @@ -1411,9 +1429,3 @@ declare class Bar {
});
});
});

xdescribe("all these structures are writable via ts-morph after packing them down", () => {
xit("to a TypeScript file", () => {
expect(false).toBe(true);
});
});

0 comments on commit 0bc013a

Please sign in to comment.