From ccc1ee747b2c515759af9628428b6a7c93e281db Mon Sep 17 00:00:00 2001 From: cpojer Date: Thu, 12 Dec 2024 11:16:06 +0900 Subject: [PATCH] Enable import attributes. --- example/src/example/Example.react.tsx | 3 +-- example/vite.config.ts | 6 ++---- jest-preprocessor.js | 2 ++ package.json | 1 + .../src/bin/__tests__/collectFBT-test.tsx | 3 +-- packages/babel-plugin-fbtee/src/utils/addLeafToTree.tsx | 2 +- pnpm-lock.yaml | 3 +++ 7 files changed, 11 insertions(+), 9 deletions(-) diff --git a/example/src/example/Example.react.tsx b/example/src/example/Example.react.tsx index a69d646e..1da6dd78 100644 --- a/example/src/example/Example.react.tsx +++ b/example/src/example/Example.react.tsx @@ -1,8 +1,7 @@ import classNames from 'classnames'; import { fbs, fbt, GenderConst, init, IntlVariations } from 'fbtee'; import { ChangeEvent, useCallback, useState } from 'react'; -// @ts-expect-error -import translations from '../translatedFbts.json'; +import translations from '../translatedFbts.json' with { type: 'json' }; import ExampleEnum from './Example$FbtEnum.js'; const viewerContext = { diff --git a/example/vite.config.ts b/example/vite.config.ts index 06bd1b97..a37d6895 100644 --- a/example/vite.config.ts +++ b/example/vite.config.ts @@ -1,9 +1,7 @@ import fbteePreset from '@nkzw/babel-fbtee'; import react from '@vitejs/plugin-react'; -// @ts-expect-error -import EnumManifest from './.enum_manifest.json'; -// @ts-expect-error -import CommonStrings from './common_strings.json'; +import EnumManifest from './.enum_manifest.json' with { type: 'json' }; +import CommonStrings from './common_strings.json' with { type: 'json' }; const root = process.cwd(); diff --git a/jest-preprocessor.js b/jest-preprocessor.js index 4fd2be2c..69e8e591 100644 --- a/jest-preprocessor.js +++ b/jest-preprocessor.js @@ -1,4 +1,5 @@ import babel from '@babel/core'; +import pluginSyntaxAttributes from '@babel/plugin-syntax-import-attributes'; import presetReact from '@babel/preset-react'; import presetTypescript from '@babel/preset-typescript'; @@ -6,6 +7,7 @@ const createTransformer = (opts = {}) => ({ process: (src, filename) => babel.transform(src, { filename, + plugins: [pluginSyntaxAttributes], presets: [ ...(opts?.presets || []), [ diff --git a/package.json b/package.json index 9b480e09..fd0c9dc3 100644 --- a/package.json +++ b/package.json @@ -20,6 +20,7 @@ "@babel/core": "^7.26.0", "@babel/generator": "^7.26.3", "@babel/parser": "^7.26.3", + "@babel/plugin-syntax-import-attributes": "^7.26.0", "@babel/preset-react": "^7.26.3", "@babel/preset-typescript": "^7.26.0", "@babel/types": "^7.26.3", diff --git a/packages/babel-plugin-fbtee/src/bin/__tests__/collectFBT-test.tsx b/packages/babel-plugin-fbtee/src/bin/__tests__/collectFBT-test.tsx index 0530ec84..e9fbe05d 100644 --- a/packages/babel-plugin-fbtee/src/bin/__tests__/collectFBT-test.tsx +++ b/packages/babel-plugin-fbtee/src/bin/__tests__/collectFBT-test.tsx @@ -5,8 +5,7 @@ import { getFbtCollector, getPackagers, } from '../collectFbtUtils.tsx'; -// @ts-expect-error -import fbtCommon from './FbtCommonForTests.json'; +import fbtCommon from './FbtCommonForTests.json' with { type: 'json' }; async function collect( source: Array<[string, string]> | string, diff --git a/packages/babel-plugin-fbtee/src/utils/addLeafToTree.tsx b/packages/babel-plugin-fbtee/src/utils/addLeafToTree.tsx index e2c7fc16..068c94b8 100644 --- a/packages/babel-plugin-fbtee/src/utils/addLeafToTree.tsx +++ b/packages/babel-plugin-fbtee/src/utils/addLeafToTree.tsx @@ -63,7 +63,7 @@ import invariant from 'invariant'; export default function addLeafToTree>( tree: T, keys: ReadonlyArray, - leaf: unknown, + leaf: V, ) { let branch = tree; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 1bc9a945..7c3015c9 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -20,6 +20,9 @@ importers: '@babel/parser': specifier: ^7.26.3 version: 7.26.3 + '@babel/plugin-syntax-import-attributes': + specifier: ^7.26.0 + version: 7.26.0(@babel/core@7.26.0) '@babel/preset-react': specifier: ^7.26.3 version: 7.26.3(@babel/core@7.26.0)