Skip to content

Commit

Permalink
fix: import binop (#262)
Browse files Browse the repository at this point in the history
  • Loading branch information
cap-Bernardito committed Sep 22, 2020
1 parent a88af56 commit 538f4ba
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 4 deletions.
9 changes: 8 additions & 1 deletion src/evaluator.js
Expand Up @@ -80,13 +80,20 @@ async function getDependencies(
class ImportVisitor extends DepsResolver {
// eslint-disable-next-line class-methods-use-this
visitImport(imported) {
const node = imported.path.first;
let node = imported.path.first;

if (node.name === 'url') {
return;
}

if (!node.val) {
const evaluator = new Evaluator(ast);

node = evaluator.visit.call(evaluator, node).first;
}

const importedPath = (!node.val.isNull && node.val) || node.name;

let nodePath = importedPath;

if (!importedPath || deps.has(importedPath)) {
Expand Down
11 changes: 11 additions & 0 deletions test/__snapshots__/loader.test.js.snap
Expand Up @@ -480,6 +480,17 @@ exports[`loader should work "use" option: errors 1`] = `Array []`;
exports[`loader should work "use" option: warnings 1`] = `Array []`;
exports[`loader should work binop import: css 1`] = `
".not-real-nib {
color: #000;
}
"
`;
exports[`loader should work binop import: errors 1`] = `Array []`;
exports[`loader should work binop import: warnings 1`] = `Array []`;
exports[`loader should work indented import: css 1`] = `
"body {
color: #f00;
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/deep/import-fakenib-binop.styl
@@ -0,0 +1 @@
@import 'fake' + 'nib'
2 changes: 1 addition & 1 deletion test/fixtures/import-binop.styl
@@ -1,2 +1,2 @@
@import "deep/" + "import-" + "fakenib"
@import "deep/" + "import-" + "fakenib-binop"

4 changes: 2 additions & 2 deletions test/loader.test.js
Expand Up @@ -232,7 +232,7 @@ describe('loader', () => {
expect(getErrors(stats)).toMatchSnapshot('errors');
});

it.skip('should work binop import', async () => {
it('should work binop import', async () => {
const testId = './import-binop.styl';
const compiler = getCompiler(testId);
const stats = await compile(compiler);
Expand All @@ -243,7 +243,7 @@ describe('loader', () => {

const fixturesDir = path.resolve(__dirname, 'fixtures');
const fixtures = [
path.resolve(fixturesDir, 'deep', 'import-fakenib.styl'),
path.resolve(fixturesDir, 'deep', 'import-fakenib-binop.styl'),
path.resolve(fixturesDir, 'node_modules', 'fakenib', 'index.styl'),
path.resolve(fixturesDir, 'import-binop.styl'),
];
Expand Down

0 comments on commit 538f4ba

Please sign in to comment.