UNPKG

2.36 kBJavaScriptView Raw
1"use strict";
2var __importDefault = (this && this.__importDefault) || function (mod) {
3 return (mod && mod.__esModule) ? mod : { "default": mod };
4};
5Object.defineProperty(exports, "__esModule", { value: true });
6exports.patchCreateProgramTransformer = void 0;
7const typescript_1 = __importDefault(require("typescript"));
8/* ****************************************************************************************************************** */
9// region: Utils
10/* ****************************************************************************************************************** */
11function patchCreateProgramTransformer(context) {
12 const { factory } = context;
13 let patchSuccess = false;
14 return (sourceFile) => {
15 if (sourceFile.fileName !== 'src/compiler/program.ts')
16 throw new Error('Wrong program file sent to transformer! This should be unreachable.');
17 const res = factory.updateSourceFile(sourceFile, typescript_1.default.visitNodes(sourceFile.statements, visitNode));
18 if (!patchSuccess)
19 throw new Error('Failed to patch createProgram function!');
20 return res;
21 function visitNode(node) {
22 if (typescript_1.default.isFunctionDeclaration(node) && node.name?.getText() === 'createProgram') {
23 const originalCreateProgram = factory.updateFunctionDeclaration(node, node.modifiers, node.asteriskToken, factory.createIdentifier('originalCreateProgram'), node.typeParameters, node.parameters, node.type, node.body);
24 // function createProgram() { return tsp.originalCreateProgram(...arguments); }
25 const newCreateProgram = factory.createFunctionDeclaration(undefined, undefined, 'createProgram', undefined, [], undefined, factory.createBlock([
26 factory.createReturnStatement(factory.createCallExpression(factory.createPropertyAccessExpression(factory.createIdentifier('tsp'), factory.createIdentifier('createProgram')), undefined, [factory.createSpreadElement(factory.createIdentifier('arguments'))])),
27 ]));
28 patchSuccess = true;
29 return [newCreateProgram, originalCreateProgram];
30 }
31 return node;
32 }
33 };
34}
35exports.patchCreateProgramTransformer = patchCreateProgramTransformer;
36// endregion
37//# sourceMappingURL=patch-create-program.js.map
\No newline at end of file