File tree Expand file tree Collapse file tree 2 files changed +20
-1
lines changed
Expand file tree Collapse file tree 2 files changed +20
-1
lines changed Original file line number Diff line number Diff line change 11import { version , reactive , watchEffect , watch } from 'vue'
22import * as defaultCompiler from 'vue/compiler-sfc'
33import { compileFile } from './transform'
4- import { utoa , atou } from './utils'
4+ import { utoa , atou , isSciptLangChanged } from './utils'
55import {
66 SFCScriptCompileOptions ,
77 SFCAsyncStyleCompileOptions ,
@@ -193,6 +193,17 @@ export class ReplStore implements Store {
193193 )
194194 )
195195
196+ // Temporary workaround for https://github.com/vuejs/repl/issues/321
197+ // which is related to https://github.com/microsoft/TypeScript/issues/57631
198+ // TODO: remove this when the issue is fixed
199+ watch (
200+ ( ) => this . state . activeFile . code ,
201+ ( newCode , oldCode ) => {
202+ if ( this . state . activeFile . language !== 'vue' ) return
203+ if ( isSciptLangChanged ( newCode , oldCode ) ) this . reloadLanguageTools ?.( )
204+ }
205+ )
206+
196207 watch (
197208 ( ) => [
198209 this . state . files [ tsconfigFile ] ?. code ,
Original file line number Diff line number Diff line change @@ -31,3 +31,11 @@ export function atou(base64: string): string {
3131 // https://base64.guru/developers/javascript/examples/unicode-strings
3232 return decodeURIComponent ( escape ( binary ) )
3333}
34+
35+ // This function compares the `lang` attribute of the `<script>` tag in .vue files
36+ export function isSciptLangChanged ( newCode : string , oldCode : string ) {
37+ const newLang = newCode . match ( / < s c r i p t [ ^ > ] * l a n g = " ( [ ^ " ] + ) " [ ^ > ] * > / ) ?. [ 1 ]
38+ const oldLang = oldCode . match ( / < s c r i p t [ ^ > ] * l a n g = " ( [ ^ " ] + ) " [ ^ > ] * > / ) ?. [ 1 ]
39+
40+ return newLang !== oldLang
41+ }
You can’t perform that action at this time.
0 commit comments