Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,38 +27,40 @@ describe('Environment: ETI', () => {
});
});

test('handles multi-byte characters', () => {
let source = [
`const a = <template>one 💩</template>;`,
`const b = <template>two</template>;`,
`const c = "‘foo’";`,
`const d = <template>four</template>;`,
].join('\n');

let result = preprocess(source, 'index.gts');
describe('character testing', () => {
test('‘, 💩', () => {
let source = [
`const a = <template>one 💩</template>;`,
`const b = <template>two</template>;`,
`const c = "‘foo’";`,
`const d = <template>four</template>;`,
].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 = '<template>${{dollarAmount}}</template>;';

test('handles the $ character', () => {
let source = '<template>${{dollarAmount}}</template>;';
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 = '<template>`code`</template>;';

test('handles the ` character', () => {
let source = '<template>`code`</template>;';
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', () => {
Expand Down Expand Up @@ -199,6 +201,66 @@ describe('Environment: ETI', () => {
);
});

describe('character testing', () => {
test('‘, 💩', () => {
let source = [
`const a = <template>one 💩</template>;`,
`const b = <template>two</template>;`,
`const c = "‘foo’";`,
`const d = <template>four</template>;`,
].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<template>${{foo}}</template>\n';
let { sourceFile } = applyTransform(source);

expect(sourceFile.text).toMatchInlineSnapshot(`
"const foo = 2;

[___T\`\\\${{foo}}\`]
"
`);
});

test('`', () => {
let source = '<template>`code`</template>;';
let { meta, sourceFile } = applyTransform(source);
let templateNode = (sourceFile.statements[1] as ts.ExpressionStatement).expression;

let start = source.indexOf('<template>');
let contentStart = start + '<template>'.length;
let contentEnd = source.indexOf('</template>');
let end = contentEnd + '</template>'.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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
'<template>',
' ${{foo}}',
'</template>',
].join('\n'),
);

expect(diagnostics).toMatchInlineSnapshot(`[]`);
});
});
});

test('expected argument count', async () => {
let diagnostics = await requestDiagnostics(
'ts-template-imports-app/src/ephemeral-index.gts',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
'<template>',
' ${{foo}}',
'</template>',
].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__;
})"
`);
});
});
});
});
});
Loading