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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
> templates with type arguments (``sql<Row>`...` ``), `export type *`, `import("m").X[]`,
> keyword-named tuple labels and template-literal escapes no longer turn a declaration, and in
> large files the whole file, into a parse error that indexes as almost nothing. On Effect, Zod,
> Excalidraw and VS Code, the files that tsc accepts but the grammar rejects drop from 201 to 5
> Excalidraw and VS Code, the files that tsc accepts but the grammar rejects drop from 201 to 3
> (upstream [#3226](https://github.com/colbymchenry/codegraph/pull/3226)
> covers variance only; see `docs/grammars/tree-sitter-typescript.md`). Re-index TypeScript
> projects after updating.
Expand Down
22 changes: 22 additions & 0 deletions __tests__/fixtures/ts-syntax/asi-in-names.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Must keep parsing: identifiers starting with `in` after a line with no `;`
// (upstream #373), members named `in`, and `in` continuing an expression.
declare let in2: number, in$x: number, b: object;
let a = 1
in2 = 3
let c = 1
in$x = 4
export interface I {
a: string
in?: number
}
export interface J {
a(): void
in<T>(): T
}
export class K {
a: number = 1
b!: string
in!: number
}
export const d = "x"
in b
22 changes: 22 additions & 0 deletions __tests__/fixtures/ts-syntax/asi-in-names.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Must keep parsing: identifiers starting with `in` after a line with no `;`
// (upstream #373), members named `in`, and `in` continuing an expression.
declare let in2: number, in$x: number, b: object;
let a = 1
in2 = 3
let c = 1
in$x = 4
export interface I {
a: string
in?: number
}
export interface J {
a(): void
in<T>(): T
}
export class K {
a: number = 1
b!: string
in!: number
}
export const d = "x"
in b
9 changes: 9 additions & 0 deletions __tests__/fixtures/ts-syntax/for-var-in-newline.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
declare const o: any, x: any;
for (var k
in!o) {}
for (var k2
in!!x) {}
for (var k3
in!(x)) {}
for (var k4
in<any>o.p) {}
7 changes: 7 additions & 0 deletions __tests__/fixtures/ts-syntax/for-var-in-newline.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
declare const o: any, x: any;
for (var k
in!o) {}
for (var k2
in!!x) {}
for (var k3
in!(x)) {}
5 changes: 0 additions & 5 deletions __tests__/fixtures/ts-syntax/gap-unique-in-comparison.ts

This file was deleted.

5 changes: 0 additions & 5 deletions __tests__/fixtures/ts-syntax/gap-unique-in-comparison.tsx

This file was deleted.

12 changes: 12 additions & 0 deletions __tests__/fixtures/ts-syntax/in-member-after-arrow-field.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class K {
a = () => {}
in(): void {}
}
class L {
a = async () => {}
in() {}
}
class M {
a = (): number => { return 1 }
in(): void {}
}
12 changes: 12 additions & 0 deletions __tests__/fixtures/ts-syntax/in-member-after-arrow-field.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class K {
a = () => {}
in(): void {}
}
class L {
a = async () => {}
in() {}
}
class M {
a = (): number => { return 1 }
in(): void {}
}
8 changes: 8 additions & 0 deletions __tests__/fixtures/ts-syntax/in-member-space-paren.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class C {
a: number
in () {}
}
interface I {
a: number
in (): void
}
8 changes: 8 additions & 0 deletions __tests__/fixtures/ts-syntax/in-member-space-paren.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class C {
a: number
in () {}
}
interface I {
a: number
in (): void
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
declare const x: any, b: any, c: any;
class K {
a = x
in(b) ? 1 : 2
d = x
in(b, c)
? 1 : 2
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
declare const x: any, b: any, c: any;
class K {
a = x
in(b) ? 1 : 2
d = x
in(b, c)
? 1 : 2
}
13 changes: 13 additions & 0 deletions __tests__/fixtures/ts-syntax/in-paren-strings-comments.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
declare const x: any, b: any;
class K {
a = x
in("): ")
c = x
in(b /* ): */)
}
class M {
a = () => {}
in() /* c */ {}
b = () => {}
in(s = ")"): void {}
}
13 changes: 13 additions & 0 deletions __tests__/fixtures/ts-syntax/in-paren-strings-comments.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
declare const x: any, b: any;
class K {
a = x
in("): ")
c = x
in(b /* ): */)
}
class M {
a = () => {}
in() /* c */ {}
b = () => {}
in(s = ")"): void {}
}
2 changes: 2 additions & 0 deletions __tests__/fixtures/ts-syntax/unique-comment-line-separator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
declare const t: unique // c
 symbol;
declare const v: unique // c
 symbol;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
declare const t: unique // c
 symbol;
declare const v: unique // c
 symbol;
3 changes: 3 additions & 0 deletions __tests__/fixtures/ts-syntax/unique-comment-symbol.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
declare const a: number, unique: number;
const b = a < unique // the symbol
&& a;
3 changes: 3 additions & 0 deletions __tests__/fixtures/ts-syntax/unique-comment-symbol.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
declare const a: number, unique: number;
const b = a < unique // the symbol
&& a;
12 changes: 12 additions & 0 deletions __tests__/fixtures/ts-syntax/unique-identifier.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Must keep parsing: `unique` is a name everywhere except `unique symbol`.
declare const unique: string[];
for (let i = 0; i < unique.length; i++) {}
export const b = 1 < unique.length;
interface unique { a: 1 }
export type U = typeof unique;
export class D implements unique { a = 1 as const }
export type A = [unique: number, unique2?: string];
export declare const s: unique symbol;
export declare const t: readonly unique /* comment */ symbol[];
declare function f<T>(x: T): T;
export const r = f<typeof unique>([]);
12 changes: 12 additions & 0 deletions __tests__/fixtures/ts-syntax/unique-identifier.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Must keep parsing: `unique` is a name everywhere except `unique symbol`.
declare const unique: string[];
for (let i = 0; i < unique.length; i++) {}
export const b = 1 < unique.length;
interface unique { a: 1 }
export type U = typeof unique;
export class D implements unique { a = 1 as const }
export type A = [unique: number, unique2?: string];
export declare const s: unique symbol;
export declare const t: readonly unique /* comment */ symbol[];
declare function f<T>(x: T): T;
export const r = f<typeof unique>([]);
3 changes: 3 additions & 0 deletions __tests__/fixtures/ts-syntax/unique-symbol-unicode-space.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
declare const u: unique symbol;
declare const v: unique symbol;
declare const w: uniquesymbol;
3 changes: 3 additions & 0 deletions __tests__/fixtures/ts-syntax/unique-symbol-unicode-space.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
declare const u: unique symbol;
declare const v: unique symbol;
declare const w: uniquesymbol;
36 changes: 36 additions & 0 deletions __tests__/typescript-grammar-fork-shapes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,42 @@ describe('tuple labels named like type keywords', () => {
});
});

describe('unique as a name', () => {
it.each(LANGS)('%s: `unique` is a name everywhere except `unique symbol`', (language) => {
for (const src of [
'for (let i = 0; i < unique.length; i++) {}',
'type U = typeof unique;',
'class D implements unique {}',
'type A = [unique: T];',
'declare const s: readonly unique /* c */ symbol[];',
]) {
expect(parse(language, src).hasError, src).toBe(false);
}
const sym = parse(language, 'declare const s: unique symbol;').descendantsOfType('predefined_type');
expect(sym.map((n) => n.text)).toEqual(['unique symbol']);
});
});

describe('ASI before names starting with in', () => {
it.each(LANGS)('%s: in2 / in$x start a statement; `a\\n in(b)` stays the operator', (language) => {
const root = parse(language, 'let a = 1\nin2 = 3\nlet c = 1\nin$x = 4\nvar x = a\n in(b)');
expect(root.hasError).toBe(false);
expect(root.descendantsOfType('expression_statement')).toHaveLength(2);
expect(root.descendantsOfType('binary_expression').map((n) => n.child(1)!.type)).toEqual(['in']);
expect(calls(language, 'export function g() { return a\n in(b) }')).not.toContain('in');
});

// Silent before fork 9ce21f8: `in(b)` vanished (`a = x ? 1 : 2`), and no ERROR shows it.
it.each(LANGS)('%s: after a field initializer, `in(b) ? 1 : 2` keeps the `in` operator', (language) => {
const root = parse(language, 'class K {\n a = x\n in(b) ? 1 : 2\n c = x\n in(")") ? 1 : 2\n}');
expect(root.hasError).toBe(false);
const conds = root.descendantsOfType('ternary_expression').map((t) => t.childForFieldName('condition')!);
expect(conds.map((c) => c.type)).toEqual(['binary_expression', 'binary_expression']);
expect(conds.map((c) => c.child(1)!.type)).toEqual(['in', 'in']);
expect(root.descendantsOfType(['method_definition', 'method_signature'])).toHaveLength(0);
});
});

describe('typeof unique in type arguments', () => {
it.each(LANGS)('%s: f<typeof unique>(x) stays a generic call', (language) => {
const src = 'export function g() { return f<typeof unique>(1); }\ntype E = (typeof unique)[];';
Expand Down
6 changes: 3 additions & 3 deletions codegraph-kernel/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,9 @@ fn main() {
// the upstream repo so scanner.c's `../../common/scanner.h` resolves
// unedited. See docs/grammars/tree-sitter-typescript.md for what the base
// and the fork each fix.
// common/scanner.h 6bf2fd5994bc8a4b6777c5b8ee63fa2fbe5c206ec59b06cf398a9d78ae4c3142
// typescript/src/parser.c d4033c44e73006419f890b41780324c9bc26a2679e9045956210331a9d6d3c4a
// tsx/src/parser.c 5372712651e0d900af85fb760f358a7b0b39a3ef624f575d4952c84e5e2ff2a7
// common/scanner.h daa69422522f270cb38b7927ad8b35205222ce9b3094a40074fab00c3d673ee5
// typescript/src/parser.c 69145b216b33599dd0c1d3e67bf57c9bc9b63243c1f60503c702df679da2cc85
// tsx/src/parser.c c9cd43c6d10e969e7e586475a1dd02c5070284567dc7dc4784b6170831abdc93
// Flags crib the crate's bindings/rust/build.rs (c11). Each parser.c is
// ~9 MB.
for dialect in ["typescript", "tsx"] {
Expand Down
Loading
Loading