@@ -152,7 +152,7 @@ function isDefaultExport(declaration: ts.InterfaceDeclaration | ts.ClassDeclarat
152152 ) ;
153153}
154154
155- function getMassagedTopLevelDeclarationText ( sourceFile : ts . SourceFile , declaration : TSTopLevelDeclare , importName : string , usage : string [ ] ) : string {
155+ function getMassagedTopLevelDeclarationText ( sourceFile : ts . SourceFile , declaration : TSTopLevelDeclare , importName : string , usage : string [ ] , enums : string [ ] ) : string {
156156 let result = getNodeText ( sourceFile , declaration ) ;
157157 if ( declaration . kind === ts . SyntaxKind . InterfaceDeclaration || declaration . kind === ts . SyntaxKind . ClassDeclaration ) {
158158 let interfaceDeclaration = < ts . InterfaceDeclaration | ts . ClassDeclaration > declaration ;
@@ -194,6 +194,12 @@ function getMassagedTopLevelDeclarationText(sourceFile: ts.SourceFile, declarati
194194 }
195195 result = result . replace ( / e x p o r t d e f a u l t / g, 'export' ) ;
196196 result = result . replace ( / e x p o r t d e c l a r e / g, 'export' ) ;
197+
198+ if ( declaration . kind === ts . SyntaxKind . EnumDeclaration ) {
199+ result = result . replace ( / c o n s t e n u m / , 'enum' ) ;
200+ enums . push ( result ) ;
201+ }
202+
197203 return result ;
198204}
199205
@@ -356,7 +362,7 @@ function createReplacer(data: string): (str: string) => string {
356362 } ;
357363}
358364
359- function generateDeclarationFile ( recipe : string , sourceFileGetter : SourceFileGetter ) : [ string , string ] {
365+ function generateDeclarationFile ( recipe : string , sourceFileGetter : SourceFileGetter ) : [ string , string , string ] {
360366 const endl = / \r \n / . test ( recipe ) ? '\r\n' : '\n' ;
361367
362368 let lines = recipe . split ( endl ) ;
@@ -375,6 +381,8 @@ function generateDeclarationFile(recipe: string, sourceFileGetter: SourceFileGet
375381 return importName ;
376382 } ;
377383
384+ let enums : string [ ] = [ ] ;
385+
378386 lines . forEach ( line => {
379387
380388 let m1 = line . match ( / ^ \s * # i n c l u d e \( ( [ ^ ; ) ] * ) ( ; [ ^ ) ] * ) ? \) \: ( .* ) $ / ) ;
@@ -401,7 +409,7 @@ function generateDeclarationFile(recipe: string, sourceFileGetter: SourceFileGet
401409 logErr ( 'Cannot find type ' + typeName ) ;
402410 return ;
403411 }
404- result . push ( replacer ( getMassagedTopLevelDeclarationText ( sourceFile , declaration , importName , usage ) ) ) ;
412+ result . push ( replacer ( getMassagedTopLevelDeclarationText ( sourceFile , declaration , importName , usage , enums ) ) ) ;
405413 } ) ;
406414 return ;
407415 }
@@ -445,7 +453,7 @@ function generateDeclarationFile(recipe: string, sourceFileGetter: SourceFileGet
445453 }
446454 }
447455 }
448- result . push ( replacer ( getMassagedTopLevelDeclarationText ( sourceFile , declaration , importName , usage ) ) ) ;
456+ result . push ( replacer ( getMassagedTopLevelDeclarationText ( sourceFile , declaration , importName , usage , enums ) ) ) ;
449457 } ) ;
450458 return ;
451459 }
@@ -456,12 +464,23 @@ function generateDeclarationFile(recipe: string, sourceFileGetter: SourceFileGet
456464 let resultTxt = result . join ( endl ) ;
457465 resultTxt = resultTxt . replace ( / \b U R I \b / g, 'Uri' ) ;
458466 resultTxt = resultTxt . replace ( / \b E v e n t < / g, 'IEvent<' ) ;
459-
460467 resultTxt = format ( resultTxt , endl ) ;
461468
469+ let resultEnums = [
470+ '/*---------------------------------------------------------------------------------------------' ,
471+ ' * Copyright (c) Microsoft Corporation. All rights reserved.' ,
472+ ' * Licensed under the MIT License. See License.txt in the project root for license information.' ,
473+ ' *--------------------------------------------------------------------------------------------*/' ,
474+ '' ,
475+ '// THIS IS A GENERATED FILE. DO NOT EDIT DIRECTLY.' ,
476+ ''
477+ ] . concat ( enums ) . join ( endl ) ;
478+ resultEnums = format ( resultEnums , endl ) ;
479+
462480 return [
463481 resultTxt ,
464- `${ usageImports . join ( '\n' ) } \n\n${ usage . join ( '\n' ) } `
482+ `${ usageImports . join ( '\n' ) } \n\n${ usage . join ( '\n' ) } ` ,
483+ resultEnums
465484 ] ;
466485}
467486
@@ -497,6 +516,7 @@ export function getFilesToWatch(out: string): string[] {
497516export interface IMonacoDeclarationResult {
498517 content : string ;
499518 usageContent : string ;
519+ enums : string ;
500520 filePath : string ;
501521 isTheSame : boolean ;
502522}
@@ -505,7 +525,7 @@ function _run(sourceFileGetter: SourceFileGetter): IMonacoDeclarationResult {
505525 log ( 'Starting monaco.d.ts generation' ) ;
506526
507527 const recipe = fs . readFileSync ( RECIPE_PATH ) . toString ( ) ;
508- const [ result , usageContent ] = generateDeclarationFile ( recipe , sourceFileGetter ) ;
528+ const [ result , usageContent , enums ] = generateDeclarationFile ( recipe , sourceFileGetter ) ;
509529
510530 const currentContent = fs . readFileSync ( DECLARATION_PATH ) . toString ( ) ;
511531 const one = currentContent . replace ( / \r \n / gm, '\n' ) ;
@@ -517,6 +537,7 @@ function _run(sourceFileGetter: SourceFileGetter): IMonacoDeclarationResult {
517537 return {
518538 content : result ,
519539 usageContent : usageContent ,
540+ enums : enums ,
520541 filePath : DECLARATION_PATH ,
521542 isTheSame
522543 } ;
0 commit comments