Skip to content

Commit 13a85c5

Browse files
authored
Merge pull request #186 from Calidus/issue150
inJsxText closing element bug
2 parents edf5ce8 + 91a92e0 commit 13a85c5

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

packages/ts-migrate-plugins/src/plugins/ts-ignore.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable no-use-before-define, @typescript-eslint/no-use-before-define */
2-
import ts from 'typescript';
2+
import ts, { isJsxFragment } from 'typescript';
33
import { Plugin } from 'ts-migrate-server';
44
import { isDiagnosticWithLinePosition } from '../utils/type-guards';
55
import updateSourceText, { SourceTextUpdate } from '../utils/updateSourceText';
@@ -166,7 +166,8 @@ function inJsxText(sourceFile: ts.SourceFile, pos: number) {
166166
const isJsxTextChild = node.children.some(
167167
(child) => ts.isJsxText(child) && child.pos <= pos && pos < child.end,
168168
);
169-
if (isJsxTextChild) {
169+
const isClosingElement = !isJsxFragment(node) && node.closingElement.pos === pos;
170+
if (isJsxTextChild || isClosingElement) {
170171
return true;
171172
}
172173
}

packages/ts-migrate-plugins/tests/src/ts-ignore.test.ts

+22
Original file line numberDiff line numberDiff line change
@@ -409,4 +409,26 @@ export default Foo;
409409
"
410410
`);
411411
});
412+
413+
it('add comment to closing tag in tsx file', async () => {
414+
const text = `<div>
415+
<span>text</span>
416+
</div>
417+
`;
418+
const result = await tsIgnorePlugin.run(
419+
mockPluginParams({
420+
fileName: 'Foo.tsx',
421+
text,
422+
semanticDiagnostics: [mockDiagnostic(text, '/div')],
423+
options: { messagePrefix: 'FIXME' },
424+
}),
425+
);
426+
expect(result).toMatchInlineSnapshot(`
427+
"<div>
428+
<span>text</span>
429+
{/* @ts-expect-error TS(123) FIXME: diagnostic message */}
430+
</div>
431+
"
432+
`);
433+
});
412434
});

0 commit comments

Comments
 (0)