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
9 changes: 8 additions & 1 deletion napi/playground/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
/* auto-generated by NAPI-RS */
/* eslint-disable */

/** The WASI flavor this loader instantiates. */
export declare const __napiBindingTarget: 'wasm32-wasi'

export interface Comment {
type: 'Line' | 'Block'
value: string
Expand All @@ -24,8 +28,9 @@ export interface OxcError {
export declare const enum Severity {
Error = 'Error',
Warning = 'Warning',
Advice = 'Advice'
Advice = 'Advice',
}

export declare class Oxc {
ast: object
astJson: string
Expand Down Expand Up @@ -167,6 +172,8 @@ export interface OxcOptions {

export interface OxcParserOptions {
extension: string
/** Overrides the module kind inferred from the extension. */
sourceType?: 'script' | 'module' | 'commonjs' | 'unambiguous' | undefined
allowReturnOutsideFunction: boolean
preserveParens: boolean
allowV8Intrinsics: boolean
Expand Down
2 changes: 2 additions & 0 deletions napi/playground/playground.wasi.d.cts
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ export interface OxcOptions {

export interface OxcParserOptions {
extension: string
/** Overrides the module kind inferred from the extension. */
sourceType?: 'script' | 'module' | 'commonjs' | 'unambiguous' | undefined
allowReturnOutsideFunction: boolean
preserveParens: boolean
allowV8Intrinsics: boolean
Expand Down
1 change: 1 addition & 0 deletions napi/playground/scripts/patch.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { join as pathJoin } from "node:path";
import "./patch-wasi-browser.js";

const packageDir = pathJoin(import.meta.dirname, "..");
fs.copyFileSync(pathJoin(packageDir, "playground.wasi.d.cts"), pathJoin(packageDir, "index.d.ts"));
const path = pathJoin(packageDir, "playground.wasi-browser.js");

let data = fs.readFileSync(path, "utf-8");
Expand Down
5 changes: 2 additions & 3 deletions napi/playground/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ use oxc_linter::{
ConfigStore, ConfigStoreBuilder, ContextSubHost, ContextSubHostOptions, ExternalPluginStore,
LintOptions, Linter, ModuleRecord, Oxlintrc,
};
use oxc_napi::{Comment, OxcError, convert_utf8_to_utf16};
use oxc_napi::{Comment, OxcError, convert_utf8_to_utf16, get_source_type};
use oxc_transformer_plugins::{
InjectGlobalVariables, InjectGlobalVariablesConfig, InjectImport, ReplaceGlobalDefines,
ReplaceGlobalDefinesConfig,
Expand Down Expand Up @@ -123,9 +123,8 @@ impl Oxc {

// Setup path and source type
let filename = format!("test.{}", parser_options.extension);
let source_type = get_source_type(&filename, None, parser_options.source_type.as_deref());
let path = PathBuf::from(filename);
let source_type =
SourceType::from_path(&path).map_err(|e| napi::Error::from_reason(e.to_string()))?;

// Phase 1: Parse source
let (mut program, mut module_record) =
Expand Down
3 changes: 3 additions & 0 deletions napi/playground/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ pub struct OxcRunOptions {
#[derive(Default, Clone)]
pub struct OxcParserOptions {
pub extension: String,
/// Overrides the module kind inferred from the extension.
#[napi(ts_type = "'script' | 'module' | 'commonjs' | 'unambiguous' | undefined")]
pub source_type: Option<String>,
pub allow_return_outside_function: bool,
pub preserve_parens: bool,
pub allow_v8_intrinsics: bool,
Expand Down
Loading