Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
worker: address review comments
Lazy load the type stripping helper with getLazy(), and list type
stripping under the differences from the HTML Standard.

Signed-off-by: Hubert Walczak <hubertwalczak8@gmail.com>
  • Loading branch information
osztenkurden committed Sep 23, 2026
commit acbfc92b8cef930c048f92d0a156f8341317afa0
9 changes: 5 additions & 4 deletions doc/api/globals.md
Original file line number Diff line number Diff line change
Expand Up @@ -1373,9 +1373,9 @@ accepted and how failures are reported:
* For `blob:` URLs, the script must be held in memory, so blobs backed by a file,
such as those returned by [`fs.openAsBlob()`][], cannot be used.

[Type stripping][] only applies to module workers loaded from `file:` URLs. The
`type` option, not the file extension, decides how an entry is run, so a `.cts`
entry is still evaluated as an ES module.
[Type stripping][type stripping] only applies to module workers loaded from
`file:` URLs. The `type` option, not the file extension, decides how an entry is
run, so a `.cts` entry is still evaluated as an ES module.

### Differences from the HTML Standard

Expand All @@ -1401,6 +1401,7 @@ Besides script loading, mentioned above:
`unhandledrejection`, since Node.js exposes the equivalent does not
implement the `PromiseRejectionEvent` interface or the per-rejection
`preventDefault()` behavior required by the HTML Standard.
* Module workers loaded from `file:` URLs support [type stripping][].

### Web Workers and `node:worker_threads`

Expand Down Expand Up @@ -1471,7 +1472,6 @@ A browser-compatible implementation of [`WritableStreamDefaultWriter`][].
[Navigator API]: https://html.spec.whatwg.org/multipage/system-state.html#the-navigator-object
[RFC 5646]: https://www.rfc-editor.org/rfc/rfc5646.txt
[Refable protocol]: process.md#processrefmayberefable
[Type stripping]: typescript.md#type-stripping
[Web Crypto API]: webcrypto.md
[`--experimental-eventsource`]: cli.md#--experimental-eventsource
[`--experimental-web-worker`]: cli.md#--experimental-web-worker
Expand Down Expand Up @@ -1545,5 +1545,6 @@ A browser-compatible implementation of [`WritableStreamDefaultWriter`][].
[buffer section]: buffer.md
[built-in objects]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects
[timers]: timers.md
[type stripping]: typescript.md#type-stripping
[webassembly-mdn]: https://developer.mozilla.org/en-US/docs/WebAssembly
[webassembly-org]: https://webassembly.org
6 changes: 4 additions & 2 deletions lib/internal/webworker.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ let scopeBaseURL = null;
const lazyErrorEvent =
getLazy(() => require('internal/deps/undici/undici').ErrorEvent);

const lazyStripTypeScriptModuleTypes = getLazy(
() => require('internal/modules/typescript').stripTypeScriptModuleTypes);

function createErrorEvent(init) {
const ErrorEvent = lazyErrorEvent();
return new ErrorEvent('error', init);
Expand Down Expand Up @@ -265,8 +268,7 @@ function runModuleScriptSource(source, url) {
const filename = fileURLToPath(parsedURL);
const extension = extname(filename);
if (extension === '.ts' || extension === '.mts' || extension === '.cts') {
const { stripTypeScriptModuleTypes } = require('internal/modules/typescript');
source = stripTypeScriptModuleTypes(source, filename, url);
source = lazyStripTypeScriptModuleTypes()(source, filename, url);
}
}
// Necessary to reset RegExp statics before user code runs.
Expand Down
Loading