Skip to content

Commit cf80f1f

Browse files
committed
Demonstrate failing test (revert this commit)
1 parent f913950 commit cf80f1f

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

packages/core/src/transform/template/template-to-typescript.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { EmbeddingSyntax, mapTemplateContents, RewriteResult } from './map-templ
44
import ScopeStack from './scope-stack.js';
55
import { GlintEmitMetadata, GlintSpecialForm } from '@glint/core/config-types';
66
import { TextContent } from './glimmer-ast-mapping-tree.js';
7+
import { Directive } from './transformed-module.js';
78
import { DirectiveKind } from './transformed-module.js';
89

910
const SPLATTRIBUTES = '...attributes';
@@ -59,7 +60,7 @@ export function templateToTypescript(
5960
return mapTemplateContents(originalTemplate, { embeddingSyntax }, (ast, mapper) => {
6061
let { rangeForNode } = mapper;
6162
let scope = new ScopeStack([]);
62-
let contextStack = ['default'];
63+
let inHtmlContext: 'svg' | 'math' | 'default' = 'default';
6364

6465
emitTemplateBoilerplate(() => {
6566
for (let statement of ast?.body ?? []) {
@@ -185,11 +186,11 @@ export function templateToTypescript(
185186
// Push to the directives array on the record
186187
mapper.directive(node, 'nocheck');
187188
} else if (kind === 'in-svg') {
188-
contextStack.push('svg');
189+
inHtmlContext = 'svg';
189190
} else if (kind === 'in-mathml') {
190-
contextStack.push('math');
191+
inHtmlContext = 'math';
191192
} else if (kind === 'out-svg' || kind === 'out-mathml') {
192-
contextStack.pop();
193+
inHtmlContext = 'default';
193194
} else {
194195
// Push an error on the record
195196
mapper.error(`Unknown directive @glint-${kind}`, location);
@@ -885,19 +886,17 @@ export function templateToTypescript(
885886
const directivesWeakMap = assignDirectivesToElementOpenTagPieces(node);
886887

887888
if (node.tag === 'svg') {
888-
contextStack.push('svg');
889+
inHtmlContext = 'svg';
889890
}
890891

891892
if (node.tag === 'math') {
892-
contextStack.push('math');
893+
inHtmlContext = 'math';
893894
}
894895

895896
mapper.text('{');
896897
mapper.newline();
897898
mapper.indent();
898899

899-
let inHtmlContext = contextStack.at(-1);
900-
901900
if (inHtmlContext === 'default') {
902901
mapper.text('const __glintY__ = __glintDSL__.emitElement("');
903902
} else if (inHtmlContext === 'svg') {
@@ -922,7 +921,7 @@ export function templateToTypescript(
922921
}
923922

924923
if (node.tag === 'svg' || node.tag === 'math') {
925-
contextStack.pop();
924+
inHtmlContext = 'default';
926925
}
927926

928927
mapper.dedent();

0 commit comments

Comments
 (0)