MCPcopy Index your code
hub / github.com/NativeScript/NativeScript / transformStatements

Function transformStatements

tools/transformers/native-class.js:15–61  ·  view source on GitHub ↗
(statements, isTopLevel)

Source from the content-addressed store, hash-verified

13 const originalImportStatements = sourceFile.statements.filter((s) => ts.isImportDeclaration(s));
14
15 const transformStatements = (statements, isTopLevel) => {
16 let changed = false;
17 const result = [];
18
19 for (const statement of statements) {
20 if (ts.isClassDeclaration(statement) && hasNativeClassDecorator(statement)) {
21 mutated = true;
22 changed = true;
23 result.push(...emitDownleveledClass(statement));
24 continue;
25 }
26
27 if (ts.isExpressionStatement(statement)) {
28 const updated = removeNativeClassFromDecorate(factory, statement);
29 if (updated === undefined) {
30 mutated = true;
31 changed = true;
32 continue;
33 }
34 const visited = ts.visitEachChild(updated, visitNode, context);
35 if (updated !== statement || visited !== statement) {
36 mutated = true;
37 changed = true;
38 }
39 result.push(visited);
40 continue;
41 }
42
43 if (isTopLevel && ts.isImportDeclaration(statement)) {
44 // Safety: Do not alter import declarations here. Earlier versions attempted to
45 // remove `NativeClass` from named imports, but this proved too risky and could
46 // accidentally elide unrelated imports in certain TS versions/configs. We keep
47 // imports intact and rely on bundlers/TS to tree-shake if needed.
48 result.push(statement);
49 continue;
50 }
51
52 const visited = ts.visitEachChild(statement, visitNode, context);
53 if (visited !== statement) {
54 mutated = true;
55 changed = true;
56 }
57 result.push(visited);
58 }
59
60 return [changed ? factory.createNodeArray(result) : statements, changed];
61 };
62
63 function visitNode(node) {
64 if (ts.isBlock(node)) {

Callers 2

visitNodeFunction · 0.70
beforeFunction · 0.70

Calls 4

hasNativeClassDecoratorFunction · 0.70
emitDownleveledClassFunction · 0.70
pushMethod · 0.45

Tested by

no test coverage detected