From fbbd58d7e711d5f886589e1856836449f9af28e5 Mon Sep 17 00:00:00 2001
From: NullVoxPopuli <199018+NullVoxPopuli@users.noreply.github.com>
Date: Sun, 6 Apr 2025 22:45:09 -0400
Subject: [PATCH 1/2] Add character tests
---
.../__tests__/transformation.test.ts | 114 ++++++++++++++----
.../diagnostic-augmentation.test.ts | 19 +++
.../__tests__/transform/rewrite.test.ts | 36 ++++++
3 files changed, 143 insertions(+), 26 deletions(-)
diff --git a/packages/environment-ember-template-imports/__tests__/transformation.test.ts b/packages/environment-ember-template-imports/__tests__/transformation.test.ts
index 868761644..b07a550c9 100644
--- a/packages/environment-ember-template-imports/__tests__/transformation.test.ts
+++ b/packages/environment-ember-template-imports/__tests__/transformation.test.ts
@@ -27,38 +27,40 @@ describe('Environment: ETI', () => {
});
});
- test('handles multi-byte characters', () => {
- let source = [
- `const a = one 💩;`,
- `const b = two;`,
- `const c = "‘foo’";`,
- `const d = four;`,
- ].join('\n');
-
- let result = preprocess(source, 'index.gts');
+ describe('character testing', () => {
+ test('‘, 💩', () => {
+ let source = [
+ `const a = one 💩;`,
+ `const b = two;`,
+ `const c = "‘foo’";`,
+ `const d = four;`,
+ ].join('\n');
+
+ let result = preprocess(source, 'index.gts');
+
+ expect(result.contents).toMatchInlineSnapshot(`
+ "const a = [___T\`one 💩\`];
+ const b = [___T\`two\`];
+ const c = "‘foo’";
+ const d = [___T\`four\`];"
+ `);
+ });
- expect(result.contents).toMatchInlineSnapshot(`
- "const a = [___T\`one 💩\`];
- const b = [___T\`two\`];
- const c = "‘foo’";
- const d = [___T\`four\`];"
- `);
- });
+ test('$', () => {
+ let source = '${{dollarAmount}};';
- test('handles the $ character', () => {
- let source = '${{dollarAmount}};';
+ let result = preprocess(source, 'index.gts');
- let result = preprocess(source, 'index.gts');
+ expect(result.contents).toMatchInlineSnapshot('"[___T`\\${{dollarAmount}}`];"');
+ });
- expect(result.contents).toMatchInlineSnapshot('"[___T`\\${{dollarAmount}}`];"');
- });
+ test('`', () => {
+ let source = '`code`;';
- test('handles the ` character', () => {
- let source = '`code`;';
+ let result = preprocess(source, 'index.gts');
- let result = preprocess(source, 'index.gts');
-
- expect(result.contents).toMatchInlineSnapshot('"[___T`\\`code\\``];"');
+ expect(result.contents).toMatchInlineSnapshot('"[___T`\\`code\\``];"');
+ });
});
test('multiple templates', () => {
@@ -199,6 +201,66 @@ describe('Environment: ETI', () => {
);
});
+ describe('character testing', () => {
+ test('‘, 💩', () => {
+ let source = [
+ `const a = one 💩;`,
+ `const b = two;`,
+ `const c = "‘foo’";`,
+ `const d = four;`,
+ ].join('\n');
+
+ let { sourceFile } = applyTransform(source);
+
+ expect(sourceFile.text).toMatchInlineSnapshot(`
+ "const a = [___T\`one 💩\`];
+ const b = [___T\`two\`];
+ const c = "‘foo’";
+ const d = [___T\`four\`];"
+ `);
+ });
+
+ test('$', () => {
+ let source = 'const foo = 2;\n\n${{foo}}\n';
+ let { sourceFile } = applyTransform(source);
+
+ expect(sourceFile.text).toMatchInlineSnapshot(`
+"const foo = 2;
+
+[___T\`\\\${{foo}}\`]
+"
+`);
+ });
+
+ test('`', () => {
+ let source = '`code`;';
+ let { meta, sourceFile } = applyTransform(source);
+ let templateNode = (sourceFile.statements[1] as ts.ExpressionStatement).expression;
+
+ let start = source.indexOf('');
+ let contentStart = start + ''.length;
+ let contentEnd = source.indexOf('');
+ let end = contentEnd + ''.length;
+
+ expect(meta).toEqual(
+ new Map([
+ [
+ templateNode,
+ {
+ prepend: 'export default ',
+ templateLocation: {
+ start,
+ contentStart,
+ contentEnd,
+ end,
+ },
+ },
+ ],
+ ]),
+ );
+ });
+ });
+
test('single template with satisfies', () => {
let source = stripIndent`
import type { TOC } from '@ember/component/template-only';
diff --git a/test-packages/package-test-core/__tests__/language-server/diagnostic-augmentation.test.ts b/test-packages/package-test-core/__tests__/language-server/diagnostic-augmentation.test.ts
index be9ac6141..a5f95f22f 100644
--- a/test-packages/package-test-core/__tests__/language-server/diagnostic-augmentation.test.ts
+++ b/test-packages/package-test-core/__tests__/language-server/diagnostic-augmentation.test.ts
@@ -37,6 +37,25 @@ describe('Language Server: Diagnostic Augmentation', () => {
expect(diagnostics).toMatchInlineSnapshot();
});
+ describe('unicode and other special characters', () => {
+ describe('$', () => {
+ test('GitHub Issue#840', async () => {
+ let diagnostics = await requestDiagnostics(
+ 'ts-template-imports-app/src/ephemeral-index.gts',
+ 'glimmer-ts',
+ [
+ // https://github.com/typed-ember/glint/issues/879
+ '',
+ ' ${{foo}}',
+ '',
+ ].join('\n'),
+ );
+
+ expect(diagnostics).toMatchInlineSnapshot();
+ });
+ });
+ });
+
test('expected argument count', async () => {
let diagnostics = await requestDiagnostics(
'ts-template-imports-app/src/ephemeral-index.gts',
diff --git a/test-packages/package-test-core/__tests__/transform/rewrite.test.ts b/test-packages/package-test-core/__tests__/transform/rewrite.test.ts
index d8ce5b7d9..ddf9086b2 100644
--- a/test-packages/package-test-core/__tests__/transform/rewrite.test.ts
+++ b/test-packages/package-test-core/__tests__/transform/rewrite.test.ts
@@ -1063,5 +1063,41 @@ describe('Transform: rewriteModule', () => {
`);
});
});
+
+ describe('unicode and other special characters', () => {
+ describe('$', () => {
+ test('GitHub Issue#840 - does not error', () => {
+ const emberTemplateImportsEnvironment = GlintEnvironment.load(['ember-template-imports']);
+
+ let script = {
+ filename: 'test.gts',
+ contents: [
+ // https://github.com/typed-ember/glint/issues/879
+ '',
+ ' ${{foo}}',
+ '',
+ ].join('\n'),
+ };
+
+ let transformedModule = rewriteModule(ts, { script }, emberTemplateImportsEnvironment);
+
+ expect.soft(transformedModule?.errors?.length).toBe(0);
+ expect.soft(transformedModule?.errors).toMatchInlineSnapshot(`[]`);
+ expect.soft(transformedModule?.transformedContents).toMatchInlineSnapshot(`
+ "
+ // @ts-expect-error
+ ({} as typeof import('./__glint-hacky-nonexistent.gts'));
+
+ // @ts-expect-error
+ ({} as typeof import('./__glint-hacky-nonexistent.gjs'));
+
+ export default ({} as typeof import("@glint/environment-ember-template-imports/-private/dsl")).templateExpression(function(__glintRef__, __glintDSL__: typeof import("@glint/environment-ember-template-imports/-private/dsl")) {
+ __glintDSL__.emitContent(__glintDSL__.resolveOrReturn(foo)());
+ __glintRef__; __glintDSL__;
+ })"
+ `);
+ });
+ });
+ });
});
});
From 733e5fd9aef539dc4a6ceb5fb0607ec17f3d6d7b Mon Sep 17 00:00:00 2001
From: NullVoxPopuli <199018+NullVoxPopuli@users.noreply.github.com>
Date: Sun, 6 Apr 2025 22:51:55 -0400
Subject: [PATCH 2/2] fix
---
.../__tests__/language-server/diagnostic-augmentation.test.ts | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/test-packages/package-test-core/__tests__/language-server/diagnostic-augmentation.test.ts b/test-packages/package-test-core/__tests__/language-server/diagnostic-augmentation.test.ts
index a5f95f22f..34d0618f3 100644
--- a/test-packages/package-test-core/__tests__/language-server/diagnostic-augmentation.test.ts
+++ b/test-packages/package-test-core/__tests__/language-server/diagnostic-augmentation.test.ts
@@ -44,6 +44,7 @@ describe('Language Server: Diagnostic Augmentation', () => {
'ts-template-imports-app/src/ephemeral-index.gts',
'glimmer-ts',
[
+ 'const foo = 2;',
// https://github.com/typed-ember/glint/issues/879
'',
' ${{foo}}',
@@ -51,7 +52,7 @@ describe('Language Server: Diagnostic Augmentation', () => {
].join('\n'),
);
- expect(diagnostics).toMatchInlineSnapshot();
+ expect(diagnostics).toMatchInlineSnapshot(`[]`);
});
});
});