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
1 change: 1 addition & 0 deletions crates/oxc_napi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ pub fn get_source_type(
Some("jsx") => SourceType::jsx(),
Some("ts") => SourceType::ts(),
Some("tsx") => SourceType::tsx(),
Some("dts") => SourceType::d_ts(),
_ => SourceType::from_path(filename).unwrap_or_default(),
};
match source_type {
Expand Down
4 changes: 2 additions & 2 deletions napi/parser/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ export declare const enum ImportNameKind {
export declare function parseAsync(filename: string, sourceText: string, options?: ParserOptions | undefined | null): Promise<ParseResult>

export interface ParserOptions {
/** Treat the source text as `js`, `jsx`, `ts`, or `tsx`. */
lang?: 'js' | 'jsx' | 'ts' | 'tsx'
/** Treat the source text as `js`, `jsx`, `ts`, `tsx` or `dts`. */
lang?: 'js' | 'jsx' | 'ts' | 'tsx' | 'dts'
/** Treat the source text as `script` or `module` code. */
sourceType?: 'script' | 'module' | 'unambiguous' | undefined
/**
Expand Down
4 changes: 2 additions & 2 deletions napi/parser/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use oxc_napi::{Comment, OxcError};
#[napi(object)]
#[derive(Default)]
pub struct ParserOptions {
/// Treat the source text as `js`, `jsx`, `ts`, or `tsx`.
#[napi(ts_type = "'js' | 'jsx' | 'ts' | 'tsx'")]
/// Treat the source text as `js`, `jsx`, `ts`, `tsx` or `dts`.
#[napi(ts_type = "'js' | 'jsx' | 'ts' | 'tsx' | 'dts'")]
pub lang: Option<String>,

/// Treat the source text as `script` or `module` code.
Expand Down
8 changes: 7 additions & 1 deletion napi/parser/test/parse.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Worker } from 'node:worker_threads';
import { describe, expect, it, test } from 'vitest';

import { parseAsync, parseSync } from '../index.js';
import type { ExpressionStatement, ParserOptions, TSTypeAliasDeclaration } from '../index.js';
import type { ExpressionStatement, ParserOptions, TSTypeAliasDeclaration, VariableDeclaration } from '../index.js';

describe('parse', () => {
const code = '/* comment */ foo';
Expand Down Expand Up @@ -55,6 +55,12 @@ describe('parse', () => {
// Parsed as `await 1`
expect((ret.program.body[0] as ExpressionStatement).expression.type).toBe('AwaitExpression');
});
test('sets lang as dts', () => {
const code = 'declare const foo';
const ret = parseSync('test', code, { lang: 'dts' });
expect(ret.errors.length).toBe(0);
expect((ret.program.body[0] as VariableDeclaration).declare).toBe(true);
});
});

describe('TS properties', () => {
Expand Down
4 changes: 2 additions & 2 deletions napi/transform/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -359,8 +359,8 @@ export declare function transform(filename: string, sourceText: string, options?
* @see {@link transform}
*/
export interface TransformOptions {
/** Treat the source text as `js`, `jsx`, `ts`, or `tsx`. */
lang?: 'js' | 'jsx' | 'ts' | 'tsx'
/** Treat the source text as `js`, `jsx`, `ts`, `tsx`, or `dts`. */
lang?: 'js' | 'jsx' | 'ts' | 'tsx' | 'dts'
/** Treat the source text as `script` or `module` code. */
sourceType?: 'script' | 'module' | 'unambiguous' | undefined
/**
Expand Down
4 changes: 2 additions & 2 deletions napi/transform/src/transformer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ pub struct TransformResult {
#[napi(object)]
#[derive(Default)]
pub struct TransformOptions {
/// Treat the source text as `js`, `jsx`, `ts`, or `tsx`.
#[napi(ts_type = "'js' | 'jsx' | 'ts' | 'tsx'")]
/// Treat the source text as `js`, `jsx`, `ts`, `tsx`, or `dts`.
#[napi(ts_type = "'js' | 'jsx' | 'ts' | 'tsx' | 'dts'")]
pub lang: Option<String>,

/// Treat the source text as `script` or `module` code.
Expand Down
2 changes: 0 additions & 2 deletions pnpm-lock.yaml

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

Loading