Skip to content

Commit

Permalink
fix(58399): [isolatedDeclarations][5.5] Autofix does not work when JS…
Browse files Browse the repository at this point in the history
…X prop contains a dash (#58478)
  • Loading branch information
a-tarasyuk committed May 8, 2024
1 parent fece7f1 commit dcec37e
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/services/utilities.ts
Expand Up @@ -332,6 +332,7 @@ import {
SemicolonPreference,
setConfigFileInOptions,
setOriginalNode,
setParentRecursive,
setTextRange,
Signature,
SignatureDeclaration,
Expand Down Expand Up @@ -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 */
Expand Down
Expand Up @@ -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() {
Expand All @@ -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;
}
Expand Down
45 changes: 45 additions & 0 deletions tests/cases/fourslash/codeFixMissingTypeAnnotationOnExports47.ts
@@ -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" />;',
});
45 changes: 45 additions & 0 deletions tests/cases/fourslash/codeFixMissingTypeAnnotationOnExports48.ts
@@ -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;',
});

0 comments on commit dcec37e

Please sign in to comment.