[@babel/preset-env] Add types (#43612)

This commit is contained in:
Slava Fomin II 2020-04-04 02:09:46 +03:00 committed by GitHub
parent c35c497c2b
commit cc78cc2e22
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 399 additions and 0 deletions

View File

@ -0,0 +1,277 @@
/* tslint:disable:no-consecutive-blank-lines comment-format */
import { Options } from '@babel/preset-env';
//=========//
// TARGETS //
//=========//
let options: Options = {
targets: '> 0.25%, not dead',
};
options = {
targets: [
'> 0.25%',
'not dead',
],
};
options = {
targets: {
OperaMini: '80',
Edge: '22',
ie: '11',
},
};
options = {
targets: {
esmodules: true,
},
};
options = {
targets: {
node: '12',
},
};
options = {
targets: {
node: 'current',
},
};
options = {
targets: {
node: true,
},
};
options = {
targets: {
safari: '20',
},
};
options = {
targets: {
safari: 'tp',
},
};
options = {
targets: {
browsers: '> 0.25%, not dead',
},
};
options = {
targets: {
browsers: [
'> 0.25%',
'not dead',
],
},
};
//==========//
// BUGFIXES //
//==========//
options = {
bugfixes: true,
};
options = {
bugfixes: false,
};
//======//
// SPEC //
//======//
options = {
spec: true,
};
options = {
spec: false,
};
//=======//
// LOOSE //
//=======//
options = {
loose: true,
};
options = {
loose: false,
};
//=========//
// MODULES //
//=========//
options = {
modules: 'amd',
};
options = {
modules: 'cjs',
};
options = {
modules: 'commonjs',
};
options = {
modules: false,
};
//=======//
// DEBUG //
//=======//
options = {
debug: true,
};
options = {
debug: false,
};
//=========//
// INCLUDE //
//=========//
options = {
include: [],
};
options = {
include: ['foo', 'bar'],
};
options = {
include: [/foo/, /bar/],
};
//=========//
// EXCLUDE //
//=========//
options = {
exclude: [],
};
options = {
exclude: ['foo', 'bar'],
};
options = {
exclude: [/foo/, /bar/],
};
//===============//
// USE BUILT INS //
//===============//
options = {
useBuiltIns: 'usage',
};
options = {
useBuiltIns: 'entry',
};
options = {
useBuiltIns: false,
};
//========//
// COREJS //
//========//
options = {
corejs: 2,
};
options = {
corejs: 3,
};
options = {
corejs: {
version: 2,
proposals: true,
},
};
options = {
corejs: {
version: 3,
proposals: false,
},
};
//======================//
// FORCE ALL TRANSFORMS //
//======================//
options = {
forceAllTransforms: true,
};
options = {
forceAllTransforms: false,
};
//======================//
// FORCE ALL TRANSFORMS //
//======================//
options = {
configPath: '/etc/babel-config.json',
};
//============================//
// IGNORE BROWSERSLIST CONFIG //
//============================//
options = {
ignoreBrowserslistConfig: true,
};
options = {
ignoreBrowserslistConfig: false,
};
//===================//
// SHIPPED PROPOSALS //
//===================//
options = {
shippedProposals: true,
};
options = {
shippedProposals: false,
};

94
types/babel__preset-env/index.d.ts vendored Normal file
View File

@ -0,0 +1,94 @@
// Type definitions for @babel/preset-env 7.9
// Project: https://github.com/babel/babel/tree/master/packages/babel-preset-env, https://babeljs.io/docs/en/babel-preset-env
// Definitions by: Slava Fomin II <https://github.com/slavafomin>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
export interface Options {
targets?: TargetsOptions;
bugfixes?: boolean;
spec?: boolean;
loose?: boolean;
modules?: ModuleOption;
debug?: boolean;
include?: PluginList;
exclude?: PluginList;
useBuiltIns?: UseBuiltInsOption;
corejs?: CorejsOption;
forceAllTransforms?: boolean;
configPath?: string;
ignoreBrowserslistConfig?: boolean;
shippedProposals?: boolean;
}
/**
* "targets" config option:
* https://babeljs.io/docs/en/babel-preset-env#targets
*/
export type TargetsOptions = (
| BrowserslistQuery
| ReadonlyArray<BrowserslistQuery>
| { [key in Target]?: string; }
| { esmodules: true }
| { node: (string | 'current' | true) }
| { safari: (string | 'tp') }
| { browsers: (string | ReadonlyArray<string>) }
);
export type BrowserslistQuery = string;
/**
* List of supported Browserslist targets:
* Source: https://github.com/browserslist/browserslist#browsers
*/
export type Target = (
| 'Android'
| 'Baidu'
| 'BlackBerry' | 'bb'
| 'Chrome'
| 'ChromeAndroid' | 'and_chr'
| 'Edge'
| 'Electron'
| 'Explorer' | 'ie'
| 'ExplorerMobile' | 'ie_mob'
| 'Firefox' | 'ff'
| 'FirefoxAndroid' | 'and_ff'
| 'iOS' | 'ios_saf'
| 'Node'
| 'Opera'
| 'OperaMini' | 'op_mini'
| 'OperaMobile' | 'op_mob'
| 'QQAndroid' | 'and_qq'
| 'Safari'
| 'Samsung'
| 'UCAndroid' | 'and_uc'
| 'kaios'
);
/**
* https://babeljs.io/docs/en/babel-preset-env#modules
*/
export type ModuleOption = (
| 'amd'
| 'umd'
| 'systemjs'
| 'commonjs'
| 'cjs'
| 'auto'
| false
);
export type PluginList = ReadonlyArray<PluginListItem>;
export type PluginListItem = (string | RegExp);
export type UseBuiltInsOption = (
| 'usage'
| 'entry'
| false
);
export type CorejsOption = (
| CorejsVersion
| { version: CorejsVersion, proposals: boolean }
);
export type CorejsVersion = (2 | 3);

View File

@ -0,0 +1,25 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"strict": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true,
"paths": {
"@babel/preset-env": [
"babel__preset-env"
]
}
},
"files": [
"index.d.ts",
"babel__preset-env-tests.ts"
]
}

View File

@ -0,0 +1,3 @@
{
"extends": "dtslint/dt.json"
}