Skip to content

Commit

Permalink
fix(core): improve detection of custom idents in shorthands.gridArea() (
Browse files Browse the repository at this point in the history
  • Loading branch information
layershifter authored Nov 30, 2023
1 parent fb6f681 commit 7d72d1e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "fix: improve detection of custom idents in shorthands.gridArea()",
"packageName": "@griffel/core",
"email": "[email protected]",
"dependentChangeType": "patch"
}
12 changes: 11 additions & 1 deletion packages/core/src/shorthands/gridArea.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
import { gridArea } from './gridArea';
import { gridArea, isCustomIdent } from './gridArea';

it('isCustomIdent', () => {
expect(isCustomIdent('auto')).toBe(false);
expect(isCustomIdent(2)).toBe(false);
expect(isCustomIdent('2')).toBe(false);
expect(isCustomIdent('2 span')).toBe(false);

expect(isCustomIdent('areaA')).toBe(true);
expect(isCustomIdent('area1')).toBe(true);
});

describe('gridArea(all)', () => {
it('for auto', () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/shorthands/gridArea.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ function isValidGridAreaInput(value: GridAreaInput) {

// A custom-ident can be an alpha-numeric string including dash (-), underscore, escaped (\) characters, and escaped unicode
const customIdentRegEx = /^[a-zA-Z0-9\-_\\#;]+$/;
const nonCustomIdentRegEx = /^-moz-initial$|^auto$|^initial$|^inherit$|^revert$|^unset$|^span \d+$|\d.*/;
const nonCustomIdentRegEx = /^-moz-initial$|^auto$|^initial$|^inherit$|^revert$|^unset$|^span \d+$|^\d.*/;

// See https://developer.mozilla.org/en-US/docs/Web/CSS/custom-ident
function isCustomIdent(value: GridAreaInput | undefined): boolean {
export function isCustomIdent(value: GridAreaInput | undefined): boolean {
return (
value !== undefined && typeof value === 'string' && customIdentRegEx.test(value) && !nonCustomIdentRegEx.test(value)
);
Expand Down

0 comments on commit 7d72d1e

Please sign in to comment.