Skip to content
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
1 change: 1 addition & 0 deletions packages/typescript/src/api/node/node.generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ export class RemoteNode extends RemoteNodeBase implements Node {
}

private getChildAtOrder(order: number): RemoteNode | RemoteNodeList | undefined {
if (!this.hasChildren()) return undefined;
const mask = this.childMask;
if (!(mask & (1 << order))) {
// Property is not present
Expand Down
25 changes: 25 additions & 0 deletions packages/typescript/test/sync/ast.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type {
ExpressionStatement,
Identifier,
JSDoc,
Node,
NodeArray,
SourceFile,
Expand All @@ -12,6 +13,7 @@ import {
isClassDeclaration,
isImportDeclaration,
isInterfaceDeclaration,
isJSDocLink,
isNamedImports,
isValidTypeOnlyAliasUseSite,
SyntaxKind,
Expand Down Expand Up @@ -579,6 +581,29 @@ function getRemoteSourceFile(api: API, configPath: string, filePath: string) {
}

describe("RemoteNode + cloneNode", () => {
test("does not read a sibling as an invalid JSDoc link name", () => {
const api = spawnAPI({
"/tsconfig.json": "{}",
"/src/index.ts": `/**
* {@link #toggled} property
*/
export const x = 1;`,
});
try {
const sf = getRemoteSourceFile(api, "/tsconfig.json", "/src/index.ts");
const jsDoc = sf.statements[0].jsDoc?.[0] as JSDoc | undefined;
assert.ok(jsDoc?.kind === SyntaxKind.JSDoc);
const comment = jsDoc.comment;
assert.ok(typeof comment !== "string");
const link = comment?.[1];
assert.ok(link && isJSDocLink(link));
assert.strictEqual(link.name, undefined);
}
finally {
api.close();
}
});

test("uses distinct nodes for expression and type heritage", () => {
const api = spawnAPI({
"/tsconfig.json": "{}",
Expand Down
1 change: 1 addition & 0 deletions tools/scripts/tsc/generate-encoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1806,6 +1806,7 @@ function emitRemoteNodeClassOpen(w: CodeWriter) {
w.write(` }`);
w.write(``);
w.write(` private getChildAtOrder(order: number): RemoteNode | RemoteNodeList | undefined {`);
w.write(` if (!this.hasChildren()) return undefined;`);
w.write(` const mask = this.childMask;`);
w.write(` if (!(mask & (1 << order))) {`);
w.write(` // Property is not present`);
Expand Down
Loading