Skip to content

Instantly share code, notes, and snippets.

@divmain
Last active July 17, 2016 01:39
Show Gist options
  • Save divmain/860998eb9e2c923efb593c4459ee0a70 to your computer and use it in GitHub Desktop.
Save divmain/860998eb9e2c923efb593c4459ee0a70 to your computer and use it in GitHub Desktop.
{
"type": "Program",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "CallExpression",
"callee": {
"type": "FunctionExpression",
"id": null,
"generator": false,
"expression": false,
"params": [],
"body": {
"type": "BlockStatement",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "CallExpression",
"callee": {
"type": "MemberExpression",
"object": {
"type": "MemberExpression",
"object": {
"type": "Identifier",
"name": "window",
"_fromTemplate": true
},
"property": {
"type": "StringLiteral",
"value": "__interlock__",
"trailingComments": [],
"leadingComments": [],
"innerComments": []
},
"computed": true,
"_fromTemplate": true
},
"property": {
"type": "Identifier",
"name": "load",
"_fromTemplate": true
},
"computed": false,
"_fromTemplate": true
},
"arguments": [
{
"type": "ObjectExpression",
"properties": [
{
"type": "ObjectProperty",
"key": {
"type": "StringLiteral",
"value": "Vhuc3trv2ZXj20yeW-O2pydCgF4"
},
"value": {
"type": "ObjectExpression",
"properties": [
{
"type": "ObjectProperty",
"method": false,
"shorthand": false,
"computed": false,
"key": {
"type": "Identifier",
"name": "deps",
"_fromTemplate": true
},
"value": {
"type": "ArrayExpression",
"elements": [],
"trailingComments": [],
"leadingComments": [],
"innerComments": []
},
"_fromTemplate": true
},
{
"type": "ObjectProperty",
"method": false,
"shorthand": false,
"computed": false,
"key": {
"type": "Identifier",
"name": "fn",
"_fromTemplate": true
},
"value": {
"type": "FunctionExpression",
"id": null,
"generator": false,
"expression": false,
"params": [
{
"type": "Identifier",
"name": "require",
"_fromTemplate": true
},
{
"type": "Identifier",
"name": "module",
"_fromTemplate": true
},
{
"type": "Identifier",
"name": "exports",
"_fromTemplate": true
}
],
"body": {
"type": "BlockStatement",
"body": [
{
"type": "ExpressionStatement",
"start": 37,
"end": 55,
"loc": {
"start": {
"line": 2,
"column": 0
},
"end": {
"line": 2,
"column": 18
},
"filename": "interlock-example/app/entry-a.js"
},
"expression": {
"type": "CallExpression",
"start": 37,
"end": 54,
"loc": {
"start": {
"line": 2,
"column": 0
},
"end": {
"line": 2,
"column": 17
},
"filename": "interlock-example/app/entry-a.js"
},
"callee": {
"type": "MemberExpression",
"start": 37,
"end": 48,
"loc": {
"start": {
"line": 2,
"column": 0
},
"end": {
"line": 2,
"column": 11
},
"filename": "interlock-example/app/entry-a.js"
},
"object": {
"type": "Identifier",
"start": 37,
"end": 44,
"loc": {
"start": {
"line": 2,
"column": 0
},
"end": {
"line": 2,
"column": 7
},
"filename": "interlock-example/app/entry-a.js"
},
"name": "console",
"leadingComments": null
},
"property": {
"type": "Identifier",
"start": 45,
"end": 48,
"loc": {
"start": {
"line": 2,
"column": 8
},
"end": {
"line": 2,
"column": 11
},
"filename": "interlock-example/app/entry-a.js"
},
"name": "log"
},
"computed": false,
"leadingComments": null
},
"arguments": [
{
"type": "StringLiteral",
"start": 49,
"end": 53,
"loc": {
"start": {
"line": 2,
"column": 12
},
"end": {
"line": 2,
"column": 16
},
"filename": "interlock-example/app/entry-a.js"
},
"extra": {
"rawValue": "hi",
"raw": "\"hi\""
},
"value": "hi"
}
],
"leadingComments": null
},
"leadingComments": [
{
"type": "CommentLine",
"value": " the comment seems to break things",
"start": 0,
"end": 36,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 36
}
}
}
]
}
],
"directives": [],
"_fromTemplate": true
},
"_fromTemplate": true
},
"_fromTemplate": true
}
],
"extra": {
"parenthesized": true,
"parenStart": 0
},
"_fromTemplate": true
},
"computed": false,
"shorthand": false,
"decorators": null
}
],
"trailingComments": [],
"leadingComments": [],
"innerComments": []
}
],
"_fromTemplate": true
},
"_fromTemplate": true
}
],
"directives": [],
"_fromTemplate": true
},
"extra": {
"parenthesized": true,
"parenStart": 0
},
"_fromTemplate": true
},
"arguments": [],
"_fromTemplate": true
},
"_fromTemplate": true
}
]
}
const generate = require("babel-generator").default;
const ast = require("./ast.json");
generate(ast, {
sourceMaps: true,
sourceMapTarget: "my-output-file.js"
}, {
"interlock-example/app/entry-a.js": "// the comment seems to break things\nconsole.log(\"hi\");\n"
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment