-
-
Notifications
You must be signed in to change notification settings - Fork 594
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(commonjs): Generate simpler code when replacing module.exports
- Loading branch information
1 parent
e8948a0
commit ec20e09
Showing
31 changed files
with
458 additions
and
704 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
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 |
---|---|---|
@@ -1,29 +1,29 @@ | ||
const isCjsPromises = new Map(); | ||
const commonJSMetaPromises = new Map(); | ||
|
||
export function getIsCjsPromise(id) { | ||
let isCjsPromise = isCjsPromises.get(id); | ||
if (isCjsPromise) return isCjsPromise.promise; | ||
export function getCommonJSMetaPromise(id) { | ||
let commonJSMetaPromise = commonJSMetaPromises.get(id); | ||
if (commonJSMetaPromise) return commonJSMetaPromise.promise; | ||
|
||
const promise = new Promise((resolve) => { | ||
isCjsPromise = { | ||
commonJSMetaPromise = { | ||
resolve, | ||
promise: null | ||
}; | ||
isCjsPromises.set(id, isCjsPromise); | ||
commonJSMetaPromises.set(id, commonJSMetaPromise); | ||
}); | ||
isCjsPromise.promise = promise; | ||
commonJSMetaPromise.promise = promise; | ||
|
||
return promise; | ||
} | ||
|
||
export function setIsCjsPromise(id, resolution) { | ||
const isCjsPromise = isCjsPromises.get(id); | ||
if (isCjsPromise) { | ||
if (isCjsPromise.resolve) { | ||
isCjsPromise.resolve(resolution); | ||
isCjsPromise.resolve = null; | ||
export function setCommonJSMetaPromise(id, commonjsMeta) { | ||
const commonJSMetaPromise = commonJSMetaPromises.get(id); | ||
if (commonJSMetaPromise) { | ||
if (commonJSMetaPromise.resolve) { | ||
commonJSMetaPromise.resolve(commonjsMeta); | ||
commonJSMetaPromise.resolve = null; | ||
} | ||
} else { | ||
isCjsPromises.set(id, { promise: Promise.resolve(resolution), resolve: null }); | ||
commonJSMetaPromises.set(id, { promise: Promise.resolve(commonjsMeta), resolve: null }); | ||
} | ||
} |
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
8 changes: 3 additions & 5 deletions
8
packages/commonjs/test/fixtures/form/async-function/output.js
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 |
---|---|---|
@@ -1,8 +1,6 @@ | ||
import { __module as input } from "\u0000fixtures/form/async-function/input.js?commonjs-module" | ||
|
||
input.exports = async function () { | ||
var input = async function () { | ||
// TODO | ||
}; | ||
|
||
export { exports as __moduleExports } from "\u0000fixtures/form/async-function/input.js?commonjs-module" | ||
export default input.exports; | ||
export { input as __moduleExports }; | ||
export { input as default }; |
6 changes: 3 additions & 3 deletions
6
packages/commonjs/test/fixtures/form/constant-template-literal/output.js
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 |
---|---|---|
@@ -1,8 +1,8 @@ | ||
import { __module as input } from "\u0000fixtures/form/constant-template-literal/input.js?commonjs-module" | ||
import "\u0000tape?commonjs-require"; | ||
import foo from "\u0000tape?commonjs-proxy"; | ||
|
||
console.log(foo); | ||
|
||
export { exports as __moduleExports } from "\u0000fixtures/form/constant-template-literal/input.js?commonjs-module" | ||
export default input.exports; | ||
var input = {}; | ||
export { input as __moduleExports }; | ||
export { input as default }; |
Oops, something went wrong.