Skip to content

Commit 4a929db

Browse files
authored
Ignore reparsed nodes when determining external module indicator (#2044)
1 parent 7c19676 commit 4a929db

File tree

76 files changed

+355
-472
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+355
-472
lines changed

internal/ast/parseoptions.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@ func isFileProbablyExternalModule(sourceFile *SourceFile) *Node {
112112
}
113113

114114
func isAnExternalModuleIndicatorNode(node *Node) bool {
115+
if node.Flags&NodeFlagsReparsed != 0 {
116+
return false
117+
}
115118
return HasSyntacticModifier(node, ModifierFlagsExport) ||
116119
IsImportEqualsDeclaration(node) && IsExternalModuleReference(node.AsImportEqualsDeclaration().ModuleReference) ||
117120
IsImportDeclaration(node) || IsExportAssignment(node) || IsExportDeclaration(node)

testdata/baselines/reference/compiler/jsDeclarationExportDefaultAssignmentCrash.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ exports.default = () => {
77

88

99
//// [index.js]
10-
"use strict";
11-
Object.defineProperty(exports, "__esModule", { value: true });
1210
export var default = () => {
1311
return 1234;
1412
};

testdata/baselines/reference/submodule/compiler/jsFileAlternativeUseOfOverloadTag.js

Lines changed: 99 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,9 @@ const example3 = {
5555

5656

5757
//// [jsFileAlternativeUseOfOverloadTag.js]
58-
"use strict";
5958
// These are a few examples of existing alternative uses of @overload tag.
6059
// They will not work as expected with our implementation, but we are
6160
// trying to make sure that our changes do not result in any crashes here.
62-
Object.defineProperty(exports, "__esModule", { value: true });
6361
const example1 = {
6462
/**
6563
* @overload Example1(value)
@@ -108,17 +106,115 @@ const example3 = {
108106

109107

110108
//// [jsFileAlternativeUseOfOverloadTag.d.ts]
109+
declare function Example1(value: any): any;
110+
declare const example1: {
111+
/**
112+
* @overload Example1(value)
113+
* Creates Example1
114+
* @param value [String]
115+
*/
116+
constructor: (value: any, options: any) => void;
117+
};
118+
declare function Example2(value: any, secretAccessKey: any, sessionToken: any): any;
119+
declare function Example2(): any;
120+
declare const example2: {
121+
/**
122+
* Example 2
123+
*
124+
* @overload Example2(value)
125+
* Creates Example2
126+
* @param value [String]
127+
* @param secretAccessKey [String]
128+
* @param sessionToken [String]
129+
* @example Creates with string value
130+
* const example = new Example('');
131+
* @overload Example2(options)
132+
* Creates Example2
133+
* @option options value [String]
134+
* @example Creates with options object
135+
* const example = new Example2({
136+
* value: '',
137+
* });
138+
*/
139+
constructor: () => void;
140+
};
141+
declare function evaluate(): any;
111142
export type callback = (error: any, result: any) ;
143+
declare const example3: {
144+
/**
145+
* @overload evaluate(options = {}, [callback])
146+
* Evaluate something
147+
* @note Something interesting
148+
* @param options [map]
149+
* @return [string] returns evaluation result
150+
* @return [null] returns nothing if callback provided
151+
* @callback callback function (error, result)
152+
* If callback is provided it will be called with evaluation result
153+
* @param error [Error]
154+
* @param result [String]
155+
* @see callback
156+
*/
157+
evaluate: (options: any, callback: any) => void;
158+
};
112159

113160

114161
//// [DtsFileErrors]
115162

116163

117-
dist/jsFileAlternativeUseOfOverloadTag.d.ts(1,50): error TS1005: '=>' expected.
164+
dist/jsFileAlternativeUseOfOverloadTag.d.ts(34,50): error TS1005: '=>' expected.
118165

119166

120167
==== dist/jsFileAlternativeUseOfOverloadTag.d.ts (1 errors) ====
168+
declare function Example1(value: any): any;
169+
declare const example1: {
170+
/**
171+
* @overload Example1(value)
172+
* Creates Example1
173+
* @param value [String]
174+
*/
175+
constructor: (value: any, options: any) => void;
176+
};
177+
declare function Example2(value: any, secretAccessKey: any, sessionToken: any): any;
178+
declare function Example2(): any;
179+
declare const example2: {
180+
/**
181+
* Example 2
182+
*
183+
* @overload Example2(value)
184+
* Creates Example2
185+
* @param value [String]
186+
* @param secretAccessKey [String]
187+
* @param sessionToken [String]
188+
* @example Creates with string value
189+
* const example = new Example('');
190+
* @overload Example2(options)
191+
* Creates Example2
192+
* @option options value [String]
193+
* @example Creates with options object
194+
* const example = new Example2({
195+
* value: '',
196+
* });
197+
*/
198+
constructor: () => void;
199+
};
200+
declare function evaluate(): any;
121201
export type callback = (error: any, result: any) ;
122202
~
123203
!!! error TS1005: '=>' expected.
204+
declare const example3: {
205+
/**
206+
* @overload evaluate(options = {}, [callback])
207+
* Evaluate something
208+
* @note Something interesting
209+
* @param options [map]
210+
* @return [string] returns evaluation result
211+
* @return [null] returns nothing if callback provided
212+
* @callback callback function (error, result)
213+
* If callback is provided it will be called with evaluation result
214+
* @param error [Error]
215+
* @param result [String]
216+
* @see callback
217+
*/
218+
evaluate: (options: any, callback: any) => void;
219+
};
124220

testdata/baselines/reference/submodule/compiler/jsFileAlternativeUseOfOverloadTag.js.diff

Lines changed: 95 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,17 @@
11
--- old.jsFileAlternativeUseOfOverloadTag.js
22
+++ new.jsFileAlternativeUseOfOverloadTag.js
3-
@@= skipped -54, +54 lines =@@
4-
5-
6-
//// [jsFileAlternativeUseOfOverloadTag.js]
7-
+"use strict";
8-
// These are a few examples of existing alternative uses of @overload tag.
9-
// They will not work as expected with our implementation, but we are
10-
// trying to make sure that our changes do not result in any crashes here.
11-
+Object.defineProperty(exports, "__esModule", { value: true });
12-
const example1 = {
13-
/**
14-
* @overload Example1(value)
15-
@@= skipped -51, +53 lines =@@
3+
@@= skipped -105, +105 lines =@@
164

175

186
//// [jsFileAlternativeUseOfOverloadTag.d.ts]
197
-declare namespace example1 {
20-
- /**
21-
- * @overload Example1(value)
22-
- * Creates Example1
23-
- * @param value [String]
24-
- */
8+
+declare function Example1(value: any): any;
9+
+declare const example1: {
10+
/**
11+
* @overload Example1(value)
12+
* Creates Example1
13+
* @param value [String]
14+
*/
2515
- function constructor(value: any): any;
2616
-}
2717
-declare namespace example2 {
@@ -66,37 +56,109 @@
6656
- export { constructor_1 as constructor };
6757
-}
6858
-declare namespace example3 {
69-
- /**
70-
- * @overload evaluate(options = {}, [callback])
71-
- * Evaluate something
72-
- * @note Something interesting
73-
- * @param options [map]
74-
- * @return [string] returns evaluation result
75-
- * @return [null] returns nothing if callback provided
76-
- * @callback callback function (error, result)
77-
- * If callback is provided it will be called with evaluation result
78-
- * @param error [Error]
79-
- * @param result [String]
80-
- * @see callback
81-
- */
59+
+ constructor: (value: any, options: any) => void;
60+
+};
61+
+declare function Example2(value: any, secretAccessKey: any, sessionToken: any): any;
62+
+declare function Example2(): any;
63+
+declare const example2: {
64+
+ /**
65+
+ * Example 2
66+
+ *
67+
+ * @overload Example2(value)
68+
+ * Creates Example2
69+
+ * @param value [String]
70+
+ * @param secretAccessKey [String]
71+
+ * @param sessionToken [String]
72+
+ * @example Creates with string value
73+
+ * const example = new Example('');
74+
+ * @overload Example2(options)
75+
+ * Creates Example2
76+
+ * @option options value [String]
77+
+ * @example Creates with options object
78+
+ * const example = new Example2({
79+
+ * value: '',
80+
+ * });
81+
+ */
82+
+ constructor: () => void;
83+
+};
84+
+declare function evaluate(): any;
85+
+export type callback = (error: any, result: any) ;
86+
+declare const example3: {
87+
/**
88+
* @overload evaluate(options = {}, [callback])
89+
* Evaluate something
90+
@@= skipped -63, +48 lines =@@
91+
* @param result [String]
92+
* @see callback
93+
*/
8294
- function evaluate(): any;
8395
-}
8496
-/**
8597
- * function (error, result)
8698
- * If callback is provided it will be called with evaluation result
8799
- */
88100
-type callback = (error: any, result: any) => any;
89-
+export type callback = (error: any, result: any) ;
101+
+ evaluate: (options: any, callback: any) => void;
102+
+};
90103
+
91104
+
92105
+//// [DtsFileErrors]
93106
+
94107
+
95-
+dist/jsFileAlternativeUseOfOverloadTag.d.ts(1,50): error TS1005: '=>' expected.
108+
+dist/jsFileAlternativeUseOfOverloadTag.d.ts(34,50): error TS1005: '=>' expected.
96109
+
97110
+
98111
+==== dist/jsFileAlternativeUseOfOverloadTag.d.ts (1 errors) ====
112+
+ declare function Example1(value: any): any;
113+
+ declare const example1: {
114+
+ /**
115+
+ * @overload Example1(value)
116+
+ * Creates Example1
117+
+ * @param value [String]
118+
+ */
119+
+ constructor: (value: any, options: any) => void;
120+
+ };
121+
+ declare function Example2(value: any, secretAccessKey: any, sessionToken: any): any;
122+
+ declare function Example2(): any;
123+
+ declare const example2: {
124+
+ /**
125+
+ * Example 2
126+
+ *
127+
+ * @overload Example2(value)
128+
+ * Creates Example2
129+
+ * @param value [String]
130+
+ * @param secretAccessKey [String]
131+
+ * @param sessionToken [String]
132+
+ * @example Creates with string value
133+
+ * const example = new Example('');
134+
+ * @overload Example2(options)
135+
+ * Creates Example2
136+
+ * @option options value [String]
137+
+ * @example Creates with options object
138+
+ * const example = new Example2({
139+
+ * value: '',
140+
+ * });
141+
+ */
142+
+ constructor: () => void;
143+
+ };
144+
+ declare function evaluate(): any;
99145
+ export type callback = (error: any, result: any) ;
100146
+ ~
101147
+!!! error TS1005: '=>' expected.
148+
+ declare const example3: {
149+
+ /**
150+
+ * @overload evaluate(options = {}, [callback])
151+
+ * Evaluate something
152+
+ * @note Something interesting
153+
+ * @param options [map]
154+
+ * @return [string] returns evaluation result
155+
+ * @return [null] returns nothing if callback provided
156+
+ * @callback callback function (error, result)
157+
+ * If callback is provided it will be called with evaluation result
158+
+ * @param error [Error]
159+
+ * @param result [String]
160+
+ * @see callback
161+
+ */
162+
+ evaluate: (options: any, callback: any) => void;
163+
+ };
102164
+

testdata/baselines/reference/submodule/compiler/modulePreserve4.errors.txt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
/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`.
33
/main1.ts(19,4): error TS2339: Property 'default' does not exist on type '() => void'.
44
/main1.ts(23,8): error TS1192: Module '"/e"' has no default export.
5-
/main1.ts(30,4): error TS2339: Property 'default' does not exist on type '0'.
65
/main2.mts(4,4): error TS2339: Property 'default' does not exist on type 'typeof import("/a")'.
76
/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`.
87
/main2.mts(14,8): error TS1192: Module '"/e"' has no default export.
@@ -43,7 +42,7 @@
4342
==== /g.js (0 errors) ====
4443
exports.default = 0;
4544

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

8180
import g1 from "./g"; // { default: 0 }
8281
g1.default;
83-
~~~~~~~
84-
!!! error TS2339: Property 'default' does not exist on type '0'.
8582
import g2 = require("./g"); // { default: 0 }
8683
g2.default;
8784

testdata/baselines/reference/submodule/compiler/modulePreserve4.errors.txt.diff

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
/main1.ts(19,4): error TS2339: Property 'default' does not exist on type '() => void'.
99
/main1.ts(23,8): error TS1192: Module '"/e"' has no default export.
1010
-/main2.mts(1,13): error TS2305: Module '"./a"' has no exported member 'y'.
11-
+/main1.ts(30,4): error TS2339: Property 'default' does not exist on type '0'.
1211
/main2.mts(4,4): error TS2339: Property 'default' does not exist on type 'typeof import("/a")'.
1312
/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`.
1413
/main2.mts(14,8): error TS1192: Module '"/e"' has no default export.
@@ -18,7 +17,7 @@
1817
/main3.cjs(2,1): error TS8002: 'import ... =' can only be used in TypeScript files.
1918
/main3.cjs(5,8): error TS1293: ECMAScript module syntax is not allowed in a CommonJS module when 'module' is set to 'preserve'.
2019
/main3.cjs(8,8): error TS1293: ECMAScript module syntax is not allowed in a CommonJS module when 'module' is set to 'preserve'.
21-
@@= skipped -18, +16 lines =@@
20+
@@= skipped -18, +15 lines =@@
2221
/main3.cjs(17,8): error TS1293: ECMAScript module syntax is not allowed in a CommonJS module when 'module' is set to 'preserve'.
2322

2423

@@ -31,21 +30,19 @@
3130

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

36-
==== /main1.ts (4 errors) ====
37+
-==== /main1.ts (4 errors) ====
38+
+==== /main1.ts (3 errors) ====
3739
import { x, y } from "./a"; // No y
3840
- ~
3941
-!!! error TS2305: Module '"./a"' has no exported member 'y'.
4042
import a1 = require("./a"); // { x: 0 }
4143
const a2 = require("./a"); // Error in TS
4244
~~~~~~~
43-
@@= skipped -37, +35 lines =@@
44-
45-
import g1 from "./g"; // { default: 0 }
46-
g1.default;
47-
+ ~~~~~~~
48-
+!!! error TS2339: Property 'default' does not exist on type '0'.
45+
@@= skipped -42, +40 lines =@@
4946
import g2 = require("./g"); // { default: 0 }
5047
g2.default;
5148

@@ -57,7 +54,7 @@
5754
import a1 = require("./a"); // { x: 0 }
5855
a1.x;
5956
a1.default.x; // Arguably should exist but doesn't
60-
@@= skipped -38, +38 lines =@@
57+
@@= skipped -35, +33 lines =@@
6158
~
6259
!!! error TS1293: ECMAScript module syntax is not allowed in a CommonJS module when 'module' is set to 'preserve'.
6360
~

0 commit comments

Comments
 (0)