From 6163af9df16a8a043ae9907b626c65b4f62ba506 Mon Sep 17 00:00:00 2001 From: Justin Ridgewell Date: Tue, 26 Apr 2022 23:11:43 -0400 Subject: [PATCH] Fix types --- packages/babel-generator/src/buffer.ts | 21 +++------------------ packages/babel-generator/src/index.ts | 3 +++ 2 files changed, 6 insertions(+), 18 deletions(-) diff --git a/packages/babel-generator/src/buffer.ts b/packages/babel-generator/src/buffer.ts index df19975123ef..a6f6132c2b3f 100644 --- a/packages/babel-generator/src/buffer.ts +++ b/packages/babel-generator/src/buffer.ts @@ -2,21 +2,6 @@ import type SourceMap from "./source-map"; import type * as t from "@babel/types"; import * as charcodes from "charcodes"; -import type { - EncodedSourceMap, - DecodedSourceMap, - Mapping, -} from "@jridgewell/gen-mapping"; - -type Mutable = { -readonly [P in keyof T]: T[P] }; - -type Result = { - code: string; - map: Mutable | undefined | null; - decodedMap: DecodedSourceMap | undefined | null; - rawMappings: Mapping[] | null; -}; - const SPACES_RE = /^[ \t]+$/; export default class Buffer { constructor(map?: SourceMap | null) { @@ -53,11 +38,11 @@ export default class Buffer { * Get the final string output from the buffer, along with the sourcemap if one exists. */ - get(): Result { + get() { this._flush(); const map = this._map; - const result: Result = { + const result = { // Whatever trim is used here should not execute a regex against the // source string since it may be arbitrarily large after all transformations code: this._buf.trimRight(), @@ -66,7 +51,7 @@ export default class Buffer { // Encoding the sourcemap is moderately CPU expensive. get map() { - return (result.map = map?.get()); + return (result.map = map ? map.get() : null); }, set map(value) { Object.defineProperty(result, "map", { value, writable: true }); diff --git a/packages/babel-generator/src/index.ts b/packages/babel-generator/src/index.ts index 193740afaaed..42cdb0b76290 100644 --- a/packages/babel-generator/src/index.ts +++ b/packages/babel-generator/src/index.ts @@ -3,6 +3,7 @@ import Printer from "./printer"; import type * as t from "@babel/types"; import type { Format } from "./printer"; +import type { DecodedSourceMap, Mapping } from "@jridgewell/gen-mapping"; /** * Babel's code generator, turns an ast into code, maintaining sourcemaps, @@ -225,6 +226,8 @@ export interface GeneratorResult { mappings: string; file: string; } | null; + decodedMap: DecodedSourceMap | undefined; + rawMappings: Mapping[] | undefined; } /**