Skip to content

Commit 3e256e1

Browse files
committed
Add fourslash tests
1 parent 7102de7 commit 3e256e1

File tree

4 files changed

+69
-0
lines changed

4 files changed

+69
-0
lines changed

src/services/refactors/moveToNewFile.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,12 @@ namespace ts.refactor {
510510
}
511511

512512
const jsxNamespace = checker.getJsxNamespace(containsJsx);
513+
514+
// Strictly speaking, this could resolve to a symbol other than the JSX namespace.
515+
// This will produce erroneous output (probably, an incorrectly copied import) but
516+
// is expected to be very rare and easily reversible.
513517
const jsxNamespaceSymbol = checker.resolveName(jsxNamespace, containsJsx, SymbolFlags.Namespace, /*excludeGlobals*/ true);
518+
514519
return !!jsxNamespaceSymbol && some(jsxNamespaceSymbol.declarations, isInImport)
515520
? jsxNamespaceSymbol
516521
: undefined;
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
// @jsx: preserve
4+
// @noLib: true
5+
// @libFiles: react.d.ts,lib.d.ts
6+
7+
// @Filename: file.tsx
8+
//// import React = require('react');
9+
//// [|<div/>;|]
10+
//// 1;
11+
12+
verify.moveToNewFile({
13+
newFileContents: {
14+
"/tests/cases/fourslash/file.tsx":
15+
`1;`,
16+
"/tests/cases/fourslash/newFile.tsx":
17+
`import React = require('react');
18+
<div />;
19+
`,
20+
}
21+
});
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
// @jsx: preserve
4+
// @noLib: true
5+
// @libFiles: react.d.ts,lib.d.ts
6+
7+
// @Filename: file.tsx
8+
//// import React = require('react');
9+
//// [|<div/>;|]
10+
//// <div/>;
11+
12+
verify.moveToNewFile({
13+
newFileContents: {
14+
"/tests/cases/fourslash/file.tsx":
15+
`import React = require('react');
16+
<div/>;`,
17+
"/tests/cases/fourslash/newFile.tsx":
18+
`import React = require('react');
19+
<div />;
20+
`,
21+
}
22+
});
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
// @jsx: preserve
4+
// @noLib: true
5+
// @libFiles: react.d.ts,lib.d.ts
6+
7+
// @Filename: file.tsx
8+
//// import React = require('react');
9+
//// [|1;|]
10+
//// <div/>;
11+
12+
verify.moveToNewFile({
13+
newFileContents: {
14+
"/tests/cases/fourslash/file.tsx":
15+
`import React = require('react');
16+
<div/>;`,
17+
"/tests/cases/fourslash/newFile.tsx":
18+
`1;
19+
`,
20+
}
21+
});

0 commit comments

Comments
 (0)