Remove useless iterator library
This commit is contained in:
parent
743dce09ae
commit
8a73947697
2
dist/package.json
vendored
2
dist/package.json
vendored
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@aet/eslint-rules",
|
||||
"version": "0.0.1-beta.30",
|
||||
"version": "0.0.1-beta.32",
|
||||
"license": "UNLICENSED",
|
||||
"peerDependencies": {
|
||||
"esbin": "^0.0.2",
|
||||
|
23
esbuild.ts
23
esbuild.ts
@ -8,9 +8,12 @@ import type { Loader, Plugin } from 'esbuild';
|
||||
import * as babel from '@babel/core';
|
||||
import { memoize } from 'lodash';
|
||||
import { gray, green } from 'picocolors';
|
||||
import type { types as t } from '@babel/core';
|
||||
import type { types as t, types } from '@babel/core';
|
||||
import { dependencies } from './dist/package.json';
|
||||
import { createMacro, type MacroHandler } from 'babel-plugin-macros';
|
||||
import * as polyfill from './src/polyfill';
|
||||
|
||||
const polyfills = Object.keys(polyfill);
|
||||
|
||||
const ENV = process.env.NODE_ENV || 'development';
|
||||
const PROD = ENV === 'production';
|
||||
@ -91,6 +94,24 @@ const map = new HandlerMap()
|
||||
),
|
||||
);
|
||||
|
||||
// es-iterator-helpers/Iterator.prototype.*
|
||||
const polyfillPath = resolve(__dirname, './src/polyfill.ts');
|
||||
const requirePolyfill = (t: typeof types, name: string) =>
|
||||
t.memberExpression(
|
||||
t.callExpression(t.identifier('require'), [t.stringLiteral(polyfillPath)]),
|
||||
t.identifier(name),
|
||||
);
|
||||
map.set(
|
||||
`es-iterator-helpers/Iterator.from`,
|
||||
replace(t => requirePolyfill(t, 'from')),
|
||||
);
|
||||
for (const name of polyfills) {
|
||||
map.set(
|
||||
`es-iterator-helpers/Iterator.prototype.${name}`,
|
||||
replace(t => requirePolyfill(t, name)),
|
||||
);
|
||||
}
|
||||
|
||||
function replace(getReplacement: (types: typeof t) => t.Expression): MacroHandler {
|
||||
return ({ references, babel: { types: t } }) => {
|
||||
references.default.forEach(referencePath => {
|
||||
|
@ -15,11 +15,11 @@
|
||||
"@types/estree": "^1.0.1",
|
||||
"@types/estree-jsx": "^1.0.0",
|
||||
"@types/lodash": "^4.14.197",
|
||||
"@types/node": "^20.5.1",
|
||||
"@types/node": "^20.5.4",
|
||||
"@typescript-eslint/types": "^6.4.1",
|
||||
"babel-plugin-macros": "^3.1.0",
|
||||
"dts-bundle-generator": "^8.0.1",
|
||||
"esbin": "0.0.1-beta.3",
|
||||
"esbin": "0.0.2",
|
||||
"esbuild": "0.19.2",
|
||||
"esbuild-plugin-alias": "^0.2.1",
|
||||
"esbuild-register": "3.4.2",
|
||||
|
18
pnpm-lock.yaml
generated
18
pnpm-lock.yaml
generated
@ -33,8 +33,8 @@ devDependencies:
|
||||
specifier: ^4.14.197
|
||||
version: 4.14.197
|
||||
'@types/node':
|
||||
specifier: ^20.5.1
|
||||
version: 20.5.1
|
||||
specifier: ^20.5.4
|
||||
version: 20.5.4
|
||||
'@typescript-eslint/types':
|
||||
specifier: ^6.4.1
|
||||
version: 6.4.1
|
||||
@ -45,8 +45,8 @@ devDependencies:
|
||||
specifier: ^8.0.1
|
||||
version: 8.0.1
|
||||
esbin:
|
||||
specifier: 0.0.1-beta.3
|
||||
version: 0.0.1-beta.3(esbuild@0.19.2)
|
||||
specifier: 0.0.2
|
||||
version: 0.0.2(esbuild@0.19.2)
|
||||
esbuild:
|
||||
specifier: 0.19.2
|
||||
version: 0.19.2
|
||||
@ -1719,8 +1719,8 @@ packages:
|
||||
resolution: {integrity: sha512-BMVOiWs0uNxHVlHBgzTIqJYmj+PgCo4euloGF+5m4okL3rEYzM2EEv78mw8zWSMM57dM7kVIgJ2QDvwHSoCI5g==}
|
||||
dev: true
|
||||
|
||||
/@types/node@20.5.1:
|
||||
resolution: {integrity: sha512-4tT2UrL5LBqDwoed9wZ6N3umC4Yhz3W3FloMmiiG4JwmUJWpie0c7lcnUNd4gtMKuDEO4wRVS8B6Xa0uMRsMKg==}
|
||||
/@types/node@20.5.4:
|
||||
resolution: {integrity: sha512-Y9vbIAoM31djQZrPYjpTLo0XlaSwOIsrlfE3LpulZeRblttsLQRFRlBAppW0LOxyT3ALj2M5vU1ucQQayQH3jA==}
|
||||
dev: true
|
||||
|
||||
/@types/normalize-package-data@2.4.1:
|
||||
@ -2177,11 +2177,11 @@ packages:
|
||||
is-symbol: 1.0.4
|
||||
dev: true
|
||||
|
||||
/esbin@0.0.1-beta.3(esbuild@0.19.2):
|
||||
resolution: {integrity: sha512-r8elIQs0Q0ArVkZJylVqiXxeNTlwvgjzK5V4lzjGDKbwobSuW2EzHBOmF8/Jb2pSTeysh0oRtXO+3YDne2U/PA==}
|
||||
/esbin@0.0.2(esbuild@0.19.2):
|
||||
resolution: {integrity: sha512-kmQ0D4pW0t1+VjA3YbSJQrhuuRjhqlSEPTTMrVVlJZOnfCoPbm1Hr648phOWLD2tMi9dDlFi5qE/p3ceJJcNjQ==}
|
||||
hasBin: true
|
||||
peerDependencies:
|
||||
esbuild: '>=0.17 <1'
|
||||
esbuild: '>=0.19 <1'
|
||||
dependencies:
|
||||
debug: 4.3.4
|
||||
esbuild: 0.19.2
|
||||
|
59
src/polyfill.ts
Normal file
59
src/polyfill.ts
Normal file
@ -0,0 +1,59 @@
|
||||
// es-iterator-helpers/Iterator.prototype.filter
|
||||
export function* filter<T>(
|
||||
iterable: Iterable<T>,
|
||||
predicate: (value: T) => boolean,
|
||||
): Iterable<T> {
|
||||
for (const value of iterable) {
|
||||
if (predicate(value)) {
|
||||
yield value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// es-iterator-helpers/Iterator.prototype.forEach
|
||||
export function forEach<T>(iterable: Iterable<T>, callback: (value: T) => void) {
|
||||
for (const value of iterable) {
|
||||
callback(value);
|
||||
}
|
||||
}
|
||||
|
||||
// es-iterator-helpers/Iterator.prototype.some
|
||||
export function some<T>(
|
||||
iterable: Iterable<T>,
|
||||
predicate: (value: T) => boolean,
|
||||
): boolean {
|
||||
for (const value of iterable) {
|
||||
if (predicate(value)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// es-iterator-helpers/Iterator.prototype.find
|
||||
export function find<T>(
|
||||
iterable: Iterable<T>,
|
||||
predicate: (value: T) => boolean,
|
||||
): T | undefined {
|
||||
for (const value of iterable) {
|
||||
if (predicate(value)) {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// es-iterator-helpers/Iterator.from
|
||||
export function from<T>(iterable: Iterable<T>) {
|
||||
return iterable;
|
||||
}
|
||||
|
||||
// es-iterator-helpers/Iterator.prototype.map
|
||||
export function* map<T, U>(
|
||||
iterable: Iterable<T>,
|
||||
callback: (value: T) => U,
|
||||
): Iterable<U> {
|
||||
for (const value of iterable) {
|
||||
yield callback(value);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user