From 0cd38cd2b9adb966e4ff02596526725311fadf64 Mon Sep 17 00:00:00 2001 From: stephan Date: Fri, 27 Jan 2023 01:33:12 +0000 Subject: Beginnings of a bundler-friendly build of sqlite3.mjs. Not yet ready for downstream testing. FossilOrigin-Name: 4271bf5f41df091696f1dcfc4ffe7a60d24066fc75c896941e0b56de95fe5f89 --- ext/wasm/api/pre-js.c-pp.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'ext/wasm/api/pre-js.c-pp.js') diff --git a/ext/wasm/api/pre-js.c-pp.js b/ext/wasm/api/pre-js.c-pp.js index 2e2fe66bc..d1ee3be19 100644 --- a/ext/wasm/api/pre-js.c-pp.js +++ b/ext/wasm/api/pre-js.c-pp.js @@ -29,7 +29,12 @@ sqlite3InitModuleState.debugModule('self.location =',self.location); 4) If none of the above apply, (prefix+path) is returned. */ Module['locateFile'] = function(path, prefix) { -//#if target=es6-module +//#if target=es6-bundler-friendly + // TEMPORARY KLUDGE to work around a c-pp nested blocks bug which is + // currently eluding a fix. We really should have (#ifnot + // target=es6-bundler-friendly) around this whole function. + return new URL('sqlite3.wasm', import.meta.url).href; +//#elif target=es6-module return new URL(path, import.meta.url).href; //#else 'use strict'; @@ -51,7 +56,7 @@ Module['locateFile'] = function(path, prefix) { "result =", theFile ); return theFile; -//#endif /* SQLITE_JS_EMS */ +//#endif //target=es6-module }.bind(sqlite3InitModuleState); /** @@ -62,7 +67,7 @@ Module['locateFile'] = function(path, prefix) { In such builds we must disable this. */ -const xNameOfInstantiateWasm = true +const xNameOfInstantiateWasm = false ? 'instantiateWasm' : 'emscripten-bug-17951'; Module[xNameOfInstantiateWasm] = function callee(imports,onSuccess){ @@ -102,4 +107,4 @@ Module[xNameOfInstantiateWasm] = function callee(imports,onSuccess){ Module[xNameOfInstantiateWasm].uri = 'sqlite3.wasm'; /* END FILE: api/pre-js.js, noting that the build process may add a line after this one to change the above .uri to a build-specific - one. */ + one. *//* END FILE: api/pre-js.js */ -- cgit v1.2.3 From 67bfea4ea6fb3bba1425079301727d350132cde0 Mon Sep 17 00:00:00 2001 From: stephan Date: Fri, 27 Jan 2023 02:21:16 +0000 Subject: Resolve a nested if-block bug in ext/wasm/c-pp.c which caused output after a nested block to be unduly elided. Remove a kludge, added in the previous check-in, which worked around that bug. FossilOrigin-Name: 7a026a4b24d57c1b0970923b972dd42c3f1bb5b282f908079075468b2e1bf601 --- ext/wasm/api/pre-js.c-pp.js | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'ext/wasm/api/pre-js.c-pp.js') diff --git a/ext/wasm/api/pre-js.c-pp.js b/ext/wasm/api/pre-js.c-pp.js index d1ee3be19..772601f42 100644 --- a/ext/wasm/api/pre-js.c-pp.js +++ b/ext/wasm/api/pre-js.c-pp.js @@ -10,6 +10,7 @@ const sqlite3InitModuleState = self.sqlite3InitModuleState || Object.create(null delete self.sqlite3InitModuleState; sqlite3InitModuleState.debugModule('self.location =',self.location); +//#ifnot target=es6-bundler-friendly /** This custom locateFile() tries to figure out where to load `path` from. The intent is to provide a way for foo/bar/X.js loaded from a @@ -29,12 +30,7 @@ sqlite3InitModuleState.debugModule('self.location =',self.location); 4) If none of the above apply, (prefix+path) is returned. */ Module['locateFile'] = function(path, prefix) { -//#if target=es6-bundler-friendly - // TEMPORARY KLUDGE to work around a c-pp nested blocks bug which is - // currently eluding a fix. We really should have (#ifnot - // target=es6-bundler-friendly) around this whole function. - return new URL('sqlite3.wasm', import.meta.url).href; -//#elif target=es6-module +//#if target=es6-module return new URL(path, import.meta.url).href; //#else 'use strict'; @@ -58,6 +54,7 @@ Module['locateFile'] = function(path, prefix) { return theFile; //#endif //target=es6-module }.bind(sqlite3InitModuleState); +//#endif //ifnot target=es6-bundler-friendly /** Bug warning: a custom Module.instantiateWasm() does not work @@ -107,4 +104,4 @@ Module[xNameOfInstantiateWasm] = function callee(imports,onSuccess){ Module[xNameOfInstantiateWasm].uri = 'sqlite3.wasm'; /* END FILE: api/pre-js.js, noting that the build process may add a line after this one to change the above .uri to a build-specific - one. *//* END FILE: api/pre-js.js */ + one. */ -- cgit v1.2.3 From a0013fbe879fb59843c69610af56b5b9141c9614 Mon Sep 17 00:00:00 2001 From: stephan Date: Fri, 27 Jan 2023 03:18:16 +0000 Subject: More work on creating a separate sqlite3.js build which is hopefully friendly to JS bundlers. FossilOrigin-Name: b7b896fb448a7f46eb88eadadb1359255aec637a384cabcdd526276a02f4f0b4 --- ext/wasm/api/pre-js.c-pp.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'ext/wasm/api/pre-js.c-pp.js') diff --git a/ext/wasm/api/pre-js.c-pp.js b/ext/wasm/api/pre-js.c-pp.js index 772601f42..c27c2fe0d 100644 --- a/ext/wasm/api/pre-js.c-pp.js +++ b/ext/wasm/api/pre-js.c-pp.js @@ -6,7 +6,10 @@ */ // See notes in extern-post-js.js -const sqlite3InitModuleState = self.sqlite3InitModuleState || Object.create(null); +const sqlite3InitModuleState = self.sqlite3InitModuleState + || Object.assign(Object.create(null),{ + debugModule: ()=>{} + }); delete self.sqlite3InitModuleState; sqlite3InitModuleState.debugModule('self.location =',self.location); -- cgit v1.2.3