Skip to content

Commit

Permalink
fix(plugin): support typescript 4.2+
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilmysliwiec committed Feb 24, 2021
1 parent 12f7db1 commit 5bbd70f
Show file tree
Hide file tree
Showing 3 changed files with 187 additions and 20,186 deletions.
26 changes: 16 additions & 10 deletions lib/plugin/visitors/model-class.visitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,7 @@ export class ModelClassVisitor {
createDecoratorObjectLiteralExpr(
node: ts.PropertyDeclaration | ts.PropertySignature,
typeChecker: ts.TypeChecker,
existingProperties: ts.NodeArray<
ts.PropertyAssignment
> = ts.createNodeArray(),
existingProperties: ts.NodeArray<ts.PropertyAssignment> = ts.createNodeArray(),
hostFilename = '',
sourceFile: ts.SourceFile,
pluginOptions: PluginOptions,
Expand Down Expand Up @@ -272,14 +270,24 @@ export class ModelClassVisitor {
pathsToImport: string[],
): ts.SourceFile {
const IMPORT_PREFIX = 'eager_import_';
const importDeclarations = pathsToImport.map((path, index) =>
ts.createImportEqualsDeclaration(
const importDeclarations = pathsToImport.map((path, index) => {
if (ts.createImportEqualsDeclaration.length === 5) {
// support TS v4.2+
return (ts.createImportEqualsDeclaration as any)(
undefined,
undefined,
false,
IMPORT_PREFIX + index,
ts.createExternalModuleReference(ts.createLiteral(path)),
);
}
return (ts.createImportEqualsDeclaration as any)(
undefined,
undefined,
IMPORT_PREFIX + index,
ts.createExternalModuleReference(ts.createLiteral(path)),
),
);
);
});
return ts.updateSourceFileNode(sourceFile, [
...importDeclarations,
...sourceFile.statements,
Expand All @@ -288,9 +296,7 @@ export class ModelClassVisitor {

createDescriptionPropertyAssigment(
node: ts.PropertyDeclaration | ts.PropertySignature,
existingProperties: ts.NodeArray<
ts.PropertyAssignment
> = ts.createNodeArray(),
existingProperties: ts.NodeArray<ts.PropertyAssignment> = ts.createNodeArray(),
options: PluginOptions = {},
sourceFile?: ts.SourceFile,
): ts.PropertyAssignment {
Expand Down
Loading

0 comments on commit 5bbd70f

Please sign in to comment.