mirror of
https://github.com/denoland/deno.git
synced 2025-08-04 19:08:15 +00:00
fix: add "module.exports" export to ESM CJS wrapper module (#28373)
This commit is contained in:
parent
9bcbef6d2f
commit
a566d8bd10
28 changed files with 125 additions and 23 deletions
|
@ -210,7 +210,7 @@ impl<
|
|||
));
|
||||
|
||||
for export in &all_exports {
|
||||
if export.as_str() != "default" {
|
||||
if !matches!(export.as_str(), "default" | "module.exports") {
|
||||
add_export(
|
||||
&mut source,
|
||||
export,
|
||||
|
@ -221,6 +221,7 @@ impl<
|
|||
}
|
||||
|
||||
source.push("export default mod;".to_string());
|
||||
add_export(&mut source, "module.exports", "mod", &mut temp_var_count);
|
||||
|
||||
let translated_source = source.join("\n");
|
||||
Ok(Cow::Owned(translated_source))
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
@denotest/esm-basic
|
||||
[Module: null prototype] {
|
||||
add: [Function (anonymous)],
|
||||
default: { add: [Function (anonymous)] }
|
||||
default: { add: [Function (anonymous)] },
|
||||
"module.exports": { add: [Function (anonymous)] }
|
||||
}
|
||||
|
|
|
@ -3,5 +3,6 @@ imported: [Module: null prototype] {
|
|||
"\nx": "test",
|
||||
"\rz": "test",
|
||||
'"a': "test",
|
||||
default: { "\nx": "test", "\ty": "test", "\rz": "test", '"a': "test" }
|
||||
default: { "\nx": "test", "\ty": "test", "\rz": "test", '"a': "test" },
|
||||
"module.exports": { "\nx": "test", "\ty": "test", "\rz": "test", '"a': "test" }
|
||||
}
|
||||
|
|
|
@ -3,5 +3,6 @@ Download http://localhost:4260/@denotest/cjs-reexport-same-specifier-in-sub-fold
|
|||
[Module: null prototype] {
|
||||
default: { main: [Getter], sub: [Getter] },
|
||||
main: 1,
|
||||
"module.exports": { main: [Getter], sub: [Getter] },
|
||||
sub: 2
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
{
|
||||
"args": "run --allow-read --quiet cjs-invalid-name-exports/main.ts",
|
||||
"output": "cjs-invalid-name-exports/main.out"
|
||||
"args": "run --allow-read --quiet main.ts",
|
||||
"output": "main.out"
|
||||
}
|
||||
|
|
|
@ -9,5 +9,12 @@
|
|||
"foo - bar": "foo - bar"
|
||||
},
|
||||
"foo - bar": "foo - bar",
|
||||
"module.exports": {
|
||||
'wow "double quotes"': "double quotes",
|
||||
"another 'case'": "example",
|
||||
"a \\ b": "a \\ b",
|
||||
"name variable": "a",
|
||||
"foo - bar": "foo - bar"
|
||||
},
|
||||
'wow "double quotes"': "double quotes"
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
{
|
||||
"args": "run --allow-read cjs_local_global_decls/main.ts",
|
||||
"output": "cjs_local_global_decls/main.out"
|
||||
"args": "run --allow-read main.ts",
|
||||
"output": "main.out"
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
{
|
||||
"args": "run -A --quiet --check=all cjs_module_export_assignment/main.ts",
|
||||
"output": "cjs_module_export_assignment/main.out"
|
||||
"args": "run -A --quiet --check=all main.ts",
|
||||
"output": "main.out"
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
{ func: [Function: func] }
|
||||
[Module: null prototype] {
|
||||
default: { func: [Function: func] },
|
||||
func: [Function: func]
|
||||
func: [Function: func],
|
||||
"module.exports": { func: [Function: func] }
|
||||
}
|
||||
5
|
|
@ -1,4 +1,4 @@
|
|||
{
|
||||
"args": "run -A --quiet --check=all cjs_module_export_assignment_number/main.ts",
|
||||
"output": "cjs_module_export_assignment_number/main.out"
|
||||
"args": "run -A --quiet --check=all main.ts",
|
||||
"output": "main.out"
|
||||
}
|
||||
|
|
|
@ -1,3 +0,0 @@
|
|||
5
|
||||
5
|
||||
[Module: null prototype] { default: 5 }
|
|
@ -0,0 +1,3 @@
|
|||
5
|
||||
5
|
||||
[Module: null prototype] { default: 5, "module.exports": 5 }
|
|
@ -1,4 +1,4 @@
|
|||
{
|
||||
"args": "run --allow-read --quiet cjs_require_esm/main.ts",
|
||||
"output": "cjs_require_esm/main.out"
|
||||
"args": "run --allow-read --quiet main.ts",
|
||||
"output": "main.out"
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
[Module: null prototype] {
|
||||
Test: [Module: null prototype] { Test: [class Test] },
|
||||
default: { Test: [Module: null prototype] { Test: [class Test] } }
|
||||
default: { Test: [Module: null prototype] { Test: [class Test] } },
|
||||
"module.exports": { Test: [Module: null prototype] { Test: [class Test] } }
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
{
|
||||
"args": "run --allow-read --quiet cjs_require_esm_mjs/main.ts",
|
||||
"output": "cjs_require_esm_mjs/main.out"
|
||||
"args": "run --allow-read --quiet main.ts",
|
||||
"output": "main.out"
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
[Module: null prototype] {
|
||||
Test: [Module: null prototype] { Test: [class Test] },
|
||||
default: { Test: [Module: null prototype] { Test: [class Test] } }
|
||||
default: { Test: [Module: null prototype] { Test: [class Test] } },
|
||||
"module.exports": { Test: [Module: null prototype] { Test: [class Test] } }
|
||||
}
|
|
@ -21,11 +21,17 @@ Node esm importing node cjs
|
|||
named: [Function (anonymous)],
|
||||
MyClass: [class MyClass]
|
||||
},
|
||||
"module.exports": {
|
||||
default: [Function (anonymous)],
|
||||
named: [Function (anonymous)],
|
||||
MyClass: [class MyClass]
|
||||
},
|
||||
named: [Function (anonymous)]
|
||||
}
|
||||
[Module: null prototype] {
|
||||
__esModule: true,
|
||||
default: { default: [Function (anonymous)], named: [Function (anonymous)] },
|
||||
"module.exports": { default: [Function (anonymous)], named: [Function (anonymous)] },
|
||||
named: [Function (anonymous)]
|
||||
}
|
||||
===========================
|
||||
|
@ -45,6 +51,11 @@ Deno esm importing node cjs
|
|||
named: [Function (anonymous)],
|
||||
MyClass: [class MyClass]
|
||||
},
|
||||
"module.exports": {
|
||||
default: [Function (anonymous)],
|
||||
named: [Function (anonymous)],
|
||||
MyClass: [class MyClass]
|
||||
},
|
||||
named: [Function (anonymous)]
|
||||
}
|
||||
===========================
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
{
|
||||
"args": "run reserved_word_exports/main.ts",
|
||||
"output": "reserved_word_exports/main.out"
|
||||
"args": "run main.ts",
|
||||
"output": "main.out"
|
||||
}
|
||||
|
|
|
@ -111,6 +111,76 @@ Download http://localhost:4260/@denotest/reserved-word-exports/1.0.0.tgz
|
|||
let: "let",
|
||||
long: "long",
|
||||
mod: "mod",
|
||||
"module.exports": {
|
||||
abstract: "abstract",
|
||||
arguments: "arguments",
|
||||
async: "async",
|
||||
await: "await",
|
||||
boolean: "boolean",
|
||||
break: "break",
|
||||
byte: "byte",
|
||||
case: "case",
|
||||
catch: "catch",
|
||||
char: "char",
|
||||
class: "class",
|
||||
const: "const",
|
||||
continue: "continue",
|
||||
debugger: "debugger",
|
||||
default: "default",
|
||||
delete: "delete",
|
||||
do: "do",
|
||||
double: "double",
|
||||
else: "else",
|
||||
enum: "enum",
|
||||
eval: "eval",
|
||||
export: "export",
|
||||
extends: "extends",
|
||||
false: "false",
|
||||
final: "final",
|
||||
finally: "finally",
|
||||
float: "float",
|
||||
for: "for",
|
||||
function: "function",
|
||||
get: "get",
|
||||
goto: "goto",
|
||||
if: "if",
|
||||
implements: "implements",
|
||||
import: "import",
|
||||
in: "in",
|
||||
instanceof: "instanceof",
|
||||
int: "int",
|
||||
interface: "interface",
|
||||
let: "let",
|
||||
long: "long",
|
||||
mod: "mod",
|
||||
native: "native",
|
||||
new: "new",
|
||||
null: "null",
|
||||
package: "package",
|
||||
private: "private",
|
||||
protected: "protected",
|
||||
public: "public",
|
||||
return: "return",
|
||||
set: "set",
|
||||
short: "short",
|
||||
static: "static",
|
||||
super: "super",
|
||||
switch: "switch",
|
||||
synchronized: "synchronized",
|
||||
this: "this",
|
||||
throw: "throw",
|
||||
throws: "throws",
|
||||
transient: "transient",
|
||||
true: "true",
|
||||
try: "try",
|
||||
typeof: "typeof",
|
||||
var: "var",
|
||||
void: "void",
|
||||
volatile: "volatile",
|
||||
while: "while",
|
||||
with: "with",
|
||||
yield: "yield"
|
||||
},
|
||||
native: "native",
|
||||
new: "new",
|
||||
null: "null",
|
||||
|
@ -139,3 +209,7 @@ Download http://localhost:4260/@denotest/reserved-word-exports/1.0.0.tgz
|
|||
with: "with",
|
||||
yield: "yield"
|
||||
}
|
||||
[Module: null prototype] {
|
||||
default: { "module.exports": 6 },
|
||||
"module.exports": { "module.exports": 6 }
|
||||
}
|
|
@ -1,3 +1,5 @@
|
|||
import * as exports from "npm:@denotest/reserved-word-exports";
|
||||
import * as moduleExports from "./module_exports.cjs";
|
||||
|
||||
console.log(exports);
|
||||
console.log(moduleExports);
|
1
tests/specs/npm/reserved_word_exports/module_exports.cjs
Normal file
1
tests/specs/npm/reserved_word_exports/module_exports.cjs
Normal file
|
@ -0,0 +1 @@
|
|||
module.exports["module.exports"] = 6;
|
Loading…
Add table
Add a link
Reference in a new issue