fix(58399): [isolatedDeclarations][5.5] Autofix does not work when JSX prop contains a dash (#58478)

This commit is contained in:
Oleksandr T
2024-05-09 01:12:43 +03:00
committed by GitHub
parent fece7f11c0
commit dcec37e532
4 changed files with 94 additions and 3 deletions

View File

@@ -332,6 +332,7 @@ import {
SemicolonPreference,
setConfigFileInOptions,
setOriginalNode,
setParentRecursive,
setTextRange,
Signature,
SignatureDeclaration,
@@ -3172,7 +3173,7 @@ export function getPrecedingNonSpaceCharacterPosition(text: string, position: nu
export function getSynthesizedDeepClone<T extends Node | undefined>(node: T, includeTrivia = true): T {
const clone = node && getSynthesizedDeepCloneWorker(node);
if (clone && !includeTrivia) suppressLeadingAndTrailingTrivia(clone);
return clone;
return setParentRecursive(clone, /*incremental*/ false);
}
/** @internal */

View File

@@ -10,7 +10,7 @@ function f() {
function f() {
let a = 1;
let x: 8 | 10 | 2 = /*RENAME*/newFunction();
let x: 0o10 | 10 | 0b10 = /*RENAME*/newFunction();
a; x;
function newFunction() {
@@ -23,7 +23,7 @@ function f() {
function f() {
let a = 1;
let x: (8 | 10 | 2) | undefined;
let x: (0o10 | 10 | 0b10) | undefined;
({ x, a } = /*RENAME*/newFunction(a));
a; x;
}

View File

@@ -0,0 +1,45 @@
/// <reference path='fourslash.ts'/>
// @isolatedDeclarations: true
// @declaration: true
// @moduleResolution: node
// @target: es2018
// @jsx: react-jsx
// @filename: node_modules/react/package.json
////{
//// "name": "react",
//// "types": "index.d.ts",
////}
// @filename: node_modules/react/index.d.ts
////export = React;
////declare namespace JSX {
//// interface Element extends GlobalJSXElement { }
//// interface IntrinsicElements extends GlobalJSXIntrinsicElements { }
////}
////declare namespace React { }
////declare global {
//// namespace JSX {
//// interface Element { }
//// interface IntrinsicElements { [x: string]: any; }
//// }
////}
////interface GlobalJSXElement extends JSX.Element {}
////interface GlobalJSXIntrinsicElements extends JSX.IntrinsicElements {}
// @filename: node_modules/react/jsx-runtime.d.ts
////import './';
// @filename: node_modules/react/jsx-dev-runtime.d.ts
////import './';
// @filename: /a.tsx
////export const x = <div aria-label="label text" />;
goTo.file("/a.tsx");
verify.codeFix({
description: `Add annotation of type 'JSX.Element'`,
index: 0,
newFileContent: 'export const x: JSX.Element = <div aria-label="label text" />;',
});

View File

@@ -0,0 +1,45 @@
/// <reference path='fourslash.ts'/>
// @isolatedDeclarations: true
// @declaration: true
// @moduleResolution: node
// @target: es2018
// @jsx: react-jsx
// @filename: node_modules/react/package.json
////{
//// "name": "react",
//// "types": "index.d.ts",
////}
// @filename: node_modules/react/index.d.ts
////export = React;
////declare namespace JSX {
//// interface Element extends GlobalJSXElement { }
//// interface IntrinsicElements extends GlobalJSXIntrinsicElements { }
////}
////declare namespace React { }
////declare global {
//// namespace JSX {
//// interface Element { }
//// interface IntrinsicElements { [x: string]: any; }
//// }
////}
////interface GlobalJSXElement extends JSX.Element {}
////interface GlobalJSXIntrinsicElements extends JSX.IntrinsicElements {}
// @filename: node_modules/react/jsx-runtime.d.ts
////import './';
// @filename: node_modules/react/jsx-dev-runtime.d.ts
////import './';
// @filename: /a.tsx
////export const x = <div aria-label="label text" />;
goTo.file("/a.tsx");
verify.codeFix({
description: `Add satisfies and an inline type assertion with 'JSX.Element'`,
index: 1,
newFileContent: 'export const x = (<div aria-label="label text" />) satisfies JSX.Element as JSX.Element;',
});