mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
fix(webpack): make NativeClass transformer backwards compatible
This commit is contained in:
@@ -8,5 +8,3 @@ module.exports = (env) => {
|
|||||||
|
|
||||||
return webpack.resolveConfig();
|
return webpack.resolveConfig();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,20 +1,24 @@
|
|||||||
import ts from 'typescript';
|
import ts from 'typescript';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A TypeScript transform that compiles classes marked with @NativeClass as es5 & commonjs
|
* A TypeScript transform that compiles classes marked with `@NativeClass` as es5
|
||||||
*
|
|
||||||
* @param ctx
|
|
||||||
*/
|
*/
|
||||||
export default function (ctx: ts.TransformationContext) {
|
export default function (ctx: ts.TransformationContext) {
|
||||||
function isNativeClassExtension(node: ts.ClassDeclaration) {
|
function isNativeClassExtension(node: ts.ClassDeclaration) {
|
||||||
return (
|
let decorators: Readonly<ts.Decorator[]>;
|
||||||
ts.canHaveDecorators(node) &&
|
|
||||||
ts.getDecorators(node) &&
|
if ('canHaveDecorators' in ts && ts.canHaveDecorators(node)) {
|
||||||
ts.getDecorators(node).filter((d) => {
|
// use the newer decorators API when using a newer typescript version
|
||||||
|
decorators = ts.getDecorators(node);
|
||||||
|
} else {
|
||||||
|
// fallback to old behavior on older typescript versions
|
||||||
|
decorators = node.decorators;
|
||||||
|
}
|
||||||
|
|
||||||
|
return !!decorators?.some((d) => {
|
||||||
const fullText = d.getFullText().trim();
|
const fullText = d.getFullText().trim();
|
||||||
return fullText.indexOf('@NativeClass') > -1;
|
return fullText.indexOf('@NativeClass') > -1;
|
||||||
}).length > 0
|
});
|
||||||
);
|
|
||||||
}
|
}
|
||||||
function visitNode(node: ts.Node): ts.Node {
|
function visitNode(node: ts.Node): ts.Node {
|
||||||
if (ts.isClassDeclaration(node) && isNativeClassExtension(node)) {
|
if (ts.isClassDeclaration(node) && isNativeClassExtension(node)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user