feat: TypeScript 4.8+ support and NativeClass decorator improvements (#10081)

This commit is contained in:
Nathan Walker
2022-11-08 15:18:10 -08:00
committed by GitHub
parent 59ca35b44b
commit 7f069a7093
24 changed files with 143 additions and 149 deletions

View File

@@ -8,8 +8,9 @@ import ts from 'typescript';
export default function (ctx: ts.TransformationContext) {
function isNativeClassExtension(node: ts.ClassDeclaration) {
return (
node.decorators &&
node.decorators.filter((d) => {
ts.canHaveDecorators(node) &&
ts.getDecorators(node) &&
ts.getDecorators(node).filter((d) => {
const fullText = d.getFullText().trim();
return fullText.indexOf('@NativeClass') > -1;
}).length > 0
@@ -24,14 +25,14 @@ export default function (ctx: ts.TransformationContext) {
function createHelper(node: ts.Node) {
// we remove the decorator for now!
return ts.createIdentifier(
return ts.factory.createIdentifier(
ts
.transpileModule(
node.getText().replace(/@NativeClass(\((.|\n)*?\))?/gm, ''),
{
compilerOptions: {
noEmitHelpers: true,
module: ts.ModuleKind.CommonJS,
module: ts.ModuleKind.ESNext,
target: ts.ScriptTarget.ES5,
},
}
@@ -44,7 +45,7 @@ export default function (ctx: ts.TransformationContext) {
}
return (source: ts.SourceFile) =>
ts.updateSourceFileNode(
ts.factory.updateSourceFile(
source,
ts.visitNodes(source.statements, visitNode)
);