( environment: Environment, hook: Plugin['transform'] | undefined, pluginName: string, )
| 1413 | } |
| 1414 | |
| 1415 | function wrapEnvironmentTransform( |
| 1416 | environment: Environment, |
| 1417 | hook: Plugin['transform'] | undefined, |
| 1418 | pluginName: string, |
| 1419 | ): Plugin['transform'] { |
| 1420 | if (!hook) return |
| 1421 | |
| 1422 | const fn = getHookHandler(hook) |
| 1423 | const handler: Plugin['transform'] = function (code, importer, ...args) { |
| 1424 | return fn.call( |
| 1425 | injectEnvironmentInContext(this, environment), |
| 1426 | code, |
| 1427 | importer, |
| 1428 | injectSsrFlag(args[0], environment, pluginName), |
| 1429 | ) |
| 1430 | } |
| 1431 | |
| 1432 | if ('handler' in hook) { |
| 1433 | return wrapHookObject(hook, handler) |
| 1434 | } else { |
| 1435 | return handler |
| 1436 | } |
| 1437 | } |
| 1438 | |
| 1439 | function wrapEnvironmentHook<HookName extends keyof Plugin>( |
| 1440 | environment: Environment, |
no test coverage detected