Skip to content

Commit 24437eb

Browse files
authored
Finish migrating off of @import and global built-ins (#2005)
* Migrate some more inspect calls * Migrate some additional global functions * Migrate some additional meta functions * More libsass global functions * libsass-closed-issues global functions * Migrate remaining global functions * Migrate plain CSS tests to module system * Migrate js-api-spec tests * Fix typo in is-bracketed * Fix remaining failures
1 parent f3d9fc8 commit 24437eb

File tree

273 files changed

+4131
-3557
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

273 files changed

+4131
-3557
lines changed

js-api-spec/compile.node.test.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,11 @@ describe('compileString', () => {
8282
'_upstream.scss': 'a {b: c}',
8383
});
8484
expect(
85-
compileString('@import "left"; @import "right"', {url}).loadedUrls
85+
compileString('@import "left"; @import "right"', {
86+
url,
87+
// TODO(jathak): Add this once import deprecation is active
88+
// silenceDeprecations: ['import'],
89+
}).loadedUrls
8690
).toEqual([
8791
url,
8892
dir.url('_left.scss'),

js-api-spec/compiler.node.test.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ describe('Compiler', () => {
3030
it('performs complete compilations', () =>
3131
sandbox(dir => {
3232
const logger = getLogger();
33-
dir.write({'input.scss': '@import "bar"; .fn {value: foo(bar)}'});
33+
dir.write({'input.scss': '@use "bar"; .fn {value: foo(bar)}'});
3434
const result = compiler.compile(dir('input.scss'), {
3535
importers,
3636
functions,
@@ -52,7 +52,7 @@ describe('Compiler', () => {
5252
syntax: 'scss',
5353
}),
5454
};
55-
dir.write({'input.scss': '@import "nested"; a {b: c}'});
55+
dir.write({'input.scss': '@use "nested"; a {b: c}'});
5656
const result = compiler.compile(dir('input.scss'), {
5757
importers: [nestedImporter],
5858
});
@@ -91,7 +91,7 @@ describe('AsyncCompiler', () => {
9191
.map((_, i) => {
9292
const filename = `input-${i}.scss`;
9393
dir.write({
94-
[filename]: `@import "${i}"; .fn {value: foo(${i})}`,
94+
[filename]: `@use "${i}" as _; .fn {value: foo(${i})}`,
9595
});
9696
return compiler.compileAsync(dir(filename), {
9797
importers: asyncImporters,
@@ -121,7 +121,7 @@ describe('AsyncCompiler', () => {
121121
it('waits for compilations to finish before disposing', () =>
122122
sandbox(async dir => {
123123
let completed = false;
124-
dir.write({'input.scss': '@import "slow"'});
124+
dir.write({'input.scss': '@use "slow"'});
125125
const {importer, triggerComplete} = getTriggeredImporter(
126126
() => (completed = true)
127127
);

js-api-spec/compiler.test.ts

+9-5
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ describe('Compiler', () => {
7373
it('performs complete compilations', () => {
7474
const logger = getLogger();
7575
const result = compiler.compileString(
76-
'@import "bar"; .fn {value: foo(baz)}',
76+
'@use "bar"; .fn {value: foo(baz)}',
7777
{importers, functions, logger}
7878
);
7979
expect(result.css).toEqualIgnoringWhitespace(
@@ -90,7 +90,7 @@ describe('Compiler', () => {
9090
syntax: 'scss',
9191
}),
9292
};
93-
const result = compiler.compileString('@import "nested"; a {b: c}', {
93+
const result = compiler.compileString('@use "nested"; a {b: c}', {
9494
importers: [nestedImporter],
9595
});
9696
expect(result.css).toEqualIgnoringWhitespace('x {y: z;} a {b: c;}');
@@ -139,8 +139,12 @@ describe('AsyncCompiler', () => {
139139
.fill(0)
140140
.map((_, i) =>
141141
compiler.compileStringAsync(
142-
`@import "${i}"; .fn {value: foo(${i})}`,
143-
{importers: asyncImporters, functions, logger}
142+
`@use "${i}" as _; .fn {value: foo(${i})}`,
143+
{
144+
importers: asyncImporters,
145+
functions,
146+
logger,
147+
}
144148
)
145149
);
146150
Array.from(await Promise.all(compilations))
@@ -165,7 +169,7 @@ describe('AsyncCompiler', () => {
165169
const {importer, triggerComplete} = getTriggeredImporter(
166170
() => (completed = true)
167171
);
168-
const compilation = compiler.compileStringAsync('@import "slow"', {
172+
const compilation = compiler.compileStringAsync('@use "slow"', {
169173
importers: [importer],
170174
});
171175

js-api-spec/deprecations.test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ describe('an error', () => {
131131
});
132132
});
133133

134+
// TODO(jathak): Disable these tests when there aren't any future deprecations.
134135
describe('for a future deprecation,', () => {
135136
let importer: Importer;
136137
beforeEach(() => {

js-api-spec/importer.node.test.ts

+28-26
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ it('avoids importer when canonicalize() returns null', () =>
1818
sandbox(dir => {
1919
dir.write({'dir/_other.scss': 'a {from: dir}'});
2020

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

3939
expect(() => {
40-
compileString('@import "other";', {
40+
compileString('@use "other";', {
4141
importers: [
4242
{
4343
canonicalize: (url: string) => new URL(`u:${url}`),
@@ -52,7 +52,7 @@ it('fails to import when load() returns null', () =>
5252
it('prefers a relative file load to an importer', () =>
5353
sandbox(dir => {
5454
dir.write({
55-
'input.scss': '@import "other"',
55+
'input.scss': '@use "other"',
5656
'_other.scss': 'a {from: relative}',
5757
});
5858

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

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

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

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

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

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

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

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

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

174174
let count = 0;
175-
const result = compileString('@import "midstream";', {
175+
const result = compileString('@use "midstream";', {
176176
importers: [
177177
{
178178
findFileUrl() {
@@ -191,7 +191,7 @@ describe('FileImporter', () => {
191191

192192
it('wraps an error', () => {
193193
expect(() => {
194-
compileString('@import "other";', {
194+
compileString('@use "other";', {
195195
importers: [
196196
{
197197
findFileUrl() {
@@ -205,7 +205,7 @@ describe('FileImporter', () => {
205205

206206
it('rejects a non-file URL', () => {
207207
expect(() => {
208-
compileString('@import "other";', {
208+
compileString('@use "other";', {
209209
importers: [{findFileUrl: () => new URL('u:other.scss')}],
210210
});
211211
}).toThrowSassException({line: 0});
@@ -215,7 +215,7 @@ describe('FileImporter', () => {
215215
it('.scss, parses it as SCSS', () =>
216216
sandbox(dir => {
217217
dir.write({'_other.scss': '$a: value; b {c: $a}'});
218-
const result = compileString('@import "other";', {
218+
const result = compileString('@use "other";', {
219219
importers: [{findFileUrl: () => dir.url('other')}],
220220
});
221221
expect(result.css).toBe('b {\n c: value;\n}');
@@ -224,7 +224,7 @@ describe('FileImporter', () => {
224224
it('.sass, parses it as the indented syntax', () =>
225225
sandbox(dir => {
226226
dir.write({'_other.sass': '$a: value\nb\n c: $a'});
227-
const result = compileString('@import "other";', {
227+
const result = compileString('@use "other";', {
228228
importers: [{findFileUrl: () => dir.url('other')}],
229229
});
230230
expect(result.css).toBe('b {\n c: value;\n}');
@@ -233,7 +233,7 @@ describe('FileImporter', () => {
233233
it('.css, allows plain CSS', () =>
234234
sandbox(dir => {
235235
dir.write({'_other.css': 'a {b: c}'});
236-
const result = compileString('@import "other";', {
236+
const result = compileString('@use "other";', {
237237
importers: [{findFileUrl: () => dir.url('other')}],
238238
});
239239
expect(result.css).toBe('a {\n b: c;\n}');
@@ -243,7 +243,7 @@ describe('FileImporter', () => {
243243
sandbox(dir => {
244244
dir.write({'_other.css': '$a: value; b {c: $a}'});
245245
expect(() => {
246-
compileString('@import "other";', {
246+
compileString('@use "other";', {
247247
importers: [{findFileUrl: () => dir.url('other')}],
248248
});
249249
}).toThrowSassException({
@@ -266,6 +266,8 @@ describe('FileImporter', () => {
266266
},
267267
},
268268
],
269+
// TODO(jathak): Add this once import deprecation is active
270+
// silenceDeprecations: ['import'],
269271
});
270272
}));
271273

@@ -289,7 +291,7 @@ describe('FileImporter', () => {
289291
it('set for a relative URL', () =>
290292
sandbox(dir => {
291293
dir.write({'_other.css': 'a {b: c}'});
292-
const result = compileString('@import "other";', {
294+
const result = compileString('@use "other";', {
293295
importers: [
294296
{
295297
findFileUrl: (url: string, context: CanonicalizeContext) => {
@@ -308,7 +310,7 @@ describe('FileImporter', () => {
308310
it('set for an absolute URL', () =>
309311
sandbox(dir => {
310312
dir.write({'_other.css': 'a {b: c}'});
311-
const result = compileString('@import "u:other";', {
313+
const result = compileString('@use "u:other";', {
312314
importers: [
313315
{
314316
findFileUrl: (url: string, context: CanonicalizeContext) => {
@@ -327,7 +329,7 @@ describe('FileImporter', () => {
327329
it('unset when the URL is unavailable', () =>
328330
sandbox(dir => {
329331
dir.write({'_other.css': 'a {b: c}'});
330-
const result = compileString('@import "u:other";', {
332+
const result = compileString('@use "u:other";', {
331333
importers: [
332334
{
333335
findFileUrl: (url: string, context: CanonicalizeContext) => {
@@ -342,7 +344,7 @@ describe('FileImporter', () => {
342344
});
343345

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

358360
it('wraps an error', async () => {
359361
await expectAsync(() =>
360-
compileStringAsync('@import "other";', {
362+
compileStringAsync('@use "other";', {
361363
importers: [
362364
{
363365
findFileUrl: () => Promise.reject('this import is bad actually'),
@@ -376,10 +378,10 @@ describe('FileImporter', () => {
376378
});
377379

378380
dir.write({
379-
'main.scss': '@import "sub1/test"; @import "sub1/sub2/test"',
380-
'sub1/test.scss': '@import "y"',
381+
'main.scss': '@use "sub1/test"; @use "sub1/sub2/test" as test2',
382+
'sub1/test.scss': '@use "y"',
381383
'sub1/x.scss': 'x { from: sub1; }',
382-
'sub1/sub2/test.scss': '@import "y"',
384+
'sub1/sub2/test.scss': '@use "y"',
383385
'sub1/sub2/x.scss': 'x { from: sub2; }',
384386
});
385387

0 commit comments

Comments
 (0)