Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions tsc/internal/checker/exports.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,18 @@ func (c *Checker) GetPropertiesOfType(t *Type) []*ast.Symbol {
return c.getPropertiesOfType(t)
}

func (c *Checker) GetJsxAttributesType(node *ast.Node) *Type {
return c.checkExpressionCached(node)
}

func (c *Checker) GetUnmatchedProperties(source *Type, target *Type, requireOptionalProperties bool, matchDiscriminantProperties bool) []*ast.Symbol {
return c.getUnmatchedProperties(source, target, requireOptionalProperties, matchDiscriminantProperties)
}

func (c *Checker) IsDeeplyNestedType(t *Type, stack []*Type, maxDepth int) bool {
return c.isDeeplyNestedType(t, stack, maxDepth)
}

func (c *Checker) GetPropertyOfType(t *Type, name string) *ast.Symbol {
return c.getPropertyOfType(t, name)
}
Expand All @@ -172,6 +184,10 @@ func (c *Checker) IsPropertyAccessible(node *ast.Node, isSuper bool, isWrite boo
return c.isPropertyAccessible(node, isSuper, isWrite, containingType, property)
}

func (c *Checker) IsConstructorAccessible(node *ast.Node, signatures []*Signature) bool {
return c.getConstructorAccessibilityError(node, signatures, ast.ModifierFlagsNonPublicAccessibilityModifier) == nil
}

func (c *Checker) GetTypeOfPropertyOfContextualType(t *Type, name string) *Type {
return c.getTypeOfPropertyOfContextualType(t, name)
}
Expand All @@ -188,6 +204,10 @@ func (c *Checker) GetSignaturesOfType(t *Type, kind SignatureKind) []*Signature
return c.getSignaturesOfType(t, kind)
}

func (c *Checker) GetMinArgumentCount(signature *Signature) int {
return c.getMinArgumentCount(signature)
}

