@geastack/geatsc-plugin-gea 0.1.9 → 0.1.10
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.
|
@@ -1,2 +1,4 @@
|
|
|
1
1
|
import ts from 'typescript';
|
|
2
|
-
export declare function sourceLiteralResolver(files: Map<string, string>, initiallyOpaque: boolean): (node: ts.Expression) => string[] | undefined
|
|
2
|
+
export declare function sourceLiteralResolver(files: Map<string, string>, initiallyOpaque: boolean): ((node: ts.Expression) => string[] | undefined) & {
|
|
3
|
+
isSourceMethod(node: ts.Expression): boolean;
|
|
4
|
+
};
|
package/dist/analyze-literals.js
CHANGED
|
@@ -263,5 +263,25 @@ export function sourceLiteralResolver(files, initiallyOpaque) {
|
|
|
263
263
|
expressions.set(`${node.getSourceFile().fileName}:${node.pos}:${node.end}`, node); ts.forEachChild(node, index); };
|
|
264
264
|
for (const source of sources.values())
|
|
265
265
|
index(source);
|
|
266
|
-
|
|
266
|
+
const original = (node) => expressions.get(`${node.getSourceFile().fileName}:${node.pos}:${node.end}`);
|
|
267
|
+
return Object.assign((node) => resolve(original(node)), {
|
|
268
|
+
// A user-authored method called animate is not Element.animate. Require
|
|
269
|
+
// both its implementation in the scanned graph and a local receiver;
|
|
270
|
+
// an opaque/DOM receiver merely cast to a class is not sufficient.
|
|
271
|
+
isSourceMethod(node) {
|
|
272
|
+
const at = original(node);
|
|
273
|
+
if (!at || initiallyOpaque)
|
|
274
|
+
return false;
|
|
275
|
+
const parent = at.parent;
|
|
276
|
+
if (ts.isMethodDeclaration(parent) && parent.name === at && parent.body)
|
|
277
|
+
return true;
|
|
278
|
+
const access = ts.isPropertyAccessExpression(at) || ts.isElementAccessExpression(at) ? at
|
|
279
|
+
: ts.isPropertyAccessExpression(parent) && parent.name === at ? parent : undefined;
|
|
280
|
+
if (!access || !localReceiver(access.expression))
|
|
281
|
+
return false;
|
|
282
|
+
const name = ts.isPropertyAccessExpression(access) ? access.name : access.argumentExpression;
|
|
283
|
+
const declarations = name && typeChecker().getSymbolAtLocation(name)?.declarations;
|
|
284
|
+
return !!declarations?.length && declarations.every(declaration => sources.has(declaration.getSourceFile().fileName) && ts.isMethodDeclaration(declaration) && !!declaration.body);
|
|
285
|
+
},
|
|
286
|
+
});
|
|
267
287
|
}
|
|
@@ -2,6 +2,7 @@ import ts from 'typescript';
|
|
|
2
2
|
export declare const rendererAnalysisVersion = "renderer-analysis-v1";
|
|
3
3
|
export declare function addUnknownRendererFeatures(features: Set<string>): void;
|
|
4
4
|
export interface StyleUsageObserver {
|
|
5
|
+
isSourceMethod?(node: ts.Expression): boolean;
|
|
5
6
|
selector?(css: string): void;
|
|
6
7
|
property(name: string | undefined, value: string | undefined, expression?: ts.Expression): void;
|
|
7
8
|
unknown(): void;
|
package/dist/analyze-renderer.js
CHANGED
|
@@ -262,7 +262,8 @@ export function addRendererFeatures(file, text, features, observer, variables) {
|
|
|
262
262
|
// Imperative animation APIs can mutate arbitrary style fields. Observe
|
|
263
263
|
// references as well as calls so aliases cannot bypass the proof. Frame
|
|
264
264
|
// scheduling (requestAnimationFrame) is independent and stays available.
|
|
265
|
-
if (ts.isIdentifier(node) && /^(?:animate|KeyframeEffect|Animation|AnimationEngine|DeclarativeAnimations|Reflect)$/.test(node.text)
|
|
265
|
+
if (ts.isIdentifier(node) && /^(?:animate|KeyframeEffect|Animation|AnimationEngine|DeclarativeAnimations|Reflect)$/.test(node.text) &&
|
|
266
|
+
!(node.text === 'animate' && observer?.isSourceMethod?.(node)))
|
|
266
267
|
allStyles();
|
|
267
268
|
if (ts.isBindingElement(node) && /^(?:createElement|createElementNS|animate|setAttribute|insertRule|replaceSync)$/.test(node.propertyName?.getText(source).replace(/^['"]|['"]$/g, '') ?? node.name.getText(source)))
|
|
268
269
|
allStyles();
|
|
@@ -279,7 +280,7 @@ export function addRendererFeatures(file, text, features, observer, variables) {
|
|
|
279
280
|
observer?.unknownRanges?.();
|
|
280
281
|
if (name && circleMethods.has(name))
|
|
281
282
|
features.add('renderer-circles');
|
|
282
|
-
if (name === 'dataset' || name === 'animate')
|
|
283
|
+
if (name === 'dataset' || (name === 'animate' && !observer?.isSourceMethod?.(node)))
|
|
283
284
|
allStyles();
|
|
284
285
|
if (name && /^(?:setAttribute|insertRule|replaceSync)$/.test(name) && !(ts.isCallExpression(node.parent) && node.parent.expression === node))
|
|
285
286
|
allStyles();
|
package/dist/analyze.js
CHANGED
|
@@ -35,9 +35,11 @@ export function analyzeSourceHostBindings(entry) {
|
|
|
35
35
|
let classUnknown = discovery.unknown;
|
|
36
36
|
const variables = rendererVariableAnalysis(features);
|
|
37
37
|
const literalSources = new Map([...discovery.files].filter(file => fs.existsSync(file)).map(file => [file, fs.readFileSync(file, 'utf8')]));
|
|
38
|
-
const
|
|
38
|
+
const literals = sourceLiteralResolver(literalSources, discovery.unknown);
|
|
39
|
+
const css = cssUsageObserver(features, literals);
|
|
39
40
|
const ranges = cssRangeObserver(features);
|
|
40
41
|
const observer = {
|
|
42
|
+
isSourceMethod: literals.isSourceMethod,
|
|
41
43
|
selector(value) { css.selector?.(value); ranges.selector?.(value); },
|
|
42
44
|
property(name, value, expression) { css.property(name, value, expression); ranges.property(name, value); variables.property(name, value); },
|
|
43
45
|
unknown() { classUnknown = true; css.unknown(); ranges.unknown(); variables.unknown(); addUnknownNodeFeatures(features); },
|