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 198b0cd commit 98a9068
Show file tree
Hide file tree
Showing 18 changed files with 33 additions and 648 deletions.
2 changes: 0 additions & 2 deletions Source/Example/Output/Namespace.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
namespace MyNamespace {
;
;
export const z = (5
+ 3)
* 2;
Expand Down
6 changes: 0 additions & 6 deletions Source/Example/Output/Predefined.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,5 @@
import * as fs from "fs";
import * as path from "path";
const root = path.dirname(path.dirname(__dirname));
;
;
;
const platform = process.platform;
;
;
;
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"));
58 changes: 29 additions & 29 deletions Source/Function/Output/Transformer/Visit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ export const Fn = ((Usage, Initializer) =>

let NodeCurrent = Node;

if (ts.isEmptyStatement(NodeCurrent)) {
return {
Node: factory.createNotEmittedStatement(NodeCurrent),
Use: true,
};
}

if (ts.isVariableStatement(NodeCurrent)) {
const Declaration = NodeCurrent.declarationList.declarations;

Expand Down Expand Up @@ -53,71 +60,64 @@ export const Fn = ((Usage, Initializer) =>
}
}

// Handle identifiers
if (isIdentifier(NodeCurrent)) {
try {
const nameNode = NodeCurrent.text;
const NodeName = NodeCurrent.text;

const usageNode = Usage.get(nameNode);
const NodeUsage = Usage.get(NodeName);

const initializerNode = Get(nameNode, Initializer);
const NodeInitializer = Get(NodeName, Initializer);

if (initializerNode && usageNode === 1) {
// Check if we're in a property access expression
const parent = NodeCurrent.parent;
if (NodeInitializer && NodeUsage === 1) {
const NodeParent = NodeCurrent.parent;

if (
isPropertyAccessExpression(parent) &&
parent.name === NodeCurrent
isPropertyAccessExpression(NodeParent) &&
NodeParent.name === NodeCurrent
) {
// If we're the name part of a property access, keep as identifier
return {
Node: NodeCurrent,
Use: false,
};
}

// For identifiers, create new identifier
if (isIdentifier(initializerNode)) {
if (isIdentifier(NodeInitializer)) {
return {
Node: factory.createIdentifier(
initializerNode.text,
NodeInitializer.text,
),
Use: true,
};
}

// For expressions, preserve the node structure
const updatedNode = ts.transform(initializerNode, [
(_Context) => (node) => node,
]).transformed[0];

return {
Node: updatedNode as Node,
Node: ts.transform(NodeInitializer, [
(_Context) => (node) => node,
]).transformed[0] as Node,
Use: true,
};
}
} catch (error) {
} catch (_Error) {
console.error(
"Error during identifier replacement:",
error,
_Error,
);
}
}

const { Node: NodeProcessed, Use: UseChildren } = ((
const { Node: NodeOutput, Use: UseChildren } = ((
parentNode: Node,
): { Node: Node; Use: boolean } => {
let Use = false;

const NodeNew = visitEachChild(
parentNode,
(child) => {
const result = Eliminate(child);
const Output = Eliminate(child);

Use = Use || result.Use;
Use = Use || Output.Use;

return result.Node;
return Output.Node;
},
Context,
);
Expand All @@ -126,7 +126,7 @@ export const Fn = ((Usage, Initializer) =>
})(NodeCurrent);

return {
Node: NodeProcessed,
Node: NodeOutput,
Use: Use || UseChildren,
};
};
Expand All @@ -136,13 +136,13 @@ export const Fn = ((Usage, Initializer) =>
let Use = true;

while (Use) {
const Processed = Eliminate(NodeCurrent);
const Output = Eliminate(NodeCurrent);

if (!Processed.Use) {
if (!Output.Use) {
Use = false;
}

NodeCurrent = Processed.Node;
NodeCurrent = Output.Node;
}

return NodeCurrent;
Expand Down
1 change: 0 additions & 1 deletion Target/Example/Input/Decorator.js

This file was deleted.

1 change: 0 additions & 1 deletion Target/Example/Input/Namespace.js

This file was deleted.

1 change: 0 additions & 1 deletion Target/Example/Input/Predefined.js

This file was deleted.

1 change: 0 additions & 1 deletion Target/Example/Output/Decorator.js

This file was deleted.

1 change: 0 additions & 1 deletion Target/Example/Output/Namespace.js

This file was deleted.

2 changes: 1 addition & 1 deletion Target/Example/Output/Predefined.js

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

Loading

0 comments on commit 98a9068

Please sign in to comment.