@gql.tada/cli-utils 1.3.8 → 1.3.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/dist/chunks/vue-chunk.js +62 -36
- package/dist/chunks/vue-chunk.js.map +1 -1
- package/dist/chunks/vue-chunk.mjs +55 -27
- package/dist/chunks/vue-chunk.mjs.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# @gql.tada/cli-utils
|
|
2
2
|
|
|
3
|
+
## 1.3.9
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- ⚠️ Fix Vue not transpiling to `.tsx` files properly due to missing SFC plugin
|
|
8
|
+
Submitted by [@JoviDeCroock](https://github.com/JoviDeCroock) (See [#305](https://github.com/0no-co/gql.tada/pull/305))
|
|
9
|
+
|
|
3
10
|
## 1.3.8
|
|
4
11
|
|
|
5
12
|
### Patch Changes
|
package/dist/chunks/vue-chunk.js
CHANGED
|
@@ -1,80 +1,106 @@
|
|
|
1
1
|
var e = require("typescript");
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var t = require("@vue/compiler-dom");
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var r = require("@vue/language-core");
|
|
6
6
|
|
|
7
7
|
function _interopNamespaceDefault(e) {
|
|
8
|
-
var
|
|
8
|
+
var t = Object.create(null);
|
|
9
9
|
if (e) {
|
|
10
|
-
Object.keys(e).forEach((function(
|
|
11
|
-
if ("default" !==
|
|
12
|
-
var
|
|
13
|
-
Object.defineProperty(
|
|
10
|
+
Object.keys(e).forEach((function(r) {
|
|
11
|
+
if ("default" !== r) {
|
|
12
|
+
var o = Object.getOwnPropertyDescriptor(e, r);
|
|
13
|
+
Object.defineProperty(t, r, o.get ? o : {
|
|
14
14
|
enumerable: !0,
|
|
15
15
|
get: function() {
|
|
16
|
-
return e[
|
|
16
|
+
return e[r];
|
|
17
17
|
}
|
|
18
18
|
});
|
|
19
19
|
}
|
|
20
20
|
}));
|
|
21
21
|
}
|
|
22
|
-
|
|
23
|
-
return
|
|
22
|
+
t.default = e;
|
|
23
|
+
return t;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
var
|
|
26
|
+
var o = _interopNamespaceDefault(t);
|
|
27
27
|
|
|
28
|
-
var
|
|
28
|
+
var a = _interopNamespaceDefault(r);
|
|
29
29
|
|
|
30
30
|
function* forEachEmbeddedCode(e) {
|
|
31
31
|
yield e;
|
|
32
32
|
if (e.embeddedCodes) {
|
|
33
|
-
for (var
|
|
34
|
-
yield* forEachEmbeddedCode(
|
|
33
|
+
for (var t of e.embeddedCodes) {
|
|
34
|
+
yield* forEachEmbeddedCode(t);
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
var
|
|
39
|
+
var i;
|
|
40
40
|
|
|
41
|
-
if ("VueVirtualCode" in
|
|
42
|
-
|
|
43
|
-
} else if ("VueGeneratedCode" in
|
|
44
|
-
|
|
41
|
+
if ("VueVirtualCode" in a) {
|
|
42
|
+
i = a.VueVirtualCode;
|
|
43
|
+
} else if ("VueGeneratedCode" in a) {
|
|
44
|
+
i = a.VueGeneratedCode;
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
var
|
|
47
|
+
var s;
|
|
48
48
|
|
|
49
|
-
if ("getBasePlugins" in
|
|
50
|
-
|
|
51
|
-
} else if ("getDefaultVueLanguagePlugins" in
|
|
52
|
-
|
|
49
|
+
if ("getBasePlugins" in a) {
|
|
50
|
+
s = a.getBasePlugins;
|
|
51
|
+
} else if ("getDefaultVueLanguagePlugins" in a) {
|
|
52
|
+
s = a.getDefaultVueLanguagePlugins;
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
var n =
|
|
55
|
+
var n = a.resolveVueCompilerOptions({});
|
|
56
56
|
|
|
57
|
-
var
|
|
57
|
+
var f;
|
|
58
58
|
|
|
59
|
-
exports.transform =
|
|
60
|
-
if (!
|
|
59
|
+
exports.transform = t => {
|
|
60
|
+
if (!i || !s) {
|
|
61
61
|
return;
|
|
62
|
-
} else if (!
|
|
63
|
-
|
|
62
|
+
} else if (!f) {
|
|
63
|
+
(f = s({
|
|
64
64
|
modules: {
|
|
65
65
|
typescript: e,
|
|
66
|
-
"@vue/compiler-dom":
|
|
66
|
+
"@vue/compiler-dom": o
|
|
67
67
|
},
|
|
68
68
|
compilerOptions: {},
|
|
69
69
|
globalTypesHolder: void 0,
|
|
70
70
|
vueCompilerOptions: n
|
|
71
|
+
})).push({
|
|
72
|
+
version: 2,
|
|
73
|
+
parseSFC: (e, t) => r.parse(t),
|
|
74
|
+
updateSFC(e, t) {
|
|
75
|
+
var r = [ e.descriptor.template, e.descriptor.script, e.descriptor.scriptSetup, ...e.descriptor.styles, ...e.descriptor.customBlocks ].filter((e => !!e));
|
|
76
|
+
var o = r.find((e => t.start >= e.loc.start.offset && t.end <= e.loc.end.offset));
|
|
77
|
+
if (!o) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
var a = o.content;
|
|
81
|
+
var i = o.content = o.content.substring(0, t.start - o.loc.start.offset) + t.newText + o.content.substring(t.end - o.loc.start.offset);
|
|
82
|
+
var s = new RegExp(`</\\s*${o.type}\\s*>`);
|
|
83
|
+
if (!!a.match(s) != !!i.match(s)) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
var n = t.newText.length - (t.end - t.start);
|
|
87
|
+
for (var f of r) {
|
|
88
|
+
if (f.loc.start.offset > t.end) {
|
|
89
|
+
f.loc.start.offset += n;
|
|
90
|
+
}
|
|
91
|
+
if (f.loc.end.offset >= t.end) {
|
|
92
|
+
f.loc.end.offset += n;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return e;
|
|
96
|
+
}
|
|
71
97
|
});
|
|
72
98
|
}
|
|
73
|
-
var
|
|
74
|
-
var
|
|
75
|
-
for (var
|
|
76
|
-
if (
|
|
77
|
-
return
|
|
99
|
+
var a = e.ScriptSnapshot.fromString(t.getFullText());
|
|
100
|
+
var d = new i(t.fileName, "vue", a, n, f, ...[ e, !1 ]);
|
|
101
|
+
for (var u of forEachEmbeddedCode(d)) {
|
|
102
|
+
if (u.id.startsWith("script_")) {
|
|
103
|
+
return u;
|
|
78
104
|
}
|
|
79
105
|
}
|
|
80
106
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vue-chunk.js","sources":["../../src/ts/transformers/vue.ts"],"sourcesContent":["import ts from 'typescript';\nimport type { VirtualCode } from '@vue/language-core';\nimport * as vueCompilerDOM from '@vue/compiler-dom';\nimport * as vue from '@vue/language-core';\n\nfunction* forEachEmbeddedCode(virtualCode: VirtualCode) {\n yield virtualCode;\n if (virtualCode.embeddedCodes) {\n for (const embeddedCode of virtualCode.embeddedCodes) {\n yield* forEachEmbeddedCode(embeddedCode);\n }\n }\n}\n\nlet VueVirtualCode: typeof vue.VueVirtualCode | undefined;\nif ('VueVirtualCode' in vue) {\n VueVirtualCode = vue.VueVirtualCode;\n} else if ('VueGeneratedCode' in vue) {\n VueVirtualCode = (vue as any).VueGeneratedCode;\n}\n\nlet getBasePlugins: typeof vue.getBasePlugins | undefined;\nif ('getBasePlugins' in vue) {\n getBasePlugins = vue.getBasePlugins;\n} else if ('getDefaultVueLanguagePlugins' in vue) {\n getBasePlugins = (vue as any).getDefaultVueLanguagePlugins;\n}\n\nconst vueCompilerOptions = vue.resolveVueCompilerOptions({});\n\nlet plugins: ReturnType<typeof vue.getBasePlugins> | undefined;\n\nexport const transform = (sourceFile: ts.SourceFile): VirtualCode | undefined => {\n if (!VueVirtualCode || !getBasePlugins) {\n return undefined;\n } else if (!plugins) {\n
|
|
1
|
+
{"version":3,"file":"vue-chunk.js","sources":["../../src/ts/transformers/vue.ts"],"sourcesContent":["import ts from 'typescript';\nimport type { VirtualCode } from '@vue/language-core';\nimport * as vueCompilerDOM from '@vue/compiler-dom';\nimport * as vue from '@vue/language-core';\nimport { parse } from '@vue/language-core';\n\nconst useVueFilePlugin: vue.VueLanguagePlugin = (_ctx) => {\n return {\n version: 2,\n\n parseSFC(_fileName, content) {\n return parse(content);\n },\n\n updateSFC(sfc, change) {\n const blocks = [\n sfc.descriptor.template,\n sfc.descriptor.script,\n sfc.descriptor.scriptSetup,\n ...sfc.descriptor.styles,\n ...sfc.descriptor.customBlocks,\n ].filter((block): block is NonNullable<typeof block> => !!block);\n\n const hitBlock = blocks.find(\n (block) => change.start >= block.loc.start.offset && change.end <= block.loc.end.offset\n );\n if (!hitBlock) {\n return;\n }\n\n const oldContent = hitBlock.content;\n const newContent = (hitBlock.content =\n hitBlock.content.substring(0, change.start - hitBlock.loc.start.offset) +\n change.newText +\n hitBlock.content.substring(change.end - hitBlock.loc.start.offset));\n\n // #3449\n const endTagRegex = new RegExp(`</\\\\s*${hitBlock.type}\\\\s*>`);\n const insertedEndTag = !!oldContent.match(endTagRegex) !== !!newContent.match(endTagRegex);\n if (insertedEndTag) {\n return;\n }\n\n const lengthDiff = change.newText.length - (change.end - change.start);\n\n for (const block of blocks) {\n if (block.loc.start.offset > change.end) {\n block.loc.start.offset += lengthDiff;\n }\n if (block.loc.end.offset >= change.end) {\n block.loc.end.offset += lengthDiff;\n }\n }\n\n return sfc;\n },\n };\n};\n\nfunction* forEachEmbeddedCode(virtualCode: VirtualCode) {\n yield virtualCode;\n if (virtualCode.embeddedCodes) {\n for (const embeddedCode of virtualCode.embeddedCodes) {\n yield* forEachEmbeddedCode(embeddedCode);\n }\n }\n}\n\nlet VueVirtualCode: typeof vue.VueVirtualCode | undefined;\nif ('VueVirtualCode' in vue) {\n VueVirtualCode = vue.VueVirtualCode;\n} else if ('VueGeneratedCode' in vue) {\n VueVirtualCode = (vue as any).VueGeneratedCode;\n}\n\nlet getBasePlugins: typeof vue.getBasePlugins | undefined;\nif ('getBasePlugins' in vue) {\n getBasePlugins = vue.getBasePlugins;\n} else if ('getDefaultVueLanguagePlugins' in vue) {\n getBasePlugins = (vue as any).getDefaultVueLanguagePlugins;\n}\n\nconst vueCompilerOptions = vue.resolveVueCompilerOptions({});\n\nlet plugins: ReturnType<typeof vue.getBasePlugins> | undefined;\n\nexport const transform = (sourceFile: ts.SourceFile): VirtualCode | undefined => {\n if (!VueVirtualCode || !getBasePlugins) {\n return undefined;\n } else if (!plugins) {\n const pluginContext = {\n modules: {\n typescript: ts,\n '@vue/compiler-dom': vueCompilerDOM,\n },\n compilerOptions: {},\n globalTypesHolder: undefined,\n vueCompilerOptions,\n };\n plugins = getBasePlugins(pluginContext);\n const vueSfcPlugin = useVueFilePlugin(pluginContext);\n plugins.push(vueSfcPlugin);\n }\n\n const snapshot = ts.ScriptSnapshot.fromString(sourceFile.getFullText());\n const root = new VueVirtualCode(\n sourceFile.fileName,\n 'vue',\n snapshot,\n vueCompilerOptions,\n plugins,\n ...([ts, false] as any as [typeof ts])\n );\n for (const code of forEachEmbeddedCode(root)) if (code.id.startsWith('script_')) return code;\n};\n"],"names":["forEachEmbeddedCode","virtualCode","embeddedCodes","embeddedCode","VueVirtualCode","vue","VueGeneratedCode","getBasePlugins","getDefaultVueLanguagePlugins","vueCompilerOptions","resolveVueCompilerOptions","plugins","sourceFile","modules","typescript","ts","vueCompilerDOM","compilerOptions","globalTypesHolder","undefined","push","version","parseSFC","_fileName","content","parse","updateSFC","sfc","change","blocks","descriptor","template","script","scriptSetup","styles","customBlocks","filter","block","hitBlock","find","start","loc","offset","end","oldContent","newContent","substring","newText","endTagRegex","RegExp","type","match","lengthDiff","length","snapshot","ScriptSnapshot","fromString","getFullText","root","fileName","code","id","startsWith"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2DA,UAAUA,oBAAoBC;QACtBA;EACN,IAAIA,EAAYC;IACd,KAAK,IAAMC,KAAgBF,EAAYC;aAC9BF,oBAAoBG;;;AAGjC;;AAEA,IAAIC;;AACJ,IAAI,oBAAoBC;EACtBD,IAAiBC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EAAOe;YAClCN,EAAMI,IAAID,MAAME,UAAUU;;UAE5B,IAAIf,EAAMI,IAAIE,IAAID,UAAUd,EAAOe;YACjCN,EAAMI,IAAIE,IAAID,UAAUU;;AAE5B;QAEA,OAAOzB;AACT;;AA+CF;EAEA,IAAM2B,IAAWvC,EAAGwC,eAAeC,WAAW5C,EAAW6C;EACzD,IAAMC,IAAO,IAAItD,EACfQ,EAAW+C,UACX,OACAL,GACA7C,GACAE,MACI,EAACI,IAAI;EAEX,KAAK,IAAM6C,KAAQ5D,oBAAoB0D;IAAO,IAAIE,EAAKC,GAAGC,WAAW;MAAY,OAAOF;;;AAAI"}
|
|
@@ -1,57 +1,85 @@
|
|
|
1
1
|
import e from "typescript";
|
|
2
2
|
|
|
3
|
-
import * as
|
|
3
|
+
import * as t from "@vue/compiler-dom";
|
|
4
4
|
|
|
5
|
-
import * as
|
|
5
|
+
import * as r from "@vue/language-core";
|
|
6
|
+
|
|
7
|
+
import { parse as o } from "@vue/language-core";
|
|
6
8
|
|
|
7
9
|
function* forEachEmbeddedCode(e) {
|
|
8
10
|
yield e;
|
|
9
11
|
if (e.embeddedCodes) {
|
|
10
|
-
for (var
|
|
11
|
-
yield* forEachEmbeddedCode(
|
|
12
|
+
for (var t of e.embeddedCodes) {
|
|
13
|
+
yield* forEachEmbeddedCode(t);
|
|
12
14
|
}
|
|
13
15
|
}
|
|
14
16
|
}
|
|
15
17
|
|
|
16
|
-
var
|
|
18
|
+
var s;
|
|
17
19
|
|
|
18
|
-
if ("VueVirtualCode" in
|
|
19
|
-
|
|
20
|
-
} else if ("VueGeneratedCode" in
|
|
21
|
-
|
|
20
|
+
if ("VueVirtualCode" in r) {
|
|
21
|
+
s = r.VueVirtualCode;
|
|
22
|
+
} else if ("VueGeneratedCode" in r) {
|
|
23
|
+
s = r.VueGeneratedCode;
|
|
22
24
|
}
|
|
23
25
|
|
|
24
|
-
var
|
|
26
|
+
var i;
|
|
25
27
|
|
|
26
|
-
if ("getBasePlugins" in
|
|
27
|
-
|
|
28
|
-
} else if ("getDefaultVueLanguagePlugins" in
|
|
29
|
-
|
|
28
|
+
if ("getBasePlugins" in r) {
|
|
29
|
+
i = r.getBasePlugins;
|
|
30
|
+
} else if ("getDefaultVueLanguagePlugins" in r) {
|
|
31
|
+
i = r.getDefaultVueLanguagePlugins;
|
|
30
32
|
}
|
|
31
33
|
|
|
32
|
-
var
|
|
34
|
+
var a = r.resolveVueCompilerOptions({});
|
|
33
35
|
|
|
34
|
-
var
|
|
36
|
+
var n;
|
|
35
37
|
|
|
36
|
-
var transform =
|
|
37
|
-
if (!
|
|
38
|
+
var transform = r => {
|
|
39
|
+
if (!s || !i) {
|
|
38
40
|
return;
|
|
39
|
-
} else if (!
|
|
40
|
-
|
|
41
|
+
} else if (!n) {
|
|
42
|
+
(n = i({
|
|
41
43
|
modules: {
|
|
42
44
|
typescript: e,
|
|
43
|
-
"@vue/compiler-dom":
|
|
45
|
+
"@vue/compiler-dom": t
|
|
44
46
|
},
|
|
45
47
|
compilerOptions: {},
|
|
46
48
|
globalTypesHolder: void 0,
|
|
47
|
-
vueCompilerOptions:
|
|
49
|
+
vueCompilerOptions: a
|
|
50
|
+
})).push({
|
|
51
|
+
version: 2,
|
|
52
|
+
parseSFC: (e, t) => o(t),
|
|
53
|
+
updateSFC(e, t) {
|
|
54
|
+
var r = [ e.descriptor.template, e.descriptor.script, e.descriptor.scriptSetup, ...e.descriptor.styles, ...e.descriptor.customBlocks ].filter((e => !!e));
|
|
55
|
+
var o = r.find((e => t.start >= e.loc.start.offset && t.end <= e.loc.end.offset));
|
|
56
|
+
if (!o) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
var s = o.content;
|
|
60
|
+
var i = o.content = o.content.substring(0, t.start - o.loc.start.offset) + t.newText + o.content.substring(t.end - o.loc.start.offset);
|
|
61
|
+
var a = new RegExp(`</\\s*${o.type}\\s*>`);
|
|
62
|
+
if (!!s.match(a) != !!i.match(a)) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
var n = t.newText.length - (t.end - t.start);
|
|
66
|
+
for (var d of r) {
|
|
67
|
+
if (d.loc.start.offset > t.end) {
|
|
68
|
+
d.loc.start.offset += n;
|
|
69
|
+
}
|
|
70
|
+
if (d.loc.end.offset >= t.end) {
|
|
71
|
+
d.loc.end.offset += n;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return e;
|
|
75
|
+
}
|
|
48
76
|
});
|
|
49
77
|
}
|
|
50
|
-
var
|
|
51
|
-
var
|
|
52
|
-
for (var
|
|
53
|
-
if (
|
|
54
|
-
return
|
|
78
|
+
var d = e.ScriptSnapshot.fromString(r.getFullText());
|
|
79
|
+
var f = new s(r.fileName, "vue", d, a, n, ...[ e, !1 ]);
|
|
80
|
+
for (var l of forEachEmbeddedCode(f)) {
|
|
81
|
+
if (l.id.startsWith("script_")) {
|
|
82
|
+
return l;
|
|
55
83
|
}
|
|
56
84
|
}
|
|
57
85
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vue-chunk.mjs","sources":["../../src/ts/transformers/vue.ts"],"sourcesContent":["import ts from 'typescript';\nimport type { VirtualCode } from '@vue/language-core';\nimport * as vueCompilerDOM from '@vue/compiler-dom';\nimport * as vue from '@vue/language-core';\n\nfunction* forEachEmbeddedCode(virtualCode: VirtualCode) {\n yield virtualCode;\n if (virtualCode.embeddedCodes) {\n for (const embeddedCode of virtualCode.embeddedCodes) {\n yield* forEachEmbeddedCode(embeddedCode);\n }\n }\n}\n\nlet VueVirtualCode: typeof vue.VueVirtualCode | undefined;\nif ('VueVirtualCode' in vue) {\n VueVirtualCode = vue.VueVirtualCode;\n} else if ('VueGeneratedCode' in vue) {\n VueVirtualCode = (vue as any).VueGeneratedCode;\n}\n\nlet getBasePlugins: typeof vue.getBasePlugins | undefined;\nif ('getBasePlugins' in vue) {\n getBasePlugins = vue.getBasePlugins;\n} else if ('getDefaultVueLanguagePlugins' in vue) {\n getBasePlugins = (vue as any).getDefaultVueLanguagePlugins;\n}\n\nconst vueCompilerOptions = vue.resolveVueCompilerOptions({});\n\nlet plugins: ReturnType<typeof vue.getBasePlugins> | undefined;\n\nexport const transform = (sourceFile: ts.SourceFile): VirtualCode | undefined => {\n if (!VueVirtualCode || !getBasePlugins) {\n return undefined;\n } else if (!plugins) {\n
|
|
1
|
+
{"version":3,"file":"vue-chunk.mjs","sources":["../../src/ts/transformers/vue.ts"],"sourcesContent":["import ts from 'typescript';\nimport type { VirtualCode } from '@vue/language-core';\nimport * as vueCompilerDOM from '@vue/compiler-dom';\nimport * as vue from '@vue/language-core';\nimport { parse } from '@vue/language-core';\n\nconst useVueFilePlugin: vue.VueLanguagePlugin = (_ctx) => {\n return {\n version: 2,\n\n parseSFC(_fileName, content) {\n return parse(content);\n },\n\n updateSFC(sfc, change) {\n const blocks = [\n sfc.descriptor.template,\n sfc.descriptor.script,\n sfc.descriptor.scriptSetup,\n ...sfc.descriptor.styles,\n ...sfc.descriptor.customBlocks,\n ].filter((block): block is NonNullable<typeof block> => !!block);\n\n const hitBlock = blocks.find(\n (block) => change.start >= block.loc.start.offset && change.end <= block.loc.end.offset\n );\n if (!hitBlock) {\n return;\n }\n\n const oldContent = hitBlock.content;\n const newContent = (hitBlock.content =\n hitBlock.content.substring(0, change.start - hitBlock.loc.start.offset) +\n change.newText +\n hitBlock.content.substring(change.end - hitBlock.loc.start.offset));\n\n // #3449\n const endTagRegex = new RegExp(`</\\\\s*${hitBlock.type}\\\\s*>`);\n const insertedEndTag = !!oldContent.match(endTagRegex) !== !!newContent.match(endTagRegex);\n if (insertedEndTag) {\n return;\n }\n\n const lengthDiff = change.newText.length - (change.end - change.start);\n\n for (const block of blocks) {\n if (block.loc.start.offset > change.end) {\n block.loc.start.offset += lengthDiff;\n }\n if (block.loc.end.offset >= change.end) {\n block.loc.end.offset += lengthDiff;\n }\n }\n\n return sfc;\n },\n };\n};\n\nfunction* forEachEmbeddedCode(virtualCode: VirtualCode) {\n yield virtualCode;\n if (virtualCode.embeddedCodes) {\n for (const embeddedCode of virtualCode.embeddedCodes) {\n yield* forEachEmbeddedCode(embeddedCode);\n }\n }\n}\n\nlet VueVirtualCode: typeof vue.VueVirtualCode | undefined;\nif ('VueVirtualCode' in vue) {\n VueVirtualCode = vue.VueVirtualCode;\n} else if ('VueGeneratedCode' in vue) {\n VueVirtualCode = (vue as any).VueGeneratedCode;\n}\n\nlet getBasePlugins: typeof vue.getBasePlugins | undefined;\nif ('getBasePlugins' in vue) {\n getBasePlugins = vue.getBasePlugins;\n} else if ('getDefaultVueLanguagePlugins' in vue) {\n getBasePlugins = (vue as any).getDefaultVueLanguagePlugins;\n}\n\nconst vueCompilerOptions = vue.resolveVueCompilerOptions({});\n\nlet plugins: ReturnType<typeof vue.getBasePlugins> | undefined;\n\nexport const transform = (sourceFile: ts.SourceFile): VirtualCode | undefined => {\n if (!VueVirtualCode || !getBasePlugins) {\n return undefined;\n } else if (!plugins) {\n const pluginContext = {\n modules: {\n typescript: ts,\n '@vue/compiler-dom': vueCompilerDOM,\n },\n compilerOptions: {},\n globalTypesHolder: undefined,\n vueCompilerOptions,\n };\n plugins = getBasePlugins(pluginContext);\n const vueSfcPlugin = useVueFilePlugin(pluginContext);\n plugins.push(vueSfcPlugin);\n }\n\n const snapshot = ts.ScriptSnapshot.fromString(sourceFile.getFullText());\n const root = new VueVirtualCode(\n sourceFile.fileName,\n 'vue',\n snapshot,\n vueCompilerOptions,\n plugins,\n ...([ts, false] as any as [typeof ts])\n );\n for (const code of forEachEmbeddedCode(root)) if (code.id.startsWith('script_')) return code;\n};\n"],"names":["forEachEmbeddedCode","virtualCode","embeddedCodes","embeddedCode","VueVirtualCode","vue","VueGeneratedCode","getBasePlugins","getDefaultVueLanguagePlugins","vueCompilerOptions","resolveVueCompilerOptions","plugins","transform","sourceFile","modules","typescript","ts","vueCompilerDOM","compilerOptions","globalTypesHolder","undefined","push","version","parseSFC","_fileName","content","parse","updateSFC","sfc","change","blocks","descriptor","template","script","scriptSetup","styles","customBlocks","filter","block","hitBlock","find","start","loc","offset","end","oldContent","newContent","substring","newText","endTagRegex","RegExp","type","match","lengthDiff","length","snapshot","ScriptSnapshot","fromString","getFullText","root","fileName","code","id","startsWith"],"mappings":";;;;;;;;AA2DA,UAAUA,oBAAoBC;QACtBA;EACN,IAAIA,EAAYC;IACd,KAAK,IAAMC,KAAgBF,EAAYC;aAC9BF,oBAAoBG;;;AAGjC;;AAEA,IAAIC;;AACJ,IAAI,oBAAoBC;EACtBD,IAAiBC,EAAID;OAChB,IAAI,sBAAsBC;EAC/BD,IAAkBC,EAAYC;;;AAGhC,IAAIC;;AACJ,IAAI,oBAAoBF;EACtBE,IAAiBF,EAAIE;OAChB,IAAI,kCAAkCF;EAC3CE,IAAkBF,EAAYG;;;AAGhC,IAAMC,IAAqBJ,EAAIK,0BAA0B,CAAA;;AAEzD,IAAIC;;AAESC,IAAAA,YAAaC;EACxB,KAAKT,MAAmBG;IACtB;SACK,KAAKI,GAAS;KAUnBA,IAAUJ,EATY;MACpBO,SAAS;QACPC,YAAYC;QACZ,qBAAqBC;;MAEvBC,iBAAiB,CAAE;MACnBC,wBAAmBC;MACnBX;QAIMY,KA9FH;MACLC,SAAS;MAETC,UAAQA,CAACC,GAAWC,MACXC,EAAMD;MAGfE,SAAAA,CAAUC,GAAKC;QACb,IAAMC,IAAS,EACbF,EAAIG,WAAWC,UACfJ,EAAIG,WAAWE,QACfL,EAAIG,WAAWG,gBACZN,EAAIG,WAAWI,WACfP,EAAIG,WAAWK,eAClBC,QAAQC,OAAgDA;QAE1D,IAAMC,IAAWT,EAAOU,MACrBF,KAAUT,EAAOY,SAASH,EAAMI,IAAID,MAAME,UAAUd,EAAOe,OAAON,EAAMI,IAAIE,IAAID;QAEnF,KAAKJ;UACH;;QAGF,IAAMM,IAAaN,EAASd;QAC5B,IAAMqB,IAAcP,EAASd,UAC3Bc,EAASd,QAAQsB,UAAU,GAAGlB,EAAOY,QAAQF,EAASG,IAAID,M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