Skip to content

Commit c9c086b

Browse files
authored
chore: mark parser classes as internal, reduce dts size (#44)
Saves ~4kB of .d.ts files contents
1 parent 24464d5 commit c9c086b

15 files changed

+429
-537
lines changed

src/api.test.ts

Lines changed: 53 additions & 105 deletions
Large diffs are not rendered by default.

src/arena.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ export const ATTR_FLAG_NONE = 0 // No flag
8989
export const ATTR_FLAG_CASE_INSENSITIVE = 1 // [attr=value i]
9090
export const ATTR_FLAG_CASE_SENSITIVE = 2 // [attr=value s]
9191

92+
/** @internal */
9293
export class CSSDataArena {
9394
private buffer: ArrayBuffer
9495
private view: DataView

src/lexer.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ export interface LexerPosition {
6868
token_column: number
6969
}
7070

71+
/** @internal */
7172
export class Lexer {
7273
source: string
7374
pos: number

src/parse-anplusb.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { CHAR_MINUS_HYPHEN, CHAR_PLUS } from './string-utils'
1111
import { skip_whitespace_forward } from './parse-utils'
1212
import { CSSNode } from './css-node'
1313

14+
/** @internal */
1415
export class ANplusBParser {
1516
private lexer: Lexer
1617
private arena: CSSDataArena

src/parse-atrule-prelude.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import { str_equals } from './string-utils'
2828
import { trim_boundaries, skip_whitespace_forward } from './parse-utils'
2929
import { CSSNode } from './css-node'
3030

31+
/** @internal */
3132
export class AtRulePreludeParser {
3233
private lexer: Lexer
3334
private arena: CSSDataArena

src/parse-options.test.ts

Lines changed: 16 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
import { describe, it, expect } from 'vitest'
2-
import { Parser } from './parse'
2+
import { parse } from './parse'
33
import { SELECTOR_LIST, DECLARATION, IDENTIFIER } from './arena'
44

55
describe('Parser Options', () => {
66
const css = 'body { color: red; }'
77

88
describe('Default behavior (all parsing enabled)', () => {
99
it('should parse values and selectors by default', () => {
10-
const parser = new Parser(css)
11-
const root = parser.parse()
10+
const root = parse(css)
1211
const rule = root.first_child
1312

1413
// Check selector is parsed with detailed structure
@@ -27,8 +26,7 @@ describe('Parser Options', () => {
2726
})
2827

2928
it('should parse values and selectors with explicit options', () => {
30-
const parser = new Parser(css, { parse_values: true, parse_selectors: true })
31-
const root = parser.parse()
29+
const root = parse(css, { parse_values: true, parse_selectors: true })
3230
const rule = root.first_child
3331

3432
// Check selector is parsed
@@ -46,8 +44,7 @@ describe('Parser Options', () => {
4644

4745
describe('parse_values disabled', () => {
4846
it('should not parse value details when parse_values is false', () => {
49-
const parser = new Parser(css, { parse_values: false })
50-
const root = parser.parse()
47+
const root = parse(css, { parse_values: false })
5148
const rule = root.first_child
5249

5350
// Selector should still be parsed
@@ -67,8 +64,7 @@ describe('Parser Options', () => {
6764
})
6865

6966
it('should handle complex values without parsing', () => {
70-
const parser = new Parser('div { margin: 10px 20px; }', { parse_values: false })
71-
const root = parser.parse()
67+
const root = parse('div { margin: 10px 20px; }', { parse_values: false })
7268
const rule = root.first_child
7369
const selector = rule?.first_child
7470
const block = selector?.next_sibling
@@ -80,8 +76,7 @@ describe('Parser Options', () => {
8076
})
8177

8278
it('should handle function values without parsing', () => {
83-
const parser = new Parser('div { color: rgb(255, 0, 0); }', { parse_values: false })
84-
const root = parser.parse()
79+
const root = parse('div { color: rgb(255, 0, 0); }', { parse_values: false })
8580
const rule = root.first_child
8681
const selector = rule?.first_child
8782
const block = selector?.next_sibling
@@ -95,8 +90,7 @@ describe('Parser Options', () => {
9590

9691
describe('parseSelectors disabled', () => {
9792
it('should not parse selector details when parseSelectors is false', () => {
98-
const parser = new Parser(css, { parse_selectors: false })
99-
const root = parser.parse()
93+
const root = parse(css, { parse_selectors: false })
10094
const rule = root.first_child
10195

10296
// Selector should exist but be simple (just NODE_SELECTOR_LIST, no detailed structure)
@@ -114,8 +108,7 @@ describe('Parser Options', () => {
114108
})
115109

116110
it('should handle complex selectors without parsing', () => {
117-
const parser = new Parser('div.container#app { color: red; }', { parse_selectors: false })
118-
const root = parser.parse()
111+
const root = parse('div.container#app { color: red; }', { parse_selectors: false })
119112
const rule = root.first_child
120113
const selector = rule?.first_child
121114

@@ -125,8 +118,7 @@ describe('Parser Options', () => {
125118
})
126119

127120
it('should handle selector lists without parsing', () => {
128-
const parser = new Parser('div, p, span { color: red; }', { parse_selectors: false })
129-
const root = parser.parse()
121+
const root = parse('div, p, span { color: red; }', { parse_selectors: false })
130122
const rule = root.first_child
131123
const selector = rule?.first_child
132124

@@ -138,8 +130,7 @@ describe('Parser Options', () => {
138130

139131
describe('Both parse_values and parseSelectors disabled', () => {
140132
it('should not parse details for values or selectors', () => {
141-
const parser = new Parser(css, { parse_values: false, parse_selectors: false })
142-
const root = parser.parse()
133+
const root = parse(css, { parse_values: false, parse_selectors: false })
143134
const rule = root.first_child
144135

145136
// Selector should be simple
@@ -164,8 +155,7 @@ describe('Parser Options', () => {
164155
color: rgb(255, 0, 0);
165156
}
166157
`
167-
const parser = new Parser(css, { parse_values: false, parse_selectors: false })
168-
const root = parser.parse()
158+
const root = parse(css, { parse_values: false, parse_selectors: false })
169159
const rule = root.first_child
170160

171161
const selector = rule?.first_child
@@ -194,8 +184,7 @@ describe('Parser Options', () => {
194184
margin: 10px 20px 30px 40px;
195185
}
196186
`
197-
const parser = new Parser(css, { parse_values: false })
198-
const root = parser.parse()
187+
const root = parse(css, { parse_values: false })
199188
const rule = root.first_child
200189
const selector = rule?.first_child
201190

@@ -219,8 +208,7 @@ describe('Parser Options', () => {
219208
.another-complex[data-attr~="value"] { margin: 0; }
220209
#very-specific-id:not(.excluded) { padding: 10px; }
221210
`
222-
const parser = new Parser(css, { parse_selectors: false })
223-
const root = parser.parse()
211+
const root = parse(css, { parse_selectors: false })
224212

225213
// Can quickly count rules without parsing complex selectors
226214
let count = 0
@@ -236,8 +224,7 @@ describe('Parser Options', () => {
236224

237225
describe('Options validation', () => {
238226
it('should accept empty options object', () => {
239-
const parser = new Parser(css, {})
240-
const root = parser.parse()
227+
const root = parse(css, {})
241228
const rule = root.first_child
242229
const selector = rule?.first_child
243230
const block = selector?.next_sibling
@@ -249,8 +236,7 @@ describe('Parser Options', () => {
249236
})
250237

251238
it('should accept partial options', () => {
252-
const parser = new Parser(css, { parse_values: false })
253-
const root = parser.parse()
239+
const root = parse(css, { parse_values: false })
254240
const rule = root.first_child
255241
const selector = rule?.first_child
256242
const block = selector?.next_sibling
@@ -263,11 +249,10 @@ describe('Parser Options', () => {
263249
})
264250

265251
it('should accept skip_comments with parsing options', () => {
266-
const parser = new Parser('/* test */ body { color: red; }', {
252+
const root = parse('/* test */ body { color: red; }', {
267253
skip_comments: true,
268254
parse_values: false,
269255
})
270-
const root = parser.parse()
271256
const rule = root.first_child
272257

273258
// Comment should be skipped

src/parse-selector.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ import {
6969
import { ANplusBParser } from './parse-anplusb'
7070
import { CSSNode } from './css-node'
7171

72+
/** @internal */
7273
export class SelectorParser {
7374
private lexer: Lexer
7475
private arena: CSSDataArena

src/parse-utils.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ export function parse_dimension(text: string): { value: number; unit: string } {
6464
* @param pos - Starting position
6565
* @param end - End boundary (exclusive)
6666
* @returns New position after skipping whitespace
67+
* @internal
6768
*/
6869
export function skip_whitespace_forward(source: string, pos: number, end: number): number {
6970
while (pos < end && is_whitespace(source.charCodeAt(pos))) {
@@ -79,6 +80,7 @@ export function skip_whitespace_forward(source: string, pos: number, end: number
7980
* @param pos - Starting position
8081
* @param end - End boundary (exclusive)
8182
* @returns New position after skipping whitespace/comments
83+
* @internal
8284
*/
8385
export function skip_whitespace_and_comments_forward(source: string, pos: number, end: number): number {
8486
while (pos < end) {
@@ -115,6 +117,7 @@ export function skip_whitespace_and_comments_forward(source: string, pos: number
115117
* @param pos - Starting position (exclusive, scanning backward from pos-1)
116118
* @param start - Start boundary (inclusive, won't go before this)
117119
* @returns New position after skipping whitespace/comments backward
120+
* @internal
118121
*/
119122
export function skip_whitespace_and_comments_backward(source: string, pos: number, start: number): number {
120123
while (pos > start) {
@@ -151,6 +154,7 @@ export function skip_whitespace_and_comments_backward(source: string, pos: numbe
151154
* @param start - Start offset in source
152155
* @param end - End offset in source
153156
* @returns [trimmed_start, trimmed_end] or null if all whitespace/comments
157+
* @internal
154158
*
155159
* Skips whitespace (space, tab, newline, CR, FF) and CSS comments from both ends
156160
* of the specified range. Returns the trimmed boundaries or null if the range

0 commit comments

Comments
 (0)