Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: import binop #262

Merged
merged 1 commit into from Sep 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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