Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const NOOP_PARSE_ERROR = { onParseError: () => {} };
const MATCH_CALC = /^(?:-(?:moz|webkit)-)?calc$/i;

/**
* @typedef {object} PluginOptions
* @typedef {object} PostCssCalcOptions
* @property {number | false} [precision]
* @property {boolean} [preserve]
* @property {boolean} [warnWhenCannotResolve]
Expand All @@ -32,7 +32,7 @@ const MATCH_CALC = /^(?:-(?:moz|webkit)-)?calc$/i;
* @property {(error: Error, input: string) => void} [onParseError] Invoked when parse/simplify throws. Replaces the default `result.warn`.
*/

/** @typedef {Required<Omit<PluginOptions, 'onParseError'>> & Pick<PluginOptions, 'onParseError'>} ResolvedOptions */
/** @typedef {Required<Omit<PostCssCalcOptions, 'onParseError'>> & Pick<PostCssCalcOptions, 'onParseError'>} ResolvedOptions */

/**
* Fields threaded unchanged through the recursive `transformList` walk.
Expand Down Expand Up @@ -153,7 +153,7 @@ function applyTransform(node, current, setProp, options, result) {
}

/**
* @param {PluginOptions} [opts]
* @param {PostCssCalcOptions} [opts]
* @return {import('postcss').Plugin}
*/
function pluginCreator(opts) {
Expand Down Expand Up @@ -215,9 +215,10 @@ function pluginCreator(opts) {
};
}

/** @type {true} */
pluginCreator.postcss = true;

export default /** @type import('postcss').PluginCreator<PluginOptions>*/ (
export default /** @type import('postcss').PluginCreator<PostCssCalcOptions>*/ (
pluginCreator
);
export { pluginCreator as 'module.exports' };
12 changes: 6 additions & 6 deletions types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export type PluginOptions = {
export type PostCssCalcOptions = {
precision?: number | false;
preserve?: boolean;
warnWhenCannotResolve?: boolean;
Expand All @@ -9,21 +9,21 @@ export type PluginOptions = {
*/
onParseError?: (error: Error, input: string) => void;
};
export type ResolvedOptions = Required<Omit<PluginOptions, 'onParseError'>> & Pick<PluginOptions, 'onParseError'>;
export type ResolvedOptions = Required<Omit<PostCssCalcOptions, 'onParseError'>> & Pick<PostCssCalcOptions, 'onParseError'>;
export type TransformContext = {
options: ResolvedOptions;
result: import('postcss').Result;
item: import('postcss').ChildNode;
value: string;
};
/**
* @param {PluginOptions} [opts]
* @param {PostCssCalcOptions} [opts]
* @return {import('postcss').Plugin}
*/
declare function pluginCreator(opts?: PluginOptions): import('postcss').Plugin;
declare function pluginCreator(opts?: PostCssCalcOptions): import('postcss').Plugin;
declare namespace pluginCreator {
var postcss: boolean;
var postcss: true;
}
declare const _default: import('postcss').PluginCreator<PluginOptions>;
declare const _default: import('postcss').PluginCreator<PostCssCalcOptions>;
export default _default;
export { pluginCreator as 'module.exports' };