File tree Expand file tree Collapse file tree 5 files changed +21
-8
lines changed Expand file tree Collapse file tree 5 files changed +21
-8
lines changed Original file line number Diff line number Diff line change @@ -61,6 +61,7 @@ ifdef EMSCRIPTEN
6161 -sEXPORT_NAME="$(WASM_MODULE_NAME)" \
6262 -sENVIRONMENT="web,node" \
6363 -sMODULARIZE=1 \
64+ -sEXPORT_ES6=0 \
6465 -sALLOW_MEMORY_GROWTH=1 \
6566 -lpg_query \
6667 -o $@ \
Original file line number Diff line number Diff line change 11{
22 "name" : " libpg-query" ,
3- "version" : " 17.3.0 " ,
3+ "version" : " 17.3.1 " ,
44 "description" : " The real PostgreSQL query parser" ,
55 "homepage" : " https://github.com/launchql/libpg-query-node" ,
66 "main" : " ./wasm/index.cjs" ,
7+ "module" : " ./wasm/index.js" ,
78 "typings" : " ./wasm/index.d.ts" ,
89 "publishConfig" : {
910 "access" : " public"
1213 " wasm/*" ,
1314 " proto.js"
1415 ],
15- "exports" : {
16- "." : {
17- "types" : " ./wasm/index.d.ts" ,
18- "import" : " ./wasm/index.js" ,
19- "require" : " ./wasm/index.cjs"
20- }
21- },
2216 "scripts" : {
2317 "clean" : " yarn wasm:clean && rimraf cjs esm" ,
2418 "build:js" : " node scripts/build.js" ,
Original file line number Diff line number Diff line change @@ -43,6 +43,10 @@ const initPromise = PgQueryModule().then((module: WasmModule) => {
4343 wasmModule = module ;
4444} ) ;
4545
46+ function ensureLoaded ( ) {
47+ if ( ! wasmModule ) throw new Error ( "WASM module not initialized. Call `loadModule()` first." ) ;
48+ }
49+
4650export async function loadModule ( ) : Promise < void > {
4751 if ( ! wasmModule ) {
4852 await initPromise ;
@@ -57,6 +61,7 @@ function awaitInit<T extends (...args: any[]) => Promise<any>>(fn: T): T {
5761}
5862
5963function stringToPtr ( str : string ) : number {
64+ ensureLoaded ( ) ;
6065 const len = wasmModule . lengthBytesUTF8 ( str ) + 1 ;
6166 const ptr = wasmModule . _malloc ( len ) ;
6267 try {
@@ -69,6 +74,7 @@ function stringToPtr(str: string): number {
6974}
7075
7176function ptrToString ( ptr : number ) : string {
77+ ensureLoaded ( ) ;
7278 return wasmModule . UTF8ToString ( ptr ) ;
7379}
7480
Original file line number Diff line number Diff line change @@ -34,6 +34,10 @@ let wasmModule;
3434const initPromise = ( 0 , libpg_query_js_1 . default ) ( ) . then ( ( module ) => {
3535 wasmModule = module ;
3636} ) ;
37+ function ensureLoaded ( ) {
38+ if ( ! wasmModule )
39+ throw new Error ( "WASM module not initialized. Call `loadModule()` first." ) ;
40+ }
3741async function loadModule ( ) {
3842 if ( ! wasmModule ) {
3943 await initPromise ;
@@ -46,6 +50,7 @@ function awaitInit(fn) {
4650 } ) ;
4751}
4852function stringToPtr ( str ) {
53+ ensureLoaded ( ) ;
4954 const len = wasmModule . lengthBytesUTF8 ( str ) + 1 ;
5055 const ptr = wasmModule . _malloc ( len ) ;
5156 try {
@@ -58,6 +63,7 @@ function stringToPtr(str) {
5863 }
5964}
6065function ptrToString ( ptr ) {
66+ ensureLoaded ( ) ;
6167 return wasmModule . UTF8ToString ( ptr ) ;
6268}
6369exports . parse = awaitInit ( async ( query ) => {
Original file line number Diff line number Diff line change @@ -7,6 +7,10 @@ let wasmModule;
77const initPromise = PgQueryModule ( ) . then ( ( module ) => {
88 wasmModule = module ;
99} ) ;
10+ function ensureLoaded ( ) {
11+ if ( ! wasmModule )
12+ throw new Error ( "WASM module not initialized. Call `loadModule()` first." ) ;
13+ }
1014export async function loadModule ( ) {
1115 if ( ! wasmModule ) {
1216 await initPromise ;
@@ -19,6 +23,7 @@ function awaitInit(fn) {
1923 } ) ;
2024}
2125function stringToPtr ( str ) {
26+ ensureLoaded ( ) ;
2227 const len = wasmModule . lengthBytesUTF8 ( str ) + 1 ;
2328 const ptr = wasmModule . _malloc ( len ) ;
2429 try {
@@ -31,6 +36,7 @@ function stringToPtr(str) {
3136 }
3237}
3338function ptrToString ( ptr ) {
39+ ensureLoaded ( ) ;
3440 return wasmModule . UTF8ToString ( ptr ) ;
3541}
3642export const parse = awaitInit ( async ( query ) => {
You can’t perform that action at this time.
0 commit comments