UNPKG

2.06 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.hookTscExecTransformer = void 0;
7const typescript_1 = __importDefault(require("typescript"));
8/* ****************************************************************************************************************** */
9// region: Utils
10/* ****************************************************************************************************************** */
11function hookTscExecTransformer(context) {
12 const { factory } = context;
13 let patchSuccess = false;
14 return (sourceFile) => {
15 if (sourceFile.fileName !== 'src/tsc/tsc.ts')
16 throw new Error('Wrong emitter file sent to transformer! This should be unreachable.');
17 const res = factory.updateSourceFile(sourceFile, typescript_1.default.visitNodes(sourceFile.statements, visitNodes));
18 if (!patchSuccess)
19 throw new Error('Failed to patch tsc exec statement early return!');
20 return res;
21 function visitNodes(node) {
22 if (typescript_1.default.isExpressionStatement(node) && typescript_1.default.isCallExpression(node.expression) &&
23 typescript_1.default.isIdentifier(node.expression.expression) && node.expression.expression.text === 'executeCommandLine') {
24 patchSuccess = true;
25 return factory.createExpressionStatement(factory.createBinaryExpression(factory.createPropertyAccessExpression(factory.createIdentifier("tsp"), factory.createIdentifier("execTsc")), factory.createToken(typescript_1.default.SyntaxKind.EqualsToken), factory.createArrowFunction(undefined, undefined, [], undefined, factory.createToken(typescript_1.default.SyntaxKind.EqualsGreaterThanToken), node.expression)));
26 }
27 return node;
28 }
29 };
30}
31exports.hookTscExecTransformer = hookTscExecTransformer;
32// endregion
33//# sourceMappingURL=hook-tsc-exec.js.map
\No newline at end of file