Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion resolvers/node/analyze.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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))
Expand Down
Original file line number Diff line number Diff line change
@@ -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 changes: 2 additions & 1 deletion tests/specs/node/cjs_key_escaped_whitespace/output.out
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
4 changes: 2 additions & 2 deletions tests/specs/npm/cjs_invalid_name_exports/__test__.jsonc
Original file line number Diff line number Diff line change
@@ -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"
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
4 changes: 2 additions & 2 deletions tests/specs/npm/cjs_local_global_decls/__test__.jsonc
Original file line number Diff line number Diff line change
@@ -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"
}
4 changes: 2 additions & 2 deletions tests/specs/npm/cjs_module_export_assignment/__test__.jsonc
Original file line number Diff line number Diff line change
@@ -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"
}
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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"
}

This file was deleted.

3 changes: 3 additions & 0 deletions tests/specs/npm/cjs_module_export_assignment_number/main.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
5
5
[Module: null prototype] { default: 5, "module.exports": 5 }
4 changes: 2 additions & 2 deletions tests/specs/npm/cjs_require_esm/__test__.jsonc
Original file line number Diff line number Diff line change
@@ -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"
}
Original file line number Diff line number Diff line change
@@ -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] } }
}
4 changes: 2 additions & 2 deletions tests/specs/npm/cjs_require_esm_mjs/__test__.jsonc
Original file line number Diff line number Diff line change
@@ -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"
}
Original file line number Diff line number Diff line change
@@ -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] } }
}
11 changes: 11 additions & 0 deletions tests/specs/npm/esm_import_cjs_default/main.out
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
}
===========================
Expand All @@ -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)]
}
===========================
Expand Down
4 changes: 2 additions & 2 deletions tests/specs/npm/reserved_word_exports/__test__.jsonc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"args": "run reserved_word_exports/main.ts",
"output": "reserved_word_exports/main.out"
"args": "run main.ts",
"output": "main.out"
}
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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 }
}
Original file line number Diff line number Diff line change
@@ -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 change: 1 addition & 0 deletions tests/specs/npm/reserved_word_exports/module_exports.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports["module.exports"] = 6;
Loading