Skip to content

Commit c9a3c95

Browse files
committed
remove dead code #93
1 parent 2e93a1c commit c9a3c95

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+4327
-3329
lines changed

.npmignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@
1818
/Writerside
1919
/validator
2020
/sw.js
21-
/jsr.json
21+
/jsr.json
22+
/.editorconfig

dist/index-umd-web.js

Lines changed: 1098 additions & 880 deletions
Large diffs are not rendered by default.

dist/index.cjs

Lines changed: 1098 additions & 880 deletions
Large diffs are not rendered by default.

dist/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,6 +1160,7 @@ interface ValidationOptions {
11601160
validation?: boolean | ValidationLevel;
11611161
lenient?: boolean;
11621162
visited?: WeakMap<Token, Map<string, Set<ValidationToken>>>;
1163+
isOptional?:boolean | null;
11631164
isRepeatable?:boolean | null;
11641165
isList?:boolean | null;
11651166
occurence?:boolean | null;

dist/lib/ast/expand.js

Lines changed: 80 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,22 @@ import '../syntax/color/utils/constants.js';
1313
*/
1414
function expand(ast) {
1515
//
16-
if (![EnumToken.RuleNodeType, EnumToken.StyleSheetNodeType, EnumToken.AtRuleNodeType].includes(ast.typ)) {
17-
return ast;
18-
}
19-
if (EnumToken.RuleNodeType == ast.typ) {
20-
return {
21-
typ: EnumToken.StyleSheetNodeType,
22-
chi: expandRule(ast)
23-
};
24-
}
25-
if (!('chi' in ast)) {
26-
return ast;
27-
}
16+
// if (![EnumToken.RuleNodeType, EnumToken.StyleSheetNodeType, EnumToken.AtRuleNodeType].includes(ast.typ)) {
17+
//
18+
// return ast;
19+
// }
20+
// if (EnumToken.RuleNodeType == ast.typ) {
21+
//
22+
// return <AstRuleStyleSheet>{
23+
// typ: EnumToken.StyleSheetNodeType,
24+
// chi: expandRule(<AstRule>ast)
25+
// }
26+
// }
27+
//
28+
// if (!('chi' in ast)) {
29+
//
30+
// return ast;
31+
// }
2832
const result = { ...ast, chi: [] };
2933
// @ts-ignore
3034
for (let i = 0; i < ast.chi.length; i++) {
@@ -48,10 +52,11 @@ function expand(ast) {
4852
// @ts-ignore
4953
result.chi.push({ ...(hasRule ? expand(node) : node) });
5054
}
51-
else {
52-
// @ts-ignore
53-
result.chi.push(node);
54-
}
55+
// else {
56+
//
57+
// // @ts-ignore
58+
// result.chi.push(node);
59+
// }
5560
}
5661
return result;
5762
}
@@ -65,24 +70,26 @@ function expandRule(node) {
6570
const rule = ast.chi[i];
6671
if (!rule.sel.includes('&')) {
6772
const selRule = splitRule(rule.sel);
68-
if (selRule.length > 1) {
69-
const r = ':is(' + selRule.map(a => a.join('')).join(',') + ')';
70-
rule.sel = splitRule(ast.sel).reduce((a, b) => a.concat([b.join('') + r]), []).join(',');
71-
}
72-
else {
73-
// selRule = splitRule(selRule.reduce((acc, curr) => acc + (acc.length > 0 ? ',' : '') + curr.join(''), ''));
74-
const arSelf = splitRule(ast.sel).filter((r) => r.every((t) => t != ':before' && t != ':after' && !t.startsWith('::'))).reduce((acc, curr) => acc.concat([curr.join('')]), []).join(',');
75-
if (arSelf.length == 0) {
76-
ast.chi.splice(i--, 1);
77-
continue;
78-
}
79-
//
80-
selRule.forEach(arr => combinators.includes(arr[0].charAt(0)) ? arr.unshift(arSelf) : arr.unshift(arSelf, ' '));
81-
rule.sel = selRule.reduce((acc, curr) => {
82-
acc.push(curr.join(''));
83-
return acc;
84-
}, []).join(',');
73+
// if (selRule.length > 1) {
74+
//
75+
// const r: string = ':is(' + selRule.map(a => a.join('')).join(',') + ')';
76+
// rule.sel = splitRule(ast.sel).reduce((a: string[], b: string[]): string[] => a.concat([b.join('') + r]), <string[]>[]).join(',');
77+
//
78+
// }
79+
// else {
80+
// selRule = splitRule(selRule.reduce((acc, curr) => acc + (acc.length > 0 ? ',' : '') + curr.join(''), ''));
81+
const arSelf = splitRule(ast.sel).filter((r) => r.every((t) => t != ':before' && t != ':after' && !t.startsWith('::'))).reduce((acc, curr) => acc.concat([curr.join('')]), []).join(',');
82+
if (arSelf.length == 0) {
83+
ast.chi.splice(i--, 1);
84+
continue;
8585
}
86+
//
87+
selRule.forEach(arr => combinators.includes(arr[0].charAt(0)) ? arr.unshift(arSelf) : arr.unshift(arSelf, ' '));
88+
rule.sel = selRule.reduce((acc, curr) => {
89+
acc.push(curr.join(''));
90+
return acc;
91+
}, []).join(',');
92+
// }
8693
}
8794
else {
8895
let childSelectorCompound = [];
@@ -108,9 +115,10 @@ function expandRule(node) {
108115
if (s == '&' || parentSelector) {
109116
withCompound.push(s);
110117
}
111-
else {
112-
withoutCompound.push(s.slice(1));
113-
}
118+
// else {
119+
//
120+
// withoutCompound.push(s.slice(1));
121+
// }
114122
}
115123
}
116124
else {
@@ -121,9 +129,10 @@ function expandRule(node) {
121129
withCompound.push(s);
122130
}
123131
}
124-
else {
125-
withoutCompound.push(s);
126-
}
132+
// else {
133+
//
134+
// withoutCompound.push(s);
135+
// }
127136
}
128137
const selectors = [];
129138
const selector = rules.length > 1 ? ':is(' + rules.map(a => a.join('')).join(',') + ')' : rules[0].join('');
@@ -155,11 +164,13 @@ function expandRule(node) {
155164
if (withCompound.length == 1) {
156165
selectors.push(replaceCompound(withCompound[0], selector));
157166
}
158-
else {
159-
for (const w of withCompound) {
160-
selectors.push(replaceCompound(w, selector));
161-
}
162-
}
167+
// else {
168+
//
169+
// for (const w of withCompound) {
170+
//
171+
// selectors.push(replaceCompound(w, selector));
172+
// }
173+
// }
163174
}
164175
rule.sel = selectors.reduce((acc, curr) => curr.length == 0 ? acc : acc + (acc.length > 0 ? ',' : '') + curr, '');
165176
}
@@ -200,10 +211,11 @@ function expandRule(node) {
200211
// @ts-ignore
201212
astAtRule.chi.push(...expandRule(r));
202213
}
203-
else {
204-
// @ts-ignore
205-
astAtRule.chi.push(r);
206-
}
214+
// else {
215+
//
216+
// // @ts-ignore
217+
// astAtRule.chi.push(r);
218+
// }
207219
}
208220
}
209221
// @ts-ignore
@@ -230,21 +242,23 @@ function replaceCompound(input, replace) {
230242
if (replacement == null) {
231243
replacement = parseString(replace);
232244
}
233-
if (tokens[1].typ == EnumToken.IdenTokenType) {
234-
t.value.val = replacement.length == 1 || (!replace.includes(' ') && replace.charAt(0).match(/[:.]/)) ? tokens[1].val + replace : replaceCompoundLiteral(tokens[1].val + '&', replace);
235-
tokens.splice(1, 1);
236-
}
237-
else {
238-
t.value.val = replaceCompoundLiteral(t.value.val, replace);
239-
}
245+
// if (tokens[1].typ == EnumToken.IdenTokenType) {
246+
//
247+
//
248+
// (t.value as LiteralToken).val = (replacement as Token[]).length == 1 || (!replace.includes(' ') && replace.charAt(0).match(/[:.]/)) ? (tokens[1] as IdentToken).val + replace : replaceCompoundLiteral((tokens[1] as IdentToken).val + '&', replace);
249+
// tokens.splice(1, 1);
250+
// } else {
251+
t.value.val = replaceCompoundLiteral(t.value.val, replace);
252+
// }
240253
continue;
241254
}
242255
const rule = splitRule(replace);
243256
t.value.val = rule.length > 1 ? ':is(' + replace + ')' : replace;
244257
}
245-
else if (t.value.val.length > 1 && t.value.val.charAt(0) == '&') {
246-
t.value.val = replaceCompoundLiteral(t.value.val, replace);
247-
}
258+
// else if ((t.value as LiteralToken).val.length > 1 && (t.value as LiteralToken).val.charAt(0) == '&') {
259+
//
260+
// (t.value as LiteralToken).val = replaceCompoundLiteral((t.value as LiteralToken).val, replace);
261+
// }
248262
}
249263
}
250264
return tokens.reduce((acc, curr) => acc + renderToken(curr), '');
@@ -257,19 +271,21 @@ function replaceCompoundLiteral(selector, replace) {
257271
tokens.push('&');
258272
tokens.push('');
259273
}
260-
else {
261-
tokens[tokens.length - 1] += selector.charAt(i);
262-
}
274+
// else {
275+
//
276+
// tokens[tokens.length - 1] += selector.charAt(i);
277+
// }
263278
}
264279
return tokens.sort((a, b) => {
265280
if (a == '&') {
266281
return 1;
267282
}
268283
return b == '&' ? -1 : 0;
269284
}).reduce((acc, curr) => {
270-
if (acc.length > 0 && curr == '&' && (replace.charAt(0) != '.' || replace.includes(' '))) {
271-
return acc + ':is(' + replace + ')';
272-
}
285+
// if (acc.length > 0 && curr == '&' && (replace.charAt(0) != '.' || replace.includes(' '))) {
286+
//
287+
// return acc + ':is(' + replace + ')';
288+
// }
273289
return acc + (curr == '&' ? replace : curr);
274290
}, '');
275291
}

