@geastack/geatsc-plugin-gea 0.1.11 → 0.1.12
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-literals.js +27 -0
- package/dist/analyze-renderer.js +6 -1
- package/dist/analyze.js +11 -5
- package/package.json +1 -1
package/dist/analyze-literals.js
CHANGED
|
@@ -294,6 +294,33 @@ export function sourceLiteralResolver(files, initiallyOpaque) {
|
|
|
294
294
|
if (!at || initiallyOpaque)
|
|
295
295
|
return false;
|
|
296
296
|
const parent = at.parent;
|
|
297
|
+
// A locally declared frame callback may also be named animate. Resolve
|
|
298
|
+
// its binding instead of confusing the name with Element.animate.
|
|
299
|
+
if (ts.isIdentifier(at)) {
|
|
300
|
+
let symbol = typeChecker().getSymbolAtLocation(at);
|
|
301
|
+
if (symbol && (symbol.flags & ts.SymbolFlags.Alias))
|
|
302
|
+
symbol = typeChecker().getAliasedSymbol(symbol);
|
|
303
|
+
const declarations = symbol?.declarations;
|
|
304
|
+
if (declarations?.length && declarations.every(declaration => sources.has(declaration.getSourceFile().fileName) && ts.isFunctionDeclaration(declaration) && !!declaration.body)) {
|
|
305
|
+
let reassigned = false;
|
|
306
|
+
const checkWrites = (child) => {
|
|
307
|
+
if (ts.isBinaryExpression(child) && child.operatorToken.kind >= ts.SyntaxKind.FirstAssignment &&
|
|
308
|
+
child.operatorToken.kind <= ts.SyntaxKind.LastAssignment) {
|
|
309
|
+
const checkTarget = (target) => {
|
|
310
|
+
if (ts.isIdentifier(target) && typeChecker().getSymbolAtLocation(target) === symbol)
|
|
311
|
+
reassigned = true;
|
|
312
|
+
ts.forEachChild(target, checkTarget);
|
|
313
|
+
};
|
|
314
|
+
checkTarget(child.left);
|
|
315
|
+
}
|
|
316
|
+
ts.forEachChild(child, checkWrites);
|
|
317
|
+
};
|
|
318
|
+
for (const source of sources.values())
|
|
319
|
+
checkWrites(source);
|
|
320
|
+
if (!reassigned)
|
|
321
|
+
return true;
|
|
322
|
+
}
|
|
323
|
+
}
|
|
297
324
|
if (ts.isMethodDeclaration(parent) && parent.name === at && parent.body)
|
|
298
325
|
return true;
|
|
299
326
|
const access = ts.isPropertyAccessExpression(at) || ts.isElementAccessExpression(at) ? at
|
package/dist/analyze-renderer.js
CHANGED
|
@@ -426,7 +426,12 @@ export function addRendererFeatures(file, text, features, observer, variables) {
|
|
|
426
426
|
for (const arg of node.arguments.slice(1))
|
|
427
427
|
styleObject(arg);
|
|
428
428
|
}
|
|
429
|
-
|
|
429
|
+
// String.replace is not CSSStyleSheet.replace. A literal receiver is
|
|
430
|
+
// a primitive string even when its replacement callback is dynamic.
|
|
431
|
+
const literalStringReplace = name === 'replace' &&
|
|
432
|
+
(ts.isPropertyAccessExpression(node.expression) || ts.isElementAccessExpression(node.expression)) &&
|
|
433
|
+
literal(node.expression.expression) !== undefined;
|
|
434
|
+
if (name === 'insertRule' || name === 'replaceSync' || (name === 'replace' && !literalStringReplace)) {
|
|
430
435
|
if (node.arguments[0])
|
|
431
436
|
styleObject(node.arguments[0]);
|
|
432
437
|
}
|
package/dist/analyze.js
CHANGED
|
@@ -157,6 +157,9 @@ function addBindingsForGeaEmbeddedImports(text, bindings) {
|
|
|
157
157
|
const hostGlobalCalls = [
|
|
158
158
|
[/(?<![.\w$])fetch\s*\(/, 'fetch'],
|
|
159
159
|
[/(?<![.\w$])new\s+WebSocket\s*\(/, 'websocket'],
|
|
160
|
+
[/(?<![.\w$])new\s+(?:window\.|globalThis\.)?RTCPeerConnection\s*\(/, 'rtc'],
|
|
161
|
+
[/(?<![.\w$])navigator\s*\.\s*mediaDevices\s*\.\s*getUserMedia\s*\(/, 'audio'],
|
|
162
|
+
[/(?<![.\w$])new\s+(?:window\.|globalThis\.)?AudioContext\s*\(/, 'audio'],
|
|
160
163
|
];
|
|
161
164
|
// A file that declares its own `fetch` (a class method, or a wrapper such as
|
|
162
165
|
// image-demo's runtime.ts) calls that one; its network use, if any, shows up
|
|
@@ -200,6 +203,11 @@ function discoverSourceFiles(entry) {
|
|
|
200
203
|
if (visited.has(resolved) || !fs.existsSync(resolved) || !fs.statSync(resolved).isFile())
|
|
201
204
|
return;
|
|
202
205
|
visited.add(resolved);
|
|
206
|
+
// Imported data is not executable source. Parsing a JPEG or JSON as TS
|
|
207
|
+
// manufactures syntax errors and falsely marks every renderer feature as
|
|
208
|
+
// reachable. Dynamic use of data as CSS is still observed at its call site.
|
|
209
|
+
if (/\.(?:json|png|jpe?g|gif|webp|bmp|ico|ttf|otf|woff2?|wav|mp3|ogg|mp4)$/i.test(resolved))
|
|
210
|
+
return;
|
|
203
211
|
const text = fs.readFileSync(resolved, 'utf8');
|
|
204
212
|
for (const specifier of /\.css$/i.test(resolved) ? [] : moduleSpecifiers(resolved, text)) {
|
|
205
213
|
// Framework host imports do not inject renderer instructions. Other
|
|
@@ -253,11 +261,9 @@ function moduleSpecifiers(file, text) {
|
|
|
253
261
|
return specifiers;
|
|
254
262
|
}
|
|
255
263
|
function resolvePackageModule(importer, specifier) {
|
|
256
|
-
//
|
|
257
|
-
//
|
|
258
|
-
//
|
|
259
|
-
if (!/\.css$/i.test(specifier))
|
|
260
|
-
return null;
|
|
264
|
+
// Installed JS libraries can be the only consumers of networking and audio
|
|
265
|
+
// (e.g. livekit-client). Traverse their real source just like relative imports.
|
|
266
|
+
// Unresolved/native imports still retain the conservative renderer feature set.
|
|
261
267
|
try {
|
|
262
268
|
return createRequire(importer).resolve(specifier);
|
|
263
269
|
}
|