diff --git a/package-lock.json b/package-lock.json index dffbb6a9e..1cf3a4e56 100644 --- a/package-lock.json +++ b/package-lock.json @@ -38,7 +38,7 @@ "all-contributors-cli": "^6.26.1", "babel-core": "^7.0.0-bridge.0", "babel-plugin-macros": "^3.1.0", - "babel-plugin-tester": "^7.0.4", + "babel-plugin-tester": "^11.0.4", "coveralls": "^3.1.1", "cpy-cli": "^5.0.0", "cross-env": "^7.0.3", @@ -4682,20 +4682,48 @@ } }, "node_modules/babel-plugin-tester": { - "version": "7.0.4", - "resolved": "https://registry.npmjs.org/babel-plugin-tester/-/babel-plugin-tester-7.0.4.tgz", - "integrity": "sha512-ZKhOa0aaaPNQVOZjxJ4svy8lIKjHswzCNxv3WROmirlFz+5IM22hzNg+p4MGC/C3Tv3sX5JfYSKJIcUE9aPdsA==", + "version": "11.0.4", + "resolved": "https://registry.npmjs.org/babel-plugin-tester/-/babel-plugin-tester-11.0.4.tgz", + "integrity": "sha512-cqswtpSPo0e++rZB0l/54EG17LL25l9gLgh59yXfnmNxX+2lZTIOpx2zt4YI9QIClVXc8xf63J6yWwKkzy0jNg==", "dev": true, "dependencies": { + "core-js": "^3.27.2", + "debug": "^4.3.4", "lodash.mergewith": "^4.6.2", + "prettier": "^2.8.3", "strip-indent": "^3.0.0" }, "engines": { - "node": ">=8", - "npm": ">=6" + "node": "^14.20.0 || ^16.16.0 || >=18.5.0" }, "peerDependencies": { - "@babel/core": "^7.7.2" + "@babel/core": ">=7.11.6" + } + }, + "node_modules/babel-plugin-tester/node_modules/core-js": { + "version": "3.38.0", + "resolved": "https://registry.npmjs.org/core-js/-/core-js-3.38.0.tgz", + "integrity": "sha512-XPpwqEodRljce9KswjZShh95qJ1URisBeKCjUdq27YdenkslVe7OO0ZJhlYXAChW7OhXaRLl8AAba7IBfoIHug==", + "dev": true, + "hasInstallScript": true, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/core-js" + } + }, + "node_modules/babel-plugin-tester/node_modules/prettier": { + "version": "2.8.8", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.8.8.tgz", + "integrity": "sha512-tdN8qQGvNjw4CHbY+XXk0JgCXn9QiF21a55rBe5LJAU+kDyC4WQn4+awm2Xfk2lQMk5fKup9XgzTZtGkjBdP9Q==", + "dev": true, + "bin": { + "prettier": "bin-prettier.js" + }, + "engines": { + "node": ">=10.13.0" + }, + "funding": { + "url": "https://github.com/prettier/prettier?sponsor=1" } }, "node_modules/balanced-match": { @@ -15407,13 +15435,30 @@ } }, "babel-plugin-tester": { - "version": "7.0.4", - "resolved": "https://registry.npmjs.org/babel-plugin-tester/-/babel-plugin-tester-7.0.4.tgz", - "integrity": "sha512-ZKhOa0aaaPNQVOZjxJ4svy8lIKjHswzCNxv3WROmirlFz+5IM22hzNg+p4MGC/C3Tv3sX5JfYSKJIcUE9aPdsA==", + "version": "11.0.4", + "resolved": "https://registry.npmjs.org/babel-plugin-tester/-/babel-plugin-tester-11.0.4.tgz", + "integrity": "sha512-cqswtpSPo0e++rZB0l/54EG17LL25l9gLgh59yXfnmNxX+2lZTIOpx2zt4YI9QIClVXc8xf63J6yWwKkzy0jNg==", "dev": true, "requires": { + "core-js": "^3.27.2", + "debug": "^4.3.4", "lodash.mergewith": "^4.6.2", + "prettier": "^2.8.3", "strip-indent": "^3.0.0" + }, + "dependencies": { + "core-js": { + "version": "3.38.0", + "resolved": "https://registry.npmjs.org/core-js/-/core-js-3.38.0.tgz", + "integrity": "sha512-XPpwqEodRljce9KswjZShh95qJ1URisBeKCjUdq27YdenkslVe7OO0ZJhlYXAChW7OhXaRLl8AAba7IBfoIHug==", + "dev": true + }, + "prettier": { + "version": "2.8.8", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.8.8.tgz", + "integrity": "sha512-tdN8qQGvNjw4CHbY+XXk0JgCXn9QiF21a55rBe5LJAU+kDyC4WQn4+awm2Xfk2lQMk5fKup9XgzTZtGkjBdP9Q==", + "dev": true + } } }, "balanced-match": { diff --git a/package.json b/package.json index fbd00f390..4adfddd71 100644 --- a/package.json +++ b/package.json @@ -93,7 +93,7 @@ "all-contributors-cli": "^6.26.1", "babel-core": "^7.0.0-bridge.0", "babel-plugin-macros": "^3.1.0", - "babel-plugin-tester": "^7.0.4", + "babel-plugin-tester": "^11.0.4", "coveralls": "^3.1.1", "cpy-cli": "^5.0.0", "cross-env": "^7.0.3", diff --git a/test/__snapshots__/icu.macro.spec.js.snap b/test/__snapshots__/icu.macro.spec.js.snap index 424e6dfa9..5f6794d58 100644 --- a/test/__snapshots__/icu.macro.spec.js.snap +++ b/test/__snapshots__/icu.macro.spec.js.snap @@ -2,193 +2,290 @@ exports[`macros > 1. macros > 1. macros 1`] = ` " -import { Trans } from '../icu.macro' + +import { Trans } from '../../../icu.macro' const x = Welcome, { name }! + ↓ ↓ ↓ ↓ ↓ ↓ -import { Trans } from "react-i18next"; -const x = ; +import { Trans } from 'react-i18next'; +const x = ( + +); " `; exports[`macros > 2. macros > 2. macros 1`] = ` " -import { Trans } from '../icu.macro' + +import { Trans } from '../../../icu.macro' const x = Welcome, { name }! + ↓ ↓ ↓ ↓ ↓ ↓ -import { Trans } from "react-i18next"; -const x = {name}]} values={{ - name -}} />; +import { Trans } from 'react-i18next'; +const x = ( + {name}]} + values={{ + name, + }} + /> +); " `; exports[`macros > 3. macros > 3. macros 1`] = ` " -import { Trans } from '../icu.macro' + +import { Trans } from '../../../icu.macro' import { useTranslation } from 'react-i18next' const x = Trainers: { trainersCount, number } + ↓ ↓ ↓ ↓ ↓ ↓ import { useTranslation, Trans } from 'react-i18next'; -const x = ; +const x = ( + +); " `; exports[`macros > 4. macros > 4. macros 1`] = ` " -import { Trans } from '../icu.macro' + +import { Trans } from '../../../icu.macro' const x = Trainers: { trainersCount, number }! + ↓ ↓ ↓ ↓ ↓ ↓ -import { Trans } from "react-i18next"; -const x = {(trainersCount)}]} values={{ - trainersCount -}} />; +import { Trans } from 'react-i18next'; +const x = ( + {trainersCount}]} + values={{ + trainersCount, + }} + /> +); " `; exports[`macros > 5. macros > 5. macros 1`] = ` " -import { Trans } from '../icu.macro' + +import { Trans } from '../../../icu.macro' const x = Caught on { catchDate, date, short } + ↓ ↓ ↓ ↓ ↓ ↓ -import { Trans } from "react-i18next"; -const x = ; +import { Trans } from 'react-i18next'; +const x = ( + +); " `; exports[`macros > 6. macros > 6. macros 1`] = ` " -import { Trans } from '../icu.macro' + +import { Trans } from '../../../icu.macro' const x = Caught on { catchDate, date, short }! + ↓ ↓ ↓ ↓ ↓ ↓ -import { Trans } from "react-i18next"; -const x = {(catchDate)}]} values={{ - catchDate -}} />; +import { Trans } from 'react-i18next'; +const x = ( + {catchDate}]} + values={{ + catchDate, + }} + /> +); " `; exports[`macros > 7. macros > 7. macros 1`] = ` " -import { Trans } from '../icu.macro' + +import { Trans } from '../../../icu.macro' const x = + ↓ ↓ ↓ ↓ ↓ ↓ -import { Trans } from "react-i18next"; -const x = ; +import { Trans } from 'react-i18next'; +const x = ( + +); " `; exports[`macros > 8. macros > 8. macros 1`] = ` " -import { Trans } from '../icu.macro' + +import { Trans } from '../../../icu.macro' const x = + ↓ ↓ ↓ ↓ ↓ ↓ -import { Trans } from "react-i18next"; -const x = {(trainersCount)}]} values={{ - trainersCount -}} />; +import { Trans } from 'react-i18next'; +const x = ( + {trainersCount}]} + values={{ + trainersCount, + }} + /> +); " `; exports[`macros > 9. macros > 9. macros 1`] = ` " -import { Trans } from '../icu.macro' + +import { Trans } from '../../../icu.macro' const x = + ↓ ↓ ↓ ↓ ↓ ↓ -import { Trans } from "react-i18next"; -const x = ; +import { Trans } from 'react-i18next'; +const x = ( + +); " `; exports[`macros > 10. macros > 10. macros 1`] = ` " -import { Trans } from '../icu.macro' + +import { Trans } from '../../../icu.macro' const x = + ↓ ↓ ↓ ↓ ↓ ↓ -import { Trans } from "react-i18next"; -const x = {(catchDate)}]} values={{ - catchDate -}} />; +import { Trans } from 'react-i18next'; +const x = ( + {catchDate}]} + values={{ + catchDate, + }} + /> +); " `; exports[`macros > 11. macros > 11. macros 1`] = ` " -import { Trans } from '../icu.macro' + +import { Trans } from '../../../icu.macro' const Link = ({to, children}) => ({children}) const x = This should be overridden by defaults + ↓ ↓ ↓ ↓ ↓ ↓ -import { Trans } from "react-i18next"; -const Link = ({ - to, - children -}) => {children}; -const x = {(catchDate)}]} />; +import { Trans } from 'react-i18next'; +const Link = ({ to, children }) => {children}; +const x = ( + {catchDate}]} + /> +); " `; exports[`macros > 12. macros > 12. macros 1`] = ` " -import { Trans } from '../icu.macro' + +import { Trans } from '../../../icu.macro' const x = + ↓ ↓ ↓ ↓ ↓ ↓ -import { Trans } from "react-i18next"; -const x = ; +import { Trans } from 'react-i18next'; +const x = ( + +); " `; exports[`macros > 13. macros > 13. macros 1`] = ` " -import { Select } from '../icu.macro' + +import { Select } from '../../../icu.macro' const x = She avoids bugs.} other={They avoid bugs.} /> + ↓ ↓ ↓ ↓ ↓ ↓ -import { Trans } from "react-i18next"; -const x = He, She, They]} values={{ - gender -}} />; +import { Trans } from 'react-i18next'; +const x = ( + He, She, They]} + values={{ + gender, + }} + /> +); " `; exports[`macros > 15. macros > 15. macros 1`] = ` " -import { Plural } from '../icu.macro' + +import { Plural } from '../../../icu.macro' const x = + ↓ ↓ ↓ ↓ ↓ ↓ -import { Trans } from "react-i18next"; -const x = ; +import { Trans } from 'react-i18next'; +const x = ( + +); " `; exports[`macros > 16. macros > 16. macros 1`] = ` " -import { Plural } from '../icu.macro' + +import { Plural } from '../../../icu.macro' const x = There is # item.} other={There are # items.} /> + ↓ ↓ ↓ ↓ ↓ ↓ -import { Trans } from "react-i18next"; -const x = no, #, #]} values={{ - itemsCount3 -}} />; +import { Trans } from 'react-i18next'; +const x = ( + no, #, #]} + values={{ + itemsCount3, + }} + /> +); " `; exports[`macros > 17. macros > 17. macros 1`] = ` " -import { Plural } from '../icu.macro' + +import { Plural } from '../../../icu.macro' const x = There is # item on the {location}.} other={There are # items on the {location}.} /> + ↓ ↓ ↓ ↓ ↓ ↓ -import { Trans } from "react-i18next"; -const x = no, {location}, #, {location}, #, {location}]} values={{ - itemsCount3, - location: 'table' -}} />; +import { Trans } from 'react-i18next'; +const x = ( + no, + {location}, + #, + {location}, + #, + {location}, + ]} + values={{ + itemsCount3, + location: 'table', + }} + /> +); " `; exports[`macros > 18. macros > 18. macros 1`] = ` " -import { SelectOrdinal } from '../icu.macro' + +import { SelectOrdinal } from '../../../icu.macro' const x = + ↓ ↓ ↓ ↓ ↓ ↓ -import { Trans } from "react-i18next"; -const x = ; +import { Trans } from 'react-i18next'; +const x = ( + +); " `; exports[`macros > 19. macros > 19. macros 1`] = ` " -import { SelectOrdinal } from '../icu.macro' + +import { SelectOrdinal } from '../../../icu.macro' const x = You are #th in line} $0={You are #th in line} /> + ↓ ↓ ↓ ↓ ↓ ↓ -import { Trans } from "react-i18next"; -const x = #st in line, #nd in line, #rd in line, #th in line, #th in line]} values={{ - position -}} />; +import { Trans } from 'react-i18next'; +const x = ( + #st in line, + #nd in line, + #rd in line, + #th in line, + #th in line, + ]} + values={{ + position, + }} + /> +); " `; exports[`macros > 20. macros > 20. macros 1`] = ` " + import React from 'react' import { useTranslation } from 'react-i18next' -import { Plural, Select, SelectOrdinal, Trans } from '../icu.macro' +import { Plural, Select, SelectOrdinal, Trans } from '../../../icu.macro' const Link = ({to, children}) => ({children}) export default function TestPage({count = 1}) { @@ -446,78 +616,152 @@ export default function TestPage({count = 1}) { ) } + ↓ ↓ ↓ ↓ ↓ ↓ import React from 'react'; import { useTranslation, Trans } from 'react-i18next'; -const Link = ({ - to, - children -}) => {children}; -export default function TestPage({ - count = 1 -}) { +const Link = ({ to, children }) => {children}; +export default function TestPage({ count = 1 }) { const [t] = useTranslation(); const catchDate = Date.now(); const completion = 0.75; const gender = Math.random() < 0.5 ? 'female' : 'male'; - return <> - {t('sample.text', 'Some sample text with {word} {gender} {count, number} {catchDate, date} {completion, number, percent}', { - word: 'interpolation', - gender, - count, - catchDate, - completion - })} - Your cart, empty, # item, your cart, # items, your cart]} values={{ - linkPath: "/item/" + count - }} /> - her items, his items, their items]} values={{ - gender - }} /> - #st item, #nd item, #rd item, #th item]} values={{ - linkPath: "/item/" + itemIndex - }} /> - {(completion)} of your tasks]} values={{ - completion - }} /> - {(catchDate)}]} values={{ - catchDate - }} /> - - #st {type} - , - #nd {type} - , - #rd {type} - , - #th {type} - ]} values={{ - linkPath: \`/item/\${count}\`, - type: 'item', - prop - }} /> - - He - , - She - , - They - ]} values={{ - selectKey: \`\${gender}Person\`, - linkPath: \`/users/\${number}\`, - type: 'bugs' - }} /> - ; + return ( + <> + {t( + 'sample.text', + 'Some sample text with {word} {gender} {count, number} {catchDate, date} {completion, number, percent}', + { + word: 'interpolation', + gender, + count, + catchDate, + completion, + }, + )} + Your cart, + empty, + # item, + your cart, + # items, + your cart, + ]} + values={{ + linkPath: '/item/' + count, + }} + /> + her items, + his items, + their items, + ]} + values={{ + gender, + }} + /> + + #st item + , + + #nd item + , + + #rd item + , + + #th item + , + ]} + values={{ + linkPath: '/item/' + itemIndex, + }} + /> + {completion} of your tasks]} + values={{ + completion, + }} + /> + {catchDate}]} + values={{ + catchDate, + }} + /> + + #st {type} + , + + #nd {type} + , + + #rd {type} + , + + #th {type} + , + ]} + values={{ + linkPath: \`/item/\${count}\`, + type: 'item', + prop, + }} + /> + + He + , + + She + , + + They + , + ]} + values={{ + selectKey: \`\${gender}Person\`, + linkPath: \`/users/\${number}\`, + type: 'bugs', + }} + /> + + ); } " `; exports[`macros > 21. macros > 21. macros 1`] = ` " + import React from "react" -import { Trans, number, date, time, plural, select, selectOrdinal } from "../icu.macro"; +import { Trans, number, date, time, plural, select, selectOrdinal } from "../../../icu.macro"; function Component({ children, style }) { return
{children}
@@ -539,45 +783,64 @@ const x = ( }} \`}
); + ↓ ↓ ↓ ↓ ↓ ↓ -import { Trans, number, date, plural, select } from "react-i18next"; -import React from "react"; -function Component({ - children, - style -}) { +import { Trans, number, date, plural, select } from 'react-i18next'; +import React from 'react'; +function Component({ children, style }) { return
{children}
; } const count = 2; const numbers = 34; -const selectInput = "thing"; +const selectInput = 'thing'; const now = new Date(); -const x = exciting!, friend, - with regular text and a date:
{date\`\${now}\`}
-
]} values={{ - count, - numbers, - selectInput, - now -}} />; +const x = ( + exciting!, + friend, + + with regular text and a date:
{date\`\${now}\`}
+
, + ]} + values={{ + count, + numbers, + selectInput, + now, + }} + /> +); " `; exports[`macros > 22. macros > 22. macros 1`] = ` " -import { Trans } from "../icu.macro"; + +import { Trans } from "../../../icu.macro"; const x = Welcome, "{ name }"! + ↓ ↓ ↓ ↓ ↓ ↓ -import { Trans } from "react-i18next"; -const x = ; +import { Trans } from 'react-i18next'; +const x = ( + +); " `; diff --git a/test/icu.macro.spec.js b/test/icu.macro.spec.js index b7082e9c7..4d1afb79a 100644 --- a/test/icu.macro.spec.js +++ b/test/icu.macro.spec.js @@ -19,81 +19,81 @@ pluginTester({ babelOptions: { filename: __filename, parserOpts: { plugins: ['jsx'] } }, tests: [ ` - import { Trans } from '../icu.macro' + import { Trans } from '../../../icu.macro' const x = Welcome, { name }! `, ` - import { Trans } from '../icu.macro' + import { Trans } from '../../../icu.macro' const x = Welcome, { name }! `, ` - import { Trans } from '../icu.macro' + import { Trans } from '../../../icu.macro' import { useTranslation } from 'react-i18next' const x = Trainers: { trainersCount, number } `, ` - import { Trans } from '../icu.macro' + import { Trans } from '../../../icu.macro' const x = Trainers: { trainersCount, number }! `, ` - import { Trans } from '../icu.macro' + import { Trans } from '../../../icu.macro' const x = Caught on { catchDate, date, short } `, ` - import { Trans } from '../icu.macro' + import { Trans } from '../../../icu.macro' const x = Caught on { catchDate, date, short }! `, ` - import { Trans } from '../icu.macro' + import { Trans } from '../../../icu.macro' const x = `, ` - import { Trans } from '../icu.macro' + import { Trans } from '../../../icu.macro' const x = `, ` - import { Trans } from '../icu.macro' + import { Trans } from '../../../icu.macro' const x = `, ` - import { Trans } from '../icu.macro' + import { Trans } from '../../../icu.macro' const x = `, ` - import { Trans } from '../icu.macro' + import { Trans } from '../../../icu.macro' const Link = ({to, children}) => ({children}) - + const x = This should be overridden by defaults `, ` - import { Trans } from '../icu.macro' - + import { Trans } from '../../../icu.macro' + const x = `, ` - import { Select } from '../icu.macro' + import { Select } from '../../../icu.macro' const x =