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 cmd/sourcerer/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v0.5.3
v0.5.4
8 changes: 7 additions & 1 deletion internal/parser/javascript.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,13 @@ var JavaScriptSpec = &LanguageSpec{
NameQuery: `(variable_declaration (variable_declarator name: (identifier) @name))`,
},
"export_statement": {
NameQuery: `(export_statement (declaration name: (identifier) @name))`,
NameQuery: `(export_statement [
(function_declaration name: (identifier) @name)
(generator_function_declaration name: (identifier) @name)
(class_declaration name: (identifier) @name)
(lexical_declaration (variable_declarator name: (identifier) @name))
(variable_declaration (variable_declarator name: (identifier) @name))
])`,
},
},
FoldIntoNextNode: []string{"comment"},
Expand Down
112 changes: 112 additions & 0 deletions internal/parser/javascript_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,48 @@ function* generator_function() {
startLine: 43,
endLine: 47,
},
{
name: "Exported Function",
path: "exported_function",
summary: "export function exported_function(input) {",
source: `// Exported functions
export function exported_function(input) {
return input.length > 0;
}`,
startLine: 49,
endLine: 52,
},
{
name: "Async Exported Function",
path: "async_exported_function",
summary: "export async function async_exported_function(data) {",
source: `export async function async_exported_function(data) {
return await Promise.resolve(data);
}`,
startLine: 54,
endLine: 56,
},
{
name: "Default Exported Function",
path: "default_exported_function",
summary: "export default function default_exported_function() {",
source: `export default function default_exported_function() {
return "default";
}`,
startLine: 58,
endLine: 60,
},
{
name: "Exported Generator",
path: "exported_generator",
summary: "export function* exported_generator() {",
source: `export function* exported_generator() {
yield "a";
yield "b";
}`,
startLine: 62,
endLine: 65,
},
}

for _, test := range tests {
Expand Down Expand Up @@ -246,6 +288,51 @@ class ClassWithPrivates {
startLine: 52,
endLine: 59,
},
{
name: "Exported Class",
path: "ExportedClass",
summary: "export class ExportedClass {",
source: `// Exported classes
export class ExportedClass {
constructor(value) {
this.value = value;
}

getValue() {
return this.value;
}
}`,
startLine: 61,
endLine: 70,
},
{
name: "Exported APIProvider",
path: "APIProvider",
summary: "export class APIProvider {",
source: `export class APIProvider {
constructor(name) {
this.name = name;
}

process() {
return ` + "`Processing: ${this.name}`" + `;
}
}`,
startLine: 72,
endLine: 80,
},
{
name: "Default Exported Plugin",
path: "DefaultPlugin",
summary: "export default class DefaultPlugin {",
source: `export default class DefaultPlugin {
constructor(config) {
this.config = config;
}
}`,
startLine: 82,
endLine: 86,
},
}

for _, test := range tests {
Expand Down Expand Up @@ -528,6 +615,31 @@ let {name, age} = person;`,
startLine: 47,
endLine: 47,
},
{
name: "Exported Const",
path: "EXPORTED_CONST",
summary: "export const EXPORTED_CONST = \"constant value\";",
source: `// Exported variables
export const EXPORTED_CONST = "constant value";`,
startLine: 49,
endLine: 50,
},
{
name: "Exported API_KEY",
path: "API_KEY",
summary: "export const API_KEY = \"api-key-12345\";",
source: `export const API_KEY = "api-key-12345";`,
startLine: 51,
endLine: 51,
},
{
name: "Exported Let",
path: "exported_let",
summary: "export let exported_let = 42;",
source: `export let exported_let = 42;`,
startLine: 52,
endLine: 52,
},
}

for _, test := range tests {
Expand Down
16 changes: 13 additions & 3 deletions internal/parser/typescript.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,25 @@ var TypeScriptSpec = &LanguageSpec{
"ambient_declaration": {
NameQuery: `(ambient_declaration (variable_declaration (variable_declarator name: (identifier) @name)))`,
},
"export_statement": {
NameQuery: `(export_statement (declaration name: (identifier) @name))`,
},
"enum_declaration": {
NameQuery: `(enum_declaration name: (identifier) @name)`,
},
"module": {
NameQuery: `(module name: (identifier) @name)`,
},
"export_statement": {
NameQuery: `(export_statement [
(function_declaration name: (identifier) @name)
(generator_function_declaration name: (identifier) @name)
(class_declaration name: (type_identifier) @name)
(abstract_class_declaration name: (type_identifier) @name)
(interface_declaration name: (type_identifier) @name)
(type_alias_declaration name: (type_identifier) @name)
(lexical_declaration (variable_declarator name: (identifier) @name))
(variable_declaration (variable_declarator name: (identifier) @name))
(enum_declaration name: (identifier) @name)
])`,
},
},
FoldIntoNextNode: []string{"comment"},
SkipTypes: []string{
Expand Down
171 changes: 171 additions & 0 deletions internal/parser/typescript_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,37 @@ function myFunc(x: number): string;`,
startLine: 64,
endLine: 65,
},
{
name: "Exported Function",
path: "exportedFunction",
summary: "export function exportedFunction(input: string): boolean {",
source: `// Exported functions
export function exportedFunction(input: string): boolean {
return input.length > 0;
}`,
startLine: 67,
endLine: 70,
},
{
name: "Async Exported Function",
path: "asyncExportedFunction",
summary: "export async function asyncExportedFunction(data: any): Promise<void> {",
source: `export async function asyncExportedFunction(data: any): Promise<void> {
await Promise.resolve(data);
}`,
startLine: 72,
endLine: 74,
},
{
name: "Exported Default Function",
path: "defaultExportedFunction",
summary: "export default function defaultExportedFunction(): string {",
source: `export default function defaultExportedFunction(): string {
return "default";
}`,
startLine: 76,
endLine: 78,
},
}

