-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Auto-include types for the jsx import source in the new jsx transforms #41330
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
weswigham
merged 5 commits into
microsoft:master
from
weswigham:jsx-import-source-as-auto-import
Oct 30, 2020
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
6714998
Auto-include types for the jsx import source in the new jsx transforms
weswigham fe3b343
Add affectsModuleResolution: true ot jsx and jsxImportSource options
weswigham 8493ee8
Add mroe incremental-affecting affixes to compiler options, add incre…
weswigham fe94a21
Use same metho as importHelpers to add synthetic import
weswigham 1e1ae30
Update src/compiler/program.ts
weswigham File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -276,5 +276,33 @@ export interface A { | |
], | ||
modifyFs: host => host.deleteFile(`${project}/globals.d.ts`) | ||
}); | ||
|
||
const jsxImportSourceOptions = { module: "commonjs", jsx: "react-jsx", incremental: true, jsxImportSource: "react" }; | ||
const jsxLibraryContent = `export namespace JSX { | ||
interface Element {} | ||
interface IntrinsicElements { | ||
div: { | ||
propA?: boolean; | ||
}; | ||
} | ||
} | ||
export function jsx(...args: any[]): void; | ||
export function jsxs(...args: any[]): void; | ||
export const Fragment: unique symbol; | ||
`; | ||
|
||
verifyIncrementalWatchEmit({ | ||
subScenario: "jsxImportSource option changed", | ||
files: () => [ | ||
{ path: libFile.path, content: libContent }, | ||
{ path: `${project}/node_modules/react/jsx-runtime/index.d.ts`, content: jsxLibraryContent }, | ||
{ path: `${project}/node_modules/react/package.json`, content: JSON.stringify({ name: "react", version: "0.0.1" }) }, | ||
{ path: `${project}/node_modules/preact/jsx-runtime/index.d.ts`, content: jsxLibraryContent.replace("propA", "propB") }, | ||
{ path: `${project}/node_modules/preact/package.json`, content: JSON.stringify({ name: "preact", version: "0.0.1" }) }, | ||
{ path: `${project}/index.tsx`, content: `export const App = () => <div propA={true}></div>;` }, | ||
{ path: configFile.path, content: JSON.stringify({ compilerOptions: jsxImportSourceOptions }) } | ||
], | ||
modifyFs: host => host.writeFile(configFile.path, JSON.stringify({ compilerOptions: { ...jsxImportSourceOptions, jsxImportSource: "preact" } })) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add another case hen preact*.d.ts file is missing and added. |
||
}); | ||
}); | ||
} |
14 changes: 14 additions & 0 deletions
14
tests/baselines/reference/jsxJsxsCjsTransformCustomImport(jsx=react-jsx).errors.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
tests/cases/conformance/jsx/jsxs/jsxJsxsCjsTransformCustomImport.tsx(2,11): error TS2307: Cannot find module 'preact/jsx-runtime' or its corresponding type declarations. | ||
|
||
|
||
==== tests/cases/conformance/jsx/jsxs/jsxJsxsCjsTransformCustomImport.tsx (1 errors) ==== | ||
/// <reference path="/.lib/react16.d.ts" /> | ||
const a = <> | ||
~~ | ||
!!! error TS2307: Cannot find module 'preact/jsx-runtime' or its corresponding type declarations. | ||
<p></p> | ||
text | ||
<div className="foo"></div> | ||
</> | ||
|
||
export {}; |
14 changes: 14 additions & 0 deletions
14
tests/baselines/reference/jsxJsxsCjsTransformCustomImport(jsx=react-jsxdev).errors.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
tests/cases/conformance/jsx/jsxs/jsxJsxsCjsTransformCustomImport.tsx(2,11): error TS2307: Cannot find module 'preact/jsx-dev-runtime' or its corresponding type declarations. | ||
|
||
|
||
==== tests/cases/conformance/jsx/jsxs/jsxJsxsCjsTransformCustomImport.tsx (1 errors) ==== | ||
/// <reference path="/.lib/react16.d.ts" /> | ||
const a = <> | ||
~~ | ||
!!! error TS2307: Cannot find module 'preact/jsx-dev-runtime' or its corresponding type declarations. | ||
<p></p> | ||
text | ||
<div className="foo"></div> | ||
</> | ||
|
||
export {}; |
26 changes: 26 additions & 0 deletions
26
tests/baselines/reference/jsxJsxsCjsTransformCustomImportPragma(jsx=react-jsx).errors.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
tests/cases/conformance/jsx/jsxs/preact.tsx(3,11): error TS2307: Cannot find module 'preact/jsx-runtime' or its corresponding type declarations. | ||
|
||
|
||
==== tests/cases/conformance/jsx/jsxs/react.tsx (0 errors) ==== | ||
/// <reference path="/.lib/react16.d.ts" /> | ||
/* @jsxImportSource react */ | ||
import "./preact"; | ||
const a = <> | ||
<p></p> | ||
text | ||
<div className="foo"></div> | ||
</> | ||
|
||
export {}; | ||
==== tests/cases/conformance/jsx/jsxs/preact.tsx (1 errors) ==== | ||
/// <reference path="/.lib/react16.d.ts" /> | ||
/* @jsxImportSource preact */ | ||
const a = <> | ||
~~ | ||
!!! error TS2307: Cannot find module 'preact/jsx-runtime' or its corresponding type declarations. | ||
<p></p> | ||
text | ||
<div className="foo"></div> | ||
</> | ||
|
||
export {}; |
26 changes: 26 additions & 0 deletions
26
tests/baselines/reference/jsxJsxsCjsTransformCustomImportPragma(jsx=react-jsxdev).errors.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
tests/cases/conformance/jsx/jsxs/preact.tsx(3,11): error TS2307: Cannot find module 'preact/jsx-dev-runtime' or its corresponding type declarations. | ||
|
||
|
||
==== tests/cases/conformance/jsx/jsxs/react.tsx (0 errors) ==== | ||
/// <reference path="/.lib/react16.d.ts" /> | ||
/* @jsxImportSource react */ | ||
import "./preact"; | ||
const a = <> | ||
<p></p> | ||
text | ||
<div className="foo"></div> | ||
</> | ||
|
||
export {}; | ||
==== tests/cases/conformance/jsx/jsxs/preact.tsx (1 errors) ==== | ||
/// <reference path="/.lib/react16.d.ts" /> | ||
/* @jsxImportSource preact */ | ||
const a = <> | ||
~~ | ||
!!! error TS2307: Cannot find module 'preact/jsx-dev-runtime' or its corresponding type declarations. | ||
<p></p> | ||
text | ||
<div className="foo"></div> | ||
</> | ||
|
||
export {}; |
13 changes: 13 additions & 0 deletions
13
tests/baselines/reference/jsxJsxsCjsTransformKeyPropCustomImport(jsx=react-jsx).errors.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
tests/cases/conformance/jsx/jsxs/jsxJsxsCjsTransformKeyPropCustomImport.tsx(3,11): error TS2307: Cannot find module 'preact/jsx-runtime' or its corresponding type declarations. | ||
|
||
|
||
==== tests/cases/conformance/jsx/jsxs/jsxJsxsCjsTransformKeyPropCustomImport.tsx (1 errors) ==== | ||
/// <reference path="/.lib/react16.d.ts" /> | ||
const props = { answer: 42 } | ||
const a = <div key="foo" {...props}>text</div>; | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
!!! error TS2307: Cannot find module 'preact/jsx-runtime' or its corresponding type declarations. | ||
const b = <div {...props} key="bar">text</div>; | ||
|
||
export {}; | ||
|
13 changes: 13 additions & 0 deletions
13
...s/baselines/reference/jsxJsxsCjsTransformKeyPropCustomImport(jsx=react-jsxdev).errors.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
tests/cases/conformance/jsx/jsxs/jsxJsxsCjsTransformKeyPropCustomImport.tsx(3,11): error TS2307: Cannot find module 'preact/jsx-dev-runtime' or its corresponding type declarations. | ||
|
||
|
||
==== tests/cases/conformance/jsx/jsxs/jsxJsxsCjsTransformKeyPropCustomImport.tsx (1 errors) ==== | ||
/// <reference path="/.lib/react16.d.ts" /> | ||
const props = { answer: 42 } | ||
const a = <div key="foo" {...props}>text</div>; | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
!!! error TS2307: Cannot find module 'preact/jsx-dev-runtime' or its corresponding type declarations. | ||
const b = <div {...props} key="bar">text</div>; | ||
|
||
export {}; | ||
|
24 changes: 24 additions & 0 deletions
24
...aselines/reference/jsxJsxsCjsTransformKeyPropCustomImportPragma(jsx=react-jsx).errors.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
tests/cases/conformance/jsx/jsxs/preact.tsx(4,11): error TS2307: Cannot find module 'preact/jsx-runtime' or its corresponding type declarations. | ||
|
||
|
||
==== tests/cases/conformance/jsx/jsxs/react.tsx (0 errors) ==== | ||
/// <reference path="/.lib/react16.d.ts" /> | ||
/* @jsxImportSource react */ | ||
import "./preact"; | ||
const props2 = { answer: 42 } | ||
const a2 = <div key="foo" {...props2}>text</div>; | ||
const b2 = <div {...props2} key="bar">text</div>; | ||
|
||
export {}; | ||
|
||
==== tests/cases/conformance/jsx/jsxs/preact.tsx (1 errors) ==== | ||
/// <reference path="/.lib/react16.d.ts" /> | ||
/* @jsxImportSource preact */ | ||
const props = { answer: 42 } | ||
const a = <div key="foo" {...props}>text</div>; | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
!!! error TS2307: Cannot find module 'preact/jsx-runtime' or its corresponding type declarations. | ||
const b = <div {...props} key="bar">text</div>; | ||
|
||
export {}; | ||
|
24 changes: 24 additions & 0 deletions
24
...lines/reference/jsxJsxsCjsTransformKeyPropCustomImportPragma(jsx=react-jsxdev).errors.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
tests/cases/conformance/jsx/jsxs/preact.tsx(4,11): error TS2307: Cannot find module 'preact/jsx-dev-runtime' or its corresponding type declarations. | ||
|
||
|
||
==== tests/cases/conformance/jsx/jsxs/react.tsx (0 errors) ==== | ||
/// <reference path="/.lib/react16.d.ts" /> | ||
/* @jsxImportSource react */ | ||
import "./preact"; | ||
const props2 = { answer: 42 } | ||
const a2 = <div key="foo" {...props2}>text</div>; | ||
const b2 = <div {...props2} key="bar">text</div>; | ||
|
||
export {}; | ||
|
||
==== tests/cases/conformance/jsx/jsxs/preact.tsx (1 errors) ==== | ||
/// <reference path="/.lib/react16.d.ts" /> | ||
/* @jsxImportSource preact */ | ||
const props = { answer: 42 } | ||
const a = <div key="foo" {...props}>text</div>; | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
!!! error TS2307: Cannot find module 'preact/jsx-dev-runtime' or its corresponding type declarations. | ||
const b = <div {...props} key="bar">text</div>; | ||
|
||
export {}; | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.