Skip to content

Only use 'es2015.iterable' to avoid accidental es2015 feature usage. #28951

New issue

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

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

Already on GitHub? # to your account

Merged
merged 2 commits into from
Dec 11, 2018
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: 5 additions & 1 deletion src/compiler/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2165,6 +2165,10 @@ namespace ts {
}

export function fill<T>(length: number, cb: (index: number) => T): T[] {
return new Array(length).fill(0).map((_, i) => cb(i));
const result = Array<T>(length);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At least in V8 this causes the array to be considered "holey" and therefore it's not as optimized as packed arrays.
On the other hand repeatedly calling push needs to grow the backing store.

I'd say this is fine as is, as this function is only used in a single place in generateTypes.ts. So the holey array won't cause too much deoptimization where it's used. The alternative using push wouldn't be a problem either because the arrays are unlikely to contain more than a dozen elements.

for (let i = 0; i < length; i++) {
result[i] = cb(i);
}
return result;
}
}
2 changes: 1 addition & 1 deletion src/tsconfig-base.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"compilerOptions": {
"pretty": true,
"lib": ["es2015"],
"lib": ["es2015.iterable", "es5"],
"target": "es5",
"rootDir": ".",

Expand Down