typenative 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bin/parse-node.js CHANGED
@@ -68,6 +68,18 @@ const KIND_NAMES = (() => {
68
68
  }
69
69
  return names;
70
70
  })();
71
+ // var / let / const / using / await using (await using sets Const | Using)
72
+ function declarationKind(flags) {
73
+ if ((flags & 6) === 6)
74
+ return 'await using';
75
+ if (flags & 4)
76
+ return 'using';
77
+ if (flags & 2)
78
+ return 'const';
79
+ if (flags & 1)
80
+ return 'let';
81
+ return 'var';
82
+ }
71
83
  function isNode(v) {
72
84
  return typeof v === 'object' && v !== null && typeof v.kind === 'number' && typeof v.pos === 'number';
73
85
  }
@@ -76,6 +88,8 @@ function convertNode(node) {
76
88
  if (TEXT_KINDS.has(node.kind)) {
77
89
  obj.text = node.text ?? node.escapedText;
78
90
  }
91
+ if (node.kind === ts.SyntaxKind.VariableDeclarationList)
92
+ obj.declarationKind = declarationKind(node.flags);
79
93
  for (const key of Object.keys(node)) {
80
94
  if (SKIP_PROPS.has(key))
81
95
  continue;
@@ -104,7 +118,9 @@ function convertNode(node) {
104
118
  return obj;
105
119
  }
106
120
  // Parse TypeScript source into the normalized JSON AST shape.
107
- export function parseAstJson(code) {
108
- const sourceFile = ts.createSourceFile('main.ts', code, ts.ScriptTarget.ES2020, true, ts.ScriptKind.TS);
121
+ export function parseAstJson(code, tsx) {
122
+ const sourceFile = tsx
123
+ ? ts.createSourceFile('main.tsx', code, ts.ScriptTarget.ES2020, true, ts.ScriptKind.TSX)
124
+ : ts.createSourceFile('main.ts', code, ts.ScriptTarget.ES2020, true, ts.ScriptKind.TS);
109
125
  return convertNode(sourceFile);
110
126
  }