phetsims / paper-land

Build and explore multimodal web interactives with pieces of paper!
https://phetsims.github.io/paper-land/
MIT License
19 stars 3 forks source link

Add an error when you refer to a model component that is not selected #235

Closed jessegreenberg closed 6 months ago

jessegreenberg commented 7 months ago

If you forget to select a component but still use it, it will toString it (or worse) and projects won't behave as expected. It would be much better if this were caught earlier so that the user knows they are using a component that is not selected for use.

jessegreenberg commented 6 months ago

Its pretty difficult to throw an error for this because. My thought was that we would throw an error any time a component is referenced in the control function that exists in all model components, but is not selected in dependencies. But each program generates its code in isolation and doesn't have a reference to all model components.

Instead, we could more easily provide a warning near the monaco editor when a component is referenced but not listed in dependencies.

jessegreenberg commented 6 months ago

Nope, this would still require a significant amount of work. The CreatorMonacoEditor needs all model components and provided model components at each usage to determine what the acceptable variables are for its code block.

I also looked into using acorn to find undeclared variables in the generated code but it doesn't support that. We would need to walk through the AST and look for undeclared variablese manually. That, while difficult, is probably the best approach for this issue. But i am going to let that go for now and start to work on a more important enhancement.