JavaScript Macros

@beckje01

sweet.js


Made by Mozilla
http://sweetjs.org/
mozilla/sweet.js

Install


npm install -g sweet.js

Use


sjs -o output.js example.sjs

SEAF

Self Executing Anonymous Function

(function(){
    //Work Here
})();
        

Macro


macro seaf {
    case  $body => {
		(function()
			$body
		)();
	}
}

seaf.sjs

var foo = 'go';

seaf{
     var bar ='bob';
 	console.log("In sef");
}

console.log(foo);
console.log(bar);
Output:
In seaf
go

/Users/jeffbeck/projects/jsmacro/seaf.js:7
console.log(bar);
ReferenceError: bar is not defined

seaf.js


var foo = 'go';
(function () {
    var bar$2 = 'bob';
    console.log('In seaf');
}());
console.log(foo);
console.log(bar);

Other Macros


Start of Scheme
scheme {
  (display "hello")
  (display "foo")
  (define foo (lambda (a) (return "hello")))
}

Other Macros


Enum
$enum Suites { CLUBS, SPADES, HEARTS, DIAMONDS }
Made with Slides.com