33
44namespace ts {
55 describe ( "customTransforms" , ( ) => {
6- function emitsCorrectly ( name : string , sources : { file : string , text : string } [ ] , customTransformers : CustomTransformers ) {
6+ function emitsCorrectly ( name : string , sources : { file : string , text : string } [ ] , customTransformers : CustomTransformers , options : CompilerOptions = { } ) {
77 it ( name , ( ) => {
88 const roots = sources . map ( source => createSourceFile ( source . file , source . text , ScriptTarget . ES2015 ) ) ;
99 const fileMap = arrayToMap ( roots , file => file . fileName ) ;
1010 const outputs = createMap < string > ( ) ;
11- const options : CompilerOptions = { } ;
1211 const host : CompilerHost = {
1312 getSourceFile : ( fileName ) => fileMap . get ( fileName ) ,
1413 getDefaultLibFileName : ( ) => "lib.d.ts" ,
@@ -82,5 +81,25 @@ namespace ts {
8281 emitsCorrectly ( "before" , sources , { before : [ before ] } ) ;
8382 emitsCorrectly ( "after" , sources , { after : [ after ] } ) ;
8483 emitsCorrectly ( "both" , sources , { before : [ before ] , after : [ after ] } ) ;
84+
85+ emitsCorrectly ( "before+decorators" , [ {
86+ file : "source.ts" ,
87+ text : `
88+ declare const dec: any;
89+ class B {}
90+ @dec export class C { constructor(b: B) { } }
91+ 'change'
92+ `
93+ } ] , { before : [
94+ context => node => visitNode ( node , function visitor ( node : Node ) : Node {
95+ if ( isStringLiteral ( node ) && node . text === "change" ) return createLiteral ( "changed" ) ;
96+ return visitEachChild ( node , visitor , context ) ;
97+ } )
98+ ] } , {
99+ target : ScriptTarget . ES5 ,
100+ module : ModuleKind . ES2015 ,
101+ emitDecoratorMetadata : true ,
102+ experimentalDecorators : true
103+ } ) ;
85104 } ) ;
86105}
0 commit comments