func (c *Checker) GetDeclaredTypeOfSymbol(symbol *ast.Symbol) *Type {
return c.getDeclaredTypeOfSymbol(symbol)
}
Expand Down
4 changes: 3 additions & 1 deletion tsc/internal/fourslash/fourslash.go
Original file line number Diff line number Diff line change
Expand Up @@ -1687,6 +1687,7 @@ type VerifyCodeFixOptions struct {
// VerifyCodeFixAllOptions are the options for VerifyCodeFixAll.
type VerifyCodeFixAllOptions struct {
FixID string
Description string
NewFileContent string
}

Expand Down Expand Up @@ -1931,7 +1932,8 @@ func (f *FourslashTest) VerifyCodeFixAll(t *testing.T, options VerifyCodeFixAllO
// We look for actions that are NOT single-diagnostic fixes (i.e., have no Diagnostics attached).
var fixAllCandidates []*lsproto.CodeAction
for _, action := range actions {
if action.Diagnostics == nil || len(*action.Diagnostics) == 0 {
if (action.Diagnostics == nil || len(*action.Diagnostics) == 0) &&
(options.Description == "" || action.Title == options.Description) {
fixAllCandidates = append(fixAllCandidates, action)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package fourslash_test
import (
"testing"

"github.com/microsoft/TypeScript/tsc/internal/diagnostics"
"github.com/microsoft/TypeScript/tsc/internal/fourslash"
"github.com/microsoft/TypeScript/tsc/internal/locale"
"github.com/microsoft/TypeScript/tsc/internal/testutil"
)

Expand All @@ -20,8 +22,9 @@ const A = (props: { [K in D]: K }) =>
<div {...props}></div>;

const Bar = () =>
[|<A></A>|]`
f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content)
<A></A>`
f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content+addMissingAttributesJsxDeclarations)
defer done()
f.VerifyCodeFixNotAvailable(t, "fixMissingAttributes")
f.VerifyNumberOfErrorsInCurrentFile(t, 1)
f.VerifyCodeFixNotAvailable(t, diagnostics.Add_missing_attributes.Localize(locale.Default))
}
147 changes: 147 additions & 0 deletions tsc/internal/fourslash/tests/codeFixAddMissingAttributes11_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
package fourslash_test

import (
"strconv"
"testing"

"github.com/microsoft/TypeScript/tsc/internal/diagnostics"
"github.com/microsoft/TypeScript/tsc/internal/fourslash"
"github.com/microsoft/TypeScript/tsc/internal/locale"
"github.com/microsoft/TypeScript/tsc/internal/testutil"
)

func TestCodeFixAddMissingAttributes11(t *testing.T) {
t.Parallel()
for i, test := range []struct {
content string
result string
fileResult string
filename string
}{
{
content: `// @jsx: preserve
// @Filename: a.tsx
interface T { a: number; b?: string }
const A = (a: T) => null;
const a = <A[||] />;`,
result: ` a={0}`,
},
{
content: `// @jsx: preserve
// @Filename: /a.ts
export enum E { a, b }
export class C {}
// @Filename: /b.tsx
import { E as B, C as D } from "./a";
const A = (a: { a: B; b: D }) => null;
const a = <A[||] />;`,
result: ` a={B.a} b={new D}`,
filename: "/b.tsx",
},
{
content: `// @jsx: preserve
// @Filename: a.tsx
declare namespace JSX {
interface Element {}
interface ElementChildrenAttribute { children: {} }
}
const A = (a: { children: string; b: number }) => null;
const a = <A[||]>text</A>;`,
result: ` b={0}`,
},
{
content: `// @jsx: preserve
// @Filename: a.tsx
declare namespace JSX {
interface Element {}
interface ElementChildrenAttribute { c: {} }
}
const A = (a: { c: string; b: number }) => null;
const a = <A[||]>{"text"}</A>;`,
result: ` b={0}`,
},
{
content: `// @jsx: preserve
// @Filename: a.tsx
declare namespace JSX {
interface Element {}
interface ElementChildrenAttribute { children: {} }
}
const A = (a: { children: string; b: number }) => null;
const a = <A[||]>{}</A>;`,
result: ` children={""} b={0}`,
},
{
content: `// @jsx: preserve
// @Filename: a.tsx
const A = (a: { a: number; b: string }) => null;
declare const b: { a?: number };
const a = <A[||] {...b} />;`,
result: ` a={0} b={""}`,
},
{
content: `// @jsx: preserve
// @Filename: a.tsx
const A = (a: { a: number; b: string }) => null;
declare const b: { a: number } | {};
const a = <A[||] {...b} />;`,
result: ` a={0} b={""}`,
},
{
content: `// @jsx: preserve
// @Filename: a.tsx
const A = (a: { a: number; b: string }) => null;
declare const b: { a?: number };
const a = <A[||] {...b} a={1} />;`,
result: ` b={""}`,
},
{
content: `// @jsx: preserve
// @Filename: a.tsx
const A = (a: { a: number }) => null;
declare const b: { a?: number };
const a = <A[||] {...b} />;`,
result: ` a={0}`,
},
{
content: `// @jsx: preserve
// @Filename: a.tsx
const A = (a: { a: number; b: string }) => null;
declare const b: { a?: number };
declare const c: { a: number };
const a = <A[||] {...c} {...b} />;`,
result: ` b={""}`,
},
{
content: `// @jsx: preserve
// @Filename: /a.ts
export enum E { a, b }
export class C {}
// @Filename: /b.tsx
import type { C as D, E as B } from "./a";
const A = (a: { a: B; b: D }) => null;
const a = <A />;`,
fileResult: `import { C as D, E as B } from "./a";
const A = (a: { a: B; b: D }) => null;
const a = <A a={B.a} b={new D} />;`,
filename: "/b.tsx",
},
} {
t.Run(strconv.Itoa(i+1), func(t *testing.T) {
t.Parallel()
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
f, done := fourslash.NewFourslash(t, nil /*capabilities*/, test.content)
defer done()
if test.filename != "" {
f.GoToFile(t, test.filename)
}
f.VerifyCodeFix(t, fourslash.VerifyCodeFixOptions{
Description: diagnostics.Add_missing_attributes.Localize(locale.Default),
NewFileContent: test.fileResult,
NewRangeContent: test.result,
ApplyChanges: true,
})
f.VerifyNoErrors(t)
})
}
}
Loading