DrSensor / DrSensor/p5-global2instance
Declarations within Functions get duplicated
- Dominant language
- JavaScript
- Stars
- 19
- Forks
- 7
- PR merge metrics
- No merged PRs in 30d
Description
I stumbled upon this repo and its been crazy useful so far so thank you!
I've discovered that when a declaration is made within a function, it gets copied to the local scope when querying for Variable Declarations (line 62).
This leads to errors when using let statements in loops, etc. They also don't seem to get parsed properly, like TWO_PI won't get prefixed.
Any idea how I could go about fixing this? I've never used esquery or anything before. So far my hacky solution is ignoring Declarations with a column > 0.
Example
INPUT:
```
function setup () {
createCanvas(width, 400);
};
function draw () {
background(200);
let d = TWO_PI;
let p = TWO_PI;
}
```
OUTPUT:
```
export default function (sketch) {
let d = TWO_PI; // doubled
let p = TWO_PI; // doubled
sketch.setup = function () {
sketch.createCanvas(sketch.width, 400)
};
sketch.draw = function () {
sketch.background(200);
let d = sketch.TWO_PI; // doubled
let p = sketch.TWO_PI // doubled
};
}
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.