Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export default function TagMultiSelect({
isSelected: value.indexOf(item.value) > -1,
label: item.label,
value: item.value,
onClick: () => onClick(item.value, item)
onClick: () => onClick(item.value)
});
}
return (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ReactNode, useState } from 'react';
import { ReactNode } from 'react';
import { Tooltip, Drawer, Button, Card, theme } from 'antd';
import Icon from '@/components/Icons';
import type { DrawerProps } from 'antd';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ const NoticeIcon: React.FC<NoticeIconProps> & {
);
};

const { className, count, bell } = props;
const { count, bell } = props;

const [visible, setVisible] = useControllableValue<boolean>({
value: props.popupVisible,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { List, Avatar, theme, Tag } from 'antd';
import { List, Avatar, theme } from 'antd';
import classNames from 'classnames';
import styles from './NoticeList.module.css';
const { useToken } = theme;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ const NoticeIconView: React.FC = () => {
);

const noticeData = getNoticeData(notices);
const unreadMsg = getUnreadData(noticeData || {});
const unreadMsg = getUnreadData(noticeData);

const changeReadState = (id: string) => {
setNotices(
Expand Down
19 changes: 1 addition & 18 deletions demos/vite-react/src/pages/dashboard/components/SalesCard.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Card, Tabs, Space, DatePicker } from 'antd';
import { Card, Tabs } from 'antd';
import { Column } from '@ant-design/plots';
import '../style.css';
const { RangePicker } = DatePicker;

interface SalesCardProps {
loading: boolean;
Expand Down Expand Up @@ -77,21 +76,5 @@ function SalesCard({ loading, data }: SalesCardProps) {
);
}

function TabBarExtraContent() {
return (
<Space size="large">
<a>今日</a>
<a>本周</a>
<a>本月</a>
<a>本年</a>
<RangePicker
style={{ width: 256 }}
onChange={(date, string) => {
console.log(date, string);
}}
/>
</Space>
);
}

export default SalesCard;
2 changes: 1 addition & 1 deletion demos/vite-react/src/pages/dashboard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default function Analysis() {
<IntroduceRow loading={loading} visitData={data.visitData || []} />
<Row gutter={16}>
<Col span={16}>
<SalesCard loading={loading} data={data?.salesData || []} />
<SalesCard loading={loading} data={data.salesData || []} />
</Col>
<Col span={8}>
<Ranking loading={loading} data={Array.from({ length: 18 })} />
Expand Down
2 changes: 1 addition & 1 deletion demos/vite-react/src/store/reducer/userSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const userSlice = createSlice({
extraReducers: (builder) => {
builder
.addCase(login.fulfilled, (state, action) => {
const { UserInfo, SessionKey, MenuItems = [] } = action.payload;
const { UserInfo, SessionKey } = action.payload;
state.userInfo = UserInfo;
state.token = SessionKey;
state.isLogin = true;
Expand Down
4 changes: 2 additions & 2 deletions demos/vite-vue2/src/utils/axios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export const get = (
.catch((err) => {
console.error(err, 'Get err')
if (notice) {
let message = err?.data?.desc
let message = err.data?.desc
if (err.message && err.message.indexOf('timeout') !== -1) {
message = notice.timeoutMsg || '接口超时'
}
Expand Down Expand Up @@ -96,7 +96,7 @@ export const post = (
.catch((err) => {
console.error(err, 'Post err')
if (notice) {
let message = err?.data?.desc
let message = err.data?.desc
if (err.message.indexOf('timeout') !== -1) {
message = notice.timeoutMsg || '接口超时'
}
Expand Down
1 change: 0 additions & 1 deletion demos/webpack-vue-tsx/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
</template>

<script lang="ts" setup>
import { defineComponent } from 'vue';
import HelloWorld from './components/HelloWorld.vue';
import Detail from './components/detail';
import About from './components/about.vue';
Expand Down
2 changes: 1 addition & 1 deletion demos/webpack-vue-tsx/src/components/detail.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { defineComponent, onMounted, ref } from 'vue';
import { defineComponent, onMounted } from 'vue';

export default defineComponent({
setup(props, { emit }) {
Expand Down
17 changes: 5 additions & 12 deletions packages/code-inspector-plugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@ import { TurbopackCodeInspectorPlugin } from '@code-inspector/turbopack';
import { MakoCodeInspectorPlugin } from '@code-inspector/mako';
import {
CodeOptions,
fileURLToPath,
getEnvVariable,
resetFileRecord,
} from '@code-inspector/core';
import chalk from 'chalk';
/* v8 ignore next -- import statement branch coverage not testable */
import path, { dirname } from 'path';
import path from 'path';
import { fileURLToPath } from 'url';

export interface CodeInspectorPluginOptions extends CodeOptions {
/**
Expand All @@ -26,8 +25,8 @@ export function CodeInspectorPlugin(options: CodeInspectorPluginOptions): any {
if (!options?.bundler) {
console.log(
chalk.red(
'Please specify the bundler in the options of code-inspector-plugin.'
)
'Please specify the bundler in the options of code-inspector-plugin.',
),
);
return;
}
Expand All @@ -40,13 +39,7 @@ export function CodeInspectorPlugin(options: CodeInspectorPluginOptions): any {
}
}

let compatibleDirname = '';
/* v8 ignore next 5 -- environment-specific: __dirname available in CJS, import.meta.url in ESM */
if (typeof __dirname !== 'undefined') {
compatibleDirname = __dirname;
} else {
compatibleDirname = dirname(fileURLToPath(import.meta.url));
}
const compatibleDirname = path.dirname(fileURLToPath(import.meta.url));
const params = {
...options,
close,
Expand Down
1 change: 1 addition & 0 deletions packages/code-inspector-plugin/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export default defineConfig({
'@code-inspector/mako',
'chalk',
'path',
'url',
],
},
target: ['node8', 'es2015'],
Expand Down
3 changes: 0 additions & 3 deletions packages/core/src/server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ function getProjectRoot(): string {
stdio: ['pipe', 'pipe', 'pipe'],
}).trim();
return gitRoot;
/* v8 ignore next 3 -- only runs when not in a git repo */
} catch (error) {
return '';
}
Expand All @@ -28,7 +27,6 @@ function getProjectRoot(): string {
// 项目根目录
export const ProjectRootPath = getProjectRoot();
export function getRelativePath(filePath: string): string {
/* v8 ignore next 5 -- branch depends on git repo presence at module load time */
if (ProjectRootPath) {
return filePath.replace(`${ProjectRootPath}/`, '');
}
Expand Down Expand Up @@ -97,7 +95,6 @@ export function createServer(
portFinder.getPort(
{ port: options?.port ?? DefaultPort },
(err: Error, port: number) => {
/* v8 ignore next 3 -- error thrown in callback, tested via integration */
if (err) {
throw err;
}
Expand Down
13 changes: 9 additions & 4 deletions packages/core/src/server/transform/transform-jsx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ import importMetaPlugin from '@babel/plugin-syntax-import-meta';
// @ts-expect-error - @babel/plugin-proposal-decorators doesn't provide TypeScript types
import proposalDecorators from '@babel/plugin-proposal-decorators';

export function transformJsx(content: string, filePath: string, escapeTags: EscapeTags) {
export function transformJsx(
content: string,
filePath: string,
escapeTags: EscapeTags,
) {
const s = new MagicString(content);

const ast = parse(content, {
Expand All @@ -27,8 +31,8 @@ export function transformJsx(content: string, filePath: string, escapeTags: Esca

traverse(ast!, {
enter({ node }: any) {
const nodeName = node?.openingElement?.name?.name || '';
const attributes = node?.openingElement?.attributes || [];
const nodeName = node.openingElement?.name?.name || '';
const attributes = node.openingElement?.attributes || [];
if (
node.type === 'JSXElement' &&
nodeName &&
Expand All @@ -37,7 +41,8 @@ export function transformJsx(content: string, filePath: string, escapeTags: Esca
if (
attributes.some(
(attr: any) =>
attr.type !== 'JSXSpreadAttribute' && attr.name?.name === PathName
attr.type !== 'JSXSpreadAttribute' &&
attr.name?.name === PathName,
)
) {
return;
Expand Down
14 changes: 10 additions & 4 deletions packages/core/src/server/transform/transform-svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,20 @@ import MagicString from 'magic-string';
import { EscapeTags, PathName, isEscapeTags } from '../../shared';
import { parse as parseSvelte, walk } from 'svelte/compiler';

export function transformSvelte(content: string, filePath: string, escapeTags: EscapeTags) {
export function transformSvelte(
content: string,
filePath: string,
escapeTags: EscapeTags,
) {
const s = new MagicString(content);

// svelte parse dosen't support ts or scss/less
// so replace the content of <script></script> and <style></style> with space
let replacedContent = content;
const scriptRegex = /<script(?:\s+[a-zA-Z-]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^>\s]*))?)?>[\s\S]*?<\/script>/gi;
const styleRegex = /<style(?:\s+[a-zA-Z-]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^>\s]*))?)?>[\s\S]*?<\/style>/gi;
const scriptRegex =
/<script(?:\s+[a-zA-Z-]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^>\s]*))?)?>[\s\S]*?<\/script>/gi;
const styleRegex =
/<style(?:\s+[a-zA-Z-]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^>\s]*))?)?>[\s\S]*?<\/style>/gi;
const scriptMatches = content.match(scriptRegex) || [];
const styleMatches = content.match(styleRegex) || [];
[...scriptMatches, ...styleMatches].forEach((match) => {
Expand All @@ -23,7 +29,7 @@ export function transformSvelte(content: string, filePath: string, escapeTags: E
if (
node.type === 'Element' &&
!isEscapeTags(escapeTags, node.name) &&
!node?.attributes?.some((attr: any) => attr?.name === PathName)
!node.attributes?.some((attr: any) => attr?.name === PathName)
) {
const insertPosition = node.start + node.name.length + 1;
const line = countLines(content, node.start) + 1;
Expand Down
30 changes: 12 additions & 18 deletions packages/core/src/server/transform/transform-vue-pug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@ export interface PugFileInfo {
const AttributeNodeType = 6;
export const pugMap = new Map<string, PugFileInfo>(); // 使用了 pug 模板的 vue 文件集合

/* v8 ignore next 14 -- defensive checks: column undefined branches rarely triggered by Pug parser */
function belongTemplate(
export function belongTemplate(
target: AstLocation,
start: AstLocation,
end: AstLocation
end: AstLocation,
) {
return (
(target.line > start.line && target.line < end.line) ||
Expand All @@ -32,16 +31,15 @@ function belongTemplate(
}

interface TransformPugParams {
node: pug.Node;
node: pug.Node | null | undefined;
templateNode: ElementNode;
s: MagicString;
escapeTags: EscapeTags;
filePath: string;
}

function transformPugAst(params: TransformPugParams) {
export function transformPugAst(params: TransformPugParams) {
const { node, templateNode, escapeTags, s, filePath } = params;
/* v8 ignore next 3 -- defensive guard: node.block can be null for empty Pug elements */
if (!node) {
return;
}
Expand All @@ -58,7 +56,7 @@ function transformPugAst(params: TransformPugParams) {
const belongToTemplate = belongTemplate(
nodeLocation,
templateNode.loc.start,
templateNode.loc.end
templateNode.loc.end,
);
if (
belongToTemplate &&
Expand All @@ -77,8 +75,10 @@ function transformPugAst(params: TransformPugParams) {
const attr = node.attrs[i];
if (['class', 'id'].includes(attr.name) && !attr.mustEscape) {
insertPosition =
// @ts-expect-error - Pug attr type not typed
offsets[attr.line + lineOffset - 1] + attr.column + (attr.val.length - 2);
offsets[attr.line + lineOffset - 1] +
attr.column +
// @ts-expect-error - attr.val is not typed
(attr.val.length - 2);
}
}
}
Expand All @@ -94,14 +94,12 @@ function transformPugAst(params: TransformPugParams) {
transformPugAst({ ...params, node: node.block });
} else if (['Case', 'Code', 'When', 'Each', 'While'].includes(node.type)) {
if ((node as pug.MixinNode).block) {
/* v8 ignore next 3 -- defensive fallback: nodes array always exists when block exists */
((node as pug.MixinNode).block?.nodes || []).forEach((childNode) => {
transformPugAst({ ...params, node: childNode });
});
}
// @ts-expect-error - Pug Conditional type not exported
} else if (node.type === 'Conditional') {
/* v8 ignore next 7 -- defensive fallbacks: Pug Conditional nodes always have consequent/alternate structure */
// @ts-expect-error - Pug Conditional consequent/alternate properties not typed
(node.consequent?.nodes || []).forEach((childNode) => {
transformPugAst({ ...params, node: childNode });
Expand All @@ -122,12 +120,11 @@ export function isPugTemplate(templateNode: ElementNode | undefined): boolean {
if (!templateNode) {
return false;
}
/* v8 ignore next 9 -- defensive fallback: templateNode.props is always an array in valid Vue SFCs */
return (templateNode.props || []).some(
(prop) =>
prop.type === AttributeNodeType &&
prop.name === 'lang' &&
prop.value?.content === 'pug'
prop.value?.content === 'pug',
);
}

Expand Down Expand Up @@ -159,7 +156,7 @@ export function transformPugTemplate(
filePath: string,
templateNode: ElementNode,
escapeTags: EscapeTags,
s: MagicString
s: MagicString,
): void {
// Calculate and store line offsets
const offsets = calculateLineOffsets(content);
Expand All @@ -168,10 +165,7 @@ export function transformPugTemplate(
// Create temporary content with template section preserved
const tempContent =
' '.repeat(templateNode.loc.start.offset - 0) +
content.slice(
templateNode.loc.start.offset,
templateNode.loc.end.offset
) +
content.slice(templateNode.loc.start.offset, templateNode.loc.end.offset) +
' '.repeat(content.length - templateNode.loc.end.offset);

// Parse and transform Pug AST
Expand Down
Loading
Loading