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://git@github.com: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
sweet.js@0.6.0 node_modules/sweet.js
├── resolve@0.6.3
├── underscore@1.3.3
├── escope@1.0.1 (estraverse@1.5.0)
├── optimist@0.3.7 (wordwrap@0.0.2)
└── escodegen@1.2.0 (estraverse@1.5.0, esutils@1.0.0, esprima@1.0.4, source-map@0.1.33)
$ ./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