dist/lib/ast/features/calc.js

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,19 @@ class ComputeCalcExpressionFeature {
5757
if (slice != null && node.typ == EnumToken.FunctionTokenType && mathFuncs.includes(node.val)) {
5858
// @ts-ignore
5959
const cp = (node.typ == EnumToken.FunctionTokenType && mathFuncs.includes(node.val) && node.val != 'calc' ? [node] : (node.typ == EnumToken.DeclarationNodeType ? node.val : node.chi)).slice();
60-
const values = evaluate(cp);
60+
evaluate(cp);
6161
const key = 'chi' in node ? 'chi' : 'val';
6262
const str1 = renderToken({ ...node, [key]: slice });
6363
const str2 = renderToken(node); // values.reduce((acc: string, curr: Token): string => acc + renderToken(curr), '');
6464
if (str1.length <= str2.length) {
6565
// @ts-ignore
6666
node[key] = slice;
6767
}
68-
else {
69-
// @ts-ignore
70-
node[key] = values;
71-
}
68+
// else {
69+
//
70+
// // @ts-ignore
71+
// node[key] = values;
72+
// }
7273
return WalkerOptionEnum.Ignore;
7374
}
7475
return null;
@@ -84,41 +85,42 @@ class ComputeCalcExpressionFeature {
8485
// @ts-ignore
8586
const children = parent.typ == EnumToken.DeclarationNodeType ? parent.val : parent.chi;
8687
if (values.length == 1 && values[0].typ != EnumToken.BinaryExpressionTokenType) {
87-
if (parent.typ == EnumToken.BinaryExpressionTokenType) {
88-
if (parent.l == value) {
89-
parent.l = values[0];
90-
}
91-
else {
92-
parent.r = values[0];
93-
}
94-
}
95-
else {
96-
for (let i = 0; i < children.length; i++) {
97-
if (children[i] == value) {
98-
// @ts-ignore
99-
children.splice(i, 1, !(parent.typ == EnumToken.FunctionTokenType && parent.val == 'calc') && typeof values[0].val != 'string' ? {
100-
typ: EnumToken.FunctionTokenType,
101-
val: 'calc',
102-
chi: values
103-
} : values[0]);
104-
break;
105-
}
88+
// if (parent.typ == EnumToken.BinaryExpressionTokenType) {
89+
//
90+
// if ((parent as BinaryExpressionToken).l == value) {
91+
//
92+
// (parent as BinaryExpressionToken).l = values[0];
93+
// } else {
94+
//
95+
// (parent as BinaryExpressionToken).r = values[0];
96+
// }
97+
// } else {
98+
for (let i = 0; i < children.length; i++) {
99+
if (children[i] == value) {
100+
// @ts-ignore
101+
children.splice(i, 1, !(parent.typ == EnumToken.FunctionTokenType && parent.val == 'calc') && typeof values[0].val != 'string' ? {
102+
typ: EnumToken.FunctionTokenType,
103+
val: 'calc',
104+
chi: values
105+
} : values[0]);
106+
break;
106107
}
107108
}
109+
// }
108110
}
109111
else {
110112
for (let i = 0; i < children.length; i++) {
111113
if (children[i] == value) {
112-
if (parent.typ == EnumToken.FunctionTokenType && parent.val == 'calc') {
113-
children.splice(i, 1, ...values);
114-
}
115-
else {
116-
children.splice(i, 1, {
117-
typ: EnumToken.FunctionTokenType,
118-
val: 'calc',
119-
chi: values
120-
});
121-
}
114+
// if (parent.typ == EnumToken.FunctionTokenType && (parent as FunctionToken).val == 'calc') {
115+
//
116+
// children.splice(i, 1, ...values);
117+
// } else {
118+
children.splice(i, 1, {
119+
typ: EnumToken.FunctionTokenType,
120+
val: 'calc',
121+
chi: values
122+
});
123+
// }
122124
break;
123125
}
124126
}

dist/lib/ast/features/inlinecssvariables.js

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -106,18 +106,25 @@ class InlineCssVariablesFeature {
106106
replace(node, variableScope);
107107
}
108108
}
109-
else {
110-
const info = variableScope.get(node.nam);
111-
info.globalScope = isRoot;
112-
if (!isRoot) {
113-
++info.declarationCount;
114-
}
115-
if (info.replaceable) {
116-
info.replaceable = isRoot && info.declarationCount == 1;
117-
}
118-
info.parent.add(ast);
119-
info.node = node;
120-
}
109+
// else {
110+
//
111+
// const info: VariableScopeInfo = <VariableScopeInfo>variableScope.get((<AstDeclaration>node).nam);
112+
//
113+
// info.globalScope = isRoot;
114+
//
115+
// if (!isRoot) {
116+
//
117+
// ++info.declarationCount;
118+
// }
119+
//
120+
// if (info.replaceable) {
121+
//
122+
// info.replaceable = isRoot && info.declarationCount == 1;
123+
// }
124+
//
125+
// info.parent.add(ast);
126+
// info.node = (<AstDeclaration>node);
127+
// }
121128
}
122129
else {
123130
replace(node, variableScope);
@@ -126,9 +133,10 @@ class InlineCssVariablesFeature {
126133
}
127134
cleanup(ast, options = {}, context) {
128135
const variableScope = context.variableScope;
129-
if (variableScope == null) {
130-
return;
131-
}
136+
// if (variableScope == null) {
137+
//
138+
// return;
139+
// }
132140
for (const info of variableScope.values()) {
133141
if (info.replaceable) {
134142
let i;

0 commit comments

Comments
 (0)