Skip to content

Commit af7fdbe

Browse files
committed
polyfill .flat() array method
1 parent d63e20b commit af7fdbe

File tree

4 files changed

+218
-3
lines changed

4 files changed

+218
-3
lines changed

packages/utils/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
"tslib": "^1.9.3"
2121
},
2222
"devDependencies": {
23+
"@types/array.prototype.flat": "^1.2.1",
24+
"array.prototype.flat": "^1.3.0",
2325
"chai": "^4.1.2"
2426
},
2527
"scripts": {

packages/utils/test/buildPolyfills/optionalChain.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
1+
import { default as arrayFlat } from 'array.prototype.flat';
2+
13
import { _optionalChain } from '../../src/buildPolyfills';
24
import { GenericFunction, GenericObject, Value } from '../../src/buildPolyfills/types';
35
import { _optionalChain as _optionalChainOrig } from './originals';
46

7+
// Older versions of Node don't have `Array.prototype.flat`, which crashes these tests. On newer versions that do have
8+
// it, this is a no-op.
9+
arrayFlat.shim();
10+
511
type OperationType = 'access' | 'call' | 'optionalAccess' | 'optionalCall';
612
type OperationExecutor =
713
| ((intermediateValue: GenericObject) => Value)

packages/utils/tsconfig.test.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@
99

1010
// other package-specific, test-specific options
1111
// this is necessary in order to be able to handle the buildPolyfills `originals.js` which is used for testing
12-
"allowJs": true
12+
"allowJs": true,
13+
14+
// `es2020` is the recommended `lib` and `target` for Node 14
15+
// see https://github.com/tsconfig/bases/blob/main/bases/node14.json
16+
"lib": ["dom", "es2020"],
17+
"module": "commonjs",
18+
"target": "es2020",
19+
20+
// so we don't have to worry about how libraries we use export things
21+
"esModuleInterop": true
1322
}
1423
}

0 commit comments

Comments
 (0)