From ec1230d218f703f4af0cfeddb18d50e20d28e4e6 Mon Sep 17 00:00:00 2001 From: Anton Gilgur Date: Fri, 25 Mar 2022 16:46:17 -0400 Subject: [PATCH 01/13] env: begin supporting TS files MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - deps: add typescript - future commits will use this more - add a tsconfig.json for TS support - config as requested by Nicolò - plus some fixes to properly put `paths` in the right place --- package.json | 3 ++- tsconfig.json | 21 +++++++++++++++++++++ yarn.lock | 21 +++++++++++++++++++++ 3 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 tsconfig.json diff --git a/package.json b/package.json index aabbba5f..e5348a48 100644 --- a/package.json +++ b/package.json @@ -51,7 +51,8 @@ "prettier": "^2.6.1", "rimraf": "^2.6.3", "rollup": "^2.42.3", - "through2": "^2.0.0" + "through2": "^2.0.0", + "typescript": "^4.6.3" }, "resolutions": { "@lerna/npm-publish": "patch:@lerna/npm-publish@npm:3.18.5#.yarn-patches/@lerna/npm-publish.patch", diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 00000000..faf4c12a --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,21 @@ +{ + "include": ["./packages/*/src/**/*.ts"], + "compilerOptions": { + "target": "esnext", + "module": "esnext", + "lib": [ + "esnext" + ], + "noEmit": true, + "moduleResolution": "node", + "esModuleInterop": true, + "isolatedModules": true, + "skipLibCheck": true, + "resolveJsonModule": true, + "paths": { + "@babel/helper-define-polyfill-provider": [ + "./packages/babel-helper-define-polyfill-provider/src" + ] + } + } +} diff --git a/yarn.lock b/yarn.lock index 47bdeca3..27c164bd 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3998,6 +3998,7 @@ __metadata: rimraf: ^2.6.3 rollup: ^2.42.3 through2: ^2.0.0 + typescript: ^4.6.3 languageName: unknown linkType: soft @@ -13312,6 +13313,26 @@ resolve@1.1.7: languageName: node linkType: hard +"typescript@npm:^4.6.3": + version: 4.6.3 + resolution: "typescript@npm:4.6.3" + bin: + tsc: bin/tsc + tsserver: bin/tsserver + checksum: 255bb26c8cb846ca689dd1c3a56587af4f69055907aa2c154796ea28ee0dea871535b1c78f85a6212c77f2657843a269c3a742d09d81495b97b914bf7920415b + languageName: node + linkType: hard + +"typescript@patch:typescript@^4.6.3#~builtin": + version: 4.6.3 + resolution: "typescript@patch:typescript@npm%3A4.6.3#~builtin::version=4.6.3&hash=ddd1e8" + bin: + tsc: bin/tsc + tsserver: bin/tsserver + checksum: fe6bdc1afb2f145ddb7b0a3a31f96352209f6a5704d97f038414ea22ff9d8dd42f32cfb6652e30458d7d958d2d4e85de2df11c574899c6f750a6b3c0e90a3a76 + languageName: node + linkType: hard + "uglify-js@npm:^3.0.5, uglify-js@npm:^3.1.4": version: 3.8.1 resolution: "uglify-js@npm:3.8.1" From 1773c77d3eca8921d3473cc6cda094e74adb5bb2 Mon Sep 17 00:00:00 2001 From: Anton Gilgur Date: Sat, 26 Mar 2022 15:23:06 -0400 Subject: [PATCH 02/13] env: support linting and formatting TS files deps: add @typescript-eslint packages and config - to support linting and formatting TS files with type information - add .ts extension to eslint config and commands - add @typescript-eslint packages to config - fix `no-unused-vars` errors with custom rule similar to Babel core - correspondingly change `// eslint-disable-line` comments to use `@typescript-eslint/no-unused-vars` instead of `no-unused vars` - add .ts extension to .prettierrc - to support formatting TS files - and so that `flowts` will use this config during its formatting step as the files will have now been renamed with .ts extensions --- .eslintrc.json | 11 +- .prettierrc | 2 +- package.json | 4 +- .../src/browser/dependencies.js | 6 +- yarn.lock | 569 +++++++++++++----- 5 files changed, 445 insertions(+), 147 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index b8581d57..873532a9 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -9,7 +9,16 @@ "env": { "node": true }, "overrides": [ { - "files": ["packages/*/src/**/*.js"], + "files": ["**/*.ts"], + "parser": "@typescript-eslint/parser", + "plugins": ["@typescript-eslint"], + "rules": { + "no-unused-vars": "off", + "@typescript-eslint/no-unused-vars": "error" + } + }, + { + "files": ["packages/*/src/**/*.{js,ts}"], "rules": { "@babel/development/no-undefined-identifier": "error", "@babel/development/no-deprecated-clone": "error", diff --git a/.prettierrc b/.prettierrc index bec52b3a..079e42de 100644 --- a/.prettierrc +++ b/.prettierrc @@ -10,7 +10,7 @@ "printWidth": 80, "overrides": [ { - "files": ["**/packages/*/src/**/*.js", "**/packages/*/test/**/*.js"], + "files": ["**/packages/*/src/**/*.{js,ts}", "**/packages/*/test/**/*.{js,ts}"], "parser": "babylon", "options": { "trailingComma": "all" diff --git a/package.json b/package.json index e5348a48..e7fdd54e 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "clean": "rimraf packages/*/lib packages/*/esm", "clean-all": "yarn clean && rimraf packages/*/node_modules node_modules", "flow": "flow check --strip-root", - "lint": "eslint packages '*.js' --format=codeframe", + "lint": "eslint packages '*.{js,ts}' --ext .js,.ts --format=codeframe", "publish": "yarn clean && NODE_ENV=production yarn build && yarn validate && lerna publish from-git", "test": "jest && yarn test:esm", "test:esm": "node test/esm/index.mjs", @@ -28,6 +28,8 @@ "@rollup/plugin-babel": "^5.3.0", "@rollup/plugin-json": "^4.1.0", "@rollup/plugin-node-resolve": "^11.2.0", + "@typescript-eslint/eslint-plugin": "^5.16.0", + "@typescript-eslint/parser": "^5.16.0", "babel-jest": "^24.8.0", "chalk": "^3.0.0", "electron-to-chromium": "^1.3.683", diff --git a/packages/babel-helper-define-polyfill-provider/src/browser/dependencies.js b/packages/babel-helper-define-polyfill-provider/src/browser/dependencies.js index 220a0caf..20c0961a 100644 --- a/packages/babel-helper-define-polyfill-provider/src/browser/dependencies.js +++ b/packages/babel-helper-define-polyfill-provider/src/browser/dependencies.js @@ -12,13 +12,13 @@ export function resolve( ); } -// eslint-disable-next-line no-unused-vars +// eslint-disable-next-line @typescript-eslint/no-unused-vars export function has(basedir: string, name: string) { return true; } -// eslint-disable-next-line no-unused-vars +// eslint-disable-next-line @typescript-eslint/no-unused-vars export function logMissing(missingDeps: Set) {} -// eslint-disable-next-line no-unused-vars +// eslint-disable-next-line @typescript-eslint/no-unused-vars export function laterLogMissing(missingDeps: Set) {} diff --git a/yarn.lock b/yarn.lock index 27c164bd..defdeaa2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2574,6 +2574,23 @@ __metadata: languageName: node linkType: hard +"@nodelib/fs.scandir@npm:2.1.5": + version: 2.1.5 + resolution: "@nodelib/fs.scandir@npm:2.1.5" + dependencies: + "@nodelib/fs.stat": 2.0.5 + run-parallel: ^1.1.9 + checksum: a970d595bd23c66c880e0ef1817791432dbb7acbb8d44b7e7d0e7a22f4521260d4a83f7f9fd61d44fda4610105577f8f58a60718105fb38352baed612fd79e59 + languageName: node + linkType: hard + +"@nodelib/fs.stat@npm:2.0.5, @nodelib/fs.stat@npm:^2.0.2": + version: 2.0.5 + resolution: "@nodelib/fs.stat@npm:2.0.5" + checksum: 012480b5ca9d97bff9261571dbbec7bbc6033f69cc92908bc1ecfad0792361a5a1994bc48674b9ef76419d056a03efadfce5a6cf6dbc0a36559571a7a483f6f0 + languageName: node + linkType: hard + "@nodelib/fs.stat@npm:^1.1.2": version: 1.1.3 resolution: "@nodelib/fs.stat@npm:1.1.3" @@ -2581,6 +2598,16 @@ __metadata: languageName: node linkType: hard +"@nodelib/fs.walk@npm:^1.2.3": + version: 1.2.8 + resolution: "@nodelib/fs.walk@npm:1.2.8" + dependencies: + "@nodelib/fs.scandir": 2.1.5 + fastq: ^1.6.0 + checksum: 190c643f156d8f8f277bf2a6078af1ffde1fd43f498f187c2db24d35b4b4b5785c02c7dc52e356497b9a1b65b13edc996de08de0b961c32844364da02986dc53 + languageName: node + linkType: hard + "@octokit/auth-token@npm:^2.4.0": version: 2.4.0 resolution: "@octokit/auth-token@npm:2.4.0" @@ -2861,6 +2888,13 @@ __metadata: languageName: node linkType: hard +"@types/json-schema@npm:^7.0.9": + version: 7.0.11 + resolution: "@types/json-schema@npm:7.0.11" + checksum: 527bddfe62db9012fccd7627794bd4c71beb77601861055d87e3ee464f2217c85fca7a4b56ae677478367bbd248dbde13553312b7d4dbc702a2f2bbf60c4018d + languageName: node + linkType: hard + "@types/minimatch@npm:*": version: 3.0.3 resolution: "@types/minimatch@npm:3.0.3" @@ -2907,6 +2941,123 @@ __metadata: languageName: node linkType: hard +"@typescript-eslint/eslint-plugin@npm:^5.16.0": + version: 5.16.0 + resolution: "@typescript-eslint/eslint-plugin@npm:5.16.0" + dependencies: + "@typescript-eslint/scope-manager": 5.16.0 + "@typescript-eslint/type-utils": 5.16.0 + "@typescript-eslint/utils": 5.16.0 + debug: ^4.3.2 + functional-red-black-tree: ^1.0.1 + ignore: ^5.1.8 + regexpp: ^3.2.0 + semver: ^7.3.5 + tsutils: ^3.21.0 + peerDependencies: + "@typescript-eslint/parser": ^5.0.0 + eslint: ^6.0.0 || ^7.0.0 || ^8.0.0 + peerDependenciesMeta: + typescript: + optional: true + checksum: 4007cc1599503424037300e7401fb969ca441b122ef8a8f2fc8d70f84d656fdf7ab7b0d00e506a3aaf702871616c3756da17eb1508ff315dfb25170f2d28a904 + languageName: node + linkType: hard + +"@typescript-eslint/parser@npm:^5.16.0": + version: 5.16.0 + resolution: "@typescript-eslint/parser@npm:5.16.0" + dependencies: + "@typescript-eslint/scope-manager": 5.16.0 + "@typescript-eslint/types": 5.16.0 + "@typescript-eslint/typescript-estree": 5.16.0 + debug: ^4.3.2 + peerDependencies: + eslint: ^6.0.0 || ^7.0.0 || ^8.0.0 + peerDependenciesMeta: + typescript: + optional: true + checksum: 40006578e9ac451c80dc4b4b7e29af97b53fb9e9ea660d6ca17fb98b5c9858c648f9b17523c9de9b9b9e4155af17b65435e6163f02c4a2dfacf48274f45cba21 + languageName: node + linkType: hard + +"@typescript-eslint/scope-manager@npm:5.16.0": + version: 5.16.0 + resolution: "@typescript-eslint/scope-manager@npm:5.16.0" + dependencies: + "@typescript-eslint/types": 5.16.0 + "@typescript-eslint/visitor-keys": 5.16.0 + checksum: 008a6607d3e6ebcc59a9b28cddcc25703f39a88e27a96c69a6d988acc50a1ea7dbf50963c165ffa5b85a101209a0da3a7ec6832633a162ca4ecc78c0e54acd9f + languageName: node + linkType: hard + +"@typescript-eslint/type-utils@npm:5.16.0": + version: 5.16.0 + resolution: "@typescript-eslint/type-utils@npm:5.16.0" + dependencies: + "@typescript-eslint/utils": 5.16.0 + debug: ^4.3.2 + tsutils: ^3.21.0 + peerDependencies: + eslint: "*" + peerDependenciesMeta: + typescript: + optional: true + checksum: 86d9f1dff6a096c8465453b8c7d0cc667b87a769f19073bfa9bbd36f8baa772c0384ec396b1132052383846bbbcf0d051345ed7d373260c1b506ed27100b383d + languageName: node + linkType: hard + +"@typescript-eslint/types@npm:5.16.0": + version: 5.16.0 + resolution: "@typescript-eslint/types@npm:5.16.0" + checksum: 0450125741c3eef9581da0b75b4a987a633d77009cfb03507c3db29885b790ee80e3c0efc4f9a0dd3376ba758b49c7829722676153472616a57bb04bce5cc4fa + languageName: node + linkType: hard + +"@typescript-eslint/typescript-estree@npm:5.16.0": + version: 5.16.0 + resolution: "@typescript-eslint/typescript-estree@npm:5.16.0" + dependencies: + "@typescript-eslint/types": 5.16.0 + "@typescript-eslint/visitor-keys": 5.16.0 + debug: ^4.3.2 + globby: ^11.0.4 + is-glob: ^4.0.3 + semver: ^7.3.5 + tsutils: ^3.21.0 + peerDependenciesMeta: + typescript: + optional: true + checksum: 930ead4655712c3bd40885fb6b2074cd3c10fb03da864dd7a7dd2e43abfd330bb07e505f0aec8b4846178bff8befbb017f9f3370c67e9c717e4cb8d3df6e16ef + languageName: node + linkType: hard + +"@typescript-eslint/utils@npm:5.16.0": + version: 5.16.0 + resolution: "@typescript-eslint/utils@npm:5.16.0" + dependencies: + "@types/json-schema": ^7.0.9 + "@typescript-eslint/scope-manager": 5.16.0 + "@typescript-eslint/types": 5.16.0 + "@typescript-eslint/typescript-estree": 5.16.0 + eslint-scope: ^5.1.1 + eslint-utils: ^3.0.0 + peerDependencies: + eslint: ^6.0.0 || ^7.0.0 || ^8.0.0 + checksum: 46749091a204d7cf80d81b04704e23a86903a142a7e35cc5068a821c147c3bf098a7eff99af2b0e2ea7310013ca90300db9bab33ae5e3b5f773ed1d2961a5ed4 + languageName: node + linkType: hard + +"@typescript-eslint/visitor-keys@npm:5.16.0": + version: 5.16.0 + resolution: "@typescript-eslint/visitor-keys@npm:5.16.0" + dependencies: + "@typescript-eslint/types": 5.16.0 + eslint-visitor-keys: ^3.0.0 + checksum: b587bf3b0da95bb58ff877b75fefcee6472222de1e3ec76aa4b94cae66078b62a372c7d0343374a16aab15cdcbae3f9e019624028b35827f68ef6559389f7fd0 + languageName: node + linkType: hard + "@webassemblyjs/ast@npm:1.9.0": version: 1.9.0 resolution: "@webassemblyjs/ast@npm:1.9.0" @@ -3612,6 +3763,13 @@ __metadata: languageName: node linkType: hard +"array-union@npm:^2.1.0": + version: 2.1.0 + resolution: "array-union@npm:2.1.0" + checksum: 5bee12395cba82da674931df6d0fea23c4aa4660cb3b338ced9f828782a65caa232573e6bf3968f23e0c5eb301764a382cef2f128b170a9dc59de0e36c39f98d + languageName: node + linkType: hard + "array-uniq@npm:^1.0.1": version: 1.0.3 resolution: "array-uniq@npm:1.0.3" @@ -3974,6 +4132,8 @@ __metadata: "@rollup/plugin-babel": ^5.3.0 "@rollup/plugin-json": ^4.1.0 "@rollup/plugin-node-resolve": ^11.2.0 + "@typescript-eslint/eslint-plugin": ^5.16.0 + "@typescript-eslint/parser": ^5.16.0 babel-jest: ^24.8.0 chalk: ^3.0.0 electron-to-chromium: ^1.3.683 @@ -4113,10 +4273,10 @@ __metadata: languageName: node linkType: hard -"bn.js@npm:^4.0.0, bn.js@npm:^4.1.0, bn.js@npm:^4.1.1, bn.js@npm:^4.11.9": - version: 4.12.0 - resolution: "bn.js@npm:4.12.0" - checksum: 39afb4f15f4ea537b55eaf1446c896af28ac948fdcf47171961475724d1bb65118cca49fa6e3d67706e4790955ec0e74de584e45c8f1ef89f46c812bee5b5a12 +"bn.js@npm:^4.0.0, bn.js@npm:^4.1.0, bn.js@npm:^4.1.1, bn.js@npm:^4.4.0": + version: 4.11.8 + resolution: "bn.js@npm:4.11.8" + checksum: 80d4709cd58a21f0be8201e9e5859fea5ef133318e9800c8454cd334625c6e1caea593ca21f9b9a085fb560fbc12fb2fb3514363f8604258db924237fd039139 languageName: node linkType: hard @@ -4159,7 +4319,7 @@ __metadata: languageName: node linkType: hard -"braces@npm:~3.0.2": +"braces@npm:^3.0.2, braces@npm:~3.0.2": version: 3.0.2 resolution: "braces@npm:3.0.2" dependencies: @@ -4168,7 +4328,7 @@ __metadata: languageName: node linkType: hard -"brorand@npm:^1.0.1, brorand@npm:^1.1.0": +"brorand@npm:^1.0.1": version: 1.1.0 resolution: "brorand@npm:1.1.0" checksum: 8a05c9f3c4b46572dec6ef71012b1946db6cae8c7bb60ccd4b7dd5a84655db49fe043ecc6272e7ef1f69dc53d6730b9e2a3a03a8310509a3d797a618cbee52be @@ -4604,7 +4764,7 @@ __metadata: languageName: node linkType: hard -"chownr@npm:^1.1.1, chownr@npm:^1.1.2, chownr@npm:^1.1.4": +"chownr@npm:^1.1.1, chownr@npm:^1.1.2": version: 1.1.4 resolution: "chownr@npm:1.1.4" checksum: 115648f8eb38bac5e41c3857f3e663f9c39ed6480d1349977c4d96c95a47266fcacc5a5aabf3cb6c481e22d72f41992827db47301851766c4fd77ac21a4f081d @@ -5089,12 +5249,12 @@ __metadata: linkType: hard "copy-props@npm:^2.0.1": - version: 2.0.5 - resolution: "copy-props@npm:2.0.5" + version: 2.0.4 + resolution: "copy-props@npm:2.0.4" dependencies: - each-props: ^1.3.2 - is-plain-object: ^5.0.0 - checksum: e05bbd4b020fb19f3ce9edce51478d41283397af7ac393297859e2014f518d96e3e2d47ff84736e7c46c17f03fee58c5cef16a8a2420237b069873e5cfe80672 + each-props: ^1.3.0 + is-plain-object: ^2.0.1 + checksum: 48a8cd2374f222a58eeacbe268fd52f96a039e632ee96cc3f8fe1fbb00699b76032cee47c073882aec44fcc1e2096685e811e1c65995bcfefae739b5f2b2a2a4 languageName: node linkType: hard @@ -5315,12 +5475,15 @@ __metadata: languageName: node linkType: hard -"debug@npm:^4.0.1, debug@npm:^4.1.0, debug@npm:^4.1.1": - version: 4.1.1 - resolution: "debug@npm:4.1.1" +"debug@npm:^4.0.1, debug@npm:^4.1.0, debug@npm:^4.1.1, debug@npm:^4.3.2": + version: 4.3.4 + resolution: "debug@npm:4.3.4" dependencies: - ms: ^2.1.1 - checksum: 1e681f5cce94ba10f8dde74b20b42e4d8cf0d2a6700f4c165bb3bb6885565ef5ca5885bf07e704974a835f2415ff095a63164f539988a1f07e8a69fe8b1d65ad + ms: 2.1.2 + peerDependenciesMeta: + supports-color: + optional: true + checksum: 3dbad3f94ea64f34431a9cbf0bafb61853eda57bff2880036153438f50fb5a84f27683ba0d8e5426bf41a8c6ff03879488120cf5b3a761e77953169c0600a708 languageName: node linkType: hard @@ -5543,6 +5706,15 @@ __metadata: languageName: node linkType: hard +"dir-glob@npm:^3.0.1": + version: 3.0.1 + resolution: "dir-glob@npm:3.0.1" + dependencies: + path-type: ^4.0.0 + checksum: fa05e18324510d7283f55862f3161c6759a3f2f8dbce491a2fc14c8324c498286c54282c1f0e933cb930da8419b30679389499b919122952a4f8592362ef4615 + languageName: node + linkType: hard + "doctrine@npm:1.5.0": version: 1.5.0 resolution: "doctrine@npm:1.5.0" @@ -5588,11 +5760,11 @@ __metadata: linkType: hard "dot-prop@npm:^4.2.0": - version: 4.2.1 - resolution: "dot-prop@npm:4.2.1" + version: 4.2.0 + resolution: "dot-prop@npm:4.2.0" dependencies: is-obj: ^1.0.0 - checksum: 5f4f19aa440bc548670d87f2adcbd105fa6842cd1fba3165a8a2b1380568ae82862acf8ebafcc6093fa062505d7d08d7155c7ba9a88da212f7348e95ef2bdce6 + checksum: 3806dbed9f38aec6246e7a5ceb17007b416262fd9219803b4a4d178b5dac6eedba3269f640d5b2af5cdc8c0504a95cf64b33199204f02aaeaf26945f3c341a40 languageName: node linkType: hard @@ -5615,7 +5787,7 @@ __metadata: languageName: node linkType: hard -"each-props@npm:^1.3.2": +"each-props@npm:^1.3.0": version: 1.3.2 resolution: "each-props@npm:1.3.2" dependencies: @@ -5636,24 +5808,24 @@ __metadata: linkType: hard "electron-to-chromium@npm:^1.3.683, electron-to-chromium@npm:^1.4.84": - version: 1.4.95 - resolution: "electron-to-chromium@npm:1.4.95" - checksum: fe4f53e573532401050839c89c39710cb628470bacb46670f5a03cdf8e5ccabea0c27a98ba1e6f2555d50fe1bb63c0a4ea568cfcfef45456647d308c43f61d4f + version: 1.4.96 + resolution: "electron-to-chromium@npm:1.4.96" + checksum: 6a7f97c5fc7080b8739df269a9da0047aee9153807af99e72138dc416ea1dd8ccc167812c66c49d3bb83a55098cd8669ef075515d999aad13b266da72bc98cee languageName: node linkType: hard "elliptic@npm:^6.0.0": - version: 6.5.4 - resolution: "elliptic@npm:6.5.4" + version: 6.5.2 + resolution: "elliptic@npm:6.5.2" dependencies: - bn.js: ^4.11.9 - brorand: ^1.1.0 + bn.js: ^4.4.0 + brorand: ^1.0.1 hash.js: ^1.0.0 - hmac-drbg: ^1.0.1 - inherits: ^2.0.4 - minimalistic-assert: ^1.0.1 - minimalistic-crypto-utils: ^1.0.1 - checksum: d56d21fd04e97869f7ffcc92e18903b9f67f2d4637a23c860492fbbff5a3155fd9ca0184ce0c865dd6eb2487d234ce9551335c021c376cd2d3b7cb749c7d10f4 + hmac-drbg: ^1.0.0 + inherits: ^2.0.1 + minimalistic-assert: ^1.0.0 + minimalistic-crypto-utils: ^1.0.0 + checksum: c4e6247db6f86a7cd0b58cb998122ed1054ab36890d64524abcdafc508025a326392d1de2cf1f2d97fd6c4bbf48a941d69790e7c5f3e976f398f619429ab5fe7 languageName: node linkType: hard @@ -6019,6 +6191,17 @@ __metadata: languageName: node linkType: hard +"eslint-utils@npm:^3.0.0": + version: 3.0.0 + resolution: "eslint-utils@npm:3.0.0" + dependencies: + eslint-visitor-keys: ^2.0.0 + peerDependencies: + eslint: ">=5" + checksum: 0668fe02f5adab2e5a367eee5089f4c39033af20499df88fe4e6aba2015c20720404d8c3d6349b6f716b08fdf91b9da4e5d5481f265049278099c4c836ccb619 + languageName: node + linkType: hard + "eslint-visitor-keys@npm:^1.1.0": version: 1.3.0 resolution: "eslint-visitor-keys@npm:1.3.0" @@ -6026,13 +6209,20 @@ __metadata: languageName: node linkType: hard -"eslint-visitor-keys@npm:^2.1.0": +"eslint-visitor-keys@npm:^2.0.0, eslint-visitor-keys@npm:^2.1.0": version: 2.1.0 resolution: "eslint-visitor-keys@npm:2.1.0" checksum: e3081d7dd2611a35f0388bbdc2f5da60b3a3c5b8b6e928daffff7391146b434d691577aa95064c8b7faad0b8a680266bcda0a42439c18c717b80e6718d7e267d languageName: node linkType: hard +"eslint-visitor-keys@npm:^3.0.0": + version: 3.3.0 + resolution: "eslint-visitor-keys@npm:3.3.0" + checksum: d59e68a7c5a6d0146526b0eec16ce87fbf97fe46b8281e0d41384224375c4e52f5ffb9e16d48f4ea50785cde93f766b0c898e31ab89978d88b0e1720fbfb7808 + languageName: node + linkType: hard + "eslint@npm:^6.8.0": version: 6.8.0 resolution: "eslint@npm:6.8.0" @@ -6402,6 +6592,19 @@ __metadata: languageName: node linkType: hard +"fast-glob@npm:^3.2.9": + version: 3.2.11 + resolution: "fast-glob@npm:3.2.11" + dependencies: + "@nodelib/fs.stat": ^2.0.2 + "@nodelib/fs.walk": ^1.2.3 + glob-parent: ^5.1.2 + merge2: ^1.3.0 + micromatch: ^4.0.4 + checksum: f473105324a7780a20c06de842e15ddbb41d3cb7e71d1e4fe6e8373204f22245d54f5ab9e2061e6a1c613047345954d29b022e0e76f5c28b1df9858179a0e6d7 + languageName: node + linkType: hard + "fast-json-stable-stringify@npm:^2.0.0": version: 2.1.0 resolution: "fast-json-stable-stringify@npm:2.1.0" @@ -6416,6 +6619,15 @@ __metadata: languageName: node linkType: hard +"fastq@npm:^1.6.0": + version: 1.13.0 + resolution: "fastq@npm:1.13.0" + dependencies: + reusify: ^1.0.4 + checksum: 32cf15c29afe622af187d12fc9cd93e160a0cb7c31a3bb6ace86b7dea3b28e7b72acde89c882663f307b2184e14782c6c664fa315973c03626c7d4bff070bb0b + languageName: node + linkType: hard + "fb-watchman@npm:^2.0.0": version: 2.0.1 resolution: "fb-watchman@npm:2.0.1" @@ -6709,7 +6921,7 @@ __metadata: languageName: node linkType: hard -"fs-minipass@npm:^1.2.7": +"fs-minipass@npm:^1.2.5": version: 1.2.7 resolution: "fs-minipass@npm:1.2.7" dependencies: @@ -7025,7 +7237,7 @@ fsevents@~2.3.1: languageName: node linkType: hard -"glob-parent@npm:^5.0.0, glob-parent@npm:~5.1.0": +"glob-parent@npm:^5.0.0, glob-parent@npm:^5.1.2, glob-parent@npm:~5.1.0": version: 5.1.2 resolution: "glob-parent@npm:5.1.2" dependencies: @@ -7147,6 +7359,20 @@ fsevents@~2.3.1: languageName: node linkType: hard +"globby@npm:^11.0.4": + version: 11.1.0 + resolution: "globby@npm:11.1.0" + dependencies: + array-union: ^2.1.0 + dir-glob: ^3.0.1 + fast-glob: ^3.2.9 + ignore: ^5.2.0 + merge2: ^1.4.1 + slash: ^3.0.0 + checksum: b4be8885e0cfa018fc783792942d53926c35c50b3aefd3fdcfb9d22c627639dc26bd2327a40a0b74b074100ce95bb7187bfeae2f236856aa3de183af7a02aea6 + languageName: node + linkType: hard + "globby@npm:^9.2.0": version: 9.2.0 resolution: "globby@npm:9.2.0" @@ -7320,8 +7546,8 @@ fsevents@~2.3.1: linkType: hard "handlebars@npm:^4.4.0": - version: 4.7.7 - resolution: "handlebars@npm:4.7.7" + version: 4.7.6 + resolution: "handlebars@npm:4.7.6" dependencies: minimist: ^1.2.5 neo-async: ^2.6.0 @@ -7333,7 +7559,7 @@ fsevents@~2.3.1: optional: true bin: handlebars: bin/handlebars - checksum: 1e79a43f5e18d15742977cb987923eab3e2a8f44f2d9d340982bcb69e1735ed049226e534d7c1074eaddaf37e4fb4f471a8adb71cddd5bc8cf3f894241df5cee + checksum: 6fb9ba14c703cb6e77d5a1dcb37631126d25ae1503834b9b4f151d5324b52192a618d1944badc351588271cc28a8144093f85dbabc8c72278cfa2dbd09c70124 languageName: node linkType: hard @@ -7484,7 +7710,7 @@ fsevents@~2.3.1: languageName: node linkType: hard -"hmac-drbg@npm:^1.0.1": +"hmac-drbg@npm:^1.0.0": version: 1.0.1 resolution: "hmac-drbg@npm:1.0.1" dependencies: @@ -7620,6 +7846,13 @@ fsevents@~2.3.1: languageName: node linkType: hard +"ignore@npm:^5.1.8, ignore@npm:^5.2.0": + version: 5.2.0 + resolution: "ignore@npm:5.2.0" + checksum: 6b1f926792d614f64c6c83da3a1f9c83f6196c2839aa41e1e32dd7b8d174cef2e329d75caabb62cb61ce9dc432f75e67d07d122a037312db7caa73166a1bdb77 + languageName: node + linkType: hard + "import-fresh@npm:^2.0.0": version: 2.0.0 resolution: "import-fresh@npm:2.0.0" @@ -7692,7 +7925,7 @@ fsevents@~2.3.1: languageName: node linkType: hard -"inherits@npm:2, inherits@npm:^2.0.1, inherits@npm:^2.0.3, inherits@npm:^2.0.4, inherits@npm:~2.0.1, inherits@npm:~2.0.3": +"inherits@npm:2, inherits@npm:^2.0.1, inherits@npm:^2.0.3, inherits@npm:~2.0.1, inherits@npm:~2.0.3": version: 2.0.4 resolution: "inherits@npm:2.0.4" checksum: 4a48a733847879d6cf6691860a6b1e3f0f4754176e4d71494c41f3475553768b10f84b5ce1d40fbd0e34e6bfbb864ee35858ad4dd2cf31e02fc4a154b724d7f1 @@ -7714,9 +7947,9 @@ fsevents@~2.3.1: linkType: hard "ini@npm:^1.3.2, ini@npm:^1.3.4, ini@npm:^1.3.5, ini@npm:~1.3.0": - version: 1.3.8 - resolution: "ini@npm:1.3.8" - checksum: dfd98b0ca3a4fc1e323e38a6c8eb8936e31a97a918d3b377649ea15bdb15d481207a0dda1021efbd86b464cae29a0d33c1d7dcaf6c5672bee17fa849bc50a1b3 + version: 1.3.5 + resolution: "ini@npm:1.3.5" + checksum: a4c1652f481a7770f6c4d223dbc0ea3cbbe253f7af8ddc8276e22e1185ab8252404dd0ca2ba625e4829a507b3e8e1ec3df38243d0cc4b20dbe915a22118d3f98 languageName: node linkType: hard @@ -8094,12 +8327,12 @@ fsevents@~2.3.1: languageName: node linkType: hard -"is-glob@npm:^4.0.0, is-glob@npm:^4.0.1, is-glob@npm:~4.0.1": - version: 4.0.1 - resolution: "is-glob@npm:4.0.1" +"is-glob@npm:^4.0.0, is-glob@npm:^4.0.1, is-glob@npm:^4.0.3, is-glob@npm:~4.0.1": + version: 4.0.3 + resolution: "is-glob@npm:4.0.3" dependencies: is-extglob: ^2.1.1 - checksum: 84627cad11b4e745f5db5a163f32c47b711585a5ff6e14f8f8d026db87f4cdd3e2c95f6fa1f94ad22e469f36d819ae2814f03f9c668b164422ac3354a94672d3 + checksum: d381c1319fcb69d341cc6e6c7cd588e17cd94722d9a32dbd60660b993c4fb7d0f19438674e68dfec686d09b7c73139c9166b47597f846af387450224a8101ab4 languageName: node linkType: hard @@ -8204,13 +8437,6 @@ fsevents@~2.3.1: languageName: node linkType: hard -"is-plain-object@npm:^5.0.0": - version: 5.0.0 - resolution: "is-plain-object@npm:5.0.0" - checksum: e32d27061eef62c0847d303125440a38660517e586f2f3db7c9d179ae5b6674ab0f469d519b2e25c147a1a3bc87156d0d5f4d8821e0ce4a9ee7fe1fcf11ce45c - languageName: node - linkType: hard - "is-posix-bracket@npm:^0.1.0": version: 0.1.1 resolution: "is-posix-bracket@npm:0.1.1" @@ -9422,9 +9648,9 @@ fsevents@~2.3.1: linkType: hard "lodash@npm:^4.17.12, lodash@npm:^4.17.14, lodash@npm:^4.17.15, lodash@npm:^4.2.1": - version: 4.17.21 - resolution: "lodash@npm:4.17.21" - checksum: eb835a2e51d381e561e508ce932ea50a8e5a68f4ebdd771ea240d3048244a8d13658acbd502cd4829768c56f2e16bdd4340b9ea141297d472517b83868e677f7 + version: 4.17.20 + resolution: "lodash@npm:4.17.20" + checksum: b31afa09739b7292a88ec49ffdb2fcaeb41f690def010f7a067eeedffece32da6b6847bfe4d38a77e6f41778b9b2bca75eeab91209936518173271f0b69376ea languageName: node linkType: hard @@ -9458,6 +9684,15 @@ fsevents@~2.3.1: languageName: node linkType: hard +"lru-cache@npm:^6.0.0": + version: 6.0.0 + resolution: "lru-cache@npm:6.0.0" + dependencies: + yallist: ^4.0.0 + checksum: f97f499f898f23e4585742138a22f22526254fdba6d75d41a1c2526b3b6cc5747ef59c5612ba7375f42aca4f8461950e925ba08c991ead0651b4918b7c978297 + languageName: node + linkType: hard + "macos-release@npm:^2.2.0": version: 2.3.0 resolution: "macos-release@npm:2.3.0" @@ -9706,10 +9941,10 @@ fsevents@~2.3.1: languageName: node linkType: hard -"merge2@npm:^1.2.3": - version: 1.3.0 - resolution: "merge2@npm:1.3.0" - checksum: bff71d47cd8c01edf2222f205f1c312cae0082e2c05b06123b0990605447dc395208367bb1d1635caec6083d3e6bb0756df05ac24cdc15cb630d5af6daa8eb7c +"merge2@npm:^1.2.3, merge2@npm:^1.3.0, merge2@npm:^1.4.1": + version: 1.4.1 + resolution: "merge2@npm:1.4.1" + checksum: 7268db63ed5169466540b6fb947aec313200bcf6d40c5ab722c22e242f651994619bcd85601602972d3c85bd2cc45a358a4c61937e9f11a061919a1da569b0c2 languageName: node linkType: hard @@ -9755,6 +9990,16 @@ fsevents@~2.3.1: languageName: node linkType: hard +"micromatch@npm:^4.0.4": + version: 4.0.5 + resolution: "micromatch@npm:4.0.5" + dependencies: + braces: ^3.0.2 + picomatch: ^2.3.1 + checksum: 02a17b671c06e8fefeeb6ef996119c1e597c942e632a21ef589154f23898c9c6a9858526246abb14f8bca6e77734aa9dcf65476fca47cedfb80d9577d52843fc + languageName: node + linkType: hard + "miller-rabin@npm:^4.0.0": version: 4.0.1 resolution: "miller-rabin@npm:4.0.1" @@ -9804,7 +10049,7 @@ fsevents@~2.3.1: languageName: node linkType: hard -"minimalistic-crypto-utils@npm:^1.0.1": +"minimalistic-crypto-utils@npm:^1.0.0, minimalistic-crypto-utils@npm:^1.0.1": version: 1.0.1 resolution: "minimalistic-crypto-utils@npm:1.0.1" checksum: 6e8a0422b30039406efd4c440829ea8f988845db02a3299f372fceba56ffa94994a9c0f2fd70c17f9969eedfbd72f34b5070ead9656a34d3f71c0bd72583a0ed @@ -9830,14 +10075,14 @@ fsevents@~2.3.1: languageName: node linkType: hard -"minimist@npm:^1.1.1, minimist@npm:^1.1.3, minimist@npm:^1.2.0, minimist@npm:^1.2.5, minimist@npm:^1.2.6": - version: 1.2.6 - resolution: "minimist@npm:1.2.6" - checksum: d15428cd1e11eb14e1233bcfb88ae07ed7a147de251441d61158619dfb32c4d7e9061d09cab4825fdee18ecd6fce323228c8c47b5ba7cd20af378ca4048fb3fb +"minimist@npm:^1.1.1, minimist@npm:^1.1.3, minimist@npm:^1.2.0, minimist@npm:^1.2.5": + version: 1.2.5 + resolution: "minimist@npm:1.2.5" + checksum: 86706ce5b36c16bfc35c5fe3dbb01d5acdc9a22f2b6cc810b6680656a1d2c0e44a0159c9a3ba51fb072bb5c203e49e10b51dcd0eec39c481f4c42086719bae52 languageName: node linkType: hard -"minipass@npm:^2.3.5, minipass@npm:^2.6.0, minipass@npm:^2.9.0": +"minipass@npm:^2.3.5, minipass@npm:^2.6.0, minipass@npm:^2.8.6, minipass@npm:^2.9.0": version: 2.9.0 resolution: "minipass@npm:2.9.0" dependencies: @@ -9847,7 +10092,7 @@ fsevents@~2.3.1: languageName: node linkType: hard -"minizlib@npm:^1.3.3": +"minizlib@npm:^1.2.1": version: 1.3.3 resolution: "minizlib@npm:1.3.3" dependencies: @@ -9893,14 +10138,14 @@ fsevents@~2.3.1: languageName: node linkType: hard -"mkdirp@npm:*, mkdirp@npm:^0.5.1, mkdirp@npm:^0.5.3, mkdirp@npm:^0.5.5": - version: 0.5.6 - resolution: "mkdirp@npm:0.5.6" +"mkdirp@npm:*, mkdirp@npm:^0.5.0, mkdirp@npm:^0.5.1, mkdirp@npm:^0.5.3": + version: 0.5.5 + resolution: "mkdirp@npm:0.5.5" dependencies: - minimist: ^1.2.6 + minimist: ^1.2.5 bin: mkdirp: bin/cmd.js - checksum: 0c91b721bb12c3f9af4b77ebf73604baf350e64d80df91754dc509491ae93bf238581e59c7188360cec7cb62fc4100959245a42cfe01834efedc5e9d068376c2 + checksum: 3bce20ea525f9477befe458ab85284b0b66c8dc3812f94155af07c827175948cdd8114852ac6c6d82009b13c1048c37f6d98743eb019651ee25c39acc8aabe7d languageName: node linkType: hard @@ -9932,7 +10177,7 @@ fsevents@~2.3.1: languageName: node linkType: hard -"ms@npm:^2.0.0, ms@npm:^2.1.1": +"ms@npm:2.1.2, ms@npm:^2.0.0, ms@npm:^2.1.1": version: 2.1.2 resolution: "ms@npm:2.1.2" checksum: 673cdb2c3133eb050c745908d8ce632ed2c02d85640e2edb3ace856a2266a813b30c613569bf3354fdf4ea7d1a1494add3bfa95e2713baa27d0c2c71fc44f58f @@ -10064,16 +10309,9 @@ fsevents@~2.3.1: linkType: hard "node-fetch@npm:^2.3.0, node-fetch@npm:^2.5.0": - version: 2.6.7 - resolution: "node-fetch@npm:2.6.7" - dependencies: - whatwg-url: ^5.0.0 - peerDependencies: - encoding: ^0.1.0 - peerDependenciesMeta: - encoding: - optional: true - checksum: 8d816ffd1ee22cab8301c7756ef04f3437f18dace86a1dae22cf81db8ef29c0bf6655f3215cb0cdb22b420b6fe141e64b26905e7f33f9377a7fa59135ea3e10b + version: 2.6.0 + resolution: "node-fetch@npm:2.6.0" + checksum: 2b741e9315c1c07df4a291d0b304892fa7e8d623fe789fedd53f9bcb8d09102b07591b4b93e552a65dfc457eee9d5d879d0440aefdb64f2d78e7cb78cbad28e9 languageName: node linkType: hard @@ -10976,6 +11214,13 @@ fsevents@~2.3.1: languageName: node linkType: hard +"path-type@npm:^4.0.0": + version: 4.0.0 + resolution: "path-type@npm:4.0.0" + checksum: 5b1e2daa247062061325b8fdbfd1fb56dde0a448fb1455453276ea18c60685bdad23a445dc148cf87bc216be1573357509b7d4060494a6fd768c7efad833ee45 + languageName: node + linkType: hard + "pbkdf2@npm:^3.0.3": version: 3.0.17 resolution: "pbkdf2@npm:3.0.17" @@ -11003,10 +11248,10 @@ fsevents@~2.3.1: languageName: node linkType: hard -"picomatch@npm:^2.0.4, picomatch@npm:^2.2.1, picomatch@npm:^2.2.2": - version: 2.2.2 - resolution: "picomatch@npm:2.2.2" - checksum: 897a589f94665b4fd93e075fa94893936afe3f7bbef44250f0e878a8d9d001972a79589cac2856c24f6f5aa3b0abc9c8ba00c98fae4dc22bc0117188864d4181 +"picomatch@npm:^2.0.4, picomatch@npm:^2.2.1, picomatch@npm:^2.2.2, picomatch@npm:^2.3.1": + version: 2.3.1 + resolution: "picomatch@npm:2.3.1" + checksum: 050c865ce81119c4822c45d3c84f1ced46f93a0126febae20737bd05ca20589c564d6e9226977df859ed5e03dc73f02584a2b0faad36e896936238238b0446cf languageName: node linkType: hard @@ -11359,6 +11604,13 @@ fsevents@~2.3.1: languageName: node linkType: hard +"queue-microtask@npm:^1.2.2": + version: 1.2.3 + resolution: "queue-microtask@npm:1.2.3" + checksum: b676f8c040cdc5b12723ad2f91414d267605b26419d5c821ff03befa817ddd10e238d22b25d604920340fd73efd8ba795465a0377c4adf45a4a41e4234e42dc4 + languageName: node + linkType: hard + "quick-lru@npm:5.1.0": version: 5.1.0 resolution: "quick-lru@npm:5.1.0" @@ -11697,6 +11949,13 @@ fsevents@~2.3.1: languageName: node linkType: hard +"regexpp@npm:^3.2.0": + version: 3.2.0 + resolution: "regexpp@npm:3.2.0" + checksum: a78dc5c7158ad9ddcfe01aa9144f46e192ddbfa7b263895a70a5c6c73edd9ce85faf7c0430e59ac38839e1734e275b9c3de5c57ee3ab6edc0e0b1bdebefccef8 + languageName: node + linkType: hard + "regexpu-core@npm:^5.0.1": version: 5.0.1 resolution: "regexpu-core@npm:5.0.1" @@ -11995,6 +12254,13 @@ resolve@1.1.7: languageName: node linkType: hard +"reusify@npm:^1.0.4": + version: 1.0.4 + resolution: "reusify@npm:1.0.4" + checksum: c3076ebcc22a6bc252cb0b9c77561795256c22b757f40c0d8110b1300723f15ec0fc8685e8d4ea6d7666f36c79ccc793b1939c748bf36f18f542744a4e379fcc + languageName: node + linkType: hard + "rimraf@npm:2.6.3": version: 2.6.3 resolution: "rimraf@npm:2.6.3" @@ -12079,6 +12345,15 @@ resolve@1.1.7: languageName: node linkType: hard +"run-parallel@npm:^1.1.9": + version: 1.2.0 + resolution: "run-parallel@npm:1.2.0" + dependencies: + queue-microtask: ^1.2.2 + checksum: cb4f97ad25a75ebc11a8ef4e33bb962f8af8516bb2001082ceabd8902e15b98f4b84b4f8a9b222e5d57fc3bd1379c483886ed4619367a7680dad65316993021d + languageName: node + linkType: hard + "run-queue@npm:^1.0.0, run-queue@npm:^1.0.3": version: 1.0.3 resolution: "run-queue@npm:1.0.3" @@ -12097,10 +12372,10 @@ resolve@1.1.7: languageName: node linkType: hard -"safe-buffer@npm:^5.0.1, safe-buffer@npm:^5.1.0, safe-buffer@npm:^5.1.1, safe-buffer@npm:^5.1.2, safe-buffer@npm:^5.2.0, safe-buffer@npm:^5.2.1, safe-buffer@npm:~5.2.0": - version: 5.2.1 - resolution: "safe-buffer@npm:5.2.1" - checksum: b99c4b41fdd67a6aaf280fcd05e9ffb0813654894223afb78a31f14a19ad220bba8aba1cb14eddce1fcfb037155fe6de4e861784eb434f7d11ed58d1e70dd491 +"safe-buffer@npm:^5.0.1, safe-buffer@npm:^5.1.0, safe-buffer@npm:^5.1.1, safe-buffer@npm:^5.1.2, safe-buffer@npm:^5.2.0, safe-buffer@npm:~5.2.0": + version: 5.2.0 + resolution: "safe-buffer@npm:5.2.0" + checksum: 91d50127aeaee9b8cb1ee12c810d719e29813d1ab1ce6d1b4704cd9ca0e0bfa47455e02cf1bb238be90f2db764447f058fbaef1a1018ae8387c692615d72f86c languageName: node linkType: hard @@ -12210,6 +12485,17 @@ resolve@1.1.7: languageName: node linkType: hard +"semver@npm:^7.3.5": + version: 7.3.5 + resolution: "semver@npm:7.3.5" + dependencies: + lru-cache: ^6.0.0 + bin: + semver: bin/semver.js + checksum: 5eafe6102bea2a7439897c1856362e31cc348ccf96efd455c8b5bc2c61e6f7e7b8250dc26b8828c1d76a56f818a7ee907a36ae9fb37a599d3d24609207001d60 + languageName: node + linkType: hard + "serialize-javascript@npm:^2.1.2": version: 2.1.2 resolution: "serialize-javascript@npm:2.1.2" @@ -12326,6 +12612,13 @@ resolve@1.1.7: languageName: node linkType: hard +"slash@npm:^3.0.0": + version: 3.0.0 + resolution: "slash@npm:3.0.0" + checksum: 94a93fff615f25a999ad4b83c9d5e257a7280c90a32a7cb8b4a87996e4babf322e469c42b7f649fd5796edd8687652f3fb452a86dc97a816f01113183393f11c + languageName: node + linkType: hard + "slice-ansi@npm:^2.1.0": version: 2.1.0 resolution: "slice-ansi@npm:2.1.0" @@ -12564,11 +12857,11 @@ resolve@1.1.7: linkType: hard "ssri@npm:^6.0.0, ssri@npm:^6.0.1": - version: 6.0.2 - resolution: "ssri@npm:6.0.2" + version: 6.0.1 + resolution: "ssri@npm:6.0.1" dependencies: figgy-pudding: ^3.5.1 - checksum: 7c2e5d442f6252559c8987b7114bcf389fe5614bf65de09ba3e6f9a57b9b65b2967de348fcc3acccff9c069adb168140dd2c5fc2f6f4a779e604a27ef1f7d551 + checksum: 9520acadfe75867e4a9d815572320133465730b1cd5f76b80913096b69266eceb40673e62b4899c7a62607eb07f625b9748016d94bdfcf8d813b3c2f9629ec76 languageName: node linkType: hard @@ -12926,17 +13219,17 @@ resolve@1.1.7: linkType: hard "tar@npm:^4.4.10, tar@npm:^4.4.12, tar@npm:^4.4.2, tar@npm:^4.4.8": - version: 4.4.19 - resolution: "tar@npm:4.4.19" + version: 4.4.13 + resolution: "tar@npm:4.4.13" dependencies: - chownr: ^1.1.4 - fs-minipass: ^1.2.7 - minipass: ^2.9.0 - minizlib: ^1.3.3 - mkdirp: ^0.5.5 - safe-buffer: ^5.2.1 - yallist: ^3.1.1 - checksum: 423c8259b17f8f612cef9c96805d65f90ba9a28e19be582cd9d0fcb217038219f29b7547198e8fd617da5f436376d6a74b99827acd1238d2f49cf62330f9664e + chownr: ^1.1.1 + fs-minipass: ^1.2.5 + minipass: ^2.8.6 + minizlib: ^1.2.1 + mkdirp: ^0.5.0 + safe-buffer: ^5.1.2 + yallist: ^3.0.3 + checksum: 71d9914468eb7cdc361a5d79267aa45d41081fbc8e1a244381052e6147ac1b285d3b8eb9a3521bf58a6a0d8498394623b3fd8db16c808364594874a15e6fa10a languageName: node linkType: hard @@ -13204,13 +13497,6 @@ resolve@1.1.7: languageName: node linkType: hard -"tr46@npm:~0.0.3": - version: 0.0.3 - resolution: "tr46@npm:0.0.3" - checksum: 726321c5eaf41b5002e17ffbd1fb7245999a073e8979085dacd47c4b4e8068ff5777142fc6726d6ca1fd2ff16921b48788b87225cbc57c72636f6efa8efbffe3 - languageName: node - linkType: hard - "trim-newlines@npm:^1.0.0": version: 1.0.0 resolution: "trim-newlines@npm:1.0.0" @@ -13232,10 +13518,21 @@ resolve@1.1.7: languageName: node linkType: hard -"tslib@npm:^1.9.0": - version: 1.11.1 - resolution: "tslib@npm:1.11.1" - checksum: 06976234d5c63455d6f2ae38c1f1534bb559587248e1de7c2790f9e2c2ee6149a793f1138dba77665cb3f23b4bdeb033b2ac75a8368999ec056ed58681b7dfc7 +"tslib@npm:^1.8.1, tslib@npm:^1.9.0": + version: 1.14.1 + resolution: "tslib@npm:1.14.1" + checksum: dbe628ef87f66691d5d2959b3e41b9ca0045c3ee3c7c7b906cc1e328b39f199bb1ad9e671c39025bd56122ac57dfbf7385a94843b1cc07c60a4db74795829acd + languageName: node + linkType: hard + +"tsutils@npm:^3.21.0": + version: 3.21.0 + resolution: "tsutils@npm:3.21.0" + dependencies: + tslib: ^1.8.1 + peerDependencies: + typescript: ">=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta" + checksum: 1843f4c1b2e0f975e08c4c21caa4af4f7f65a12ac1b81b3b8489366826259323feb3fc7a243123453d2d1a02314205a7634e048d4a8009921da19f99755cdc48 languageName: node linkType: hard @@ -13796,13 +14093,6 @@ resolve@1.1.7: languageName: node linkType: hard -"webidl-conversions@npm:^3.0.0": - version: 3.0.1 - resolution: "webidl-conversions@npm:3.0.1" - checksum: c92a0a6ab95314bde9c32e1d0a6dfac83b578f8fa5f21e675bc2706ed6981bc26b7eb7e6a1fab158e5ce4adf9caa4a0aee49a52505d4d13c7be545f15021b17c - languageName: node - linkType: hard - "webidl-conversions@npm:^4.0.2": version: 4.0.2 resolution: "webidl-conversions@npm:4.0.2" @@ -13892,16 +14182,6 @@ resolve@1.1.7: languageName: node linkType: hard -"whatwg-url@npm:^5.0.0": - version: 5.0.0 - resolution: "whatwg-url@npm:5.0.0" - dependencies: - tr46: ~0.0.3 - webidl-conversions: ^3.0.0 - checksum: b8daed4ad3356cc4899048a15b2c143a9aed0dfae1f611ebd55073310c7b910f522ad75d727346ad64203d7e6c79ef25eafd465f4d12775ca44b90fa82ed9e2c - languageName: node - linkType: hard - "whatwg-url@npm:^6.4.1": version: 6.5.0 resolution: "whatwg-url@npm:6.5.0" @@ -14124,26 +14404,33 @@ resolve@1.1.7: linkType: hard "y18n@npm:^3.2.1": - version: 3.2.2 - resolution: "y18n@npm:3.2.2" - checksum: 6154fd7544f8bbf5b18cdf77692ed88d389be49c87238ecb4e0d6a5276446cd2a5c29cc4bdbdddfc7e4e498b08df9d7e38df4a1453cf75eecfead392246ea74a + version: 3.2.1 + resolution: "y18n@npm:3.2.1" + checksum: e359082da23498caf6ffa5f4f715338fa974027d7e9cf1938462b41e69cf62addac0f1970c169f15f97fd20fb1cf8d44d069b4d51942b3c255ee13d5b234b6b8 languageName: node linkType: hard "y18n@npm:^4.0.0": - version: 4.0.3 - resolution: "y18n@npm:4.0.3" - checksum: 014dfcd9b5f4105c3bb397c1c8c6429a9df004aa560964fb36732bfb999bfe83d45ae40aeda5b55d21b1ee53d8291580a32a756a443e064317953f08025b1aa4 + version: 4.0.0 + resolution: "y18n@npm:4.0.0" + checksum: 66e22d38bf994723b625dcc0159f6fd4068c511f8c565df39e8aa53426f5f31e4a9664a8d7099fbde2c22a1c71be2cb60e83f4c2961a5ee48672418d825a7bc2 languageName: node linkType: hard -"yallist@npm:^3.0.0, yallist@npm:^3.0.2, yallist@npm:^3.1.1": +"yallist@npm:^3.0.0, yallist@npm:^3.0.2, yallist@npm:^3.0.3": version: 3.1.1 resolution: "yallist@npm:3.1.1" checksum: 48f7bb00dc19fc635a13a39fe547f527b10c9290e7b3e836b9a8f1ca04d4d342e85714416b3c2ab74949c9c66f9cebb0473e6bc353b79035356103b47641285d languageName: node linkType: hard +"yallist@npm:^4.0.0": + version: 4.0.0 + resolution: "yallist@npm:4.0.0" + checksum: 343617202af32df2a15a3be36a5a8c0c8545208f3d3dfbc6bb7c3e3b7e8c6f8e7485432e4f3b88da3031a6e20afa7c711eded32ddfb122896ac5d914e75848d5 + languageName: node + linkType: hard + "yargs-parser@npm:^10.0.0": version: 10.1.0 resolution: "yargs-parser@npm:10.1.0" From e48fa62d392d0e10b0426af5444a7547cee64886 Mon Sep 17 00:00:00 2001 From: Anton Gilgur Date: Sat, 26 Mar 2022 15:59:50 -0400 Subject: [PATCH 03/13] env: support building TS files deps: add @babel/preset-typescript to parse and build TS files - to continue working with rollup-plugin-babel - Babel core does this as well - and add it to babel.config.json - modify Gulpfile + Rollup config to handle TS - add TS extensions to Gulpfile globs - use index.ts as entrypoint now - this will be used in the next commit post-conversion - modify shipped-proposals script to output as TS - basically just no `// @flow` comment on top - and use `.ts` extension - also update comment to use the script's current extension, `.mjs` --- Gulpfile.js | 6 +-- babel.config.json | 3 +- package.json | 1 + ...pped-proposals.js => shipped-proposals.ts} | 3 +- scripts/build-corejs3-shipped-proposals.mjs | 5 +-- test/esm/package.json | 2 +- yarn.lock | 42 ++++++++++++++++++- 7 files changed, 50 insertions(+), 12 deletions(-) rename packages/babel-plugin-polyfill-corejs3/src/{shipped-proposals.js => shipped-proposals.ts} (88%) diff --git a/Gulpfile.js b/Gulpfile.js index 1f76129c..863a53e2 100644 --- a/Gulpfile.js +++ b/Gulpfile.js @@ -55,7 +55,7 @@ function build() { const base = path.join(__dirname, "packages"); return gulp - .src("./packages/*/src/**/*.js", { base: base }) + .src("./packages/*/src/**/*.{js,ts}", { base: base }) .pipe(errorsLogger()) .pipe(newer({ dest: base, map: swapSrcWithLib })) .pipe(compilationLogger()) @@ -85,7 +85,7 @@ async function buildRollup() { }; const bundle = await rollup({ - input: `${dir}/src/index.js`, + input: `${dir}/src/index.ts`, external, plugins: [ rollupJson(), @@ -127,7 +127,7 @@ gulp.task( "watch", gulp.series("build", function watch() { gulpWatch( - "./packages/*/src/**/*.js", + "./packages/*/src/**/*.{js,ts}", { debounceDelay: 200 }, gulp.task("build") ); diff --git a/babel.config.json b/babel.config.json index e7dbfef4..af130cd3 100644 --- a/babel.config.json +++ b/babel.config.json @@ -2,7 +2,8 @@ "sourceType": "unambiguous", "presets": [ ["@babel/preset-env", { "loose": true }], - "@babel/preset-flow" + "@babel/preset-flow", + "@babel/preset-typescript" ], "plugins": ["./scripts/babel-plugin-remove-create-require"], "targets": { "node": "current" }, diff --git a/package.json b/package.json index e7fdd54e..d94e64d0 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,7 @@ "@babel/plugin-transform-runtime": "^7.17.0", "@babel/preset-env": "^7.16.11", "@babel/preset-flow": "^7.16.7", + "@babel/preset-typescript": "^7.16.7", "@babel/runtime": "^7.17.8", "@rollup/plugin-babel": "^5.3.0", "@rollup/plugin-json": "^4.1.0", diff --git a/packages/babel-plugin-polyfill-corejs3/src/shipped-proposals.js b/packages/babel-plugin-polyfill-corejs3/src/shipped-proposals.ts similarity index 88% rename from packages/babel-plugin-polyfill-corejs3/src/shipped-proposals.js rename to packages/babel-plugin-polyfill-corejs3/src/shipped-proposals.ts index 40433fff..61b0aefd 100644 --- a/packages/babel-plugin-polyfill-corejs3/src/shipped-proposals.js +++ b/packages/babel-plugin-polyfill-corejs3/src/shipped-proposals.ts @@ -1,5 +1,4 @@ -// @flow -// This file is automatically generated by scripts/build-corejs3-shipped-proposals.js +// This file is automatically generated by scripts/build-corejs3-shipped-proposals.mjs export default new Set([ "esnext.array.find-last", diff --git a/scripts/build-corejs3-shipped-proposals.mjs b/scripts/build-corejs3-shipped-proposals.mjs index b1d4076c..ba5ff7e6 100644 --- a/scripts/build-corejs3-shipped-proposals.mjs +++ b/scripts/build-corejs3-shipped-proposals.mjs @@ -2,12 +2,11 @@ import compatData from "../packages/babel-plugin-polyfill-corejs3/core-js-compat import fs from "node:fs"; const path = new URL( - "../packages/babel-plugin-polyfill-corejs3/src/shipped-proposals.js", + "../packages/babel-plugin-polyfill-corejs3/src/shipped-proposals.ts", import.meta.url ); -const template = features => `// @flow -// This file is automatically generated by scripts/build-corejs3-shipped-proposals.js +const template = features => `// This file is automatically generated by scripts/build-corejs3-shipped-proposals.mjs export default new Set([ ${features.map(f => ` "${f}",\n`).join("")}]); diff --git a/test/esm/package.json b/test/esm/package.json index 5ef22f51..633477dc 100644 --- a/test/esm/package.json +++ b/test/esm/package.json @@ -2,7 +2,7 @@ "private": true, "name": "@babel-internal/test-esm", "devDependencies": { - "@babel/core": "^7.13.10", + "@babel/core": "^7.17.8", "babel-plugin-polyfill-corejs2": "workspace:*", "babel-plugin-polyfill-corejs3": "workspace:*", "babel-plugin-polyfill-es-shims": "workspace:*", diff --git a/yarn.lock b/yarn.lock index defdeaa2..ee3be50c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -18,7 +18,7 @@ __metadata: version: 0.0.0-use.local resolution: "@babel-internal/test-esm@workspace:test/esm" dependencies: - "@babel/core": ^7.13.10 + "@babel/core": ^7.17.8 babel-plugin-polyfill-corejs2: "workspace:*" babel-plugin-polyfill-corejs3: "workspace:*" babel-plugin-polyfill-es-shims: "workspace:*" @@ -70,7 +70,7 @@ __metadata: languageName: node linkType: hard -"@babel/core@npm:^7.1.0, @babel/core@npm:^7.13.10, @babel/core@npm:^7.17.7, @babel/core@npm:^7.17.8": +"@babel/core@npm:^7.1.0, @babel/core@npm:^7.17.7, @babel/core@npm:^7.17.8": version: 7.17.8 resolution: "@babel/core@npm:7.17.8" dependencies: @@ -845,6 +845,17 @@ __metadata: languageName: node linkType: hard +"@babel/plugin-syntax-typescript@npm:^7.16.7": + version: 7.16.7 + resolution: "@babel/plugin-syntax-typescript@npm:7.16.7" + dependencies: + "@babel/helper-plugin-utils": ^7.16.7 + peerDependencies: + "@babel/core": ^7.0.0-0 + checksum: 661e636060609ede9a402e22603b01784c21fabb0a637e65f561c8159351fe0130bbc11fdefe31902107885e3332fc34d95eb652ac61d3f61f2d61f5da20609e + languageName: node + linkType: hard + "@babel/plugin-transform-arrow-functions@npm:^7.16.7": version: 7.16.7 resolution: "@babel/plugin-transform-arrow-functions@npm:7.16.7" @@ -1228,6 +1239,19 @@ __metadata: languageName: node linkType: hard +"@babel/plugin-transform-typescript@npm:^7.16.7": + version: 7.16.8 + resolution: "@babel/plugin-transform-typescript@npm:7.16.8" + dependencies: + "@babel/helper-create-class-features-plugin": ^7.16.7 + "@babel/helper-plugin-utils": ^7.16.7 + "@babel/plugin-syntax-typescript": ^7.16.7 + peerDependencies: + "@babel/core": ^7.0.0-0 + checksum: a76d0afcbd550208cf2e7cdedb4f2d3ca3fa287640a4858a5ee0a28270b784d7d20d5a51b5997dc84514e066a5ebef9e0a0f74ed9fffae09e73984786dd08036 + languageName: node + linkType: hard + "@babel/plugin-transform-unicode-escapes@npm:^7.16.7": version: 7.16.7 resolution: "@babel/plugin-transform-unicode-escapes@npm:7.16.7" @@ -1363,6 +1387,19 @@ __metadata: languageName: node linkType: hard +"@babel/preset-typescript@npm:^7.16.7": + version: 7.16.7 + resolution: "@babel/preset-typescript@npm:7.16.7" + dependencies: + "@babel/helper-plugin-utils": ^7.16.7 + "@babel/helper-validator-option": ^7.16.7 + "@babel/plugin-transform-typescript": ^7.16.7 + peerDependencies: + "@babel/core": ^7.0.0-0 + checksum: 44e2f3fa302befe0dc50a01b79e5aa8c27a9c7047c46df665beae97201173030646ddf7c83d7d3ed3724fc38151745b11693e7b4502c81c4cd67781ff5677da5 + languageName: node + linkType: hard + "@babel/runtime@npm:^7.17.8, @babel/runtime@npm:^7.8.4": version: 7.17.8 resolution: "@babel/runtime@npm:7.17.8" @@ -4128,6 +4165,7 @@ __metadata: "@babel/plugin-transform-runtime": ^7.17.0 "@babel/preset-env": ^7.16.11 "@babel/preset-flow": ^7.16.7 + "@babel/preset-typescript": ^7.16.7 "@babel/runtime": ^7.17.8 "@rollup/plugin-babel": ^5.3.0 "@rollup/plugin-json": ^4.1.0 From 7d7865ae9178d63cbf6659453cf55e542c276041 Mon Sep 17 00:00:00 2001 From: Anton Gilgur Date: Fri, 25 Mar 2022 17:32:34 -0400 Subject: [PATCH 04/13] refactor: auto Flow -> TS via flowts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - ran `flowts` - then manually reversed a few incorrect formatting - some lines that had `// eslint-ignore` or `// prettier-ignore` - and manually reversed some unnecessary spacing / new line changes - as requested by Nicolò - manually renamed some auto-named vars in parameter types - major changes seem to be: - removing `// @flow` at the top of files - `*` -> `any` - `Object` -> `any` - `?type` -> `type | undefined | null` - using semicolons instead of commas for object property types - this is just TS syntax vs. Flow syntax - this is the majority of reformatting and caused a types file to appear as deletion+addition instead of rename as the majority of lines were reformatted due to this change - 453 type errors post-conversion that need to be manually fixed --- .../{dependencies.js => dependencies.ts} | 2 - .../src/{debug-utils.js => debug-utils.ts} | 2 - ...{define-provider.js => define-provider.ts} | 4 +- .../{imports-cache.js => imports-cache.ts} | 8 +- .../src/{index.js => index.ts} | 21 ++-- .../{meta-resolver.js => meta-resolver.ts} | 2 - .../node/{dependencies.js => dependencies.ts} | 2 - ...malize-options.js => normalize-options.ts} | 6 +- .../src/types.js | 109 ------------------ .../src/types.ts | 106 +++++++++++++++++ .../src/{utils.js => utils.ts} | 4 +- .../src/visitors/{entry.js => entry.ts} | 2 - .../src/visitors/{index.js => index.ts} | 2 - .../src/visitors/{usage.js => usage.ts} | 2 - ....js => add-platform-specific-polyfills.ts} | 4 +- ...definitions.js => built-in-definitions.ts} | 20 ++-- .../src/{helpers.js => helpers.ts} | 4 +- .../src/{index.js => index.ts} | 18 ++- ...definitions.js => built-in-definitions.ts} | 10 +- .../src/{index.js => index.ts} | 20 ++-- .../src/{utils.js => utils.ts} | 4 +- .../test/check-builtin-definitions.test.js | 2 +- .../src/{index.js => index.ts} | 15 ++- .../src/{mappings.js => mappings.ts} | 28 +++-- .../src/{index.js => index.ts} | 2 - 25 files changed, 181 insertions(+), 218 deletions(-) rename packages/babel-helper-define-polyfill-provider/src/browser/{dependencies.js => dependencies.ts} (98%) rename packages/babel-helper-define-polyfill-provider/src/{debug-utils.js => debug-utils.ts} (98%) rename packages/babel-helper-define-polyfill-provider/src/{define-provider.js => define-provider.ts} (87%) rename packages/babel-helper-define-polyfill-provider/src/{imports-cache.js => imports-cache.ts} (96%) rename packages/babel-helper-define-polyfill-provider/src/{index.js => index.ts} (96%) rename packages/babel-helper-define-polyfill-provider/src/{meta-resolver.js => meta-resolver.ts} (99%) rename packages/babel-helper-define-polyfill-provider/src/node/{dependencies.js => dependencies.ts} (99%) rename packages/babel-helper-define-polyfill-provider/src/{normalize-options.js => normalize-options.ts} (96%) delete mode 100644 packages/babel-helper-define-polyfill-provider/src/types.js create mode 100644 packages/babel-helper-define-polyfill-provider/src/types.ts rename packages/babel-helper-define-polyfill-provider/src/{utils.js => utils.ts} (98%) rename packages/babel-helper-define-polyfill-provider/src/visitors/{entry.js => entry.ts} (98%) rename packages/babel-helper-define-polyfill-provider/src/visitors/{index.js => index.ts} (89%) rename packages/babel-helper-define-polyfill-provider/src/visitors/{usage.js => usage.ts} (99%) rename packages/babel-plugin-polyfill-corejs2/src/{add-platform-specific-polyfills.js => add-platform-specific-polyfills.ts} (96%) rename packages/babel-plugin-polyfill-corejs2/src/{built-in-definitions.js => built-in-definitions.ts} (97%) rename packages/babel-plugin-polyfill-corejs2/src/{helpers.js => helpers.ts} (94%) rename packages/babel-plugin-polyfill-corejs2/src/{index.js => index.ts} (96%) rename packages/babel-plugin-polyfill-corejs3/src/{built-in-definitions.js => built-in-definitions.ts} (99%) rename packages/babel-plugin-polyfill-corejs3/src/{index.js => index.ts} (97%) rename packages/babel-plugin-polyfill-corejs3/src/{utils.js => utils.ts} (94%) rename packages/babel-plugin-polyfill-es-shims/src/{index.js => index.ts} (94%) rename packages/babel-plugin-polyfill-es-shims/src/{mappings.js => mappings.ts} (93%) rename packages/babel-plugin-polyfill-regenerator/src/{index.js => index.ts} (98%) diff --git a/packages/babel-helper-define-polyfill-provider/src/browser/dependencies.js b/packages/babel-helper-define-polyfill-provider/src/browser/dependencies.ts similarity index 98% rename from packages/babel-helper-define-polyfill-provider/src/browser/dependencies.js rename to packages/babel-helper-define-polyfill-provider/src/browser/dependencies.ts index 20c0961a..51e61c9b 100644 --- a/packages/babel-helper-define-polyfill-provider/src/browser/dependencies.js +++ b/packages/babel-helper-define-polyfill-provider/src/browser/dependencies.ts @@ -1,5 +1,3 @@ -// @flow - export function resolve( dirname: string, moduleName: string, diff --git a/packages/babel-helper-define-polyfill-provider/src/debug-utils.js b/packages/babel-helper-define-polyfill-provider/src/debug-utils.ts similarity index 98% rename from packages/babel-helper-define-polyfill-provider/src/debug-utils.js rename to packages/babel-helper-define-polyfill-provider/src/debug-utils.ts index 1042e6fc..51dd0afc 100644 --- a/packages/babel-helper-define-polyfill-provider/src/debug-utils.js +++ b/packages/babel-helper-define-polyfill-provider/src/debug-utils.ts @@ -1,5 +1,3 @@ -// @flow - import { prettifyTargets } from "@babel/helper-compilation-targets"; import type { Targets } from "./types"; diff --git a/packages/babel-helper-define-polyfill-provider/src/define-provider.js b/packages/babel-helper-define-polyfill-provider/src/define-provider.ts similarity index 87% rename from packages/babel-helper-define-polyfill-provider/src/define-provider.js rename to packages/babel-helper-define-polyfill-provider/src/define-provider.ts index 07b195fd..3ebb08f2 100644 --- a/packages/babel-helper-define-polyfill-provider/src/define-provider.js +++ b/packages/babel-helper-define-polyfill-provider/src/define-provider.ts @@ -1,5 +1,3 @@ -// @flow - import type { PolyfillProviderInternal, PolyfillProvider } from "./types"; export function defineProvider( @@ -7,5 +5,5 @@ export function defineProvider( ): PolyfillProviderInternal { // This will allow us to do some things - return (factory: any); + return factory as any; } diff --git a/packages/babel-helper-define-polyfill-provider/src/imports-cache.js b/packages/babel-helper-define-polyfill-provider/src/imports-cache.ts similarity index 96% rename from packages/babel-helper-define-polyfill-provider/src/imports-cache.js rename to packages/babel-helper-define-polyfill-provider/src/imports-cache.ts index eca704b7..6779eb34 100644 --- a/packages/babel-helper-define-polyfill-provider/src/imports-cache.js +++ b/packages/babel-helper-define-polyfill-provider/src/imports-cache.ts @@ -1,5 +1,3 @@ -// @flow - import type { NodePath } from "@babel/traverse"; import * as babel from "@babel/core"; const { types: t } = babel.default || babel; @@ -48,7 +46,7 @@ export default class ImportsCache { source: t.StringLiteral, // eslint-disable-next-line no-undef name: t.Identifier, - ) => { node: t.Node, name: string }, + ) => { node: t.Node; name: string }, ) { const key = this._normalizeKey(programPath, url, name); const imports = this._ensure(this._imports, programPath, Map); @@ -106,10 +104,10 @@ export default class ImportsCache { });*/ } - _ensure | Set<*>>( + _ensure | Set>( map: WeakMap, programPath: NodePath, - Collection: Class, + Collection: { new (...args: any): C }, ): C { let collection = map.get(programPath); if (!collection) { diff --git a/packages/babel-helper-define-polyfill-provider/src/index.js b/packages/babel-helper-define-polyfill-provider/src/index.ts similarity index 96% rename from packages/babel-helper-define-polyfill-provider/src/index.js rename to packages/babel-helper-define-polyfill-provider/src/index.ts index a1710258..68590c3d 100644 --- a/packages/babel-helper-define-polyfill-provider/src/index.js +++ b/packages/babel-helper-define-polyfill-provider/src/index.ts @@ -1,5 +1,3 @@ -// @flow - import { declare } from "@babel/helper-plugin-utils"; import type { NodePath } from "@babel/traverse"; @@ -41,13 +39,16 @@ function resolveOptions( options: PluginOptions, babelApi, ): { - method: MethodString, - methodName: "usageGlobal" | "entryGlobal" | "usagePure", - targets: Targets, - debug: boolean, - shouldInjectPolyfill: ?(name: string, shouldInject: boolean) => boolean, - providerOptions: ProviderOptions, - absoluteImports: string | boolean, + method: MethodString; + methodName: "usageGlobal" | "entryGlobal" | "usagePure"; + targets: Targets; + debug: boolean; + shouldInjectPolyfill: + | ((name: string, shouldInject: boolean) => boolean) + | undefined + | null; + providerOptions: ProviderOptions; + absoluteImports: string | boolean; } { const { method, @@ -141,7 +142,7 @@ See more options at https://github.com/babel/babel-polyfills/blob/main/docs/usag absoluteImports: absoluteImports ?? false, shouldInjectPolyfill, debug: !!debug, - providerOptions: ((providerOptions: Object): ProviderOptions), + providerOptions: providerOptions as any as ProviderOptions, }; } diff --git a/packages/babel-helper-define-polyfill-provider/src/meta-resolver.js b/packages/babel-helper-define-polyfill-provider/src/meta-resolver.ts similarity index 99% rename from packages/babel-helper-define-polyfill-provider/src/meta-resolver.js rename to packages/babel-helper-define-polyfill-provider/src/meta-resolver.ts index d1573094..a286b604 100644 --- a/packages/babel-helper-define-polyfill-provider/src/meta-resolver.js +++ b/packages/babel-helper-define-polyfill-provider/src/meta-resolver.ts @@ -1,5 +1,3 @@ -// @flow - import type { MetaDescriptor, ResolverPolyfills, diff --git a/packages/babel-helper-define-polyfill-provider/src/node/dependencies.js b/packages/babel-helper-define-polyfill-provider/src/node/dependencies.ts similarity index 99% rename from packages/babel-helper-define-polyfill-provider/src/node/dependencies.js rename to packages/babel-helper-define-polyfill-provider/src/node/dependencies.ts index f755f6a3..adf212b1 100644 --- a/packages/babel-helper-define-polyfill-provider/src/node/dependencies.js +++ b/packages/babel-helper-define-polyfill-provider/src/node/dependencies.ts @@ -1,5 +1,3 @@ -// @flow - import path from "path"; import debounce from "lodash.debounce"; import requireResolve from "resolve"; diff --git a/packages/babel-helper-define-polyfill-provider/src/normalize-options.js b/packages/babel-helper-define-polyfill-provider/src/normalize-options.ts similarity index 96% rename from packages/babel-helper-define-polyfill-provider/src/normalize-options.js rename to packages/babel-helper-define-polyfill-provider/src/normalize-options.ts index c985015e..2bc4b6ff 100644 --- a/packages/babel-helper-define-polyfill-provider/src/normalize-options.js +++ b/packages/babel-helper-define-polyfill-provider/src/normalize-options.ts @@ -1,5 +1,3 @@ -// @flow - import { intersection } from "./utils"; import type { Pattern, @@ -7,7 +5,7 @@ import type { MissingDependenciesOption, } from "./types"; -function patternToRegExp(pattern: Pattern): ?RegExp { +function patternToRegExp(pattern: Pattern): RegExp | undefined | null { if (pattern instanceof RegExp) return pattern; try { @@ -82,7 +80,7 @@ export function validateIncludeExclude( export function applyMissingDependenciesDefaults( options: PluginOptions, - babelApi: Object, + babelApi: any, ): MissingDependenciesOption { const { missingDependencies = {} } = options; if (missingDependencies === false) return false; diff --git a/packages/babel-helper-define-polyfill-provider/src/types.js b/packages/babel-helper-define-polyfill-provider/src/types.js deleted file mode 100644 index 70badbce..00000000 --- a/packages/babel-helper-define-polyfill-provider/src/types.js +++ /dev/null @@ -1,109 +0,0 @@ -// @flow - -import type { NodePath } from "@babel/traverse"; -import * as babel from "@babel/core"; -const { types: t } = babel.default || babel; -import createMetaResolver from "./meta-resolver"; - -type ObjectMap = { [k: string]: T }; - -export type Pattern = string | RegExp; - -export type MissingDependenciesOption = - | false - | { - log?: "per-file" | "deferred", - inject?: "import" | "throw", - // When true, log all the polyfills without checking if they are installed - all?: boolean, - }; - -export type ProviderOptions = {| - ...Opts, - include?: Pattern[], - exclude?: Pattern[], -|}; - -export type PluginOptions = {| - method: MethodString, - targets?: { browsers: string | string[], [target: string]: string | number }, - ignoreBrowserslistConfig?: boolean, - configPath?: string, - debug?: boolean, - include?: Pattern[], - exclude?: Pattern[], - shouldInjectPolyfill?: (name: string, shouldInject: boolean) => boolean, - missingDependencies?: MissingDependenciesOption, - absoluteImports?: boolean | string, -|}; - -export type PolyfillProvider = ( - api: ProviderApi, - options: ProviderOptions, - dirname: string, -) => ProviderResult; - -export opaque type PolyfillProviderInternal = PolyfillProvider; - -export type MethodString = "entry-global" | "usage-global" | "usage-pure"; - -export type Targets = { - [target: string]: string, -}; - -export type ProviderApi = {| - babel: Object, - method: MethodString, - targets: Targets, - createMetaResolver: typeof createMetaResolver, - getUtils(path: NodePath): Utils, - shouldInjectPolyfill(name: string): boolean, - debug(name: string | null): void, - assertDependency(name: string, version?: string): void, -|}; - -export type Utils = {| - injectGlobalImport(url: string): void, - injectNamedImport(url: string, name: string, hint?: string): t.Identifier, - injectDefaultImport(url: string, hint?: string): t.Identifier, -|}; - -export type ProviderResult = {| - name: string, - polyfills?: string[] | { [name: string]: Targets }, - filterPolyfills?: (name: string) => boolean, - entryGlobal?: (meta: MetaDescriptor, utils: Utils, path: NodePath) => void, - usageGlobal?: (meta: MetaDescriptor, utils: Utils, path: NodePath) => void, - usagePure?: (meta: MetaDescriptor, utils: Utils, path: NodePath) => void, - visitor?: Object, - pre?: Function, - post?: Function, -|}; - -export type MetaDescriptor = - | {| kind: "import", source: string |} - | {| kind: "global", name: string |} - | {| - kind: "property", - placement: ?("static" | "prototype"), - object: ?string, - key: string, - |} - | {| - kind: "in", - placement: ?("static" | "prototype"), - object: ?string, - key: string, - |}; - -export type ResolverPolyfills = { - global?: ObjectMap, - static?: ObjectMap>, - instance?: ObjectMap, -}; - -export type ResolvedPolyfill = { - kind: "global" | "static" | "instance", - name: string, - desc: T, -}; diff --git a/packages/babel-helper-define-polyfill-provider/src/types.ts b/packages/babel-helper-define-polyfill-provider/src/types.ts new file mode 100644 index 00000000..4bf5a372 --- /dev/null +++ b/packages/babel-helper-define-polyfill-provider/src/types.ts @@ -0,0 +1,106 @@ +import type { NodePath } from "@babel/traverse"; +import * as babel from "@babel/core"; +const { types: t } = babel.default || babel; +import createMetaResolver from "./meta-resolver"; + +type ObjectMap = { [k: string]: T }; + +export type Pattern = string | RegExp; + +export type MissingDependenciesOption = + | false + | { + log?: "per-file" | "deferred"; + inject?: "import" | "throw"; + // When true, log all the polyfills without checking if they are installed + all?: boolean; + }; + +export type ProviderOptions = { + include?: Pattern[]; + exclude?: Pattern[]; +} & Opts; + +export type PluginOptions = { + method: MethodString; + targets?: { browsers: string | string[]; [target: string]: string | number }; + ignoreBrowserslistConfig?: boolean; + configPath?: string; + debug?: boolean; + include?: Pattern[]; + exclude?: Pattern[]; + shouldInjectPolyfill?: (name: string, shouldInject: boolean) => boolean; + missingDependencies?: MissingDependenciesOption; + absoluteImports?: boolean | string; +}; + +export type PolyfillProvider = ( + api: ProviderApi, + options: ProviderOptions, + dirname: string, +) => ProviderResult; + +export type PolyfillProviderInternal = PolyfillProvider; + +export type MethodString = "entry-global" | "usage-global" | "usage-pure"; + +export type Targets = { + [target: string]: string; +}; + +export type ProviderApi = { + babel: any; + method: MethodString; + targets: Targets; + createMetaResolver: typeof createMetaResolver; + getUtils(path: NodePath): Utils; + shouldInjectPolyfill(name: string): boolean; + debug(name: string | null): void; + assertDependency(name: string, version?: string): void; +}; + +export type Utils = { + injectGlobalImport(url: string): void; + injectNamedImport(url: string, name: string, hint?: string): t.Identifier; + injectDefaultImport(url: string, hint?: string): t.Identifier; +}; + +export type ProviderResult = { + name: string; + polyfills?: string[] | { [name: string]: Targets }; + filterPolyfills?: (name: string) => boolean; + entryGlobal?: (meta: MetaDescriptor, utils: Utils, path: NodePath) => void; + usageGlobal?: (meta: MetaDescriptor, utils: Utils, path: NodePath) => void; + usagePure?: (meta: MetaDescriptor, utils: Utils, path: NodePath) => void; + visitor?: any; + pre?: Function; + post?: Function; +}; + +export type MetaDescriptor = + | { kind: "import"; source: string } + | { kind: "global"; name: string } + | { + kind: "property"; + placement: "static" | "prototype" | undefined | null; + object: string | undefined | null; + key: string; + } + | { + kind: "in"; + placement: "static" | "prototype" | undefined | null; + object: string | undefined | null; + key: string; + }; + +export type ResolverPolyfills = { + global?: ObjectMap; + static?: ObjectMap>; + instance?: ObjectMap; +}; + +export type ResolvedPolyfill = { + kind: "global" | "static" | "instance"; + name: string; + desc: T; +}; diff --git a/packages/babel-helper-define-polyfill-provider/src/utils.js b/packages/babel-helper-define-polyfill-provider/src/utils.ts similarity index 98% rename from packages/babel-helper-define-polyfill-provider/src/utils.js rename to packages/babel-helper-define-polyfill-provider/src/utils.ts index 924c6511..c70559d8 100644 --- a/packages/babel-helper-define-polyfill-provider/src/utils.js +++ b/packages/babel-helper-define-polyfill-provider/src/utils.ts @@ -1,5 +1,3 @@ -// @flow - import * as babel from "@babel/core"; const { types: t, template } = babel.default || babel; import type NodePath from "@babel/traverse"; @@ -12,7 +10,7 @@ export function intersection(a: Set, b: Set): Set { return result; } -export function has(object: Object, key: string) { +export function has(object: any, key: string) { return Object.prototype.hasOwnProperty.call(object, key); } diff --git a/packages/babel-helper-define-polyfill-provider/src/visitors/entry.js b/packages/babel-helper-define-polyfill-provider/src/visitors/entry.ts similarity index 98% rename from packages/babel-helper-define-polyfill-provider/src/visitors/entry.js rename to packages/babel-helper-define-polyfill-provider/src/visitors/entry.ts index 831ae111..6aaeda4b 100644 --- a/packages/babel-helper-define-polyfill-provider/src/visitors/entry.js +++ b/packages/babel-helper-define-polyfill-provider/src/visitors/entry.ts @@ -1,5 +1,3 @@ -// @flow - import type { NodePath } from "@babel/traverse"; import type { MetaDescriptor } from "../types"; diff --git a/packages/babel-helper-define-polyfill-provider/src/visitors/index.js b/packages/babel-helper-define-polyfill-provider/src/visitors/index.ts similarity index 89% rename from packages/babel-helper-define-polyfill-provider/src/visitors/index.js rename to packages/babel-helper-define-polyfill-provider/src/visitors/index.ts index c526a4e3..f47d510a 100644 --- a/packages/babel-helper-define-polyfill-provider/src/visitors/index.js +++ b/packages/babel-helper-define-polyfill-provider/src/visitors/index.ts @@ -1,4 +1,2 @@ -// @flow - export { default as usage } from "./usage"; export { default as entry } from "./entry"; diff --git a/packages/babel-helper-define-polyfill-provider/src/visitors/usage.js b/packages/babel-helper-define-polyfill-provider/src/visitors/usage.ts similarity index 99% rename from packages/babel-helper-define-polyfill-provider/src/visitors/usage.js rename to packages/babel-helper-define-polyfill-provider/src/visitors/usage.ts index 17094c30..1b04d7a7 100644 --- a/packages/babel-helper-define-polyfill-provider/src/visitors/usage.js +++ b/packages/babel-helper-define-polyfill-provider/src/visitors/usage.ts @@ -1,5 +1,3 @@ -// @flow - import type { NodePath } from "@babel/traverse"; import type { MetaDescriptor } from "../types"; diff --git a/packages/babel-plugin-polyfill-corejs2/src/add-platform-specific-polyfills.js b/packages/babel-plugin-polyfill-corejs2/src/add-platform-specific-polyfills.ts similarity index 96% rename from packages/babel-plugin-polyfill-corejs2/src/add-platform-specific-polyfills.js rename to packages/babel-plugin-polyfill-corejs2/src/add-platform-specific-polyfills.ts index 10a0d053..f0b2dfdb 100644 --- a/packages/babel-plugin-polyfill-corejs2/src/add-platform-specific-polyfills.js +++ b/packages/babel-plugin-polyfill-corejs2/src/add-platform-specific-polyfills.ts @@ -1,5 +1,3 @@ -// @flow - import type { Targets } from "@babel/helper-define-polyfill-provider"; const webPolyfills = { @@ -14,7 +12,7 @@ const purePolyfills = { "es7.string.at": {}, }; -export default function (targets: Targets, method: string, polyfills: Object) { +export default function (targets: Targets, method: string, polyfills: any) { const targetNames = Object.keys(targets); const isAnyTarget = !targetNames.length; const isWebTarget = targetNames.some(name => name !== "node"); diff --git a/packages/babel-plugin-polyfill-corejs2/src/built-in-definitions.js b/packages/babel-plugin-polyfill-corejs2/src/built-in-definitions.ts similarity index 97% rename from packages/babel-plugin-polyfill-corejs2/src/built-in-definitions.js rename to packages/babel-plugin-polyfill-corejs2/src/built-in-definitions.ts index b8438353..a2f2ec51 100644 --- a/packages/babel-plugin-polyfill-corejs2/src/built-in-definitions.js +++ b/packages/babel-plugin-polyfill-corejs2/src/built-in-definitions.ts @@ -1,25 +1,23 @@ -// @flow - import corejs2Polyfills from "@babel/compat-data/corejs2-built-ins"; type ObjectMap = { [name: string]: V }; type PolyfillDescriptor = { - name: string, - pure: ?string, - global: string[], - meta: ?T, + name: string; + pure: string | undefined | null; + global: string[]; + meta: T | undefined | null; }; type CoreJS2Meta = { - minRuntimeVersion: ?string, + minRuntimeVersion: string | undefined | null; }; const define = ( name: string, - pure: ?string, + pure?: string | null, global: string[] = [], - meta: ?T, + meta?: T | null, ): PolyfillDescriptor => { return { name, pure, global, meta }; }; @@ -27,7 +25,7 @@ const define = ( const pureAndGlobal = ( pure: string, global: string[], - minRuntimeVersion: ?string = null, + minRuntimeVersion: string | undefined | null = null, ) => define(global[0], pure, global, { minRuntimeVersion }); const globalOnly = (global: string[]) => define(global[0], null, global); @@ -142,7 +140,7 @@ if ("es6.array.slice" in corejs2Polyfills) { } export const StaticProperties: ObjectMap< - ObjectMap>, + ObjectMap> > = { Array: { from: pureAndGlobal("array/from", [ diff --git a/packages/babel-plugin-polyfill-corejs2/src/helpers.js b/packages/babel-plugin-polyfill-corejs2/src/helpers.ts similarity index 94% rename from packages/babel-plugin-polyfill-corejs2/src/helpers.js rename to packages/babel-plugin-polyfill-corejs2/src/helpers.ts index 57b96364..001b99b1 100644 --- a/packages/babel-plugin-polyfill-corejs2/src/helpers.js +++ b/packages/babel-plugin-polyfill-corejs2/src/helpers.ts @@ -1,8 +1,8 @@ import semver from "semver"; export function hasMinVersion( - minVersion: ?string, - runtimeVersion: ?(string | number), + minVersion?: string | null, + runtimeVersion?: string | number | null, ) { // If the range is unavailable, we're running the script during Babel's // build process, and we want to assume that all versions are satisfied so diff --git a/packages/babel-plugin-polyfill-corejs2/src/index.js b/packages/babel-plugin-polyfill-corejs2/src/index.ts similarity index 96% rename from packages/babel-plugin-polyfill-corejs2/src/index.js rename to packages/babel-plugin-polyfill-corejs2/src/index.ts index 527baa64..1bfc1dcc 100644 --- a/packages/babel-plugin-polyfill-corejs2/src/index.js +++ b/packages/babel-plugin-polyfill-corejs2/src/index.ts @@ -1,5 +1,3 @@ -// @flow - import corejs2Polyfills from "@babel/compat-data/corejs2-built-ins"; import { BuiltIns, @@ -20,16 +18,16 @@ const runtimeCompat = "#__secret_key__@babel/runtime__compatibility"; // $FlowIgnore const has = Function.call.bind(Object.hasOwnProperty); -type Options = {| +type Options = { "#__secret_key__@babel/preset-env__compatibility": void | { - entryInjectRegenerator: boolean, - }, + entryInjectRegenerator: boolean; + }; "#__secret_key__@babel/runtime__compatibility": void | { - useBabelRuntime: string, - runtimeVersion: string, - ext: string, - }, -|}; + useBabelRuntime: string; + runtimeVersion: string; + ext: string; + }; +}; export default defineProvider(function ( api, diff --git a/packages/babel-plugin-polyfill-corejs3/src/built-in-definitions.js b/packages/babel-plugin-polyfill-corejs3/src/built-in-definitions.ts similarity index 99% rename from packages/babel-plugin-polyfill-corejs3/src/built-in-definitions.js rename to packages/babel-plugin-polyfill-corejs3/src/built-in-definitions.ts index e64977cd..b8e55ee7 100644 --- a/packages/babel-plugin-polyfill-corejs3/src/built-in-definitions.js +++ b/packages/babel-plugin-polyfill-corejs3/src/built-in-definitions.ts @@ -1,15 +1,13 @@ -// @flow - import corejs3Polyfills from "../core-js-compat/data.js"; type ObjectMap = { [name: string]: V }; type ObjectMap2 = ObjectMap>; export type CoreJSPolyfillDescriptor = { - name: string, - pure: ?string, - global: string[], - exclude: ?(string[]), + name: string; + pure: string | undefined | null; + global: string[]; + exclude: string[] | undefined | null; }; const polyfillsOrder = {}; diff --git a/packages/babel-plugin-polyfill-corejs3/src/index.js b/packages/babel-plugin-polyfill-corejs3/src/index.ts similarity index 97% rename from packages/babel-plugin-polyfill-corejs3/src/index.js rename to packages/babel-plugin-polyfill-corejs3/src/index.ts index 6f195632..4a08bfb2 100644 --- a/packages/babel-plugin-polyfill-corejs3/src/index.js +++ b/packages/babel-plugin-polyfill-corejs3/src/index.ts @@ -1,5 +1,3 @@ -// @flow - import corejs3Polyfills from "../core-js-compat/data.js"; import corejs3ShippedProposalsList from "./shipped-proposals"; import getModulesListForTargetVersion from "../core-js-compat/get-modules-list-for-target-version.js"; @@ -27,15 +25,15 @@ import defineProvider from "@babel/helper-define-polyfill-provider"; const runtimeCompat = "#__secret_key__@babel/runtime__compatibility"; -type Options = {| - version?: number | string, - proposals?: boolean, - shippedProposals?: boolean, +type Options = { + version?: number | string; + proposals?: boolean; + shippedProposals?: boolean; "#__secret_key__@babel/runtime__compatibility": void | { - useBabelRuntime: string, - ext: string, - }, -|}; + useBabelRuntime: string; + ext: string; + }; +}; const esnextFallback = ( name: string, @@ -216,7 +214,7 @@ export default defineProvider(function ( if (path.parentPath.isUnaryExpression({ operator: "delete" })) return; - let isCall: ?boolean; + let isCall: boolean | undefined | null; if (meta.kind === "property") { // We can't compile destructuring. diff --git a/packages/babel-plugin-polyfill-corejs3/src/utils.js b/packages/babel-plugin-polyfill-corejs3/src/utils.ts similarity index 94% rename from packages/babel-plugin-polyfill-corejs3/src/utils.js rename to packages/babel-plugin-polyfill-corejs3/src/utils.ts index 34fb590f..0fe52cb8 100644 --- a/packages/babel-plugin-polyfill-corejs3/src/utils.js +++ b/packages/babel-plugin-polyfill-corejs3/src/utils.ts @@ -1,10 +1,8 @@ -// @flow - import * as babel from "@babel/core"; const { types: t } = babel.default || babel; import corejsEntries from "../core-js-compat/entries.js"; -export function callMethod(path: *, id: t.Identifier) { +export function callMethod(path: any, id: t.Identifier) { const { object } = path.node; let context1, context2; diff --git a/packages/babel-plugin-polyfill-corejs3/test/check-builtin-definitions.test.js b/packages/babel-plugin-polyfill-corejs3/test/check-builtin-definitions.test.js index e3ec6a49..ba7cdcac 100644 --- a/packages/babel-plugin-polyfill-corejs3/test/check-builtin-definitions.test.js +++ b/packages/babel-plugin-polyfill-corejs3/test/check-builtin-definitions.test.js @@ -4,7 +4,7 @@ import { BuiltIns, StaticProperties, InstanceProperties, -} from "../src/built-in-definitions.js"; +} from "../src/built-in-definitions"; const supportedCorejs3Modules = new Set(); diff --git a/packages/babel-plugin-polyfill-es-shims/src/index.js b/packages/babel-plugin-polyfill-es-shims/src/index.ts similarity index 94% rename from packages/babel-plugin-polyfill-es-shims/src/index.js rename to packages/babel-plugin-polyfill-es-shims/src/index.ts index 2caf17d2..57252c79 100644 --- a/packages/babel-plugin-polyfill-es-shims/src/index.js +++ b/packages/babel-plugin-polyfill-es-shims/src/index.ts @@ -1,5 +1,3 @@ -// @flow - import defineProvider, { type Utils, type MetaDescriptor, @@ -14,7 +12,7 @@ import { InstanceProperties, } from "./mappings"; -export default defineProvider<{||}>(function ({ +export default defineProvider<{}>(function ({ shouldInjectPolyfill, assertDependency, createMetaResolver, @@ -30,8 +28,13 @@ export default defineProvider<{||}>(function ({ }); function createDescIterator( - cb: (Descriptor, Utils, Object) => void, - instance?: (MetaDescriptor, *, Utils, Object) => void, + cb: (desc: Descriptor, utils: Utils, path: any) => void, + instance?: ( + meta: MetaDescriptor, + resolved: any, + utils: Utils, + path: any, + ) => void, ) { return (meta, utils, path) => { if (path.parentPath.isUnaryExpression({ operator: "delete" })) return; @@ -91,7 +94,7 @@ export default defineProvider<{||}>(function ({ const isGetter = resolved.desc[0].getter; const matchesPolyfill = ({ name }) => - name.startsWith(((meta.object: any): string)); + name.startsWith(meta.object as any as string); let index = -1; if ( diff --git a/packages/babel-plugin-polyfill-es-shims/src/mappings.js b/packages/babel-plugin-polyfill-es-shims/src/mappings.ts similarity index 93% rename from packages/babel-plugin-polyfill-es-shims/src/mappings.js rename to packages/babel-plugin-polyfill-es-shims/src/mappings.ts index 9599f61a..948ef798 100644 --- a/packages/babel-plugin-polyfill-es-shims/src/mappings.js +++ b/packages/babel-plugin-polyfill-es-shims/src/mappings.ts @@ -1,5 +1,3 @@ -// @flow - import * as babel from "@babel/core"; const { types: t, template } = babel.default || babel; @@ -11,15 +9,15 @@ const expr = template.expression.ast; const has = Function.call.bind(Object.hasOwnProperty); export type Descriptor = { - name: string, - version: string, - package: string, - path: string, // This is different from .package for multi-entry-point packages - pure?: false, - global?: false, - thisCheck?: (thisObj: Object) => Object, - exclude?: (meta: MetaDescriptor) => boolean, - getter?: true, + name: string; + version: string; + package: string; + path: string; // This is different from .package for multi-entry-point packages, + pure?: false; + global?: false; + thisCheck?: (thisObj: any) => any; + exclude?: (meta: MetaDescriptor) => boolean; + getter?: true; }; export const Globals = {}; @@ -194,10 +192,10 @@ function defineInstance( pkg, subfolder, }: { - getter?: boolean, - exclude?: (meta: MetaDescriptor) => boolean, - pkg?: string, - subfolder?: string, + getter?: boolean; + exclude?: (meta: MetaDescriptor) => boolean; + pkg?: string; + subfolder?: string; } = {}, ) { if (!has(InstanceProperties, property)) InstanceProperties[property] = []; diff --git a/packages/babel-plugin-polyfill-regenerator/src/index.js b/packages/babel-plugin-polyfill-regenerator/src/index.ts similarity index 98% rename from packages/babel-plugin-polyfill-regenerator/src/index.js rename to packages/babel-plugin-polyfill-regenerator/src/index.ts index 47250364..3eb3fc10 100644 --- a/packages/babel-plugin-polyfill-regenerator/src/index.js +++ b/packages/babel-plugin-polyfill-regenerator/src/index.ts @@ -1,5 +1,3 @@ -// @flow - import defineProvider from "@babel/helper-define-polyfill-provider"; const runtimeCompat = "#__secret_key__@babel/runtime__compatibility"; From a7093b6149fcfa368f2deb4f4ce363ddc9666bb8 Mon Sep 17 00:00:00 2001 From: Anton Gilgur Date: Sat, 26 Mar 2022 13:51:16 -0400 Subject: [PATCH 05/13] fix(types): manually remediate several type errors post-conversion went from 453 type errors at the beginning to only 40 type errors now! - some missing types: - missing generics in a few places, particulary with Sets - e.g. `Set` - missing optional parameters in a few places - e.g. `subfolder?` - missing default values in some initializers - e.g. `{ useBabelRuntime = "" }` - some small fixes: - add `| typeof presetEnvSilentDebugHeader` to fix debug checks - add `"object" in meta` check to `usageGlobal` funcs to narrow type before assuming `meta.object` exists - one NodePath type import was incorrect / different from the rest - one `hasOwnProperty` was called as a global func instead of on `Object` or `Object.prototype` - remove `babel.default || babel` imports - tsconfig `esModuleInterop` should handle this --- .../src/imports-cache.ts | 3 +-- .../src/index.ts | 2 +- .../src/node/dependencies.ts | 4 ++-- .../src/types.ts | 5 ++--- .../src/utils.ts | 7 +++---- .../src/built-in-definitions.ts | 3 ++- packages/babel-plugin-polyfill-corejs2/src/index.ts | 13 +++++++++---- .../src/built-in-definitions.ts | 2 +- packages/babel-plugin-polyfill-corejs3/src/index.ts | 8 ++++---- packages/babel-plugin-polyfill-corejs3/src/utils.ts | 8 +++++--- .../babel-plugin-polyfill-es-shims/src/mappings.ts | 10 ++++------ .../babel-plugin-polyfill-regenerator/src/index.ts | 3 ++- 12 files changed, 36 insertions(+), 32 deletions(-) diff --git a/packages/babel-helper-define-polyfill-provider/src/imports-cache.ts b/packages/babel-helper-define-polyfill-provider/src/imports-cache.ts index 6779eb34..1a20fb38 100644 --- a/packages/babel-helper-define-polyfill-provider/src/imports-cache.ts +++ b/packages/babel-helper-define-polyfill-provider/src/imports-cache.ts @@ -1,6 +1,5 @@ import type { NodePath } from "@babel/traverse"; -import * as babel from "@babel/core"; -const { types: t } = babel.default || babel; +import { types as t } from "@babel/core"; type StrMap = Map; diff --git a/packages/babel-helper-define-polyfill-provider/src/index.ts b/packages/babel-helper-define-polyfill-provider/src/index.ts index 68590c3d..e8cb7667 100644 --- a/packages/babel-helper-define-polyfill-provider/src/index.ts +++ b/packages/babel-helper-define-polyfill-provider/src/index.ts @@ -42,7 +42,7 @@ function resolveOptions( method: MethodString; methodName: "usageGlobal" | "entryGlobal" | "usagePure"; targets: Targets; - debug: boolean; + debug: boolean | typeof presetEnvSilentDebugHeader; shouldInjectPolyfill: | ((name: string, shouldInject: boolean) => boolean) | undefined diff --git a/packages/babel-helper-define-polyfill-provider/src/node/dependencies.ts b/packages/babel-helper-define-polyfill-provider/src/node/dependencies.ts index adf212b1..c09136d5 100644 --- a/packages/babel-helper-define-polyfill-provider/src/node/dependencies.ts +++ b/packages/babel-helper-define-polyfill-provider/src/node/dependencies.ts @@ -72,11 +72,11 @@ export function logMissing(missingDeps: Set) { process.exitCode = 1; } -let allMissingDeps = new Set(); +let allMissingDeps = new Set(); const laterLogMissingDependencies = debounce(() => { logMissing(allMissingDeps); - allMissingDeps = new Set(); + allMissingDeps = new Set(); }, 100); export function laterLogMissing(missingDeps: Set) { diff --git a/packages/babel-helper-define-polyfill-provider/src/types.ts b/packages/babel-helper-define-polyfill-provider/src/types.ts index 4bf5a372..64c5afb8 100644 --- a/packages/babel-helper-define-polyfill-provider/src/types.ts +++ b/packages/babel-helper-define-polyfill-provider/src/types.ts @@ -1,6 +1,5 @@ import type { NodePath } from "@babel/traverse"; -import * as babel from "@babel/core"; -const { types: t } = babel.default || babel; +import { types as t } from "@babel/core"; import createMetaResolver from "./meta-resolver"; type ObjectMap = { [k: string]: T }; @@ -40,7 +39,7 @@ export type PolyfillProvider = ( dirname: string, ) => ProviderResult; -export type PolyfillProviderInternal = PolyfillProvider; +export type PolyfillProviderInternal = PolyfillProvider; export type MethodString = "entry-global" | "usage-global" | "usage-pure"; diff --git a/packages/babel-helper-define-polyfill-provider/src/utils.ts b/packages/babel-helper-define-polyfill-provider/src/utils.ts index c70559d8..d45ff030 100644 --- a/packages/babel-helper-define-polyfill-provider/src/utils.ts +++ b/packages/babel-helper-define-polyfill-provider/src/utils.ts @@ -1,11 +1,10 @@ -import * as babel from "@babel/core"; -const { types: t, template } = babel.default || babel; -import type NodePath from "@babel/traverse"; +import { types as t, template } from "@babel/core"; +import type { NodePath } from "@babel/traverse"; import type { Utils } from "./types"; import type ImportsCache from "./imports-cache"; export function intersection(a: Set, b: Set): Set { - const result = new Set(); + const result = new Set(); a.forEach(v => b.has(v) && result.add(v)); return result; } diff --git a/packages/babel-plugin-polyfill-corejs2/src/built-in-definitions.ts b/packages/babel-plugin-polyfill-corejs2/src/built-in-definitions.ts index a2f2ec51..66d19bbb 100644 --- a/packages/babel-plugin-polyfill-corejs2/src/built-in-definitions.ts +++ b/packages/babel-plugin-polyfill-corejs2/src/built-in-definitions.ts @@ -28,7 +28,8 @@ const pureAndGlobal = ( minRuntimeVersion: string | undefined | null = null, ) => define(global[0], pure, global, { minRuntimeVersion }); -const globalOnly = (global: string[]) => define(global[0], null, global); +const globalOnly = (global: string[]) => + define(global[0], null, global); const pureOnly = (pure: string, name: string) => define(name, pure, []); diff --git a/packages/babel-plugin-polyfill-corejs2/src/index.ts b/packages/babel-plugin-polyfill-corejs2/src/index.ts index 1bfc1dcc..3ad29db6 100644 --- a/packages/babel-plugin-polyfill-corejs2/src/index.ts +++ b/packages/babel-plugin-polyfill-corejs2/src/index.ts @@ -9,8 +9,7 @@ import addPlatformSpecificPolyfills from "./add-platform-specific-polyfills"; import { hasMinVersion } from "./helpers"; import defineProvider from "@babel/helper-define-polyfill-provider"; -import * as babel from "@babel/core"; -const { types: t } = babel.default || babel; +import { types as t } from "@babel/core"; const presetEnvCompat = "#__secret_key__@babel/preset-env__compatibility"; const runtimeCompat = "#__secret_key__@babel/runtime__compatibility"; @@ -32,8 +31,13 @@ type Options = { export default defineProvider(function ( api, { - [presetEnvCompat]: { entryInjectRegenerator } = {}, - [runtimeCompat]: { useBabelRuntime, runtimeVersion, ext = ".js" } = {}, + [presetEnvCompat]: { entryInjectRegenerator } = { + entryInjectRegenerator: false, + }, + [runtimeCompat]: { useBabelRuntime, runtimeVersion, ext = ".js" } = { + useBabelRuntime: "", + runtimeVersion: "", + }, }, ) { const resolve = api.createMetaResolver({ @@ -114,6 +118,7 @@ export default defineProvider(function ( if ( resolved.kind !== "global" && + "object" in meta && meta.object && meta.placement === "prototype" ) { diff --git a/packages/babel-plugin-polyfill-corejs3/src/built-in-definitions.ts b/packages/babel-plugin-polyfill-corejs3/src/built-in-definitions.ts index b8e55ee7..995e9f2c 100644 --- a/packages/babel-plugin-polyfill-corejs3/src/built-in-definitions.ts +++ b/packages/babel-plugin-polyfill-corejs3/src/built-in-definitions.ts @@ -19,7 +19,7 @@ const define = ( pure, global, name = global[0], - exclude, + exclude?, ): CoreJSPolyfillDescriptor => { return { name, diff --git a/packages/babel-plugin-polyfill-corejs3/src/index.ts b/packages/babel-plugin-polyfill-corejs3/src/index.ts index 4a08bfb2..73b61a58 100644 --- a/packages/babel-plugin-polyfill-corejs3/src/index.ts +++ b/packages/babel-plugin-polyfill-corejs3/src/index.ts @@ -12,8 +12,7 @@ import { type CoreJSPolyfillDescriptor, } from "./built-in-definitions"; -import * as babel from "@babel/core"; -const { types: t } = babel.default || babel; +import { types as t } from "@babel/core"; import { callMethod, coreJSModule, @@ -52,7 +51,7 @@ export default defineProvider(function ( version = 3, proposals, shippedProposals, - [runtimeCompat]: { useBabelRuntime, ext = ".js" } = {}, + [runtimeCompat]: { useBabelRuntime, ext = ".js" } = { useBabelRuntime: "" }, }, ) { const isWebpack = babel.caller(caller => caller?.name === "babel-loader"); @@ -98,7 +97,7 @@ export default defineProvider(function ( desc: CoreJSPolyfillDescriptor, hint, utils, - object, + object?, ) { if ( desc.pure && @@ -184,6 +183,7 @@ export default defineProvider(function ( if ( resolved.kind !== "global" && + "object" in meta && meta.object && meta.placement === "prototype" ) { diff --git a/packages/babel-plugin-polyfill-corejs3/src/utils.ts b/packages/babel-plugin-polyfill-corejs3/src/utils.ts index 0fe52cb8..dc3ec068 100644 --- a/packages/babel-plugin-polyfill-corejs3/src/utils.ts +++ b/packages/babel-plugin-polyfill-corejs3/src/utils.ts @@ -1,5 +1,4 @@ -import * as babel from "@babel/core"; -const { types: t } = babel.default || babel; +import { types as t } from "@babel/core"; import corejsEntries from "../core-js-compat/entries.js"; export function callMethod(path: any, id: t.Identifier) { @@ -29,7 +28,10 @@ export function isCoreJSSource(source: string) { .toLowerCase(); } - return hasOwnProperty.call(corejsEntries, source) && corejsEntries[source]; + return ( + Object.prototype.hasOwnProperty.call(corejsEntries, source) && + corejsEntries[source] + ); } export function coreJSModule(name: string) { diff --git a/packages/babel-plugin-polyfill-es-shims/src/mappings.ts b/packages/babel-plugin-polyfill-es-shims/src/mappings.ts index 948ef798..6f029e87 100644 --- a/packages/babel-plugin-polyfill-es-shims/src/mappings.ts +++ b/packages/babel-plugin-polyfill-es-shims/src/mappings.ts @@ -1,6 +1,4 @@ -import * as babel from "@babel/core"; -const { types: t, template } = babel.default || babel; - +import { types as t, template } from "@babel/core"; import type { MetaDescriptor } from "@babel/helper-define-polyfill-provider"; const expr = template.expression.ast; @@ -160,7 +158,7 @@ for (const name of [ }); } -function createDescriptor(name, version, pkg = name.toLowerCase(), subfolder) { +function createDescriptor(name, version, pkg = name.toLowerCase(), subfolder?) { return { name, version, @@ -169,11 +167,11 @@ function createDescriptor(name, version, pkg = name.toLowerCase(), subfolder) { }; } -function defineGlobal(name, version, pkg) { +function defineGlobal(name, version, pkg?) { Globals[name] = [createDescriptor(name, version, pkg)]; } -function defineStatic(object, property, version, pkg) { +function defineStatic(object, property, version, pkg?) { if (!has(StaticProperties, object)) StaticProperties[object] = {}; StaticProperties[object][property] = [ diff --git a/packages/babel-plugin-polyfill-regenerator/src/index.ts b/packages/babel-plugin-polyfill-regenerator/src/index.ts index 3eb3fc10..a612246a 100644 --- a/packages/babel-plugin-polyfill-regenerator/src/index.ts +++ b/packages/babel-plugin-polyfill-regenerator/src/index.ts @@ -3,7 +3,8 @@ import defineProvider from "@babel/helper-define-polyfill-provider"; const runtimeCompat = "#__secret_key__@babel/runtime__compatibility"; export default defineProvider(({ debug }, options) => { - const { [runtimeCompat]: { useBabelRuntime } = {} } = options; + const { [runtimeCompat]: { useBabelRuntime } = { useBabelRuntime: "" } } = + options; const pureName = useBabelRuntime ? `${useBabelRuntime}/regenerator` From dfc0f2b2bbcb5912dfac5c1a021eee69d80db0d9 Mon Sep 17 00:00:00 2001 From: Anton Gilgur Date: Sat, 26 Mar 2022 22:43:57 -0400 Subject: [PATCH 06/13] refactor(types): remove or replace $FlowIgnore with @ts-expect-error MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - in most places, there was no type error, so just removed the `// $FlowIgnore` comment - in 2 places, there was a type error, so replace with a `// @ts-expect-error` comment instead - this could be removed with some type narrowing checks instead, but this is a more direct conversion - and requested by Nicolò - 38 type errors remaining --- packages/babel-helper-define-polyfill-provider/src/index.ts | 3 --- .../src/node/dependencies.ts | 3 --- packages/babel-plugin-polyfill-corejs2/src/index.ts | 1 - packages/babel-plugin-polyfill-corejs3/src/index.ts | 5 ++--- packages/babel-plugin-polyfill-es-shims/src/index.ts | 2 -- packages/babel-plugin-polyfill-es-shims/src/mappings.ts | 1 - 6 files changed, 2 insertions(+), 13 deletions(-) diff --git a/packages/babel-helper-define-polyfill-provider/src/index.ts b/packages/babel-helper-define-polyfill-provider/src/index.ts index e8cb7667..00fcc417 100644 --- a/packages/babel-helper-define-polyfill-provider/src/index.ts +++ b/packages/babel-helper-define-polyfill-provider/src/index.ts @@ -283,7 +283,6 @@ function instantiateProvider( provider, callProvider(payload: MetaDescriptor, path: NodePath) { const utils = getUtils(path); - // $FlowIgnore provider[methodName](payload, utils, path); }, }; @@ -337,11 +336,9 @@ export default function definePolyfillProvider( missingDeps: new Set(), }; - // $FlowIgnore - Flow doesn't support optional calls provider.pre?.apply(this, arguments); }, post() { - // $FlowIgnore - Flow doesn't support optional calls provider.post?.apply(this, arguments); if (missingDependencies !== false) { diff --git a/packages/babel-helper-define-polyfill-provider/src/node/dependencies.ts b/packages/babel-helper-define-polyfill-provider/src/node/dependencies.ts index c09136d5..db3a9756 100644 --- a/packages/babel-helper-define-polyfill-provider/src/node/dependencies.ts +++ b/packages/babel-helper-define-polyfill-provider/src/node/dependencies.ts @@ -4,9 +4,7 @@ import requireResolve from "resolve"; const nativeRequireResolve = parseFloat(process.versions.node) >= 8.9; -// $FlowIgnore import { createRequire } from "module"; -// $FlowIgnore const require = createRequire(import/*::(_)*/.meta.url); // eslint-disable-line export function resolve( @@ -32,7 +30,6 @@ export function resolve( } catch (err) { if (err.code !== "MODULE_NOT_FOUND") throw err; - // $FlowIgnore throw Object.assign( new Error(`Failed to resolve "${moduleName}" relative to "${dirname}"`), { diff --git a/packages/babel-plugin-polyfill-corejs2/src/index.ts b/packages/babel-plugin-polyfill-corejs2/src/index.ts index 3ad29db6..c163bef7 100644 --- a/packages/babel-plugin-polyfill-corejs2/src/index.ts +++ b/packages/babel-plugin-polyfill-corejs2/src/index.ts @@ -14,7 +14,6 @@ import { types as t } from "@babel/core"; const presetEnvCompat = "#__secret_key__@babel/preset-env__compatibility"; const runtimeCompat = "#__secret_key__@babel/runtime__compatibility"; -// $FlowIgnore const has = Function.call.bind(Object.hasOwnProperty); type Options = { diff --git a/packages/babel-plugin-polyfill-corejs3/src/index.ts b/packages/babel-plugin-polyfill-corejs3/src/index.ts index 73b61a58..b47e6190 100644 --- a/packages/babel-plugin-polyfill-corejs3/src/index.ts +++ b/packages/babel-plugin-polyfill-corejs3/src/index.ts @@ -113,7 +113,6 @@ export default defineProvider(function ( } const coreJSPureBase = getCoreJSPureBase(useProposalBase); return utils.injectDefaultImport( - // $FlowIgnore, we already guard desc.pure `${coreJSPureBase}/${desc.pure}${ext}`, hint, ); @@ -289,7 +288,7 @@ export default defineProvider(function ( resolved.desc, resolved.name, utils, - // $FlowIgnore + // @ts-expect-error meta.object, ); if (id) path.replaceWith(id); @@ -298,7 +297,7 @@ export default defineProvider(function ( resolved.desc, `${resolved.name}InstanceProperty`, utils, - // $FlowIgnore + // @ts-expect-error meta.object, ); if (!id) return; diff --git a/packages/babel-plugin-polyfill-es-shims/src/index.ts b/packages/babel-plugin-polyfill-es-shims/src/index.ts index 57252c79..b21d4631 100644 --- a/packages/babel-plugin-polyfill-es-shims/src/index.ts +++ b/packages/babel-plugin-polyfill-es-shims/src/index.ts @@ -48,7 +48,6 @@ export default defineProvider<{}>(function ({ } for (const desc of resolved.desc) { - // $FlowIgnore if (!desc.exclude?.(meta) && shouldInjectPolyfill(desc.name)) { cb(desc, utils, path); } @@ -136,7 +135,6 @@ export default defineProvider<{}>(function ({ const { thisCheck } = desc; if ( !thisCheck || - // $FlowIgnore desc.exclude?.(meta) || !shouldInjectPolyfill(desc.name) ) { diff --git a/packages/babel-plugin-polyfill-es-shims/src/mappings.ts b/packages/babel-plugin-polyfill-es-shims/src/mappings.ts index 6f029e87..a039eeef 100644 --- a/packages/babel-plugin-polyfill-es-shims/src/mappings.ts +++ b/packages/babel-plugin-polyfill-es-shims/src/mappings.ts @@ -3,7 +3,6 @@ import type { MetaDescriptor } from "@babel/helper-define-polyfill-provider"; const expr = template.expression.ast; -// $FlowIgnore const has = Function.call.bind(Object.hasOwnProperty); export type Descriptor = { From ec73a5166543e3f1b79bf23f26e2157faa7e1bef Mon Sep 17 00:00:00 2001 From: Anton Gilgur Date: Mon, 28 Mar 2022 14:55:53 -0400 Subject: [PATCH 07/13] fix(types): refine non-trivial types to remediate remaining type errors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - deps: add `@types/babel__traverse` for more accurate typings - Babel 8 will produce its own typings - this was already a transitive dep, so adding it just updated it to a newer (and more accurate) version - some complicated generics refined: - missing `Options` in regenerator's `defineProvider` call - many missing generics for various `NodePath` args - thanks to Nicolò for help with some of these, I didn't know where to even start with these - had to switch up some `isXXX()` conditionals and surroundings to narrow the right type - unfortunately the type narrowing doesn't work on every property :/ - add a `@ts-expect-error` where proper type resolution was not possible with the current Babel types - use casts where TS was not able to narrow the type all the way - add some typings here and there as I went --- package.json | 1 + .../src/imports-cache.ts | 47 ++++++++++++------- .../src/types.ts | 5 +- .../src/utils.ts | 41 ++++++++++------ .../src/visitors/entry.ts | 5 +- .../src/visitors/usage.ts | 15 +++--- .../src/index.ts | 11 +++-- .../src/index.ts | 25 +++++----- .../src/index.ts | 5 +- .../src/index.ts | 8 +++- yarn.lock | 9 ++-- 11 files changed, 108 insertions(+), 64 deletions(-) diff --git a/package.json b/package.json index d94e64d0..da94717b 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,7 @@ "@rollup/plugin-babel": "^5.3.0", "@rollup/plugin-json": "^4.1.0", "@rollup/plugin-node-resolve": "^11.2.0", + "@types/babel__traverse": "^7.14.2", "@typescript-eslint/eslint-plugin": "^5.16.0", "@typescript-eslint/parser": "^5.16.0", "babel-jest": "^24.8.0", diff --git a/packages/babel-helper-define-polyfill-provider/src/imports-cache.ts b/packages/babel-helper-define-polyfill-provider/src/imports-cache.ts index 1a20fb38..b44c655f 100644 --- a/packages/babel-helper-define-polyfill-provider/src/imports-cache.ts +++ b/packages/babel-helper-define-polyfill-provider/src/imports-cache.ts @@ -4,9 +4,9 @@ import { types as t } from "@babel/core"; type StrMap = Map; export default class ImportsCache { - _imports: WeakMap>; - _anonymousImports: WeakMap>; - _lastImports: WeakMap; + _imports: WeakMap, StrMap>; + _anonymousImports: WeakMap, Set>; + _lastImports: WeakMap, NodePath>; _resolver: (url: string) => string; constructor(resolver: (url: string) => string) { @@ -17,13 +17,17 @@ export default class ImportsCache { } storeAnonymous( - programPath: NodePath, + programPath: NodePath, url: string, // eslint-disable-next-line no-undef getVal: (isScript: boolean, source: t.StringLiteral) => t.Node, ) { const key = this._normalizeKey(programPath, url); - const imports = this._ensure(this._anonymousImports, programPath, Set); + const imports = this._ensure>( + this._anonymousImports, + programPath, + Set, + ); if (imports.has(key)) return; @@ -36,7 +40,7 @@ export default class ImportsCache { } storeNamed( - programPath: NodePath, + programPath: NodePath, url: string, name: string, getVal: ( @@ -48,7 +52,11 @@ export default class ImportsCache { ) => { node: t.Node; name: string }, ) { const key = this._normalizeKey(programPath, url, name); - const imports = this._ensure(this._imports, programPath, Map); + const imports = this._ensure>( + this._imports, + programPath, + Map, + ); if (!imports.has(key)) { const { node, name: id } = getVal( @@ -63,8 +71,9 @@ export default class ImportsCache { return t.identifier(imports.get(key)); } - _injectImport(programPath: NodePath, node: t.Node) { - let lastImport = this._lastImports.get(programPath); + _injectImport(programPath: NodePath, node: t.Node) { + const lastImport = this._lastImports.get(programPath); + let newNodes: [NodePath]; if ( lastImport && lastImport.node && @@ -73,12 +82,12 @@ export default class ImportsCache { lastImport.parent === programPath.node && lastImport.container === programPath.node.body ) { - lastImport = lastImport.insertAfter(node); + newNodes = lastImport.insertAfter(node); } else { - lastImport = programPath.unshiftContainer("body", node); + newNodes = programPath.unshiftContainer("body", node); } - lastImport = lastImport[lastImport.length - 1]; - this._lastImports.set(programPath, lastImport); + const newNode = newNodes[newNodes.length - 1]; + this._lastImports.set(programPath, newNode); /* let lastImport; @@ -103,9 +112,9 @@ export default class ImportsCache { });*/ } - _ensure | Set>( - map: WeakMap, - programPath: NodePath, + _ensure | Set>( + map: WeakMap, C>, + programPath: NodePath, Collection: { new (...args: any): C }, ): C { let collection = map.get(programPath); @@ -116,7 +125,11 @@ export default class ImportsCache { return collection; } - _normalizeKey(programPath: NodePath, url: string, name: string = ""): string { + _normalizeKey( + programPath: NodePath, + url: string, + name: string = "", + ): string { const { sourceType } = programPath.node; // If we rely on the imported binding (the "name" parameter), we also need to cache diff --git a/packages/babel-helper-define-polyfill-provider/src/types.ts b/packages/babel-helper-define-polyfill-provider/src/types.ts index 64c5afb8..52d61664 100644 --- a/packages/babel-helper-define-polyfill-provider/src/types.ts +++ b/packages/babel-helper-define-polyfill-provider/src/types.ts @@ -22,7 +22,10 @@ export type ProviderOptions = { export type PluginOptions = { method: MethodString; - targets?: { browsers: string | string[]; [target: string]: string | number }; + targets?: { + browsers: string | string[]; + [target: string]: string | string[] | number; + }; ignoreBrowserslistConfig?: boolean; configPath?: string; debug?: boolean; diff --git a/packages/babel-helper-define-polyfill-provider/src/utils.ts b/packages/babel-helper-define-polyfill-provider/src/utils.ts index d45ff030..a043b037 100644 --- a/packages/babel-helper-define-polyfill-provider/src/utils.ts +++ b/packages/babel-helper-define-polyfill-provider/src/utils.ts @@ -17,7 +17,7 @@ function getType(target: any): string { return Object.prototype.toString.call(target).slice(8, -1); } -function resolveId(path) { +function resolveId(path): string { if ( path.isIdentifier() && !path.scope.hasBinding(path.node.name, /* noGlobals */ true) @@ -31,12 +31,19 @@ function resolveId(path) { } } -export function resolveKey(path: NodePath, computed: boolean = false) { - const { node, parent, scope } = path; - if (path.isStringLiteral()) return node.value; - const { name } = node; +export function resolveKey( + path: NodePath, + computed: boolean = false, +) { + const { scope } = path; + if (path.isStringLiteral()) return path.node.value; const isIdentifier = path.isIdentifier(); - if (isIdentifier && !(computed || parent.computed)) return name; + if ( + isIdentifier && + !(computed || (path.parent as t.MemberExpression).computed) + ) { + return path.node.name; + } if ( computed && @@ -48,13 +55,16 @@ export function resolveKey(path: NodePath, computed: boolean = false) { if (sym) return "Symbol." + sym; } - if (!isIdentifier || scope.hasBinding(name, /* noGlobals */ true)) { + if (!isIdentifier || scope.hasBinding(path.node.name, /* noGlobals */ true)) { const { value } = path.evaluate(); if (typeof value === "string") return value; } } -export function resolveSource(obj: NodePath) { +export function resolveSource(obj: NodePath): { + id: string; + placement: "prototype" | "static"; +} { if ( obj.isMemberExpression() && obj.get("property").isIdentifier({ name: "prototype" }) @@ -84,30 +94,33 @@ export function resolveSource(obj: NodePath) { return { id: null, placement: null }; } -export function getImportSource({ node }: NodePath) { +export function getImportSource({ node }: NodePath) { if (node.specifiers.length === 0) return node.source.value; } -export function getRequireSource({ node }: NodePath) { +export function getRequireSource({ node }: NodePath) { if (!t.isExpressionStatement(node)) return; const { expression } = node; - const isRequire = + if ( t.isCallExpression(expression) && t.isIdentifier(expression.callee) && expression.callee.name === "require" && expression.arguments.length === 1 && - t.isStringLiteral(expression.arguments[0]); - if (isRequire) return expression.arguments[0].value; + t.isStringLiteral(expression.arguments[0]) + ) { + return expression.arguments[0].value; + } } function hoist(node: t.Node) { + // @ts-expect-error node._blockHoist = 3; return node; } export function createUtilsGetter(cache: ImportsCache) { return (path: NodePath): Utils => { - const prog = path.findParent(p => p.isProgram()); + const prog = path.findParent(p => p.isProgram()) as NodePath; return { injectGlobalImport(url) { diff --git a/packages/babel-helper-define-polyfill-provider/src/visitors/entry.ts b/packages/babel-helper-define-polyfill-provider/src/visitors/entry.ts index 6aaeda4b..86292fc8 100644 --- a/packages/babel-helper-define-polyfill-provider/src/visitors/entry.ts +++ b/packages/babel-helper-define-polyfill-provider/src/visitors/entry.ts @@ -1,4 +1,5 @@ import type { NodePath } from "@babel/traverse"; +import { types as t } from "@babel/core"; import type { MetaDescriptor } from "../types"; import { getImportSource, getRequireSource } from "../utils"; @@ -6,12 +7,12 @@ import { getImportSource, getRequireSource } from "../utils"; export default ( callProvider: (payload: MetaDescriptor, path: NodePath) => void, ) => ({ - ImportDeclaration(path: NodePath) { + ImportDeclaration(path: NodePath) { const source = getImportSource(path); if (!source) return; callProvider({ kind: "import", source }, path); }, - Program(path: NodePath) { + Program(path: NodePath) { path.get("body").forEach(bodyPath => { const source = getRequireSource(bodyPath); if (!source) return; diff --git a/packages/babel-helper-define-polyfill-provider/src/visitors/usage.ts b/packages/babel-helper-define-polyfill-provider/src/visitors/usage.ts index 1b04d7a7..8724565c 100644 --- a/packages/babel-helper-define-polyfill-provider/src/visitors/usage.ts +++ b/packages/babel-helper-define-polyfill-provider/src/visitors/usage.ts @@ -1,4 +1,5 @@ import type { NodePath } from "@babel/traverse"; +import { types as t } from "@babel/core"; import type { MetaDescriptor } from "../types"; import { resolveKey, resolveSource } from "../utils"; @@ -12,7 +13,7 @@ export default ( return { // Symbol(), new Promise - ReferencedIdentifier(path: NodePath) { + ReferencedIdentifier(path: NodePath) { const { node: { name }, scope, @@ -22,19 +23,21 @@ export default ( callProvider({ kind: "global", name }, path); }, - MemberExpression(path: NodePath) { + MemberExpression(path: NodePath) { const key = resolveKey(path.get("property"), path.node.computed); if (!key || key === "prototype") return; const object = path.get("object"); - const binding = object.scope.getBinding(object.node.name); - if (binding && binding.path.isImportNamespaceSpecifier()) return; + if (object.isIdentifier()) { + const binding = object.scope.getBinding(object.node.name); + if (binding && binding.path.isImportNamespaceSpecifier()) return; + } const source = resolveSource(object); return property(source.id, key, source.placement, path); }, - ObjectPattern(path: NodePath) { + ObjectPattern(path: NodePath) { const { parentPath, parent } = path; let obj; @@ -67,7 +70,7 @@ export default ( } }, - BinaryExpression(path: NodePath) { + BinaryExpression(path: NodePath) { if (path.node.operator !== "in") return; const source = resolveSource(path.get("right")); diff --git a/packages/babel-plugin-polyfill-corejs2/src/index.ts b/packages/babel-plugin-polyfill-corejs2/src/index.ts index c163bef7..2a25c15a 100644 --- a/packages/babel-plugin-polyfill-corejs2/src/index.ts +++ b/packages/babel-plugin-polyfill-corejs2/src/index.ts @@ -9,6 +9,7 @@ import addPlatformSpecificPolyfills from "./add-platform-specific-polyfills"; import { hasMinVersion } from "./helpers"; import defineProvider from "@babel/helper-define-polyfill-provider"; +import type { NodePath } from "@babel/traverse"; import { types as t } from "@babel/core"; const presetEnvCompat = "#__secret_key__@babel/preset-env__compatibility"; @@ -137,7 +138,7 @@ export default defineProvider(function ( `${coreJSBase}/is-iterable${ext}`, "isIterable", ), - [path.node.right], + [(path.node as t.BinaryExpression).right], // meta.kind === "in" narrows this ), ); } @@ -156,7 +157,7 @@ export default defineProvider(function ( meta.key === "Symbol.iterator" && shouldInjectPolyfill("es6.symbol") && path.parentPath.isCallExpression({ callee: path.node }) && - path.parent.arguments.length === 0 + path.parentPath.node.arguments.length === 0 ) { path.parentPath.replaceWith( t.callExpression( @@ -182,14 +183,16 @@ export default defineProvider(function ( visitor: method === "usage-global" && { // yield* - YieldExpression(path) { + YieldExpression(path: NodePath) { if (path.node.delegate) { inject("web.dom.iterable", api.getUtils(path)); } }, // for-of, [a, b] = c - "ForOfStatement|ArrayPattern"(path) { + "ForOfStatement|ArrayPattern"( + path: NodePath, + ) { CommonIterators.forEach(name => inject(name, api.getUtils(path))); }, }, diff --git a/packages/babel-plugin-polyfill-corejs3/src/index.ts b/packages/babel-plugin-polyfill-corejs3/src/index.ts index b47e6190..42064fdc 100644 --- a/packages/babel-plugin-polyfill-corejs3/src/index.ts +++ b/packages/babel-plugin-polyfill-corejs3/src/index.ts @@ -12,6 +12,7 @@ import { type CoreJSPolyfillDescriptor, } from "./built-in-definitions"; +import type { NodePath } from "@babel/traverse"; import { types as t } from "@babel/core"; import { callMethod, @@ -204,7 +205,7 @@ export default defineProvider(function ( coreJSPureHelper("is-iterable", useBabelRuntime, ext), "isIterable", ), - [path.node.right], + [(path.node as t.BinaryExpression).right], // meta.kind === "in" narrows this ), ); } @@ -213,20 +214,16 @@ export default defineProvider(function ( if (path.parentPath.isUnaryExpression({ operator: "delete" })) return; - let isCall: boolean | undefined | null; - if (meta.kind === "property") { // We can't compile destructuring. if (!path.isMemberExpression()) return; if (!path.isReferenced()) return; - isCall = path.parentPath.isCallExpression({ callee: path.node }); - if (meta.key === "Symbol.iterator") { if (!shouldInjectPolyfill("es.symbol.iterator")) return; - if (isCall) { - if (path.parent.arguments.length === 0) { + if (path.parentPath.isCallExpression({ callee: path.node })) { + if (path.parentPath.node.arguments.length === 0) { path.parentPath.replaceWith( t.callExpression( utils.injectDefaultImport( @@ -302,7 +299,7 @@ export default defineProvider(function ( ); if (!id) return; - if (isCall) { + if (path.parentPath.isCallExpression({ callee: path.node })) { callMethod(path, id); } else { path.replaceWith(t.callExpression(id, [path.node.object])); @@ -312,7 +309,7 @@ export default defineProvider(function ( visitor: method === "usage-global" && { // import("foo") - CallExpression(path) { + CallExpression(path: NodePath) { if (path.get("callee").isImport()) { const utils = getUtils(path); @@ -326,26 +323,28 @@ export default defineProvider(function ( }, // (async function () { }).finally(...) - Function(path) { + Function(path: NodePath) { if (path.node.async) { maybeInjectGlobal(PromiseDependencies, getUtils(path)); } }, // for-of, [a, b] = c - "ForOfStatement|ArrayPattern"(path) { + "ForOfStatement|ArrayPattern"( + path: NodePath, + ) { maybeInjectGlobal(CommonIterators, getUtils(path)); }, // [...spread] - SpreadElement(path) { + SpreadElement(path: NodePath) { if (!path.parentPath.isObjectExpression()) { maybeInjectGlobal(CommonIterators, getUtils(path)); } }, // yield* - YieldExpression(path) { + YieldExpression(path: NodePath) { if (path.node.delegate) { maybeInjectGlobal(CommonIterators, getUtils(path)); } diff --git a/packages/babel-plugin-polyfill-es-shims/src/index.ts b/packages/babel-plugin-polyfill-es-shims/src/index.ts index b21d4631..9ea28565 100644 --- a/packages/babel-plugin-polyfill-es-shims/src/index.ts +++ b/packages/babel-plugin-polyfill-es-shims/src/index.ts @@ -2,6 +2,7 @@ import defineProvider, { type Utils, type MetaDescriptor, } from "@babel/helper-define-polyfill-provider"; +import type { NodePath } from "@babel/traverse"; import polyfills from "../data/polyfills.js"; @@ -28,7 +29,7 @@ export default defineProvider<{}>(function ({ }); function createDescIterator( - cb: (desc: Descriptor, utils: Utils, path: any) => void, + cb: (desc: Descriptor, utils: Utils, path: NodePath) => void, instance?: ( meta: MetaDescriptor, resolved: any, @@ -36,7 +37,7 @@ export default defineProvider<{}>(function ({ path: any, ) => void, ) { - return (meta, utils, path) => { + return (meta: MetaDescriptor, utils: Utils, path: NodePath) => { if (path.parentPath.isUnaryExpression({ operator: "delete" })) return; const resolved = resolvePolyfill(meta); diff --git a/packages/babel-plugin-polyfill-regenerator/src/index.ts b/packages/babel-plugin-polyfill-regenerator/src/index.ts index a612246a..254503c2 100644 --- a/packages/babel-plugin-polyfill-regenerator/src/index.ts +++ b/packages/babel-plugin-polyfill-regenerator/src/index.ts @@ -2,7 +2,13 @@ import defineProvider from "@babel/helper-define-polyfill-provider"; const runtimeCompat = "#__secret_key__@babel/runtime__compatibility"; -export default defineProvider(({ debug }, options) => { +type Options = { + "#__secret_key__@babel/runtime__compatibility": void | { + useBabelRuntime: string; + }; +}; + +export default defineProvider(({ debug }, options) => { const { [runtimeCompat]: { useBabelRuntime } = { useBabelRuntime: "" } } = options; diff --git a/yarn.lock b/yarn.lock index ee3be50c..c7f7bdae 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2858,12 +2858,12 @@ __metadata: languageName: node linkType: hard -"@types/babel__traverse@npm:*, @types/babel__traverse@npm:^7.0.6": - version: 7.0.10 - resolution: "@types/babel__traverse@npm:7.0.10" +"@types/babel__traverse@npm:*, @types/babel__traverse@npm:^7.0.6, @types/babel__traverse@npm:^7.14.2": + version: 7.14.2 + resolution: "@types/babel__traverse@npm:7.14.2" dependencies: "@babel/types": ^7.3.0 - checksum: 177c01e1e5d3793624c3bbb3474f5582c15f2a66151d308bbd2ee910120eae7ecab34b0b1462b310a9d731f6caeaf8b4707a4a37debfddea42c2cda2790ae5b4 + checksum: a797ea09c72307569e3ee08aa3900ca744ce3091114084f2dc59b67a45ee7d01df7865252790dbfa787a7915ce892cdc820c9b920f3683292765fc656b08dc63 languageName: node linkType: hard @@ -4170,6 +4170,7 @@ __metadata: "@rollup/plugin-babel": ^5.3.0 "@rollup/plugin-json": ^4.1.0 "@rollup/plugin-node-resolve": ^11.2.0 + "@types/babel__traverse": ^7.14.2 "@typescript-eslint/eslint-plugin": ^5.16.0 "@typescript-eslint/parser": ^5.16.0 babel-jest: ^24.8.0 From 2ed56d0de056e6b493182236330407153a274dea Mon Sep 17 00:00:00 2001 From: Anton Gilgur Date: Sat, 26 Mar 2022 16:39:57 -0400 Subject: [PATCH 08/13] ci: support TS type-checking in CI - add `yarn tscheck` command - same naming as Babel core - modify `yarn validate` to also run `yarn tscheck` - modify ci.yml GitHub workflow to also run `yarn tscheck` - add `yarn tscheck` to CONTRIBUTING.md --- .github/workflows/ci.yml | 2 ++ CONTRIBUTING.md | 8 ++++++++ package.json | 3 ++- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 23e95004..8a51d348 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -52,6 +52,8 @@ jobs: run: yarn lint - name: Flow run: yarn flow + - name: TSCheck + run: yarn tscheck - name: Check compat-data run: yarn build-es-shims-data env: diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 73d0afd8..5eff8e16 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -40,10 +40,18 @@ $ yarn lint #### Type-check +To run Flow type-checking, run: + ```sh $ yarn flow ``` +To run TypeScript type-checking, run: + +```sh +$ yarn tscheck +``` + #### Test ```sh diff --git a/package.json b/package.json index da94717b..967ae691 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,8 @@ "publish": "yarn clean && NODE_ENV=production yarn build && yarn validate && lerna publish from-git", "test": "jest && yarn test:esm", "test:esm": "node test/esm/index.mjs", - "validate": "yarn lint && yarn flow && yarn test", + "tscheck": "yarn tsc", + "validate": "yarn lint && yarn flow && yarn tscheck && yarn test", "watch": "gulp watch" }, "devDependencies": { From 7dc712f9bb36db90cfab6dd27d69083b290993cc Mon Sep 17 00:00:00 2001 From: Anton Gilgur Date: Tue, 29 Mar 2022 16:57:06 -0400 Subject: [PATCH 09/13] clean: remove all Flow deps, scripts, config, CI, etc - remove Flow dep and .flowconfig - remove Flow scripts from package.json and ci.yml - remove Babel config and Babel plugin - ESLint plugin is required by eslint-config-babel, so cannot be removed --- .flowconfig | 13 ----------- .github/workflows/ci.yml | 2 -- CONTRIBUTING.md | 8 ------- babel.config.json | 1 - package.json | 5 +---- yarn.lock | 47 ---------------------------------------- 6 files changed, 1 insertion(+), 75 deletions(-) delete mode 100644 .flowconfig diff --git a/.flowconfig b/.flowconfig deleted file mode 100644 index 5896e5d3..00000000 --- a/.flowconfig +++ /dev/null @@ -1,13 +0,0 @@ -[ignore] -/packages/.*/lib -/packages/.*/test - -[include] -packages/*/src - -[options] -include_warnings=true -suppress_comment= \\(.\\|\n\\)*\\$FlowIgnore -suppress_type=$FlowIgnore -esproposal.optional_chaining=enable -module.name_mapper='^@babel/helper-define-polyfill-provider$' -> '/packages/babel-helper-define-polyfill-provider/src/index' \ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8a51d348..5ecb14d6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -50,8 +50,6 @@ jobs: run: yarn install - name: Lint run: yarn lint - - name: Flow - run: yarn flow - name: TSCheck run: yarn tscheck - name: Check compat-data diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 5eff8e16..ba6dfe09 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -40,14 +40,6 @@ $ yarn lint #### Type-check -To run Flow type-checking, run: - -```sh -$ yarn flow -``` - -To run TypeScript type-checking, run: - ```sh $ yarn tscheck ``` diff --git a/babel.config.json b/babel.config.json index af130cd3..7855fc78 100644 --- a/babel.config.json +++ b/babel.config.json @@ -2,7 +2,6 @@ "sourceType": "unambiguous", "presets": [ ["@babel/preset-env", { "loose": true }], - "@babel/preset-flow", "@babel/preset-typescript" ], "plugins": ["./scripts/babel-plugin-remove-create-require"], diff --git a/package.json b/package.json index 967ae691..6357113a 100644 --- a/package.json +++ b/package.json @@ -8,13 +8,12 @@ "build-es-shims-data": "./scripts/download-compat-table.sh && node ./scripts/build-es-shims-data", "clean": "rimraf packages/*/lib packages/*/esm", "clean-all": "yarn clean && rimraf packages/*/node_modules node_modules", - "flow": "flow check --strip-root", "lint": "eslint packages '*.{js,ts}' --ext .js,.ts --format=codeframe", "publish": "yarn clean && NODE_ENV=production yarn build && yarn validate && lerna publish from-git", "test": "jest && yarn test:esm", "test:esm": "node test/esm/index.mjs", "tscheck": "yarn tsc", - "validate": "yarn lint && yarn flow && yarn tscheck && yarn test", + "validate": "yarn lint && yarn tscheck && yarn test", "watch": "gulp watch" }, "devDependencies": { @@ -24,7 +23,6 @@ "@babel/eslint-plugin-development": "^7.17.7", "@babel/plugin-transform-runtime": "^7.17.0", "@babel/preset-env": "^7.16.11", - "@babel/preset-flow": "^7.16.7", "@babel/preset-typescript": "^7.16.7", "@babel/runtime": "^7.17.8", "@rollup/plugin-babel": "^5.3.0", @@ -42,7 +40,6 @@ "eslint-plugin-import": "^2.17.2", "eslint-plugin-prettier": "^3.1.0", "fancy-log": "^1.3.3", - "flow-bin": "^0.107.0", "gulp": "^4.0.2", "gulp-babel": "^8.0.0", "gulp-newer": "^1.0.0", diff --git a/yarn.lock b/yarn.lock index c7f7bdae..7d2264ce 100644 --- a/yarn.lock +++ b/yarn.lock @@ -735,17 +735,6 @@ __metadata: languageName: node linkType: hard -"@babel/plugin-syntax-flow@npm:^7.16.7": - version: 7.16.7 - resolution: "@babel/plugin-syntax-flow@npm:7.16.7" - dependencies: - "@babel/helper-plugin-utils": ^7.16.7 - peerDependencies: - "@babel/core": ^7.0.0-0 - checksum: b1ab0bd9b78e4aa5fb48714d6514f3d08d72693807c6044a5be4f301a9bb677b5648fbdae11c8bc93923da6b320a1898560c307933021bdb75ee39e577ed74ee - languageName: node - linkType: hard - "@babel/plugin-syntax-json-strings@npm:^7.8.3": version: 7.8.3 resolution: "@babel/plugin-syntax-json-strings@npm:7.8.3" @@ -977,18 +966,6 @@ __metadata: languageName: node linkType: hard -"@babel/plugin-transform-flow-strip-types@npm:^7.16.7": - version: 7.16.7 - resolution: "@babel/plugin-transform-flow-strip-types@npm:7.16.7" - dependencies: - "@babel/helper-plugin-utils": ^7.16.7 - "@babel/plugin-syntax-flow": ^7.16.7 - peerDependencies: - "@babel/core": ^7.0.0-0 - checksum: 4b4801c91d805d95957781e537f88e9f34c7f8a4c262c4d230af2ab7a920889c542860e505149a856d4c16916ffb02df4f3af161733adeedb7671555d1510bba - languageName: node - linkType: hard - "@babel/plugin-transform-for-of@npm:^7.16.7": version: 7.16.7 resolution: "@babel/plugin-transform-for-of@npm:7.16.7" @@ -1359,19 +1336,6 @@ __metadata: languageName: node linkType: hard -"@babel/preset-flow@npm:^7.16.7": - version: 7.16.7 - resolution: "@babel/preset-flow@npm:7.16.7" - dependencies: - "@babel/helper-plugin-utils": ^7.16.7 - "@babel/helper-validator-option": ^7.16.7 - "@babel/plugin-transform-flow-strip-types": ^7.16.7 - peerDependencies: - "@babel/core": ^7.0.0-0 - checksum: b73c743a6bdfb51fe907adbc425a82469145ea15f32b43096804e28ba30921c4ac3199f86e11d1cefbce95c3a5404aaf3534152f5a12358c57303c05dfc51b4f - languageName: node - linkType: hard - "@babel/preset-modules@npm:^0.1.5": version: 0.1.5 resolution: "@babel/preset-modules@npm:0.1.5" @@ -4164,7 +4128,6 @@ __metadata: "@babel/eslint-plugin-development": ^7.17.7 "@babel/plugin-transform-runtime": ^7.17.0 "@babel/preset-env": ^7.16.11 - "@babel/preset-flow": ^7.16.7 "@babel/preset-typescript": ^7.16.7 "@babel/runtime": ^7.17.8 "@rollup/plugin-babel": ^5.3.0 @@ -4182,7 +4145,6 @@ __metadata: eslint-plugin-import: ^2.17.2 eslint-plugin-prettier: ^3.1.0 fancy-log: ^1.3.3 - flow-bin: ^0.107.0 gulp: ^4.0.2 gulp-babel: ^8.0.0 gulp-newer: ^1.0.0 @@ -6868,15 +6830,6 @@ __metadata: languageName: node linkType: hard -"flow-bin@npm:^0.107.0": - version: 0.107.0 - resolution: "flow-bin@npm:0.107.0" - bin: - flow: cli.js - checksum: 31e9fa3c81ceeb102a2269385e5d7c64d4040adb152ddeded108f5b8d47401cd78fe503087061b8a74ef34b2b09ed00cd87a923b2ffe5dcbbd9b9164e3466618 - languageName: node - linkType: hard - "flush-write-stream@npm:^1.0.0, flush-write-stream@npm:^1.0.2": version: 1.1.1 resolution: "flush-write-stream@npm:1.1.1" From 08d732987f98858e5e38ddb52159190bdf270a7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Ribaudo?= Date: Sun, 3 Apr 2022 23:32:44 +0200 Subject: [PATCH 10/13] Minor updates --- packages/babel-plugin-polyfill-corejs3/src/index.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/babel-plugin-polyfill-corejs3/src/index.ts b/packages/babel-plugin-polyfill-corejs3/src/index.ts index 42064fdc..90feba33 100644 --- a/packages/babel-plugin-polyfill-corejs3/src/index.ts +++ b/packages/babel-plugin-polyfill-corejs3/src/index.ts @@ -222,15 +222,16 @@ export default defineProvider(function ( if (meta.key === "Symbol.iterator") { if (!shouldInjectPolyfill("es.symbol.iterator")) return; - if (path.parentPath.isCallExpression({ callee: path.node })) { - if (path.parentPath.node.arguments.length === 0) { + const { parent, node } = path; + if (t.isCallExpression(parent, { callee: node })) { + if (parent.arguments.length === 0) { path.parentPath.replaceWith( t.callExpression( utils.injectDefaultImport( coreJSPureHelper("get-iterator", useBabelRuntime, ext), "getIterator", ), - [path.node.object], + [node.object], ), ); path.skip(); @@ -299,10 +300,11 @@ export default defineProvider(function ( ); if (!id) return; - if (path.parentPath.isCallExpression({ callee: path.node })) { + const { node } = path as NodePath; + if (t.isCallExpression(path.parent, { callee: node })) { callMethod(path, id); } else { - path.replaceWith(t.callExpression(id, [path.node.object])); + path.replaceWith(t.callExpression(id, [node.object])); } } }, From ff3432bab7a3a7282cd89a5472a564f9ea5e54ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Ribaudo?= Date: Sun, 3 Apr 2022 23:45:07 +0200 Subject: [PATCH 11/13] Revert `targets` type --- packages/babel-helper-define-polyfill-provider/src/types.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/babel-helper-define-polyfill-provider/src/types.ts b/packages/babel-helper-define-polyfill-provider/src/types.ts index 52d61664..d0ff1874 100644 --- a/packages/babel-helper-define-polyfill-provider/src/types.ts +++ b/packages/babel-helper-define-polyfill-provider/src/types.ts @@ -23,8 +23,10 @@ export type ProviderOptions = { export type PluginOptions = { method: MethodString; targets?: { + // @ts-expect-error - This is technically unsound, because the type of + // "browsers" is not assignable to "string | number". browsers: string | string[]; - [target: string]: string | string[] | number; + [target: string]: string | number; }; ignoreBrowserslistConfig?: boolean; configPath?: string; From 68f27965a2d2d3779bda0f8d1e33b68346c291b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Ribaudo?= Date: Mon, 4 Apr 2022 00:29:47 +0200 Subject: [PATCH 12/13] Fix ESM building --- babel.config.json | 5 +++- scripts/babel-plugin-compat-core-import.js | 31 ++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 scripts/babel-plugin-compat-core-import.js diff --git a/babel.config.json b/babel.config.json index 7855fc78..6bd6cd3d 100644 --- a/babel.config.json +++ b/babel.config.json @@ -4,7 +4,10 @@ ["@babel/preset-env", { "loose": true }], "@babel/preset-typescript" ], - "plugins": ["./scripts/babel-plugin-remove-create-require"], + "plugins": [ + "./scripts/babel-plugin-remove-create-require", + "./scripts/babel-plugin-compat-core-import" + ], "targets": { "node": "current" }, "env": { "production": { diff --git a/scripts/babel-plugin-compat-core-import.js b/scripts/babel-plugin-compat-core-import.js new file mode 100644 index 00000000..7e0172f6 --- /dev/null +++ b/scripts/babel-plugin-compat-core-import.js @@ -0,0 +1,31 @@ +// Convert +// import { x as y } from "@babel/core"; +// to +// import * as babel from "@babel/core"; +// const { x: y } = babel.default || babel; + +module.exports = function ({ types: t, template }) { + return { + visitor: { + ImportDeclaration(path) { + if ( + t.isStringLiteral(path.node.source, { value: "@babel/core" }) && + path.node.specifiers.every(node => t.isImportSpecifier(node)) + ) { + const defaultName = path.scope.generateUidIdentifier("babel"); + + const destr = t.objectPattern( + path.node.specifiers.map(spec => + t.objectProperty(spec.imported, spec.local) + ) + ); + + path.replaceWithMultiple(template.statements.ast` + import * as ${defaultName} from "@babel/core"; + const ${destr} = ${defaultName}.default || ${defaultName}; + `); + } + }, + }, + }; +}; From 80605cc0084c4adfd6b50c2d626ce2bd169a4236 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Ribaudo?= Date: Mon, 4 Apr 2022 00:35:52 +0200 Subject: [PATCH 13/13] Simplify `| null | undefined` --- .../babel-helper-define-polyfill-provider/src/index.ts | 3 +-- .../src/normalize-options.ts | 2 +- .../babel-helper-define-polyfill-provider/src/types.ts | 8 ++++---- .../babel-helper-define-polyfill-provider/src/utils.ts | 4 ++-- .../src/built-in-definitions.ts | 8 ++++---- .../src/built-in-definitions.ts | 4 ++-- 6 files changed, 14 insertions(+), 15 deletions(-) diff --git a/packages/babel-helper-define-polyfill-provider/src/index.ts b/packages/babel-helper-define-polyfill-provider/src/index.ts index 00fcc417..246ea7a6 100644 --- a/packages/babel-helper-define-polyfill-provider/src/index.ts +++ b/packages/babel-helper-define-polyfill-provider/src/index.ts @@ -45,8 +45,7 @@ function resolveOptions( debug: boolean | typeof presetEnvSilentDebugHeader; shouldInjectPolyfill: | ((name: string, shouldInject: boolean) => boolean) - | undefined - | null; + | undefined; providerOptions: ProviderOptions; absoluteImports: string | boolean; } { diff --git a/packages/babel-helper-define-polyfill-provider/src/normalize-options.ts b/packages/babel-helper-define-polyfill-provider/src/normalize-options.ts index 2bc4b6ff..84940a96 100644 --- a/packages/babel-helper-define-polyfill-provider/src/normalize-options.ts +++ b/packages/babel-helper-define-polyfill-provider/src/normalize-options.ts @@ -5,7 +5,7 @@ import type { MissingDependenciesOption, } from "./types"; -function patternToRegExp(pattern: Pattern): RegExp | undefined | null { +function patternToRegExp(pattern: Pattern): RegExp | null { if (pattern instanceof RegExp) return pattern; try { diff --git a/packages/babel-helper-define-polyfill-provider/src/types.ts b/packages/babel-helper-define-polyfill-provider/src/types.ts index d0ff1874..15f117ef 100644 --- a/packages/babel-helper-define-polyfill-provider/src/types.ts +++ b/packages/babel-helper-define-polyfill-provider/src/types.ts @@ -86,14 +86,14 @@ export type MetaDescriptor = | { kind: "global"; name: string } | { kind: "property"; - placement: "static" | "prototype" | undefined | null; - object: string | undefined | null; + placement: "static" | "prototype" | null; + object: string | null; key: string; } | { kind: "in"; - placement: "static" | "prototype" | undefined | null; - object: string | undefined | null; + placement: "static" | "prototype" | null; + object: string | null; key: string; }; diff --git a/packages/babel-helper-define-polyfill-provider/src/utils.ts b/packages/babel-helper-define-polyfill-provider/src/utils.ts index a043b037..b53a4fdc 100644 --- a/packages/babel-helper-define-polyfill-provider/src/utils.ts +++ b/packages/babel-helper-define-polyfill-provider/src/utils.ts @@ -62,8 +62,8 @@ export function resolveKey( } export function resolveSource(obj: NodePath): { - id: string; - placement: "prototype" | "static"; + id: string | null; + placement: "prototype" | "static" | null; } { if ( obj.isMemberExpression() && diff --git a/packages/babel-plugin-polyfill-corejs2/src/built-in-definitions.ts b/packages/babel-plugin-polyfill-corejs2/src/built-in-definitions.ts index 66d19bbb..13df7852 100644 --- a/packages/babel-plugin-polyfill-corejs2/src/built-in-definitions.ts +++ b/packages/babel-plugin-polyfill-corejs2/src/built-in-definitions.ts @@ -4,13 +4,13 @@ type ObjectMap = { [name: string]: V }; type PolyfillDescriptor = { name: string; - pure: string | undefined | null; + pure: string | null; global: string[]; - meta: T | undefined | null; + meta: T | null; }; type CoreJS2Meta = { - minRuntimeVersion: string | undefined | null; + minRuntimeVersion: string | null; }; const define = ( @@ -25,7 +25,7 @@ const define = ( const pureAndGlobal = ( pure: string, global: string[], - minRuntimeVersion: string | undefined | null = null, + minRuntimeVersion: string | null = null, ) => define(global[0], pure, global, { minRuntimeVersion }); const globalOnly = (global: string[]) => diff --git a/packages/babel-plugin-polyfill-corejs3/src/built-in-definitions.ts b/packages/babel-plugin-polyfill-corejs3/src/built-in-definitions.ts index 995e9f2c..67c9ca80 100644 --- a/packages/babel-plugin-polyfill-corejs3/src/built-in-definitions.ts +++ b/packages/babel-plugin-polyfill-corejs3/src/built-in-definitions.ts @@ -5,9 +5,9 @@ type ObjectMap2 = ObjectMap>; export type CoreJSPolyfillDescriptor = { name: string; - pure: string | undefined | null; + pure: string | null; global: string[]; - exclude: string[] | undefined | null; + exclude: string[] | null; }; const polyfillsOrder = {};