-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Feature/detect outside variables strands #8208
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev-2.0
Are you sure you want to change the base?
Changes from 2 commits
84832ba
9bb6ec3
795e50c
4440d6e
2129ca0
1694f2d
70644dc
09c3f46
9307929
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| import { detectOutsideVariableReferences } from '../../../src/strands/strands_transpiler.js'; | ||
| import { suite, test } from '../../../test/js/spec.js'; | ||
|
|
||
| suite('Strands Transpiler - Outside Variable Detection', function() { | ||
| test('should detect undeclared variable in uniform', function() { | ||
| // Simulate code that references mouseX (not declared in strand context) | ||
| const code = ` | ||
| const myUniform = uniform('color', () => { | ||
| return mouseX; // mouseX is not declared | ||
|
||
| }); | ||
| `; | ||
|
|
||
| const errors = detectOutsideVariableReferences(code); | ||
| assert.ok(errors.length > 0, 'Should detect at least one error'); | ||
| assert.ok(errors.some(e => e.variable === 'mouseX'), 'Should detect mouseX'); | ||
| }); | ||
|
|
||
| test('should not error when variable is declared', function() { | ||
| // Variable is declared before use | ||
| const code = ` | ||
| let myVar = 5; | ||
| const myUniform = uniform('color', () => { | ||
| return myVar; // myVar is declared | ||
| }); | ||
| `; | ||
|
|
||
| const errors = detectOutsideVariableReferences(code); | ||
| assert.equal(errors.length, 0, 'Should not detect errors'); | ||
| }); | ||
|
|
||
| test('should detect multiple undeclared variables', function() { | ||
| const code = ` | ||
| const myUniform = uniform('color', () => { | ||
| return mouseX + windowWidth; // Both not declared | ||
| }); | ||
| `; | ||
|
|
||
| const errors = detectOutsideVariableReferences(code); | ||
| assert.equal(errors.length, 2, 'Should detect both mouseX and windowWidth'); | ||
| }); | ||
|
|
||
| test('should handle empty code', function() { | ||
| const errors = detectOutsideVariableReferences(''); | ||
| assert.equal(errors.length, 0, 'Empty code should have no errors'); | ||
| }); | ||
| }); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right now it looks like
scopeChaindoesn't get used really -- it gets added to and then popped off the array before anything reads from it. Maybe consider doing the check all in one step, so that when you encounter a variable identifier, you can check to see if it should be visible in the current scope?