@css-modules-kit/core 0.1.0 → 0.3.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 +13 -17
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +41 -30
- 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 +8 -28
- package/dist/dts-creator.d.ts.map +1 -1
- package/dist/dts-creator.js +106 -7
- 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 +7 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -2
- 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/path.d.ts +0 -1
- package/dist/path.d.ts.map +1 -1
- package/dist/path.js +1 -3
- package/dist/path.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 +2 -2
- package/src/checker.ts +13 -15
- package/src/config.ts +50 -45
- package/src/diagnostic.ts +69 -29
- package/src/dts-creator.ts +120 -13
- package/src/export-builder.ts +1 -16
- package/src/file.ts +1 -2
- package/src/index.ts +14 -14
- 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/path.ts +0 -3
- 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/dist/checker.d.ts
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
import type { MatchesPattern } from './file.js';
|
|
4
|
-
import type { CSSModule } from './parser/css-module-parser.js';
|
|
5
|
-
import type { Resolver } from './resolver.js';
|
|
6
|
-
export declare function checkCSSModule(cssModule: CSSModule, exportBuilder: ExportBuilder, matchesPattern: MatchesPattern, resolver: Resolver, getCSSModule: (path: string) => CSSModule | undefined): SemanticDiagnostic[];
|
|
1
|
+
import type { CSSModule, Diagnostic, ExportBuilder, MatchesPattern, Resolver } from './type.js';
|
|
2
|
+
export declare function checkCSSModule(cssModule: CSSModule, exportBuilder: ExportBuilder, matchesPattern: MatchesPattern, resolver: Resolver, getCSSModule: (path: string) => CSSModule | undefined): Diagnostic[];
|
|
7
3
|
//# sourceMappingURL=checker.d.ts.map
|
package/dist/checker.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"checker.d.ts","sourceRoot":"","sources":["../src/checker.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"checker.d.ts","sourceRoot":"","sources":["../src/checker.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGV,SAAS,EACT,UAAU,EACV,aAAa,EACb,cAAc,EACd,QAAQ,EAET,MAAM,WAAW,CAAC;AAEnB,wBAAgB,cAAc,CAC5B,SAAS,EAAE,SAAS,EACpB,aAAa,EAAE,aAAa,EAC5B,cAAc,EAAE,cAAc,EAC9B,QAAQ,EAAE,QAAQ,EAClB,YAAY,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,SAAS,GAAG,SAAS,GACpD,UAAU,EAAE,CAsBd"}
|
package/dist/checker.js
CHANGED
|
@@ -25,22 +25,20 @@ function checkCSSModule(cssModule, exportBuilder, matchesPattern, resolver, getC
|
|
|
25
25
|
}
|
|
26
26
|
function createCannotImportModuleDiagnostic(cssModule, tokenImporter) {
|
|
27
27
|
return {
|
|
28
|
-
type: 'semantic',
|
|
29
28
|
text: `Cannot import module '${tokenImporter.from}'`,
|
|
30
29
|
category: 'error',
|
|
31
|
-
fileName: cssModule.fileName,
|
|
30
|
+
file: { fileName: cssModule.fileName, text: cssModule.text },
|
|
32
31
|
start: { line: tokenImporter.fromLoc.start.line, column: tokenImporter.fromLoc.start.column },
|
|
33
|
-
|
|
32
|
+
length: tokenImporter.fromLoc.end.offset - tokenImporter.fromLoc.start.offset,
|
|
34
33
|
};
|
|
35
34
|
}
|
|
36
35
|
function createModuleHasNoExportedTokenDiagnostic(cssModule, tokenImporter, value) {
|
|
37
36
|
return {
|
|
38
|
-
type: 'semantic',
|
|
39
37
|
text: `Module '${tokenImporter.from}' has no exported token '${value.name}'.`,
|
|
40
38
|
category: 'error',
|
|
41
|
-
fileName: cssModule.fileName,
|
|
39
|
+
file: { fileName: cssModule.fileName, text: cssModule.text },
|
|
42
40
|
start: { line: value.loc.start.line, column: value.loc.start.column },
|
|
43
|
-
|
|
41
|
+
length: value.loc.end.offset - value.loc.start.offset,
|
|
44
42
|
};
|
|
45
43
|
}
|
|
46
44
|
//# sourceMappingURL=checker.js.map
|
package/dist/checker.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"checker.js","sourceRoot":"","sources":["../src/checker.ts"],"names":[],"mappings":";;AAWA,wCA4BC;AA5BD,SAAgB,cAAc,CAC5B,SAAoB,EACpB,aAA4B,EAC5B,cAA8B,EAC9B,QAAkB,EAClB,YAAqD;IAErD,MAAM,WAAW,
|
|
1
|
+
{"version":3,"file":"checker.js","sourceRoot":"","sources":["../src/checker.ts"],"names":[],"mappings":";;AAWA,wCA4BC;AA5BD,SAAgB,cAAc,CAC5B,SAAoB,EACpB,aAA4B,EAC5B,cAA8B,EAC9B,QAAkB,EAClB,YAAqD;IAErD,MAAM,WAAW,GAAiB,EAAE,CAAC;IAErC,KAAK,MAAM,aAAa,IAAI,SAAS,CAAC,cAAc,EAAE,CAAC;QACrD,MAAM,IAAI,GAAG,QAAQ,CAAC,aAAa,CAAC,IAAI,EAAE,EAAE,OAAO,EAAE,SAAS,CAAC,QAAQ,EAAE,CAAC,CAAC;QAC3E,IAAI,CAAC,IAAI,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC;YAAE,SAAS;QAC7C,MAAM,QAAQ,GAAG,YAAY,CAAC,IAAI,CAAC,CAAC;QACpC,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,WAAW,CAAC,IAAI,CAAC,kCAAkC,CAAC,SAAS,EAAE,aAAa,CAAC,CAAC,CAAC;YAC/E,SAAS;QACX,CAAC;QAED,IAAI,aAAa,CAAC,IAAI,KAAK,OAAO,EAAE,CAAC;YACnC,MAAM,YAAY,GAAG,aAAa,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;YACnD,KAAK,MAAM,KAAK,IAAI,aAAa,CAAC,MAAM,EAAE,CAAC;gBACzC,IAAI,CAAC,YAAY,CAAC,SAAS,C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CAAC,GAAG,CAAC,KAAK,CAAC,MAAM;KACtD,CAAC;AACJ,CAAC"}
|
package/dist/config.d.ts
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
import ts from 'typescript';
|
|
2
|
-
import type {
|
|
3
|
-
type RemoveUndefined<T> = {
|
|
4
|
-
[K in keyof T]: Exclude<T[K], undefined>;
|
|
5
|
-
};
|
|
2
|
+
import type { Diagnostic } from './type.js';
|
|
6
3
|
/**
|
|
7
4
|
* The config used by css-modules-kit.
|
|
8
5
|
* This is normalized. Paths are resolved from relative to absolute, and default values are set for missing options.
|
|
@@ -12,6 +9,8 @@ export interface CMKConfig {
|
|
|
12
9
|
excludes: string[];
|
|
13
10
|
dtsOutDir: string;
|
|
14
11
|
arbitraryExtensions: boolean;
|
|
12
|
+
namedExports: boolean;
|
|
13
|
+
prioritizeNamedImports: boolean;
|
|
15
14
|
/**
|
|
16
15
|
* A root directory to resolve relative path entries in the config file to.
|
|
17
16
|
* This is an absolute path.
|
|
@@ -53,27 +52,29 @@ export interface CMKConfig {
|
|
|
53
52
|
configFileName: string;
|
|
54
53
|
compilerOptions: ts.CompilerOptions;
|
|
55
54
|
/** The diagnostics that occurred while reading the config file. */
|
|
56
|
-
diagnostics:
|
|
55
|
+
diagnostics: Diagnostic[];
|
|
57
56
|
}
|
|
58
57
|
/**
|
|
59
58
|
* The config loaded from `ts.ParsedCommandLine['raw']`.
|
|
60
59
|
* This is unnormalized. Paths are relative, and some options may be omitted.
|
|
61
60
|
*/
|
|
62
61
|
interface UnnormalizedRawConfig {
|
|
63
|
-
includes
|
|
64
|
-
excludes
|
|
65
|
-
dtsOutDir
|
|
66
|
-
arbitraryExtensions
|
|
62
|
+
includes?: string[];
|
|
63
|
+
excludes?: string[];
|
|
64
|
+
dtsOutDir?: string;
|
|
65
|
+
arbitraryExtensions?: boolean;
|
|
66
|
+
namedExports?: boolean;
|
|
67
|
+
prioritizeNamedImports?: boolean;
|
|
67
68
|
}
|
|
68
69
|
/**
|
|
69
70
|
* The validated data of `ts.ParsedCommandLine['raw']`.
|
|
70
71
|
*/
|
|
71
72
|
interface ParsedRawData {
|
|
72
73
|
config: UnnormalizedRawConfig;
|
|
73
|
-
diagnostics:
|
|
74
|
+
diagnostics: Diagnostic[];
|
|
74
75
|
}
|
|
75
76
|
export declare function findTsConfigFile(project: string): string | undefined;
|
|
76
|
-
declare function parseRawData(raw: unknown,
|
|
77
|
+
declare function parseRawData(raw: unknown, tsConfigSourceFile: ts.TsConfigSourceFile): ParsedRawData;
|
|
77
78
|
export { parseRawData as parseRawDataForTest };
|
|
78
79
|
/**
|
|
79
80
|
* @throws {TsConfigFileNotFoundError}
|
|
@@ -82,13 +83,8 @@ export declare function readTsConfigFile(project: string): {
|
|
|
82
83
|
configFileName: string;
|
|
83
84
|
config: UnnormalizedRawConfig;
|
|
84
85
|
compilerOptions: ts.CompilerOptions;
|
|
85
|
-
diagnostics:
|
|
86
|
+
diagnostics: Diagnostic[];
|
|
86
87
|
};
|
|
87
|
-
/**
|
|
88
|
-
* Normalize `UnnormalizedRawConfig`. Resolve relative paths to absolute paths, and set default values for missing options.
|
|
89
|
-
* @param basePath A root directory to resolve relative path entries in the config file to.
|
|
90
|
-
*/
|
|
91
|
-
export declare function normalizeConfig(config: UnnormalizedRawConfig, basePath: string): RemoveUndefined<UnnormalizedRawConfig>;
|
|
92
88
|
/**
|
|
93
89
|
* Reads the `tsconfig.json` file and returns the normalized config.
|
|
94
90
|
* Even if the `tsconfig.json` file contains syntax or semantic errors,
|
package/dist/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;AAG5B,OAAO,KAAK,EAAE,UA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AAe,EAAE,EAAE,CAAC,eAAe,CAAC;IACpC,WAAW,EAAE,UAAU,EAAE,CAAC;CAC3B,CAgDA;AAED;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,CAiBzD"}
|
package/dist/config.js
CHANGED
|
@@ -6,7 +6,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.findTsConfigFile = findTsConfigFile;
|
|
7
7
|
exports.parseRawDataForTest = parseRawData;
|
|
8
8
|
exports.readTsConfigFile = readTsConfigFile;
|
|
9
|
-
exports.normalizeConfig = normalizeConfig;
|
|
10
9
|
exports.readConfigFile = readConfigFile;
|
|
11
10
|
const typescript_1 = __importDefault(require("typescript"));
|
|
12
11
|
const error_js_1 = require("./error.js");
|
|
@@ -21,14 +20,9 @@ function findTsConfigFile(project) {
|
|
|
21
20
|
return undefined;
|
|
22
21
|
return (0, path_js_1.resolve)(configFile);
|
|
23
22
|
}
|
|
24
|
-
function parseRawData(raw,
|
|
23
|
+
function parseRawData(raw, tsConfigSourceFile) {
|
|
25
24
|
const result = {
|
|
26
|
-
config: {
|
|
27
|
-
includes: undefined,
|
|
28
|
-
excludes: undefined,
|
|
29
|
-
dtsOutDir: undefined,
|
|
30
|
-
arbitraryExtensions: undefined,
|
|
31
|
-
},
|
|
25
|
+
config: {},
|
|
32
26
|
diagnostics: [],
|
|
33
27
|
};
|
|
34
28
|
if (typeof raw !== 'object' || raw === null)
|
|
@@ -56,10 +50,9 @@ function parseRawData(raw, configFileName) {
|
|
|
56
50
|
}
|
|
57
51
|
else {
|
|
58
52
|
result.diagnostics.push({
|
|
59
|
-
type: 'semantic',
|
|
60
53
|
category: 'error',
|
|
61
|
-
text:
|
|
62
|
-
|
|
54
|
+
text: `\`dtsOutDir\` in ${tsConfigSourceFile.fileName} must be a string.`,
|
|
55
|
+
// MEMO: Location information can be obtained from `tsConfigSourceFile.statements`, but this is complicated and will be omitted.
|
|
63
56
|
});
|
|
64
57
|
}
|
|
65
58
|
}
|
|
@@ -69,10 +62,33 @@ function parseRawData(raw, configFileName) {
|
|
|
69
62
|
}
|
|
70
63
|
else {
|
|
71
64
|
result.diagnostics.push({
|
|
72
|
-
type: 'semantic',
|
|
73
65
|
category: 'error',
|
|
74
|
-
text:
|
|
75
|
-
|
|
66
|
+
text: `\`arbitraryExtensions\` in ${tsConfigSourceFile.fileName} must be a boolean.`,
|
|
67
|
+
// MEMO: Location information can be obtained from `tsConfigSourceFile.statements`, but this is complicated and will be omitted.
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
if ('namedExports' in raw.cmkOptions) {
|
|
72
|
+
if (typeof raw.cmkOptions.namedExports === 'boolean') {
|
|
73
|
+
result.config.namedExports = raw.cmkOptions.namedExports;
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
result.diagnostics.push({
|
|
77
|
+
category: 'error',
|
|
78
|
+
text: `\`namedExports\` in ${tsConfigSourceFile.fileName} must be a boolean.`,
|
|
79
|
+
// MEMO: Location information can be obtained from `tsConfigSourceFile.statements`, but this is complicated and will be omitted.
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
if ('prioritizeNamedImports' in raw.cmkOptions) {
|
|
84
|
+
if (typeof raw.cmkOptions.prioritizeNamedImports === 'boolean') {
|
|
85
|
+
result.config.prioritizeNamedImports = raw.cmkOptions.prioritizeNamedImports;
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
result.diagnostics.push({
|
|
89
|
+
category: 'error',
|
|
90
|
+
text: `\`prioritizeNamedImports\` in ${tsConfigSourceFile.fileName} must be a boolean.`,
|
|
91
|
+
// MEMO: Location information can be obtained from `tsConfigSourceFile.statements`, but this is complicated and will be omitted.
|
|
76
92
|
});
|
|
77
93
|
}
|
|
78
94
|
}
|
|
@@ -89,6 +105,8 @@ function mergeParsedRawData(base, overrides) {
|
|
|
89
105
|
result.config.dtsOutDir = overrides.config.dtsOutDir;
|
|
90
106
|
if (overrides.config.arbitraryExtensions !== undefined)
|
|
91
107
|
result.config.arbitraryExtensions = overrides.config.arbitraryExtensions;
|
|
108
|
+
if (overrides.config.namedExports !== undefined)
|
|
109
|
+
result.config.namedExports = overrides.config.namedExports;
|
|
92
110
|
result.diagnostics.push(...overrides.diagnostics);
|
|
93
111
|
return result;
|
|
94
112
|
}
|
|
@@ -112,7 +130,7 @@ function readTsConfigFile(project) {
|
|
|
112
130
|
},
|
|
113
131
|
]);
|
|
114
132
|
// Read options from `parsedCommandLine.raw`
|
|
115
|
-
let parsedRawData = parseRawData(parsedCommandLine.raw,
|
|
133
|
+
let parsedRawData = parseRawData(parsedCommandLine.raw, tsConfigSourceFile);
|
|
116
134
|
// The options read from `parsedCommandLine.raw` do not inherit values from the file specified in `extends`.
|
|
117
135
|
// So here we read the options from those files and merge them into `parsedRawData`.
|
|
118
136
|
if (tsConfigSourceFile.extendedSourceFiles) {
|
|
@@ -135,20 +153,6 @@ function readTsConfigFile(project) {
|
|
|
135
153
|
...parsedRawData,
|
|
136
154
|
};
|
|
137
155
|
}
|
|
138
|
-
/**
|
|
139
|
-
* Normalize `UnnormalizedRawConfig`. Resolve relative paths to absolute paths, and set default values for missing options.
|
|
140
|
-
* @param basePath A root directory to resolve relative path entries in the config file to.
|
|
141
|
-
*/
|
|
142
|
-
function normalizeConfig(config, basePath) {
|
|
143
|
-
return {
|
|
144
|
-
// If `include` is not specified, fallback to the default include spec.
|
|
145
|
-
// ref: https://github.com/microsoft/TypeScript/blob/caf1aee269d1660b4d2a8b555c2d602c97cb28d7/src/compiler/commandLineParser.ts#L3102
|
|
146
|
-
includes: (config.includes ?? [DEFAULT_INCLUDE_SPEC]).map((i) => (0, path_js_1.join)(basePath, i)),
|
|
147
|
-
excludes: (config.excludes ?? []).map((e) => (0, path_js_1.join)(basePath, e)),
|
|
148
|
-
dtsOutDir: (0, path_js_1.join)(basePath, config.dtsOutDir ?? 'generated'),
|
|
149
|
-
arbitraryExtensions: config.arbitraryExtensions ?? false,
|
|
150
|
-
};
|
|
151
|
-
}
|
|
152
156
|
/**
|
|
153
157
|
* Reads the `tsconfig.json` file and returns the normalized config.
|
|
154
158
|
* Even if the `tsconfig.json` file contains syntax or semantic errors,
|
|
@@ -161,7 +165,14 @@ function readConfigFile(project) {
|
|
|
161
165
|
const { configFileName, config, compilerOptions, diagnostics } = readTsConfigFile(project);
|
|
162
166
|
const basePath = (0, path_js_1.dirname)(configFileName);
|
|
163
167
|
return {
|
|
164
|
-
|
|
168
|
+
// If `include` is not specified, fallback to the default include spec.
|
|
169
|
+
// ref: https://github.com/microsoft/TypeScript/blob/caf1aee269d1660b4d2a8b555c2d602c97cb28d7/src/compiler/commandLineParser.ts#L3102
|
|
170
|
+
includes: (config.includes ?? [DEFAULT_INCLUDE_SPEC]).map((i) => (0, path_js_1.join)(basePath, i)),
|
|
171
|
+
excludes: (config.excludes ?? []).map((e) => (0, path_js_1.join)(basePath, e)),
|
|
172
|
+
dtsOutDir: (0, path_js_1.join)(basePath, config.dtsOutDir ?? 'generated'),
|
|
173
|
+
arbitraryExtensions: config.arbitraryExtensions ?? false,
|
|
174
|
+
namedExports: config.namedExports ?? false,
|
|
175
|
+
prioritizeNamedImports: config.prioritizeNamedImports ?? false,
|
|
165
176
|
basePath,
|
|
166
177
|
configFileName,
|
|
167
178
|
compilerOptions,
|
package/dist/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":";;;;;AAoFA,4CAOC;
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":";;;;;AAoFA,4CAOC;AA0EwB,2CAAmB;AAiB5C,4CAqDC;AAUD,wCAiBC;AAtQD,4DAA4B;AAC5B,yCAAuD;AACvD,uCAA6D;AAG7D,gIAAgI;AAChI,MAAM,oBAAoB,GAAG,MAAM,CAAC;AA8EpC,SA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,CAAC,EAAE,EAAE,CAAC,IAAA,cAAI,EAAC,QAAQ,EAAE,CAAC,CAAC,CAAC;QAC/D,SAAS,EAAE,IAAA,cAAI,EAAC,QAAQ,EAAE,MAAM,CAAC,SAAS,IAAI,WAAW,CAAC;QAC1D,mBAAmB,EAAE,MAAM,CAAC,mBAAmB,IAAI,KAAK;QACxD,YAAY,EAAE,MAAM,CAAC,YAAY,IAAI,KAAK;QAC1C,sBAAsB,EAAE,MAAM,CAAC,sBAAsB,IAAI,KAAK;QAC9D,QAAQ;QACR,cAAc;QACd,eAAe;QACf,WAAW;KACZ,CAAC;AACJ,CAAC"}
|
package/dist/diagnostic.d.ts
CHANGED
|
@@ -1,34 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
export type Diagnostic = SemanticDiagnostic | SyntacticDiagnostic;
|
|
9
|
-
interface DiagnosticBase {
|
|
10
|
-
/** Text of diagnostic message. */
|
|
11
|
-
text: string;
|
|
12
|
-
/** The category of the diagnostic message. */
|
|
13
|
-
category: DiagnosticCategory;
|
|
14
|
-
}
|
|
15
|
-
export interface SemanticDiagnostic extends DiagnosticBase {
|
|
16
|
-
type: 'semantic';
|
|
17
|
-
/** The filename of the file in which the diagnostic occurred */
|
|
18
|
-
fileName?: string;
|
|
19
|
-
/** Starting file position at which text applies. It is inclusive. */
|
|
20
|
-
start?: DiagnosticPosition;
|
|
21
|
-
/** The last file position at which the text applies. It is exclusive. */
|
|
22
|
-
end?: DiagnosticPosition;
|
|
23
|
-
}
|
|
24
|
-
export interface SyntacticDiagnostic extends DiagnosticBase {
|
|
25
|
-
type: 'syntactic';
|
|
26
|
-
/** The filename of the file in which the diagnostic occurred */
|
|
27
|
-
fileName: string;
|
|
28
|
-
/** Starting file position at which text applies. It is inclusive. */
|
|
29
|
-
start: DiagnosticPosition;
|
|
30
|
-
/** The last file position at which the text applies. It is exclusive. */
|
|
31
|
-
end?: DiagnosticPosition;
|
|
32
|
-
}
|
|
33
|
-
export {};
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
import type { SystemError } from './error.js';
|
|
3
|
+
import type { Diagnostic, DiagnosticSourceFile, DiagnosticWithLocation } from './type.js';
|
|
4
|
+
export declare function convertDiagnostic(diagnostic: Diagnostic, getSourceFile: (file: DiagnosticSourceFile) => ts.SourceFile): ts.Diagnostic;
|
|
5
|
+
export declare function convertDiagnosticWithLocation(diagnostic: DiagnosticWithLocation, getSourceFile: (file: DiagnosticSourceFile) => ts.SourceFile): ts.DiagnosticWithLocation;
|
|
6
|
+
export declare function convertSystemError(systemError: SystemError): ts.Diagnostic;
|
|
34
7
|
//# sourceMappingURL=diagnostic.d.ts.map
|
package/dist/diagnostic.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"diagnostic.d.ts","sourceRoot":"","sources":["../src/diagnostic.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"diagnostic.d.ts","sourceRoot":"","sources":["../src/diagnostic.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,KAAK,EAAE,UAAU,EAAE,oBAAoB,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAC;AAoB1F,wBAAgB,iBAAiB,CAC/B,UAAU,EAAE,UAAU,EACtB,aAAa,EAAE,CAAC,IAAI,EAAE,oBAAoB,KAAK,EAAE,CAAC,UAAU,GAC3D,EAAE,CAAC,UAAU,CAcf;AAED,wBAAgB,6BAA6B,CAC3C,UAAU,EAAE,sBAAsB,EAClC,aAAa,EAAE,CAAC,IAAI,EAAE,oBAAoB,KAAK,EAAE,CAAC,UAAU,GAC3D,EAAE,CAAC,sBAAsB,CAY3B;AAED,wBAAgB,kBAAkB,CAAC,WAAW,EAAE,WAAW,GAAG,EAAE,CAAC,UAAU,CAkB1E"}
|
package/dist/diagnostic.js
CHANGED
|
@@ -1,3 +1,74 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.convertDiagnostic = convertDiagnostic;
|
|
7
|
+
exports.convertDiagnosticWithLocation = convertDiagnosticWithLocation;
|
|
8
|
+
exports.convertSystemError = convertSystemError;
|
|
9
|
+
const typescript_1 = __importDefault(require("typescript"));
|
|
10
|
+
/** The error code used by tsserver to display the css-modules-kit error in the editor. */
|
|
11
|
+
const TS_ERROR_CODE = 0;
|
|
12
|
+
const TS_ERROR_SOURCE = 'css-modules-kit';
|
|
13
|
+
function convertErrorCategory(category) {
|
|
14
|
+
switch (category) {
|
|
15
|
+
case 'error':
|
|
16
|
+
return typescript_1.default.DiagnosticCategory.Error;
|
|
17
|
+
case 'warning':
|
|
18
|
+
return typescript_1.default.DiagnosticCategory.Warning;
|
|
19
|
+
case 'suggestion':
|
|
20
|
+
return typescript_1.default.DiagnosticCategory.Suggestion;
|
|
21
|
+
default:
|
|
22
|
+
throw new Error(`Unknown category: ${String(category)}`);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
function convertDiagnostic(diagnostic, getSourceFile) {
|
|
26
|
+
if ('file' in diagnostic) {
|
|
27
|
+
return convertDiagnosticWithLocation(diagnostic, getSourceFile);
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
return {
|
|
31
|
+
file: undefined,
|
|
32
|
+
start: undefined,
|
|
33
|
+
length: undefined,
|
|
34
|
+
category: convertErrorCategory(diagnostic.category),
|
|
35
|
+
messageText: diagnostic.text,
|
|
36
|
+
code: TS_ERROR_CODE,
|
|
37
|
+
source: TS_ERROR_SOURCE,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
function convertDiagnosticWithLocation(diagnostic, getSourceFile) {
|
|
42
|
+
const sourceFile = getSourceFile(diagnostic.file);
|
|
43
|
+
const start = typescript_1.default.getPositionOfLineAndCharacter(sourceFile, diagnostic.start.line - 1, diagnostic.start.column - 1);
|
|
44
|
+
return {
|
|
45
|
+
file: sourceFile,
|
|
46
|
+
start,
|
|
47
|
+
length: diagnostic.length,
|
|
48
|
+
category: convertErrorCategory(diagnostic.category),
|
|
49
|
+
messageText: diagnostic.text,
|
|
50
|
+
code: TS_ERROR_CODE,
|
|
51
|
+
source: TS_ERROR_SOURCE,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
function convertSystemError(systemError) {
|
|
55
|
+
let messageText = systemError.message;
|
|
56
|
+
if (systemError.cause) {
|
|
57
|
+
if (systemError.cause instanceof Error) {
|
|
58
|
+
messageText += `: ${systemError.cause.message}`;
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
messageText += `: ${JSON.stringify(systemError.cause)}`;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return {
|
|
65
|
+
file: undefined,
|
|
66
|
+
start: undefined,
|
|
67
|
+
length: undefined,
|
|
68
|
+
category: typescript_1.default.DiagnosticCategory.Error,
|
|
69
|
+
messageText,
|
|
70
|
+
code: TS_ERROR_CODE,
|
|
71
|
+
source: TS_ERROR_SOURCE,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
3
74
|
//# sourceMappingURL=diagnostic.js.map
|
package/dist/diagnostic.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"diagnostic.js","sourceRoot":"","sources":["../src/diagnostic.ts"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"diagnostic.js","sourceRoot":"","sources":["../src/diagnostic.ts"],"names":[],"mappings":";;;;;AAsBA,8CAiBC;AAED,sEAeC;AAED,gDAkBC;AA5ED,4DAA4B;AAI5B,0FAA0F;AAC1F,MAAM,aAAa,GAAG,C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ACzB,QAAQ,EAAE,oBAAoB,CAAC,UAAU,CAAC,QAAQ,CAAC;QACnD,WAAW,EAAE,UAAU,CAAC,IAAI;QAC5B,IAAI,EAAE,aAAa;QACnB,MAAM,EAAE,eAAe;KACxB,CAAC;AACJ,CAAC;AAED,SAAgB,kBAAkB,CAAC,WAAwB;IACzD,IAAI,WAAW,GAAG,WAAW,CAAC,OAAO,CAAC;IACtC,IAAI,WAAW,CAAC,KAAK,EAAE,CAAC;QACtB,IAAI,WAAW,CAAC,KAAK,YAAY,KAAK,EAAE,CAAC;YACvC,WAAW,IAAI,KAAK,WAAW,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC;QAClD,CAAC;aAAM,CAAC;YACN,WAAW,IAAI,KAAK,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,KAAK,CAAC,EAAE,CAAC;QAC1D,CAAC;IACH,CAAC;IACD,OAAO;QACL,IAAI,EAAE,SAAS;QACf,KAAK,EAAE,SAAS;QAChB,MAAM,EAAE,SAAS;QACjB,QAAQ,EAAE,oBAAE,CAAC,kBAAkB,CAAC,KAAK;QACrC,WAAW;QACX,IAAI,EAAE,aAAa;QACnB,MAAM,EAAE,eAAe;KACxB,CAAC;AACJ,CAAC"}
|
package/dist/dts-creator.d.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import type { MatchesPattern } from './
|
|
2
|
-
import type { CSSModule } from './parser/css-module-parser.js';
|
|
3
|
-
import type { Resolver } from './resolver.js';
|
|
1
|
+
import type { CSSModule, MatchesPattern, Resolver } from './type.js';
|
|
4
2
|
export declare const STYLES_EXPORT_NAME = "styles";
|
|
5
3
|
export interface CreateDtsOptions {
|
|
6
4
|
resolver: Resolver;
|
|
7
5
|
matchesPattern: MatchesPattern;
|
|
6
|
+
namedExports: boolean;
|
|
8
7
|
}
|
|
9
8
|
interface CodeMapping {
|
|
10
9
|
/** The source offsets of the tokens in the *.module.css file. */
|
|
@@ -25,33 +24,14 @@ interface LinkedCodeMapping extends CodeMapping {
|
|
|
25
24
|
/** The length of the second code to be linked. */
|
|
26
25
|
generatedLengths: number[];
|
|
27
26
|
}
|
|
28
|
-
|
|
29
|
-
* Create a d.ts file from a CSS module file.
|
|
30
|
-
* @example
|
|
31
|
-
* If the CSS module file is:
|
|
32
|
-
* ```css
|
|
33
|
-
* @import './a.module.css';
|
|
34
|
-
* @value local1: string;
|
|
35
|
-
* @value imported1, imported2 as aliasedImported2 from './b.module.css';
|
|
36
|
-
* .local2 { color: red }
|
|
37
|
-
* ```
|
|
38
|
-
* The d.ts file would be:
|
|
39
|
-
* ```ts
|
|
40
|
-
* // @ts-nocheck
|
|
41
|
-
* const styles = {
|
|
42
|
-
* local1: '' as readonly string,
|
|
43
|
-
* local2: '' as readonly string,
|
|
44
|
-
* ...(await import('./a.module.css')).default,
|
|
45
|
-
* imported1: (await import('./b.module.css')).default.imported1,
|
|
46
|
-
* aliasedImported2: (await import('./b.module.css')).default.imported2,
|
|
47
|
-
* };
|
|
48
|
-
* export default styles;
|
|
49
|
-
* ```
|
|
50
|
-
*/
|
|
51
|
-
export declare function createDts({ fileName, localTokens, tokenImporters: _tokenImporters }: CSSModule, options: CreateDtsOptions): {
|
|
27
|
+
interface CreateDtsResult {
|
|
52
28
|
text: string;
|
|
53
29
|
mapping: CodeMapping;
|
|
54
30
|
linkedCodeMapping: LinkedCodeMapping;
|
|
55
|
-
}
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Create a d.ts file.
|
|
34
|
+
*/
|
|
35
|
+
export declare function createDts(cssModules: CSSModule, options: CreateDtsOptions): CreateDtsResult;
|
|
56
36
|
export {};
|
|
57
37
|
//# sourceMappingURL=dts-creator.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dts-creator.d.ts","sourceRoot":"","sources":["../src/dts-creator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"dts-creator.d.ts","sourceRoot":"","sources":["../src/dts-creator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,cAAc,EAAE,QAAQ,EAAwB,MAAM,WAAW,CAAC;AAE3F,eAAO,MAAM,kBAAkB,WAAW,CAAC;AAE3C,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,QAAQ,CAAC;IACnB,cAAc,EAAE,cAAc,CAAC;IAC/B,YAAY,EAAE,OAAO,CAAC;CACvB;AAED,UAAU,WAAW;IACnB,iEAAiE;IACjE,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,0DAA0D;IAC1D,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,8DAA8D;IAC9D,gBAAgB,EAAE,MAAM,EAAE,CAAC;CAC5B;AAED,8CAA8C;AAE9C,UAAU,iBAAkB,SAAQ,WAAW;IAC7C,iDAAiD;IACjD,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,iDAAiD;IACjD,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,kDAAkD;IAClD,gBAAgB,EAAE,MAAM,EAAE,CAAC;IAC3B,kDAAkD;IAClD,gBAAgB,EAAE,MAAM,EAAE,CAAC;CAC5B;AAED,UAAU,eAAe;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,WAAW,CAAC;IACrB,iBAAiB,EAAE,iBAAiB,CAAC;CACtC;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,UAAU,EAAE,SAAS,EAAE,OAAO,EAAE,gBAAgB,GAAG,eAAe,CAW3F"}
|
package/dist/dts-creator.js
CHANGED
|
@@ -4,7 +4,111 @@ exports.STYLES_EXPORT_NAME = void 0;
|
|
|
4
4
|
exports.createDts = createDts;
|
|
5
5
|
exports.STYLES_EXPORT_NAME = 'styles';
|
|
6
6
|
/**
|
|
7
|
-
* Create a d.ts file
|
|
7
|
+
* Create a d.ts file.
|
|
8
|
+
*/
|
|
9
|
+
function createDts(cssModules, options) {
|
|
10
|
+
// Filter external files
|
|
11
|
+
const tokenImporters = cssModules.tokenImporters.filter((tokenImporter) => {
|
|
12
|
+
const resolved = options.resolver(tokenImporter.from, { request: cssModules.fileName });
|
|
13
|
+
return resolved !== undefined && options.matchesPattern(resolved);
|
|
14
|
+
});
|
|
15
|
+
if (options.namedExports) {
|
|
16
|
+
return createNamedExportsDts(cssModules.localTokens, tokenImporters);
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
return createDefaultExportDts(cssModules.localTokens, tokenImporters);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Create a d.ts file with named exports.
|
|
24
|
+
* @example
|
|
25
|
+
* If the CSS module file is:
|
|
26
|
+
* ```css
|
|
27
|
+
* @import './a.module.css';
|
|
28
|
+
* @value local1: string;
|
|
29
|
+
* @value imported1, imported2 as aliasedImported2 from './b.module.css';
|
|
30
|
+
* .local2 { color: red }
|
|
31
|
+
* ```
|
|
32
|
+
* The d.ts file would be:
|
|
33
|
+
* ```ts
|
|
34
|
+
* // @ts-nocheck
|
|
35
|
+
* export var local1: string;
|
|
36
|
+
* export var local2: string;
|
|
37
|
+
* export * from './a.module.css';
|
|
38
|
+
* export {
|
|
39
|
+
* imported1,
|
|
40
|
+
* imported2 as aliasedImported2,
|
|
41
|
+
* } from './b.module.css';
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
function createNamedExportsDts(localTokens, tokenImporters) {
|
|
45
|
+
const mapping = { sourceOffsets: [], lengths: [], generatedOffsets: [] };
|
|
46
|
+
const linkedCodeMapping = {
|
|
47
|
+
sourceOffsets: [],
|
|
48
|
+
lengths: [],
|
|
49
|
+
generatedOffsets: [],
|
|
50
|
+
generatedLengths: [],
|
|
51
|
+
};
|
|
52
|
+
// MEMO: Depending on the TypeScript compilation options, the generated type definition file contains compile errors.
|
|
53
|
+
// For example, it contains `Top-level 'await' expressions are only allowed when the 'module' option is set to ...` error.
|
|
54
|
+
//
|
|
55
|
+
// If `--skipLibCheck` is false, those errors will be reported by `tsc`. However, these are negligible errors.
|
|
56
|
+
// Therefore, `@ts-nocheck` is added to the generated type definition file.
|
|
57
|
+
let text = `// @ts-nocheck\n`;
|
|
58
|
+
for (const token of localTokens) {
|
|
59
|
+
text += `export var `;
|
|
60
|
+
mapping.sourceOffsets.push(token.loc.start.offset);
|
|
61
|
+
mapping.generatedOffsets.push(text.length);
|
|
62
|
+
mapping.lengths.push(token.name.length);
|
|
63
|
+
text += `${token.name}: string;\n`;
|
|
64
|
+
}
|
|
65
|
+
for (const tokenImporter of tokenImporters) {
|
|
66
|
+
if (tokenImporter.type === 'import') {
|
|
67
|
+
text += `export * from `;
|
|
68
|
+
mapping.sourceOffsets.push(tokenImporter.fromLoc.start.offset - 1);
|
|
69
|
+
mapping.lengths.push(tokenImporter.from.length + 2);
|
|
70
|
+
mapping.generatedOffsets.push(text.length);
|
|
71
|
+
text += `'${tokenImporter.from}';\n`;
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
text += `export {\n`;
|
|
75
|
+
// eslint-disable-next-line no-loop-func
|
|
76
|
+
tokenImporter.values.forEach((value) => {
|
|
77
|
+
const localName = value.localName ?? value.name;
|
|
78
|
+
const localLoc = value.localLoc ?? value.loc;
|
|
79
|
+
text += ` `;
|
|
80
|
+
if ('localName' in value) {
|
|
81
|
+
mapping.sourceOffsets.push(value.loc.start.offset);
|
|
82
|
+
mapping.lengths.push(value.name.length);
|
|
83
|
+
mapping.generatedOffsets.push(text.length);
|
|
84
|
+
linkedCodeMapping.generatedOffsets.push(text.length);
|
|
85
|
+
linkedCodeMapping.generatedLengths.push(value.name.length);
|
|
86
|
+
text += `${value.name} as `;
|
|
87
|
+
mapping.sourceOffsets.push(localLoc.start.offset);
|
|
88
|
+
mapping.lengths.push(localName.length);
|
|
89
|
+
mapping.generatedOffsets.push(text.length);
|
|
90
|
+
linkedCodeMapping.sourceOffsets.push(text.length);
|
|
91
|
+
linkedCodeMapping.lengths.push(localName.length);
|
|
92
|
+
text += `${localName},\n`;
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
mapping.sourceOffsets.push(value.loc.start.offset);
|
|
96
|
+
mapping.lengths.push(value.name.length);
|
|
97
|
+
mapping.generatedOffsets.push(text.length);
|
|
98
|
+
text += `${value.name},\n`;
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
text += `} from `;
|
|
102
|
+
mapping.sourceOffsets.push(tokenImporter.fromLoc.start.offset - 1);
|
|
103
|
+
mapping.lengths.push(tokenImporter.from.length + 2);
|
|
104
|
+
mapping.generatedOffsets.push(text.length);
|
|
105
|
+
text += `'${tokenImporter.from}';\n`;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return { text, mapping, linkedCodeMapping };
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Create a d.ts file with a default export.
|
|
8
112
|
* @example
|
|
9
113
|
* If the CSS module file is:
|
|
10
114
|
* ```css
|
|
@@ -26,7 +130,7 @@ exports.STYLES_EXPORT_NAME = 'styles';
|
|
|
26
130
|
* export default styles;
|
|
27
131
|
* ```
|
|
28
132
|
*/
|
|
29
|
-
function
|
|
133
|
+
function createDefaultExportDts(localTokens, tokenImporters) {
|
|
30
134
|
const mapping = { sourceOffsets: [], lengths: [], generatedOffsets: [] };
|
|
31
135
|
const linkedCodeMapping = {
|
|
32
136
|
sourceOffsets: [],
|
|
@@ -34,11 +138,6 @@ function createDts({ fileName, localTokens, tokenImporters: _tokenImporters }, o
|
|
|
34
138
|
generatedOffsets: [],
|
|
35
139
|
generatedLengths: [],
|
|
36
140
|
};
|
|
37
|
-
// Filter external files
|
|
38
|
-
const tokenImporters = _tokenImporters.filter((tokenImporter) => {
|
|
39
|
-
const resolved = options.resolver(tokenImporter.from, { request: fileName });
|
|
40
|
-
return resolved !== undefined && options.matchesPattern(resolved);
|
|
41
|
-
});
|
|
42
141
|
// MEMO: Depending on the TypeScript compilation options, the generated type definition file contains compile errors.
|
|
43
142
|
// For example, it contains `Top-level 'await' expressions are only allowed when the 'module' option is set to ...` error.
|
|
44
143
|
//
|