From a653b9c08ebb7547116c4c9c234016b7367cdbed Mon Sep 17 00:00:00 2001 From: Bogdan Savluk Date: Mon, 1 Mar 2021 16:44:23 +0100 Subject: [PATCH] Convert `@babel/helper-fixtures` to typescript (#12922) --- packages/babel-helper-fixtures/package.json | 4 ++ .../src/{index.js => index.ts} | 38 +++++++++++-------- yarn.lock | 9 +++++ 3 files changed, 35 insertions(+), 16 deletions(-) rename packages/babel-helper-fixtures/src/{index.js => index.ts} (94%) diff --git a/packages/babel-helper-fixtures/package.json b/packages/babel-helper-fixtures/package.json index dfa8a48f83..7076e72ce5 100644 --- a/packages/babel-helper-fixtures/package.json +++ b/packages/babel-helper-fixtures/package.json @@ -17,5 +17,9 @@ "dependencies": { "lodash": "^4.17.19", "semver": "condition:BABEL_8_BREAKING ? ^7.3.4 : ^6.3.0" + }, + "devDependencies": { + "@types/lodash": "^4.14.150", + "@types/semver": "^7.3.4" } } diff --git a/packages/babel-helper-fixtures/src/index.js b/packages/babel-helper-fixtures/src/index.ts similarity index 94% rename from packages/babel-helper-fixtures/src/index.js rename to packages/babel-helper-fixtures/src/index.ts index 6179414ba1..6c904c7965 100644 --- a/packages/babel-helper-fixtures/src/index.js +++ b/packages/babel-helper-fixtures/src/index.ts @@ -5,31 +5,34 @@ import fs from "fs"; const nodeVersion = semver.clean(process.version.slice(1)); -function humanize(val, noext) { +function humanize(val, noext?) { if (noext) val = path.basename(val, path.extname(val)); return val.replace(/-/g, " "); } type TestFile = { - loc: string, - code: string, - filename: string, + loc: string; + code: string; + filename: string; }; type Test = { - title: string, - disabled: boolean, - options: Object, - exec: TestFile, - actual: TestFile, - expected: TestFile, + title: string; + disabled: boolean; + options: any; + exec: TestFile; + actual: TestFile; + expected: TestFile; + // todo(flow->ts): improve types here + sourceMappings; + sourceMap; }; type Suite = { - options: Object, - tests: Array, - title: string, - filename: string, + options: any; + tests: Array; + title: string; + filename: string; }; function tryResolve(module) { @@ -60,7 +63,7 @@ function shouldIgnore(name, ignore?: Array) { const EXTENSIONS = [".js", ".mjs", ".ts", ".tsx"]; -function findFile(filepath: string, allowJSON: boolean) { +function findFile(filepath: string, allowJSON?: boolean) { const matches = []; for (const ext of EXTENSIONS.concat(allowJSON ? ".json" : [])) { @@ -148,6 +151,9 @@ function pushTask(taskName, taskDir, suite, suiteName) { code: readFile(expectLoc), filename: expectLocAlias, }, + sourceMappings: undefined, + sourceMap: undefined, + inputSourceMap: undefined, }; delete taskOpts.BABEL_8_BREAKING; @@ -293,7 +299,7 @@ function wrapPackagesArray(type, names, optionsDir) { * @returns {{}} options whose plugins/presets are resolved */ export function resolveOptionPluginOrPreset( - options: {}, + options: any, optionsDir: string, ): {} { if (options.plugins) { diff --git a/yarn.lock b/yarn.lock index 2a8cb3fe2b..dc280f1b04 100644 --- a/yarn.lock +++ b/yarn.lock @@ -520,6 +520,8 @@ __metadata: version: 0.0.0-use.local resolution: "@babel/helper-fixtures@workspace:packages/babel-helper-fixtures" dependencies: + "@types/lodash": ^4.14.150 + "@types/semver": ^7.3.4 lodash: ^4.17.19 semver: "condition:BABEL_8_BREAKING ? ^7.3.4 : ^6.3.0" languageName: unknown @@ -4087,6 +4089,13 @@ __metadata: languageName: node linkType: hard +"@types/semver@npm:^7.3.4": + version: 7.3.4 + resolution: "@types/semver@npm:7.3.4" + checksum: 7e8588aa55ecb344eda6954674b83a3c568d97d478e70e4617bd3ab22902590ac416ccf2cea48b58fb2f0fbd80f9ad1896332c9b3c3189ffd24e4350ff22094a + languageName: node + linkType: hard + "@types/source-map@npm:^0.5.0": version: 0.5.2 resolution: "@types/source-map@npm:0.5.2"