mirror of
https://github.com/LuanRT/YouTube.js.git
synced 2026-06-23 23:09:28 +00:00
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
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
[youtubei.js](../../../README.md) / [JsHelpers](../README.md) / 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`](../../Types/classes/JsAnalyzer.md)
|
||||
|
||||
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](https://github.com/LuanRT/YouTube.js/blob/af92984523f90200a18314b94478a2697c9deab0/src/utils/javascript/helpers.ts#L223)
|
||||
27
docs/api/namespaces/JsHelpers/functions/extractNodeSource.md
Normal file
27
docs/api/namespaces/JsHelpers/functions/extractNodeSource.md
Normal file
@@ -0,0 +1,27 @@
|
||||
[youtubei.js](../../../README.md) / [JsHelpers](../README.md) / extractNodeSource
|
||||
|
||||
# Function: extractNodeSource()
|
||||
|
||||
> **extractNodeSource**(`node`, `source`): `string` \| `null`
|
||||
|
||||
Extracts the source code corresponding to a given AST node.
|
||||
|
||||
## Parameters
|
||||
|
||||
• **node**: `undefined` \| `null` \| `Node`
|
||||
|
||||
The AST node to extract source from.
|
||||
|
||||
• **source**: `string`
|
||||
|
||||
The original source code.
|
||||
|
||||
## Returns
|
||||
|
||||
`string` \| `null`
|
||||
|
||||
The source code corresponding to the node, or null if not available.
|
||||
|
||||
## Defined in
|
||||
|
||||
[src/utils/javascript/helpers.ts:143](https://github.com/LuanRT/YouTube.js/blob/af92984523f90200a18314b94478a2697c9deab0/src/utils/javascript/helpers.ts#L143)
|
||||
@@ -0,0 +1,23 @@
|
||||
[youtubei.js](../../../README.md) / [JsHelpers](../README.md) / getNodeSourceRange
|
||||
|
||||
# Function: getNodeSourceRange()
|
||||
|
||||
> **getNodeSourceRange**(`node`): [`number`, `number`] \| `null`
|
||||
|
||||
Returns the source range of an ESTree node as a tuple of start and end positions.
|
||||
|
||||
## Parameters
|
||||
|
||||
• **node**: `undefined` \| `null` \| `Node`
|
||||
|
||||
The ESTree node to extract the source range from.
|
||||
|
||||
## Returns
|
||||
|
||||
[`number`, `number`] \| `null`
|
||||
|
||||
A tuple `[start, end]` representing the source range, or `null` if unavailable.
|
||||
|
||||
## Defined in
|
||||
|
||||
[src/utils/javascript/helpers.ts:130](https://github.com/LuanRT/YouTube.js/blob/af92984523f90200a18314b94478a2697c9deab0/src/utils/javascript/helpers.ts#L130)
|
||||
25
docs/api/namespaces/JsHelpers/functions/memberBaseName.md
Normal file
25
docs/api/namespaces/JsHelpers/functions/memberBaseName.md
Normal file
@@ -0,0 +1,25 @@
|
||||
[youtubei.js](../../../README.md) / [JsHelpers](../README.md) / memberBaseName
|
||||
|
||||
# Function: memberBaseName()
|
||||
|
||||
> **memberBaseName**(`memberExpression`, `source`): `string` \| `null`
|
||||
|
||||
Retrieves the base identifier for a member expression chain.
|
||||
|
||||
## Parameters
|
||||
|
||||
• **memberExpression**: `MemberExpression`
|
||||
|
||||
Member expression whose root should be resolved.
|
||||
|
||||
• **source**: `string`
|
||||
|
||||
Original source code for range lookups.
|
||||
|
||||
## Returns
|
||||
|
||||
`string` \| `null`
|
||||
|
||||
## Defined in
|
||||
|
||||
[src/utils/javascript/helpers.ts:193](https://github.com/LuanRT/YouTube.js/blob/af92984523f90200a18314b94478a2697c9deab0/src/utils/javascript/helpers.ts#L193)
|
||||
25
docs/api/namespaces/JsHelpers/functions/memberToString.md
Normal file
25
docs/api/namespaces/JsHelpers/functions/memberToString.md
Normal file
@@ -0,0 +1,25 @@
|
||||
[youtubei.js](../../../README.md) / [JsHelpers](../README.md) / memberToString
|
||||
|
||||
# Function: memberToString()
|
||||
|
||||
> **memberToString**(`memberExpression`, `source`): `string` \| `null`
|
||||
|
||||
Converts a member expression into its dot/bracket string form.
|
||||
|
||||
## Parameters
|
||||
|
||||
• **memberExpression**: `Node`
|
||||
|
||||
Member expression node to stringify.
|
||||
|
||||
• **source**: `string`
|
||||
|
||||
Original source code for range lookups.
|
||||
|
||||
## Returns
|
||||
|
||||
`string` \| `null`
|
||||
|
||||
## Defined in
|
||||
|
||||
[src/utils/javascript/helpers.ts:153](https://github.com/LuanRT/YouTube.js/blob/af92984523f90200a18314b94478a2697c9deab0/src/utils/javascript/helpers.ts#L153)
|
||||
30
docs/api/namespaces/JsHelpers/functions/walkAst.md
Normal file
30
docs/api/namespaces/JsHelpers/functions/walkAst.md
Normal file
@@ -0,0 +1,30 @@
|
||||
[youtubei.js](../../../README.md) / [JsHelpers](../README.md) / walkAst
|
||||
|
||||
# Function: walkAst()
|
||||
|
||||
> **walkAst**(`root`, `visitor`): `void`
|
||||
|
||||
Performs a non-recursive traversal of an ESTree AST.
|
||||
|
||||
## Parameters
|
||||
|
||||
• **root**: `Node`
|
||||
|
||||
Root AST node to start the traversal from.
|
||||
|
||||
• **visitor**: [`AstVisitor`](../type-aliases/AstVisitor.md)
|
||||
|
||||
Callbacks invoked when nodes are entered or left.
|
||||
|
||||
## Returns
|
||||
|
||||
`void`
|
||||
|
||||
## Remarks
|
||||
|
||||
- If it returns `WALK_STOP`, the entire traversal is halted.
|
||||
- Why did I not use some AST walker library instead?: They're too slow.
|
||||
|
||||
## Defined in
|
||||
|
||||
[src/utils/javascript/helpers.ts:62](https://github.com/LuanRT/YouTube.js/blob/af92984523f90200a18314b94478a2697c9deab0/src/utils/javascript/helpers.ts#L62)
|
||||
Reference in New Issue
Block a user