[ddc] Fix sourcemap for field initializers

New source locations were added for field initializers to support
upcoming primary constructor work.
See: https://dart-review.googlesource.com/c/sdk/+/468780

This change ensures the initializer assignment statements we add to
the constructor body are fully mapped.

Without this change the new initializer assignment wasn't getting a
mapping so it continued from whatever appeared before it.

Change-Id: Id6ba0619e49e4a517ea36ffa728cf0c1502a14e8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/469300
Auto-Submit: Nicholas Shahan <nshahan@google.com>
Reviewed-by: Nate Biggs <natebiggs@google.com>
Commit-Queue: Nate Biggs <natebiggs@google.com>
This commit is contained in:
Nicholas Shahan
2025-12-21 15:08:42 -08:00
committed by Commit Queue
parent 10147534f4
commit 5fd3ccd4d0
2 changed files with 7 additions and 12 deletions
@@ -2375,12 +2375,8 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
: _getSymbol(virtualField);
var jsInit = _visitInitializer(initializer, f.annotations);
body.add(
jsInit
.toAssignExpression(
js.call('this.#', [access])
..sourceInformation = _nodeStart(hoverInfo),
)
.toStatement(),
jsInit.toAssignExpression(js.call('this.#', [access])).toStatement()
..sourceInformation = _nodeStart(hoverInfo),
);
}
@@ -2665,16 +2665,15 @@ class LibraryCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
return access;
}
js_ast.Expression _emitFieldInit(
js_ast.Statement _emitFieldInit(
Field f,
Expression? initializer,
TreeNode hoverInfo,
) {
var access = _emitFieldValueAccessor(f);
var jsInit = _visitInitializer(initializer, f.annotations);
return jsInit.toAssignExpression(
js.call('this.#', [access])..sourceInformation = _nodeStart(hoverInfo),
);
return jsInit.toAssignExpression(js.call('this.#', [access])).toStatement()
..sourceInformation = _nodeStart(hoverInfo);
}
/// Initialize fields. They follow the sequence:
@@ -2700,7 +2699,7 @@ class LibraryCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
continue;
}
_staticTypeContext.enterMember(f);
body.add(_emitFieldInit(f, init, f).toStatement());
body.add(_emitFieldInit(f, init, f));
_staticTypeContext.leaveMember(f);
}
@@ -2708,7 +2707,7 @@ class LibraryCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
if (ctor != null) {
for (var init in ctor.initializers) {
if (init is FieldInitializer) {
body.add(_emitFieldInit(init.field, init.value, init).toStatement());
body.add(_emitFieldInit(init.field, init.value, init));
} else if (init is LocalInitializer) {
body.add(visitVariableDeclaration(init.variable));
} else if (init is AssertInitializer) {