Skip to content
This repository has been archived by the owner on Jan 14, 2019. It is now read-only.

Commit

Permalink
fix: don't mutate original TypeScript AST in converter (#100)
Browse files Browse the repository at this point in the history
  • Loading branch information
armano2 authored and JamesHenry committed Jan 6, 2019
1 parent c8dd0d9 commit 40eae73
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions src/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2080,22 +2080,26 @@ export default function convert(config: ConvertConfig): ESTreeNode | null {
break;

case SyntaxKind.JsxSelfClosingElement: {
/**
* Convert SyntaxKind.JsxSelfClosingElement to SyntaxKind.JsxOpeningElement,
* TypeScript does not seem to have the idea of openingElement when tag is self-closing
*/
(node as any).kind = SyntaxKind.JsxOpeningElement;

const openingElement = convertChild(node);
(openingElement as any).selfClosing = true;

Object.assign(result, {
type: AST_NODE_TYPES.JSXElement,
openingElement,
/**
* Convert SyntaxKind.JsxSelfClosingElement to SyntaxKind.JsxOpeningElement,
* TypeScript does not seem to have the idea of openingElement when tag is self-closing
*/
openingElement: {
type: AST_NODE_TYPES.JSXOpeningElement,
typeParameters: node.typeArguments
? convertTypeArgumentsToTypeParameters(node.typeArguments)
: undefined,
selfClosing: true,
name: convertTypeScriptJSXTagNameToESTreeName(node.tagName),
attributes: node.attributes.properties.map(convertChild),
range: result.range,
loc: result.loc
},
closingElement: null,
children: []
});

break;
}

Expand Down

0 comments on commit 40eae73

Please sign in to comment.