mirror of
https://github.com/morluto/rea.git
synced 2026-10-26 17:35:11 +00:00
refactor(javascript): own property capture translation
This commit is contained in:
1 parent
adfde012ec
commit
247c8f4eab
5 files changed
+42
-34
No files matched your search
@@ -33,6 +33,10 @@ it.each([
|
||||
'const { app } = require("electron"); const runtime = app; runtime.setAppPath("./other");',
|
||||
true,
|
||||
],
|
||||
[
|
||||
'const { app } = require("electron"); const copy = { ...{ app } }; copy.app.setAppPath("./other");',
|
||||
true,
|
||||
],
|
||||
[
|
||||
'const { app } = require("electron"); const change = app.setAppPath; change("./other");',
|
||||
true,
|
||||
|
||||
@@ -13,6 +13,7 @@ import {
|
||||
semanticObjectPropertyReferences,
|
||||
} from "./javascriptSemanticObjectReferences.js";
|
||||
import {
|
||||
semanticCapturedSelectionsAfterPropertyRead,
|
||||
semanticNormalizeCapturedSelections,
|
||||
semanticProjectedSourceFactsAtRead,
|
||||
semanticShiftCapturedSelections,
|
||||
@@ -329,23 +330,10 @@ export const createSemanticElectronAppPathChangeQuery = (
|
||||
awaitDepths: current.awaitDepths.filter(
|
||||
(depth) => depth !== path?.length,
|
||||
),
|
||||
capturedSelections: [
|
||||
...(semanticShiftCapturedSelections(
|
||||
current.capturedSelections,
|
||||
source.path.length - 1,
|
||||
) ?? []),
|
||||
...(source.capturedSelectionAt === undefined
|
||||
? []
|
||||
: [
|
||||
{
|
||||
at: source.capturedSelectionAt,
|
||||
depth: source.path.length,
|
||||
...(source.ownEnumerable
|
||||
? { ownEnumerable: true as const }
|
||||
: {}),
|
||||
},
|
||||
]),
|
||||
],
|
||||
capturedSelections: semanticCapturedSelectionsAfterPropertyRead(
|
||||
current.capturedSelections,
|
||||
source,
|
||||
),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import { unwrapJavaScriptExpression } from "./javascriptAstValues.js";
|
||||
import {
|
||||
semanticObjectPropertyReferences,
|
||||
semanticArrayPropertyReferences,
|
||||
type JavaScriptSemanticObjectReference,
|
||||
} from "./javascriptSemanticObjectReferences.js";
|
||||
import { SEMANTIC_ALIAS_SELECTION_LIMIT } from "./javascriptSemanticResourceLimits.js";
|
||||
import {
|
||||
@@ -68,6 +69,27 @@ export const semanticShiftCapturedSelections = (
|
||||
return semanticNormalizeCapturedSelections(shifted);
|
||||
};
|
||||
|
||||
/** Record an object/array property selected when a shallow copy was made. */
|
||||
export const semanticCapturedSelectionsAfterPropertyRead = (
|
||||
selections: readonly SemanticCapturedSelection[] | undefined,
|
||||
source: Pick<
|
||||
JavaScriptSemanticObjectReference,
|
||||
"path" | "capturedSelectionAt" | "ownEnumerable"
|
||||
>,
|
||||
): readonly SemanticCapturedSelection[] => [
|
||||
...(semanticShiftCapturedSelections(selections, source.path.length - 1) ??
|
||||
[]),
|
||||
...(source.capturedSelectionAt === undefined
|
||||
? []
|
||||
: [
|
||||
{
|
||||
at: source.capturedSelectionAt,
|
||||
depth: source.path.length,
|
||||
...(source.ownEnumerable ? { ownEnumerable: true as const } : {}),
|
||||
},
|
||||
]),
|
||||
];
|
||||
|
||||
interface ProjectedSource {
|
||||
readonly node: t.Node;
|
||||
readonly path: SemanticAliasSelectionPath;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import {
|
||||
semanticCapturedSelectionsAfterPropertyRead,
|
||||
semanticProjectedSourceFactsAtRead,
|
||||
semanticProjectedSourceEligibilityAtRead,
|
||||
semanticNormalizeCapturedSelections,
|
||||
@@ -806,23 +807,10 @@ const loaderObjectPropertySources = (
|
||||
.map((source) => ({
|
||||
node: source.node,
|
||||
path: [...source.path, ...remaining],
|
||||
capturedSelections: [
|
||||
...(semanticShiftCapturedSelections(
|
||||
current.capturedSelections,
|
||||
source.path.length - 1,
|
||||
) ?? []),
|
||||
...(source.capturedSelectionAt === undefined
|
||||
? []
|
||||
: [
|
||||
{
|
||||
at: source.capturedSelectionAt,
|
||||
depth: source.path.length,
|
||||
...(source.ownEnumerable
|
||||
? { ownEnumerable: true as const }
|
||||
: {}),
|
||||
},
|
||||
]),
|
||||
],
|
||||
capturedSelections: semanticCapturedSelectionsAfterPropertyRead(
|
||||
current.capturedSelections,
|
||||
source,
|
||||
),
|
||||
})),
|
||||
);
|
||||
};
|
||||
|
||||
@@ -18,6 +18,12 @@ const cases = [
|
||||
owners: 1,
|
||||
changed: true,
|
||||
},
|
||||
{
|
||||
name: "shallow-copied app",
|
||||
setter: "const copy={...{app}};copy.app.setAppPath('./lib');",
|
||||
owners: 1,
|
||||
changed: true,
|
||||
},
|
||||
{
|
||||
name: "local app",
|
||||
setter: "const getApp=()=>({setAppPath(){}});getApp().setAppPath('./lib');",
|
||||
|
||||
Reference in new issue
Block a user