mirror of https://github.com/webpack/webpack.git
Compare commits
5 Commits
dd4769b5ff
...
d2a2b6c81b
| Author | SHA1 | Date |
|---|---|---|
|
|
d2a2b6c81b | |
|
|
c89ae03cb4 | |
|
|
ba8e66372d | |
|
|
6644fe9a6e | |
|
|
20dc109ec2 |
|
|
@ -133,20 +133,7 @@ class SystemLibraryPlugin extends AbstractLibraryPlugin {
|
||||||
chunk.runtime
|
chunk.runtime
|
||||||
);
|
);
|
||||||
if (used) {
|
if (used) {
|
||||||
if (used === "default" && exportInfo.name === "default") {
|
if (otherUnused || used !== exportInfo.name) {
|
||||||
instructions.push(
|
|
||||||
Template.asString([
|
|
||||||
"if (typeof module.default !== 'undefined') {",
|
|
||||||
Template.indent([
|
|
||||||
`${external}.default = module.default;`
|
|
||||||
]),
|
|
||||||
"} else {",
|
|
||||||
Template.indent([`${external} = module;`]),
|
|
||||||
"}"
|
|
||||||
])
|
|
||||||
);
|
|
||||||
handledNames.push(exportInfo.name);
|
|
||||||
} else if (otherUnused || used !== exportInfo.name) {
|
|
||||||
instructions.push(
|
instructions.push(
|
||||||
`${external}${propertyAccess([
|
`${external}${propertyAccess([
|
||||||
used
|
used
|
||||||
|
|
@ -183,6 +170,7 @@ class SystemLibraryPlugin extends AbstractLibraryPlugin {
|
||||||
])
|
])
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
|
// Special handling for SystemJS externals - check if module has default property
|
||||||
instructions.push(
|
instructions.push(
|
||||||
Template.asString([
|
Template.asString([
|
||||||
"if (typeof module.default !== 'undefined') {",
|
"if (typeof module.default !== 'undefined') {",
|
||||||
|
|
|
||||||
|
|
@ -1,19 +0,0 @@
|
||||||
import React, { useEffect } from "react";
|
|
||||||
|
|
||||||
/* This test verifies that default imports work correctly with SystemJS externals
|
|
||||||
* when the external module doesn't have a default property (e.g., React)
|
|
||||||
*/
|
|
||||||
|
|
||||||
it("should correctly handle default import from SystemJS external", function() {
|
|
||||||
// React should be the entire module object, not undefined
|
|
||||||
expect(React).toBeDefined();
|
|
||||||
expect(typeof React).toBe("object");
|
|
||||||
expect(React.Component).toBeDefined();
|
|
||||||
expect(React.Fragment).toBeDefined();
|
|
||||||
|
|
||||||
// Named imports should still work
|
|
||||||
expect(typeof useEffect).toBe("function");
|
|
||||||
|
|
||||||
// The default import should not be undefined
|
|
||||||
expect(React).not.toBeUndefined();
|
|
||||||
});
|
|
||||||
|
|
@ -1,26 +0,0 @@
|
||||||
// Mock React module that HAS a default property
|
|
||||||
// This simulates ES6 modules with default exports
|
|
||||||
const React = {
|
|
||||||
Component: function Component() {},
|
|
||||||
Fragment: Symbol("react.fragment"),
|
|
||||||
Profiler: Symbol("react.profiler"),
|
|
||||||
useEffect: function useEffect(callback, deps) {
|
|
||||||
return callback();
|
|
||||||
},
|
|
||||||
useState: function useState(initial) {
|
|
||||||
return [initial, function() {}];
|
|
||||||
},
|
|
||||||
createElement: function createElement(type, props, ...children) {
|
|
||||||
return { type, props, children };
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// Export with default property (ES6 module format)
|
|
||||||
module.exports = React;
|
|
||||||
module.exports.default = React;
|
|
||||||
module.exports.useEffect = React.useEffect;
|
|
||||||
module.exports.Component = React.Component;
|
|
||||||
module.exports.Fragment = React.Fragment;
|
|
||||||
module.exports.Profiler = React.Profiler;
|
|
||||||
module.exports.useState = React.useState;
|
|
||||||
module.exports.createElement = React.createElement;
|
|
||||||
|
|
@ -1,25 +0,0 @@
|
||||||
// Mock React module that doesn't have a default property
|
|
||||||
// This simulates how React is typically exported in SystemJS environments
|
|
||||||
const React = {
|
|
||||||
Component: function Component() {},
|
|
||||||
Fragment: Symbol("react.fragment"),
|
|
||||||
Profiler: Symbol("react.profiler"),
|
|
||||||
useEffect: function useEffect(callback, deps) {
|
|
||||||
return callback();
|
|
||||||
},
|
|
||||||
useState: function useState(initial) {
|
|
||||||
return [initial, function() {}];
|
|
||||||
},
|
|
||||||
createElement: function createElement(type, props, ...children) {
|
|
||||||
return { type, props, children };
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// Export named exports (SystemJS style - no default property)
|
|
||||||
module.exports = React;
|
|
||||||
module.exports.useEffect = React.useEffect;
|
|
||||||
module.exports.Component = React.Component;
|
|
||||||
module.exports.Fragment = React.Fragment;
|
|
||||||
module.exports.Profiler = React.Profiler;
|
|
||||||
module.exports.useState = React.useState;
|
|
||||||
module.exports.createElement = React.createElement;
|
|
||||||
|
|
@ -1,27 +0,0 @@
|
||||||
"use strict";
|
|
||||||
|
|
||||||
const path = require("path");
|
|
||||||
|
|
||||||
/** @type {import("../../../../").Configuration} */
|
|
||||||
module.exports = {
|
|
||||||
entry: "./test.js",
|
|
||||||
output: {
|
|
||||||
path: path.resolve(__dirname, "dist"),
|
|
||||||
filename: "bundle.js",
|
|
||||||
libraryTarget: "system"
|
|
||||||
},
|
|
||||||
externals: {
|
|
||||||
react: "react",
|
|
||||||
"react-with-default": "react-with-default"
|
|
||||||
},
|
|
||||||
resolve: {
|
|
||||||
alias: {
|
|
||||||
react: path.resolve(__dirname, "react.js"),
|
|
||||||
"react-with-default": path.resolve(__dirname, "react-with-default.js")
|
|
||||||
}
|
|
||||||
},
|
|
||||||
node: {
|
|
||||||
__dirname: false,
|
|
||||||
__filename: false
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
@ -1,36 +0,0 @@
|
||||||
import React, { useEffect } from "react";
|
|
||||||
import ReactWithDefault, { useEffect as useEffectWithDefault } from "react-with-default";
|
|
||||||
|
|
||||||
/* This test verifies that default imports work correctly with SystemJS externals
|
|
||||||
* in both scenarios:
|
|
||||||
* 1. External module without default property (traditional SystemJS)
|
|
||||||
* 2. External module with default property (ES6 module format)
|
|
||||||
*/
|
|
||||||
|
|
||||||
it("should correctly handle default import from SystemJS external without default property", function() {
|
|
||||||
// React should be the entire module object, not undefined
|
|
||||||
expect(React).toBeDefined();
|
|
||||||
expect(typeof React).toBe("object");
|
|
||||||
expect(React.Component).toBeDefined();
|
|
||||||
expect(React.Fragment).toBeDefined();
|
|
||||||
|
|
||||||
// Named imports should still work
|
|
||||||
expect(typeof useEffect).toBe("function");
|
|
||||||
|
|
||||||
// The default import should not be undefined
|
|
||||||
expect(React).not.toBeUndefined();
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should correctly handle default import from SystemJS external with default property", function() {
|
|
||||||
// ReactWithDefault should be the default property value
|
|
||||||
expect(ReactWithDefault).toBeDefined();
|
|
||||||
expect(typeof ReactWithDefault).toBe("object");
|
|
||||||
expect(ReactWithDefault.Component).toBeDefined();
|
|
||||||
expect(ReactWithDefault.Fragment).toBeDefined();
|
|
||||||
|
|
||||||
// Named imports should still work
|
|
||||||
expect(typeof useEffectWithDefault).toBe("function");
|
|
||||||
|
|
||||||
// The default import should not be undefined
|
|
||||||
expect(ReactWithDefault).not.toBeUndefined();
|
|
||||||
});
|
|
||||||
|
|
@ -1,15 +0,0 @@
|
||||||
"use strict";
|
|
||||||
|
|
||||||
/** @type {import("../../../../").Configuration} */
|
|
||||||
module.exports = {
|
|
||||||
output: {
|
|
||||||
libraryTarget: "system"
|
|
||||||
},
|
|
||||||
externals: {
|
|
||||||
react: "react"
|
|
||||||
},
|
|
||||||
node: {
|
|
||||||
__dirname: false,
|
|
||||||
__filename: false
|
|
||||||
}
|
|
||||||
};
|
|
||||||
Loading…
Reference in New Issue