Skip to content

Commit

Permalink
chore: wip
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisbbreuer committed Oct 29, 2024
1 parent 9be5305 commit 8fd07e8
Showing 11 changed files with 1,359 additions and 1,378 deletions.
31 changes: 31 additions & 0 deletions src/comments.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* Removes leading comments from code
*/
export function removeLeadingComments(code: string): string {
const lines = code.split('\n')
let index = 0
while (index < lines.length) {
const line = lines[index].trim()
if (line.startsWith('//') || line.startsWith('/*') || line.startsWith('*') || line === '') {
index++
}
else {
break
}
}
return lines.slice(index).join('\n')
}

/**
* Clean single line comments and whitespace from a string
*/
export function cleanComments(input: string): string {
return input
// Remove single line comments
.replace(/\/\/[^\n]*/g, '')
// Clean up empty lines that may be left after comment removal
.split('\n')
.map(line => line.trim())
.filter(Boolean)
.join('\n')
}
47 changes: 47 additions & 0 deletions src/create.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import type { ImportTrackingState, ProcessingState } from './types'

/**
* Creates initial processing state with empty collections
*/
export function createProcessingState(): ProcessingState {
return {
dtsLines: [],
imports: [],
usedTypes: new Set(),
typeSources: new Map(),
defaultExport: null,
exportAllStatements: [],
currentDeclaration: '',
lastCommentBlock: '',
bracketCount: 0,
isMultiLineDeclaration: false,
moduleImports: new Map(),
availableTypes: new Map(),
availableValues: new Map(),
currentIndentation: '',
declarationBuffer: null,
importTracking: createImportTrackingState(),
defaultExports: new Set(),
debug: {
exports: {
default: [],
named: [],
all: [],
},
declarations: [],
currentProcessing: '',
},
}
}

/**
* Creates initial import tracking state
*/
function createImportTrackingState(): ImportTrackingState {
return {
typeImports: new Map(),
valueImports: new Map(),
usedTypes: new Set(),
usedValues: new Set(),
}
}
Loading

0 comments on commit 8fd07e8

Please # to comment.