restfuncs-transformer 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.js CHANGED
@@ -1,10 +1,34 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
2
25
  Object.defineProperty(exports, "__esModule", { value: true });
3
26
  exports.transformerVersion = void 0;
4
27
  const AddRemoteMethodsMeta_1 = require("./AddRemoteMethodsMeta");
5
28
  const transformerUtil_1 = require("./transformerUtil");
29
+ const fs = __importStar(require("node:fs"));
6
30
  // From: https://github.com/nonara/ts-patch/discussions/29#discussioncomment-325979
7
- exports.transformerVersion = { major: 1, feature: 1 };
31
+ exports.transformerVersion = { major: 1, feature: 2 };
8
32
  /* ****************************************************************************************************************** */
9
33
  // region: Helpers
10
34
  /* ****************************************************************************************************************** */
@@ -40,18 +64,30 @@ function transformProgram(program, host, config, extras) {
40
64
  const compilerHost = getPatchedHost(host, tsInstance, compilerOptions);
41
65
  const rootFileNames = program.getRootFileNames().map(tsInstance.normalizePath);
42
66
  const transformerFactoryOOP = new transformerUtil_1.TransformerFactoryOOP(AddRemoteMethodsMeta_1.AddRemoteMethodsMeta);
67
+ AddRemoteMethodsMeta_1.AddRemoteMethodsMeta.squeezeDeclarationsIntoOneLine = !(config.pretty);
68
+ // TODO: Do we still need all this transformer stuff or can we throw that out and use a simple file vistor ? Cause we don't actually **transform** a SourceFile anymore, but just patch text content and not an AST.
43
69
  /* Transform AST */
44
70
  tsInstance.transform(
45
- /* sourceFiles */ program.getSourceFiles().filter(sourceFile => rootFileNames.includes(sourceFile.fileName)),
71
+ /* sourceFiles */ program.getSourceFiles().filter(sourceFile => rootFileNames.includes(sourceFile.fileName) && !sourceFile.fileName.includes("after_restfuncs-transformer")),
46
72
  /* transformerFactoryOOP */ [transformerFactoryOOP.asFunction], compilerOptions);
47
73
  transformerFactoryOOP.transformRunsDone.forEach(transformRun => {
48
- if (transformRun.astWasModified) {
74
+ if (transformRun.result.patches.length > 0) { // wants to make changes to the file ?
49
75
  /* Render modified files and create new SourceFiles for them to use in host's cache */
50
- const { printFile } = tsInstance.createPrinter();
51
76
  const sourceFile = transformRun.sourceFile;
52
- const updatedSourceFile = tsInstance.createSourceFile(sourceFile.fileName, printFile(sourceFile), sourceFile.languageVersion);
53
- updatedSourceFile.version = `${sourceFile.version}_restfuncs_${exports.transformerVersion.major}.${exports.transformerVersion.feature}`;
54
- compilerHost.fileCache.set(sourceFile.fileName, updatedSourceFile);
77
+ const sourceText = fs.readFileSync(sourceFile.fileName, { encoding: "utf8" });
78
+ const patchedSourceText = transformRun.result.applyPatches(sourceText);
79
+ if (config.debug) {
80
+ // Write content to file so you can better inspect it.
81
+ const newFileName = sourceFile.fileName.replace(/\.ts$/, ".after_restfuncs-transformer.tmp");
82
+ if (newFileName === sourceFile.fileName) {
83
+ throw new Error("invalid file name");
84
+ }
85
+ fs.writeFileSync(newFileName, patchedSourceText, { encoding: "utf8" });
86
+ }
87
+ // Insert patchedSourceText into host's cache:
88
+ const newSourceFile = tsInstance.createSourceFile(sourceFile.fileName, patchedSourceText, sourceFile.languageVersion);
89
+ newSourceFile.version = `${sourceFile.version}_restfuncs_${exports.transformerVersion.major}.${exports.transformerVersion.feature}`;
90
+ compilerHost.fileCache.set(sourceFile.fileName, newSourceFile);
55
91
  }
56
92
  });
57
93
  /* Re-create Program instance */
package/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;;AAEA,iEAA4D;AAC5D,uDAA0E;AAE1E,mFAAmF;AAEtE,QAAA,kBAAkB,GAAG,EAAC,KAAK,EAAE,CAAC,EAAG,OAAO,EAAE,CAAC,EAAE,CAAA;AAE1D,wHAAwH;AACxH,kBAAkB;AAClB,wHAAwH;AAExH;;GAEG;AACH,SAAS,cAAc,CACnB,SAAmC,EACnC,UAAqB,EACrB,eAAgC;IAGhC,MAAM,SAAS,GAAG,IAAI,GAAG,EAAE,CAAC;IAC5B,MAAM,YAAY,GAAG,SAAS,aAAT,SAAS,cAAT,SAAS,GAAI,UAAU,CAAC,kBAAkB,CAAC,eAAe,EAAE,IAAI,CAAC,CAAC;IACvF,MAAM,qBAAqB,GAAG,YAAY,CAAC,aAAa,CAAC;IAEzD,OAAO,MAAM,CAAC,MAAM,CAAC,YAAY,EAAE;QAC/B,aAAa,CAAC,QAAgB,EAAE,eAAgC;YAC5D,QAAQ,GAAG,UAAU,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;YAC9C,IAAI,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC;gBAAE,OAAO,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;YAE5D,MAAM,UAAU,GAAG,qBAAqB,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC,IAAI,CAAC,SAAS,CAAQ,CAAC,CAAC;YACrF,SAAS,CAAC,GAAG,CAAC,QAAQ,EAAE,UAAU,CAAC,CAA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UAAU,CAAC,aAAa,CAAC,aAAa,EAAE,eAAe,EAAE,YAAY,CAAC,CAAC;AAClF,CAAC;AAtDD,mCAsDC;AAED,YAAY"}
package/index.ts CHANGED
@@ -2,10 +2,11 @@ import ts, {CompilerHost, CompilerOptions, Program, SourceFile} from 'typescript
2
2
  import {PluginConfig, ProgramTransformerExtras} from "ts-patch";
3
3
  import {AddRemoteMethodsMeta} from "./AddRemoteMethodsMeta";
4
4
  import {FileTransformRun, TransformerFactoryOOP} from "./transformerUtil";
5
+ import * as fs from "node:fs";
5
6
 
6
7
  // From: https://github.com/nonara/ts-patch/discussions/29#discussioncomment-325979
7
8
 
8
- export const transformerVersion = {major: 1, feature: 1 }
9
+ export const transformerVersion = {major: 1, feature: 2 }
9
10
 
10
11
  /* ****************************************************************************************************************** */
11
12
  // region: Helpers
@@ -61,22 +62,37 @@ export default function transformProgram(
61
62
  const rootFileNames = program.getRootFileNames().map(tsInstance.normalizePath);
62
63
 
63
64
  const transformerFactoryOOP = new TransformerFactoryOOP(AddRemoteMethodsMeta);
65
+ AddRemoteMethodsMeta.squeezeDeclarationsIntoOneLine = !((config as any).pretty);
66
+
67
+ // TODO: Do we still need all this transformer stuff or can we throw that out and use a simple file vistor ? Cause we don't actually **transform** a SourceFile anymore, but just patch text content and not an AST.
64
68
 
65
69
  /* Transform AST */
66
70
  tsInstance.transform(
67
- /* sourceFiles */ program.getSourceFiles().filter(sourceFile => rootFileNames.includes(sourceFile.fileName)),
71
+ /* sourceFiles */ program.getSourceFiles().filter(sourceFile => rootFileNames.includes(sourceFile.fileName) && !sourceFile.fileName.includes("after_restfuncs-transformer")),
68
72
  /* transformerFactoryOOP */ [ transformerFactoryOOP.asFunction ],
69
73
  compilerOptions
70
74
  )
71
75
 
72
76
  transformerFactoryOOP.transformRunsDone.forEach(transformRun => {
73
- if(transformRun.astWasModified) {
77
+ if(transformRun.result.patches.length > 0) { // wants to make changes to the file ?
74
78
  /* Render modified files and create new SourceFiles for them to use in host's cache */
75
- const {printFile} = tsInstance.createPrinter();
76
79
  const sourceFile = transformRun.sourceFile;
77
- const updatedSourceFile = tsInstance.createSourceFile(sourceFile.fileName, printFile(sourceFile), sourceFile.languageVersion);
78
- updatedSourceFile.version = `${sourceFile.version}_restfuncs_${transformerVersion.major}.${transformerVersion.feature}`;
79
- compilerHost.fileCache.set(sourceFile.fileName, updatedSourceFile);
80
+ const sourceText = fs.readFileSync(sourceFile.fileName, {encoding: "utf8"});
81
+ const patchedSourceText = transformRun.result.applyPatches(sourceText);
82
+ if((config as any).debug) {
83
+ // Write content to file so you can better inspect it.
84
+ const newFileName = sourceFile.fileName.replace(/\.ts$/,".after_restfuncs-transformer.tmp");
85
+ if(newFileName === sourceFile.fileName) {
86
+ throw new Error("invalid file name")
87
+ }
88
+ fs.writeFileSync(newFileName, patchedSourceText, {encoding: "utf8"});
89
+ }
90
+
91
+
92
+ // Insert patchedSourceText into host's cache:
93
+ const newSourceFile = tsInstance.createSourceFile(sourceFile.fileName, patchedSourceText, sourceFile.languageVersion);
94
+ newSourceFile.version = `${sourceFile.version}_restfuncs_${transformerVersion.major}.${transformerVersion.feature}`;
95
+ compilerHost.fileCache.set(sourceFile.fileName, newSourceFile);
80
96
  }
81
97
  })
82
98
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "restfuncs-transformer",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "Enhances your classes with typescript-rtti, to make them usable with Restfuncs",
5
5
  "keywords": ["rpc","rest"],
6
6
  "author": "Boris Gingold <bogeee@bogitech.de>",
@@ -13,6 +13,7 @@
13
13
  "scripts": {
14
14
  "clean": "tsc --build --clean && rimraf dist LICENSE",
15
15
  "build": "tsc --build",
16
+ "test": "npm run build && jest --runInBand --testPathIgnorePatterns=\".*\\.ts\" --testNamePattern=\".*\"",
16
17
  "dev:playgrund": "tsx devPlayground.ts"
17
18
  },
18
19
  "exports": {
@@ -21,13 +22,16 @@
21
22
  }
22
23
  },
23
24
  "dependencies": {
24
- "typescript": "5.0 || 5.1 || 5.3"
25
+ "typescript": "5.0 || 5.1 || 5.3",
26
+ "restfuncs-common": "^3.1.0"
25
27
  },
26
28
  "peerDependencies": {
27
29
  "restfuncs-server": ">=2"
28
30
  },
29
31
  "devDependencies": {
30
32
  "@types/ts-expose-internals": "npm:ts-expose-internals@5.3.3",
31
- "rimraf": "=5.0.5"
33
+ "rimraf": "=5.0.5",
34
+ "ts-jest": "^29.0.3",
35
+ "@types/jest": "^29.2.2"
32
36
  }
33
37
  }
package/readme.md CHANGED
@@ -4,30 +4,56 @@ This transformer prepares `ServerSession` subclasses for Typia and adds jsDoc in
4
4
  ## Usage
5
5
  [Here's how to use it](https://github.com/bogeeee/restfuncs/tree/3.x/readme.md#setting-up-the-build-here-it-gets-a-bit-nasty-)
6
6
 
7
+ ## Debugging parameters
8
+ Insert these into the `{ "transform": "restfuncs-transformer", ...}` block.
9
+ - debug: Set to true to dump the output of transformed **and affected** files each into a file named ...after_restfuncs-transformer.tmp
10
+ - pretty: Pretty print the output (normally it is squeezed into one line to preserve line numbers and keep source maps intact)
11
+
7
12
 
8
13
  ## How the transformer chain works
9
14
  Here is, how the restfuncs-transformer, typia transformer and typescript-rtti work together:
10
- 1. The `restfuncs-transformer` scans for all `@remote` methods and, at the bottom of inside their class, it adds the following code (here for "myMethod"):
15
+ 1. The `restfuncs-transformer` scans for all `@remote` methods and, at the bottom of inside their class, it adds the following code (here for):
11
16
  ````typescript
17
+ @remote
18
+ async myMethod(param1: string, someCallbackFn: (p:number) => Promise<string>);
19
+ ````
20
+
21
+ results in adding this to the class body:
12
22
 
23
+ ````typescript
24
+ import _rf_typia from "typia";
13
25
  /**
14
26
  * Code is generated by the restfuncs-transformer during compile-time
15
27
  */
16
28
  static getRemoteMethodsMeta(): (typeof this.type_remoteMethodsMeta) {
17
- this.__hello_developer__make_sure_your_class_is_a_subclass_of_ServerSession // Give a friendly error message when this is not the case. Otherwise the following statement "const typia = ..." would fail and leaves the user wondering.
18
- let typia = this.typiaRuntime; // We need a "typia" defined in the scope, but let restfuncs manage where that dependency comes from
19
- return {
29
+ this.__hello_developer__make_sure_your_class_is_a_subclass_of_ServerSession // Attempt to give a friendly error message when this is not the case. Otherwise the previous line would fail and leaves the user wondering.
30
+ type CallbackPlaceholder<DECL_INDEX extends number> = string & _rf_typia.tags.TagBase<{kind: "callbackFn", target: "string", value: DECL_INDEX, validate: `onValidateCallbackArg($input, ${DECL_INDEX})`}>; // Create a [custom tag](https://typia.io/docs/validators/tags/#customization), that can be used via `CallbackPlaceholder<n>`. During validation, this tag then calls onValidateCallbackArg.
31
+ const result= {
20
32
  transformerVersion: {major: XX, feature: XX },
21
33
  instanceMethods: {
22
34
  "myMethod": {
23
35
  arguments: {
24
- validateEquals: (args: unknown) => typia.validateEquals<Parameters<typeof this.prototype["myMethod"]>>(args),
25
- validatePrune: ...
26
- },
36
+ validateEquals: (args: unknown) => _rf_typia.validateEquals<[param1: string, someCallback: (p:number) => Promise<string>]>(args),
37
+ validatePrune: ...,
38
+ withPlaceholders: {
39
+ validateEquals: (args: unknown, onValidateCallbackArg: (placeholderId: string, declarationIndex: number) => boolean) => _rf_typia.validateEquals<[param1: string, someCallback: CallbackPlaceholder<0>]>(args),
40
+ ...
41
+ }
42
+ },
27
43
  result: {
28
- validateEquals: (value: unknown) => typia.validateEquals<Awaited<ReturnType<typeof this.prototype["myMethod"]>>>(value),
44
+ validateEquals: (value: unknown) => _rf_typia.validateEquals<Awaited<ReturnType<typeof this.prototype["myMethod"]>>>(value),
29
45
  ...
30
46
  },
47
+ callbacks: [{ // here for the `someCallbackFn: (p:number) => Promise<string>` declaration
48
+ arguments: {
49
+ validateEquals: (args: unknown) => _rf_typia.validateEquals<[p: number]>(args),
50
+ validatePrune: ...
51
+ },
52
+ awaitedResult: {
53
+ validateEquals: (value: unknown) => _rf_typia.validateEquals<string>(value),
54
+ ...
55
+ }
56
+ }],
31
57
  jsDoc: {
32
58
  comment: "text with <strong>markup</strong>",
33
59
  params: {a: "text..."},
@@ -35,7 +61,9 @@ static getRemoteMethodsMeta(): (typeof this.type_remoteMethodsMeta) {
35
61
  }
36
62
  }
37
63
  }
38
- }
64
+ };
65
+
66
+ return result; // Code style note for this line: Why not do `return {...}` directly ? This tiny difference allows for extra properties which ensure backward compatibility with older "restfuncs-server" packages.
39
67
  }
40
68
  ````
41
69
 
@@ -46,5 +46,15 @@ export declare abstract class FileTransformRun {
46
46
  */
47
47
  getIdentifierName(node: Node, escaped?: boolean): any;
48
48
  }
49
+ export declare class TextPatch {
50
+ /**
51
+ * character index (not byte index) => content to insert
52
+ */
53
+ patches: {
54
+ position: number;
55
+ contentToInsert: string;
56
+ }[];
57
+ applyPatches(content: string): string;
58
+ }
49
59
  export {};
50
60
  //# sourceMappingURL=transformerUtil.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"transformerUtil.d.ts","sourceRoot":"","sources":["transformerUtil.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAC,IAAI,EAAE,UAAU,EAAc,qBAAqB,EAAE,kBAAkB,EAAC,MAAM,YAAY,CAAC;AAEvG,KAAK,OAAO,CAAC,CAAC,IAAI;IACd,KAAI,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,CAAC,CAAA;CACzB,CAAA;AAED;;GAEG;AACH,qBAAa,qBAAqB,CAAC,EAAE,SAAS,gBAAgB;IAC1D,iBAAiB,EAAE,EAAE,EAAE,CAAK;IAC5B,qBAAqB,EAAE,OAAO,CAAC,gBAAgB,CAAC,CAAC;gBAGrC,uBAAuB,EAAE,OAAO,CAAC,EAAE,CAAC;IAIhD;;OAEG;IACH,IAAI,UAAU,IAAI,kBAAkB,CAAC,UAAU,CAAC,CAQ/C;CACJ;AAED;;GAEG;AACH,8BAAsB,gBAAgB;IAClC,UAAU,EAAE,OAAO,EAAE,CAAC;IACtB,UAAU,EAAE,UAAU,CAAA;IACtB,OAAO,EAAE,qBAAqB,CAAC;IAC/B,WAAW,E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AE,UAAU,EAAE,UAAU,EAAE,OAAO,EAAE,qBAAqB;IAOzF,SAAS,gBAEP;IAEF;;;;OAIG;IACH,QAAQ,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI;IAGhC,SAAS,CAAC,WAAW,CAAC,IAAI,EAAE,IAAI;IAWhC;;;OAGG;IACH,OAAO,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM;IAK3B,SAAS,CAAC,IAAI,EAAE,IAAI;IAMpB;;;;;OAKG;IACH,iBAAiB,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,UAAQ;CAUhD;AAED,qBAAa,SAAS;IAClB;;OAEG;IACH,OAAO,EAAE;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,eAAe,EAAE,MAAM,CAAA;KAAC,EAAE,CAAM;IAC5D,YAAY,CAAC,OAAO,EAAE,MAAM;CAgB/B"}
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.FileTransformRun = exports.TransformerFactoryOOP = void 0;
26
+ exports.TextPatch = exports.FileTransformRun = exports.TransformerFactoryOOP = void 0;
27
27
  const typescript_1 = __importStar(require("typescript"));
28
28
  /**
29
29
  * Transformerfactory in a better oop style
@@ -101,4 +101,26 @@ class FileTransformRun {
101
101
  }
102
102
  }
103
103
  exports.FileTransformRun = FileTransformRun;
104
+ class TextPatch {
105
+ constructor() {
106
+ /**
107
+ * character index (not byte index) => content to insert
108
+ */
109
+ this.patches = [];
110
+ }
111
+ applyPatches(content) {
112
+ this.patches.sort((a, b) => a.position - b.position);
113
+ let result = "";
114
+ let emittedTil = 0;
115
+ for (const patch of this.patches) {
116
+ // emit the stuff before the patch
117
+ result += content.slice(emittedTil, patch.position);
118
+ emittedTil = patch.position;
119
+ result += patch.contentToInsert;
120
+ }
121
+ result += content.slice(emittedTil); // emit the rest
122
+ return result;
123
+ }
124
+ }
125
+ exports.TextPatch = TextPatch;
104
126
  //# sourceMappingURL=transformerUtil.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"transformerUtil.js","sourceRoot":"","sources":["transformerUtil.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yDAAuG;AAMvG;;GAEG;AACH,MAAa,qBAAqB;IAK9B,YAAY,uBAAoC;QAJhD,sBAAiB,GAAS,EAAE,CAAA;QAKxB,IAAI,CAAC,qBAAqB,GAAG,uBAAuB,CAAC;IACzD,CAAC;IAED;;OAEG;IACH,IAAI,UAAU;QACV,OAAO,CAAC,OAA8B,EAAE,EAAE;YACtC,OAAO,CAAC,UAAsB,EAAc,EAAE;gBAC1C,MAAM,eAAe,GAAG,IAAI,IAAI,CAAC,qBAAqB,CAAC,oBAAE,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC;gBAChF,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,eAAqB,CAAC,CAAC;gBACnD,OAAO,oBAAE,CAAC,cAAc,CAAC,UAAU,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,eAAe,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC,CAAC;YACzF,CAAC,CAAA;QACL,CAAC,CAAA;IACL,CAAC;CACJ;AArBD,sDAqBC;AAED;;GAEG;AACH,MAAsB,gBAAgB;IAOlC,YAAY,UAAqB,EAAE,UAAsB,EAAE,OAA8B;QAHzF,gBAAW,GAAW,EAAE,CAAA;QACxB,SAAI,GAAG,KAAK,CAAC;QASb,cAAS,GAAG,GAAG,EAAE;YACb,OAAO,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;QACzD,CAAC,CAAC;QARE,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IAC3B,CAAC;IAeS,WAAW,C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AK,IAAI,IAAI,CAAC,OAAO,EAAE;YAC7B,kCAAkC;YAClC,MAAM,IAAE,OAAO,CAAC,KAAK,CAAC,UAAU,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAC;YAClD,UAAU,GAAG,KAAK,CAAC,QAAQ,CAAC;YAE5B,MAAM,IAAE,KAAK,CAAC,eAAe,CAAC;SACjC;QAED,MAAM,IAAG,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAA,gBAAgB;QAEnD,OAAO,MAAM,CAAC;IAClB,CAAC;CACJ;AArBD,8BAqBC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=transformerUtil.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transformerUtil.test.d.ts","sourceRoot":"","sources":["transformerUtil.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const transformerUtil_1 = require("./transformerUtil");
4
+ jest.setTimeout(60 * 60 * 1000); // Increase timeout to 1h to make debugging possible
5
+ test('TextPatch', () => {
6
+ const content = 'abc><de><fg';
7
+ const patch = new transformerUtil_1.TextPatch();
8
+ patch.patches = [{ position: 4, contentToInsert: "_insert1_" }, { position: 8, contentToInsert: "_insert2_" }];
9
+ expect(patch.applyPatches(content)).toBe('abc>_insert1_<de>_insert2_<fg');
10
+ });
11
+ //# sourceMappingURL=transformerUtil.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transformerUtil.test.js","sourceRoot":"","sources":["transformerUtil.test.ts"],"names":[],"mappings":";;AAAA,uDAA4C;AAE5C,IAAI,CAAC,UAAU,CAAC,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,CAAC,oDAAoD;AAGrF,IAAI,CAAC,WAAW,EAAE,GAAG,EAAE;IACnB,MAAM,OAAO,GAAC,aAAa,CAAA;IAC3B,MAAM,KAAK,GAAG,IAAI,2BAAS,EAAE,CAAC;IAC9B,KAAK,CAAC,OAAO,GAAG,CAAC,EAAC,QAAQ,EAAE,CAAC,EAAE,eAAe,EAAE,WAAW,EAAC,EAAE,EAAC,QAAQ,EAAE,CAAC,EAAE,eAAe,EAAE,WAAW,EAAC,CAAC,CAAC;IAC3G,MAAM,CAAC,KAAK,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,+BAA+B,CAAC,CAAC;AAC9E,CAAC,CAAC,CAAC"}
@@ -0,0 +1,12 @@
1
+ import {TextPatch} from "./transformerUtil";
2
+
3
+ jest.setTimeout(60 * 60 * 1000); // Increase timeout to 1h to make debugging possible
4
+
5
+
6
+ test('TextPatch', () => {
7
+ const content='abc><de><fg'
8
+ const patch = new TextPatch();
9
+ patch.patches = [{position: 4, contentToInsert: "_insert1_"}, {position: 8, contentToInsert: "_insert2_"}];
10
+ expect(patch.applyPatches(content)).toBe('abc>_insert1_<de>_insert2_<fg');
11
+ });
12
+
@@ -101,4 +101,27 @@ export abstract class FileTransformRun {
101
101
  }
102
102
  return identifierNode.getText();
103
103
  }
104
+ }
105
+
106
+ export class TextPatch {
107
+ /**
108
+ * character index (not byte index) => content to insert
109
+ */
110
+ patches: {position: number, contentToInsert: string}[] = [];
111
+ applyPatches(content: string) {
112
+ this.patches.sort((a,b) => a.position - b.position);
113
+ let result = "";
114
+ let emittedTil = 0;
115
+ for(const patch of this.patches) {
116
+ // emit the stuff before the patch
117
+ result+=content.slice(emittedTil, patch.position);
118
+ emittedTil = patch.position;
119
+
120
+ result+=patch.contentToInsert;
121
+ }
122
+
123
+ result+= content.slice(emittedTil);// emit the rest
124
+
125
+ return result;
126
+ }
104
127
  }