diff --git a/crates/rspack_plugin_javascript/src/visitors/dependency/common_js_export_scanner.rs b/crates/rspack_plugin_javascript/src/visitors/dependency/common_js_export_scanner.rs index 0a625268e9a..5c053180af6 100644 --- a/crates/rspack_plugin_javascript/src/visitors/dependency/common_js_export_scanner.rs +++ b/crates/rspack_plugin_javascript/src/visitors/dependency/common_js_export_scanner.rs @@ -96,6 +96,12 @@ impl Visit for CommonJsExportDependencyScanner<'_> { { return; } + // var a = exports/module.exports/this; + // Object.setPrototypeOf(exports/module.exports/this, a); + // ... + if self.is_exports_or_module_exports_or_this_expr(expr) { + self.bailout(); + } expr.visit_children_with(self); } @@ -114,12 +120,16 @@ impl Visit for CommonJsExportDependencyScanner<'_> { // const flagIt = () => { exports.__esModule = true }; => stmt_level = 2, last_stmt_is_expr_stmt = true // (exports.__esModule = true); => stmt_level = 1, last_stmt_is_expr_stmt = true self.stmt_level == 1 && self.last_stmt_is_expr_stmt, - &assign_expr.right, + Some(&assign_expr.right), ); + assign_expr.right.visit_children_with(self); + return; } // exports.xxx = 1; if self.is_exports_member_expr_start(expr) { self.enable(); + assign_expr.right.visit_children_with(self); + return; } if self.is_exports_or_module_exports_or_this_expr(expr) { self.enable(); @@ -135,14 +145,10 @@ impl Visit for CommonJsExportDependencyScanner<'_> { // this = {}; self.bailout(); } + assign_expr.right.visit_children_with(self); + return; } } - // var a = exports; - // var a = module.exports; - // var a = this; - if self.is_exports_or_module_exports_or_this_expr(&assign_expr.right) { - self.bailout(); - } assign_expr.visit_children_with(self); } @@ -151,15 +157,31 @@ impl Visit for CommonJsExportDependencyScanner<'_> { // Object.defineProperty(exports, "__esModule", { value: true }); // Object.defineProperty(module.exports, "__esModule", { value: true }); // Object.defineProperty(this, "__esModule", { value: true }); - if expr_matcher::is_object_define_property(expr) && let Some(ExprOrSpread { expr, .. }) = call_expr.args.get(0) && let Some(ExprOrSpread { expr: box Expr::Lit(Lit::Str(str)), .. }) = call_expr.args.get(1) && &str.value == "__esModule" && let Some(value) = get_value_of_property_description(&call_expr.args.get(2)) && self.is_exports_or_module_exports_or_this_expr(expr) { + if expr_matcher::is_object_define_property(expr) + && let Some(ExprOrSpread { expr, .. }) = call_expr.args.get(0) + && self.is_exports_or_module_exports_or_this_expr(expr) + && let Some(arg2) = call_expr.args.get(2) { self.enable(); - self.check_namespace(self.stmt_level == 1, value); + + if let Some(ExprOrSpread { expr: box Expr::Lit(Lit::Str(str)), .. }) = call_expr.args.get(1) + && str.value == "__esModule" { + self.check_namespace(self.stmt_level == 1, get_value_of_property_description(arg2)); + } + + self.enter_call += 1; + arg2.visit_children_with(self); + self.enter_call -= 1; + return; } // exports() // module.exports() // this() if self.is_exports_or_module_exports_or_this_expr(expr) { self.bailout(); + self.enter_call += 1; + call_expr.args.visit_children_with(self); + self.enter_call -= 1; + return; } } self.enter_call += 1; @@ -189,11 +211,11 @@ impl<'a> CommonJsExportDependencyScanner<'a> { matches!(expr, Expr::Ident(ident) if &ident.sym == "exports" && ident.span.ctxt == *self.unresolved_ctxt) } - fn check_namespace(&mut self, top_level: bool, value_expr: &Expr) { + fn check_namespace(&mut self, top_level: bool, value_expr: Option<&Expr>) { if matches!(self.parser_exports_state, Some(false)) || self.parser_exports_state.is_none() { return; } - if is_truthy_literal(value_expr) && top_level { + if let Some(value_expr) = value_expr && is_truthy_literal(value_expr) && top_level { self.set_flagged(); } else { self.set_dynamic(); @@ -241,13 +263,11 @@ impl<'a> CommonJsExportDependencyScanner<'a> { } } -fn get_value_of_property_description<'a>( - expr_or_spread: &Option<&'a ExprOrSpread>, -) -> Option<&'a Expr> { - if let Some(ExprOrSpread { +fn get_value_of_property_description(expr_or_spread: &ExprOrSpread) -> Option<&Expr> { + if let ExprOrSpread { expr: box Expr::Object(ObjectLit { props, .. }), .. - }) = expr_or_spread + } = expr_or_spread { for prop in props { if let PropOrSpread::Prop(prop) = prop && let Prop::KeyValue(key_value_prop) = &**prop && let PropName::Ident(ident) = &key_value_prop.key && &ident.sym == "value" { diff --git a/webpack-test/cases/json/data/test.filter.js b/webpack-test/cases/json/data/test.filter.js deleted file mode 100644 index 0e2d717f967..00000000000 --- a/webpack-test/cases/json/data/test.filter.js +++ /dev/null @@ -1,4 +0,0 @@ - -module.exports = () => {return true} - - \ No newline at end of file diff --git a/webpack-test/cases/json/default-default-with-concatenation/test.filter.js b/webpack-test/cases/json/default-default-with-concatenation/test.filter.js index 0557cb116c1..8a4ce83a7aa 100644 --- a/webpack-test/cases/json/default-default-with-concatenation/test.filter.js +++ b/webpack-test/cases/json/default-default-with-concatenation/test.filter.js @@ -1,4 +1,5 @@ +const { FilteredStatus } = require("../../../lib/util/filterUtil") -module.exports = () => {return false} +module.exports = () => {return [FilteredStatus.PARTIAL_PASS, "https://github.com/web-infra-dev/rspack/issues/3823"]} \ No newline at end of file diff --git a/webpack-test/cases/json/default-default/test.filter.js b/webpack-test/cases/json/default-default/test.filter.js deleted file mode 100644 index 0557cb116c1..00000000000 --- a/webpack-test/cases/json/default-default/test.filter.js +++ /dev/null @@ -1,4 +0,0 @@ - -module.exports = () => {return false} - - \ No newline at end of file diff --git a/webpack-test/cases/json/import-assertions-type-json/test.filter.js b/webpack-test/cases/json/import-assertions-type-json/test.filter.js index 0557cb116c1..d4ba32dcf3d 100644 --- a/webpack-test/cases/json/import-assertions-type-json/test.filter.js +++ b/webpack-test/cases/json/import-assertions-type-json/test.filter.js @@ -1,4 +1,4 @@ -module.exports = () => {return false} +module.exports = () => {return "https://github.com/web-infra-dev/rspack/issues/4358"} \ No newline at end of file diff --git a/webpack-test/cases/json/import-by-name-with-concatenation/test.filter.js b/webpack-test/cases/json/import-by-name-with-concatenation/test.filter.js index 0557cb116c1..00510295521 100644 --- a/webpack-test/cases/json/import-by-name-with-concatenation/test.filter.js +++ b/webpack-test/cases/json/import-by-name-with-concatenation/test.filter.js @@ -1,4 +1,5 @@ +const { FilteredStatus } = require("../../../lib/util/filterUtil") -module.exports = () => {return false} +module.exports = () => {return [FilteredStatus.PARTIAL_PASS, "https://github.com/web-infra-dev/rspack/issues/3823, https://github.com/web-infra-dev/rspack/issues/4323"]} \ No newline at end of file diff --git a/webpack-test/cases/json/import-by-name/test.filter.js b/webpack-test/cases/json/import-by-name/test.filter.js index 0557cb116c1..2735e947c45 100644 --- a/webpack-test/cases/json/import-by-name/test.filter.js +++ b/webpack-test/cases/json/import-by-name/test.filter.js @@ -1,4 +1,4 @@ -module.exports = () => {return false} +module.exports = () => {return "https://github.com/web-infra-dev/rspack/issues/4323"} \ No newline at end of file diff --git a/webpack-test/cases/json/import-lazy/test.filter.js b/webpack-test/cases/json/import-lazy/test.filter.js deleted file mode 100644 index 0557cb116c1..00000000000 --- a/webpack-test/cases/json/import-lazy/test.filter.js +++ /dev/null @@ -1,4 +0,0 @@ - -module.exports = () => {return false} - - \ No newline at end of file diff --git a/webpack-test/cases/json/import-with-default-with-concatenation/test.filter.js b/webpack-test/cases/json/import-with-default-with-concatenation/test.filter.js index 0557cb116c1..8a4ce83a7aa 100644 --- a/webpack-test/cases/json/import-with-default-with-concatenation/test.filter.js +++ b/webpack-test/cases/json/import-with-default-with-concatenation/test.filter.js @@ -1,4 +1,5 @@ +const { FilteredStatus } = require("../../../lib/util/filterUtil") -module.exports = () => {return false} +module.exports = () => {return [FilteredStatus.PARTIAL_PASS, "https://github.com/web-infra-dev/rspack/issues/3823"]} \ No newline at end of file diff --git a/webpack-test/cases/json/import-with-default/test.filter.js b/webpack-test/cases/json/import-with-default/test.filter.js deleted file mode 100644 index 0557cb116c1..00000000000 --- a/webpack-test/cases/json/import-with-default/test.filter.js +++ /dev/null @@ -1,4 +0,0 @@ - -module.exports = () => {return false} - - \ No newline at end of file diff --git a/webpack-test/cases/json/prototype-methods/test.filter.js b/webpack-test/cases/json/prototype-methods/test.filter.js deleted file mode 100644 index 0557cb116c1..00000000000 --- a/webpack-test/cases/json/prototype-methods/test.filter.js +++ /dev/null @@ -1,4 +0,0 @@ - -module.exports = () => {return false} - - \ No newline at end of file diff --git a/webpack-test/cases/json/reexport/test.filter.js b/webpack-test/cases/json/reexport/test.filter.js index 0557cb116c1..cadab58b611 100644 --- a/webpack-test/cases/json/reexport/test.filter.js +++ b/webpack-test/cases/json/reexport/test.filter.js @@ -1,4 +1,5 @@ +const { FilteredStatus } = require("../../../lib/util/filterUtil") -module.exports = () => {return false} +module.exports = () => {return [FilteredStatus.PARTIAL_PASS, "https://github.com/web-infra-dev/rspack/issues/4323"]} \ No newline at end of file diff --git a/webpack-test/cases/json/weird-properties/test.filter.js b/webpack-test/cases/json/weird-properties/test.filter.js deleted file mode 100644 index 0557cb116c1..00000000000 --- a/webpack-test/cases/json/weird-properties/test.filter.js +++ /dev/null @@ -1,4 +0,0 @@ - -module.exports = () => {return false} - - \ No newline at end of file diff --git a/webpack-test/cases/large/big-assets/index.js b/webpack-test/cases/large/big-assets/index.js index 106c4f2c339..81ac4ad5083 100644 --- a/webpack-test/cases/large/big-assets/index.js +++ b/webpack-test/cases/large/big-assets/index.js @@ -1,4 +1,4 @@ -const createHash = require("../../../../lib/util/hash/xxhash64"); +const createHash = require("@rspack/core/dist/util/hash/xxhash64"); const fs = require("fs"); const h = url => { diff --git a/webpack-test/cases/large/big-assets/test.filter.js b/webpack-test/cases/large/big-assets/test.filter.js index 6fb7deae5b2..3647ce9c8b0 100644 --- a/webpack-test/cases/large/big-assets/test.filter.js +++ b/webpack-test/cases/large/big-assets/test.filter.js @@ -5,6 +5,6 @@ module.exports = function (config) { }; */ -module.exports = () => {return false} +module.exports = () => {return "https://github.com/web-infra-dev/rspack/issues/3180"} \ No newline at end of file diff --git a/webpack-test/cases/large/many-replacements/test.filter.js b/webpack-test/cases/large/many-replacements/test.filter.js index 6fb7deae5b2..1ae95bcd901 100644 --- a/webpack-test/cases/large/many-replacements/test.filter.js +++ b/webpack-test/cases/large/many-replacements/test.filter.js @@ -5,6 +5,6 @@ module.exports = function (config) { }; */ -module.exports = () => {return false} +module.exports = () => {return "https://github.com/web-infra-dev/rspack/issues/4396"} \ No newline at end of file diff --git a/webpack-test/cases/loaders/async/test.filter.js b/webpack-test/cases/loaders/async/test.filter.js deleted file mode 100644 index 0e2d717f967..00000000000 --- a/webpack-test/cases/loaders/async/test.filter.js +++ /dev/null @@ -1,4 +0,0 @@ - -module.exports = () => {return true} - - \ No newline at end of file diff --git a/webpack-test/cases/loaders/coffee-loader/test.filter.js b/webpack-test/cases/loaders/coffee-loader/test.filter.js index 0557cb116c1..801a0693f49 100644 --- a/webpack-test/cases/loaders/coffee-loader/test.filter.js +++ b/webpack-test/cases/loaders/coffee-loader/test.filter.js @@ -1,4 +1,4 @@ -module.exports = () => {return false} +module.exports = () => {return "https://github.com/web-infra-dev/rspack/issues/4396"} \ No newline at end of file diff --git a/webpack-test/cases/loaders/context/test.filter.js b/webpack-test/cases/loaders/context/test.filter.js index c62d7f60e0c..4dbfb2fa557 100644 --- a/webpack-test/cases/loaders/context/test.filter.js +++ b/webpack-test/cases/loaders/context/test.filter.js @@ -7,6 +7,6 @@ module.exports = config => { }; */ -module.exports = () => {return false} +module.exports = () => {return "https://github.com/web-infra-dev/rspack/issues/4397"} \ No newline at end of file diff --git a/webpack-test/cases/loaders/css-loader/test.filter.js b/webpack-test/cases/loaders/css-loader/test.filter.js deleted file mode 100644 index 0e2d717f967..00000000000 --- a/webpack-test/cases/loaders/css-loader/test.filter.js +++ /dev/null @@ -1,4 +0,0 @@ - -module.exports = () => {return true} - - \ No newline at end of file diff --git a/webpack-test/cases/loaders/import-module/test.filter.js b/webpack-test/cases/loaders/import-module/test.filter.js index 937ca57009c..566c410a79e 100644 --- a/webpack-test/cases/loaders/import-module/test.filter.js +++ b/webpack-test/cases/loaders/import-module/test.filter.js @@ -5,6 +5,6 @@ module.exports = config => { }; */ -module.exports = () => {return false} +module.exports = () => {return "https://github.com/web-infra-dev/rspack/issues/4398"} \ No newline at end of file diff --git a/webpack-test/cases/loaders/json-loader/test.filter.js b/webpack-test/cases/loaders/json-loader/test.filter.js deleted file mode 100644 index 0e2d717f967..00000000000 --- a/webpack-test/cases/loaders/json-loader/test.filter.js +++ /dev/null @@ -1,4 +0,0 @@ - -module.exports = () => {return true} - - \ No newline at end of file diff --git a/webpack-test/cases/loaders/less-loader/test.filter.js b/webpack-test/cases/loaders/less-loader/test.filter.js deleted file mode 100644 index 0e2d717f967..00000000000 --- a/webpack-test/cases/loaders/less-loader/test.filter.js +++ /dev/null @@ -1,4 +0,0 @@ - -module.exports = () => {return true} - - \ No newline at end of file diff --git a/webpack-test/cases/loaders/module-description-file/test.filter.js b/webpack-test/cases/loaders/module-description-file/test.filter.js deleted file mode 100644 index 7961ae75898..00000000000 --- a/webpack-test/cases/loaders/module-description-file/test.filter.js +++ /dev/null @@ -1,4 +0,0 @@ - -module.exports = () => {return "blocked by https://github.com/web-infra-dev/rspack/issues/3737"} - - \ No newline at end of file diff --git a/webpack-test/cases/loaders/pug-loader/test.filter.js b/webpack-test/cases/loaders/pug-loader/test.filter.js index cf024c8d760..35e7eb878cc 100644 --- a/webpack-test/cases/loaders/pug-loader/test.filter.js +++ b/webpack-test/cases/loaders/pug-loader/test.filter.js @@ -1,12 +1,5 @@ - -/* const supportsRequireInModule = require("../../../helpers/supportsRequireInModule"); module.exports = config => { return !config.module || supportsRequireInModule(); }; - -*/ -module.exports = () => {return true} - - \ No newline at end of file diff --git a/webpack-test/cases/loaders/query/test.filter.js b/webpack-test/cases/loaders/query/test.filter.js index 930866336f1..083dd3e5e5d 100644 --- a/webpack-test/cases/loaders/query/test.filter.js +++ b/webpack-test/cases/loaders/query/test.filter.js @@ -1,5 +1,3 @@ +const { FilteredStatus } = require("../../../lib/util/filterUtil") -// Didn't turn on every cases -module.exports = () => {return true} - - \ No newline at end of file +module.exports = () => {return [FilteredStatus.PARTIAL_PASS, "https://github.com/web-infra-dev/rspack/issues/3180, https://github.com/web-infra-dev/rspack/issues/4397"]} diff --git a/webpack-test/cases/loaders/raw-loader/test.filter.js b/webpack-test/cases/loaders/raw-loader/test.filter.js deleted file mode 100644 index 0e2d717f967..00000000000 --- a/webpack-test/cases/loaders/raw-loader/test.filter.js +++ /dev/null @@ -1,4 +0,0 @@ - -module.exports = () => {return true} - - \ No newline at end of file diff --git a/webpack-test/cases/loaders/resolve/test.filter.js b/webpack-test/cases/loaders/resolve/test.filter.js index 11252c2ccb6..9d8b25bfd46 100644 --- a/webpack-test/cases/loaders/resolve/test.filter.js +++ b/webpack-test/cases/loaders/resolve/test.filter.js @@ -1,4 +1,4 @@ -module.exports = () => {return "Rspack does not support resolving a virtual resource with only loader available, see: query test"} +module.exports = () => {return "https://github.com/web-infra-dev/rspack/issues/3180"} \ No newline at end of file diff --git a/webpack-test/cases/loaders/utils/test.filter.js b/webpack-test/cases/loaders/utils/test.filter.js index 1866bde3fbf..f2b579d55d6 100644 --- a/webpack-test/cases/loaders/utils/test.filter.js +++ b/webpack-test/cases/loaders/utils/test.filter.js @@ -1,4 +1,4 @@ -module.exports = () => {return "blocked by context support for loader"} +module.exports = () => {return "https://github.com/web-infra-dev/rspack/issues/4397"} \ No newline at end of file diff --git a/webpack-test/cases/mjs/no-module-main-field/node_modules/m/a.js b/webpack-test/cases/mjs/no-module-main-field/node_modules/m/a.js new file mode 100644 index 00000000000..b43605e3975 --- /dev/null +++ b/webpack-test/cases/mjs/no-module-main-field/node_modules/m/a.js @@ -0,0 +1 @@ +export default "yep"; diff --git a/webpack-test/cases/mjs/no-module-main-field/node_modules/m/a.mjs b/webpack-test/cases/mjs/no-module-main-field/node_modules/m/a.mjs new file mode 100644 index 00000000000..edbdf0bdeff --- /dev/null +++ b/webpack-test/cases/mjs/no-module-main-field/node_modules/m/a.mjs @@ -0,0 +1 @@ +export default "nope1"; diff --git a/webpack-test/cases/mjs/no-module-main-field/node_modules/m/b.js b/webpack-test/cases/mjs/no-module-main-field/node_modules/m/b.js new file mode 100644 index 00000000000..546bdcec4c6 --- /dev/null +++ b/webpack-test/cases/mjs/no-module-main-field/node_modules/m/b.js @@ -0,0 +1 @@ +export default "nope2"; diff --git a/webpack-test/cases/mjs/no-module-main-field/node_modules/m/b.mjs b/webpack-test/cases/mjs/no-module-main-field/node_modules/m/b.mjs new file mode 100644 index 00000000000..9e4044b4856 --- /dev/null +++ b/webpack-test/cases/mjs/no-module-main-field/node_modules/m/b.mjs @@ -0,0 +1 @@ +export default "nope3"; diff --git a/webpack-test/cases/mjs/no-module-main-field/node_modules/m/package.json b/webpack-test/cases/mjs/no-module-main-field/node_modules/m/package.json new file mode 100644 index 00000000000..8fc09d62d80 --- /dev/null +++ b/webpack-test/cases/mjs/no-module-main-field/node_modules/m/package.json @@ -0,0 +1,4 @@ +{ + "main": "a", + "module": "b" +} diff --git a/webpack-test/cases/mjs/no-module-main-field/test.filter.js b/webpack-test/cases/mjs/no-module-main-field/test.filter.js deleted file mode 100644 index 0557cb116c1..00000000000 --- a/webpack-test/cases/mjs/no-module-main-field/test.filter.js +++ /dev/null @@ -1,4 +0,0 @@ - -module.exports = () => {return false} - - \ No newline at end of file diff --git a/webpack-test/cases/mjs/type-module/test.fitler.js b/webpack-test/cases/mjs/type-module/test.fitler.js deleted file mode 100644 index 46721713524..00000000000 --- a/webpack-test/cases/mjs/type-module/test.fitler.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = () => {return false } diff --git a/webpack-test/cases/nonce/set-nonce/test.filter.js b/webpack-test/cases/nonce/set-nonce/test.filter.js index 0557cb116c1..04ba3b4f9b0 100644 --- a/webpack-test/cases/nonce/set-nonce/test.filter.js +++ b/webpack-test/cases/nonce/set-nonce/test.filter.js @@ -1,4 +1,4 @@ -module.exports = () => {return false} +module.exports = () => {return "https://github.com/web-infra-dev/rspack/issues/4401"} \ No newline at end of file diff --git a/webpack-test/scripts/test-metric-util.js b/webpack-test/scripts/test-metric-util.js index b9857a92919..d161657ab91 100644 --- a/webpack-test/scripts/test-metric-util.js +++ b/webpack-test/scripts/test-metric-util.js @@ -60,7 +60,8 @@ function renderAllTestsToMarkdown(jsonObj) { const testResults = jsonObj["testResults"]; return testResults .flatMap(testSuite => testSuite.assertionResults) - .map((test, index) => `${index + 1}. ${renderTestToMarkdown(test.fullName)}`) + // use 1\. to break GitHub markdown list auto ordering + .map((test, index) => `${index + 1}\. ${renderTestToMarkdown(test.fullName)}`) .join('\n') }