diff --git a/internal/bundler_tests/snapshots/snapshots_default.txt b/internal/bundler_tests/snapshots/snapshots_default.txt index 9337cce113e..06d867e79fb 100644 --- a/internal/bundler_tests/snapshots/snapshots_default.txt +++ b/internal/bundler_tests/snapshots/snapshots_default.txt @@ -4527,7 +4527,7 @@ copy import { __commonJS, __require -} from "./chunk-WXLYCZIT.js"; +} from "./chunk-MQN2VSL5.js"; // project/cjs.js var require_cjs = __commonJS({ @@ -4558,15 +4558,15 @@ console.log( e, __require("extern-cjs"), require_cjs(), - import("./dynamic-TGITTCVZ.js") + import("./dynamic-Q2DWDUFV.js") ); var exported; export { exported }; ----------- /out/dynamic-TGITTCVZ.js ---------- -import "./chunk-WXLYCZIT.js"; +---------- /out/dynamic-Q2DWDUFV.js ---------- +import "./chunk-MQN2VSL5.js"; // project/dynamic.js var dynamic_default = 5; @@ -4574,7 +4574,7 @@ export { dynamic_default as default }; ----------- /out/chunk-WXLYCZIT.js ---------- +---------- /out/chunk-MQN2VSL5.js ---------- export { __require, __commonJS @@ -4731,7 +4731,7 @@ d { "out/entry.js": { "imports": [ { - "path": "out/chunk-WXLYCZIT.js", + "path": "out/chunk-MQN2VSL5.js", "kind": "import-statement" }, { @@ -4753,7 +4753,7 @@ d { "external": true }, { - "path": "out/dynamic-TGITTCVZ.js", + "path": "out/dynamic-Q2DWDUFV.js", "kind": "dynamic-import" } ], @@ -4780,10 +4780,10 @@ d { }, "bytes": 642 }, - "out/dynamic-TGITTCVZ.js": { + "out/dynamic-Q2DWDUFV.js": { "imports": [ { - "path": "out/chunk-WXLYCZIT.js", + "path": "out/chunk-MQN2VSL5.js", "kind": "import-statement" } ], @@ -4798,7 +4798,7 @@ d { }, "bytes": 119 }, - "out/chunk-WXLYCZIT.js": { + "out/chunk-MQN2VSL5.js": { "imports": [], "exports": [ "__commonJS", diff --git a/internal/bundler_tests/snapshots/snapshots_glob.txt b/internal/bundler_tests/snapshots/snapshots_glob.txt index 5c008b8090d..59b248d7fa9 100644 --- a/internal/bundler_tests/snapshots/snapshots_glob.txt +++ b/internal/bundler_tests/snapshots/snapshots_glob.txt @@ -59,13 +59,13 @@ TestGlobBasicSplitting ---------- /out/entry.js ---------- import { require_a -} from "./chunk-Z3PINQB2.js"; +} from "./chunk-KO426RN2.js"; import { require_b -} from "./chunk-XAB6ATD2.js"; +} from "./chunk-SGVK3D4Q.js"; import { __glob -} from "./chunk-NI2FVOS3.js"; +} from "./chunk-WCFE7E2E.js"; // require("./src/**/*") in entry.js var globRequire_src = __glob({ @@ -75,8 +75,8 @@ var globRequire_src = __glob({ // import("./src/**/*") in entry.js var globImport_src = __glob({ - "./src/a.js": () => import("./a-G7HQS5H7.js"), - "./src/b.js": () => import("./b-DBW3WPXU.js") + "./src/a.js": () => import("./a-7QA47R6Z.js"), + "./src/b.js": () => import("./b-KY4MVCQS.js") }); // entry.js @@ -92,17 +92,17 @@ console.log({ } }); ----------- /out/a-G7HQS5H7.js ---------- +---------- /out/a-7QA47R6Z.js ---------- import { require_a -} from "./chunk-Z3PINQB2.js"; -import "./chunk-NI2FVOS3.js"; +} from "./chunk-KO426RN2.js"; +import "./chunk-WCFE7E2E.js"; export default require_a(); ----------- /out/chunk-Z3PINQB2.js ---------- +---------- /out/chunk-KO426RN2.js ---------- import { __commonJS -} from "./chunk-NI2FVOS3.js"; +} from "./chunk-WCFE7E2E.js"; // src/a.js var require_a = __commonJS({ @@ -115,17 +115,17 @@ export { require_a }; ----------- /out/b-DBW3WPXU.js ---------- +---------- /out/b-KY4MVCQS.js ---------- import { require_b -} from "./chunk-XAB6ATD2.js"; -import "./chunk-NI2FVOS3.js"; +} from "./chunk-SGVK3D4Q.js"; +import "./chunk-WCFE7E2E.js"; export default require_b(); ----------- /out/chunk-XAB6ATD2.js ---------- +---------- /out/chunk-SGVK3D4Q.js ---------- import { __commonJS -} from "./chunk-NI2FVOS3.js"; +} from "./chunk-WCFE7E2E.js"; // src/b.js var require_b = __commonJS({ @@ -138,7 +138,7 @@ export { require_b }; ----------- /out/chunk-NI2FVOS3.js ---------- +---------- /out/chunk-WCFE7E2E.js ---------- export { __glob, __commonJS @@ -321,13 +321,13 @@ TestTSGlobBasicSplitting ---------- /out/entry.js ---------- import { require_a -} from "./chunk-NW3BCH2J.js"; +} from "./chunk-YMCIDKCT.js"; import { require_b -} from "./chunk-LX6LSYGO.js"; +} from "./chunk-2BST4PYI.js"; import { __glob -} from "./chunk-NI2FVOS3.js"; +} from "./chunk-WCFE7E2E.js"; // require("./src/**/*") in entry.ts var globRequire_src = __glob({ @@ -337,8 +337,8 @@ var globRequire_src = __glob({ // import("./src/**/*") in entry.ts var globImport_src = __glob({ - "./src/a.ts": () => import("./a-CIKLEGQA.js"), - "./src/b.ts": () => import("./b-UWTMLRMB.js") + "./src/a.ts": () => import("./a-YXM4MR7E.js"), + "./src/b.ts": () => import("./b-IPMBSSGN.js") }); // entry.ts @@ -354,17 +354,17 @@ console.log({ } }); ----------- /out/a-CIKLEGQA.js ---------- +---------- /out/a-YXM4MR7E.js ---------- import { require_a -} from "./chunk-NW3BCH2J.js"; -import "./chunk-NI2FVOS3.js"; +} from "./chunk-YMCIDKCT.js"; +import "./chunk-WCFE7E2E.js"; export default require_a(); ----------- /out/chunk-NW3BCH2J.js ---------- +---------- /out/chunk-YMCIDKCT.js ---------- import { __commonJS -} from "./chunk-NI2FVOS3.js"; +} from "./chunk-WCFE7E2E.js"; // src/a.ts var require_a = __commonJS({ @@ -377,17 +377,17 @@ export { require_a }; ----------- /out/b-UWTMLRMB.js ---------- +---------- /out/b-IPMBSSGN.js ---------- import { require_b -} from "./chunk-LX6LSYGO.js"; -import "./chunk-NI2FVOS3.js"; +} from "./chunk-2BST4PYI.js"; +import "./chunk-WCFE7E2E.js"; export default require_b(); ----------- /out/chunk-LX6LSYGO.js ---------- +---------- /out/chunk-2BST4PYI.js ---------- import { __commonJS -} from "./chunk-NI2FVOS3.js"; +} from "./chunk-WCFE7E2E.js"; // src/b.ts var require_b = __commonJS({ @@ -400,7 +400,7 @@ export { require_b }; ----------- /out/chunk-NI2FVOS3.js ---------- +---------- /out/chunk-WCFE7E2E.js ---------- export { __glob, __commonJS diff --git a/internal/bundler_tests/snapshots/snapshots_splitting.txt b/internal/bundler_tests/snapshots/snapshots_splitting.txt index 3976512cc97..da0de38d5f7 100644 --- a/internal/bundler_tests/snapshots/snapshots_splitting.txt +++ b/internal/bundler_tests/snapshots/snapshots_splitting.txt @@ -259,19 +259,19 @@ TestSplittingDynamicAndNotDynamicCommonJSIntoES6 import { __toESM, require_foo -} from "./chunk-P5A5627R.js"; +} from "./chunk-X3UWZZCR.js"; // entry.js var import_foo = __toESM(require_foo()); -import("./foo-N2LAC7TT.js").then(({ default: { bar: b } }) => console.log(import_foo.bar, b)); +import("./foo-BJYZ44Z3.js").then(({ default: { bar: b } }) => console.log(import_foo.bar, b)); ----------- /out/foo-N2LAC7TT.js ---------- +---------- /out/foo-BJYZ44Z3.js ---------- import { require_foo -} from "./chunk-P5A5627R.js"; +} from "./chunk-X3UWZZCR.js"; export default require_foo(); ----------- /out/chunk-P5A5627R.js ---------- +---------- /out/chunk-X3UWZZCR.js ---------- // foo.js var require_foo = __commonJS({ "foo.js"(exports) { @@ -314,9 +314,9 @@ export { TestSplittingDynamicCommonJSIntoES6 ---------- /out/entry.js ---------- // entry.js -import("./foo-LH6ELO2A.js").then(({ default: { bar } }) => console.log(bar)); +import("./foo-X6C7FV5C.js").then(({ default: { bar } }) => console.log(bar)); ----------- /out/foo-LH6ELO2A.js ---------- +---------- /out/foo-X6C7FV5C.js ---------- // foo.js var require_foo = __commonJS({ "foo.js"(exports) { @@ -371,7 +371,7 @@ TestSplittingHybridESMAndCJSIssue617 import { foo, init_a -} from "./chunk-P3Z6IJKQ.js"; +} from "./chunk-PDZFCFBH.js"; init_a(); export { foo @@ -382,7 +382,7 @@ import { __toCommonJS, a_exports, init_a -} from "./chunk-P3Z6IJKQ.js"; +} from "./chunk-PDZFCFBH.js"; // b.js var bar = (init_a(), __toCommonJS(a_exports)); @@ -390,7 +390,7 @@ export { bar }; ----------- /out/chunk-P3Z6IJKQ.js ---------- +---------- /out/chunk-PDZFCFBH.js ---------- // a.js var a_exports = {}; __export(a_exports, { @@ -541,7 +541,7 @@ TestSplittingSharedCommonJSIntoES6 ---------- /out/a.js ---------- import { require_shared -} from "./chunk-EJ4GJF3D.js"; +} from "./chunk-JQJBVS2P.js"; // a.js var { foo } = require_shared(); @@ -550,13 +550,13 @@ console.log(foo); ---------- /out/b.js ---------- import { require_shared -} from "./chunk-EJ4GJF3D.js"; +} from "./chunk-JQJBVS2P.js"; // b.js var { foo } = require_shared(); console.log(foo); ----------- /out/chunk-EJ4GJF3D.js ---------- +---------- /out/chunk-JQJBVS2P.js ---------- // shared.js var require_shared = __commonJS({ "shared.js"(exports) { diff --git a/internal/runtime/runtime.go b/internal/runtime/runtime.go index 600d7ac8d1b..e46ded6e7d0 100644 --- a/internal/runtime/runtime.go +++ b/internal/runtime/runtime.go @@ -75,9 +75,8 @@ func Source(unsupportedJSFeatures compat.JSFeature) logger.Source { var __reflectGet = Reflect.get var __reflectSet = Reflect.set - var __knownSymbol = (name, symbol) => { - return (symbol = Symbol[name]) ? symbol : Symbol.for('Symbol.' + name) - } + var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : Symbol.for('Symbol.' + name) + var __throwTypeError = msg => { throw TypeError(msg) } export var __pow = Math.pow @@ -263,30 +262,33 @@ func Source(unsupportedJSFeatures compat.JSFeature) logger.Source { export var __decorateParam = (index, decorator) => (target, key) => decorator(target, key, index) // For class members - export var __publicField = (obj, key, value) => { + export var __publicField = (obj, key, value) => ( __defNormalProp(obj, typeof key !== 'symbol' ? key + '' : key, value) - return value - } - var __accessCheck = (obj, member, msg) => { - if (!member.has(obj)) throw TypeError('Cannot ' + msg) - } - export var __privateIn = (member, obj) => { - if (Object(obj) !== obj) throw TypeError('Cannot use the "in" operator on this value') - return member.has(obj) - } - export var __privateGet = (obj, member, getter) => { - __accessCheck(obj, member, 'read from private field') - return getter ? getter.call(obj) : member.get(obj) - } - export var __privateAdd = (obj, member, value) => { - if (member.has(obj)) throw TypeError('Cannot add the same private member more than once') + ) + var __accessCheck = (obj, member, msg) => ( + member.has(obj) || __throwTypeError('Cannot ' + msg) + ) + export var __privateIn = (member, obj) => ( + Object(obj) !== obj ? __throwTypeError('Cannot use the "in" operator on this value') : + member.has(obj) + ) + export var __privateGet = (obj, member, getter) => ( + __accessCheck(obj, member, 'read from private field'), + getter ? getter.call(obj) : member.get(obj) + ) + export var __privateAdd = (obj, member, value) => ( + member.has(obj) ? __throwTypeError('Cannot add the same private member more than once') : member instanceof WeakSet ? member.add(obj) : member.set(obj, value) - } - export var __privateSet = (obj, member, value, setter) => { - __accessCheck(obj, member, 'write to private field') - setter ? setter.call(obj, value) : member.set(obj, value) - return value - } + ) + export var __privateSet = (obj, member, value, setter) => ( + __accessCheck(obj, member, 'write to private field'), + setter ? setter.call(obj, value) : member.set(obj, value), + value + ) + export var __privateMethod = (obj, member, method) => ( + __accessCheck(obj, member, 'access private method'), + method + ) export var __earlyAccess = (name) => { throw ReferenceError('Cannot access "' + name + '" before initialization') } @@ -309,11 +311,6 @@ func Source(unsupportedJSFeatures compat.JSFeature) logger.Source { } text += ` - export var __privateMethod = (obj, member, method) => { - __accessCheck(obj, member, 'access private method') - return method - } - // For "super" property accesses export var __superGet = (cls, obj, key) => __reflectGet(__getProtoOf(cls), key, obj) export var __superSet = (cls, obj, key, val) => (__reflectSet(__getProtoOf(cls), key, val, obj), val) @@ -378,9 +375,7 @@ func Source(unsupportedJSFeatures compat.JSFeature) logger.Source { } catch (e) { no(e) } - } - var method = k => it[k] = x => new Promise((yes, no) => resume(k, x, yes, no)) - var it = {} + }, method = k => it[k] = x => new Promise((yes, no) => resume(k, x, yes, no)), it = {} return generator = generator.apply(__this, __arguments), it[__knownSymbol('asyncIterator')] = () => it, method('next'), @@ -389,10 +384,7 @@ func Source(unsupportedJSFeatures compat.JSFeature) logger.Source { it } export var __yieldStar = value => { - var obj = value[__knownSymbol('asyncIterator')] - var isAwait = false - var method - var it = {} + var obj = value[__knownSymbol('asyncIterator')], isAwait = false, method, it = {} if (obj == null) { obj = value[__knownSymbol('iterator')]() method = k => it[k] = x => obj[k](x) @@ -409,7 +401,7 @@ func Source(unsupportedJSFeatures compat.JSFeature) logger.Source { done: false, value: new __await(new Promise(resolve => { var x = obj[k](v) - if (!(x instanceof Object)) throw TypeError('Object expected') + if (!(x instanceof Object)) __throwTypeError('Object expected') resolve(x) }), 1), } @@ -461,11 +453,11 @@ func Source(unsupportedJSFeatures compat.JSFeature) logger.Source { // These are for the "using" statement in TypeScript 5.2+ export var __using = (stack, value, async) => { if (value != null) { - if (typeof value !== 'object' && typeof value !== 'function') throw TypeError('Object expected') + if (typeof value !== 'object' && typeof value !== 'function') __throwTypeError('Object expected') var dispose if (async) dispose = value[__knownSymbol('asyncDispose')] if (dispose === void 0) dispose = value[__knownSymbol('dispose')] - if (typeof dispose !== 'function') throw TypeError('Object not disposable') + if (typeof dispose !== 'function') __throwTypeError('Object not disposable') stack.push([async, dispose, value]) } else if (async) { stack.push([async]) diff --git a/scripts/js-api-tests.js b/scripts/js-api-tests.js index 74c11b6a743..d2f9a792c35 100644 --- a/scripts/js-api-tests.js +++ b/scripts/js-api-tests.js @@ -905,8 +905,8 @@ export { const names2 = result2.outputFiles.map(x => path.basename(x.path)).sort() // Check that the public path is included in chunk hashes but not asset hashes - assert.deepStrictEqual(names1, ['data-BYATPJRB.bin', 'in-7SVE3DTC.js']) - assert.deepStrictEqual(names2, ['data-BYATPJRB.bin', 'in-E6EBO534.js']) + assert.deepStrictEqual(names1, ['data-BYATPJRB.bin', 'in-6QN3TZ3A.js']) + assert.deepStrictEqual(names2, ['data-BYATPJRB.bin', 'in-EJERHMG4.js']) }, async fileLoaderPublicPath({ esbuild, testDir }) { @@ -5536,10 +5536,7 @@ let transformTests = { }) assert.strictEqual(code, `var __defProp = Object.defineProperty; var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; -var __publicField = (obj, key, value) => { - __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value); - return value; -}; +var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value); class Foo { constructor() { __publicField(this, "foo");