Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
machty committed Jul 9, 2024
1 parent 41397f6 commit 3ee048e
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/core/__tests__/cli/check.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ describe('CLI: single-pass typechecking', () => {
`);
});

test.only('reports diagnostics for a companion template type error', async () => {
test('reports diagnostics for a companion template type error', async () => {
project.setGlintConfig({ environment: 'ember-loose' });

let script = stripIndent`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ export function calculateCompanionTemplateSpans(
suffix: '}\n',
});
} else {
// TODO: when does this get called?
throw new Error("ALEX not class like");
let backingValue: string | undefined;
if (targetNode) {
let moduleName = path.basename(script.filename, path.extname(script.filename));
Expand Down Expand Up @@ -143,6 +145,9 @@ export function calculateCompanionTemplateSpans(
}
}

/**
* Find and return the TS AST node which can serve as a proper insertion point
*/
function findCompanionTemplateTarget(
ts: TSLib,
sourceFile: ts.SourceFile,
Expand All @@ -155,6 +160,7 @@ function findCompanionTemplateTarget(
mods?.some((mod) => mod.kind === ts.SyntaxKind.DefaultKeyword) &&
mods.some((mod) => mod.kind === ts.SyntaxKind.ExportKeyword)
) {
// We've found a `export default class` statement; return it.
return statement;
}

Expand All @@ -164,6 +170,8 @@ function findCompanionTemplateTarget(
}
}

// We didn't find a default export, but maybe there is a named export that
// matches one of the class statements we found above.
for (let statement of sourceFile.statements) {
if (ts.isExportAssignment(statement) && !statement.isExportEquals) {
if (ts.isIdentifier(statement.expression) && statement.expression.text in classes) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ export type MapTemplateContentsOptions = {
};

/**
* Given the text of an embedded template, invokes the given callback
* Given the text of a handlebars template (either standalone .hbs file, or the contents
* of an embedded `<template>...</template>` within a .gts file), invokes the given callback
* with a set of tools to emit mapped contents corresponding to
* that template, tracking the text emitted in order to provide
* a mapping of ranges in the input to ranges in the output.
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/volar/handlebars-virtual-code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export class VirtualHandlebarsCode implements VirtualCode {
// Here we are assembling the args to pass into rewriteModule, which wants both the .ts script
// and the template file. For .gts template is undefined but here we need to pass in the contents.
// Let's see how rewriteModule attempts to transform this shit.
let script = { filename: 'disregard.ts', contents: 'export {}; let a = 123;' };
let script = { filename: 'disregard.ts', contents: 'export default class MyComponent {}' };
let template = {
filename: 'disregard.hbs',
contents,
Expand Down

0 comments on commit 3ee048e

Please sign in to comment.