@css-modules-kit/core 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/checker.d.ts +2 -6
- package/dist/checker.d.ts.map +1 -1
- package/dist/checker.js +4 -6
- package/dist/checker.js.map +1 -1
- package/dist/config.d.ts +5 -5
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +6 -8
- package/dist/config.js.map +1 -1
- package/dist/diagnostic.d.ts +6 -33
- package/dist/diagnostic.d.ts.map +1 -1
- package/dist/diagnostic.js +71 -0
- package/dist/diagnostic.js.map +1 -1
- package/dist/dts-creator.d.ts +1 -3
- package/dist/dts-creator.d.ts.map +1 -1
- package/dist/dts-creator.js.map +1 -1
- package/dist/export-builder.d.ts +1 -14
- package/dist/export-builder.d.ts.map +1 -1
- package/dist/export-builder.js.map +1 -1
- package/dist/file.d.ts +1 -1
- package/dist/file.d.ts.map +1 -1
- package/dist/file.js.map +1 -1
- package/dist/index.d.ts +6 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -1
- package/dist/index.js.map +1 -1
- package/dist/parser/at-import-parser.d.ts +1 -1
- package/dist/parser/at-import-parser.d.ts.map +1 -1
- package/dist/parser/at-value-parser.d.ts +2 -3
- package/dist/parser/at-value-parser.d.ts.map +1 -1
- package/dist/parser/at-value-parser.js +2 -13
- package/dist/parser/at-value-parser.js.map +1 -1
- package/dist/parser/css-module-parser.d.ts +2 -83
- package/dist/parser/css-module-parser.d.ts.map +1 -1
- package/dist/parser/css-module-parser.js +7 -8
- package/dist/parser/css-module-parser.js.map +1 -1
- package/dist/parser/rule-parser.d.ts +8 -4
- package/dist/parser/rule-parser.d.ts.map +1 -1
- package/dist/parser/rule-parser.js +9 -10
- package/dist/parser/rule-parser.js.map +1 -1
- package/dist/resolver.d.ts +3 -12
- package/dist/resolver.d.ts.map +1 -1
- package/dist/resolver.js +2 -2
- package/dist/resolver.js.map +1 -1
- package/dist/type.d.ts +174 -0
- package/dist/type.d.ts.map +1 -0
- package/dist/type.js +3 -0
- package/dist/type.js.map +1 -0
- package/package.json +1 -1
- package/src/checker.ts +13 -15
- package/src/config.ts +10 -12
- package/src/diagnostic.ts +69 -29
- package/src/dts-creator.ts +1 -3
- package/src/export-builder.ts +1 -16
- package/src/file.ts +1 -2
- package/src/index.ts +13 -13
- package/src/parser/at-import-parser.ts +1 -1
- package/src/parser/at-value-parser.ts +5 -17
- package/src/parser/css-module-parser.ts +16 -98
- package/src/parser/rule-parser.ts +17 -14
- package/src/resolver.ts +12 -15
- package/src/type.ts +191 -0
- package/dist/parser/location.d.ts +0 -34
- package/dist/parser/location.d.ts.map +0 -1
- package/dist/parser/location.js +0 -9
- package/dist/parser/location.js.map +0 -1
- package/src/parser/location.ts +0 -40
package/src/type.ts
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
/** The position of the node in the source file. */
|
|
2
|
+
export interface Position {
|
|
3
|
+
/**
|
|
4
|
+
* The line number in the source file. It is 1-based.
|
|
5
|
+
* This is compatible with postcss and tsserver.
|
|
6
|
+
*/
|
|
7
|
+
line: number;
|
|
8
|
+
/**
|
|
9
|
+
* The column number in the source file. It is 1-based.
|
|
10
|
+
* This is compatible with postcss and tsserver.
|
|
11
|
+
*/
|
|
12
|
+
column: number;
|
|
13
|
+
/** The offset in the source file. It is 0-based. */
|
|
14
|
+
offset: number;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** The location of the node in the source file. */
|
|
18
|
+
export interface Location {
|
|
19
|
+
/**
|
|
20
|
+
* The starting position of the node. It is inclusive.
|
|
21
|
+
* This is compatible with postcss and tsserver.
|
|
22
|
+
*/
|
|
23
|
+
start: Position;
|
|
24
|
+
/**
|
|
25
|
+
* The ending position of the node. It is exclusive.
|
|
26
|
+
* This is compatible with tsserver, but not postcss.
|
|
27
|
+
*/
|
|
28
|
+
end: Position;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** The item being exported from a CSS module file (a.k.a. token). */
|
|
32
|
+
export interface Token {
|
|
33
|
+
/** The token name. */
|
|
34
|
+
name: string;
|
|
35
|
+
/** The location of the token in the source file. */
|
|
36
|
+
loc: Location;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* A token importer using `@import '...'`.
|
|
41
|
+
* `@import` imports all tokens from the file. Therefore, it does not have
|
|
42
|
+
* the name of the imported token unlike {@link AtValueTokenImporter}.
|
|
43
|
+
*/
|
|
44
|
+
export interface AtImportTokenImporter {
|
|
45
|
+
type: 'import';
|
|
46
|
+
/**
|
|
47
|
+
* The specifier of the file from which the token is imported.
|
|
48
|
+
* This is a string before being resolved and unquoted.
|
|
49
|
+
* @example `@import './a.module.css'` would have `from` as `'./a.module.css'`.
|
|
50
|
+
*/
|
|
51
|
+
from: string;
|
|
52
|
+
/** The location of the `from` in *.module.css file. */
|
|
53
|
+
fromLoc: Location;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** A token importer using `@value ... from '...'`. */
|
|
57
|
+
export interface AtValueTokenImporter {
|
|
58
|
+
type: 'value';
|
|
59
|
+
/** The values imported from the file. */
|
|
60
|
+
values: AtValueTokenImporterValue[];
|
|
61
|
+
/**
|
|
62
|
+
* The specifier of the file from which the token is imported.
|
|
63
|
+
* This is a string before being resolved and unquoted.
|
|
64
|
+
* @example `@value a from './a.module.css'` would have `from` as `'./a.module.css'`.
|
|
65
|
+
*/
|
|
66
|
+
from: string;
|
|
67
|
+
/** The location of the `from` in *.module.css file. */
|
|
68
|
+
fromLoc: Location;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** A value imported from a CSS module file using `@value ... from '...'`. */
|
|
72
|
+
export interface AtValueTokenImporterValue {
|
|
73
|
+
/**
|
|
74
|
+
* The name of the token in the file from which it is imported.
|
|
75
|
+
* @example `@value a from './a.module.css'` would have `name` as `'a'`.
|
|
76
|
+
* @example `@value a as b from './a.module.css'` would have `name` as `'a'`.
|
|
77
|
+
*/
|
|
78
|
+
name: string;
|
|
79
|
+
/** The location of the `name` in *.module.css file. */
|
|
80
|
+
loc: Location;
|
|
81
|
+
/**
|
|
82
|
+
* The name of the token in the current file.
|
|
83
|
+
* @example `@value a from './a.module.css'` would not have `localName`.
|
|
84
|
+
* @example `@value a as b from './a.module.css'` would have `localName` as `'b'`.
|
|
85
|
+
*/
|
|
86
|
+
localName?: string;
|
|
87
|
+
/**
|
|
88
|
+
* The location of the `localName` in *.module.css file.
|
|
89
|
+
* This is `undefined` when `localName` is `undefined`.
|
|
90
|
+
*/
|
|
91
|
+
localLoc?: Location;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export type TokenImporter = AtImportTokenImporter | AtValueTokenImporter;
|
|
95
|
+
|
|
96
|
+
export interface CSSModule {
|
|
97
|
+
/** Absolute path of the file */
|
|
98
|
+
fileName: string;
|
|
99
|
+
/** The content of the file */
|
|
100
|
+
text: string;
|
|
101
|
+
/**
|
|
102
|
+
* List of token names defined in the file.
|
|
103
|
+
* @example
|
|
104
|
+
* Consider the following file:
|
|
105
|
+
* ```css
|
|
106
|
+
* .foo { color: red }
|
|
107
|
+
* .bar, .baz { color: red }
|
|
108
|
+
* ```
|
|
109
|
+
* The `localTokens` for this file would be `['foo', 'bar', 'baz']`.
|
|
110
|
+
*/
|
|
111
|
+
localTokens: Token[];
|
|
112
|
+
/**
|
|
113
|
+
* List of token importers in the file.
|
|
114
|
+
* Token importer is a statement that imports tokens from another file.
|
|
115
|
+
*/
|
|
116
|
+
tokenImporters: TokenImporter[];
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export interface ResolverOptions {
|
|
120
|
+
/** The file that imports the specifier. It is a absolute path. */
|
|
121
|
+
request: string;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* A resolver function that resolves import specifiers.
|
|
126
|
+
* @param specifier The import specifier.
|
|
127
|
+
* @param options The options.
|
|
128
|
+
* @returns The resolved import specifier. It is a absolute path. If the import specifier cannot be resolved, return `undefined`.
|
|
129
|
+
*/
|
|
130
|
+
export type Resolver = (specifier: string, options: ResolverOptions) => string | undefined;
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* A function that checks if a file name matches a pattern.
|
|
134
|
+
* @param fileName The file name. It is an absolute path.
|
|
135
|
+
* @returns `true` if the file name matches the pattern, otherwise `false`.
|
|
136
|
+
*/
|
|
137
|
+
export type MatchesPattern = (fileName: string) => boolean;
|
|
138
|
+
|
|
139
|
+
/** The export token record of a CSS module. */
|
|
140
|
+
export interface ExportRecord {
|
|
141
|
+
/** The all exported tokens of the CSS module. */
|
|
142
|
+
allTokens: string[];
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export interface ExportBuilder {
|
|
146
|
+
build(cssModule: CSSModule): ExportRecord;
|
|
147
|
+
clearCache(): void;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export type DiagnosticCategory = 'error' | 'warning';
|
|
151
|
+
|
|
152
|
+
export interface DiagnosticSourceFile {
|
|
153
|
+
fileName: string;
|
|
154
|
+
text: string;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export interface DiagnosticPosition {
|
|
158
|
+
/** The line number in the source file. It is 1-based. */
|
|
159
|
+
line: number;
|
|
160
|
+
/** The column number in the source file. It is 1-based. */
|
|
161
|
+
column: number;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
interface DiagnosticWithoutLocation {
|
|
165
|
+
/** Text of diagnostic message. */
|
|
166
|
+
text: string;
|
|
167
|
+
/** The category of the diagnostic message. */
|
|
168
|
+
category: DiagnosticCategory;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
export interface DiagnosticWithLocation extends DiagnosticWithoutLocation {
|
|
172
|
+
/** The file in which the diagnostic occurred */
|
|
173
|
+
file: DiagnosticSourceFile;
|
|
174
|
+
/** Starting file position at which text applies. It is inclusive. */
|
|
175
|
+
start: DiagnosticPosition;
|
|
176
|
+
/** Length of the diagnostic. */
|
|
177
|
+
length: number;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
export type Diagnostic = DiagnosticWithLocation | DiagnosticWithoutLocation;
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* A diagnostic with location information detached from the source file.
|
|
184
|
+
* It is an intermediate representation used inside the CSS Module parser.
|
|
185
|
+
*/
|
|
186
|
+
export interface DiagnosticWithDetachedLocation extends DiagnosticWithoutLocation {
|
|
187
|
+
/** Starting file position at which text applies. It is inclusive. */
|
|
188
|
+
start: DiagnosticPosition;
|
|
189
|
+
/** Length of the diagnostic. */
|
|
190
|
+
length: number;
|
|
191
|
+
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import type { Rule } from 'postcss';
|
|
2
|
-
import type selectorParser from 'postcss-selector-parser';
|
|
3
|
-
import type { DiagnosticPosition } from '../diagnostic.js';
|
|
4
|
-
export interface Position {
|
|
5
|
-
/**
|
|
6
|
-
* The line number in the source file. It is 1-based.
|
|
7
|
-
* This is compatible with postcss and tsserver.
|
|
8
|
-
*/
|
|
9
|
-
line: number;
|
|
10
|
-
/**
|
|
11
|
-
* The column number in the source file. It is 1-based.
|
|
12
|
-
* This is compatible with postcss and tsserver.
|
|
13
|
-
*/
|
|
14
|
-
column: number;
|
|
15
|
-
/** The offset in the source file. It is 0-based. */
|
|
16
|
-
offset: number;
|
|
17
|
-
}
|
|
18
|
-
export interface Location {
|
|
19
|
-
/**
|
|
20
|
-
* The starting position of the node. It is inclusive.
|
|
21
|
-
* This is compatible with postcss and tsserver.
|
|
22
|
-
*/
|
|
23
|
-
start: Position;
|
|
24
|
-
/**
|
|
25
|
-
* The ending position of the node. It is exclusive.
|
|
26
|
-
* This is compatible with tsserver, but not postcss.
|
|
27
|
-
*/
|
|
28
|
-
end: Position;
|
|
29
|
-
}
|
|
30
|
-
export declare function calcDiagnosticsLocationForSelectorParserNode(rule: Rule, node: selectorParser.Node): {
|
|
31
|
-
start: DiagnosticPosition;
|
|
32
|
-
end: DiagnosticPosition;
|
|
33
|
-
};
|
|
34
|
-
//# sourceMappingURL=location.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"location.d.ts","sourceRoot":"","sources":["../../src/parser/location.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,KAAK,cAAc,MAAM,yBAAyB,CAAC;AAC1D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAE3D,MAAM,WAAW,QAAQ;IACvB;;;OAGG;IACH,IAAI,EAAE,MAAM,CAAC;IACb;;;OAGG;IACH,MAAM,EAAE,MAAM,CAAC;IACf,oDAAoD;IACpD,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,QAAQ;IACvB;;;OAGG;IACH,KAAK,EAAE,QAAQ,CAAC;IAChB;;;OAGG;IACH,GAAG,EAAE,QAAQ,CAAC;CACf;AAED,wBAAgB,4CAA4C,CAC1D,IAAI,EAAE,IAAI,EACV,IAAI,EAAE,cAAc,CAAC,IAAI,GACxB;IAAE,KAAK,EAAE,kBAAkB,CAAC;IAAC,GAAG,EAAE,kBAAkB,CAAA;CAAE,CAIxD"}
|
package/dist/parser/location.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.calcDiagnosticsLocationForSelectorParserNode = calcDiagnosticsLocationForSelectorParserNode;
|
|
4
|
-
function calcDiagnosticsLocationForSelectorParserNode(rule, node) {
|
|
5
|
-
const start = rule.positionBy({ index: node.sourceIndex });
|
|
6
|
-
const end = rule.positionBy({ index: node.sourceIndex + node.toString().length });
|
|
7
|
-
return { start, end };
|
|
8
|
-
}
|
|
9
|
-
//# sourceMappingURL=location.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"location.js","sourceRoot":"","sources":["../../src/parser/location.ts"],"names":[],"mappings":";;AAgCA,oGAOC;AAPD,SAAgB,4CAA4C,CAC1D,IAAU,EACV,IAAyB;IAEzB,MAAM,KAAK,GAAG,IAAI,CAAC,UAAU,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC;IAC3D,MAAM,GAAG,GAAG,IAAI,CAAC,UAAU,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAC,MAAM,EAAE,CAAC,CAAC;IAClF,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC;AACxB,CAAC"}
|
package/src/parser/location.ts
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import type { Rule } from 'postcss';
|
|
2
|
-
import type selectorParser from 'postcss-selector-parser';
|
|
3
|
-
import type { DiagnosticPosition } from '../diagnostic.js';
|
|
4
|
-
|
|
5
|
-
export interface Position {
|
|
6
|
-
/**
|
|
7
|
-
* The line number in the source file. It is 1-based.
|
|
8
|
-
* This is compatible with postcss and tsserver.
|
|
9
|
-
*/
|
|
10
|
-
line: number;
|
|
11
|
-
/**
|
|
12
|
-
* The column number in the source file. It is 1-based.
|
|
13
|
-
* This is compatible with postcss and tsserver.
|
|
14
|
-
*/
|
|
15
|
-
column: number;
|
|
16
|
-
/** The offset in the source file. It is 0-based. */
|
|
17
|
-
offset: number;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export interface Location {
|
|
21
|
-
/**
|
|
22
|
-
* The starting position of the node. It is inclusive.
|
|
23
|
-
* This is compatible with postcss and tsserver.
|
|
24
|
-
*/
|
|
25
|
-
start: Position;
|
|
26
|
-
/**
|
|
27
|
-
* The ending position of the node. It is exclusive.
|
|
28
|
-
* This is compatible with tsserver, but not postcss.
|
|
29
|
-
*/
|
|
30
|
-
end: Position;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export function calcDiagnosticsLocationForSelectorParserNode(
|
|
34
|
-
rule: Rule,
|
|
35
|
-
node: selectorParser.Node,
|
|
36
|
-
): { start: DiagnosticPosition; end: DiagnosticPosition } {
|
|
37
|
-
const start = rule.positionBy({ index: node.sourceIndex });
|
|
38
|
-
const end = rule.positionBy({ index: node.sourceIndex + node.toString().length });
|
|
39
|
-
return { start, end };
|
|
40
|
-
}
|