From 538f4ba8d50a97808f6ea97cfcbe569d0b853f46 Mon Sep 17 00:00:00 2001 From: Alexey Lavinsky Date: Tue, 22 Sep 2020 16:06:51 +0300 Subject: [PATCH] fix: import binop (#262) --- src/evaluator.js | 9 ++++++++- test/__snapshots__/loader.test.js.snap | 11 +++++++++++ test/fixtures/deep/import-fakenib-binop.styl | 1 + test/fixtures/import-binop.styl | 2 +- test/loader.test.js | 4 ++-- 5 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 test/fixtures/deep/import-fakenib-binop.styl diff --git a/src/evaluator.js b/src/evaluator.js index 1d04384..4133c55 100644 --- a/src/evaluator.js +++ b/src/evaluator.js @@ -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)) { diff --git a/test/__snapshots__/loader.test.js.snap b/test/__snapshots__/loader.test.js.snap index 9027c22..4bbe625 100644 --- a/test/__snapshots__/loader.test.js.snap +++ b/test/__snapshots__/loader.test.js.snap @@ -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; diff --git a/test/fixtures/deep/import-fakenib-binop.styl b/test/fixtures/deep/import-fakenib-binop.styl new file mode 100644 index 0000000..496b857 --- /dev/null +++ b/test/fixtures/deep/import-fakenib-binop.styl @@ -0,0 +1 @@ +@import 'fake' + 'nib' diff --git a/test/fixtures/import-binop.styl b/test/fixtures/import-binop.styl index da5bbf1..119bb93 100644 --- a/test/fixtures/import-binop.styl +++ b/test/fixtures/import-binop.styl @@ -1,2 +1,2 @@ -@import "deep/" + "import-" + "fakenib" +@import "deep/" + "import-" + "fakenib-binop" diff --git a/test/loader.test.js b/test/loader.test.js index ebf60d4..825c416 100644 --- a/test/loader.test.js +++ b/test/loader.test.js @@ -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); @@ -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'), ];