Skip to content

Disallow var#92

Merged
cs01 merged 2 commits intomainfrom
disallow-var
Mar 5, 2026
Merged

Disallow var#92
cs01 merged 2 commits intomainfrom
disallow-var

Conversation

@cs01
Copy link
Owner

@cs01 cs01 commented Mar 5, 2026

Summary

  • Disallow the var keyword in ChadScript source files
  • Emit a compile-time error with file/line/column on var usage
  • let and const are the only allowed variable declaration keywords

Details

var is semantically confusing (function-scoped, hoisted) and provides no value over let/const. This change rejects it at parse time rather than silently compiling it.

Error format:

src/main.ts:5:3: error: 'var' is not allowed; use 'let' or 'const'

Files changed

  • src/parser-ts/transformer.ts — catches var in top-level variable statements
  • src/parser-ts/handlers/statements.ts — catches var in function bodies and for/for-of/for-in initializers
  • src/parser-native/transformer.ts — catches var in both the tree-sitter variable_declaration node and for-loop keyword scanning

Test plan

  • var x = 5 at top level → compiler error, exit 1
  • var x = 5 inside a function → compiler error, exit 1
  • for (var i = 0; ...) → compiler error, exit 1
  • for (var x of arr) → compiler error, exit 1
  • let and const continue to work normally
  • All 276 existing tests pass

@cs01 cs01 merged commit bcc013a into main Mar 5, 2026
12 checks passed
@cs01 cs01 deleted the disallow-var branch March 5, 2026 06:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant