feat(transformer/react-jsx): support @jsxImportSource annotation (#1179)

This commit is contained in:
Dunqing 2023-11-07 17:29:38 +08:00 committed by GitHub
parent f0e452a599
commit bf23d87848
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 4 deletions

View file

@ -56,12 +56,18 @@ impl ReactJsxOptions {
let comment = comment.strip_prefix('*').unwrap_or(comment).trim_start();
// strip leading `@`
let Some(comment) = comment.strip_prefix('@') else { continue };
// read jsxRuntime
match comment.strip_prefix("jsxRuntime").map(str::trim) {
Some("classic") => self.runtime = ReactJsxRuntime::Classic,
Some("automatic") => self.runtime = ReactJsxRuntime::Automatic,
_ => {}
}
// read jsxImportSource
if let Some(import_source) = comment.strip_prefix("jsxImportSource").map(str::trim) {
self.import_source = Cow::from(import_source.to_string());
}
}
self
}

View file

@ -1,4 +1,4 @@
Passed: 256/1113
Passed: 258/1113
# All Passed:
* babel-plugin-transform-numeric-separator
@ -825,14 +825,13 @@ Passed: 256/1113
* regression/11061/input.mjs
* variable-declaration/non-null-in-optional-chain/input.ts
# babel-plugin-transform-react-jsx (94/170)
# babel-plugin-transform-react-jsx (96/170)
* autoImport/after-polyfills-compiled-to-cjs/input.mjs
* autoImport/after-polyfills-script-not-supported/input.js
* autoImport/auto-import-react-source-type-module/input.js
* autoImport/auto-import-react-source-type-script/input.js
* autoImport/complicated-scope-module/input.js
* autoImport/complicated-scope-script/input.js
* autoImport/import-source-pragma/input.js
* pure/false-default-pragma-automatic-runtime/input.js
* pure/false-pragma-comment-automatic-runtime/input.js
* pure/false-pragma-comment-classic-runtime/input.js
@ -877,7 +876,6 @@ Passed: 256/1113
* react-automatic/does-not-add-source-self-automatic/input.mjs
* react-automatic/handle-nonstatic-children/input.js
* react-automatic/optimisation.react.constant-elements/input.js
* react-automatic/pragma-works-with-no-space-at-the-end/input.js
* react-automatic/should-add-quotes-es3/input.js
* react-automatic/should-allow-nested-fragments/input.js
* react-automatic/should-avoid-wrapping-in-extra-parens-if-not-needed/input.js