@esportsplus/typescript
Advanced tools
@@ -5,2 +5,3 @@ import { ts } from '../../index.js'; | ||
| const FILE_REGEX = /\.[tj]sx?$/; | ||
| const DIRECTORY_SEPARATOR_REGEX = /\\/g; | ||
| let contexts = new Map(); | ||
@@ -20,3 +21,7 @@ export default ({ name, onWatchChange, plugins }) => { | ||
| try { | ||
| let result = coordinator.transform(plugins, code, ts.createSourceFile(id, code, ts.ScriptTarget.Latest, true), program.get(root || ''), contexts.get(root || '') ?? contexts.set(root || '', new Map()).get(root || '')); | ||
| let prog = program.get(root || ''), sourceFile = prog.getSourceFile(id.replace(DIRECTORY_SEPARATOR_REGEX, '/')) || prog.getSourceFile(id); | ||
| if (!sourceFile || sourceFile.getText() !== code) { | ||
| sourceFile = ts.createSourceFile(id, code, ts.ScriptTarget.Latest, true); | ||
| } | ||
| let result = coordinator.transform(plugins, code, sourceFile, prog, contexts.get(root || '') ?? contexts.set(root || '', new Map()).get(root || '')); | ||
| if (!result.changed) { | ||
@@ -23,0 +28,0 @@ return null; |
+1
-1
@@ -40,3 +40,3 @@ { | ||
| "types": "build/index.d.ts", | ||
| "version": "0.27.4", | ||
| "version": "0.27.5", | ||
| "scripts": { | ||
@@ -43,0 +43,0 @@ "build": "tsc && tsc-alias", |
@@ -25,3 +25,5 @@ import type { ResolvedConfig } from 'vite'; | ||
| const DIRECTORY_SEPARATOR_REGEX = /\\/g; | ||
| let contexts = new Map<string, SharedContext>(); | ||
@@ -44,7 +46,14 @@ | ||
| try { | ||
| let prog = program.get(root || ''), | ||
| sourceFile = prog.getSourceFile(id.replace(DIRECTORY_SEPARATOR_REGEX, '/')) || prog.getSourceFile(id); | ||
| if (!sourceFile || sourceFile.getText() !== code) { | ||
| sourceFile = ts.createSourceFile(id, code, ts.ScriptTarget.Latest, true); | ||
| } | ||
| let result = coordinator.transform( | ||
| plugins, | ||
| code, | ||
| ts.createSourceFile(id, code, ts.ScriptTarget.Latest, true), | ||
| program.get(root || ''), | ||
| sourceFile, | ||
| prog, | ||
| contexts.get(root || '') ?? contexts.set(root || '', new Map()).get(root || '')! | ||
@@ -51,0 +60,0 @@ ); |
58642
1.16%1501
0.74%