mirror of
https://github.com/lancedikson/bowser
synced 2026-10-08 03:41:50 +00:00
fix: restore ES5 output for bundled.js, and assert it
`bundled.js` stopped being ES5 when the webpack build was replaced by tsdown in #628. It parses at ecmaVersion 2015 but not 5: var t=(t,e)=>()=>(e||(t((e={exports:{}}).exports,e),t=null),e.exports) That is rolldown's `__commonJS` interop helper. `@rolldown/plugin-babel` only transforms input modules, and rolldown appends the helper afterwards; terser with `ecma: 5` avoids introducing newer syntax but does not transpile, so the arrow functions reached the published file. `es5.js` has no CommonJS dependencies and never gets the helper, which is why only `bundled.js` broke. The effect is total rather than partial: in an ES5 engine the whole script is a SyntaxError, so `bundled.js` — the bundle that exists specifically to serve those engines, polyfills included — does not load at all there. Lower the emitted chunk with a babel renderChunk pass that runs after bundling and before terser, so rolldown's own helpers are covered too. Costs 2.8 kB (+1.6%) on bundled.js; es5.js is unchanged at 34 kB. The existing guard was a grep for backticks, which this syntax slips straight past. Replace it with an acorn parse at ecmaVersion 5 over both legacy bundles, plus a tokeniser check for real template literals (backticks inside core-js string literals are fine, and 2.14.1 shipped three of them). Verified by reverting the build fix: `bundled.js parses as ES5` fails, and passes again once restored. Also confirmed bundled.js loads and parses the live navigator.userAgent in a real browser.
This commit is contained in:
27
pnpm-lock.yaml
generated
27
pnpm-lock.yaml
generated
@@ -42,6 +42,9 @@ importers:
|
||||
'@rolldown/plugin-babel':
|
||||
specifier: 0.2.3
|
||||
version: 0.2.3(@babel/core@7.29.7(supports-color@7.2.0))(rolldown@1.2.0)
|
||||
acorn:
|
||||
specifier: ^8.18.0
|
||||
version: 8.18.0
|
||||
ava:
|
||||
specifier: ^3.0.0
|
||||
version: 3.15.0(supports-color@7.2.0)
|
||||
@@ -1330,8 +1333,8 @@ packages:
|
||||
resolution: {integrity: sha512-HEHNfbars9v4pgpW6SO1KSPkfoS0xVOM/9UzkJltjlsHZmJasxg8aXkuZa7SMf8vKGIBhpUsPluQSqhJFCqebw==}
|
||||
engines: {node: '>=0.4.0'}
|
||||
|
||||
acorn@8.17.0:
|
||||
resolution: {integrity: sha512-xRQbDb9BnwDafYNn6Vwl839DYVjqXYb1XVGtWAZ1kcDc6iwAL4hg3B1dZlRiuENFeO2H53gFG3in621AdERVAg==}
|
||||
acorn@8.18.0:
|
||||
resolution: {integrity: sha512-lGq+9yr1/GuAWaVYIHRjvvySG5/4VfKIvC8EWxStPdcDh/Ka7FG3twP6v4d5BkravUilhIAsG4Qj83t02LWUPQ==}
|
||||
engines: {node: '>=0.4.0'}
|
||||
hasBin: true
|
||||
|
||||
@@ -5853,15 +5856,15 @@ snapshots:
|
||||
mime-types: 3.0.2
|
||||
negotiator: 1.0.0
|
||||
|
||||
acorn-jsx@5.3.2(acorn@8.17.0):
|
||||
acorn-jsx@5.3.2(acorn@8.18.0):
|
||||
dependencies:
|
||||
acorn: 8.17.0
|
||||
acorn: 8.18.0
|
||||
|
||||
acorn-walk@8.3.5:
|
||||
dependencies:
|
||||
acorn: 8.17.0
|
||||
acorn: 8.18.0
|
||||
|
||||
acorn@8.17.0: {}
|
||||
acorn@8.18.0: {}
|
||||
|
||||
aggregate-error@3.1.0:
|
||||
dependencies:
|
||||
@@ -6006,7 +6009,7 @@ snapshots:
|
||||
ava@3.15.0(supports-color@7.2.0):
|
||||
dependencies:
|
||||
'@concordance/react': 2.0.0
|
||||
acorn: 8.17.0
|
||||
acorn: 8.18.0
|
||||
acorn-walk: 8.3.5
|
||||
ansi-styles: 5.2.0
|
||||
arrgv: 1.0.2
|
||||
@@ -6993,14 +6996,14 @@ snapshots:
|
||||
|
||||
espree@10.4.0:
|
||||
dependencies:
|
||||
acorn: 8.17.0
|
||||
acorn-jsx: 5.3.2(acorn@8.17.0)
|
||||
acorn: 8.18.0
|
||||
acorn-jsx: 5.3.2(acorn@8.18.0)
|
||||
eslint-visitor-keys: 4.2.1
|
||||
|
||||
espree@11.2.0:
|
||||
dependencies:
|
||||
acorn: 8.17.0
|
||||
acorn-jsx: 5.3.2(acorn@8.17.0)
|
||||
acorn: 8.18.0
|
||||
acorn-jsx: 5.3.2(acorn@8.18.0)
|
||||
eslint-visitor-keys: 5.0.1
|
||||
|
||||
esprima@4.0.1: {}
|
||||
@@ -8915,7 +8918,7 @@ snapshots:
|
||||
terser@5.49.0:
|
||||
dependencies:
|
||||
'@jridgewell/source-map': 0.3.11
|
||||
acorn: 8.17.0
|
||||
acorn: 8.18.0
|
||||
commander: 2.20.3
|
||||
source-map-support: 0.5.21
|
||||
|
||||
|
||||
Reference in New Issue
Block a user