@shapeshift-labs/frontier-lang-compiler 0.2.147 → 0.2.148
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.
|
@@ -50,6 +50,9 @@ function createIndependentTopLevelDeletionPlan(input, topLevelResult) {
|
|
|
50
50
|
if (deletedEntry.kind !== 'declaration' || deletedEntry.declarationInfo?.exported === true) {
|
|
51
51
|
return { ok: false, reasonCodes: ['exported-or-unsupported-top-level-deletion'] };
|
|
52
52
|
}
|
|
53
|
+
if (isUnsupportedTopLevelDeletion(deletedEntry)) {
|
|
54
|
+
return { ok: false, reasonCodes: ['unsupported-top-level-deletion-declaration'] };
|
|
55
|
+
}
|
|
53
56
|
|
|
54
57
|
const expectedWorkerKeys = base.entries
|
|
55
58
|
.filter((entry) => entry.key !== deletedEntry.key)
|
|
@@ -127,6 +130,11 @@ function entriesByKey(entries) {
|
|
|
127
130
|
return new Map(entries.map((entry) => [entry.key, entry]));
|
|
128
131
|
}
|
|
129
132
|
|
|
133
|
+
function isUnsupportedTopLevelDeletion(entry) {
|
|
134
|
+
if (entry.declarationInfo?.declarationKind === 'module') return true;
|
|
135
|
+
return /^\s*(?:export\s+)?declare\b/.test(entry.text ?? '');
|
|
136
|
+
}
|
|
137
|
+
|
|
130
138
|
function sameStringList(left, right) {
|
|
131
139
|
return left.length === right.length && left.every((value, index) => value === right[index]);
|
|
132
140
|
}
|
|
@@ -58,6 +58,7 @@ function isProjectedDeleteAlreadyAppliedReplay(input) {
|
|
|
58
58
|
.filter((edit) => edit.editKind === 'delete')
|
|
59
59
|
.map((edit) => edit.operationId));
|
|
60
60
|
const staleDeletes = edits.filter(isProjectedDeleteMissingAnchor);
|
|
61
|
+
if (hasUnsafeProjectedDeleteCompanions(input, staleDeletes)) return false;
|
|
61
62
|
return staleDeletes.length > 0
|
|
62
63
|
&& edits.every((edit) => edit.status === 'already-applied' || isProjectedDeleteMissingAnchor(edit))
|
|
63
64
|
&& staleDeletes.every((edit) => appliedDeleteIds.has(edit.operationId) && projectionDeleteIds.has(edit.operationId));
|
|
@@ -79,4 +80,48 @@ function alreadyAppliedDeleteEdit(edit) {
|
|
|
79
80
|
};
|
|
80
81
|
}
|
|
81
82
|
|
|
83
|
+
function hasUnsafeProjectedDeleteCompanions(input, staleDeletes) {
|
|
84
|
+
const projectionEdits = input.projection?.edits ?? [];
|
|
85
|
+
if (!projectionEdits.length || !staleDeletes.length) return false;
|
|
86
|
+
const projectionDeleteById = new Map(projectionEdits
|
|
87
|
+
.filter((edit) => edit.editKind === 'delete')
|
|
88
|
+
.map((edit) => [edit.operationId, edit]));
|
|
89
|
+
for (const staleDelete of staleDeletes) {
|
|
90
|
+
const projectedDelete = projectionDeleteById.get(staleDelete.operationId);
|
|
91
|
+
const scope = memberBodyDeleteScope(projectedDelete ?? staleDelete);
|
|
92
|
+
if (!scope) continue;
|
|
93
|
+
const companions = projectionEdits.filter((edit) => (
|
|
94
|
+
edit.operationId !== staleDelete.operationId
|
|
95
|
+
&& edit.editKind !== 'delete'
|
|
96
|
+
&& symbolContainerName(edit.symbolName) === scope.container
|
|
97
|
+
));
|
|
98
|
+
if (!companions.length) return true;
|
|
99
|
+
const bodyInserts = companions.filter((edit) => (
|
|
100
|
+
edit.editKind === 'insert'
|
|
101
|
+
&& edit.regionKind === scope.regionKind
|
|
102
|
+
&& edit.symbolKind === scope.symbolKind
|
|
103
|
+
));
|
|
104
|
+
if (bodyInserts.length === 0) return true;
|
|
105
|
+
if (companions.some((edit) => !bodyInserts.includes(edit))) return true;
|
|
106
|
+
}
|
|
107
|
+
return false;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function memberBodyDeleteScope(edit) {
|
|
111
|
+
if (edit?.editKind !== 'delete' || edit?.regionKind !== 'body') return undefined;
|
|
112
|
+
const container = symbolContainerName(edit.symbolName);
|
|
113
|
+
if (!container) return undefined;
|
|
114
|
+
return {
|
|
115
|
+
container,
|
|
116
|
+
regionKind: edit.regionKind,
|
|
117
|
+
symbolKind: edit.symbolKind
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function symbolContainerName(symbolName) {
|
|
122
|
+
const normalized = String(symbolName ?? '').split(':controlFlow:')[0];
|
|
123
|
+
const separator = normalized.lastIndexOf('.');
|
|
124
|
+
return separator === -1 ? undefined : normalized.slice(0, separator);
|
|
125
|
+
}
|
|
126
|
+
|
|
82
127
|
export { normalizeAlreadyAppliedDeleteReplay };
|
package/package.json
CHANGED