-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
feat: add support for compileFunction allowing us to avoid the module wrapper
#9252
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
Conversation
| return compileFunction(code, params, { | ||
| filename, | ||
| parsingContext: this.context, | ||
| }) as any; |
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.
it returns Function
4022404 to
8b200be
Compare
|
@thymikee I've reworked this to use feature detection instead of an option, and just dropped it from jsdom for now. It should be invisible to consumers. Thoughts? |
| fakeTimersLolex: LolexFakeTimers | null; | ||
| moduleMocker: jestMock.ModuleMocker | null; | ||
| runScript<T = unknown>(script: Script): T | null; | ||
| compileFunction?<T = unknown>( |
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've made it optional so we're not blocked by jsdom having support. It'll silently use it if it's ever implemented
| if ( | ||
| e instanceof SyntaxError && | ||
| // `instanceof` might come from the wrong context | ||
| e.name === 'SyntaxError' && |
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 SyntaxError thrown by compileFunction comes from the passed in context
compileFunction allowing us to avoid the module wrapper
|
@SimenB works for me |
|
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Summary
This is essentially nodejs/node#21573. Doing this should make it easier for sourcemaps to do their thing since we don't inject arbitrary code around the code.
I made this into an option as
vm.compileFunctionwas addednode@10.10. Happy to not have an option and rather use feature detection? Also note that JSDOM does not support it, but I'll open up a PR shortly.EDIT: jsdom/jsdom#2731
Mildly related to #8596 as it won't need the
moduleWrapperLengththing anymore.Docs: https://nodejs.org/api/vm.html#vm_vm_compilefunction_code_params_options
Test plan
I haven't added new tests yet, but existing tests should pass, na drunning locally with
--no-module-wrapperseems to work correctly. If CI is happy, I'll flip the default and see what it says - hopefully the only failing tests at that point will be the ones for config