Skip to content

Commit e75ac5f

Browse files
authored
Merge pull request #115 from ryoppippi/feature/use-using
Refactor Typia Transformation: Introduce using result and Improve Resource Disposal
2 parents c7d8427 + 1ad47f5 commit e75ac5f

File tree

1 file changed

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

1 file changed

+11
-10
lines changed

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

+11-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,12 +142,14 @@ function transform(
145142
tsSource: ts.SourceFile,
146143
typiaOptions?: ResolvedOptions['typia'],
147144
): {
148-
/** The diagnostics */
145+
/** The diagnostics */
149146
diagnostics: ts.Diagnostic[];
150147
/** The transformed source files */
151148
transformed: ts.SourceFile[];
152149
/** The transformed source file we need */
153150
file: ts.SourceFile;
151+
/** Dispose the transformation */
152+
[Symbol.dispose]: () => void;
154153
} {
155154
const diagnostics: ts.Diagnostic[] = [];
156155

@@ -179,12 +178,14 @@ function transform(
179178
throw new Error('No file found');
180179
}
181180

182-
/** dispose transformation result */
183-
transformationResult.dispose();
184-
185181
const { transformed } = transformationResult;
186182

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

190191
/** Warn diagnostics */

0 commit comments

Comments
 (0)