@bakery-framework/plugin-vue 2.0.0-alpha.15 → 2.0.0-alpha.17

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.
Files changed (2) hide show
  1. package/package.json +2 -2
  2. package/src/compile.ts +31 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bakery-framework/plugin-vue",
3
- "version": "2.0.0-alpha.15",
3
+ "version": "2.0.0-alpha.17",
4
4
  "description": "Bakery vue plugin.",
5
5
  "keywords": [
6
6
  "bakery",
@@ -43,7 +43,7 @@
43
43
  "vue": "^3.5.38"
44
44
  },
45
45
  "dependencies": {
46
- "@bakery-framework/core": "^2.0.0-alpha.15"
46
+ "@bakery-framework/core": "^2.0.0-alpha.17"
47
47
  },
48
48
  "engines": {
49
49
  "bun": ">=1.4.0"
package/src/compile.ts CHANGED
@@ -205,6 +205,23 @@ export async function compileTemplateBlock(
205
205
  e instanceof Error ? e.message : String(e),
206
206
  )
207
207
 
208
+ // `export function render` becomes a local `function render`, which
209
+ // `assembleComponent` then hangs off `__sfc__.render`.
210
+ //
211
+ // **This must stay above `compileText`, and the anchor is why.** The
212
+ // template compiler emits multi-line source with the export at a line
213
+ // start, so `^` matches. `compileText` minifies to a single line where the
214
+ // export lands after the `import{…}from"vue";` prologue, and `^` cannot
215
+ // reach it there. Measured over four render shapes: correct on all four
216
+ // before minification, wrong on the one real shape after. Swapping these
217
+ // two lines therefore breaks silently — the bundle still builds, still
218
+ // serves 200, and ships a module with a stray `export` in the middle of it.
219
+ //
220
+ // A regex is the wrong tool for this and no spelling fixes it. An
221
+ // anchor-free `\bexport\s+(?=function\b)` handles the minified shape and
222
+ // then eats the words out of a string literal that contains them. The
223
+ // trade was measured rather than argued; the ordering is the cheaper
224
+ // guarantee, so it is the one written down.
208
225
  let code = result.code
209
226
  code = code.replace(/^export\s+/m, '')
210
227
  code = await compileText(code)
@@ -233,8 +250,20 @@ export function assembleComponent(options: AssembleComponentOptions): string {
233
250
  )
234
251
 
235
252
  if (renderCode) {
236
- const renderFn = renderCode.replace(/^export\s+/m, '')
237
- output += `\n${renderFn}\n${COMPONENT_VAR}.render = render;`
253
+ // No export strip here, deliberately. `compileTemplateBlock` has already
254
+ // removed it, above minification where the removal works, and repeating
255
+ // it on this input is a no-op that *reads* as a backstop.
256
+ //
257
+ // The line that used to sit here was `/^export\s+/m` over
258
+ // already-minified code. Measured against four render shapes it fired on
259
+ // three and missed the fourth, and the fourth is the only one this
260
+ // function is ever handed: minified, with the export sitting after the
261
+ // import prologue where `^` cannot see it. A guard that cannot fire on
262
+ // its own input is worse than none, because the next reader counts on it.
263
+ //
264
+ // Three lines above is what the right spelling looks like when the input
265
+ // may be minified: `\b` and no anchor.
266
+ output += `\n${renderCode}\n${COMPONENT_VAR}.render = render;`
238
267
  }
239
268
 
240
269
  if (scopeId) {