Skip to content

Commit 707df0c

Browse files
authored
fix(core): remove unnecessary mappings (#317)
1 parent b534580 commit 707df0c

3 files changed

Lines changed: 25 additions & 25 deletions

File tree

.changeset/petite-zebras-enjoy.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@css-modules-kit/core': patch
3+
---
4+
5+
fix(core): remove unnecessary mappings

packages/core/src/dts-generator.ts

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -353,36 +353,35 @@ function generateDefaultExportDts(
353353
* The mapping is created as follows:
354354
* a.module.css:
355355
* 1 | @value b_1, b_2 from './b.module.css';
356-
* | ^ ^ ^ mapping.sourceOffsets[1]
357-
* | ^ ^ mapping.sourceOffsets[3], mapping.sourceOffsets[4]
358-
* | ^ mapping.sourceOffsets[0], mapping.sourceOffsets[2]
356+
* | ^ ^ ^ mapping.sourceOffsets[0]
357+
* | ^ ^ mapping.sourceOffsets[2]
358+
* | ^ mapping.sourceOffsets[1]
359359
* |
360360
* 2 | @value c_1 as aliased_c_1 from './c.module.css';
361-
* | ^ ^ ^ mapping.sourceOffsets[6]
362-
* | ^ ^ mapping.sourceOffsets[5]
363-
* | ^ mapping.sourceOffsets[7]
361+
* | ^ ^ ^ mapping.sourceOffsets[4]
362+
* | ^ ^ mapping.sourceOffsets[3]
363+
* | ^ mapping.sourceOffsets[5]
364364
* |
365365
*
366366
* a.module.css.d.ts:
367367
* 1 | declare const styles = {
368368
* 2 | b_1: (await import('./b.module.css')).default.b_1,
369-
* | ^ ^ ^ mapping.generatedOffsets[2], linkedCodeMapping.generatedOffsets[0]
369+
* | ^ ^ ^ linkedCodeMapping.generatedOffsets[0]
370370
* | ^ ^ mapping.generatedOffsets[1]
371371
* | ^ mapping.generatedOffsets[0], linkedCodeMapping.sourceOffsets[0]
372372
* |
373373
* 3 | b_2: (await import('./b.module.css')).default.b_2,
374-
* | ^ ^ mapping.generatedOffsets[4], linkedCodeMapping.generatedOffsets[1]
375-
* | ^ mapping.generatedOffsets[3], linkedCodeMapping.sourceOffsets[1]
374+
* | ^ ^ linkedCodeMapping.generatedOffsets[1]
375+
* | ^ mapping.generatedOffsets[2], linkedCodeMapping.sourceOffsets[1]
376376
* |
377377
* 4 | aliased_c_1: (await import('./c.module.css')).default.c_1,
378-
* | ^ ^ ^ mapping.generatedOffsets[7], linkedCodeMapping.generatedOffsets[2]
379-
* | ^ ^ mapping.generatedOffsets[6]
380-
* | ^ mapping.generatedOffsets[5], linkedCodeMapping.sourceOffsets[2]
378+
* | ^ ^ ^ mapping.generatedOffsets[5], linkedCodeMapping.generatedOffsets[2]
379+
* | ^ ^ mapping.generatedOffsets[4]
380+
* | ^ mapping.generatedOffsets[3], linkedCodeMapping.sourceOffsets[2]
381381
* |
382382
* 5 | };
383383
*
384384
* NOTE: Not only the specifier but also the surrounding quotes are included in the mapping.
385-
* TODO: Stop generating unnecessary mappings for tokens that do not have a `localName`.
386385
*/
387386

388387
// eslint-disable-next-line no-loop-func
@@ -403,9 +402,11 @@ function generateDefaultExportDts(
403402
mapping.generatedOffsets.push(text.length);
404403
}
405404
text += `'${tokenImporter.from}')).default.`;
406-
mapping.sourceOffsets.push(value.loc.start.offset);
407-
mapping.lengths.push(value.name.length);
408-
mapping.generatedOffsets.push(text.length);
405+
if ('localName' in value) {
406+
mapping.sourceOffsets.push(value.loc.start.offset);
407+
mapping.lengths.push(value.name.length);
408+
mapping.generatedOffsets.push(text.length);
409+
}
409410
linkedCodeMapping.generatedOffsets.push(text.length);
410411
linkedCodeMapping.generatedLengths.push(value.name.length);
411412
text += `${value.name},\n`;

packages/ts-plugin/e2e-test/feature/find-all-references.test.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -168,25 +168,19 @@ describe('Find All References', async () => {
168168
name: 'c_1 in index.ts',
169169
file: c_1_in_index_ts.file,
170170
...c_1_in_index_ts.start,
171-
// NOTE: For simplicity of implementation, this is not the ideal behavior. The ideal behavior is as follows:
172-
// expected: [c_1_in_index_ts, c_1_in_a_module_css, c_1_in_c_module_css],
173-
expected: [c_1_in_index_ts, c_1_in_a_module_css, c_1_in_a_module_css, c_1_in_c_module_css],
171+
expected: [c_1_in_index_ts, c_1_in_a_module_css, c_1_in_c_module_css],
174172
},
175173
{
176174
name: 'c_1 in a.module.css',
177175
file: c_1_in_a_module_css.file,
178176
...c_1_in_a_module_css.start,
179-
// NOTE: For simplicity of implementation, this is not the ideal behavior. The ideal behavior is as follows:
180-
// expected: [c_1_in_index_ts, c_1_in_a_module_css, c_1_in_c_module_css],
181-
expected: [c_1_in_index_ts, c_1_in_a_module_css, c_1_in_a_module_css, c_1_in_c_module_css],
177+
expected: [c_1_in_index_ts, c_1_in_a_module_css, c_1_in_c_module_css],
182178
},
183179
{
184180
name: 'c_1 in c.module.css',
185181
file: c_1_in_c_module_css.file,
186182
...c_1_in_c_module_css.start,
187-
// NOTE: For simplicity of implementation, this is not the ideal behavior. The ideal behavior is as follows:
188-
// expected: [c_1_in_index_ts, c_1_in_a_module_css, c_1_in_c_module_css],
189-
expected: [c_1_in_index_ts, c_1_in_a_module_css, c_1_in_a_module_css, c_1_in_c_module_css],
183+
expected: [c_1_in_index_ts, c_1_in_a_module_css, c_1_in_c_module_css],
190184
},
191185
{
192186
name: 'c_alias in index.ts',

0 commit comments

Comments
 (0)