feat: css loading

This commit is contained in:
Igor Randjelovic
2020-11-20 19:56:54 +01:00
parent fa879ba49f
commit 288444c05c
8 changed files with 226 additions and 46 deletions

View File

@ -1 +1,46 @@
// todo
import ts from 'typescript';
export default function (ctx: ts.TransformationContext) {
function isNativeClassExtension(node: ts.ClassDeclaration) {
return (
node.decorators &&
node.decorators.filter((d) => {
const fullText = d.getFullText().trim();
return fullText.indexOf('@NativeClass') > -1;
}).length > 0
);
}
function visitNode(node: ts.Node): ts.Node {
if (ts.isClassDeclaration(node) && isNativeClassExtension(node)) {
return createHelper(node);
}
return ts.visitEachChild(node, visitNode, ctx);
}
function createHelper(node: ts.Node) {
// we remove the decorator for now!
return ts.createIdentifier(
ts
.transpileModule(
node.getText().replace(/@NativeClass(\((.|\n)*?\))?/gm, ''),
{
compilerOptions: {
noEmitHelpers: true,
module: ts.ModuleKind.CommonJS,
target: ts.ScriptTarget.ES5,
},
}
)
.outputText.replace(
/(Object\.defineProperty\(.*?{.*?)(enumerable:\s*false)(.*?}\))/gs,
'$1enumerable: true$3'
)
);
}
return (source: ts.SourceFile) =>
ts.updateSourceFileNode(
source,
ts.visitNodes(source.statements, visitNode)
);
}