Skip to content

Commit

Permalink
refactor(compiler): Fix two-way binding source maps
Browse files Browse the repository at this point in the history
Now that two-way bindings work correctly with implicit receivers, we can fix the corresponing source map tests. The main issue was that we were not properly mapping `elementEnd` for elements with no closing tag (self-closing elements).
  • Loading branch information
dylhunn committed Nov 2, 2023
1 parent 04f1563 commit 699a0f9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -419,8 +419,7 @@
],
"compilerOptions": {
"sourceMap": true
},
"skipForTemplatePipeline": true
}
},
{
"description": "should map a two-way binding expression (partial compile)",
Expand Down Expand Up @@ -454,8 +453,7 @@
],
"compilerOptions": {
"sourceMap": true
},
"skipForTemplatePipeline": true
}
},
{
"description": "should map a longhand two-way binding expression (partial compile)",
Expand Down
7 changes: 6 additions & 1 deletion packages/compiler/src/template/pipeline/src/ingest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,12 @@ function ingestElement(unit: ViewCompilationUnit, element: t.Element): void {
ingestReferences(startOp, element);
ingestNodes(unit, element.children);

const endOp = ir.createElementEndOp(id, element.endSourceSpan);
// The source span for the end op is typically the element closing tag. However, if no closing tag
// exists, such as in `<input>`, we use the start source span instead. Usually the start and end
// instructions will be collapsed into one `element` instruction, negating the purpose of this
// fallback, but in cases when it is not collapsed (such as an input with a binding), we still
// want to map the end instruction to the main element.
const endOp = ir.createElementEndOp(id, element.endSourceSpan ?? element.startSourceSpan);
unit.create.push(endOp);

// If there is an i18n message associated with this element, insert i18n start and end ops.
Expand Down

0 comments on commit 699a0f9

Please sign in to comment.