@geastack/geatsc-plugin-gea 0.1.6 → 0.1.8
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/analyze-alpha.d.ts +5 -0
- package/dist/analyze-alpha.js +76 -0
- package/dist/analyze-classes.d.ts +1 -0
- package/dist/analyze-classes.js +157 -0
- package/dist/analyze-css-ranges.d.ts +4 -0
- package/dist/analyze-css-ranges.js +115 -0
- package/dist/analyze-css.d.ts +8 -0
- package/dist/analyze-css.js +205 -0
- package/dist/analyze-literals.d.ts +2 -0
- package/dist/analyze-literals.js +267 -0
- package/dist/analyze-nodes.d.ts +4 -0
- package/dist/analyze-nodes.js +68 -0
- package/dist/analyze-renderer.d.ts +23 -0
- package/dist/analyze-renderer.js +403 -0
- package/dist/analyze.js +96 -16
- package/dist/cpp-mounted-lowering.js +24 -6
- package/dist/cpp-template-renderer.js +21 -7
- package/dist/host-shims.js +17 -0
- package/dist/utils.d.ts +1 -0
- package/dist/utils.js +43 -16
- package/package.json +1 -1
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
// A closed-source, finite literal proof for style values. It deliberately uses
|
|
4
|
+
// all writes to a property name, even across unrelated objects: ambiguity keeps
|
|
5
|
+
// storage. Types alone never certify colour values. Mutable palettes must not
|
|
6
|
+
// escape their declaration/import/indexed-read paths.
|
|
7
|
+
export function sourceLiteralResolver(files, initiallyOpaque) {
|
|
8
|
+
const sources = new Map([...files].filter(([file]) => !/\.css$/i.test(file)).map(([file, text]) => [file, ts.createSourceFile(file, text, ts.ScriptTarget.Latest, true, /\.[jt]sx$/i.test(file) ? ts.ScriptKind.TSX : ts.ScriptKind.TS)]));
|
|
9
|
+
const variables = new Map();
|
|
10
|
+
const properties = new Map();
|
|
11
|
+
const arrays = new Set(), escapedArrays = new Set();
|
|
12
|
+
const calledMembers = new Set();
|
|
13
|
+
let opaque = initiallyOpaque;
|
|
14
|
+
const nameOf = (node) => node && (ts.isIdentifier(node) || ts.isStringLiteralLike(node) || ts.isNumericLiteral(node)) ? node.text : undefined;
|
|
15
|
+
const member = (node) => ts.isPropertyAccessExpression(node) ? node.name.text
|
|
16
|
+
: ts.isElementAccessExpression(node) && node.argumentExpression && ts.isStringLiteralLike(node.argumentExpression) ? node.argumentExpression.text : undefined;
|
|
17
|
+
const addProperty = (name, value) => {
|
|
18
|
+
if (name === undefined) {
|
|
19
|
+
opaque = true;
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
const values = properties.get(name) ?? [];
|
|
23
|
+
values.push(value);
|
|
24
|
+
properties.set(name, values);
|
|
25
|
+
};
|
|
26
|
+
const collect = (node) => {
|
|
27
|
+
if (ts.isCallExpression(node)) {
|
|
28
|
+
const name = member(node.expression);
|
|
29
|
+
if (name !== undefined)
|
|
30
|
+
calledMembers.add(name);
|
|
31
|
+
}
|
|
32
|
+
if (ts.isVariableDeclaration(node) && ts.isIdentifier(node.name)) {
|
|
33
|
+
const name = node.name.text;
|
|
34
|
+
const immutable = ts.isVariableDeclarationList(node.parent) && (node.parent.flags & ts.NodeFlags.Const);
|
|
35
|
+
variables.set(name, variables.has(name) || !immutable ? undefined : node.initializer);
|
|
36
|
+
if (node.initializer && ts.isArrayLiteralExpression(node.initializer))
|
|
37
|
+
arrays.add(name);
|
|
38
|
+
}
|
|
39
|
+
if (ts.isParameter(node) && ts.isIdentifier(node.name))
|
|
40
|
+
variables.set(node.name.text, undefined);
|
|
41
|
+
if (ts.isPropertyDeclaration(node) || ts.isPropertyAssignment(node))
|
|
42
|
+
addProperty(nameOf(node.name), node.initializer);
|
|
43
|
+
if (ts.isGetAccessorDeclaration(node)) {
|
|
44
|
+
const returns = [];
|
|
45
|
+
const visit = (child) => { if (ts.isReturnStatement(child))
|
|
46
|
+
returns.push(child.expression); ts.forEachChild(child, visit); };
|
|
47
|
+
if (node.body)
|
|
48
|
+
visit(node.body);
|
|
49
|
+
for (const value of returns.length ? returns : [undefined])
|
|
50
|
+
addProperty(nameOf(node.name), value);
|
|
51
|
+
}
|
|
52
|
+
ts.forEachChild(node, collect);
|
|
53
|
+
};
|
|
54
|
+
for (const source of sources.values()) {
|
|
55
|
+
if (source.parseDiagnostics?.length)
|
|
56
|
+
opaque = true;
|
|
57
|
+
collect(source);
|
|
58
|
+
}
|
|
59
|
+
let checker;
|
|
60
|
+
const typeChecker = () => {
|
|
61
|
+
if (!checker) {
|
|
62
|
+
const host = {
|
|
63
|
+
getSourceFile: file => sources.get(path.resolve(file)), getDefaultLibFileName: () => '', writeFile: () => { },
|
|
64
|
+
getCurrentDirectory: () => '/', getDirectories: () => [], getCanonicalFileName: file => file,
|
|
65
|
+
useCaseSensitiveFileNames: () => true, getNewLine: () => '\n',
|
|
66
|
+
fileExists: file => sources.has(path.resolve(file)), readFile: file => files.get(path.resolve(file)),
|
|
67
|
+
resolveModuleNames: (names, from) => names.map(name => {
|
|
68
|
+
if (!name.startsWith('.'))
|
|
69
|
+
return undefined;
|
|
70
|
+
const base = path.resolve(path.dirname(from), name.replace(/\.js$/, ''));
|
|
71
|
+
const resolved = [base, ...['.ts', '.tsx', '.js', '.jsx'].map(ext => base + ext), ...['index.ts', 'index.tsx'].map(file => path.join(base, file))].find(file => sources.has(file));
|
|
72
|
+
return resolved ? { resolvedFileName: resolved, extension: /\.tsx$/.test(resolved) ? ts.Extension.Tsx : ts.Extension.Ts } : undefined;
|
|
73
|
+
}),
|
|
74
|
+
};
|
|
75
|
+
checker = ts.createProgram([...sources.keys()], { noLib: true, target: ts.ScriptTarget.ESNext, module: ts.ModuleKind.ESNext, moduleResolution: ts.ModuleResolutionKind.Bundler, jsx: ts.JsxEmit.Preserve, strict: true, allowJs: true }, host).getTypeChecker();
|
|
76
|
+
}
|
|
77
|
+
return checker;
|
|
78
|
+
};
|
|
79
|
+
const numeric = (node) => !!(typeChecker().getTypeAtLocation(node).flags & ts.TypeFlags.NumberLike);
|
|
80
|
+
const declarationOf = (node) => {
|
|
81
|
+
let symbol = ts.isShorthandPropertyAssignment(node.parent) ? typeChecker().getShorthandAssignmentValueSymbol(node.parent) : typeChecker().getSymbolAtLocation(node);
|
|
82
|
+
if (symbol && (symbol.flags & ts.SymbolFlags.Alias))
|
|
83
|
+
symbol = typeChecker().getAliasedSymbol(symbol);
|
|
84
|
+
const declaration = symbol?.valueDeclaration;
|
|
85
|
+
return declaration && ts.isVariableDeclaration(declaration) && ts.isIdentifier(declaration.name) &&
|
|
86
|
+
sources.has(declaration.getSourceFile().fileName) && ts.isVariableDeclarationList(declaration.parent) &&
|
|
87
|
+
(declaration.parent.flags & ts.NodeFlags.Const) ? declaration : undefined;
|
|
88
|
+
};
|
|
89
|
+
const localReceiver = (node, seen = new Set()) => {
|
|
90
|
+
if (seen.has(node))
|
|
91
|
+
return false;
|
|
92
|
+
seen.add(node);
|
|
93
|
+
if (ts.isParenthesizedExpression(node))
|
|
94
|
+
return localReceiver(node.expression, seen);
|
|
95
|
+
if (node.kind === ts.SyntaxKind.ThisKeyword)
|
|
96
|
+
return true;
|
|
97
|
+
if (ts.isObjectLiteralExpression(node))
|
|
98
|
+
return true;
|
|
99
|
+
if (ts.isIdentifier(node)) {
|
|
100
|
+
const declaration = declarationOf(node);
|
|
101
|
+
return !!declaration?.initializer && localReceiver(declaration.initializer, seen);
|
|
102
|
+
}
|
|
103
|
+
if (ts.isNewExpression(node)) {
|
|
104
|
+
let symbol = typeChecker().getSymbolAtLocation(node.expression);
|
|
105
|
+
if (symbol && (symbol.flags & ts.SymbolFlags.Alias))
|
|
106
|
+
symbol = typeChecker().getAliasedSymbol(symbol);
|
|
107
|
+
const declaration = symbol?.valueDeclaration;
|
|
108
|
+
if (!declaration || !ts.isClassDeclaration(declaration) || !sources.has(declaration.getSourceFile().fileName))
|
|
109
|
+
return false;
|
|
110
|
+
// A constructor returning another object breaks the local-instance proof.
|
|
111
|
+
let returnsObject = false;
|
|
112
|
+
const visit = (child) => { if (ts.isReturnStatement(child) && child.expression)
|
|
113
|
+
returnsObject = true; ts.forEachChild(child, visit); };
|
|
114
|
+
for (const member of declaration.members)
|
|
115
|
+
if (ts.isConstructorDeclaration(member))
|
|
116
|
+
visit(member);
|
|
117
|
+
return !returnsObject;
|
|
118
|
+
}
|
|
119
|
+
return false;
|
|
120
|
+
};
|
|
121
|
+
const writes = (node) => {
|
|
122
|
+
// Follow receiver references, not just call argument shapes: hiding an
|
|
123
|
+
// instance inside an array/object before passing it out is still an escape.
|
|
124
|
+
if ((ts.isIdentifier(node) && localReceiver(node)) || node.kind === ts.SyntaxKind.ThisKeyword) {
|
|
125
|
+
const parent = node.parent;
|
|
126
|
+
const memberRead = (ts.isPropertyAccessExpression(parent) || ts.isElementAccessExpression(parent)) && parent.expression === node;
|
|
127
|
+
const declaration = ts.isVariableDeclaration(parent) && parent.name === node;
|
|
128
|
+
const immutableAlias = ts.isVariableDeclaration(parent) && parent.initializer === node && ts.isVariableDeclarationList(parent.parent) && (parent.parent.flags & ts.NodeFlags.Const);
|
|
129
|
+
const imported = ts.isImportSpecifier(parent) || ts.isExportSpecifier(parent);
|
|
130
|
+
if (!memberRead && !declaration && !immutableAlias && !imported)
|
|
131
|
+
opaque = true;
|
|
132
|
+
}
|
|
133
|
+
// Passing or publishing a mutable local receiver lets opaque code replace
|
|
134
|
+
// a field without a visible assignment. Keep dynamic-value storage rather
|
|
135
|
+
// than relying on the apparent class type at the later read.
|
|
136
|
+
if ((ts.isCallExpression(node) || ts.isNewExpression(node)) && node.arguments?.some(argument => localReceiver(argument)))
|
|
137
|
+
opaque = true;
|
|
138
|
+
if (ts.isReturnStatement(node) && node.expression && localReceiver(node.expression))
|
|
139
|
+
opaque = true;
|
|
140
|
+
if (ts.isPropertyAccessExpression(node) && /^(?:call|apply|bind)$/.test(node.name.text))
|
|
141
|
+
opaque = true;
|
|
142
|
+
if (ts.isCallExpression(node) && (ts.isPropertyAccessExpression(node.expression) || ts.isElementAccessExpression(node.expression)) && localReceiver(node.expression.expression)) {
|
|
143
|
+
const declaration = typeChecker().getResolvedSignature(node)?.declaration;
|
|
144
|
+
// An opaque method receives the object implicitly through `this`.
|
|
145
|
+
if (!declaration || !sources.has(declaration.getSourceFile().fileName) ||
|
|
146
|
+
!(ts.isMethodDeclaration(declaration) || ts.isFunctionDeclaration(declaration) || ts.isFunctionExpression(declaration) || ts.isArrowFunction(declaration)))
|
|
147
|
+
opaque = true;
|
|
148
|
+
}
|
|
149
|
+
if (ts.isBinaryExpression(node) && node.operatorToken.kind === ts.SyntaxKind.EqualsToken &&
|
|
150
|
+
(ts.isPropertyAccessExpression(node.left) || ts.isElementAccessExpression(node.left)) && localReceiver(node.right))
|
|
151
|
+
opaque = true;
|
|
152
|
+
if (ts.isAsExpression(node) || ts.isTypeAssertionExpression(node) || ts.isNonNullExpression(node) ||
|
|
153
|
+
ts.isSpreadAssignment(node) || ts.isSpreadElement(node))
|
|
154
|
+
opaque = true;
|
|
155
|
+
if (ts.isIdentifier(node) && /^(?:Object|Reflect|Proxy|eval|Function)$/.test(node.text))
|
|
156
|
+
opaque = true;
|
|
157
|
+
if (ts.isBinaryExpression(node) && node.operatorToken.kind >= ts.SyntaxKind.FirstAssignment && node.operatorToken.kind <= ts.SyntaxKind.LastAssignment) {
|
|
158
|
+
const lhs = node.left;
|
|
159
|
+
if (ts.isPropertyAccessExpression(lhs) || ts.isElementAccessExpression(lhs)) {
|
|
160
|
+
const name = member(lhs);
|
|
161
|
+
if (name !== undefined && calledMembers.has(name))
|
|
162
|
+
opaque = true;
|
|
163
|
+
if (name !== undefined)
|
|
164
|
+
addProperty(name, node.operatorToken.kind === ts.SyntaxKind.EqualsToken ? node.right : undefined);
|
|
165
|
+
else if (!ts.isElementAccessExpression(lhs) || !lhs.argumentExpression || !numeric(lhs.argumentExpression))
|
|
166
|
+
opaque = true;
|
|
167
|
+
}
|
|
168
|
+
else if (ts.isIdentifier(lhs))
|
|
169
|
+
variables.set(lhs.text, undefined);
|
|
170
|
+
else
|
|
171
|
+
opaque = true;
|
|
172
|
+
}
|
|
173
|
+
if (ts.isPrefixUnaryExpression(node) || ts.isPostfixUnaryExpression(node) || ts.isDeleteExpression(node)) {
|
|
174
|
+
const operand = ts.isDeleteExpression(node) ? node.expression : node.operand;
|
|
175
|
+
if (ts.isDeleteExpression(node) || node.operator === ts.SyntaxKind.PlusPlusToken || node.operator === ts.SyntaxKind.MinusMinusToken) {
|
|
176
|
+
const name = member(operand);
|
|
177
|
+
if (name !== undefined)
|
|
178
|
+
addProperty(name, undefined);
|
|
179
|
+
else if (ts.isIdentifier(operand))
|
|
180
|
+
variables.set(operand.text, undefined);
|
|
181
|
+
else if (!ts.isElementAccessExpression(operand) || !operand.argumentExpression || !numeric(operand.argumentExpression))
|
|
182
|
+
opaque = true;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
const arrayDeclaration = ts.isIdentifier(node) ? declarationOf(node) : undefined;
|
|
186
|
+
if (arrayDeclaration && ts.isIdentifier(arrayDeclaration.name) && arrays.has(arrayDeclaration.name.text)) {
|
|
187
|
+
const arrayName = arrayDeclaration.name.text;
|
|
188
|
+
const parent = node.parent;
|
|
189
|
+
const declaration = ts.isVariableDeclaration(parent) && parent.name === node;
|
|
190
|
+
const imported = ts.isImportSpecifier(parent) || ts.isExportSpecifier(parent);
|
|
191
|
+
const indexed = ts.isElementAccessExpression(parent) && parent.expression === node && parent.argumentExpression && numeric(parent.argumentExpression);
|
|
192
|
+
const operation = parent.parent;
|
|
193
|
+
const mutated = indexed && ((ts.isBinaryExpression(operation) && operation.left === parent && operation.operatorToken.kind >= ts.SyntaxKind.FirstAssignment && operation.operatorToken.kind <= ts.SyntaxKind.LastAssignment) || ts.isDeleteExpression(operation) || ts.isPrefixUnaryExpression(operation) || ts.isPostfixUnaryExpression(operation));
|
|
194
|
+
if ((!declaration && !imported && !indexed) || mutated)
|
|
195
|
+
escapedArrays.add(arrayName);
|
|
196
|
+
}
|
|
197
|
+
ts.forEachChild(node, writes);
|
|
198
|
+
};
|
|
199
|
+
for (const source of sources.values())
|
|
200
|
+
writes(source);
|
|
201
|
+
const merge = (values) => {
|
|
202
|
+
if (values.some(value => value === undefined))
|
|
203
|
+
return undefined;
|
|
204
|
+
const result = [...new Set(values.flat())];
|
|
205
|
+
return result.length <= 64 ? result : undefined;
|
|
206
|
+
};
|
|
207
|
+
const resolve = (node, seen = new Set()) => {
|
|
208
|
+
if (!node || opaque)
|
|
209
|
+
return undefined;
|
|
210
|
+
if (ts.isParenthesizedExpression(node))
|
|
211
|
+
return resolve(node.expression, seen);
|
|
212
|
+
if (ts.isStringLiteralLike(node) || ts.isNumericLiteral(node))
|
|
213
|
+
return [node.text];
|
|
214
|
+
if (ts.isConditionalExpression(node))
|
|
215
|
+
return merge([resolve(node.whenTrue, new Set(seen)), resolve(node.whenFalse, new Set(seen))]);
|
|
216
|
+
if (ts.isIdentifier(node)) {
|
|
217
|
+
const declaration = declarationOf(node);
|
|
218
|
+
if (!declaration || !ts.isIdentifier(declaration.name))
|
|
219
|
+
return undefined;
|
|
220
|
+
const key = 'variable:' + declaration.name.text;
|
|
221
|
+
if (seen.has(key))
|
|
222
|
+
return undefined;
|
|
223
|
+
seen.add(key);
|
|
224
|
+
return resolve(variables.get(declaration.name.text), seen);
|
|
225
|
+
}
|
|
226
|
+
if (ts.isElementAccessExpression(node) && ts.isIdentifier(node.expression) && node.argumentExpression && numeric(node.argumentExpression)) {
|
|
227
|
+
const declaration = declarationOf(node.expression);
|
|
228
|
+
if (!declaration || !ts.isIdentifier(declaration.name))
|
|
229
|
+
return undefined;
|
|
230
|
+
const name = declaration.name.text, array = variables.get(name);
|
|
231
|
+
const key = 'array:' + name;
|
|
232
|
+
if (seen.has(key))
|
|
233
|
+
return undefined;
|
|
234
|
+
seen.add(key);
|
|
235
|
+
if (escapedArrays.has(name) || !array || !ts.isArrayLiteralExpression(array))
|
|
236
|
+
return undefined;
|
|
237
|
+
return merge(array.elements.map(item => ts.isExpression(item) ? resolve(item, new Set(seen)) : undefined));
|
|
238
|
+
}
|
|
239
|
+
const name = member(node);
|
|
240
|
+
if (name !== undefined) {
|
|
241
|
+
// A coincidentally equal property name on an opaque/any receiver is not
|
|
242
|
+
// a source proof. Require the receiver's declared local field/getter.
|
|
243
|
+
if (!(ts.isPropertyAccessExpression(node) || ts.isElementAccessExpression(node)) || !localReceiver(node.expression))
|
|
244
|
+
return undefined;
|
|
245
|
+
const at = ts.isPropertyAccessExpression(node) ? node.name : ts.isElementAccessExpression(node) ? node.argumentExpression : node;
|
|
246
|
+
const symbol = at && typeChecker().getSymbolAtLocation(at);
|
|
247
|
+
if (!symbol?.declarations?.some(declaration => sources.has(declaration.getSourceFile().fileName) &&
|
|
248
|
+
(ts.isPropertyDeclaration(declaration) || ts.isGetAccessorDeclaration(declaration) || ts.isPropertyAssignment(declaration))))
|
|
249
|
+
return undefined;
|
|
250
|
+
const key = 'property:' + name;
|
|
251
|
+
if (seen.has(key))
|
|
252
|
+
return undefined;
|
|
253
|
+
seen.add(key);
|
|
254
|
+
const values = properties.get(name);
|
|
255
|
+
return values?.length ? merge(values.map(value => resolve(value, new Set(seen)))) : undefined;
|
|
256
|
+
}
|
|
257
|
+
return undefined;
|
|
258
|
+
};
|
|
259
|
+
// addRendererFeatures has its own AST. Locate the corresponding expression
|
|
260
|
+
// in this graph so type queries use nodes owned by the proof's program.
|
|
261
|
+
const expressions = new Map();
|
|
262
|
+
const index = (node) => { if (ts.isExpression(node))
|
|
263
|
+
expressions.set(`${node.getSourceFile().fileName}:${node.pos}:${node.end}`, node); ts.forEachChild(node, index); };
|
|
264
|
+
for (const source of sources.values())
|
|
265
|
+
index(source);
|
|
266
|
+
return (node) => resolve(expressions.get(`${node.getSourceFile().fileName}:${node.pos}:${node.end}`));
|
|
267
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare const nodeAnalysisVersion = "node-analysis-v1";
|
|
2
|
+
export declare const nodeFeatures: readonly ["node-images", "node-inputs"];
|
|
3
|
+
export declare function addUnknownNodeFeatures(features: Set<string>): void;
|
|
4
|
+
export declare function addNodeFeatures(file: string, text: string, features: Set<string>): void;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
export const nodeAnalysisVersion = 'node-analysis-v1';
|
|
3
|
+
export const nodeFeatures = ['node-images', 'node-inputs'];
|
|
4
|
+
export function addUnknownNodeFeatures(features) {
|
|
5
|
+
for (const feature of nodeFeatures)
|
|
6
|
+
features.add(feature);
|
|
7
|
+
}
|
|
8
|
+
// Native node payloads are selected from the whole discovered source graph.
|
|
9
|
+
// CSS rendering features remain independent: a background image does not make
|
|
10
|
+
// an <img> node, and ordinary buttons do not need a native text-input keyboard.
|
|
11
|
+
export function addNodeFeatures(file, text, features) {
|
|
12
|
+
if (/\.css$/i.test(file))
|
|
13
|
+
return;
|
|
14
|
+
const source = ts.createSourceFile(file, text, ts.ScriptTarget.Latest, true, /\.[jt]sx$/i.test(file) ? ts.ScriptKind.TSX : ts.ScriptKind.TS);
|
|
15
|
+
const unknown = () => addUnknownNodeFeatures(features);
|
|
16
|
+
const name = (value) => {
|
|
17
|
+
if (/^(?:img|image)$/i.test(value) || /^(?:ImageElement|HTMLImageElement|createImage|loadImage)$/.test(value))
|
|
18
|
+
features.add('node-images');
|
|
19
|
+
if (/^(?:input|textarea|select|contenteditable)$/i.test(value) || /^(?:TextInput|InputElement|TextInputElement|HTMLInputElement|HTMLTextAreaElement|HTMLSelectElement|VirtualKeyboard|createInput|createTextInput)$/.test(value))
|
|
20
|
+
features.add('node-inputs');
|
|
21
|
+
};
|
|
22
|
+
const visit = (node) => {
|
|
23
|
+
if (ts.isIdentifier(node)) {
|
|
24
|
+
name(node.text);
|
|
25
|
+
// A destructured or bare factory can receive a tag outside this call site.
|
|
26
|
+
if (/^(?:createElement|createElementNS)$/.test(node.text) &&
|
|
27
|
+
!(ts.isPropertyAccessExpression(node.parent) && node.parent.name === node))
|
|
28
|
+
unknown();
|
|
29
|
+
if (/^__gea_/.test(node.text) && node.text !== '__gea_Display')
|
|
30
|
+
unknown();
|
|
31
|
+
}
|
|
32
|
+
if (ts.isStringLiteralLike(node)) {
|
|
33
|
+
name(node.text);
|
|
34
|
+
if (/^(?:createElement|createElementNS)$/.test(node.text) &&
|
|
35
|
+
!ts.isElementAccessExpression(node.parent))
|
|
36
|
+
unknown();
|
|
37
|
+
if (/<(?:img|image|input|textarea|select)\b/i.test(node.text))
|
|
38
|
+
unknown();
|
|
39
|
+
}
|
|
40
|
+
if (ts.isJsxOpeningElement(node) || ts.isJsxSelfClosingElement(node))
|
|
41
|
+
name(node.tagName.getText(source).split(':').at(-1));
|
|
42
|
+
if (ts.isImportDeclaration(node) && ts.isStringLiteral(node.moduleSpecifier) &&
|
|
43
|
+
/^(?:gea-embedded|@geastack\/(?:core|engine)|@geajs\/core)(?:\/|$)/.test(node.moduleSpecifier.text) &&
|
|
44
|
+
node.importClause && !node.importClause.isTypeOnly) {
|
|
45
|
+
const bindings = node.importClause.namedBindings;
|
|
46
|
+
if (node.importClause.name || !bindings || !ts.isNamedImports(bindings) ||
|
|
47
|
+
bindings.elements.some(item => !item.isTypeOnly && !/^(?:Component|Store|mount)$/.test((item.propertyName ?? item.name).text)))
|
|
48
|
+
unknown();
|
|
49
|
+
}
|
|
50
|
+
// Mutation/markup helpers can create descendants whose tags are not present
|
|
51
|
+
// as JSX. Known literal factories are covered by their tag strings above.
|
|
52
|
+
if (ts.isPropertyAccessExpression(node) || ts.isElementAccessExpression(node)) {
|
|
53
|
+
const member = ts.isPropertyAccessExpression(node) ? node.name.text : node.argumentExpression && ts.isStringLiteralLike(node.argumentExpression) ? node.argumentExpression.text : undefined;
|
|
54
|
+
if (member && /^(?:innerHTML|outerHTML|insertAdjacentHTML|parseFromString|createContextualFragment|write|writeln|tagName|setTagName)$/.test(member))
|
|
55
|
+
unknown();
|
|
56
|
+
if (member && /^(?:createElement|createElementNS)$/.test(member)) {
|
|
57
|
+
const call = node.parent;
|
|
58
|
+
const argument = ts.isCallExpression(call) && call.expression === node ? call.arguments[member === 'createElementNS' ? 1 : 0] : undefined;
|
|
59
|
+
if (!argument || !ts.isStringLiteralLike(argument))
|
|
60
|
+
unknown();
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
if (ts.isIdentifier(node) && /^(?:DOMParser|eval|Function)$/.test(node.text))
|
|
64
|
+
unknown();
|
|
65
|
+
ts.forEachChild(node, visit);
|
|
66
|
+
};
|
|
67
|
+
visit(source);
|
|
68
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
export declare const rendererAnalysisVersion = "renderer-analysis-v1";
|
|
3
|
+
export declare function addUnknownRendererFeatures(features: Set<string>): void;
|
|
4
|
+
export interface StyleUsageObserver {
|
|
5
|
+
selector?(css: string): void;
|
|
6
|
+
property(name: string | undefined, value: string | undefined, expression?: ts.Expression): void;
|
|
7
|
+
unknown(): void;
|
|
8
|
+
unknownRanges?(): void;
|
|
9
|
+
}
|
|
10
|
+
export declare function colorVariableAnalysis(): {
|
|
11
|
+
property(name: string | undefined, value: string | undefined): void;
|
|
12
|
+
unknown(): void;
|
|
13
|
+
isColor(value: string | undefined): boolean;
|
|
14
|
+
};
|
|
15
|
+
export declare function rendererVariableAnalysis(features: Set<string>): {
|
|
16
|
+
property: (name: string | undefined, value: string | undefined) => void;
|
|
17
|
+
unknown: () => void;
|
|
18
|
+
background(value: string): void;
|
|
19
|
+
finish(): void;
|
|
20
|
+
};
|
|
21
|
+
type RendererVariableAnalysis = ReturnType<typeof rendererVariableAnalysis>;
|
|
22
|
+
export declare function addRendererFeatures(file: string, text: string, features: Set<string>, observer?: StyleUsageObserver, variables?: RendererVariableAnalysis): void;
|
|
23
|
+
export {};
|