Skip to content

refactor(lexer): TS contextual keyword 30개를 identifier로 통합#309

Merged
ohah merged 2 commits intomainfrom
refactor/ts-keyword-to-identifier
Mar 23, 2026
Merged

refactor(lexer): TS contextual keyword 30개를 identifier로 통합#309
ohah merged 2 commits intomainfrom
refactor/ts-keyword-to-identifier

Conversation

@ohah
Copy link
Copy Markdown
Owner

@ohah ohah commented Mar 23, 2026

Summary

  • number, string, boolean 등 30개 TS contextual keyword를 개별 토큰(kw_number 등) 대신 일반 identifier로 토큰화
  • 파서에 isContextual/eatContextual/expectContextual/isContextualAny 헬퍼 추가
  • esbuild/oxc/SWC와 동일한 방식으로, export default function number(x) 같은 버그가 원천 차단됨
  • 코드 65줄 감소 (157 추가, 222 삭제)

변경 파일 (8개)

  • token.zig: 30개 TS keyword enum 제거, keywords 맵에서 제거
  • parser.zig: contextual keyword 헬퍼 4개 추가
  • ts.zig, statement.zig, expression.zig, module.zig, declaration.zig, binding.zig: 토큰 매칭 → 문자열 비교로 전환

Test plan

  • zig build test — 1260개 유닛 테스트 통과
  • 스모크 테스트 38/38 통과
  • d3 번들 실행 정상 (scaleLinear(50) = 0.5)
  • 성능 동일 (10k줄 파싱 ~14ms → ~14ms)

🤖 Generated with Claude Code

number, string, boolean 등 TS contextual keyword를 개별 토큰(kw_number 등)
대신 일반 identifier로 토큰화하도록 변경. 파서에서 isContextual/eatContextual
헬퍼로 문자열 비교하여 TS 키워드를 판별.

이유: 개별 토큰 방식은 식별자 위치에서 TS 키워드를 누락하는 버그를 유발
(d3의 `export default function number(x)` 등). esbuild/oxc/SWC와 동일하게
identifier로 토큰화하면 이런 류의 버그가 원천 차단됨.

변경:
- token.zig: 30개 TS keyword enum 제거, keywords 맵에서 제거
- parser.zig: isContextual/eatContextual/expectContextual/isContextualAny 헬퍼 추가
- ts.zig: parsePrimaryType 등 TS 타입 키워드를 문자열 비교로 변환
- statement.zig: type/namespace/module/declare/abstract를 .identifier arm에서 처리
- expression.zig: as/satisfies를 isContextual로 변환
- module.zig: import/export의 as/type/assert를 헬퍼로 변환
- declaration.zig: class member modifier를 isContextualAny로 변환
- binding.zig: parameter property readonly를 isContextual로 변환

성능: 벤치마크 동일 (10k줄 파싱 ~14ms → ~14ms)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@ohah ohah added the enhancement New feature or request label Mar 23, 2026
@ohah ohah self-assigned this Mar 23, 2026
@ohah ohah added the enhancement New feature or request label Mar 23, 2026
@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 23, 2026

Smoke Test Results (CI)

Smoke Test Results

Project ZTS Size Time esbuild Size Time rolldown Size Time
lodash-es OK 50KB 56ms OK 65KB 55ms OK 100KB 483ms
preact OK 13KB 3ms OK 15KB 7ms OK 13KB 119ms
date-fns OK 38KB 28ms OK 47KB 43ms OK 78KB 137ms
uuid OK 3KB 3ms OK 2KB 9ms OK 2KB 116ms
zod OK 413KB 67ms OK 507KB 35ms OK 90KB 154ms
axios OK 350KB 34ms OK 415KB 27ms OK 377KB 145ms
toolkit OK 141KB 13ms OK 51KB 17ms OK 39KB 125ms
rxjs OK 43KB 29ms OK 371KB 38ms OK 309KB 164ms
immer OK 40KB 5ms OK 26KB 9ms OK 23KB 115ms
superjson OK 22KB 6ms OK 26KB 10ms OK 24KB 121ms
express OK 778KB 68ms OK 1127KB 40ms OK 880KB 168ms
react OK 51KB 5ms OK 64KB 9ms OK 54KB 120ms
commander OK 69KB 7ms OK 124KB 12ms OK 104KB 116ms
eventemitter3 OK 6KB 2ms OK 8KB 6ms OK 9KB 118ms
ms OK 3KB 2ms OK 4KB 7ms OK 4KB 113ms
dotenv OK 13KB 2ms OK 16KB 7ms OK 13KB 115ms
jsonwebtoken OK 113KB 23ms OK 139KB 17ms OK 142KB 126ms
bcryptjs OK 27KB 4ms OK 32KB 8ms OK 37KB 111ms
clsx OK 1KB 2ms OK 1KB 6ms OK 1KB 121ms
tiny-invariant OK 0KB 1ms OK 1KB 6ms OK 1KB 108ms
tanstack-query OK 77KB 9ms OK 57KB 11ms OK 49KB 117ms
fast-glob OK 155KB 24ms OK 193KB 20ms OK 182KB 129ms
micromatch OK 73KB 10ms OK 93KB 11ms OK 94KB 123ms
semver OK 53KB 13ms OK 67KB 11ms OK 52KB 123ms
debug OK 14KB 3ms OK 20KB 7ms OK 20KB 115ms
chalk OK 10KB 3ms OK 16KB 7ms OK 14KB 117ms
yaml OK 163KB 22ms OK 262KB 20ms OK 228KB 145ms
yargs OK 198KB 19ms OK 222KB 18ms OK 202KB 133ms
effect OK 679KB 361ms OK 477KB 161ms OK 368KB 279ms
vue OK 284KB 25ms OK 2007KB 78ms OK 1603KB 273ms
svelte OK 122KB 19ms OK 5KB 17ms OK 4KB 123ms
solid-js OK 43KB 5ms OK 2KB 8ms OK 2KB 118ms
three OK 1150KB 76ms OK 414KB 84ms OK 267KB 205ms
graphql OK 60KB 24ms OK 606KB 33ms OK 547KB 154ms
supabase OK 326KB 33ms OK 652KB 29ms OK 610KB 152ms
mobx OK 152KB 11ms OK 271KB 23ms OK 234KB 149ms
jotai OK 22KB 4ms FAIL - 7ms OK 20KB 132ms
valtio OK 14KB 3ms OK 8KB 7ms OK 8KB 119ms

38/38 projects built successfully.

Auto-generated by CI on 2026-03-23 17:06 UTC

@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 23, 2026

Benchmark Results (CI)

macos-latest

transpile — small (100 lines)

Tool Avg (ms) Min (ms) Max (ms) vs fastest
ZTS 3 2 3 1.0x
esbuild 6 5 8 2.0x
Bun 8 6 14 2.7x
oxc (node) 70 63 78 23.3x
SWC 159 138 183 53.0x

transpile — medium (1K lines)

Tool Avg (ms) Min (ms) Max (ms) vs fastest
ZTS 5 4 7 1.0x
esbuild 6 5 8 1.2x
Bun 7 6 8 1.4x
oxc (node) 62 60 65 12.4x
SWC 141 136 150 28.2x

transpile — large (5K lines)

Tool Avg (ms) Min (ms) Max (ms) vs fastest
esbuild 5 5 6 1.0x
ZTS 8 8 8 1.6x
Bun 11 10 11 2.2x
oxc (node) 65 60 70 13.0x
SWC 158 140 182 31.6x

bundle — small (10 modules)

Tool Avg (ms) Min (ms) Max (ms) vs fastest
ZTS 3 3 3 1.0x
Bun 8 8 9 2.7x
esbuild 9 9 10 3.0x
rolldown 126 125 129 42.0x
rspack 145 133 155 48.3x
webpack 411 339 468 137.0x

bundle — medium (50 modules)

Tool Avg (ms) Min (ms) Max (ms) vs fastest
ZTS 5 4 5 1.0x
Bun 9 8 10 1.8x
esbuild 11 11 13 2.2x
rolldown 124 118 129 24.8x
rspack 142 136 147 28.4x
webpack 444 409 501 88.8x

bundle — large (200 modules)

Tool Avg (ms) Min (ms) Max (ms) vs fastest
ZTS 11 11 13 1.0x
Bun 13 12 13 1.2x
esbuild 18 17 18 1.6x
rolldown 141 130 158 12.8x

ubuntu-latest

transpile — small (100 lines)

Tool Avg (ms) Min (ms) Max (ms) vs fastest
ZTS 1 1 2 1.0x
esbuild 2 2 3 2.0x
Bun 3 3 3 3.0x
oxc (node) 30 29 31 30.0x
SWC 95 93 97 95.0x

transpile — medium (1K lines)

Tool Avg (ms) Min (ms) Max (ms) vs fastest
esbuild 2 2 2 1.0x
ZTS 4 4 4 2.0x
Bun 5 4 5 2.5x
oxc (node) 30 29 30 15.0x
SWC 99 97 102 49.5x

transpile — large (5K lines)

Tool Avg (ms) Min (ms) Max (ms) vs fastest
esbuild 2 2 2 1.0x
Bun 11 11 12 5.5x
ZTS 15 15 16 7.5x
oxc (node) 31 30 31 15.5x
SWC 119 117 121 59.5x

bundle — small (10 modules)

Tool Avg (ms) Min (ms) Max (ms) vs fastest
ZTS 2 2 2 1.0x
Bun 5 5 5 2.5x
esbuild 6 6 6 3.0x
rspack 114 114 114 57.0x
rolldown 115 110 119 57.5x
webpack 529 522 534 264.5x

bundle — medium (50 modules)

Tool Avg (ms) Min (ms) Max (ms) vs fastest
ZTS 4 4 5 1.0x
Bun 6 5 6 1.5x
esbuild 8 8 8 2.0x
rolldown 119 115 125 29.8x
rspack 120 119 121 30.0x
webpack 528 521 534 132.0x

bundle — large (200 modules)

Tool Avg (ms) Min (ms) Max (ms) vs fastest
Bun 10 9 10 1.0x
esbuild 16 15 17 1.6x
ZTS 21 21 22 2.1x
rolldown 124 122 131 12.4x

windows-latest

transpile — small (100 lines)

Tool Avg (ms) Min (ms) Max (ms) vs fastest
ZTS 8 8 9 1.0x
Bun 19 18 19 2.4x
oxc (node) 63 62 65 7.9x

transpile — medium (1K lines)

Tool Avg (ms) Min (ms) Max (ms) vs fastest
ZTS 11 10 11 1.0x
Bun 19 19 19 1.7x
oxc (node) 63 61 64 5.7x

transpile — large (5K lines)

Tool Avg (ms) Min (ms) Max (ms) vs fastest
ZTS 19 19 20 1.0x
Bun 19 19 19 1.0x
oxc (node) 63 62 64 3.3x

bundle — small (10 modules)

Tool Avg (ms) Min (ms) Max (ms) vs fastest
ZTS 10 9 10 1.0x
Bun 33 32 35 3.3x

bundle — medium (50 modules)

Tool Avg (ms) Min (ms) Max (ms) vs fastest
ZTS 16 16 16 1.0x
Bun 35 35 36 2.2x

bundle — large (200 modules)

Tool Avg (ms) Min (ms) Max (ms) vs fastest
ZTS 41 41 42 1.0x
Bun 45 45 46 1.1x

Auto-generated by CI on 2026-03-23 17:06 UTC

- module.zig: 직접 소스 슬라이싱 → isContextual("source")로 통일
- expression.zig: isContextual 중복 호출 제거 (tokenText 1회 캐시)
- ts.zig: 10개 문자열 비교 체인 → StaticStringMap(ts_type_keywords) 룩업
- declaration.zig: modifier 문자열 목록 → ts_class_modifiers 상수 추출
- parser.zig: expectContextual에서 addError 호출로 통일

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@ohah ohah merged commit d214644 into main Mar 23, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant