forked from vercel/next.js
-
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: Fix wrong cjs detection of
auto-cjs
pass (vercel#60118)
### What? Make `auto-cjs` pass consider shadowing of `module`, so it can ignore `module.exports = foo` in nested scopes. ### Why? It's problematic for many tasks ### How? Closes PACK-2074
- Loading branch information
Showing
14 changed files
with
112 additions
and
38 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
8 changes: 0 additions & 8 deletions
8
packages/next-swc/crates/core/tests/full/auto-cjs/1/output.js
This file was deleted.
Oops, something went wrong.
13 changes: 0 additions & 13 deletions
13
packages/next-swc/crates/core/tests/full/auto-cjs/2/output.js
This file was deleted.
Oops, something went wrong.
4 changes: 0 additions & 4 deletions
4
packages/next-swc/crates/core/tests/full/auto-cjs/3/output.js
This file was deleted.
Oops, something went wrong.
File renamed without changes.
12 changes: 12 additions & 0 deletions
12
packages/next-swc/crates/core/tests/loader/auto-cjs/1/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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var _esm = /*#__PURE__*/ _interop_require_default(require("esm")); | ||
function _interop_require_default(obj) { | ||
return obj && obj.__esModule ? obj : { | ||
default: obj | ||
}; | ||
} | ||
console.log(_esm.default.foo); | ||
module.exports = _esm.default; |
File renamed without changes.
14 changes: 14 additions & 0 deletions
14
packages/next-swc/crates/core/tests/loader/auto-cjs/2/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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
Object.defineProperty(exports, "default", { | ||
enumerable: true, | ||
get: function() { | ||
return _default; | ||
} | ||
}); | ||
var _default = 1; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); |
File renamed without changes.
6 changes: 6 additions & 0 deletions
6
packages/next-swc/crates/core/tests/loader/auto-cjs/3/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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export default 1; | ||
console.log("__esModule"); | ||
Object.defineProperty({}, "__esModule", { | ||
value: true | ||
}); | ||
Object.defineProperty(); |
5 changes: 5 additions & 0 deletions
5
packages/next-swc/crates/core/tests/loader/auto-cjs/pack-2074/1/input.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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export default (module) => { | ||
module.exports = {} | ||
} | ||
|
||
export const value = 'mixed-syntax-esm' |
4 changes: 4 additions & 0 deletions
4
packages/next-swc/crates/core/tests/loader/auto-cjs/pack-2074/1/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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export default function(module) { | ||
module.exports = {}; | ||
}; | ||
export var value = "mixed-syntax-esm"; |
5 changes: 5 additions & 0 deletions
5
packages/next-swc/crates/core/tests/loader/auto-cjs/pack-2074/2/input.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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
function foo(module) { | ||
module.exports = 'this is just normal assignment of scope variable' | ||
} | ||
|
||
export const value = 'mixed-syntax-esm' |
4 changes: 4 additions & 0 deletions
4
packages/next-swc/crates/core/tests/loader/auto-cjs/pack-2074/2/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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
function foo(module) { | ||
module.exports = "this is just normal assignment of scope variable"; | ||
} | ||
export var value = "mixed-syntax-esm"; |