Skip to content

Commit

Permalink
fix(modern-module): export syntax detect more invalid chars
Browse files Browse the repository at this point in the history
  • Loading branch information
fi3ework committed Aug 8, 2024
1 parent 921b522 commit af0452f
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,12 @@ fn render_startup(

let final_name = exports_final_names.get(used_name.as_str());

let contains_char =
|string: &str, chars: &str| -> bool { string.chars().any(|c| chars.contains(c)) };

if let Some(final_name) = final_name {
// Currently, there's not way to determine if a final_name contains a property access.
if final_name.contains('.') || final_name.contains("()") {
if contains_char(final_name, "[]().") {
exports_with_property_access.push((final_name, info_name));
} else if info_name == final_name {
exports.push(info_name.to_string());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = 'foo'
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import defaultImport from 'external-module'
import { namedImport } from 'external-module'
import cjsInterop from './foo.cjs'

export { defaultImport, namedImport, cjsInterop }
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/** @type {import("@rspack/core").Configuration} */
module.exports = {
entry: {
"index": "./index.js",
},
output: {
filename: `[name].js`,
module: true,
libraryTarget: "modern-module",
iife: false,
chunkFormat: "module",
},
externalsType: 'module-import',
experiments: {
outputModule: true
},
externals: "external-module",
optimization: {
concatenateModules: true,
minimize: false
},
plugins: [
function () {
/**
* @param {import("@rspack/core").Compilation} compilation compilation
* @returns {void}
*/
const handler = compilation => {
compilation.hooks.afterProcessAssets.tap("testcase", assets => {
const bundle = Object.values(assets)[0]._value
expect(bundle).toContain(`var __webpack_exports__cjsInterop = (foo_default());
var __webpack_exports__defaultImport = external_external_module_namespaceObject["default"];
var __webpack_exports__namedImport = external_external_module_namespaceObject.namedImport;`)
});
};
this.hooks.compilation.tap("testcase", handler);
}
]
};

0 comments on commit af0452f

Please sign in to comment.