for _, test := range tests {
Expand Down Expand Up @@ -359,6 +390,53 @@ class BugReport {
startLine: 96,
endLine: 106,
},
{
name: "Exported Class",
path: "ExportedClass",
summary: "export class ExportedClass {",
source: `// Exported classes
export class ExportedClass {
private value: number;

constructor(value: number) {
this.value = value;
}

getValue(): number {
return this.value;
}
}`,
startLine: 108,
endLine: 119,
},
{
name: "Exported OpenRouterProvider",
path: "OpenRouterProvider",
summary: "export class OpenRouterProvider implements Processable {",
source: `export class OpenRouterProvider implements Processable {
name = "OpenRouter";

process(): void {
console.log("processing");
}
}`,
startLine: 121,
endLine: 127,
},
{
name: "Exported Default Class",
path: "TutorPlugin",
summary: "export default class TutorPlugin {",
source: `export default class TutorPlugin {
private config: any;

constructor(config: any) {
this.config = config;
}
}`,
startLine: 129,
endLine: 135,
},
}

for _, test := range tests {
Expand Down Expand Up @@ -523,6 +601,29 @@ interface MergedInterface {
startLine: 65,
endLine: 67,
},
{
name: "Exported Interface",
path: "ExportedInterface",
summary: "export interface ExportedInterface {",
source: `// Exported interfaces
export interface ExportedInterface {
id: string;
process(): void;
}`,
startLine: 69,
endLine: 73,
},
{
name: "Exported LLMProvider",
path: "LLMProvider",
summary: "export interface LLMProvider {",
source: `export interface LLMProvider {
name: string;
generate(prompt: string): Promise<string>;
}`,
startLine: 75,
endLine: 78,
},
}

for _, test := range tests {
Expand Down Expand Up @@ -723,6 +824,26 @@ type ConstrainedType<T extends Record<string, any>> = {
startLine: 61,
endLine: 65,
},
{
name: "Exported Type",
path: "ExportedType",
summary: "export type ExportedType = string | number;",
source: `// Exported types
export type ExportedType = string | number;`,
startLine: 67,
endLine: 68,
},
{
name: "Exported ConfigOptions",
path: "ConfigOptions",
summary: "export type ConfigOptions = {",
source: `export type ConfigOptions = {
enabled: boolean;
timeout: number;
};`,
startLine: 70,
endLine: 73,
},
}

for _, test := range tests {
Expand Down Expand Up @@ -865,6 +986,31 @@ namespace EnumNamespace {
startLine: 57,
endLine: 63,
},
{
name: "Exported Enum",
path: "ExportedEnum",
summary: "export enum ExportedEnum {",
source: `// Exported enums
export enum ExportedEnum {
Alpha = "alpha",
Beta = "beta",
Gamma = "gamma"
}`,
startLine: 65,
endLine: 70,
},
{
name: "Exported Status",
path: "Status",
summary: "export enum Status {",
source: `export enum Status {
Pending = "pending",
Active = "active",
Complete = "complete"
}`,
startLine: 72,
endLine: 76,
},
}

for _, test := range tests {
Expand Down Expand Up @@ -1440,6 +1586,31 @@ const readonly_array = [1, 2, 3] as const;`,
startLine: 67,
endLine: 67,
},
{
name: "Exported Const",
path: "EXPORTED_CONST",
summary: `export const EXPORTED_CONST = "constant value";`,
source: `// Exported variables
export const EXPORTED_CONST = "constant value";`,
startLine: 69,
endLine: 70,
},
{
name: "Exported VIEW_TYPE_REVIEW",
path: "VIEW_TYPE_REVIEW",
summary: `export const VIEW_TYPE_REVIEW = "tutor-review";`,
source: `export const VIEW_TYPE_REVIEW = "tutor-review";`,
startLine: 72,
endLine: 72,
},
{
name: "Exported Let",
path: "exportedLet",
summary: `export let exportedLet: number = 42;`,
source: `export let exportedLet: number = 42;`,
startLine: 74,
endLine: 74,
},
}

for _, test := range tests {
Expand Down
Loading