adding self closing jsx element

This commit is contained in:
Sebastian 2022-02-23 16:12:34 -03:00
parent 8c3e572934
commit 7774f3508f
No known key found for this signature in database
GPG Key ID: BE4FF68352439FC1

View File

@ -19,8 +19,7 @@
*/ */
import * as ts from "typescript"; import * as ts from "typescript";
import * as fs from "fs"; import * as fs from "fs";
import * as os from "os"; import * as path from "path"
import path = require("path/posix");
function wordwrap(str: string, width: number = 80): string[] { function wordwrap(str: string, width: number = 80): string[] {
var regex = ".{1," + width + "}(\\s|$)|\\S+(\\s|$)"; var regex = ".{1," + width + "}(\\s|$)|\\S+(\\s|$)";
@ -146,7 +145,7 @@ function processFile(
outChunks.push(`#. ${cl}\n`); outChunks.push(`#. ${cl}\n`);
} }
} }
const fn = path.relative(process.cwd(), sourceFile.fileName); const fn = path.posix.relative(process.cwd(), sourceFile.fileName);
outChunks.push(`#: ${fn}:${line + 1}\n`); outChunks.push(`#: ${fn}:${line + 1}\n`);
outChunks.push(`#, c-format\n`); outChunks.push(`#, c-format\n`);
} }
@ -218,6 +217,7 @@ function processFile(
} }
case ts.SyntaxKind.JsxOpeningElement: case ts.SyntaxKind.JsxOpeningElement:
break; break;
case ts.SyntaxKind.JsxSelfClosingElement:
case ts.SyntaxKind.JsxElement: case ts.SyntaxKind.JsxElement:
fragments.push(`%${holeNum[0]++}$s`); fragments.push(`%${holeNum[0]++}$s`);
break; break;
@ -229,16 +229,13 @@ function processFile(
case ts.SyntaxKind.JsxClosingElement: case ts.SyntaxKind.JsxClosingElement:
break; break;
default: default:
console.log("unhandled node type: ", childNode.kind)
let lc = ts.getLineAndCharacterOfPosition( let lc = ts.getLineAndCharacterOfPosition(
childNode.getSourceFile(), childNode.getSourceFile(),
childNode.getStart(), childNode.getStart(),
); );
console.error( console.error(
`unrecognized syntax in JSX Element ${ `unrecognized syntax in JSX Element ${ts.SyntaxKind[childNode.kind]} (${childNode.getSourceFile().fileName}:${lc.line + 1}:${lc.character + 1}`,
ts.SyntaxKind[childNode.kind]
} (${childNode.getSourceFile().fileName}:${lc.line + 1}:${
lc.character + 1
}`,
); );
break; break;
} }