-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf(unminify) : improve performance of
prettier
and lebab
- Loading branch information
Showing
6 changed files
with
42 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import type { Options, Transform } from 'jscodeshift' | ||
|
||
export interface StringTransformation<Params = object> { | ||
(code: string, params: Params): string | void | ||
} | ||
|
||
export function wrapStringTransformation<Params extends Options>( | ||
transformAST: StringTransformation<Params>, | ||
): Transform { | ||
// @ts-expect-error - jscodeshift is not happy | ||
const transform: Transform = (file, api, options: Params) => { | ||
const code = file.source | ||
const result = transformAST(code, options) | ||
return result ?? code | ||
} | ||
|
||
return transform | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,13 @@ | ||
import { wrapAstTransformation } from '@wakaru/ast-utils/wrapAstTransformation' | ||
import { wrapStringTransformation } from '@wakaru/ast-utils/wrapStringTransformation' | ||
import babelParser from 'prettier/parser-babel' | ||
import prettier from 'prettier/standalone' | ||
import type { ASTTransformation } from '@wakaru/ast-utils/wrapAstTransformation' | ||
|
||
/** | ||
* @url https://prettier.io | ||
*/ | ||
export const transformAST: ASTTransformation = (context) => { | ||
const code = context.root.toSource() | ||
export default wrapStringTransformation((code) => { | ||
return prettier.format(code, { | ||
parser: 'babel', | ||
plugins: [babelParser], | ||
}) | ||
} | ||
|
||
export default wrapAstTransformation(transformAST) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters