Compare commits
1 commit
main
...
export_def
Author | SHA1 | Date | |
---|---|---|---|
|
876c30bd98 |
|
@ -1226,12 +1226,12 @@ namespace ts {
|
|||
if (token() === SyntaxKind.ExportKeyword) {
|
||||
nextToken();
|
||||
if (token() === SyntaxKind.DefaultKeyword) {
|
||||
return lookAhead(nextTokenIsClassOrFunctionOrAsync);
|
||||
return lookAhead(nextTokenFollowsDefault);
|
||||
}
|
||||
return token() !== SyntaxKind.AsteriskToken && token() !== SyntaxKind.AsKeyword && token() !== SyntaxKind.OpenBraceToken && canFollowModifier();
|
||||
}
|
||||
if (token() === SyntaxKind.DefaultKeyword) {
|
||||
return nextTokenIsClassOrFunctionOrAsync();
|
||||
return nextTokenFollowsDefault();
|
||||
}
|
||||
if (token() === SyntaxKind.StaticKeyword) {
|
||||
nextToken();
|
||||
|
@ -1253,9 +1253,15 @@ namespace ts {
|
|||
|| isLiteralPropertyName();
|
||||
}
|
||||
|
||||
function nextTokenIsClassOrFunctionOrAsync(): boolean {
|
||||
/** Whether a token may follow the `default` keyword */
|
||||
function nextTokenFollowsDefault(): boolean {
|
||||
nextToken();
|
||||
return token() === SyntaxKind.ClassKeyword || token() === SyntaxKind.FunctionKeyword ||
|
||||
return token() === SyntaxKind.ClassKeyword ||
|
||||
token() === SyntaxKind.FunctionKeyword ||
|
||||
token() === SyntaxKind.InterfaceKeyword ||
|
||||
token() === SyntaxKind.TypeKeyword ||
|
||||
token() === SyntaxKind.EnumKeyword ||
|
||||
token() === SyntaxKind.ConstKeyword || // For `const enum`
|
||||
(token() === SyntaxKind.AsyncKeyword && lookAhead(nextTokenIsFunctionKeywordOnSameLine));
|
||||
}
|
||||
|
||||
|
|
15
tests/baselines/reference/exportDefaultConstEnum.js
Normal file
15
tests/baselines/reference/exportDefaultConstEnum.js
Normal file
|
@ -0,0 +1,15 @@
|
|||
//// [tests/cases/compiler/exportDefaultConstEnum.ts] ////
|
||||
|
||||
//// [boolean.ts]
|
||||
export default const enum Boolean { TRUE, FALSE, FILE_NOT_FOUND }
|
||||
|
||||
//// [user.ts]
|
||||
import Boolean from "./boolean";
|
||||
const b: Boolean = Boolean.FILE_NOT_FOUND;
|
||||
|
||||
|
||||
//// [boolean.js]
|
||||
"use strict";
|
||||
//// [user.js]
|
||||
"use strict";
|
||||
var b = 2 /* FILE_NOT_FOUND */;
|
18
tests/baselines/reference/exportDefaultConstEnum.symbols
Normal file
18
tests/baselines/reference/exportDefaultConstEnum.symbols
Normal file
|
@ -0,0 +1,18 @@
|
|||
=== tests/cases/compiler/boolean.ts ===
|
||||
export default const enum Boolean { TRUE, FALSE, FILE_NOT_FOUND }
|
||||
>Boolean : Symbol(Boolean, Decl(boolean.ts, 0, 0))
|
||||
>TRUE : Symbol(Boolean.TRUE, Decl(boolean.ts, 0, 35))
|
||||
>FALSE : Symbol(Boolean.FALSE, Decl(boolean.ts, 0, 41))
|
||||
>FILE_NOT_FOUND : Symbol(Boolean.FILE_NOT_FOUND, Decl(boolean.ts, 0, 48))
|
||||
|
||||
=== tests/cases/compiler/user.ts ===
|
||||
import Boolean from "./boolean";
|
||||
>Boolean : Symbol(Boolean, Decl(user.ts, 0, 6))
|
||||
|
||||
const b: Boolean = Boolean.FILE_NOT_FOUND;
|
||||
>b : Symbol(b, Decl(user.ts, 1, 5))
|
||||
>Boolean : Symbol(Boolean, Decl(user.ts, 0, 6))
|
||||
>Boolean.FILE_NOT_FOUND : Symbol(Boolean.FILE_NOT_FOUND, Decl(boolean.ts, 0, 48))
|
||||
>Boolean : Symbol(Boolean, Decl(user.ts, 0, 6))
|
||||
>FILE_NOT_FOUND : Symbol(Boolean.FILE_NOT_FOUND, Decl(boolean.ts, 0, 48))
|
||||
|
18
tests/baselines/reference/exportDefaultConstEnum.types
Normal file
18
tests/baselines/reference/exportDefaultConstEnum.types
Normal file
|
@ -0,0 +1,18 @@
|
|||
=== tests/cases/compiler/boolean.ts ===
|
||||
export default const enum Boolean { TRUE, FALSE, FILE_NOT_FOUND }
|
||||
>Boolean : Boolean
|
||||
>TRUE : Boolean.TRUE
|
||||
>FALSE : Boolean.FALSE
|
||||
>FILE_NOT_FOUND : Boolean.FILE_NOT_FOUND
|
||||
|
||||
=== tests/cases/compiler/user.ts ===
|
||||
import Boolean from "./boolean";
|
||||
>Boolean : typeof Boolean
|
||||
|
||||
const b: Boolean = Boolean.FILE_NOT_FOUND;
|
||||
>b : Boolean
|
||||
>Boolean : Boolean
|
||||
>Boolean.FILE_NOT_FOUND : Boolean.FILE_NOT_FOUND
|
||||
>Boolean : typeof Boolean
|
||||
>FILE_NOT_FOUND : Boolean.FILE_NOT_FOUND
|
||||
|
22
tests/baselines/reference/exportDefaultEnum.js
Normal file
22
tests/baselines/reference/exportDefaultEnum.js
Normal file
|
@ -0,0 +1,22 @@
|
|||
//// [tests/cases/compiler/exportDefaultEnum.ts] ////
|
||||
|
||||
//// [boolean.ts]
|
||||
export default enum Boolean { TRUE, FALSE, FILE_NOT_FOUND }
|
||||
|
||||
//// [user.ts]
|
||||
import Boolean from "./boolean";
|
||||
const b: Boolean = Boolean.FILE_NOT_FOUND;
|
||||
|
||||
|
||||
//// [boolean.js]
|
||||
"use strict";
|
||||
var Boolean;
|
||||
(function (Boolean) {
|
||||
Boolean[Boolean["TRUE"] = 0] = "TRUE";
|
||||
Boolean[Boolean["FALSE"] = 1] = "FALSE";
|
||||
Boolean[Boolean["FILE_NOT_FOUND"] = 2] = "FILE_NOT_FOUND";
|
||||
})(Boolean = exports.Boolean || (exports.Boolean = {}));
|
||||
//// [user.js]
|
||||
"use strict";
|
||||
var boolean_1 = require("./boolean");
|
||||
var b = boolean_1["default"].FILE_NOT_FOUND;
|
18
tests/baselines/reference/exportDefaultEnum.symbols
Normal file
18
tests/baselines/reference/exportDefaultEnum.symbols
Normal file
|
@ -0,0 +1,18 @@
|
|||
=== tests/cases/compiler/boolean.ts ===
|
||||
export default enum Boolean { TRUE, FALSE, FILE_NOT_FOUND }
|
||||
>Boolean : Symbol(Boolean, Decl(boolean.ts, 0, 0))
|
||||
>TRUE : Symbol(Boolean.TRUE, Decl(boolean.ts, 0, 29))
|
||||
>FALSE : Symbol(Boolean.FALSE, Decl(boolean.ts, 0, 35))
|
||||
>FILE_NOT_FOUND : Symbol(Boolean.FILE_NOT_FOUND, Decl(boolean.ts, 0, 42))
|
||||
|
||||
=== tests/cases/compiler/user.ts ===
|
||||
import Boolean from "./boolean";
|
||||
>Boolean : Symbol(Boolean, Decl(user.ts, 0, 6))
|
||||
|
||||
const b: Boolean = Boolean.FILE_NOT_FOUND;
|
||||
>b : Symbol(b, Decl(user.ts, 1, 5))
|
||||
>Boolean : Symbol(Boolean, Decl(user.ts, 0, 6))
|
||||
>Boolean.FILE_NOT_FOUND : Symbol(Boolean.FILE_NOT_FOUND, Decl(boolean.ts, 0, 42))
|
||||
>Boolean : Symbol(Boolean, Decl(user.ts, 0, 6))
|
||||
>FILE_NOT_FOUND : Symbol(Boolean.FILE_NOT_FOUND, Decl(boolean.ts, 0, 42))
|
||||
|
18
tests/baselines/reference/exportDefaultEnum.types
Normal file
18
tests/baselines/reference/exportDefaultEnum.types
Normal file
|
@ -0,0 +1,18 @@
|
|||
=== tests/cases/compiler/boolean.ts ===
|
||||
export default enum Boolean { TRUE, FALSE, FILE_NOT_FOUND }
|
||||
>Boolean : Boolean
|
||||
>TRUE : Boolean.TRUE
|
||||
>FALSE : Boolean.FALSE
|
||||
>FILE_NOT_FOUND : Boolean.FILE_NOT_FOUND
|
||||
|
||||
=== tests/cases/compiler/user.ts ===
|
||||
import Boolean from "./boolean";
|
||||
>Boolean : typeof Boolean
|
||||
|
||||
const b: Boolean = Boolean.FILE_NOT_FOUND;
|
||||
>b : Boolean
|
||||
>Boolean : Boolean
|
||||
>Boolean.FILE_NOT_FOUND : Boolean.FILE_NOT_FOUND
|
||||
>Boolean : typeof Boolean
|
||||
>FILE_NOT_FOUND : Boolean.FILE_NOT_FOUND
|
||||
|
17
tests/baselines/reference/exportDefaultInterface.js
Normal file
17
tests/baselines/reference/exportDefaultInterface.js
Normal file
|
@ -0,0 +1,17 @@
|
|||
//// [tests/cases/compiler/exportDefaultInterface.ts] ////
|
||||
|
||||
//// [interface.ts]
|
||||
export default interface I {
|
||||
x: number;
|
||||
}
|
||||
|
||||
//// [user.ts]
|
||||
import I from "./interface";
|
||||
const x: I = { x: 0 };
|
||||
|
||||
|
||||
//// [interface.js]
|
||||
"use strict";
|
||||
//// [user.js]
|
||||
"use strict";
|
||||
var x = { x: 0 };
|
17
tests/baselines/reference/exportDefaultInterface.symbols
Normal file
17
tests/baselines/reference/exportDefaultInterface.symbols
Normal file
|
@ -0,0 +1,17 @@
|
|||
=== tests/cases/compiler/interface.ts ===
|
||||
export default interface I {
|
||||
>I : Symbol(I, Decl(interface.ts, 0, 0))
|
||||
|
||||
x: number;
|
||||
>x : Symbol(I.x, Decl(interface.ts, 0, 28))
|
||||
}
|
||||
|
||||
=== tests/cases/compiler/user.ts ===
|
||||
import I from "./interface";
|
||||
>I : Symbol(I, Decl(user.ts, 0, 6))
|
||||
|
||||
const x: I = { x: 0 };
|
||||
>x : Symbol(x, Decl(user.ts, 1, 5))
|
||||
>I : Symbol(I, Decl(user.ts, 0, 6))
|
||||
>x : Symbol(x, Decl(user.ts, 1, 14))
|
||||
|
19
tests/baselines/reference/exportDefaultInterface.types
Normal file
19
tests/baselines/reference/exportDefaultInterface.types
Normal file
|
@ -0,0 +1,19 @@
|
|||
=== tests/cases/compiler/interface.ts ===
|
||||
export default interface I {
|
||||
>I : I
|
||||
|
||||
x: number;
|
||||
>x : number
|
||||
}
|
||||
|
||||
=== tests/cases/compiler/user.ts ===
|
||||
import I from "./interface";
|
||||
>I : any
|
||||
|
||||
const x: I = { x: 0 };
|
||||
>x : I
|
||||
>I : I
|
||||
>{ x: 0 } : { x: number; }
|
||||
>x : number
|
||||
>0 : 0
|
||||
|
15
tests/baselines/reference/exportDefaultType.js
Normal file
15
tests/baselines/reference/exportDefaultType.js
Normal file
|
@ -0,0 +1,15 @@
|
|||
//// [tests/cases/compiler/exportDefaultType.ts] ////
|
||||
|
||||
//// [a.ts]
|
||||
export default type T = number;
|
||||
|
||||
//// [b.ts]
|
||||
import T from "./a";
|
||||
const x: T = 0;
|
||||
|
||||
|
||||
//// [a.js]
|
||||
"use strict";
|
||||
//// [b.js]
|
||||
"use strict";
|
||||
var x = 0;
|
12
tests/baselines/reference/exportDefaultType.symbols
Normal file
12
tests/baselines/reference/exportDefaultType.symbols
Normal file
|
@ -0,0 +1,12 @@
|
|||
=== tests/cases/compiler/a.ts ===
|
||||
export default type T = number;
|
||||
>T : Symbol(T, Decl(a.ts, 0, 0))
|
||||
|
||||
=== tests/cases/compiler/b.ts ===
|
||||
import T from "./a";
|
||||
>T : Symbol(T, Decl(b.ts, 0, 6))
|
||||
|
||||
const x: T = 0;
|
||||
>x : Symbol(x, Decl(b.ts, 1, 5))
|
||||
>T : Symbol(T, Decl(b.ts, 0, 6))
|
||||
|
13
tests/baselines/reference/exportDefaultType.types
Normal file
13
tests/baselines/reference/exportDefaultType.types
Normal file
|
@ -0,0 +1,13 @@
|
|||
=== tests/cases/compiler/a.ts ===
|
||||
export default type T = number;
|
||||
>T : number
|
||||
|
||||
=== tests/cases/compiler/b.ts ===
|
||||
import T from "./a";
|
||||
>T : any
|
||||
|
||||
const x: T = 0;
|
||||
>x : number
|
||||
>T : number
|
||||
>0 : 0
|
||||
|
6
tests/cases/compiler/exportDefaultConstEnum.ts
Normal file
6
tests/cases/compiler/exportDefaultConstEnum.ts
Normal file
|
@ -0,0 +1,6 @@
|
|||
// @Filename: boolean.ts
|
||||
export default const enum Boolean { TRUE, FALSE, FILE_NOT_FOUND }
|
||||
|
||||
// @Filename: user.ts
|
||||
import Boolean from "./boolean";
|
||||
const b: Boolean = Boolean.FILE_NOT_FOUND;
|
6
tests/cases/compiler/exportDefaultEnum.ts
Normal file
6
tests/cases/compiler/exportDefaultEnum.ts
Normal file
|
@ -0,0 +1,6 @@
|
|||
// @Filename: boolean.ts
|
||||
export default enum Boolean { TRUE, FALSE, FILE_NOT_FOUND }
|
||||
|
||||
// @Filename: user.ts
|
||||
import Boolean from "./boolean";
|
||||
const b: Boolean = Boolean.FILE_NOT_FOUND;
|
8
tests/cases/compiler/exportDefaultInterface.ts
Normal file
8
tests/cases/compiler/exportDefaultInterface.ts
Normal file
|
@ -0,0 +1,8 @@
|
|||
// @Filename: interface.ts
|
||||
export default interface I {
|
||||
x: number;
|
||||
}
|
||||
|
||||
// @Filename: user.ts
|
||||
import I from "./interface";
|
||||
const x: I = { x: 0 };
|
6
tests/cases/compiler/exportDefaultType.ts
Normal file
6
tests/cases/compiler/exportDefaultType.ts
Normal file
|
@ -0,0 +1,6 @@
|
|||
// @Filename: a.ts
|
||||
export default type T = number;
|
||||
|
||||
// @Filename: b.ts
|
||||
import T from "./a";
|
||||
const x: T = 0;
|
Loading…
Reference in a new issue