diff --git a/src/index.ts b/src/index.ts index 9ad92c5..f57c12c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,7 +1,7 @@ import { RollupContext } from "./rollupcontext"; import { ConsoleContext, IRollupContext, VerbosityLevel } from "./context"; import { LanguageServiceHost } from "./host"; -import { TsCache, convertDiagnostic, ICode } from "./tscache"; +import { TsCache, convertDiagnostic, ICode, IRollupCode } from "./tscache"; import { tsModule, setTypescriptModule } from "./tsproxy"; import * as tsTypes from "typescript"; import * as resolve from "resolve"; @@ -173,7 +173,7 @@ export default function typescript(options?: Partial) return undefined; }, - transform(this: IRollupContext, code: string, id: string): ICode | undefined + transform(this: IRollupContext, code: string, id: string): IRollupCode | undefined { generateRound = 0; // in watch mode transform call resets generate count (used to avoid printing too many copies of the same error messages) @@ -249,18 +249,21 @@ export default function typescript(options?: Partial) const key = normalize(id); declarations[key] = result.dts; context.debug(() => `${blue("generated declarations")} for '${key}'`); - result.dts = undefined; } + const transformResult = { code: result.code, map: { mappings: "" } }; + if (result.map) { if (pluginOptions.sourceMapCallback) pluginOptions.sourceMapCallback(id, result.map); - result.map = JSON.parse(result.map); + transformResult.map = JSON.parse(result.map); } + + return transformResult; } - return result; + return undefined; }, ongenerate(): void diff --git a/src/tscache.ts b/src/tscache.ts index db83560..149341d 100644 --- a/src/tscache.ts +++ b/src/tscache.ts @@ -17,6 +17,12 @@ export interface ICode dts?: tsTypes.OutputFile | undefined; } +export interface IRollupCode +{ + code: string | undefined; + map: { mappings: string }; +} + interface INodeLabel { dirty: boolean;