mizdra / happy-css-modules

Typed, definition jumpable CSS Modules. Moreover, easy!
MIT License
213 stars 5 forks source link

Token has only one `originalLocation` #265

Closed mizdra closed 2 weeks ago

mizdra commented 2 weeks ago

Breaking Changes

The token has only one originalLocation

Previously, a token returned Locator#load could have multiple OriginalLocation.

const filePath = resolve('example/02-import/2.css'); // Convert to absolute path
const result = await locator.load(filePath);

assert.deepEqual(result, {
  dependencies: ['/path/to/1.css'],
  tokens: [
    {
      name: 'a',
      originalLocations: [
        {
          filePath: '/path/to/1.css',
          start: { line: 1, column: 1 },
          end: { line: 1, column: 2 },
        },
        {
          filePath: '/path/to/1.css',
          start: { line: 2, column: 1 },
          end: { line: 2, column: 2 },
        },
      ],
    },
  ],
});

From now on, each token will have one OriginalLocation.

const filePath = resolve('example/02-import/2.css'); // Convert to absolute path
const result = await locator.load(filePath);

assert.deepEqual(result, {
  dependencies: ['/path/to/1.css'],
  tokens: [
    {
      name: 'a',
      originalLocation: {
        filePath: '/path/to/1.css',
        start: { line: 1, column: 1 },
        end: { line: 1, column: 2 },
      },
    },
    {
      name: 'a',
      originalLocation: {
        filePath: '/path/to/1.css',
        start: { line: 2, column: 1 },
        end: { line: 2, column: 2 },
      },
    },
  ],
});

Locator#load is part of the experimental Programmable API. Therefore, this change is shipped as a minor update.