Skip to main content
Module

x/deno2node/src/deps.deno.ts>SourceFile

Compile your Deno project to run on Node.js.
Go to Latest
class SourceFile
extends SourceFileBase<ts.SourceFile>
import { SourceFile } from "https://deno.land/x/deno2node@v1.7.1/src/deps.deno.ts";

Constructors

new
private
SourceFile()

Properties

private
_refreshFromFileSystemInternal

Methods

applyTextChanges(textChanges: ReadonlyArray<ts.TextChange | TextChange>): this

Applies the text changes to the source file.

WARNING! This will forget all the nodes in the file! It's best to do this after you're all done with the file.

copy(filePath: string, options?: SourceFileCopyOptions): SourceFile

Copy this source file to a new file.

This will modify the module specifiers in the new file, if necessary.

copyImmediately(filePath: string, options?: SourceFileCopyOptions): Promise<SourceFile>

Copy this source file to a new file and immediately saves it to the file system asynchronously.

This will modify the module specifiers in the new file, if necessary.

Copy this source file to a new file and immediately saves it to the file system synchronously.

This will modify the module specifiers in the new file, if necessary.

copyToDirectory(dirPathOrDirectory: string | Directory, options?: SourceFileCopyOptions): SourceFile

Copies this source file to the specified directory.

This will modify the module specifiers in the new file, if necessary.

delete(): void

Queues a deletion of the file to the file system.

The file will be deleted when you call ast.save(). If you wish to immediately delete the file, then use deleteImmediately().

deleteImmediately(): Promise<void>

Asynchronously deletes the file from the file system.

Synchronously deletes the file from the file system.

Asynchronously emits the source file as a JavaScript file.

Synchronously emits the source file as a JavaScript file.

fixMissingImports(formatSettings?: FormatCodeSettings, userPreferences?: UserPreferences): this

Code fix to add import declarations for identifiers that are referenced, but not imported in the source file.

fixUnusedIdentifiers(formatSettings?: FormatCodeSettings, userPreferences?: UserPreferences): this

Removes all unused declarations like interfaces, classes, enums, functions, variables, parameters, methods, properties, imports, etc. from this file.

Tip: For optimal results, sometimes this method needs to be called more than once. There could be nodes that are only referenced in unused declarations and in this case, another call will also remove them.

WARNING! This will forget all the nodes in the file! It's best to do this after you're all done with the file.

formatText(settings?: FormatCodeSettings): void

Formats the source file text using the internal TypeScript formatting API.

getBaseName(): string

Gets the file path's base name.

Gets the file path's base name without the extension.

Gets the directory that the source file is contained in.

Gets the directory path that the source file is contained in.

getEmitOutput(options?: { emitOnlyDtsFiles?: boolean; }): EmitOutput

Gets the emit output of this source file.

getExtension(): string

Gets the file path's extension.

Gets the file path.

getFullText(): string

Gets the full text with leading trivia.

Gets all the descendant string literals that reference a module.

Gets the language variant of the source file.

Gets the script target of the source file.

getLengthFromLineStartAtPos(pos: number): number

Gets the character count from the start of the line to the provided position.

Gets any /// <reference lib="..." /> comments.

getLineAndColumnAtPos(pos: number): { line: number; column: number; }

Gets the line and column number at the provided position (1-indexed).

Gets the string literals in this source file that references other source files.

Gets the nodes that reference other source files in string literals.

getParent(): NodeParentType<ts.SourceFile>
getParentOrThrow(message?: string | (() => string)): NonNullable<NodeParentType<ts.SourceFile>>

Gets any /// <reference path="..." /> comments.

Gets the pre-emit diagnostics of the specified source file.

Gets the source files this source file references in string literals.

Gets the string literals in other source files that reference this source file.

Gets the import and exports in other source files that reference this source file.

Gets any source files that reference this source file.

getRelativePathAsModuleSpecifierTo(filePath: string): string

Gets the relative path to the specified file path as a module specifier.

Gets the relative path to the specified source file as a module specifier.

Gets the relative path to the specified directory as a module specifier.

getRelativePathTo(fileOrDirPath: string): string

Gets the relative path to the specified path.

getRelativePathTo(sourceFile: SourceFile): string

Gets the relative path to another source file.

getRelativePathTo(directory: Directory): string

Gets the relative path to another directory.

Gets the script kind of the source file.

Gets the structure equivalent to this node.

Gets any /// <reference types="..." /> comments.

indent(pos: number, times?: number): this

Indents the line at the specified position.

indent(positionRange: [number, number], times?: number): this

Indents the lines within the specified range.

Gets if this is a declaration file.

Gets if the source file was discovered while loading an external library.

isInNodeModules(): boolean

Gets if the source file is a descendant of a node_modules directory.

isSaved(): boolean

Gets if this source file has been saved or if the latest changes have been saved.

move(filePath: string, options?: SourceFileMoveOptions): SourceFile

Moves this source file to a new file.

This will modify the module specifiers in other files that specify this file and the module specifiers in the current file, if necessary.

moveImmediately(filePath: string, options?: SourceFileMoveOptions): Promise<SourceFile>

Moves this source file to a new file and asynchronously updates the file system immediately.

This will modify the module specifiers in other files that specify this file and the module specifiers in the current file, if necessary.

Moves this source file to a new file and synchronously updates the file system immediately.

This will modify the module specifiers in other files that specify this file and the module specifiers in the current file, if necessary.

moveToDirectory(dirPathOrDirectory: string | Directory, options?: SourceFileMoveOptions): SourceFile

Moves this source file to the specified directory.

This will modify the module specifiers in other files that specify this file and the module specifiers in the current file, if necessary.

onModified(subscription: (sender: SourceFile) => void, subscribe?: boolean): this

Subscribe to when the source file is modified.

organizeImports(formatSettings?: FormatCodeSettings, userPreferences?: UserPreferences): this

Organizes the imports in the file.

WARNING! This will forget all the nodes in the file! It's best to do this after you're all done with the file.

Refresh the source file from the file system.

WARNING: When updating from the file system, this will "forget" any previously navigated nodes.

Synchronously refreshes the source file from the file system.

WARNING: When updating from the file system, this will "forget" any previously navigated nodes.

save(): Promise<void>

Asynchronously saves this file with any changes.

saveSync(): void

Synchronously saves this file with any changes.

set(structure: Partial<SourceFileStructure>): this

Sets the node from a structure.

unindent(pos: number, times?: number): this

Deindents the line at the specified position.

unindent(positionRange: [number, number], times?: number): this

Deindents the lines within the specified range.