Skip to content

Commit

Permalink
fix: transform function types
Browse files Browse the repository at this point in the history
  • Loading branch information
bennypowers committed Oct 21, 2021
1 parent ffa5e22 commit d4ff2ca
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/eighty-ducks-live.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@pwrs/lit-css": patch
---

Fixed the `transform` function signature's types.
2 changes: 1 addition & 1 deletion packages/lit-css-loader/lit-css-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export type LitCSSOptions = Omit<Options, 'css'>;

type Context = LoaderContext<LitCSSOptions>;

const loader: LoaderDefinitionFunction = function loader(this: Context, css, map, meta): void {
const loader: LoaderDefinitionFunction = function loader(this: Context, css): void {
const callback = this.async();
const filePath = this.resourcePath;
const options = this.getOptions();
Expand Down
15 changes: 14 additions & 1 deletion packages/lit-css/lit-css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@ import stringToTemplateLiteral from 'string-to-template-literal';

import { processString, UglifyCSSOptions } from 'uglifycss';

export interface Meta {
/**
* Path to the source file being transformed
* Typically passed to transform functions e.g.
* @example
* ```js
* (data, { filePath }) =>
* Sass.renderSync(data, { file: filePath }).css.toString()
* ```
*/
filePath: string;
}

export interface Options {
/** CSS to transform */
css: string;
Expand All @@ -28,7 +41,7 @@ export interface Options {
* @param meta Source file absolute (i.e. resolved) path
* @return Transformed, standard CSS
*/
transform?(source: string, meta?: { filePath: string }): string|Promise<string>;
transform?(source: string, meta: Meta): string|Promise<string>;
}

export async function transform({
Expand Down

0 comments on commit d4ff2ca

Please sign in to comment.