Skip to content

Commit

Permalink
fix source map
Browse files Browse the repository at this point in the history
  • Loading branch information
alongubkin committed Nov 15, 2014
1 parent 0904a27 commit 83cdb5b
Showing 1 changed file with 39 additions and 28 deletions.
67 changes: 39 additions & 28 deletions lib/spider.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,33 +55,46 @@ exports.compile = function (text, verbose, errors, sourceMap, sourceMapUrl, iifi
if (parsed) {
var tree = parsed.codegen();

if (iifi) {
if (iifi || useStrict) {
// Add ;(function () { ... })()
tree = {
"type": "Program",
"body": [
{ "type": "EmptyStatement" },
{
"type": "ExpressionStatement",
"expression": {
"type": "CallExpression",
"callee": {
"type": "FunctionExpression",
"id": null,
"params": [],
"defaults": [],
"body": {
"type": "BlockStatement",
"body": tree.body
},
"rest": null,
"generator": false,
"expression": false
var body = [];

if (useStrict) {
body.push({
"type": "ExpressionStatement",
"expression": {
"type": "Literal",
"value": "use strict;"
}
});
}

if (iifi) {
body.push({
"type": "ExpressionStatement",
"expression": {
"type": "CallExpression",
"callee": {
"type": "FunctionExpression",
"id": null,
"params": [],
"defaults": [],
"body": {
"type": "BlockStatement",
"body": tree.body
},
"arguments": []
}
"rest": null,
"generator": false,
"expression": false
},
"arguments": []
}
]
});
}

tree = {
"type": "Program",
"body": body
};
}

Expand All @@ -93,13 +106,11 @@ exports.compile = function (text, verbose, errors, sourceMap, sourceMapUrl, iifi
}
});

var finalCode = [useStrict ? '"use strict";\n\n' : '', sourceMap ? output.code : output];

var js = sourceMap ? output.code : output;
if (sourceMap) {
finalCode.push("\n\n", "//# sourceMappingURL=", sourceMapUrl);
js += "\n\n//# sourceMappingURL=" + sourceMapUrl;
}

var js = finalCode.join('');
if (sourceMap) {
output.code = js;
} else {
Expand Down

0 comments on commit 83cdb5b

Please sign in to comment.