From ffc6a466cc83f09b8c9b1cf75e2b9541b8a8e991 Mon Sep 17 00:00:00 2001 From: Gareth Jones Date: Sun, 28 Nov 2021 12:46:07 +1300 Subject: [PATCH 1/4] feat(babel-plugin-jsx-pragmatic): add changeset --- .changeset/wet-boxes-raise.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/wet-boxes-raise.md diff --git a/.changeset/wet-boxes-raise.md b/.changeset/wet-boxes-raise.md new file mode 100644 index 0000000000..3e08df2c2b --- /dev/null +++ b/.changeset/wet-boxes-raise.md @@ -0,0 +1,5 @@ +--- +'@emotion/babel-plugin-jsx-pragmatic': minor +--- + +Convert to TypeScript. No breaking changes From 339a3ef89b72233070fae2ea81f71e3cd99f6c63 Mon Sep 17 00:00:00 2001 From: Gareth Jones Date: Sun, 28 Nov 2021 11:37:53 +1300 Subject: [PATCH 2/4] feat(babel-plugin-jsx-pragmatic): convert to typescript --- .../babel__plugin-syntax-jsx.d.ts | 4 +++ .../babel-plugin-jsx-pragmatic/package.json | 3 +- .../src/{index.js => index.ts} | 36 +++++++++++++++++-- yarn.lock | 11 ++++++ 4 files changed, 50 insertions(+), 4 deletions(-) create mode 100644 packages/babel-plugin-jsx-pragmatic/babel__plugin-syntax-jsx.d.ts rename packages/babel-plugin-jsx-pragmatic/src/{index.js => index.ts} (60%) diff --git a/packages/babel-plugin-jsx-pragmatic/babel__plugin-syntax-jsx.d.ts b/packages/babel-plugin-jsx-pragmatic/babel__plugin-syntax-jsx.d.ts new file mode 100644 index 0000000000..26446987ad --- /dev/null +++ b/packages/babel-plugin-jsx-pragmatic/babel__plugin-syntax-jsx.d.ts @@ -0,0 +1,4 @@ +declare module '@babel/plugin-syntax-jsx' { + const plugin: any + export default plugin +} diff --git a/packages/babel-plugin-jsx-pragmatic/package.json b/packages/babel-plugin-jsx-pragmatic/package.json index 7195057ffa..b88076a9ae 100644 --- a/packages/babel-plugin-jsx-pragmatic/package.json +++ b/packages/babel-plugin-jsx-pragmatic/package.json @@ -23,6 +23,7 @@ "access": "public" }, "devDependencies": { - "@babel/core": "^7.13.10" + "@babel/core": "^7.13.10", + "@types/babel__core": "^7.1.16" } } diff --git a/packages/babel-plugin-jsx-pragmatic/src/index.js b/packages/babel-plugin-jsx-pragmatic/src/index.ts similarity index 60% rename from packages/babel-plugin-jsx-pragmatic/src/index.js rename to packages/babel-plugin-jsx-pragmatic/src/index.ts index c2523b9d94..4a95dcf3d0 100644 --- a/packages/babel-plugin-jsx-pragmatic/src/index.js +++ b/packages/babel-plugin-jsx-pragmatic/src/index.ts @@ -1,17 +1,47 @@ +import type { + NodePath, + PluginObj, + PluginPass as BabelPluginPass, + types as BabelTypes +} from '@babel/core' import syntaxJsx from '@babel/plugin-syntax-jsx' -const findLast = (arr, predicate) => { +const findLast = (arr: T[], predicate: (item: T) => boolean): T | null => { for (let i = arr.length - 1; i >= 0; i--) { if (predicate(arr[i])) { return arr[i] } } + + return null +} + +// todo: PR these to @types/babel__core - PluginPass should extend Store +// https://github.com/babel/babel/blob/4e50b2d9d9c376cee7a2cbf56553fe5b982ea53c/packages/babel-core/src/transformation/store.js +interface BabelStore { + setDynamic(key: string, fn: () => unknown): void + set(key: string, val: unknown): void + get(key: string): unknown } -export default function jsxPragmatic(babel) { +type PluginPass = BabelPluginPass & + BabelStore & { + opts: { + module: string + import: string + export?: string + } + } + +export default function jsxPragmatic(babel: { + types: typeof BabelTypes +}): PluginObj { const t = babel.types - function addPragmaImport(path, state) { + function addPragmaImport( + path: NodePath, + state: PluginPass + ) { const importDeclar = t.importDeclaration( [ t.importSpecifier( diff --git a/yarn.lock b/yarn.lock index 413d6c020b..a8ef3c6017 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5594,6 +5594,17 @@ "@types/babel__template" "*" "@types/babel__traverse" "*" +"@types/babel__core@^7.1.16": + version "7.1.16" + resolved "https://registry.yarnpkg.com/@types/babel__core/-/babel__core-7.1.16.tgz#bc12c74b7d65e82d29876b5d0baf5c625ac58702" + integrity sha512-EAEHtisTMM+KaKwfWdC3oyllIqswlznXCIVCt7/oRNrh+DhgT4UEBNC/jlADNjvw7UnfbcdkGQcPVZ1xYiLcrQ== + dependencies: + "@babel/parser" "^7.1.0" + "@babel/types" "^7.0.0" + "@types/babel__generator" "*" + "@types/babel__template" "*" + "@types/babel__traverse" "*" + "@types/babel__generator@*": version "7.6.2" resolved "https://registry.yarnpkg.com/@types/babel__generator/-/babel__generator-7.6.2.tgz#f3d71178e187858f7c45e30380f8f1b7415a12d8" From 29d6afea4f736bc32d24dcec881649a50bf69fa9 Mon Sep 17 00:00:00 2001 From: Gareth Jones Date: Sun, 20 Feb 2022 11:55:39 +1300 Subject: [PATCH 3/4] fix(babel-plugin-jsx-pragmatic): update babel core types --- .../babel-plugin-jsx-pragmatic/package.json | 2 +- .../babel-plugin-jsx-pragmatic/src/index.ts | 27 +++++++------------ yarn.lock | 8 +++--- 3 files changed, 14 insertions(+), 23 deletions(-) diff --git a/packages/babel-plugin-jsx-pragmatic/package.json b/packages/babel-plugin-jsx-pragmatic/package.json index b88076a9ae..40c97472f6 100644 --- a/packages/babel-plugin-jsx-pragmatic/package.json +++ b/packages/babel-plugin-jsx-pragmatic/package.json @@ -24,6 +24,6 @@ }, "devDependencies": { "@babel/core": "^7.13.10", - "@types/babel__core": "^7.1.16" + "@types/babel__core": "^7.1.18" } } diff --git a/packages/babel-plugin-jsx-pragmatic/src/index.ts b/packages/babel-plugin-jsx-pragmatic/src/index.ts index 4a95dcf3d0..2315326e70 100644 --- a/packages/babel-plugin-jsx-pragmatic/src/index.ts +++ b/packages/babel-plugin-jsx-pragmatic/src/index.ts @@ -1,7 +1,7 @@ import type { NodePath, PluginObj, - PluginPass as BabelPluginPass, + PluginPass, types as BabelTypes } from '@babel/core' import syntaxJsx from '@babel/plugin-syntax-jsx' @@ -16,31 +16,22 @@ const findLast = (arr: T[], predicate: (item: T) => boolean): T | null => { return null } -// todo: PR these to @types/babel__core - PluginPass should extend Store -// https://github.com/babel/babel/blob/4e50b2d9d9c376cee7a2cbf56553fe5b982ea53c/packages/babel-core/src/transformation/store.js -interface BabelStore { - setDynamic(key: string, fn: () => unknown): void - set(key: string, val: unknown): void - get(key: string): unknown -} - -type PluginPass = BabelPluginPass & - BabelStore & { - opts: { - module: string - import: string - export?: string - } +interface PluginPassWithOpts extends PluginPass { + opts: { + module: string + import: string + export?: string } +} export default function jsxPragmatic(babel: { types: typeof BabelTypes -}): PluginObj { +}): PluginObj { const t = babel.types function addPragmaImport( path: NodePath, - state: PluginPass + state: PluginPassWithOpts ) { const importDeclar = t.importDeclaration( [ diff --git a/yarn.lock b/yarn.lock index a8ef3c6017..bcb31ea06e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5594,10 +5594,10 @@ "@types/babel__template" "*" "@types/babel__traverse" "*" -"@types/babel__core@^7.1.16": - version "7.1.16" - resolved "https://registry.yarnpkg.com/@types/babel__core/-/babel__core-7.1.16.tgz#bc12c74b7d65e82d29876b5d0baf5c625ac58702" - integrity sha512-EAEHtisTMM+KaKwfWdC3oyllIqswlznXCIVCt7/oRNrh+DhgT4UEBNC/jlADNjvw7UnfbcdkGQcPVZ1xYiLcrQ== +"@types/babel__core@^7.1.18": + version "7.1.18" + resolved "https://registry.yarnpkg.com/@types/babel__core/-/babel__core-7.1.18.tgz#1a29abcc411a9c05e2094c98f9a1b7da6cdf49f8" + integrity sha512-S7unDjm/C7z2A2R9NzfKCK1I+BAALDtxEmsJBwlB3EzNfb929ykjL++1CK9LO++EIp2fQrC8O+BwjKvz6UeDyQ== dependencies: "@babel/parser" "^7.1.0" "@babel/types" "^7.0.0" From 7a491b3938592a37bedc75add5101dc7e8ce8997 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Fri, 18 Mar 2022 22:50:08 +0100 Subject: [PATCH 4/4] Update .changeset/wet-boxes-raise.md --- .changeset/wet-boxes-raise.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/wet-boxes-raise.md b/.changeset/wet-boxes-raise.md index 3e08df2c2b..32c7a707c9 100644 --- a/.changeset/wet-boxes-raise.md +++ b/.changeset/wet-boxes-raise.md @@ -2,4 +2,4 @@ '@emotion/babel-plugin-jsx-pragmatic': minor --- -Convert to TypeScript. No breaking changes +Source code has been migrated to TypeScript. From now on type declarations will be emitted based on that, instead of being hand-written.