Skip to content

Commit

Permalink
feat(napi/parser): add MagicString
Browse files Browse the repository at this point in the history
  • Loading branch information
Boshen committed Nov 28, 2024
1 parent 6655345 commit d143ef8
Show file tree
Hide file tree
Showing 8 changed files with 289 additions and 35 deletions.
102 changes: 73 additions & 29 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions napi/parser/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ oxc_module_lexer = { workspace = true }

napi = { workspace = true, features = ["async"] }
napi-derive = { workspace = true }
self_cell = "1.0.4"
serde_json = { workspace = true }
string_wizard = { version = "0.0.22", features = ["source_map"] }

[package.metadata.cargo-shear]
ignored = ["napi"]
Expand Down
1 change: 1 addition & 0 deletions napi/parser/bindings.js
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,7 @@ if (!nativeBinding) {
throw new Error(`Failed to load native binding`)
}

module.exports.ParserBuilder = nativeBinding.ParserBuilder
module.exports.moduleLexerAsync = nativeBinding.moduleLexerAsync
module.exports.moduleLexerSync = nativeBinding.moduleLexerSync
module.exports.parseAsync = nativeBinding.parseAsync
Expand Down
26 changes: 25 additions & 1 deletion napi/parser/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,30 @@
/* eslint-disable */

export * from '@oxc-project/types';
/** A Parser instance that holds a MagicString. */
export declare class ParserBuilder {
constructor(sourceText: string)
/**
* # Panics
*
* * File extension is invalid
* * Serde JSON serialization
*/
parseSync(options?: ParserOptions | undefined | null): ParseResult
sourceText(start: number, end: number): string
toString(): string
len(): number
append(source: string): void
appendLeft(textIndex: number, content: string): void
appendRight(textIndex: number, content: string): void
indent(): void
prepend(source: string): void
prependLeft(textIndex: number, content: string): void
relocate(start: number, end: number, to: number): void
remove(start: number, end: number): void
update(start: number, end: number, content: string): void
}

export interface Comment {
type: 'Line' | 'Block'
value: string
Expand Down Expand Up @@ -89,7 +113,7 @@ export declare function moduleLexerSync(sourceText: string, options?: ParserOpti
/**
* # Panics
*
* * Tokio crashes
* * Internal runtime (tokio) crashes
*/
export declare function parseAsync(sourceText: string, options?: ParserOptions | undefined | null): Promise<ParseResult>

Expand Down
Loading

0 comments on commit d143ef8

Please sign in to comment.