Skip to content

Commit 1501a44

Browse files
committed
bump version #97
1 parent 6f0cd53 commit 1501a44

File tree

9 files changed

+107
-19
lines changed

9 files changed

+107
-19
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ Javascript module from cdn
9797

9898
<script type="module">
9999
100-
import {transform} from 'https://esm.sh/@tbela99/css-parser@1.1.2/web';
100+
import {transform} from 'https://esm.sh/@tbela99/css-parser@1.3.0/web';
101101
102102
103103
const css = `

dist/index-umd-web.js

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16748,6 +16748,18 @@
1674816748
stats.bytesIn = item.bytesIn;
1674916749
rawTokens.push(item);
1675016750
if (item.hint != null && BadTokensTypes.includes(item.hint)) {
16751+
const node = getTokenType(item.token, item.hint);
16752+
errors.push({
16753+
action: 'drop',
16754+
message: 'Bad token',
16755+
syntax: null,
16756+
node,
16757+
location: {
16758+
src,
16759+
sta: item.sta,
16760+
end: item.end
16761+
}
16762+
});
1675116763
// bad token
1675216764
continue;
1675316765
}
@@ -16792,7 +16804,12 @@
1679216804
errors.push({
1679316805
action: 'drop',
1679416806
message: 'invalid block',
16795-
rawTokens: tokens.slice()
16807+
rawTokens: tokens.slice(),
16808+
location: {
16809+
src,
16810+
sta: tokens[0].sta,
16811+
end: tokens[tokens.length - 1].end
16812+
}
1679616813
});
1679716814
}
1679816815
}
@@ -16960,6 +16977,7 @@
1696016977
errors.push({
1696116978
action: 'drop',
1696216979
message: `CDOCOMM not allowed here ${JSON.stringify(tokens[i], null, 1)}`,
16980+
node: tokens[i],
1696316981
location
1696416982
});
1696516983
continue;
@@ -17014,7 +17032,8 @@
1701417032
if (!(type == exports.EnumToken.InvalidAtRuleTokenType &&
1701517033
// @ts-ignore
1701617034
['charset', 'layer', 'import'].includes(context.chi[i].nam))) {
17017-
errors.push({ action: 'drop', message: 'invalid @import', location });
17035+
// @ts-ignore
17036+
errors.push({ action: 'drop', message: 'invalid @import', location, rawTokens: [atRule, ...tokens] });
1701817037
return null;
1701917038
}
1702017039
}
@@ -17090,7 +17109,7 @@
1709017109
action: 'drop',
1709117110
message: '@charset must have only one space',
1709217111
// @ts-ignore
17093-
location
17112+
location, rawTokens: [atRule, ...tokens]
1709417113
});
1709517114
return null;
1709617115
}
@@ -17159,6 +17178,7 @@
1715917178
errors.push({
1716017179
action: 'drop',
1716117180
message: valid.error + ' - "' + tokens.reduce((acc, curr) => acc + renderToken(curr, { minify: false }), '') + '"',
17181+
node,
1716217182
// @ts-ignore
1716317183
location: { src, ...(map.get(valid.node) ?? location) }
1716417184
});
@@ -17260,6 +17280,7 @@
1726017280
errors.push({
1726117281
action: 'drop',
1726217282
message: valid.error + ' - "' + tokens.reduce((acc, curr) => acc + renderToken(curr, { minify: false }), '') + '"',
17283+
node,
1726317284
// @ts-ignore
1726417285
location
1726517286
});

dist/index.cjs

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16844,6 +16844,18 @@ async function doParse(iterator, options = {}) {
1684416844
stats.bytesIn = item.bytesIn;
1684516845
rawTokens.push(item);
1684616846
if (item.hint != null && BadTokensTypes.includes(item.hint)) {
16847+
const node = getTokenType(item.token, item.hint);
16848+
errors.push({
16849+
action: 'drop',
16850+
message: 'Bad token',
16851+
syntax: null,
16852+
node,
16853+
location: {
16854+
src,
16855+
sta: item.sta,
16856+
end: item.end
16857+
}
16858+
});
1684716859
// bad token
1684816860
continue;
1684916861
}
@@ -16888,7 +16900,12 @@ async function doParse(iterator, options = {}) {
1688816900
errors.push({
1688916901
action: 'drop',
1689016902
message: 'invalid block',
16891-
rawTokens: tokens.slice()
16903+
rawTokens: tokens.slice(),
16904+
location: {
16905+
src,
16906+
sta: tokens[0].sta,
16907+
end: tokens[tokens.length - 1].end
16908+
}
1689216909
});
1689316910
}
1689416911
}
@@ -17056,6 +17073,7 @@ function parseNode(results, context, options, errors, src, map, rawTokens) {
1705617073
errors.push({
1705717074
action: 'drop',
1705817075
message: `CDOCOMM not allowed here ${JSON.stringify(tokens[i], null, 1)}`,
17076+
node: tokens[i],
1705917077
location
1706017078
});
1706117079
continue;
@@ -17110,7 +17128,8 @@ function parseNode(results, context, options, errors, src, map, rawTokens) {
1711017128
if (!(type == exports.EnumToken.InvalidAtRuleTokenType &&
1711117129
// @ts-ignore
1711217130
['charset', 'layer', 'import'].includes(context.chi[i].nam))) {
17113-
errors.push({ action: 'drop', message: 'invalid @import', location });
17131+
// @ts-ignore
17132+
errors.push({ action: 'drop', message: 'invalid @import', location, rawTokens: [atRule, ...tokens] });
1711417133
return null;
1711517134
}
1711617135
}
@@ -17186,7 +17205,7 @@ function parseNode(results, context, options, errors, src, map, rawTokens) {
1718617205
action: 'drop',
1718717206
message: '@charset must have only one space',
1718817207
// @ts-ignore
17189-
location
17208+
location, rawTokens: [atRule, ...tokens]
1719017209
});
1719117210
return null;
1719217211
}
@@ -17255,6 +17274,7 @@ function parseNode(results, context, options, errors, src, map, rawTokens) {
1725517274
errors.push({
1725617275
action: 'drop',
1725717276
message: valid.error + ' - "' + tokens.reduce((acc, curr) => acc + renderToken(curr, { minify: false }), '') + '"',
17277+
node,
1725817278
// @ts-ignore
1725917279
location: { src, ...(map.get(valid.node) ?? location) }
1726017280
});
@@ -17356,6 +17376,7 @@ function parseNode(results, context, options, errors, src, map, rawTokens) {
1735617376
errors.push({
1735717377
action: 'drop',
1735817378
message: valid.error + ' - "' + tokens.reduce((acc, curr) => acc + renderToken(curr, { minify: false }), '') + '"',
17379+
node,
1735917380
// @ts-ignore
1736017381
location
1736117382
});

dist/index.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1254,7 +1254,8 @@ export declare interface ErrorDescription {
12541254
// drop rule or declaration | fix rule or declaration
12551255
action: 'drop' | 'ignore';
12561256
message: string;
1257-
syntax?: string;
1257+
syntax?: string | null;
1258+
node?: Token | AstNode | null;
12581259
location?: Location;
12591260
error?: Error;
12601261
rawTokens?: TokenizeResult[];

dist/lib/parser/parse.js

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,18 @@ async function doParse(iterator, options = {}) {
122122
stats.bytesIn = item.bytesIn;
123123
rawTokens.push(item);
124124
if (item.hint != null && BadTokensTypes.includes(item.hint)) {
125+
const node = getTokenType(item.token, item.hint);
126+
errors.push({
127+
action: 'drop',
128+
message: 'Bad token',
129+
syntax: null,
130+
node,
131+
location: {
132+
src,
133+
sta: item.sta,
134+
end: item.end
135+
}
136+
});
125137
// bad token
126138
continue;
127139
}
@@ -166,7 +178,12 @@ async function doParse(iterator, options = {}) {
166178
errors.push({
167179
action: 'drop',
168180
message: 'invalid block',
169-
rawTokens: tokens.slice()
181+
rawTokens: tokens.slice(),
182+
location: {
183+
src,
184+
sta: tokens[0].sta,
185+
end: tokens[tokens.length - 1].end
186+
}
170187
});
171188
}
172189
}
@@ -334,6 +351,7 @@ function parseNode(results, context, options, errors, src, map, rawTokens) {
334351
errors.push({
335352
action: 'drop',
336353
message: `CDOCOMM not allowed here ${JSON.stringify(tokens[i], null, 1)}`,
354+
node: tokens[i],
337355
location
338356
});
339357
continue;
@@ -388,7 +406,8 @@ function parseNode(results, context, options, errors, src, map, rawTokens) {
388406
if (!(type == EnumToken.InvalidAtRuleTokenType &&
389407
// @ts-ignore
390408
['charset', 'layer', 'import'].includes(context.chi[i].nam))) {
391-
errors.push({ action: 'drop', message: 'invalid @import', location });
409+
// @ts-ignore
410+
errors.push({ action: 'drop', message: 'invalid @import', location, rawTokens: [atRule, ...tokens] });
392411
return null;
393412
}
394413
}
@@ -464,7 +483,7 @@ function parseNode(results, context, options, errors, src, map, rawTokens) {
464483
action: 'drop',
465484
message: '@charset must have only one space',
466485
// @ts-ignore
467-
location
486+
location, rawTokens: [atRule, ...tokens]
468487
});
469488
return null;
470489
}
@@ -533,6 +552,7 @@ function parseNode(results, context, options, errors, src, map, rawTokens) {
533552
errors.push({
534553
action: 'drop',
535554
message: valid.error + ' - "' + tokens.reduce((acc, curr) => acc + renderToken(curr, { minify: false }), '') + '"',
555+
node,
536556
// @ts-ignore
537557
location: { src, ...(map.get(valid.node) ?? location) }
538558
});
@@ -634,6 +654,7 @@ function parseNode(results, context, options, errors, src, map, rawTokens) {
634654
errors.push({
635655
action: 'drop',
636656
message: valid.error + ' - "' + tokens.reduce((acc, curr) => acc + renderToken(curr, { minify: false }), '') + '"',
657+
node,
637658
// @ts-ignore
638659
location
639660
});

jsr.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@tbela99/css-parser",
3-
"version": "1.3.0-alpha1",
3+
"version": "1.3.0",
44
"publish": {
55
"include": [
66
"src",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@tbela99/css-parser",
33
"description": "CSS parser for node and the browser",
4-
"version": "v1.3.0-alpha1",
4+
"version": "v1.3.0",
55
"exports": {
66
".": "./dist/node/index.js",
77
"./node": "./dist/node/index.js",

src/@types/index.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ export declare interface ErrorDescription {
1919
// drop rule or declaration | fix rule or declaration
2020
action: 'drop' | 'ignore';
2121
message: string;
22-
syntax?: string;
22+
syntax?: string | null;
23+
node?: Token | AstNode | null;
2324
location?: Location;
2425
error?: Error;
2526
rawTokens?: TokenizeResult[];

src/lib/parser/parse.ts

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,19 @@ export async function doParse(iterator: string, options: ParserOptions = {}): Pr
243243

244244
if (item.hint != null && BadTokensTypes.includes(item.hint)) {
245245

246+
const node: Token = getTokenType(item.token, item.hint);
247+
248+
errors.push({
249+
action: 'drop',
250+
message: 'Bad token',
251+
syntax: null,
252+
node,
253+
location: {
254+
src,
255+
sta: item.sta,
256+
end: item.end
257+
}
258+
});
246259
// bad token
247260
continue;
248261
}
@@ -310,7 +323,12 @@ export async function doParse(iterator: string, options: ParserOptions = {}): Pr
310323
errors.push({
311324
action: 'drop',
312325
message: 'invalid block',
313-
rawTokens: tokens.slice()
326+
rawTokens: tokens.slice(),
327+
location: {
328+
src,
329+
sta: tokens[0].sta,
330+
end: tokens[tokens.length - 1].end
331+
}
314332
});
315333
}
316334
}
@@ -563,6 +581,7 @@ function parseNode(results: TokenizeResult[], context: AstRuleList | AstInvalidR
563581
errors.push({
564582
action: 'drop',
565583
message: `CDOCOMM not allowed here ${JSON.stringify(tokens[i], null, 1)}`,
584+
node: tokens[i],
566585
location
567586
});
568587
continue;
@@ -607,7 +626,7 @@ function parseNode(results: TokenizeResult[], context: AstRuleList | AstInvalidR
607626

608627
if (tokens[0]?.typ == EnumToken.AtRuleTokenType) {
609628

610-
const atRule: AtRuleToken = <AtRuleToken>tokens.shift();
629+
const atRule: AtRuleToken = tokens.shift() as AtRuleToken;
611630
const location: Location = <Location>map.get(atRule);
612631

613632
// @ts-ignore
@@ -637,7 +656,8 @@ function parseNode(results: TokenizeResult[], context: AstRuleList | AstInvalidR
637656
// @ts-ignore
638657
['charset', 'layer', 'import'].includes((<AstInvalidAtRule>context.chi[i]).nam as string))) {
639658

640-
errors.push({action: 'drop', message: 'invalid @import', location});
659+
// @ts-ignore
660+
errors.push({action: 'drop', message: 'invalid @import', location, rawTokens: [atRule,...tokens]});
641661
return null;
642662
}
643663
}
@@ -742,7 +762,7 @@ function parseNode(results: TokenizeResult[], context: AstRuleList | AstInvalidR
742762
action: 'drop',
743763
message: '@charset must have only one space',
744764
// @ts-ignore
745-
location
765+
location, rawTokens: [atRule,...tokens]
746766
});
747767

748768
return null;
@@ -841,6 +861,7 @@ function parseNode(results: TokenizeResult[], context: AstRuleList | AstInvalidR
841861
errors.push({
842862
action: 'drop',
843863
message: valid.error + ' - "' + tokens.reduce((acc, curr) => acc + renderToken(curr, {minify: false}), '') + '"',
864+
node,
844865
// @ts-ignore
845866
location: {src, ...(map.get(valid.node) ?? location)}
846867
});
@@ -980,6 +1001,7 @@ function parseNode(results: TokenizeResult[], context: AstRuleList | AstInvalidR
9801001
errors.push({
9811002
action: 'drop',
9821003
message: valid.error + ' - "' + tokens.reduce((acc, curr) => acc + renderToken(curr, {minify: false}), '') + '"',
1004+
node,
9831005
// @ts-ignore
9841006
location
9851007
});
@@ -1922,7 +1944,8 @@ export function parseTokens(tokens: Token[], options: ParseTokenOptions = {}): T
19221944
if ((slice.charAt(0) != '-' || (slice.charAt(0) == '-' && isIdentStart(slice.charCodeAt(1)))) && isIdent(slice)) {
19231945
Object.assign(val, {typ: EnumToken.IdenTokenType, val: slice});
19241946
}
1925-
} else if (val.typ == EnumToken.LiteralTokenType && (val as LiteralToken).val == '|') {
1947+
} else
1948+
if (val.typ == EnumToken.LiteralTokenType && (val as LiteralToken).val == '|') {
19261949

19271950
let upper: number = m;
19281951
let lower: number = m;

0 commit comments

Comments
 (0)