aboutsummaryrefslogtreecommitdiff
path: root/test/bundler/bundler_regressions.test.ts
blob: b8792f5ea6819737c0d18ee71ae1e75443545c93 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
import assert from "assert";
import { itBundled, testForFile } from "./expectBundled";
var { describe, test, expect } = testForFile(import.meta.path);

describe("bundler", () => {
  // https://github.com/oven-sh/bun/issues/2946
  itBundled("regression/InvalidIdentifierInFileName#2946", {
    files: {
      "/entry.js": "import foo from './1.png';\nconsole.log(foo);",
      "/1.png": "abcdefgh",
    },
    entryPoints: ["/entry.js"],
    outdir: "/out",
    run: {
      file: "/out/entry.js",
    },
  });

  itBundled("regression/MergeAdjacentDecl#2942", {
    files: {
      "/shared.js": `
      // Current version.
      export var VERSION = '1.13.6';
      
      // Establish the root object, \`window\` (\`self\`) in the browser, \`global\`
      // on the server, or \`this\` in some virtual machines. We use \`self\`
      // instead of \`window\` for \`WebWorker\` support.
      export var root = (typeof self == 'object' && self.self === self && self) ||
                (typeof global == 'object' && global.global === global && global) ||
                Function('return this')() ||
                {};
      
      // Save bytes in the minified (but not gzipped) version:
      export var ArrayProto = Array.prototype, ObjProto = Object.prototype;
      export var SymbolProto = typeof Symbol !== 'undefined' ? Symbol.prototype : null;
      
      // Create quick reference variables for speed access to core prototypes.
      export var push = ArrayProto.push,
          slice = ArrayProto.slice,
          toString = ObjProto.toString,
          hasOwnProperty = ObjProto.hasOwnProperty;
      
      // Modern feature detection.
      export var supportsArrayBuffer = typeof ArrayBuffer !== 'undefined',
          supportsDataView = typeof DataView !== 'undefined';
      
      // All **ECMAScript 5+** native function implementations that we hope to use
      // are declared here.
      export var nativeIsArray = Array.isArray,
          nativeKeys = Object.keys,
          nativeCreate = Object.create,
          nativeIsView = supportsArrayBuffer && ArrayBuffer.isView;
      
      // Create references to these builtin functions because we override them.
      export var _isNaN = isNaN,
          _isFinite = isFinite;
      
      // Keys in IE < 9 that won't be iterated by \`for key in ...\` and thus missed.
      export var hasEnumBug = !{toString: null}.propertyIsEnumerable('toString');
      export var nonEnumerableProps = ['valueOf', 'isPrototypeOf', 'toString',
        'propertyIsEnumerable', 'hasOwnProperty', 'toLocaleString'];
      
      // The largest integer that can be represented exactly.
      export var MAX_ARRAY_INDEX = Math.pow(2, 53) - 1;
      
      `,
      // This was a race condition, so we want to add a lot of files to maximize the chances of hitting it
      "/a.js": "import * as ABC from './shared.js';; console.log(ABC);",
      "/b.js": "import * as ABC from './shared.js'; console.log(ABC);",
      "/c.js": "import * as ABC from './shared.js';; console.log(ABC);",
      "/d.js": "import * as ABC from './shared.js'; console.log(ABC);",
      "/e.js": "import * as ABC from './shared.js'; console.log(ABC);",
      "/g.js": "import * as ABC from './shared.js'; console.log(ABC);",
      "/h.js": "import * as ABC from './shared.js'; console.log(ABC);",
      "/i.js": "import * as ABC from './shared.js'; console.log(ABC);",
      "/j.js": "import * as ABC from './shared.js'; console.log(ABC);",
      "/k.js": "import * as ABC from './shared.js'; console.log(ABC);",
      "/l.js": "import * as ABC from './shared.js'; console.log(ABC);",
      "/m.js": "import * as ABC from './shared.js'; console.log(ABC);",
      "/n.js": "import * as ABC from './shared.js'; console.log(ABC);",
      "/a_1.js": "import * as ABC from './shared.js';; console.log(ABC);",
      "/a_2.js": "import * as ABC from './shared.js'; console.log(ABC);",
      "/a_3.js": "import * as ABC from './shared.js';; console.log(ABC);",
      "/a_4.js": "import * as ABC from './shared.js'; console.log(ABC);",
      "/a_5.js": "import * as ABC from './shared.js'; console.log(ABC);",
      "/a_6.js": "import * as ABC from './shared.js'; console.log(ABC);",
      "/a_7.js": "import * as ABC from './shared.js'; console.log(ABC);",
      "/a_8.js": "import * as ABC from './shared.js'; console.log(ABC);",
      "/a_9.js": "import * as ABC from './shared.js'; console.log(ABC);",
      "/a_10.js": "import * as ABC from './shared.js'; console.log(ABC);",
      "/a_11.js": "import * as ABC from './shared.js'; console.log(ABC);",
      "/a_12.js": "import * as ABC from './shared.js'; console.log(ABC);",
      "/a_13.js": "import * as ABC from './shared.js'; console.log(ABC);",
      "/b_1.js": "import * as ABC from './shared.js';; console.log(ABC);",
      "/b_2.js": "import * as ABC from './shared.js'; console.log(ABC);",
      "/b_3.js": "import * as ABC from './shared.js';; console.log(ABC);",
      "/b_4.js": "import * as ABC from './shared.js'; console.log(ABC);",
      "/b_5.js": "import * as ABC from './shared.js'; console.log(ABC);",
      "/b_6.js": "import * as ABC from './shared.js'; console.log(ABC);",
      "/b_7.js": "import * as ABC from './shared.js'; console.log(ABC);",
      "/b_8.js": "import * as ABC from './shared.js'; console.log(ABC);",
      "/b_9.js": "import * as ABC from './shared.js'; console.log(ABC);",
      "/b_10.js": "import * as ABC from './shared.js'; console.log(ABC);",
      "/b_11.js": "import * as ABC from './shared.js'; console.log(ABC);",
      "/b_12.js": "import * as ABC from './shared.js'; console.log(ABC);",
      "/b_13.js": "import * as ABC from './shared.js'; console.log(ABC);",
    },
    minifySyntax: true,

    entryPoints: [
      "/a.js",
      "/b.js",
      "/c.js",
      "/d.js",
      "/e.js",
      "/g.js",
      "/h.js",
      "/i.js",
      "/j.js",
      "/k.js",
      "/l.js",
      "/m.js",
      "/n.js",
      "/a_1.js",
      "/a_2.js",
      "/a_3.js",
      "/a_4.js",
      "/a_5.js",
      "/a_6.js",
      "/a_7.js",
      "/a_8.js",
      "/a_9.js",
      "/a_10.js",
      "/a_11.js",
      "/a_12.js",
      "/a_13.js",
      "/b_1.js",
      "/b_2.js",
      "/b_3.js",
      "/b_4.js",
      "/b_5.js",
      "/b_6.js",
      "/b_7.js",
      "/b_8.js",
      "/b_9.js",
      "/b_10.js",
      "/b_11.js",
      "/b_12.js",
      "/b_13.js",
    ],
  });

  // https://github.com/oven-sh/bun/issues/2948
  itBundled("regression/ReassignLocal#2948", {
    files: {
      "/entry.js": `
      import { Buffer } from 'node:buffer';

      export function schemaEncode(data) {
        const filename_len = Buffer.byteLength(data.filename);
        const buf = Buffer.allocUnsafe(29 + filename_len);
        buf.writeUInt8(1);
        for (let i=0; i<3; i++) buf.writeUInt32LE(data.to[i], 1 + i * 4);
        buf.writeDoubleLE(data.random, 13);
        buf.writeUInt16LE(data.page, 21);
        let offset = 23;
        offset = buf.writeUInt16LE(filename_len, offset);
        offset += buf.write(data.filename, offset);
        buf.writeUInt32LE(data.from, offset);
        return buf;
      }

      schemaEncode({filename: "heyyyy", to: [1,2,3], page: 123, random: Math.random(), from: 158})
      `,
    },
    minifySyntax: true,
    target: "bun",
    run: {
      file: "/entry.js",
    },
  });

  // https://github.com/oven-sh/bun/issues/3660
  itBundled("regression/StringDecoder#3660", {
    files: {
      "/entry.js": `
        import { StringDecoder } from 'string_decoder'

        const decoder = new StringDecoder('utf8')
        const buf = Buffer.from([0xe4, 0xbd, 0xa0, 0xe5, 0xa5, 0xbd])
        const str = decoder.write(buf)

        console.log(str)
      `,
    },
    run: { stdout: "你好" },
  });
});