You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I thought it might be useful to statically analyze the user's sketch and determine whether they're using p5.dom and/or p5.sound, and include those libraries in the preview frame if so. This has the benefit of resolving #58 without needing any extra setup or configuration on the part of the author.
escope could make the static analysis task pretty easy. (It could also make implicit-sketch.ts a lot simpler, too.)
Concerns:
This will require us to have a representation of the global symbols of p5.dom/p5.sound in the widget source code, and they could go out of date.
I'm not sure how much extra weight escope will add to the bundled code.
Below is an example snippet I wrote while playing around with escope.
Example escope snippet
"use strict";letesprima=require('esprima');letescope=require('escope');letast=esprima.parse(` var a = 1; function boop() { a += b; } boop`);letscopeManager=escope.analyze(ast);functionisInScope(ref,scope){if(scope.set.has(ref.identifier.name)){returntrue;}if(!scope.upper){returnfalse;}returnisInScope(ref,scope.upper);}scopeManager.scopes.forEach(scope=>{scope.references.forEach(ref=>{console.log(ref.identifier.name,isInScope(ref,scope));});});
The text was updated successfully, but these errors were encountered:
I thought it might be useful to statically analyze the user's sketch and determine whether they're using p5.dom and/or p5.sound, and include those libraries in the preview frame if so. This has the benefit of resolving #58 without needing any extra setup or configuration on the part of the author.
escope
could make the static analysis task pretty easy. (It could also makeimplicit-sketch.ts
a lot simpler, too.)Concerns:
escope
will add to the bundled code.Below is an example snippet I wrote while playing around with
escope
.Example
escope
snippetThe text was updated successfully, but these errors were encountered: