From a30aac56687598c373c51255308ef5833de0c9bb Mon Sep 17 00:00:00 2001 From: Grant Colestock Date: Sat, 31 Dec 2022 13:08:36 -0600 Subject: [PATCH] fix: make sure jsx fragments are transformed (#19755) Fixes: #19142 --- .../playwright-test/ThirdPartyNotices.txt | 36 +++++++++++++-- .../bundles/babel/package-lock.json | 44 ++++++++++++++++--- .../bundles/babel/package.json | 2 +- .../bundles/babel/src/babelBundleImpl.ts | 2 +- tests/playwright-test/loader.spec.ts | 34 ++++++++++++++ 5 files changed, 105 insertions(+), 13 deletions(-) diff --git a/packages/playwright-test/ThirdPartyNotices.txt b/packages/playwright-test/ThirdPartyNotices.txt index 2d146f82d0..862f476d8c 100644 --- a/packages/playwright-test/ThirdPartyNotices.txt +++ b/packages/playwright-test/ThirdPartyNotices.txt @@ -53,11 +53,12 @@ This project incorporates components from the projects listed below. The origina - @babel/plugin-syntax-private-property-in-object@7.14.5 (https://github.com/babel/babel) - @babel/plugin-syntax-typescript@7.20.0 (https://github.com/babel/babel) - @babel/plugin-transform-modules-commonjs@7.19.6 (https://github.com/babel/babel) +- @babel/plugin-transform-react-jsx@7.20.7 (https://github.com/babel/babel) - @babel/plugin-transform-typescript@7.20.2 (https://github.com/babel/babel) - @babel/preset-typescript@7.18.6 (https://github.com/babel/babel) - @babel/template@7.18.10 (https://github.com/babel/babel) - @babel/traverse@7.20.1 (https://github.com/babel/babel) -- @babel/types@7.20.2 (https://github.com/babel/babel) +- @babel/types@7.20.7 (https://github.com/babel/babel) - @jest/types@27.5.1 (https://github.com/facebook/jest) - @jridgewell/gen-mapping@0.1.1 (https://github.com/jridgewell/gen-mapping) - @jridgewell/gen-mapping@0.3.2 (https://github.com/jridgewell/gen-mapping) @@ -1634,6 +1635,33 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ========================================= END OF @babel/plugin-transform-modules-commonjs@7.19.6 AND INFORMATION +%% @babel/plugin-transform-react-jsx@7.20.7 NOTICES AND INFORMATION BEGIN HERE +========================================= +MIT License + +Copyright (c) 2014-present Sebastian McKenzie and other contributors + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +========================================= +END OF @babel/plugin-transform-react-jsx@7.20.7 AND INFORMATION + %% @babel/plugin-transform-typescript@7.20.2 NOTICES AND INFORMATION BEGIN HERE ========================================= MIT License @@ -1742,7 +1770,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ========================================= END OF @babel/traverse@7.20.1 AND INFORMATION -%% @babel/types@7.20.2 NOTICES AND INFORMATION BEGIN HERE +%% @babel/types@7.20.7 NOTICES AND INFORMATION BEGIN HERE ========================================= MIT License @@ -1767,7 +1795,7 @@ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ========================================= -END OF @babel/types@7.20.2 AND INFORMATION +END OF @babel/types@7.20.7 AND INFORMATION %% @jest/types@27.5.1 NOTICES AND INFORMATION BEGIN HERE ========================================= @@ -3813,6 +3841,6 @@ END OF update-browserslist-db@1.0.10 AND INFORMATION SUMMARY BEGIN HERE ========================================= -Total Packages: 130 +Total Packages: 131 ========================================= END OF SUMMARY \ No newline at end of file diff --git a/packages/playwright-test/bundles/babel/package-lock.json b/packages/playwright-test/bundles/babel/package-lock.json index 7098712f23..cbaac67438 100644 --- a/packages/playwright-test/bundles/babel/package-lock.json +++ b/packages/playwright-test/bundles/babel/package-lock.json @@ -23,10 +23,10 @@ "@babel/plugin-proposal-private-property-in-object": "^7.18.6", "@babel/plugin-syntax-async-generators": "^7.8.4", "@babel/plugin-syntax-json-strings": "^7.8.3", - "@babel/plugin-syntax-jsx": "^7.18.6", "@babel/plugin-syntax-object-rest-spread": "^7.8.3", "@babel/plugin-syntax-optional-catch-binding": "^7.8.3", "@babel/plugin-transform-modules-commonjs": "^7.19.6", + "@babel/plugin-transform-react-jsx": "^7.20.7", "@babel/preset-typescript": "^7.18.6" }, "devDependencies": { @@ -675,6 +675,24 @@ "@babel/core": "^7.0.0-0" } }, + "node_modules/@babel/plugin-transform-react-jsx": { + "version": "7.20.7", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-react-jsx/-/plugin-transform-react-jsx-7.20.7.tgz", + "integrity": "sha512-Tfq7qqD+tRj3EoDhY00nn2uP2hsRxgYGi5mLQ5TimKav0a9Lrpd4deE+fcLXU8zFYRjlKPHZhpCvfEA6qnBxqQ==", + "dependencies": { + "@babel/helper-annotate-as-pure": "^7.18.6", + "@babel/helper-module-imports": "^7.18.6", + "@babel/helper-plugin-utils": "^7.20.2", + "@babel/plugin-syntax-jsx": "^7.18.6", + "@babel/types": "^7.20.7" + }, + "engines": { + "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" + } + }, "node_modules/@babel/plugin-transform-typescript": { "version": "7.20.2", "resolved": "https://registry.npmjs.org/@babel/plugin-transform-typescript/-/plugin-transform-typescript-7.20.2.tgz", @@ -741,9 +759,9 @@ } }, "node_modules/@babel/types": { - "version": "7.20.2", - "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.20.2.tgz", - "integrity": "sha512-FnnvsNWgZCr232sqtXggapvlkk/tuwR/qhGzcmxI0GXLCjmPYQPzio2FbdlWuY6y1sHFfQKk+rRbUZ9VStQMog==", + "version": "7.20.7", + "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.20.7.tgz", + "integrity": "sha512-69OnhBxSSgK0OzTJai4kyPDiKTIe3j+ctaHdIGVbRahTLAT7L3R9oeXHC2aVSuGYt3cVnoAMDmOCgJ2yaiLMvg==", "dependencies": { "@babel/helper-string-parser": "^7.19.4", "@babel/helper-validator-identifier": "^7.19.1", @@ -1539,6 +1557,18 @@ "@babel/helper-simple-access": "^7.19.4" } }, + "@babel/plugin-transform-react-jsx": { + "version": "7.20.7", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-react-jsx/-/plugin-transform-react-jsx-7.20.7.tgz", + "integrity": "sha512-Tfq7qqD+tRj3EoDhY00nn2uP2hsRxgYGi5mLQ5TimKav0a9Lrpd4deE+fcLXU8zFYRjlKPHZhpCvfEA6qnBxqQ==", + "requires": { + "@babel/helper-annotate-as-pure": "^7.18.6", + "@babel/helper-module-imports": "^7.18.6", + "@babel/helper-plugin-utils": "^7.20.2", + "@babel/plugin-syntax-jsx": "^7.18.6", + "@babel/types": "^7.20.7" + } + }, "@babel/plugin-transform-typescript": { "version": "7.20.2", "resolved": "https://registry.npmjs.org/@babel/plugin-transform-typescript/-/plugin-transform-typescript-7.20.2.tgz", @@ -1587,9 +1617,9 @@ } }, "@babel/types": { - "version": "7.20.2", - "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.20.2.tgz", - "integrity": "sha512-FnnvsNWgZCr232sqtXggapvlkk/tuwR/qhGzcmxI0GXLCjmPYQPzio2FbdlWuY6y1sHFfQKk+rRbUZ9VStQMog==", + "version": "7.20.7", + "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.20.7.tgz", + "integrity": "sha512-69OnhBxSSgK0OzTJai4kyPDiKTIe3j+ctaHdIGVbRahTLAT7L3R9oeXHC2aVSuGYt3cVnoAMDmOCgJ2yaiLMvg==", "requires": { "@babel/helper-string-parser": "^7.19.4", "@babel/helper-validator-identifier": "^7.19.1", diff --git a/packages/playwright-test/bundles/babel/package.json b/packages/playwright-test/bundles/babel/package.json index 007dbe5e7b..c0f97078d2 100644 --- a/packages/playwright-test/bundles/babel/package.json +++ b/packages/playwright-test/bundles/babel/package.json @@ -24,10 +24,10 @@ "@babel/plugin-proposal-private-property-in-object": "^7.18.6", "@babel/plugin-syntax-async-generators": "^7.8.4", "@babel/plugin-syntax-json-strings": "^7.8.3", - "@babel/plugin-syntax-jsx": "^7.18.6", "@babel/plugin-syntax-object-rest-spread": "^7.8.3", "@babel/plugin-syntax-optional-catch-binding": "^7.8.3", "@babel/plugin-transform-modules-commonjs": "^7.19.6", + "@babel/plugin-transform-react-jsx": "^7.20.7", "@babel/preset-typescript": "^7.18.6" }, "devDependencies": { diff --git a/packages/playwright-test/bundles/babel/src/babelBundleImpl.ts b/packages/playwright-test/bundles/babel/src/babelBundleImpl.ts index 6980b4de85..23213d7c4e 100644 --- a/packages/playwright-test/bundles/babel/src/babelBundleImpl.ts +++ b/packages/playwright-test/bundles/babel/src/babelBundleImpl.ts @@ -61,7 +61,7 @@ export function babelTransform(filename: string, isTypeScript: boolean, isModule } // Support JSX/TSX at all times, regardless of the file extension. - plugins.push([require('@babel/plugin-syntax-jsx')]); + plugins.push([require('@babel/plugin-transform-react-jsx')]); if (!isModule) { plugins.push([require('@babel/plugin-transform-modules-commonjs')]); diff --git a/tests/playwright-test/loader.spec.ts b/tests/playwright-test/loader.spec.ts index 8d25ce6624..235ff3c1b0 100644 --- a/tests/playwright-test/loader.spec.ts +++ b/tests/playwright-test/loader.spec.ts @@ -472,6 +472,40 @@ test('should load a jsx/tsx files', async ({ runInlineTest }) => { expect(exitCode).toBe(0); }); +test('should load a jsx/tsx files with fragments', async ({ runInlineTest }) => { + const { exitCode, passed } = await runInlineTest({ + 'helper.tsx': ` + export const component = () => <>
; + export function add(a: number, b: number) { + return a + b; + } + `, + 'helper2.jsx': ` + const component = () => <>
; + function add(a, b) { + return a + b; + } + module.exports = { add, component } + `, + 'a.spec.ts': ` + import { add } from './helper'; + const { test } = pwt; + test('succeeds', () => { + expect(add(1, 1)).toBe(2); + }); + `, + 'b.spec.js': ` + const { add } = require('./helper2'); + const { test } = pwt; + test('succeeds', () => { + expect(add(1, 1)).toBe(2); + }); + ` + }); + expect(passed).toBe(2); + expect(exitCode).toBe(0); +}); + test('should remove type imports from ts', async ({ runInlineTest }) => { const result = await runInlineTest({ 'a.test.ts': `