Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit47ad54a

Browse files
convert @babel/preset-env to typescript (#13217)
* babel-preset-env flowts rename* babel-preset-env flowts convert* babel-preset-env fixes* babel-preset-env* make generate-tsconfig* Minimize diff* Fix many type errorsCo-authored-by: Nicolò Ribaudo <nicolo.ribaudo@gmail.com>
1 parent22e5afc commit47ad54a

16 files changed

+117
-124
lines changed

‎packages/babel-preset-env/src/available-plugins.js‎renamed to ‎packages/babel-preset-env/src/available-plugins.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
//@flow
21
/* eslint sort-keys: "error" */
32

43
importsyntaxAsyncGeneratorsfrom"@babel/plugin-syntax-async-generators";

‎packages/babel-preset-env/src/debug.js‎renamed to ‎packages/babel-preset-env/src/debug.ts‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
//@flow
1+
import{getInclusionReasons}from"@babel/helper-compilation-targets";
22

3-
import{
4-
getInclusionReasons,
5-
typeTargets,
6-
}from"@babel/helper-compilation-targets";
3+
importtype{Targets}from"@babel/helper-compilation-targets";
74

85
// Outputs a message that shows which target(s) caused an item to be included:
96
// transform-foo { "edge":"13", "firefox":"49", "ie":"10" }

‎packages/babel-preset-env/src/filter-items.js‎renamed to ‎packages/babel-preset-env/src/filter-items.ts‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
//@flow
2-
31
import{lt}from"semver";
42
import{minVersions}from"./available-plugins";
53

‎packages/babel-preset-env/src/get-option-specific-excludes.js‎renamed to ‎packages/babel-preset-env/src/get-option-specific-excludes.ts‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
//@flow
2-
31
constdefaultExcludesForLooseMode=["transform-typeof-symbol"];
42

53
exportdefaultfunction({ loose}:{loose:boolean}):null|string[]{

‎packages/babel-preset-env/src/index.js‎renamed to ‎packages/babel-preset-env/src/index.ts‎

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
//@flow
2-
3-
import{SemVer,lt}from"semver";
1+
import{lt}from"semver";
2+
importtype{SemVer}from"semver";
43
import{logPlugin}from"./debug";
54
importgetOptionSpecificExcludesForfrom"./get-option-specific-excludes";
65
import{removeUnnecessaryItems,removeUnsupportedItems}from"./filter-items";
@@ -27,13 +26,13 @@ import getTargets, {
2726
prettifyTargets,
2827
filterItems,
2928
isRequired,
30-
typeTargets,
31-
typeInputTargets,
3229
}from"@babel/helper-compilation-targets";
30+
importtype{Targets,InputTargets}from"@babel/helper-compilation-targets";
3331
importavailablePluginsfrom"./available-plugins";
3432
import{declare}from"@babel/helper-plugin-utils";
3533

36-
importtypeofModuleTransformationsTypefrom"./module-transformations";
34+
typeModuleTransformationsType=
35+
typeofimport("./module-transformations").default;
3736
importtype{BuiltInsOption,ModuleOption}from"./types";
3837

3938
// TODO: Remove in Babel 8
@@ -92,7 +91,7 @@ const getPlugin = (pluginName: string) => {
9291
returnplugin;
9392
};
9493

95-
exportconsttransformIncludesAndExcludes=(opts:Array<string>):Object=>{
94+
exportconsttransformIncludesAndExcludes=(opts:Array<string>):any=>{
9695
returnopts.reduce(
9796
(result,opt)=>{
9897
consttarget=opt.match(/^(es|es6|es7|esnext|web)\./)
@@ -116,14 +115,14 @@ export const getModulesPluginNames = ({
116115
shouldTransformDynamicImport,
117116
shouldTransformExportNamespaceFrom,
118117
shouldParseTopLevelAwait,
119-
}:{|
120-
modules:ModuleOption,
121-
transformations:ModuleTransformationsType,
122-
shouldTransformESM:boolean,
123-
shouldTransformDynamicImport:boolean,
124-
shouldTransformExportNamespaceFrom:boolean,
125-
shouldParseTopLevelAwait:boolean,
126-
|})=>{
118+
}:{
119+
modules:ModuleOption;
120+
transformations:ModuleTransformationsType;
121+
shouldTransformESM:boolean;
122+
shouldTransformDynamicImport:boolean;
123+
shouldTransformExportNamespaceFrom:boolean;
124+
shouldParseTopLevelAwait:boolean;
125+
})=>{
127126
constmodulesPluginNames=[];
128127
if(modules!==false&&transformations[modules]){
129128
if(shouldTransformESM){
@@ -173,15 +172,15 @@ export const getPolyfillPlugins = ({
173172
regenerator,
174173
debug,
175174
}:{
176-
useBuiltIns:BuiltInsOption,
177-
corejs:typeofSemVer|null|false,
178-
polyfillTargets:Targets,
179-
include:Set<string>,
180-
exclude:Set<string>,
181-
proposals:boolean,
182-
shippedProposals:boolean,
183-
regenerator:boolean,
184-
debug:boolean,
175+
useBuiltIns:BuiltInsOption;
176+
corejs:SemVer|null|false;
177+
polyfillTargets:Targets;
178+
include:Set<string>;
179+
exclude:Set<string>;
180+
proposals:boolean;
181+
shippedProposals:boolean;
182+
regenerator:boolean;
183+
debug:boolean;
185184
})=>{
186185
constpolyfillPlugins=[];
187186
if(useBuiltIns==="usage"||useBuiltIns==="entry"){
@@ -249,7 +248,7 @@ function getLocalTargets(
249248
`);
250249
}
251250

252-
returngetTargets((optionsTargets:InputTargets),{
251+
returngetTargets(optionsTargetsasInputTargets,{
253252
ignoreBrowserslistConfig,
254253
configPath,
255254
browserslistEnv,
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
//@flow
1+
typeAvailablePlugins=typeofimport("./available-plugins").default;
22

3-
importtypeofAvailablePluginsfrom"./available-plugins";
4-
5-
exportdefault({
3+
exportdefault{
64
auto:"transform-modules-commonjs",
75
amd:"transform-modules-amd",
86
commonjs:"transform-modules-commonjs",
97
cjs:"transform-modules-commonjs",
108
systemjs:"transform-modules-systemjs",
119
umd:"transform-modules-umd",
12-
}:{[transform:string]:$Keys<AvailablePlugins>});
10+
}as{[transform:string]:keyofAvailablePlugins};

‎packages/babel-preset-env/src/normalize-options.js‎renamed to ‎packages/babel-preset-env/src/normalize-options.ts‎

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
//@flow
21
importcorejs3Polyfillsfrom"core-js-compat/data.json";
3-
import{coerce,SemVer}from"semver";
2+
import{coerce}from"semver";
3+
importtype{SemVer}from"semver";
44
importcorejs2Polyfillsfrom"@babel/compat-data/corejs2-built-ins";
55
import{pluginsaspluginsList}from"./plugins-compat-data";
66
importmoduleTransformationsfrom"./module-transformations";
@@ -22,6 +22,8 @@ import type {
2222
PluginListOption,
2323
}from"./types";
2424

25+
declareconstPACKAGE_JSON:{name:string;version:string};
26+
2527
constv=newOptionValidator(PACKAGE_JSON.name);
2628

2729
constallPluginsList=Object.keys(pluginsList);
@@ -111,9 +113,10 @@ export const checkDuplicateIncludeExcludes = (
111113
);
112114
};
113115

114-
const normalizeTargets = (targets):$PropertyType<Options,"targets">=>{
116+
constnormalizeTargets=(targets):Options["targets"]=>{
115117
// TODO: Allow to use only query or strings as a targets from next breaking change.
116118
if(typeoftargets==="string"||Array.isArray(targets)){
119+
//@ts-expect-error
117120
return{browsers:targets};
118121
}
119122
return{ ...targets};
@@ -150,12 +153,12 @@ export const validateUseBuiltInsOption = (
150153
};
151154

152155
exporttypeNormalizedCorejsOption={
153-
proposals:boolean,
154-
version:typeofSemVer|null|false,
156+
proposals:boolean;
157+
version:SemVer|null|false;
155158
};
156159

157160
exportfunctionnormalizeCoreJSOption(
158-
corejs?:CorejsOption,
161+
corejs:CorejsOption|undefined|null,
159162
useBuiltIns:BuiltInsOption,
160163
):NormalizedCorejsOption{
161164
letproposals=false;
@@ -249,7 +252,7 @@ export default function normalizeOptions(opts: Options) {
249252
opts.ignoreBrowserslistConfig,
250253
false,
251254
),
252-
loose:v.validateBooleanOption(TopLevelOptions.loose,opts.loose),
255+
loose:v.validateBooleanOption<boolean>(TopLevelOptions.loose,opts.loose),
253256
modules:validateModulesOption(opts.modules),
254257
shippedProposals:v.validateBooleanOption(
255258
TopLevelOptions.shippedProposals,

‎packages/babel-preset-env/src/options.js‎renamed to ‎packages/babel-preset-env/src/options.ts‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
//@flow
2-
31
exportconstTopLevelOptions={
42
bugfixes:"bugfixes",
53
configPath:"configPath",
@@ -16,7 +14,7 @@ export const TopLevelOptions = {
1614
targets:"targets",
1715
useBuiltIns:"useBuiltIns",
1816
browserslistEnv:"browserslistEnv",
19-
};
17+
}asconst;
2018

2119
exportconstModulesOption={
2220
false:false,
@@ -26,10 +24,10 @@ export const ModulesOption = {
2624
cjs:"cjs",
2725
systemjs:"systemjs",
2826
umd:"umd",
29-
};
27+
}asconst;
3028

3129
exportconstUseBuiltInsOption={
3230
false:false,
3331
entry:"entry",
3432
usage:"usage",
35-
};
33+
}asconst;

‎packages/babel-preset-env/src/plugins-compat-data.js‎renamed to ‎packages/babel-preset-env/src/plugins-compat-data.ts‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
//@flow
2-
31
importpluginsfrom"@babel/compat-data/plugins";
42
importbugfixPluginsfrom"@babel/compat-data/plugin-bugfixes";
53
importavailablePluginsfrom"./available-plugins";

‎packages/babel-preset-env/src/polyfills/babel-polyfill.js‎renamed to ‎packages/babel-preset-env/src/polyfills/babel-polyfill.ts‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
//@flow
2-
31
import{getImportSource,getRequireSource,isPolyfillSource}from"./utils";
42

53
importtype{NodePath}from"@babel/traverse";
4+
import*astfrom"@babel/types";
65

76
constBABEL_POLYFILL_DEPRECATION=`
87
\`@babel/polyfill\` is deprecated. Please, use required parts of \`core-js\`
@@ -19,7 +18,7 @@ export default function (
1918
return{
2019
name:"preset-env/replace-babel-polyfill",
2120
visitor:{
22-
ImportDeclaration(path:NodePath){
21+
ImportDeclaration(path:NodePath<t.ImportDeclaration>){
2322
constsrc=getImportSource(path);
2423
if(usage&&isPolyfillSource(src)){
2524
// $FlowIgnore
@@ -40,7 +39,7 @@ export default function (
4039
}
4140
}
4241
},
43-
Program(path:NodePath){
42+
Program(path:NodePath<t.Program>){
4443
path.get("body").forEach(bodyPath=>{
4544
constsrc=getRequireSource(bodyPath);
4645
if(usage&&isPolyfillSource(src)){

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp