From 59c836e0c1cb271bf27cc111f2f395bbc05895ef Mon Sep 17 00:00:00 2001 From: yoyo930021 Date: Mon, 11 Jul 2022 11:15:26 +0800 Subject: [PATCH] Fix #3323 #3424 --- .../services/typescriptService/preprocess.ts | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/server/src/services/typescriptService/preprocess.ts b/server/src/services/typescriptService/preprocess.ts index 0c0b7a12aa..c81fd0bc00 100644 --- a/server/src/services/typescriptService/preprocess.ts +++ b/server/src/services/typescriptService/preprocess.ts @@ -245,6 +245,15 @@ export function injectVueTemplate( tsModule.createLiteral(componentFilePath) ); + const createImportSpecifier = (name: string) => { + const [major, minor] = tsModule.version.split('.'); + if ((Number(major) === 4 && Number(minor) >= 5) || Number(major) > 4) { + // @ts-expect-error + return tsModule.createImportSpecifier(undefined, undefined, tsModule.createIdentifier(renderHelperName)); + } + return tsModule.createImportSpecifier(undefined, tsModule.createIdentifier(name)); + }; + // import helper type to handle Vue's private methods const helperImport = tsModule.createImportDeclaration( undefined, @@ -252,10 +261,10 @@ export function injectVueTemplate( tsModule.createImportClause( undefined, tsModule.createNamedImports([ - tsModule.createImportSpecifier(undefined, tsModule.createIdentifier(renderHelperName)), - tsModule.createImportSpecifier(undefined, tsModule.createIdentifier(componentHelperName)), - tsModule.createImportSpecifier(undefined, tsModule.createIdentifier(iterationHelperName)), - tsModule.createImportSpecifier(undefined, tsModule.createIdentifier(componentDataName)) + createImportSpecifier(renderHelperName), + createImportSpecifier(componentHelperName), + createImportSpecifier(iterationHelperName), + createImportSpecifier(componentDataName) ]) ), tsModule.createLiteral('vue-editor-bridge')