1
1
import * as ts from "../../_namespaces/ts.js" ;
2
- import * as Utils from "../../_namespaces/Utils.js" ;
3
- import * as vfs from "../../_namespaces/vfs.js" ;
2
+ import { dedent } from "../../_namespaces/Utils.js" ;
3
+ import { FileSystem } from "../../_namespaces/vfs.js" ;
4
4
import { jsonToReadableText } from "../helpers.js" ;
5
5
import {
6
6
compilerOptionsToConfigJson ,
@@ -27,7 +27,7 @@ describe("unittests:: tsc:: incremental::", () => {
27
27
fs :( ) =>
28
28
loadProjectFromFiles ( {
29
29
"/src/project/src/main.ts" :"export const x = 10;" ,
30
- "/src/project/tsconfig.json" :Utils . dedent `
30
+ "/src/project/tsconfig.json" :dedent `
31
31
{
32
32
"compilerOptions": {
33
33
"target": "es5",
@@ -48,7 +48,7 @@ describe("unittests:: tsc:: incremental::", () => {
48
48
fs :( ) =>
49
49
loadProjectFromFiles ( {
50
50
"/src/project/src/main.ts" :"export const x = 10;" ,
51
- "/src/project/tsconfig.json" :Utils . dedent `
51
+ "/src/project/tsconfig.json" :dedent `
52
52
{
53
53
"compilerOptions": {
54
54
"incremental": true,
@@ -85,7 +85,7 @@ describe("unittests:: tsc:: incremental::", () => {
85
85
fs :( ) =>
86
86
loadProjectFromFiles ( {
87
87
"/src/project/src/main.ts" :"export const x = 10;" ,
88
- "/src/project/tsconfig.json" :Utils . dedent `
88
+ "/src/project/tsconfig.json" :dedent `
89
89
{
90
90
"compilerOptions": {
91
91
"incremental": true,
@@ -115,7 +115,7 @@ describe("unittests:: tsc:: incremental::", () => {
115
115
} ) ;
116
116
117
117
describe ( "with noEmitOnError" , ( ) => {
118
- let projFs :vfs . FileSystem ;
118
+ let projFs :FileSystem ;
119
119
before ( ( ) => {
120
120
projFs = getFsForNoEmitOnError ( ) ;
121
121
} ) ;
@@ -275,25 +275,25 @@ const a: string = 10;`,
275
275
276
276
function fs ( ) {
277
277
return loadProjectFromFiles ( {
278
- "/src/project/src/class.ts" :Utils . dedent `
278
+ "/src/project/src/class.ts" :dedent `
279
279
export class classC {
280
280
prop = 1;
281
281
}` ,
282
- "/src/project/src/indirectClass.ts" :Utils . dedent `
282
+ "/src/project/src/indirectClass.ts" :dedent `
283
283
import { classC } from './class';
284
284
export class indirectClass {
285
285
classC = new classC();
286
286
}` ,
287
- "/src/project/src/directUse.ts" :Utils . dedent `
287
+ "/src/project/src/directUse.ts" :dedent `
288
288
import { indirectClass } from './indirectClass';
289
289
new indirectClass().classC.prop;` ,
290
- "/src/project/src/indirectUse.ts" :Utils . dedent `
290
+ "/src/project/src/indirectUse.ts" :dedent `
291
291
import { indirectClass } from './indirectClass';
292
292
new indirectClass().classC.prop;` ,
293
- "/src/project/src/noChangeFile.ts" :Utils . dedent `
293
+ "/src/project/src/noChangeFile.ts" :dedent `
294
294
export function writeLog(s: string) {
295
295
}` ,
296
- "/src/project/src/noChangeFileWithEmitSpecificError.ts" :Utils . dedent `
296
+ "/src/project/src/noChangeFileWithEmitSpecificError.ts" :dedent `
297
297
function someFunc(arguments: boolean, ...rest: any[]) {
298
298
}` ,
299
299
"/src/project/tsconfig.json" :jsonToReadableText ( { compilerOptions} ) ,
@@ -307,12 +307,12 @@ const a: string = 10;`,
307
307
subScenario :`when global file is added, the signatures are updated` ,
308
308
fs :( ) =>
309
309
loadProjectFromFiles ( {
310
- "/src/project/src/main.ts" :Utils . dedent `
310
+ "/src/project/src/main.ts" :dedent `
311
311
/// <reference path="./filePresent.ts"/>
312
312
/// <reference path="./fileNotFound.ts"/>
313
313
function main() { }
314
314
` ,
315
- "/src/project/src/anotherFileWithSameReferenes.ts" :Utils . dedent `
315
+ "/src/project/src/anotherFileWithSameReferenes.ts" :dedent `
316
316
/// <reference path="./filePresent.ts"/>
317
317
/// <reference path="./fileNotFound.ts"/>
318
318
function anotherFileWithSameReferenes() { }
@@ -495,7 +495,7 @@ declare global {
495
495
module :"esnext" ,
496
496
} ,
497
497
} ) ,
498
- "/src/project/index.tsx" :Utils . dedent `
498
+ "/src/project/index.tsx" :dedent `
499
499
declare namespace JSX {
500
500
interface ElementChildrenAttribute { children: {}; }
501
501
interface IntrinsicElements { div: {} }
@@ -518,7 +518,7 @@ declare global {
518
518
subScenario :"ts file with no-default-lib that augments the global scope" ,
519
519
fs :( ) =>
520
520
loadProjectFromFiles ( {
521
- "/src/project/src/main.ts" :Utils . dedent `
521
+ "/src/project/src/main.ts" :dedent `
522
522
/// <reference no-default-lib="true"/>
523
523
/// <reference lib="esnext" />
524
524
@@ -529,7 +529,7 @@ declare global {
529
529
530
530
export {};
531
531
` ,
532
- "/src/project/tsconfig.json" :Utils . dedent `
532
+ "/src/project/tsconfig.json" :dedent `
533
533
{
534
534
"compilerOptions": {
535
535
"target": "ESNext",
@@ -590,12 +590,12 @@ console.log(a);`,
590
590
fs :( ) =>
591
591
loadProjectFromFiles ( {
592
592
"/src/project/tsconfig.json" :jsonToReadableText ( { compilerOptions :{ declaration} } ) ,
593
- "/src/project/main.ts" :Utils . dedent `
593
+ "/src/project/main.ts" :dedent `
594
594
import MessageablePerson from './MessageablePerson.js';
595
595
function logMessage( person: MessageablePerson ) {
596
596
console.log( person.message );
597
597
}` ,
598
- "/src/project/MessageablePerson.ts" :Utils . dedent `
598
+ "/src/project/MessageablePerson.ts" :dedent `
599
599
const Messageable = () => {
600
600
return class MessageableClass {
601
601
public message = 'hello';
@@ -609,7 +609,7 @@ console.log(a);`,
609
609
appendText (
610
610
fs ,
611
611
"/lib/lib.d.ts" ,
612
- Utils . dedent `
612
+ dedent `
613
613
type ReturnType<T extends (...args: any) => any> = T extends (...args: any) => infer R ? R : any;
614
614
type InstanceType<T extends abstract new (...args: any) => any> = T extends abstract new (...args: any) => infer R ? R : any;` ,
615
615
) ,
@@ -922,12 +922,12 @@ console.log(a);`,
922
922
} ,
923
923
include :[ "src" ] ,
924
924
} ) ,
925
- "/src/project/src/box.ts" :Utils . dedent `
925
+ "/src/project/src/box.ts" :dedent `
926
926
export interface Box<T> {
927
927
unbox(): T
928
928
}
929
929
` ,
930
- "/src/project/src/bug.js" :Utils . dedent `
930
+ "/src/project/src/bug.js" :dedent `
931
931
import * as B from "./box.js"
932
932
import * as W from "./wrap.js"
933
933
@@ -947,7 +947,7 @@ console.log(a);`,
947
947
948
948
export const bug = wrap({ n: box(1) });
949
949
` ,
950
- "/src/project/src/wrap.ts" :Utils . dedent `
950
+ "/src/project/src/wrap.ts" :dedent `
951
951
export type Wrap<C> = {
952
952
[K in keyof C]: { wrapped: C[K] }
953
953
}
@@ -974,14 +974,14 @@ console.log(a);`,
974
974
skipDefaultLibCheck :true ,
975
975
} ,
976
976
} ) ,
977
- "/src/project/index.ts" :Utils . dedent `
977
+ "/src/project/index.ts" :dedent `
978
978
import ky from 'ky';
979
979
export const api = ky.extend({});
980
980
` ,
981
981
"/src/project/package.json" :jsonToReadableText ( {
982
982
type :"module" ,
983
983
} ) ,
984
- "/src/project/node_modules/ky/distribution/index.d.ts" :Utils . dedent `
984
+ "/src/project/node_modules/ky/distribution/index.d.ts" :dedent `
985
985
type KyInstance = {
986
986
extend(options: Record<string,unknown>): KyInstance;
987
987
}
@@ -1003,4 +1003,79 @@ console.log(a);`,
1003
1003
} ,
1004
1004
] ,
1005
1005
} ) ;
1006
+
1007
+ describe ( "with const enums" , ( ) => {
1008
+ enum AliasType {
1009
+ None = "" ,
1010
+ SameFile = "aliased " ,
1011
+ DifferentFile = "aliased in different file " ,
1012
+ }
1013
+ function fileWithEnum ( withAlias :AliasType ) {
1014
+ return withAlias !== AliasType . DifferentFile ?"/src/project/b.d.ts" :"/src/project/worker.d.ts" ;
1015
+ }
1016
+ function verify ( withAlias :AliasType , preserveConstEnums :boolean ) {
1017
+ verifyTsc ( {
1018
+ scenario :"incremental" ,
1019
+ subScenario :`with${ withAlias } const enums${ preserveConstEnums ?" with preserveConstEnums" :"" } ` ,
1020
+ commandLineArgs :[ "-i" , `/src/project/a.ts` , "--tsbuildinfofile" , "/src/project/a.tsbuildinfo" , ...preserveConstEnums ?[ "--preserveConstEnums" ] :[ ] ] ,
1021
+ fs :( ) =>
1022
+ loadProjectFromFiles ( {
1023
+ "/src/project/a.ts" :dedent `
1024
+ import {A} from "./c"
1025
+ let a = A.ONE
1026
+ ` ,
1027
+ "/src/project/b.d.ts" :withAlias === AliasType . SameFile ?
1028
+ dedent `
1029
+ declare const enum AWorker {
1030
+ ONE = 1
1031
+ }
1032
+ export { AWorker as A };
1033
+ ` :
1034
+ withAlias === AliasType . DifferentFile ?
1035
+ dedent `
1036
+ export { AWorker as A } from "./worker";
1037
+ ` :
1038
+ dedent `
1039
+ export const enum A {
1040
+ ONE = 1
1041
+ }
1042
+ ` ,
1043
+ "/src/project/c.ts" :dedent `
1044
+ import {A} from "./b"
1045
+ let b = A.ONE
1046
+ export {A}
1047
+ ` ,
1048
+ "/src/project/worker.d.ts" :dedent `
1049
+ export const enum AWorker {
1050
+ ONE = 1
1051
+ }
1052
+ ` ,
1053
+ } ) ,
1054
+ edits :[
1055
+ {
1056
+ caption :"change enum value" ,
1057
+ edit :fs => replaceText ( fs , fileWithEnum ( withAlias ) , "1" , "2" ) ,
1058
+ } ,
1059
+ {
1060
+ caption :"change enum value again" ,
1061
+ edit :fs => replaceText ( fs , fileWithEnum ( withAlias ) , "2" , "3" ) ,
1062
+ } ,
1063
+ {
1064
+ caption :"something else changes in b.d.ts" ,
1065
+ edit :fs => appendText ( fs , "/src/project/b.d.ts" , "export const randomThing = 10;" ) ,
1066
+ } ,
1067
+ {
1068
+ caption :"something else changes in b.d.ts again" ,
1069
+ edit :fs => appendText ( fs , "/src/project/b.d.ts" , "export const randomThing2 = 10;" ) ,
1070
+ } ,
1071
+ ] ,
1072
+ } ) ;
1073
+ }
1074
+ verify ( /*withAlias*/ AliasType . None , /*preserveConstEnums*/ false ) ;
1075
+ verify ( /*withAlias*/ AliasType . SameFile , /*preserveConstEnums*/ false ) ;
1076
+ verify ( /*withAlias*/ AliasType . DifferentFile , /*preserveConstEnums*/ false ) ;
1077
+ verify ( /*withAlias*/ AliasType . None , /*preserveConstEnums*/ true ) ;
1078
+ verify ( /*withAlias*/ AliasType . SameFile , /*preserveConstEnums*/ true ) ;
1079
+ verify ( /*withAlias*/ AliasType . DifferentFile , /*preserveConstEnums*/ true ) ;
1080
+ } ) ;
1006
1081
} ) ;