@wordpress/babel-preset-default 8.8.1 → 8.9.0

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/babel-preset-default",
3
- "version": "8.8.1",
3
+ "version": "8.9.0",
4
4
  "description": "Default Babel preset for WordPress development.",
5
5
  "author": "The WordPress Contributors",
6
6
  "license": "GPL-2.0-or-later",
@@ -26,7 +26,9 @@
26
26
  },
27
27
  "files": [
28
28
  "build",
29
- "index.js"
29
+ "index.js",
30
+ "polyfill-exclusions.js",
31
+ "replace-polyfills.js"
30
32
  ],
31
33
  "main": "index.js",
32
34
  "dependencies": {
@@ -36,8 +38,8 @@
36
38
  "@babel/preset-env": "^7.16.0",
37
39
  "@babel/preset-typescript": "^7.16.0",
38
40
  "@babel/runtime": "^7.16.0",
39
- "@wordpress/browserslist-config": "^6.8.1",
40
- "@wordpress/warning": "^3.8.1",
41
+ "@wordpress/browserslist-config": "^6.9.0",
42
+ "@wordpress/warning": "^3.9.0",
41
43
  "browserslist": "^4.21.10",
42
44
  "core-js": "^3.31.0",
43
45
  "react": "^18.3.0"
@@ -48,5 +50,5 @@
48
50
  "scripts": {
49
51
  "build": "node ./bin/index.js"
50
52
  },
51
- "gitHead": "cf707c1f25a2716e310cc8f9afcc8554405c79ac"
53
+ "gitHead": "2e5495c635910cb34bfaca3c6258d2e989f66214"
52
54
  }
@@ -0,0 +1,10 @@
1
+ module.exports = [
2
+ // Ignore excessively strict polyfilling of `Array.prototype.push` to work
3
+ // around an obscure bug involving non-writable arrays.
4
+ // See https://issues.chromium.org/issues/42202623 for the details of the
5
+ // bug that leads to the polyfilling, and which we are choosing to ignore.
6
+ 'es.array.push',
7
+ // This is an IE-only feature which we don't use, and don't want to polyfill.
8
+ // @see https://github.com/WordPress/gutenberg/pull/49234
9
+ 'web.immediate',
10
+ ];
@@ -0,0 +1,59 @@
1
+ // Babel plugin that looks for `core-js` imports (or requires)
2
+ // and replaces them with magic comments to mark the file as
3
+ // depending on wp-polyfill.
4
+ function replacePolyfills() {
5
+ return {
6
+ pre() {
7
+ this.hasAddedPolyfills = false;
8
+ },
9
+ visitor: {
10
+ Program: {
11
+ exit( path ) {
12
+ if ( this.hasAddedPolyfills ) {
13
+ // Add magic comment to top of file.
14
+ path.addComment( 'leading', ' wp:polyfill ' );
15
+ }
16
+ },
17
+ },
18
+ // Handle `import` syntax.
19
+ ImportDeclaration( path ) {
20
+ const source = path?.node?.source;
21
+ const name = source?.value || '';
22
+
23
+ // Look for imports from `core-js`.
24
+ if ( name.startsWith( 'core-js/' ) ) {
25
+ // Remove import.
26
+ path.remove();
27
+ this.hasAddedPolyfills = true;
28
+ }
29
+ },
30
+
31
+ // Handle `require` syntax.
32
+ CallExpression( path ) {
33
+ const callee = path?.node?.callee;
34
+ const arg = path?.node?.arguments[ 0 ];
35
+
36
+ if (
37
+ ! callee ||
38
+ ! arg ||
39
+ callee.type !== 'Identifier' ||
40
+ callee.name !== 'require'
41
+ ) {
42
+ return;
43
+ }
44
+
45
+ // Look for requires for `core-js`.
46
+ if (
47
+ arg.type === 'StringLiteral' &&
48
+ arg.value.startsWith( 'core-js/' )
49
+ ) {
50
+ // Remove import.
51
+ path.remove();
52
+ this.hasAddedPolyfills = true;
53
+ }
54
+ },
55
+ },
56
+ };
57
+ }
58
+
59
+ module.exports = replacePolyfills;