Skip to content

Commit

Permalink
Update some configuration names to avoid unnecessary namespacing
Browse files Browse the repository at this point in the history
  • Loading branch information
nex3 committed Nov 20, 2024
1 parent 57a6853 commit ea47287
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 91 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ exports[`a configured variable toJSON 1`] = `
"id": "<input css _____>",
},
],
"name": "baz",
"raws": {},
"sassType": "configured-variable",
"source": <1:18-1:29 in 0>,
"variableName": "baz",
}
`;
56 changes: 27 additions & 29 deletions pkg/sass-parser/lib/src/configuration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ describe('a configuration map', () => {
it('contains the variable', () => {
expect(node.size).toBe(1);
const variable = [...node.variables()][0];
expect(variable.variableName).toEqual('bar');
expect(variable.name).toEqual('bar');
expect(variable).toHaveStringExpression('expression', 'baz');
});
});
Expand All @@ -101,9 +101,7 @@ describe('a configuration map', () => {
'variables array',
() =>
new Configuration({
variables: [
{variableName: 'bar', expression: {text: 'baz', quotes: true}},
],
variables: [{name: 'bar', expression: {text: 'baz', quotes: true}}],
}),
);

Expand All @@ -127,7 +125,7 @@ describe('a configuration map', () => {
describe('add()', () => {
test('with a ConfiguredVariable', () => {
const variable = new ConfiguredVariable({
variableName: 'foo',
name: 'foo',
expression: {text: 'bar', quotes: true},
});
expect(node.add(variable)).toBe(node);
Expand All @@ -137,29 +135,29 @@ describe('a configuration map', () => {
});

test('with a ConfiguredVariableProps', () => {
node.add({variableName: 'foo', expression: {text: 'bar', quotes: true}});
node.add({name: 'foo', expression: {text: 'bar', quotes: true}});
expect(node.size).toBe(1);
const variable = node.get('foo');
expect(variable?.variableName).toBe('foo');
expect(variable?.name).toBe('foo');
expect(variable).toHaveStringExpression('expression', 'bar');
expect(variable?.parent).toBe(node);
});

test('overwrites on old variable', () => {
node.add({variableName: 'foo', expression: {text: 'old', quotes: true}});
node.add({name: 'foo', expression: {text: 'old', quotes: true}});
const old = node.get('foo');
expect(old?.parent).toBe(node);

node.add({variableName: 'foo', expression: {text: 'new', quotes: true}});
node.add({name: 'foo', expression: {text: 'new', quotes: true}});
expect(node.size).toBe(1);
expect(old?.parent).toBeUndefined();
expect(node.get('foo')).toHaveStringExpression('expression', 'new');
});
});

test('clear() removes all variables', () => {
node.add({variableName: 'foo', expression: {text: 'bar', quotes: true}});
node.add({variableName: 'baz', expression: {text: 'bang', quotes: true}});
node.add({name: 'foo', expression: {text: 'bar', quotes: true}});
node.add({name: 'baz', expression: {text: 'bang', quotes: true}});
const foo = node.get('foo');
const bar = node.get('bar');
node.clear();
Expand All @@ -172,8 +170,8 @@ describe('a configuration map', () => {

describe('delete()', () => {
beforeEach(() => {
node.add({variableName: 'foo', expression: {text: 'bar', quotes: true}});
node.add({variableName: 'baz', expression: {text: 'bang', quotes: true}});
node.add({name: 'foo', expression: {text: 'bar', quotes: true}});
node.add({name: 'baz', expression: {text: 'bang', quotes: true}});
});

test('removes a matching variable', () => {
Expand All @@ -192,12 +190,12 @@ describe('a configuration map', () => {

describe('get()', () => {
beforeEach(() => {
node.add({variableName: 'foo', expression: {text: 'bar', quotes: true}});
node.add({name: 'foo', expression: {text: 'bar', quotes: true}});
});

test('returns a variable in the configuration', () => {
const variable = node.get('foo');
expect(variable?.variableName).toBe('foo');
expect(variable?.name).toBe('foo');
expect(variable).toHaveStringExpression('expression', 'bar');
});

Expand All @@ -208,7 +206,7 @@ describe('a configuration map', () => {

describe('has()', () => {
beforeEach(() => {
node.add({variableName: 'foo', expression: {text: 'bar', quotes: true}});
node.add({name: 'foo', expression: {text: 'bar', quotes: true}});
});

test('returns true for a variable in the configuration', () =>
Expand All @@ -220,7 +218,7 @@ describe('a configuration map', () => {

describe('set()', () => {
beforeEach(() => {
node.add({variableName: 'foo', expression: {text: 'bar', quotes: true}});
node.add({name: 'foo', expression: {text: 'bar', quotes: true}});
});

describe('adds a new variable', () => {
Expand All @@ -233,7 +231,7 @@ describe('a configuration map', () => {
expect(node.size).toBe(2);
const variable = node.get('baz');
expect(variable?.parent).toBe(node);
expect(variable?.variableName).toBe('baz');
expect(variable?.name).toBe('baz');
expect(variable).toHaveStringExpression('expression', 'bang');
});
}
Expand Down Expand Up @@ -285,15 +283,15 @@ describe('a configuration map', () => {
}).toString(),
).toBe('($foo: "bar", $baz: "bang",)'));

it('with comma: true and afterValue', () =>
it('with comma: true and after', () =>
expect(
new Configuration({
raws: {comma: true},
variables: {
foo: {text: 'bar', quotes: true},
baz: {
expression: {text: 'bang', quotes: true},
raws: {afterValue: '/**/'},
raws: {after: '/**/'},
},
},
}).toString(),
Expand All @@ -310,28 +308,28 @@ describe('a configuration map', () => {
}).toString(),
).toBe('($foo: "bar", $baz: "bang"/**/)'));

it('with after and afterValue', () =>
it('with after and after', () =>
expect(
new Configuration({
raws: {after: '/**/'},
variables: {
foo: {text: 'bar', quotes: true},
baz: {
expression: {text: 'bang', quotes: true},
raws: {afterValue: ' '},
raws: {after: ' '},
},
},
}).toString(),
).toBe('($foo: "bar", $baz: "bang" /**/)'));

it('with afterValue and a guard', () =>
it('with after and a guard', () =>
expect(
new Configuration({
variables: {
foo: {text: 'bar', quotes: true},
baz: {
expression: {text: 'bang', quotes: true},
raws: {afterValue: '/**/'},
raws: {after: '/**/'},
guarded: true,
},
},
Expand Down Expand Up @@ -359,10 +357,10 @@ describe('a configuration map', () => {
it('variables', () => {
expect(clone.size).toBe(2);
const variables = [...clone.variables()];
expect(variables[0]?.variableName).toBe('foo');
expect(variables[0]?.name).toBe('foo');
expect(variables[0]?.parent).toBe(clone);
expect(variables[0]).toHaveStringExpression('expression', 'bar');
expect(variables[1]?.variableName).toBe('baz');
expect(variables[1]?.name).toBe('baz');
expect(variables[1]?.parent).toBe(clone);
expect(variables[1]).toHaveStringExpression('expression', 'bang');
});
Expand Down Expand Up @@ -399,7 +397,7 @@ describe('a configuration map', () => {
});
expect(clone.size).toBe(1);
const variables = [...clone.variables()];
expect(variables[0]?.variableName).toBe('zip');
expect(variables[0]?.name).toBe('zip');
expect(variables[0]?.parent).toBe(clone);
expect(variables[0]).toHaveStringExpression('expression', 'zap');
});
Expand All @@ -408,10 +406,10 @@ describe('a configuration map', () => {
const clone = original.clone({variables: undefined});
expect(clone.size).toBe(2);
const variables = [...clone.variables()];
expect(variables[0]?.variableName).toBe('foo');
expect(variables[0]?.name).toBe('foo');
expect(variables[0]?.parent).toBe(clone);
expect(variables[0]).toHaveStringExpression('expression', 'bar');
expect(variables[1]?.variableName).toBe('baz');
expect(variables[1]?.name).toBe('baz');
expect(variables[1]?.parent).toBe(clone);
expect(variables[1]).toHaveStringExpression('expression', 'bang');
});
Expand Down
6 changes: 3 additions & 3 deletions pkg/sass-parser/lib/src/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ export class Configuration extends Node {
const realVariable =
'sassType' in variable ? variable : new ConfiguredVariable(variable);
realVariable.parent = this;
const old = this._variables.get(realVariable.variableName);
const old = this._variables.get(realVariable.name);
if (old) old.parent = undefined;
this._variables.set(realVariable.variableName, realVariable);
this._variables.set(realVariable.name, realVariable);
return this;
}

Expand Down Expand Up @@ -189,7 +189,7 @@ export class Configuration extends Node {
result += variable.raws.before ?? ' ';
}
result += variable.toString();
result += variable.raws.afterValue ?? '';
result += variable.raws.after ?? '';
}
return result + `${this.raws.comma ? ',' : ''}${this.raws.after ?? ''})`;
}
Expand Down
Loading

0 comments on commit ea47287

Please sign in to comment.