blob: 00c17af35a65db48f1ed6dc5a59883f47c69b388 [file] [log] [blame]
{"version":3,"file":"transformer.js","sourceRoot":"","sources":["../../src/bundler/transformer.ts"],"names":[],"mappings":";;AAAA,6BAA+B;AAC/B,6BAA+B;AAE/B,uBAAyB;AACzB,+BAAiC;AAQjC;IAEI,qBAAoB,MAAqB,EAAU,OAAgB;QAA/C,WAAM,GAAN,MAAM,CAAe;QAAU,YAAO,GAAP,OAAO,CAAS;IAAI,CAAC;IAEjE,uCAAiB,GAAxB,UAAyB,WAAqB,EAAE,mBAA+B;QAA/E,iBAoDC;QAlDG,IAAM,UAAU,GAAG,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,UAAU,CAAC;QAEzD,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE;YACpB,OAAO,CAAC,QAAQ,CAAC;gBACb,mBAAmB,EAAE,CAAC;YAC1B,CAAC,CAAC,CAAC;YACH,OAAO;SACV;QAED,KAAK,CAAC,UAAU,CAAC,WAAW,EAAE,UAAC,MAAc,EAAE,gBAAsC;YAEjF,IAAM,OAAO,GAAqB;gBAC9B,MAAM,EAAE,KAAI,CAAC,MAAM;gBACnB,QAAQ,EAAE,MAAM,CAAC,IAAI,CAAC,YAAY;gBAClC,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,YAAY;gBAChC,MAAM,EAAE,MAAM,CAAC,UAAU,CAAC,UAAU,CAAC,WAAW,EAAE;gBAClD,EAAE,EAAE;oBACA,GAAG,EAAE,MAAM,CAAC,UAAU,CAAC,UAAU;oBACjC,UAAU,EAAE,MAAM,CAAC,UAAU,CAAC,UAAU;oBACxC,OAAO,EAAE,EAAE,CAAC,OAAO;iBACtB;aACJ,CAAC;YACF,KAAK,CAAC,UAAU,CAAC,UAAU,EAAE,UAAC,SAAoB,EAAE,kBAAwC;gBACxF,OAAO,CAAC,QAAQ,CAAC;oBACb,SAAS,CAAC,OAAO,EAAE,UAAC,KAAY,EAAE,MAAiC,EAAE,SAAyB;wBAAzB,0BA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IAC5B,CAAC;IAEO,iCAAW,GAAnB,UAAoB,KAAY,EAAE,SAAoB,EAAE,OAAyB;QAC7E,IAAI,KAAK,EAAE;YACP,IAAM,YAAY,GAAG,OAAO,CAAC,QAAQ,GAAG,IAAI,GAAG,KAAK,CAAC,OAAO,GAAG,EAAE,CAAC,GAAG;gBACjE,sBAAsB,GAAG,EAAE,CAAC,GAAG,GAAG,EAAE,CAAC,GAAG;gBACxC,SAAS,GAAG,EAAE,CAAC,GAAG,CAAC;YACvB,MAAM,IAAI,KAAK,CAAC,YAAY,CAAC,CAAC;SACjC;IACL,CAAC;IACL,kBAAC;AAAD,CAAC,AA7GD,IA6GC;AA7GY,kCAAW","sourcesContent":["import * as acorn from \"acorn\";\nimport * as async from \"async\";\nimport { ErrorCallback } from \"async\";\nimport * as os from \"os\";\nimport * as ts from \"typescript\";\n\nimport { Transform, TransformContext, TransformResult } from \"../api\";\nimport { Configuration } from \"../shared/configuration\";\nimport { Project } from \"../shared/project\";\nimport { BundleItem } from \"./bundle-item\";\nimport { Queued } from \"./queued\";\n\nexport class Transformer {\n\n constructor(private config: Configuration, private project: Project) { }\n\n public applyTsTransforms(bundleQueue: Queued[], onTransformsApplied: () => void): void {\n\n const transforms = this.config.bundlerOptions.transforms;\n\n if (!transforms.length) {\n process.nextTick(() => {\n onTransformsApplied();\n });\n return;\n }\n\n async.eachSeries(bundleQueue, (queued: Queued, onQueueProcessed: ErrorCallback<Error>) => {\n\n const context: TransformContext = {\n config: this.config,\n filename: queued.file.originalPath,\n module: queued.file.originalPath,\n source: queued.emitOutput.sourceFile.getFullText(),\n ts: {\n ast: queued.emitOutput.sourceFile,\n transpiled: queued.emitOutput.outputText,\n version: ts.version\n }\n };\n async.eachSeries(transforms, (transform: Transform, onTransformApplied: ErrorCallback<Error>) => {\n process.nextTick(() => {\n transform(context, (error: Error, result: TransformResult | boolean, transpile: boolean = true) => {\n if (typeof result !== \"object\" || result === null) {\n result = {\n dirty: !!result,\n transpile\n };\n }\n this.handleError(error, transform, context);\n if (result.dirty) {\n if (result.transpile) {\n const transpiled = ts.transpileModule(context.source, {\n compilerOptions: this.project.getTsconfig().options,\n fileName: context.filename\n });\n queued.emitOutput.outputText = transpiled.outputText;\n queued.emitOutput.sourceMapText = transpiled.sourceMapText;\n }\n else {\n queued.emitOutput.outputText = context.ts.transpiled;\n }\n }\n onTransformApplied();\n });\n });\n }, onQueueProcessed);\n }, onTransformsApplied);\n }\n\n public applyTransforms(bundleItem: BundleItem, onTransformsApplied: () => void): void {\n\n const transforms = this.config.bundlerOptions.transforms;\n\n if (!transforms.length) {\n process.nextTick(() => {\n onTransformsApplied();\n });\n return;\n }\n\n const context: TransformContext = {\n config: this.config,\n filename: bundleItem.filename,\n js: {\n ast: bundleItem.ast || { end: 0, start: 0, type: \"\" }\n },\n module: bundleItem.moduleName,\n source: bundleItem.source\n };\n async.eachSeries(transforms, (transform: Transform, onTransformApplied: ErrorCallback<Error>) => {\n process.nextTick(() => {\n transform(context, (error: Error, result: TransformResult | boolean) => {\n if (typeof result !== \"object\" || result === null) {\n result = {\n dirty: !!result\n };\n }\n this.handleError(error, transform, context);\n if (result.dirty) {\n bundleItem.ast = context.js.ast;\n bundleItem.source = context.source;\n bundleItem.transformedScript = result.transformedScript;\n if (result.transformedScript && bundleItem.ast) {\n bundleItem.ast = acorn.parse(context.source, this.config.bundlerOptions.acornOptions);\n }\n }\n onTransformApplied();\n });\n });\n }, onTransformsApplied);\n }\n\n private handleError(error: Error, transform: Transform, context: TransformContext): void {\n if (error) {\n const errorMessage = context.filename + \": \" + error.message + os.EOL +\n \"Transform function: \" + os.EOL + os.EOL +\n transform + os.EOL;\n throw new Error(errorMessage);\n }\n }\n}\n"]}