@jay-framework/compiler-analyze-exported-types 0.19.6 → 0.19.7

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.
Files changed (2) hide show
  1. package/dist/index.js +42 -5
  2. package/package.json +6 -6
package/dist/index.js CHANGED
@@ -2,7 +2,7 @@ import fs from "fs";
2
2
  import { createRequire } from "module";
3
3
  import path from "path";
4
4
  import ts from "typescript";
5
- import { JayUnknown, JayElementType, JayObjectType, JayElementConstructorType, JayComponentApiMember, JayComponentType, resolvePrimitiveType, JayArrayType, JAY_COMPONENT, MAKE_JAY_COMPONENT } from "@jay-framework/compiler-shared";
5
+ import { JayUnknown, JayElementType, JayComponentType, JayObjectType, JayElementConstructorType, JayComponentApiMember, resolvePrimitiveType, JayArrayType, JAY_COMPONENT, MAKE_JAY_COMPONENT, JAY_FULLSTACK_COMPONENTS, MAKE_JAY_STACK_COMPONENT } from "@jay-framework/compiler-shared";
6
6
  const s = createRequire(import.meta.url), e = s("typescript"), c = new Proxy(e, {
7
7
  get(t, r) {
8
8
  return t[r];
@@ -92,6 +92,10 @@ function autoAddExtension(filename) {
92
92
  return filename + ".tsx";
93
93
  else if (fs.existsSync(filename + ".d.ts"))
94
94
  return filename + ".d.ts";
95
+ else if (fs.existsSync(filename) && fs.statSync(filename).isDirectory())
96
+ throw new Error(
97
+ `"${filename}" is a directory. The src attribute must point to the component file, e.g. "${filename}/${filename.split("/").pop()}"`
98
+ );
95
99
  else if (fs.existsSync(filename))
96
100
  return filename;
97
101
  else
@@ -120,6 +124,21 @@ function loadTSCompilerOptions(options = {}) {
120
124
  let tsConfig = parseConfigFileTextToJson("tsconfig.json", loadedTSConfig);
121
125
  return convertCompilerOptionsFromJson(tsConfig.config.compilerOptions, tsConfigPath).options;
122
126
  }
127
+ function findRootCallIdentifier(node) {
128
+ let expr = node.expression;
129
+ while (expr) {
130
+ if (isIdentifier(expr))
131
+ return expr;
132
+ if (isCallExpression(expr)) {
133
+ expr = expr.expression;
134
+ } else if ("expression" in expr) {
135
+ expr = expr.expression;
136
+ } else {
137
+ return void 0;
138
+ }
139
+ }
140
+ return void 0;
141
+ }
123
142
  function isExportedStatement(statement) {
124
143
  return Boolean(
125
144
  statement.modifiers && statement.modifiers.find(
@@ -128,7 +147,11 @@ function isExportedStatement(statement) {
128
147
  );
129
148
  }
130
149
  const SYMBOLS = {
131
- MAKE_JAY_COMPONENT: { module: JAY_COMPONENT, namedImport: MAKE_JAY_COMPONENT }
150
+ MAKE_JAY_COMPONENT: { module: JAY_COMPONENT, namedImport: MAKE_JAY_COMPONENT },
151
+ MAKE_JAY_STACK_COMPONENT: {
152
+ module: JAY_FULLSTACK_COMPONENTS,
153
+ namedImport: MAKE_JAY_STACK_COMPONENT
154
+ }
132
155
  };
133
156
  function findImportedSymbol(module, namedImport) {
134
157
  return Object.values(SYMBOLS).find(
@@ -158,7 +181,10 @@ function analyzeExportedTypes(filename, options = {}) {
158
181
  const sourceFile = program.getSourceFile(filename);
159
182
  const tsTypeChecker = program.getTypeChecker();
160
183
  const types = [];
161
- const { MAKE_JAY_COMPONENT: MAKE_JAY_COMPONENT2 } = mapImportedSymbols(sourceFile.statements, tsTypeChecker);
184
+ const { MAKE_JAY_COMPONENT: MAKE_JAY_COMPONENT2, MAKE_JAY_STACK_COMPONENT: MAKE_JAY_STACK_COMPONENT2 } = mapImportedSymbols(
185
+ sourceFile.statements,
186
+ tsTypeChecker
187
+ );
162
188
  for (const statement of sourceFile.statements.filter(isExportedStatement)) {
163
189
  if (isInterfaceDeclaration(statement)) {
164
190
  types.push(getInterfaceJayType(statement, types));
@@ -181,17 +207,28 @@ function analyzeExportedTypes(filename, options = {}) {
181
207
  } else if (isVariableStatement(statement)) {
182
208
  statement.declarationList.declarations.forEach((declaration) => {
183
209
  if (isCallExpression(declaration.initializer) && isIdentifier(declaration.name)) {
210
+ const name = declaration.name.text;
184
211
  const functionType = tsTypeChecker.getTypeAtLocation(
185
212
  declaration.initializer.expression
186
213
  );
187
- const name = declaration.name.text;
188
- if (functionType.symbol === MAKE_JAY_COMPONENT2.symbol) {
214
+ if (MAKE_JAY_COMPONENT2.symbol && functionType.symbol === MAKE_JAY_COMPONENT2.symbol) {
189
215
  const callMakeJayComponentSignature = tsTypeChecker.getResolvedSignature(
190
216
  declaration.initializer
191
217
  );
192
218
  const componentConstructorSignature = callMakeJayComponentSignature.getReturnType().getCallSignatures();
193
219
  let componentType = componentConstructorSignature[0].getReturnType();
194
220
  types.push(getComponentType(tsTypeChecker, name, componentType));
221
+ return;
222
+ }
223
+ if (MAKE_JAY_STACK_COMPONENT2.symbol) {
224
+ const rootIdentifier = findRootCallIdentifier(declaration.initializer);
225
+ if (rootIdentifier) {
226
+ const rootType = tsTypeChecker.getTypeAtLocation(rootIdentifier);
227
+ if (rootType.symbol === MAKE_JAY_STACK_COMPONENT2.symbol) {
228
+ types.push(new JayComponentType(name, [], true));
229
+ return;
230
+ }
231
+ }
195
232
  }
196
233
  }
197
234
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jay-framework/compiler-analyze-exported-types",
3
- "version": "0.19.6",
3
+ "version": "0.19.7",
4
4
  "description": "",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/index.js",
@@ -25,10 +25,10 @@
25
25
  },
26
26
  "author": "",
27
27
  "dependencies": {
28
- "@jay-framework/compiler-shared": "^0.19.6",
29
- "@jay-framework/component": "^0.19.6",
30
- "@jay-framework/runtime": "^0.19.6",
31
- "@jay-framework/secure": "^0.19.6",
28
+ "@jay-framework/compiler-shared": "^0.19.7",
29
+ "@jay-framework/component": "^0.19.7",
30
+ "@jay-framework/runtime": "^0.19.7",
31
+ "@jay-framework/secure": "^0.19.7",
32
32
  "@types/js-yaml": "^4.0.9",
33
33
  "change-case": "^4.1.2",
34
34
  "js-yaml": "^4.1.0",
@@ -38,7 +38,7 @@
38
38
  },
39
39
  "devDependencies": {
40
40
  "@caiogondim/strip-margin": "^1.0.0",
41
- "@jay-framework/dev-environment": "^0.19.6",
41
+ "@jay-framework/dev-environment": "^0.19.7",
42
42
  "@testing-library/jest-dom": "^6.2.0",
43
43
  "@types/js-beautify": "^1",
44
44
  "@types/node": "^20.11.5",