-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Update sketch verifier to check for redefinitions and print friendly messages #7326
base: dev-2.0
Are you sure you want to change the base?
Conversation
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.
Nice work on this! The one thing I'd want to get a bit of clarification on is some of the false positive cases -- I wonder if that's from treating some p5 classes as globals when they no longer need to be?
// reference on the p5.js website. | ||
function generateFriendlyError(errorType, name, line) { | ||
const url = `https://p5js.org/reference/#/p5/${name}`; | ||
const message = `${errorType} "${name}" on line ${line} is being redeclared and conflicts with a p5.js ${errorType.toLowerCase()}. JavaScript does not declaring a ${errorType.toLowerCase()} more than once. p5.js reference: ${url}.`; |
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.
Looks like we maybe lost a verb in here:
const message = `${errorType} "${name}" on line ${line} is being redeclared and conflicts with a p5.js ${errorType.toLowerCase()}. JavaScript does not declaring a ${errorType.toLowerCase()} more than once. p5.js reference: ${url}.`; | |
const message = `${errorType} "${name}" on line ${line} is being redeclared and conflicts with a p5.js ${errorType.toLowerCase()}. JavaScript does not support declaring a ${errorType.toLowerCase()} more than once. p5.js reference: ${url}.`; |
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.
Also, I guess JavaScript does technically allow it in different scopes? We could consider saying "your code might not behave correctly" or "your code might behave unexpectedly" or something like that.
'toString', | ||
'print', | ||
'stop', | ||
'onended' |
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.
The functions meant to be redefined by the user make sense. Out of curiosity where do the other false positive entries come from? Is that from looking at classesWithGlobalFunctions
?
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.
I think we should be able to leverage the AST more as it gives more context and information about where and what things are defined
// in the p5.js library, either as a constant or as a function. | ||
function checkForRedefinition(name, libValue, line, type) { | ||
try { | ||
const userValue = eval("name"); |
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.
I'm not sure what this line is meant to be doing but we want to avoid eval()
as the bundler generally does work well with it.
Addresses #7269
Changes:
checkForConstsAndFuncs()
that checks for redefinitions and prints friendly error messagesPR Checklist