mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-04 23:07:06 +00:00
Transform method for plugins has correct 'this' context
See link for more info: https://github.com/rollup/rollup/wiki/Plugins#warnings-and-errors
This commit is contained in:
Vendored
+9
-1
@@ -133,7 +133,7 @@ export interface Plugin {
|
||||
*/
|
||||
resolveId?(importee: string, importer: string): string | null | undefined | false | 0 | ''
|
||||
/** A module transformer function */
|
||||
transform?(source: string, id: string): string | { code: string, map: SourceMap }
|
||||
transform?(this: TransformContext, source: string, id: string): string | { code: string, map: SourceMap }
|
||||
/** A bundle transformer function */
|
||||
transformBundle?(source: string, options: { format: Format }): string | { code: string, map: SourceMap }
|
||||
/** Function hook called when bundle.generate() is being executed. */
|
||||
@@ -150,5 +150,13 @@ export interface Plugin {
|
||||
footer?: string | (() => string)
|
||||
}
|
||||
|
||||
// See https://github.com/rollup/rollup/wiki/Plugins#warnings-and-errors
|
||||
export interface TransformContext {
|
||||
/** Emit warnings to Rollup which will be logged during bundling */
|
||||
warn(message: string | { message: string }, pos?: number | { line: number, column: number }): void;
|
||||
/** Emit an error, which will abort the bundling process */
|
||||
error(message: string | { message: string }, pos?: number | { line: number, column: number }): void;
|
||||
}
|
||||
|
||||
/** Returns a Promise that resolves with a bundle */
|
||||
export function rollup(options: Options): Promise<Bundle>
|
||||
|
||||
@@ -3,7 +3,19 @@ import { rollup, Bundle, Plugin } from 'rollup'
|
||||
let console: any
|
||||
|
||||
let cache: Bundle | undefined
|
||||
let plugin: Plugin
|
||||
let plugin: Plugin = {
|
||||
name: 'test-plugin',
|
||||
transform(source, id) {
|
||||
if (id === 'rxjs') {
|
||||
this.error(new Error(`Don't import this directly`))
|
||||
}
|
||||
let indexOfQuote = source.indexOf('"')
|
||||
if (indexOfQuote >= 0) {
|
||||
this.warn(`Prefer ' over " for strings`, indexOfQuote)
|
||||
}
|
||||
return source
|
||||
}
|
||||
}
|
||||
|
||||
async function main() {
|
||||
const bundle = await rollup({
|
||||
|
||||
Reference in New Issue
Block a user