Skip to content

Instantly share code, notes, and snippets.

@jbalogh
Last active August 29, 2015 14:01
Show Gist options
  • Save jbalogh/91d9ff781a377729a468 to your computer and use it in GitHub Desktop.
Save jbalogh/91d9ff781a377729a468 to your computer and use it in GitHub Desktop.
[1,2,3].map(x => x * x)
macro => {
rule infix { ($value (,) ...) | {$body ...} } => {
function($value (,) ...) {
$body ...
}.bind(this)
}
rule infix { ($value (,) ...) | $guard:expr } => {
function($value (,) ...) {
return $guard;
}.bind(this)
}
rule infix { $param:ident | $guard:expr } => {
function($param) {
return $guard;
}.bind(this)
}
}
export =>
$ git clone https://gist.github.com/91d9ff781a377729a468.git && cd 91d9ff781a377729a468
Cloning into '91d9ff781a377729a468'...
remote: Counting objects: 4, done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 4 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (4/4), done.
Checking connectivity... done.
$ npm install git+ssh://[email protected]:mozilla/sweet.js.git
npm http GET https://registry.npmjs.org/escodegen
npm http GET https://registry.npmjs.org/optimist
npm http GET https://registry.npmjs.org/underscore
npm http GET https://registry.npmjs.org/escope
npm http GET https://registry.npmjs.org/resolve
npm http 304 https://registry.npmjs.org/escodegen
npm http 304 https://registry.npmjs.org/resolve
npm http 304 https://registry.npmjs.org/optimist
npm http 304 https://registry.npmjs.org/underscore
npm http 304 https://registry.npmjs.org/escope
npm http GET https://registry.npmjs.org/estraverse
npm http GET https://registry.npmjs.org/wordwrap
npm http GET https://registry.npmjs.org/esprima
npm http GET https://registry.npmjs.org/estraverse
npm http GET https://registry.npmjs.org/source-map
npm http GET https://registry.npmjs.org/esutils
npm http 304 https://registry.npmjs.org/source-map
npm http 304 https://registry.npmjs.org/estraverse
npm http 304 https://registry.npmjs.org/estraverse
npm http 304 https://registry.npmjs.org/wordwrap
npm http 304 https://registry.npmjs.org/esutils
npm http 304 https://registry.npmjs.org/esprima
npm http GET https://registry.npmjs.org/amdefine
npm http 304 https://registry.npmjs.org/amdefine
[email protected] node_modules/sweet.js
├── [email protected]
├── [email protected]
├── [email protected] ([email protected])
├── [email protected] ([email protected])
└── [email protected] ([email protected], [email protected], [email protected], [email protected])
$ ./node_modules/.bin/sjs --sourcemap --module ./macro.js file.js -o output.js
/private/tmp/91d9ff781a377729a468/node_modules/sweet.js/node_modules/escodegen/node_modules/source-map/lib/source-map/source-map-generator.js:269
throw new Error('Invalid mapping: ' + JSON.stringify({
^
Error: Invalid mapping: {"generated":{"line":5,"column":16},"source":"file.js","original":{"line":1,"column":-295},"name":"x$532"}
at SourceMapGenerator_validateMapping [as _validateMapping] (/private/tmp/91d9ff781a377729a468/node_modules/sweet.js/node_modules/escodegen/node_modules/source-map/lib/source-map/source-map-generator.js:269:15)
at SourceMapGenerator_addMapping [as addMapping] (/private/tmp/91d9ff781a377729a468/node_modules/sweet.js/node_modules/escodegen/node_modules/source-map/lib/source-map/source-map-generator.js:102:12)
at /private/tmp/91d9ff781a377729a468/node_modules/sweet.js/node_modules/escodegen/node_modules/source-map/lib/source-map/source-node.js:323:15
at SourceNode_walk [as walk] (/private/tmp/91d9ff781a377729a468/node_modules/sweet.js/node_modules/escodegen/node_modules/source-map/lib/source-map/source-node.js:202:11)
at SourceNode_walk [as walk] (/private/tmp/91d9ff781a377729a468/node_modules/sweet.js/node_modules/escodegen/node_modules/source-map/lib/source-map/source-node.js:198:15)
at SourceNode_walk [as walk] (/private/tmp/91d9ff781a377729a468/node_modules/sweet.js/node_modules/escodegen/node_modules/source-map/lib/source-map/source-node.js:198:15)
at SourceNode_walk [as walk] (/private/tmp/91d9ff781a377729a468/node_modules/sweet.js/node_modules/escodegen/node_modules/source-map/lib/source-map/source-node.js:198:15)
at SourceNode_walk [as walk] (/private/tmp/91d9ff781a377729a468/node_modules/sweet.js/node_modules/escodegen/node_modules/source-map/lib/source-map/source-node.js:198:15)
at SourceNode_walk [as walk] (/private/tmp/91d9ff781a377729a468/node_modules/sweet.js/node_modules/escodegen/node_modules/source-map/lib/source-map/source-node.js:198:15)
at SourceNode_walk [as walk] (/private/tmp/91d9ff781a377729a468/node_modules/sweet.js/node_modules/escodegen/node_modules/source-map/lib/source-map/source-node.js:198:15)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment