Skip to content

Commit 0abed82

Browse files
committed
fix: always call getProgram() to get latest snapshots
1 parent 0d38dc5 commit 0abed82

File tree

4 files changed

+9
-15
lines changed

4 files changed

+9
-15
lines changed

packages/complex-types/src/core/transform.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import type { TransformOptions } from "./types";
99
export function transform(code: string, id: string, options: TransformOptions) {
1010
const s = new MagicString(code);
1111
const language = getLanguage();
12-
const typeChecker = language.__internal__.typeChecker;
13-
const printer = new Printer(typeChecker);
12+
const checker = language.tsLs.getProgram()!.getTypeChecker();
13+
const printer = new Printer(checker);
1414
const transformers = getTransformers(options);
1515

1616
for (const [, transform] of transformers) {

packages/language/src/helpers.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type ts from "typescript/lib/tsserverlibrary";
33

44
export function createHelpers(
55
language: vue.Language<string>,
6-
program: ts.Program,
6+
tsLs: ts.LanguageService,
77
vueCompilerOptions: vue.VueCompilerOptions,
88
ts: typeof import("typescript/lib/tsserverlibrary"),
99
) {
@@ -37,6 +37,7 @@ export function createHelpers(
3737
}
3838

3939
function getVirtualFileOrTsAst(normalizedFilepath: string) {
40+
const program = tsLs.getProgram()!;
4041
let virtualFileOrTsAst = program.getSourceFile(normalizedFilepath);
4142
if (virtualFileOrTsAst) {
4243
return virtualFileOrTsAst;

packages/language/src/index.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,11 @@ function createLanguageWorker(
135135
return getScriptKind!(fileName);
136136
};
137137

138-
const program = tsLs.getProgram()!;
139-
const typeChecker = program.getTypeChecker();
140-
141-
const helpers = createHelpers(language, program, vueOptions, ts);
138+
const helpers = createHelpers(language, tsLs, vueOptions, ts);
142139

143140
return {
144141
...helpers,
142+
tsLs,
145143
updateFile(fileName: string, text: string) {
146144
fileName = normalizePath(fileName);
147145
scriptSnapshots.set(fileName, ts.ScriptSnapshot.fromString(text));
@@ -167,11 +165,6 @@ function createLanguageWorker(
167165
scriptSnapshots.clear();
168166
projectVersion++;
169167
},
170-
__internal__: {
171-
tsLs,
172-
program,
173-
typeChecker,
174-
},
175168
};
176169
}
177170

packages/tsx-auto-props/src/core/transform.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export function transform(code: string, id: string): TransformResult {
1717
const s = new MagicString(code);
1818
const normalizedFilepath = normalizePath(id);
1919
const language = getLanguage();
20-
const typeChecker = language.__internal__.typeChecker;
20+
const checker = language.tsLs.getProgram()!.getTypeChecker();
2121
// This transform is supposed to be used in `.tsx` files not Vue SFCs.
2222
const ast = language.getVirtualFileOrTsAst(normalizedFilepath);
2323
if (!ast) {
@@ -29,7 +29,7 @@ export function transform(code: string, id: string): TransformResult {
2929
return;
3030
}
3131
const identifier = node.expression;
32-
const symbol = typeChecker.getSymbolAtLocation(identifier);
32+
const symbol = checker.getSymbolAtLocation(identifier);
3333
// This is a `defineComponent` call...
3434
if (
3535
symbol?.declarations?.some(
@@ -73,7 +73,7 @@ export function transform(code: string, id: string): TransformResult {
7373
}
7474
const props = setupFn?.parameters[0];
7575
if (props) {
76-
const propsList = typeChecker
76+
const propsList = checker
7777
.getTypeAtLocation(props)
7878
.getProperties()
7979
.map((p) => p.name);

0 commit comments

Comments
 (0)