-
Notifications
You must be signed in to change notification settings - Fork 357
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Carlos (Goodwine) <[email protected]>
- Loading branch information
Showing
22 changed files
with
2,021 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,7 @@ | |
|
||
## 0.4.10 | ||
|
||
* No user-visible changes. | ||
* Add support for parsing the `@import` rule. | ||
|
||
## 0.4.9 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
pkg/sass-parser/lib/src/__snapshots__/dynamic-import.test.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`a dynamic import toJSON 1`] = ` | ||
{ | ||
"inputs": [ | ||
{ | ||
"css": "@import "foo"", | ||
"hasBOM": false, | ||
"id": "<input css _____>", | ||
}, | ||
], | ||
"raws": {}, | ||
"sassType": "dynamic-import", | ||
"source": <1:9-1:14 in 0>, | ||
"url": "foo", | ||
} | ||
`; |
20 changes: 20 additions & 0 deletions
20
pkg/sass-parser/lib/src/__snapshots__/import-list.test.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`an import list toJSON 1`] = ` | ||
{ | ||
"inputs": [ | ||
{ | ||
"css": "@import "foo", "bar.css"", | ||
"hasBOM": false, | ||
"id": "<input css _____>", | ||
}, | ||
], | ||
"nodes": [ | ||
<"foo">, | ||
<"bar.css">, | ||
], | ||
"raws": {}, | ||
"sassType": "import-list", | ||
"source": <1:1-1:25 in 0>, | ||
} | ||
`; |
34 changes: 34 additions & 0 deletions
34
pkg/sass-parser/lib/src/__snapshots__/static-import.test.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`a static import toJSON with modifiers 1`] = ` | ||
{ | ||
"inputs": [ | ||
{ | ||
"css": "@import "foo.css" screen", | ||
"hasBOM": false, | ||
"id": "<input css _____>", | ||
}, | ||
], | ||
"modifiers": <screen>, | ||
"raws": {}, | ||
"sassType": "static-import", | ||
"source": <1:9-1:25 in 0>, | ||
"staticUrl": <"foo.css">, | ||
} | ||
`; | ||
exports[`a static import toJSON without modifiers 1`] = ` | ||
{ | ||
"inputs": [ | ||
{ | ||
"css": "@import "foo.css"", | ||
"hasBOM": false, | ||
"id": "<input css _____>", | ||
}, | ||
], | ||
"raws": {}, | ||
"sassType": "static-import", | ||
"source": <1:9-1:18 in 0>, | ||
"staticUrl": <"foo.css">, | ||
} | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
// Copyright 2025 Google Inc. Use of this source code is governed by an | ||
// MIT-style license that can be found in the LICENSE file or at | ||
// https://opensource.org/licenses/MIT. | ||
|
||
import {DynamicImport, ImportList, ImportRule, sass, scss} from '..'; | ||
|
||
describe('a dynamic import', () => { | ||
let node: DynamicImport; | ||
|
||
function describeNode( | ||
description: string, | ||
create: () => DynamicImport, | ||
): void { | ||
describe(description, () => { | ||
beforeEach(() => (node = create())); | ||
|
||
it('has a sassType', () => | ||
expect(node.sassType.toString()).toBe('dynamic-import')); | ||
|
||
it('has a url', () => expect(node.url).toBe('foo')); | ||
}); | ||
} | ||
|
||
describeNode( | ||
'parsed as SCSS', | ||
() => | ||
(scss.parse('@import "foo"').nodes[0] as ImportRule).imports | ||
.nodes[0] as DynamicImport, | ||
); | ||
|
||
describeNode( | ||
'parsed as Sass', | ||
() => | ||
(sass.parse('@import "foo"').nodes[0] as ImportRule).imports | ||
.nodes[0] as DynamicImport, | ||
); | ||
|
||
describe('constructed manually', () => { | ||
describeNode('with a string', () => new DynamicImport('foo')); | ||
|
||
describeNode('with an object', () => new DynamicImport({url: 'foo'})); | ||
}); | ||
|
||
describe('constructed from properties', () => { | ||
describeNode( | ||
'with a string', | ||
() => new ImportList({nodes: ['foo']}).nodes[0] as DynamicImport, | ||
); | ||
|
||
describeNode( | ||
'with an object', | ||
() => new ImportList({nodes: [{url: 'foo'}]}).nodes[0] as DynamicImport, | ||
); | ||
}); | ||
|
||
describe('stringifies', () => { | ||
describe('to SCSS', () => { | ||
describe('with default raws', () => { | ||
it('with a simple URL', () => | ||
expect(new DynamicImport('foo').toString()).toBe('"foo"')); | ||
|
||
it('with a URL that needs escaping', () => | ||
expect(new DynamicImport('\\').toString()).toBe('"\\\\"')); | ||
}); | ||
|
||
// raws.before is only used as part of a ImportList | ||
it('ignores before', () => | ||
expect( | ||
new DynamicImport({ | ||
url: 'foo', | ||
raws: {before: '/**/'}, | ||
}).toString(), | ||
).toBe('"foo"')); | ||
|
||
// raws.after is only used as part of a ImportList | ||
it('ignores after', () => | ||
expect( | ||
new DynamicImport({ | ||
url: 'foo', | ||
raws: {after: '/**/'}, | ||
}).toString(), | ||
).toBe('"foo"')); | ||
|
||
it('with matching url', () => | ||
expect( | ||
new DynamicImport({ | ||
url: 'foo', | ||
raws: {url: {raw: '"f\\6fo"', value: 'foo'}}, | ||
}).toString(), | ||
).toBe('"f\\6fo"')); | ||
|
||
it('with non-matching url', () => | ||
expect( | ||
new DynamicImport({ | ||
url: 'foo', | ||
raws: {url: {raw: '"f\\41o"', value: 'fao'}}, | ||
}).toString(), | ||
).toBe('"foo"')); | ||
}); | ||
}); | ||
|
||
describe('clone()', () => { | ||
let original: DynamicImport; | ||
beforeEach(() => { | ||
original = (scss.parse('@import "foo"').nodes[0] as ImportRule).imports | ||
.nodes[0] as DynamicImport; | ||
// TODO: remove this once raws are properly parsed. | ||
original.raws.before = '/**/'; | ||
}); | ||
|
||
describe('with no overrides', () => { | ||
let clone: DynamicImport; | ||
beforeEach(() => void (clone = original.clone())); | ||
|
||
describe('has the same properties:', () => { | ||
it('url', () => expect(clone.url).toBe('foo')); | ||
}); | ||
|
||
describe('creates a new', () => { | ||
it('self', () => expect(clone).not.toBe(original)); | ||
|
||
for (const attr of ['raws'] as const) { | ||
it(attr, () => expect(clone[attr]).not.toBe(original[attr])); | ||
} | ||
}); | ||
}); | ||
|
||
describe('overrides', () => { | ||
describe('raws', () => { | ||
it('defined', () => | ||
expect(original.clone({raws: {after: ' '}}).raws).toEqual({ | ||
after: ' ', | ||
})); | ||
|
||
it('undefined', () => | ||
expect(original.clone({raws: undefined}).raws).toEqual({ | ||
before: '/**/', | ||
})); | ||
}); | ||
|
||
describe('url', () => { | ||
it('defined', () => | ||
expect(original.clone({url: 'bar'}).url).toBe('bar')); | ||
|
||
it('undefined', () => | ||
expect(original.clone({url: undefined}).url).toBe('foo')); | ||
}); | ||
}); | ||
}); | ||
|
||
it('toJSON', () => | ||
expect( | ||
(scss.parse('@import "foo"').nodes[0] as ImportRule).imports.nodes[0], | ||
).toMatchSnapshot()); | ||
}); |
Oops, something went wrong.