Fix pure mini highlight (#994)

* preserve locations for pure values via mininotation

* preserve weight
This commit is contained in:
Alex McLean 2024-03-18 10:37:55 +00:00 committed by GitHub
parent d99af7c4ad
commit 29cb6195b3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -451,7 +451,9 @@ export class Pattern {
* @noAutocomplete
*/
withHaps(func) {
return new Pattern((state) => func(this.query(state), state));
const result = new Pattern((state) => func(this.query(state), state));
result.weight = this.weight;
return result;
}
/**
@ -484,6 +486,7 @@ export class Pattern {
const result = this.withHap((hap) => hap.setContext(func(hap.context)));
if (this.__pure !== undefined) {
result.__pure = this.__pure;
result.__pure_loc = this.__pure_loc;
}
return result;
}
@ -510,10 +513,15 @@ export class Pattern {
start,
end,
};
return this.withContext((context) => {
const result = this.withContext((context) => {
const locations = (context.locations || []).concat([location]);
return { ...context, locations };
});
if (this.__pure) {
result.__pure = this.__pure;
result.__pure_loc = location;
}
return result;
}
/**
@ -1608,7 +1616,12 @@ export function register(name, func, patternify = true, preserveWeight = false)
if (firstArgs.every((arg) => arg.__pure != undefined)) {
const pureArgs = firstArgs.map((arg) => arg.__pure);
const pureLocs = firstArgs.filter((arg) => arg.__pure_loc).map((arg) => arg.__pure_loc);
result = func(...pureArgs, pat);
result = result.withContext((context) => {
const locations = (context.locations || []).concat(pureLocs);
return { ...context, locations };
});
} else {
const [left, ...right] = firstArgs;