diff --git a/packages/shared-internals/src/colocation.ts b/packages/shared-internals/src/colocation.ts index b83f11a9a..3c635a7df 100644 --- a/packages/shared-internals/src/colocation.ts +++ b/packages/shared-internals/src/colocation.ts @@ -7,7 +7,7 @@ export function syntheticJStoHBS(source: string): string | null { // only ever JS (never TS or anything else). And extensionless imports are // handled by the default resolving system doing extension search. if (cleanUrl(source).endsWith('.js')) { - return source.replace(/.js(\?.*)?/, '.hbs$1'); + return source.replace(/\.js(\?.*)?$/, '.hbs$1'); } return null; diff --git a/packages/shared-internals/tests/colocation.test.ts b/packages/shared-internals/tests/colocation.test.ts new file mode 100644 index 000000000..9bdd22bb2 --- /dev/null +++ b/packages/shared-internals/tests/colocation.test.ts @@ -0,0 +1,25 @@ +import { syntheticJStoHBS } from '../src'; + +describe('colocation utils', function () { + describe('syntheticJStoHBS', function () { + test('it returns .hbs files for .js', function () { + const testCases = [ + ['foo.js', 'foo.hbs'], + ['foo.js?qp', 'foo.hbs?qp'], + ['foo/json.js', 'foo/json.hbs'], + ]; + + for (const [from, to] of testCases) { + expect(syntheticJStoHBS(from)).toEqual(to); + } + }); + + test('it ignores non .js files', function () { + const testCases = ['foo.ts', 'foo.hbs', 'foo.js.xxx']; + + for (const from of testCases) { + expect(syntheticJStoHBS(from)).toEqual(null); + } + }); + }); +});