31
PropertyLiteral,
32
ReactiveScopeDependency,
33
ScopeId,
34
+ SourceLocation,
35
TInstruction,
36
} from './HIR';
37
245
getOrCreateIdentifier(
246
identifier: Identifier,
247
reactive: boolean,
248
+ loc: SourceLocation,
249
): PropertyPathNode {
250
/**
251
* Reads from a statically scoped variable are always safe in JS,
262
identifier,
263
reactive,
264
path: [],
265
+ loc,
266
},
267
hasOptional: false,
268
parent: null,
293
identifier: parent.fullPath.identifier,
294
reactive: parent.fullPath.reactive,
295
path: parent.fullPath.path.concat(entry),
296
+ loc: entry.loc,
297
},
298
hasOptional: parent.hasOptional || entry.optional,
299
};
308
* so all subpaths of a PropertyLoad should already exist
309
* (e.g. a.b is added before a.b.c),
310
*/
307
- let currNode = this.getOrCreateIdentifier(n.identifier, n.reactive);
311
+ let currNode = this.getOrCreateIdentifier(n.identifier, n.reactive, n.loc);
312
if (n.path.length === 0) {
313
return currNode;
314
}
327
}
328
329
function getMaybeNonNullInInstruction(
326
- instr: InstructionValue,
330
+ value: InstructionValue,
331
context: CollectHoistablePropertyLoadsContext,
332
): PropertyPathNode | null {
333
let path: ReactiveScopeDependency | null = null;
330
- if (instr.kind === 'PropertyLoad') {
331
- path = context.temporaries.get(instr.object.identifier.id) ?? {
332
- identifier: instr.object.identifier,
333
- reactive: instr.object.reactive,
334
+ if (value.kind === 'PropertyLoad') {
335
+ path = context.temporaries.get(value.object.identifier.id) ?? {
336
+ identifier: value.object.identifier,
337
+ reactive: value.object.reactive,
338
path: [],
339
+ loc: value.loc,
340
};
336
- } else if (instr.kind === 'Destructure') {
337
- path = context.temporaries.get(instr.value.identifier.id) ?? null;
338
- } else if (instr.kind === 'ComputedLoad') {
339
- path = context.temporaries.get(instr.object.identifier.id) ?? null;
341
+ } else if (value.kind === 'Destructure') {
342
+ path = context.temporaries.get(value.value.identifier.id) ?? null;
343
+ } else if (value.kind === 'ComputedLoad') {
344
+ path = context.temporaries.get(value.object.identifier.id) ?? null;
345
}
346
return path != null ? context.registry.getOrCreateProperty(path) : null;
347
}
398
) {
399
const identifier = fn.params[0].identifier;
400
knownNonNullIdentifiers.add(
396
- context.registry.getOrCreateIdentifier(identifier, true),
401
+ context.registry.getOrCreateIdentifier(
402
+ identifier,
403
+ true,
404
+ fn.params[0].loc,
405
+ ),
406
);
407
}
408
const nodes = new Map<
477
identifier: dep.root.value.identifier,
478
path: dep.path.slice(0, i),
479
reactive: dep.root.value.reactive,
480
+ loc: dep.loc,
481
});
482
assumedNonNullObjects.add(depNode);
483
}
664
changed = false;
665
666
for (const original of optionalChainNodes) {
657
- let {identifier, path: origPath, reactive} = original.fullPath;
667
+ let {
668
+ identifier,
669
+ path: origPath,
670
+ reactive,
671
+ loc: origLoc,
672
+ } = original.fullPath;
673
let currNode: PropertyPathNode = registry.getOrCreateIdentifier(
674
identifier,
675
reactive,
676
+ origLoc,
677
);
678
for (let i = 0; i < origPath.length; i++) {
679
const entry = origPath[i];
680
// If the base is known to be non-null, replace with a non-optional load
681
const nextEntry: DependencyPathEntry =
682
entry.optional && nodes.has(currNode)
667
- ? {property: entry.property, optional: false}
683
+ ? {property: entry.property, optional: false, loc: entry.loc}
684
: entry;
685
currNode = PropertyPathRegistry.getOrCreatePropertyEntry(
686
currNode,