From 5f31d71f014c3065b951b52a23431629c778ae2c Mon Sep 17 00:00:00 2001 From: Hyeonjong Date: Sun, 24 Sep 2023 10:37:49 +0900 Subject: [PATCH 1/8] chore: add this plugin as alias --- package.json | 2 ++ pnpm-lock.yaml | 22 ++++++++++++++++------ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 4994055..a3415f2 100644 --- a/package.json +++ b/package.json @@ -47,6 +47,8 @@ "eslint-import-resolver-typescript": "3.5.3", "eslint-plugin-import": "2.27.5", "jest": "29.5.0", + "ppm-012": "npm:prettier-plugin-merge@0.1.2", + "ppm-020": "npm:prettier-plugin-merge@0.2.0", "prettier": "~2.8.4", "prettier-plugin-brace-style": "0.2.1", "prettier-plugin-classnames": "0.1.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 43ba9f5..db9a985 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -15,6 +15,8 @@ specifiers: eslint-import-resolver-typescript: 3.5.3 eslint-plugin-import: 2.27.5 jest: 29.5.0 + ppm-012: npm:prettier-plugin-merge@0.1.2 + ppm-020: npm:prettier-plugin-merge@0.2.0 prettier: ~2.8.4 prettier-plugin-brace-style: 0.2.1 prettier-plugin-classnames: 0.1.1 @@ -41,6 +43,8 @@ devDependencies: eslint-import-resolver-typescript: 3.5.3_yckic57kx266ph64dhq6ozvb54 eslint-plugin-import: 2.27.5_tqrcrxlenpngfto46ddarus52y jest: 29.5.0 + ppm-012: /prettier-plugin-merge/0.1.2_prettier@2.8.4 + ppm-020: /prettier-plugin-merge/0.2.0_prettier@2.8.4 prettier: 2.8.4 prettier-plugin-brace-style: 0.2.1_prettier@2.8.4 prettier-plugin-classnames: 0.1.1_prettier@2.8.4 @@ -1883,7 +1887,6 @@ packages: /diff/5.1.0: resolution: {integrity: sha512-D+mk+qE8VC/PAUrlAU34N+VfXev0ghe5ywmpqrawphmVZc1bEfn56uo9qpyGp1p4xpzOHkSW4ztBd6L7Xx4ACw==} engines: {node: '>=0.3.1'} - dev: false /dir-glob/3.0.1: resolution: {integrity: sha512-WkrWp9GR4KXfKGYzOLmTuGVi1UWFfws377n9cc55/tb6DuqyF6pcQ5AbiHEshaDpY9v6oaSr2XCDidGmMwdzIA==} @@ -3837,7 +3840,7 @@ packages: dependencies: prettier: 2.8.4 optionalDependencies: - prettier-plugin-merge: 0.1.1_prettier@2.8.4 + prettier-plugin-merge: 0.1.2_prettier@2.8.4 dev: true /prettier-plugin-classnames/0.1.1_prettier@2.8.4: @@ -3850,15 +3853,22 @@ packages: classnames: 2.3.2 dev: true - /prettier-plugin-merge/0.1.1_prettier@2.8.4: - resolution: {integrity: sha512-5h+RQWjn4si+K06opGL2B8pf73A9syTyxLtkX8RaO/C2XcWtZdZAmaJ3a8LL20Gg/synkxWGLZrnxD8PYQGziQ==} - requiresBuild: true + /prettier-plugin-merge/0.1.2_prettier@2.8.4: + resolution: {integrity: sha512-fXUGHRwIY1AwbFuiMhS+Kp4ELrXlbC171d3DpL3mlHfL8OP6rrlA5LLMmlaKsKfuK3CwTTfUAN9Tw89bii/qhQ==} peerDependencies: prettier: ~2.8.4 dependencies: prettier: 2.8.4 dev: true - optional: true + + /prettier-plugin-merge/0.2.0_prettier@2.8.4: + resolution: {integrity: sha512-2iStjZCMlmBXoGstBcBYXHcNhmafSL/pwJd4mWAQVTOGXPWo1UJ77wuI22vpVgla8Pkgbn62UA51d/rBsxAwrg==} + peerDependencies: + prettier: ~2.8.4 + dependencies: + diff: 5.1.0 + prettier: 2.8.4 + dev: true /prettier-plugin-tailwindcss/0.3.0_zmkqdpv3ldc45e6wei6qtrbrca: resolution: {integrity: sha512-009/Xqdy7UmkcTBpwlq7jsViDqXAYSOMLDrHAdTMlVZOrKfM2o9Ci7EMWTMZ7SkKBFTG04UM9F9iM2+4i6boDA==} From 68f6d7d18c406f84b12061ad000886e9cf4ecccd Mon Sep 17 00:00:00 2001 From: Hyeonjong Date: Sun, 24 Sep 2023 11:59:22 +0900 Subject: [PATCH 2/8] chore: add @types/node to dev dependencies --- package.json | 1 + pnpm-lock.yaml | 80 +++++++++++++++----------------------------------- 2 files changed, 24 insertions(+), 57 deletions(-) diff --git a/package.json b/package.json index a3415f2..a3824bc 100644 --- a/package.json +++ b/package.json @@ -37,6 +37,7 @@ "@trivago/prettier-plugin-sort-imports": "4.1.1", "@types/diff": "5.0.3", "@types/jest": "29.5.2", + "@types/node": "20.2.5", "@typescript-eslint/eslint-plugin": "5.54.0", "@typescript-eslint/parser": "5.54.0", "eslint": "8.35.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index db9a985..471bebc 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -4,6 +4,7 @@ specifiers: '@trivago/prettier-plugin-sort-imports': 4.1.1 '@types/diff': 5.0.3 '@types/jest': 29.5.2 + '@types/node': 20.2.5 '@typescript-eslint/eslint-plugin': 5.54.0 '@typescript-eslint/parser': 5.54.0 diff: 5.1.0 @@ -33,6 +34,7 @@ devDependencies: '@trivago/prettier-plugin-sort-imports': 4.1.1_prettier@2.8.4 '@types/diff': 5.0.3 '@types/jest': 29.5.2 + '@types/node': 20.2.5 '@typescript-eslint/eslint-plugin': 5.54.0_6mj2wypvdnknez7kws2nfdgupi '@typescript-eslint/parser': 5.54.0_ycpbpc6yetojsgtrx3mwntkhsu eslint: 8.35.0 @@ -42,7 +44,7 @@ devDependencies: eslint-import-resolver-node: 0.3.7 eslint-import-resolver-typescript: 3.5.3_yckic57kx266ph64dhq6ozvb54 eslint-plugin-import: 2.27.5_tqrcrxlenpngfto46ddarus52y - jest: 29.5.0 + jest: 29.5.0_@types+node@20.2.5 ppm-012: /prettier-plugin-merge/0.1.2_prettier@2.8.4 ppm-020: /prettier-plugin-merge/0.2.0_prettier@2.8.4 prettier: 2.8.4 @@ -51,8 +53,8 @@ devDependencies: prettier-plugin-tailwindcss: 0.3.0_zmkqdpv3ldc45e6wei6qtrbrca ts-jest: 29.1.0_doipufordlnvh5g4adbwayvyvy typescript: 4.9.5 - vite: 4.3.9 - vite-plugin-dts: 3.0.0-beta.2_typescript@4.9.5 + vite: 4.3.9_@types+node@20.2.5 + vite-plugin-dts: 3.0.0-beta.2_6yd3dr4iiziaqkscqiabuqynye packages: @@ -935,24 +937,24 @@ packages: '@jridgewell/sourcemap-codec': 1.4.14 dev: true - /@microsoft/api-extractor-model/7.27.3: + /@microsoft/api-extractor-model/7.27.3_@types+node@20.2.5: resolution: {integrity: sha512-fSFvw7otYHduOkyshjTbapKKgwF8bgquVHvgF8VgeKtMYvqXkoaj7W6VcM7PNY7E2bbblhUgC4XNdqZLD4SJGw==} dependencies: '@microsoft/tsdoc': 0.14.2 '@microsoft/tsdoc-config': 0.16.2 - '@rushstack/node-core-library': 3.59.4 + '@rushstack/node-core-library': 3.59.4_@types+node@20.2.5 transitivePeerDependencies: - '@types/node' dev: true - /@microsoft/api-extractor/7.36.0: + /@microsoft/api-extractor/7.36.0_@types+node@20.2.5: resolution: {integrity: sha512-P+kYgJFDXIr+UNzhRMhlpM/dderi6ab4lxn35vdhfAIMPtGCSXIJxrrtpTOQmQW8CZtmoZX06LYoUsKCc1zjow==} hasBin: true dependencies: - '@microsoft/api-extractor-model': 7.27.3 + '@microsoft/api-extractor-model': 7.27.3_@types+node@20.2.5 '@microsoft/tsdoc': 0.14.2 '@microsoft/tsdoc-config': 0.16.2 - '@rushstack/node-core-library': 3.59.4 + '@rushstack/node-core-library': 3.59.4_@types+node@20.2.5 '@rushstack/rig-package': 0.4.0 '@rushstack/ts-command-line': 4.15.1 colors: 1.2.5 @@ -1026,7 +1028,7 @@ packages: rollup: 3.23.0 dev: true - /@rushstack/node-core-library/3.59.4: + /@rushstack/node-core-library/3.59.4_@types+node@20.2.5: resolution: {integrity: sha512-YAKJDC6Mz/KA1D7bvB88WaRX3knt/ZuLzkRu5G9QADGSjLtvTWzCNCytRF2PCSaaHOZaZsWul4F1KQdgFgUDqA==} peerDependencies: '@types/node': '*' @@ -1034,6 +1036,7 @@ packages: '@types/node': optional: true dependencies: + '@types/node': 20.2.5 colors: 1.2.5 fs-extra: 7.0.1 import-lazy: 4.0.0 @@ -2982,7 +2985,7 @@ packages: - supports-color dev: true - /jest-cli/29.5.0: + /jest-cli/29.5.0_@types+node@20.2.5: resolution: {integrity: sha512-L1KcP1l4HtfwdxXNFCL5bmUbLQiKrakMUriBEcc1Vfz6gx31ORKdreuWvmQVBit+1ss9NNR3yxjwfwzZNdQXJw==} engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} hasBin: true @@ -2999,7 +3002,7 @@ packages: exit: 0.1.2 graceful-fs: 4.2.11 import-local: 3.1.0 - jest-config: 29.5.0 + jest-config: 29.5.0_@types+node@20.2.5 jest-util: 29.5.0 jest-validate: 29.5.0 prompts: 2.4.2 @@ -3010,44 +3013,6 @@ packages: - ts-node dev: true - /jest-config/29.5.0: - resolution: {integrity: sha512-kvDUKBnNJPNBmFFOhDbm59iu1Fii1Q6SxyhXfvylq3UTHbg6o7j/g8k2dZyXWLvfdKB1vAPxNZnMgtKJcmu3kA==} - engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} - peerDependencies: - '@types/node': '*' - ts-node: '>=9.0.0' - peerDependenciesMeta: - '@types/node': - optional: true - ts-node: - optional: true - dependencies: - '@babel/core': 7.22.1 - '@jest/test-sequencer': 29.5.0 - '@jest/types': 29.5.0 - babel-jest: 29.5.0_@babel+core@7.22.1 - chalk: 4.1.2 - ci-info: 3.8.0 - deepmerge: 4.3.1 - glob: 7.2.3 - graceful-fs: 4.2.11 - jest-circus: 29.5.0 - jest-environment-node: 29.5.0 - jest-get-type: 29.4.3 - jest-regex-util: 29.4.3 - jest-resolve: 29.5.0 - jest-runner: 29.5.0 - jest-util: 29.5.0 - jest-validate: 29.5.0 - micromatch: 4.0.5 - parse-json: 5.2.0 - pretty-format: 29.5.0 - slash: 3.0.0 - strip-json-comments: 3.1.1 - transitivePeerDependencies: - - supports-color - dev: true - /jest-config/29.5.0_@types+node@20.2.5: resolution: {integrity: sha512-kvDUKBnNJPNBmFFOhDbm59iu1Fii1Q6SxyhXfvylq3UTHbg6o7j/g8k2dZyXWLvfdKB1vAPxNZnMgtKJcmu3kA==} engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} @@ -3373,7 +3338,7 @@ packages: supports-color: 8.1.1 dev: true - /jest/29.5.0: + /jest/29.5.0_@types+node@20.2.5: resolution: {integrity: sha512-juMg3he2uru1QoXX078zTa7pO85QyB9xajZc6bU+d9yEGwrKX6+vGmJQ3UdVZsvTEUARIdObzH68QItim6OSSQ==} engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} hasBin: true @@ -3386,7 +3351,7 @@ packages: '@jest/core': 29.5.0 '@jest/types': 29.5.0 import-local: 3.1.0 - jest-cli: 29.5.0 + jest-cli: 29.5.0_@types+node@20.2.5 transitivePeerDependencies: - '@types/node' - supports-color @@ -4335,7 +4300,7 @@ packages: dependencies: bs-logger: 0.2.6 fast-json-stable-stringify: 2.1.0 - jest: 29.5.0 + jest: 29.5.0_@types+node@20.2.5 jest-util: 29.5.0 json5: 2.2.3 lodash.memoize: 4.1.2 @@ -4464,15 +4429,15 @@ packages: engines: {node: '>= 0.10'} dev: true - /vite-plugin-dts/3.0.0-beta.2_typescript@4.9.5: + /vite-plugin-dts/3.0.0-beta.2_6yd3dr4iiziaqkscqiabuqynye: resolution: {integrity: sha512-8Ua+MyljJeXWYerMvvbX8voFyc+kCMG49F6rCQ6QRD2eVVMkbZkDoafVjbwWogmipSVirKS8zCBMN5WckXmyxg==} engines: {node: ^14.18.0 || >=16.0.0} peerDependencies: typescript: '*' dependencies: - '@microsoft/api-extractor': 7.36.0 + '@microsoft/api-extractor': 7.36.0_@types+node@20.2.5 '@rollup/pluginutils': 5.0.2_rollup@3.23.0 - '@rushstack/node-core-library': 3.59.4 + '@rushstack/node-core-library': 3.59.4_@types+node@20.2.5 '@vue/language-core': 1.8.3_typescript@4.9.5 debug: 4.3.4 kolorist: 1.8.0 @@ -4480,7 +4445,7 @@ packages: vue-tsc: 1.8.3_typescript@4.9.5 optionalDependencies: rollup: 3.23.0 - vite: 4.3.9 + vite: 4.3.9_@types+node@20.2.5 transitivePeerDependencies: - '@types/node' - less @@ -4491,7 +4456,7 @@ packages: - terser dev: true - /vite/4.3.9: + /vite/4.3.9_@types+node@20.2.5: resolution: {integrity: sha512-qsTNZjO9NoJNW7KnOrgYwczm0WctJ8m/yqYAMAK9Lxt4SoySUfS5S8ia9K7JHpa3KEeMfyF8LoJ3c5NeBJy6pg==} engines: {node: ^14.18.0 || >=16.0.0} hasBin: true @@ -4516,6 +4481,7 @@ packages: terser: optional: true dependencies: + '@types/node': 20.2.5 esbuild: 0.17.19 postcss: 8.4.24 rollup: 3.23.0 From aa54ea5aecc9b13df2c8188afe4396ca104e00f8 Mon Sep 17 00:00:00 2001 From: Hyeonjong Date: Sun, 24 Sep 2023 13:36:27 +0900 Subject: [PATCH 3/8] test: add performance tests --- .eslintignore | 1 + .prettierrc.json | 11 ++++- package.json | 2 +- tests/babel/performance/Callout.jsx | 11 +++++ tests/babel/performance/index.test.ts | 56 ++++++++++++++++++++++ tests/typescript/performance/Callout.tsx | 13 +++++ tests/typescript/performance/index.test.ts | 56 ++++++++++++++++++++++ tsconfig.json | 2 +- 8 files changed, 149 insertions(+), 3 deletions(-) create mode 100644 tests/babel/performance/Callout.jsx create mode 100644 tests/babel/performance/index.test.ts create mode 100644 tests/typescript/performance/Callout.tsx create mode 100644 tests/typescript/performance/index.test.ts diff --git a/.eslintignore b/.eslintignore index 211fca3..bd2db57 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,2 +1,3 @@ **/*.*js +**/*.jsx **/*.d.ts diff --git a/.prettierrc.json b/.prettierrc.json index 4b2e59d..ae3493a 100644 --- a/.prettierrc.json +++ b/.prettierrc.json @@ -4,5 +4,14 @@ "trailingComma": "all", "plugins": ["@trivago/prettier-plugin-sort-imports"], "importOrder": ["", "^@/(.*)$", "^\\.(.*)$"], - "importOrderSeparation": true + "importOrderSeparation": true, + "overrides": [ + { + "files": ["tests/**/performance/Callout.*"], + "options": { + "printWidth": 80, + "singleQuote": false + } + } + ] } diff --git a/package.json b/package.json index a3824bc..eef9846 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ "dev": "vite build --watch --minify=false", "build": "vite build", "lint": "eslint src", - "test": "jest --ci --passWithNoTests", + "test": "pnpm run build && jest --ci --passWithNoTests", "test:watch": "jest --watch" }, "dependencies": { diff --git a/tests/babel/performance/Callout.jsx b/tests/babel/performance/Callout.jsx new file mode 100644 index 0000000..ba03d53 --- /dev/null +++ b/tests/babel/performance/Callout.jsx @@ -0,0 +1,11 @@ +// @ts-nocheck +export default function Callout({ children }) { + return ( +
+ {children} +
+ ); +} diff --git a/tests/babel/performance/index.test.ts b/tests/babel/performance/index.test.ts new file mode 100644 index 0000000..914e53e --- /dev/null +++ b/tests/babel/performance/index.test.ts @@ -0,0 +1,56 @@ +import { execSync } from 'child_process'; +import { resolve, sep } from 'path'; + +const filePath = resolve(__dirname, './Callout.jsx').split(sep).join('/'); + +function calculateAverageExecutionTime(trialCount: number, mergePluginName: string): number { + if (trialCount <= 0) { + return 0; + } + + const command = [ + 'pnpm prettier --no-config', + '--parser babel', + `--check ${filePath}`, + '--plugin @trivago/prettier-plugin-sort-imports', + '--plugin prettier-plugin-tailwindcss', + '--plugin prettier-plugin-classnames', + '--plugin prettier-plugin-brace-style', + `--plugin ${mergePluginName}`, + ].join(' '); + let totalExecutionTime = 0; + + for (let index = 0; index < trialCount; index += 1) { + const startTime = new Date().getTime(); + execSync(command); + const endTime = new Date().getTime(); + + totalExecutionTime += endTime - startTime; + } + + return totalExecutionTime / trialCount; +} + +describe('babel/performance', () => { + const trialCount = 5; + const averageExecutionTimeWithPlugin012 = calculateAverageExecutionTime(trialCount, 'ppm-012'); + const averageExecutionTimeWithPlugin020 = calculateAverageExecutionTime(trialCount, 'ppm-020'); + const averageExecutionTimeWithCurrentPlugin = calculateAverageExecutionTime(trialCount, '.'); + + const timeDifferenceWithPlugin020 = + averageExecutionTimeWithPlugin020 - averageExecutionTimeWithPlugin012; + const timeDifferenceWithCurrentPlugin = + averageExecutionTimeWithCurrentPlugin - averageExecutionTimeWithPlugin012; + + test('v0.1.2 is faster than v0.2.0', () => { + expect(averageExecutionTimeWithPlugin012 < averageExecutionTimeWithPlugin020).toBe(true); + }); + + for (const percent of [10, 20, 30, 40, 50, 60, 70, 80, 90]) { + test(`The current version reduces the difference between v0.1.2 and v0.2.0 by ${percent}%`, () => { + const expectedTime = timeDifferenceWithPlugin020 * (1 - percent / 100); + + expect(timeDifferenceWithCurrentPlugin).toBeLessThanOrEqual(expectedTime); + }); + } +}); diff --git a/tests/typescript/performance/Callout.tsx b/tests/typescript/performance/Callout.tsx new file mode 100644 index 0000000..d4f9dfd --- /dev/null +++ b/tests/typescript/performance/Callout.tsx @@ -0,0 +1,13 @@ +// @ts-nocheck +import type { ComponentProps } from "react"; + +export default function Callout({ children }: ComponentProps<"div">) { + return ( +
+ {children} +
+ ); +} diff --git a/tests/typescript/performance/index.test.ts b/tests/typescript/performance/index.test.ts new file mode 100644 index 0000000..cb9cf31 --- /dev/null +++ b/tests/typescript/performance/index.test.ts @@ -0,0 +1,56 @@ +import { execSync } from 'child_process'; +import { resolve, sep } from 'path'; + +const filePath = resolve(__dirname, './Callout.tsx').split(sep).join('/'); + +function calculateAverageExecutionTime(trialCount: number, mergePluginName: string): number { + if (trialCount <= 0) { + return 0; + } + + const command = [ + 'pnpm prettier --no-config', + '--parser typescript', + `--check ${filePath}`, + '--plugin @trivago/prettier-plugin-sort-imports', + '--plugin prettier-plugin-tailwindcss', + '--plugin prettier-plugin-classnames', + '--plugin prettier-plugin-brace-style', + `--plugin ${mergePluginName}`, + ].join(' '); + let totalExecutionTime = 0; + + for (let index = 0; index < trialCount; index += 1) { + const startTime = new Date().getTime(); + execSync(command); + const endTime = new Date().getTime(); + + totalExecutionTime += endTime - startTime; + } + + return totalExecutionTime / trialCount; +} + +describe('typescript/performance', () => { + const trialCount = 5; + const averageExecutionTimeWithPlugin012 = calculateAverageExecutionTime(trialCount, 'ppm-012'); + const averageExecutionTimeWithPlugin020 = calculateAverageExecutionTime(trialCount, 'ppm-020'); + const averageExecutionTimeWithCurrentPlugin = calculateAverageExecutionTime(trialCount, '.'); + + const timeDifferenceWithPlugin020 = + averageExecutionTimeWithPlugin020 - averageExecutionTimeWithPlugin012; + const timeDifferenceWithCurrentPlugin = + averageExecutionTimeWithCurrentPlugin - averageExecutionTimeWithPlugin012; + + test('v0.1.2 is faster than v0.2.0', () => { + expect(averageExecutionTimeWithPlugin012 < averageExecutionTimeWithPlugin020).toBe(true); + }); + + for (const percent of [10, 20, 30, 40, 50, 60, 70, 80, 90]) { + test(`The current version reduces the difference between v0.1.2 and v0.2.0 by ${percent}%`, () => { + const expectedTime = timeDifferenceWithPlugin020 * (1 - percent / 100); + + expect(timeDifferenceWithCurrentPlugin).toBeLessThanOrEqual(expectedTime); + }); + } +}); diff --git a/tsconfig.json b/tsconfig.json index 3d15887..ae28623 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -16,6 +16,6 @@ "@/*": ["./src/*"] } }, - "include": ["**/*.ts"], + "include": ["**/*.ts", "**/*.tsx"], "exclude": ["node_modules"] } From afc546638a10d35faeee5c721cc14287838411a4 Mon Sep 17 00:00:00 2001 From: Hyeonjong Date: Sun, 24 Sep 2023 14:08:19 +0900 Subject: [PATCH 4/8] chore: remove unused cli command --- package.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/package.json b/package.json index eef9846..1431e2a 100644 --- a/package.json +++ b/package.json @@ -27,8 +27,7 @@ "dev": "vite build --watch --minify=false", "build": "vite build", "lint": "eslint src", - "test": "pnpm run build && jest --ci --passWithNoTests", - "test:watch": "jest --watch" + "test": "pnpm run build && jest --ci --passWithNoTests" }, "dependencies": { "diff": "5.1.0" From 10d9d60dff30490ae66814bdd141c317c08f17ad Mon Sep 17 00:00:00 2001 From: Hyeonjong Date: Sun, 24 Sep 2023 18:31:05 +0900 Subject: [PATCH 5/8] perf: applies sequential formatting only to plugins that implement target parser --- src/printers.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/printers.ts b/src/printers.ts index b431cca..9086758 100644 --- a/src/printers.ts +++ b/src/printers.ts @@ -125,6 +125,7 @@ function createPrinter(): Printer { throw new Error('A default plugin with the detected parser does not exist.'); } + const parserName = options.parser as string; const node = path.getValue(); if (node?.comments) { @@ -149,9 +150,13 @@ function createPrinter(): Printer { ); } + const parserImplementedPlugins = plugins + .slice(0, pluginIndex) + .filter((plugin) => plugin.parsers?.[parserName]); + return sequentialFormattingAndTryMerging( options, - plugins.slice(0, pluginIndex), + parserImplementedPlugins, defaultPluginCandidate, ); } From df15ec71140d6195e28baea0c60a2a6500723569 Mon Sep 17 00:00:00 2001 From: Hyeonjong Date: Sun, 24 Sep 2023 19:01:51 +0900 Subject: [PATCH 6/8] perf: remove fallback text that is no longer needed --- src/printers.ts | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/src/printers.ts b/src/printers.ts index 9086758..110219f 100644 --- a/src/printers.ts +++ b/src/printers.ts @@ -24,8 +24,7 @@ function sequentialFormattingAndTryMerging( rangeEnd: Infinity, }; - let sequentiallyFormattedText = originalText; - let sequentiallyMergedText: string | undefined; + let sequentiallyMergedText = originalText; /** * Changes that may be removed during the sequential formatting process. @@ -33,17 +32,12 @@ function sequentialFormattingAndTryMerging( const patches: SubstitutePatch[] = []; plugins.forEach((plugin) => { - sequentiallyFormattedText = format(sequentiallyFormattedText, { + const temporaryFormattedText = format(sequentiallyMergedText, { ...sequentialFormattingOptions, plugins: [plugin], }); - const temporaryFormattedText = format(sequentiallyMergedText ?? originalText, { - ...sequentialFormattingOptions, - plugins: [plugin], - }); - - if (sequentiallyMergedText === undefined) { + if (sequentiallyMergedText === originalText) { sequentiallyMergedText = temporaryFormattedText; return; } @@ -106,7 +100,7 @@ function sequentialFormattingAndTryMerging( ); }); - return sequentiallyMergedText ?? sequentiallyFormattedText; + return sequentiallyMergedText; } function createPrinter(): Printer { From 3efac28aaa4a68768014509c485e2a2845b21f74 Mon Sep 17 00:00:00 2001 From: Hyeonjong Date: Sun, 24 Sep 2023 19:21:28 +0900 Subject: [PATCH 7/8] test: add metrics for performance tests --- tests/babel/performance/index.test.ts | 2 +- tests/typescript/performance/index.test.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/babel/performance/index.test.ts b/tests/babel/performance/index.test.ts index 914e53e..a9aacff 100644 --- a/tests/babel/performance/index.test.ts +++ b/tests/babel/performance/index.test.ts @@ -46,7 +46,7 @@ describe('babel/performance', () => { expect(averageExecutionTimeWithPlugin012 < averageExecutionTimeWithPlugin020).toBe(true); }); - for (const percent of [10, 20, 30, 40, 50, 60, 70, 80, 90]) { + for (const percent of [10, 20, 30, 40, 50, 60, 70, 80, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99]) { test(`The current version reduces the difference between v0.1.2 and v0.2.0 by ${percent}%`, () => { const expectedTime = timeDifferenceWithPlugin020 * (1 - percent / 100); diff --git a/tests/typescript/performance/index.test.ts b/tests/typescript/performance/index.test.ts index cb9cf31..253b377 100644 --- a/tests/typescript/performance/index.test.ts +++ b/tests/typescript/performance/index.test.ts @@ -46,7 +46,7 @@ describe('typescript/performance', () => { expect(averageExecutionTimeWithPlugin012 < averageExecutionTimeWithPlugin020).toBe(true); }); - for (const percent of [10, 20, 30, 40, 50, 60, 70, 80, 90]) { + for (const percent of [10, 20, 30, 40, 50, 60, 70, 80, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99]) { test(`The current version reduces the difference between v0.1.2 and v0.2.0 by ${percent}%`, () => { const expectedTime = timeDifferenceWithPlugin020 * (1 - percent / 100); From 6f7a8c9f8576acd7b74679fb9fd65a331007c2c1 Mon Sep 17 00:00:00 2001 From: Hyeonjong Date: Sun, 24 Sep 2023 22:04:57 +0900 Subject: [PATCH 8/8] refactor: rename variables --- tests/babel/performance/index.test.ts | 4 ++-- tests/typescript/performance/index.test.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/babel/performance/index.test.ts b/tests/babel/performance/index.test.ts index a9aacff..3169304 100644 --- a/tests/babel/performance/index.test.ts +++ b/tests/babel/performance/index.test.ts @@ -48,9 +48,9 @@ describe('babel/performance', () => { for (const percent of [10, 20, 30, 40, 50, 60, 70, 80, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99]) { test(`The current version reduces the difference between v0.1.2 and v0.2.0 by ${percent}%`, () => { - const expectedTime = timeDifferenceWithPlugin020 * (1 - percent / 100); + const expectedTimeDifference = timeDifferenceWithPlugin020 * (1 - percent / 100); - expect(timeDifferenceWithCurrentPlugin).toBeLessThanOrEqual(expectedTime); + expect(timeDifferenceWithCurrentPlugin).toBeLessThanOrEqual(expectedTimeDifference); }); } }); diff --git a/tests/typescript/performance/index.test.ts b/tests/typescript/performance/index.test.ts index 253b377..107816a 100644 --- a/tests/typescript/performance/index.test.ts +++ b/tests/typescript/performance/index.test.ts @@ -48,9 +48,9 @@ describe('typescript/performance', () => { for (const percent of [10, 20, 30, 40, 50, 60, 70, 80, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99]) { test(`The current version reduces the difference between v0.1.2 and v0.2.0 by ${percent}%`, () => { - const expectedTime = timeDifferenceWithPlugin020 * (1 - percent / 100); + const expectedTimeDifference = timeDifferenceWithPlugin020 * (1 - percent / 100); - expect(timeDifferenceWithCurrentPlugin).toBeLessThanOrEqual(expectedTime); + expect(timeDifferenceWithCurrentPlugin).toBeLessThanOrEqual(expectedTimeDifference); }); } });