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

getExpressionOrThrow no longer exists on JsxElement in v16 #1325

Closed
oshi97 opened this issue Sep 9, 2022 · 2 comments
Closed

getExpressionOrThrow no longer exists on JsxElement in v16 #1325

oshi97 opened this issue Sep 9, 2022 · 2 comments
Labels

Comments

@oshi97
Copy link

oshi97 commented Sep 9, 2022

Describe the bug

Version: 16.0.0

To Reproduce

getExpressionOrThrow no longer exists on JsxElement in v16. This doesn't appear to be present in the release notes for the 16.0.0 breaking changes

import { SyntaxKind, JsxAttribute } from 'ts-morph'

function doJsxThing(n: JsxAttribute) {
  const initializer = n.getInitializerOrThrow()
  if (initializer.isKind(SyntaxKind.StringLiteral)) {
    return
  }
  // no longer compiles
  const expression = initializer.getExpressionOrThrow()
}

Expected behavior

I think the code should compile if this isn't an expected change. Otherwise would appreciate an alternative!

@dsherret
Copy link
Owner

dsherret commented Sep 9, 2022

There are too many changes in TS 4.8 for me to document in the release notes as I don't have time, so I just say "upgraded to TS 4.8" as a breaking change.

Previously JsxAttribute#getInitializerOrThrow() returned StringLiteral | JsxExpression. In TS 4.8, they updated that to be StringLiteral | JsxExpression | JsxElement | JsxSelfClosingElement | JsxFragment:

https://github.com/dsherret/ts-morph/pull/1316/files#diff-1689901fc8d46451616bd34e0e34bf5c359401decc33ecd5fa7065f30525af6aR1403

So, the issue occurs because the jsx attribute initializer could be more things than possibly a StringLiteral | JsxExpression now. You will have to add extra checks for those other syntax kinds.

@oshi97
Copy link
Author

oshi97 commented Sep 9, 2022

Thank you!

@oshi97 oshi97 closed this as completed Sep 9, 2022
oshi97 added a commit to yext/studio that referenced this issue Sep 9, 2022
…ts (#37)

There was a breaking change in ts-morph 16 that broke the ts build,
so kept it at 15 dsherret/ts-morph#1325
uuid v9 speedup seems cool uuidjs/uuid#597

TEST=manual

started up the app, ran jest tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants