feat: finalize language parser and loader#11
Merged
Conversation
Phase 0 (infra):
- Vitest 0.24 → 1.6 with v8 coverage, baseline 88% statements
- CI workflow (lint + test matrix + build + compat summary)
- 14 Vietnamese keyword aliases (biến, nhường, đây, rỗng, là kiểu,
tĩnh, công khai, riêng tư, bảo vệ, lấy, gán, vô cực, của, lặp)
- CONTRIBUTING with parser node template + Unicode boundary rules
- scripts/compat-summary.mjs dashboard
- docs/compatibility.md matrix + docs/roadmap.md
Phase 1 (P1 syntax):
- ArrowFunctionExpression (single/paren/multi/empty params, expr + block body)
- Default parameters (AssignmentPattern)
- Rest parameters (RestElement, position validation)
- SpreadElement (array/object/call)
- ObjectPattern destructuring (shorthand, rename, default, rest, nested)
- ArrayPattern destructuring (hole, default, rest, nested, mixed)
- TemplateLiteral with interpolation + nested braces
- for-of / for-in / for-await-of statements
- Object shorthand + computed key
Phase 2 (P2 syntax):
- Private field #x (ClassPrivateProperty)
- Getter/setter in class + object literal (kind: get|set)
- Yield expression + yield*, wired into Expression + StatementListItem
- Optional chaining: ?.prop, ?.[k], chained
- Compound assignment (16 operators): +=, -=, *=, /=, %=, **=, &=,
|=, ^=, <<=, >>=, >>>=, ||=, &&=, ??=
- Numeric literals: hex 0x, octal 0o, binary 0b, BigInt 123n, separator 1_000
- RegExp literal /pattern/flags with context-aware tokenization
- String escape sequences (\n, \x41, \u{1F600}, etc.)
- Labeled break/continue, fix ContinueStatement BREAK→CONTINUE bug
Phase 3 (mangling):
- Identifier mangling: xin chào → xin_chào (Unicode direct)
instead of _xin_ch224o (codepoint encoding)
Phase 4 (errors):
- VietScriptError class with file:line:col + snippet + caret
- Parser.filename support
Phase 5 (CLI):
- packages/cli: vietscript run/build/watch/check
- Source maps via @babel/generator
- examples/hello/hello.vjs sample
Tokenizer improvements:
- Template literal scan with nested ${...} brace tracking
- Regex literal scan with context detection (REGEX_PRECEDING_TOKENS)
- Multi-word identifier truncation when embedded keyword found
- Operator specs reordered longest-first to fix += vs + conflict
Test results: 70 → 249 tests (100% pass)
Coverage: 79.85% → 88.22% statements, 71.23% → 84.12% branches
Matrix: 40.8% → 71.6% complete, 21.5% → 4.5% missing
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
- ConditionalExpression (?:) with ternaryDepth state to distinguish from labels - NewExpression (new A(args)) - Fix UnaryExpression: keyword tokens (DELETE/VOID/TYPEOF) instead of literal strings - Fix BinaryExpression: support keyword operators (instanceof, in) and full operator set - Add missing operator cases in Expression.ts (&, |, !=, !==, instanceof, in) - Fix tokenizer for `xoá` and `khi mà` (trailing non-ASCII char boundary) - Test coverage: while, do-while, ternary, unary/binary operators, this, new Tests: 249 → 269 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
- ClassDeclaration: support `extends` keyword (in addition to paren form) - ClassProperty: access modifiers (công khai/riêng tư/bảo vệ), constructor keyword as method name, method detection by `(`, generator method `*foo()` - Expression: Super expression (call + member), Infinity literal dispatch - InfinityIdentifier: new literal class, name = "Infinity" - UndefinedIdentifier: fix name to lowercase "undefined" (was "Undefined") - WithStatement: actually parse object + body (was empty) - StatementList: handle leading `;` as EmptyStatement (not infinite loop) - Test coverage: primitives (NaN, Infinity, null, undefined, booleans), while/do-while, ternary ?:, debugger/with/empty/comments, class extras (static, accessibility, super call, generator method) Tests: 269 → 291 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
- ImportDeclaration: detect `sử dụng(` as dynamic import, transform to ExpressionStatement wrapping CallExpression with Import callee - StatementListItem: route IMPORT/EXPORT keywords to Declaration dispatcher - Update compatibility matrix: 30+ items 🟡/❌ → ✅ after verification tests Matrix: 71.6% → 95.5% complete (128/134 features) Tests: 291 → 294 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
- TaggedTemplateExpression: identifier followed by template literal - Verify optional catch binding works (param: null) - Update matrix: 95.5% → 97% complete Tests: 294 → 298 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
- Fix Vite plugin: use @babel/generator to emit JS (was returning JSON AST) - Fix Webpack plugin: same fix + sourcemap support - Both plugins now support source maps - New package @vietscript/stdlib with Vietnamese wrappers: ghi/ghi_lỗi/ghi_cảnh_báo (console), tự_số/tự_chuỗi/tự_bool (conversions), kiểu (typeof), độ_dài (length), đợi (sleep), ngẫu_nhiên (random), tròn/làm_tròn_xuống/làm_tròn_lên (Math), giá_trị_tuyệt_đối (abs), nhỏ_nhất/lớn_nhất (min/max), phân_tích_JSON/JSON_sang_chuỗi, tải_văn_bản/tải_JSON (fetch) - CLI run: write tmp file alongside source so stdlib and other workspace deps resolve correctly (not in OS tmpdir anymore) - examples/hello/stdlib-test.vjs — demo 100% Vietnamese syntax Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
- packages/cli/src/loader.ts — Node loader hook that transpiles .vjs on import - packages/cli/src/register.ts — convenience registration entry - Usage: node --import '@vietscript/cli/register' file.vjs - Works with imports from other .vjs files and @vietscript/stdlib Example usage verified: node --import '@vietscript/cli/register' examples/hello/stdlib-test.vjs Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
- @vietscript/cli/bun-plugin for Bun.plugin() API - Update compat matrix: Vite/Webpack/Node loader/Bun plugin/Stdlib all ✅ - Custom element <vi-script> moved to post-v1 (plugins cover the use case) Matrix: 97% → 98.5% (only Import assertions + JSDoc remain, both niche) Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
- Rewrite getting-started.md with CLI commands, Node loader, Bun plugin, Vite/Webpack, stdlib usage - Add docs/stdlib.md — full API reference for @vietscript/stdlib Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Exclude CLI and stdlib from coverage report (they're integration-tested via example runs, not unit-tested). Coverage now properly reflects parser quality. Coverage: parser + shared = 92.44% statements / 85.88% branches / 96.25% functions Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Update to cover new capabilities: destructuring, arrow functions, default/rest params, async/generator, destructuring params, etc. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Comprehensive changelog covering all 9 phases of work in this session: infra, P1 syntax, P2 syntax, mangling, error quality, CLI, plugins, stdlib. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
if.md: includes ternary + switch-case. for.md: covers for/for-of/for-in/for-await-of/while/do-while/labeled/destructuring. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
- operators.md: full operator list including compound assignment, logical assignment (\|\|= &&= ??=), bitwise shifts, keyword operators (typeof/instanceof/in/delete/void), spread, optional chaining - class.md (new): inheritance, static, getter/setter, access modifiers, private fields #, generator & async methods - module.md (new): import/export forms, dynamic import - Remove stale do-while.md and switch-case.md (merged into for.md / if.md) Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
- Expression.applyPostfix(): loop to handle member/call/optional/logical chains on any primary expression (e.g., array literal . method, call result ?? fallback, etc.) - Expression.THIS case: handle member access, method call, assignment, postfix update (++/--) after `this.member` - MemberExpression: handle PrivateName (#field) after `.` - Identifier regex: allow digits after first letter (mèo1, x2, etc.) - VariableDeclarator: init defaults to null (was `undefined` Identifier, which broke for-of const form at Babel layer) - StatementList: throw VietScriptError with source offset instead of plain SyntaxError Demo: full-features.vjs now runs end-to-end with class + private field + destructuring + spread + optional chaining + try/catch + for-of + destructuring pattern. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
- 6 new tests: [].map(...), obj literal, logical chain, optional+logical, foo().bar, foo().bar() - Fix Expression: apply postfix after CallExpression on identifier (enables foo().bar pattern) Tests: 298 → 304 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
- @vietscript/parser 0.0.1 → 1.0.0-beta.1 - @vietscript/shared 0.0.1 → 1.0.0-beta.1 - @vietscript/cli 0.0.1 → 1.0.0-beta.1 - @vietscript/stdlib 0.0.1 → 1.0.0-beta.1 - @vietscript/plugin-vite 0.0.1 → 1.0.0-beta.1 - @vietscript/plugin-webpack 0.0.1 → 1.0.0-beta.1 Full build + 304/304 tests + examples runs confirmed. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…lement - errors.ts: tests for positionToLocation, formatSnippet, VietScriptError - NewExpression: 3 tests (no args, args, spread) - parser/src/index.ts: remove unused custom element code (was dead code, plugins cover the browser use case) Coverage: 92.44% → 92.85% statements, 84.24% → 85.01% branches Tests: 304 → 318 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…level
- Add tests for throw, return, break, continue, nested blocks
- StatementListItem: route `{` to Statement (BlockStatement as top-level stmt)
Tests: 318 → 324
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Add 8 tests: skip whitespace+comments, empty source, unknown token, complex operators, template with interpolation, regex vs division context, unicode escape. Tests: 324 → 332 Coverage: 92.85% → 93.49% statements Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Complete JS → VietScript keyword mapping + side-by-side class example (demonstrates private fields, getter, static, destructuring, for-of, try-catch, spread, optional chaining) + notes on identifier rules. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Cover: tự_số/tự_chuỗi/tự_bool/kiểu/độ_dài, Math wrappers (tròn, làm_tròn_*, giá_trị_tuyệt_đối, nhỏ_nhất, lớn_nhất, ngẫu_nhiên), JSON (phân_tích_JSON, JSON_sang_chuỗi), async đợi. Tests: 332 → 347 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.