-
Notifications
You must be signed in to change notification settings - Fork 785
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(test): fix infinite loops w/ react and @testing-library/dom #4188
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import ts from 'typescript'; | ||
|
||
import type * as d from '../../../declarations'; | ||
import { createAnonymousClassMetadataProxy } from '../add-component-meta-proxy'; | ||
import { createClassMetadataProxy } from '../add-component-meta-proxy'; | ||
import { addImports } from '../add-imports'; | ||
import { RUNTIME_APIS } from '../core-runtime-apis'; | ||
import { getModuleFromSourceFile } from '../transform-utils'; | ||
|
@@ -47,8 +47,22 @@ export const proxyCustomElement = ( | |
continue; | ||
} | ||
|
||
// to narrow the type of `declaration.initializer` to `ts.ClassExpression` | ||
if (!ts.isClassExpression(declaration.initializer)) { | ||
continue; | ||
} | ||
Comment on lines
+50
to
+53
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. This feels a little sketchy to me. Is there a different way to do this type-cast/assertion? 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 could instead do 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. Not necessarily concerned, this just stood out to me as a pattern I haven't really seen. I've always strayed away from using 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. I'm OK with this as-is. Using an if statement with a 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. yeah I'm also in favor of less nesting where we can, and I also generally favor the 'should we be here? no? ok lets get out right now' sort of early-return pattern (well, early |
||
|
||
const renamedClassExpression = ts.factory.updateClassExpression( | ||
declaration.initializer, | ||
ts.getModifiers(declaration.initializer), | ||
ts.factory.createIdentifier(principalComponent.componentClassName), | ||
declaration.initializer.typeParameters, | ||
declaration.initializer.heritageClauses, | ||
declaration.initializer.members | ||
); | ||
|
||
// wrap the Stencil component's class declaration in a component proxy | ||
const proxyCreationCall = createAnonymousClassMetadataProxy(principalComponent, declaration.initializer); | ||
const proxyCreationCall = createClassMetadataProxy(principalComponent, renamedClassExpression); | ||
ts.addSyntheticLeadingComment(proxyCreationCall, ts.SyntaxKind.MultiLineCommentTrivia, '@__PURE__', false); | ||
|
||
// update the component's variable declaration to use the new initializer | ||
|
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.
"clazz" 😂
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.
FWIW ☕ - https://stackoverflow.com/questions/2529974/why-do-java-programmers-like-to-name-a-variable-clazz
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 python I'm using to seeing
klass
for the same reason haha