From dc5429e040528aa2b710d7a953e08d74498f2904 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Wed, 28 Oct 2020 10:45:58 +0100 Subject: [PATCH] chore: remove custom babel plugin for stripping namespaces (#10729) --- babel.config.js | 13 +++++++++++-- package.json | 1 - packages/expect/src/index.ts | 2 +- packages/jest-haste-map/src/index.ts | 2 +- packages/jest-jasmine2/src/index.ts | 2 +- packages/jest-mock/src/index.ts | 2 +- packages/jest-resolve-dependencies/src/index.ts | 2 +- packages/jest-resolve/src/index.ts | 2 +- packages/jest-runner/src/index.ts | 2 +- packages/jest-runtime/src/index.ts | 2 +- packages/jest-snapshot/src/index.ts | 2 +- packages/pretty-format/src/index.ts | 2 +- yarn.lock | 10 ---------- 13 files changed, 21 insertions(+), 23 deletions(-) diff --git a/babel.config.js b/babel.config.js index 686b452119e5..b0dc52a720ba 100644 --- a/babel.config.js +++ b/babel.config.js @@ -17,13 +17,22 @@ module.exports = { overrides: [ { plugins: [ - 'babel-plugin-typescript-strip-namespaces', 'babel-plugin-replace-ts-export-assignment', require.resolve( './scripts/babel-plugin-jest-replace-ts-require-assignment.js', ), ], - presets: ['@babel/preset-typescript'], + presets: [ + [ + '@babel/preset-typescript', + { + // will be the default in Babel 8, so let's just turn it on now + allowDeclareFields: true, + // will be default in the future, but we don't want to use it + allowNamespaces: false, + }, + ], + ], test: /\.tsx?$/, }, // we want this file to keep `import()`, so exclude the transform for it diff --git a/package.json b/package.json index 7969acafbd1a..1b869eefa1da 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,6 @@ "ansi-styles": "^4.2.0", "babel-eslint": "^10.0.3", "babel-plugin-replace-ts-export-assignment": "^0.0.2", - "babel-plugin-typescript-strip-namespaces": "^1.1.1", "camelcase": "^6.0.0", "chalk": "^4.0.0", "chokidar": "^3.3.0", diff --git a/packages/expect/src/index.ts b/packages/expect/src/index.ts index 8ded56ee97fb..a99571dbf8c5 100644 --- a/packages/expect/src/index.ts +++ b/packages/expect/src/index.ts @@ -421,7 +421,7 @@ expect.extractExpectedAssertionsErrors = extractExpectedAssertionsErrors; const expectExport = expect as Expect; -namespace expectExport { +declare namespace expectExport { export type MatcherState = JestMatcherState; export interface Matchers extends MatcherInterface {} } diff --git a/packages/jest-haste-map/src/index.ts b/packages/jest-haste-map/src/index.ts index f0e4aa25e605..37b2e292fae8 100644 --- a/packages/jest-haste-map/src/index.ts +++ b/packages/jest-haste-map/src/index.ts @@ -104,7 +104,7 @@ type Watcher = { type WorkerInterface = {worker: typeof worker; getSha1: typeof getSha1}; // TODO: Ditch namespace when this module exports ESM -namespace HasteMap { +declare namespace HasteMap { export type ModuleMap = HasteModuleMap; export type SerializableModuleMap = HasteSerializableModuleMap; export type FS = HasteFS; diff --git a/packages/jest-jasmine2/src/index.ts b/packages/jest-jasmine2/src/index.ts index 36567220b120..0e02a7569e00 100644 --- a/packages/jest-jasmine2/src/index.ts +++ b/packages/jest-jasmine2/src/index.ts @@ -220,7 +220,7 @@ const addSnapshotData = ( return results; }; -namespace jasmine2 { +declare namespace jasmine2 { export type Jasmine = JestJasmine; } diff --git a/packages/jest-mock/src/index.ts b/packages/jest-mock/src/index.ts index 948c31fcf59a..3d3dcd50e199 100644 --- a/packages/jest-mock/src/index.ts +++ b/packages/jest-mock/src/index.ts @@ -9,7 +9,7 @@ type Global = NodeJS.Global; // | Window – add once TS improves typings; -namespace JestMock { +declare namespace JestMock { export type ModuleMocker = ModuleMockerClass; export type MockFunctionMetadataType = | 'object' diff --git a/packages/jest-resolve-dependencies/src/index.ts b/packages/jest-resolve-dependencies/src/index.ts index 779040371ad8..ed6212e7bf14 100644 --- a/packages/jest-resolve-dependencies/src/index.ts +++ b/packages/jest-resolve-dependencies/src/index.ts @@ -11,7 +11,7 @@ import type {FS as HasteFS} from 'jest-haste-map'; import type {ResolveModuleConfig, ResolverType} from 'jest-resolve'; import {SnapshotResolver, isSnapshotPath} from 'jest-snapshot'; -namespace DependencyResolver { +declare namespace DependencyResolver { export type ResolvedModule = { file: Config.Path; dependencies: Array; diff --git a/packages/jest-resolve/src/index.ts b/packages/jest-resolve/src/index.ts index 2068632f84c1..d77ab35738a6 100644 --- a/packages/jest-resolve/src/index.ts +++ b/packages/jest-resolve/src/index.ts @@ -34,7 +34,7 @@ type FindNodeModuleConfig = { // TODO: replace with a Map in Jest 26 type BooleanObject = Record; -namespace Resolver { +declare namespace Resolver { export type ResolveModuleConfig = { skipNodeResolution?: boolean; paths?: Array; diff --git a/packages/jest-runner/src/index.ts b/packages/jest-runner/src/index.ts index 6b05a46417e6..73fe2ad539cc 100644 --- a/packages/jest-runner/src/index.ts +++ b/packages/jest-runner/src/index.ts @@ -34,7 +34,7 @@ interface WorkerInterface extends Worker { worker: typeof worker; } -namespace TestRunner { +declare namespace TestRunner { export type Test = JestTest; export type OnTestFailure = JestOnTestFailure; export type OnTestStart = JestOnTestStart; diff --git a/packages/jest-runtime/src/index.ts b/packages/jest-runtime/src/index.ts index 224fe024d25c..351f5dc3e9c6 100644 --- a/packages/jest-runtime/src/index.ts +++ b/packages/jest-runtime/src/index.ts @@ -107,7 +107,7 @@ const fromEntries: typeof Object.fromEntries = }, {}); }; -namespace Runtime { +declare namespace Runtime { export type Context = JestContext; // ditch this export when moving to esm - for now we need it for to avoid faulty type elision export type RuntimeType = Runtime; diff --git a/packages/jest-snapshot/src/index.ts b/packages/jest-snapshot/src/index.ts index adb03117d871..c8b62d08b9ee 100644 --- a/packages/jest-snapshot/src/index.ts +++ b/packages/jest-snapshot/src/index.ts @@ -560,7 +560,7 @@ const JestSnapshot = { utils, }; -namespace JestSnapshot { +declare namespace JestSnapshot { export type SnapshotResolver = JestSnapshotResolver; export type SnapshotStateType = SnapshotState; } diff --git a/packages/pretty-format/src/index.ts b/packages/pretty-format/src/index.ts index 1960daf96b41..aeef901e40ee 100644 --- a/packages/pretty-format/src/index.ts +++ b/packages/pretty-format/src/index.ts @@ -530,7 +530,7 @@ prettyFormat.plugins = { ReactTestComponent, }; -namespace prettyFormat { +declare namespace prettyFormat { export type Colors = PrettyFormat.Colors; export type Config = PrettyFormat.Config; export type Options = PrettyFormat.Options; diff --git a/yarn.lock b/yarn.lock index 83f715f706a7..88e1380fe069 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4839,15 +4839,6 @@ __metadata: languageName: node linkType: hard -"babel-plugin-typescript-strip-namespaces@npm:^1.1.1": - version: 1.1.1 - resolution: "babel-plugin-typescript-strip-namespaces@npm:1.1.1" - peerDependencies: - "@babel/core": ^7.0.0 - checksum: f0e59ea0d37bcf98cc7891db8f6089b1a1f2607e43ddc6a8c6b19ed782f1277f8f46998267e8ab636c12f8d0ed70194fb0a84ab610f4df463e1712e493002ee9 - languageName: node - linkType: hard - "babel-preset-current-node-syntax@npm:^0.1.3": version: 0.1.4 resolution: "babel-preset-current-node-syntax@npm:0.1.4" @@ -17152,7 +17143,6 @@ fsevents@^1.2.7: ansi-styles: ^4.2.0 babel-eslint: ^10.0.3 babel-plugin-replace-ts-export-assignment: ^0.0.2 - babel-plugin-typescript-strip-namespaces: ^1.1.1 camelcase: ^6.0.0 chalk: ^4.0.0 chokidar: ^3.3.0