Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade TypeScript to 4.7.4 #6682

Merged
merged 25 commits into from
Oct 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .changeset/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
"firebase-repo-scripts-prune-dts"
],
"___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH": {
"onlyUpdatePeerDependentsWhenOutOfRange": true,
"useCalculatedVersionForSnapshots": true
"onlyUpdatePeerDependentsWhenOutOfRange": true
},
"snapshot": {
"useCalculatedVersion": true
}
}
50 changes: 50 additions & 0 deletions .changeset/fluffy-pumpkins-train.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
---
'@firebase/rules-unit-testing': patch
'@firebase/analytics': patch
'@firebase/analytics-compat': patch
'@firebase/analytics-interop-types': patch
'@firebase/analytics-types': patch
'@firebase/app': patch
'@firebase/app-check': patch
'@firebase/app-check-compat': patch
'@firebase/app-check-interop-types': patch
'@firebase/app-check-types': patch
'@firebase/app-compat': patch
'@firebase/app-types': patch
'@firebase/auth': patch
'@firebase/auth-compat': patch
'@firebase/auth-interop-types': patch
'@firebase/auth-types': patch
'@firebase/component': patch
'@firebase/database': patch
'@firebase/database-compat': patch
'@firebase/database-types': patch
'firebase': minor
'@firebase/firestore': patch
'@firebase/firestore-compat': patch
'@firebase/firestore-types': patch
'@firebase/functions': patch
'@firebase/functions-compat': patch
'@firebase/functions-types': patch
'@firebase/installations': patch
'@firebase/installations-compat': patch
'@firebase/installations-types': patch
'@firebase/logger': patch
'@firebase/messaging': patch
'@firebase/messaging-compat': patch
'@firebase/messaging-interop-types': patch
'@firebase/messaging-types': patch
'@firebase/performance': patch
'@firebase/performance-compat': patch
'@firebase/performance-types': patch
'@firebase/remote-config': patch
'@firebase/remote-config-compat': patch
'@firebase/remote-config-types': patch
'@firebase/storage': patch
'@firebase/storage-compat': patch
'@firebase/storage-types': patch
'@firebase/util': patch
'@firebase/webchannel-wrapper': patch
---

