Skip to content

Commit

Permalink
Pass version in new template sourceFile
Browse files Browse the repository at this point in the history
  • Loading branch information
yoyo930021 committed Oct 11, 2020
1 parent a733125 commit da57ffb
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions server/src/services/typescriptService/preprocess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,14 @@ export function createUpdater(tsModule: T_TypeScript, allChildComponentsInfo: Ma
true /* setParentNodes: Need this to walk the AST */,
tsModule.ScriptKind.JS
);
// Don't update program and file every time
// *internal* property
(newSourceFile as any).version = (sourceFile as any).version;
(newSourceFile as any).scriptSnapshot = {
getText: (start: number, end: number) => newText.substring(start, end),
getLength: () => newText.length,
getChangeRange: () => void 0
};

const templateFsPath = URI.file(vueTemplateFileName).fsPath;
const sourceMapNodes = generateSourceMap(tsModule, sourceFile, newSourceFile);
Expand Down Expand Up @@ -179,7 +187,7 @@ function modifyVueScript(tsModule: T_TypeScript, sourceFile: ts.SourceFile): voi
st =>
st.kind === tsModule.SyntaxKind.ExportAssignment &&
(st as ts.ExportAssignment).expression.kind === tsModule.SyntaxKind.ObjectLiteralExpression
);
) as ts.ExportAssignment;
if (exportDefaultObject) {
// 1. add `import Vue from 'vue'
// (the span of the inserted statement must be (0,0) to avoid overlapping existing statements)
Expand All @@ -204,7 +212,7 @@ function modifyVueScript(tsModule: T_TypeScript, sourceFile: ts.SourceFile): voi
end: objectLiteral.pos + 1
});
(exportDefaultObject as any).expression = setObjPos(tsModule.createCall(vue, undefined, [objectLiteral]));
setObjPos(((exportDefaultObject as ts.ExportAssignment).expression as ts.CallExpression).arguments!);
setObjPos((exportDefaultObject.expression as ts.CallExpression).arguments!);
}
}

Expand Down

0 comments on commit da57ffb

Please sign in to comment.