-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
fix: fix illegal decorator check #6723
Changes from 2 commits
282e115
35304da
07b03ee
1a4b800
a2e2a42
63f0c3f
01c197f
af3a56f
6360076
acaee6b
ee03f74
28a43e7
9a83be1
229c4ce
aea5e0d
04e3b73
a84fa78
1bbf432
00e9b42
e7743d4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -766,3 +766,41 @@ export function getContainingFunction( | |
): ts.SignatureDeclaration | undefined { | ||
return ts.findAncestor(node.parent, ts.isFunctionLike); | ||
} | ||
|
||
// `ts.nodeCanBeDecorated` | ||
export function nodeCanBeDecorated(node: ts.Node): boolean { | ||
return [true, false].some( | ||
useLegacyDecorators => | ||
// @ts-expect-error -- internal api | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-call | ||
ts.nodeCanBeDecorated?.( | ||
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. we can't use this function, or at least not without version checks. Given it's an internal API - I think we might want to consider rewriting it for ourselves? The logic will be pretty static given the spec doesn't change much if at all. 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.
Didn't know that.
I can try. 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. Added acaee6b, but I don't know the equivalent of 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.
We can queue a separate PR for that then update this PR to use 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.
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. it's still a private, internal API! 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. Let's use a fake one for now? a84fa78 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. If we're going with a fake |
||
useLegacyDecorators, | ||
node, | ||
node.parent, | ||
node.parent.parent, | ||
) ?? true, | ||
); | ||
} | ||
|
||
// `ts.hasDecorators` | ||
export function hasDecorators(node: ts.Node | undefined): boolean { | ||
// @ts-expect-error -- internal api | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-return | ||
return Boolean(node) && (ts.hasDecorators?.(node) ?? false); | ||
} | ||
|
||
// `ts.getAllAccessorDeclarations` | ||
export function getAllAccessorDeclarations( | ||
accessor: ts.GetAccessorDeclaration | ts.SetAccessorDeclaration, | ||
): { | ||
firstAccessor?: ts.Node; | ||
secondAccessor?: ts.Node; | ||
} { | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-return | ||
return ( | ||
// @ts-expect-error -- internal api | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-call | ||
ts.getAllAccessorDeclarations?.(accessor.parent.members ?? [], accessor) ?? | ||
{} | ||
); | ||
fisker marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of using
.modifiers
can we usegetModifiers
here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getModifiers
only returnsts.Modifier
, but we needts.Decorator
s, unless we callgetDecorators
again.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In that same file there is the
getDecorators
util which should do what you want I think?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know.
But I checked both modifiers and decorators here, and
getModifiers() + getDecorators()
isnode.modifiers
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not quite sure I understand - your code below does "for each modifier, only action the decorators"
So couldn't the code be
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally, it should work, but I still can't get why you want 4 loops when you can do it in 1 loop.
Anyway, I tried, but turns out
getModifiers() + getDecorators()
not equals tonode.modifiers
.ts.canHaveModifiers()
andts.canHaveDecorators()
are stopping me to access modifiers on some node. You can try it to see the failed tests.Should we
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem here is that they purposely removed
node.modifiers
from the types in TSv5 - so we definitely don't want to be accessing it directly if we can avoid it as it's clear that their intention is for it to be a truly private property.I guess we could add an option to skip the checks?