@css-modules-kit/core 0.0.5 → 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 +5 -1
- package/dist/file.d.ts.map +1 -1
- package/dist/file.js +15 -0
- package/dist/file.js.map +1 -1
- package/dist/index.d.ts +7 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -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/dist/util.d.ts +1 -0
- package/dist/util.d.ts.map +1 -1
- package/dist/util.js +17 -0
- package/dist/util.js.map +1 -1
- 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 +17 -1
- package/src/index.ts +15 -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/src/util.ts +18 -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
|
@@ -1,16 +1,25 @@
|
|
|
1
1
|
import type { Rule } from 'postcss';
|
|
2
2
|
import selectorParser from 'postcss-selector-parser';
|
|
3
|
-
import type {
|
|
4
|
-
|
|
3
|
+
import type { DiagnosticPosition, DiagnosticWithDetachedLocation, Location } from '../type.js';
|
|
4
|
+
|
|
5
|
+
function calcDiagnosticsLocationForSelectorParserNode(
|
|
6
|
+
rule: Rule,
|
|
7
|
+
node: selectorParser.Node,
|
|
8
|
+
): { start: DiagnosticPosition; length: number } {
|
|
9
|
+
const start = rule.positionBy({ index: node.sourceIndex });
|
|
10
|
+
const length = node.toString().length;
|
|
11
|
+
return { start, length };
|
|
12
|
+
}
|
|
13
|
+
export { calcDiagnosticsLocationForSelectorParserNode as calcDiagnosticsLocationForSelectorParserNodeForTest };
|
|
5
14
|
|
|
6
15
|
interface CollectResult {
|
|
7
16
|
classNames: selectorParser.ClassName[];
|
|
8
|
-
diagnostics:
|
|
17
|
+
diagnostics: DiagnosticWithDetachedLocation[];
|
|
9
18
|
}
|
|
10
19
|
|
|
11
20
|
function flatCollectResults(results: CollectResult[]): CollectResult {
|
|
12
21
|
const classNames: selectorParser.ClassName[] = [];
|
|
13
|
-
const diagnostics:
|
|
22
|
+
const diagnostics: DiagnosticWithDetachedLocation[] = [];
|
|
14
23
|
for (const result of results) {
|
|
15
24
|
classNames.push(...result.classNames);
|
|
16
25
|
diagnostics.push(...result.diagnostics);
|
|
@@ -25,9 +34,7 @@ function convertClassNameToCollectResult(rule: Rule, node: selectorParser.ClassN
|
|
|
25
34
|
const name = (node as any).raws?.value ?? node.value;
|
|
26
35
|
|
|
27
36
|
if (!JS_IDENTIFIER_PATTERN.test(name)) {
|
|
28
|
-
const diagnostic:
|
|
29
|
-
type: 'syntactic',
|
|
30
|
-
fileName: rule.source!.input.file!,
|
|
37
|
+
const diagnostic: DiagnosticWithDetachedLocation = {
|
|
31
38
|
...calcDiagnosticsLocationForSelectorParserNode(rule, node),
|
|
32
39
|
text: `\`${name}\` is not allowed because it is not a valid JavaScript identifier.`,
|
|
33
40
|
category: 'error',
|
|
@@ -67,9 +74,7 @@ function collectLocalClassNames(rule: Rule, root: selectorParser.Root): CollectR
|
|
|
67
74
|
if (node.nodes.length === 0) {
|
|
68
75
|
// `node` is `:local` or `:global` (without any arguments)
|
|
69
76
|
// We don't support `:local` and `:global` (without any arguments) because they are complex.
|
|
70
|
-
const diagnostic:
|
|
71
|
-
type: 'syntactic',
|
|
72
|
-
fileName: rule.source!.input.file!,
|
|
77
|
+
const diagnostic: DiagnosticWithDetachedLocation = {
|
|
73
78
|
...calcDiagnosticsLocationForSelectorParserNode(rule, node),
|
|
74
79
|
text: `\`${node.value}\` is not supported. Use \`${node.value}(...)\` instead.`,
|
|
75
80
|
category: 'error',
|
|
@@ -78,9 +83,7 @@ function collectLocalClassNames(rule: Rule, root: selectorParser.Root): CollectR
|
|
|
78
83
|
} else {
|
|
79
84
|
// `node` is `:local(...)` or `:global(...)` (with arguments)
|
|
80
85
|
if (wrappedBy !== undefined) {
|
|
81
|
-
const diagnostic:
|
|
82
|
-
type: 'syntactic',
|
|
83
|
-
fileName: rule.source!.input.file!,
|
|
86
|
+
const diagnostic: DiagnosticWithDetachedLocation = {
|
|
84
87
|
...calcDiagnosticsLocationForSelectorParserNode(rule, node),
|
|
85
88
|
text: `A \`${node.value}(...)\` is not allowed inside of \`${wrappedBy}\`.`,
|
|
86
89
|
category: 'error',
|
|
@@ -107,7 +110,7 @@ interface ClassSelector {
|
|
|
107
110
|
|
|
108
111
|
interface ParseRuleResult {
|
|
109
112
|
classSelectors: ClassSelector[];
|
|
110
|
-
diagnostics:
|
|
113
|
+
diagnostics: DiagnosticWithDetachedLocation[];
|
|
111
114
|
}
|
|
112
115
|
|
|
113
116
|
/**
|
package/src/resolver.ts
CHANGED
|
@@ -2,21 +2,12 @@ import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
|
2
2
|
import type { CompilerOptions } from 'typescript';
|
|
3
3
|
import ts from 'typescript';
|
|
4
4
|
import { isAbsolute, resolve } from './path.js';
|
|
5
|
+
import type { Resolver, ResolverOptions } from './type.js';
|
|
5
6
|
|
|
6
|
-
export
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* A resolver function that resolves import specifiers.
|
|
13
|
-
* @param specifier The import specifier.
|
|
14
|
-
* @param options The options.
|
|
15
|
-
* @returns The resolved import specifier. It is a absolute path. If the import specifier cannot be resolved, return `undefined`.
|
|
16
|
-
*/
|
|
17
|
-
export type Resolver = (specifier: string, options: ResolverOptions) => string | undefined;
|
|
18
|
-
|
|
19
|
-
export function createResolver(compilerOptions: CompilerOptions): Resolver {
|
|
7
|
+
export function createResolver(
|
|
8
|
+
compilerOptions: CompilerOptions,
|
|
9
|
+
moduleResolutionCache: ts.ModuleResolutionCache | undefined,
|
|
10
|
+
): Resolver {
|
|
20
11
|
return (_specifier: string, options: ResolverOptions) => {
|
|
21
12
|
let specifier = _specifier;
|
|
22
13
|
|
|
@@ -29,7 +20,13 @@ export function createResolver(compilerOptions: CompilerOptions): Resolver {
|
|
|
29
20
|
return ts.sys.fileExists(fileName);
|
|
30
21
|
},
|
|
31
22
|
};
|
|
32
|
-
const { resolvedModule } = ts.resolveModuleName(
|
|
23
|
+
const { resolvedModule } = ts.resolveModuleName(
|
|
24
|
+
specifier,
|
|
25
|
+
options.request,
|
|
26
|
+
compilerOptions,
|
|
27
|
+
host,
|
|
28
|
+
moduleResolutionCache,
|
|
29
|
+
);
|
|
33
30
|
if (resolvedModule) {
|
|
34
31
|
// TODO: Logging that the paths is used.
|
|
35
32
|
specifier = resolvedModule.resolvedFileName.replace(/\.module\.d\.css\.ts$/u, '.module.css');
|
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
|
+
}
|
package/src/util.ts
CHANGED
|
@@ -1,3 +1,21 @@
|
|
|
1
1
|
export function isPosixRelativePath(path: string): boolean {
|
|
2
2
|
return path.startsWith(`./`) || path.startsWith(`../`);
|
|
3
3
|
}
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The syntax pattern for consuming tokens imported from CSS Module.
|
|
7
|
+
* @example `styles.foo`
|
|
8
|
+
*/
|
|
9
|
+
// TODO(#125): Support `styles['foo']` and `styles["foo"]`
|
|
10
|
+
// MEMO: The `xxxStyles.foo` format is not supported, because the css module file for current component file is usually imported with `styles`.
|
|
11
|
+
// It is sufficient to support only the `styles.foo` format.
|
|
12
|
+
const TOKEN_CONSUMER_PATTERN = /styles\.([$_\p{ID_Start}][$\u200c\u200d\p{ID_Continue}]*)/gu;
|
|
13
|
+
|
|
14
|
+
export function findUsedTokenNames(componentText: string): Set<string> {
|
|
15
|
+
const usedClassNames = new Set<string>();
|
|
16
|
+
let match;
|
|
17
|
+
while ((match = TOKEN_CONSUMER_PATTERN.exec(componentText)) !== null) {
|
|
18
|
+
usedClassNames.add(match[1]!);
|
|
19
|
+
}
|
|
20
|
+
return usedClassNames;
|
|
21
|
+
}
|
|
@@ -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
|
-
}
|