-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
88 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { ASTNode } from "../types"; | ||
import { MagicastError } from "../error"; | ||
import { createProxy } from "./_utils"; | ||
import { proxifyArrayElements } from "./array"; | ||
import { ProxifiedModule, ProxifiedNewExpression } from "./types"; | ||
|
||
export function proxifyNewExpression<T extends []>( | ||
node: ASTNode, | ||
mod?: ProxifiedModule | ||
): ProxifiedNewExpression<T> { | ||
if (node.type !== "NewExpression") { | ||
throw new MagicastError("Not a new expression"); | ||
} | ||
|
||
function stringifyExpression(node: ASTNode): string { | ||
if (node.type === "Identifier") { | ||
return node.name; | ||
} | ||
if (node.type === "MemberExpression") { | ||
return `${stringifyExpression(node.object)}.${stringifyExpression( | ||
node.property | ||
)}`; | ||
} | ||
throw new MagicastError("Not implemented"); | ||
} | ||
|
||
const argumentsProxy = proxifyArrayElements<T>(node, node.arguments, mod); | ||
|
||
return createProxy( | ||
node, | ||
{ | ||
$type: "new-expression", | ||
$callee: stringifyExpression(node.callee as any), | ||
$args: argumentsProxy, | ||
}, | ||
{} | ||
) as ProxifiedNewExpression<T>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters