Skip to content

nested @import fails when importer is async #59

@nelisbijl

Description

@nelisbijl

When the importer does not call done synchronously, a nested @import fails.
See sample code below
If you comment out the async invocation and uncomment the direct invocation, things work as expected

import Sass from 'sass.js';
var scssSuccess = '@import "child"; .parent { color:green; }',
    scssFail = '.parent { @import "child"; }';

Sass.importer((request, done) => {
    var childCss = '.child { color: red; }';

    var processContent = (content) => {
        var result = {
            content: content,
            path: 'file:///C:/TMP/child.scss'
        };
        console.log('importer\n  result', result);
        done(result);
    };

    // delayed (async) invocation of done
    new Promise(resolve => { resolve(childCss); }).then(processContent);

    // direct invocation of done
    //processContent(childCss);
});

async function compile(scss) {
    return await new Promise(resolve => {
        console.log('sass.compile\n  content', '>>>' + scss + '<<<');
        Sass.compile(scss, resolve);
    }).then(function (result) {
        console.log('result', result);
        return this;
    });
}

compile(scssSuccess).
then(() => {
    console.log('\n\nFAIL SITUATION');
    compile(scssFail);
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions