Skip to content
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

[isolatedDeclarations][5.5] Autofix does not work when JSX prop contains a dash - #58399

Closed
MichaelMitchell-at opened this issue May 2, 2024 · 2 comments Β· Fixed by #58478
Closed
Labels
Bug A bug in TypeScript Help Wanted You can do this
Milestone

Comments

@MichaelMitchell-at
Copy link

πŸ”Ž Search Terms

isolated declarations, jsx, autofix

πŸ•— Version & Regression Information

⏯ Playground Link

No response

πŸ’» Code

export const x = <div aria-label="hello" />

πŸ™ Actual behavior

No autofix suggestion

πŸ™‚ Expected behavior

Autofix to add explicit type annotation

Additional information about the issue

This is with "jsx": "react-jsx" in tsconfig

@RyanCavanaugh RyanCavanaugh added Bug A bug in TypeScript Help Wanted You can do this labels May 2, 2024
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone May 2, 2024
@blickly
Copy link

blickly commented May 8, 2024

I've started taking a look at this, and after figuring out how to repro in fourslash, it looks like there is a crash coming from pretty deep within a call to ChangeTracker.getChanges

  1) fourslash tests
       tests/cases/fourslash/codeFixMissingTypeAnnotationOnExports47-tsx-with-dash.tsx
         fourslash test codeFixMissingTypeAnnotationOnExports47-tsx-with-dash.tsx runs correctly:
     Error: Debug Failure. False expression: Token end is child end
      at processChildNode (src/services/formatting/formatting.ts:880:27)
      at /Users/blickly/repos/TypeScript/src/services/formatting/formatting.ts:791:17
      at visitNode (src/compiler/parser.ts:441:20)
      at forEachChildInJsxAttribute (src/compiler/parser.ts:1022:16)
      at forEachChild (src/compiler/parser.ts:1251:43)
      at processNode (src/services/formatting/formatting.ts:788:9)
      at processChildNode (src/services/formatting/formatting.ts:889:13)
      at processChildNodes (src/services/formatting/formatting.ts:955:40)
      at /Users/blickly/repos/TypeScript/src/services/formatting/formatting.ts:794:17
      at visitNodes (src/compiler/parser.ts:447:20)
      at forEachChildInJsxAttributes (src/compiler/parser.ts:1019:16)
      at forEachChild (src/compiler/parser.ts:1251:43)
      at processNode (src/services/formatting/formatting.ts:788:9)
      at processChildNode (src/services/formatting/formatting.ts:889:13)
      at /Users/blickly/repos/TypeScript/src/services/formatting/formatting.ts:791:17
      at visitNode (src/compiler/parser.ts:441:20)
      at forEachChildInJsxOpeningOrSelfClosingElement (src/compiler/parser.ts:1191:9)
      at forEachChild (src/compiler/parser.ts:1251:43)
      at processNode (src/services/formatting/formatting.ts:788:9)
      at processChildNode (src/services/formatting/formatting.ts:889:13)
      at /Users/blickly/repos/TypeScript/src/services/formatting/formatting.ts:791:17
      at visitNode (src/compiler/parser.ts:441:20)
      at forEachChildInParenthesizedExpression (src/compiler/parser.ts:756:16)
      at forEachChild (src/compiler/parser.ts:1251:43)
      at processNode (src/services/formatting/formatting.ts:788:9)
      at processChildNode (src/services/formatting/formatting.ts:889:13)
      at /Users/blickly/repos/TypeScript/src/services/formatting/formatting.ts:791:17
      at visitNode (src/compiler/parser.ts:441:20)
      at forEachChildInSatisfiesExpression (src/compiler/parser.ts:793:16)
      at forEachChild (src/compiler/parser.ts:1251:43)
      at processNode (src/services/formatting/formatting.ts:788:9)
      at processChildNode (src/services/formatting/formatting.ts:889:13)
      at /Users/blickly/repos/TypeScript/src/services/formatting/formatting.ts:791:17
      at visitNode (src/compiler/parser.ts:441:20)
      at forEachChildInAsExpression (src/compiler/parser.ts:786:16)
      at forEachChild (src/compiler/parser.ts:1251:43)
      at processNode (src/services/formatting/formatting.ts:788:9)
      at formatSpanWorker (src/services/formatting/formatting.ts:521:9)
      at /Users/blickly/repos/TypeScript/src/services/formatting/formatting.ts:440:9
      at getFormattingScanner (src/services/formatting/formattingScanner.ts:69:17)
      at Object.formatNodeGivenIndentation (src/services/formatting/formatting.ts:439:12)
      at getFormattedTextOfNode (src/services/textChanges.ts:1342:36)
      at format (src/services/textChanges.ts:1313:37)
      at computeNewText (src/services/textChanges.ts:1316:15)
      at /Users/blickly/repos/TypeScript/src/services/textChanges.ts:1278:33
      at mapDefined (src/compiler/core.ts:518:28)
      at /Users/blickly/repos/TypeScript/src/services/textChanges.ts:1273:33
      at mapDefined (src/compiler/core.ts:518:28)
      at Object.getTextChangesFromChanges (src/services/textChanges.ts:1263:16)
      at _ChangeTracker.getChanges (src/services/textChanges.ts:1179:39)
      at withContext (src/services/codefixes/fixMissingTypeAnnotationOnExports.ts:254:36)

After debugging a bit, I suspect the issue is that the formatter seems to rely on Nodes having a valid parent pointer (such as here), which seem to be set to undefined in the replacement node passed to the ChangeTracker.

Is it safe to assume that the ChangeTracker / formatter in TS are designed to require valid parent pointers?

@jakebailey
Copy link
Member

Judging by the location, this looks more like that the formatter didn't consider - to be a part of a name; it checks if it's a token (which I'm assuming is -), then only complains if that's in JsxText, but surely it can be an attribute too.

blickly added a commit to blickly/TypeScript that referenced this issue May 8, 2024
blickly added a commit to blickly/TypeScript that referenced this issue May 8, 2024
blickly added a commit to blickly/TypeScript that referenced this issue May 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Help Wanted You can do this
Projects
None yet
4 participants