Skip to content

Commit

Permalink
Merge branch 'main' into 09-19-feat_isolated_declarations_add_stripin…
Browse files Browse the repository at this point in the history
…ternal_
  • Loading branch information
Dunqing authored Sep 19, 2024
2 parents c2d2749 + a07f03a commit f0b3b96
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 6 deletions.
5 changes: 5 additions & 0 deletions crates/oxc_semantic/src/post_transform_checker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ pub fn check_semantic_after_transform(
) -> Option<Vec<OxcDiagnostic>> {
let mut errors = Errors::default();

let source_type = program.source_type;
if !source_type.is_typescript_definition() && !source_type.is_javascript() {
errors.push(format!("SourceType is not javascript: {:?}", program.source_type));
}

// Collect `ScopeId`s, `SymbolId`s and `ReferenceId`s from AST after transformer
let scoping_after_transform =
Scoping { symbols: symbols_after_transform, scopes: scopes_after_transform };
Expand Down
16 changes: 16 additions & 0 deletions crates/oxc_span/src/source_type/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,14 @@ impl SourceType {
self
}

#[must_use]
pub const fn with_javascript(mut self, yes: bool) -> Self {
if yes {
self.language = Language::JavaScript;
}
self
}

#[must_use]
pub const fn with_typescript(mut self, yes: bool) -> Self {
if yes {
Expand All @@ -318,6 +326,14 @@ impl SourceType {
self
}

#[must_use]
pub const fn with_standard(mut self, yes: bool) -> Self {
if yes {
self.variant = LanguageVariant::Standard;
}
self
}

/// Converts a file [`Path`] to [`SourceType`].
///
/// ## Examples
Expand Down
3 changes: 3 additions & 0 deletions crates/oxc_transformer/src/react/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ impl<'a> React<'a> {

impl<'a> Traverse<'a> for React<'a> {
fn enter_program(&mut self, program: &mut Program<'a>, ctx: &mut TraverseCtx<'a>) {
if self.jsx_plugin {
program.source_type = program.source_type.with_standard(true);
}
if self.refresh_plugin {
self.refresh.enter_program(program, ctx);
}
Expand Down
1 change: 1 addition & 0 deletions crates/oxc_transformer/src/typescript/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ impl<'a> Traverse<'a> for TypeScript<'a> {
program.hashbang = None;
program.body.clear();
} else {
program.source_type = program.source_type.with_javascript(true);
self.namespace.enter_program(program, ctx);
}
}
Expand Down
8 changes: 5 additions & 3 deletions napi/transform/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export interface IsolatedDeclarationsResult {
/**
* Configure how TSX and JSX are transformed.
*
* @see [@babel/plugin-transform-react-jsx](https://babeljs.io/docs/babel-plugin-transform-react-jsx#options)
* @see {@link https://babeljs.io/docs/babel-plugin-transform-react-jsx#options}
*/
export interface ReactBindingOptions {
/**
Expand All @@ -59,7 +59,7 @@ export interface ReactBindingOptions {
*
* @default false
*
* @see [@babel/plugin-transform-react-jsx-development](https://babeljs.io/docs/babel-plugin-transform-react-jsx-development)
* @see {@link https://babeljs.io/docs/babel-plugin-transform-react-jsx-development}
*/
development?: boolean
/**
Expand All @@ -73,10 +73,12 @@ export interface ReactBindingOptions {
*/
throwIfNamespace?: boolean
/**
* Enables [@babel/plugin-transform-react-pure-annotations](https://babeljs.io/docs/en/babel-plugin-transform-react-pure-annotations).
* Enables `@babel/plugin-transform-react-pure-annotations`.
*
* It will mark top-level React method calls as pure for tree shaking.
*
* @see {@link https://babeljs.io/docs/en/babel-plugin-transform-react-pure-annotations}
*
* @default true
*/
pure?: boolean
Expand Down
10 changes: 7 additions & 3 deletions napi/transform/src/options.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(rustdoc::bare_urls)]

use std::path::PathBuf;

use napi::Either;
Expand Down Expand Up @@ -71,7 +73,7 @@ impl From<TypeScriptBindingOptions> for TypeScriptOptions {

/// Configure how TSX and JSX are transformed.
///
/// @see [@babel/plugin-transform-react-jsx](https://babeljs.io/docs/babel-plugin-transform-react-jsx#options)
/// @see {@link https://babeljs.io/docs/babel-plugin-transform-react-jsx#options}
#[napi(object)]
pub struct ReactBindingOptions {
/// Decides which runtime to use.
Expand All @@ -87,7 +89,7 @@ pub struct ReactBindingOptions {
///
/// @default false
///
/// @see [@babel/plugin-transform-react-jsx-development](https://babeljs.io/docs/babel-plugin-transform-react-jsx-development)
/// @see {@link https://babeljs.io/docs/babel-plugin-transform-react-jsx-development}
pub development: Option<bool>,

/// Toggles whether or not to throw an error if an XML namespaced tag name
Expand All @@ -99,10 +101,12 @@ pub struct ReactBindingOptions {
/// @default true
pub throw_if_namespace: Option<bool>,

/// Enables [@babel/plugin-transform-react-pure-annotations](https://babeljs.io/docs/en/babel-plugin-transform-react-pure-annotations).
/// Enables `@babel/plugin-transform-react-pure-annotations`.
///
/// It will mark top-level React method calls as pure for tree shaking.
///
/// @see {@link https://babeljs.io/docs/en/babel-plugin-transform-react-pure-annotations}
///
/// @default true
pub pure: Option<bool>,

Expand Down

0 comments on commit f0b3b96

Please sign in to comment.