@jay-framework/compiler 0.8.0 → 0.10.0
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/dist/index.d.ts +152 -1
- package/dist/index.js +200 -66
- package/package.json +8 -8
package/dist/index.d.ts
CHANGED
|
@@ -3,9 +3,127 @@ import * as ts from 'typescript';
|
|
|
3
3
|
import { JayHtmlSourceFile } from '@jay-framework/compiler-jay-html';
|
|
4
4
|
export { generateElementDefinitionFile } from '@jay-framework/compiler-jay-html';
|
|
5
5
|
|
|
6
|
+
declare enum VariableRootType {
|
|
7
|
+
FunctionParameter = 0,
|
|
8
|
+
FunctionDefinition = 1,
|
|
9
|
+
Literal = 2,
|
|
10
|
+
ImportModule = 3,
|
|
11
|
+
FunctionCall = 4,
|
|
12
|
+
Global = 5,
|
|
13
|
+
Other = 6
|
|
14
|
+
}
|
|
15
|
+
interface VariableRoot {
|
|
16
|
+
kind: VariableRootType;
|
|
17
|
+
}
|
|
18
|
+
interface ParamVariableRoot extends VariableRoot {
|
|
19
|
+
kind: VariableRootType.FunctionParameter;
|
|
20
|
+
paramIndex: number;
|
|
21
|
+
param: ts.ParameterDeclaration;
|
|
22
|
+
}
|
|
23
|
+
declare function mkParameterVariableRoot(param: ts.ParameterDeclaration, paramIndex: number): ParamVariableRoot;
|
|
24
|
+
interface FunctionVariableRoot extends VariableRoot {
|
|
25
|
+
kind: VariableRootType.FunctionDefinition;
|
|
26
|
+
func: ts.FunctionLikeDeclarationBase;
|
|
27
|
+
}
|
|
28
|
+
declare function mkFunctionVariableRoot(func: ts.FunctionLikeDeclarationBase): FunctionVariableRoot;
|
|
29
|
+
interface LiteralVariableRoot extends VariableRoot {
|
|
30
|
+
kind: VariableRootType.Literal;
|
|
31
|
+
literal: ts.Expression;
|
|
32
|
+
}
|
|
33
|
+
declare function mkLiteralVariableRoot(literal: ts.Expression): LiteralVariableRoot;
|
|
34
|
+
declare enum ImportType {
|
|
35
|
+
defaultImport = 0,
|
|
36
|
+
namedImport = 1
|
|
37
|
+
}
|
|
38
|
+
interface ImportModuleVariableRoot extends VariableRoot {
|
|
39
|
+
kind: VariableRootType.ImportModule;
|
|
40
|
+
module: ts.Expression;
|
|
41
|
+
importType: ImportType;
|
|
42
|
+
}
|
|
43
|
+
declare function mkImportModuleVariableRoot(module: ts.Expression, importType: ImportType): ImportModuleVariableRoot;
|
|
44
|
+
interface FunctionCallVariableRoot extends VariableRoot {
|
|
45
|
+
kind: VariableRootType.FunctionCall;
|
|
46
|
+
node: ts.CallExpression;
|
|
47
|
+
}
|
|
48
|
+
declare function mkFunctionCallVariableRoot(node: ts.CallExpression): FunctionCallVariableRoot;
|
|
49
|
+
interface GlobalVariableRoot extends VariableRoot {
|
|
50
|
+
kind: VariableRootType.Global;
|
|
51
|
+
name: string;
|
|
52
|
+
}
|
|
53
|
+
declare function mkGlobalVariableRoot(name: string): GlobalVariableRoot;
|
|
54
|
+
interface OtherVariableRoot extends VariableRoot {
|
|
55
|
+
kind: VariableRootType.Other;
|
|
56
|
+
node: ts.Node;
|
|
57
|
+
}
|
|
58
|
+
declare function mkOtherVariableRoot(node: ts.Node): OtherVariableRoot;
|
|
59
|
+
declare function isParamVariableRoot(vr: VariableRoot): vr is ParamVariableRoot;
|
|
60
|
+
declare function isFunctionVariableRoot(vr: VariableRoot): vr is FunctionVariableRoot;
|
|
61
|
+
declare function isImportModuleVariableRoot(vr: VariableRoot): vr is ImportModuleVariableRoot;
|
|
62
|
+
declare function isLiteralVariableRoot(vr: VariableRoot): vr is LiteralVariableRoot;
|
|
63
|
+
declare function isFunctionCallVariableRoot(vr: VariableRoot): vr is FunctionCallVariableRoot;
|
|
64
|
+
declare function isGlobalVariableRoot(vr: VariableRoot): vr is GlobalVariableRoot;
|
|
65
|
+
declare function isOtherVariableRoot(vr: VariableRoot): vr is OtherVariableRoot;
|
|
66
|
+
declare enum LetOrConst {
|
|
67
|
+
LET = 0,
|
|
68
|
+
CONST = 1
|
|
69
|
+
}
|
|
70
|
+
interface Variable {
|
|
71
|
+
name?: string;
|
|
72
|
+
letOrConst?: LetOrConst;
|
|
73
|
+
definingStatement?: ts.Statement;
|
|
74
|
+
accessedFrom?: Variable;
|
|
75
|
+
accessedByProperty?: string;
|
|
76
|
+
assignedFrom?: Variable;
|
|
77
|
+
root?: VariableRoot;
|
|
78
|
+
properties?: Variable[];
|
|
79
|
+
}
|
|
80
|
+
declare function mkVariable(members: {
|
|
81
|
+
name?: string;
|
|
82
|
+
letOrConst?: LetOrConst;
|
|
83
|
+
definingStatement?: ts.Statement;
|
|
84
|
+
accessedFrom?: Variable;
|
|
85
|
+
accessedByProperty?: string;
|
|
86
|
+
assignedFrom?: Variable;
|
|
87
|
+
root?: VariableRoot;
|
|
88
|
+
properties?: Variable[];
|
|
89
|
+
}): {
|
|
90
|
+
[k: string]: string | ts.Statement | VariableRoot | Variable | LetOrConst | Variable[];
|
|
91
|
+
};
|
|
92
|
+
declare const UNKNOWN_VARIABLE: Variable;
|
|
93
|
+
declare function tsBindingNameToVariable(binding: ts.BindingName, accessedFrom?: Variable, assignedFrom?: Variable, propertyName?: ts.PropertyName, root?: ParamVariableRoot): Variable[];
|
|
94
|
+
declare class NameBindingResolver {
|
|
95
|
+
readonly parentNameResolver?: NameBindingResolver;
|
|
96
|
+
constructor(parentNameResolver?: NameBindingResolver);
|
|
97
|
+
variables: Map<string, Variable>;
|
|
98
|
+
addVariable(name: string, variable: Variable): void;
|
|
99
|
+
addFunctionParams(functionDeclaration: ts.FunctionLikeDeclarationBase): void;
|
|
100
|
+
addFunctionDeclaration(statement: ts.FunctionDeclaration): void;
|
|
101
|
+
addVariableDeclarationList(declarationList: ts.VariableDeclarationList): void;
|
|
102
|
+
addVariableStatement(variableStatement: ts.VariableStatement): void;
|
|
103
|
+
getVariable(name: string): Variable;
|
|
104
|
+
resolvePropertyAccessChain(expression: ts.Expression): Variable;
|
|
105
|
+
resolvePropertyAccess(expression: ts.PropertyAccessExpression): Variable;
|
|
106
|
+
resolveIdentifier(expression: ts.Identifier): Variable;
|
|
107
|
+
addImportDeclaration(node: ts.ImportDeclaration): void;
|
|
108
|
+
}
|
|
109
|
+
interface FlattenedAccessChain {
|
|
110
|
+
path: string[];
|
|
111
|
+
root: VariableRoot;
|
|
112
|
+
}
|
|
113
|
+
declare function flattenVariable(variable: Variable, path?: string[]): FlattenedAccessChain;
|
|
114
|
+
|
|
6
115
|
interface ResolvedType {
|
|
7
116
|
canBeAssignedFrom(rightSide: ResolvedType): any;
|
|
8
117
|
}
|
|
118
|
+
declare class SourceFileBindingResolver {
|
|
119
|
+
private nameBindingResolvers;
|
|
120
|
+
constructor(sourceFile: ts.SourceFile);
|
|
121
|
+
findBindingResolver(node: ts.Node): NameBindingResolver;
|
|
122
|
+
explain(identifier: ts.Identifier | ts.PropertyAccessExpression): Variable;
|
|
123
|
+
explainFlattenedVariableType(flattened: FlattenedAccessChain): ResolvedType;
|
|
124
|
+
explainType(type: ts.TypeNode): ResolvedType;
|
|
125
|
+
globalType(globalVariableRoot: GlobalVariableRoot): ResolvedType;
|
|
126
|
+
}
|
|
9
127
|
|
|
10
128
|
declare enum CompilePatternType {
|
|
11
129
|
RETURN = 0,
|
|
@@ -71,6 +189,39 @@ declare function createTsSourceFileFromSource(filePath: string, sourceCode: stri
|
|
|
71
189
|
|
|
72
190
|
declare function transformComponentImports(needsHandler$: boolean, needsFunc$: boolean, needsFuncGlobal$: boolean, transformedSourceFile: ts.SourceFile, context: ts.TransformationContext, factory: ts.NodeFactory, sourceFile: ts.SourceFile): ts.SourceFile;
|
|
73
191
|
|
|
192
|
+
interface StatementDependencies {
|
|
193
|
+
id: number;
|
|
194
|
+
parent?: ts.Statement;
|
|
195
|
+
statement: ts.Statement;
|
|
196
|
+
dependsOn: Set<StatementDependencies>;
|
|
197
|
+
isDependencyFor: Set<StatementDependencies>;
|
|
198
|
+
}
|
|
199
|
+
declare class SourceFileStatementDependencies {
|
|
200
|
+
private statementDependencies;
|
|
201
|
+
constructor(sourceFile: ts.SourceFile, bindingResolver: SourceFileBindingResolver);
|
|
202
|
+
getDependsOn(statement: ts.Statement): Set<StatementDependencies>;
|
|
203
|
+
getIsDependencyFor(statement: ts.Statement): Set<StatementDependencies>;
|
|
204
|
+
getAllStatements(): IterableIterator<StatementDependencies>;
|
|
205
|
+
getStatementDependencies(statement: ts.Statement): StatementDependencies;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
interface SourceFileTransformerContext {
|
|
209
|
+
factory: ts.NodeFactory;
|
|
210
|
+
context: ts.TransformationContext;
|
|
211
|
+
sourceFile: ts.SourceFile;
|
|
212
|
+
}
|
|
213
|
+
type SourceFileTransformer<S extends SourceFileTransformerContext> = (data: SourceFileTransformerContext) => ts.SourceFile;
|
|
214
|
+
declare function mkTransformer<C extends object>(fileTransformer: SourceFileTransformer<C & SourceFileTransformerContext>, config?: C): ts.TransformerFactory<ts.SourceFile>;
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Compare two FlattenedAccessChain objects for equality
|
|
218
|
+
*
|
|
219
|
+
* Two chains are equal if:
|
|
220
|
+
* 1. Their paths are identical (same length, same elements in order)
|
|
221
|
+
* 2. Their roots refer to the same source
|
|
222
|
+
*/
|
|
223
|
+
declare function areFlattenedAccessChainsEqual(chain1: FlattenedAccessChain, chain2: FlattenedAccessChain): boolean;
|
|
224
|
+
|
|
74
225
|
declare function generateElementFile(jayFile: JayHtmlSourceFile, importerMode: MainRuntimeModes, generateTarget?: GenerateTarget): WithValidations<string>;
|
|
75
226
|
|
|
76
|
-
export { type CompiledPattern, FunctionRepositoryBuilder, compileFunctionSplitPatternsBlock, createTsSourceFileFromSource, extractImportDeclarations, extractImportedModules, generateElementFile, generateImportsFileFromJayFile, generateImportsFileFromTsSource, getImportName, getImportSpecifiers, isRelativeImport, parseGenericTypescriptFile, transformComponent, transformComponentBridge, transformComponentImports };
|
|
227
|
+
export { type CompiledPattern, type FlattenedAccessChain, type FunctionCallVariableRoot, FunctionRepositoryBuilder, type FunctionVariableRoot, type GlobalVariableRoot, type ImportModuleVariableRoot, ImportType, LetOrConst, type LiteralVariableRoot, NameBindingResolver, type OtherVariableRoot, type ParamVariableRoot, SourceFileBindingResolver, SourceFileStatementDependencies, type SourceFileTransformerContext, UNKNOWN_VARIABLE, type Variable, type VariableRoot, VariableRootType, areFlattenedAccessChainsEqual, compileFunctionSplitPatternsBlock, createTsSourceFileFromSource, extractImportDeclarations, extractImportedModules, flattenVariable, generateElementFile, generateImportsFileFromJayFile, generateImportsFileFromTsSource, getImportName, getImportSpecifiers, isFunctionCallVariableRoot, isFunctionVariableRoot, isGlobalVariableRoot, isImportModuleVariableRoot, isLiteralVariableRoot, isOtherVariableRoot, isParamVariableRoot, isRelativeImport, mkFunctionCallVariableRoot, mkFunctionVariableRoot, mkGlobalVariableRoot, mkImportModuleVariableRoot, mkLiteralVariableRoot, mkOtherVariableRoot, mkParameterVariableRoot, mkTransformer, mkVariable, parseGenericTypescriptFile, transformComponent, transformComponentBridge, transformComponentImports, tsBindingNameToVariable };
|
package/dist/index.js
CHANGED
|
@@ -56,7 +56,7 @@ function mkTransformer(fileTransformer, config) {
|
|
|
56
56
|
};
|
|
57
57
|
};
|
|
58
58
|
}
|
|
59
|
-
const { isStringLiteral: isStringLiteral$
|
|
59
|
+
const { isStringLiteral: isStringLiteral$a, isImportDeclaration: isImportDeclaration$5, forEachChild: forEachChild$4, isNamedImports: isNamedImports$1 } = c;
|
|
60
60
|
function extractImportDeclarations(sourceFile) {
|
|
61
61
|
const importDeclarations = [];
|
|
62
62
|
function visit(node) {
|
|
@@ -69,7 +69,7 @@ function extractImportDeclarations(sourceFile) {
|
|
|
69
69
|
return importDeclarations;
|
|
70
70
|
}
|
|
71
71
|
function extractImportedModules(sourceFile) {
|
|
72
|
-
return extractImportDeclarations(sourceFile).filter((node) => isStringLiteral$
|
|
72
|
+
return extractImportDeclarations(sourceFile).filter((node) => isStringLiteral$a(node.moduleSpecifier)).map((node) => node.moduleSpecifier.text);
|
|
73
73
|
}
|
|
74
74
|
function isRelativeImport(module) {
|
|
75
75
|
return module.startsWith(".");
|
|
@@ -81,9 +81,9 @@ function getImportSpecifiers(importDeclaration) {
|
|
|
81
81
|
function getImportName(importSpecifier) {
|
|
82
82
|
return importSpecifier.propertyName?.text ?? importSpecifier.name.text;
|
|
83
83
|
}
|
|
84
|
-
const { isStringLiteral: isStringLiteral$
|
|
84
|
+
const { isStringLiteral: isStringLiteral$9, forEachChild: forEachChild$3, isImportDeclaration: isImportDeclaration$4 } = c;
|
|
85
85
|
function findMakeJayComponentImport(makeJayComponentName, node) {
|
|
86
|
-
if (isImportDeclaration$4(node) && isStringLiteral$
|
|
86
|
+
if (isImportDeclaration$4(node) && isStringLiteral$9(node.moduleSpecifier) && node.moduleSpecifier.text === JAY_COMPONENT) {
|
|
87
87
|
let importSpecifier = getImportSpecifiers(node)?.find(
|
|
88
88
|
(element) => getImportName(element) === makeJayComponentName
|
|
89
89
|
);
|
|
@@ -93,11 +93,11 @@ function findMakeJayComponentImport(makeJayComponentName, node) {
|
|
|
93
93
|
}
|
|
94
94
|
return void 0;
|
|
95
95
|
}
|
|
96
|
-
const { isIdentifier: isIdentifier$
|
|
96
|
+
const { isIdentifier: isIdentifier$a, isArrowFunction: isArrowFunction$3, isFunctionDeclaration: isFunctionDeclaration$2, isVariableStatement: isVariableStatement$3, forEachChild: forEachChild$2 } = c;
|
|
97
97
|
function findComponentConstructorsBlock(componentFunctionExpressions, sourceFile) {
|
|
98
98
|
const foundConstructors = [];
|
|
99
99
|
const namedConstructors = new Set(
|
|
100
|
-
componentFunctionExpressions.filter((expression) => isIdentifier$
|
|
100
|
+
componentFunctionExpressions.filter((expression) => isIdentifier$a(expression)).map((expression) => isIdentifier$a(expression) && expression.text)
|
|
101
101
|
);
|
|
102
102
|
const inlineConstructors = componentFunctionExpressions.filter(
|
|
103
103
|
isFunctionLikeDeclarationBase
|
|
@@ -108,7 +108,7 @@ function findComponentConstructorsBlock(componentFunctionExpressions, sourceFile
|
|
|
108
108
|
foundConstructors.push(node);
|
|
109
109
|
} else if (isVariableStatement$3(node)) {
|
|
110
110
|
node.declarationList.declarations.forEach((declaration) => {
|
|
111
|
-
if (isIdentifier$
|
|
111
|
+
if (isIdentifier$a(declaration.name) && namedConstructors.has(declaration.name.text) && declaration.initializer && isArrowFunction$3(declaration.initializer))
|
|
112
112
|
foundConstructors.push(declaration.initializer);
|
|
113
113
|
});
|
|
114
114
|
}
|
|
@@ -118,14 +118,14 @@ function findComponentConstructorsBlock(componentFunctionExpressions, sourceFile
|
|
|
118
118
|
return [...foundConstructors, ...inlineConstructors];
|
|
119
119
|
}
|
|
120
120
|
const {
|
|
121
|
-
isIdentifier: isIdentifier$
|
|
122
|
-
isStatement: isStatement$
|
|
121
|
+
isIdentifier: isIdentifier$9,
|
|
122
|
+
isStatement: isStatement$3,
|
|
123
123
|
isObjectBindingPattern,
|
|
124
124
|
isArrayBindingPattern,
|
|
125
125
|
isBindingElement,
|
|
126
126
|
isPropertyAccessExpression: isPropertyAccessExpression$5,
|
|
127
127
|
isElementAccessExpression: isElementAccessExpression$1,
|
|
128
|
-
isStringLiteral: isStringLiteral$
|
|
128
|
+
isStringLiteral: isStringLiteral$8,
|
|
129
129
|
isParenthesizedExpression,
|
|
130
130
|
isAsExpression,
|
|
131
131
|
isObjectLiteralExpression,
|
|
@@ -141,6 +141,16 @@ const {
|
|
|
141
141
|
NodeFlags,
|
|
142
142
|
SyntaxKind: SyntaxKind$5
|
|
143
143
|
} = c;
|
|
144
|
+
var VariableRootType = /* @__PURE__ */ ((VariableRootType2) => {
|
|
145
|
+
VariableRootType2[VariableRootType2["FunctionParameter"] = 0] = "FunctionParameter";
|
|
146
|
+
VariableRootType2[VariableRootType2["FunctionDefinition"] = 1] = "FunctionDefinition";
|
|
147
|
+
VariableRootType2[VariableRootType2["Literal"] = 2] = "Literal";
|
|
148
|
+
VariableRootType2[VariableRootType2["ImportModule"] = 3] = "ImportModule";
|
|
149
|
+
VariableRootType2[VariableRootType2["FunctionCall"] = 4] = "FunctionCall";
|
|
150
|
+
VariableRootType2[VariableRootType2["Global"] = 5] = "Global";
|
|
151
|
+
VariableRootType2[VariableRootType2["Other"] = 6] = "Other";
|
|
152
|
+
return VariableRootType2;
|
|
153
|
+
})(VariableRootType || {});
|
|
144
154
|
function mkParameterVariableRoot(param, paramIndex) {
|
|
145
155
|
return { kind: 0, param, paramIndex };
|
|
146
156
|
}
|
|
@@ -150,6 +160,11 @@ function mkFunctionVariableRoot(func) {
|
|
|
150
160
|
function mkLiteralVariableRoot(literal) {
|
|
151
161
|
return { kind: 2, literal };
|
|
152
162
|
}
|
|
163
|
+
var ImportType = /* @__PURE__ */ ((ImportType2) => {
|
|
164
|
+
ImportType2[ImportType2["defaultImport"] = 0] = "defaultImport";
|
|
165
|
+
ImportType2[ImportType2["namedImport"] = 1] = "namedImport";
|
|
166
|
+
return ImportType2;
|
|
167
|
+
})(ImportType || {});
|
|
153
168
|
function mkImportModuleVariableRoot(module, importType) {
|
|
154
169
|
return { kind: 3, module, importType };
|
|
155
170
|
}
|
|
@@ -180,6 +195,9 @@ function isFunctionCallVariableRoot(vr) {
|
|
|
180
195
|
function isGlobalVariableRoot(vr) {
|
|
181
196
|
return vr.kind === 5;
|
|
182
197
|
}
|
|
198
|
+
function isOtherVariableRoot(vr) {
|
|
199
|
+
return vr.kind === 6;
|
|
200
|
+
}
|
|
183
201
|
var LetOrConst = /* @__PURE__ */ ((LetOrConst2) => {
|
|
184
202
|
LetOrConst2[LetOrConst2["LET"] = 0] = "LET";
|
|
185
203
|
LetOrConst2[LetOrConst2["CONST"] = 1] = "CONST";
|
|
@@ -190,18 +208,18 @@ function mkVariable(members) {
|
|
|
190
208
|
}
|
|
191
209
|
const UNKNOWN_VARIABLE = {};
|
|
192
210
|
const getAccessedByProperty = (binding, accessedFrom, propertyName) => {
|
|
193
|
-
return accessedFrom ? propertyName ? isIdentifier$
|
|
211
|
+
return accessedFrom ? propertyName ? isIdentifier$9(propertyName) ? propertyName.text : void 0 : binding.text : void 0;
|
|
194
212
|
};
|
|
195
213
|
function findDeclaringStatement(node) {
|
|
196
214
|
if (!node)
|
|
197
215
|
return void 0;
|
|
198
|
-
else if (isStatement$
|
|
216
|
+
else if (isStatement$3(node))
|
|
199
217
|
return node;
|
|
200
218
|
else
|
|
201
219
|
return findDeclaringStatement(node.parent);
|
|
202
220
|
}
|
|
203
221
|
function tsBindingNameToVariable(binding, accessedFrom, assignedFrom, propertyName, root) {
|
|
204
|
-
if (isIdentifier$
|
|
222
|
+
if (isIdentifier$9(binding)) {
|
|
205
223
|
return [
|
|
206
224
|
mkVariable({
|
|
207
225
|
name: binding.text,
|
|
@@ -215,7 +233,7 @@ function tsBindingNameToVariable(binding, accessedFrom, assignedFrom, propertyNa
|
|
|
215
233
|
} else if (isObjectBindingPattern(binding)) {
|
|
216
234
|
let variable = mkVariable({
|
|
217
235
|
accessedFrom,
|
|
218
|
-
accessedByProperty: propertyName ? isIdentifier$
|
|
236
|
+
accessedByProperty: propertyName ? isIdentifier$9(propertyName) ? propertyName.text : void 0 : void 0,
|
|
219
237
|
assignedFrom,
|
|
220
238
|
root,
|
|
221
239
|
definingStatement: findDeclaringStatement(binding)
|
|
@@ -226,7 +244,7 @@ function tsBindingNameToVariable(binding, accessedFrom, assignedFrom, propertyNa
|
|
|
226
244
|
} else if (isArrayBindingPattern(binding)) {
|
|
227
245
|
let variable = mkVariable({
|
|
228
246
|
accessedFrom,
|
|
229
|
-
accessedByProperty: propertyName ? isIdentifier$
|
|
247
|
+
accessedByProperty: propertyName ? isIdentifier$9(propertyName) ? propertyName.text : void 0 : void 0,
|
|
230
248
|
assignedFrom,
|
|
231
249
|
root,
|
|
232
250
|
definingStatement: findDeclaringStatement(binding)
|
|
@@ -298,11 +316,11 @@ class NameBindingResolver {
|
|
|
298
316
|
const name = expression.name.text;
|
|
299
317
|
const identifiersFromObject = this.resolvePropertyAccessChain(expression.expression);
|
|
300
318
|
return { accessedFrom: identifiersFromObject, accessedByProperty: name };
|
|
301
|
-
} else if (isElementAccessExpression$1(expression) && isStringLiteral$
|
|
319
|
+
} else if (isElementAccessExpression$1(expression) && isStringLiteral$8(expression.argumentExpression)) {
|
|
302
320
|
const name = expression.argumentExpression.text;
|
|
303
321
|
const identifiersFromObject = this.resolvePropertyAccessChain(expression.expression);
|
|
304
322
|
return { accessedFrom: identifiersFromObject, accessedByProperty: name };
|
|
305
|
-
} else if (isIdentifier$
|
|
323
|
+
} else if (isIdentifier$9(expression)) {
|
|
306
324
|
return this.resolveIdentifier(expression);
|
|
307
325
|
} else if (isParenthesizedExpression(expression)) {
|
|
308
326
|
return this.resolvePropertyAccessChain(expression.expression);
|
|
@@ -311,8 +329,8 @@ class NameBindingResolver {
|
|
|
311
329
|
} else if (isObjectLiteralExpression(expression)) {
|
|
312
330
|
return {
|
|
313
331
|
properties: expression.properties.map((property) => {
|
|
314
|
-
if (isPropertyAssignment$1(property) && (isStringLiteral$
|
|
315
|
-
if (isIdentifier$
|
|
332
|
+
if (isPropertyAssignment$1(property) && (isStringLiteral$8(property.name) || isIdentifier$9(property.name))) {
|
|
333
|
+
if (isIdentifier$9(property.initializer))
|
|
316
334
|
return {
|
|
317
335
|
name: property.name.text,
|
|
318
336
|
assignedFrom: this.resolveIdentifier(property.initializer)
|
|
@@ -344,7 +362,7 @@ class NameBindingResolver {
|
|
|
344
362
|
return { root: mkFunctionVariableRoot(expression) };
|
|
345
363
|
} else if (isCallExpression$6(expression)) {
|
|
346
364
|
return { root: mkFunctionCallVariableRoot(expression) };
|
|
347
|
-
} else if (isStringLiteral$
|
|
365
|
+
} else if (isStringLiteral$8(expression) || isNumericLiteral(expression) || isToken(expression) && expression.kind === SyntaxKind$5.TrueKeyword || isToken(expression) && expression.kind === SyntaxKind$5.FalseKeyword) {
|
|
348
366
|
return { root: mkLiteralVariableRoot(expression) };
|
|
349
367
|
} else {
|
|
350
368
|
return { root: mkOtherVariableRoot(expression) };
|
|
@@ -423,9 +441,9 @@ function flattenVariable(variable, path2 = []) {
|
|
|
423
441
|
} else
|
|
424
442
|
return { path: path2, root: variable.root };
|
|
425
443
|
}
|
|
426
|
-
const { isIdentifier: isIdentifier$
|
|
444
|
+
const { isIdentifier: isIdentifier$8, isPropertyAccessExpression: isPropertyAccessExpression$4 } = c;
|
|
427
445
|
function isIdentifierOrPropertyAccessExpression(node) {
|
|
428
|
-
return isIdentifier$
|
|
446
|
+
return isIdentifier$8(node) || isPropertyAccessExpression$4(node);
|
|
429
447
|
}
|
|
430
448
|
function byAnd() {
|
|
431
449
|
return (agg, value) => agg && value;
|
|
@@ -433,7 +451,7 @@ function byAnd() {
|
|
|
433
451
|
const {
|
|
434
452
|
isCallExpression: isCallExpression$5,
|
|
435
453
|
isExpressionStatement: isExpressionStatement$1,
|
|
436
|
-
isIdentifier: isIdentifier$
|
|
454
|
+
isIdentifier: isIdentifier$7,
|
|
437
455
|
isPropertyAccessExpression: isPropertyAccessExpression$3,
|
|
438
456
|
isBlock: isBlock$3
|
|
439
457
|
} = c;
|
|
@@ -455,7 +473,7 @@ function findEventHandlersBlock(functionDeclaration, bindingResolver) {
|
|
|
455
473
|
eventHandlerCallStatement: statement,
|
|
456
474
|
handlerIndex: nextEventHandlerIndex++
|
|
457
475
|
});
|
|
458
|
-
else if (isIdentifier$
|
|
476
|
+
else if (isIdentifier$7(handler) || isPropertyAccessExpression$3(handler)) {
|
|
459
477
|
let flattenedHandler = flattenVariable(
|
|
460
478
|
bindingResolver.explain(handler)
|
|
461
479
|
);
|
|
@@ -476,10 +494,10 @@ function findEventHandlersBlock(functionDeclaration, bindingResolver) {
|
|
|
476
494
|
return foundEventHandlers;
|
|
477
495
|
}
|
|
478
496
|
const {
|
|
479
|
-
isIdentifier: isIdentifier$
|
|
497
|
+
isIdentifier: isIdentifier$6,
|
|
480
498
|
SyntaxKind: SyntaxKind$4,
|
|
481
|
-
isStringLiteral: isStringLiteral$
|
|
482
|
-
visitNode: visitNode$
|
|
499
|
+
isStringLiteral: isStringLiteral$7,
|
|
500
|
+
visitNode: visitNode$4,
|
|
483
501
|
isFunctionDeclaration: isFunctionDeclaration$1,
|
|
484
502
|
isVariableStatement: isVariableStatement$2,
|
|
485
503
|
isImportDeclaration: isImportDeclaration$3,
|
|
@@ -582,7 +600,7 @@ class SourceFileBindingResolver {
|
|
|
582
600
|
nbResolversQueue.unshift(new NameBindingResolver(nbResolversQueue[0]));
|
|
583
601
|
this.nameBindingResolvers.set(node, nbResolversQueue[0]);
|
|
584
602
|
callback();
|
|
585
|
-
node.getChildren().forEach((child) => visitNode$
|
|
603
|
+
node.getChildren().forEach((child) => visitNode$4(child, visitor));
|
|
586
604
|
nbResolversQueue.shift();
|
|
587
605
|
return node;
|
|
588
606
|
};
|
|
@@ -608,7 +626,7 @@ class SourceFileBindingResolver {
|
|
|
608
626
|
node.initializer
|
|
609
627
|
)
|
|
610
628
|
);
|
|
611
|
-
} else if ((isForInStatement$1(node) || isForOfStatement$1(node)) && isVariableDeclarationList(node.initializer) && node.initializer.declarations.length === 1 && isIdentifier$
|
|
629
|
+
} else if ((isForInStatement$1(node) || isForOfStatement$1(node)) && isVariableDeclarationList(node.initializer) && node.initializer.declarations.length === 1 && isIdentifier$6(node.initializer.declarations[0].name)) {
|
|
612
630
|
return doWithChildBindingResolver(node, () => {
|
|
613
631
|
let name = node.initializer.declarations[0].name.text;
|
|
614
632
|
nbResolversQueue[0].addVariable(
|
|
@@ -621,10 +639,10 @@ class SourceFileBindingResolver {
|
|
|
621
639
|
);
|
|
622
640
|
});
|
|
623
641
|
}
|
|
624
|
-
node.getChildren().forEach((child) => visitNode$
|
|
642
|
+
node.getChildren().forEach((child) => visitNode$4(child, visitor));
|
|
625
643
|
return node;
|
|
626
644
|
};
|
|
627
|
-
visitNode$
|
|
645
|
+
visitNode$4(sourceFile, visitor);
|
|
628
646
|
}
|
|
629
647
|
findBindingResolver(node) {
|
|
630
648
|
let found;
|
|
@@ -637,7 +655,7 @@ class SourceFileBindingResolver {
|
|
|
637
655
|
}
|
|
638
656
|
explainFlattenedVariableType(flattened) {
|
|
639
657
|
if (!!flattened.root) {
|
|
640
|
-
if (isImportModuleVariableRoot(flattened.root) && isStringLiteral$
|
|
658
|
+
if (isImportModuleVariableRoot(flattened.root) && isStringLiteral$7(flattened.root.module)) {
|
|
641
659
|
return new ImportFromModuleResolvedType(flattened.root.module.text, flattened.path);
|
|
642
660
|
}
|
|
643
661
|
} else
|
|
@@ -647,7 +665,7 @@ class SourceFileBindingResolver {
|
|
|
647
665
|
if (type) {
|
|
648
666
|
if (isTypeReferenceNode$1(type)) {
|
|
649
667
|
let typeName = type.typeName;
|
|
650
|
-
if (isIdentifier$
|
|
668
|
+
if (isIdentifier$6(typeName)) {
|
|
651
669
|
let resolved = this.findBindingResolver(typeName).resolveIdentifier(typeName);
|
|
652
670
|
let flattened = flattenVariable(resolved);
|
|
653
671
|
let typeFromFlattened = this.explainFlattenedVariableType(flattened);
|
|
@@ -689,7 +707,7 @@ const {
|
|
|
689
707
|
isFunctionDeclaration,
|
|
690
708
|
isDecorator,
|
|
691
709
|
isCallExpression: isCallExpression$4,
|
|
692
|
-
isIdentifier: isIdentifier$
|
|
710
|
+
isIdentifier: isIdentifier$5,
|
|
693
711
|
isPropertyAccessExpression: isPropertyAccessExpression$2,
|
|
694
712
|
isReturnStatement,
|
|
695
713
|
isNewExpression: isNewExpression$1,
|
|
@@ -762,7 +780,7 @@ function compileFunctionSplitPatternsBlock(patternFiles) {
|
|
|
762
780
|
if (isFunctionDeclaration(node)) {
|
|
763
781
|
let declaredTargetEnv = 0;
|
|
764
782
|
node.modifiers && node.modifiers.forEach((modifier) => {
|
|
765
|
-
if (isDecorator(modifier) && isCallExpression$4(modifier.expression) && isIdentifier$
|
|
783
|
+
if (isDecorator(modifier) && isCallExpression$4(modifier.expression) && isIdentifier$5(modifier.expression.expression) && modifier.expression.expression.text === "JayPattern" && modifier.expression.arguments.length === 1 && isPropertyAccessExpression$2(modifier.expression.arguments[0]) && isIdentifier$5(modifier.expression.arguments[0].expression) && modifier.expression.arguments[0].expression.text === "JayTargetEnv" && modifier.expression.arguments[0].name.text === "any")
|
|
766
784
|
declaredTargetEnv = 1;
|
|
767
785
|
});
|
|
768
786
|
let name = node.name.text;
|
|
@@ -799,7 +817,7 @@ function compileFunctionSplitPatternsBlock(patternFiles) {
|
|
|
799
817
|
sourceFileBinding,
|
|
800
818
|
node
|
|
801
819
|
);
|
|
802
|
-
} else if (isExpressionStatement(statement) && isBinaryExpression$1(statement.expression) && isPropertyAccessExpression$2(statement.expression.left) && statement.expression.operatorToken.kind === SyntaxKind$3.EqualsToken && isIdentifier$
|
|
820
|
+
} else if (isExpressionStatement(statement) && isBinaryExpression$1(statement.expression) && isPropertyAccessExpression$2(statement.expression.left) && statement.expression.operatorToken.kind === SyntaxKind$3.EqualsToken && isIdentifier$5(statement.expression.right)) {
|
|
803
821
|
patternType = 3;
|
|
804
822
|
leftHandSide = statement.expression.left;
|
|
805
823
|
callArgumentTypes = [
|
|
@@ -851,7 +869,7 @@ function compileFunctionSplitPatternsBlock(patternFiles) {
|
|
|
851
869
|
});
|
|
852
870
|
return new WithValidations(compiledPatterns, validations);
|
|
853
871
|
}
|
|
854
|
-
const { visitEachChild: visitEachChild$3, transform: transform$4, visitNode: visitNode$
|
|
872
|
+
const { visitEachChild: visitEachChild$3, transform: transform$4, visitNode: visitNode$3 } = c;
|
|
855
873
|
function visitWithContext(node, initialContext, contextualVisitor) {
|
|
856
874
|
return visitWithContext2(node, initialContext, void 0, contextualVisitor);
|
|
857
875
|
}
|
|
@@ -860,7 +878,7 @@ function visitWithContext2(node, initialContext, transformationContext, contextu
|
|
|
860
878
|
const visitChild = (node2, childContext) => {
|
|
861
879
|
if (childContext)
|
|
862
880
|
contexts.push(childContext);
|
|
863
|
-
let visitedNode = visitNode$
|
|
881
|
+
let visitedNode = visitNode$3(node2, visitor);
|
|
864
882
|
if (childContext)
|
|
865
883
|
contexts.pop();
|
|
866
884
|
return visitedNode;
|
|
@@ -876,7 +894,7 @@ function visitWithContext2(node, initialContext, transformationContext, contextu
|
|
|
876
894
|
const visitor = (node2) => {
|
|
877
895
|
return contextualVisitor(node2, contexts.at(-1), visitChild, _visitEachChild);
|
|
878
896
|
};
|
|
879
|
-
return visitNode$
|
|
897
|
+
return visitNode$3(node, visitor);
|
|
880
898
|
}
|
|
881
899
|
const { isTypeReferenceNode } = c;
|
|
882
900
|
function isFirstParamJayEvent(eventHandler, bindingResolver) {
|
|
@@ -895,14 +913,14 @@ function filterEventHandlersToHaveJayEventType(foundEventHandlers, bindingResolv
|
|
|
895
913
|
}
|
|
896
914
|
const {
|
|
897
915
|
visitEachChild: visitEachChild$2,
|
|
898
|
-
isIdentifier: isIdentifier$
|
|
916
|
+
isIdentifier: isIdentifier$4,
|
|
899
917
|
SyntaxKind: SyntaxKind$2,
|
|
900
918
|
transform: transform$3,
|
|
901
|
-
isStatement: isStatement$
|
|
919
|
+
isStatement: isStatement$2,
|
|
902
920
|
isBlock: isBlock$1,
|
|
903
921
|
isExpression: isExpression$1,
|
|
904
922
|
isLiteralExpression: isLiteralExpression$1,
|
|
905
|
-
visitNode: visitNode$
|
|
923
|
+
visitNode: visitNode$2
|
|
906
924
|
} = c;
|
|
907
925
|
function generateFunctionRepository(matchedReturnPatterns, matchedVariableReads, matchedConstants, safeStatements) {
|
|
908
926
|
const constCode = [...new Set(matchedConstants)].join("\n");
|
|
@@ -947,7 +965,7 @@ const mkTransformEventHandlerStatementVisitor = (factory, context, bindingResolv
|
|
|
947
965
|
return patternIndexes.get(pattern);
|
|
948
966
|
};
|
|
949
967
|
const visitor = (node, { parentStatementTargetEnv }, visitChild, visitEachChild2) => {
|
|
950
|
-
if (isStatement$
|
|
968
|
+
if (isStatement$2(node)) {
|
|
951
969
|
let statementAnalysis = analyzer.getStatementStatus(node);
|
|
952
970
|
if (statementAnalysis)
|
|
953
971
|
parentStatementTargetEnv = intersectJayTargetEnv(
|
|
@@ -987,9 +1005,9 @@ const mkTransformEventHandlerStatementVisitor = (factory, context, bindingResolv
|
|
|
987
1005
|
let patternKey = getPatternIndex(pattern);
|
|
988
1006
|
if (pattern.patternType === CompilePatternType.RETURN)
|
|
989
1007
|
sideEffects.matchedReturnPatterns.push({ pattern, patternKey });
|
|
990
|
-
else if (pattern.patternType === CompilePatternType.KNOWN_VARIABLE_READ && isIdentifier$
|
|
1008
|
+
else if (pattern.patternType === CompilePatternType.KNOWN_VARIABLE_READ && isIdentifier$4(node))
|
|
991
1009
|
sideEffects.matchedVariableReads.push({ variable: node, patternKey });
|
|
992
|
-
else if (pattern.patternType === CompilePatternType.CONST_READ && isIdentifier$
|
|
1010
|
+
else if (pattern.patternType === CompilePatternType.CONST_READ && isIdentifier$4(node)) {
|
|
993
1011
|
let constant = bindingResolver.explain(node);
|
|
994
1012
|
let flattenedConstant = flattenVariable(constant);
|
|
995
1013
|
let literal = flattenedConstant.root.literal;
|
|
@@ -1048,7 +1066,7 @@ const analyzeEventHandlerByPatternBlock = (context, bindingResolver, analyzer, f
|
|
|
1048
1066
|
let mainNode = isBlock$1(node) && sideEffects.mainContextBlocks.has(node) ? sideEffects.mainContextBlocks.get(node) : node;
|
|
1049
1067
|
return visitEachChild$2(mainNode, replaceBodiesVisitor, context);
|
|
1050
1068
|
};
|
|
1051
|
-
bodyForFunctionRepository = visitNode$
|
|
1069
|
+
bodyForFunctionRepository = visitNode$2(body, replaceBodiesVisitor);
|
|
1052
1070
|
}
|
|
1053
1071
|
const { handlerCode, key } = generateFunctionRepository(
|
|
1054
1072
|
sideEffects.matchedReturnPatterns,
|
|
@@ -1141,13 +1159,13 @@ function analyzeEventHandlers(context, bindingResolver, analyzer, factory, found
|
|
|
1141
1159
|
const {
|
|
1142
1160
|
isBinaryExpression,
|
|
1143
1161
|
isCallExpression: isCallExpression$2,
|
|
1144
|
-
isIdentifier: isIdentifier$
|
|
1162
|
+
isIdentifier: isIdentifier$3,
|
|
1145
1163
|
isNewExpression,
|
|
1146
1164
|
isPropertyAccessExpression,
|
|
1147
1165
|
SyntaxKind: SyntaxKind$1,
|
|
1148
1166
|
isArrowFunction: isArrowFunction$1,
|
|
1149
1167
|
isLiteralExpression,
|
|
1150
|
-
isStatement,
|
|
1168
|
+
isStatement: isStatement$1,
|
|
1151
1169
|
isVariableStatement: isVariableStatement$1,
|
|
1152
1170
|
isBlock,
|
|
1153
1171
|
isIfStatement,
|
|
@@ -1309,7 +1327,7 @@ class ScopedSourceFileStatementAnalyzer {
|
|
|
1309
1327
|
/* none */
|
|
1310
1328
|
},
|
|
1311
1329
|
(node, { statement, roleInParent }, visitChild) => {
|
|
1312
|
-
if (isStatement(node))
|
|
1330
|
+
if (isStatement$1(node))
|
|
1313
1331
|
statement = node;
|
|
1314
1332
|
if (roleInParent === 1 || roleInParent === 2) {
|
|
1315
1333
|
if (isIdentifierOrPropertyAccessExpression(node))
|
|
@@ -1569,7 +1587,7 @@ function isChildOf(node, parent) {
|
|
|
1569
1587
|
return true;
|
|
1570
1588
|
return isChildOf(node.parent, parent);
|
|
1571
1589
|
}
|
|
1572
|
-
const { isCallExpression: isCallExpression$1, isIdentifier: isIdentifier$
|
|
1590
|
+
const { isCallExpression: isCallExpression$1, isIdentifier: isIdentifier$2, isStringLiteral: isStringLiteral$6, isVariableStatement, forEachChild: forEachChild$1 } = c;
|
|
1573
1591
|
var FindComponentConstructorType = /* @__PURE__ */ ((FindComponentConstructorType2) => {
|
|
1574
1592
|
FindComponentConstructorType2["makeJayComponent"] = "makeJayComponent";
|
|
1575
1593
|
FindComponentConstructorType2["makeJayTsxComponent"] = "makeJayTsxComponent";
|
|
@@ -1584,7 +1602,7 @@ function findComponentConstructorCalls(findType, bindingResolver, node) {
|
|
|
1584
1602
|
declaration.initializer.expression
|
|
1585
1603
|
);
|
|
1586
1604
|
const flattened = flattenVariable(explainedInitializer);
|
|
1587
|
-
if (flattened.path.length === 1 && flattened.path[0] === findType && flattened.root && isImportModuleVariableRoot(flattened.root) && isStringLiteral$
|
|
1605
|
+
if (flattened.path.length === 1 && flattened.path[0] === findType && flattened.root && isImportModuleVariableRoot(flattened.root) && isStringLiteral$6(flattened.root.module) && flattened.root.module.text === JAY_COMPONENT) {
|
|
1588
1606
|
let render = findType === "makeJayComponent" ? declaration.initializer.arguments[0] : void 0;
|
|
1589
1607
|
let comp = findType === "makeJayComponent" ? declaration.initializer.arguments[1] : declaration.initializer.arguments[0];
|
|
1590
1608
|
let foundConstructor = {
|
|
@@ -1666,14 +1684,14 @@ export ${_}`
|
|
|
1666
1684
|
);
|
|
1667
1685
|
}
|
|
1668
1686
|
}
|
|
1669
|
-
const { isCallExpression, isIdentifier, isStringLiteral: isStringLiteral$
|
|
1687
|
+
const { isCallExpression, isIdentifier: isIdentifier$1, isStringLiteral: isStringLiteral$5, forEachChild } = c;
|
|
1670
1688
|
function findExec$(bindingResolver, sourceFile) {
|
|
1671
1689
|
const foundExec$ = [];
|
|
1672
1690
|
function visit(node) {
|
|
1673
|
-
if (isCallExpression(node) && isIdentifier(node.expression)) {
|
|
1691
|
+
if (isCallExpression(node) && isIdentifier$1(node.expression)) {
|
|
1674
1692
|
const functionVariable = bindingResolver.explain(node.expression);
|
|
1675
1693
|
const accessChain = flattenVariable(functionVariable);
|
|
1676
|
-
if (accessChain.path.length === 1 && accessChain.path[0] === "exec$" && isImportModuleVariableRoot(accessChain.root) && isStringLiteral$
|
|
1694
|
+
if (accessChain.path.length === 1 && accessChain.path[0] === "exec$" && isImportModuleVariableRoot(accessChain.root) && isStringLiteral$5(accessChain.root.module) && accessChain.root.module.text === "@jay-framework/secure")
|
|
1677
1695
|
foundExec$.push(node);
|
|
1678
1696
|
}
|
|
1679
1697
|
forEachChild(node, visit);
|
|
@@ -1681,7 +1699,7 @@ function findExec$(bindingResolver, sourceFile) {
|
|
|
1681
1699
|
forEachChild(sourceFile, visit);
|
|
1682
1700
|
return foundExec$;
|
|
1683
1701
|
}
|
|
1684
|
-
const { transform: transform$2, isArrowFunction, isExpression, visitNode } = c;
|
|
1702
|
+
const { transform: transform$2, isArrowFunction, isExpression, visitNode: visitNode$1 } = c;
|
|
1685
1703
|
function analyzeGlobalExec$(context, analyzer, functionRepositoryBuilder, foundExec$) {
|
|
1686
1704
|
const scopedAnalyzer = analyzer.analyzeForScope(foundExec$);
|
|
1687
1705
|
let foundUnsafeExpression = false;
|
|
@@ -1690,12 +1708,12 @@ function analyzeGlobalExec$(context, analyzer, functionRepositoryBuilder, foundE
|
|
|
1690
1708
|
const matchedPattern = scopedAnalyzer.getExpressionStatus(node);
|
|
1691
1709
|
foundUnsafeExpression = foundUnsafeExpression || !matchedPattern || !matchedPattern.subExpressionsMatching;
|
|
1692
1710
|
} else {
|
|
1693
|
-
node.getChildren().forEach((child) => visitNode(child, visitor));
|
|
1711
|
+
node.getChildren().forEach((child) => visitNode$1(child, visitor));
|
|
1694
1712
|
}
|
|
1695
1713
|
return node;
|
|
1696
1714
|
};
|
|
1697
1715
|
if (isArrowFunction(foundExec$.arguments[0]))
|
|
1698
|
-
visitNode(foundExec$.arguments[0].body, visitor);
|
|
1716
|
+
visitNode$1(foundExec$.arguments[0].body, visitor);
|
|
1699
1717
|
if (foundUnsafeExpression)
|
|
1700
1718
|
return { foundExec$, wasTransformed: false };
|
|
1701
1719
|
else {
|
|
@@ -1718,7 +1736,7 @@ function transformedGlobalExec$toReplaceMap(transformedGlobalExec$s) {
|
|
|
1718
1736
|
});
|
|
1719
1737
|
return map;
|
|
1720
1738
|
}
|
|
1721
|
-
const { SyntaxKind, transform: transform$1, isStringLiteral: isStringLiteral$
|
|
1739
|
+
const { SyntaxKind, transform: transform$1, isStringLiteral: isStringLiteral$4, isInterfaceDeclaration, isImportDeclaration: isImportDeclaration$2 } = c;
|
|
1722
1740
|
function generateComponentConstructorCalls(context, componentConstructorCalls, hasFunctionRepository) {
|
|
1723
1741
|
let optionsParam = hasFunctionRepository ? ", { funcRepository }" : "";
|
|
1724
1742
|
let transformedConstructors = componentConstructorCalls.map(({ name, render }) => {
|
|
@@ -1741,7 +1759,7 @@ function getRenderImportSpecifier(node) {
|
|
|
1741
1759
|
}
|
|
1742
1760
|
}
|
|
1743
1761
|
function transformImport(node, importerMode, context, hasFunctionRepository) {
|
|
1744
|
-
if (isStringLiteral$
|
|
1762
|
+
if (isStringLiteral$4(node.moduleSpecifier)) {
|
|
1745
1763
|
if (findMakeJayComponentImport(MAKE_JAY_COMPONENT, node)) {
|
|
1746
1764
|
const code = hasFunctionRepository ? `import { makeJayComponentBridge, FunctionsRepository } from '@jay-framework/secure';` : `import { makeJayComponentBridge } from '@jay-framework/secure';`;
|
|
1747
1765
|
return codeToAst(code, context)[0];
|
|
@@ -1839,9 +1857,9 @@ function transformComponentBridge(importerMode, patterns = [], globalFunctionRep
|
|
|
1839
1857
|
globalFunctionRepository
|
|
1840
1858
|
});
|
|
1841
1859
|
}
|
|
1842
|
-
const { isStringLiteral: isStringLiteral$
|
|
1860
|
+
const { isStringLiteral: isStringLiteral$3 } = c;
|
|
1843
1861
|
function transformImportModeFileExtension(node, factory, importerMode) {
|
|
1844
|
-
if (!isStringLiteral$
|
|
1862
|
+
if (!isStringLiteral$3(node.moduleSpecifier))
|
|
1845
1863
|
return void 0;
|
|
1846
1864
|
const originalTarget = node.moduleSpecifier.text;
|
|
1847
1865
|
if (!isRelativeImport(originalTarget))
|
|
@@ -1882,9 +1900,9 @@ function transformComponentImports(needsHandler$, needsFunc$, needsFuncGlobal$,
|
|
|
1882
1900
|
} else
|
|
1883
1901
|
return transformedSourceFile;
|
|
1884
1902
|
}
|
|
1885
|
-
const { visitEachChild, transform, isStringLiteral: isStringLiteral$
|
|
1903
|
+
const { visitEachChild, transform, isStringLiteral: isStringLiteral$2, isImportDeclaration } = c;
|
|
1886
1904
|
function isCssImport(node) {
|
|
1887
|
-
return isStringLiteral$
|
|
1905
|
+
return isStringLiteral$2(node.moduleSpecifier) && node.moduleSpecifier.text.endsWith(".css");
|
|
1888
1906
|
}
|
|
1889
1907
|
function mkComponentTransformer(sftContext) {
|
|
1890
1908
|
const { patterns, globalFunctionRepository, context, factory, sourceFile } = sftContext;
|
|
@@ -1974,10 +1992,10 @@ function generateImportsFileFromJayFile(jayFile) {
|
|
|
1974
1992
|
function fromImportModules(modules) {
|
|
1975
1993
|
return modules.filter(isRelativeImport).map((module) => `import '${module}${JAY_QUERY_WORKER_TRUSTED}'`).join("\n");
|
|
1976
1994
|
}
|
|
1977
|
-
const { isStringLiteral } = c;
|
|
1995
|
+
const { isStringLiteral: isStringLiteral$1 } = c;
|
|
1978
1996
|
function parseImportLinks(sourceFile) {
|
|
1979
1997
|
const importDeclarations = extractImportDeclarations(sourceFile).filter(
|
|
1980
|
-
(importDeclaration) => isStringLiteral(importDeclaration.moduleSpecifier)
|
|
1998
|
+
(importDeclaration) => isStringLiteral$1(importDeclaration.moduleSpecifier)
|
|
1981
1999
|
);
|
|
1982
2000
|
const importLinks = importDeclarations.map((importDeclaration) => {
|
|
1983
2001
|
const module = importDeclaration.moduleSpecifier.text;
|
|
@@ -2016,24 +2034,140 @@ function parseGenericTypescriptFile(filePath, code) {
|
|
|
2016
2034
|
[]
|
|
2017
2035
|
);
|
|
2018
2036
|
}
|
|
2037
|
+
const { isIdentifier, isStatement, visitNode } = c;
|
|
2038
|
+
class SourceFileStatementDependencies {
|
|
2039
|
+
constructor(sourceFile, bindingResolver) {
|
|
2040
|
+
__publicField(this, "statementDependencies", /* @__PURE__ */ new Map());
|
|
2041
|
+
let parents = [];
|
|
2042
|
+
let id = 0;
|
|
2043
|
+
const visitor = (node) => {
|
|
2044
|
+
if (isStatement(node)) {
|
|
2045
|
+
const statementDependencies = {
|
|
2046
|
+
statement: node,
|
|
2047
|
+
parent: parents.at(-1)?.statement,
|
|
2048
|
+
isDependencyFor: /* @__PURE__ */ new Set(),
|
|
2049
|
+
dependsOn: /* @__PURE__ */ new Set(),
|
|
2050
|
+
id: id++
|
|
2051
|
+
};
|
|
2052
|
+
this.statementDependencies.set(node, statementDependencies);
|
|
2053
|
+
parents.push(statementDependencies);
|
|
2054
|
+
}
|
|
2055
|
+
if (isIdentifier(node)) {
|
|
2056
|
+
let variable = bindingResolver.explain(node);
|
|
2057
|
+
let thisStatementDependencies = parents.at(-1);
|
|
2058
|
+
if (variable.definingStatement && variable.definingStatement !== thisStatementDependencies.statement) {
|
|
2059
|
+
let dependsOnStatementDependencies = this.statementDependencies.get(
|
|
2060
|
+
variable.definingStatement
|
|
2061
|
+
);
|
|
2062
|
+
thisStatementDependencies.dependsOn.add(dependsOnStatementDependencies);
|
|
2063
|
+
dependsOnStatementDependencies.isDependencyFor.add(thisStatementDependencies);
|
|
2064
|
+
}
|
|
2065
|
+
}
|
|
2066
|
+
node.getChildren().forEach((child) => visitNode(child, visitor));
|
|
2067
|
+
if (isStatement(node))
|
|
2068
|
+
parents.pop();
|
|
2069
|
+
return node;
|
|
2070
|
+
};
|
|
2071
|
+
visitNode(sourceFile, visitor);
|
|
2072
|
+
}
|
|
2073
|
+
getDependsOn(statement) {
|
|
2074
|
+
return this.statementDependencies.get(statement).dependsOn;
|
|
2075
|
+
}
|
|
2076
|
+
getIsDependencyFor(statement) {
|
|
2077
|
+
return this.statementDependencies.get(statement).isDependencyFor;
|
|
2078
|
+
}
|
|
2079
|
+
getAllStatements() {
|
|
2080
|
+
return this.statementDependencies.values();
|
|
2081
|
+
}
|
|
2082
|
+
getStatementDependencies(statement) {
|
|
2083
|
+
return this.statementDependencies.get(statement);
|
|
2084
|
+
}
|
|
2085
|
+
}
|
|
2086
|
+
const { isStringLiteral } = c;
|
|
2087
|
+
function areFlattenedAccessChainsEqual(chain1, chain2) {
|
|
2088
|
+
if (chain1.path.length !== chain2.path.length) {
|
|
2089
|
+
return false;
|
|
2090
|
+
}
|
|
2091
|
+
const pathsEqual = chain1.path.every((value, index) => value === chain2.path[index]);
|
|
2092
|
+
if (!pathsEqual) {
|
|
2093
|
+
return false;
|
|
2094
|
+
}
|
|
2095
|
+
return areVariableRootsEqual(chain1.root, chain2.root);
|
|
2096
|
+
}
|
|
2097
|
+
function areVariableRootsEqual(root1, root2) {
|
|
2098
|
+
if (!root1 && !root2) {
|
|
2099
|
+
return true;
|
|
2100
|
+
}
|
|
2101
|
+
if (!root1 || !root2) {
|
|
2102
|
+
return false;
|
|
2103
|
+
}
|
|
2104
|
+
if (root1.kind !== root2.kind) {
|
|
2105
|
+
return false;
|
|
2106
|
+
}
|
|
2107
|
+
switch (root1.kind) {
|
|
2108
|
+
case VariableRootType.ImportModule:
|
|
2109
|
+
if (isImportModuleVariableRoot(root1) && isImportModuleVariableRoot(root2)) {
|
|
2110
|
+
const module1 = isStringLiteral(root1.module) ? root1.module.text : String(root1.module);
|
|
2111
|
+
const module2 = isStringLiteral(root2.module) ? root2.module.text : String(root2.module);
|
|
2112
|
+
return module1 === module2 && root1.importType === root2.importType;
|
|
2113
|
+
}
|
|
2114
|
+
return false;
|
|
2115
|
+
case VariableRootType.FunctionParameter:
|
|
2116
|
+
case VariableRootType.FunctionDefinition:
|
|
2117
|
+
case VariableRootType.Literal:
|
|
2118
|
+
case VariableRootType.FunctionCall:
|
|
2119
|
+
return true;
|
|
2120
|
+
case VariableRootType.Global:
|
|
2121
|
+
case VariableRootType.Other:
|
|
2122
|
+
return true;
|
|
2123
|
+
default:
|
|
2124
|
+
return false;
|
|
2125
|
+
}
|
|
2126
|
+
}
|
|
2019
2127
|
function generateElementFile(jayFile, importerMode, generateTarget = GenerateTarget.jay) {
|
|
2020
2128
|
return generateTarget === GenerateTarget.jay ? generateElementFile$1(jayFile, importerMode) : generateElementFileReactTarget(jayFile, importerMode);
|
|
2021
2129
|
}
|
|
2022
2130
|
export {
|
|
2023
2131
|
FunctionRepositoryBuilder,
|
|
2132
|
+
ImportType,
|
|
2133
|
+
LetOrConst,
|
|
2134
|
+
NameBindingResolver,
|
|
2135
|
+
SourceFileBindingResolver,
|
|
2136
|
+
SourceFileStatementDependencies,
|
|
2137
|
+
UNKNOWN_VARIABLE,
|
|
2138
|
+
VariableRootType,
|
|
2139
|
+
areFlattenedAccessChainsEqual,
|
|
2024
2140
|
compileFunctionSplitPatternsBlock,
|
|
2025
2141
|
createTsSourceFileFromSource,
|
|
2026
2142
|
extractImportDeclarations,
|
|
2027
2143
|
extractImportedModules,
|
|
2144
|
+
flattenVariable,
|
|
2028
2145
|
generateElementDefinitionFile,
|
|
2029
2146
|
generateElementFile,
|
|
2030
2147
|
generateImportsFileFromJayFile,
|
|
2031
2148
|
generateImportsFileFromTsSource,
|
|
2032
2149
|
getImportName,
|
|
2033
2150
|
getImportSpecifiers,
|
|
2151
|
+
isFunctionCallVariableRoot,
|
|
2152
|
+
isFunctionVariableRoot,
|
|
2153
|
+
isGlobalVariableRoot,
|
|
2154
|
+
isImportModuleVariableRoot,
|
|
2155
|
+
isLiteralVariableRoot,
|
|
2156
|
+
isOtherVariableRoot,
|
|
2157
|
+
isParamVariableRoot,
|
|
2034
2158
|
isRelativeImport,
|
|
2159
|
+
mkFunctionCallVariableRoot,
|
|
2160
|
+
mkFunctionVariableRoot,
|
|
2161
|
+
mkGlobalVariableRoot,
|
|
2162
|
+
mkImportModuleVariableRoot,
|
|
2163
|
+
mkLiteralVariableRoot,
|
|
2164
|
+
mkOtherVariableRoot,
|
|
2165
|
+
mkParameterVariableRoot,
|
|
2166
|
+
mkTransformer,
|
|
2167
|
+
mkVariable,
|
|
2035
2168
|
parseGenericTypescriptFile,
|
|
2036
2169
|
transformComponent,
|
|
2037
2170
|
transformComponentBridge,
|
|
2038
|
-
transformComponentImports
|
|
2171
|
+
transformComponentImports,
|
|
2172
|
+
tsBindingNameToVariable
|
|
2039
2173
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jay-framework/compiler",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -25,12 +25,12 @@
|
|
|
25
25
|
},
|
|
26
26
|
"author": "",
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@jay-framework/compiler-analyze-exported-types": "^0.
|
|
29
|
-
"@jay-framework/compiler-jay-html": "^0.
|
|
30
|
-
"@jay-framework/compiler-shared": "^0.
|
|
31
|
-
"@jay-framework/component": "^0.
|
|
32
|
-
"@jay-framework/runtime": "^0.
|
|
33
|
-
"@jay-framework/secure": "^0.
|
|
28
|
+
"@jay-framework/compiler-analyze-exported-types": "^0.10.0",
|
|
29
|
+
"@jay-framework/compiler-jay-html": "^0.10.0",
|
|
30
|
+
"@jay-framework/compiler-shared": "^0.10.0",
|
|
31
|
+
"@jay-framework/component": "^0.10.0",
|
|
32
|
+
"@jay-framework/runtime": "^0.10.0",
|
|
33
|
+
"@jay-framework/secure": "^0.10.0",
|
|
34
34
|
"@types/js-yaml": "^4.0.9",
|
|
35
35
|
"change-case": "^4.1.2",
|
|
36
36
|
"js-yaml": "^4.1.0",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@caiogondim/strip-margin": "^1.0.0",
|
|
44
|
-
"@jay-framework/dev-environment": "^0.
|
|
44
|
+
"@jay-framework/dev-environment": "^0.10.0",
|
|
45
45
|
"@testing-library/jest-dom": "^6.2.0",
|
|
46
46
|
"@types/js-beautify": "^1",
|
|
47
47
|
"@types/node": "^20.11.5",
|