Skip to content
Closed
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: 0 additions & 3 deletions internal/ast/parseoptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,6 @@ func isFileProbablyExternalModule(sourceFile *SourceFile) *Node {
}

func isAnExternalModuleIndicatorNode(node *Node) bool {
if node.Flags&NodeFlagsReparsed != 0 {
return false
}
return HasSyntacticModifier(node, ModifierFlagsExport) ||
IsImportEqualsDeclaration(node) && IsExternalModuleReference(node.AsImportEqualsDeclaration().ModuleReference) ||
IsImportDeclaration(node) || IsExportAssignment(node) || IsExportDeclaration(node)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ exports.default = () => {


//// [index.js]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
export var default = () => {
return 1234;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/main1.ts(3,12): error TS2580: Cannot find name 'require'. Do you need to install type definitions for node? Try `npm i --save-dev @types/node`.
/main1.ts(19,4): error TS2339: Property 'default' does not exist on type '() => void'.
/main1.ts(23,8): error TS1192: Module '"/e"' has no default export.
/main1.ts(30,4): error TS2339: Property 'default' does not exist on type '0'.
/main2.mts(4,4): error TS2339: Property 'default' does not exist on type 'typeof import("/a")'.
/main2.mts(5,12): error TS2580: Cannot find name 'require'. Do you need to install type definitions for node? Try `npm i --save-dev @types/node`.
/main2.mts(14,8): error TS1192: Module '"/e"' has no default export.
Expand Down Expand Up @@ -42,7 +43,7 @@
==== /g.js (0 errors) ====
exports.default = 0;

==== /main1.ts (3 errors) ====
==== /main1.ts (4 errors) ====
import { x, y } from "./a"; // No y
import a1 = require("./a"); // { x: 0 }
const a2 = require("./a"); // Error in TS
Expand Down Expand Up @@ -79,6 +80,8 @@

import g1 from "./g"; // { default: 0 }
g1.default;
~~~~~~~
!!! error TS2339: Property 'default' does not exist on type '0'.
import g2 = require("./g"); // { default: 0 }
g2.default;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
/main1.ts(19,4): error TS2339: Property 'default' does not exist on type '() => void'.
/main1.ts(23,8): error TS1192: Module '"/e"' has no default export.
-/main2.mts(1,13): error TS2305: Module '"./a"' has no exported member 'y'.
+/main1.ts(30,4): error TS2339: Property 'default' does not exist on type '0'.
/main2.mts(4,4): error TS2339: Property 'default' does not exist on type 'typeof import("/a")'.
/main2.mts(5,12): error TS2580: Cannot find name 'require'. Do you need to install type definitions for node? Try `npm i --save-dev @types/node`.
/main2.mts(14,8): error TS1192: Module '"/e"' has no default export.
Expand All @@ -17,7 +18,7 @@
/main3.cjs(2,1): error TS8002: 'import ... =' can only be used in TypeScript files.
/main3.cjs(5,8): error TS1293: ECMAScript module syntax is not allowed in a CommonJS module when 'module' is set to 'preserve'.
/main3.cjs(8,8): error TS1293: ECMAScript module syntax is not allowed in a CommonJS module when 'module' is set to 'preserve'.
@@= skipped -18, +15 lines =@@
@@= skipped -18, +16 lines =@@
/main3.cjs(17,8): error TS1293: ECMAScript module syntax is not allowed in a CommonJS module when 'module' is set to 'preserve'.


Expand All @@ -30,19 +31,21 @@

==== /b.ts (0 errors) ====
export default 0;
@@= skipped -28, +26 lines =@@
==== /g.js (0 errors) ====
exports.default = 0;
@@= skipped -30, +28 lines =@@

-==== /main1.ts (4 errors) ====
+==== /main1.ts (3 errors) ====
==== /main1.ts (4 errors) ====
import { x, y } from "./a"; // No y
- ~
-!!! error TS2305: Module '"./a"' has no exported member 'y'.
import a1 = require("./a"); // { x: 0 }
const a2 = require("./a"); // Error in TS
~~~~~~~
@@= skipped -42, +40 lines =@@
@@= skipped -37, +35 lines =@@

import g1 from "./g"; // { default: 0 }
g1.default;
+ ~~~~~~~
+!!! error TS2339: Property 'default' does not exist on type '0'.
Comment on lines +47 to +48
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strange error appearing here. g.js is exports.default = 0 which breaks for some reason.

import g2 = require("./g"); // { default: 0 }
g2.default;

Expand All @@ -54,7 +57,7 @@
import a1 = require("./a"); // { x: 0 }
a1.x;
a1.default.x; // Arguably should exist but doesn't
@@= skipped -35, +33 lines =@@
@@= skipped -38, +38 lines =@@
~
!!! error TS1293: ECMAScript module syntax is not allowed in a CommonJS module when 'module' is set to 'preserve'.
~
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,17 +133,15 @@ import g1 from "./g"; // { default: 0 }
>g1 : Symbol(g1, Decl(main1.ts, 28, 6))

g1.default;
>g1.default : Symbol(g1.default, Decl(g.js, 0, 0))
>g1 : Symbol(g1, Decl(main1.ts, 28, 6))
>default : Symbol(g1.default, Decl(g.js, 0, 0))

import g2 = require("./g"); // { default: 0 }
>g2 : Symbol(g2, Decl(main1.ts, 29, 11))

g2.default;
>g2.default : Symbol(g1.default, Decl(g.js, 0, 0))
>g2.default : Symbol(g1, Decl(g.js, 0, 0))
>g2 : Symbol(g2, Decl(main1.ts, 29, 11))
>default : Symbol(g1.default, Decl(g.js, 0, 0))
>default : Symbol(g1, Decl(g.js, 0, 0))

=== /main2.mts ===
import { x, y } from "./a"; // No y
Expand Down Expand Up @@ -259,7 +257,7 @@ import g1 from "./g"; // { default: 0 }
const g2 = require("./g"); // { default: 0 }
>g2 : Symbol(g2, Decl(main3.cjs, 17, 5))
>require : Symbol(require)
>"./g" : Symbol(g1, Decl(g.js, 0, 0))
>"./g" : Symbol(g2, Decl(g.js, 0, 0))

=== /main4.cjs ===
exports.x = require("./g");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,33 @@
>default : Symbol(default, Decl(g.js, 0, 0))

=== /main1.ts ===
@@= skipped -227, +227 lines =@@
@@= skipped -96, +96 lines =@@
>g1 : Symbol(g1, Decl(main1.ts, 28, 6))

g1.default;
->g1.default : Symbol(g1.default, Decl(g.js, 0, 0))
>g1 : Symbol(g1, Decl(main1.ts, 28, 6))
->default : Symbol(g1.default, Decl(g.js, 0, 0))

import g2 = require("./g"); // { default: 0 }
>g2 : Symbol(g2, Decl(main1.ts, 29, 11))

g2.default;
->g2.default : Symbol(g1.default, Decl(g.js, 0, 0))
+>g2.default : Symbol(g1, Decl(g.js, 0, 0))
>g2 : Symbol(g2, Decl(main1.ts, 29, 11))
->default : Symbol(g1.default, Decl(g.js, 0, 0))
+>default : Symbol(g1, Decl(g.js, 0, 0))

=== /main2.mts ===
import { x, y } from "./a"; // No y
@@= skipped -126, +124 lines =@@
const g2 = require("./g"); // { default: 0 }
>g2 : Symbol(g2, Decl(main3.cjs, 17, 5))
>require : Symbol(require)
->"./g" : Symbol(g1, Decl(g.js, 0, 0))
+>"./g" : Symbol(g2, Decl(g.js, 0, 0))

=== /main4.cjs ===
exports.x = require("./g");
>exports.x : Symbol(x, Decl(main4.cjs, 0, 0))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,19 +152,19 @@ f2.default;
>default : 0

import g1 from "./g"; // { default: 0 }
>g1 : typeof g1
>g1 : 0

g1.default;
>g1.default : 0
>g1 : typeof g1
>default : 0
>g1.default : any
>g1 : 0
>default : any

import g2 = require("./g"); // { default: 0 }
>g2 : typeof g1
>g2 : typeof g2

g2.default;
>g2.default : 0
>g2 : typeof g1
>g2 : typeof g2
>default : 0

=== /main2.mts ===
Expand Down Expand Up @@ -224,10 +224,10 @@ import f2 = require("./f.cjs"); // { default: 0 }
>f2 : typeof f2

import g1 from "./g"; // { default: 0 }
>g1 : typeof g1
>g1 : 0

import g2 = require("./g"); // { default: 0 }
>g2 : typeof g1
>g2 : typeof g2

=== /main3.cjs ===
import { x, y } from "./a"; // No y
Expand Down Expand Up @@ -289,11 +289,11 @@ const f2 = require("./f.cjs"); // { default: 0 }
>"./f.cjs" : "./f.cjs"

import g1 from "./g"; // { default: 0 }
>g1 : typeof g1
>g1 : 0

const g2 = require("./g"); // { default: 0 }
>g2 : typeof g1
>require("./g") : typeof g1
>g2 : typeof g2
>require("./g") : typeof g2
>require : any
>"./g" : "./g"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,31 @@

import a1 = require("./a"); // { x: 0 }
>a1 : typeof a1
@@= skipped -119, +119 lines =@@
@@= skipped -101, +101 lines =@@
>default : 0

import g1 from "./g"; // { default: 0 }
->g1 : typeof g1
+>g1 : 0

g1.default;
->g1.default : 0
->g1 : typeof g1
->default : 0
+>g1.default : any
+>g1 : 0
+>default : any

import g2 = require("./g"); // { default: 0 }
->g2 : typeof g1
+>g2 : typeof g2

g2.default;
>g2.default : 0
->g2 : typeof g1
+>g2 : typeof g2
>default : 0

=== /main2.mts ===
import { x, y } from "./a"; // No y
>x : 0
Expand All @@ -35,12 +59,36 @@

import a1 = require("./a"); // { x: 0 }
>a1 : typeof a1
@@= skipped -62, +62 lines =@@
@@= skipped -72, +72 lines =@@
>f2 : typeof f2

import g1 from "./g"; // { default: 0 }
->g1 : typeof g1
+>g1 : 0

import g2 = require("./g"); // { default: 0 }
->g2 : typeof g1
+>g2 : typeof g2

=== /main3.cjs ===
import { x, y } from "./a"; // No y
>x : 0
->y : any
+>y : 0

import a1 = require("./a"); // Error in JS
>a1 : typeof a1
>a1 : typeof a1
@@= skipped -65, +65 lines =@@
>"./f.cjs" : "./f.cjs"

import g1 from "./g"; // { default: 0 }
->g1 : typeof g1
+>g1 : 0

const g2 = require("./g"); // { default: 0 }
->g2 : typeof g1
->require("./g") : typeof g1
+>g2 : typeof g2
+>require("./g") : typeof g2
>require : any
>"./g" : "./g"
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ exports.equal()
/// <reference path="node.d.ts"/>
var myAssert = require('assert');
//// [app.js]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
export var equal = myAssert.equal;
exports.equal = myAssert.equal;
exports.equal();
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
/// <reference path="node.d.ts"/>
var myAssert = require('assert');
//// [app.js]
+"use strict";
+Object.defineProperty(exports, "__esModule", { value: true });
+export var equal = myAssert.equal;
exports.equal = myAssert.equal;
exports.equal();
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ exports.y = 2;


//// [assignmentToVoidZero1.js]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
// #38552
export var y = exports.x = void 0;
// #38552
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
--- old.assignmentToVoidZero1.js
+++ new.assignmentToVoidZero1.js
@@= skipped -8, +8 lines =@@
@@= skipped -7, +7 lines =@@


//// [assignmentToVoidZero1.js]
// #38552
+export var y = exports.x = void 0;
+"use strict";
+Object.defineProperty(exports, "__esModule", { value: true });
+// #38552
+export var y = exports.x = void 0;
// #38552
exports.y = exports.x = void 0;
+export var x = 1;
exports.x = 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ j + k


//// [assignmentToVoidZero2.js]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
export var j = 1;
exports.j = 1;
export var k = void 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@


//// [assignmentToVoidZero2.js]
+"use strict";
+Object.defineProperty(exports, "__esModule", { value: true });
+export var j = 1;
exports.j = 1;
+export var k = void 0;
exports.k = void 0;
var o = {};
o.x = 1;
@@= skipped -20, +22 lines =@@
@@= skipped -20, +24 lines =@@


//// [assignmentToVoidZero2.d.ts]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ var diddy = funky(1)


//// [commonJSAliasedExport.js]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const donkey = (ast) => ast;
function funky(declaration) {
return false;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
--- old.commonJSAliasedExport.js
+++ new.commonJSAliasedExport.js
@@= skipped -22, +22 lines =@@
@@= skipped -17, +17 lines =@@


//// [commonJSAliasedExport.js]
+"use strict";
+Object.defineProperty(exports, "__esModule", { value: true });
const donkey = (ast) => ast;
function funky(declaration) {
return false;
}
module.exports = donkey;
+export var funky = funky;
module.exports.funky = funky;
//// [bug43713.js]
const { funky } = require('./commonJSAliasedExport');
@@= skipped -9, +10 lines =@@
@@= skipped -14, +17 lines =@@


//// [commonJSAliasedExport.d.ts]
Expand Down
Loading