Skip to content

Commit

Permalink
This commit updates tsickle's JSDoc closure translation to
Browse files Browse the repository at this point in the history
not attempt translating/resolving enum members multiple times.

The double lookup was introduced back then with the TS 5.x bump.

This is important because in complex applications, this may be
extremely expensive, causing double expensive lookups searching all files and their exports in a `ts.Program`.

PiperOrigin-RevId: 626365165
  • Loading branch information
tsjs-language-eng authored and copybara-github committed May 6, 2024
1 parent d5c2921 commit efeee83
Show file tree
Hide file tree
Showing 223 changed files with 5,053 additions and 2,708 deletions.
2 changes: 1 addition & 1 deletion demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"dependencies": {
"minimist": "^1.2.3",
"tsickle": "file:../",
"typescript": "5.2.2"
"typescript": "5.4.2"
},
"devDependencies": {
"@types/minimist": "1.2.0",
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"out/src/*"
],
"peerDependencies": {
"typescript": "~5.1.5"
"typescript": "~5.4.2"
},
"devDependencies": {
"@types/diff-match-patch": "^1.0.32",
Expand All @@ -28,7 +28,7 @@
"source-map-support": "^0.5.19",
"tslib": "^2.2.0",
"tslint": "^6.1.3",
"typescript": "5.2.2"
"typescript": "5.4.2"
},
"scripts": {
"build": "tsc",
Expand Down
5 changes: 4 additions & 1 deletion src/annotator_host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ export interface AnnotatorHost {
* prefix to scope symbols in externs file (see externs.ts).
*/
export function moduleNameAsIdentifier(
host: AnnotatorHost, fileName: string, context = ''): string {
host: AnnotatorHost,
fileName: string,
context = '',
): string {
return host.pathToModuleName(context, fileName).replace(/\./g, '$');
}
15 changes: 11 additions & 4 deletions src/cli_support.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ export function assertAbsolute(fileName: string) {
* import and generates a googmodule module name for the imported module.
*/
export function pathToModuleName(
rootModulePath: string, context: string, fileName: string): string {
rootModulePath: string,
context: string,
fileName: string,
): string {
fileName = fileName.replace(/(\.d)?\.[tj]s$/, '');

if (fileName[0] === '.') {
Expand All @@ -37,7 +40,9 @@ export function pathToModuleName(
// TODO(evanm): various tests assume they can import relative paths like
// 'foo/bar' and have them interpreted as root-relative; preserve that here.
// Fix this by removing the next line.
if (!path.isAbsolute(fileName)) fileName = path.join(rootModulePath, fileName);
if (!path.isAbsolute(fileName)) {
fileName = path.join(rootModulePath, fileName);
}

// TODO(evanm): various tests assume they can pass in a 'fileName' like
// 'goog:foo.bar' and have this function do something reasonable.
Expand All @@ -50,8 +55,10 @@ export function pathToModuleName(
}

// Replace characters not supported by goog.module.
const moduleName =
fileName.replace(/\/|\\/g, '.').replace(/^[^a-zA-Z_$]/, '_').replace(/[^a-zA-Z0-9._$]/g, '_');
const moduleName = fileName
.replace(/\/|\\/g, '.')
.replace(/^[^a-zA-Z_$]/, '_')
.replace(/[^a-zA-Z0-9._$]/g, '_');

return moduleName;
}
4 changes: 2 additions & 2 deletions src/closure_externs.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ var ReadonlySet;
* @template T
* @extends {IThenable<T>}
*/
function PromiseLike() {};
function PromiseLike() {}

/** @typedef {function(new:Promise)} */
var PromiseConstructor;
Expand Down Expand Up @@ -94,7 +94,7 @@ var TemplateStringsArray;
var RegExpMatchArray;

/** @record */
function ImportMeta() {};
function ImportMeta() {}

// Representations for TS' EventMap objects.
// These are types that contain a mapping from event names to event object
Expand Down
Loading

0 comments on commit efeee83

Please sign in to comment.