Skip to content

Commit 031d1aa

Browse files
AVGVSTVS96claudeampcode-com
committed
chore: remove redundant comments, keep decision justifications
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude <noreply@anthropic.com> Amp-Thread-ID: https://ampcode.com/threads/T-019b0c3d-971d-734e-903d-d043fab85ea1 Co-authored-by: Amp <amp@ampcode.com>
1 parent 7b3a44f commit 031d1aa

File tree

11 files changed

+17
-329
lines changed

11 files changed

+17
-329
lines changed

TODO.md

Lines changed: 0 additions & 80 deletions
This file was deleted.

package/src/core.ts

Lines changed: 1 addition & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -39,49 +39,13 @@ export {
3939
createJavaScriptRawEngine,
4040
} from 'shiki/engine/javascript';
4141

42-
/**
43-
* Highlight code with shiki (core bundle)
44-
*
45-
* @param code - Code to highlight
46-
* @param lang - Language (bundled or custom)
47-
* @param theme - Theme (bundled, multi-theme, or custom)
48-
* @param options - react-shiki options + shiki options (highlighter required)
49-
* @returns Highlighted code based on outputFormat option:
50-
* - 'react' (default): ReactNode
51-
* - 'html': string
52-
* - 'tokens': TokensResult
53-
*
54-
* @example
55-
* ```tsx
56-
* import { createHighlighterCore, createOnigurumaEngine } from 'react-shiki/core';
57-
*
58-
* const highlighter = await createHighlighterCore({
59-
* themes: [import('@shikijs/themes/github-light'), import('@shikijs/themes/github-dark')],
60-
* langs: [import('@shikijs/langs/typescript')],
61-
* engine: createOnigurumaEngine(import('shiki/wasm'))
62-
* });
63-
*
64-
* // Default React output
65-
* const highlighted = useShikiHighlighter(code, 'typescript', 'github-dark', {
66-
* highlighter
67-
* });
68-
*
69-
* // Token output for custom rendering
70-
* const tokens = useShikiHighlighter(code, 'typescript', 'github-dark', {
71-
* highlighter,
72-
* outputFormat: 'tokens'
73-
* });
74-
* ```
75-
*
76-
* Core bundle (minimal). For plug-and-play: `react-shiki` or `react-shiki/web`
77-
*/
42+
/** Core bundle (minimal). Requires custom highlighter. For plug-and-play: `react-shiki` or `react-shiki/web` */
7843
export const useShikiHighlighter = <F extends OutputFormat = 'react'>(
7944
code: string,
8045
lang: Language,
8146
themeInput: Theme | Themes,
8247
options: HighlighterOptions<F> = {} as HighlighterOptions<F>
8348
): OutputFormatMap[F] | null => {
84-
// Validate that highlighter is provided
8549
const highlighter = validateCoreHighlighter(options.highlighter);
8650

8751
return useBaseHook(
@@ -93,10 +57,6 @@ export const useShikiHighlighter = <F extends OutputFormat = 'react'>(
9357
);
9458
};
9559

96-
/**
97-
* ShikiHighlighter component using a custom highlighter.
98-
* Requires a highlighter to be provided.
99-
*/
10060
export const ShikiHighlighter = createShikiHighlighterComponent(
10161
useShikiHighlighter
10262
);

package/src/index.ts

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -37,37 +37,7 @@ export {
3737
createJavaScriptRawEngine,
3838
} from 'shiki/engine/javascript';
3939

40-
/**
41-
* Highlight code with shiki (full bundle)
42-
*
43-
* @param code - Code to highlight
44-
* @param lang - Language (bundled or custom)
45-
* @param theme - Theme (bundled, multi-theme, or custom)
46-
* @param options - react-shiki options + shiki options
47-
* @returns Highlighted code based on outputFormat option:
48-
* - 'react' (default): ReactNode
49-
* - 'html': string
50-
* - 'tokens': TokensResult
51-
*
52-
* @example
53-
* ```tsx
54-
* // Default React output
55-
* const highlighted = useShikiHighlighter(code, 'typescript', 'github-dark');
56-
*
57-
* // HTML output
58-
* const html = useShikiHighlighter(code, 'typescript', 'github-dark', {
59-
* outputFormat: 'html'
60-
* });
61-
*
62-
* // Token output for custom rendering
63-
* const tokens = useShikiHighlighter(code, 'typescript', 'github-dark', {
64-
* outputFormat: 'tokens'
65-
* });
66-
* ```
67-
*
68-
* Full bundle (~6.4MB minified, 1.2MB gzipped).
69-
* For smaller bundles: `react-shiki/web` or `react-shiki/core`
70-
*/
40+
/** Full bundle (~6.4MB). For smaller: `react-shiki/web` or `react-shiki/core` */
7141
export const useShikiHighlighter = <F extends OutputFormat = 'react'>(
7242
code: string,
7343
lang: Language,
@@ -83,10 +53,6 @@ export const useShikiHighlighter = <F extends OutputFormat = 'react'>(
8353
);
8454
};
8555

86-
/**
87-
* ShikiHighlighter component using the full bundle.
88-
* Includes all languages and themes for maximum compatibility.
89-
*/
9056
export const ShikiHighlighter = createShikiHighlighterComponent(
9157
useShikiHighlighter
9258
);

package/src/lib/component.tsx

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,9 @@ import type {
1212
import type { ReactNode } from 'react';
1313
import { forwardRef } from 'react';
1414

15-
/**
16-
* Output formats the component can render.
17-
* 'tokens' returns raw data requiring custom rendering - use the hook directly.
18-
*/
15+
// 'tokens' not included: returns raw data, use hook directly for custom rendering
1916
type ComponentRenderableFormat = 'react' | 'html';
2017

21-
/**
22-
* Props for the ShikiHighlighter component.
23-
* Extends HighlighterOptions but restricts outputFormat to component-supported values.
24-
*/
2518
export interface ShikiHighlighterProps
2619
extends Omit<HighlighterOptions, 'outputFormat'> {
2720
/**
@@ -113,10 +106,6 @@ export interface ShikiHighlighterProps
113106
as?: React.ElementType;
114107
}
115108

116-
/**
117-
* Base ShikiHighlighter component factory.
118-
* Creates a component that uses the provided hook implementation.
119-
*/
120109
export const createShikiHighlighterComponent = (
121110
useShikiHighlighterImpl: UseShikiHighlighter
122111
) => {

package/src/lib/hook.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,13 @@ import { resolveLanguage, resolveTheme } from './resolvers';
2424
import { buildShikiOptions } from './options';
2525
import { transformOutput } from './output';
2626

27-
/**
28-
* Factory function type for creating highlighter instances.
29-
* Different entry points provide different implementations.
30-
*/
27+
// Each entry point (index, web, core) provides a different factory for bundle optimization
3128
type HighlighterFactory = (
3229
langsToLoad: ShikiLanguageRegistration,
3330
themesToLoad: Theme[],
3431
engine?: Awaitable<RegexEngine>
3532
) => Promise<Highlighter | HighlighterCore>;
3633

37-
/**
38-
* Base hook for syntax highlighting using Shiki.
39-
* Generic parameter narrows return type based on outputFormat option.
40-
*/
4134
export const useShikiHighlighter = <F extends OutputFormat = 'react'>(
4235
code: string,
4336
lang: Language,
@@ -73,6 +66,7 @@ export const useShikiHighlighter = <F extends OutputFormat = 'react'>(
7366

7467
const shikiOptions = useMemo(
7568
() => buildShikiOptions(languageId, themeResult, stableOpts),
69+
// Revs ensure recompute even if useStableOptions returns same reference
7670
[languageId, themeResult, langRev, themeRev, optsRev]
7771
);
7872

package/src/lib/options.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
/**
2-
* Options builder for constructing Shiki configuration from react-shiki options.
3-
* Extracts option building logic from the hook for cleaner separation of concerns.
4-
*/
5-
61
import type {
72
CodeToHastOptions,
83
CodeOptionsSingleTheme,
@@ -19,9 +14,6 @@ const DEFAULT_THEMES: Themes = {
1914
dark: 'github-dark',
2015
};
2116

22-
/**
23-
* Build theme options for Shiki based on theme configuration
24-
*/
2517
const buildThemeOptions = (
2618
themeResult: ThemeResult
2719
):
@@ -40,10 +32,6 @@ const buildThemeOptions = (
4032
} as CodeOptionsSingleTheme<BundledTheme>;
4133
};
4234

43-
/**
44-
* Build complete Shiki options from react-shiki options.
45-
* Handles theme configuration, transformers, and format-specific logic.
46-
*/
4735
export const buildShikiOptions = <F extends OutputFormat>(
4836
languageId: string,
4937
themeResult: ThemeResult,

package/src/lib/output.ts

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
/**
2-
* Output transformers for converting Shiki highlighter output to different formats.
3-
*/
4-
51
import type { ReactNode } from 'react';
62
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
73
import { toJsxRuntime } from 'hast-util-to-jsx-runtime';
@@ -18,13 +14,13 @@ import type {
1814

1915
import type { OutputFormat, OutputFormatMap } from './types';
2016

21-
/**
22-
* Shiki's Highlighter methods are parameterized by BundledLanguage/BundledTheme,
23-
* but we accept dynamic string values. This type widens the method signatures.
24-
*/
17+
// Widens Shiki's method signatures to accept dynamic string values for lang/theme
2518
type LooseHighlighter = (Highlighter | HighlighterCore) & {
2619
codeToTokens(code: string, options: CodeToTokensOptions): TokensResult;
27-
codeToTokensBase(code: string, options: CodeToTokensBaseOptions): ThemedToken[][];
20+
codeToTokensBase(
21+
code: string,
22+
options: CodeToTokensBaseOptions
23+
): ThemedToken[][];
2824
};
2925

3026
type TransformContext = {
@@ -34,9 +30,6 @@ type TransformContext = {
3430
isMultiTheme: boolean;
3531
};
3632

37-
/**
38-
* Transform highlighted code to React nodes via HAST
39-
*/
4033
const transformToReact = ({
4134
highlighter,
4235
code,
@@ -48,24 +41,20 @@ const transformToReact = ({
4841
Fragment,
4942
});
5043

51-
/**
52-
* Transform highlighted code to HTML string
53-
*/
5444
const transformToHtml = ({
5545
highlighter,
5646
code,
5747
options,
5848
}: TransformContext): string => highlighter.codeToHtml(code, options);
5949

60-
/**
61-
* Transform highlighted code to themed tokens with metadata.
62-
*/
6350
const transformToTokens = ({
6451
highlighter,
6552
code,
6653
options,
6754
isMultiTheme,
6855
}: TransformContext): TokensResult => {
56+
// Multi-theme: codeToTokens returns full TokensResult with all theme variants
57+
// Single-theme: codeToTokensBase returns just tokens, we construct the rest
6958
if (isMultiTheme) {
7059
return highlighter.codeToTokens(code, options as CodeToTokensOptions);
7160
}
@@ -89,18 +78,12 @@ const transformToTokens = ({
8978
};
9079
};
9180

92-
/**
93-
* Registry of output transformers keyed by format
94-
*/
9581
const outputTransformers = {
9682
react: transformToReact,
9783
html: transformToHtml,
9884
tokens: transformToTokens,
9985
} as const;
10086

101-
/**
102-
* Transform highlighter output to the specified format.
103-
*/
10487
export const transformOutput = <F extends OutputFormat>(
10588
format: F,
10689
highlighter: Highlighter | HighlighterCore,

0 commit comments

Comments
 (0)