Sweet.js - Can macros be used in more than one file?

119 Views Asked by At

I've got macros defined in file 'A'. I'd like to use the macros in other files, e.g. file B.

Is this possible? I know of course that I could use the compiled results of the macro in file B, but I'd like to use the macro there too.

A

macro test {
 ...
}

test 1
test 2

B

test 3
test 4
2

There are 2 best solutions below

1
On BEST ANSWER

Yes, you need to use the --module flag and export your macro in file A. It's documented here.

1
On

You can surely do it!

You'll need to export the macro and pass the file name as a parameter when compiling.

Look this:

set.sjs

macro set {
    rule { $i:ident = $value:lit } => {
        var $i = $value;
    }
}
export set;

id.sjs

macro id {
    rule { $i:ident } => 
    {
        $i;
    }
}
export id;

And while compiling:

 => # sjs --module ./set.sjs ./id.sjs