Skip to content

Commit

Permalink
Supported double quoted use imports from built-ins (#147)
Browse files Browse the repository at this point in the history
  • Loading branch information
amannn committed Jul 2, 2021
1 parent a5bca05 commit c391d6b
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
@@ -1,4 +1,7 @@
# Change Log
## [2.2.4] - Unreleased
* Support double quoted imports of built-ins. [#145](https://github.com/shakacode/sass-resources-loader/pull/147) by [Jan Amann](https://github.com/amannn).

## [2.2.3] - 2021-06-21
* Fix regression introduced in 2.2.2 for "causes TypeError: Cannot read property 'indexOf' of undefined". [#145](https://github.com/shakacode/sass-resources-loader/pull/145) by [Juan Antonio Gómez](https://github.com/shokmaster).

Expand Down
2 changes: 1 addition & 1 deletion src/utils/rewritePaths.js
Expand Up @@ -24,7 +24,7 @@ export default function rewritePaths(error, file, contents, moduleContext, callb

const rewritten = contents.replace(useRegexp, (entire, importer, single, double, unquoted) => {
// Don't rewrite imports from built-ins
if (single && single.indexOf('sass:') === 0) {
if ([single, double].some(match => match && match.indexOf('sass:') === 0)) {
return entire;
}

Expand Down
18 changes: 18 additions & 0 deletions test/__snapshots__/index.test.js.snap
Expand Up @@ -103,6 +103,20 @@ exports[`sass-resources-loader imports should not rewrite the path for built-ins
@use 'sass:math';
$padding: #{math.div(4 / 2)}px;
div {
padding: $padding;
margin: #{math.div(4 / 2)}px;;
}
"
`;

exports[`sass-resources-loader imports should not rewrite the path for built-ins with @use and double quotes 1`] = `
"// Should be de-duplicated
@use 'sass:math';
$padding: #{math.div(4 / 2)}px;
div {
Expand Down Expand Up @@ -140,6 +154,10 @@ exports[`sass-resources-loader resources should parse array resources 1`] = `
@forward \\"variables\\";
@use \\"sass:math\\";
$padding: #{math.div(4 / 2)}px;
@use 'sass:math';
$padding: #{math.div(4 / 2)}px;
Expand Down
11 changes: 11 additions & 0 deletions test/index.test.js
Expand Up @@ -252,6 +252,17 @@ describe('sass-resources-loader', () => {
const output = require('./output/use-builtin').default;
expect(output).toMatchSnapshot();
}));

it('should not rewrite the path for built-ins with @use and double quotes', () => execTest('use-builtin', {
hoistUseStatements: true,
resources: [
path.resolve(__dirname, './scss/shared/_math-double-quotes.scss'),
],
}).then(() => {
// eslint-disable-next-line global-require
const output = require('./output/use-builtin').default;
expect(output).toMatchSnapshot();
}));
});

describe('getOutput', () => {
Expand Down
3 changes: 3 additions & 0 deletions test/scss/shared/_math-double-quotes.scss
@@ -0,0 +1,3 @@
@use "sass:math";

$padding: #{math.div(4 / 2)}px;

0 comments on commit c391d6b

Please sign in to comment.