mirror of
https://github.com/swc-project/swc.git
synced 2024-11-29 11:47:21 +03:00
fix(es/module): Resolve .jsx
imports fully (#8936)
**Related issue:** - Closes #8935
This commit is contained in:
parent
6021b47c25
commit
c536d2ad6f
@ -0,0 +1,6 @@
|
||||
import React from "react";
|
||||
var a = function(props) {
|
||||
return /*#__PURE__*/ React.createElement("div", null);
|
||||
};
|
||||
a.propTypes = {};
|
||||
export default a;
|
13
crates/swc/tests/fixture/issues-8xxx/8935/input/.swcrc
Normal file
13
crates/swc/tests/fixture/issues-8xxx/8935/input/.swcrc
Normal file
@ -0,0 +1,13 @@
|
||||
{
|
||||
"module": {
|
||||
"type": "es6",
|
||||
"resolveFully": true
|
||||
},
|
||||
"jsc": {
|
||||
"baseUrl": ".",
|
||||
"parser": {
|
||||
"syntax": "ecmascript",
|
||||
"jsx": true
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
export function Button(props) {
|
||||
return <button {...props} />;
|
||||
}export function Button(props) {
|
||||
return <button {...props} />;
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
export function greet() {
|
||||
return "Hello";
|
||||
}
|
@ -0,0 +1,2 @@
|
||||
export { greet } from "./greet";
|
||||
export { Button } from "./button";
|
@ -0,0 +1,6 @@
|
||||
export function Button(props) {
|
||||
return /*#__PURE__*/ React.createElement("button", props);
|
||||
}
|
||||
export function Button(props) {
|
||||
return /*#__PURE__*/ React.createElement("button", props);
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
export function greet() {
|
||||
return "Hello";
|
||||
}
|
@ -0,0 +1,2 @@
|
||||
export { greet } from "./greet.js";
|
||||
export { Button } from "./button.js";
|
@ -796,6 +796,7 @@ fn tests(input_dir: PathBuf) {
|
||||
|
||||
if !entry.file_name().to_string_lossy().ends_with(".ts")
|
||||
&& !entry.file_name().to_string_lossy().ends_with(".js")
|
||||
&& !entry.file_name().to_string_lossy().ends_with(".jsx")
|
||||
&& !entry.file_name().to_string_lossy().ends_with(".tsx")
|
||||
{
|
||||
continue;
|
||||
|
@ -173,6 +173,12 @@ where
|
||||
false
|
||||
};
|
||||
|
||||
let file_stem_matches = if let Some(stem) = target_path.file_stem() {
|
||||
stem == orig_filename
|
||||
} else {
|
||||
false
|
||||
};
|
||||
|
||||
if self.config.resolve_fully && is_resolved_as_js {
|
||||
} else if orig_filename == "index" {
|
||||
// Import: `./foo/index`
|
||||
@ -188,6 +194,8 @@ where
|
||||
// Resolved: `./foo/index.js`
|
||||
|
||||
target_path.pop();
|
||||
} else if is_resolved_as_non_js && self.config.resolve_fully && file_stem_matches {
|
||||
target_path.set_extension("js");
|
||||
} else if !is_resolved_as_js && !is_resolved_as_index && !is_exact {
|
||||
target_path.set_file_name(orig_filename);
|
||||
} else if is_resolved_as_non_js && is_exact {
|
||||
|
@ -1 +1 @@
|
||||
import "./src/rel.decorator";
|
||||
import "./src/rel.decorator.js";
|
||||
|
@ -1,2 +1,2 @@
|
||||
import boo from "./src/utils/shared/foo/boo";
|
||||
import boo from "./src/utils/shared/foo/boo.js";
|
||||
console.log(boo());
|
||||
|
@ -1 +1 @@
|
||||
import "./src/rel.decorator";
|
||||
import "./src/rel.decorator.js";
|
||||
|
@ -1,5 +1,5 @@
|
||||
async function main() {
|
||||
const addFunction = (await import("./add")).default // This doesn't work
|
||||
const addFunction = (await import("./add.js")).default // This doesn't work
|
||||
;
|
||||
console.log('2 + 3 =', addFunction(2, 3));
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
import addFunction from "./add";
|
||||
import addFunction from "./add.js";
|
||||
async function main() {
|
||||
console.log('2 + 3 =', addFunction(2, 3));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user