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:
Luan
2025-10-12 09:08:51 -03:00
committed by GitHub
parent bffa92d96e
commit 25d0876b91
873 changed files with 10992 additions and 8345 deletions

View File

@@ -26,7 +26,7 @@
#### Defined in
[src/parser/classes/VideoCard.ts:11](https://github.com/LuanRT/YouTube.js/blob/4ae0cc5c523a2080e68d6c0c1437c78fe318ea30/src/parser/classes/VideoCard.ts#L11)
[src/parser/classes/VideoCard.ts:11](https://github.com/LuanRT/YouTube.js/blob/af92984523f90200a18314b94478a2697c9deab0/src/parser/classes/VideoCard.ts#L11)
## Properties
@@ -40,7 +40,7 @@
#### Defined in
[src/parser/classes/Video.ts:22](https://github.com/LuanRT/YouTube.js/blob/4ae0cc5c523a2080e68d6c0c1437c78fe318ea30/src/parser/classes/Video.ts#L22)
[src/parser/classes/Video.ts:22](https://github.com/LuanRT/YouTube.js/blob/af92984523f90200a18314b94478a2697c9deab0/src/parser/classes/Video.ts#L22)
***
@@ -54,13 +54,13 @@
#### Defined in
[src/parser/classes/Video.ts:26](https://github.com/LuanRT/YouTube.js/blob/4ae0cc5c523a2080e68d6c0c1437c78fe318ea30/src/parser/classes/Video.ts#L26)
[src/parser/classes/Video.ts:26](https://github.com/LuanRT/YouTube.js/blob/af92984523f90200a18314b94478a2697c9deab0/src/parser/classes/Video.ts#L26)
***
### badges
> **badges**: [`MetadataBadge`](MetadataBadge.md)[]
> **badges**: [`ObservedArray`](../../Helpers/type-aliases/ObservedArray.md)\<[`MetadataBadge`](MetadataBadge.md)\>
#### Inherited from
@@ -68,7 +68,7 @@
#### Defined in
[src/parser/classes/Video.ts:27](https://github.com/LuanRT/YouTube.js/blob/4ae0cc5c523a2080e68d6c0c1437c78fe318ea30/src/parser/classes/Video.ts#L27)
[src/parser/classes/Video.ts:27](https://github.com/LuanRT/YouTube.js/blob/af92984523f90200a18314b94478a2697c9deab0/src/parser/classes/Video.ts#L27)
***
@@ -82,7 +82,7 @@
#### Defined in
[src/parser/classes/Video.ts:37](https://github.com/LuanRT/YouTube.js/blob/4ae0cc5c523a2080e68d6c0c1437c78fe318ea30/src/parser/classes/Video.ts#L37)
[src/parser/classes/Video.ts:37](https://github.com/LuanRT/YouTube.js/blob/af92984523f90200a18314b94478a2697c9deab0/src/parser/classes/Video.ts#L37)
***
@@ -96,7 +96,7 @@
#### Defined in
[src/parser/classes/Video.ts:19](https://github.com/LuanRT/YouTube.js/blob/4ae0cc5c523a2080e68d6c0c1437c78fe318ea30/src/parser/classes/Video.ts#L19)
[src/parser/classes/Video.ts:19](https://github.com/LuanRT/YouTube.js/blob/af92984523f90200a18314b94478a2697c9deab0/src/parser/classes/Video.ts#L19)
***
@@ -110,7 +110,7 @@
#### Defined in
[src/parser/classes/Video.ts:28](https://github.com/LuanRT/YouTube.js/blob/4ae0cc5c523a2080e68d6c0c1437c78fe318ea30/src/parser/classes/Video.ts#L28)
[src/parser/classes/Video.ts:28](https://github.com/LuanRT/YouTube.js/blob/af92984523f90200a18314b94478a2697c9deab0/src/parser/classes/Video.ts#L28)
***
@@ -124,7 +124,7 @@
#### Defined in
[src/parser/classes/Video.ts:21](https://github.com/LuanRT/YouTube.js/blob/4ae0cc5c523a2080e68d6c0c1437c78fe318ea30/src/parser/classes/Video.ts#L21)
[src/parser/classes/Video.ts:21](https://github.com/LuanRT/YouTube.js/blob/af92984523f90200a18314b94478a2697c9deab0/src/parser/classes/Video.ts#L21)
***
@@ -138,7 +138,7 @@
#### Defined in
[src/parser/classes/Video.ts:35](https://github.com/LuanRT/YouTube.js/blob/4ae0cc5c523a2080e68d6c0c1437c78fe318ea30/src/parser/classes/Video.ts#L35)
[src/parser/classes/Video.ts:35](https://github.com/LuanRT/YouTube.js/blob/af92984523f90200a18314b94478a2697c9deab0/src/parser/classes/Video.ts#L35)
***
@@ -152,7 +152,7 @@
#### Defined in
[src/parser/classes/Video.ts:33](https://github.com/LuanRT/YouTube.js/blob/4ae0cc5c523a2080e68d6c0c1437c78fe318ea30/src/parser/classes/Video.ts#L33)
[src/parser/classes/Video.ts:33](https://github.com/LuanRT/YouTube.js/blob/af92984523f90200a18314b94478a2697c9deab0/src/parser/classes/Video.ts#L33)
***
@@ -166,7 +166,7 @@
#### Defined in
[src/parser/classes/Video.ts:36](https://github.com/LuanRT/YouTube.js/blob/4ae0cc5c523a2080e68d6c0c1437c78fe318ea30/src/parser/classes/Video.ts#L36)
[src/parser/classes/Video.ts:36](https://github.com/LuanRT/YouTube.js/blob/af92984523f90200a18314b94478a2697c9deab0/src/parser/classes/Video.ts#L36)
***
@@ -176,7 +176,7 @@
#### Defined in
[src/parser/classes/VideoCard.ts:9](https://github.com/LuanRT/YouTube.js/blob/4ae0cc5c523a2080e68d6c0c1437c78fe318ea30/src/parser/classes/VideoCard.ts#L9)
[src/parser/classes/VideoCard.ts:9](https://github.com/LuanRT/YouTube.js/blob/af92984523f90200a18314b94478a2697c9deab0/src/parser/classes/VideoCard.ts#L9)
***
@@ -190,7 +190,7 @@
#### Defined in
[src/parser/classes/Video.ts:29](https://github.com/LuanRT/YouTube.js/blob/4ae0cc5c523a2080e68d6c0c1437c78fe318ea30/src/parser/classes/Video.ts#L29)
[src/parser/classes/Video.ts:29](https://github.com/LuanRT/YouTube.js/blob/af92984523f90200a18314b94478a2697c9deab0/src/parser/classes/Video.ts#L29)
***
@@ -204,7 +204,7 @@
#### Defined in
[src/parser/classes/Video.ts:25](https://github.com/LuanRT/YouTube.js/blob/4ae0cc5c523a2080e68d6c0c1437c78fe318ea30/src/parser/classes/Video.ts#L25)
[src/parser/classes/Video.ts:25](https://github.com/LuanRT/YouTube.js/blob/af92984523f90200a18314b94478a2697c9deab0/src/parser/classes/Video.ts#L25)
***
@@ -218,7 +218,7 @@
#### Defined in
[src/parser/classes/Video.ts:38](https://github.com/LuanRT/YouTube.js/blob/4ae0cc5c523a2080e68d6c0c1437c78fe318ea30/src/parser/classes/Video.ts#L38)
[src/parser/classes/Video.ts:38](https://github.com/LuanRT/YouTube.js/blob/af92984523f90200a18314b94478a2697c9deab0/src/parser/classes/Video.ts#L38)
***
@@ -232,7 +232,7 @@
#### Defined in
[src/parser/classes/Video.ts:40](https://github.com/LuanRT/YouTube.js/blob/4ae0cc5c523a2080e68d6c0c1437c78fe318ea30/src/parser/classes/Video.ts#L40)
[src/parser/classes/Video.ts:40](https://github.com/LuanRT/YouTube.js/blob/af92984523f90200a18314b94478a2697c9deab0/src/parser/classes/Video.ts#L40)
***
@@ -246,7 +246,7 @@
#### Defined in
[src/parser/classes/Video.ts:39](https://github.com/LuanRT/YouTube.js/blob/4ae0cc5c523a2080e68d6c0c1437c78fe318ea30/src/parser/classes/Video.ts#L39)
[src/parser/classes/Video.ts:39](https://github.com/LuanRT/YouTube.js/blob/af92984523f90200a18314b94478a2697c9deab0/src/parser/classes/Video.ts#L39)
***
@@ -260,7 +260,7 @@
#### Defined in
[src/parser/classes/Video.ts:31](https://github.com/LuanRT/YouTube.js/blob/4ae0cc5c523a2080e68d6c0c1437c78fe318ea30/src/parser/classes/Video.ts#L31)
[src/parser/classes/Video.ts:31](https://github.com/LuanRT/YouTube.js/blob/af92984523f90200a18314b94478a2697c9deab0/src/parser/classes/Video.ts#L31)
***
@@ -274,7 +274,7 @@
#### Defined in
[src/parser/classes/Video.ts:34](https://github.com/LuanRT/YouTube.js/blob/4ae0cc5c523a2080e68d6c0c1437c78fe318ea30/src/parser/classes/Video.ts#L34)
[src/parser/classes/Video.ts:34](https://github.com/LuanRT/YouTube.js/blob/af92984523f90200a18314b94478a2697c9deab0/src/parser/classes/Video.ts#L34)
***
@@ -288,7 +288,7 @@
#### Defined in
[src/parser/classes/Video.ts:20](https://github.com/LuanRT/YouTube.js/blob/4ae0cc5c523a2080e68d6c0c1437c78fe318ea30/src/parser/classes/Video.ts#L20)
[src/parser/classes/Video.ts:20](https://github.com/LuanRT/YouTube.js/blob/af92984523f90200a18314b94478a2697c9deab0/src/parser/classes/Video.ts#L20)
***
@@ -302,7 +302,7 @@
#### Defined in
[src/parser/classes/Video.ts:41](https://github.com/LuanRT/YouTube.js/blob/4ae0cc5c523a2080e68d6c0c1437c78fe318ea30/src/parser/classes/Video.ts#L41)
[src/parser/classes/Video.ts:41](https://github.com/LuanRT/YouTube.js/blob/af92984523f90200a18314b94478a2697c9deab0/src/parser/classes/Video.ts#L41)
***
@@ -316,7 +316,7 @@
#### Defined in
[src/parser/classes/Video.ts:24](https://github.com/LuanRT/YouTube.js/blob/4ae0cc5c523a2080e68d6c0c1437c78fe318ea30/src/parser/classes/Video.ts#L24)
[src/parser/classes/Video.ts:24](https://github.com/LuanRT/YouTube.js/blob/af92984523f90200a18314b94478a2697c9deab0/src/parser/classes/Video.ts#L24)
***
@@ -330,7 +330,7 @@
#### Defined in
[src/parser/classes/Video.ts:23](https://github.com/LuanRT/YouTube.js/blob/4ae0cc5c523a2080e68d6c0c1437c78fe318ea30/src/parser/classes/Video.ts#L23)
[src/parser/classes/Video.ts:23](https://github.com/LuanRT/YouTube.js/blob/af92984523f90200a18314b94478a2697c9deab0/src/parser/classes/Video.ts#L23)
***
@@ -344,7 +344,7 @@
#### Defined in
[src/parser/classes/Video.ts:17](https://github.com/LuanRT/YouTube.js/blob/4ae0cc5c523a2080e68d6c0c1437c78fe318ea30/src/parser/classes/Video.ts#L17)
[src/parser/classes/Video.ts:17](https://github.com/LuanRT/YouTube.js/blob/af92984523f90200a18314b94478a2697c9deab0/src/parser/classes/Video.ts#L17)
***
@@ -358,7 +358,7 @@
#### Defined in
[src/parser/helpers.ts:8](https://github.com/LuanRT/YouTube.js/blob/4ae0cc5c523a2080e68d6c0c1437c78fe318ea30/src/parser/helpers.ts#L8)
[src/parser/helpers.ts:8](https://github.com/LuanRT/YouTube.js/blob/af92984523f90200a18314b94478a2697c9deab0/src/parser/helpers.ts#L8)
***
@@ -372,7 +372,7 @@
#### Defined in
[src/parser/classes/Video.ts:18](https://github.com/LuanRT/YouTube.js/blob/4ae0cc5c523a2080e68d6c0c1437c78fe318ea30/src/parser/classes/Video.ts#L18)
[src/parser/classes/Video.ts:18](https://github.com/LuanRT/YouTube.js/blob/af92984523f90200a18314b94478a2697c9deab0/src/parser/classes/Video.ts#L18)
***
@@ -386,7 +386,7 @@
#### Defined in
[src/parser/classes/Video.ts:32](https://github.com/LuanRT/YouTube.js/blob/4ae0cc5c523a2080e68d6c0c1437c78fe318ea30/src/parser/classes/Video.ts#L32)
[src/parser/classes/Video.ts:32](https://github.com/LuanRT/YouTube.js/blob/af92984523f90200a18314b94478a2697c9deab0/src/parser/classes/Video.ts#L32)
***
@@ -400,7 +400,7 @@
#### Defined in
[src/parser/classes/Video.ts:16](https://github.com/LuanRT/YouTube.js/blob/4ae0cc5c523a2080e68d6c0c1437c78fe318ea30/src/parser/classes/Video.ts#L16)
[src/parser/classes/Video.ts:16](https://github.com/LuanRT/YouTube.js/blob/af92984523f90200a18314b94478a2697c9deab0/src/parser/classes/Video.ts#L16)
***
@@ -414,7 +414,7 @@
#### Defined in
[src/parser/classes/Video.ts:30](https://github.com/LuanRT/YouTube.js/blob/4ae0cc5c523a2080e68d6c0c1437c78fe318ea30/src/parser/classes/Video.ts#L30)
[src/parser/classes/Video.ts:30](https://github.com/LuanRT/YouTube.js/blob/af92984523f90200a18314b94478a2697c9deab0/src/parser/classes/Video.ts#L30)
***
@@ -428,7 +428,7 @@
#### Defined in
[src/parser/classes/VideoCard.ts:7](https://github.com/LuanRT/YouTube.js/blob/4ae0cc5c523a2080e68d6c0c1437c78fe318ea30/src/parser/classes/VideoCard.ts#L7)
[src/parser/classes/VideoCard.ts:7](https://github.com/LuanRT/YouTube.js/blob/af92984523f90200a18314b94478a2697c9deab0/src/parser/classes/VideoCard.ts#L7)
## Accessors
@@ -446,7 +446,7 @@
#### Defined in
[src/parser/classes/Video.ts:148](https://github.com/LuanRT/YouTube.js/blob/4ae0cc5c523a2080e68d6c0c1437c78fe318ea30/src/parser/classes/Video.ts#L148)
[src/parser/classes/Video.ts:148](https://github.com/LuanRT/YouTube.js/blob/af92984523f90200a18314b94478a2697c9deab0/src/parser/classes/Video.ts#L148)
***
@@ -464,7 +464,7 @@
#### Defined in
[src/parser/classes/Video.ts:119](https://github.com/LuanRT/YouTube.js/blob/4ae0cc5c523a2080e68d6c0c1437c78fe318ea30/src/parser/classes/Video.ts#L119)
[src/parser/classes/Video.ts:119](https://github.com/LuanRT/YouTube.js/blob/af92984523f90200a18314b94478a2697c9deab0/src/parser/classes/Video.ts#L119)
***
@@ -490,7 +490,7 @@
#### Defined in
[src/parser/classes/Video.ts:152](https://github.com/LuanRT/YouTube.js/blob/4ae0cc5c523a2080e68d6c0c1437c78fe318ea30/src/parser/classes/Video.ts#L152)
[src/parser/classes/Video.ts:152](https://github.com/LuanRT/YouTube.js/blob/af92984523f90200a18314b94478a2697c9deab0/src/parser/classes/Video.ts#L152)
***
@@ -508,7 +508,7 @@
#### Defined in
[src/parser/classes/Video.ts:144](https://github.com/LuanRT/YouTube.js/blob/4ae0cc5c523a2080e68d6c0c1437c78fe318ea30/src/parser/classes/Video.ts#L144)
[src/parser/classes/Video.ts:144](https://github.com/LuanRT/YouTube.js/blob/af92984523f90200a18314b94478a2697c9deab0/src/parser/classes/Video.ts#L144)
***
@@ -530,7 +530,7 @@ Use [`video_id`](Video.md#video_id) instead.
#### Defined in
[src/parser/classes/Video.ts:115](https://github.com/LuanRT/YouTube.js/blob/4ae0cc5c523a2080e68d6c0c1437c78fe318ea30/src/parser/classes/Video.ts#L115)
[src/parser/classes/Video.ts:115](https://github.com/LuanRT/YouTube.js/blob/af92984523f90200a18314b94478a2697c9deab0/src/parser/classes/Video.ts#L115)
***
@@ -548,7 +548,7 @@ Use [`video_id`](Video.md#video_id) instead.
#### Defined in
[src/parser/classes/Video.ts:140](https://github.com/LuanRT/YouTube.js/blob/4ae0cc5c523a2080e68d6c0c1437c78fe318ea30/src/parser/classes/Video.ts#L140)
[src/parser/classes/Video.ts:140](https://github.com/LuanRT/YouTube.js/blob/af92984523f90200a18314b94478a2697c9deab0/src/parser/classes/Video.ts#L140)
***
@@ -566,7 +566,7 @@ Use [`video_id`](Video.md#video_id) instead.
#### Defined in
[src/parser/classes/Video.ts:125](https://github.com/LuanRT/YouTube.js/blob/4ae0cc5c523a2080e68d6c0c1437c78fe318ea30/src/parser/classes/Video.ts#L125)
[src/parser/classes/Video.ts:125](https://github.com/LuanRT/YouTube.js/blob/af92984523f90200a18314b94478a2697c9deab0/src/parser/classes/Video.ts#L125)
***
@@ -584,7 +584,7 @@ Use [`video_id`](Video.md#video_id) instead.
#### Defined in
[src/parser/classes/Video.ts:136](https://github.com/LuanRT/YouTube.js/blob/4ae0cc5c523a2080e68d6c0c1437c78fe318ea30/src/parser/classes/Video.ts#L136)
[src/parser/classes/Video.ts:136](https://github.com/LuanRT/YouTube.js/blob/af92984523f90200a18314b94478a2697c9deab0/src/parser/classes/Video.ts#L136)
***
@@ -602,7 +602,7 @@ Use [`video_id`](Video.md#video_id) instead.
#### Defined in
[src/parser/classes/Video.ts:132](https://github.com/LuanRT/YouTube.js/blob/4ae0cc5c523a2080e68d6c0c1437c78fe318ea30/src/parser/classes/Video.ts#L132)
[src/parser/classes/Video.ts:132](https://github.com/LuanRT/YouTube.js/blob/af92984523f90200a18314b94478a2697c9deab0/src/parser/classes/Video.ts#L132)
## Methods
@@ -640,7 +640,7 @@ If the node is not of the given type
#### Defined in
[src/parser/helpers.ts:29](https://github.com/LuanRT/YouTube.js/blob/4ae0cc5c523a2080e68d6c0c1437c78fe318ea30/src/parser/helpers.ts#L29)
[src/parser/helpers.ts:29](https://github.com/LuanRT/YouTube.js/blob/af92984523f90200a18314b94478a2697c9deab0/src/parser/helpers.ts#L29)
***
@@ -674,7 +674,7 @@ Whether the node has the key
#### Defined in
[src/parser/helpers.ts:41](https://github.com/LuanRT/YouTube.js/blob/4ae0cc5c523a2080e68d6c0c1437c78fe318ea30/src/parser/helpers.ts#L41)
[src/parser/helpers.ts:41](https://github.com/LuanRT/YouTube.js/blob/af92984523f90200a18314b94478a2697c9deab0/src/parser/helpers.ts#L41)
***
@@ -708,7 +708,7 @@ whether the node is of the given type
#### Defined in
[src/parser/helpers.ts:19](https://github.com/LuanRT/YouTube.js/blob/4ae0cc5c523a2080e68d6c0c1437c78fe318ea30/src/parser/helpers.ts#L19)
[src/parser/helpers.ts:19](https://github.com/LuanRT/YouTube.js/blob/af92984523f90200a18314b94478a2697c9deab0/src/parser/helpers.ts#L19)
***
@@ -746,4 +746,4 @@ If the node does not have the key
#### Defined in
[src/parser/helpers.ts:51](https://github.com/LuanRT/YouTube.js/blob/4ae0cc5c523a2080e68d6c0c1437c78fe318ea30/src/parser/helpers.ts#L51)
[src/parser/helpers.ts:51](https://github.com/LuanRT/YouTube.js/blob/af92984523f90200a18314b94478a2697c9deab0/src/parser/helpers.ts#L51)