Skip to content

Commit 9f40498

Browse files
committed
Renamed len function to length, with a fix to the prune-dts script
1 parent 1aa4051 commit 9f40498

File tree

5 files changed

+35
-4
lines changed

5 files changed

+35
-4
lines changed

packages/firestore/lite/pipelines/pipelines.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ export {
175175
currentTimestamp,
176176
ifAbsent,
177177
join,
178+
length,
178179
arraySum,
179180
AliasedExpression,
180181
Field,

packages/firestore/src/api_pipelines.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ export {
138138
log,
139139
sqrt,
140140
stringReverse,
141-
length as len,
141+
length,
142142
abs,
143143
concat,
144144
currentTimestamp,

packages/firestore/test/integration/api/pipeline.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ import {
132132
log,
133133
sqrt,
134134
stringReverse,
135-
len as length,
135+
length,
136136
abs,
137137
concat,
138138
currentTimestamp,

packages/firestore/test/lite/pipeline.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import { FirebaseError } from '@firebase/util';
2020
import { expect, use } from 'chai';
2121
import chaiAsPromised from 'chai-as-promised';
2222

23-
import { len as length } from '../../src/api_pipelines';
2423
import { Bytes } from '../../src/lite-api/bytes';
2524
import {
2625
Firestore,
@@ -68,6 +67,7 @@ import {
6867
isError,
6968
or,
7069
map,
70+
length,
7171
mod,
7272
documentId,
7373
equal,

repo-scripts/prune-dts/prune-dts.ts

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,21 @@ function dropPrivateApiTransformer(
564564
return (sourceFile: ts.SourceFile) => {
565565
const imports: Record<string, Array<string>> = {};
566566

567+
// Get exported symbols
568+
const directExportedSymbols = typeChecker.getExportsOfModule(
569+
typeChecker.getSymbolAtLocation(sourceFile)!
570+
);
571+
// Map exported symbols to aliases.
572+
// For the statement `export { X as Y };`, this list would contain a symbol
573+
// for `X`.
574+
const aliasedExportedSymbols = directExportedSymbols
575+
.map(symbol =>
576+
symbol.flags & ts.SymbolFlags.Alias
577+
? typeChecker.getAliasedSymbol(symbol)
578+
: undefined
579+
)
580+
.filter(symbol => symbol !== undefined);
581+
567582
function ensureImportsForFile(filename: string): Array<string> {
568583
let importsForFile = imports[filename];
569584
if (!importsForFile) {
@@ -584,12 +599,27 @@ function dropPrivateApiTransformer(
584599
ts.isEnumDeclaration(node)
585600
) {
586601
// Remove any types that are not exported.
602+
// First we check the modifiers for the symbol `export function X`. If
603+
// the export keyword is found, the symbol is modified.
604+
// Second we check if the symbol has an alias that is exported elsewhere,
605+
// for example: `function X; export { X as Y }`. If the alias is
606+
// exported elsewhere, then we also have to keep the symbol.
587607
if (
588608
!ts
589609
.getModifiers(node)
590610
?.find(m => m.kind === ts.SyntaxKind.ExportKeyword)
591611
) {
592-
return ts.factory.createNotEmittedStatement(node);
612+
// Try to get a symbol for this node.
613+
const symbol =
614+
'name' in node && node.name
615+
? typeChecker.getSymbolAtLocation(node.name)
616+
: undefined;
617+
// Check if that symbol is in the list of aliased exported symbols.
618+
// If it is, we keep the symbol. Otherwise, we remove the symbol.
619+
if (!symbol || !aliasedExportedSymbols.includes(symbol)) {
620+
// NO-OP block to keep the condition readable
621+
return ts.factory.createNotEmittedStatement(node);
622+
}
593623
}
594624
}
595625

0 commit comments

Comments
 (0)