Skip to content

Commit 2b084c7

Browse files
committed
fix: Fix properties sorting in JSX attribute completions
fixes #206
1 parent 53d4bb2 commit 2b084c7

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

typescript/src/completions/fixPropertiesSorting.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export default (entries: ts.CompletionEntry[]) => {
3131
const typeChecker = program.getTypeChecker()
3232
let sourceProps: string[]
3333
if (isJsxElem) {
34-
const type = typeChecker.getContextualType((node as ts.JsxOpeningElement).attributes)
34+
const type = typeChecker.getContextualType((targetNode as ts.JsxOpeningElement).attributes)
3535
if (!type) return
3636
// usually component own props defined first like interface Props extends ... {} or type A = Props & ..., but this is not a case with mui...
3737
sourceProps = (type.isIntersection() ? type.types.flatMap(type => type.getProperties()) : type.getProperties()).map(symbol => symbol.name)

typescript/test/completions.spec.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -527,26 +527,38 @@ test('Fix properties sorting', () => {
527527
a.b({/*2*/})./*3*/
528528
}
529529
530+
let a: { b:{}, a() } = {
531+
/*5*/
532+
}
533+
530534
declare function MyComponent(props: { b?; c? } & { a? }): JSX.Element
531535
<MyComponent /*4*/ />;
532536
<MyComponent
533537
c=''
534538
/*41*/
535539
/>;
536-
537-
let a: { b:{}, a() } = {
538-
/*5*/
539-
}
540+
<MyComponent
541+
test2=''
542+
/*41*/
543+
test=''
544+
/>;
545+
<MyComponent /*42*/
546+
test2=''
547+
/>;
540548
`)
541549
const assertSorted = (marker: number, expected: string[]) => {
542550
const { entriesSorted } = getCompletionsAtPosition(currentTestingContext.markers[marker]!)!
543-
expect(entriesSorted.map(x => x.name)).toEqual(expected)
551+
expect(
552+
entriesSorted.map(x => x.name),
553+
`${marker}`,
554+
).toEqual(expected)
544555
}
545556
assertSorted(1, ['c', 'b'])
546557
assertSorted(2, ['c', 'b'])
547558
assertSorted(3, ['c', 'b'])
548559
assertSorted(4, ['b', 'c', 'a'])
549-
assertSorted(41, ['b', 'a'])
560+
assertSorted(41, ['b', 'c', 'a'])
561+
assertSorted(42, ['b', 'c', 'a'])
550562
assertSorted(5, ['b', 'b', 'a', 'a'])
551563
settingsOverride.fixSuggestionsSorting = false
552564
})

0 commit comments

Comments
 (0)