Skip to content

Commit

Permalink
Destructure export name
Browse files Browse the repository at this point in the history
  • Loading branch information
askoufis committed Apr 2, 2024
1 parent 3c6601e commit e0ffaad
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions packages/webpack/src/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ function renderLanguageLoaderAsync(
};
}

function findExportNames(source: string, mode: 'cjs'): string[];
function findExportNames(
source: string,
mode: 'esm',
): esModuleLexer.ExportSpecifier[];
function findExportNames(source: string, mode: 'cjs' | 'esm') {
if (mode === 'esm') {
const [, exports] = esModuleLexer.parse(source);
Expand Down Expand Up @@ -126,12 +131,12 @@ export default async function vocabLoader(this: LoaderContext, source: string) {
const esmExports = findExportNames(source, 'esm');
if (esmExports.length > 0) {
const exportName = esmExports[0];
trace(`Found ESM export '${exportName}' in ${this.resourcePath}`);
trace(`Found ESM export '${exportName.n}' in ${this.resourcePath}`);

result = /* ts */ `
import { createLanguage, createTranslationFile } from '@vocab/webpack/${target}';
${translations}
export { translations as ${exportName} };
export { translations as ${exportName.n} };
`;
} else {
// init needs to be called and waited upon
Expand Down

0 comments on commit e0ffaad

Please sign in to comment.