Skip to content

Commit 5cb14c4

Browse files
committed
fix: broken terser minification
1 parent 7ce91d4 commit 5cb14c4

File tree

3 files changed

+17
-12
lines changed

3 files changed

+17
-12
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"unpkg": "dist/index.umd.js",
99
"types": "dist/index.d.ts",
1010
"scripts": {
11-
"build": "microbundle --tsconfig tsconfig.build.json --no-compress",
11+
"build": "microbundle --tsconfig tsconfig.build.json --compress",
1212
"release": "dotenv semantic-release",
1313
"prepack": "npm run build",
1414
"test": "node --require babel-register-ts test",

src/index.ts

+12-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import type { Declaration, Root, Result } from 'postcss';
2-
import stylelint, { LinterOptions, Plugin } from 'stylelint';
1+
import type { Declaration, Root, Result, AtRule } from 'postcss';
2+
import stylelint from 'stylelint';
33
import shortCSS from 'shortcss';
44
import list from 'shortcss/lib/list';
55
import cssValues from 'css-values';
@@ -84,6 +84,9 @@ const mapIgnoreValue = (ignoreValue: TOptionPrimitive) =>
8484
* @param {object} result - PostCSS lazy result.
8585
*/
8686
type PostCSSPlugin = (root: Root, result: Result) => void | PromiseLike<void>;
87+
interface StylelintContext {
88+
fix?: boolean;
89+
}
8790

8891
/**
8992
* Stylelint declaration strict value rule function.
@@ -99,14 +102,14 @@ interface StylelintRuleFunction {
99102
(
100103
primaryOption: string | string[],
101104
secondaryOptions?: ISecondaryOptions,
102-
context?: LinterOptions
105+
context?: StylelintContext
103106
): PostCSSPlugin;
104107
primaryOptionArray: boolean;
105108
}
106109
const ruleFunction: StylelintRuleFunction = (
107110
properties: string | string[],
108111
options: ISecondaryOptions,
109-
context: LinterOptions
112+
context: StylelintContext = {}
110113
) => (root: Root, result: Result) => {
111114
// validate stylelint plugin options
112115
const hasValidOptions = utils.validateOptions(
@@ -161,7 +164,7 @@ const ruleFunction: StylelintRuleFunction = (
161164

162165
if (ignoreVariables) {
163166
const cssLoaderValuesNames: string[] = [];
164-
root.walkAtRules('value', (rule) => {
167+
root.walkAtRules('value', (rule: AtRule) => {
165168
const { params } = rule;
166169
const name = params.split(':')[0].trim();
167170

@@ -343,7 +346,7 @@ const ruleFunction: StylelintRuleFunction = (
343346
const types = getTypes(config, property);
344347

345348
// support auto fixing
346-
if (context?.fix && !disableFix) {
349+
if (context.fix && !disableFix) {
347350
const fixedValue = autoFixFuncNormalized!(
348351
node,
349352
{
@@ -365,7 +368,8 @@ const ruleFunction: StylelintRuleFunction = (
365368
}
366369
} else {
367370
const { raws } = node;
368-
const { start } = node.source!;
371+
// eslint-disable-next-line prefer-destructuring
372+
const start = node.source!.start;
369373

370374
utils.report({
371375
ruleName,
@@ -389,7 +393,7 @@ ruleFunction.primaryOptionArray = true;
389393

390394
const declarationStrictValuePlugin = stylelint.createPlugin(
391395
ruleName,
392-
(ruleFunction as unknown) as Plugin
396+
ruleFunction
393397
);
394398

395399
export default declarationStrictValuePlugin;

tsconfig.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
{
22
"compilerOptions": {
33
"declaration": true,
4-
"emitDeclarationOnly": true,
5-
"isolatedModules": true,
4+
"emitDeclarationOnly": false,
5+
"isolatedModules": false,
66
"noImplicitAny": true,
77
"strictNullChecks": true,
88
"noImplicitThis": true,
99
"esModuleInterop": true,
1010
"target": "ESNext",
11-
"module": "ESNext"
11+
"module": "ESNext",
12+
"moduleResolution": "Node"
1213
},
1314
}

0 commit comments

Comments
 (0)