Skip to content

Commit

Permalink
Merge branch 'main' of github.com:sass/sass-spec into merge
Browse files Browse the repository at this point in the history
  • Loading branch information
nex3 committed Aug 12, 2024
2 parents 00338ba + 24437eb commit 250a836
Show file tree
Hide file tree
Showing 553 changed files with 33,742 additions and 9,358 deletions.
6 changes: 5 additions & 1 deletion js-api-spec/compile.node.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,11 @@ describe('compileString', () => {
'_upstream.scss': 'a {b: c}',
});
expect(
compileString('@import "left"; @import "right"', {url}).loadedUrls
compileString('@import "left"; @import "right"', {
url,
// TODO(jathak): Add this once import deprecation is active
// silenceDeprecations: ['import'],
}).loadedUrls
).toEqual([
url,
dir.url('_left.scss'),
Expand Down
8 changes: 4 additions & 4 deletions js-api-spec/compiler.node.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('Compiler', () => {
it('performs complete compilations', () =>
sandbox(dir => {
const logger = getLogger();
dir.write({'input.scss': '@import "bar"; .fn {value: foo(bar)}'});
dir.write({'input.scss': '@use "bar"; .fn {value: foo(bar)}'});
const result = compiler.compile(dir('input.scss'), {
importers,
functions,
Expand All @@ -52,7 +52,7 @@ describe('Compiler', () => {
syntax: 'scss',
}),
};
dir.write({'input.scss': '@import "nested"; a {b: c}'});
dir.write({'input.scss': '@use "nested"; a {b: c}'});
const result = compiler.compile(dir('input.scss'), {
importers: [nestedImporter],
});
Expand Down Expand Up @@ -91,7 +91,7 @@ describe('AsyncCompiler', () => {
.map((_, i) => {
const filename = `input-${i}.scss`;
dir.write({
[filename]: `@import "${i}"; .fn {value: foo(${i})}`,
[filename]: `@use "${i}" as _; .fn {value: foo(${i})}`,
});
return compiler.compileAsync(dir(filename), {
importers: asyncImporters,
Expand Down Expand Up @@ -121,7 +121,7 @@ describe('AsyncCompiler', () => {
it('waits for compilations to finish before disposing', () =>
sandbox(async dir => {
let completed = false;
dir.write({'input.scss': '@import "slow"'});
dir.write({'input.scss': '@use "slow"'});
const {importer, triggerComplete} = getTriggeredImporter(
() => (completed = true)
);
Expand Down
14 changes: 9 additions & 5 deletions js-api-spec/compiler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ describe('Compiler', () => {
it('performs complete compilations', () => {
const logger = getLogger();
const result = compiler.compileString(
'@import "bar"; .fn {value: foo(baz)}',
'@use "bar"; .fn {value: foo(baz)}',
{importers, functions, logger}
);
expect(result.css).toEqualIgnoringWhitespace(
Expand All @@ -90,7 +90,7 @@ describe('Compiler', () => {
syntax: 'scss',
}),
};
const result = compiler.compileString('@import "nested"; a {b: c}', {
const result = compiler.compileString('@use "nested"; a {b: c}', {
importers: [nestedImporter],
});
expect(result.css).toEqualIgnoringWhitespace('x {y: z;} a {b: c;}');
Expand Down Expand Up @@ -139,8 +139,12 @@ describe('AsyncCompiler', () => {
.fill(0)
.map((_, i) =>
compiler.compileStringAsync(
`@import "${i}"; .fn {value: foo(${i})}`,
{importers: asyncImporters, functions, logger}
`@use "${i}" as _; .fn {value: foo(${i})}`,
{
importers: asyncImporters,
functions,
logger,
}
)
);
Array.from(await Promise.all(compilations))
Expand All @@ -165,7 +169,7 @@ describe('AsyncCompiler', () => {
const {importer, triggerComplete} = getTriggeredImporter(
() => (completed = true)
);
const compilation = compiler.compileStringAsync('@import "slow"', {
const compilation = compiler.compileStringAsync('@use "slow"', {
importers: [importer],
});

Expand Down
1 change: 1 addition & 0 deletions js-api-spec/deprecations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ describe('an error', () => {
});
});

// TODO(jathak): Disable these tests when there aren't any future deprecations.
describe('for a future deprecation,', () => {
let importer: Importer;
beforeEach(() => {
Expand Down
54 changes: 28 additions & 26 deletions js-api-spec/importer.node.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ it('avoids importer when canonicalize() returns null', () =>
sandbox(dir => {
dir.write({'dir/_other.scss': 'a {from: dir}'});

const result = compileString('@import "other";', {
const result = compileString('@use "other";', {
importers: [
{
canonicalize: () => null,
Expand All @@ -37,7 +37,7 @@ it('fails to import when load() returns null', () =>
dir.write({'dir/_other.scss': 'a {from: dir}'});

expect(() => {
compileString('@import "other";', {
compileString('@use "other";', {
importers: [
{
canonicalize: (url: string) => new URL(`u:${url}`),
Expand All @@ -52,7 +52,7 @@ it('fails to import when load() returns null', () =>
it('prefers a relative file load to an importer', () =>
sandbox(dir => {
dir.write({
'input.scss': '@import "other"',
'input.scss': '@use "other"',
'_other.scss': 'a {from: relative}',
});

Expand All @@ -74,7 +74,7 @@ it('prefers a relative file load to an importer', () =>
it('prefers an importer to a load path', () =>
sandbox(dir => {
dir.write({
'input.scss': '@import "other"',
'input.scss': '@use "other"',
'dir/_other.scss': 'a {from: load-path}',
});

Expand All @@ -95,7 +95,7 @@ describe('FileImporter', () => {
sandbox(dir => {
dir.write({'_other.scss': 'a {b: c}'});

const result = compileString('@import "other";', {
const result = compileString('@use "other";', {
importers: [{findFileUrl: () => dir.url('_other.scss')}],
});
expect(result.css).toBe('a {\n b: c;\n}');
Expand All @@ -105,7 +105,7 @@ describe('FileImporter', () => {
sandbox(dir => {
dir.write({'other/_index.scss': 'a {b: c}'});

const result = compileString('@import "other";', {
const result = compileString('@use "other";', {
importers: [{findFileUrl: () => dir.url('other')}],
});
expect(result.css).toBe('a {\n b: c;\n}');
Expand All @@ -115,7 +115,7 @@ describe('FileImporter', () => {
sandbox(dir => {
dir.write({'_other.scss': 'a {from: dir}'});

const result = compileString('@import "other";', {
const result = compileString('@use "other";', {
importers: [{findFileUrl: () => null}],
loadPaths: [dir.root],
});
Expand All @@ -126,7 +126,7 @@ describe('FileImporter', () => {
sandbox(dir => {
dir.write({'_other.scss': 'a {from: dir}'});

const result = compileString('@import "other";', {
const result = compileString('@use "other";', {
importers: [{findFileUrl: () => dir.url('nonexistent/other')}],
loadPaths: [dir.root],
});
Expand All @@ -137,7 +137,7 @@ describe('FileImporter', () => {
sandbox(dir => {
dir.write({'dir/_other.scss': 'a {b: c}'});

const result = compileString('@import "u:other";', {
const result = compileString('@use "u:other";', {
importers: [
{
findFileUrl(url: string) {
Expand All @@ -154,7 +154,7 @@ describe('FileImporter', () => {
sandbox(dir => {
dir.write({'_other.scss': 'a {b: c}'});

const result = compileString(`@import "${dir.url('other')}";`, {
const result = compileString(`@use "${dir.url('other')}";`, {
importers: [
{
findFileUrl() {
Expand All @@ -168,11 +168,11 @@ describe('FileImporter', () => {

it("doesn't pass relative loads to the importer", () =>
sandbox(dir => {
dir.write({'_midstream.scss': '@import "upstream"'});
dir.write({'_midstream.scss': '@use "upstream"'});
dir.write({'_upstream.scss': 'a {b: c}'});

let count = 0;
const result = compileString('@import "midstream";', {
const result = compileString('@use "midstream";', {
importers: [
{
findFileUrl() {
Expand All @@ -191,7 +191,7 @@ describe('FileImporter', () => {

it('wraps an error', () => {
expect(() => {
compileString('@import "other";', {
compileString('@use "other";', {
importers: [
{
findFileUrl() {
Expand All @@ -205,7 +205,7 @@ describe('FileImporter', () => {

it('rejects a non-file URL', () => {
expect(() => {
compileString('@import "other";', {
compileString('@use "other";', {
importers: [{findFileUrl: () => new URL('u:other.scss')}],
});
}).toThrowSassException({line: 0});
Expand All @@ -215,7 +215,7 @@ describe('FileImporter', () => {
it('.scss, parses it as SCSS', () =>
sandbox(dir => {
dir.write({'_other.scss': '$a: value; b {c: $a}'});
const result = compileString('@import "other";', {
const result = compileString('@use "other";', {
importers: [{findFileUrl: () => dir.url('other')}],
});
expect(result.css).toBe('b {\n c: value;\n}');
Expand All @@ -224,7 +224,7 @@ describe('FileImporter', () => {
it('.sass, parses it as the indented syntax', () =>
sandbox(dir => {
dir.write({'_other.sass': '$a: value\nb\n c: $a'});
const result = compileString('@import "other";', {
const result = compileString('@use "other";', {
importers: [{findFileUrl: () => dir.url('other')}],
});
expect(result.css).toBe('b {\n c: value;\n}');
Expand All @@ -233,7 +233,7 @@ describe('FileImporter', () => {
it('.css, allows plain CSS', () =>
sandbox(dir => {
dir.write({'_other.css': 'a {b: c}'});
const result = compileString('@import "other";', {
const result = compileString('@use "other";', {
importers: [{findFileUrl: () => dir.url('other')}],
});
expect(result.css).toBe('a {\n b: c;\n}');
Expand All @@ -243,7 +243,7 @@ describe('FileImporter', () => {
sandbox(dir => {
dir.write({'_other.css': '$a: value; b {c: $a}'});
expect(() => {
compileString('@import "other";', {
compileString('@use "other";', {
importers: [{findFileUrl: () => dir.url('other')}],
});
}).toThrowSassException({
Expand All @@ -266,6 +266,8 @@ describe('FileImporter', () => {
},
},
],
// TODO(jathak): Add this once import deprecation is active
// silenceDeprecations: ['import'],
});
}));

Expand All @@ -289,7 +291,7 @@ describe('FileImporter', () => {
it('set for a relative URL', () =>
sandbox(dir => {
dir.write({'_other.css': 'a {b: c}'});
const result = compileString('@import "other";', {
const result = compileString('@use "other";', {
importers: [
{
findFileUrl: (url: string, context: CanonicalizeContext) => {
Expand All @@ -308,7 +310,7 @@ describe('FileImporter', () => {
it('set for an absolute URL', () =>
sandbox(dir => {
dir.write({'_other.css': 'a {b: c}'});
const result = compileString('@import "u:other";', {
const result = compileString('@use "u:other";', {
importers: [
{
findFileUrl: (url: string, context: CanonicalizeContext) => {
Expand All @@ -327,7 +329,7 @@ describe('FileImporter', () => {
it('unset when the URL is unavailable', () =>
sandbox(dir => {
dir.write({'_other.css': 'a {b: c}'});
const result = compileString('@import "u:other";', {
const result = compileString('@use "u:other";', {
importers: [
{
findFileUrl: (url: string, context: CanonicalizeContext) => {
Expand All @@ -342,7 +344,7 @@ describe('FileImporter', () => {
});

describe('async', () => {
it('resolves an @import', async () =>
it('resolves an @use', async () =>
sandbox(async dir => {
dir.write({'_other.scss': 'a {b: c}'});
const result = await compileStringAsync('@use "other"', {
Expand All @@ -357,7 +359,7 @@ describe('FileImporter', () => {

it('wraps an error', async () => {
await expectAsync(() =>
compileStringAsync('@import "other";', {
compileStringAsync('@use "other";', {
importers: [
{
findFileUrl: () => Promise.reject('this import is bad actually'),
Expand All @@ -376,10 +378,10 @@ describe('FileImporter', () => {
});

dir.write({
'main.scss': '@import "sub1/test"; @import "sub1/sub2/test"',
'sub1/test.scss': '@import "y"',
'main.scss': '@use "sub1/test"; @use "sub1/sub2/test" as test2',
'sub1/test.scss': '@use "y"',
'sub1/x.scss': 'x { from: sub1; }',
'sub1/sub2/test.scss': '@import "y"',
'sub1/sub2/test.scss': '@use "y"',
'sub1/sub2/x.scss': 'x { from: sub2; }',
});

Expand Down
Loading

0 comments on commit 250a836

Please sign in to comment.