Skip to content

Commit

Permalink
fix: broken terser minification
Browse files Browse the repository at this point in the history
  • Loading branch information
AndyOGo committed Nov 22, 2020
1 parent 7ce91d4 commit 5cb14c4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"unpkg": "dist/index.umd.js",
"types": "dist/index.d.ts",
"scripts": {
"build": "microbundle --tsconfig tsconfig.build.json --no-compress",
"build": "microbundle --tsconfig tsconfig.build.json --compress",
"release": "dotenv semantic-release",
"prepack": "npm run build",
"test": "node --require babel-register-ts test",
Expand Down
20 changes: 12 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Declaration, Root, Result } from 'postcss';
import stylelint, { LinterOptions, Plugin } from 'stylelint';
import type { Declaration, Root, Result, AtRule } from 'postcss';
import stylelint from 'stylelint';
import shortCSS from 'shortcss';
import list from 'shortcss/lib/list';
import cssValues from 'css-values';
Expand Down Expand Up @@ -84,6 +84,9 @@ const mapIgnoreValue = (ignoreValue: TOptionPrimitive) =>
* @param {object} result - PostCSS lazy result.
*/
type PostCSSPlugin = (root: Root, result: Result) => void | PromiseLike<void>;
interface StylelintContext {
fix?: boolean;
}

/**
* Stylelint declaration strict value rule function.
Expand All @@ -99,14 +102,14 @@ interface StylelintRuleFunction {
(
primaryOption: string | string[],
secondaryOptions?: ISecondaryOptions,
context?: LinterOptions
context?: StylelintContext
): PostCSSPlugin;
primaryOptionArray: boolean;
}
const ruleFunction: StylelintRuleFunction = (
properties: string | string[],
options: ISecondaryOptions,
context: LinterOptions
context: StylelintContext = {}
) => (root: Root, result: Result) => {
// validate stylelint plugin options
const hasValidOptions = utils.validateOptions(
Expand Down Expand Up @@ -161,7 +164,7 @@ const ruleFunction: StylelintRuleFunction = (

if (ignoreVariables) {
const cssLoaderValuesNames: string[] = [];
root.walkAtRules('value', (rule) => {
root.walkAtRules('value', (rule: AtRule) => {
const { params } = rule;
const name = params.split(':')[0].trim();

Expand Down Expand Up @@ -343,7 +346,7 @@ const ruleFunction: StylelintRuleFunction = (
const types = getTypes(config, property);

// support auto fixing
if (context?.fix && !disableFix) {
if (context.fix && !disableFix) {
const fixedValue = autoFixFuncNormalized!(
node,
{
Expand All @@ -365,7 +368,8 @@ const ruleFunction: StylelintRuleFunction = (
}
} else {
const { raws } = node;
const { start } = node.source!;
// eslint-disable-next-line prefer-destructuring
const start = node.source!.start;

utils.report({
ruleName,
Expand All @@ -389,7 +393,7 @@ ruleFunction.primaryOptionArray = true;

const declarationStrictValuePlugin = stylelint.createPlugin(
ruleName,
(ruleFunction as unknown) as Plugin
ruleFunction
);

export default declarationStrictValuePlugin;
Expand Down
7 changes: 4 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
{
"compilerOptions": {
"declaration": true,
"emitDeclarationOnly": true,
"isolatedModules": true,
"emitDeclarationOnly": false,
"isolatedModules": false,
"noImplicitAny": true,
"strictNullChecks": true,
"noImplicitThis": true,
"esModuleInterop": true,
"target": "ESNext",
"module": "ESNext"
"module": "ESNext",
"moduleResolution": "Node"
},
}

0 comments on commit 5cb14c4

Please sign in to comment.