Skip to content

Commit 1ad47f5

Browse files
committed
feat: Add dispose method to transform result
This commit modifies the transform function to return an object that includes a dispose method. This allows the caller to clean up resources once they are done with the transformation result. The usage of the transform function has been updated accordingly.
1 parent 3868c44 commit 1ad47f5

File tree

1 file changed

+10
-10
lines changed
  • packages/unplugin-typia/src/core

1 file changed

+10
-10
lines changed

packages/unplugin-typia/src/core/typia.ts

+10-10
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,8 @@ export async function transformTypia(
4545

4646
const { program, tsSource } = await getProgramAndSource(id, source, compilerOptions, cacheEnable);
4747

48-
const {
49-
diagnostics,
50-
transformed,
51-
file,
52-
} = transform(id, program, tsSource, options.typia);
48+
using result = transform(id, program, tsSource, options.typia);
49+
const { diagnostics, transformed, file } = result;
5350

5451
warnDiagnostic(diagnostics, transformed, unpluginContext);
5552

@@ -145,13 +142,14 @@ function transform(
145142
tsSource: ts.SourceFile,
146143
typiaOptions?: ResolvedOptions['typia'],
147144
): {
148-
/** The diagnostics */
149145
/** The diagnostics */
150146
diagnostics: ts.Diagnostic[];
151147
/** The transformed source files */
152148
transformed: ts.SourceFile[];
153149
/** The transformed source file we need */
154150
file: ts.SourceFile;
151+
/** Dispose the transformation */
152+
[Symbol.dispose]: () => void;
155153
} {
156154
const diagnostics: ts.Diagnostic[] = [];
157155

@@ -180,12 +178,14 @@ function transform(
180178
throw new Error('No file found');
181179
}
182180

183-
/** dispose transformation result */
184-
transformationResult.dispose();
185-
186181
const { transformed } = transformationResult;
187182

188-
return { diagnostics, transformed, file };
183+
return {
184+
diagnostics,
185+
transformed,
186+
file,
187+
[Symbol.dispose]: () => transformationResult.dispose(),
188+
};
189189
}
190190

191191
/** Warn diagnostics */

0 commit comments

Comments
 (0)