File tree Expand file tree Collapse file tree 2 files changed +24
-19
lines changed Expand file tree Collapse file tree 2 files changed +24
-19
lines changed Original file line number Diff line number Diff line change @@ -856,26 +856,31 @@ class Language {
856856 ) ;
857857 }
858858
859- static load ( url ) {
859+ static load ( input ) {
860860 let bytes ;
861- if (
862- typeof process !== 'undefined' &&
863- process . versions &&
864- process . versions . node
865- ) {
866- const fs = require ( 'fs' ) ;
867- bytes = Promise . resolve ( fs . readFileSync ( url ) ) ;
861+ if ( input instanceof Uint8Array ) {
862+ bytes = Promise . resolve ( input ) ;
868863 } else {
869- bytes = fetch ( url )
870- . then ( response => response . arrayBuffer ( )
871- . then ( buffer => {
872- if ( response . ok ) {
873- return new Uint8Array ( buffer ) ;
874- } else {
875- const body = new TextDecoder ( 'utf-8' ) . decode ( buffer ) ;
876- throw new Error ( `Language.load failed with status ${ response . status } .\n\n${ body } ` )
877- }
878- } ) ) ;
864+ const url = input ;
865+ if (
866+ typeof process !== 'undefined' &&
867+ process . versions &&
868+ process . versions . node
869+ ) {
870+ const fs = require ( 'fs' ) ;
871+ bytes = Promise . resolve ( fs . readFileSync ( url ) ) ;
872+ } else {
873+ bytes = fetch ( url )
874+ . then ( response => response . arrayBuffer ( )
875+ . then ( buffer => {
876+ if ( response . ok ) {
877+ return new Uint8Array ( buffer ) ;
878+ } else {
879+ const body = new TextDecoder ( 'utf-8' ) . decode ( buffer ) ;
880+ throw new Error ( `Language.load failed with status ${ response . status } .\n\n${ body } ` )
881+ }
882+ } ) ) ;
883+ }
879884 }
880885
881886 // emscripten-core/emscripten#12969
Original file line number Diff line number Diff line change @@ -127,7 +127,7 @@ declare module 'web-tree-sitter' {
127127 }
128128
129129 class Language {
130- static load ( path : string ) : Promise < Language > ;
130+ static load ( input : string | Uint8Array ) : Promise < Language > ;
131131
132132 readonly version : number ;
133133 readonly fieldCount : number ;
You can’t perform that action at this time.
0 commit comments