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 = ;`, - `const b = ;`, - `const c = "‘foo’";`, - `const d = ;`, - ].join('\n'); - - let result = preprocess(source, 'index.gts'); + describe('character testing', () => { + test('‘, 💩', () => { + let source = [ + `const a = ;`, + `const b = ;`, + `const c = "‘foo’";`, + `const d = ;`, + ].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 = ';'; - test('handles the $ character', () => { - let source = ';'; + 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 = ';'; - test('handles the ` character', () => { - let source = ';'; + 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 = ;`, + `const b = ;`, + `const c = "‘foo’";`, + `const d = ;`, + ].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\n'; + let { sourceFile } = applyTransform(source); + + expect(sourceFile.text).toMatchInlineSnapshot(` +"const foo = 2; + +[___T\`\\\${{foo}}\`] +" +`); + }); + + test('`', () => { + let source = ';'; + let { meta, sourceFile } = applyTransform(source); + let templateNode = (sourceFile.statements[1] as ts.ExpressionStatement).expression; + + let start = source.indexOf(''.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..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 @@ -37,6 +37,26 @@ 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', + [ + 'const foo = 2;', + // https://github.com/typed-ember/glint/issues/879 + '', + ].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 + '', + ].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__; + })" + `); + }); + }); + }); }); });