File tree Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change 1
1
import { version , reactive , watchEffect , watch } from 'vue'
2
2
import * as defaultCompiler from 'vue/compiler-sfc'
3
3
import { compileFile } from './transform'
4
- import { utoa , atou } from './utils'
4
+ import { utoa , atou , hasScriptLangChanged } from './utils'
5
5
import {
6
6
SFCScriptCompileOptions ,
7
7
SFCAsyncStyleCompileOptions ,
@@ -193,6 +193,18 @@ export class ReplStore implements Store {
193
193
)
194
194
)
195
195
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 ( hasScriptLangChanged ( newCode , oldCode ) )
204
+ this . reloadLanguageTools ?.( )
205
+ } ,
206
+ )
207
+
196
208
watch (
197
209
( ) => [
198
210
this . state . files [ tsconfigFile ] ?. code ,
Original file line number Diff line number Diff line change @@ -31,3 +31,13 @@ export function atou(base64: string): string {
31
31
// https://base64.guru/developers/javascript/examples/unicode-strings
32
32
return decodeURIComponent ( escape ( binary ) )
33
33
}
34
+
35
+ // compares the `lang` attribute of the `<script>` tag in .vue files
36
+ export function hasScriptLangChanged ( newCode : string , oldCode : string ) {
37
+ const langRegex = / < s c r i p t [ ^ > ] * l a n g \s * = \s * [ " ' ] ( [ ^ " ' ] + ) [ " ' ] [ ^ > ] * > / ;
38
+
39
+ const newLang = newCode . match ( langRegex ) ?. [ 1 ]
40
+ const oldLang = oldCode . match ( langRegex ) ?. [ 1 ]
41
+
42
+ return newLang !== oldLang
43
+ }
You can’t perform that action at this time.
0 commit comments