Skip to content

Commit

Permalink
split volar mappings b/w .ts and .hbs
Browse files Browse the repository at this point in the history
  • Loading branch information
machty committed Jul 10, 2024
1 parent da06db6 commit 44d556e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
6 changes: 5 additions & 1 deletion packages/core/src/transform/template/transformed-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ export default class TransformedModule {
* - to
* - `[[ZEROLEN-A]]χ.emitContent(χ.resolveOrReturn([[expectsAtLeastOneArg]])());[[ZEROLEN-B]]`
*/
public toVolarMappings(): CodeMapping[] {
public toVolarMappings(filenameFilter?: string): CodeMapping[] {
const sourceOffsets: number[] = [];
const generatedOffsets: number[] = [];
const lengths: number[] = [];
Expand Down Expand Up @@ -301,6 +301,10 @@ export default class TransformedModule {
};

this.correlatedSpans.forEach((span) => {
if (filenameFilter && span.originalFile.filename !== filenameFilter) {
return;
}

if (span.glimmerAstMapping) {
// this span is transformation from HBS to TS (either the replaced contents
// within `<template>` tags in a .gts file, or the inserted and transformed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,13 @@ export class LooseModeBackingComponentClassVirtualCode implements VirtualCode {

const hbsLength = hbsSourceScript.snapshot.getLength();
const hbsContent = hbsSourceScript.snapshot.getText(0, hbsLength);
const sourceTsFileName = String(this.fileId)

const transformedModule = rewriteModule(
this.glintConfig.ts,
{
script: {
filename: 'disregard.ts', // not sure why this is disregard but template file is not?
filename: sourceTsFileName,
contents,
},
template: {
Expand All @@ -110,20 +111,21 @@ export class LooseModeBackingComponentClassVirtualCode implements VirtualCode {
this.transformedModule = transformedModule;

if (transformedModule) {
const mappings = transformedModule.toVolarMappings();
const volarTsMappings = transformedModule.toVolarMappings(sourceTsFileName);
const volarHbsMappings = transformedModule.toVolarMappings(templatePathCandidate.path);
this.embeddedCodes = [
{
embeddedCodes: [],
id: 'ts',
languageId: 'typescript',

// Mappings from the backing component class file to the transformed module.
mappings: [],
mappings: volarTsMappings,
snapshot: new ScriptSnapshot(transformedModule.transformedContents),
directives: transformedModule.directives,

// Mappings from the .hbs template file to the transformed module.
associatedScriptMappings: new Map([[hbsSourceScript.id, mappings]]),
associatedScriptMappings: new Map([[hbsSourceScript.id, volarHbsMappings]]),
},
];
} else {
Expand Down

0 comments on commit 44d556e

Please sign in to comment.