1 | "use strict";
|
2 | var __importDefault = (this && this.__importDefault) || function (mod) {
|
3 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
4 | };
|
5 | Object.defineProperty(exports, "__esModule", { value: true });
|
6 | exports.patchCreateProgramTransformer = void 0;
|
7 | const typescript_1 = __importDefault(require("typescript"));
|
8 |
|
9 |
|
10 |
|
11 | function 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 |
|
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 | }
|
35 | exports.patchCreateProgramTransformer = patchCreateProgramTransformer;
|
36 |
|
37 |
|
\ | No newline at end of file |