@vuebro/loader-sfc 2.1.1 → 2.2.1
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/dist/loader-sfc.d.ts +7 -1
- package/dist/loader-sfc.esm-browser.prod.js +2254 -2255
- package/dist/loader-sfc.js +42 -26
- package/package.json +1 -1
package/dist/loader-sfc.js
CHANGED
|
@@ -20,56 +20,65 @@ const fetchText = async (url) => {
|
|
|
20
20
|
}
|
|
21
21
|
};
|
|
22
22
|
/* -------------------------------------------------------------------------- */
|
|
23
|
-
export default async (filename) => {
|
|
24
|
-
const
|
|
25
|
-
|
|
23
|
+
export default async (filename, options) => {
|
|
24
|
+
const styleErrors = [], { descriptor, errors: parseErrors } = parse((await (await fetchText(filename)).text()) || "<template></template>"), { script, scriptSetup, slotted, styles, template } = descriptor;
|
|
25
|
+
let moduleWarning;
|
|
26
|
+
const id = `data-v-${hash(filename)}`, langs = new Set([script, scriptSetup].flatMap((scriptBlock) => {
|
|
26
27
|
const { lang = "js" } = scriptBlock ?? {};
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
})
|
|
32
|
-
const compilerOptions = {
|
|
28
|
+
return [
|
|
29
|
+
...(/[jt]sx$/.test(lang) ? ["jsx"] : []),
|
|
30
|
+
...(/tsx?$/.test(lang) ? ["typescript"] : []),
|
|
31
|
+
];
|
|
32
|
+
})), compilerOptions = {
|
|
33
33
|
expressionPlugins: [...langs],
|
|
34
34
|
scopeId: id,
|
|
35
35
|
slotted,
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
36
|
+
...options?.compiler,
|
|
37
|
+
}, scoped = styles.some(({ scoped }) => scoped), component = scoped ? { __scopeId: id } : {}, templateOptions = {
|
|
38
|
+
compilerOptions,
|
|
39
|
+
scoped,
|
|
40
|
+
slotted,
|
|
41
|
+
}, scriptOptions = {
|
|
42
|
+
id,
|
|
43
|
+
templateOptions,
|
|
44
|
+
...options?.script,
|
|
45
|
+
}, isCompileTemplate = template && (!scriptSetup || !scriptOptions.inlineTemplate), style = !(document.getElementById(id) instanceof HTMLStyleElement)
|
|
40
46
|
? Promise.all(styles.map(async ({ content, module = false, scoped = false, src }) => {
|
|
41
47
|
const { code, errors } = await compileStyleAsync({
|
|
42
48
|
filename,
|
|
43
49
|
id,
|
|
44
50
|
scoped,
|
|
45
51
|
source: src ? await (await fetchText(src)).text() : content,
|
|
52
|
+
...options?.style,
|
|
46
53
|
});
|
|
47
|
-
if (module)
|
|
48
|
-
|
|
49
|
-
|
|
54
|
+
if (module && !moduleWarning)
|
|
55
|
+
moduleWarning = Error("<style module> is not supported in the playground.");
|
|
56
|
+
styleErrors.push(...errors);
|
|
50
57
|
return code;
|
|
51
58
|
}))
|
|
52
|
-
: Promise.resolve([]),
|
|
53
|
-
|
|
59
|
+
: Promise.resolve([]), sucraseOptions = {
|
|
60
|
+
jsxRuntime: "preserve",
|
|
61
|
+
transforms: [...langs],
|
|
62
|
+
}, { ast, content: source = "" } = template ?? {}, { bindings, content, warnings: scriptWarnings, } = script || scriptSetup ? compileScript(descriptor, scriptOptions) : {};
|
|
63
|
+
if (bindings && isCompileTemplate)
|
|
54
64
|
compilerOptions.bindingMetadata = bindings;
|
|
55
|
-
const { code, errors, tips } =
|
|
65
|
+
const { code, errors: templateErrors, tips: templateTips, } = isCompileTemplate
|
|
56
66
|
? compileTemplate({
|
|
57
|
-
...
|
|
58
|
-
compilerOptions,
|
|
67
|
+
...ast,
|
|
59
68
|
filename,
|
|
60
69
|
id,
|
|
61
|
-
scoped,
|
|
62
|
-
slotted,
|
|
63
70
|
source,
|
|
71
|
+
...templateOptions,
|
|
72
|
+
...options?.template,
|
|
64
73
|
})
|
|
65
74
|
: {};
|
|
66
75
|
const [styleResult, scriptResult, templateResult] = await Promise.all([
|
|
67
76
|
style,
|
|
68
77
|
content
|
|
69
|
-
? inject(langs.size ? transform(content,
|
|
78
|
+
? inject(langs.size ? transform(content, sucraseOptions).code : content)
|
|
70
79
|
: Promise.resolve(undefined),
|
|
71
80
|
code
|
|
72
|
-
? inject(langs.size ? transform(code,
|
|
81
|
+
? inject(langs.size ? transform(code, sucraseOptions).code : code)
|
|
73
82
|
: Promise.resolve(undefined),
|
|
74
83
|
]), textContent = styleResult.join("\n").trim();
|
|
75
84
|
if (textContent) {
|
|
@@ -80,7 +89,14 @@ export default async (filename) => {
|
|
|
80
89
|
}
|
|
81
90
|
Object.assign(component, scriptResult?.default);
|
|
82
91
|
Object.assign(component, templateResult);
|
|
83
|
-
[
|
|
92
|
+
[
|
|
93
|
+
...parseErrors,
|
|
94
|
+
...(scriptWarnings ?? []),
|
|
95
|
+
...(templateTips ?? []),
|
|
96
|
+
...(templateErrors ?? []),
|
|
97
|
+
...styleErrors,
|
|
98
|
+
...(moduleWarning ? [moduleWarning] : []),
|
|
99
|
+
].forEach((msg) => {
|
|
84
100
|
console.log(msg);
|
|
85
101
|
});
|
|
86
102
|
return component;
|
package/package.json
CHANGED