bun-plugin-stx 0.2.381 → 0.2.383
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1129,6 +1129,47 @@ function routerSource() {
|
|
|
1129
1129
|
function isComposablesScript(s){
|
|
1130
1130
|
return !!s&&((s.hasAttribute&&s.hasAttribute('data-stx-composables'))||COMPOSABLES_TEXT.test(s.textContent||''));
|
|
1131
1131
|
}
|
|
1132
|
+
/*
|
|
1133
|
+
* What the block wrap below would otherwise hide (stacksjs/stx#2041).
|
|
1134
|
+
*
|
|
1135
|
+
* A re-executed script is wrapped in a bare block so that top-level const
|
|
1136
|
+
* and let cannot collide across navigations. That wrap is invisible for a
|
|
1137
|
+
* plain function declaration -- Annex B.3.3 still hoists its binding to the
|
|
1138
|
+
* enclosing scope in sloppy mode -- and NOT invisible for anything else.
|
|
1139
|
+
* async function, function*, class, const and let are all block-scoped, so
|
|
1140
|
+
* the same source published a global when the browser parsed the script and
|
|
1141
|
+
* published nothing when the router re-ran it.
|
|
1142
|
+
*
|
|
1143
|
+
* The effect is a divergence between development and a built app, because
|
|
1144
|
+
* only the built one reaches a route as a fragment: a page served whole runs
|
|
1145
|
+
* its script natively. An inline onclick that names such a declaration then
|
|
1146
|
+
* worked in dev and threw ReferenceError in the packaged app, where there is
|
|
1147
|
+
* no console, so it read as a button that does nothing.
|
|
1148
|
+
*
|
|
1149
|
+
* So: re-publish what the browser would have published. Only values that are
|
|
1150
|
+
* functions, which is what an inline handler calls -- assigning every
|
|
1151
|
+
* top-level const would otherwise write over window.name and friends, which
|
|
1152
|
+
* a lexical global shadows rather than overwrites. Each name is guarded on
|
|
1153
|
+
* its own so an unmatched one cannot take the rest down, and typeof is safe
|
|
1154
|
+
* on a name that was never declared.
|
|
1155
|
+
*
|
|
1156
|
+
* Column-anchored: a declaration nested inside a function is indented, and
|
|
1157
|
+
* is not in scope at the end of the block anyway.
|
|
1158
|
+
*/
|
|
1159
|
+
var TOP_LEVEL_DECL=/^(?:export\\s+)?(?:async\\s+)?(?:function\\s*\\*?|class|const|let|var)\\s+([A-Za-z_$][\\w$]*)/gm;
|
|
1160
|
+
function republishTopLevel(src){
|
|
1161
|
+
var names=[],m;
|
|
1162
|
+
TOP_LEVEL_DECL.lastIndex=0;
|
|
1163
|
+
while((m=TOP_LEVEL_DECL.exec(src))!==null){
|
|
1164
|
+
if(names.indexOf(m[1])===-1)names.push(m[1]);
|
|
1165
|
+
}
|
|
1166
|
+
if(!names.length)return '';
|
|
1167
|
+
var out='\\n;';
|
|
1168
|
+
for(var i=0;i<names.length;i++){
|
|
1169
|
+
out+='try{if(typeof '+names[i]+'==="function")window.'+names[i]+'='+names[i]+'}catch(e){}';
|
|
1170
|
+
}
|
|
1171
|
+
return out;
|
|
1172
|
+
}
|
|
1132
1173
|
function runsAlways(declared, code){
|
|
1133
1174
|
if(declared==='always')return true;
|
|
1134
1175
|
if(declared==='once')return false;
|
|
@@ -2389,7 +2430,7 @@ else {
|
|
|
2389
2430
|
// ESM, and top-level 'import' is illegal inside a block, which
|
|
2390
2431
|
// would throw SyntaxError before the script ever runs.
|
|
2391
2432
|
var alreadyScoped=runsAlways(typeof entry==='string'?'':entry.run,text);
|
|
2392
|
-
ns.textContent=(hasImport||alreadyScoped)?text:'{'+text+'}';
|
|
2433
|
+
ns.textContent=(hasImport||alreadyScoped)?text:'{'+text+republishTopLevel(text)+'}';
|
|
2393
2434
|
ns.setAttribute('data-stx-page','');
|
|
2394
2435
|
var placeholder=entry.slot?qs('script[data-stx-route-script="'+entry.slot+'"]'):null;
|
|
2395
2436
|
if(placeholder&&placeholder.parentNode){
|
package/dist/serve.js
CHANGED
|
@@ -9800,7 +9800,7 @@ function __stxOverlay(errs){
|
|
|
9800
9800
|
rebuildDiscoveredPagePaths(kept);
|
|
9801
9801
|
await indexPageMiddleware(kept);
|
|
9802
9802
|
try {
|
|
9803
|
-
const { Router } = await import("./chunk-
|
|
9803
|
+
const { Router } = await import("./chunk-4azczpxz.js");
|
|
9804
9804
|
const pagesDirs = patterns.map((p) => p.replace(/\/$/, "")).filter(Boolean);
|
|
9805
9805
|
const router = new Router(process19.cwd(), { pagesDirs, stateDir: stateDirName(), exclude: options.exclude });
|
|
9806
9806
|
if (!options.quiet)
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bun-plugin-stx",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.2.
|
|
4
|
+
"version": "0.2.383",
|
|
5
5
|
"description": "A Bun plugin that allows for using Laravel Blade-like syntax.",
|
|
6
6
|
"author": "Chris Breuer <chris@stacksjs.org>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -74,7 +74,7 @@
|
|
|
74
74
|
"typecheck": "bun tsc --noEmit"
|
|
75
75
|
},
|
|
76
76
|
"dependencies": {
|
|
77
|
-
"@stacksjs/stx": "0.2.
|
|
78
|
-
"stx-router": "0.2.
|
|
77
|
+
"@stacksjs/stx": "0.2.383",
|
|
78
|
+
"stx-router": "0.2.383"
|
|
79
79
|
}
|
|
80
80
|
}
|