Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
NikolaRHristov committed Nov 2, 2024
1 parent 6e93c77 commit 447adef
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 26 deletions.
18 changes: 8 additions & 10 deletions Source/Function/Output/Transformer/Visit.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
import type Interface from "@Interface/Output/Transformer/Visit.js";
import {
factory,
isIdentifier,
isPropertyAccessExpression,
visitEachChild,
type Node,
} from "typescript";
import type { Node } from "typescript";

/**
* @module Output
Expand Down Expand Up @@ -107,7 +101,7 @@ export const Fn = ((Usage, Initializer) =>
const NodeParent = NodeCurrent.parent;

if (
isPropertyAccessExpression(NodeParent) &&
ts.isPropertyAccessExpression(NodeParent) &&
NodeParent.name === NodeCurrent
) {
return {
Expand Down Expand Up @@ -147,7 +141,7 @@ export const Fn = ((Usage, Initializer) =>

let Return = false;

const NodeNew = visitEachChild(
const NodeNew = ts.visitEachChild(
NodeParent,
(NodeChild) => {
if (Return) {
Expand Down Expand Up @@ -217,7 +211,11 @@ export const Fn = ((Usage, Initializer) =>
return NodeCurrent;
}) satisfies Interface as Interface;

export const { default: ts } = await import("typescript");
export const {
default: ts,
isIdentifier,
factory,
} = await import("typescript");

export const { default: Get } = await import("@Function/Output/Visit/Get.js");

Expand Down
35 changes: 23 additions & 12 deletions Source/Function/Output/Visit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,19 @@ export const Fn = ((...[Usage, Initializer]) =>

const visitedNodes = new Set<string>();

const nodeId = `${ts.SyntaxKind[Node.kind]}-${Node.pos}-${Node.end}`;
const ID = `${ts.SyntaxKind[Node.kind]}-${Node.pos}-${Node.end}`;

if (visitedNodes.has(nodeId)) {
if (visitedNodes.has(ID)) {
console.warn("Warning: Circular reference detected", {
nodeType: ts.SyntaxKind[Node.kind],
position: Node.pos,
TypeNode: ts.SyntaxKind[Node.kind],
Position: Node.pos,
Text: Node.getText?.(),
});

return;
}

visitedNodes.add(nodeId);
visitedNodes.add(ID);

ts.forEachChild(Node, Fn(Usage, Initializer));

Expand All @@ -33,8 +34,8 @@ export const Fn = ((...[Usage, Initializer]) =>
Initializer.size >= MAX_INITIALIZER_SIZE
) {
console.warn("Warning: Maximum map size reached", {
usageSize: Usage.size,
initializerSize: Initializer.size,
UsageLength: Usage.size,
InitializerLength: Initializer.size,
});

return;
Expand Down Expand Up @@ -67,8 +68,13 @@ export const Fn = ((...[Usage, Initializer]) =>
})();

if (SelfReferential) {
console.debug(
`Skipping self-referential initializer for: ${NameNode}`,
console.info(
`Info: Skipping self-referential initializer for: ${NameNode}`,
{
TypeNode: ts.SyntaxKind[Node.kind],
Position: Node.pos,
Text: Node.getText?.(),
},
);

return;
Expand All @@ -87,13 +93,18 @@ export const Fn = ((...[Usage, Initializer]) =>
const NameNode = Node.getText();

if (!ts.isVariableDeclaration(Node.parent)) {
const currentCount = Usage.get(NameNode) ?? 0;
const Count = Usage.get(NameNode) ?? 0;

if (currentCount < MAX_USAGE_COUNT) {
Usage.set(NameNode, currentCount + 1);
if (Count < MAX_USAGE_COUNT) {
Usage.set(NameNode, Count + 1);
} else {
console.warn(
`Warning: Maximum usage count reached for identifier: ${NameNode}`,
{
TypeNode: ts.SyntaxKind[Node.kind],
Position: Node.pos,
Text: Node.getText?.(),
},
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion Target/Class/Eliminate.js

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

2 changes: 1 addition & 1 deletion Target/Function/Output/Transformer/Visit.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ import type Interface from "@Interface/Output/Transformer/Visit.js";
*
*/
export declare const Fn: Interface;
export declare const ts: typeof import("typescript");
export declare const ts: typeof import("typescript"), isIdentifier: typeof import("typescript").isIdentifier, factory: import("typescript").NodeFactory;
export declare const Get: import("../../../Interface/Output/Visit/Get").default;
export default Fn;
2 changes: 1 addition & 1 deletion Target/Function/Output/Transformer/Visit.js

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

2 changes: 1 addition & 1 deletion Target/Function/Output/Visit.js

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

0 comments on commit 447adef

Please sign in to comment.