metro-transform-worker 0.71.0 → 0.71.3

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.
@@ -1,702 +0,0 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- * @emails oncall+metro_bundler
8
- * @flow strict-local
9
- * @format
10
- */
11
-
12
- 'use strict';
13
-
14
- jest
15
- .mock('../utils/getMinifier', () => () => ({code, map}) => ({
16
- code: code.replace('arbitrary(code)', 'minified(code)'),
17
- map,
18
- }))
19
- .mock('metro-transform-plugins', () => ({
20
- ...jest.requireActual('metro-transform-plugins'),
21
- inlinePlugin: () => ({}),
22
- constantFoldingPlugin: () => ({}),
23
- }))
24
- .mock('metro-minify-uglify');
25
-
26
- import type {JsTransformerConfig} from '../index';
27
- import typeof TransformerType from '../index';
28
- import typeof FSType from 'fs';
29
-
30
- const HermesCompiler = require('metro-hermes-compiler');
31
- const path = require('path');
32
-
33
- const babelTransformerPath = require.resolve(
34
- 'metro-react-native-babel-transformer',
35
- );
36
- const transformerContents = (() =>
37
- require('fs').readFileSync(babelTransformerPath))();
38
-
39
- const HEADER_DEV =
40
- '__d(function (global, _$$_REQUIRE, _$$_IMPORT_DEFAULT, _$$_IMPORT_ALL, module, exports, _dependencyMap) {';
41
- const HEADER_PROD = '__d(function (g, r, i, a, m, e, d) {';
42
-
43
- let fs: FSType;
44
- let Transformer: TransformerType;
45
-
46
- const baseConfig: JsTransformerConfig = {
47
- allowOptionalDependencies: false,
48
- assetPlugins: [],
49
- assetRegistryPath: '',
50
- asyncRequireModulePath: 'asyncRequire',
51
- babelTransformerPath,
52
- dynamicDepsInPackages: 'reject',
53
- enableBabelRCLookup: false,
54
- enableBabelRuntime: true,
55
- experimentalImportBundleSupport: false,
56
- globalPrefix: '',
57
- hermesParser: false,
58
- minifierConfig: {},
59
- minifierPath: 'minifyModulePath',
60
- optimizationSizeLimit: 100000,
61
- publicPath: '/assets',
62
- unstable_collectDependenciesPath:
63
- 'metro/src/ModuleGraph/worker/collectDependencies',
64
- unstable_dependencyMapReservedName: null,
65
- unstable_compactOutput: false,
66
- unstable_disableModuleWrapping: false,
67
- unstable_disableNormalizePseudoGlobals: false,
68
- };
69
-
70
- beforeEach(() => {
71
- jest.resetModules();
72
-
73
- jest.mock('fs', () => new (require('metro-memory-fs'))());
74
-
75
- fs = require('fs');
76
- Transformer = require('../');
77
- // $FlowFixMe[prop-missing] Cannot call `fs.reset` because property `reset` is missing in module `fs`
78
- fs.reset();
79
-
80
- fs.mkdirSync('/root/local', {recursive: true});
81
- fs.mkdirSync(path.dirname(babelTransformerPath), {recursive: true});
82
- fs.writeFileSync(babelTransformerPath, transformerContents);
83
- });
84
-
85
- it('transforms a simple script', async () => {
86
- const result = await Transformer.transform(
87
- baseConfig,
88
- '/root',
89
- 'local/file.js',
90
- // $FlowFixMe[incompatible-call] Added when annotating Transformer. string is incompatible with Buffer.
91
- 'someReallyArbitrary(code)',
92
- // $FlowFixMe[prop-missing] Added when annotating Transformer.
93
- {
94
- dev: true,
95
- type: 'script',
96
- },
97
- );
98
-
99
- expect(result.output[0].type).toBe('js/script');
100
- expect(result.output[0].data.code).toBe(
101
- [
102
- '(function (global) {',
103
- ' someReallyArbitrary(code);',
104
- "})(typeof globalThis !== 'undefined' ? globalThis : typeof global !== 'undefined' ? global : typeof window !== 'undefined' ? window : this);",
105
- ].join('\n'),
106
- );
107
- expect(result.output[0].data.map).toMatchSnapshot();
108
- expect(result.output[0].data.functionMap).toMatchSnapshot();
109
- expect(result.dependencies).toEqual([]);
110
- });
111
-
112
- it('transforms a simple module', async () => {
113
- const result = await Transformer.transform(
114
- baseConfig,
115
- '/root',
116
- 'local/file.js',
117
- // $FlowFixMe[incompatible-call] Added when annotating Transformer. string is incompatible with Buffer.
118
- 'arbitrary(code)',
119
- // $FlowFixMe[prop-missing] Added when annotating Transformer.
120
- {
121
- dev: true,
122
- type: 'module',
123
- },
124
- );
125
-
126
- expect(result.output[0].type).toBe('js/module');
127
- expect(result.output[0].data.code).toBe(
128
- [HEADER_DEV, ' arbitrary(code);', '});'].join('\n'),
129
- );
130
- expect(result.output[0].data.map).toMatchSnapshot();
131
- expect(result.output[0].data.functionMap).toMatchSnapshot();
132
- expect(result.dependencies).toEqual([]);
133
- });
134
-
135
- it('transforms a module with dependencies', async () => {
136
- const contents = [
137
- '"use strict";',
138
- 'require("./a");',
139
- 'arbitrary(code);',
140
- 'const b = require("b");',
141
- 'import c from "./c";',
142
- ].join('\n');
143
-
144
- const result = await Transformer.transform(
145
- baseConfig,
146
- '/root',
147
- 'local/file.js',
148
- // $FlowFixMe[incompatible-call] Added when annotating Transformer. string is incompatible with Buffer.
149
- contents,
150
- // $FlowFixMe[prop-missing] Added when annotating Transformer.
151
- {
152
- dev: true,
153
- type: 'module',
154
- },
155
- );
156
-
157
- expect(result.output[0].type).toBe('js/module');
158
- expect(result.output[0].data.code).toBe(
159
- [
160
- HEADER_DEV,
161
- ' "use strict";',
162
- '',
163
- ' var _interopRequireDefault = _$$_REQUIRE(_dependencyMap[0], "@babel/runtime/helpers/interopRequireDefault");',
164
- '',
165
- ' var _c = _interopRequireDefault(_$$_REQUIRE(_dependencyMap[1], "./c"));',
166
- '',
167
- ' _$$_REQUIRE(_dependencyMap[2], "./a");',
168
- '',
169
- ' arbitrary(code);',
170
- '',
171
- ' var b = _$$_REQUIRE(_dependencyMap[3], "b");',
172
- '});',
173
- ].join('\n'),
174
- );
175
- expect(result.output[0].data.map).toMatchSnapshot();
176
- expect(result.output[0].data.functionMap).toMatchSnapshot();
177
- expect(result.dependencies).toEqual([
178
- {
179
- data: expect.objectContaining({asyncType: null}),
180
- name: '@babel/runtime/helpers/interopRequireDefault',
181
- },
182
- {data: expect.objectContaining({asyncType: null}), name: './c'},
183
- {data: expect.objectContaining({asyncType: null}), name: './a'},
184
- {data: expect.objectContaining({asyncType: null}), name: 'b'},
185
- ]);
186
- });
187
-
188
- it('transforms an es module with asyncToGenerator', async () => {
189
- const result = await Transformer.transform(
190
- baseConfig,
191
- '/root',
192
- 'local/file.js',
193
- // $FlowFixMe[incompatible-call] Added when annotating Transformer. string is incompatible with Buffer.
194
- 'export async function test() {}',
195
- // $FlowFixMe[prop-missing] Added when annotating Transformer.
196
- {
197
- dev: true,
198
- type: 'module',
199
- },
200
- );
201
-
202
- expect(result.output[0].type).toBe('js/module');
203
- expect(result.output[0].data.code).toMatchSnapshot();
204
- expect(result.output[0].data.map).toHaveLength(6);
205
- expect(result.output[0].data.functionMap).toMatchSnapshot();
206
- expect(result.dependencies).toEqual([
207
- {
208
- data: expect.objectContaining({asyncType: null}),
209
- name: '@babel/runtime/helpers/interopRequireDefault',
210
- },
211
- {
212
- data: expect.objectContaining({asyncType: null}),
213
- name: '@babel/runtime/helpers/asyncToGenerator',
214
- },
215
- ]);
216
- });
217
-
218
- it('transforms async generators', async () => {
219
- const result = await Transformer.transform(
220
- baseConfig,
221
- '/root',
222
- 'local/file.js',
223
- // $FlowFixMe[incompatible-call] Added when annotating Transformer. string is incompatible with Buffer.
224
- 'export async function* test() { yield "ok"; }',
225
- // $FlowFixMe[prop-missing] Added when annotating Transformer.
226
- {
227
- dev: true,
228
- type: 'module',
229
- },
230
- );
231
-
232
- expect(result.output[0].data.code).toMatchSnapshot();
233
- expect(result.dependencies).toEqual([
234
- {
235
- data: expect.objectContaining({asyncType: null}),
236
- name: '@babel/runtime/helpers/interopRequireDefault',
237
- },
238
- {
239
- data: expect.objectContaining({asyncType: null}),
240
- name: '@babel/runtime/helpers/awaitAsyncGenerator',
241
- },
242
- {
243
- data: expect.objectContaining({asyncType: null}),
244
- name: '@babel/runtime/helpers/wrapAsyncGenerator',
245
- },
246
- ]);
247
- });
248
-
249
- it('transforms import/export syntax when experimental flag is on', async () => {
250
- const contents = ['import c from "./c";'].join('\n');
251
-
252
- const result = await Transformer.transform(
253
- baseConfig,
254
- '/root',
255
- 'local/file.js',
256
- // $FlowFixMe[incompatible-call] Added when annotating Transformer. string is incompatible with Buffer.
257
- contents,
258
- // $FlowFixMe[prop-missing] Added when annotating Transformer.
259
- {
260
- dev: true,
261
- experimentalImportSupport: true,
262
- type: 'module',
263
- },
264
- );
265
-
266
- expect(result.output[0].type).toBe('js/module');
267
- expect(result.output[0].data.code).toBe(
268
- [
269
- HEADER_DEV,
270
- ' "use strict";',
271
- '',
272
- ' var c = _$$_IMPORT_DEFAULT(_dependencyMap[0], "./c");',
273
- '});',
274
- ].join('\n'),
275
- );
276
- expect(result.output[0].data.map).toMatchSnapshot();
277
- expect(result.output[0].data.functionMap).toMatchSnapshot();
278
- expect(result.dependencies).toEqual([
279
- {
280
- data: expect.objectContaining({
281
- asyncType: null,
282
- }),
283
- name: './c',
284
- },
285
- ]);
286
- });
287
-
288
- it('does not add "use strict" on non-modules', async () => {
289
- const result = await Transformer.transform(
290
- baseConfig,
291
- '/root',
292
- 'node_modules/local/file.js',
293
- // $FlowFixMe[incompatible-call] Added when annotating Transformer. string is incompatible with Buffer.
294
- 'module.exports = {};',
295
- // $FlowFixMe[prop-missing] Added when annotating Transformer.
296
- {
297
- dev: true,
298
- experimentalImportSupport: true,
299
- type: 'module',
300
- },
301
- );
302
-
303
- expect(result.output[0].type).toBe('js/module');
304
- expect(result.output[0].data.code).toBe(
305
- [HEADER_DEV, ' module.exports = {};', '});'].join('\n'),
306
- );
307
- });
308
-
309
- it('preserves require() calls when module wrapping is disabled', async () => {
310
- const contents = ['require("./c");'].join('\n');
311
-
312
- const result = await Transformer.transform(
313
- {
314
- ...baseConfig,
315
- unstable_disableModuleWrapping: true,
316
- },
317
- '/root',
318
- 'local/file.js',
319
- // $FlowFixMe[incompatible-call] Added when annotating Transformer. string is incompatible with Buffer.
320
- contents,
321
- // $FlowFixMe[prop-missing] Added when annotating Transformer.
322
- {
323
- dev: true,
324
- type: 'module',
325
- },
326
- );
327
-
328
- expect(result.output[0].type).toBe('js/module');
329
- expect(result.output[0].data.code).toBe('require("./c");');
330
- });
331
-
332
- it('reports filename when encountering unsupported dynamic dependency', async () => {
333
- const contents = [
334
- 'require("./a");',
335
- 'let a = arbitrary(code);',
336
- 'const b = require(a);',
337
- ].join('\n');
338
-
339
- try {
340
- await Transformer.transform(
341
- baseConfig,
342
- '/root',
343
- 'local/file.js',
344
- // $FlowFixMe[incompatible-call] Added when annotating Transformer. string is incompatible with Buffer.
345
- contents,
346
- // $FlowFixMe[prop-missing] Added when annotating Transformer.
347
- {
348
- dev: true,
349
- type: 'module',
350
- },
351
- );
352
- throw new Error('should not reach this');
353
- } catch (error) {
354
- expect(error.message).toMatchSnapshot();
355
- }
356
- });
357
-
358
- it('supports dynamic dependencies from within `node_modules`', async () => {
359
- expect(
360
- (
361
- await Transformer.transform(
362
- {
363
- ...baseConfig,
364
- dynamicDepsInPackages: 'throwAtRuntime',
365
- },
366
- '/root',
367
- 'node_modules/foo/bar.js',
368
- // $FlowFixMe[incompatible-call] Added when annotating Transformer. string is incompatible with Buffer.
369
- 'require(foo.bar);',
370
- // $FlowFixMe[prop-missing] Added when annotating Transformer.
371
- {
372
- dev: true,
373
- type: 'module',
374
- },
375
- )
376
- ).output[0].data.code,
377
- ).toBe(
378
- [
379
- HEADER_DEV,
380
- ' (function (line) {',
381
- " throw new Error('Dynamic require defined at line ' + line + '; not supported by Metro');",
382
- ' })(1);',
383
- '});',
384
- ].join('\n'),
385
- );
386
- });
387
-
388
- it('minifies the code correctly', async () => {
389
- expect(
390
- (
391
- await Transformer.transform(
392
- baseConfig,
393
- '/root',
394
- 'local/file.js',
395
- // $FlowFixMe[incompatible-call] Added when annotating Transformer. string is incompatible with Buffer.
396
- 'arbitrary(code);',
397
- // $FlowFixMe[prop-missing] Added when annotating Transformer.
398
- {
399
- dev: true,
400
- minify: true,
401
- type: 'module',
402
- },
403
- )
404
- ).output[0].data.code,
405
- ).toBe([HEADER_PROD, ' minified(code);', '});'].join('\n'));
406
- });
407
-
408
- it('minifies a JSON file', async () => {
409
- expect(
410
- (
411
- await Transformer.transform(
412
- baseConfig,
413
- '/root',
414
- 'local/file.json',
415
- // $FlowFixMe[incompatible-call] Added when annotating Transformer. string is incompatible with Buffer.
416
- 'arbitrary(code);',
417
- // $FlowFixMe[prop-missing] Added when annotating Transformer.
418
- {
419
- dev: true,
420
- minify: true,
421
- type: 'module',
422
- },
423
- )
424
- ).output[0].data.code,
425
- ).toBe(
426
- [
427
- '__d(function(global, require, _importDefaultUnused, _importAllUnused, module, exports, _dependencyMapUnused) {',
428
- ' module.exports = minified(code);;',
429
- '});',
430
- ].join('\n'),
431
- );
432
- });
433
-
434
- it('does not wrap a JSON file when disableModuleWrapping is enabled', async () => {
435
- expect(
436
- (
437
- await Transformer.transform(
438
- {
439
- ...baseConfig,
440
- unstable_disableModuleWrapping: true,
441
- },
442
- '/root',
443
- 'local/file.json',
444
- // $FlowFixMe[incompatible-call] Added when annotating Transformer. string is incompatible with Buffer.
445
- 'arbitrary(code);',
446
- // $FlowFixMe[prop-missing] Added when annotating Transformer.
447
- {
448
- dev: true,
449
- type: 'module',
450
- },
451
- )
452
- ).output[0].data.code,
453
- ).toBe('module.exports = arbitrary(code);;');
454
- });
455
-
456
- it('transforms a script to JS source and bytecode', async () => {
457
- const result = await Transformer.transform(
458
- baseConfig,
459
- '/root',
460
- 'local/file.js',
461
- // $FlowFixMe[incompatible-call] Added when annotating Transformer. string is incompatible with Buffer.
462
- 'someReallyArbitrary(code)',
463
- // $FlowFixMe[prop-missing] Added when annotating Transformer.
464
- {
465
- dev: true,
466
- runtimeBytecodeVersion: 1,
467
- type: 'script',
468
- },
469
- );
470
-
471
- const jsOutput = result.output.find(output => output.type === 'js/script');
472
- const bytecodeOutput = result.output.find(
473
- output => output.type === 'bytecode/script',
474
- );
475
- // $FlowFixMe[incompatible-use] Added when annotating Transformer. data missing in jsOutput.
476
- expect(jsOutput.data.code).toBe(
477
- [
478
- '(function (global) {',
479
- ' someReallyArbitrary(code);',
480
- "})(typeof globalThis !== 'undefined' ? globalThis : typeof global !== 'undefined' ? global : typeof window !== 'undefined' ? window : this);",
481
- ].join('\n'),
482
- );
483
-
484
- expect(() =>
485
- // $FlowFixMe[incompatible-use] Added when annotating Transformer. data missing in bytecodeOutput.
486
- // $FlowFixMe[incompatible-call] Added when annotating Transformer. bytecode property is missing.
487
- HermesCompiler.validateBytecodeModule(bytecodeOutput.data.bytecode, 0),
488
- ).not.toThrow();
489
- });
490
-
491
- it('allows replacing the collectDependencies implementation', async () => {
492
- jest.mock(
493
- 'metro-transform-worker/__virtual__/collectModifiedDependencies',
494
- () =>
495
- jest.fn((ast, opts) => {
496
- const metroCoreCollectDependencies = jest.requireActual(
497
- 'metro/src/ModuleGraph/worker/collectDependencies',
498
- );
499
- const collectedDeps = metroCoreCollectDependencies(ast, opts);
500
- return {
501
- ...collectedDeps,
502
- dependencies: collectedDeps.dependencies.map(dep => ({
503
- ...dep,
504
- name: 'modified_' + dep.name,
505
- })),
506
- };
507
- }),
508
- {virtual: true},
509
- );
510
-
511
- const config = {
512
- ...baseConfig,
513
- unstable_collectDependenciesPath:
514
- 'metro-transform-worker/__virtual__/collectModifiedDependencies',
515
- };
516
- const options = {
517
- dev: true,
518
- type: 'module',
519
- };
520
- const result = await Transformer.transform(
521
- config,
522
- '/root',
523
- 'local/file.js',
524
- // $FlowFixMe[incompatible-call] Added when annotating Transformer. string is incompatible with Buffer.
525
- 'require("foo")',
526
- // $FlowFixMe[prop-missing] Added when annotating Transformer.
527
- options,
528
- );
529
-
530
- // $FlowIgnore[cannot-resolve-module] this is a virtual module
531
- const collectModifiedDependencies = require('metro-transform-worker/__virtual__/collectModifiedDependencies');
532
- expect(collectModifiedDependencies).toHaveBeenCalledWith(
533
- expect.objectContaining({type: 'File'}),
534
- {
535
- allowOptionalDependencies: config.allowOptionalDependencies,
536
- asyncRequireModulePath: config.asyncRequireModulePath,
537
- dynamicRequires: 'reject',
538
- inlineableCalls: ['_$$_IMPORT_DEFAULT', '_$$_IMPORT_ALL'],
539
- keepRequireNames: options.dev,
540
- dependencyMapName: null,
541
- },
542
- );
543
- expect(result.dependencies).toEqual([
544
- expect.objectContaining({name: 'modified_foo'}),
545
- ]);
546
- });
547
-
548
- it('uses a reserved dependency map name and prevents it from being minified', async () => {
549
- const result = await Transformer.transform(
550
- {...baseConfig, unstable_dependencyMapReservedName: 'THE_DEP_MAP'},
551
- '/root',
552
- 'local/file.js',
553
- // $FlowFixMe[incompatible-call] Added when annotating Transformer. string is incompatible with Buffer.
554
- 'arbitrary(code);',
555
- // $FlowFixMe[prop-missing] Added when annotating Transformer.
556
- {
557
- dev: false,
558
- minify: true,
559
- type: 'module',
560
- },
561
- );
562
- expect(result.output[0].data.code).toMatchInlineSnapshot(`
563
- "__d(function (g, r, i, a, m, e, THE_DEP_MAP) {
564
- minified(code);
565
- });"
566
- `);
567
- });
568
-
569
- it('throws if the reserved dependency map name appears in the input', async () => {
570
- await expect(
571
- Transformer.transform(
572
- {...baseConfig, unstable_dependencyMapReservedName: 'THE_DEP_MAP'},
573
- '/root',
574
- 'local/file.js',
575
- // $FlowFixMe[incompatible-call] Added when annotating Transformer. string is incompatible with Buffer.
576
- 'arbitrary(code); /* the code is not allowed to mention THE_DEP_MAP, even in a comment */',
577
- // $FlowFixMe[prop-missing] Added when annotating Transformer.
578
- {
579
- dev: false,
580
- minify: true,
581
- type: 'module',
582
- },
583
- ),
584
- ).rejects.toThrowErrorMatchingInlineSnapshot(
585
- `"Source code contains the reserved string \`THE_DEP_MAP\` at character offset 55"`,
586
- );
587
- });
588
-
589
- it('allows disabling the normalizePseudoGlobals pass when minifying', async () => {
590
- const result = await Transformer.transform(
591
- {...baseConfig, unstable_disableNormalizePseudoGlobals: true},
592
- '/root',
593
- 'local/file.js',
594
- // $FlowFixMe[incompatible-call] Added when annotating Transformer. string is incompatible with Buffer.
595
- 'arbitrary(code);',
596
- // $FlowFixMe[prop-missing] Added when annotating Transformer.
597
- {
598
- dev: false,
599
- minify: true,
600
- type: 'module',
601
- },
602
- );
603
- expect(result.output[0].data.code).toMatchInlineSnapshot(`
604
- "__d(function (global, _$$_REQUIRE, _$$_IMPORT_DEFAULT, _$$_IMPORT_ALL, module, exports, _dependencyMap) {
605
- minified(code);
606
- });"
607
- `);
608
- });
609
-
610
- it('allows emitting compact code when not minifying', async () => {
611
- const result = await Transformer.transform(
612
- {...baseConfig, unstable_compactOutput: true},
613
- '/root',
614
- 'local/file.js',
615
- // $FlowFixMe[incompatible-call] Added when annotating Transformer. string is incompatible with Buffer.
616
- 'arbitrary(code);',
617
- // $FlowFixMe[prop-missing] Added when annotating Transformer.
618
- {
619
- dev: false,
620
- minify: false,
621
- type: 'module',
622
- },
623
- );
624
- expect(result.output[0].data.code).toMatchInlineSnapshot(
625
- `"__d(function(global,_$$_REQUIRE,_$$_IMPORT_DEFAULT,_$$_IMPORT_ALL,module,exports,_dependencyMap){arbitrary(code);});"`,
626
- );
627
- });
628
-
629
- it('skips minification in Hermes stable transform profile', async () => {
630
- const result = await Transformer.transform(
631
- baseConfig,
632
- '/root',
633
- 'local/file.js',
634
- // $FlowFixMe[incompatible-call] Added when annotating Transformer. string is incompatible with Buffer.
635
- 'arbitrary(code);',
636
- // $FlowFixMe[prop-missing] Added when annotating Transformer.
637
- {
638
- dev: false,
639
- minify: true,
640
- type: 'module',
641
- unstable_transformProfile: 'hermes-canary',
642
- },
643
- );
644
- expect(result.output[0].data.code).toMatchInlineSnapshot(`
645
- "__d(function (global, _$$_REQUIRE, _$$_IMPORT_DEFAULT, _$$_IMPORT_ALL, module, exports, _dependencyMap) {
646
- arbitrary(code);
647
- });"
648
- `);
649
- });
650
-
651
- it('skips minification in Hermes canary transform profile', async () => {
652
- const result = await Transformer.transform(
653
- baseConfig,
654
- '/root',
655
- 'local/file.js',
656
- // $FlowFixMe[incompatible-call] Added when annotating Transformer. string is incompatible with Buffer.
657
- 'arbitrary(code);',
658
- // $FlowFixMe[prop-missing] Added when annotating Transformer.
659
- {
660
- dev: false,
661
- minify: true,
662
- type: 'module',
663
- unstable_transformProfile: 'hermes-canary',
664
- },
665
- );
666
- expect(result.output[0].data.code).toMatchInlineSnapshot(`
667
- "__d(function (global, _$$_REQUIRE, _$$_IMPORT_DEFAULT, _$$_IMPORT_ALL, module, exports, _dependencyMap) {
668
- arbitrary(code);
669
- });"
670
- `);
671
- });
672
-
673
- it('counts all line endings correctly', async () => {
674
- const transformStr = (
675
- str: $TEMPORARY$string<'one\ntwo\nthree\nfour\nfive\nsix'> | string,
676
- ) =>
677
- Transformer.transform(
678
- baseConfig,
679
- '/root',
680
- 'local/file.js',
681
- // $FlowFixMe[incompatible-call] Added when annotating Transformer. string is incompatible with Buffer.
682
- str,
683
- // $FlowFixMe[prop-missing] Added when annotating Transformer.
684
- {
685
- dev: false,
686
- minify: false,
687
- type: 'module',
688
- },
689
- );
690
-
691
- const differentEndingsResult = await transformStr(
692
- 'one\rtwo\r\nthree\nfour\u2028five\u2029six',
693
- );
694
-
695
- const standardEndingsResult = await transformStr(
696
- 'one\ntwo\nthree\nfour\nfive\nsix',
697
- );
698
-
699
- expect(differentEndingsResult.output[0].data.lineCount).toEqual(
700
- standardEndingsResult.output[0].data.lineCount,
701
- );
702
- });