From dfa89496d524900b14a10ce405a91965a3023602 Mon Sep 17 00:00:00 2001 From: Jordan Thomson Date: Wed, 11 Dec 2024 19:02:12 +1100 Subject: [PATCH 01/11] Preparing for React 19 --- package.json | 15 +-- src/index.spec.js | 21 ++++- src/parser/parseReactElement.js | 2 +- yarn.lock | 158 ++++++++++++++------------------ 4 files changed, 98 insertions(+), 98 deletions(-) diff --git a/package.json b/package.json index 7fe260171..a9b5fb48a 100644 --- a/package.json +++ b/package.json @@ -43,8 +43,9 @@ "@babel/preset-react": "7.24.1", "@commitlint/cli": "8.3.6", "@commitlint/config-angular": "8.3.6", + "@testing-library/dom": "10.4.0", "@testing-library/jest-dom": "5.17.0", - "@testing-library/react": "13.4.0", + "@testing-library/react": "16.1.0", "babel-eslint": "10.1.0", "babel-jest": "24.9.0", "babel-register": "6.26.0", @@ -67,9 +68,9 @@ "lint-staged": "10.5.4", "mversion": "2.0.1", "prettier": "1.19.1", - "react": "18.2.0", - "react-dom": "18.2.0", - "react-test-renderer": "18.2.0", + "react": "19.0.0", + "react-dom": "19.0.0", + "react-shallow-renderer": "16.15.0", "rollup": "2.79.1", "rollup-plugin-babel": "4.4.0", "rollup-plugin-node-builtins": "2.1.2", @@ -78,13 +79,13 @@ "rollup-plugin-sourcemaps": "0.6.3" }, "peerDependencies": { - "react": "^0.14.8 || ^15.0.1 || ^16.0.0 || ^17.0.1 || ^18.0.0", - "react-dom": "^0.14.8 || ^15.0.1 || ^16.0.0 || ^17.0.1 || ^18.0.0" + "react": "^0.14.8 || ^15.0.1 || ^16.0.0 || ^17.0.1 || ^18.0.0 || ^19.0.0", + "react-dom": "^0.14.8 || ^15.0.1 || ^16.0.0 || ^17.0.1 || ^18.0.0 || ^19.0.0" }, "dependencies": { "@base2/pretty-print-object": "1.0.2", "is-plain-object": "5.0.0", - "react-is": "18.2.0" + "react-is": "19.0.0" }, "jest": { "setupFilesAfterEnv": [ diff --git a/src/index.spec.js b/src/index.spec.js index e7ec29b08..274557570 100644 --- a/src/index.spec.js +++ b/src/index.spec.js @@ -7,7 +7,7 @@ /* eslint-disable react/no-string-refs */ import React, { Fragment, Component } from 'react'; -import { createRenderer } from 'react-test-renderer/shallow'; +import ShallowRenderer from 'react-shallow-renderer'; import { render, screen } from '@testing-library/react'; import reactElementToJSXString, { preserveFunctionLineBreak } from './index'; import AnonymousStatelessComponent from './AnonymousStatelessComponent'; @@ -654,7 +654,7 @@ describe('reactElementToJSXString(ReactElement)', () => { } const NestedSpan = myDecorator(); - const renderer = createRenderer(); + const renderer = new ShallowRenderer(); renderer.render(); expect(reactElementToJSXString(renderer.getRenderOutput())).toEqual( `
@@ -671,7 +671,7 @@ describe('reactElementToJSXString(ReactElement)', () => { } } - const renderer = createRenderer(); + const renderer = new ShallowRenderer(); renderer.render(); const actualElement = renderer.getRenderOutput(); expect(reactElementToJSXString(actualElement)).toEqual( @@ -1300,6 +1300,21 @@ describe('reactElementToJSXString(ReactElement)', () => { `); }); + it('should stringify `Context` correctly', () => { + const Ctx = React.createContext(); + const App = () => {}; + + expect( + reactElementToJSXString( + + + + ) + ).toEqual(` + +`); + }); + it('should stringify `Contex.Provider` with `displayName` correctly', () => { const Ctx = React.createContext(); Ctx.displayName = 'MyCtx'; diff --git a/src/parser/parseReactElement.js b/src/parser/parseReactElement.js index 589a59169..fb946d893 100644 --- a/src/parser/parseReactElement.js +++ b/src/parser/parseReactElement.js @@ -61,7 +61,7 @@ const getReactElementDisplayName = (element: ReactElement<*>): string => { case isContextConsumer(element): return `${element.type._context.displayName || 'Context'}.Consumer`; case isContextProvider(element): - return `${element.type._context.displayName || 'Context'}.Provider`; + return `${element.type.displayName || 'Context'}.Provider`; case isLazy(element): return 'Lazy'; case isProfiler(element): diff --git a/yarn.lock b/yarn.lock index d002719af..d4a6fb999 100644 --- a/yarn.lock +++ b/yarn.lock @@ -31,13 +31,22 @@ "@nicolo-ribaudo/chokidar-2" "2.1.8-no-fsevents.3" chokidar "^3.4.0" -"@babel/code-frame@^7.0.0", "@babel/code-frame@^7.10.4", "@babel/code-frame@^7.12.13", "@babel/code-frame@^7.16.7": +"@babel/code-frame@^7.0.0", "@babel/code-frame@^7.12.13", "@babel/code-frame@^7.16.7": version "7.16.7" resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.16.7.tgz#44416b6bd7624b998f5b1af5d470856c40138789" integrity sha512-iAXqUn8IIeBTNd72xsFlgaXHkMBMt6y4HJp1tIaK465CWLT/fG1aqB7ykr95gHHmlBdGbFeWWfyB4NJJ0nmeIg== dependencies: "@babel/highlight" "^7.16.7" +"@babel/code-frame@^7.10.4": + version "7.26.2" + resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.26.2.tgz#4b5fab97d33338eff916235055f0ebc21e573a85" + integrity sha512-RJlIHRueQgwWitWgF8OdFYGZX328Ax5BCemNGlqHfplnRT9ESi8JkFlvaVYbS+UubVY6dpv87Fs2u5M29iNFVQ== + dependencies: + "@babel/helper-validator-identifier" "^7.25.9" + js-tokens "^4.0.0" + picocolors "^1.0.0" + "@babel/code-frame@^7.22.13": version "7.22.13" resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.22.13.tgz#e3c1c099402598483b7a8c46a721d1038803755e" @@ -505,6 +514,11 @@ resolved "https://registry.yarnpkg.com/@babel/helper-validator-identifier/-/helper-validator-identifier-7.22.5.tgz#9544ef6a33999343c8740fa51350f30eeaaaf193" integrity sha512-aJXu+6lErq8ltp+JhkJUfk1MTGyuA4v7f3pA+BJ5HLfNC6nAQ0Cpi9uOquUj8Hehg0aUiHzWQbOVJGao6ztBAQ== +"@babel/helper-validator-identifier@^7.25.9": + version "7.25.9" + resolved "https://registry.yarnpkg.com/@babel/helper-validator-identifier/-/helper-validator-identifier-7.25.9.tgz#24b64e2c3ec7cd3b3c547729b8d16871f22cbdc7" + integrity sha512-Ed61U6XJc3CVRfkERJWDz4dJwKe7iLmmJsbOGu9wSloNSFttHV0I8g6UAgb7qnK5ly5bGLPd4oXZlxCdANBOWQ== + "@babel/helper-validator-option@^7.16.7": version "7.16.7" resolved "https://registry.yarnpkg.com/@babel/helper-validator-option/-/helper-validator-option-7.16.7.tgz#b203ce62ce5fe153899b617c08957de860de4d23" @@ -2055,18 +2069,18 @@ dependencies: defer-to-connect "^1.0.1" -"@testing-library/dom@^8.5.0": - version "8.13.0" - resolved "https://registry.yarnpkg.com/@testing-library/dom/-/dom-8.13.0.tgz#bc00bdd64c7d8b40841e27a70211399ad3af46f5" - integrity sha512-9VHgfIatKNXQNaZTtLnalIy0jNZzY35a4S3oi08YAt9Hv1VsfZ/DfA45lM8D/UhtHBGJ4/lGwp0PZkVndRkoOQ== +"@testing-library/dom@10.4.0": + version "10.4.0" + resolved "https://registry.yarnpkg.com/@testing-library/dom/-/dom-10.4.0.tgz#82a9d9462f11d240ecadbf406607c6ceeeff43a8" + integrity sha512-pemlzrSESWbdAloYml3bAJMEfNh1Z7EduzqPKprCH5S341frlpYnUEW0H72dLxa6IsYr+mPno20GiSm+h9dEdQ== dependencies: "@babel/code-frame" "^7.10.4" "@babel/runtime" "^7.12.5" - "@types/aria-query" "^4.2.0" - aria-query "^5.0.0" + "@types/aria-query" "^5.0.1" + aria-query "5.3.0" chalk "^4.1.0" dom-accessibility-api "^0.5.9" - lz-string "^1.4.4" + lz-string "^1.5.0" pretty-format "^27.0.2" "@testing-library/jest-dom@5.17.0": @@ -2084,14 +2098,12 @@ lodash "^4.17.15" redent "^3.0.0" -"@testing-library/react@13.4.0": - version "13.4.0" - resolved "https://registry.yarnpkg.com/@testing-library/react/-/react-13.4.0.tgz#6a31e3bf5951615593ad984e96b9e5e2d9380966" - integrity sha512-sXOGON+WNTh3MLE9rve97ftaZukN3oNf2KjDy7YTx6hcTO2uuLHuCGynMDhFwGw/jYf4OJ2Qk0i4i79qMNNkyw== +"@testing-library/react@16.1.0": + version "16.1.0" + resolved "https://registry.yarnpkg.com/@testing-library/react/-/react-16.1.0.tgz#aa0c61398bac82eaf89776967e97de41ac742d71" + integrity sha512-Q2ToPvg0KsVL0ohND9A3zLJWcOXXcO8IDu3fj11KhNt0UlCWyFyvnCIBkd12tidB2lkiVRG8VFqdhcqhqnAQtg== dependencies: "@babel/runtime" "^7.12.5" - "@testing-library/dom" "^8.5.0" - "@types/react-dom" "^18.0.0" "@textlint/ast-node-types@^4.0.3": version "4.4.3" @@ -2116,10 +2128,10 @@ resolved "https://registry.yarnpkg.com/@tootallnate/once/-/once-1.1.2.tgz#ccb91445360179a04e7fe6aff78c00ffc1eeaf82" integrity sha512-RbzJvlNzmRq5c3O09UipeuXno4tA1FE6ikOjxZK0tuxVv3412l64l5t1W5pj4+rJq9vpkm/kwiR07aZXnsKPxw== -"@types/aria-query@^4.2.0": - version "4.2.2" - resolved "https://registry.yarnpkg.com/@types/aria-query/-/aria-query-4.2.2.tgz#ed4e0ad92306a704f9fb132a0cfcf77486dbe2bc" - integrity sha512-HnYpAE1Y6kRyKM/XkEuiRQhTHvkzMBurTHnpFLYLBGPIylZNPs9jJcuOOYWxPLJCSEtmZT0Y8rHDokKN7rRTig== +"@types/aria-query@^5.0.1": + version "5.0.4" + resolved "https://registry.yarnpkg.com/@types/aria-query/-/aria-query-5.0.4.tgz#1a31c3d378850d2778dabb6374d036dcba4ba708" + integrity sha512-rfT93uj5s0PRL7EzccGMs3brplhcrghnDoV26NqKhCAS1hVo+WdNsPvE/yb6ilfr5hi2MEk6d5EWJTKdxg8jVw== "@types/babel__core@^7.0.0", "@types/babel__core@^7.1.0", "@types/babel__core@^7.1.14": version "7.1.19" @@ -2236,27 +2248,6 @@ resolved "https://registry.yarnpkg.com/@types/prettier/-/prettier-2.6.1.tgz#76e72d8a775eef7ce649c63c8acae1a0824bbaed" integrity sha512-XFjFHmaLVifrAKaZ+EKghFHtHSUonyw8P2Qmy2/+osBnrKbH9UYtlK10zg8/kCt47MFilll/DEDKy3DHfJ0URw== -"@types/prop-types@*": - version "15.7.5" - resolved "https://registry.yarnpkg.com/@types/prop-types/-/prop-types-15.7.5.tgz#5f19d2b85a98e9558036f6a3cacc8819420f05cf" - integrity sha512-JCB8C6SnDoQf0cNycqd/35A7MjcnK+ZTqE7judS6o7utxUCg6imJg3QK2qzHKszlTjcj2cn+NwMB2i96ubpj7w== - -"@types/react-dom@^18.0.0": - version "18.0.4" - resolved "https://registry.yarnpkg.com/@types/react-dom/-/react-dom-18.0.4.tgz#dcbcadb277bcf6c411ceff70069424c57797d375" - integrity sha512-FgTtbqPOCI3dzZPZoC2T/sx3L34qxy99ITWn4eoSA95qPyXDMH0ALoAqUp49ITniiJFsXUVBtalh/KffMpg21Q== - dependencies: - "@types/react" "*" - -"@types/react@*": - version "18.0.9" - resolved "https://registry.yarnpkg.com/@types/react/-/react-18.0.9.tgz#d6712a38bd6cd83469603e7359511126f122e878" - integrity sha512-9bjbg1hJHUm4De19L1cHiW0Jvx3geel6Qczhjd0qY5VKVE2X5+x77YxAepuCwVh4vrgZJdgEJw48zrhRIeF4Nw== - dependencies: - "@types/prop-types" "*" - "@types/scheduler" "*" - csstype "^3.0.2" - "@types/resolve@0.0.8": version "0.0.8" resolved "https://registry.yarnpkg.com/@types/resolve/-/resolve-0.0.8.tgz#f26074d238e02659e323ce1a13d041eee280e194" @@ -2264,11 +2255,6 @@ dependencies: "@types/node" "*" -"@types/scheduler@*": - version "0.16.2" - resolved "https://registry.yarnpkg.com/@types/scheduler/-/scheduler-0.16.2.tgz#1a62f89525723dde24ba1b01b092bf5df8ad4d39" - integrity sha512-hppQEBDmlwhFAXKJX2KnWLYu5yMfi91yazPb2l+lbJiwW+wdo1gNeRA+3RgNSO39WYX2euey41KEwnqesU2Jew== - "@types/stack-utils@^1.0.1": version "1.0.1" resolved "https://registry.yarnpkg.com/@types/stack-utils/-/stack-utils-1.0.1.tgz#0a851d3bd96498fa25c33ab7278ed3bd65f06c3e" @@ -2510,6 +2496,13 @@ argparse@^1.0.7: dependencies: sprintf-js "~1.0.2" +aria-query@5.3.0: + version "5.3.0" + resolved "https://registry.yarnpkg.com/aria-query/-/aria-query-5.3.0.tgz#650c569e41ad90b51b3d7df5e5eed1c7549c103e" + integrity sha512-b0P0sZPKtyu8HkeRAfCq0IfURZK+SuwMjY1UXGBU27wpAiTwQAIlq56IbIO+ytk/JjS1fMR14ee5WBBfKi5J6A== + dependencies: + dequal "^2.0.3" + aria-query@^5.0.0: version "5.0.0" resolved "https://registry.yarnpkg.com/aria-query/-/aria-query-5.0.0.tgz#210c21aaf469613ee8c9a62c7f86525e058db52c" @@ -3991,11 +3984,6 @@ cssstyle@^2.3.0: dependencies: cssom "~0.3.6" -csstype@^3.0.2: - version "3.1.0" - resolved "https://registry.yarnpkg.com/csstype/-/csstype-3.1.0.tgz#4ddcac3718d787cf9df0d1b7d15033925c8f29f2" - integrity sha512-uX1KG+x9h5hIJsaKR9xHUeUraxf8IODOwq9JLNPq6BwB04a/xgpq3rcx47l5BZu5zBPlgD342tdke3Hom/nJRA== - currently-unhandled@^0.4.1: version "0.4.1" resolved "https://registry.yarnpkg.com/currently-unhandled/-/currently-unhandled-0.4.1.tgz#988df33feab191ef799a61369dd76c17adf957ea" @@ -4157,6 +4145,11 @@ delayed-stream@~1.0.0: resolved "https://registry.yarnpkg.com/delayed-stream/-/delayed-stream-1.0.0.tgz#df3ae199acadfb7d440aaae0b29e2272b24ec619" integrity sha1-3zrhmayt+31ECqrgsp4icrJOxhk= +dequal@^2.0.3: + version "2.0.3" + resolved "https://registry.yarnpkg.com/dequal/-/dequal-2.0.3.tgz#2644214f1997d39ed0ee0ece72335490a7ac67be" + integrity sha512-0je+qPKHEMohvfRTCEo3CrPG6cAzAYgmzKyxRiYSSDkS6eGJdyVJm7WaYA5ECaAD9wLB2T4EEeymA5aFVcYXCA== + des.js@^1.0.0: version "1.0.1" resolved "https://registry.yarnpkg.com/des.js/-/des.js-1.0.1.tgz#5382142e1bdc53f85d86d53e5f4aa7deb91e0843" @@ -4217,11 +4210,16 @@ doctrine@^3.0.0: dependencies: esutils "^2.0.2" -dom-accessibility-api@^0.5.6, dom-accessibility-api@^0.5.9: +dom-accessibility-api@^0.5.6: version "0.5.14" resolved "https://registry.yarnpkg.com/dom-accessibility-api/-/dom-accessibility-api-0.5.14.tgz#56082f71b1dc7aac69d83c4285eef39c15d93f56" integrity sha512-NMt+m9zFMPZe0JcY9gN224Qvk6qLIdqex29clBvc/y75ZBX9YA9wNK3frsYvu2DI1xcCIwxwnX+TlsJ2DSOADg== +dom-accessibility-api@^0.5.9: + version "0.5.16" + resolved "https://registry.yarnpkg.com/dom-accessibility-api/-/dom-accessibility-api-0.5.16.tgz#5a7429e6066eb3664d911e33fb0e45de8eb08453" + integrity sha512-X7BJ2yElsnOJ30pZF4uIIDfBEVgF4XEBxL9Bxhy6dnrm5hkzqmsWHGTiHqRiITNhMyFLyAiWndIJP7Z1NTteDg== + dom-serializer@0: version "0.2.2" resolved "https://registry.yarnpkg.com/dom-serializer/-/dom-serializer-0.2.2.tgz#1afb81f533717175d478655debc5e332d9f9bb51" @@ -7182,7 +7180,7 @@ log-update@^4.0.0: slice-ansi "^4.0.0" wrap-ansi "^6.2.0" -loose-envify@^1.0.0, loose-envify@^1.1.0, loose-envify@^1.4.0: +loose-envify@^1.0.0, loose-envify@^1.4.0: version "1.4.0" resolved "https://registry.yarnpkg.com/loose-envify/-/loose-envify-1.4.0.tgz#71ee51fa7be4caec1a63839f7e682d8132d30caf" integrity sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q== @@ -7226,10 +7224,10 @@ ltgt@^2.1.2: resolved "https://registry.yarnpkg.com/ltgt/-/ltgt-2.2.1.tgz#f35ca91c493f7b73da0e07495304f17b31f87ee5" integrity sha1-81ypHEk/e3PaDgdJUwTxezH4fuU= -lz-string@^1.4.4: - version "1.4.4" - resolved "https://registry.yarnpkg.com/lz-string/-/lz-string-1.4.4.tgz#c0d8eaf36059f705796e1e344811cf4c498d3a26" - integrity sha1-wNjq82BZ9wV5bh40SBHPTEmNOiY= +lz-string@^1.5.0: + version "1.5.0" + resolved "https://registry.yarnpkg.com/lz-string/-/lz-string-1.5.0.tgz#c1ab50f77887b712621201ba9fd4e3a6ed099941" + integrity sha512-h5bgJWpxJNswbU7qCrV0tIKQCaS3blPDrqKWx+QxzuzL1zGUzij9XCWLrSLsJPu5t+eWA/ycetzYAO5IOMcWAQ== magic-string@^0.22.5: version "0.22.5" @@ -8250,18 +8248,17 @@ rc@^1.2.8: minimist "^1.2.0" strip-json-comments "~2.0.1" -react-dom@18.2.0: - version "18.2.0" - resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-18.2.0.tgz#22aaf38708db2674ed9ada224ca4aa708d821e3d" - integrity sha512-6IMTriUmvsjHUjNtEDudZfuDQUoWXVxKHhlEGSk81n4YFS+r/Kl99wXiwlVXtPBtJenozv2P+hxDsw9eA7Xo6g== +react-dom@19.0.0: + version "19.0.0" + resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-19.0.0.tgz#43446f1f01c65a4cd7f7588083e686a6726cfb57" + integrity sha512-4GV5sHFG0e/0AD4X+ySy6UJd3jVl1iNsNHdpad0qhABJ11twS3TTBnseqsKurKcsNqCEFeGL3uLpVChpIO3QfQ== dependencies: - loose-envify "^1.1.0" - scheduler "^0.23.0" + scheduler "^0.25.0" -react-is@18.2.0, react-is@^18.2.0: - version "18.2.0" - resolved "https://registry.yarnpkg.com/react-is/-/react-is-18.2.0.tgz#199431eeaaa2e09f86427efbb4f1473edb47609b" - integrity sha512-xWGDIW6x921xtzPkhiULtthJHoJvBbF3q26fzloPCK0hsvxtPVelvftw3zjbHWSkR2km9Z+4uxbDDK/6Zw9B8w== +react-is@19.0.0: + version "19.0.0" + resolved "https://registry.yarnpkg.com/react-is/-/react-is-19.0.0.tgz#d6669fd389ff022a9684f708cf6fa4962d1fea7a" + integrity sha512-H91OHcwjZsbq3ClIDHMzBShc1rotbfACdWENsmEf0IFvZ3FgGPtdHMcsv45bQ1hAbgdfiA8SnxTKfDS+x/8m2g== "react-is@^16.12.0 || ^17.0.0 || ^18.0.0": version "18.1.0" @@ -8278,7 +8275,7 @@ react-is@^17.0.1: resolved "https://registry.yarnpkg.com/react-is/-/react-is-17.0.2.tgz#e691d4a8e9c789365655539ab372762b0efb54f0" integrity sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w== -react-shallow-renderer@^16.15.0: +react-shallow-renderer@16.15.0: version "16.15.0" resolved "https://registry.yarnpkg.com/react-shallow-renderer/-/react-shallow-renderer-16.15.0.tgz#48fb2cf9b23d23cde96708fe5273a7d3446f4457" integrity sha512-oScf2FqQ9LFVQgA73vr86xl2NaOIX73rh+YFqcOp68CWj56tSfgtGKrEbyhCj0rSijyG9M1CYprTh39fBi5hzA== @@ -8286,21 +8283,10 @@ react-shallow-renderer@^16.15.0: object-assign "^4.1.1" react-is "^16.12.0 || ^17.0.0 || ^18.0.0" -react-test-renderer@18.2.0: - version "18.2.0" - resolved "https://registry.yarnpkg.com/react-test-renderer/-/react-test-renderer-18.2.0.tgz#1dd912bd908ff26da5b9fca4fd1c489b9523d37e" - integrity sha512-JWD+aQ0lh2gvh4NM3bBM42Kx+XybOxCpgYK7F8ugAlpaTSnWsX+39Z4XkOykGZAHrjwwTZT3x3KxswVWxHPUqA== - dependencies: - react-is "^18.2.0" - react-shallow-renderer "^16.15.0" - scheduler "^0.23.0" - -react@18.2.0: - version "18.2.0" - resolved "https://registry.yarnpkg.com/react/-/react-18.2.0.tgz#555bd98592883255fa00de14f1151a917b5d77d5" - integrity sha512-/3IjMdb2L9QbBdWiW5e3P2/npwMBaU9mHCSCUzNln0ZCYbcfTsGbTJrU/kGemdH2IWmB2ioZ+zkxtmq6g09fGQ== - dependencies: - loose-envify "^1.1.0" +react@19.0.0: + version "19.0.0" + resolved "https://registry.yarnpkg.com/react/-/react-19.0.0.tgz#6e1969251b9f108870aa4bff37a0ce9ddfaaabdd" + integrity sha512-V8AVnmPIICiWpGfm6GLzCR/W5FXLchHop40W4nXBmdlEceh16rCN8O8LNWm5bh5XUX91fh7KpA+W0TgMKmgTpQ== read-pkg-up@^3.0.0: version "3.0.0" @@ -8923,12 +8909,10 @@ saxes@^5.0.1: dependencies: xmlchars "^2.2.0" -scheduler@^0.23.0: - version "0.23.0" - resolved "https://registry.yarnpkg.com/scheduler/-/scheduler-0.23.0.tgz#ba8041afc3d30eb206a487b6b384002e4e61fdfe" - integrity sha512-CtuThmgHNg7zIZWAXi3AsyIzA3n4xx7aNyjwC2VJldO2LMVDhFK+63xGqq6CsJH4rTAt6/M+N4GhZiDYPx9eUw== - dependencies: - loose-envify "^1.1.0" +scheduler@^0.25.0: + version "0.25.0" + resolved "https://registry.yarnpkg.com/scheduler/-/scheduler-0.25.0.tgz#336cd9768e8cceebf52d3c80e3dcf5de23e7e015" + integrity sha512-xFVuu11jh+xcO7JOAGJNOXld8/TcEHK/4CituBUeUb5hqxJLj9YuemAEuvm9gQ/+pgXYfbQuqAkiYu+u7YEsNA== semver-compare@^1.0.0: version "1.0.0" From 9c0421564b0107e89634e00618dfbc77ddb61e45 Mon Sep 17 00:00:00 2001 From: Jordan Thomson Date: Wed, 18 Dec 2024 09:59:38 +1100 Subject: [PATCH 02/11] bump major --- package.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index a9b5fb48a..4604c961c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-element-to-jsx-string", - "version": "15.0.0", + "version": "16.0.0", "description": "Turn a ReactElement into the corresponding JSX string.", "main": "dist/cjs/index.js", "module": "dist/esm/index.js", @@ -79,8 +79,8 @@ "rollup-plugin-sourcemaps": "0.6.3" }, "peerDependencies": { - "react": "^0.14.8 || ^15.0.1 || ^16.0.0 || ^17.0.1 || ^18.0.0 || ^19.0.0", - "react-dom": "^0.14.8 || ^15.0.1 || ^16.0.0 || ^17.0.1 || ^18.0.0 || ^19.0.0" + "react": "^19.0.0", + "react-dom": "^19.0.0" }, "dependencies": { "@base2/pretty-print-object": "1.0.2", From cb37bfbf2dd0ca13b7ab490e3c67ae2c19a88a9a Mon Sep 17 00:00:00 2001 From: Jordan Thomson Date: Tue, 24 Dec 2024 21:26:02 +1100 Subject: [PATCH 03/11] peer deps again --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 4604c961c..ea7d30973 100644 --- a/package.json +++ b/package.json @@ -79,8 +79,8 @@ "rollup-plugin-sourcemaps": "0.6.3" }, "peerDependencies": { - "react": "^19.0.0", - "react-dom": "^19.0.0" + "react": "^0.14.8 || ^15.0.1 || ^16.0.0 || ^17.0.1 || ^18.0.0 || ^19.0.0", + "react-dom": "^0.14.8 || ^15.0.1 || ^16.0.0 || ^17.0.1 || ^18.0.0 || ^19.0.0" }, "dependencies": { "@base2/pretty-print-object": "1.0.2", From 5ee48e9dffadf5ce98b6ee9c4057e7be9525b59b Mon Sep 17 00:00:00 2001 From: Jordan Thomson Date: Tue, 24 Dec 2024 22:55:02 +1100 Subject: [PATCH 04/11] `react-is` peer dep --- package.json | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index ea7d30973..688135410 100644 --- a/package.json +++ b/package.json @@ -70,6 +70,7 @@ "prettier": "1.19.1", "react": "19.0.0", "react-dom": "19.0.0", + "react-is": "19.0.0", "react-shallow-renderer": "16.15.0", "rollup": "2.79.1", "rollup-plugin-babel": "4.4.0", @@ -80,12 +81,12 @@ }, "peerDependencies": { "react": "^0.14.8 || ^15.0.1 || ^16.0.0 || ^17.0.1 || ^18.0.0 || ^19.0.0", - "react-dom": "^0.14.8 || ^15.0.1 || ^16.0.0 || ^17.0.1 || ^18.0.0 || ^19.0.0" + "react-dom": "^0.14.8 || ^15.0.1 || ^16.0.0 || ^17.0.1 || ^18.0.0 || ^19.0.0", + "react-is": "^18.0.0 || ^19.0.0" }, "dependencies": { "@base2/pretty-print-object": "1.0.2", - "is-plain-object": "5.0.0", - "react-is": "19.0.0" + "is-plain-object": "5.0.0" }, "jest": { "setupFilesAfterEnv": [ From f0ab79832d411d3ae4f598c0241d1cb378f3b230 Mon Sep 17 00:00:00 2001 From: Armand Abric Date: Mon, 13 Jan 2025 14:55:48 +0100 Subject: [PATCH 05/11] Only support react 19 --- package.json | 7 +++--- src/index.spec.js | 42 --------------------------------- src/parser/parseReactElement.js | 3 --- yarn.lock | 21 ++++------------- 4 files changed, 7 insertions(+), 66 deletions(-) diff --git a/package.json b/package.json index 688135410..9fe8ea3a9 100644 --- a/package.json +++ b/package.json @@ -71,7 +71,6 @@ "react": "19.0.0", "react-dom": "19.0.0", "react-is": "19.0.0", - "react-shallow-renderer": "16.15.0", "rollup": "2.79.1", "rollup-plugin-babel": "4.4.0", "rollup-plugin-node-builtins": "2.1.2", @@ -80,9 +79,9 @@ "rollup-plugin-sourcemaps": "0.6.3" }, "peerDependencies": { - "react": "^0.14.8 || ^15.0.1 || ^16.0.0 || ^17.0.1 || ^18.0.0 || ^19.0.0", - "react-dom": "^0.14.8 || ^15.0.1 || ^16.0.0 || ^17.0.1 || ^18.0.0 || ^19.0.0", - "react-is": "^18.0.0 || ^19.0.0" + "react": "^19.0.0", + "react-dom": "^19.0.0", + "react-is": "^19.0.0" }, "dependencies": { "@base2/pretty-print-object": "1.0.2", diff --git a/src/index.spec.js b/src/index.spec.js index 274557570..75d8a85a3 100644 --- a/src/index.spec.js +++ b/src/index.spec.js @@ -7,7 +7,6 @@ /* eslint-disable react/no-string-refs */ import React, { Fragment, Component } from 'react'; -import ShallowRenderer from 'react-shallow-renderer'; import { render, screen } from '@testing-library/react'; import reactElementToJSXString, { preserveFunctionLineBreak } from './index'; import AnonymousStatelessComponent from './AnonymousStatelessComponent'; @@ -640,47 +639,6 @@ describe('reactElementToJSXString(ReactElement)', () => { ); }); - it('reactElementToJSXString(decorator()', () => { - function myDecorator(ComposedComponent) { - class MyDecorator extends React.Component { - render() { - return ( -
{React.createElement(ComposedComponent.type, this.props)}
- ); - } - } - MyDecorator.displayName = `${ComposedComponent.name}-Decorated`; - return MyDecorator; - } - - const NestedSpan = myDecorator(); - const renderer = new ShallowRenderer(); - renderer.render(); - expect(reactElementToJSXString(renderer.getRenderOutput())).toEqual( - `
- -
` - ); - }); - - it('reactElementToJSXString(
Hello {this.props.name}
', () => { - /* eslint-disable react/prop-types */ - class InlineProps extends React.Component { - render() { - return
Hello {this.props.name}
; - } - } - - const renderer = new ShallowRenderer(); - renderer.render(); - const actualElement = renderer.getRenderOutput(); - expect(reactElementToJSXString(actualElement)).toEqual( - `
- Hello John -
` - ); - }); - it('reactElementToJSXString(
)', () => { expect(reactElementToJSXString(
)).toEqual( "
" diff --git a/src/parser/parseReactElement.js b/src/parser/parseReactElement.js index fb946d893..64cb8e98d 100644 --- a/src/parser/parseReactElement.js +++ b/src/parser/parseReactElement.js @@ -112,9 +112,6 @@ const parseReactElement = ( const displayName = displayNameFn(element); const props = filterProps(element.props, noChildren); - if (element.ref !== null) { - props.ref = element.ref; - } const key = element.key; if (typeof key === 'string' && key.search(/^\./)) { diff --git a/yarn.lock b/yarn.lock index d4a6fb999..1f4965a0b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8255,16 +8255,6 @@ react-dom@19.0.0: dependencies: scheduler "^0.25.0" -react-is@19.0.0: - version "19.0.0" - resolved "https://registry.yarnpkg.com/react-is/-/react-is-19.0.0.tgz#d6669fd389ff022a9684f708cf6fa4962d1fea7a" - integrity sha512-H91OHcwjZsbq3ClIDHMzBShc1rotbfACdWENsmEf0IFvZ3FgGPtdHMcsv45bQ1hAbgdfiA8SnxTKfDS+x/8m2g== - -"react-is@^16.12.0 || ^17.0.0 || ^18.0.0": - version "18.1.0" - resolved "https://registry.yarnpkg.com/react-is/-/react-is-18.1.0.tgz#61aaed3096d30eacf2a2127118b5b41387d32a67" - integrity sha512-Fl7FuabXsJnV5Q1qIOQwx/sagGF18kogb4gpfcG4gjLBWO0WDiiz1ko/ExayuxE7InyQkBLkxRFG5oxY6Uu3Kg== - react-is@^16.13.1: version "16.13.1" resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.13.1.tgz#789729a4dc36de2999dc156dd6c1d9c18cea56a4" @@ -8275,13 +8265,10 @@ react-is@^17.0.1: resolved "https://registry.yarnpkg.com/react-is/-/react-is-17.0.2.tgz#e691d4a8e9c789365655539ab372762b0efb54f0" integrity sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w== -react-shallow-renderer@16.15.0: - version "16.15.0" - resolved "https://registry.yarnpkg.com/react-shallow-renderer/-/react-shallow-renderer-16.15.0.tgz#48fb2cf9b23d23cde96708fe5273a7d3446f4457" - integrity sha512-oScf2FqQ9LFVQgA73vr86xl2NaOIX73rh+YFqcOp68CWj56tSfgtGKrEbyhCj0rSijyG9M1CYprTh39fBi5hzA== - dependencies: - object-assign "^4.1.1" - react-is "^16.12.0 || ^17.0.0 || ^18.0.0" +react-is@^19.0.0: + version "19.0.0" + resolved "https://registry.yarnpkg.com/react-is/-/react-is-19.0.0.tgz#d6669fd389ff022a9684f708cf6fa4962d1fea7a" + integrity sha512-H91OHcwjZsbq3ClIDHMzBShc1rotbfACdWENsmEf0IFvZ3FgGPtdHMcsv45bQ1hAbgdfiA8SnxTKfDS+x/8m2g== react@19.0.0: version "19.0.0" From ca59a86cb122afdb891ab87da0af41cc79b28512 Mon Sep 17 00:00:00 2001 From: Armand Abric Date: Mon, 13 Jan 2025 15:03:38 +0100 Subject: [PATCH 06/11] Fix yarn version --- package.json | 1 + yarn.lock | 10 +++++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 9fe8ea3a9..ab210fe6d 100644 --- a/package.json +++ b/package.json @@ -2,6 +2,7 @@ "name": "react-element-to-jsx-string", "version": "16.0.0", "description": "Turn a ReactElement into the corresponding JSX string.", + "packageManager": "yarn@1.22.22+sha1.ac34549e6aa8e7ead463a7407e1c7390f61a6610", "main": "dist/cjs/index.js", "module": "dist/esm/index.js", "browser": "dist/cjs/index.js", diff --git a/yarn.lock b/yarn.lock index 1f4965a0b..582db1e88 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8255,6 +8255,11 @@ react-dom@19.0.0: dependencies: scheduler "^0.25.0" +react-is@19.0.0: + version "19.0.0" + resolved "https://registry.yarnpkg.com/react-is/-/react-is-19.0.0.tgz#d6669fd389ff022a9684f708cf6fa4962d1fea7a" + integrity sha512-H91OHcwjZsbq3ClIDHMzBShc1rotbfACdWENsmEf0IFvZ3FgGPtdHMcsv45bQ1hAbgdfiA8SnxTKfDS+x/8m2g== + react-is@^16.13.1: version "16.13.1" resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.13.1.tgz#789729a4dc36de2999dc156dd6c1d9c18cea56a4" @@ -8265,11 +8270,6 @@ react-is@^17.0.1: resolved "https://registry.yarnpkg.com/react-is/-/react-is-17.0.2.tgz#e691d4a8e9c789365655539ab372762b0efb54f0" integrity sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w== -react-is@^19.0.0: - version "19.0.0" - resolved "https://registry.yarnpkg.com/react-is/-/react-is-19.0.0.tgz#d6669fd389ff022a9684f708cf6fa4962d1fea7a" - integrity sha512-H91OHcwjZsbq3ClIDHMzBShc1rotbfACdWENsmEf0IFvZ3FgGPtdHMcsv45bQ1hAbgdfiA8SnxTKfDS+x/8m2g== - react@19.0.0: version "19.0.0" resolved "https://registry.yarnpkg.com/react/-/react-19.0.0.tgz#6e1969251b9f108870aa4bff37a0ce9ddfaaabdd" From 28b29ac2d7a7059cee31715401793e3f84930eea Mon Sep 17 00:00:00 2001 From: Armand Abric Date: Mon, 13 Jan 2025 15:10:46 +0100 Subject: [PATCH 07/11] Upgrade CI --- .github/workflows/continuous-integration.yaml | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/.github/workflows/continuous-integration.yaml b/.github/workflows/continuous-integration.yaml index cfa020948..87f0f2a47 100644 --- a/.github/workflows/continuous-integration.yaml +++ b/.github/workflows/continuous-integration.yaml @@ -8,7 +8,7 @@ jobs: - uses: actions/checkout@v2 - uses: actions/setup-node@v2-beta with: - node-version: '14' + node-version: '22' - name: Get yarn cache directory path id: yarn-cache-dir-path run: echo "::set-output name=dir::$(yarn cache dir)" @@ -23,16 +23,8 @@ jobs: - run: yarn run test - run: yarn run lint - run: yarn run flow - - run: yarn run smoke cjs 15.6.2 - - run: yarn run smoke esm 15.6.2 - - run: yarn run smoke cjs 16.7.0 - - run: yarn run smoke esm 16.7.0 - - run: yarn run smoke cjs 17.0.2 - - run: yarn run smoke esm 17.0.2 - - run: yarn run smoke cjs 18.0.0 - - run: yarn run smoke esm 18.0.0 - - run: yarn run smoke cjs 18.1.0 - - run: yarn run smoke esm 18.1.0 + - run: yarn run smoke cjs 19.0.0 + - run: yarn run smoke esm 19.0.0 - run: yarn run smoke cjs latest - run: yarn run smoke esm latest - run: yarn run smoke cjs next From 9324db37dfdb88eae8ff9e1fb8ac7434dc0dfe2c Mon Sep 17 00:00:00 2001 From: Armand Abric Date: Mon, 13 Jan 2025 15:13:44 +0100 Subject: [PATCH 08/11] Keep upgrading CI --- .github/workflows/continuous-integration.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/continuous-integration.yaml b/.github/workflows/continuous-integration.yaml index 87f0f2a47..3ae0d2a86 100644 --- a/.github/workflows/continuous-integration.yaml +++ b/.github/workflows/continuous-integration.yaml @@ -5,14 +5,14 @@ jobs: name: Continuous Integration runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - uses: actions/setup-node@v2-beta + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 with: node-version: '22' - name: Get yarn cache directory path id: yarn-cache-dir-path run: echo "::set-output name=dir::$(yarn cache dir)" - - uses: actions/cache@v2 + - uses: actions/cache@v4 id: yarn-cache with: path: ${{ steps.yarn-cache-dir-path.outputs.dir }} From 117f38390ea008354521b3d73a8ceb044992d938 Mon Sep 17 00:00:00 2001 From: Armand Abric Date: Mon, 13 Jan 2025 15:15:15 +0100 Subject: [PATCH 09/11] Ignore new lint errors --- src/index.spec.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/index.spec.js b/src/index.spec.js index 75d8a85a3..c27217a49 100644 --- a/src/index.spec.js +++ b/src/index.spec.js @@ -5,6 +5,7 @@ /* @flow */ /* eslint-disable react/no-string-refs */ +/* eslint-disable react/prop-types */ import React, { Fragment, Component } from 'react'; import { render, screen } from '@testing-library/react'; From d6ec12f44b904771cd6e3b0c97a3beb5fd634ef1 Mon Sep 17 00:00:00 2001 From: Armand Abric Date: Mon, 13 Jan 2025 15:28:14 +0100 Subject: [PATCH 10/11] Use node 20 for now --- .github/workflows/continuous-integration.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/continuous-integration.yaml b/.github/workflows/continuous-integration.yaml index 3ae0d2a86..67b9bb69a 100644 --- a/.github/workflows/continuous-integration.yaml +++ b/.github/workflows/continuous-integration.yaml @@ -8,10 +8,10 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 with: - node-version: '22' + node-version: '20' - name: Get yarn cache directory path id: yarn-cache-dir-path - run: echo "::set-output name=dir::$(yarn cache dir)" + run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT - uses: actions/cache@v4 id: yarn-cache with: From 45729747e010be84d6f74625e285df7fb17e5053 Mon Sep 17 00:00:00 2001 From: Armand Abric Date: Mon, 13 Jan 2025 15:29:59 +0100 Subject: [PATCH 11/11] Use actions/setup-node@v4 cache --- .github/workflows/continuous-integration.yaml | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/.github/workflows/continuous-integration.yaml b/.github/workflows/continuous-integration.yaml index 67b9bb69a..c042d6d59 100644 --- a/.github/workflows/continuous-integration.yaml +++ b/.github/workflows/continuous-integration.yaml @@ -9,16 +9,7 @@ jobs: - uses: actions/setup-node@v4 with: node-version: '20' - - name: Get yarn cache directory path - id: yarn-cache-dir-path - run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT - - uses: actions/cache@v4 - id: yarn-cache - with: - path: ${{ steps.yarn-cache-dir-path.outputs.dir }} - key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} - restore-keys: | - ${{ runner.os }}-yarn- + cache: 'yarn' - run: yarn install --frozen-lockfile - run: yarn run test - run: yarn run lint