fix(es/module): Resolve .jsx imports fully (#8936)

**Related issue:**

 - Closes #8935
This commit is contained in:
Donny/강동윤 2024-05-08 15:57:50 +09:00 committed by GitHub
parent 6021b47c25
commit c536d2ad6f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
15 changed files with 54 additions and 5 deletions

View File

@ -0,0 +1,6 @@
import React from "react";
var a = function(props) {
return /*#__PURE__*/ React.createElement("div", null);
};
a.propTypes = {};
export default a;

View File

@ -0,0 +1,13 @@
{
"module": {
"type": "es6",
"resolveFully": true
},
"jsc": {
"baseUrl": ".",
"parser": {
"syntax": "ecmascript",
"jsx": true
}
}
}

View File

@ -0,0 +1,5 @@
export function Button(props) {
return <button {...props} />;
}export function Button(props) {
return <button {...props} />;
}

View File

@ -0,0 +1,3 @@
export function greet() {
return "Hello";
}

View File

@ -0,0 +1,2 @@
export { greet } from "./greet";
export { Button } from "./button";

View File

@ -0,0 +1,6 @@
export function Button(props) {
return /*#__PURE__*/ React.createElement("button", props);
}
export function Button(props) {
return /*#__PURE__*/ React.createElement("button", props);
}

View File

@ -0,0 +1,3 @@
export function greet() {
return "Hello";
}

View File

@ -0,0 +1,2 @@
export { greet } from "./greet.js";
export { Button } from "./button.js";

View File

@ -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;

View File

@ -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 {

View File

@ -1 +1 @@
import "./src/rel.decorator";
import "./src/rel.decorator.js";

View File

@ -1,2 +1,2 @@
import boo from "./src/utils/shared/foo/boo";
import boo from "./src/utils/shared/foo/boo.js";
console.log(boo());

View File

@ -1 +1 @@
import "./src/rel.decorator";
import "./src/rel.decorator.js";

View File

@ -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));
}

View File

@ -1,4 +1,4 @@
import addFunction from "./add";
import addFunction from "./add.js";
async function main() {
console.log('2 + 3 =', addFunction(2, 3));
}