feat(transformer/react-jsx): support for throwing ImportSourceCannotBeSet error (#1224)

This commit is contained in:
Dunqing 2023-11-12 11:17:23 +08:00 committed by GitHub
parent b4ce2b5f9b
commit 39e608734f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 4 deletions

View file

@ -22,6 +22,11 @@ use crate::context::TransformerCtx;
#[diagnostic(severity(warning), help("Remove `pragma` and `pragmaFrag` options."))] #[diagnostic(severity(warning), help("Remove `pragma` and `pragmaFrag` options."))]
struct PragmaAndPragmaFragCannotBeSet; struct PragmaAndPragmaFragCannotBeSet;
#[derive(Debug, Error, Diagnostic)]
#[error("importSource cannot be set when runtime is classic.")]
#[diagnostic(severity(warning), help("Remove `importSource` option."))]
struct ImportSourceCannotBeSet;
#[derive(Debug, Error, Diagnostic)] #[derive(Debug, Error, Diagnostic)]
#[error("Namespace tags are not supported by default. React's JSX doesn't support namespace tags. You can set `throwIfNamespace: false` to bypass this warning.")] #[error("Namespace tags are not supported by default. React's JSX doesn't support namespace tags. You can set `throwIfNamespace: false` to bypass this warning.")]
#[diagnostic(severity(warning))] #[diagnostic(severity(warning))]
@ -129,6 +134,9 @@ impl<'a> ReactJsx<'a> {
pub fn add_react_jsx_runtime_imports(&mut self, program: &mut Program<'a>) { pub fn add_react_jsx_runtime_imports(&mut self, program: &mut Program<'a>) {
if self.options.runtime.is_classic() { if self.options.runtime.is_classic() {
if self.options.import_source != "react" {
self.ctx.error(ImportSourceCannotBeSet);
}
return; return;
} }

View file

@ -1,4 +1,4 @@
Passed: 273/1113 Passed: 275/1113
# All Passed: # All Passed:
* babel-plugin-transform-numeric-separator * babel-plugin-transform-numeric-separator
@ -852,7 +852,7 @@ Passed: 273/1113
* regression/11061/input.mjs * regression/11061/input.mjs
* variable-declaration/non-null-in-optional-chain/input.ts * variable-declaration/non-null-in-optional-chain/input.ts
# babel-plugin-transform-react-jsx (138/170) # babel-plugin-transform-react-jsx (140/170)
* autoImport/after-polyfills-compiled-to-cjs/input.mjs * autoImport/after-polyfills-compiled-to-cjs/input.mjs
* autoImport/complicated-scope-module/input.js * autoImport/complicated-scope-module/input.js
* react/adds-appropriate-newlines-when-using-spread-attribute-babel-7/input.js * react/adds-appropriate-newlines-when-using-spread-attribute-babel-7/input.js
@ -864,8 +864,6 @@ Passed: 273/1113
* react/optimisation.react.constant-elements/input.js * react/optimisation.react.constant-elements/input.js
* react/should-add-quotes-es3/input.js * react/should-add-quotes-es3/input.js
* react/should-disallow-spread-children/input.js * react/should-disallow-spread-children/input.js
* react/should-warn-when-importSource-is-set/input.js
* react/should-warn-when-importSource-pragma-is-set/input.js
* react/wraps-props-in-react-spread-for-first-spread-attributes-babel-7/input.js * react/wraps-props-in-react-spread-for-first-spread-attributes-babel-7/input.js
* react/wraps-props-in-react-spread-for-last-spread-attributes-babel-7/input.js * react/wraps-props-in-react-spread-for-last-spread-attributes-babel-7/input.js
* react/wraps-props-in-react-spread-for-middle-spread-attributes-babel-7/input.js * react/wraps-props-in-react-spread-for-middle-spread-attributes-babel-7/input.js