Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1235 from susnux/typescript
- Loading branch information
Showing
8 changed files
with
195 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import type { ModuleName, Target, TargetVersion } from "./shared"; | ||
|
||
type StringOrRegExp = string | RegExp; | ||
|
||
type Modules = StringOrRegExp | readonly StringOrRegExp[]; | ||
|
||
type BrowserslistQuery = string | ReadonlyArray<string>; | ||
|
||
type Environments = { | ||
[target in Target]?: string | number; | ||
}; | ||
|
||
type Targets = Environments & { | ||
browsers?: Environments | BrowserslistQuery, | ||
esmodules?: boolean, | ||
}; | ||
|
||
type CompatOptions = { | ||
/** entry / module / namespace / an array of them, by default - all `core-js` modules */ | ||
modules?: Modules, | ||
/** a blacklist, entry / module / namespace / an array of them, by default - empty list */ | ||
exclude?: Modules, | ||
/** optional browserslist or core-js-compat format query */ | ||
targets?: Targets | BrowserslistQuery, | ||
/** used `core-js` version, by default the latest */ | ||
version?: string, | ||
/** inverse of the result, shows modules that are NOT required for the target environment */ | ||
inverse?: boolean, | ||
/** | ||
* @deprecated use `modules` instead | ||
*/ | ||
filter?: Modules | ||
}; | ||
|
||
type CompatOutput = { | ||
/** array of required modules */ | ||
list: ModuleName[], | ||
/** object with targets for each module */ | ||
targets: { | ||
[module: ModuleName]: { | ||
[target in Target]?: TargetVersion | ||
} | ||
} | ||
} | ||
|
||
declare function compat(options?: CompatOptions): CompatOutput; | ||
|
||
export = compat; |
5 changes: 5 additions & 0 deletions
5
packages/core-js-compat/get-modules-list-for-target-version.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import type { ModuleName, TargetVersion } from "./shared"; | ||
|
||
declare function getModulesListForTargetVersion(version: TargetVersion): readonly ModuleName[]; | ||
|
||
export = getModulesListForTargetVersion; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import type compat from './compat' | ||
import type getModulesListForTargetVersion from './get-modules-list-for-target-version'; | ||
import type { ModuleName, Target, TargetVersion } from './shared' | ||
|
||
type CompatData = { | ||
[module: ModuleName]: { | ||
[target in Target]?: TargetVersion | ||
} | ||
}; | ||
|
||
declare const ExportedCompatObject: typeof compat & { | ||
compat: typeof compat, | ||
|
||
/** The subset of modules which available in the passed `core-js` version */ | ||
getModulesListForTargetVersion: typeof getModulesListForTargetVersion, | ||
|
||
/** Full list compatibility data */ | ||
data: CompatData, | ||
|
||
/** map of modules by `core-js` entry points */ | ||
entries: {[entry_point: string]: readonly ModuleName[]}, | ||
|
||
/** Full list of modules */ | ||
modules: readonly ModuleName[] | ||
} | ||
|
||
export = ExportedCompatObject |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
export type ModuleName = string; | ||
|
||
export type Target = | ||
| 'android' | ||
| 'bun' | ||
| 'chrome' | ||
| 'chrome-android' | ||
| 'deno' | ||
| 'edge' | ||
| 'electron' | ||
| 'firefox' | ||
| 'firefox-android' | ||
| 'hermes' | ||
| 'ie' | ||
| 'ios' | ||
| 'node' | ||
| 'opera' | ||
| 'opera-android' | ||
| 'phantom' | ||
| 'quest' | ||
| 'react-native' | ||
| 'rhino' | ||
| 'safari' | ||
| 'samsung' | ||
/** `quest` alias */ | ||
| 'oculus' | ||
/** `react-native` alias */ | ||
| 'react' | ||
/** @deprecated use `opera-android` instead */ | ||
| 'opera_mobile'; | ||
|
||
export type TargetVersion = string; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import compat from 'core-js-compat'; | ||
import compat2 from 'core-js-compat/compat'; | ||
import getModulesListForTargetVersion from 'core-js-compat/get-modules-list-for-target-version'; | ||
|
||
getModulesListForTargetVersion('3.0'); | ||
compat.getModulesListForTargetVersion('3.0'); | ||
|
||
compat.data['es.array.push'].android | ||
compat.data['es.array.push'].firefox | ||
|
||
if (typeof compat.modules[0] !== 'string') { | ||
console.error('Invalid'); | ||
} | ||
|
||
if (!compat.entries['core-js'].includes('es.array.from')) { | ||
console.error('Invalid') | ||
} | ||
|
||
compat(); | ||
compat({}); | ||
compat({ modules: 'core-js/actual' }); | ||
compat({ modules: 'es.array.push' }); | ||
compat({ modules: /^es\.array\./ }); | ||
compat({ modules: ['core-js/actual', /^es\.array\./] }); | ||
compat({ exclude: 'core-js/actual' }); | ||
compat({ exclude: 'es.array.push' }); | ||
compat({ exclude: /^es\.array\./ }); | ||
compat({ exclude: ['core-js/actual', /^es\.array\./] }); | ||
compat({ modules: 'core-js/actual', exclude: /^es\.array\./ }); | ||
compat({ targets: '> 1%' }); | ||
compat({ targets: ['defaults', 'last 5 versions'] }); | ||
compat({ targets: { esmodules: true, node: 'current', browsers: ['> 1%'] } }); | ||
compat({ targets: { chrome: '26', firefox: 4 } }); | ||
compat({ targets: { browsers: { chrome: '26', firefox: 4 } } }); | ||
compat({ targets: { chrome: '26', firefox: 4, esmodules: true, node: 'current', browsers: ['> 1%'] } }); | ||
compat({ version: '3.0' }); | ||
compat({ inverse: true }); | ||
|
||
compat.compat(); | ||
compat.compat({}); | ||
compat.compat({ modules: 'core-js/actual' }); | ||
compat.compat({ modules: 'es.array.push' }); | ||
compat.compat({ modules: /^es\.array\./ }); | ||
compat.compat({ modules: ['core-js/actual', /^es\.array\./] }); | ||
compat.compat({ exclude: 'core-js/actual' }); | ||
compat.compat({ exclude: 'es.array.push' }); | ||
compat.compat({ exclude: /^es\.array\./ }); | ||
compat.compat({ exclude: ['core-js/actual', /^es\.array\./] }); | ||
compat.compat({ modules: 'core-js/actual', exclude: /^es\.array\./ }); | ||
compat.compat({ targets: '> 1%' }); | ||
compat.compat({ targets: ['defaults', 'last 5 versions'] }); | ||
compat.compat({ targets: { esmodules: true, node: 'current', browsers: ['> 1%'] } }); | ||
compat.compat({ targets: { chrome: '26', firefox: 4 } }); | ||
compat.compat({ targets: { browsers: { chrome: '26', firefox: 4 } } }); | ||
compat.compat({ targets: { chrome: '26', firefox: 4, esmodules: true, node: 'current', browsers: ['> 1%'] } }); | ||
compat.compat({ version: '3.0' }); | ||
compat.compat({ inverse: true }); | ||
|
||
compat2(); | ||
compat2({}); | ||
compat2({ modules: 'core-js/actual' }); | ||
compat2({ modules: 'es.array.push' }); | ||
compat2({ modules: /^es\.array\./ }); | ||
compat2({ modules: ['core-js/actual', /^es\.array\./] }); | ||
compat2({ exclude: 'core-js/actual' }); | ||
compat2({ exclude: 'es.array.push' }); | ||
compat2({ exclude: /^es\.array\./ }); | ||
compat2({ exclude: ['core-js/actual', /^es\.array\./] }); | ||
compat2({ modules: 'core-js/actual', exclude: /^es\.array\./ }); | ||
compat2({ targets: '> 1%' }); | ||
compat2({ targets: ['defaults', 'last 5 versions'] }); | ||
compat2({ targets: { esmodules: true, node: 'current', browsers: ['> 1%'] } }); | ||
compat2({ targets: { chrome: '26', firefox: 4 } }); | ||
compat2({ targets: { browsers: { chrome: '26', firefox: 4 } } }); | ||
compat2({ targets: { chrome: '26', firefox: 4, esmodules: true, node: 'current', browsers: ['> 1%'] } }); | ||
compat2({ version: '3.0' }); | ||
compat2({ inverse: true }); |