Upgrade TypeScript to 4.7.4.
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@
"@babel/core": "7.17.10",
"@babel/plugin-transform-modules-commonjs": "7.17.9",
"@babel/preset-env": "7.17.10",
"@babel/register": "7.17.7",
"@babel/preset-typescript": "7.16.7",
"@babel/register": "7.17.7",
"@changesets/changelog-github": "0.4.7",
"@changesets/cli": "2.25.0",
"@types/chai": "4.3.1",
Expand All @@ -75,23 +75,24 @@
"@types/clone": "2.1.1",
"@types/eslint": "7.29.0",
"@types/inquirer": "8.2.1",
"@types/js-yaml": "4.0.5",
"@types/listr": "0.14.4",
"@types/long": "4.0.2",
"@types/mocha": "9.1.1",
"@types/mz": "2.7.4",
"@types/node": "12.20.50",
"@types/request": "2.48.8",
"@types/sinon": "9.0.11",
"@types/sinon-chai": "3.2.8",
"@types/tmp": "0.2.3",
"@types/yargs": "17.0.13",
"@types/js-yaml": "4.0.5",
"@types/request": "2.48.8",
"@typescript-eslint/eslint-plugin": "4.33.0",
"@typescript-eslint/eslint-plugin-tslint": "4.33.0",
"@typescript-eslint/parser": "4.33.0",
"api-documenter-me": "0.1.1",
"api-extractor-me": "0.1.2",
"babel-loader": "8.2.5",
"babel-plugin-transform-import-meta": "2.1.1",
"chai": "4.3.6",
"chai-as-promised": "7.1.1",
"chalk": "4.1.2",
Expand Down Expand Up @@ -150,7 +151,7 @@
"ts-node": "10.9.1",
"tslint": "6.1.3",
"typedoc": "0.16.11",
"typescript": "4.2.2",
"typescript": "4.7.4",
"watch": "1.0.2",
"webpack": "4.46.0",
"yargs": "17.6.0"
Expand Down
66 changes: 41 additions & 25 deletions repo-scripts/prune-dts/prune-dts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ function maybeHideConstructor(
function prunePrivateImports<
T extends ts.InterfaceDeclaration | ts.ClassDeclaration
>(
factory: ts.NodeFactory,
program: ts.Program,
host: ts.CompilerHost,
sourceFile: ts.SourceFile,
Expand Down Expand Up @@ -233,13 +234,13 @@ function prunePrivateImports<

if (exportedTypes.length > 0) {
prunedHeritageClauses.push(
ts.updateHeritageClause(heritageClause, exportedTypes)
factory.updateHeritageClause(heritageClause, exportedTypes)
);
}
}

if (ts.isClassDeclaration(node)) {
return ts.updateClassDeclaration(
return factory.updateClassDeclaration(
node,
node.decorators,
node.modifiers,
Expand All @@ -252,7 +253,7 @@ function prunePrivateImports<
]
) as T;
} else if (ts.isInterfaceDeclaration(node)) {
return ts.updateInterfaceDeclaration(
return factory.updateInterfaceDeclaration(
node,
node.decorators,
node.modifiers,
Expand Down Expand Up @@ -339,11 +340,23 @@ function extractJSDocComment(
}
});

if (comments.length > 0) {
if (comments.length > 0 && symbol.declarations) {
const jsDocTags = ts.getJSDocTags(symbol.declarations[overloadCount]);
const maybeNewline = jsDocTags?.length > 0 ? '\n' : '';
const joinedComments = comments
.map(comment => {
if (comment.kind === 'linkText') {
return comment.text.trim();
}
return comment.text;
})
.join('');
const formattedComments = joinedComments
.replace('*', '\n')
.replace(' \n', '\n')
.replace('\n ', '\n');
return ts.factory.createJSDocComment(
comments[0].text + maybeNewline,
formattedComments + maybeNewline,
jsDocTags
);
}
Expand Down Expand Up @@ -399,19 +412,21 @@ function extractExportedSymbol(
// See if there is an exported symbol that extends this private symbol.
// In this case, we can safely use the public symbol instead.
for (const symbol of allExportedSymbols) {
for (const declaration of symbol.declarations) {
if (
ts.isClassDeclaration(declaration) ||
ts.isInterfaceDeclaration(declaration)
) {
for (const heritageClause of declaration.heritageClauses || []) {
for (const type of heritageClause.types || []) {
if (ts.isIdentifier(type.expression)) {
const subclassName = type.expression.escapedText;
if (subclassName === localSymbolName) {
// TODO: We may need to change this to return a Union type if
// more than one public type corresponds to the private type.
return symbol;
if (symbol.declarations) {
for (const declaration of symbol.declarations) {
if (
ts.isClassDeclaration(declaration) ||
ts.isInterfaceDeclaration(declaration)
) {
for (const heritageClause of declaration.heritageClauses || []) {
for (const type of heritageClause.types || []) {
if (ts.isIdentifier(type.expression)) {
const subclassName = type.expression.escapedText;
if (subclassName === localSymbolName) {
// TODO: We may need to change this to return a Union type if
// more than one public type corresponds to the private type.
return symbol;
}
}
}
}
Expand All @@ -425,8 +440,8 @@ function extractExportedSymbol(
// symbol. Note that this is not always safe as we might replace the local
// symbol with a less restrictive type.
const localSymbol = typeChecker.getSymbolAtLocation(typeName);
if (localSymbol) {
for (const declaration of localSymbol!.declarations) {
if (localSymbol?.declarations) {
for (const declaration of localSymbol.declarations) {
if (
ts.isClassDeclaration(declaration) ||
ts.isInterfaceDeclaration(declaration)
Expand All @@ -453,6 +468,7 @@ function dropPrivateApiTransformer(
context: ts.TransformationContext
): ts.Transformer<ts.SourceFile> {
const typeChecker = program.getTypeChecker();
const { factory } = context;

return (sourceFile: ts.SourceFile) => {
function visit(node: ts.Node): ts.Node {
Expand All @@ -469,7 +485,7 @@ function dropPrivateApiTransformer(
if (
!node.modifiers?.find(m => m.kind === ts.SyntaxKind.ExportKeyword)
) {
return ts.createToken(ts.SyntaxKind.WhitespaceTrivia);
return factory.createNotEmittedStatement(node);
}
}

Expand All @@ -482,7 +498,7 @@ function dropPrivateApiTransformer(
) {
// Remove any imports that reference internal APIs, while retaining
// their public members.
return prunePrivateImports(program, host, sourceFile, node);
return prunePrivateImports(factory, program, host, sourceFile, node);
} else if (
ts.isPropertyDeclaration(node) ||
ts.isMethodDeclaration(node) ||
Expand All @@ -491,7 +507,7 @@ function dropPrivateApiTransformer(
// Remove any class and interface members that are prefixed with
// underscores.
if (hasPrivatePrefix(node.name as ts.Identifier)) {
return ts.createToken(ts.SyntaxKind.WhitespaceTrivia);
return factory.createNotEmittedStatement(node);
}
} else if (ts.isTypeReferenceNode(node)) {
// For public types that refer internal types, find a public type that
Expand All @@ -502,9 +518,9 @@ function dropPrivateApiTransformer(
node.typeName
);
return publicName
? ts.updateTypeReferenceNode(
? factory.updateTypeReferenceNode(
node,
ts.createIdentifier(publicName.name),
factory.createIdentifier(publicName.name),
node.typeArguments
)
: node;
Expand Down
54 changes: 31 additions & 23 deletions scripts/build/create-overloads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ function keepPublicFunctionsTransformer(
return (sourceFile: ts.SourceFile) => {
const typeChecker = program.getTypeChecker();
const overloads: ts.Statement[] = [];
const { factory } = context;
function visit(node: ts.Node): ts.Node {
if (ts.isFunctionDeclaration(node)) {
// return early if the function doesn't have any parameter of the type we are looking for
Expand All @@ -137,7 +138,7 @@ function keepPublicFunctionsTransformer(
return false;
})
) {
return ts.createToken(ts.SyntaxKind.WhitespaceTrivia);
return factory.createNotEmittedStatement(node);
}

const newParameters = node.parameters.map(param => {
Expand All @@ -146,14 +147,14 @@ function keepPublicFunctionsTransformer(
if (
param.type.typeName.getText(sourceFile) === replaceOption.match
) {
return ts.updateParameter(
return factory.updateParameterDeclaration(
param,
param.decorators,
param.modifiers,
param.dotDotDotToken,
param.name,
param.questionToken,
ts.createTypeReferenceNode(
factory.createTypeReferenceNode(
replaceOption.replacement,
param.type.typeArguments
),
Expand All @@ -173,7 +174,7 @@ function keepPublicFunctionsTransformer(
});

overloads.push(
ts.updateFunctionDeclaration(
factory.updateFunctionDeclaration(
node,
node.decorators,
[],
Expand All @@ -189,7 +190,7 @@ function keepPublicFunctionsTransformer(

// remove all nodes other than the source file itself
if (!ts.isSourceFile(node)) {
return ts.createToken(ts.SyntaxKind.WhitespaceTrivia);
return factory.createNotEmittedStatement(node);
}

return node;
Expand All @@ -214,42 +215,49 @@ function keepPublicFunctionsTransformer(
}

// hardcode adding `import { FirebaseApp as FirebaseAppCompat } from '@firebase/app-compat'`
const appCompatImport = ts.createImportDeclaration(
const appCompatImport = factory.createImportDeclaration(
undefined,
undefined,
ts.createImportClause(
factory.createImportClause(
false,
undefined,
ts.createNamedImports([
ts.createImportSpecifier(
ts.createIdentifier('FirebaseApp'),
ts.createIdentifier('FirebaseAppCompat')
factory.createNamedImports([
factory.createImportSpecifier(
false,
factory.createIdentifier('FirebaseApp'),
factory.createIdentifier('FirebaseAppCompat')
)
])
),
ts.createLiteral('@firebase/app-compat')
factory.createStringLiteral('@firebase/app-compat')
);

const importStatement = ts.createImportDeclaration(
const importStatement = factory.createImportDeclaration(
undefined,
undefined,
ts.createImportClause(
factory.createImportClause(
false,
undefined,
ts.createNamedImports(
factory.createNamedImports(
Array.from(typesToImport).map(typeName =>
ts.createImportSpecifier(undefined, ts.createIdentifier(typeName))
factory.createImportSpecifier(
true,
undefined,
factory.createIdentifier(typeName)
)
)
)
),
ts.createLiteral(moduleNameToEnhance)
factory.createStringLiteral(moduleNameToEnhance)
);
const moduleToEnhance = ts.createModuleDeclaration(
const moduleToEnhance = factory.createModuleDeclaration(
undefined,
[ts.createModifier(ts.SyntaxKind.DeclareKeyword)],
ts.createStringLiteral(moduleNameToEnhance),
ts.createModuleBlock(overloads)
[factory.createModifier(ts.SyntaxKind.DeclareKeyword)],
factory.createStringLiteral(moduleNameToEnhance),
factory.createModuleBlock(overloads)
);

return ts.updateSourceFileNode(transformed, [
return factory.updateSourceFile(transformed, [
appCompatImport,
importStatement,
moduleToEnhance
Expand Down Expand Up @@ -302,7 +310,7 @@ function findTypes(
// include the type if it's not in the excludes list or a builtin type
if (!typesToIgnore.includes(typeName)) {
const symbol = typeCheck.getSymbolAtLocation(node.typeName);
const declaration = symbol?.declarations[0];
const declaration = symbol?.declarations?.[0];

// ignore type parameters.
if (!declaration || !ts.isTypeParameterDeclaration(declaration)) {
Expand Down
Loading