Skip to content
Open
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
30 changes: 16 additions & 14 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const packageJson: {
name: string;
version: string;
description: string;
// eslint-disable-next-line @typescript-eslint/no-var-requires
// eslint-disable-next-line @typescript-eslint/no-var-requires
} = require('./package.json');

const replaceNamespace: Plugin = {
Expand Down Expand Up @@ -43,17 +43,16 @@ async function postProcess(
return undefined;
}
const mapping = loadConfig(config);
return (context: ts.TransformationContext) => (
root: ts.SourceFile
): ts.SourceFile => {
const [inter, converted] = replaceNamespaceDeclaration(
context,
mapping,
root
);
const result = replaceTypeReference(context, converted, inter);
return checkRootLevelModifiers(result);
};
return (context: ts.TransformationContext) =>
(root: ts.SourceFile): ts.SourceFile => {
const [inter, converted] = replaceNamespaceDeclaration(
context,
mapping,
root
);
const result = replaceTypeReference(context, converted, inter);
return checkRootLevelModifiers(result);
};
}

function checkConfig(config: Config): boolean {
Expand Down Expand Up @@ -313,7 +312,10 @@ function flattenEntityName(name: ts.EntityName): string[] {
function packEntityName(names: string[]): ts.EntityName {
let result: ts.EntityName = ts.factory.createIdentifier(names[0]);
for (let i = 1; i < names.length; i++) {
result = ts.factory.createQualifiedName(result, ts.factory.createIdentifier(names[i]));
result = ts.factory.createQualifiedName(
result,
ts.factory.createIdentifier(names[i])
);
}
return result;
}
Expand All @@ -336,7 +338,7 @@ function checkRootLevelModifiers(root: ts.SourceFile): ts.SourceFile {
}
}
if (!found) {
result.push(ts.factory.createModifier(ts.SyntaxKind.DeclareKeyword));
result.push(ts.factory.createModifier(ts.SyntaxKind.ExportKeyword));
}
return ts.factory.createNodeArray(result);
}
Expand Down