Files
YouTube.js/docs/api/namespaces/JsHelpers/functions/createWrapperFunction.md
Luan 25d0876b91 refactor(Player)!: Use AST-based JS extraction with side-effect safe code emission (#1052)
* chore(deps): Add `meriyah`

* feat(utils): Implement AST-based JS extractors

* chore(utils): Remove old ast walker code

* fix(Player): Migrate js extraction logic

* chore(JsExtractor): Fix typo in tsdoc

* perf(JsAnalyzer): Simplify main AST analysis logic

* fix(JsAnalyzer): Change `break` to `return` in AST matching logic

* chore: Update docs

* chore: Don't export `PlayerInitializationOptions`

* chore(evaluate): Update error message to include doc link

* perf: Use a `for-loop` to find iife
2025-10-12 09:08:51 -03:00

1.2 KiB

youtubei.js / JsHelpers / createWrapperFunction

Function: createWrapperFunction()

createWrapperFunction(analyzer, name, node): string | undefined

Analyzes an AST node to determine if it's a function call or a function declaration. Based on that, it then creates a new JavaScript function as a string. This new function acts as a wrapper, taking a single 'input' argument and forwarding it to the original function call.

Currently can handle:

  • CallExpression: Creates a wrapper that invokes the function being called in the expression.
  • VariableDeclarator with a FunctionExpression: Creates a wrapper that calls the declared function.

Parameters

analyzer: JsAnalyzer

The JSAnalyzer instance, used to resolve context like declared variables.

name: string

The name for the new wrapper function to be created.

node: Node

The ESTree node.

Returns

string | undefined

Todo

Look for edge cases.

Defined in

src/utils/javascript/helpers.ts:223