fix(transformer): fix position of inserted react import statement (#1082)

This commit is contained in:
Boshen 2023-10-28 23:05:02 +08:00 committed by GitHub
parent 0856111bea
commit fe4a5ed535
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 5 deletions

View file

@ -95,7 +95,7 @@ impl<'a> ReactJsx<'a> {
let imports = self.ast.move_statement_vec(&mut self.imports);
let index = stmts
.iter()
.position(|stmt| matches!(stmt, Statement::ModuleDeclaration(m) if m.is_import()))
.rposition(|stmt| matches!(stmt, Statement::ModuleDeclaration(m) if m.is_import()))
.map_or(0, |i| i + 1);
stmts.splice(index..index, imports);
}

View file

@ -1,4 +1,4 @@
Passed: 224/1083
Passed: 226/1083
# All Passed:
* babel-plugin-transform-numeric-separator
@ -804,9 +804,7 @@ Passed: 224/1083
* regression/11061/input.mjs
* variable-declaration/non-null-in-optional-chain/input.ts
# babel-plugin-transform-react-jsx (75/172)
* autoImport/after-polyfills/input.mjs
* autoImport/after-polyfills-2/input.mjs
# babel-plugin-transform-react-jsx (77/172)
* 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