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

visitNodesWithoutCopyingPositions always makes a new NodeArray #59137

Merged
merged 2 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
fix checker call
  • Loading branch information
iisaduan committed Jul 3, 2024
commit 2761af77709cdd9703080781c2beca254b7db129
2 changes: 1 addition & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8980,7 +8980,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
if (result) {
if (result.pos !== -1 || result.end !== -1) {
if (result === nodes) {
result = factory.createNodeArray(nodes, nodes.hasTrailingComma);
result = factory.createNodeArray([...nodes], nodes.hasTrailingComma);
Copy link
Member

Choose a reason for hiding this comment

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

I believe slice() tends to be a little faster than spreading since engines have to do shenanigans to support non-array iterables.

Suggested change
result = factory.createNodeArray([...nodes], nodes.hasTrailingComma);
result = factory.createNodeArray(nodes.slice(), nodes.hasTrailingComma);

}
setTextRangePosEnd(result, -1, -1);
}
Expand Down
38 changes: 38 additions & 0 deletions tests/cases/fourslash/nodeArrayCloneCrash.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/// <reference path="fourslash.ts" />

// @module: preserve

// @Filename: /TLLineShape.ts
//// import { createShapePropsMigrationIds } from "./TLShape";
//// createShapePropsMigrationIds/**/

// @Filename: /TLShape.ts
//// import { T } from "@tldraw/validate";
////
//// /**
//// * @public
//// */
//// export function createShapePropsMigrationIds<T>(): { [k in keyof T]: any } {
//// return;
//// }

verify.completions({
marker: "",
includes: [
{
name: "createShapePropsMigrationIds",
text: "(alias) function createShapePropsMigrationIds<T>(): { [k in keyof T]: any; }\nimport createShapePropsMigrationIds",
tags: [{ name: "public", text: undefined }]
}
]
});

goTo.file("/TLShape.ts");
verify.organizeImports(
`
/**
* @public
*/
export function createShapePropsMigrationIds<T>(): { [k in keyof T]: any } {
return;
}`);