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 511644d commit dfea359
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 24 deletions.
4 changes: 2 additions & 2 deletions Example/Output/Dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1351,8 +1351,8 @@ export function finalHandler<T extends Event>(fn: (event: T) => unknown): (event
}
export function domContentLoaded(targetWindow: Window): Promise<void> {
return new Promise<void>((resolve) => {
const readyState = targetWindow.document.readyState;
if (readyState === "complete" ||
if (targetWindow.document.readyState
=== "complete" ||
(targetWindow.document && targetWindow.document.body !== null)) {
resolve(undefined);
}
Expand Down
3 changes: 1 addition & 2 deletions Example/Output/Predefined.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@ import * as fs from "fs";
import * as path from "path";
const root = path.dirname(path.dirname(__dirname));
const platform = process.platform;
const arch = process.arch;
console.log(path.join(root, ".build", "node", `v${/^target="(.*)"$/m.exec(fs.readFileSync(path.join(root, "remote", ".npmrc"), "utf8"))![1]}`, `${platform}-${arch}`, platform === "win32" ? "node.exe" : "node"));
console.log(path.join(root, ".build", "node", `v${/^target="(.*)"$/m.exec(fs.readFileSync(path.join(root, "remote", ".npmrc"), "utf8"))![1]}`, `${platform}-${process.arch}`, platform === "win32" ? "node.exe" : "node"));
35 changes: 16 additions & 19 deletions Source/Function/Output/Visit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ export const Fn = ((...[Usage, Initializer]) =>

const visitedNodes = new Set<string>();

// Add node path tracking to prevent infinite recursion
const nodeId = `${ts.SyntaxKind[Node.kind]}-${Node.pos}-${Node.end}`;

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

return;
}

Expand All @@ -43,33 +43,30 @@ export const Fn = ((...[Usage, Initializer]) =>
if (ts.isVariableDeclaration(Node) && Node.initializer) {
const NameNode = Node.name.getText();

// Improved self-reference check
const containsSelfReference = (() => {
let hasSelfRef = false;

const checkNode = (node: Node) => {
if (hasSelfRef) return;
const SelfReferential = (() => {
let True = false;

if (ts.isIdentifier(node) && node.getText() === NameNode) {
// Skip if this identifier is part of a property access
const parent = node.parent;
const Visit = (node: Node) => {
if (ts.isIdentifier(node)) {
if (
!ts.isPropertyAccessExpression(parent) ||
parent.name === node
node.text === NameNode &&
!ts.isTemplateExpression(node.parent) &&
!ts.isTemplateSpan(node.parent) &&
!ts.isPropertyAccessExpression(node.parent)
) {
hasSelfRef = true;
True = true;
}
}
ts.forEachChild(node, checkNode);

ts.forEachChild(node, Visit);
};

checkNode(Node.initializer);
return hasSelfRef;
Visit(Node.initializer);

return True;
})();

// Skip self-referential initializers
if (containsSelfReference) {
if (SelfReferential) {
console.debug(
`Skipping self-referential initializer for: ${NameNode}`,
);
Expand Down
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 dfea359

Please sign in to comment.