-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(mfsu): webpack export support (umijs#6894)
* fix(mfsu): webpack export support * fix(mfsu): get all export of webpack export * fix: support webpack export object * fix: static path * fix: regexp Co-authored-by: xiefengnian <[email protected]>
- Loading branch information
1 parent
f32f969
commit 67cada7
Showing
2 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,6 +65,60 @@ export const cjsModeEsmParser = (code: string) => { | |
// ref: https://unpkg.alibaba-inc.com/browse/[email protected]/lib/core.js | ||
matchAll(/exports(?:\.|\[(?:\'|\"))(\w+)(?:\s*|(?:\'|\")\])\s*\=/g, code), | ||
) | ||
.concat( | ||
// Support __webpack_exports__["default"] | ||
// ref: https://github.com/margox/braft-editor/blob/master/dist/index.js#L8429 | ||
matchAll(/__webpack_exports__\[(?:\"|\')(\w+)(?:\"|\')\]\s*\=/g, code), | ||
) | ||
.concat( | ||
// Support __webpack_require__.d(__webpack_exports, "EditorState") | ||
// ref: https://github.com/margox/braft-editor/blob/master/dist/index.js#L8347 | ||
matchAll( | ||
/__webpack_require__\.d\(\s*__webpack_exports__\s*,\s*(?:\"|\')(\w+)(?:\"|\')\s*,/g, | ||
code, | ||
), | ||
) | ||
.concat( | ||
// Support __webpack_require__.d(__webpack_exports__, {"default": function() { return /* binding */ clipboard; }}); | ||
// ref: https://unpkg.alibaba-inc.com/browse/[email protected]/dist/clipboard.js L26 | ||
...matchAll( | ||
/__webpack_require__\.d\(\s*__webpack_exports__\s*,\s*(\{)/g, | ||
code, | ||
).map((matchResult) => { | ||
const { index } = matchResult; | ||
|
||
let idx = index; | ||
let deep = 0; | ||
let isMeetSymbol = false; | ||
let symbolBeginIndex = index; | ||
|
||
while (idx < code.length) { | ||
if (!deep && isMeetSymbol) { | ||
break; | ||
} | ||
if (code[idx] === '{') { | ||
if (!isMeetSymbol) { | ||
isMeetSymbol = true; | ||
symbolBeginIndex = idx; | ||
} | ||
deep++; | ||
} | ||
if (code[idx] === '}') { | ||
deep--; | ||
} | ||
idx++; | ||
} | ||
|
||
let result = code.slice(symbolBeginIndex, idx); | ||
|
||
return [ | ||
...matchAll( | ||
/(?:\"|\')(\w+)(?:\"|\')\s*\:\s*(?:function|\()/g, | ||
result, | ||
), | ||
]; | ||
}), | ||
) | ||
.map((result) => result[1]); | ||
}; | ||
|
||
|