You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import*astsfrom'typescript';import*aspathfrom'path';const{cachedLibPath, cachedLib}=(()=>{consthost=ts.createCompilerHost({});constfn=host.getDefaultLibFileName({});constp=ts.getDefaultLibFilePath({});return{// Normalize path to fix mixed/wrong directory separators on Windows.cachedLibPath: path.normalize(p),cachedLib: host.getSourceFile(fn,ts.ScriptTarget.Latest),};})();constreproTransformer: (context: ts.TransformationContext)=>ts.Transformer<ts.SourceFile>=(context: ts.TransformationContext): ts.Transformer<ts.SourceFile>=>{return(sf: ts.SourceFile): ts.SourceFile=>{console.error(ts.SyntaxKind[sf.kind]);returnsf;}}functioncreateSourceCachingHost(sources: Map<string,string>,options: ts.CompilerOptions): ts.CompilerHost{consthost=ts.createCompilerHost({});host.getSourceFile=(fileName: string,languageVersion: ts.ScriptTarget,onError?: (msg: string)=>void): ts.SourceFile|undefined=>{// Normalize path to fix wrong directory separators on Windows which// would break the equality check.fileName=path.normalize(fileName);if(fileName===cachedLibPath)returncachedLib;if(path.isAbsolute(fileName))fileName=path.relative(process.cwd(),fileName);constcontents=sources.get(fileName);if(contents!==undefined){returnts.createSourceFile(fileName,contents,ts.ScriptTarget.Latest,true);}thrownewError('unexpected file read of '+fileName+' not in '+Array.from(sources.keys()));};constoriginalFileExists=host.fileExists;host.fileExists=(fileName: string): boolean=>{if(path.isAbsolute(fileName))fileName=path.relative(process.cwd(),fileName);if(sources.has(fileName)){returntrue;}// Typescript occasionally needs to look on disk for files we don't pass into// the program as a source (eg to resolve a module that's in node_modules),// but only .ts files explicitly passed in should be findableif(/\.ts$/.test(fileName)){returnfalse;}returnoriginalFileExists.call(host,fileName);};returnhost;}functionemit(sources: Map<string,string>,options: ts.CompilerOptions){constfileNames=Array.from(sources.keys());consttsHost=createSourceCachingHost(sources,options);constprogram=ts.createProgram(fileNames,options,tsHost);consttsTransformers: ts.CustomTransformers={after: [reproTransformer],}program.emit(undefined,undefined,undefined,undefined,tsTransformers);}constone_source_file=newMap([['a.ts','const x = 1']]);consttwo_source_files=newMap([['a.ts','const x = 1'],['b.ts','const y = ""']]);emit(one_source_file,{});emit(two_source_files,{outFile: 'c.js'});
Expected behavior:
reproTransformer is a scheduled as an after transformer, and the type for ts.CustomTransformers says that it will only ever be called with a SourceFile, so the two emit calls should print out:
SourceFile
SourceFile
SourceFile Actual behavior:
SourceFile
Bundle
I tested without the outFile flag, and I got the expected behavior, so the issue is to do with the outfile.
The text was updated successfully, but these errors were encountered:
This seems right to me. with --outFile sourceFiles are "bundled" into a new node. a transformer can perform some transformations on the new file generated by the bundle if it needs to.
Right, my problem is not that the transformer was fed a Bundle, it's that the type of an after transformer doesn't allow for the transformer to be called with a Bundle.
TypeScript Version: 2.9.0-rc
Search Terms: bundle transformer
Code
Expected behavior:
reproTransformer is a scheduled as an after transformer, and the type for ts.CustomTransformers says that it will only ever be called with a SourceFile, so the two emit calls should print out:
SourceFile
SourceFile
SourceFile
Actual behavior:
SourceFile
Bundle
I tested without the outFile flag, and I got the expected behavior, so the issue is to do with the outfile.
The text was updated successfully, but these errors were encountered: