@vuebro/loader-sfc 2.2.0 → 2.2.2

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.
@@ -21,8 +21,8 @@ const fetchText = async (url) => {
21
21
  };
22
22
  /* -------------------------------------------------------------------------- */
23
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;
24
+ const styleErrors = [], { compiler: { expressionPlugins, ...restCompilerOptions } = {} } = options ?? {}, { descriptor, errors: parseErrors } = parse((await (await fetchText(filename)).text()) || "<template></template>", options?.parse), { script, scriptSetup, slotted, styles, template } = descriptor;
25
+ let moduleWarning = "";
26
26
  const id = `data-v-${hash(filename)}`, langs = new Set([script, scriptSetup].flatMap((scriptBlock) => {
27
27
  const { lang = "js" } = scriptBlock ?? {};
28
28
  return [
@@ -30,39 +30,48 @@ export default async (filename, options) => {
30
30
  ...(/tsx?$/.test(lang) ? ["typescript"] : []),
31
31
  ];
32
32
  })), compilerOptions = {
33
- expressionPlugins: [...langs],
33
+ expressionPlugins: [
34
+ ...new Set([...(expressionPlugins ?? []), ...langs]),
35
+ ],
34
36
  scopeId: id,
35
37
  slotted,
38
+ ...restCompilerOptions,
36
39
  }, scoped = styles.some(({ scoped }) => scoped), component = scoped ? { __scopeId: id } : {}, templateOptions = {
37
40
  compilerOptions,
38
41
  scoped,
39
42
  slotted,
40
43
  }, scriptOptions = {
41
44
  id,
42
- inlineTemplate: true,
43
45
  templateOptions,
44
46
  ...options?.script,
45
- }, isCompileTemplate = template && (!scriptSetup || !scriptOptions.inlineTemplate), style = !(document.getElementById(id) instanceof HTMLStyleElement)
46
- ? Promise.all(styles.map(async ({ content, module = false, scoped = false, src }) => {
47
- const { code, errors } = await compileStyleAsync({
48
- filename,
49
- id,
50
- scoped,
51
- source: src ? await (await fetchText(src)).text() : content,
52
- ...options?.style,
53
- });
54
- if (module && !moduleWarning)
55
- moduleWarning = Error("<style module> is not supported in the playground.");
56
- styleErrors.push(...errors);
57
- return code;
47
+ }, style = !(document.getElementById(id) instanceof HTMLStyleElement)
48
+ ? Promise.all(styles.map(async ({ content, module, scoped = false, src }) => {
49
+ const modules = !!module;
50
+ if (modules) {
51
+ moduleWarning =
52
+ "<style module> is not supported in the playground.";
53
+ return "";
54
+ }
55
+ else {
56
+ const { code, errors } = await compileStyleAsync({
57
+ filename,
58
+ id,
59
+ modules,
60
+ scoped,
61
+ source: src ? await (await fetchText(src)).text() : content,
62
+ ...options?.style,
63
+ });
64
+ styleErrors.push(...errors);
65
+ return code;
66
+ }
58
67
  }))
59
68
  : Promise.resolve([]), sucraseOptions = {
60
69
  jsxRuntime: "preserve",
61
70
  transforms: [...langs],
62
71
  }, { ast, content: source = "" } = template ?? {}, { bindings, content, warnings: scriptWarnings, } = script || scriptSetup ? compileScript(descriptor, scriptOptions) : {};
63
- if (bindings && isCompileTemplate)
72
+ if (bindings)
64
73
  compilerOptions.bindingMetadata = bindings;
65
- const { code, errors: templateErrors, tips: templateTips, } = isCompileTemplate
74
+ const { code, errors: templateErrors, tips: templateTips, } = template && (!scriptSetup || !scriptOptions.inlineTemplate)
66
75
  ? compileTemplate({
67
76
  ...ast,
68
77
  filename,
package/package.json CHANGED
@@ -21,7 +21,7 @@
21
21
  "url": "git+https://github.com/vuebro/loader-sfc.git"
22
22
  },
23
23
  "license": "AGPL-3.0-only",
24
- "version": "2.2.0",
24
+ "version": "2.2.2",
25
25
  "type": "module",
26
26
  "main": "./dist/loader-sfc.js",
27
27
  "types": "./dist/loader-sfc.d.ts",