chore: 合并代码

This commit is contained in:
就眠儀式 2022-04-10 12:49:30 +08:00
parent 0060adc843
commit b2b849a60d
5 changed files with 35 additions and 30 deletions

View File

@ -5,4 +5,4 @@ export type ButtonNativeType = "button" | "submit" | "reset";
export const ButtonEmits = { export const ButtonEmits = {
click: (evt: MouseEvent) => evt instanceof MouseEvent, click: (evt: MouseEvent) => evt instanceof MouseEvent,
} };

View File

@ -7,7 +7,7 @@ export default {
<script setup lang="ts"> <script setup lang="ts">
import "./index.less"; import "./index.less";
import { computed } from "vue"; import { computed } from "vue";
import { BooleanOrString } from '../../types'; import { BooleanOrString } from "../../types";
export interface LayContainerProps { export interface LayContainerProps {
fluid?: BooleanOrString; fluid?: BooleanOrString;

View File

@ -1,4 +1,4 @@
import type { BuiltInParserName } from 'prettier' import type { BuiltInParserName } from "prettier";
const scriptRe = /<script[^>]*>([\s\S]*)<\/script>/; const scriptRe = /<script[^>]*>([\s\S]*)<\/script>/;
const exportDefaultRe = /export\s*default\s*\{([\s\S]*)\}\;?\s*<\/script>/; const exportDefaultRe = /export\s*default\s*\{([\s\S]*)\}\;?\s*<\/script>/;
@ -16,7 +16,10 @@ const MAIN_FILE_NAME = "App.vue";
* @returns URI hsah playground * @returns URI hsah playground
} }
*/ */
export const usePlayGround = async (source: string, convertSetupSugar: boolean) => { export const usePlayGround = async (
source: string,
convertSetupSugar: boolean
) => {
const decodeCode = source; const decodeCode = source;
const scriptResult = decodeCode.match(scriptRe); const scriptResult = decodeCode.match(scriptRe);
@ -98,26 +101,28 @@ function trimBr(str: string): string {
* @returns * @returns
*/ */
async function formatCode(filename: string, data: string) { async function formatCode(filename: string, data: string) {
const { format } = await import('prettier/standalone') const { format } = await import("prettier/standalone");
const parserTypeScript = await import('prettier/parser-typescript').then( const parserTypeScript = await import("prettier/parser-typescript").then(
(m) => m.default (m) => m.default
) );
const parserBabel = await import('prettier/parser-babel').then( const parserBabel = await import("prettier/parser-babel").then(
(m) => m.default (m) => m.default
) );
const parserHtml = await import('prettier/parser-html').then((m) => m.default) const parserHtml = await import("prettier/parser-html").then(
(m) => m.default
);
let code = data; let code = data;
let parser: BuiltInParserName let parser: BuiltInParserName;
if (filename.endsWith('.vue')) { if (filename.endsWith(".vue")) {
parser = 'vue' parser = "vue";
} else if (filename.endsWith('.js')) { } else if (filename.endsWith(".js")) {
parser = 'babel' parser = "babel";
} else if (filename.endsWith('.ts')) { } else if (filename.endsWith(".ts")) {
parser = 'typescript' parser = "typescript";
} else if (filename.endsWith('.json')) { } else if (filename.endsWith(".json")) {
parser = 'json' parser = "json";
} else { } else {
return return;
} }
code = format(code, { code = format(code, {
parser, parser,
@ -125,7 +130,7 @@ async function formatCode(filename: string, data: string) {
semi: false, // 语句末尾打印分号 semi: false, // 语句末尾打印分号
singleQuote: true, // 使用单引号 singleQuote: true, // 使用单引号
vueIndentScriptAndStyle: false, // 是否缩进 Vue 文件中的 script 和 style 标签 vueIndentScriptAndStyle: false, // 是否缩进 Vue 文件中的 script 和 style 标签
}) });
return code; return code;
} }