From 9d4c2a877121c096cd0d246044136d3ab8beba85 Mon Sep 17 00:00:00 2001 From: Simon Ihmig Date: Thu, 19 Dec 2024 19:36:44 +0100 Subject: [PATCH] Fix declarations plugin to cover import() --- packages/addon-dev/src/rollup-declarations.ts | 6 +++++- packages/addon-dev/tests/declarations.test.ts | 7 +++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/addon-dev/src/rollup-declarations.ts b/packages/addon-dev/src/rollup-declarations.ts index 89db68851..0a4099623 100644 --- a/packages/addon-dev/src/rollup-declarations.ts +++ b/packages/addon-dev/src/rollup-declarations.ts @@ -46,5 +46,9 @@ async function fixDeclarationsInMatchingFiles(dir: string) { // Strip any .gts extension from imports in d.ts files, as these won't resolve. See https://github.com/typed-ember/glint/issues/628 // Once Glint v2 is available, this shouldn't be needed anymore. function fixDeclarations(content: string) { - return content.replace(/from\s+['"]([^'"]+)\.gts['"]/g, `from '$1'`); + return content + .replace(/from\s+'([^']+)\.gts'/g, `from '$1'`) + .replace(/from\s+"([^"]+)\.gts"/g, `from '$1'`) + .replace(/import\("([^"]+)\.gts"\)/g, `import('$1')`) + .replace(/import\('([^']+)\.gts'\)/g, `import('$1')`); } diff --git a/packages/addon-dev/tests/declarations.test.ts b/packages/addon-dev/tests/declarations.test.ts index e0391e4c1..37613a977 100644 --- a/packages/addon-dev/tests/declarations.test.ts +++ b/packages/addon-dev/tests/declarations.test.ts @@ -10,6 +10,8 @@ const projectBoilerplate = { 'tsconfig.json': JSON.stringify({ include: ['src/**/*'], compilerOptions: { + target: 'es2022', + module: 'esnext', declaration: true, declarationDir: 'declarations', emitDeclarationOnly: true, @@ -90,6 +92,10 @@ describe('declarations', function () { import bar from './bar.gts'; import baz from './baz.ts'; export { foo, bar, baz }; + + export class Foo { + bar = import('./bar.gts') + } `, 'foo.gts': 'export default 123', 'bar.gts': 'export default 234', @@ -108,5 +114,6 @@ describe('declarations', function () { expect(output).toContain(`import foo from './foo';`); expect(output).toContain(`import bar from './bar';`); expect(output).toContain(`import baz from './baz.ts';`); + expect(output).toContain(`import('./bar')`); }); });