Skip to content

Instantly share code, notes, and snippets.

View andreypopp's full-sized avatar
🏠
Working from home

Andrey Popp andreypopp

🏠
Working from home
View GitHub Profile
macro __rejectAwait {
case { _ $body ... } => {
letstx $await = [makeIdent('await', #{$body ...}[0])];
return #{
macro $await {
case { $name:ident $e:expr } => {
throwSyntaxError('await', 'cannot use await keyword outside of async function', #{$name});
}
}
$body ...
@andreypopp
andreypopp / di.sjs
Created February 3, 2014 08:23
Dependency injection DSL for JavaScript
macro emitQuery {
case { _ $id:ident } => {
letstx $name = [makeValue(#{$id}[0].token.value, #{$id})];
letstx $registry = [makeIdent('registry', #{$id})];
return #{ var $id = $registry.query($name) }
}
}
macro inject {
case { _ $id:ident (,) ... { $body ...} } => {
var theme = require('my-theme');
module.exports = style {
background-color: {theme.bgColor};
}
@import "./theme" as theme
.Component {
.Child {
width: var(theme.width);
}
}
function condition(props) {
return props.if ? Array.prototype.slice.call(arguments, 1) : [];
}
var Component = React.createClass({
render: function() {
return (
<div>
<condition if={this.state.show}>
True!
@andreypopp
andreypopp / macroFilter.sjs
Last active August 29, 2015 13:56
Array.prototype.filter-like method call expanded into an efficient loop
macro replace {
case { _ $a:expr $b:expr { $first $rest ... } } => {
if ($a.token.value === $first.token.value) {
return #{ $b replace $a $b $rest ... }
} else {
return #{ $first replace $a $b { $rest ... } }
}
}
case { _ $a:expr $b:expr { } } => {
return [];
function Stylesheets() {
var registry = requireAssets.currentRegistry();
var stylesheets = [];
for (var url in registry.urlToFilename)
if (/\.css$/.exec(url))
stylesheets.push(<link rel="stylesheet" key={url} href={url} />);
return stylesheets;
}
var App = React.createClass({
---
title: Some new title
...
# some new stuff
And now some text is here
Another test
/**
* @jsx React.DOM
*/
var jsx = (
React.DOM.div(null,
" Hello, " ,
React.DOM.a(null, "world!")
)
);
var React = require('react');
var Router = require('react-router-component');
var Link = Router.Link;
var Locations = Router.Locations;
var Location = Router.Location;
var plugins = [
{title: 'Reports', path: '/reports', handler: ReportHandler},
...
];