UNPKG

1.65 kBTypeScriptView Raw
1/**
2 * This file and its contents are due to an issue in TypeScript (affecting *at least* up to 4.1) which causes type
3 * elision to break during emit for nodes which have been transformed. Specifically, if the 'original' property is set,
4 * elision functionality no longer works.
5 *
6 * This results in module specifiers for types being output in import/export declarations in the compiled *JS files*
7 *
8 * The logic herein compensates for that issue by recreating type elision separately so that the transformer can update
9 * the clause with the properly elided information
10 *
11 * Issues:
12 * @see https://github.com/microsoft/TypeScript/issues/40603
13 * @see https://github.com/microsoft/TypeScript/issues/31446
14 *
15 * @example
16 * // a.ts
17 * export type A = string
18 * export const B = 2
19 *
20 * // b.ts
21 * import { A, B } from './b'
22 * export { A } from './b'
23 *
24 * // Expected output for b.js
25 * import { B } from './b'
26 *
27 * // Actual output for b.js
28 * import { A, B } from './b'
29 * export { A } from './b'
30 */
31import { ImportOrExportDeclaration, VisitorContext } from "../types";
32import { ExportDeclaration, ImportDeclaration } from "typescript";
33/**
34 * Get import / export clause for node (replicates TS elision behaviour for js files)
35 * See notes in get-import-export-clause.ts header for why this is necessary
36 *
37 * @returns import or export clause or undefined if it entire declaration should be elided
38 */
39export declare function elideImportOrExportClause<T extends ImportOrExportDeclaration>(context: VisitorContext, node: T): (T extends ImportDeclaration ? ImportDeclaration["importClause"] : ExportDeclaration["exportClause"]) | undefined;